Skip to content

refactor(agents): persist message-tool-only run outcomes in workers - #164112

Merged
steipete merged 2 commits into
mainfrom
dbasync/msgoutcome
Oct 3, 2026
Merged

steipete merged 2 commits into
mainfrom
dbasync/msgoutcome

Conversation

@steipete

@steipete steipete commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

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; executeAgentTurn already 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

  • Durable selected-path T1 exposure: 3 → 0. The conservative global inventory remains 1,333 → 1,333, because the shared incognito kernel still accounts for two SQL calls and its native wrapper for one. No mixed module was relabeled worker-only.
  • Store tests: 7 passed; zero caller-thread SQLite prepare/exec for 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 standalone pnpm 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.
  • Runner message-tool tests: 10 passed with 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.
  • Runner lifecycle sibling: 34 passed, 34.658 s test bodies, in the focused three-file invocation; its shared auto-reply shard took 135.57 s. That run exposed a test-only expectation of the raw result instead of the harness's kind: "success" adapter; the corrected message-tool file passed the standalone run above.
  • The caller-SQL regression failed on the original implementation at its insert. A further regression exposed lost SQLite errcode during 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.
  • Independent Codex autoreview, high reasoning and fast service, pinned to that merge base and including owner-contract evidence: scoped-clean through P2, no actionable findings.
  • Gateway build (node --import ./scripts/tsx.mjs scripts/build-all.mts qaRuntime, the profile used by worktree-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 in docs/reference/database-schemas/worker-access.md; merge commit 5747f2529aad6 retains both adjacent storage-owner descriptions. The source and test delta has identical stable patch ID f740d03bbe7d4027cd132359d4c9efe5b18c3601 before 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 base 805a5bea, and the reviewed source (SHA-256 1a22cabaeeae511a365ab43c0a15e1b3b98d30d79b743159737ee2b4aa44ba54). 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.ts match scheduled main: https://github.com/openclaw/openclaw/actions/runs/37104630519/job/111150766778. Main commit 0c96fd043ab36 added resolveRootedRunRuntimeWorkspace without 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 e6837944 and merge base 805a5bea, singly with node 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.

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.
@clawsweeper

clawsweeper Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation scripts Repository scripts size: L labels Oct 3, 2026
@steipete

steipete commented Oct 3, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 3, 2026
@clawsweeper

clawsweeper Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper

clawsweeper Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 3, 2026, 4:14 AM ET / 08:14 UTC (Revision 6).

ClawSweeper review

What this changes

Move 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 src/state/openclaw-agent-message-tool-outcome-schema.ts. Prefer a design that avoids changing persisted SQLite tables. Migration or upgrade compatibility proof is recorded, but maintainers should still confirm that the schema change is necessary.

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
Reviewed head: 5747f2529aad6e02c36e5e04c97e39a6dbf4ed39

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, maintainable worker cutover with meaningful boundary coverage and no actionable introduced defect.
Proof confidence 🌊 off-meta tidepool Not applicable: The supplied MEMBER classification exempts this internal refactor from external-contributor runtime proof. Real SQLite-worker tests exercise the changed store boundary, with runner mocks providing supplemental no-replay coverage; no live Gateway latency result is claimed. Released DDL and unchanged row semantics establish compatibility without migration.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The supplied MEMBER classification exempts this internal refactor from external-contributor runtime proof. Real SQLite-worker tests exercise the changed store boundary, with runner mocks providing supplemental no-replay coverage; no live Gateway latency result is claimed. Released DDL and unchanged row semantics establish compatibility without migration.
Evidence reviewed 9 items Pinned introduced change: Reviewed the complete merge-base-to-head diff. The production and schema-helper files also remain unchanged from the earlier reviewed head; previous review findings were empty.
Still necessary on pinned main: The fetched main implementation still opens the database and synchronously inserts and prunes outcomes. The supplied related PRs address cancellation, privacy, compaction, and reload behavior rather than this persistence cutover.
Current authority and settlement: The adapter retains discovery custody and captured physical identity, uses the canonical writer queue, and joins cleanup. The worker requests current authority before mutation and immediately before commit; uncertain native work is not converted into a replayable domain failure.
Findings None None.
Security None None.

How this fits together

The 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]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +273, Tests +185, Docs +10, Other +1. Total +469 across 11 files.

View PR surface stats
Area Files Added Removed Net
Source 7 326 53 +273
Tests 2 194 9 +185
Docs 1 10 0 +10
Config 0 0 0 0
Generated 0 0 0 0
Other 1 1 0 +1
Total 11 531 62 +469

Review metrics

None.

Stored data model

Persistent data-model change detected: database schema: src/state/openclaw-agent-message-tool-outcome-schema.ts. Migration or upgrade compatibility proof is recorded; maintainers should verify it before merge.

Technical review

Best 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.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: This bounded internal persistence improvement removes synchronous SQLite work from agent completion without changing user-facing capabilities.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The supplied MEMBER classification exempts this internal refactor from external-contributor runtime proof. Real SQLite-worker tests exercise the changed store boundary, with runner mocks providing supplemental no-replay coverage; no live Gateway latency result is claimed. Released DDL and unchanged row semantics establish compatibility without migration.

Evidence

What I checked:

  • Pinned introduced change: Reviewed the complete merge-base-to-head diff. The production and schema-helper files also remain unchanged from the earlier reviewed head; previous review findings were empty. (5747f2529aad)
  • Still necessary on pinned main: The fetched main implementation still opens the database and synchronously inserts and prunes outcomes. The supplied related PRs address cancellation, privacy, compaction, and reload behavior rather than this persistence cutover. (src/infra/message-tool-run-outcome-store.ts:44, 416022651103)
  • Current authority and settlement: The adapter retains discovery custody and captured physical identity, uses the canonical writer queue, and joins cleanup. The worker requests current authority before mutation and immediately before commit; uncertain native work is not converted into a replayable domain failure. (src/infra/message-tool-run-outcome-store.worker.ts:47, 5747f2529aad)
  • Both terminal callers await recording: Success and failure paths await the recorder. Persistence failures remain warnings, preserving the successful result or original execution error without repeating model or tool actions. Reference inspection found no additional production recorder callers or SDK exports. (src/auto-reply/reply/agent-runner-execution.ts:650, 5747f2529aad)
  • Released storage compatibility: The released outcome table and index match the reviewed source. The introduced diff changes neither schema SQL, schema version, nor generated row types; insertion fields, retention ordering, and the 10,000-row bound remain intact. No migration is required. (src/state/openclaw-agent-schema.sql:537, fc23bc864e45)
  • Focused regression coverage: Read the complete changed tests and applied test-audit guidance. Storage coverage exercises real SQLite persistence, caller-thread SQL refusal, FIFO ordering, captured inputs, close refusal, lazy installation, retention ties, native error metadata, and incognito ownership. Runner coverage independently protects failure settlement without replay. The body reports seven storage and ten runner tests passing; no tests were executed during this read-only review. (src/infra/message-tool-run-outcome-store.test.ts:33, 5747f2529aad)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (5 earlier review cycles)
  • reviewed 2026-10-03T07:07:14.277Z sha e683794 :: blocked before merge. :: none
  • reviewed 2026-10-03T07:13:18.659Z sha e683794 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-03T07:22:44.911Z sha e683794 :: blocked before merge. :: none
  • reviewed 2026-10-03T07:36:17.227Z sha e683794 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-03T08:00:20.480Z sha 5747f25 :: needs maintainer review before merge. :: none

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.
@steipete

steipete commented Oct 3, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@steipete
steipete merged commit fe0a4bd into main Oct 3, 2026
146 of 151 checks passed
@steipete
steipete deleted the dbasync/msgoutcome branch October 3, 2026 08:21
@steipete

steipete commented Oct 3, 2026

Copy link
Copy Markdown
Contributor Author

Merged via explicitly authorized admin squash with attributed pre-existing CI failures.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 4, 2026
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. scripts Repository scripts size: L status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant