Repository navigation
fix: stop returning expired tool event recipients - #137148
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Real Gateway follow-up: all four fixed real OpenAI turns and 57 RPC checks passed on the immutable candidate composite containing this PR. The PR body now records web fetch, oversized Unicode, MCP schema/default/dispatch and session/subscription/reconnect evidence, plus the source identity and clean shutdown limits. This supersedes the earlier pending integration note. |
|
Codex review: needs maintainer review before merge. Reviewed September 3, 2026, 5:09 AM ET / 09:09 UTC. ClawSweeper reviewWhat this changesThe PR changes Gateway tool-event recipient lookup so a finalized run’s expired WebSocket recipients cannot receive one late tool event while current session subscribers still receive their event. Merge readiness✅ Ready for maintainer review Keep this maintainer-authored PR open for normal exact-head CI and merge handling. The current base still returns an expired run’s captured recipient set after pruning; the branch fixes that lifecycle-owner defect with focused registry and handler coverage, and no correctness or security finding was identified. Priority: P1 Review scores
Verification
How this fits togetherGateway routes agent tool events to run-specific WebSocket recipients and separately to current session subscribers. The chat-run state registry owns the short final grace period that decides when a completed run’s recipient audience is removed. flowchart LR
A[Agent tool event] --> B[Gateway event handler]
B --> C[Run recipient registry]
C --> D{Final grace elapsed?}
D -->|No| E[Run-specific recipients]
D -->|Yes| F[Remove expired recipient]
E --> G[Agent event delivery]
F --> H[Session subscriber delivery]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource 0, Tests +50. Total +50 across 3 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Use the recipient registry’s post-prune membership as the sole source of run-scoped delivery, retaining the focused regression that proves session subscribers are unaffected. Do we have a high-confidence way to reproduce the issue? Yes—source-reproducible: at the exact final-grace cutoff, the base code deletes the recipient record but returns its earlier captured set; the added handler scenario exercises that delivery path. Is this the best way to solve the issue? Yes. Rereading the lifecycle owner after its own pruning fixes the stale return at the source and avoids a downstream broadcast exception. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 590ee376ad0c. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (3 earlier review cycles)
|
09b6df4 to
5dae9da
Compare
|
Maintainer disposition: accept the net-zero recipient-lifecycle repair under the authorized bug-fix campaign. The registry must reread after its own expiry pruning; focused expiry/handler regressions preserve current session subscribers. The branch now includes the upstream main lint fix #137149 with every reviewed source hash unchanged. Required CI must pass before landing. Ordinary real Gateway integration is separate from the synthetic exact-expiry reproduction, as recorded in the body. |
5dae9da to
56c3610
Compare
|
Final composite Real turns and subscribed transcript delivery passed across reconnect. The smoke does not manufacture a late tool event after the 30-second final grace. Original-fail/candidate-pass registry and actual-handler regressions remain the direct proof that expired recipients are removed while current session subscribers receive delivery. One fixed pair: main-isolate Unicode allocation estimates −35.0037%/−31.3677%; idle post-GC RSS/heap deltas +4.203125/−0.125908 MiB (Code Mode), −3.718750/−0.012688 MiB (Tool Search). RSS covers the Gateway process; heap covers its main isolate. This supports no per-PR attribution or general RSS claim. Exact-head CI and native landing gates remain required. |
|
Merged via squash.
|
What problem does this PR solve?
After the existing 30-second final grace expires, the first late tool event can still reach a finished run’s former audience. The recipient registry prunes its record but returns the Set captured before pruning. The actual agent-event handler then broadcasts to that expired audience once.
Why is this the right fix?
The registry now returns the current store membership after pruning. Active recipient renewal, the fixed final grace, retained unrelated run state, and current session subscribers keep their existing behavior. This fixes the lifecycle owner rather than adding a consumer guard. Production +5/−5 (net zero); tests net +50. No memory or throughput claim.
User-visible impact
Expired run subscriptions stop receiving late tool events immediately at their existing deadline. Current session subscribers continue receiving their tool events. There is no protocol, configuration, persistence, or permission change.
Evidence
Before editing production, the original registry failed both expiry regressions, including a run with other retained state. The actual agent-event handler also failed by sending an extra
agentevent to the expired run connection while delivering the expectedsession.toolevent to the current subscriber. The same regressions and both full affected suites pass after the fix: 217 tests.node scripts/run-vitest.mjs run src/gateway/server-chat-state.test.ts src/gateway/server-chat.agent-events.test.tsnode scripts/check-changed.mjs -- src/gateway/server-chat-state.ts src/gateway/server-chat-state.test.ts src/gateway/server-chat.agent-events.test.tspassed (297.75 seconds).The handler regression uses actual registry and routing with simulated event ingress/broadcast. It proves the deadline defect deterministically, not a live WebSocket late-event reproduction. Ordinary real-key Gateway integration passed in the campaign’s next feature run; the exact late-event deadline remains covered by the deterministic handler regression.
Real Gateway integration (2026-09-03)
A prebuilt, isolated Gateway with a real OpenAI API key passed four fixed turns: ordinary completion, real
web_fetchof example.com, a 1.31 MB Unicode return through Code Mode, and a real MCP stdio tool with default and explicit arguments. Fifty-seven Gateway RPCs verified three session identities, full/repeated/paginated/subscribed list rows, descriptions and final previews, transcript completion, an explicit reconnect, empty approval replay and unsubscribe.The MCP server observed the default
id: alphabefore server-side validation, followed by explicitid: beta; both nested call identities/order, structured results and metadata projection matched. The Unicode prefix remained well formed and within its byte budget with exact omitted-byte accounting. All four turns completed without retries.The local immutable composite
3bb6e3164a06e5c35fb50b368cc63cbb05826384contains the twelve published campaign changes through #137148, including this PR’s reviewed source. Source/build/dependency identity was checked before and after. Both clients closed, the Gateway exited successfully without escalation, all recorded MCP processes exited, and private state/port cleanup passed. This is functional integration proof; it does not attribute memory or latency differences to this PR.