Skip to content

fix: stop returning expired tool event recipients - #137148

Merged
steipete merged 1 commit into
mainfrom
codex/perf6-tool-recipient-grace
Sep 3, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/perf6-tool-recipient-grace

Conversation

@steipete

@steipete steipete commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

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 agent event to the expired run connection while delivering the expected session.tool event 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.ts
  • node scripts/check-changed.mjs -- src/gateway/server-chat-state.ts src/gateway/server-chat-state.test.ts src/gateway/server-chat.agent-events.test.ts passed (297.75 seconds).
  • Independent source/history/lifecycle review and managed Codex review found no actionable P0–P2 issue. The behavior is reachable from stable v2026.2.12; the original implementation introduced the stale return.

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_fetch of 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: alpha before server-side validation, followed by explicit id: 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 3bb6e3164a06e5c35fb50b368cc63cbb05826384 contains 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.

@clawsweeper

clawsweeper Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@steipete

steipete commented Sep 3, 2026

Copy link
Copy Markdown
Contributor Author

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.

@steipete
steipete marked this pull request as ready for review September 3, 2026 07:42
@clawsweeper

clawsweeper Bot commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 3, 2026, 5:09 AM ET / 09:09 UTC.

ClawSweeper review

What this changes

The 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
Reviewed head: 56c3610401b6cc435584feee9b61ec9b2364aef8

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused net-neutral lifecycle repair with direct owner and handler regression coverage, and no identified patch defect.
Proof confidence 🌊 off-meta tidepool Not applicable: This maintainer-authored PR is exempt from the external-contributor proof gate; its supplied evidence nevertheless describes deterministic post-fix registry and real-handler routing coverage for the changed Gateway owner.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-authored PR is exempt from the external-contributor proof gate; its supplied evidence nevertheless describes deterministic post-fix registry and real-handler routing coverage for the changed Gateway owner.
Evidence reviewed 5 items Current-base defect: The base registry prunes an expired finalized recipient but returns the previously captured connection set, leaving one stale audience available to the caller.
Owner-boundary repair: The changed lookup updates and prunes the recipient record, then rereads current store membership so a pruned final recipient returns undefined.
Delivery caller: The Gateway handler uses the registry result for targeted agent delivery, then independently emits session.tool to session subscribers excluding any run recipients.
Findings None None.
Security None None.

How this fits together

Gateway 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]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source 0, Tests +50. Total +50 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 1 5 5 0
Tests 2 51 1 +50
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 56 6 +50

Review metrics

Metric Value Why it matters
Production versus tests production +5/-5 (net 0); tests +51/-1 (net +50) The repair is production-net-neutral and the added lines are focused regression coverage for the lifecycle and delivery boundary.

Technical review

Best 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.

Labels

Label justifications:

  • P1: The patch prevents a late Gateway tool event from reaching a completed run’s former WebSocket audience.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This maintainer-authored PR is exempt from the external-contributor proof gate; its supplied evidence nevertheless describes deterministic post-fix registry and real-handler routing coverage for the changed Gateway owner.

Evidence

What I checked:

  • Current-base defect: The base registry prunes an expired finalized recipient but returns the previously captured connection set, leaving one stale audience available to the caller. (src/gateway/server-chat-state.ts:689, 590ee376ad0c)
  • Owner-boundary repair: The changed lookup updates and prunes the recipient record, then rereads current store membership so a pruned final recipient returns undefined. (src/gateway/server-chat-state.ts:689, 56c3610401b6)
  • Delivery caller: The Gateway handler uses the registry result for targeted agent delivery, then independently emits session.tool to session subscribers excluding any run recipients. (src/gateway/server-chat.ts:1554, 56c3610401b6)
  • Focused regression coverage: The added tests cover expiry with and without retained run state, plus the handler outcome where only the current session subscriber receives delivery. (src/gateway/server-chat.agent-events.test.ts:2553, 56c3610401b6)
  • Submitted validation: The PR body reports the two affected suites passing after the repair; this read-only review did not execute repository tests. (56c3610401b6)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (3 earlier review cycles)
  • reviewed 2026-09-03T07:41:31.515Z sha 09b6df4b014aa44e2efc8c3f614d67cd65e51ecd :: needs maintainer review before merge. :: none
  • reviewed 2026-09-03T07:48:19.401Z sha 09b6df4b014aa44e2efc8c3f614d67cd65e51ecd :: blocked before merge. :: none
  • reviewed 2026-09-03T08:16:12.768Z sha 5dae9da71f7a03cc60b5c9f6e71cd4144eea6a22 :: needs maintainer review before merge. :: none

@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 3, 2026
@steipete
steipete force-pushed the codex/perf6-tool-recipient-grace branch from 09b6df4 to 5dae9da Compare September 3, 2026 08:08
@steipete

steipete commented Sep 3, 2026

Copy link
Copy Markdown
Contributor Author

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.

@steipete
steipete force-pushed the codex/perf6-tool-recipient-grace branch from 5dae9da to 56c3610 Compare September 3, 2026 09:01
@steipete

steipete commented Sep 3, 2026

Copy link
Copy Markdown
Contributor Author

Final composite 565e5bb09052372405cbbb13e756f453547e86fe passed 10 real OpenAI turns across 14 memory stages, plus a separate four-turn smoke: 62 RPCs, two closed clients, stable identities, clean unforced shutdown and runtime/port cleanup.

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.

@steipete
steipete merged commit 89e35c3 into main Sep 3, 2026
186 checks passed
@steipete
steipete deleted the codex/perf6-tool-recipient-grace branch September 3, 2026 09:35
@steipete

steipete commented Sep 3, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime maintainer Maintainer-authored PR P1 High-priority user-facing bug, regression, or broken workflow. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant