Repository navigation
refactor(agents): persist message-tool-only run outcomes in workers - #164112
Conversation
Move durable outcome recording and bounded pruning to the canonical agent writer, retaining captured store identity, FIFO, live admission, and joined settlement. Preserve separately committed lazy schema preparation and SQLite error metadata through the existing domain error codec. Await recording on successful and failed turns without replaying model or tool actions. Incognito keeps its existing native owner; schemas, retention, and outcome semantics are unchanged.
|
🦞👀 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:14 AM ET / 08:14 UTC (Revision 6). ClawSweeper reviewWhat this changesMove completion recording and history pruning for agent turns that reply through message tools into the existing database writer worker, awaiting settlement before returning. Warning SQLite table change This PR modifies persisted SQLite tables in Merge readiness✅ Ready for maintainer review This PR remains useful: the pinned current main still records outcomes synchronously. No introduced correctness or security defect was found, and the prior compatibility concern is resolved. Priority: P2 Review scores
Verification
How this fits togetherThe agent runner records whether a message-tool-only turn delivered a reply and how execution ended. The outcome store writes these operational facts into the agent’s SQLite database and bounds their history. flowchart TD
A[Completed agent turn] --> B[Capture outcome and store]
B --> C{Incognito session?}
C -->|Yes| D[Process-held database owner]
C -->|No| E[Existing agent writer queue]
E --> F[Worker admission and transaction]
F --> G[Record outcome and prune history]
D --> G
G --> H[Await settlement and return]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +273, Tests +185, Docs +10, Other +1. Total +469 across 11 files. View PR surface stats
Review metricsNone. Stored data modelPersistent data-model change detected: Technical reviewBest possible solution: Keep one canonical worker writer for durable outcomes, preserving existing retention, warning semantics, and process-held incognito ownership. Do we have a high-confidence way to reproduce the issue? Not applicable as a user-facing bug reproduction: current-main source directly establishes synchronous outcome insertion and pruning. The submitted tests target the worker cutover; this review did not execute them. Is this the best way to solve the issue? Yes: the patch uses the existing reader, writer queue, executor, and error codec while preserving the storage contract, avoiding a competing persistence owner. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 416022651103. 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 (5 earlier review cycles)
|
Resolve the worker-access documentation overlap by retaining both the message-tool outcome and sandbox-browser descriptions. The source and test delta against the new main baseline has the same stable patch ID as the reviewed e683794 change. Preserve the completed P2 review; docs formatting and diff checks pass.
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Merged via explicitly authorized admin squash with attributed pre-existing CI failures.
|
…penclaw#164112) Move durable outcome recording and bounded pruning to the canonical agent writer, retaining captured store identity, FIFO, live admission, and joined settlement. Preserve separately committed lazy schema preparation and SQLite error metadata through the existing domain error codec. Await recording on successful and failed turns without replaying model or tool actions. Incognito keeps its existing native owner; schemas, retention, and outcome semantics are unchanged.
What Problem This Solves
Message-tool-only turns recorded completion facts and pruned their history synchronously on the Gateway thread, on both success and failure.
Solution
Move durable recording into a narrow domain adapter on the canonical per-agent writer broker. Store discovery uses the existing read worker; captured physical identity and lifecycle custody survive queue waits. Schema preparation still commits separately before insertion, and each transaction and commit rechecks current host authority. Both terminal callers await recording and cleanup. Confirmed rollback errors use the existing error codec; uncertain outcomes never replay the model or tool action.
Impact
Outcome semantics, best-effort warnings, occurred-at/id ordering, the 10,000-row bound, schemas, durability, and update behavior are unchanged. Incognito side data retains its existing process-held owner. No migration or operator action is required, and the diff adds zero new
OPENCLAW_*names.Production: +326 / −53 / net +273, 379 changed lines; tooling registration: +1. The extra size beyond the initial estimate handles configured-store discovery/custody and preserves SQLite error details.
Released SDK surface check: compared the recorder functions and schema helper with v2026.9.8 and checked
src/plugin-sdk/**,api.runtime.*, and documented SDK subpaths. All are internal-only;executeAgentTurnalready returns a Promise. No released synchronous contract or compatibility adapter changes.Recent overlaps were checked before editing. #131772, #138084, #118359, and #127091 modify adjacent internal runner functions, while this change only awaits recording in the outer completion wrapper. #160908 adds an independent runtime-worker registration. No same-goal or same-function authority overlap was found.
Evidence
prepare/execfor canonical and custom stores, FIFO against other writes, captured input/environment, close refusal, lazy schema installation, retention ties, native error metadata, and incognito ownership. Final standalonepnpm test src/infra/message-tool-run-outcome-store.test.ts --maxWorkers=1: 306.51 s wall, 23.342 s test bodies, including worker-build startup.pnpm test src/auto-reply/reply/agent-runner-execution-message-tools.test.ts --maxWorkers=1: 155.41 s wall, 14.463 s test bodies. Unknown persistence outcomes preserve both the successful turn and the original execution failure without replay.kind: "success"adapter; the corrected message-tool file passed the standalone run above.errcodeduring worker transport and passes with the domain error envelope.node scripts/check-changed.mjs --base 805a5bea2dd702327752dc29980b503f58908083: passed.pnpm check:madge-import-cycles: 0 cycles.pnpm check:database-worker-ratchet --base 805a5bea2dd702327752dc29980b503f58908083: passed. Env-name budget: 477/477.node --import ./scripts/tsx.mjs scripts/build-all.mts qaRuntime, the profile used byworktree-setup gateway): passed (527.51 s wall). This build preceded the final callback-binding lint correction; the final store test rebuilt and exercised the corrected worker. Runtime and compiled test-worker entrypoints derive from the existing runtime registry; the new adapter is outside the compiled PR-wrapper closure. The broader default build was intentionally stopped during unrelated package declaration generation; full-package declaration proof is not claimed.No live Gateway latency benchmark was run. Hosted CI results will attach after publication.
Landing verification
The original reviewed head was
e6837944a6f5d65319e542a8915183ef2e315ed5. Current main caused a real merge conflict only indocs/reference/database-schemas/worker-access.md; merge commit5747f2529aad6retains both adjacent storage-owner descriptions. The source and test delta has identical stable patch IDf740d03bbe7d4027cd132359d4c9efe5b18c3601before and after the merge. No production fix or SDK change was introduced; the completed clean P2 autoreview remains valid for that unchanged patch. Docs formatting and whitespace checks passed. Current-head ClawSweeper completed at 2026-10-03 08:00 UTC with no findings or before-merge items. Current-head hosted build/declarations passed (run37107985347). CI run37107985458 attempt1 finished with60 successful jobs,20 skipped and only the independently inherited test root111160312495 plus aggregate111161423534 failing. The exact tested merge6c187b49 has main parent efcd9ff and PR parent5747f252; its merge tree and five unchanged causal source files were verified. Landing uses the explicitly authorized native inherited-failure exception and does not represent this CI result as green.The original head's hosted build and SDK declaration generation passed: https://github.com/openclaw/openclaw/actions/runs/37105041593. ClawSweeper's exact-head re-review at 2026-10-03 07:13 UTC reported no findings or before-merge items and explicitly resolved the prior compatibility concern. The outcome table/index DDL is byte-identical in
v2026.9.8, merge base805a5bea, and the reviewed source (SHA-2561a22cabaeeae511a365ab43c0a15e1b3b98d30d79b743159737ee2b4aa44ba54). Existing same-version/lazy-schema tests cover first-use installation and persisted facts; no migration is required.Original CI run 37105041676 failed its changed test shard and aggregate. All ten failures in
run.prepared-harness-source-delivery.integration.test.tsmatch scheduled main: https://github.com/openclaw/openclaw/actions/runs/37104630519/job/111150766778. Main commit0c96fd043ab36addedresolveRootedRunRuntimeWorkspacewithout updating the complete workspace mock. The five causal files are untouched by this PR and byte-identical between that main run and the tested PR merge baseline; failure occurs before outcome persistence. This is historical inherited-failure attribution, not passing current-head CI.The requested comparison passed all ten tests in each of five sequential runs on both original head
e6837944and merge base805a5bea, singly withnode scripts/run-vitest.mjs src/agents/embedded-agent-runner/run.prepared-harness-source-delivery.integration.test.ts --maxWorkers=1. Head wall times: 247.231, 134.983, 58.727, 37.827, 45.877 seconds; base: 77, 46, 53, 69, 115 seconds. These passes do not claim the later main regression is fixed. The initial PR-context failure was corrected by using the required problem heading; its replacement check passed.