Repository navigation
fix: keep Gateway responsive while recording trajectory events - #157598
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 24, 2026, 6:50 PM ET / 22:50 UTC (Revision 4). ClawSweeper reviewWhat this changesMoves durable trajectory event writes and retention to the agent database worker, adds settlement and authority coverage, updates worker-access documentation, and adjusts a native test fixture copy. Merge readiness✅ Ready for maintainer review Current main still executes trajectory SQL during a Gateway flush. This PR addresses that remaining problem, and the pinned head has credible boundary proof with no actionable defect found. Priority: P2 Review scores
Verification
How this fits togetherThe trajectory recorder receives agent and worker-session events and stores a bounded timeline in each agent's SQLite database. Gateway diagnostics and trajectory readers consume those stored events. flowchart LR
A[Agent and worker events] --> B[Trajectory recorder]
B --> C[Pending event queue]
C --> D[Writer admission and live authority]
D --> E[Agent database worker]
E --> F[SQLite event timeline]
F --> G[Trajectory readers and export]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +183, Tests +352, Docs +11. Total +546 across 14 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep one settlement owner for durable trajectory writes so committed events are never replayed after a lost reply, while monitoring the documented cold-worker startup cost. Do we have a high-confidence way to reproduce the issue? Yes. Current-main source shows the Gateway flush entering synchronous trajectory SQL; this read-only review did not execute that path. Is this the best way to solve the issue? Yes. The patch uses the existing agent database worker and writer admission owner while preserving the native-only scopes and stored-row contract. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 0a6f1fa28b73. 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 (3 earlier review cycles) |
|
Merged via squash.
|
* commit '0484d7a3ecf52589b0d3d98741e58e5f6b5bf661': (68 commits) fix(subagents): stop completion transcript retry loops (#157571) perf(sessions): remove duplicate foreground history reference scans (#157572) improve(typesafe): defer startup work until the first decision (#157380) fix(update): restore npm-pack helper typechecking (#157659) fix(packaging): avoid heap exhaustion on large bundles (#157471) refactor(infra): share process error handler registries (#157632) chore(ui): refresh control ui locales (#157573) fix(gateway): release remote Skills subscriptions when shutdown drains (#157592) perf(plugins): reuse declared tool membership during resolution (#156205) fix(ui): pasted text previews fail before sending (#157390) fix(agents): wait for database resources during deletion (#157631) improve: move operator profile database reads off the Gateway thread (#155800) fix: explain rejected settings without losing edits (#157549) fix: keep Gateway responsive while recording trajectory events (#157598) fix(auth): show SIWC email and selected model account identity (#157629) docs: explain Codex app approval precedence (#155089) refactor(wizard): share select prompt requests (#157607) fix(ui): omit empty sections from conversation Markdown exports (#157590) fix(doctor): explain update lint supervisor refusals (#156547) fix(ui): GitHub folder links lose repository context (#157619) ...
* commit '0484d7a3ecf52589b0d3d98741e58e5f6b5bf661': (68 commits) fix(subagents): stop completion transcript retry loops (#157571) perf(sessions): remove duplicate foreground history reference scans (#157572) improve(typesafe): defer startup work until the first decision (#157380) fix(update): restore npm-pack helper typechecking (#157659) fix(packaging): avoid heap exhaustion on large bundles (#157471) refactor(infra): share process error handler registries (#157632) chore(ui): refresh control ui locales (#157573) fix(gateway): release remote Skills subscriptions when shutdown drains (#157592) perf(plugins): reuse declared tool membership during resolution (#156205) fix(ui): pasted text previews fail before sending (#157390) fix(agents): wait for database resources during deletion (#157631) improve: move operator profile database reads off the Gateway thread (#155800) fix: explain rejected settings without losing edits (#157549) fix: keep Gateway responsive while recording trajectory events (#157598) fix(auth): show SIWC email and selected model account identity (#157629) docs: explain Codex app approval precedence (#155089) refactor(wizard): share select prompt requests (#157607) fix(ui): omit empty sections from conversation Markdown exports (#157590) fix(doctor): explain update lint supervisor refusals (#156547) fix(ui): GitHub folder links lose repository context (#157619) ...
* refactor(ai): share Mistral text delta appends * Merge main to incorporate the upstream update type fix * commit '0484d7a3ecf52589b0d3d98741e58e5f6b5bf661': (68 commits) fix(subagents): stop completion transcript retry loops (#157571) perf(sessions): remove duplicate foreground history reference scans (#157572) improve(typesafe): defer startup work until the first decision (#157380) fix(update): restore npm-pack helper typechecking (#157659) fix(packaging): avoid heap exhaustion on large bundles (#157471) refactor(infra): share process error handler registries (#157632) chore(ui): refresh control ui locales (#157573) fix(gateway): release remote Skills subscriptions when shutdown drains (#157592) perf(plugins): reuse declared tool membership during resolution (#156205) fix(ui): pasted text previews fail before sending (#157390) fix(agents): wait for database resources during deletion (#157631) improve: move operator profile database reads off the Gateway thread (#155800) fix: explain rejected settings without losing edits (#157549) fix: keep Gateway responsive while recording trajectory events (#157598) fix(auth): show SIWC email and selected model account identity (#157629) docs: explain Codex app approval precedence (#155089) refactor(wizard): share select prompt requests (#157607) fix(ui): omit empty sections from conversation Markdown exports (#157590) fix(doctor): explain update lint supervisor refusals (#156547) fix(ui): GitHub folder links lose repository context (#157619) ... Co-authored-by: Vincent Koc <[email protected]>
…law#157598) * fix: offload trajectory flushes to the agent database worker * test: prevent inherited writable compiler descriptors
* refactor(ai): share Mistral text delta appends * Merge main to incorporate the upstream update type fix * commit 'dda1f68bfa102cb804392c0e7cc22c0566a0944a': (68 commits) fix(subagents): stop completion transcript retry loops (openclaw#157571) perf(sessions): remove duplicate foreground history reference scans (openclaw#157572) improve(typesafe): defer startup work until the first decision (openclaw#157380) fix(update): restore npm-pack helper typechecking (openclaw#157659) fix(packaging): avoid heap exhaustion on large bundles (openclaw#157471) refactor(infra): share process error handler registries (openclaw#157632) chore(ui): refresh control ui locales (openclaw#157573) fix(gateway): release remote Skills subscriptions when shutdown drains (openclaw#157592) perf(plugins): reuse declared tool membership during resolution (openclaw#156205) fix(ui): pasted text previews fail before sending (openclaw#157390) fix(agents): wait for database resources during deletion (openclaw#157631) improve: move operator profile database reads off the Gateway thread (openclaw#155800) fix: explain rejected settings without losing edits (openclaw#157549) fix: keep Gateway responsive while recording trajectory events (openclaw#157598) fix(auth): show SIWC email and selected model account identity (openclaw#157629) docs: explain Codex app approval precedence (openclaw#155089) refactor(wizard): share select prompt requests (openclaw#157607) fix(ui): omit empty sections from conversation Markdown exports (openclaw#157590) fix(doctor): explain update lint supervisor refusals (openclaw#156547) fix(ui): GitHub folder links lose repository context (openclaw#157619) ... Co-authored-by: Vincent Koc <[email protected]>
* refactor(ui): share slash-command failure results * Merge main to incorporate the upstream update type fix * commit '0484d7a3ecf52589b0d3d98741e58e5f6b5bf661': (68 commits) fix(subagents): stop completion transcript retry loops (#157571) perf(sessions): remove duplicate foreground history reference scans (#157572) improve(typesafe): defer startup work until the first decision (#157380) fix(update): restore npm-pack helper typechecking (#157659) fix(packaging): avoid heap exhaustion on large bundles (#157471) refactor(infra): share process error handler registries (#157632) chore(ui): refresh control ui locales (#157573) fix(gateway): release remote Skills subscriptions when shutdown drains (#157592) perf(plugins): reuse declared tool membership during resolution (#156205) fix(ui): pasted text previews fail before sending (#157390) fix(agents): wait for database resources during deletion (#157631) improve: move operator profile database reads off the Gateway thread (#155800) fix: explain rejected settings without losing edits (#157549) fix: keep Gateway responsive while recording trajectory events (#157598) fix(auth): show SIWC email and selected model account identity (#157629) docs: explain Codex app approval precedence (#155089) refactor(wizard): share select prompt requests (#157607) fix(ui): omit empty sections from conversation Markdown exports (#157590) fix(doctor): explain update lint supervisor refusals (#156547) fix(ui): GitHub folder links lose repository context (#157619) ... * Merge frozen main to include the question fixture authority fix * commit '229ab8a1fe957d3d4822309a39ddf9c7ec616395': (25 commits) test(ui): capture live operator authority in guest question fixture refactor(agents): deslop runners, harness and recovery (#157294) fix(auth): preserve Copilot tenant credentials during Doctor repair (#139131) refactor(msteams): share stored service URL validation (#157706) fix(codex): honor configured tool PATH in native commands (#157290) refactor(msteams): share approval kind labels (#157705) fix(sessions): keep session results current during cold reads (#156121) fix(testing): capture bounded upgrade integrity diagnostics (#157535) refactor(i18n): reuse native branch candidate extraction (#157636) fix(update): preserve recovery files after ownership refusal (#148890) fix(test): prevent late announcements from contaminating registry tests (#157681) fix(e2e): scan full onboarding logs for prompts (#157624) refactor(session-tools): derive contracts from schemas (#156365) refactor(channels): derive config contracts from schemas (#156367) perf(test): reuse MCP archives and batch worker fixture copies (#157689) refactor: reuse prepared fixtures in slow core tests (#157685) refactor(codex): reuse marketplace reference selection (#157621) chore(ui): refresh control ui locales (#157710) docs(gateway): show how we build OpenClaw on Team (#157675) refactor: verify IRC surrogate chunking over loopback (#157580) ... * chore: merge frozen main prerequisite repairs Co-authored-by: Vincent Koc <[email protected]>
* refactor(ui): share slash-command failure results * Merge main to incorporate the upstream update type fix * commit 'dda1f68bfa102cb804392c0e7cc22c0566a0944a': (68 commits) fix(subagents): stop completion transcript retry loops (openclaw#157571) perf(sessions): remove duplicate foreground history reference scans (openclaw#157572) improve(typesafe): defer startup work until the first decision (openclaw#157380) fix(update): restore npm-pack helper typechecking (openclaw#157659) fix(packaging): avoid heap exhaustion on large bundles (openclaw#157471) refactor(infra): share process error handler registries (openclaw#157632) chore(ui): refresh control ui locales (openclaw#157573) fix(gateway): release remote Skills subscriptions when shutdown drains (openclaw#157592) perf(plugins): reuse declared tool membership during resolution (openclaw#156205) fix(ui): pasted text previews fail before sending (openclaw#157390) fix(agents): wait for database resources during deletion (openclaw#157631) improve: move operator profile database reads off the Gateway thread (openclaw#155800) fix: explain rejected settings without losing edits (openclaw#157549) fix: keep Gateway responsive while recording trajectory events (openclaw#157598) fix(auth): show SIWC email and selected model account identity (openclaw#157629) docs: explain Codex app approval precedence (openclaw#155089) refactor(wizard): share select prompt requests (openclaw#157607) fix(ui): omit empty sections from conversation Markdown exports (openclaw#157590) fix(doctor): explain update lint supervisor refusals (openclaw#156547) fix(ui): GitHub folder links lose repository context (openclaw#157619) ... * Merge frozen main to include the question fixture authority fix * commit 'dc64cc3a3a3cf38fff1e44c1d7af42a32929d7e4': (25 commits) test(ui): capture live operator authority in guest question fixture refactor(agents): deslop runners, harness and recovery (openclaw#157294) fix(auth): preserve Copilot tenant credentials during Doctor repair (openclaw#139131) refactor(msteams): share stored service URL validation (openclaw#157706) fix(codex): honor configured tool PATH in native commands (openclaw#157290) refactor(msteams): share approval kind labels (openclaw#157705) fix(sessions): keep session results current during cold reads (openclaw#156121) fix(testing): capture bounded upgrade integrity diagnostics (openclaw#157535) refactor(i18n): reuse native branch candidate extraction (openclaw#157636) fix(update): preserve recovery files after ownership refusal (openclaw#148890) fix(test): prevent late announcements from contaminating registry tests (openclaw#157681) fix(e2e): scan full onboarding logs for prompts (openclaw#157624) refactor(session-tools): derive contracts from schemas (openclaw#156365) refactor(channels): derive config contracts from schemas (openclaw#156367) perf(test): reuse MCP archives and batch worker fixture copies (openclaw#157689) refactor: reuse prepared fixtures in slow core tests (openclaw#157685) refactor(codex): reuse marketplace reference selection (openclaw#157621) chore(ui): refresh control ui locales (openclaw#157710) docs(gateway): show how we build OpenClaw on Team (openclaw#157675) refactor: verify IRC surrogate chunking over loopback (openclaw#157580) ... * chore: merge frozen main prerequisite repairs Co-authored-by: Vincent Koc <[email protected]>
What Problem This Solves
Fixes Gateway event-loop stalls while recording trajectory events for active sessions. The asynchronous flush still ran sequence allocation, inserts, session trimming, and periodic retention synchronously on the Gateway thread.
User Impact
Trajectory persistence leaves the Gateway thread available for requests and events. Stored event bytes, ordering, byte limits, retention, schemas, and update behavior are unchanged; no Doctor migration or configuration change is required. A first flush can take longer while its database worker starts.
Why This Change Was Made
The existing agent database executor now runs the complete append-and-retention transaction. One SQLite writer module owns the pending prefix, physical-store FIFO, and native settlement. The live source is revalidated before the transaction and commit while its admitted host metadata handle remains retained. Confirmed commits retire the prefix even after reply loss; failed transactions remain retryable, and unknown outcomes prevent replay. Events arriving during a flush remain queued. Native-only incognito, maintenance, and already-executing worker scopes keep their existing kernel.
Evidence
The main-thread regression fails on the original path with four trajectory SQL statements and passes with zero. Focused coverage exercises stored bytes and UTF-8/UTF-16 retention, real failed INSERT retry, captured logical/physical store selection, actual launcher turn revocation at commit with a cold host handle, accepted-write/duplicate-ACK/shutdown settlement, and lost reply/unknown outcome handling. Integrated result: 64 tests in five files pass.
A fixed synthetic fixture started with 73,728 retained events (86.46 MiB), then appended 2,048 events and three 128-event batches through the real recorder. Warm median main-thread flush CPU fell from 16.670 ms to 2.463 ms (85.2%); queued-timer latency fell from 20.543 ms to 0.847 ms. Warm wall time fell from 20.516 ms to 15.212 ms. Initial flush CPU fell from 75.651 ms to 23.071 ms, but cold worker startup raised initial wall time from 75.456 ms to 406.955 ms. Every phase had identical ordered event hashes; the final table matched at 74,042 rows and 91,067,398 bytes. Event construction CPU is unchanged and outside these flush measurements. These bounded synthetic measurements do not establish production latency.
The integrated command used
node scripts/run-vitest.mjs <the five files> --maxWorkers=1: 68.174 s wall including worker compilation and three project setups. Test-body costs were 5.108 s for runtime (24 cases), 1.825 s for write settlement (2), 6.152 s for actual turn authority (2), 6.027 s for RPC acknowledgment/shutdown (4), and 2.698 s for retention (32). The authority and acknowledgment tests need real worker transactions and source lifecycle ownership, which unit mocks would bypass. The new settlement proof adds no timers or polling.Independent managed review and ClawSweeper review both completed with no actionable findings. After integrating main and retaining both test-list additions, head
f1d21a241bcpassed the same 64 tests (90.326 s wall), production typechecking (51.758 s), and the full build (584.888 s). The full changed-file check also passed on the pre-integration source, including all 25 test type graphs, unused-export scans, lint, and contract guards (2,056.126 s); the implementation and test bytes are unchanged by integration. Its first attempt found a missing common sink type annotation after extraction, which was fixed before publication. The first GitHub CI run passed the trajectory checks but failed an unrelated tooling fixture withspawn ETXTBSY; the investigation and repair are described below.The unrelated
live-docker-stage.test.tsfailure came from a freshly copied native compiler returningETXTBSY. Its Node 24.19 recursive copy now uses the existing close-on-exec policy fromnative-boundary-fixture.ts(fe55a3a). A process-local probe confirmed the writable descriptor changes fromFD_CLOEXEC=0to1, with identical bytes. Parser admission and assertions are unchanged; no retries or timing changes were added. The unchanged exact CI merge replay passed 4,916 tests in 90 files (718.670 s), recorded as non-reproduction, not proof of repair; the particular child that inherited the original CI descriptor is unknown.Post-fix Node 24.19 validation passed all 20 standalone runs (163 tests each; median 46.532 s wall, range 35.362–52.094 s) and three complete original-order two-group shard runs (4,916 tests each; 998.144, 943.342, and 939.229 s wall in independent checkouts). All inputs remained unchanged and all children settled. The original CI file cost was 31.682 s; its existing real-process suite covers frozen Git source contracts and trusted native parser admission. The fixture changed-file gate also passed, including test types, unused-export scans, lint, and guards (286.872 s). Independent review and refreshed ClawSweeper review are clean on the replacement. GitHub CI run 36065877848 passed on replacement head
5e25a857c2e, includingopenclaw/ci-gate. Gateway implementation and its 64-test coverage are unchanged by the four-line fixture correction.