Skip to content

perf(sessions): reuse participant and lifecycle read products - #169544

Merged
steipete merged 3 commits into
mainfrom
dbasync/readproducts
Oct 12, 2026
Merged

steipete merged 3 commits into
mainfrom
dbasync/readproducts

Conversation

@steipete

@steipete steipete commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Session entry reads repeated participant and lifecycle queries even when their current owner had already produced those facts.

User Impact

This reduces SQLite work for session reads without changing stored data, authorization, or public APIs.

Why This Change Was Made

Cohort and child-entry projections now reuse the existing entry cache's participant display product, whose lifetime is governed by in-process write receipts. Mixed batches query only missing products. Lifecycle entry reads use the existing fused entry/participant/membership query and derive timestamps from that same result, retaining the snapshot when a transcript-header fallback is needed.

Removed check: the fused worker read no longer captures the physical owner a second time after its synchronous read. Accepted edge case: a file replacement cannot be observed midway through that owner-held synchronous read; the next operation performs its normal admission. Cross-user membership and effect-boundary authorization remain unchanged.

The shared native participant reader remains one inventoried T1 call site (1 → 1); the changed worker is 0 → 0. This is the requested escape hatch: deprecated synchronous Plugin SDK getSessionEntry / listSessionEntries still reach this shared reader, as do native admission/projection owners. Moving that shared owner wholesale requires their async API/replica cutover; relabeling it worker-only would hide real exposure. No synchronous fallback was added.

Evidence

Metric per warmed turn Base median [min–max] Candidate median [min–max]
All-thread statements, original 3 pairs 321.4 [320.1–328.7] 325.2 [324.8–330.4]
Logical worker requests, original 3 pairs 92.0 [91.8–92.9] 92.4 [91.9–92.8]
Gateway MAIN statements 0 [0–0] 0 [0–0]
Standalone participant SELECTs 24.7 [24.7–25.0] 22.8 [22.8–22.9]
Exact-entry operation statements 20.2 [20.2–20.4] 18.7 [18.7–20.4]

The raw-turn increase triggered the required extra complete-workload pair. M4 → C4: 9,475 → 9,435 statements and 1,779 → 1,777 requests, with warmed statements 328.2 → 318.3 and requests 92.7 → 92.2. Across all four pairs the warmed medians are 324.8 → 325.0 statements (+0.06%), 92.35 → 92.30 requests, and 0 MAIN. Participant SELECTs fall 24.8 → 22.8 per turn. This is a roughly two-statement subsystem saving, not a claim of a large net-turn improvement.

Raw phase medians (first three pairs, statements): boot 2,012 → 2,012; connect 1,058 → 886; first turn 971 → 1,102; second session 1,399 → 1,397; control 15 → 13; cron 523 → 523; compaction 170 → 170; shutdown 89 → 89. The higher first/warmed counts move among existing startup, actor acquisition, lifecycle projection, and row-facts operations; the extra whole-workload pair is lower in both counted metrics. For example the 3.1-SQL warmed database.prepareWrite burst appears in baseline M3 and candidate C1/C3, and the 13-SQL lifecycle burst appears in baseline M3 and candidate C1/C3. No new request type was introduced. Warm duration median ratios are 1.0003 for the first three pairs and 0.996 across four; every gated phase ratio is below 1.5. Native calibration: 8 calls / 2 prepares / 7 successful statements / 0 failures in each of main and worker.

Measured on one AWS Crabbox with the unchanged shared harness workload, alternating M,C,M,C,M,C. Base: a52a29f82299e563e3a200966a77412dcc3bdc8b; candidate: c36320881ca36435aa9ec6055349c919540d0a37 (verified tree). The subsequent main merge was conflict-free and did not change either production file.

On the merged head, all four focused suites pass: participant products (corrected fixture: 12.23s), cohort worker (23s), entry-read worker (18s), and SQLite participants (40s). These are pnpm test <file> --maxWorkers=1 equivalent repository-runner wall times on AWS; hosted CI seconds are not yet measured. The lifecycle regression fails on the baseline. Both participant cases fail on baseline with the redundant multi-key SELECT and pass on the candidate. The fixture uses two rows to defeat the pre-existing single-key memo and checks cache freshness after an in-process participant write plus caller-owned nested data.

Type-aware Oxlint: 0 warnings/errors. Export-name/source contracts pass. Madge: 0 cycles. check:changed passes its typechecks, formatting, contracts and ratchets; its Knip failure is inherited: the exact merged head and its main parent produce the same 88 findings, zero new findings. The full-tree Knip comparison includes production, full-tree and script export scans. T1 ratchet on the merged head: 607 → 607 raw, 605 → 605 normalized; dialect groups: 0 → 0 growth.

No schema, migration, update, Doctor, plugin-loading, service lifecycle, or SDK surface change; the published-driver update cell and SDK API diff do not apply. Codex autoreview rounds 1 (production change) and 2 (test-only correction) found no actionable P0/P1 issue.

Scope: production +37/−24 lines; tests +70/−3 lines. No changelog edit; release-note context is this PR's reduction of repeated session read queries.

CI disposition: required run 38196019109 failed only in checks-node-compact-small-1, at test/scripts/eager-import-closure.test.ts ("resolves wrapper package exports and workspace aliases from the extracted dependency context"). This duplicate-entry assertion reports src/chat/sender-identity.ts, src/sessions/input-provenance.ts, and src/sessions/user-turn-transcript.metadata.ts. An independent current-main checkout at 734d5b57f1465527230b46d27da6ba01aef1c8ec fails the exact test with the same three duplicates (15.27s including the runner). The test, helper, and inventory are outside this four-file PR. Native review initialization exceeded ten minutes; landing uses the authorized head-pinned REST fallback with the inherited-CI exception. No ClawSweeper wait was requested.

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

@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 12, 2026
@clawsweeper

clawsweeper Bot commented Oct 12, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge.

What this changes

This PR reuses current participant display facts and combines lifecycle timestamps with the existing fused session-entry read.

Example: Read children of agent:main:parent after warming participant facts for agent:main:child and agent:main:sibling.

  • Before: The child batch queries session_participants again.
  • After: Current cached participant identities are returned without that query, and committed participant changes invalidate reuse.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The focused patch and reported runtime comparison support its value, but the exact-head CI failure remains unattributed.
Proof confidence 🐚 platinum hermit (4/6) The supplied maintainer-authored status places this PR outside the ordinary contributor proof gate; its body reports scoped Crabbox Gateway measurements and baseline-failing regressions, with unchanged measured production files at the reviewed head.
Patch quality 🦐 gold shrimp (3/6) No actionable review findings were identified.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: Session reads repeat SQLite work for facts their existing owner has already produced.
Reason: The supplied maintainer-authored direction supports this small optimization; it preserves existing contracts and accurately limits the performance claim.

Merge readiness

⛔ Needs changes before merge - 1 item remains

Keep this PR open: it provides a focused, maintainer-directed optimization that current main does not contain, with no actionable introduced defect found; the failed CI gate still needs attribution.

Priority: P2
Reviewed head: da36825434a07d613127cf7ef4ed2dd2a2a4c380

Before merge

  • Complete next step - Attribute the failed extracted-wrapper import-closure assertion using the executed revision and a matching base comparison; repair it only if this PR caused it.

Findings

None.

Agent review details

How this fits together

Session accessors and read workers turn admitted SQLite session rows into entry, participant, membership, and lifecycle facts consumed by chat preparation and session projections.

flowchart TD
  A[Session read callers] --> B[Existing entry reader]
  B --> C[Participant display cache]
  B --> D[Fused SQLite facts]
  D --> E[Lifecycle header fallback]
  C --> F[Caller owned results]
  D --> F
  E --> F
  G[Committed writer receipts] --> C
Loading

Technical review

Best possible solution:

Retain the existing cache and fused-read owners, and land this focused optimization once the failed required check is resolved or demonstrably inherited.

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

Base source repeats participant acquisition for these consumers and excludes lifecycle reads from the fused path; the PR reports regressions failing on the baseline, but this review executed no target code.

Is this the best way to solve the issue?

Reusing the existing revision-checked display product and fused query is a proportionate solution that preserves detached results and lifecycle snapshot consistency.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Participant batch and cohort projection keeps the original intent (cf32d5a: Reuse worker-maintained participant and membership snapshots while preserving ordering, ownership, and revocation behavior; the existing entry-cache lender was subsequently added by perf(sessions): reuse current participants across transcript appends #157622.)
  • Fused lifecycle reads and repeated physical-owner capture changes intended behavior with a stated reason (ea4693e: Reduce repeated entry, participant, and membership acquisition while retaining composite snapshots and existing authority owners.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

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

PR surface

Source +13, Tests +67. Total +80 across 4 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 2 37 24 +13
Tests 2 70 3 +67
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 107 27 +80

Review metrics

Metric Value Why it matters
Production versus test changes Production +37/−24; tests +70/−3 The net production growth extends existing read products without adding a cache owner; tests protect query reuse, mutation freshness, and caller-owned identities.

Labels

Label changes:

  • add P2: This is a bounded session-read efficiency improvement with a small subsystem saving and no established urgent user regression.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🐚 platinum hermit and patch quality is 🦐 gold shrimp.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Label justifications:

  • P2: This is a bounded session-read efficiency improvement with a small subsystem saving and no established urgent user regression.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🐚 platinum hermit and patch quality is 🦐 gold shrimp.
  • 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.

Reviewed October 11, 2026, 10:36 PM ET / October 12, 2026, 02:36 UTC.

@steipete
steipete merged commit 16d9130 into main Oct 12, 2026
125 of 185 checks passed
@steipete
steipete deleted the dbasync/readproducts branch October 12, 2026 02:55
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 12, 2026
…aw#169544)

Reuse current entry-cache participant products for cohort and batch projections, query only cache misses, and derive lifecycle facts from the fused worker read. Remove the duplicate physical-owner capture.

In-process write receipts preserve freshness; cross-user membership checks stay intact. About two fewer participant SELECTs per warmed turn, with total warmed SQL within measurement noise and zero measured main-thread statements. The shared synchronous SDK participant reader remains an explicit follow-up.

Focused owner suites, regression-before/fix-after proof, static checks, and two Codex reviews completed. The unrelated wrapper-inventory duplicate assertion also fails on main.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: S 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