Repository navigation
fix: keep gateway responsive during transcript and task database work - #157634
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review in progressClawSweeper is reviewing this revision. This supersedes any previous blocked status. |
…responsiveness-20260924
…way-database-responsiveness-20260924
…responsiveness-20260924
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Codex review: blocked before merge. Reviewed September 24, 2026, 9:51 PM ET / September 25, 2026, 01:51 UTC (Revision 4). ClawSweeper reviewWhat this changesMoves transcript matching, detached-task reads, and selected cron run and receipt operations into existing database workers so Gateway events can continue during database waits. Merge readiness⛔ Blocked before merge - 2 items remain Keep open: the branch addresses work still present on current main, and the linked WAL repair covers a different database path. This review found no concrete introduced defect or unresolved product choice. The earlier retry-grace test failure is documented with a bounded investigation under repository policy. Priority: P2 Review scores
Verification
How this fits togetherThe Gateway handles conversations and scheduled work while reading transcripts and coordinating task and cron state. Worker adapters perform the database operations and return results to the Gateway owners that publish outcomes or continue execution. flowchart LR
A[Gateway events] --> B[Transcript and task requests]
A --> C[Cron run requests]
B --> D[Read-only history worker]
C --> E[SQLite write worker]
D --> F[Owner revalidation]
E --> F
F --> G[Answers and committed state]
Before merge
Agent review detailsSecurityNone. PR surfacePR surface statistics unavailable: the file list is incomplete. Review metrics
Stored data modelPersistent data-model change detected: Technical reviewBest possible solution: Keep transcript reads and cron writes with their existing worker owners, with exact run and receipt authority checked before effects and committed results published before observers run. Do we have a high-confidence way to reproduce the issue? Yes. Current-main synchronous paths and the PR's held-coordinator and transcript-scan scenarios give a specific reproduction route; this read-only review did not execute it. Is this the best way to solve the issue? Yes. The branch uses established history and SQLite worker owners, retains the existing stored-row contract, and checks run ownership around asynchronous work. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 2042d60441eb. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
History |
|
I rechecked the complete 101-file diff at
The earlier updater and service-lifecycle disposition still applies. These are database execution changes during individual runs; the PR does not change installation, updater behavior, service-manager registration/restart, or Gateway startup/shutdown. An updater-to-candidate test does not exercise the changed product contract. The separate updater fixture repair passed its existing 19 native cases and unchanged CI wrapper with real filesystem behavior. Relevant compatibility evidence covers persisted cron jobs, exact reservation and receipt ownership, committed activation/cleanup, unavailable or replaced owners, rollback, and accepted-write settlement. The PR records the actual results and limits, including the unexplained earlier retry-grace failures. No additional compatibility patch or migration test is justified by these flags. The exact-head review found no introduced defect or security issue. Final-head CI remains required before merge; this disposition does not treat pending or failed checks as passed. |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
# Conflicts: # ui/src/e2e/question-guest.test-support.ts
|
@clawsweeper review Candidate |
|
🦞👀 Re-review progress:
|
# Conflicts: # scripts/tests/update-restart-swap-fixture.mjs
|
Merged via squash.
|
…openclaw#157634) * fix: keep gateway responsive during transcript and task database work * fix(cron): keep worker contracts independent of implementations * fix: settle cancelled task reads and retire drained receipt owners * fix: recheck local drain before preparing databases * fix: retire cancelled run before terminal delivery * test: align lifecycle fixtures with async task reads * test: load updater filesystem owners in restart fixture
Put back upstream b1c68b9 content that the continuation line had silently reverted in shared files. Every row has a keep/restore disposition recorded in the round journal. Feature hunks are preserved. Production: - announce deps: use callSubagentLifecycleGateway for the wake and cleanup deps (openclaw#146369 inherited Gateway binding). - reply-delivery: clear blockSourceText on superseded deferred replies (openclaw#143722). - stream-rendering: record a block reply as delivered only when it has text (openclaw#135751). - gateway runtime handles: carry hotReloadStatus through the managed reload. - sweep-kill and sweeper: honor retired cancellations (reconcileRetiredSubagentCancellation), and pass the run's Gateway context resolver into sweep session deletes. - registry read: per-child snapshot reads (openclaw#154727), so the Gateway event loop is not blocked. - session delivery queue: read the post-enqueue status inside the SQLite worker instead of on the main thread, restoring the openclaw#147887 invariant. Tests restored to upstream's coverage: - task-registry kernel test: back to upstream's kernel functions. - double-announce: real outbound adapter retry outcomes (openclaw#131419). - side-question: listener-failure hooks case (openclaw#144828). - session-delivery storage: main-thread-SQL idle assertion (openclaw#157458). - media-only: the re-resolved auth selection assertion. - resume persistence: activation uses the real recovery-runtime shape. The resume "steered requester turn" test was adapted for upstream's async task lookup (openclaw#157634). Its stub now settles like the real waker, and the test waits for settle before an exact count, with a no-pending-wake assertion added. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Fq5EX9ESA3CG9cuZxVoKAK
What Problem This Solves
Fixes gateway event-stream stalls while looking up older child answers or processing task completion and cron work under database contention.
User Impact
The gateway can keep processing events while these reads and writes are pending. Complete child answers, cancellation, run ownership, and committed cron state retain their existing behavior. No migration or configuration change is required.
Public V1 custom hooks, native permission/kill/requester-wake commits, cron reservation creation, and untouched timer/manual finalizers retain their synchronous contracts. This change does not claim a universal latency bound.
Why This Change Was Made
Several async entry points still performed SQLite work on the gateway thread. Transcript discovery and matching now run in the existing read-only history worker. Task lifecycle callers await prepared registry/flow reads and revalidate their owner after yielding. Cron activation, reservation cleanup, stale-family removal, and deferred receipt finishing use the existing SQLite broker.
Cancellation stops the caller's observation while accepted writes keep their settlement owner. Terminal cleanup clears the exact active run before completion subscribers observe it. Deletion waits recognize drained local receipt owners, preserve foreign-owner fences, and recheck cleanup authority after awaits. These changes complement #157484's periodic WAL repair.
Evidence
Private fixtures reproduced foreground transcript scans and blocked task/cron coordinator waits on
809808b76ad78fab4d69eaa02fb1b3e5ff127edb. Existing worker controls serviced host events while the holder remained locked. The repaired paths return the exact answer and terminal task/cron rows while allowing host events before completion or lock release.Review also exposed cancellation rereads and stale active-run state at terminal dispatch. Both were reproduced through real caller/subscription paths. The terminal regression failed only for cancelled completion; ordinary completion, deferred ownership, and outstanding task controls passed before the fix.
The cancellation follow-up passed the complete 51-case stream preparation file and all 44 requester-settle wake cases. After adding the required non-retry field to the terminal event fixture, the five affected cases and production types passed again. The same external API fixture changed cancelled terminal observation from active to inactive, and independent source-blind validation passed all five clauses, including normal/deferred controls, varied and boundary inputs, and independently checked resource cleanup. Independent follow-up review was clean through P2. All 25 test type graphs, targeted lint, formatting, and whitespace checks passed. The current candidate is
93ec1d966553f601732d8853bd8dfd7af9e5a9ca, including canonical691d2e5cd48c0ddda650123b8b9ee0089fa39004. Publication resolves the updater-helper conflict with the exact canonical implementation. No runtime or test bytes changed from the preceding head. Current-head CI passed: 149 successful jobs and 16 skipped jobs. Security and dependency review also passed. After integrating the upstream runner refactor, all four terminal ownership controls passed in 52.18 seconds wall time, with 22.96 seconds of Vitest time and cold worker preparation. Production types passed in 11.56 seconds. Integrated proof onb320b4f4e983a277229b5eb416e60f76bbfa21a1passed 283 tests across 16 complete files, production types, all 25 core test type graphs, targeted lint, import-cycle checks, Kysely guardrails, and database-first checks. The earlier ordered retry-grace E2E failure remains unexplained. An uninstrumented run passed 13 cases and failed one; a later diagnostic passed 11 and failed three. Announces returnedretryablebefore delivery with live signals; draining admitted work did not change the result. On the precedinge89585956f, one complete original-order run with pass-through guard/error observations passed all 14 cases in 99.20 seconds of Vitest time. All 38 active-child checks were false and all 48 descendant counts were zero; no wait or runtime-error calls occurred. This passing diagnostic does not identify or prove a fix for the earlier failures. Temporary instrumentation was restored byte-for-byte, with no production patch, assertion change, extra wait, or retry increase. The bounded investigation is recorded here while normal hosted CI and review gates remain required. Earlier validation passed 573 affected tests, announcement E2E coverage, and a full build in 800.94 seconds. These are earlier-candidate results, not an exact final-head build.The preceding exact-head CI run exposed three fixture failures: a missing async lookup mock in sessions-spawn, an unused async import crossing a legacy dispatch mock boundary, and the existing guest-question authority fixture defect tracked in #157708. Both task-related failures reproduced locally before correction. The final sessions-spawn file passes all eight cases in 34.64 seconds wall time; legacy dispatch and adjacent ownership pass all 42 cases in 27.25 seconds. The guest-question helper uses the exact separately reviewed fix
0753dff38a37b3a6ca28f349ee45248353a83b32; its owner recorded the unchanged lifecycle passing in 61.12 seconds of Vitest time. The four-file follow-up passed independent review through P2, all three affected test type graphs, targeted lint, formatting, and whitespace checks. Those three failing jobs passed in the next hosted run. Canonical229ab8a1fenow contains the Guest-question repair; this PR uses that exact helper and has no net UI change. Required final-head CI remains authoritative.The next hosted run exposed an upstream updater fixture defect and a Node 24 setup download failure. The updater reproduction passed 16 of 19 cases; three stopped at VM linking because a new mixed default/type import omitted the synthetic
node:fsdefault. The reviewed helper repair recognized that import and loaded the real filesystem authority/removal dependencies with the pinned fs-safe package. The same 19 cases pass in 0.89 seconds, and the unchanged CI wrapper passes in 3.88 seconds. All backup-retention, byte-content, verified-deletion, failure, and unexpected-dependency assertions remain. Whole-file audit, the full selected changed-file gate, and independent P2 review passed. No updater production code changed. The Node 24 failure was a pnpm archive download connection reset before tests; it is retained as infrastructure evidence, with no obsolete-head retry.The 2539 CI run reproduced the retry-grace failure: 13 cases passed and the sibling-delivery case failed before the first alpha delivery, with zero agent calls and a retryable announcement. An independent audit found no proven override, private-store, or cleanup defect. One original-order diagnostic on
93ec1d9665, whose affected bytes are unchanged, observed return decisions and errors without changing assertions, waits, or outcomes. All 14 cases passed in 56.92 seconds wall time, 52.57 seconds Vitest, with 16.42 seconds of tests. No failing decision was captured. Both production files were restored exactly. The failure remains unresolved; passing diagnostics do not establish a fix. No timeout, retry, assertion, or coverage was weakened. Canonical integration is needed to resolve a real merge conflict, not to replay CI for green.On the published
93ec1d9665head, the changed-files CI job passed the unchanged retry-grace file: all 14 cases, including the previously failing sibling-delivery case. Test time was 15.039 seconds and Vitest duration was 20.77 seconds; completed worker-generation verification also passed. This current-head success does not establish a cause or fix for the earlier failures.Canonical
691d2e5cd4independently repaired the updater fixture using native VM dependency specifiers and the real filesystem dependency closure. This PR adopts that exact helper, removing it from the net diff. The unchanged CI wrapper passed all 19 native assertions in 3.93 seconds wall time, 2.14 seconds Vitest. The optional Node 24 lane was skipped on the 2539 run, so it is not a passing rerun of the earlier download failure.While CI ran, main advanced to
42db2c3f2be8b7a07de1949253a4aac56ce7213a, including state schema 19 and lease-heartbeat changes. The merge request was held for dependency verification. A temporary merge with the unchanged PR head produced tree3c5e581a6f668ad2484223ae460a9b9523bb96e7. All 11 cases across the complete transcript-match, detached-task lookup, and cron responsiveness worker files passed in 70.47 seconds wall time, with completed worker-generation verification. Production types passed in 10.66 seconds. The temporary merge was then aborted, restoring the exact published head. No new authored changes or test relaxations were needed.A second combined-main check covered the dependency refresh, shared test-runtime preload, and plugin retained-work changes through
2abecd703d. With its frozen dependencies installed, merged tree13f21798175544e0bdf98c9068ee776f60b15883passed all 11 worker-responsiveness cases in 84.07 seconds, all four terminal-ownership cases in 19.08 seconds, and production types in 38.05 seconds. Worker-generation verification passed. The other 47 terminal-file cases were intentionally filtered; their earlier complete-file proof remains recorded above. The temporary merge was aborted and exact published head93ec1d9665restored clean. Later main movement througha4656d4eeachanges filesystem imports to the same pinned fs-safe helpers and splits an unrelated bootstrap test file. No authored path overlaps or new references to deleted wrappers were found. These changes preserve the tested worker and terminal contracts, so no further replay was needed.Source-blind API probes verified full-text equality, cancellation while a coordinator remained held, ownership retirement, persisted cron outcomes, and drained-receipt behavior. Accepted writes still committed. Monitor probes covered local, foreign, and unverifiable old receipt ownership, wrong agent/operation refusal, and private fixture/process cleanup. These are private runtime compositions, not a live fleet rollout or proof of later filesystem deletion.
Measured local test costs
Each row used
node scripts/run-vitest.mjs <file> --maxWorkers=1. Values are measured standalone wall seconds, including runner preparation. The final stream preparation run included 79.36 seconds of cold native preparation; its Vitest duration was 92.71 seconds. The new four-case ownership table took about 2.3 seconds inside that run. Requester wake Vitest duration was 26.78 seconds. Earlier broad validation used grouped commands; those totals are not standalone file costs or CI seconds.attempt-stream-settle.test.tsattempt-phase-lifecycle.test.tsattempt-stream-prepare.test.tsattempt.async-tasks.test.tsdetached-task-lookup.worker.test.tssession-transcript-match.worker.test.tssession-accessor.sqlite-archive-read.test.tsattempt-prompt-submit.steering.test.tsrun-admission.responsiveness.test.tsrun-admission-conflict.test.tsserver-claws-monitors.test.tsagent-deletion-cleanup.test.tssession-utils.queued-collector-admission.test.tssession-utils.queued-collector.test.tssubagent-registry.persistence.resume.test.tssubagent-registry.completion-authority.test.tssubagent-announce.requester-settle-wake.test.tsHosted job timings are available in the linked final-head CI run.
Test audit and pruning
Audited all 36 changed executable test files, seven helpers, and the routing registry in full, including assertions, fixtures, imports, setup/teardown, and skips. Existing coverage was reused where adequate. The unchanged updater native consumer and CI wrapper, guest-question lifecycle consumer, and legacy-dispatch shared helper were also inspected.
Four redundant announcement compositions were removed. Stronger retained cases cover active-run steering, leaf completion, two-child synthesis with one wake, and ordered child-parent delivery. One vacuous metadata insert/readback case and its sole helper were removed; retry/count/deadline coverage remains. A result assertion duplicating its wait helper was removed. Weak absence/self-routing assertions were replaced with observable outcomes, and unused fixtures/imports were pruned. No valid failing case was removed or skipped, and no assertion, timeout, or retry count was weakened to get green.
Worker-backed writes invalidated host-connection fault fixtures. Those now observe actual worker precommit results or persistent SQLite failure triggers, preserving real SQL, admission, and rollback. Registry fixtures join accepted work and release pending callbacks before reset. Steering cleanup now releases and joins its pending operation even after a failed assertion. Terminal event coverage uses the real subscription and private task stores. Its default mock and fixture setup live in the existing support file to keep the test within the line budget.
The CI follow-up repairs two incomplete mock boundaries exposed by the async cutover. The sessions-spawn fixture now provides the async lookup with the same available/no-task result as its synchronous fixture. Two mock aliases pointing to nonexistent paths were removed; the valid module mocks remain. Early-return controls join their own child cleanup in
finally, and the MCP case always releases its gate and joins cleanup, including on an acceptance or cache assertion failure. The legacy V1 suite isolates unused async core lookups with typed throwing spies and verifies they were never called, preserving real synchronous runtime behavior. All eight lifecycle cases and all 13 legacy cases remain. The adjacent 29 ownership cases pass unchanged. The guest-question helper reuses the separately reviewed fixture fix from #157708, commit0753dff38a37b3a6ca28f349ee45248353a83b32, to capture and release production operator authority. Its reconnect, answer, and cancellation assertions remain unchanged. The helper is now identical to main and no longer part of the net diff. The updater helper audit removed the redundant atomic alias and duplicate errno predicates in favor of canonical implementations; all 19 existing native cases remain. That helper is now identical to main and is recorded as a historical audit outside the final diff.Audited paths:
src/agents/embedded-agent-runner/run/attempt-phase-lifecycle.test.tssrc/agents/embedded-agent-runner/run/attempt-prompt-build.provenance.test.tssrc/agents/embedded-agent-runner/run/attempt-prompt-submit.steering.test.tssrc/agents/embedded-agent-runner/run/attempt-stream-prepare.test-support.tssrc/agents/embedded-agent-runner/run/attempt-stream-prepare.test.tssrc/agents/embedded-agent-runner/run/attempt-stream-settle.test.tssrc/agents/embedded-agent-runner/run/attempt.async-tasks.test.tssrc/agents/openclaw-tools.subagents.sessions-spawn.lifecycle.test.tssrc/agents/openclaw-tools.subagents.sessions-spawn.test-harness.tssrc/agents/subagents/announce/subagent-announce-result.test.tssrc/agents/subagents/announce/subagent-announce.format.e2e.test.tssrc/agents/subagents/announce/subagent-announce.requester-settle-results.test.tssrc/agents/subagents/announce/subagent-announce.requester-settle-wake.test.tssrc/agents/subagents/completion/subagent-completion-admission.test-helpers.tssrc/agents/subagents/registry/subagent-registry-lifecycle-completion.test-support.tssrc/agents/subagents/registry/subagent-registry-lifecycle-wake.retry.test.tssrc/agents/subagents/registry/subagent-registry-lifecycle.test.tssrc/agents/subagents/registry/subagent-registry-sweeper-recovery.test.tssrc/agents/subagents/registry/subagent-registry.announce-loop-guard.test.tssrc/agents/subagents/registry/subagent-registry.lifecycle-retry-grace.e2e.test.tssrc/agents/subagents/registry/subagent-registry.lifecycle-waits.test-support.tssrc/agents/subagents/registry/subagent-registry.persistence.resume.test.tssrc/agents/subagents/registry/subagent-registry.persistence.test-support.tssrc/config/sessions/session-accessor.sqlite-archive-read.test.tssrc/config/sessions/session-accessor.test.tssrc/config/sessions/session-transcript-match.worker.test.tssrc/cron/service.stale-family.test.tssrc/cron/service/ops.run-admission-cleanup.test.tssrc/cron/service/ops.run-admission.test.tssrc/cron/service/owner-hardening.test.tssrc/cron/service/run-admission.lost-queued.test.tssrc/cron/service/run-admission.responsiveness.test.tssrc/cron/service/run-admission.worker.test.tssrc/cron/service/run-recovery.settlement.test.tssrc/gateway/agent-turn/agent-run-dispatch.legacy.test.tssrc/gateway/server-claws-monitors.test.tssrc/gateway/server-cron.test.tssrc/gateway/session-message-events.test.tssrc/gateway/session-utils.queued-collector-admission.test.tssrc/sessions/background-session-result.test.tssrc/tasks/detached-task-lookup.worker.test.tssrc/tasks/task-registry.store.test.tstest/helpers/cron/runtime-mutation.tstest/vitest/vitest.database-worker-core-paths.mjs