Repository navigation
fix(gateway): unify HTTP media stream ownership - #117000
Conversation
8cd701d to
3bb1992
Compare
|
Codex review: needs real behavior proof before merge. Reviewed July 31, 2026, 3:49 PM ET / 19:49 UTC. ClawSweeper reviewWhat this changesThe PR moves assistant-media and managed outgoing-media HTTP responses to one shared gateway helper that owns the opened file descriptor through streaming, disconnect, error, and no-body paths. Merge readiness⛔ Blocked until stronger real behavior proof is added - 5 items remain Keep this PR open for protected maintainer review. Current main still has two route-specific file-handle cleanup implementations, while the proposed shared gateway byte-stream owner directly addresses that duplicated lifecycle boundary; the remaining blocker is proof tied to the current force-pushed head, not a source-proven patch defect. Priority: P2 Review scores
Verification
How this fits togetherThe Gateway serves verified local assistant and managed outgoing media over HTTP, including byte ranges and playback-transcoded replacements. Each route opens a trusted file handle, computes a response plan, streams bytes to the client, and must release the descriptor exactly once when the response finishes or disconnects. flowchart LR
A[Assistant or managed media request] --> B[Open verified local file]
B --> C[Shared byte-stream lifecycle owner]
C --> D[Range and conditional response plan]
D --> E[File-backed read stream]
E --> F[HTTP client response]
F --> G[Finish, error, or disconnect cleanup]
Decision needed
Why: The architectural direction is sound from the available source and Node contract evidence, but the only cited live proof is tied to an earlier unavailable candidate and the protected label requires explicit human handling. Before merge
Agent review detailsSecurityNone. PR surfaceSource -1, Tests +152. Total +151 across 5 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Keep one shared byte-stream lifecycle owner at the gateway response boundary, preserve verified-handle streaming and byte-response behavior, and attach focused current-head disconnect, transcode-rejection, and already-ended-response proof before merge. Do we have a high-confidence way to reproduce the issue? Yes, at source level: current main has both routes disable stream auto-close and independently close the same opened handle on stream and response lifecycle events. The PR body also describes a focused TCP-disconnect reproduction, but that run is not yet tied to the current head. Is this the best way to solve the issue? Yes in principle: descriptor ownership belongs at the shared byte-response boundary because both routes implement the same stream lifecycle and Node's FileHandle stream contract owns closure when auto-close is enabled. The final merge decision should wait for exact-head proof rather than introduce another route-specific cleanup path. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 8b5871e1b703. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
|
Merged via squash.
|
* origin/main: (22 commits) fix(cron): preserve lazy ownership and bounded notification lifetimes (#117018) fix: live updater no-op restarts healthy gateways (#117038) fix(bedrock): release streaming clients (#117039) fix(google): restore canonical Gemini and Vertex provider invariants (#117042) fix(channels): preserve accepted LINE and Mattermost delivery (#117024) fix(feishu): unify truthful delivery and media ownership (#117023) fix(ui): isolate gateway observer lifecycles (#117017) fix(tui): keep reset transitions isolated from stale input (#116873) fix(gateway): centralize streamed media descriptor ownership (#117000) feat(plugins): externalize OpenCode provider (#117035) fix(onboarding): restore skill dependency consent (#116644) fix(streaming): preserve incomplete bracket tails in final replies (#116983) fix: allow slower gateway readiness after updates (#117032) fix(plugin-state): avoid shared SQLite corruption when CLI starts during gateway runtime (#113204) fix(cli): keep config file output raw under JSON logging (#116968) fix(ai): malformed Anthropic stream frames expose raw event payloads (#116938) fix(qa): authenticate actual scenario execution evidence (#117004) feat(plugins): externalize NovitaAI provider (#117007) fix(text): preserve fenced tool markers in visible-text sanitizer (#116939) (#116971) fix(channels): reset metadata memos with plugin lifecycle (#117005) ...
…w#117000) Co-authored-by: Peter Steinberger <[email protected]>
What Problem This Solves
Gateway assistant-media and managed outgoing-media responses duplicated ownership of opened file descriptors. Disconnect cleanup could close the same
FileHandletwice, and managed playback transcoding could leave a real descriptor open when transcoding rejected or a replacement descriptor was opened after the response had already ended.Why This Change Was Made
Descriptor ownership belongs at the existing shared gateway byte-response boundary. This change replaces duplicated route-specific teardown with one bounded lifecycle owner, transfers streaming ownership to
FileHandle.createReadStream({ autoClose: true }), and starts managed-media cleanup ownership immediately after opening the descriptor. Production code gets smaller: 88 lines added, 89 removed; net -1.User Impact
HEADbehavior remains covered and unchanged.Evidence
Distinct root causes
FileHandleafter destroying itsFileHandle-backedReadStream. Personally inspected Node'sinternal/fs/streams:FileHandleOperations.closeat lines 87–96 andReadStream.prototype._destroyat lines 300–311 show stream teardown already closes the same handle. A real TCP disconnect using an 8 MiB response reproduced 2FileHandle.closecalls before; 1 after, with the descriptor closed (fd=-1) in both cases.resolvePlaybackTranscode(...), leaving rejection outside cleanup ownership. A transcoded replacement opened after response termination also missed the already-emittedcloseevent. Focused regressions spy on the actual handle and verifyfd=-1after both paths.Exact immutable candidate and focused remote proof
36b80ada3ceae2de21b3d8710b883d778e4c4578.3bb199292b9a57610ce0b5e579026adbe9601216.51c08241bb41a01a27b4a250db708bdcf484addd.{ "head": "3bb199292b9a57610ce0b5e579026adbe9601216", "payloadBytes": 8388608, "before": { "closeCalls": 2, "destroyed": true, "readableEnded": false, "fd": -1 }, "after": { "closeCalls": 1, "destroyed": true, "readableEnded": false, "fd": -1 } }git diff --check, targeted formatting, exact-head full core lint, and all 204 owner tests passed.Independent full-branch autoreview
A genuine independent structured Codex
gpt-5.6-solreview at high reasoning inspected the complete current candidate3bb199292b9a57610ce0b5e579026adbe9601216, with real TruffleHog 3.96.0 and an explicit P3 threshold: zero P0/P1/P2/P3 findings, verdict “patch is correct”, confidence 0.93. A separate strict owner/caller/Node-contract review also reported no actionable findings.An earlier review correctly identified the already-ended replacement-descriptor race as P2; it was fixed at the canonical owner and covered by a real descriptor regression. Its separate provisional P1 inference about Node stream ownership was disproved by inspecting the actual Node implementation and observing the real TCP descriptor behavior; explicit
autoClose: truemakes ownership unambiguous.Changed files
src/gateway/control-ui.tssrc/gateway/http-byte-range.tssrc/gateway/http-byte-range.test.tssrc/gateway/managed-image-attachments.tssrc/gateway/managed-image-attachments.test.tsClawSweeper rank-up moves