Repository navigation
perf(gateway): keep artifact downloads off the main thread - #158583
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. Reviewed September 26, 2026, 4:48 AM ET / 08:48 UTC (Revision 3). ClawSweeper reviewWhat this changesMoves transcript-backed artifact download preparation and HTTP response bytes into the history worker while the Gateway retains download tickets and delivery. Merge readiness✅ Ready for maintainer review Current main still hashes and decodes inline artifact downloads on the Gateway thread. This PR addresses that distinct work, and the current head repairs the connection-loss case identified in the previous review. Priority: P2 Review scores
Verification
How this fits togetherThe Gateway receives an artifact download request, selects an artifact from session history, and issues a connection-bound URL. An HTTP request for that URL reads the artifact and returns its headers and bytes. flowchart LR
A[Artifact download request] --> B[Session authorization]
B --> C[History worker]
C --> D[Prepared digest and summary]
D --> E[Connection-bound ticket]
E --> F[HTTP request]
F --> G[Worker-prepared response]
G --> H[Gateway delivery]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +199, Tests +294. Total +493 across 15 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep artifact preparation in the existing history worker while preserving live ticket and session checks, byte-range semantics, and the inline fallback for a lost connection. Do we have a high-confidence way to reproduce the issue? Yes, from source: current main hashes and decodes the full inline payload in the HTTP handler, including for HEAD and small ranges. The PR reports registered-handler before-and-after measurements; I did not execute the path in this read-only review. Is this the best way to solve the issue? Yes. The patch uses the existing history worker and retains the Gateway's ticket and authorization owners, with a tested inline fallback when a connection disappears. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against a2792b9a40bb. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (2 earlier review cycles)
|
Merge current main after the stacked artifact reader parent landed. Preserve main transcript fallback handling and keep only the artifact download worker unit in the PR diff. Recheck HTTP grant eligibility after preparation so authorized reconnected requests retain inline delivery; the registered-handler regression fails before this repair.
Keep canonical scoped-key reads on the existing no-options lookup path and pass an explicit owner only for unscoped keys. This removes an unnecessary empty options object introduced by extraction. CI and local reproduction exposed eight existing artifact scope assertions; all 94 artifact, authority, and transcript-image tests pass after correction.
|
Merged via squash.
|
…158583) * perf(gateway): move artifact reads off the main thread * fix(gateway): preserve archive-only transcript reads * style(gateway): clarify captured worker reader inputs * fix(gateway): break artifact history type import cycles * perf(gateway): prepare artifact downloads in the history worker * fix(gateway): distinguish artifact selector from read facade * fix(gateway): allow absent artifact response headers * fix(gateway): preserve default artifact session lookup Keep canonical scoped-key reads on the existing no-options lookup path and pass an explicit owner only for unscoped keys. This removes an unnecessary empty options object introduced by extraction. CI and local reproduction exposed eight existing artifact scope assertions; all 94 artifact, authority, and transcript-image tests pass after correction.
What Problem This Solves
Downloading a large inline artifact can pause the Gateway thread while it hashes and decodes the entire payload, even for HEAD or a tiny byte range.
User Impact
HTTP artifact downloads keep the same URLs, response semantics, and access checks while leaving the Gateway thread available for other conversations. There are no protocol, configuration, or database schema changes.
Why This Change Was Made
The existing history worker now prepares both grants and fresh HTTP responses. Grant creation returns only summary metadata and a digest; each delivery rereads the transcript and verifies that digest before returning any bytes. HEAD, 304, and 416 return no payload, and range reads decode and transfer only the requested bytes in an independently owned buffer. The Gateway retains current connection, ticket, request, and original session-generation authority, including rechecks after the worker read.
The artifact reader parent (#158450) is merged. This branch merges main and reuses its artifact selection operations; the remaining diff is only the download unit. Managed media keeps its canonical streaming owner, and internal callers without a live connection retain the inline fallback. Process-held incognito transcripts retain their existing in-process reader exception.
Evidence
Synthetic 12 MiB artifact, actual registered RPC grant and HTTP delivery handlers, five warmed sequential requests per operation, macOS arm64 / Node 26.9.0. Before uses the parent PR's source handlers; after uses this branch. The shared host was heavily loaded, so these are directional measurements, not deployed latency guarantees.
HEAD returns no body; the 1 KiB range returns exactly 1 KiB. Regression coverage verifies the registered worker transfer hook, range alignment and backing-buffer size, actual length despite incorrect declared size, fresh digest rejection for HEAD/range/conditional GET, and authority revocation while a read is pending.
Validation on merged candidate
07862b230d7192d052f2a0246d3626643c540e04:node scripts/run-vitest.mjs <files> --maxWorkers=1. These cover byte projection, HTTP authority, registered artifact lookup and request authority, transcript images, transcript readers, and worker schema freshness/transfer behavior.Artifact download connection is no longer available(109.38 s focused command wall). After the repair, reconnection returns the expected inline bytes, while cancellation and authority revocation still refuse disclosure. No new test cases, timers, fixtures, or production test seams were added.node scripts/check-changed.mjs --base origin/mainpassed through the repository Crabbox wrapper on one Blacksmith Testbox, with exact source/tree verification; command wall 27m35.857s, exit 0. Production and test types, lint, dead-export scans, and boundary guards passed. Leasetbx_01m3eb6qp2tmj053rxcqwegwt2is stopped/completed. Changed-gate run. A post-success portal-status sync warning did not affect the recorded check result. The first wrapper invocation rejected a raw SHA base before allocation; the corrected invocation used its required remote-tracking ref.The reconnect repair rechecks grant eligibility after the worker await and reuses the existing inline reader if the connection can no longer receive a ticket. Request and session authority remain required. The merge preserves main's reset/archive transcript fallback exactly. No schema, protocol, configuration, retention, or update behavior changes.
CI follow-up on
1eedd8b39d28bd31817dd0336bc0e1c5d0a1f52b:Exact-head CI run
36229562054failed eight existing assertions inartifacts.test.ts: the extracted reader supplied an unnecessary empty options object for canonical scoped keys. That failing job cancelled 79 siblings. The same eight failures reproduced locally (53 tests, 81.85 s command wall). The reader now preserves the existing no-options call for scoped keys; bare/global keys retain their explicit owner. No assertions were weakened or changed.After repair, the complete artifact, request-authority, and transcript-image suites passed 94 tests in 114.82 s command wall (
node scripts/run-vitest.mjs <three files> --maxWorkers=1); scoped lint and independent Codex review through P2 passed. The earlier Testbox check applies to the merged candidate before this behavior-equivalent lookup correction; current-head CI validates the final correction. No failed run was rerun solely to obtain green.