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

git-upload-pack for a runner job no longer holds the serving thread #17839

opened this

Merged 4h 20m ago, live in production

A runner's fetch through /api/v1/runner/jobs/:id/git/git-upload-pack no longer blocks the serving thread while the forge checks what the runner is asking for (#17821). What blocked, before.

Notes

opened this

A runner's fetch through /api/v1/runner/jobs/:id/git/git-upload-pack no longer blocks the serving thread while the forge checks what the runner is asking for (#17821).

What blocked, before. I couldn't read the production [loop] log from the sandbox, so I measured the worst case locally: the largest negotiation a fetch may send (1 MiB gzipped, 16 MiB inflated, about 330k packets). Git itself already ran async and streamed its output. What blocked the thread was the work done before git gets the request:

  • negotiation() in src/git/smart-http.ts inflated the body with one gunzipSync.
  • heldNegotiation().push in src/git/own_refs.ts then read every packet in one unbroken pass. That pass also ran a flatMap over all packets to collect ids and a filter plus copy to build the output.

Result: 860–970 ms of blocked loop per fetch.

After.

  • The body is inflated with async gunzip on zlib's worker, still capped at FETCH_MAX.
  • The packet read and the output build run in SLICE_MS slices, using the existing sliced() from src/kernel/breathe.ts. Ids are collected as packets are read.
  • A first piece with nothing carried over is read where it lies, without copying.

The same bytes go to git, and the job-token check still runs before any spawn. Longest block is now 25–50 ms.

Test. test/runner-fetch-loop.test.ts sends that largest negotiation through serviceRpc with onlyWants. It checks git answers with a pack and that the loop is never blocked for 150 ms or more. The bound leaves room for a loaded machine and is far below the old path. For the test I moved the loop timer from test/boot-no-stall.test.ts into test/helpers/worst-block.ts, and both tests use it. It now waits for the timer's next tick rather than a fixed 10 ms. scripts/test-honesty-allow.json drops that file's one allowed fixed wait.

Not done:

  • feedStdin's gzip path and every other gunzipSync caller are unchanged. feedStdin does use the async gunzip now, but it does not take this held path.
  • The first slice can still run about 25 ms, which is the slice length plus warm-up.

No door: server-side git transport only; no page, action or tool changed.

bun x tsc --noEmit and bun scripts/gate.ts --explain pass (32 of 32 rules). Passing tests: the new one, boot-no-stall, and the 19 suites that cover own_refs, smart-http and held fetches (162 tests). scripts/fast.ts named nearly the whole suite, so I picked those myself and left the full run to the forge's check.

Try it: bun test test/runner-fetch-loop.test.ts. It prints the longest block. Put back the two src/git files from b51ab2efa and it reports around 900 ms and fails.

🤖 Generated with Claude Code

Closes #17821

commented

A runner's fetch through /api/v1/runner/jobs/:id/git/git-upload-pack no longer blocks the serving thread while the forge checks what the runner is asking for (#17821).

What blocked, before. I couldn't read the production [loop] log from the sandbox, so I measured the worst case locally: the largest negotiation a fetch may send (1 MiB gzipped, 16 MiB inflated, about 330k packets). Git itself already ran async and streamed its output. What blocked the thread was the work done before git gets the request:

  • negotiation() in src/git/smart-http.ts inflated the body with one gunzipSync.
  • heldNegotiation().push in src/git/own_refs.ts then read every packet in one unbroken pass. That pass also ran a flatMap over all packets to collect ids and a filter plus copy to build the output.

Result: 860–970 ms of blocked loop per fetch.

After.

  • The body is inflated with async gunzip on zlib's worker, still capped at FETCH_MAX.
  • The packet read and the output build run in SLICE_MS slices, using the existing sliced() from src/kernel/breathe.ts. Ids are collected as packets are read.
  • A first piece with nothing carried over is read where it lies, without copying.

The same bytes go to git, and the job-token check still runs before any spawn. Longest block is now 25–50 ms.

Test. test/runner-fetch-loop.test.ts sends that largest negotiation through serviceRpc with onlyWants. It checks git answers with a pack and that the loop is never blocked for 150 ms or more. The bound leaves room for a loaded machine and is far below the old path. For the test I moved the loop timer from test/boot-no-stall.test.ts into test/helpers/worst-block.ts, and both tests use it. It now waits for the timer's next tick rather than a fixed 10 ms. scripts/test-honesty-allow.json drops that file's one allowed fixed wait.

Not done:

  • feedStdin's gzip path and every other gunzipSync caller are unchanged. feedStdin does use the async gunzip now, but it does not take this held path.
  • The first slice can still run about 25 ms, which is the slice length plus warm-up.

No door: server-side git transport only; no page, action or tool changed.

bun x tsc --noEmit and bun scripts/gate.ts --explain pass (32 of 32 rules). Passing tests: the new one, boot-no-stall, and the 19 suites that cover own_refs, smart-http and held fetches (162 tests). scripts/fast.ts named nearly the whole suite, so I picked those myself and left the full run to the forge's check.

Try it: bun test test/runner-fetch-loop.test.ts. It prints the longest block. Put back the two src/git files from b51ab2efa and it reports around 900 ms and fails.

🤖 Generated with Claude Code

Sign in to join this conversation.

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs