Skip to content

refactor: move session catalog reads off the Gateway thread - #169620

Merged
steipete merged 10 commits into
mainfrom
dbasync/t1cut-s2-cache-catalog
Oct 12, 2026
Merged

steipete merged 10 commits into
mainfrom
dbasync/t1cut-s2-cache-catalog

Conversation

@steipete

@steipete steipete commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Cached session-entry reads repeated an identity query even though the Gateway already owns write receipts. Session catalog pages and fallback titles also read transcript SQLite on the Gateway thread.

User Impact

No intended user-visible behavior change. Catalog reads run in the existing history worker, and warm entry-cache hits avoid a redundant identity query. No schema, retention, migration, or update changes.

Why This Change Was Made

Reuse entry-cache facts under their existing writer receipts and validate identity when populating the cache. Catalog pages and asynchronous title reads use the existing history worker; title reads select the first 100 messages in one request without a count probe. The bundled session-share plugin uses the async API.

SDK migration: readSessionTranscriptCatalogTitle is deprecated and warns; use readSessionTranscriptCatalogTitleAsync. The synchronous public contract remains until a later release after the deprecation has shipped in a stable release.

Removed checks and accepted edge cases:

  • Cached identity reread: unmanaged external writes are outside the single-Gateway ownership contract; managed writes invalidate through receipts.
  • Post-clone cache recheck: a synthetic reentrant write during cloning can return the just-captured value; no second generation handshake is required.

Cursor branch validation and final source-authority checks remain because they protect transcript identity and disclosure.

Evidence

Independent Codex review completed in two scoped rounds with no actionable P0/P1 findings. Exact-read regression suite passed 31/31 (25.772 seconds wall), and six mock-consumer suites passed. The catalog worker test exposed a missing response-decoder case; the pushed head includes the fix. PR CI owns its rerun and the required static checks.

Live SQL measurement

Completed one sequential baseline/candidate repeat on isolated local Gateway state, reusing the existing builds. Baseline 734d5b57f1465527230b46d27da6ba01aef1c8ec; candidate source 988e39ac5cc0c1758bb7fef0c17c36a220678606, built production 0e7c5976adecc5ea94a25847817b38d389d0d9a6. The only source difference between the candidate build and measured checkout is a test expectation. Both sides passed all 13 turns, control-plane RPCs including mentions.dismiss, child completion, cron, compaction, shutdown, calibration, and exact request/statement accounting.

Window All-thread statements M → C Requests M → C MAIN statements M → C Seconds M → C
Warmed turn, 10-turn mean 362.7 → 361.3 (−1.4; −0.39%) 109.9 → 110.3 (+0.4; +0.36%) 0.2 → 0.2 4.764 → 5.823
First turn 764 → 782 (+18) 174 → 187 (+13) 36 → 38 23.321 → 52.969
Startup through shutdown 10,091 → 10,065 (−26; −0.26%) 2,055 → 2,066 (+11; +0.54%) 2,002 → 1,995 225.045 → 337.788

Within-run warmed distributions (median [min–max], not repeated-run statistics): statements 365.5 [305–494] → 358 [313–463]; requests 109 [94–137] → 109.5 [95–132]; MAIN 0 [0–2] on both sides.

The warmed duration ratio is 1.22×. The first-turn ratio remains 2.27×, so the first-turn count comparison is timing-contaminated and is not a valid first-turn gate. No additional pair was run after this authorized repeat.

The +0.4 warmed requests are the net of unchanged callers: actor reads +0.3, entry-worker reads +0.3, shared facts +0.2, catalog snapshot +0.1 and agent domain bind/execute/close +0.1 each, offset by domain publications −0.3, exact-entry requests −0.4 and ordered entry reads −0.1. Stack attribution found exactly 30.9 warmed SQL statements per turn through changed files on both sides: entry-cache 29.3 and entry-cache projection 1.6. Every ordinary entry-cache SQL class had identical counts. The two extra cold projection reads occur in first-turn and cron; the rest of the observed first-turn increase is outside changed stacks. The shared workload does not invoke the moved transcript catalog reader or the removed exact-cache identity SELECT; focused CI owns those regression contracts.

The shared harness was not changed. The copied harness sets server handshake timeout to 120 seconds (from 15 seconds) and client open/handshake timeouts to 120 seconds (from 8 seconds), equally on both sides. This followed a baseline connection timeout at the original 15-second limit. The first candidate copy lacked generated workspace artifacts; the exact failing import was reproduced and passed after copying existing package build artifacts, with no rebuild or product change. Those failed attempts are retained separately and contribute no measured turns.

The earlier completed pair had a mentions.dismiss failure and inconsistent timing, and is not used as passing proof. Both sides of this repeat pass mentions.dismiss; its earlier underlying exception remains unproven, so it is recorded as a transient observation rather than claimed to be inherited or fixed.

Assigned-file inventory under current classification: 45 → 44 T1 call expressions (plus two Doctor T3 calls and one worker call). The deleted expression is the cache identity query. Shared transcript kernels remain conservatively classified while deprecated SDK and native-incognito callers exist; this PR does not relabel mixed kernels worker-only.

Diff: 15 files (+260/−170). No published-driver update cell applies.

CI disposition

Final reviewed head: 3096604ac2881edb553c8726ce02e9213a00bcbc. Main integration was conflict-free; the PR remains 15 files (+260/−170). The integration brings in the already-landed fixes for four unrelated unused exports/types found by the earlier Knip run.

Exact-head PR CI 38224202992 passed source contracts, guards, architecture/Madge, baseline ratchets, core lint and security-fast. The changed-tests lane failed only on the previously reproduced raw-cursor continuity failure below. The run was subsequently canceled while remaining static work was active; canceled jobs are not claimed as passing.

Exact-head full CI 38224250243 supplies the remaining static evidence. Production types, all five core test-type stripes, extension test types, all five core lint stripes, lint, source contracts, guards, runtime-topology architecture/Madge and baseline ratchets passed. The exact-head PR extension package boundary and negative canary passed. The full-run plugin contract lane passed 23 files / 251 tests, including the runtime API guardrails. The generated SDK API-diff report passed in job 114728170409. The surface-budget check and runtime API safety gates are also green. The separate exact-head Workflow Sanity run 38224253901 passed the SDK surface-budget check.

Knip found two untouched main-owned items: unused gateway-prewarm.mjs and unused renderPublicSessionCardSvg in src/gateway/control-ui-public-session-card-render.ts. The identical rules fired on the identical files at current-main b82b033920ee7a4df6323e3ee2b04ac8c6037fe0 in 38224696307, job 114729780159. No PR-owned unused symbol was reported; this static red is inherited.

The inherited raw-cursor case is test/embedded-transcript-cursor.e2e.test.ts → resumes a public raw cursor across /new and the next Gateway turn, returning generation_mismatch. An isolated protected-main ancestor 0387f4f96a2963409bd0da3aa42f3510459bfea8 reproduced the same normalized error; #169469 records that qualification. The raw-delta comparison, cursor encoding and watermark owners are unchanged by this PR. This is inherited red evidence, not a passing cursor test or a claimed repair.

The additional full-suite reds are in untouched code: tooling fixture copies cannot find the recently added control-ui-public-session-card-render.ts; its suppression is absent from the lint-suppression allowlist; run-additional-boundary-checks.test.ts expects an outdated guard argument list; and session-transcript-hit.projection.test.ts catches eight background PRAGMA wal_checkpoint(PASSIVE) calls in an empty-SQL assertion. No changed entry-cache SQL appears in that assertion. These are recorded as unrelated findings, without claiming repairs.

Earlier built lifecycle CI observed a concurrent-delete run ending with status: error, AbortError: agent run aborted, and endedAt, but no stopReason. The unchanged proof helper accepts that terminal result only with a named stop reason. Focused baseline/candidate diagnosis was interrupted without a behavior result after module-graph compilation consumed 495.7/398.6 seconds; neither side is claimed to pass or fail. That limitation remains explicit; no product regression was established.

The remaining ClawSweeper P2 is accepted as a follow-up: an append between catalog worker replies can reject a valid cursor or repeat a page. Clients can restart pagination; final disclosure checks remain current. The follow-up is absolute sequence bounds, without a new owner or handshake.

@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.

@clawsweeper

clawsweeper Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge.

What this changes

This PR moves session catalog pages and fallback-title reads into existing workers and removes a redundant identity query from warm entry-cache reads.

Example: Session Share opens agent:main:catalog-worker, whose first user message is “Plan the migration.”

  • Before: The fallback title and transcript page are read synchronously on the Gateway thread.
  • After: Workers return the same title and transcript content.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The focused ownership refactor has no unaccepted code finding, but targeted runtime evidence is limited to test composition.
Proof confidence 🦐 gold shrimp (3/6) The maintainer-authored PR is outside the ordinary contributor proof gate; its targeted evidence is a real SQLite/worker test, while the recorded live Gateway workload explicitly excludes the changed catalog and cache-hit paths.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Refactor · Worth it: Yes · Fix scope: Complete
User problem: Catalog reads occupy the Gateway thread and can delay other requests.
Reason: The maintainer-authored change follows the existing worker ownership direction, retains public compatibility, and explicitly accepts the recoverable pagination edge case.

Merge readiness

⛔ Needs changes before merge - 1 item remains

Keep this PR open: current main still performs these catalog reads synchronously, and the maintainer has accepted the pagination edge case as a follow-up. No additional blocking code defect was established; failing CI still needs attribution before landing.

Priority: P2
Reviewed head: 3096604ac2881edb553c8726ce02e9213a00bcbc

Before merge

  • Complete next step - Attribute the exact-head dependency, declaration-fixture, boundary-check, and raw-cursor CI failures using complete logs and baseline evidence before landing; fix only failures caused by this diff.

Findings

None.

Tests

  • Missing end-to-end proof: The supplied live workload does not exercise catalog pages, async fallback titles, or warm exact-cache identity-query removal; the added regression's baseline failure was not demonstrated.
Agent review details

How this fits together

Session Share consumes the public transcript SDK; session-entry and history workers read agent SQLite stores, and the source command checks current sharing eligibility before returning catalog data.

flowchart TD
  A[Session Share command] --> B[Transcript SDK]
  B --> C[Session entry worker]
  B --> D[History worker]
  C --> E[Agent SQLite database]
  D --> E
  B --> F[Current sharing checks]
  F --> G[Catalog response]
Loading

Technical review

Best possible solution:

Land the worker migration once CI failures are attributed, preserving the current SDK compatibility window and the accepted pagination follow-up.

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

Current-main source directly shows synchronous SQLite catalog reads and the redundant cache identity query; their latency impact was not reproduced during this read-only review.

Is this the best way to solve the issue?

Reusing the existing workers and receipt-backed cache owner is appropriate, and retaining the synchronous SDK adapter avoids an immediate plugin break.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 2fc20b367b69.

Provenance checked

  • Warm exact-entry cache identity checks changes intended behavior with a stated reason (e1472df: Selected-row checks protected exact identity when listing snapshots omitted identity columns; subsequent write-receipt ownership provides managed-write invalidation.)
  • Catalog reads and pagination keeps the original intent (5278a8f: Read-only sharing preserves source ownership and validates cursor branch identity; this PR changes execution placement while retaining final disclosure checks.)
  • Synchronous transcript-title SDK contract keeps the original intent (5278a8f: The shared-session catalog exposes metadata-first title derivation with a bounded transcript fallback.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit e1472df adds src/config/sessions/session-accessor.sqlite-entry-cache.ts:152 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: e1472df83942; files: src/config/sessions/session-accessor.sqlite-entry-cache.ts)

PR surface

Source +77, Tests +5, Docs +8. Total +90 across 15 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 10 155 78 +77
Tests 4 97 92 +5
Docs 1 8 0 +8
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 15 260 170 +90

Review metrics

Metric Value Why it matters
SDK migration 1 additive async export; 1 retained deprecated synchronous export Bundled callers migrate while existing plugins retain the current-major signature.

Labels

Label changes:

  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • remove rating: 🦪 silver shellfish: Current PR rating is rating: 🦐 gold shrimp, so this older rating label is no longer current.

Label justifications:

  • P2: This is a focused runtime responsiveness improvement without evidence of an urgent user incident.
  • merge-risk: 🚨 compatibility: The public SDK gains an async replacement and deprecates its synchronous helper; the maintainer-approved direction retains current-major compatibility.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (5 earlier review cycles)
  • reviewed 2026-10-12T05:12:36.895Z sha eb36188 :: needs changes before merge. :: [P2] Pin catalog reads to absolute sequence bounds | [P2] Update the cache-test observer for identity-bearing snapshot rows
  • reviewed 2026-10-12T05:41:22.586Z sha 0e7c597 :: needs changes before merge. :: [P2] Pin catalog reads to absolute sequence bounds | [P2] Align lifetime assertions with the broader decode observer
  • reviewed 2026-10-12T06:56:23.278Z sha 05689bf :: needs changes before merge. :: [P2] Pin catalog reads to absolute sequence bounds | [P2] Accept retained-reader invalidation in the replacement test
  • reviewed 2026-10-12T07:21:36.704Z sha 5f94ae8 :: needs changes before merge. :: [P2] Pin catalog reads to absolute sequence bounds
  • reviewed 2026-10-12T08:05:46.140Z sha 11b967b :: needs changes before merge. :: [P2] Pin catalog reads to absolute sequence bounds

Reviewed October 12, 2026, 4:41 AM ET / 08:41 UTC (Revision 6).

@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. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Oct 12, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

The remaining catalog-pagination P2 is recorded as a follow-up under the maintainer's relaxed landing policy. A transcript append between worker replies can reject a valid cursor or repeat a page; clients can restart pagination, and the final source/disclosure checks remain intact. This accepted recoverable edge case does not permit stale sharing authorization or transcript disclosure. The follow-up is to pin both anchor and page reads to absolute sequence bounds through the existing reader operation.

@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Oct 12, 2026
@steipete
steipete merged commit 2c7cc82 into main Oct 12, 2026
240 of 309 checks passed
@steipete
steipete deleted the dbasync/t1cut-s2-cache-catalog branch October 12, 2026 08:54
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 13, 2026
…#169620)

Route catalog pages and fallback titles through the existing history worker, expose the asynchronous SDK title API, and migrate the bundled session-share caller.

Remove redundant exact-cache identity and post-clone rechecks under Gateway-owned write receipts. Keep the deprecated synchronous SDK contract until the next major.

Validated with focused regression tests, isolated live SQL measurement, Codex review, and CI static gates. Inherited CI failures and the accepted pagination edge case are documented in the PR.
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 gateway Gateway runtime merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. plugin: session-share rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: M status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant