Skip to content

refactor(session-signals): move adoption and cleanup into the worker - #165681

Merged
steipete merged 2 commits into
mainfrom
dbasync/w5signals
Oct 5, 2026
Merged

steipete merged 2 commits into
mainfrom
dbasync/w5signals

Conversation

@steipete

@steipete steipete commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Session adoption and reset/delete signal cleanup still ran SQLite transactions on the Gateway thread, despite an existing shared-state signal worker.

Why This Change Was Made

Route both catalog adoption producers through the awaited recorder and move signal cleanup into that same worker. Reset and deletion retain their existing lifecycle fences and post-commit ordering. The worker checks the captured database authority at transaction and commit admission; accepted work settles before teardown. Ambient-watch read invalidation remains held across overlapping pruning and cleanup. Remove the superseded synchronous recorder and migrate its fixtures.

User Impact

No user-facing API, schema, stored format, retention, or configuration change. The 30-day/50,000-event retention policy and reset/delete scope remain unchanged. The signal owner retires 10 counted T1 sites: 876 → 866 against bb3a8a9ac304fbec8367fd64d9644bb12d956e9c. Production delta is +120/−103, net +17 (223 changed lines). Inventory tooling changes separately by +4/−6 lines.

Upstream-link lifecycle is a pending follow-up awaiting an SDK surface-budget decision. Its released synchronous APIs and deletion order remain unchanged. The released synchronous ambient-watch reader also remains compatibility debt. This PR adds no SDK exports, deprecations, budgets, or environment-variable names.

Evidence

  • Focused signal/watch/telemetry/cursor suites: 120 tests passed with --maxWorkers=1; 320.04 s wrapper wall time, including 62.50 s worker compilation. The real worker tests cover retained scope, notices, foreign commits, transaction/commit refusal, and bounded retention. Their database lifetime checks require admitted workers; telemetry and cursor-batch fixtures now route to the host-owned project.
  • Before/after focused owner-entry measurement, ten operations per path: main-thread signal SQL executions 30 → 0 adoption, 10 → 0 reset, 30 → 0 deletion. Native SQL execution total 0.345 ms → 0 ms. Warm awaited wall time was 19.35 → 43.20 ms, 7.14 → 55.26 ms, and 17.63 → 47.20 ms respectively. This is an ownership measurement on small synthetic state, not a throughput claim; retained upstream-link SQL is excluded from signal-only counts.
  • SDK surface gate passed at unchanged counts: 151 public entrypoints, 3,648 exports, 2,110 callables, 145 deprecated exports. Canonical declaration comparison has no added/removed exports, entrypoints, or direct signature changes. Its 128 conservative reachable changes reduce to two whole-module * sections: the existing indexed namespace type in AgentHarnessToolSurfaceOptions triggers the renderer's recursive declaration fallback. Source audit confirms no public path exposes the removed recorder, cleanup signatures, or new private worker command.
  • Database-worker ratchet passed (19.99 s); Madge reported zero cycles (61.60 s).
  • Gateway/adoption, corrected boundary, and required runtime-process/import-closure batch: 75 tests passed, 387.88 s wrapper wall. Final deletion/reset concurrency, accepted-close cleanup, subagent rollback, and boundary batch: 57 tests passed, 286.06 s. Cursor kernel proof after a lint-only binding rename: 2 tests passed, 21.71 s. All used --maxWorkers=1.
  • The queued ambient-read regression failed before moving invalidation ahead of queue admission (15.15 s negative control), then passed in the final lifecycle batch. Close proof uses fresh retained rows so pruning cannot mask failed cleanup.
  • Published-driver update cell passed on AWS: published 2026.9.8 → same-version candidate, update status finished, readyz=200, running version verified, durable session preserved, and expected incognito restart loss/artifact checks passed. The updater took 402.76 s; package preparation plus the cell took 1,220.92 s. The verified source capsule tree b35b1d659372b377fd49fe429e8054a0358274c5 exactly matches commit 6bedecbc7d71c. The lease was released. Testbox first stalled; an initial AWS cold-build attempt exhausted the outer envelope, so the successful run used the supported prebuilt-tarball input with the unchanged normal cell deadline.
  • P2 Codex autoreview: two scoped-clean reviews, including the final queue-fence correction; no accepted/actionable findings.
  • Full check-changed and full core lint expose inherited failures in unchanged base files: unused src/plugins/config-policy.ts:24 export resolvePolicyPluginActivationState, seven existing re-exports in src/media-understanding/defaults.ts, and src/gateway/server-methods.authorization.test.ts at 1,067 counted lines against its 1,000-line limit. All three files are byte-identical to the pinned base. The signal-owned unused export and cursor-test shadowing diagnostics were fixed. Other required checks passed, including core/test typechecks, script lint, schema/media/runtime-sidecar/import/auth guards; changed-file core lint passed in 107.57 s. Full check-changed ran for 747.50 s and stopped at those inherited dead exports; full core lint also reported the inherited authorization-test line cap. No guard is disabled. These are retained local baseline limitations; exact-head GitHub checks remain required for landing.
  • Initial CI run 37345374920 at 6bedecbc7d71 consumed 12,113 aggregate job seconds. Its only failing test was the inventory fixture described below; the corrected head subsequently passed its own CI gates.

Direct overlap: #165521 changes the event kernel/tests. #162433 covers separate umbrella ownership work. Adjacent session-authority work (#165028, #165370, #165552, #165205) remains independent. The PR keeps changes within the signal owner and its callers.

Reproducible local test selections and wall times

These selections ran through pnpm test ... --maxWorkers=1.

Selection Tests Wrapper wall
src/sessions/session-state-events.{test,worker-boundary.test,cursor-batch.test,worker-control.test}.ts, src/agents/watched-sessions-prompt.test.ts, src/infra/telemetry.test.ts 120 320.04 s
src/gateway/server-methods/session-catalog{,-adoption,-gateway-copy}.test.ts, src/gateway/server.sessions.reset-acp-timeout.test.ts, src/gateway/server-lifecycle.catalog-write.test.ts, signal worker boundary, test/scripts/runtime-process-build-graph.test.ts, src/state/openclaw-state.worker.imports.test.ts, src/auto-reply/reply/get-reply.imports.test.ts 75 387.88 s
Signal worker boundary, src/gateway/server-lifecycle.catalog-write.test.ts, src/gateway/server.sessions.delete-lifecycle.test.ts, src/gateway/server.sessions.reset-concurrency.test.ts, src/agents/subagents/spawn/subagent-spawn.preparation-authority.test.ts 57 286.06 s
src/sessions/session-state-events.cursor-batch.test.ts after the binding rename 2 21.71 s

The long suites use real database workers and existing Gateway lifecycle fixtures to exercise foreign-commit authority, SQL-thread ownership, retention, reset/delete refusal ordering, and actual server-close settlement. The new catalog case reuses mocks; the close regression extends an existing server fixture rather than adding another boot. A 61-importer routing audit found no additional routing defect; existing Gateway and agents-support suites already use forks.

Landing correction and verification

ClawSweeper and CI identified a stale inventory regression expectation: the recorder is now wholly worker-owned, so the mixed-operation fixture must count all four recorder calls as worker calls. The correction changes only test/scripts/check-database-worker-ratchet.test.ts; it explicitly retains anotherRecorder as T1 and leaves unrelated-runtime growth rejection intact.

The original fixture failed identically in five single-worker runs at 6bedecbc7d71 and passed in five runs at merge base bb3a8a9ac304f. After correction, pnpm test test/scripts/check-database-worker-ratchet.test.ts --maxWorkers=1 passed both tests in 10.48 s wrapper wall time. Root test typechecks, focused formatting/lint, the database-worker ratchet, and git diff --check passed. A fresh P2 Codex autoreview of the complete candidate was scoped-clean with no actionable findings.

Released SDK audit against v2026.9.8: the removed recorder and async reset/delete helpers are internal; neither plugin SDK exports nor api.runtime exposes them. The released ambient reader remains unchanged. An independent importer audit confirmed the worker-host routing and the existing runtime-process/import-closure proof; this correction adds no production import.

The initial PR-context failure used the earlier Problem heading. The corrected head passed the PR-context check with the current authored sections.

Final head e4df9621e9af69ba69bf071f1127ff78a3a01880: CI run 37359295318 completed successfully (11,676 aggregate job seconds; pinned watcher GREEN). ClawSweeper revision 2 completed on that head with no actionable findings and confirmed the prior fixture finding resolved. No CI rerun or inherited-failure bypass was used.

@clawsweeper

clawsweeper Bot commented Oct 5, 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 scripts Repository scripts agents Agent runtime and tooling size: L labels Oct 5, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. 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 Oct 5, 2026
@clawsweeper

clawsweeper Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 5, 2026, 3:17 PM ET / 19:17 UTC (Revision 3).

ClawSweeper review

What this changes

Moves session-adoption recording and reset/delete signal cleanup into the existing database worker, with awaited callers and updated lifecycle tests and documentation.

Merge readiness

✅ Ready for maintainer review

This PR remains useful: current main still performs the targeted signal writes synchronously. The prior fixture finding is resolved, exact-head CI succeeded, and no new actionable defect was found.

Priority: P2
Reviewed head: e4df9621e9af69ba69bf071f1127ff78a3a01880

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, supported ownership migration with resolved prior feedback and successful exact-head CI.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): Recorded owner-entry measurements exercise the moved adoption/reset/delete operations, with zero after-fix caller-thread signal SQL; real-worker and Gateway-close evidence covers queued cleanup and settlement. The published-driver update cell preserves durable state, and the final commit changes only the inventory fixture. No stored-data contract changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): Recorded owner-entry measurements exercise the moved adoption/reset/delete operations, with zero after-fix caller-thread signal SQL; real-worker and Gateway-close evidence covers queued cleanup and settlement. The published-driver update cell preserves durable state, and the final commit changes only the inventory fixture. No stored-data contract changes.
Evidence reviewed 7 items Work remains necessary on current main: Pinned current main retains the synchronous recorder and synchronous reset/delete cleanup. The related merged session-authority work does not implement this signal-owner cutover.
Cleanup retains physical ownership and admission: Cleanup captures the database context before yielding, invalidates ambient reads before queue admission, and holds that invalidation until settlement. The worker preserves existing deletion predicates and requests transaction and commit admission.
Lifecycle ordering remains awaited: Deletion awaits signal cleanup inside its exclusive lifecycle mutation. Reset records an async post-commit action, and the existing settlement owner awaits every action before returning.
Findings None None.
Security None None.

How this fits together

Session signals record adoption and lifecycle changes in OpenClaw’s shared database. Watchers and prompt preparation consume these records; reset and deletion remove the corresponding watch state.

flowchart TD
  A[Catalog adoption] --> C[Session signal owner]
  B[Session reset or deletion] --> C
  C --> D[Captured database admission]
  D --> E[Shared database worker]
  E --> F[Signal records and watch cursors]
  F --> G[Watcher notices and prompt reads]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +17, Tests +251, Docs +4, Other -5. Total +267 across 28 files.

View PR surface stats
Area Files Added Removed Net
Source 10 120 103 +17
Tests 15 431 180 +251
Docs 1 12 8 +4
Config 0 0 0 0
Generated 0 0 0 0
Other 2 4 9 -5
Total 28 567 300 +267

Review metrics

Metric Value Why it matters
Production and test growth Production +120/−103, net +17; tests/support +431/−180, net +251 The small production increase implements worker cleanup admission and settlement; test growth covers queued ownership, invalidation, and shutdown.

Technical review

Best possible solution:

Keep signal mutations with the existing shared-state worker while preserving lifecycle settlement, current database admission, and released compatibility surfaces.

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

Not applicable to this refactor; current-main source confirms the synchronous operations being migrated. This read-only review did not execute tests.

Is this the best way to solve the issue?

Yes: reusing the existing worker and awaiting its results is a focused ownership cutover that preserves existing cleanup scope and lifecycle ordering.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

No label changes.

Label justifications:

  • P2: This is a bounded internal database-worker migration with no demonstrated urgent user-facing regression.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): Recorded owner-entry measurements exercise the moved adoption/reset/delete operations, with zero after-fix caller-thread signal SQL; real-worker and Gateway-close evidence covers queued cleanup and settlement. The published-driver update cell preserves durable state, and the final commit changes only the inventory fixture. No stored-data contract changes.
  • proof: sufficient: Contributor real behavior proof is sufficient. Recorded owner-entry measurements exercise the moved adoption/reset/delete operations, with zero after-fix caller-thread signal SQL; real-worker and Gateway-close evidence covers queued cleanup and settlement. The published-driver update cell preserves durable state, and the final commit changes only the inventory fixture. No stored-data contract changes.

Evidence

What I checked:

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Jason (Json): 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 (2 earlier review cycles)
  • reviewed 2026-10-05T17:12:25.157Z sha 6bedecb :: needs changes before merge. :: [P2] Migrate the ratchet fixture with the whole-recorder classification
  • reviewed 2026-10-05T18:57:57.121Z sha e4df962 :: needs maintainer review before merge. :: none

@steipete

steipete commented Oct 5, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Fixed the inventory fixture finding in e4df962. All four recorder calls are classified as worker-owned; anotherRecorder remains T1 and unrelated-runtime growth is still rejected. Five baseline runs passed and five original-head runs failed; the corrected focused suite, root test typechecks, database-worker ratchet, and fresh full-candidate P2 autoreview passed.

@clawsweeper

clawsweeper Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. 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 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 Oct 5, 2026
@steipete
steipete merged commit 5f23299 into main Oct 5, 2026
162 checks passed
@steipete
steipete deleted the dbasync/w5signals branch October 5, 2026 19:26
@steipete

steipete commented Oct 5, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation gateway Gateway runtime P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. 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