Skip to content

perf(sessions): reuse actor replica for entry and target reads - #168677

Merged
steipete merged 62 commits into
mainfrom
dbasync/pcentry
Oct 11, 2026
Merged

steipete merged 62 commits into
mainfrom
dbasync/pcentry

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

Warm chat turns repeatedly discover the same session store and reload the same session entry, despite the session actor already publishing committed facts. This is the Phase C entry/target reader lane, stacked on #168602.

User Impact

Reduces database work during ordinary turns without changing session data, public APIs, configuration, or update behavior. Cold entries, historical session-ID lookups, and reads requiring missing membership/participant facts continue through the existing bounded worker read.

Why This Change Was Made

Entry readers now share the actor's bounded MAIN replica instead of maintaining a second entry cache. Complete commit receipts refresh entry-only facts without certifying transcript/custody state; source-only metadata notices preserve those facts. Cache lifecycle resets clear residency and lazily restore the receipt subscription. Ordered cohorts keep their existing writer ordering and before/after consistency check. Native writes without a sealed postimage invalidate the projection and require one cold read before reuse.

Store selection reuses registry- and physical-identity-bound results. Fixed-store inventory also observes in-process writes; family/scoped inventories retain discovery because their sibling row dependencies are not exhaustively captured. Current-session transcript selection consumes the prepared entry; historical/keyless selection retains the persisted index. ACP metadata and subagent-run maintenance remain with their existing independent owners.

Evidence

Pinned comparison: base 6e8a0034934c vs candidate 15defc052238; three alternating pairs (M,C,M,C,M,C) on the same AWS c7a.8xlarge, using the shared workload. Warmed values are each run’s mean of ten turns, summarized as median [min–max].

Phase All-thread SQL, M → C MAIN SQL, M → C All-thread requests, M → C Database requests, M → C Duration C/M
01.boot 2150 [2149–2150] → 2150 [2149–2151] 1925 [1925–1925] → 1925 [1925–1925] 59 [59–59] → 59 [59–59] 57 [57–57] → 57 [57–57] 1.001
total 15581 [15566–15608] → 15555 [15547–15564] 2409 [2406–2409] → 2406 [2406–2415] 2959 [2955–2961] → 2471 [2470–2472] 2577 [2573–2579] → 2323 [2322–2323] 1.000
01.connect 1024 [1024–1025] → 1025 [1023–1030] 94 [94–94] → 94 [94–100] 51 [51–51] → 51 [51–51] 49 [49–49] → 49 [49–49] 1.003
02.first-turn 1656 [1647–1675] → 1671 [1664–1673] 57 [57–57] → 57 [57–57] 274 [274–275] → 244 [244–245] 241 [241–242] → 226 [226–227] 1.002
03.warmed-per-turn 682.5 [682.5–682.9] → 680.4 [680.2–681.9] 11.2 [11.2–11.2] → 11.2 [11.2–11.2] 169.8 [169.8–170.2] → 139.1 [138.9–139.1] 146.6 [146.6–147] → 130.9 [130.9–130.9] 0.997
04.second-session 2714 [2708–2714] → 2695 [2694–2700] 106 [106–106] → 106 [106–106] 621 [619–621] → 520 [519–521] 545 [543–545] → 490 [489–491] 0.997
05.control-plane 18 [18–18] → 18 [18–18] 0 [0–0] → 0 [0–0] 5 [5–5] → 5 [5–5] 5 [5–5] → 5 [5–5] 1.000
06.cron 807 [807–807] → 806 [806–806] 26 [26–26] → 26 [26–26] 161 [161–161] → 142 [142–142] 144 [144–144] → 134 [134–134] 0.999
07.compaction 273 [273–273] → 269 [269–269] 24 [24–24] → 24 [24–24] 74 [74–74] → 45 [45–45] 61 [61–61] → 45 [45–45] 0.979
08.shutdown 114 [114–118] → 114 [105–118] 65 [62–65] → 62 [62–65] 14 [14–15] → 14 [14–15] 7 [7–8] → 7 [7–8] 0.997
Warmed operation Requests M → C SQL M → C SQL delta
session-target-inventory 8 [8–8] → 6.8 [6.6–6.8] 8.1 [8.1–8.1] → 6.9 [6.7–6.9] -1.2
session-store-target 13.8 [13.8–13.8] → 0 [0–0] 0 [0–0] → 0 [0–0] 0
session-exact-entries 8.6 [8.4–8.6] → 8.6 [8.6–8.7] 22.6 [22.4–22.6] → 22.6 [22.6–22.7] 0
session-entry-read 2.9 [2.9–3] → 3 [3–3] 2.9 [2.9–3] → 3 [3–3] 0.1
session.entry.read 4.3 [4.3–4.7] → 4.3 [4.2–4.4] 16.3 [16.3–16.7] → 16.3 [16.2–16.4] 0
session-runtime-target 2 [2–2] → 1 [1–1] 5 [5–5] → 4 [4–4] -1
acpSessions.metadata 2 [2–2] → 2 [2–2] 0.3 [0.1–0.4] → 0.3 [0.2–0.3] 0
subagents.runs 1 [1–1] → 1 [1–1] 1 [1–1] → 1 [1–1] 0
session.actor.read 0 [0–0] → 0 [0–0] 0 [0–0] → 0 [0–0] 0

Warmed all-thread request reduction: 30.7/turn (18.1%); database requests: −15.7/turn; SQL: −2.1/turn; MAIN SQL unchanged at 11.2/turn. This is a smaller saving than the lane aim: remaining exact-entry, ACP/subagent, and family-inventory reads keep this subsystem above the ≤10-request/≤30-statement target. They are not claimed as removed.

The original first-turn median is +15 SQL (+0.91%), so the RAW TURN INCREASE rule triggered the one extra alternating pair. The AWS lease expired during that attempt; a replacement hit the regional vCPU limit. The completed extra pair used one Hetzner ccx33, the same pinned commits, Node 24.21.0, pnpm 12.9.0, and the same workload. It is reported separately rather than pooled into the original three-pair statistics.

Extra-pair window All-thread SQL M → C MAIN SQL M → C All-thread requests M → C Duration C/M
First turn 1,728 → 1,691 (−37) 117 → 57 290 → 253 1.035
Warmed per turn 671.5 → 674.5 (+3) 10.1 → 11.2 168 → 138.1 1.009
Entire workload 15,576 → 15,503 (−73) 2,468 → 2,400 2,957 → 2,465 (−492) 1.014

Gate disposition: pass by the permitted entire-workload redistribution check. Both entire-workload SQL and requests fall in the extra pair; no duration ratio exceeds 1.5. The original warmed median falls, and the extra first turn falls. The extra warmed shift is +3 SQL/turn (+0.45%): corpus inventory contributes +3.3, unassigned/MAIN +1.1, tombstones +0.7, session.entry.read +0.5; inventory −1.3, runtime target −1.0, shared facts −0.3, exact entries −0.1, and ACP metadata −0.1 offset it. These are observed phase-placement/count differences, not a claim that all individual operation totals shrink.

Whole-workload operation evidence for the extra pair:

Operation SQL M → C Requests M → C
session-target-inventory 140 → 108 132 → 111
session-store-target 0 → 0 216 → 3
session-runtime-target 72 → 54 33 → 15
session-exact-entries 401 → 394 146 → 142
session-entry-read 44 → 45 44 → 45
session.entry.read 217 → 218 57 → 58
session-corpus-inventory 75 → 84 15 → 13
session-tombstones 60 → 64 15 → 13
model-context 121 → 127 18 → 18
transcript-stats 4 → 10 1 → 1
unassigned 2,609 → 2,547 0 → 0

The extra-pair baseline finished before a /tmp collection quota failure; its intact original output was validated and reduced in place. Candidate output used the root filesystem. One queued prewarm request lacked an owner stack in the reducer: it remains counted in total requests and is labeled unclassified rather than guessed as database/CPU work. No SQL/request was dropped, no workload was altered, and no additional successful pair was run.

Validation used one retained AWS Crabbox and the pinned stacked base above. Final head: 52 tests passed across five focused files, with pnpm test src/config/sessions/session-entry-read-ordered.test.ts src/config/sessions/session-actor-replica.test.ts src/config/sessions/session-accessor.transcript-identity.test.ts src/config/sessions/session-transcript-worker-readers.test.ts src/config/sessions/session-actor.test.ts --maxWorkers=1 taking 62 seconds wall time on the remote worker (62 runner-seconds; hosted CI timing is not claimed). Coverage includes post-write entry freshness, scoped invalidation, registry reassignment, fixed-store visibility, sibling-family writes, cold-read ordering, and full actor-state preservation. The final combined run also exercises cleanup and receipt resubscription between suites.

Production typechecking, formatting, lint, Madge (18 seconds), T1 (no growth), and dialect checks pass. Changed-file dialect groups are all 0 → 0. The full core-test typecheck passed in 408 seconds at 0abee34139b4; the subsequent change only repairs the internal replica subscription lifecycle, and final production typechecking and all focused tests passed. No test graph changed afterward.

check:changed was run remotely and stopped at the inherited environment budget (456 vs 455, reproduced on the exact base). Its expanded gates were then run individually so that the early failure did not hide later checks. Remaining out-of-scope failures: UI E2E test-root budget 722 vs advisory 720; unused exports in tools/solid-lint/index.mjs, src/cli/update-cli/update-command-post-activation-inspections.ts, and two session-channel fixture exports; Knip reports 16 unused files, unused @solidjs/signals, and unlisted @solidjs/compiler. None are in this lane's changed files. No budgets or baselines were loosened.

Diff size: production +475/−268 (net +207), tests +206/−9 (net +197), docs +10. The old independent entry-facts cache and subscriber are removed; the existing bounded actor pool owns those facts.

Two Codex autoreview rounds completed before the final targeted validation fixes. The repeated list-projection finding was rejected because direct list projections are ineligible for retention; partial/full snapshot coverage remains. The sibling-family inventory finding was accepted by removing that optimization and adding a sibling-write regression. No further review round under the lane's two-round cap.

No schema, migration, Doctor, updater, plugin-loading, service-lifecycle, or SDK changes; the published-driver update cell and SDK API diff do not apply.

…odules

Merge current main while preserving shared physical admission, cancellation, reader validation birthtime, and live deletion authority. Split worker usage, pool construction, failure settlement, and schema owner types to keep the existing line caps.
Checkpoint the single-owner cutover, cache invalidation regressions, and request-owned read transactions. Keep explicit migration verification. Paired measurement and final validation are still in progress.
Route retained existing-state writer coverage through the host-owned worker project, preserve first-admission incompatibility refusal, and match the final deletion-authority contract. Keep the gateway test under its inherited line count by moving existing pure fixture helpers. Regenerate assertion allowances without adding production assertions.
Include the thirteen transitive admission modules required by the native wrapper import-closure proof. Carry the existing birthtime through the worker validation fixture to preserve its physical-file identity.
Merge current main and preserve its optional settlement-only receipt delivery through the extracted owner. Keep the worker refusal error with the leaf contract to stay within the existing admission line cap. End the marker-free read-only fixture transaction normally; dedicated rollback and explicit revocation coverage remains unchanged.
Preserve snapshot-local reuse without freshness queries, publish dedicated archive writes, and remove Workboard polling. Retain native authority and settlement boundaries. Checkpoint reviewed corrections and focused regression repairs; final integrated proof remains in progress.
Define inactive typed durable phases, versioned hot snapshots, complete commit receipts, pure bookkeeping reducers, and unknown-outcome fencing. Share lifetime and settlement vocabulary with the existing incognito actor without changing routing or persistence.
@openclaw-barnacle openclaw-barnacle Bot added size: L and removed agents Agent runtime and tooling size: XL labels Oct 11, 2026
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. merge-risk: 🚨 automation 🚨 May affect CI, automerge, proof capture, label sync, or maintainer automation. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Oct 11, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

Landing review at 09aa2a62b70559f8f4e742c3f0b6dc4d81805b10: merged main without rebasing and retained the nine-file entry-reader delta. The conflict resolution preserves main's standalone reads outside the writer FIFO, active-writer borrowing, and complete wrapper dependency inventory, resolving the existing ClawSweeper findings.

Final-head Testbox proof: 57 tests across all six selected files passed (44 seconds). Type-aware oxlint, export-name collisions, formatting, and the database dialect ratchet passed. Knip reports only the same untouched-file exports seen in main CI: SQLITE_DATABASE_GENERATION_LENGTH and the four lobster-pet-look.ts exports.

Both failed PR test jobs are inherited from main run 38112256403:

Using the explicitly authorized inherited-failure exception and head-pinned REST squash fallback after native worktree operations exceeded the ten-minute stall threshold. The interrupted native operation was joined and its exact retained lock recovered. No product fix beyond the conflict-only merge was needed; no update cell applies.

@steipete
steipete merged commit 3bbc221 into main Oct 11, 2026
116 of 175 checks passed
@steipete
steipete deleted the dbasync/pcentry branch October 11, 2026 05:11
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 12, 2026
…law#168677)

* perf(sqlite): checkpoint shared admission across workers (WIP)

* test(sqlite): align worker fixtures with shared admission

* perf(sqlite): avoid repeated quarantine reads in retained scopes

* docs(sqlite): define single-owner database freshness

* perf(sqlite): replace runtime probes with writer publications

Checkpoint the single-owner cutover, cache invalidation regressions, and request-owned read transactions. Keep explicit migration verification. Paired measurement and final validation are still in progress.

* test(sqlite): align first-admission coverage and deletion fixtures

Route retained existing-state writer coverage through the host-owned worker project, preserve first-admission incompatibility refusal, and match the final deletion-authority contract. Keep the gateway test under its inherited line count by moving existing pure fixture helpers. Regenerate assertion allowances without adding production assertions.

* build(sqlite): include shared admission in compiled wrappers

Include the thirteen transitive admission modules required by the native wrapper import-closure proof. Carry the existing birthtime through the worker validation fixture to preserve its physical-file identity.

* test(sqlite): use the canonical settlement owner in publication proof

* fix(sqlite): complete writer custody and snapshot cache lifetimes

Preserve snapshot-local reuse without freshness queries, publish dedicated archive writes, and remove Workboard polling. Retain native authority and settlement boundaries. Checkpoint reviewed corrections and focused regression repairs; final integrated proof remains in progress.

* fix(sqlite): retain integrity and worker admission through cleanup

* test(sqlite): preserve reader coverage in existing fixture owners

* fix(sqlite): preserve cache receipts across sibling writers and temp DDL

* fix(workboard): type the replacement card-list promise

* fix(sessions): integrate receipt-based list revision reads

* perf(sessions): reuse committed entry facts across ordered reads

* refactor(sessions): identify fused query as worker-only

* fix(sessions): preserve receipt facts across read phases

* docs(sessions): clarify retained listing and alias guards

* refactor(sessions): define shared session actor contract

Define inactive typed durable phases, versioned hot snapshots, complete commit receipts, pure bookkeeping reducers, and unknown-outcome fencing. Share lifetime and settlement vocabulary with the existing incognito actor without changing routing or persistence.

* refactor(sessions): update actor cutover contract

* refactor(sessions): add inactive phase actor backend

* fix(sessions): preserve actor projection readiness and held facts

* perf(sessions): reuse retained transcript initialization facts

* test(sessions): split admitted cohort lifecycle coverage

* test(sessions): service actor fixture admission synchronously

* refactor(sessions): use shared string validation for entry facts

* feat(sessions): contract update 2 for existing incognito owners

* fix(sessions): preserve query builder method binding

* fix(sessions): reacquire incognito projection claims after actor commits

* test(sessions): distinguish model metadata from context messages

* refactor(sessions): separate actor contracts and share mutation executors

* docs(sessions): explain actor assertion invariants

* refactor(sessions): share native transcript presence query

* test(sessions): explain actor eviction mock isolation

* test(sessions): align actor fixtures with typed owner contracts

* fix(sessions): preserve actor callback bindings and audit inactive APIs

* fix(sessions): keep host config out of worker transport bundles

* feat(sessions): contract update 3 for scoped receipts and command preimages

* fix(sessions): reject mutations during actor authority admission

* fix(sessions): retain actor state across unrelated pending writes

* fix(sessions): preserve incognito transaction settlement contract

* test(sessions): keep scoped receipt fixtures within storage contracts

* refactor(sessions): separate receipt and transcript helper responsibilities

* fix(sessions): use scoped entry receipt for the adopted window

* fix(sessions): complete integrated actor reader references

* fix(sessions): finish actor validation cleanup

* chore(sessions): shrink moved assertion baseline

* refactor(sessions): simplify actor replica validation

* perf(sessions): reuse actor replica for entry reads

Share entry projections with the receipt-maintained MAIN actor replica, preserving ordered reads and complete snapshot coverage. Unrelated session writes retain warm entry facts; native entry postimages refresh them without a worker read.

* perf(sessions): reuse prepared storage targets

Reuse registry-owned target selection and current entry facts for runtime transcript access. Keep family inventories on the existing reader because sibling-row dependencies are not complete. Preserve canonical-path metadata in cached entry results.

* fix(sessions): retain entry receipts through metadata notices

* fix(sessions): keep queued receipt slots through unchanged markers

* chore(sessions): explain replica receipt iteration snapshot

* fix(sessions): restore replica subscription after cache reset
steipete added a commit that referenced this pull request Oct 12, 2026
The actor facts introduced by 3bbc221 (#168677) make a raw
same-inode corruption probe the wrong way to fault a prepared identity.
Close its existing owner synchronously after durable kill intent is
recorded, and retain the partial-cancellation and healthy-sibling
assertions. Remove the redundant raw-read throw and file rewrite; raw
corruption coverage remains in chat.abort-errors.test.ts.

The child case failed on the baseline because the cached read did not
throw. No production authority checks or behavior change.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 13, 2026
The actor facts introduced by 2cdcb4e (openclaw#168677) make a raw
same-inode corruption probe the wrong way to fault a prepared identity.
Close its existing owner synchronously after durable kill intent is
recorded, and retain the partial-cancellation and healthy-sibling
assertions. Remove the redundant raw-read throw and file rewrite; raw
corruption coverage remains in chat.abort-errors.test.ts.

The child case failed on the baseline because the cached read did not
throw. No production authority checks or behavior change.
steipete added a commit that referenced this pull request Oct 15, 2026
* fix(sessions): resolve cached transcript targets through their owner

resolveSessionTranscriptRuntimeTarget returned the requested key whenever
a retained entry row named the requested session ID. That does not prove
transcript ownership: an isolated cron run's row is written after its base
row and owns the shared transcript. After sessions.abort retained the base
row's facts, chat.inject on the base key hit the ownership check on every
attempt, while the uncached path wrote to the owner.

Retained facts carry no window owner, so drop the cached branch and always
read the persisted session-ID index, as the uncached path does. Each
resolution that used the cached branch now costs one runtime-target worker
request (one SQL statement, 1.2 when qualified); measured locally that is
about 0.5-1.8 ms at p50 per resolution, and the gateway concurrency
benchmark shows no difference beyond its noise. Publishing a proven
owner from actor state and write postimages would keep the cached branch
for those sources.

Proof: a Gateway WebSocket regression (sessions.abort, then two
chat.inject calls) and a resolver case for the shared session ID fail on
main and pass with the fix. The #168677 pin keeps its behavioral checks
(current transcript and lifecycle revision) without a read-count bound.

Refs #168677

* fix(sessions): preserve transcript ownership after cached entry reads

Resolve durable transcript targets through the admitted owner lookup when
cron base/run rows share a session ID. Preserve owner lifecycle revisions
and cover two ordered chat.inject calls after sessions.abort warms the row.

Close the steering fixture's extra tool-authority snapshot, which retains
one entry predicate and polluted the following Goal cleanup assertions.
Check zero retained facts at the originating fixture without changing the
production accounting or existing Goal assertion.

Fixes #170136

Co-authored-by: Serghei <[email protected]>

---------

Co-authored-by: Peter Steinberger <[email protected]>
Co-authored-by: Serghei <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 16, 2026
…aw#170137)

* fix(sessions): resolve cached transcript targets through their owner

resolveSessionTranscriptRuntimeTarget returned the requested key whenever
a retained entry row named the requested session ID. That does not prove
transcript ownership: an isolated cron run's row is written after its base
row and owns the shared transcript. After sessions.abort retained the base
row's facts, chat.inject on the base key hit the ownership check on every
attempt, while the uncached path wrote to the owner.

Retained facts carry no window owner, so drop the cached branch and always
read the persisted session-ID index, as the uncached path does. Each
resolution that used the cached branch now costs one runtime-target worker
request (one SQL statement, 1.2 when qualified); measured locally that is
about 0.5-1.8 ms at p50 per resolution, and the gateway concurrency
benchmark shows no difference beyond its noise. Publishing a proven
owner from actor state and write postimages would keep the cached branch
for those sources.

Proof: a Gateway WebSocket regression (sessions.abort, then two
chat.inject calls) and a resolver case for the shared session ID fail on
main and pass with the fix. The openclaw#168677 pin keeps its behavioral checks
(current transcript and lifecycle revision) without a read-count bound.

Refs openclaw#168677

* fix(sessions): preserve transcript ownership after cached entry reads

Resolve durable transcript targets through the admitted owner lookup when
cron base/run rows share a session ID. Preserve owner lifecycle revisions
and cover two ordered chat.inject calls after sessions.abort warms the row.

Close the steering fixture's extra tool-authority snapshot, which retains
one entry predicate and polluted the following Goal cleanup assertions.
Check zero retained facts at the originating fixture without changing the
production accounting or existing Goal assertion.

Fixes openclaw#170136

Co-authored-by: Serghei <[email protected]>

---------

Co-authored-by: Peter Steinberger <[email protected]>
Co-authored-by: Serghei <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. 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