Repository navigation
perf(gateway): release large event payloads from live text guards - #158643
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, 1:20 AM ET / 05:20 UTC (Revision 2). ClawSweeper reviewWhat this changesThe Gateway chat handler binds run, claim, and lifecycle identifiers into deferred live-text guards so large agent-event payloads can be released. Merge readiness✅ Ready for maintainer review Current main still retains whole events through deferred live-text guards. This PR addresses that distinct retention path, and the review found no introduced correctness defect. Priority: P2 Review scores
Verification
How this fits togetherAgent events enter the Gateway chat handler, which prepares live previews and queues client delivery. The run registry decides whether deferred output still belongs to an active run claim. flowchart LR
A[Agent event] --> B[Gateway chat handler]
B --> C[Live preview]
B --> D[Deferred text guard]
D --> E[Run registry check]
E --> F[Client delivery]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource -1. Total -1 across 1 file. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep the small identity-bound guard and its delivery-time registry check as the single ownership path for buffered live text. Do we have a high-confidence way to reproduce the issue? Yes. Main’s deferred closure visibly captures the event, and the PR describes a focused, repeated post-GC handler probe using large synthetic payloads. Is this the best way to solve the issue? Yes. Binding only the needed identifiers removes the reference to the full event while the registry retains the existing live-claim decision. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 0d7a4e817abc. LabelsLabel changes: No label changes. Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (1 earlier review cycle)
|
|
Merged via squash.
|
* commit '66b812f26e725cd709e08860d2cb46ba496cd308': (70 commits) fix(gateway): preserve typed boxed-number coercion chore(ui): refresh control ui locales (#158689) fix(gateway): reset staged headers on authority errors (#158669) fix(workers): keep inbound staging stable during quota scans fix: preserve Telegram delivery after bot identity changes (#158612) fix(ui): keep automation starter prompts out of startup (#158482) fix(cli): distinguish configuration read failures from invalid input (#158671) test: remove retired progress coercion suppression allowance refactor(gateway): schedule worker placement maintenance (#158662) fix(daemon): keep native service checks within their timeout (#154565) fix(test): restore gateway steering fixture contracts (#158478) fix(acpx): use SDK filesystem publication boundary fix(agentsapi): load OpenClaw persona and workspace context (#158328) fix(gateway): drop progress snapshot coercion suppression fix(qa): accept native Codex truncation in cache evidence (#158454) fix(gateway): keep chat subscriptions stable during unrelated approvals (#158633) perf(gateway): release event payloads from live text guards (#158643) perf(sessions): reduce stalls when saving large chat messages (#158402) fix(qa): reject history-bearing utility requests without session affinity (#158496) test: allow intentional progress snapshot coercion ...
* fix(test): verify followup completion ordering Exercise the real presentation settlement helper with asynchronous cleanup, preserve continuation and admission semantics, and unconditionally release and join the held work. Remote proof covers the strengthened ordering contract and both missing-await faults. * fix(test): verify followup completion ordering * chore: retain followup test branch ancestry The current-main reconstruction preserves the original reviewed scope and supersedes its stale base. Keep the remotely qualified candidate tree unchanged while retaining the original PR ancestry for a non-force branch update. * commit 'ff35145de21cf6296bec05e86bee37b5ed53bcb8': fix(test): verify followup completion ordering * test(auto-reply): signal queued presentation entry * chore: refresh followup test on boundary fix * commit '66b812f26e725cd709e08860d2cb46ba496cd308': (70 commits) fix(gateway): preserve typed boxed-number coercion chore(ui): refresh control ui locales (#158689) fix(gateway): reset staged headers on authority errors (#158669) fix(workers): keep inbound staging stable during quota scans fix: preserve Telegram delivery after bot identity changes (#158612) fix(ui): keep automation starter prompts out of startup (#158482) fix(cli): distinguish configuration read failures from invalid input (#158671) test: remove retired progress coercion suppression allowance refactor(gateway): schedule worker placement maintenance (#158662) fix(daemon): keep native service checks within their timeout (#154565) fix(test): restore gateway steering fixture contracts (#158478) fix(acpx): use SDK filesystem publication boundary fix(agentsapi): load OpenClaw persona and workspace context (#158328) fix(gateway): drop progress snapshot coercion suppression fix(qa): accept native Codex truncation in cache evidence (#158454) fix(gateway): keep chat subscriptions stable during unrelated approvals (#158633) perf(gateway): release event payloads from live text guards (#158643) perf(sessions): reduce stalls when saving large chat messages (#158402) fix(qa): reject history-bearing utility requests without session affinity (#158496) test: allow intentional progress snapshot coercion ... Co-authored-by: Vincent Koc <[email protected]>
* fix(test): verify followup completion ordering Exercise the real presentation settlement helper with asynchronous cleanup, preserve continuation and admission semantics, and unconditionally release and join the held work. Remote proof covers the strengthened ordering contract and both missing-await faults. * fix(test): verify followup completion ordering * chore: retain followup test branch ancestry The current-main reconstruction preserves the original reviewed scope and supersedes its stale base. Keep the remotely qualified candidate tree unchanged while retaining the original PR ancestry for a non-force branch update. * commit 'ff35145de21cf6296bec05e86bee37b5ed53bcb8': fix(test): verify followup completion ordering * test(auto-reply): signal queued presentation entry * chore: refresh followup test on boundary fix * commit '622be54be3ffe0fce27d6a4b147c76d4b19c528c': (70 commits) fix(gateway): preserve typed boxed-number coercion chore(ui): refresh control ui locales (openclaw#158689) fix(gateway): reset staged headers on authority errors (openclaw#158669) fix(workers): keep inbound staging stable during quota scans fix: preserve Telegram delivery after bot identity changes (openclaw#158612) fix(ui): keep automation starter prompts out of startup (openclaw#158482) fix(cli): distinguish configuration read failures from invalid input (openclaw#158671) test: remove retired progress coercion suppression allowance refactor(gateway): schedule worker placement maintenance (openclaw#158662) fix(daemon): keep native service checks within their timeout (openclaw#154565) fix(test): restore gateway steering fixture contracts (openclaw#158478) fix(acpx): use SDK filesystem publication boundary fix(agentsapi): load OpenClaw persona and workspace context (openclaw#158328) fix(gateway): drop progress snapshot coercion suppression fix(qa): accept native Codex truncation in cache evidence (openclaw#158454) fix(gateway): keep chat subscriptions stable during unrelated approvals (openclaw#158633) perf(gateway): release event payloads from live text guards (openclaw#158643) perf(sessions): reduce stalls when saving large chat messages (openclaw#158402) fix(qa): reject history-bearing utility requests without session affinity (openclaw#158496) test: allow intentional progress snapshot coercion ... Co-authored-by: Vincent Koc <[email protected]>
What Problem This Solves
Buffered live chat can retain large agent-event payloads after only a small display preview is needed.
User Impact
Concurrent sessions use less retained Gateway heap. Live text, widget previews, claim revocation, and delivery behavior stay unchanged.
Why This Change Was Made
Bind the existing current-owner guard to the run ID, claim ID, and lifecycle generation instead of closing over the whole event. The authoritative run registry already validates the lifecycle generation, so remove the duplicate check at its caller.
Related work in the same file: #158489 (incremental projection), #158587 (wire deltas), #158581 (lineage), and #158574 (stream subscriptions). Their inspected diffs do not fix this retention path; this change leaves those owners intact.
Evidence
createAgentEventHandlerheap probe: 50 active runs, each receiving a synthetic widget result plus a 4 MiB numeric payload. After explicit GC, all 50 previews and current-owner guards remain present. Three interleaved before/after pairs: baseline 200.160 / 200.098 / 200.094 MiB; candidate 0.1369 / 0.1369 / 0.1369 MiB. Median retained heap: 200.098 → 0.137 MiB (99.93% lower). This isolates retained heap, not end-to-end latency.node scripts/run-vitest.mjs src/gateway/server-chat.agent-events.test.ts --maxWorkers=1: 225 tests passed, 167.86 s wall after rebase (1% test execution; most time was worker artifact preparation). Existing coverage exercises released claims, reused run IDs, delayed text, lifecycle generations, and tool-only widget retirement; no nondeterministic GC test added to CI.node scripts/check-changed.mjs: production typecheck and all preceding guards passed; core-test validation stopped at an unrelated UI E2E TS2459 (control-ui-retained-assets.e2e.test.ts:17importsControlUiRootStatefromcontrol-ui.ts, which no longer exports it after perf(gateway): keep Control UI file reads off the event loop #158464). No files in that failure are changed here. Later gate stages remain unrun; hosted CI is authoritative.oxlintandgit diff --checkpassed.Landing validation
Exact-head CI run 36217587509 failed with TS2459 in
ui/src/e2e/control-ui-retained-assets.e2e.test.ts: the fixture importedControlUiRootStatefrom the retired module. This was an unrelated main regression, fixed byda8149b8ba7d88d76dbe7979986e307a4542e6f0. Merged main into this branch without conflicts (no rebase); the reviewed performance patch ID is unchanged. Candidate:09599c1177eaf1ccb87d4e94eef04f8911bcb07b.After the merge,
node scripts/run-vitest.mjs src/gateway/server-chat.agent-events.test.ts src/gateway/server-chat.subagent-lineage.test.ts --maxWorkers=1passed all 224 tests across two files in 72.12 seconds wall. No tests were added or changed by this PR. New-head CI replaces the failed run; no blind rerun was requested.