Skip to content

defect: laptop-agent broker — no singleton across two implementations + silent CONNECT-pool wedge (two fleet-blind episodes, 2026-11-13) #9611

Closed

Description

@dezren39

Defect: laptop-agent broker — no singleton across two implementations + silent CONNECT-pool wedge (two fleet-blind episodes, 2026-11-13)

Lineage: broker built under #5343 (laptop-agent design, closed). This issue is the broker-reliability defect record; #5343's scope (the daemon design) does not cover it.

All times CST (UTC−6); Z = UTC. Sandbox↔laptop traffic rides the session proxy (HTTP CONNECT) to the laptop tailnet IP 100.99.113.103; the broker listens on the unix socket ~/.cache/laptop-agent/broker.sock and pools CONNECT tunnels to the laptop agent on :4799.

Episode 1 — duplicate brokers + ensure churn (~16:43–17:27 CST)

  • ~/.cache/laptop-agent/broker.log shows interleaved starts of two implementations on the same socket path all afternoon: the Python broker (laptop-agent broker on .../broker.sock, untimestamped lines) and the Rust fleet proxy (fleet proxy serve start implementation=fleet-proxy version=0.1.0 pool_size=50, pids 31923 @22:43:42Z, 39880 @22:55:22Z, 42268 @22:59:29Z), plus repeated tracebacks from laptop-agent-broker.py main(): OSError: [Errno 98] Address already in use.
  • Two Python broker processes ended up LISTENing on the socket simultaneously. Diagnosis at the time isolated the fault to the broker layer: a broker-bypass health call to the laptop succeeded while brokered calls failed.
  • Fix applied ~17:27 CST: killed both brokers; a single broker (pid 19044) respawned; round-trip verified in 0.9s.

Episode 2 — single broker, silently wedged pool (from ~17:36 CST; fleet blind from ~17:48 CST)

  • The broker that held the socket from 23:36:01Z (pid 25276, Python) was the sole listener (verified via ss -xlpn: one listener, fd 3; broker.pid matched) — this is not the duplicate condition.
  • It was nonetheless dead in place: 2 threads, zero outbound TCP tunnels (a healthy broker holds a keep-alive pool), and broker.log received no writes after its start (log mtime 23:36:02Z) — a ≥20-minute total silence during the wedge.
  • Clients hung, not errored: laptop-agent.py health blocked inside tunnel_socket() at sock.recv(1) for the full client timeout (live repro 17:57 CST: 25.0s, CallTimeout). Observed failures: the 17:48 CST activity-refresh probe ("laptop-agent: proxy closed during CONNECT"), a direct probe at 17:54 CST (25.4s), and the 17:57 CST repro. A fleet worker's own note from the window reads "tunnel down since ~23:37Z", corroborating onset within a minute of this broker's start.
  • The log also contains an earlier uncaught BlockingIOError: [Errno 11] Resource temporarily unavailable traceback in the broker's read_msg (laptop-agent-broker.py lines 216/238) — a plausible handler-thread-killing mechanism for the silent wedge.
  • The fleet queue was already in GitHub-comments fallback mode by 23:56Z ("queue backend is down"), i.e. the blind spot propagated beyond quota/supervision.

Remediation attempt — restart does not restore service (17:58 CST → 19:46 CST)

  • 23:58Z: killed pid 25276; a fresh Python broker (pid 40681) auto-respawned and failed identically (24.8s, "proxy closed during CONNECT"). A broker-bypass direct CONNECT health call also failed (8.4s) — by then the refusal had moved to / was also present in the shared CONNECT leg.
  • The sandbox VM recycled ~00:05–00:15Z. Post-recycle, a Python broker (pid 2704, 01:11:49Z) briefly owned the socket, after which fleet proxy serve (pid 7861, started 01:18:01Z) took over the same socket path — and broker.pid did not match the actual socket owner.
  • The fleet proxy fails fast and explicitly (better posture): HTTP 502: broker: tunnel recovery for port 4799 still in flight; failing fast, then HTTP 502: broker: tunnel to 100.99.113.103:4799: Resource temporarily unavailable (os error 11) — but its tunnel recovery cannot complete.
  • Raw CONNECT probe at 01:43Z (bypassing all broker code): the session proxy hung ≥15s with no response to CONNECT 100.99.113.103:4799 and closed instantly with an empty response to CONNECT 100.99.113.103:22, while general HTTPS egress through the same proxy answered GitHub in 1.4s. So at the tail of episode 2 the proxy↔DERP↔laptop leg itself refuses/hangs CONNECTs to the laptop on both ports.
  • As of 19:46 CST (01:46Z) laptop-agent.py health still fails; the documented sandbox-side restart has been applied (wedged broker killed; successors respawned) but service is not restored, because the current blocker is upstream of any broker process.

Layer evidence summary

  • Sandbox egress: healthy (GitHub via the same proxy, 1.4s).
  • Laptop: healthy during episode 1 diagnosis (broker-bypass health call succeeded); unreachable by any sandbox path during episode 2's tail (both ports, raw CONNECT).
  • Broker layer: at fault in episode 1 (duplicates) and at onset of episode 2 (silent single-broker wedge); not the current blocker at the tail of episode 2.

Acceptance

  1. Singleton across implementations. Exactly one process may own broker.sock, whether the Python broker or fleet proxy serve provides it. Concurrent ensure/start invocations from both implementations converge on one owner (no Errno 98 churn, no silent takeover); broker.pid always names the socket owner (checkable against ss). Backed by a regression test or a documented invariant. (Two auto-started implementations racing for one socket path is the root architectural smell — pick one owner for the path, or partition the paths.)
  2. Wedged-pool self-detection. A broker whose tunnel pool is empty/dead and cannot complete a CONNECT within a bounded time must log loudly, rebuild the pool or respawn, and fail clients fast (<5s) with an explicit error — never accept a client connection and hang it for 25s+ in silence. The Python broker logged nothing for the entire episode-2 wedge; fleet proxy's fail-fast 502s are the behavioral floor.
  3. Handler robustness. Uncaught BlockingIOError in the request path (read_msg) must not silently kill request handling.
  4. Log observability. Every broker log line carries a timestamp (Python broker lines currently have none), and tunnel death/recovery events are logged as they happen, so the next episode is diagnosable from the log alone.

Fleet impact

Quota refresh and summit supervision were blind from ~17:48 CST until at least 19:46 CST (episode 2), on top of the episode-1 window earlier in the afternoon. Restart-alone is proven insufficient as the runbook fix: it cured episode 1 and did nothing for episode 2.

Activity

  1. dezren39 commented on Nov 14, 2026

    @dezren39
    MemberAuthor

    Downtime-investigation update (2026-11-14, Drew's order "fix why website keep go down"):

    Current state verified live 2026-11-14 ~08:55Z: exactly ONE broker owns ~/.cache/laptop-agent/broker.sock - the Python broker, pid 1804; broker.pid = 1804 matches the socket owner in ss; no fleet-proxy process running; laptop-agent health round-trip 0.49s. The defect is latent right now, not active.

    Still unmet, from the live tree/log:

    • Acceptance 1 (singleton across implementations): nothing enforces it - episode 1's race can recur any time both implementations' ensure paths fire.
    • Acceptance 3 (handler robustness): the uncaught BlockingIOError traceback in read_msg (laptop-agent-broker.py lines 216/238) is still present in broker.log.
    • Acceptance 4: Python broker log lines still carry no timestamps.

    This fix was also not in the fleet queue: no task referenced this issue (checked the queue DB by dedupe_key, title, and body on 2026-11-14). It is now queued: task 16540 (queue code-pilot, priority 20, dedupe fix-9611-broker-singleton-failfast) with the four acceptance criteria as its brief. Label queue/queued added.

  2. dezren39 commented on Nov 14, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · partial fix landed (code), remainder parked

    What this claim changed (file: ~/tools/laptop-agent-broker.py, sandbox tools)

    Verified: python3 -m py_compile passes; the currently running broker still serves normally (it runs its already-loaded copy — no restart was performed, so the fleet's laptop path was never put at risk by this change).

    • Acceptance 3 (handler robustness) — FIXED. Handler.handle now wraps read_msg(...) in except (BlockingIOError, OSError): return. The uncaught traceback in the log came from the inflight watchdog toggling setblocking() on the client socket while the handler was receiving; a racing recv raised BlockingIOError straight out of the handler. It now ends the handler quietly.
    • Acceptance 4 (log observability) — FIXED for the Python broker. A log() helper prefixes every line with a UTC timestamp. Wired into: the startup line (now … laptop-agent broker: on <sock> pid=<pid>), every failed request attempt in do_request (tunnel death, as it happens, with "connection dropped, not repooled"), and keepalive health transitions (failure logged once with the error, recovery logged on the next success — previously keepalive failures were swallowed by except: pass, which is why episode 2's wedge logged nothing).
    • Acceptance 1 (singleton) — PYTHON LEG FIXED. main() now takes an exclusive non-blocking flock on ~/.cache/laptop-agent/broker.lock before touching the socket and holds it for the process lifetime; a second Python start exits quietly instead of racing the probe-and-unlink path that produced the Errno 98 churn. The flock auto-releases on holder death, so a crashed broker cannot wedge the path. Also, broker.pid is now written only after the server socket is bound, so it names the actual owner.

    What remains (task 16540 parked for this)

    1. Acceptance 1, fleet-proxy leg: the Rust fleet proxy serve does not take broker.lock. Either it must honor the same lock file before binding broker.sock, or the two implementations' socket paths must be partitioned. That is a pkgs/fleet change plus a coordinated rollout — not safely done from a queue claim on the live path.
    2. Acceptance 2 (wedged-pool self-detection / fail-fast <5s): not implemented. The new keepalive logging makes a wedge visible in the log within one keepalive interval, but the broker still does not rebuild/respawn its pool or fail clients fast on its own. (Today's shift hit this live: repeated multi-minute broker-tunnel 502s with exactly the silent-wedge signature.)
    3. Activation + verification: the edits above activate on the next broker start. Whoever restarts the broker should verify, in order: startup line carries a timestamp; broker.pid matches ss -xlpn's socket owner; a second laptop-agent-broker.py start exits quietly while the first holds the lock; no BlockingIOError traceback appears in broker.log under load.
  3. dezren39 commented on Nov 14, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · parked — remainder is coordinated infra work, not a lane slice

    • Agent: queue worker (repo-worker-code), lane code-b
    • Session / ID: task 16540 (fix for defect: laptop-agent broker — no singleton across two implementations + silent CONNECT-pool wedge (two fleet-blind episodes, 2026-11-13) #9611, laptop-agent broker singleton + wedged-pool fail-fast)
    • Preserved state (from task 16540's prior claim, lane any-d, 12:48Z): acceptance items 3 and 4 and the Python leg of item 1 are fixed in ~/tools/laptop-agent-broker.py (py_compile verified), deliberately not activated — the running broker still serves its already-loaded copy and no restart was performed mid-shift.
    • Remainder, in order: (1) the fleet-proxy leg of the singleton guarantee (pkgs/fleet ensure path must share the same socket-ownership discipline); (2) acceptance 2, wedged-pool fail-fast; (3) activation + verification at the next broker restart — a coordinated action, since restarting the broker drops every lane's tunnel mid-flight (this shift alone hit repeated 502s from tunnel churn; an uncoordinated restart multiplies that).
    • Why park: the remaining items are one coherent infra change-set whose final step is a fleet-wide activation event. Slicing the pkgs/fleet leg in a 40-minute lane window, hours before the activation can even be verified, risks a second unreviewed implementation drifting from the parked Python half. Parked 3600s with this state; a dedicated infra session or the next coordinated broker restart should take it whole.
    • Links: queue task 16540; prior partial-fix note (12:48Z) on this issue
  4. added
    queue/parkedQueue task is parked (waiting on CI, time, or an event)
    status/parkedDeliberately paused with a recorded resume condition
    and removed on Nov 14, 2026
  5. dezren39 commented on Nov 14, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · all four acceptance legs addressed (task 16540)

    • Agent: repo queue worker (repo-worker-code), Muse lane code-d
    • Session / ID: task 16540
    • Acceptance 1 — singleton across implementations. Python leg was already in ~/tools/laptop-agent-broker.py (flock on broker.lock, broker.pid written only by the socket owner) and is live. The missing fleet-proxy leg is PR fix(fleet-proxy): broker singleton lock + broker.pid ownership (#9611) #10056: fleet proxy serve now takes the same broker.lock flock before probe/bind (converges with a log line + exit 0 when another implementation holds it) and writes broker.pid after binding, so the pid file names the owner whichever implementation it is. New unit test covers flock exclusivity; cargo test -p fleet-proxy --lib 90/90 pass.
    • Acceptance 2 — wedged-pool fail-fast (Python broker, live this shift). The broker no longer uses the client library's tunnel path (60 s CONNECT wait + sys.exit inside broker threads — a BaseException that bypassed every guard, the episode-2 wedge shape). New broker_tunnel_socket: broker-local CONNECT with a hard 5 s cap (LAPTOP_AGENT_TUNNEL_TIMEOUT), ordinary OSErrors, credential only inside the CONNECT request as before. Connection acquisition moved inside do_request's try, and a retry now happens only for a stale pooled connection — a fresh-tunnel failure fails the client immediately with a logged 502. Isolated test (dead proxy): 502 in 0.0 s, one attempt, timestamped log. The Rust broker already failed fast (its 502 posture is documented on this issue).
    • Acceptance 3 — handler robustness. The prior BlockingIOError guard stands; acquisition-in-try removes the remaining uncaught-failure path out of do_request.
    • Acceptance 4 — log observability. Live: every broker log line is timestamped and tunnel failures/recoveries log as they happen (visible in ~/.cache/laptop-agent/broker.log throughout today, including this shift's 14:09Z and 14:27Z tunnel drops).
    • Coordinated restart verification (live, 2026-11-14T14:32Z): broker restarted onto the final code — sole socket owner pid 497014, broker.pid == 497014 (checked against ss -xlpn), client round-trip 0.46 s, fleet queue health flowing through it. A duplicate-start test in an isolated HOME exits 0 quietly (singleton convergence).
    • What remains for this issue to close: merge + deploy of PR fix(fleet-proxy): broker singleton lock + broker.pid ownership (#9611) #10056 (the fleet binary release path) so the Rust leg is live, not just implemented. Everything sandbox-side is done and verified; the issue stays open until the deployed binary carries the lock.
    • Links: task 16540 · issue defect: laptop-agent broker — no singleton across two implementations + silent CONNECT-pool wedge (two fleet-blind episodes, 2026-11-13) #9611 · PR fix(fleet-proxy): broker singleton lock + broker.pid ownership (#9611) #10056
  6. removed
    status/parkedDeliberately paused with a recorded resume condition
    queue/parkedQueue task is parked (waiting on CI, time, or an event)
    on Nov 14, 2026
  7. added a commit that references this issue on Nov 15, 2026
  8. dezren39 commented on Nov 15, 2026

    @dezren39
    MemberAuthor

    Acceptance follow-through (read-only): #10056 merged as 32dc1f922a0c31e4b84177298c4dc2647fb624bf. The existing acceptance note verifies the Python leg live and explicitly leaves Rust release/activation outstanding. A healthy transport probe cannot identify the socket owner or prove which Rust build is available to start. During the existing coordinated release, please attach the installed Fleet build/source receipt containing this commit and the isolated Python↔Rust shared-lock/PID-ownership result; no live duplicate start, restart, or reopening requested here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/infrastructureInfrastructure / host-portability workpriority/highImportant and time-sensitive

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions