Skip to content

refactor(sessions): validate chat leaves through workers - #169659

Merged
steipete merged 38 commits into
mainfrom
dbasync/t1cut-s1-memory
Oct 12, 2026
Merged

steipete merged 38 commits into
mainfrom
dbasync/t1cut-s1-memory

Conversation

@steipete

@steipete steipete commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Durable chat admission and Stop still reached synchronous session SQL even though their surrounding operations were asynchronous. This stacked follow-up to #169608 carries active-path facts from the existing reader worker to those callers.

User Impact

Chat admission, Stop, archive indexing, and failed-creation rollback preserve their existing outcomes. No public SDK signature, schema, retention, migration, or update behavior changes. Native incognito stays with its separate owner cutover.

Design

The session-entry worker returns active-path facts in the same snapshot as the selected entry. Chat admission consumes those facts; Stop awaits the worker before cancellation. The selection assembly lives with the existing transcript-anchor reader. Recovery no longer rereads the active leaf while recording internal admission bookkeeping.

Memory classification and initialization rollback were also cut over during this work, and equivalent production changes independently landed on main. This PR keeps those implementations, adds Memory ingestion coverage across ordinary → dreaming → cron owner writes, and strengthens the initializer regression to reject all caller-thread session SQL with and without a native binding. The worker commits deletion before its existing commit-only participant consumes initialization. Only opaque released SDK deletion callbacks retain the native transaction adapter.

Removed check and accepted edge case: the recovery bookkeeping leaf reread is gone. A concurrent leaf change may leave bookkeeping describing the already-admitted attempt; the next actual admission validates its own active path. Current authorization and cancellation checks at effects remain.

T1 and SQL

Shared native kernels are deliberately not relabeled worker-only. This PR claims 0 raw T1-site reduction: the identity primitive moved from active-events to the existing narrow transcript-anchor owner, so their combined count remains 7 → 7 (active-events 5 → 4 and transcript-anchor 2 → 3). Ordinary durable chat admission, Stop, recovery bookkeeping, and Memory classification now use worker-backed reads. The seven original archive/conversation modules still contain 18 mixed T1 primitives with native incognito, deprecated SDK, opaque callback, and offline CLI callers recorded in the inventory.

The seven retained mixed modules contain: conversation-registry 1, archive-read 1, archive-store-kernel 6, archive-transaction 1, conversation-read 1, conversation 7, and delete-snapshot 1. Durable conversation reads, archive enumeration/publication, and deletion snapshots use their existing workers; the remaining native consumers are recorded in the inventory. Deprecated SDK readers and opaque released callbacks retain their documented replacement/removal path. Native incognito remains outside this slice.

One live combined-lane pair was run under the current validation policy: baseline 9c54108f9f20a, candidate 22bf8aa966027a499abbeb784f6e2aab9e44a397. This candidate includes the prerequisite, this PR, and the currentness cutover; it is not an isolated measurement of this PR's head. Successful SQL executions reconcile exactly with the worker census and shared statement-count CSV. Requests count one worker send per key, excluding continuation frames; prepare and failed SQL executions are excluded.

Measurement Baseline Combined candidate
Warmed all-thread statements, ten-turn total / 10 306.7 381.9
Warmed all-thread requests, ten-turn total / 10 84.0 106.7
Warmed MAIN statements, ten-turn total / 10 0 0.2
Whole-workload all-thread statements 9283 10211
Whole-workload all-thread requests 1668 2016
Whole-workload MAIN statements 1984 1982
Warmed window duration, seconds 18.806 114.302
Whole-workload duration, seconds 96.248 612.452
Relocated active-events + anchor T1 primitives 7 7

Within-run warmed median [min–max]: statements 294.5 [291–340] → 357.5 [344–514]; requests 81 [79–95] → 100 [95–128]. These are ten observed turns within one pair, not medians across three pairs. The candidate's warmed window was approximately 6.08× longer and its whole workload 6.36× longer. No SQL saving or controlled performance improvement is claimed from this slice.

Warmed owner-operation totals across ten turns:

Operation Statements before → after Requests before → after
transcript-hydration 240 → 240 20 → 20
transcript-anchors 110 → 110 10 → 10
session-row-facts 255 → 255 51 → 51
session-row-backfill 100 → 95 20 → 19
session.entry.patch.commit 370 → 370 60 → 60
session.entry.patch.prepare 60 → 60 30 → 30
session.lifecycle.project 120 → 133 10 → 10
session-activity-summary-source 60 → 60 10 → 10
session-entry-read 10 → 10 10 → 10

The 13 additional lifecycle statements are one existing temporary generation-tracker setup batch, not new lifecycle requests. The two warmed MAIN statements are unchanged scheduled GitHub OAuth maintenance outside this lane. Repeated background Memory refresh accounts for 12 extra writable entry reads and 12 each of corpus, tombstone, and transcript requests: 3 refresh cycles occurred during the baseline warmed window and 15 during the longer candidate window. Existing Memory publication and WAL maintenance also ran more often.

The shared-family audit traces the five additional admitted ordered reads to same-database Memory commits 3.5–12.5ms earlier. Those unscoped writes invalidate the existing session token. Five corresponding prompt reads refill participant coverage: the existing full-entry actor fallback after a Memory-invalidated patch lacks participants. Two read-only FIFO misses and three additional early hydrations likewise follow Memory commits. The remaining one C05 entry-admission miss is not causally cleared by the original observer, which records worker reply posting but not main-thread receipt installation or cache-decision reasons. No claim that every raw increase is unrelated is made before the diagnostic disposition below.

All 13 measured chat.send calls omit expectedLeafEntryId. The new active-path transcript projection is therefore disabled for those calls; its intentional row-cache bypass does not explain this measured increase. That projection remains required when a client explicitly pins a leaf.

The combined live run is not a fully passing end-to-end run: all 13 agent turns, cron, child terminal, compaction, and shutdown succeeded, but mentions.dismiss returned retryable UNAVAILABLE during the control-plane phase. The outer all-RPC assertion failed despite the driver's ok: true. There were no failed SQL executions in that phase; the existing generic catch hides the underlying exception, so its cause is not claimed as established.

Evidence

Two isolated Codex reviews completed without actionable findings. Basic changed-file oxfmt, oxlint, and whitespace checks pass. No new local suite or remote lease was required under RELAXED TESTING v6.

The pinned-main merge f43e2acb29531dbb593adaa1b79e64ecc35fe7ee incorporates fe79a0ff62af6054619dcb5af5144ae96f6469d6. The three source conflicts preserve both transcript selection and lifecycle facts in the same existing worker snapshot; no extra read was introduced. The fourth conflict was the generated inventory, regenerated canonically: 627 files / 2392 expressions, T1 540, compatibility 2, T2 403, T3 261, W 1186. The original 17 lane files retain 42 raw T1 expressions.

Final-head static qualification is complete at 1a9fb1108ee2293883c19cc4a84f94e57a2e019e, which additionally incorporates main 1248e1eaa663874ec2546c05068bed758f688667. Its single source conflict preserves both incoming prepared-watermark reuse and active-path facts in one existing worker result. No extra query or check was introduced. Prior head ed5a2d70a4e55349d2ef29feae66a09b72c4faa3 passed all static checks in PR CI and main-tier CI: production/test types, lint, Knip, source contracts, database ratchets, and runtime topology/Madge. The latter run was stopped after static checks settled; canceled jobs are not passing coverage. Earlier complete CI at 2e631903584bd142ac1dc36641023be18b36bfd2 also passed the runtime suites.

Regression coverage exercises Memory classification after ordinary, dreaming, and cron owner writes, plus rollback without caller-thread SQL, active-path admission, projection repair, and cancellation. Earlier CI found and drove repairs to an import cycle, a missing async cancellation await, and repair scheduling; all were resolved before this integration.

Inherited static exception independently reproduced on main fe79a0ff62af6054619dcb5af5144ae96f6469d6: pnpm test src/plugins/contracts/boundary-invariants.test.ts --maxWorkers=1 fails the typed-hook allowlist rule at boundary-invariants.test.ts:369 with the same extra path extensions/x/src/work-origin.ts (11 other cases pass; 314.40 seconds). Neither the rule nor X registration is changed here. Other prior runtime failures involved unchanged cron/retirement/background-fault fixtures; the mismatched-window fixture is repaired by the pinned main integration.

No update cell is required: update, Doctor, schema/migration, plugin loading, and service lifecycle are unchanged. Against merged main 52dce97d15dff, the final diff is 33 files, +679/-541. Production is +297/-123, tests/test support +98/-195, docs +223/-222, and inventory tooling +61/-1. Final main-tier CI covers the complete static suite, including Knip omitted by the ordinary PR manifest.

Final-head inherited failures: the eight Knip-reported worker-contract files are byte-identical between this head, its integrated main 1248e1eaa663, and observed main 9bd2fe918222. The eager-import failure names the same unchanged user-turn transcript wrapper inventory and transcript-rewrite-effects source. The retirement fixture still expects only two entry fields instead of six; the Bash background-fault counter is also the same unchanged prior-head failure. These are not represented as passing coverage.

Landing qualification at 1a9fb1108ee2293883c19cc4a84f94e57a2e019e: PR CI 38235348594 and main-tier CI 38235434498 pass production/test types including all five core stripes, type-aware lint stripes, source contracts, T1/dialect/worker ratchets, and runtime architecture/Madge (zero cycles). Security-fast and all seven Security High checks pass. No SDK/API surface changes occur in this PR's final diff; its optional SDK report is not a gate.

The failing Knip production scan is independently reproduced on clean main 1248e1eaa663874ec2546c05068bed758f688667: exit 1, exactly the same eight unused worker-contract files and no extra findings. The prior full Knip scan passed at ed5a2d70a4e55; later lane changes are the inspected conflict-only integrations. Remaining known runtime failures are the unchanged cron worker-mock cases, retirement projection fixture, background-fault counter, and transcript-wrapper extraction; X hook allowlist and locale fallback drift are inherited. The native provisioning exception uses head-pinned REST squash under the authorized inherited-failure route, with these failures retained as failures rather than passing coverage.

Current-main Knip citation: scheduled main CI 38237812441, dependency job 114773017152 on main d2154d5 reports exactly the same eight unused worker-contract files. This independently corroborates the isolated main 1248 reproduction.

Shared read-family audit

The tightened attribution rule also counts shared read families (successful SELECT executions, classified by the first non-infrastructure SQL source). These are per-turn means across the ten warmed turns in the same immutable pair, not new measurements.

Shared family Baseline / turn Candidate / turn Whole workload before → after
Exact-entry facts 9.6 12.2 157 → 188
Actor hydration 5.2 5.5 78 → 83
Entry-cache snapshot loads 0.3 1.7 12 → 34
Row-facts SELECTs 5.1 5.1 72 → 71
Watermark SELECTs 7.1 7.1 97 → 93

The original-pair attribution limits are preserved above; the completed entire-workload recheck and final disposition follow below.

Latest conflict-only integration: c2d5f01380e1467326a05b8cdb0778fcbcab14b5 merges main 52dce97d15dffd6dad9b8814a0f5661f030975fd. Only the generated inventory conflicted; canonical regeneration reports 628 files / 2391 expressions, whole-repository T1 536 and original-lane T1 42. The source auto-merge reuses main's existing transcript-anchor equality helper without adding SQL. Basic lint/format and whitespace checks pass; exact-head static qualification is complete.

Inherited merge-ref compile failure after actor revert #169811: main 483b8fdaa602e115b2827054001f590a82a29eb5 restores session-actor-memory-reports.ts, which imports missing isSteerConfirmationRewrite at line 26. Main CI 38241498196, production types job 114785384700 reports the identical TS2305. PR2 exact head c2d5 does not contain that file and leaves the export owner unchanged from its main base. This is an inherited main failure, not a reason to restore the deleted helper in this lane.

Final entire-workload recheck and landing disposition

After two diagnostic candidate attempts timed out during connection before any turn, the replacement candidate used the original successful-pair harness and passed every RPC, all 13 turns, child completion, cron, compaction and shutdown. Source is still pinned to baseline 9c54108f9f20a and combined candidate 22bf8aa966027. The diagnostic baseline has extra cache-decision logging; SQL semantics are unchanged, but this asymmetric instrumentation means neither timing nor a controlled performance saving is claimed.

Measurement Baseline Candidate
Warmed statements, median [min–max] 343.5 [328–409] 347.5 [302–447]
Warmed requests, median [min–max] 95 [91–119] 97 [83–117]
Warmed MAIN statements, median [min–max] 0 [0–2] 0 [0–2]
Warmed statements / requests, per-turn mean 348.0 / 96.9 357.1 / 99.0
Warmed MAIN statements, per-turn mean 0.2 0.4
Whole-workload statements / requests 9929 / 1889 9850 / 1851
Whole-workload MAIN statements 1989 1992
Shared family Warmed per turn, before → after Whole workload, before → after
Exact-entry facts 10.9 → 11.4 173 → 172
Actor hydration 6.2 → 5.5 87 → 81
Entry-cache snapshots 1.1 → 1.3 27 → 24
Row-fact SELECTs 5.4 → 5.1 73 → 72
Watermark SELECTs 7.4 → 7.1 98 → 97

This satisfies the RAW TURN INCREASE entire-workload recheck: total statements, requests and every required shared-family total decrease, while warm-window work is redistributed. The two replacement admission misses follow real Memory commits by 11.52ms and 4.27ms. The two extra warm snapshots are one extra Memory corpus cycle and one registry request sent in first-turn but executed in the warm window. Three added ordered writer reads and two reader misses also follow Memory commits. The original C05 admission and one replacement turn-01 ordered writer miss still lack a recorded cache-rejection reason; they are retained as individual attribution limits, not declared proven noise. Their shared families add no whole-workload work. The extra MAIN statements are unchanged scheduled GitHub OAuth maintenance, outside this lane.

Per-operation recheck: warmed transcript hydration remains 240 statements / 20 requests, anchors 110/10, entry patch commit 370/60 and patch preparation 60/30. Row facts are 270/54 → 255/51. The lifecycle projection's 120/10 → 133/10 is one existing tracker initialization batch; no new lifecycle request. No SQL saving is claimed for this owner/API cutover.

Latest exact-head qualification at c2d5f01380e1467326a05b8cdb0778fcbcab14b5: same-revision main-tier CI 38241479721 passes production and general test types, all five core test-type stripes, all five core lint stripes, source contracts, database ratchets, guards and full architecture/Madge (job 114785227939). All seven Security High slices, OpenGrep and Critical Quality pass. Production Knip repeats exactly the eight known main findings. The earlier manual run 38241142044 stopped at preflight because incompatible main-tier/qualification inputs were selected; it ran no test and was replaced with the supported same-revision dispatch.

Landing uses the authorized inherited-failure exception: PR openclaw/ci-gate 114786809230 is red from the independently confirmed main-only stale import and the documented inherited fixtures. Exact-head static and security checks above pass; corrected-run packaging/build jobs were still running at submission and are not reported as passes. The head remains c2d5f01380e1467326a05b8cdb0778fcbcab14b5.

Post-merge: package-boundary job 114785228128 passed. After recording qualification and verifying merge 8239692596a9199b532b0fcd8e35800bfa901a8e, cancellation was requested for remaining optional work in main-tier run 38241479721 to release CI capacity; ordinary run 38241088102 had already completed. Unfinished or canceled jobs are not passing coverage.

Carry active-path facts through the existing session entry reader for chat
admission, and await the same owner before Stop cancellation. Remove
redundant recovery leaf rereads and their timing-only coverage.

Read archive classification through the existing Memory corpus worker and
delete the unused synchronous discovery path. Preserve native incognito
behavior for its separate owner cutover.

Basic lint retains only the existing chat-abort-runtime line-cap violation,
with the exact baseline count preserved. Tests and typechecks are deferred
to PR CI by the campaign workflow.
# Conflicts:
#	docs/reference/database-schemas/worker-access-inventory.md
@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 in progress

ClawSweeper is reviewing this revision. This supersedes any previous blocked status.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation channel: discord Channel integration: discord channel: matrix Channel integration: matrix channel: signal Channel integration: signal channel: slack Channel integration: slack channel: telegram Channel integration: telegram app: macos App: macos app: web-ui App: web-ui gateway Gateway runtime extensions: memory-core Extension: memory-core cli CLI command changes scripts Repository scripts commands Command implementations labels Oct 12, 2026
@clawsweeper clawsweeper Bot added the status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. label Oct 12, 2026
Use the existing commit-only native deletion participant for initialization rollback, including sessions without native bindings. The worker receipt consumes the host initializer only when its row was deleted. Retain native transactions only for opaque SDK callbacks. Cover caller-thread SQL and rollback completion for bound and unbound initializers.
# Conflicts:
#	docs/reference/database-schemas/worker-access-inventory.md
#	docs/reference/database-schemas/worker-access.md
#	packages/memory-host-sdk/src/host/session-transcript-corpus.test.ts
#	scripts/database-worker-inventory.mjs
#	scripts/pr-lib/wrapper-components.txt
#	src/auto-reply/status.test.ts
#	src/config/sessions/session-accessor.sqlite-deletion.ts
…t1cut-s1-memory

# Conflicts:
#	docs/reference/database-schemas/worker-access-inventory.md
@openclaw-barnacle openclaw-barnacle Bot added size: L and removed app: web-ui App: web-ui commands Command implementations extensions: qa-lab size: XL labels Oct 12, 2026
@steipete steipete changed the title refactor(sessions): move chat leaf and Memory archive reads to workers refactor(sessions): validate chat leaves through workers Oct 12, 2026
@clawsweeper clawsweeper Bot added the merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. label Oct 12, 2026
…t1cut-s1-memory

# Conflicts:
#	docs/reference/database-schemas/worker-access-inventory.md
Base automatically changed from dbasync/t1cut-s1 to main October 12, 2026 09:08
…t1cut-s1-memory

# Conflicts:
#	docs/reference/database-schemas/worker-access-inventory.md
#	src/gateway/server-methods/chat-abort-runtime.ts
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 merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. scripts Repository scripts size: L 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