Skip to content

[Hackathon] fix(poll): a 7-second network blip ends any --wait with exit 10, and a silently dropped connection stalls it for 300s #437

Closed

Description

@Andy00L

Verified against (commit SHA or released version)

commit 988c035 (v0.14.0)

Discord Username / User ID

interferon0

What does this improvement do?

A network outage of about 7 seconds ends a --wait early, however much of --timeout is left. The run keeps executing and billing server-side, but the CLI exits 10 and the agent or CI job loses the verdict.

Every wait path goes through pollRunUntilTerminal in src/lib/poll.ts (test run, test rerun, test wait, test create --run, test create-batch --run, testlist run, test flaky, owned tunnels). When a poll read fails at the network level, http.ts spends its 4-attempt transport burst (about 2.5s), the poll loop absorbs one more failure, and the next one is thrown (poll.ts, the INTERNAL/UNAVAILABLE branch: if (consecutiveErrors >= 2) throw err).

Measured with a mock facade that answers GET /runs/run_1 with running, goes down 3 seconds into test wait run_1 --timeout 120, and comes back with passed:

outage exit result
3s 0 verdict printed
5s 0 verdict printed
7s 10 Error: fetch failed, 110s of --timeout unused
10s 10 same

Common triggers are a Wi-Fi roam, a VPN reconnect, a laptop lid closed for a minute, EAI_AGAIN DNS hiccups on CI runners, and a facade deploy window answering 502/503.

Two things make it worse:

  1. test run <id> --wait --output json prints nothing on stdout on this path. The stderr envelope carries no runId, and its nextAction says "if this persists, report it". The rate-limit, request-timeout, deadline and Ctrl-C paths all print {runId, status} plus a test wait re-attach hint; the transport path is the one sibling that does not. An agent that only parses JSON has lost a charged, running run and usually re-triggers it.
  2. With an owned tunnel (a loopback environment or --local), the poll failure also cancels the run.

test plan generate has the same gap. src/lib/plan-poll.ts throws on the first failed plans read, so a blip during a 30-minute exploration stage ends the command.

A connection that dies without an error is worse. After a Wi-Fi switch, a VPN reconnect or a laptop sleep, the open long-poll socket often gets no RST at all. The waitSeconds=25 read then waits for undici's default 300-second headers timeout, because the wait client raises its own per-request timeout to cover --timeout. With a mock that accepts the third read and never answers, test wait on main sits silent for 300 seconds, even if the run finished in the meantime.

Details / implementation notes

Proposed fix, in the two shared loops only (no per-command changes):

  • Once the endpoint is proven, a TransportError or 503 UNAVAILABLE counts as an outage. A command that just triggered the run has proven it; test wait proves it with its first successful read. The loop re-reads after 2s, 4s, 8s, then every 15s (the existing fallback schedule, with jitter), or after a 503's Retry-After, until the --timeout deadline.
  • An outage that outlasts the deadline ends as the existing TimeoutError (exit 7). Every caller already renders that with the runId and the test wait re-attach hint, which also fixes point 1 for this case.
  • For test wait, nothing changes before the first successful read, so a mistyped --endpoint-url still fails fast with exit 10.
  • INTERNAL (500), RATE_LIMITED, NOT_FOUND and the other answers keep their current handling.
  • On a proven endpoint, each read gets a stall budget: its long-poll window plus 20 seconds (45 seconds for the 25-second window). A read still silent at that point is aborted and handled as an outage, so the next read opens a fresh connection. A Retry-After wait inside the read restarts the budget, so it is not mistaken for silence.
  • --verbose prints each retry and the reconnection through the existing onTransition channel.

This follows the precedent in test wait's multi-run path, which already re-polls a shared-egress 429 because it "is a property of the window, not of this run, and the run is still executing".

Tests: unit tests for both loops (outage then verdict, 503 envelope and Retry-After, outage on the first read after a trigger, backoff restart, fail-fast on first contact, a Retry-After longer than the budget, deadline cap, INTERNAL unchanged, Ctrl-C during the backoff, a read that never answers), plus a runTestWait test that drives the real HttpClient through two transport-retry bursts with fake timers.

Confirmations

  • I have searched existing issues and this is not a duplicate.
  • I have provided my Discord identity above for reward coordination.

Activity

  1. added
    needs-triage
    hackathon
    on Oct 16, 2026
  2. zeshi-du commented on Oct 20, 2026

    @zeshi-du
    Contributor

    Thanks @Andy00L, accepted. Confirmed on v0.15.0: the transport retry burst in http.ts plus one extra absorbed failure in poll.ts ends a healthy wait after roughly 5-6 seconds of outage.

    Please send two PRs, in this order:

    1. Retry until the deadline. Once the endpoint has answered, keep re-reading with backoff (2/4/8s, then 15s, jitter, honouring Retry-After) until --timeout; keep fail-fast on first contact. Unlike your proposal, if the deadline passes while the last error is still network/503, exit 10 (UNAVAILABLE), not 7, and stdout (including --output json) must still carry {runId, status} and the test wait re-attach hint.
    2. A per-read stall timeout on the long-poll, so a silently dead socket is aborted and reconnected instead of waiting ~300s.

    Constraints: leave plan-poll.ts alone, change no other exit codes, JSON additive only, never retry 429/500 faster than http.ts, Ctrl-C still wins. Add fake-timer tests, one failing on current main. Comment /assign to claim it.

  3. added
    accepted
    and removed
    needs-triage
    on Oct 20, 2026
  4. Andy00L commented on Oct 20, 2026

    @Andy00L
    ContributorAuthor

    /assign

  5. added
    in-progress
    on Oct 20, 2026
  6. testsprite-hob commented on Oct 20, 2026

    @testsprite-hob

    Assigned to @Andy00L. Thanks for taking this on. (2 more slots available.)

    Your open assigned issues (1/3):
    (none)

  7. 3 remaining items

  8. added a commit that references this issue on Nov 11, 2026
    c1b20f6
  9. added a commit that references this issue on Nov 11, 2026
    1d95e70
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

acceptedhackathonin-progress

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions