Skip to content

refactor(heartbeat): run outcome queries in the agent database worker - #147463

Merged
steipete merged 4 commits into
mainfrom
codex/agent-database-heartbeat-worker
Sep 20, 2026
Merged

steipete merged 4 commits into
mainfrom
codex/agent-database-heartbeat-worker

Conversation

@steipete

@steipete steipete commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

Related: #144592. Builds on the foundation in #153150 and fixture isolation in #153286, both landed on main. This PR targets main. Shared fixture fixes are now covered on main by #153338 and #153296; neither remains in the focused merge diff.

What Problem This Solves

Silent heartbeat outcomes and next-user claims perform their heartbeat queries on the Gateway thread even though callers await the API.

User Impact

File-backed heartbeat persistence and claims execute on the canonical agent database worker while preserving bounded context, claim retries, FIFO ordering, and current run authority. Existing outcome rows remain readable across upgrades and rollback; there are no schema, retention, permission, config, or external SDK changes.

Why This Change Was Made

The consumer binds complete heartbeat operations to the existing worker connection and captures file-backed database lifecycle before queueing, so queued work cannot reopen an agent after close. The foundation owns commit permission repair and worker retirement. Incognito keeps its sole in-memory owner and admission queue. Cold bootstrap, custom-store target resolution, coordination SQL, and close remain host-owned; this is not an all-SQL-off-thread claim.

Real worker consumers now run in the existing fork test lane, with their previous routes removed from both focused and full-suite selection while preserving watch ownership. Fixture cleanup awaits owned agent/state paths before deletion. The terminal-cleanup fixture joins its real requester-settlement dependency and restores its test overrides even when an assertion fails.

Evidence

On the landed-foundation composition, 199 consumer tests, 974 routing controls, and the nested MCP retention test passed. The complete 137-case shared suite was replayed in its original order after reproducing its first cleanup failure. Active, revoked, and replaced ownership checks pass unchanged. The nested test retains its fresh module cache, single-worker ordering, shared scope, and original 180-second deadline. Types, lint, repository guards, growth/assertion checks, and fresh independent review through P2 passed.

Real SQLite regression proof fails on original caller-thread heartbeat SQL and passes with the worker consumer. Genuine incognito evidence checks the canonical key, symbol database identity, empty native filename, and absent disk files. Permission controls preserve rollback on authority or permission refusal; all 40 exact export-policy guards passed.

Retained ordinary-build and compiled proof calibrates all eight native SQLite methods, exercises actual next-user context, and records zero caller SQLite calls for warm persistence and claims. Every measured application phase records zero caller-thread Atomics.wait; the late-bound backend matches its build artifact hash. FIFO retries retain one coordinator call, cold bootstrap/close work stays explicit, and durable readback matches the claimed outcome. These results retain their original source bindings. The three persistence/kernel/backend production modules remain unchanged; the runtime registry preserves both main's workspace-memory worker and the heartbeat worker. The prior composition passed exact-head hosted CI; the actual-main Boards carry has now passed its own run.

The cached-filtered full-suite ownership audit now reports no missing or duplicate tests, and all 24 dispatch-recovery cases pass solely under the database-worker project. The final CI repair uses the canonical registry exclusion in auto-reply-core; its root types, typed lint, formatting, and independent P2 review pass. The unrelated exec notification-prefix flake is repaired separately in #153338 and consumed here unchanged.

The current-main reconciliation retains both worker descriptors unchanged. Fresh worker/entrypoint controls (24 cases) and the full-suite ownership invariant pass after that union; dependency manifests are unchanged. Packaging remains covered by the new exact-head CI run.

The subsequent test-registry union keeps all three outbound-loopback routes from #153076 and all nine Heartbeat routes. All 318 project-configuration and worker-registry controls pass afterward; this carry leaves the reviewed Heartbeat production files unchanged.

The ACK worker fixture cleanup was reviewed separately in #153367 and is now covered by #153296 on main. The merge preserves the complete canonical fixture, including explicit null/undefined rejection after deletion and the claimless no-op assertion. All four composed worker cases passed; no delivery authority or production changes are included in that fixture repair.

Prior hosted CI completed successfully with 156 jobs finished and no failures for commit c32515101310e93363ec03ac9cff9af645a3a7c5: CI run. The observer joined successfully; no failed-job rerun was used.

The latest main reconciliation preserves main’s active-node reset inside the asynchronous CLI fixture cleanup, including the awaited database cleanup. The former-fast routing map retains both main’s isolated cleanup owner and Heartbeat’s private-transcript owner. The three Heartbeat production modules are byte-identical to the prior green head; the worker descriptor remains additive. Independent review through P2 accepted the complete composed branch.

For the two test-conflict resolutions, all 1,302 routing/project controls and all 185 CLI preparation and fixture cases passed; selected type, lint, and repository checks passed. The subsequent descriptor union preserves main’s workspace-skills worker and the Heartbeat worker unchanged. Another 330 worker-launch, routing, and full-suite ownership controls passed on that final carry. The earlier green run is retained as historical evidence; the previous successor has its own successful hosted run.

Current-main CI exposed three moved CLI durable-context cases still routed to a threaded test project. The normal wrapper reproduced the same three host-owner admission failures while eight sibling cases passed. Adding the file to the canonical database-worker registry moves it into the existing fork project and removes its former route through the shared exclusion. All 11 unchanged cases now pass, along with 319 registry/full-suite ownership controls. Independent review through P2 accepted this one-line routing repair; no production guard, mock, assertion, timeout, or baseline changed.

Prior hosted CI completed successfully with 156 jobs finished and no failures for commit d0744c3fe74f7e0b9ad419386d75e1c6003db100: CI run. The exact-head observer joined successfully, and the completed review reports no findings or before-merge blockers.

The actual-main carry onto landed Boards #153159 preserves both worker descriptors, including every existing source and packaged path. The seven Boards and Heartbeat production modules remain byte-identical to their qualified owners. All 35 focused worker and registry controls pass, the full-suite ownership audit passes, and fresh independent review through P2 is clean. Earlier runtime/build evidence retains its original source bindings; this additive registry carry passed exact-head CI.

The actual-main Boards carry completed CI run 35495824797 successfully at be5de88a606337731f8ad190b664031bc1a3baeb, with 156 jobs finished and no failures. The exact-head observer joined cleanly.

@clawsweeper

clawsweeper Bot commented Sep 13, 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 gateway Gateway runtime cli CLI command changes agents Agent runtime and tooling size: XL maintainer Maintainer-authored PR labels Sep 13, 2026
@steipete
steipete marked this pull request as ready for review September 13, 2026 21:52
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Sep 13, 2026
@clawsweeper

clawsweeper Bot commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 20, 2026, 3:56 AM ET / 07:56 UTC (Revision 13).

ClawSweeper review

What this changes

Moves disk-backed heartbeat outcome storage and next-user context claims into the shared agent database worker, with matching test routing and asynchronous fixture cleanup.

Merge readiness

✅ Ready for maintainer review

This remains useful: current main retains caller-thread heartbeat queries, and the merged queue-admission repair does not replace this worker migration. No actionable introduced defect was found.

Priority: P2
Reviewed head: be5de88a606337731f8ad190b664031bc1a3baeb

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused worker cutover with meaningful lifecycle coverage, successful exact-head CI, and no actionable findings.
Proof confidence 🌊 off-meta tidepool Not applicable: The author is a verified repository admin, so ordinary contributor proof is exempt. The captured body reports compiled persistence and next-user claims with zero warm caller-thread SQLite calls; source inspection found no unresolved authority-chain concern requiring additional proof.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The author is a verified repository admin, so ordinary contributor proof is exempt. The captured body reports compiled persistence and next-user claims with zero warm caller-thread SQLite calls; source inspection found no unresolved authority-chain concern requiring additional proof.
Evidence reviewed 9 items Current main still needs the migration: Fetched main still executes heartbeat selection, insertion, and claim updates inside caller-thread runOpenClawAgentWriteTransaction callbacks after queue admission.
Introduced lifecycle and worker cutover: The reviewed implementation captures disk lifecycle before queueing, uses the existing worker-store owner, drains its borrow, and retains the incognito native path. Extracted queries preserve existing row fields and claim semantics.
Authority and final commit: The backend requests transaction and commit admission; the existing worker-store bridge rechecks captured run and database authority for those grants. The canonical executor retains physical-file validation and pre-commit permission repair.
Findings None None.
Security None None.

How this fits together

Heartbeat outcomes preserve silent background progress for the next user turn. The store accepts outcomes and claim requests, coordinates access to the agent database, and returns bounded model context.

flowchart TD
  A[Silent heartbeat outcome] --> C[Heartbeat outcome store]
  B[Next user turn] --> C
  C --> D{Database kind}
  D -->|Disk| E[Shared agent worker and live admission]
  D -->|Incognito| F[Existing in-memory owner]
  E --> G[Stored outcome and single-run claim]
  F --> G
  G --> H[Bounded model context]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +145, Tests +162, Other +1. Total +308 across 22 files.

View PR surface stats
Area Files Added Removed Net
Source 4 249 104 +145
Tests 17 262 100 +162
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 1 0 +1
Total 22 512 204 +308

Review metrics

Metric Value Why it matters
Growth justification Production +145 net lines; tests/support +162; tooling +1 Production growth separates the reusable query kernel from the worker adapter while retaining one canonical database lifecycle owner.

Root-cause cluster

Relationship: partial_overlap
Canonical: #144592
Summary: This PR implements the heartbeat lane of the broader asynchronous-storage program.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Technical review

Best possible solution:

Use the canonical agent worker for disk-backed heartbeat operations while preserving existing data, FIFO ordering, live authority, and incognito ownership.

Do we have a high-confidence way to reproduce the issue?

Not applicable as a functional bug reproduction: this is a worker migration, and current-main source directly confirms the remaining caller-thread queries.

Is this the best way to solve the issue?

Yes. Reusing the landed worker owner and preserving the existing query and storage contracts is a focused, maintainable cutover.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against ef79fd7adfab.

Labels

Label justifications:

  • P2: This is a bounded runtime responsiveness improvement with no demonstrated emergency regression.
  • 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 author is a verified repository admin, so ordinary contributor proof is exempt. The captured body reports compiled persistence and next-user claims with zero warm caller-thread SQLite calls; source inspection found no unresolved authority-chain concern requiring additional proof.

Evidence

What I checked:

  • Current main still needs the migration: Fetched main still executes heartbeat selection, insertion, and claim updates inside caller-thread runOpenClawAgentWriteTransaction callbacks after queue admission. (src/infra/heartbeat-outcome-store.ts:139, ef79fd7adfab)
  • Introduced lifecycle and worker cutover: The reviewed implementation captures disk lifecycle before queueing, uses the existing worker-store owner, drains its borrow, and retains the incognito native path. Extracted queries preserve existing row fields and claim semantics. (src/infra/heartbeat-outcome-store.ts:165, be5de88a6063)
  • Authority and final commit: The backend requests transaction and commit admission; the existing worker-store bridge rechecks captured run and database authority for those grants. The canonical executor retains physical-file validation and pre-commit permission repair. (src/infra/heartbeat-outcome-store.worker.ts:35, be5de88a6063)
  • Behavioral regression coverage: Read coverage for FIFO/input capture, revoked claims remaining unclaimed, close preventing queued reopening, incognito avoiding disk files, retry ownership, and rejection of caller-thread heartbeat SQL. These tests were inspected, not executed during this read-only review. (src/infra/heartbeat-outcome-store.test.ts:52, be5de88a6063)
  • Verified introduction and merge boundaries: The complete merge-base delta was inspected. Raw test-merge parents match the pinned base followed by the exact PR head; its result contains the same introduced paths, including an additive heartbeat worker descriptor. (b653c745c884)
  • Related repair and feature history: History identifies the earlier asynchronous facade, queue-admission repair, and shared worker foundation. The supplied discussion explicitly distinguishes the merged queue repair at fix: avoid Gateway stalls when heartbeat writes wait on SQLite #152763 from this remaining migration. Some older blobs were unavailable for exact-line blame, so no introduction attribution is claimed. (src/infra/heartbeat-outcome-store.ts, 6bf8d0b6c738)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • fuller-stack-dev: 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 (12 earlier review cycles; latest 8 shown)
  • reviewed 2026-09-20T02:02:01.597Z sha bfd1aba :: blocked before merge. :: none
  • reviewed 2026-09-20T02:37:30.100Z sha ff4b89b :: needs maintainer review before merge. :: none
  • reviewed 2026-09-20T03:01:21.017Z sha c325151 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-20T04:45:59.553Z sha c325151 :: blocked before merge. :: none
  • reviewed 2026-09-20T05:17:14.472Z sha 9a81724 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-20T05:33:29.618Z sha d0744c3 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-20T06:09:29.422Z sha d0744c3 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-20T07:11:36.080Z sha be5de88 :: needs maintainer review before merge. :: none

@steipete
steipete force-pushed the codex/agent-database-heartbeat-worker branch from 6ab4e10 to 32ad14b Compare September 19, 2026 22:20
@openclaw-barnacle openclaw-barnacle Bot added extensions: memory-core Extension: memory-core scripts Repository scripts plugin: file-transfer and removed gateway Gateway runtime cli CLI command changes labels Sep 19, 2026
@steipete steipete changed the title refactor(sqlite): move disk heartbeat storage off the main thread refactor(heartbeat): run outcome queries in the agent database worker Sep 19, 2026
@steipete
steipete changed the base branch from main to codex/agent-foundation-protocol-policy-20260919 September 19, 2026 22:21
@clawsweeper clawsweeper Bot added 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. and removed proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. labels Sep 19, 2026
@clawsweeper clawsweeper Bot removed the status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. label Sep 19, 2026
Base automatically changed from codex/agent-foundation-protocol-policy-20260919 to main September 20, 2026 00:08
@steipete
steipete force-pushed the codex/agent-database-heartbeat-worker branch from 32ad14b to 158645c Compare September 20, 2026 01:00
@openclaw-barnacle openclaw-barnacle Bot added size: L and removed docs Improvements or additions to documentation extensions: memory-core Extension: memory-core plugin: file-transfer size: XL labels Sep 20, 2026
@steipete
steipete force-pushed the codex/agent-database-heartbeat-worker branch 3 times, most recently from c325151 to 9a81724 Compare September 20, 2026 05:09
…rker

Move file-backed persistence and next-user claims onto the canonical agent
SQLite worker while preserving FIFO order, captured inputs, claim retries,
and live transaction and commit authority. Capture lifecycle before queueing
so file-backed work cannot reopen a retired owner.

Keep incognito on its sole in-memory owner; cold bootstrap and coordination
remain separate native work. Let the foundation own permission repair.

Route actual worker consumers through the existing forked test lane and
await scoped fixture drainage before deleting state directories.

Related: #144592
Depends on: #153150
@steipete
steipete force-pushed the codex/agent-database-heartbeat-worker branch from d0744c3 to be5de88 Compare September 20, 2026 07:02
@steipete
steipete merged commit b7d37fd into main Sep 20, 2026
221 checks passed
@steipete
steipete deleted the codex/agent-database-heartbeat-worker branch September 20, 2026 08:05
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 21, 2026
…openclaw#147463)

* refactor(heartbeat): execute outcome queries in the agent database worker

Move file-backed persistence and next-user claims onto the canonical agent
SQLite worker while preserving FIFO order, captured inputs, claim retries,
and live transaction and commit authority. Capture lifecycle before queueing
so file-backed work cannot reopen a retired owner.

Keep incognito on its sole in-memory owner; cold bootstrap and coordination
remain separate native work. Let the foundation own permission repair.

Route actual worker consumers through the existing forked test lane and
await scoped fixture drainage before deleting state directories.

Related: openclaw#144592
Depends on: openclaw#153150

* test(heartbeat): route worker consumers and join requester settlement

* test(heartbeat): exclude worker consumers from auto-reply core

* test(heartbeat): route moved durable context cases through worker owner
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling maintainer Maintainer-authored PR 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