Repository navigation
refactor(acp): persist parent-stream diagnostic batches through the agent writer - #164454
Conversation
…gent writer Move durable diagnostic sequence allocation and ordered batch insertion into the canonical per-agent worker. Retain bounded relay buffering, confirmed-refusal retries, unknown-outcome non-replay, and accepted settlement through Gateway close. Keep run-ID relay replacement immediate.
|
🦞👀 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. |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Codex review: needs maintainer review before merge. Reviewed October 3, 2026, 4:27 PM ET / 20:27 UTC (Revision 6). ClawSweeper reviewWhat this changesMoves ACP child-agent stream diagnostics into the existing agent database writer and joins accepted writes during Gateway shutdown. Merge readiness✅ Ready for maintainer review This work remains necessary on current main. Both earlier findings are resolved, and the updated evidence addresses the previous comparison request; no new actionable patch defect was found. Priority: P2 Review scores
Verification
How this fits togetherThe ACP parent-stream relay receives child-agent runtime events and sends progress to the parent conversation. Its diagnostic recorder separately stores ordered events in the child’s agent database. flowchart TD
A[Child runtime events] --> B[Parent stream relay]
B --> C[Parent progress]
B --> D[Bounded diagnostic buffer]
D --> E[Agent writer admission]
E --> F[Atomic ordered database batch]
G[Gateway shutdown] --> B
G --> H[Join accepted persistence]
H --> F
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +189, Tests +361, Docs +10, Other +1. Total +561 across 16 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep diagnostic persistence under the canonical agent writer, preserving bounded buffering, atomic ordering, conservative retry, and shutdown settlement. Do we have a high-confidence way to reproduce the issue? Yes, source establishes that current-main relay flushes enter a synchronous SQLite transaction; the supplied boundary regression reports failure on the original caller-thread BEGIN IMMEDIATE. This review performed source inspection only. Is this the best way to solve the issue? Yes, reusing the existing agent writer and Gateway resource host is a focused cutover that preserves the storage format and avoids a competing persistence owner. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 28a6f71449aa. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (5 earlier review cycles)
|
Keep rollback backoff intact when diagnostic events arrive during an in-flight write. Register the ACP adapter under the loader-required worker export contract. The deferred-write regression fails before the timer fix; all 32 relay tests and 54 export guard tests pass. P2 review is clean.
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Merged via explicitly authorized admin squash with attributed pre-existing CI failures.
|
…gent writer (openclaw#164454) * refactor(acp): persist parent-stream diagnostic batches through the agent writer Move durable diagnostic sequence allocation and ordered batch insertion into the canonical per-agent worker. Retain bounded relay buffering, confirmed-refusal retries, unknown-outcome non-replay, and accepted settlement through Gateway close. Keep run-ID relay replacement immediate. * fix(acp): retain source guard binding and await relay test cleanup * fix(acp): preserve diagnostic retry backoff and register worker Keep rollback backoff intact when diagnostic events arrive during an in-flight write. Register the ACP adapter under the loader-required worker export contract. The deferred-write regression fails before the timer fix; all 32 relay tests and 54 export guard tests pass. P2 review is clean.
What Problem This Solves
ACP parent-stream diagnostic flushes execute SQLite transactions on the Gateway caller thread. Moving them asynchronously also needs explicit shutdown settlement and must not replay a batch whose commit outcome is unknown.
Why This Change Was Made
Bind a typed diagnostic adapter to the canonical per-agent writer. Capture the child, run, and physical database before yielding; serialize diagnostics before dispatch; allocate sequence numbers and insert each ordered batch in one synchronous worker transaction with current transaction/commit grants.
The relay keeps its 256-event pending buffer, flush thresholds, retry backoff, and warning bounds, with one batch in flight. Only confirmed rollback or canonical pre-execution refusal can retry. Disposal seals admission synchronously and joins accepted persistence through the existing Gateway resource host before database transports close. Run-ID replacement installs the next relay immediately, without waiting for diagnostic cleanup.
User Impact
No schema, retention, durability, configuration, SDK surface, or update migration changes. Diagnostic failures remain isolated from child execution and parent progress. The superseded synchronous writer is removed; all runtime callers use the worker-backed recorder. There are no retained host SQL authority reads in this lane.
Production diff: +298 / -109 / net +189 (407 changed lines), excluding tests, docs, and test routing. Static inventory: T1 1,233 → 1,230, with no classification override and zero new
OPENCLAW_*names. Proof base:4ab382220e2cca1deedb2c2549982f91c0fb5c64.Evidence
prepare/execcalls and 100 ordered durable events. The same regression failed on the original source at caller-threadBEGIN IMMEDIATE(32.07 s wall).server.close()order: 101 accepted/buffered events persist before database teardown; events after the close prelude are refused. One Gateway boot; 96.71 s file duration / 48.00 s test time on the loaded host. This real lifecycle boundary cannot be established by the cheaper store or mocked relay tests.pnpm test <five files> --maxWorkers=1, 228.21 s wall. Recorder file 10.04 s, archive file 90.58 s, three agent files together 94.30 s. Covers FIFO, captured inputs, malformed diagnostics, atomic rollback, native error details, unknown-outcome non-replay, disposal settlement, and immediate relay replacement.test/scripts/runtime-process-build-graph.test.ts,src/auto-reply/reply/get-reply.imports.test.ts,src/worker/worker.runtime-imports.test.ts, andtest/scripts/eager-import-closure.test.ts: 31 tests passed. Group durations: 7.03 s, 10.61 s, and 54.50 s. The compiled-wrapper inventory is closed; the new adapter is registered in the runtime-process build inventory.pnpm build qaRuntime): passed, 537.88 s wall, including artifact-lock wait; actual build phases took 123.3 s. The broader full build completed package and main JavaScript compilation but was intentionally stopped during unrelated bundled-plugin declaration generation. No full-build pass is claimed.latestandbetaboth resolve to2026.9.8; the released SDK does not export the removed diagnostic writer or relay handle.Released-SDK comparison obtained:
pnpm plugin-sdk:api:diff -- --base v2026.9.8 --head 5d3fb7a898880adbaa2e048e06febe0651ecec5dproduced a checked report and evidence JSON after using a realpath-resolvedTMPDIRandRUNNER_TEMP. Base commit:fc23bc864e4553c2d215e479eeec47b67a0bf943; report digest:c7d46b0bc9f01609c049a2947042b5040635ea76dedff6b557ca56f0108c195f. The release-to-head report includes existing mainline SDK drift (8 removed subpaths, 1 added, 2,219 affected exports), not a claim of a globally unchanged SDK. This PR changes nosrc/plugin-sdk,api.runtime, package export, or documented SDK subpath surface. The removed recorder and changed relay handle are internal-only; none of the changed ACP symbols appears in the report, so this patch requires no released-signature compatibility adapter.node scripts/check-changed.mjs --base 4ab382220e2cca1deedb2c2549982f91c0fb5c64 -- src/agents/subagents/spawn/acp-parent-stream-store.sqlite.ts src/agents/subagents/spawn/acp-spawn-parent-stream.test.tspassed after the lint corrections (2344.08 s wall), including core and all 27 test type graphs, targeted core lint, and every selected static guard.pnpm lint:scriptsalso passed, covering the routing inventories. The initial whole-PR check found only the corrected unbound callback and floating test disposal errors; its unchanged-file lint evidence and earlier checks are retained. The corrections are committed in8f951b3594105ca35f53e65f3e0471c5fedf882c; fresh P2 review of the resulting source is clean. The corrected-head CI relay-boundary test took 0.488 s; the local wall times above are not CI measurements. Other individual test durations were not separately extracted from the shared CI shards.Overlap: #164269 is incidental normalization cleanup in the relay; #162433 is the explicitly deferred umbrella ownership draft. This change uses minimal persistence/lifecycle hunks and does not adopt either restructuring. No competing diagnostic persistence migration was found.
Landing repairs and CI attribution
5d3fb7a898880adbaa2e048e06febe0651ecec5daddresses both actionable ClawSweeper findings. The relay replaces an ordinary flush timer when establishing rollback backoff, including when traffic arrives during a pending write. Its existing retry test now fails on the unfixed source (expected one write, observed two before the retry deadline) and passes with the fix. The new ACP adapter is also registered in the scanner's existing fixed-protocol family; the worker loader requires the exactbindSqliteWorkerBackendexport.All 32 relay tests pass (523.20 s command wall time; 321.33 s Vitest file duration, dominated by worker compilation on the loaded host), and all 54 export-name guard tests pass (8.55 s command wall time). The export-name collision guard passes. Fresh Codex autoreview through P2 is clean for the complete staged candidate. The PR-body template heading failure was corrected.
Initial CI run 37144854704 had the PR-caused export registration failure and a separate inherited Linux Doctor/NOCOW teardown failure:
src/flows/doctor-health.nocow.test.ts, “joins Doctor's inspection child and database handles before rewriting both stores,” fails while releasing an agent lease under offline maintenance. The same failure and stack occur on main in job 111264313536. This PR does not change that test, Doctor maintenance, or lease/lifecycle owners. An isolated local Node 24.21 container completed all requested repetitions after remote capacity failures. Doctor reproduces the same CI failure 5/5 on the PR head, 5/5 on the merge base, and 5/5 on CI main7e3ba7f. No CI rerun was sent.Final-head boundary confirmation: hosted CI observed 100 ordered diagnostic events with zero caller-thread SQL (
acp-parent-stream.worker-boundary.test.ts, 488 ms). The real Gateway close regression passed again locally on5d3fb7a8: 101 accepted events remained durable after all database transports closed, while the late event was refused (241.93 s command wall / 183.24 s Vitest / 56.79 s test). ClawSweeper completed the corrected head at 2026-10-03 19:15 UTC with no actionable correctness findings; its only remaining item was the now-obtained SDK report.The corrected-head CI run 37146925267 passed source contracts and all other selected jobs except two Node roots and their aggregate gate; no jobs were cancelled. Besides Doctor/NOCOW, the snapshot-diagnostics assertion failed on CI's synthetic merge
0373aa48d9c12bbd9c7798fb1b7fa7296037a1d9. Its base, main7e3ba7f(#162258), introduced the exact aggregate error text that omits filesystem guidance when snapshot cleanup also fails. That message is absent from this PR head and its merge base, and the test does not reach the ACP worker. Independent execution on current mainfe6414a23399eb97b40af76e2ba2cc70b28ba5bcreproduced the exact snapshot assertion, aggregate message, anderrcode=778in all five runs. The relevant test, snapshot, retirement, and formatting sources are identical between CI baseline7e3ba7fand that main checkout. The Linux comparison matrix is complete: snapshot diagnostics passes 5/5 on the PR head and 5/5 on the merge base, then fails with the exact CI assertion and message 5/5 on CI main7e3ba7f. All 30 runs were single-file invocations with--maxWorkers=1; the container used fresh pinned public checkouts and no host credentials. Both failed CI roots are independently attributed to main in untouched files, and are retained as failures in the native admin evidence rather than relabeled as green.