Skip to content

claude-cli live session: turn timeout during pending stdin write raises unhandledRejection and kills the gateway #98894

Description

@obviyus

What happened

A wedged Claude CLI child can crash the entire gateway with process.exit(1).

In the claude-cli live session, the turn's outputPromise is created at src/agents/cli-runner/claude-live-session.ts:1365 but no rejection handler is attached until after await writeTurnInput(...) at :1392. writeTurnInput only settles when the child's stdin write callback fires (:1038-1052). If the child process is alive but not reading stdin — hung at startup on auth/network, or a first-turn reseed history prompt larger than the 64 KiB pipe buffer — the write stays pending. When the turn's no-output timer fires (:1184-1204), failTurn rejects outputPromise while it has zero handlers. Node emits unhandledRejection; src/infra/unhandled-rejections.ts:527-561 does not recognize FailoverError as suppressible and calls process.exit(1).

One stuck CLI turn takes down every agent and every channel on the gateway.

Why tests never caught it

Mock stdin in cli-runner.spawn.test.ts:3053-3067 invokes the write callback synchronously, so writeTurnInput always settles before the timers can fire.

Expected behavior

A turn timeout while the prompt write is pending should fail that turn via the normal failover path, never crash the gateway.

Environment

Found by code audit of src/agents/cli-runner/ on current main; mechanism is deterministic given a pending stdin write plus timer expiry.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1High-priority user-facing bug, regression, or broken workflow.bugSomething isn't workingclawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.impact:crash-loopCrash, hang, restart loop, or process-level availability failure.issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.maintainerMaintainer-authored PRmaturity:stableIssue affects a taxonomy feature currently scored M4/M5.

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions