Skip to content

refactor(state): register agent database worker operations - #162776

Merged
steipete merged 3 commits into
mainfrom
dbasync/agent-db-registry
Oct 1, 2026
Merged

steipete merged 3 commits into
mainfrom
dbasync/agent-db-registry

Conversation

@steipete

@steipete steipete commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

Related: #162524

What Problem This Solves

Agent-database business operations duplicate their contracts across manual input/output declarations, module preparation, and command dispatch. This migrates the business dispatch deferred from the shared-state registry work.

Solution

Infer the 13 business-operation contracts from typed lazy handler tables and reuse createWorkerOperationRegistry with the agent context. Exact-operation loader keys preserve independent kernel loading within the shared session.* namespace; shared-state namespace lookup stays unchanged. Transcript loading for entry replacement remains conditional.

Native database creation, WAL maintenance, and publication binding/execution/cleanup retain their lifecycle owner. Admission, writer FIFO, transaction labels, commit receipts, and incognito handling are unchanged. No broker implementation changes are needed.

Impact

No user-visible behavior change or claimed performance improvement. These operations already execute in the agent worker. For the five production files in this lane, inventory counts remain T1: 0 → 0; W: 1 → 1. The production delta is +328 / −346 / net −18. Including the test, the patch changes 703 lines across six files.

Merged main at 6010d074f754d142ee1134416bcd9a4d5290a3db; the lane's files had no concurrent changes or conflicts. LOC is measured against that merged base (and is identical for these files against the original pinned base).

Evidence

Runtime proof snapshot: c2fbfc599b61731fbfbeb022c90f0fecf7ba4188, validated on Blacksmith Testbox tbx_01m3vtf6msntvettpb3842dtnh (run). All six changed-file SHA-256 checks passed before execution.

  • 129 tests passed. The nine existing boundary-test files passed 127 tests in 108.07s wall. The changed registry file passed 2 tests in 4.82s wall with one worker.
  • The changed-check run passed core production types, all 27 core test type graphs, and every guard before lint. Lint correctly rejected the new context's method declarations when handlers destructured them. Final commit af7f677aead1272d34f5b8a917b8dee994939254 declares those callbacks as function properties, matching their supplied closures. This changes no emitted JavaScript.
  • On that final head, lint passes for all six files. Core production types pass in 12.29s, and the state/infrastructure test type graph passes in 9.10s. The remaining changed-check guards pass separately: native schema version, database-first stores, media helpers, runtime sidecar loaders, runtime cycles, webhook ordering, and pairing guards. The successful runtime tests and other type graphs are reused for this declaration-only correction.
  • Final pinned-base SQLite ratchet: passed (7.55s). Final type-inclusive madge check: zero cycles (32.56s); runtime cycle check also reports zero.
  • Final branch Codex autoreview after the correction: scoped-clean at P0–P2, against the merged main base.
  • Final pnpm build: passed (1757.50s), including runtime bundles, unified declarations, plugin SDK declarations, CLI import/export checks, and UI artifacts.

The boundary selection exercises real worker routing with no caller-thread SQLite, FIFO, delayed preparation, rejected/revoked authority, commit receipts, incognito ownership, archive pruning, reactions, provider review, trajectory writes, and conditional transcript initialization.

Exact final validation commands

The configured node scripts/crabbox-wrapper.mjs run --keep --timing-json -- bash -c <payload> ran the tests and changed-check command against the hash-verified frozen source. After the declaration-only lint repair, the remaining commands ran on the final local head:

export OPENCLAW_VITEST_NO_OUTPUT_TIMEOUT_MS=1800000
pnpm test src/state/openclaw-state-worker-registry.test.ts --maxWorkers=1
node scripts/run-vitest.mjs \
  src/state/openclaw-agent-worker-store.test.ts \
  src/state/openclaw-agent-execution.registration.test.ts \
  src/config/sessions/session-reaction-store.test.ts \
  src/config/sessions/session-accessor.sqlite-replacement-worker.test.ts \
  src/config/sessions/session-accessor.sqlite-creation-worker.test.ts \
  src/config/sessions/session-pending-input-withdrawal.test.ts \
  src/trajectory/runtime-store-writer.test.ts \
  src/config/sessions/provider-review-store.test.ts \
  src/config/sessions/session-history-archive-pruning.admission.test.ts --maxWorkers=2
node scripts/check-changed.mjs --base origin/main -- \
  src/state/openclaw-agent-execution-contract.ts \
  src/state/openclaw-agent-execution-operations.ts \
  src/state/openclaw-agent-execution.worker.ts \
  src/state/openclaw-agent-operation-context.ts \
  src/state/openclaw-state-worker-registry.test.ts \
  src/state/worker-operation-registry.ts
node scripts/run-oxlint.mjs --tsconfig config/tsconfig/oxlint.core.json \
  src/state/openclaw-agent-execution-contract.ts \
  src/state/openclaw-agent-execution-operations.ts \
  src/state/openclaw-agent-execution.worker.ts \
  src/state/openclaw-agent-operation-context.ts \
  src/state/openclaw-state-worker-registry.test.ts \
  src/state/worker-operation-registry.ts
node scripts/run-tsgo.mjs -p tsconfig.core.json --incremental --tsBuildInfoFile .artifacts/tsgo-cache/core.tsbuildinfo
node scripts/run-tsgo.mjs -p test/tsconfig/tsconfig.core.test.state-logging.json --incremental
node scripts/check-native-state-schema-version.mjs
pnpm check:database-first-legacy-stores
pnpm check:media-download-helpers
pnpm check:runtime-sidecar-loaders
pnpm check:import-cycles
pnpm lint:webhook:no-low-level-body-read
pnpm lint:auth:no-pairing-store-group
pnpm lint:auth:pairing-account-scope
pnpm check:database-worker-ratchet --base 1004ec3b55fd3919ab4ec3d51fa5d91b7b66dfb6
pnpm check:madge-import-cycles
pnpm build

Inventory was measured before edits on the pinned base and after the cutover with node scripts/database-worker-inventory.mjs --json, filtered to the five production files. Only openclaw-agent-execution.worker.ts contains a counted primitive: one worker-side runOpenClawAgentWriteTransaction call.

Local core typechecking, the pinned-base SQLite ratchet, and the type-inclusive import-cycle check passed. The changed registry test passed both cases with OPENCLAW_VITEST_NO_OUTPUT_TIMEOUT_MS=1800000 pnpm test src/state/openclaw-state-worker-registry.test.ts --maxWorkers=1: 21.28s wall, 557ms test time on the loaded host.

The local integration run was interrupted after 565.10s. Four unchanged openclaw-agent-worker-store.test.ts cases reached the existing five-second marker deadline: successful scope preparation and pre-commit revocation with the borrowed source, plus successful single-command preparation with both borrowed and captured sources. Neighboring cases passed, and initial worker startup took 31.85s. This is retained as a local timing limitation; no fixture deadline, retry, or assertion was changed. Those cases pass unchanged in the isolated run described above.

Compatibility retained

No compatibility aliases or synchronous host exports were added. Existing synchronous worker factories and lifecycle commands remain required by the broker's native creation/binding contract. The existing process-held incognito and maintenance paths are unchanged; this refactor does not claim to migrate them.

Update behavior

No schema, stored-state, retention, durability, configuration, permission, Doctor, or updater change. No migration is required.

Infer business operation contracts from lazy handler tables and reuse the typed registry with the agent context and exact operation loaders. Preserve conditional transcript preparation, native admission, FIFO, receipts, incognito handling, and synchronous lifecycle commands. No schema, stored-state, configuration, or user-visible behavior change.
@clawsweeper

clawsweeper Bot commented Oct 1, 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.

@clawsweeper clawsweeper Bot added P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. 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 1, 2026
@clawsweeper

clawsweeper Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 1, 2026, 11:01 AM ET / 15:01 UTC (Revision 2).

ClawSweeper review

What this changes

The PR moves 13 existing agent database operations into typed, lazily loaded handler tables without changing their user-visible behavior.

Merge readiness

✅ Ready for maintainer review

This remains useful, distinct work: current main retains the agent dispatcher that this branch replaces. The source review found no actionable introduced defects, consistent with the previous review.

Priority: P3
Reviewed head: af7f677aead1272d34f5b8a917b8dee994939254

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused registry cutover with relevant supplied validation and no actionable correctness or security findings.
Proof confidence 🌊 off-meta tidepool Not applicable: The verified repository-admin author is exempt from external-contributor proof requirements for this internal refactor. Reported worker-boundary validation covers the changed dispatch path; the final correction is type-only. No stored-data contract changes, and no new authority boundary requires additional final-effect proof.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The verified repository-admin author is exempt from external-contributor proof requirements for this internal refactor. Reported worker-boundary validation covers the changed dispatch path; the final correction is type-only. No stored-data contract changes, and no new authority boundary requires additional final-effect proof.
Evidence reviewed 9 items Pinned introduced change: Read the complete merge-base-to-head patch and original affected blobs. The introduced change is confined to the agent operation contracts, handlers, worker dispatch, shared registry, context type, and registry test.
Existing lifecycle and transaction ownership preserved: Handlers receive the existing open, admission, and synchronous transaction callbacks. Native creation, WAL maintenance, domain publication, settlement, and cleanup remain in the worker; replacement commands still prepare transcript support only when requested.
Preparation boundary: The production worker awaits preparation before synchronous execution. The registry checks exact operation keys before retaining its existing namespace lookup, preserving shared-state callers while allowing independent agent kernels.
Findings None None.
Security None None.

How this fits together

Agent database workers receive session and trajectory operations from OpenClaw’s storage callers. They prepare the required modules, check current authority, and execute reads or transactions against the agent’s SQLite database.

flowchart TD
  A[Session and trajectory requests] --> B[Existing worker broker]
  B --> C[Lazy operation registry]
  C --> D[Existing admission checks]
  D --> E[Agent SQLite database]
  E --> F[Results and commit receipts]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source -18, Tests +27. Total +9 across 6 files.

View PR surface stats
Area Files Added Removed Net
Source 5 328 346 -18
Tests 1 28 1 +27
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 6 356 347 +9

Review metrics

None.

Technical review

Best possible solution:

Use the existing typed registry for agent business dispatch while retaining native lifecycle, transaction, and admission ownership.

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

Not applicable: this refactor reports duplicated operation declarations and dispatch, which are directly visible in the original source.

Is this the best way to solve the issue?

Yes: extending the existing registry removes parallel declarations and dispatch while preserving the established worker and kernel boundaries.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

No label changes.

Label justifications:

  • P3: This is internal dispatch cleanup with no claimed user-visible behavior or performance change.
  • 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 verified repository-admin author is exempt from external-contributor proof requirements for this internal refactor. Reported worker-boundary validation covers the changed dispatch path; the final correction is type-only. No stored-data contract changes, and no new authority boundary requires additional final-effect proof.

Evidence

What I checked:

  • Pinned introduced change: Read the complete merge-base-to-head patch and original affected blobs. The introduced change is confined to the agent operation contracts, handlers, worker dispatch, shared registry, context type, and registry test. (src/state/openclaw-agent-execution-operations.ts:1, af7f677aead1)
  • Existing lifecycle and transaction ownership preserved: Handlers receive the existing open, admission, and synchronous transaction callbacks. Native creation, WAL maintenance, domain publication, settlement, and cleanup remain in the worker; replacement commands still prepare transcript support only when requested. (src/state/openclaw-agent-execution.worker.ts:328, af7f677aead1)
  • Preparation boundary: The production worker awaits preparation before synchronous execution. The registry checks exact operation keys before retaining its existing namespace lookup, preserving shared-state callers while allowing independent agent kernels. (src/infra/sqlite-store.worker.ts:181, af7f677aead1)
  • Still necessary on current main: The existing dispatcher, contract, registry, and registry test have no changes between the pinned merge base and fetched main. The related merged PR refactor(state): register transcript, skill and runtime worker operations #162524 explicitly deferred agent business dispatch, so it does not supersede this work; no shipped implementation of this cutover is established. (src/state/openclaw-agent-execution.worker.ts, 78e733b7a4aa)
  • Actual merge preserves scope: Raw test-merge records confirm the ordered parents are the pinned base followed by the exact PR head. Comparing that merge with its main parent retains only the six introduced paths, rather than the unrelated endpoint drift. (c7b2faecda9c)
  • Validation snapshot remains relevant: The captured PR body reports 129 passing tests on c2fbfc5, including worker and session boundaries, followed by final-head lint, types, guards, cycle checks, and build. GitHub’s final-commit patch confirms the intervening correction only changes type declarations for context callbacks. These are reported validation results; this review executed no tests. The body also retains the interrupted local run and unchanged marker-deadline failures. (src/state/openclaw-agent-operation-context.ts:6, af7f677aead1)

Likely related people:

  • Peter Steinberger: Raw commit 3f7689e adds src/state/worker-operation-registry.ts:5 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 3f7689e64a08; files: src/state/worker-operation-registry.ts)

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 (1 earlier review cycle)
  • reviewed 2026-10-01T14:54:12.095Z sha af7f677 :: needs maintainer review before merge. :: none

@steipete
steipete merged commit 78ed04b into main Oct 1, 2026
124 checks passed
@steipete
steipete deleted the dbasync/agent-db-registry branch October 1, 2026 15:10
@steipete

steipete commented Oct 1, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 2, 2026
…162776)

* refactor(state): register agent database worker operations

Infer business operation contracts from lazy handler tables and reuse the typed registry with the agent context and exact operation loaders. Preserve conditional transcript preparation, native admission, FIFO, receipts, incognito handling, and synchronous lifecycle commands. No schema, stored-state, configuration, or user-visible behavior change.

* fix(state): type worker context callbacks as function properties
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. 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