Skip to content

fix(ci/serial): make FbuildSerialAdapter.close() reusable (FastLED/fbuild#592) - #3058

Merged
zackees merged 1 commit into
masterfrom
fix/serial-adapter-reusable-close
Jun 15, 2026
Merged

zackees merged 1 commit into
masterfrom
fix/serial-adapter-reusable-close

Conversation

@zackees

@zackees zackees commented Jun 15, 2026 •

Copy link
Copy Markdown
Member

Summary

Stops FbuildSerialAdapter.close() from permanently killing its per-adapter ThreadPoolExecutor. The autoresearch recovery branch (ci/autoresearch/gpio.py:70) closes the adapter and reuses it for a fresh RpcClient — the executor shutdown made the next _run_in_thread fail with cannot schedule new futures after shutdown.

This was the second link in the Teensy 4.0 failure chain:

post-flash USB re-enumeration
  -> WebSocket error: connection forcibly closed (os error 10054)
  -> FastLED retries: client.close() then new RpcClient(serial_interface=...)
  -> cannot schedule new futures after shutdown        # <-- this PR fixes this

Verification (live, Teensy 4.0)

After this change + the matching fbuild fix (FastLED/fbuild#593), the OBJECT_FLED (FlexIO TX) autoresearch run no longer crashes on the recovery path. The raw-edge analyzer captures and decodes real WS2812 timing:

[RAW EDGE TIMING] Pattern Analysis:
  Short HIGH (~225ns, Bit 0): FOUND ✓
  Long HIGH  (~580ns, Bit 1): FOUND ✓
  Short LOW  (~645ns, Bit 1): FOUND ✓
  Long LOW   (~1000ns, Bit 0): FOUND ✓
[RAW EDGE TIMING] ✓ Encoder appears to be working correctly (varied timing patterns)

So the FlexIO driver itself is fine; this PR removes the layered-on crash that was masking the actual test progress.

Why removing it is safe

  • The ThreadPoolExecutor is created inside __init__ and lives for the adapter's lifetime; nothing else stashes a reference to it.
  • When the adapter is dropped (e.g. when its owning RpcClient is garbage-collected), the executor's destructor cleans up.
  • The bug was specifically that calling close() was leaving the adapter object alive but its executor dead. Removing the shutdown call restores the invariant that close is logically idempotent and reusable.

Test plan

  • Live: bash autoresearch teensy40 --object-fled --upload-port COM20 no longer crashes on the post-flash USB re-enum recovery path
  • Live: FlexIO TX edge timing analyzer reports all four pulse widths in the WS2812 spec
  • CI

Refs: FastLED/fbuild#592, FastLED/fbuild#593

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Improved reliability of serial communication recovery by ensuring necessary system resources remain available during recovery operations.

…uild#592)

The autoresearch recovery path in `ci/autoresearch/gpio.py` calls
`client.close()` on a ping retry, then re-creates an `RpcClient` reusing
the same `FbuildSerialAdapter` instance. The adapter's `close()` was
calling `self._executor.shutdown(wait=False)`, which permanently kills
the per-adapter thread executor — the next `_run_in_thread` call fails
with `cannot schedule new futures after shutdown`.

This was the second link in today's Teensy 4.0 failure chain (post-flash
USB re-enumeration → `WebSocket forcibly closed` → close-and-reopen →
this crash). With the executor shutdown removed, the same autoresearch
recovery path now completes end-to-end and the OBJECT_FLED (FlexIO TX)
driver produces correctly-timed WS2812 edges (~225/580/645/1000ns short
HIGH / long HIGH / short LOW / long LOW — all detected by the live edge
analyzer).

The executor is still cleaned up at GC time when the adapter is dropped;
nothing leaks because `FbuildSerialAdapter` is created per-`RpcClient`
session.

Tracker: FastLED/fbuild#592 §3.5 (FastLED-side seam closure). Stays in
sync with the fbuild-daemon servicedef install (FastLED/fbuild#593).
@coderabbitai

coderabbitai Bot commented Jun 15, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: c38f2894-49a6-41cd-8647-7048062b0d6f

📥 Commits

Reviewing files that changed from the base of the PR and between e15eea8 and f0462d1.

📒 Files selected for processing (1)
  • ci/util/serial_interface.py

📝 Walkthrough

Walkthrough

FbuildSerialAdapter.close() in ci/util/serial_interface.py is modified to skip shutting down its internal ThreadPoolExecutor. A comment is added explaining that the executor must remain alive because a recovery path reuses the same adapter instance after close() for subsequent _run_in_thread() calls, including DTR-reset retries.

FbuildSerialAdapter Executor Lifecycle Fix

Layer / File(s) Summary
Remove executor shutdown from close()
ci/util/serial_interface.py
close() no longer calls self._executor.shutdown(); a comment documents that the ThreadPoolExecutor must stay alive because recovery code paths reuse the adapter after close() and call _run_in_thread() (e.g., for DTR-reset retries).

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Possibly related issues

Possibly related PRs

  • FastLED/FastLED#2262: Modifies FbuildSerialAdapter threading and read-loop behavior in the same file, overlapping at the adapter lifecycle and threading level.
  • FastLED/FastLED#2274: Introduces the DTR-reset recovery flow (reset_device() and reconnect logic) that depends on _run_in_thread() being available post-close(), which this PR directly enables.

Poem

🐇 A thread pool once shuttered too soon,
Left adapters cold under the moon.
Now close() steps aside,
Lets the executor ride,
And retries bloom again — what a boon! 🌙

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: making FbuildSerialAdapter.close() reusable by fixing executor shutdown behavior.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/serial-adapter-reusable-close

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 and usage tips.

@fastled-project-sync fastled-project-sync Bot moved this to Triage in FastLED Tracker Jun 15, 2026
@zackees
zackees merged commit 84ff2de into master Jun 15, 2026
8 of 9 checks passed
@fastled-project-sync fastled-project-sync Bot moved this from Triage to Done in FastLED Tracker Jun 15, 2026
@zackees
zackees deleted the fix/serial-adapter-reusable-close branch August 21, 2026 19:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant