Skip to content

autoresearch: harness-spawned device scripts get no RPC responses while the harness holds its own connection #4207

Closed

Description

@zackees

Symptom

bash autoresearch rp2350w --rp-spi-loopback fails before reaching the device:

FAIL — rpc.discover did not return a schema object (got NoneType)

The same script, same board, same code path, run standalone, works:

uv run python -m ci.autoresearch.test_rp_spi_loopback --port /dev/ttyACM0 --spi-index 0
  rpSpiLoopback(SPI0, 1,000,000 Hz)
    FAIL — RP SPI loopback failed.
      capture: {'driver': 'SPI0', 'sckPin': 2, 'misoPin': 0, 'mosiPin': 3,
                'expected': [0, 255, 85, 170, ...],
                'received': [0, 0, 0, 0, ...], 'wireIdle': True, ...}

(That standalone failure is a separate, physical matter — an unfitted GPIO3->GPIO0 jumper. The point here is that it reached the device and executed, which the harness-invoked run never does.)

What is different

_run_rp_spi_loopback_tests in ci/autoresearch/phases.py spawns the script as a subprocess:

cmd = ["uv", "run", "python", "-m", "ci.autoresearch.test_rp_spi_loopback",
       "--port", upload_port, ...]
result = RunningProcess.run(cmd, check=False, timeout=ctx.remaining_seconds())

while the parent harness still holds its own RpcBench/serial connection to that port. The parent's own schema fetch succeeds in the same run, immediately before:

🔍 Validating RPC commands against device schema...
✅ Fetched schema: 71 methods
✅ All 0 RPC commands validated against schema
...
FAIL — rpc.discover did not return a schema object (got NoneType)

So one connection to the port works and the second gets nothing back.

What I have NOT established

The mechanism inside fbuild's serial daemon. SerialManager::attach_reader() hands out a broadcast::Receiver and reader_client_ids is a set, so reads look like they should fan out to both clients. I did not verify whether a second client's writes reach the device, which is the obvious next thing to check but which I have no evidence for either way.

I am deliberately not naming a cause. I proposed three for the NoneType before comparing harness-vs-standalone — a short discover timeout, the call_flat frame shape, and payload size — and each was refuted by the next run. The harness/standalone difference is the only thing I have actually demonstrated.

Possibly related but distinct: FastLED/fbuild#1427 (approved, unmerged) concerns a leaked reader left after deploy's post-flash monitor. This is concurrent readers by design, so I would not assume one fixes the other.

Scope

This is not SPI-specific. Any ci/autoresearch/test_*.py the harness spawns as a subprocess against a port it still holds should hit the same thing. Worth checking the other test_* runners.

Why it matters beyond the failure itself

Until PR #4206 the failure printed as:

FAIL — deployed firmware schema does not contain rpSpiLoopback

on a board that does expose the method (a direct query returns both rpSpiLoopback and rpSpiPublicApiLoopback). That asserts a firmware build gap and sends the reader hunting for a missing FASTLED_AUTORESEARCH_LOW_MEMORY branch. #4206 makes the message honest about not knowing; it does not fix this.

Reproduction

# fails
bash autoresearch rp2350w --rp-spi-loopback --rp-spi-index 0 --upload-port /dev/ttyACM0

# works (reaches device, runs the test)
uv run python -m ci.autoresearch.test_rp_spi_loopback --port /dev/ttyACM0 --spi-index 0

Bench: RP2350W 2DCB876B587EA334, 2E8A:F00F, /dev/ttyACM0.

Activity

  1. zackees commented on Sep 7, 2026

    @zackees
    MemberAuthor

    Minimal reproduction — no harness, no SPI, no subprocess. Two RpcBench clients on one port, in a single process:

    a = RpcBench(port, timeout=20.0)
    print("A ping ->", a.call("ping"))
    
    b = RpcBench(port, timeout=20.0)          # succeeds, no exception
    print("B ping ->", b.call("ping"))
    print("A ping again ->", a.call("ping"))

    RP2350W on /dev/ttyACM0:

    == opening client A ==
    A ping -> {'message': 'pong', 'success': True, 'uptimeMs': 340709, ...}
    == opening client B while A is still attached ==
    B ping -> None
    A ping again -> {'message': 'pong', 'success': True, 'uptimeMs': 362079, ...}
    

    Three things this pins down that the harness-vs-standalone comparison did not:

    1. B connects successfully. RpcBench.__init__ runs connect(boot_wait=3.0, drain_boot=True) to completion and raises nothing. There is no error to notice.
    2. B is then completely inert — every call returns None. It looks like a healthy client and answers nothing.
    3. A is unaffected, before and after B exists. The port does not break; the second client is simply dead.

    So this is not subprocess-specific, not SPI-specific, and not a teardown-ordering problem. Any code path that opens a second RpcBench against a port another client already holds gets a silently useless client.

    The silence is the dangerous part. A dead-but-connected client makes every downstream call return None, and callers then interpret None as a statement about the device. That is exactly how this surfaced originally: FAIL — deployed firmware schema does not contain rpSpiLoopback on a board that does expose the method. The transport had failed; the message blamed the firmware.

    Still not claiming the mechanism. SerialManager::attach_reader() returns a broadcast::Receiver and reader_client_ids is a set, so reads look like they should fan out. Whether B's writes reach the device is the remaining question, and I have not instrumented that. What is now established is the observable contract violation: a second attach appears to succeed and does not work.

    Two directions a fix could take, for whoever picks this up:

    • Make a second attach either work or fail loudly. Silently returning a non-functional client is worse than refusing, given how the None propagates.
    • On the FastLED side, have the harness release its connection before spawning a device script against the same port (_run_rp_spi_loopback_tests and any sibling test_* runner).

    Reproduction script is 20 lines; happy to attach it if useful.

  2. zackees commented on Sep 8, 2026

    @zackees
    MemberAuthor

    Status after #4208 merged: the workflow is fixed, the contract problem is not. Recording this so the issue is not closed on the strength of the PR.

    #4208 stopped both SPI phases from spawning a device script against a port the harness still holds, and that half is confirmed on master (ci/autoresearch/phases.py now releases ctx.serial_iface at both spawn sites). The harness-invoked loopback reaches the device and fails only on the unfitted jumper, which is the correct outcome.

    But the underlying behaviour is unchanged. Re-ran the minimal repro against merged master (3ee4009a83) on the RP2350W:

    == opening client A ==
    A ping       -> {'message': 'pong', 'success': True, 'uptimeMs': 1609307, ...}
    == opening client B while A is still attached ==
    B ping       -> None
    A ping again -> {'message': 'pong', 'success': True, 'uptimeMs': 1633438, ...}
    

    Identical to the pre-merge result: B connects without raising and is then completely inert, every call returning None, while A is unaffected before and after.

    So #4208 removed the two places in the harness that tripped over this; it did not change what happens when something opens a second client. Any future code path that does so gets the same silently useless object, and the None will again read to its caller as a statement about the device — which is how this first surfaced as deployed firmware schema does not contain rpSpiLoopback against a board that exposes the method.

    I would suggest keeping this open for the contract fix: a second attach should either work or fail loudly. Silent success is the property that makes it expensive, not the fact that two callers can collide.

    Still not claiming a mechanism. SerialManager::attach_reader() hands out a broadcast::Receiver and reader_client_ids is a set, so reads look like they should fan out; whether B's writes reach the device is the open question and I have not instrumented it.

  3. moved this from Triage to Done in FastLED Trackeron Sep 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions