Skip to content

Disable undici header/body timeouts on the review watch long-poll - #149

Open
cathrynlavery wants to merge 1 commit into
Lex-Inc:mainfrom
cathrynlavery:fix/watch-headers-timeout-main
Open

cathrynlavery wants to merge 1 commit into
Lex-Inc:mainfrom
cathrynlavery:fix/watch-headers-timeout-main

Conversation

@cathrynlavery

Copy link
Copy Markdown

Problem

roughdraft open waits on POST /api/review-events/watch, a long-poll that holds response headers open until the reviewer clicks Done Reviewing. undici's default headersTimeout (~300s) kills any review session longer than five minutes with UND_ERR_HEADERS_TIMEOUT, so long reviews always crash the waiting CLI. We've hit this repeatedly across several machines over the past month.

Fix

  • New getReviewWatchDispatcher() in packages/server/src/network.ts: a lazily-created shared undici.Agent({ headersTimeout: 0, bodyTimeout: 0 }).
  • Passed as dispatcher only on the watch fetches in cli.ts (runWatch) and mcp.ts — no global timeout changes; an explicit --timeout still aborts via the existing AbortSignal.
  • undici added as an explicit dependency; regression test included (watch with an injected 500ms headers timeout).
  • Also fixes placeholder allowBuilds values in pnpm-workspace.yaml that broke pnpm install on pnpm 11.8.

Verification

  • Full server suite: 121/121 passing, including the new regression test.
  • Live test of the built CLI: a watch session survived 405s of continuous waiting (unpatched code dies at ~301s), server responding 200 throughout.

The Done Reviewing long-poll holds response headers open until the
user finishes, so undici's default ~300s headersTimeout killed any
roughdraft open wait past five minutes with UND_ERR_HEADERS_TIMEOUT.
Route only the watch fetches in the CLI and MCP server through a
shared undici Agent with headersTimeout and bodyTimeout disabled;
explicit --timeout still aborts via the existing AbortSignal. Adds a
regression test and pins undici; also fixes pnpm-workspace.yaml
placeholder allowBuilds values that broke pnpm install.

Mirrors commit 24fc791 from roadmap/watch-headers-timeout, which was
never merged.
@vercel

vercel Bot commented Sep 1, 2026

Copy link
Copy Markdown

@cathrynlavery is attempting to deploy a commit to the Lex Team on Vercel.

A member of the Team first needs to authorize it.

jmatthewpryor added a commit to jmatthewpryor/roughdraft that referenced this pull request Sep 11, 2026
… bump to 0.1.11-patched.2

Adapts Lex-Inc#149 to a per-watch undici Agent instead of a process-wide
singleton: the singleton kept a pooled keep-alive socket to a server that
had since restarted, so the next watch in the same process failed with
UND_ERR_SOCKET "other side closed". The Agent is now created per watch in
both the CLI and the MCP watch tool and closed in a finally.

Fixes a pre-existing race in two CLI tests that posted the review event as
soon as the watch request had been sent, before the server had registered
the waiter; they now poll /api/review-events/status for a watcher first.

Documents the new patches, the Lex-Inc#149 adaptation, the merge-conflict notes,
and the new "handoff after watcher lost" state in the screenshot guide.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant