Skip to content

fix(teensy): run flash in build dir + sweep stray dash-flag files (no more -r in repo root)#968

Merged
zackees merged 1 commit into
mainfrom
fix/teensy-flash-cwd-stray-r
Jul 5, 2026
Merged

fix(teensy): run flash in build dir + sweep stray dash-flag files (no more -r in repo root)#968
zackees merged 1 commit into
mainfrom
fix/teensy-flash-cwd-stray-r

Conversation

@zackees

@zackees zackees commented Jul 5, 2026

Copy link
Copy Markdown
Member

Problem

bash autoresearch teensy41 (FastLED) intermittently left a 0-byte file literally named -r in the user's project/repo root.

Reproduced: when the deploy port auto-detects to a non-PJRC device (e.g. an ESP32 on the wrong COM port), the teensy deploy takes the teensy_loader_cli -w retry path, and a stray -r appears in the working directory during that window (~110 s in, caught by a filesystem poller). The correct-port native-flash path is clean — hence the intermittency.

Root cause

flash::run_with_retry spawned the loader with cwd=None, so it inherited the fbuild daemon's working directory — typically the user's checkout. A flag-token file (-r) written by a tool/shell mis-parse in that window therefore landed in the repo root.

Exonerated definitively: teensy_loader_cli (its --help exposes no output-file option; running its exact argv --mcu=… -w -v firmware.hex creates nothing), and the fbuild subprocess/containment layer (Windows Job Objects, no file writes). The defect is the inherited cwd, not any one tool.

Fix (crates/fbuild-deploy/src/teensy/flash.rs)

  1. Run the flash in the firmware's own build directory (feeding the loader an absolute firmware path so the cwd change can't break the hex read). Any artifact a flash tool leaves now lands in the gitignored build tree, never the user's checkout.
  2. sweep_stray_dash_files() — after the flash loop, remove + WARN-log any 0-byte dash-flag file (-r, -w, …) found in the daemon cwd and the flash cwd. Guarantees the repo stays clean, and logs context to attribute the intermittent writer if it recurs.
  3. Unit test sweep_removes_empty_dash_flag_files_only (removes empty -r/-w; preserves non-empty -x, normal.txt, and long -verbose).

soldr cargo check -p fbuild-deploy passes.

Reported from FastLED autoresearch teensy41 runs.

🤖 Generated with Claude Code

… more `-r` in repo)

## Problem
`bash autoresearch teensy41` intermittently left a 0-byte file literally
named `-r` in the user's project/repo root. Reproduced: when the port
auto-detects to a non-PJRC device (e.g. an ESP32 on the wrong COM port),
the teensy deploy takes the `teensy_loader_cli -w` retry path, and a stray
`-r` appears in the working directory during that window (~110s in). The
correct-port native-flash path is clean, hence the intermittency.

## Root cause
`flash::run_with_retry` spawned the loader with `cwd=None`, so it inherited
the fbuild daemon's working directory — typically the user's checkout. A
flag-token file (`-r`) written by a tool/shell mis-parse in that window
therefore landed in the repo root. `teensy_loader_cli` itself is exonerated
(its usage exposes no output-file option and it creates nothing when run
with our exact argv); the fbuild subprocess/containment layer uses Windows
Job Objects with no file writes. The defect is the inherited cwd.

## Fix
1. Run the flash subprocess in the firmware's own build directory (feeding
   the loader an ABSOLUTE firmware path so the cwd change can't break the
   hex read). Any artifact a flash tool leaves now lands in the gitignored
   build tree, never the user's checkout.
2. `sweep_stray_dash_files()` — after the flash loop, remove and WARN-log
   any 0-byte dash-flag file (`-r`, `-w`, …) found in the daemon cwd and the
   flash cwd. Guarantees the repo stays clean and logs context to attribute
   the intermittent writer if it ever recurs.
3. Unit test `sweep_removes_empty_dash_flag_files_only`.

Reported from FastLED autoresearch teensy41 runs.
@coderabbitai

coderabbitai Bot commented Jul 5, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@zackees, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 26 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: e95ee095-e277-4dfb-b662-1fdac2adf41b

📥 Commits

Reviewing files that changed from the base of the PR and between de36eff and b22aca2.

📒 Files selected for processing (1)
  • crates/fbuild-deploy/src/teensy/flash.rs
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/teensy-flash-cwd-stray-r

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@zackees zackees merged commit 760b40b into main Jul 5, 2026
90 of 93 checks passed
@zackees zackees deleted the fix/teensy-flash-cwd-stray-r branch July 5, 2026 17:39
zackees added a commit that referenced this pull request Jul 5, 2026
#968 landed an unformatted `.map(...).unwrap_or_default()` chain in
teensy/flash.rs:125, turning the repo-wide Formatting check red on main
(failing for every PR since). `cargo fmt --all` reformats it; the check
is green again.

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
@fastled-project-sync fastled-project-sync Bot moved this to Triage in FastLED Tracker Jul 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Triage

Development

Successfully merging this pull request may close these issues.

1 participant