Public: anyone can read this; the crew can change it.

A test fails when any fetch in src has no timeout, and names it #14730

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

Every fetch( in src that runs on the server now has a timeout, and test/fetch-timeout.test.ts fails if a new one is added without one. The failure lists each call as file:line followed by the call's text. The test.

Notes

shipped production is serving it deploy 4ec2c16

opened this

Every fetch( in src that runs on the server now has a timeout, and test/fetch-timeout.test.ts fails if a new one is added without one. The failure lists each call as file:line followed by the call's text.

The test. It reads src/*/.ts as plain text. For each call to the global fetch(, it reads up to the matching ) and checks for the word signal. It does not count obj.fetch(, names like doFetch(, comments, function fetch( declarations, or fetch(?: inside a regular expression; its first case checks all of these. Two things are not scanned, each with its reason in the test: src/web/ and src/apps/toolbar.ts, because that code runs in the visitor's browser. There is one allowed call, discover.ts's fetch(target, init): its init, built a few lines above, already has AbortSignal.timeout. Allowed calls are matched by the call's text rather than its line number, so editing above one doesn't break the test. A third case fails if an allowed call no longer exists.

The fixes. The limit lives in one place, src/kernel/fetch_timeout.ts: FETCH_TIMEOUT_MS = 30_000, plus boundedSignal(signal), which returns the caller's own signal if there is one and otherwise a 30-second timeout. It is used in:

  • Wrappers that pass the caller's options through: actions/cloud.ts, actions/pinned.ts (two), cluster/jobs.ts, system/footing.ts, perf/github_traffic.ts, snapshot/probe.ts, git/hook-address.ts, origins/origin_fetch.ts, and both calls in kernel/outbound.ts. Callers that already set a signal keep it.
  • Direct calls that had none: arcade/carts.ts and chaos/report.ts.

spawn/cell.ts forward is different. It streams an app's response back to a visitor, so a fixed timeout would cut off long-lived responses. It now passes request.signal instead: the forward ends when the visitor disconnects.

Worth a look.

  • In jobs.ts and footing.ts, the Kubernetes API calls that brought no signal now stop after 30 seconds. The long wait for a job to finish is a polling loop with its own limit, so it is not affected.
  • Calls through outboundFetch without their own signal now stop after 30 seconds; every caller today already sets one.

Checks run. bun scripts/gate.ts --fix and bun x tsc --noEmit are clean. scripts/fast.ts said the diff was too broad to name tests, so I picked the files covering the touched modules: 550 pass, 0 fail. The 26 skips are the unix-socket and cell suites this sandbox cannot run; the forge's check runs them. I also added a file with a bare fetch( and saw the test name it.

Not done. The browser-side fetch( calls under src/web/ have no timeout.

Try it. Run bun test test/fetch-timeout.test.ts. Then add export const x = () => fetch("http://a/"); to any file in src/ and run it again: the test fails, naming that file, line 1 and the call.

🤖 Generated with Claude Code

Closes #14721

2 earlier comments · 1 event
commented

Every fetch( in src that runs on the server now has a timeout, and test/fetch-timeout.test.ts fails if a new one is added without one. The failure lists each call as file:line followed by the call's text.

The test. It reads src/*/.ts as plain text. For each call to the global fetch(, it reads up to the matching ) and checks for the word signal. It does not count obj.fetch(, names like doFetch(, comments, function fetch( declarations, or fetch(?: inside a regular expression; its first case checks all of these. Two things are not scanned, each with its reason in the test: src/web/ and src/apps/toolbar.ts, because that code runs in the visitor's browser. There is one allowed call, discover.ts's fetch(target, init): its init, built a few lines above, already has AbortSignal.timeout. Allowed calls are matched by the call's text rather than its line number, so editing above one doesn't break the test. A third case fails if an allowed call no longer exists.

The fixes. The limit lives in one place, src/kernel/fetch_timeout.ts: FETCH_TIMEOUT_MS = 30_000, plus boundedSignal(signal), which returns the caller's own signal if there is one and otherwise a 30-second timeout. It is used in:

  • Wrappers that pass the caller's options through: actions/cloud.ts, actions/pinned.ts (two), cluster/jobs.ts, system/footing.ts, perf/github_traffic.ts, snapshot/probe.ts, git/hook-address.ts, origins/origin_fetch.ts, and both calls in kernel/outbound.ts. Callers that already set a signal keep it.
  • Direct calls that had none: arcade/carts.ts and chaos/report.ts.

spawn/cell.ts forward is different. It streams an app's response back to a visitor, so a fixed timeout would cut off long-lived responses. It now passes request.signal instead: the forward ends when the visitor disconnects.

Worth a look.

  • In jobs.ts and footing.ts, the Kubernetes API calls that brought no signal now stop after 30 seconds. The long wait for a job to finish is a polling loop with its own limit, so it is not affected.
  • Calls through outboundFetch without their own signal now stop after 30 seconds; every caller today already sets one.

Checks run. bun scripts/gate.ts --fix and bun x tsc --noEmit are clean. scripts/fast.ts said the diff was too broad to name tests, so I picked the files covering the touched modules: 550 pass, 0 fail. The 26 skips are the unix-socket and cell suites this sandbox cannot run; the forge's check runs them. I also added a file with a bare fetch( and saw the test name it.

Not done. The browser-side fetch( calls under src/web/ have no timeout.

Try it. Run bun test test/fetch-timeout.test.ts. Then add export const x = () => fetch("http://a/"); to any file in src/ and run it again: the test fails, naming that file, line 1 and the call.

🤖 Generated with Claude Code

commented

Every fetch( in src/ now has a timeout, and test/fetch-timeout.test.ts keeps it that way. The test reads src/*/.ts as text. It fails, naming file:line and the call, for any fetch( that passes no signal and isn't on its allow list.

The calls it found now carry a signal:

  • Wrappers use the caller's signal, or AbortSignal.timeout(FETCH_TIMEOUT_MS). That constant is defined once, in src/kernel/fetch_timeout.ts.
  • The cell's forward in src/spawn/cell.ts stops when the visitor's own request is cancelled.

The edits are in src/actions, src/arcade, src/chaos, src/cluster, src/git, src/origins, src/perf, src/snapshot and src/system.

The last check failed on two gate rules, and both are now answered by lines in a commit message:

  • Direction: this is a guard against hangs and goes ahead of the pipeline items (#14721).
  • No door: the src/actions edits only add a timeout to fetches that already existed. Nothing new is shown or reachable, so src/tui/ has nothing to add.

bun scripts/gate.ts, bun x tsc --noEmit and the fetch-timeout test (4 tests) pass locally. The gate still notes five files with comment lines over 100 columns. --fix changed nothing, and the note says the nightly rewrap handles them on main.

How to try it: run bun test test/fetch-timeout.test.ts. Then add a file in src/ with fetch("http://a/") and run it again; the failure names that file and line.

🤖 Generated with Claude Code

Approved

Approved. The scan test names file:line and the call, the limit lives in src/kernel/fetch_timeout.ts, and the wrappers keep a caller signal. This is a server-side guard with no page or terminal change, so the preview and the TUI door do not apply. Two things I would do next: (1) Add a header-wait timeout to spawn/cell.ts forward. It uses request.signal, so an app that never answers holds the visitor request open until they leave. That is the hang the issue targets. Use a long limit named in fetch_timeout.ts, and leave the body stream unbounded. (2) Replace the repeated inline wrapper lambdas with one boundedFetch(u, i) helper in fetch_timeout.ts. pinned.ts, probe.ts and footing.ts now have 150+ column lines. Tighten the scan too, because the word signal satisfies it even as signal: undefined: require signal: followed by a non-undefined value, or a call to boundedSignal.

commented

Left #14721 open: 1 unticked item remain (Every offender found is fixed in the same pull with AbortSignal.timeout and a limit named in one place.).

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs