Skip to content

refactor(sessions): cut over snapshot callbacks and SDK reads to workers - #169637

Merged
steipete merged 30 commits into
mainfrom
dbasync/t1cut-s6
Oct 12, 2026
Merged

steipete merged 30 commits into
mainfrom
dbasync/t1cut-s6

Conversation

@steipete

@steipete steipete commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Session snapshot callbacks, worktree cleanup, recovery, and run-start/statistics SDK contracts could still force durable session reads or writes onto the Gateway thread.

User Impact

Bundled callers now use worker-owned operations and prepared run-start facts. Plugins can migrate to onPreparedAgentRunStart, readTranscriptStatsAsync, and readTranscriptStatsBatchReadOnlyAsync; the synchronous SDK contracts warn and remain compatible until the next Plugin SDK major. No schema, retention, transcript-format, or operator migration changes.

Why This Change Was Made

Reuse the existing entry patch, history, and metadata workers. Snapshot callbacks no longer select a durable native fallback; real authority callbacks run at the existing commit grant. Worktree cleanup consumes one worker owner view and invalidates it through committed session changes. ACP reset and recovery consume owner-prepared source facts. Batched statistics preserve order, duplicates, and missing-store results in one request per durable store. Memory ingestion awaits file statistics; transcript export observers and explicit parsing yields obtain their snapshot through the existing worker, then retain host callback behavior. Prepared statistics are reused without a new read; full messages are transferred only for observers that require them.

Removed checks and accepted edge cases:

  • Worktree owner re-reads: an overlapping owner write defers cleanup; the final deletion boundary still validates lifecycle and placement authority.
  • Transcript-owner JSON predicate: Gateway write receipts own current state; unsupported external raw database writes are not detected by internal bookkeeping.
  • ACP reset's duplicate host snapshot admission: a host-pinned read snapshot no longer rejects reset; the metadata worker owns its transaction.
  • Run-start watermark recapture in bundled paths: the producer's prepared watermark is authoritative; deprecated third-party callbacks retain their explicit compatibility fallback.

Native incognito paths remain for their separate removal. Doctor/import canonical-validation writes remain synchronous exceptions. The CLI command-execution authority check stays because it guards a real external effect.

Evidence

Independent Codex review: no actionable P0/P1 findings in two rounds. Local changed-file formatting/basic lint and diff validation are followed by PR CI for tests, types, lint, Knip, Madge and database ratchets under RELAXED TESTING v6. The completed isolated live comparison is recorded below. The measured candidate contains the final authored changes; later commits integrate main and repair test fixtures. The prerequisite read cutover #169579 has landed; this PR targets main and preserves both changes through merge commits. The assigned-file inventory decreases from 42 to 39 T1 primitives in this slice (43 at the original base); retained compatibility/native/offline paths are documented in worker-access.md and are not claimed as worker-only.

The final bundled-caller audit found and removed two additional synchronous Memory paths: ingestion statistics and callback-based transcript exports. The existing SQLite export regression now checks callback contents, zero host SQL and fresh statistics after an append. The deprecated synchronous stat adapter warns only when it performs SQL.

LOC versus main after parent landing: 1,317 insertions and 1,018 deletions across 76 files after main integration and merge repair. No update cell is required.

Prior authored-head CI run 38214900818 passed all production/test types, lint, source contracts, architecture, database ratchets and SDK boundary checks. Follow-up fixes migrate native-only test fixtures and preserve their data/authorization assertions. Seven tests that only pinned the deleted duplicate transcript-owner predicate were removed. Main’s corrected rollback-journal regression remains and exercises the low-level writer directly. Named SDK surface accounting covers only the authorized readTranscriptStatsAsync/readTranscriptStatsSync and prepared-run-start migration pairs.

Live SQL comparison

Baseline 215556e77dbc73ed336e336f2df9faa657911a96 → candidate 4f14b0ef2c4a851f0c9b73f1c226f39d9f4fb9ca. The latter contains final authored changes before conflict-only integration. Unchanged shared harness; Node26.11.1 / SQLite3.53.4; both full QA runtime builds passed.

The initial C1b→C2 comparison was invalid for gating: warmed duration ratio4.39 (baseline64.6s total, candidate333.2s) on sharply different host load. The replacement baseline C1c failed before turns with the existing15s connect handshake timeout (auth_validated profile acquisition); no timeout changed. The completed replacement pair C1d→C2b is below. Both workloads passed13 turns, awaited child, control-plane list/history, cron, compaction and graceful shutdown.

Warmed metric Baseline median [min–max] Candidate median [min–max] Baseline mean Candidate mean
All-thread statements 355.5 [309–371] 346.5 [301–378] 352.4 340.7
Worker requests 110 [97–129] 107 [96–127] 111.6 107.9
MAIN statements 0 [0–2] 0 [0–2] 0.2 0.2
Phase Base SQL Candidate SQL Δ SQL Base requests Candidate requests Δ requests Duration ratio
01.boot 2042 2027 -15 82 73 -9 1.53
01.connect 1225 1076 -149 63 62 -1 0.77
02.first-turn 965 987 +22 229 195 -34 0.50
warmed 352.4 340.7 -11.7 111.6 107.9 -3.7 0.70
04.second-session 1370 1406 +36 386 392 +6 0.54
05.control-plane 60 13 -47 16 3 -13 0.82
06.cron 723 611 -112 214 168 -46 0.58
07.compaction 197 172 -25 47 32 -15 0.39
08.shutdown 89 77 -12 14 14 +0 5.02
total 10195 9776 -419 2167 2018 -149 0.86

Whole-workload statements fall419 (4.1%) and requests fall149 (6.9%); warmed means fall11.7 statements and3.7 requests per turn. First-turn SQL rises22 while first-turn requests fall34; the full workload and touched operation totals below distinguish redistribution from added ordinary work. Boot and shutdown counts both fall despite slower phase timing; warmed/first-turn comparison ratios are0.70/0.50.

Operation Whole SQL baseline→candidate Whole requests baseline→candidate Warm SQL/turn baseline→candidate Warm requests/turn baseline→candidate
session.entry.read 235→227 75→67 17.2→16.6 5.2→4.6
session-entry 91→76 18→15 4.5→3 0.9→0.6
session.entry.patch.prepare 120→122 61→62 6→6 3→3
session.entry.patch.commit 740→746 103→104 43→43 6→6
session-store-projection 11→10 2→1 0→0 0→0
transcript-stats 2→2 1→1 0→0 0→0
history-page 40→40 5→5 0→0 0→0
sessionRows.sharedFacts 55→58 104→108 3.1→3.2 6.8→7.1
database.domain.publish 1141→1015 241→207 57.5→50.5 14.2→12.2
database.prepareWrite 94→63 4→3 0→0 0→0

Warmed MAIN is the same2 secret-store list SELECTs in each run (outside this lane), shifting from turn7 to turn2. Exact native/request stacks are in pr2-attribution.json. Full phase/operation results are in local-pair/live-summary.json; failed baseline startup and invalid initial comparison are retained as limitations, not counted as passing proof.

Final integration repair: main independently introduced the same callback fields, so the automatic merge duplicated declarations and final callback invocation. The repair removes those duplicates, keeps the existing final transaction cancellation check, and restores the busy-timeout test helper import. No assertions were relaxed. That repaired head passed the static CI checks recorded below; that main integration is 87939000e48a31ffe0bb0f37d8e837410222ed45.

Assigned-file T1 accounting: original base 43 → preceding read PR 42 → this PR 39. This slice retires the worktree-owner host primitive (worker-only classification), one canonical-key primitive (remaining validation is an offline exception), and the transcript write-guard host primitive. Shared transcript kernels retain deprecated synchronous SDK, native incognito, offline maintenance, or final real-effect callers; this PR does not claim their literal inventory is zero.

CI on the preceding repaired head 3b55950bdb88984a3788e5ebf734099d9f9450e4, run 38220964426: production types, all five core test-type stripes and aggregate types, core/extension lint, source contracts, Madge architecture, SDK boundaries/guardrails, and T1/dialect/worker ratchets pass. Security checks pass. All scheduled changed-test jobs pass except the documented unchanged-owner failures: incognito vanished-session error wording, Bun rewind SQL count, and the stale-version lazy-writer postimage test inherited from #169651.

The build completed but its built-CLI flip smoke fails when the fixture deletes an in-flight session and agent.wait returns AbortError without a stop reason. Recent main run38220958692, head 5a1f8c692e9474323c8cbbf6c4d985ed2a1b6f0b, build job114717130399, fails with the exact same result. It is inherited; no passing smoke result is claimed. The separate live SQL workloads completed all flows.

Local verification under RELAXED TESTING v6: changed-file oxfmt, basic oxlint, and git diff --check pass; broad suites were delegated to CI. The later focused failure-attribution runs and their wall times are recorded below. No update/Doctor/migration/plugin-loader/service-lifecycle change is included. The landing uses the explicitly authorized head-pinned REST squash route after native provisioning delay, with inherited CI failures named above.

Final main integration 87939000e48a3 preserves main’s retirement of the inactive standalone Memory backend (including its obsolete corpus test). Knip diagnosis: the reviewed head’s production scan reported only three untouched-owner exports (PreparedCronRunReceiptClaim, ComposerRunStatusContent, ChatPaneVersionsMenu); main commit f0a14bf986e60 removed all three exports, and this integration includes that exact fix. Script export scans pass with zero entries on both revisions. Full-tree scans hit the same existing 600-second limit on the reviewed head and recent main 5a1f8c692e94; no timeout or baseline was raised. Prior summaries calling Knip green should be read as this explicit inherited-failure disposition.

Prior integration head: 155ca35fdf55c92d95f7f65c4a18b4aa8b8f82de, including main 97775a426a352f307838e4095fa934b445d853b9. Main independently fixed the optional fixture read; the resolution keeps its stronger pre-commit initial label assertion and this PR’s legacy callback coverage. The preceding head’s two test-type errors are corrected; production behavior did not change. Ordinary CI is recorded at 38229370938. The intermediate manual CI dispatch did not run proof: it refused a stale GitHub merge ref before this conflict resolution.

The sessions-read-cache.test.ts preview assertion failure is independently reproduced on main 802f3415be1f0fb5c88d8063a61ea19f8f95daa4 and candidate 016106aeb7d2fa1d419e1a9a81b4ae30552c2208 with pnpm test src/gateway/server-methods/sessions-read-cache.test.ts -t 'refreshes row previews after a committed transcript update' --maxWorkers=1. Both return undefined instead of Fresh committed preview at line 430. Command wall times: main 1,083.65 seconds, candidate 1,051.70 seconds (Vitest 989.26/963.09 seconds), mostly worker transformation; these were focused failure attribution, not passing proof. This unchanged-owner failure joins the independently confirmed inherited rewind SQL-count failure. No timeout, assertion, or cache behavior was changed to hide them.

Prior-head static evidence, run 38229370938: production types, all five core test-type stripes and aggregate types, all core/extension lint stripes, source contracts, Madge architecture, SDK boundaries/guardrails, and T1/dialect/worker ratchets pass. Security and dependency review pass. The corrected authority-test stripe passes. Knip retains the explicit inherited full-tree timeout disposition above; no baseline or timeout was raised.

Final CI failure attribution: recent main run 38226928416 independently reproduces the preview failure (job 114736776831), readonly-summary pending-row omission (job 114736776521), and incognito error-wording mismatch (job 114736776952). The background-tool capture-count fixture and two cron revoked-read/captured-alias fixtures belong to untouched owners; no exact main reproduction is claimed for those. Both cron fixtures request the unchanged full read path; this PR’s exact-read change removes only the obsolete worktree projection. Their theoretical in-flight close/alias expectations do not demonstrate a regression introduced here. They remain follow-ups; no compensating checks, assertion changes, or retries were added. Landing uses the authorized inherited-failure exception with the exact head pinned.

Current integration head: 1b08b81a7a8614f101e6e7f47def1e635efdf96f, including main b4063f202d3331d9825ba1a61cc446ecf17dca64. The sole conflict combines both documented SDK migration allowances: this PR’s async transcript statistics/prepared run start and main’s retained shipped createSessionHeaderLink. Public export/function/deprecation accounting is the exact composition of those named contracts. Session implementation merged automatically; local format, lint, and diff checks pass. Current-head static/security CI qualification passed in run 38232380143: all production/test type stripes, core/extension lint stripes, source contracts, Madge/architecture, SDK boundaries/guardrails, and T1/dialect/worker ratchets passed. Security-sensitive and dependency reviews passed. Knip retains the documented inherited full-tree timeout disposition. The prior exact-head REST merge returned HTTP 405 because the base moved; it did not merge the PR.

Landed by an exact-head REST squash as 1ebb24d4fbd5f954c9cc5e07f5c009ab9abaea03. The head precondition was 1b08b81a7a8614f101e6e7f47def1e635efdf96f; the final fresh check showed OPEN/MERGEABLE and all static/security checks passed. The authorized inherited-failure route did not wait for optional dynamic jobs.

@clawsweeper

clawsweeper Bot commented Oct 12, 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 channel: telegram Channel integration: telegram gateway Gateway runtime scripts Repository scripts agents Agent runtime and tooling size: XL labels Oct 12, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. labels Oct 12, 2026
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. labels Oct 12, 2026
@steipete
steipete merged commit 1ebb24d into main Oct 12, 2026
167 of 173 checks passed
@steipete
steipete deleted the dbasync/t1cut-s6 branch October 12, 2026 10:00
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 13, 2026
…ers (openclaw#169637)

Route snapshot callbacks, worktree ownership reads, prepared run starts, and bundled transcript statistics/export callers through existing session workers. Deprecate synchronous public SDK contracts while retaining released compatibility and final authority checks.

Reuse Gateway-owned facts and write receipts, remove duplicate owner checks, and preserve large-value SQL projections. Live isolated comparison reduced warmed statements from 355.5 to 346.5 and requests from 110 to 107; MAIN remained zero by median. Shared native/offline/compatibility kernels remain documented exceptions.

Completes the second session cutover slice after openclaw#169579.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling channel: telegram Channel integration: telegram docs Improvements or additions to documentation extensions: memory-core Extension: memory-core gateway Gateway runtime merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. scripts Repository scripts size: XL status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant