← Back to Pull requests

fix(cli): --wait-for-idle longer than 300 s works, as one request over node:http #2020

Closed
unknown closed this pull request without merging on Oct 25, 2026 18:35 UTC
View on GitHub
unknown unknown commented on Oct 25, 2026 12:44 UTC
Author

What a person gets

rig send <seat> --wait-for-idle <seconds> works for any wait. Until now, a wait longer than 300 s failed at about 300 s as
"Cannot connect to the OpenRig daemon … fetch failed (UND_ERR_HEADERS_TIMEOUT)", which reads as a daemon problem, and the text
wasn't sent. A long wait now behaves exactly like a short one, just longer: one wait, one deadline, and the daemon's own answer.

The cause

A waiting send's response starts only when its wait ends. Node's fetch (undici) gives up on a response whose headers haven't
arrived within 300 s. The daemon isn't what cuts the request. In a Linux container on Node 22:

  • fetch against a server holding the response 320 s failed at 300.8 s with UND_ERR_HEADERS_TIMEOUT. That held for both a plain

  • Node server and @hono/node-server, which the daemon uses.
  • node:http, which has no headers timeout, got the 200 at 320.0 s from the same @hono/node-server.
  • 0.7.0, 0.7.1 and main share this path byte for byte.

    The change

  • packages/cli/src/long-request-fetch.ts: a small fetch over node:http or https, for the subset the daemon client uses:

  • method, headers, a string body and a signal.
    - It returns the response when its headers arrive, as fetch does, with the body read afterwards. So a connection lost after
    the daemon answered is the daemon client's existing "unreadable response (HTTP 200)" error, as on fetch, never "The message was
    not sent."
    - The request's own deadline stays a timeout, reached before or after the headers. Node's response stream, cut by our deadline
    while a body is being read, ends with a plain "aborted" error. Once the request is aborted, fetchWithTimeout lets the abort's
    reason decide. A body reset with no abort stays an unreadable response.
    - Any other body is refused, rather than sent empty.
    - It uses no global agent or proxy: agent: false. A long request to an --host reached only through a proxy that Node was
    told to use would go direct.
  • DaemonClient sends a request allowed 300 s or more (FETCH_HEADERS_TIMEOUT_MS) through it. Everything around the request is

  • unchanged: the seat header, the timeout and its message, caller aborts, connection-error codes and JSON handling. Shorter requests
    still use fetch.
    - Long --wait-for-idle sends: the local send, the http-host send (--host) and MCP rig_send all go through DaemonClient.
    - rig seat set-runtime: a runtime switch is allowed 300 s by default, and up to 3720 s with --confirm-timeout, so it uses
    this path too. Its timeout still reads as outcome unknown.
  • One request: the wait stays one request, so the daemon keeps what one wait guarantees:

  • - one deadline: nothing is sent after the time the person allowed;
    - one binding to the seat's occupant: if the seat is replaced during the wait, the send is refused with guard_target_changed
    and nothing is typed.

    This PR's first version split a long wait into consecutive requests. That lost both guarantees, as review showed: a new request
    could start after the whole wait had ended, and a replacement occupant could receive the text. That version is gone.

  • The tests' request guard (test/fetch-guard.ts) now covers http.request and https.request with the same rule it applies to

  • fetch, so a test still can't reach a real daemon or another machine through the new path.

    No dependency, setting, route or daemon change.

    Proof

    All runs are in a Linux container: Node 22, tmux 3.3a, as root, with --maxWorkers=2.

    A real wait at round 1's 9dc3323f:

  • The setup: the publishable CLI, a real daemon, and a disposable terminal seat running sleep 450.

  • --wait-for-idle 400 exited after 400 s with the daemon's own answer: "Target was still busy (foreground_command) when the

  • 400000ms wait ended (787 observations). No text was sent."
  • That's one request past 300 s. The pane shows only sleep 450.

  • main's CLI, in the same setup, failed at 301 s with UND_ERR_HEADERS_TIMEOUT.

  • Round 2 changes only how the body is read after the headers arrive. Its tests below run real sockets through the long path.
  • Unit tests:

  • Round 1, at the tests-only commit c4eb045a, these fail:

  • - the one-request tests for the local send, the http-host send and MCP rig_send;
    - the guard case;
    - the new long-request-fetch file, which can't load its module yet.
  • Round 2, at the tests-only commit f875af24, these fail:

  • - a body cut off after the headers reads as connection lost on the long path, where fetch gives DaemonResponseError(200);
    - a send over that path says "The message was not sent." after a delivery;
    - a non-string body is sent empty.
  • Round 3, at the tests-only commit 2ab11a17: the body-stall test fails. On the long path, a deadline reached after the

  • headers read as an unreadable response, not a timeout.
  • At 60cd1d03:

  • - the build passes;
    - the 9 focused files pass 273 of 273: send, mcp-server, cross-host-http, long-request-fetch, fetch-guard, client,
    client-headers, client-body-timeout and fetch-with-timeout;
    - the whole CLI suite passes 5686, with 19 skipped and 2 failing;
    - test:repo passes 324 of 324.
  • The 2 failures are preflight "OpenRig home not writable" and scope-commands "current unreadable". They also fail on main in

  • this container, because root ignores the permission bits these tests depend on.

    A terminal seat reports "running" or "unknown", never idle, so a send that lands after a long wait isn't shown end to end. The
    daemon decides that the same way for any wait length.

    🤖 Generated with Claude Code

    <!-- This is an auto-generated comment: release notes by coderabbit.ai -->

    <!-- coderabbit-ai-generated:v1 -->

    Summary by CodeRabbit

    Bug Fixes
    The CLI now handles send requests with wait times longer than five minutes without prematurely timing out while waiting for a response.
    Long waits are sent in a single request, and daemon timeout errors are reported accurately.
    Interrupted responses and aborted requests are handled more reliably, avoiding misleading messages that a message was not sent.

    <!-- end of auto-generated comment: release notes by coderabbit.ai -->

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: openrig-review Review duration: 351m
    All Vouch review confidence checks passed
    Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 650 lines diff across 8 files
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #2020"
    general weight: 0.35
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52% (MEDIUM) · Higher = larger blast radius
    52%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 20.5% · Safe to merge
    20.5%