Skip to content

perf(sessions): read lifecycle and timestamp-only session facts through the list projection - #164125

Merged
steipete merged 2 commits into
mainfrom
steipete/sqlite-session-read-projection
Oct 3, 2026
Merged

steipete merged 2 commits into
mainfrom
steipete/sqlite-session-read-projection

Conversation

@steipete

@steipete steipete commented Oct 3, 2026

Copy link
Copy Markdown
Contributor

What Problem This Solves

Subagent lifecycle reconciliation and inbound session timestamps load saved prompts and diff baselines even though their consumers need only metadata.

User Impact

Lifecycle results and timestamps stay the same while these reads avoid cold snapshot lookups, decoding, and worker transfer. No migration, configuration, schema, durability, or retention change is required.

Why This Change Was Made

Select the existing list projection at the two reconciliation read sites and the timestamp accessor. The synchronous loader replaces its unused clone: false option. Audited consumers use hot identity, lifecycle, recovery, status, and timestamp fields. Existing canonical validation and physical/incognito owner selection remain authoritative; public full-read defaults and mutation/equality fences are untouched.

This does not move the synchronous sweeper or SDK timestamp surface off the host thread. Related: #149358 addresses whole-store listing consumers; this change covers only keyed reconciliation and timestamp reads.

Evidence

For each affected canonical target-row read, the data statement count stays 1 SELECT → 1 SELECT, with 3 → 0 correlated session_entry_snapshots subqueries and up to 3 → 0 cold JSON parses. Participant and admission/freshness reads are additional and variable. SQL spies verify the selected statement; a target row with three large cold fields verifies preserved completion/start facts and no cold worker-message payload. The real-store timestamp case returns exactly 42. Both regressions fail on the original production code and pass with the projection changes.

Existing opt-in component benchmark, 128 rows and a 35,054-byte fixture: full-entry control 0.21765 ms/read, 102,137 sampled allocation bytes/read (100 calls); list 0.08513 ms/read, 16,678 bytes/read (1,000 calls). Phase RSS was 259.07→263.57 MB for full and 257.75→262.52 MB for list. These are local component measurements with unequal sample counts and allocation sampling, not end-to-end latency or a production timing guarantee.

Production +3/−3 (net 0); tests +82/−1 (net +81) against the branch merge base. Four files changed.

Command Wall time Result
pnpm test src/agents/subagents/registry/subagent-session-reconciliation.metadata-read.test.ts --maxWorkers=1 345.15 s 1 passed
pnpm test src/config/sessions/session-accessor.conformance.test.ts --maxWorkers=1 313.01 s 44 passed
pnpm test src/agents/subagents/registry/subagent-session-reconciliation.test.ts src/channels/session-envelope.test.ts --maxWorkers=1 176.07 s 10 passed
OPENCLAW_SESSION_ENTRY_SNAPSHOTS_BENCH=1 pnpm test src/config/sessions/session-entry-snapshots.benchmark.test.ts --maxWorkers=1 92.26 s 1 passed

Wall times include worker preparation and cleanup. The changed lifecycle test took 7.766 s; the new timestamp case took 0.571 s. The existing conformance file spends 212 s exercising entry/transcript writes, lifecycle cleanup, and maintenance; this PR adds only the focused timestamp case. CI seconds are not yet available; this handoff stops at exact-head CI attachment.

Gateway setup, changed-file oxfmt, core oxlint, and git diff --check passed. No broad typecheck was run under the scoped work order. Codex autoreview: scoped-clean through P2, no accepted/actionable findings. An initial baseline attempt failed before collection because setup was still generating plugin assets; serializing setup and tests resolved that tooling failure.

Avoid cold snapshot selection, decoding, and worker transfer for metadata-only reconciliation and activity timestamps. Preserve the existing session owner, canonical validation, public full-read defaults, and mutation fences.
@clawsweeper

clawsweeper Bot commented Oct 3, 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 agents Agent runtime and tooling size: S labels Oct 3, 2026
@steipete
steipete marked this pull request as ready for review October 3, 2026 07:21
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 3, 2026
@clawsweeper

clawsweeper Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 3, 2026, 5:10 AM ET / 09:10 UTC (Revision 2).

ClawSweeper review

What this changes

Use existing metadata-only session reads for subagent lifecycle reconciliation and activity timestamps, avoiding unnecessary saved prompt and diff payloads.

Merge readiness

✅ Ready for maintainer review

The optimization remains useful: current main and the latest release still perform full reads at the affected sites. No actionable introduced defect was found.

Priority: P2
Reviewed head: 5b8c8579e723ece0e9c51690faa5203a9f1ae57e

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused optimization with meaningful regression coverage and no actionable correctness finding.
Proof confidence 🌊 off-meta tidepool Not applicable: The supplied MEMBER classification exempts this internal PR from external-contributor proof. Reported real SQLite and production-worker regressions exercise reconciliation and timestamp reads, with component benchmarks as supplemental evidence; no stored-data contract changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The supplied MEMBER classification exempts this internal PR from external-contributor proof. Reported real SQLite and production-worker regressions exercise reconciliation and timestamp reads, with component benchmarks as supplemental evidence; no stored-data contract changes.
Evidence reviewed 8 items Pinned introduction and review continuity: Inspected the merge-base-to-head delta. Comparing all four affected files against the earlier reviewed head produced no differences; the earlier review reported no findings. The stale test merge was not used to infer merge behavior.
Projection preserves consumed facts: The existing list parser omits only sessionDiffBaseline, skillsSnapshot, and systemPromptReport. Audited reconciliation, restoration, orphan checks, and cleanup callers consume retained identity, status, timestamps, lifecycle revision, execution, and recovery fields. Canonical validation, participant projection, physical-owner selection, and caller-current checks remain in their existing owners.
Focused regression coverage: The changed lifecycle test uses real SQLite and the production worker read path, checks completion/start facts, and observes that cold payloads do not cross worker messages. The timestamp case checks exactly 42 and absence of cold snapshot SQL or parsing. The body reports baseline failures and candidate passes, plus measured test costs and explicitly bounded component benchmarks; these execution claims were not rerun during this read-only review.
Findings None None.
Security None None.

How this fits together

OpenClaw stores session identity, lifecycle facts, and larger snapshots in SQLite. Reconciliation and inbound-message timestamp consumers need the metadata but do not need those snapshots.

flowchart TD
  A[Subagent reconciliation] --> C[Session read owner]
  B[Inbound timestamp lookup] --> C
  C --> D[Metadata projection]
  E[SQLite session storage] --> D
  D --> F[Lifecycle results]
  D --> G[Previous activity timestamp]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source 0, Tests +81. Total +81 across 4 files.

View PR surface stats
Area Files Added Removed Net
Source 2 3 3 0
Tests 2 82 1 +81
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 85 4 +81

Review metrics

Metric Value Why it matters
Cold snapshot work 3 → 0 correlated snapshot subqueries per canonical target read The existing projection removes unnecessary snapshot work without adding another target-row SELECT.

Technical review

Best possible solution:

Keep projection selection at audited metadata consumers while preserving full reads for snapshot consumers and mutation fences.

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

Yes, source establishes that current-main metadata consumers select and decode unused cold snapshots; the supplied regression scenarios target that path. Execution was not repeated in this read-only review.

Is this the best way to solve the issue?

Yes, selecting the existing projection at these audited consumers is a narrow solution that preserves storage ownership, validation, and public full-read defaults.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

No label changes.

Label justifications:

  • P2: This is a bounded performance improvement for recurring session metadata reads, with no demonstrated urgent user-facing regression.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The supplied MEMBER classification exempts this internal PR from external-contributor proof. Reported real SQLite and production-worker regressions exercise reconciliation and timestamp reads, with component benchmarks as supplemental evidence; no stored-data contract changes.

Evidence

What I checked:

  • Pinned introduction and review continuity: Inspected the merge-base-to-head delta. Comparing all four affected files against the earlier reviewed head produced no differences; the earlier review reported no findings. The stale test merge was not used to infer merge behavior. (5b8c8579e723)
  • Projection preserves consumed facts: The existing list parser omits only sessionDiffBaseline, skillsSnapshot, and systemPromptReport. Audited reconciliation, restoration, orphan checks, and cleanup callers consume retained identity, status, timestamps, lifecycle revision, execution, and recovery fields. Canonical validation, participant projection, physical-owner selection, and caller-current checks remain in their existing owners. (src/config/sessions/session-accessor.sqlite-status.ts:96, 5b8c8579e723)
  • Focused regression coverage: The changed lifecycle test uses real SQLite and the production worker read path, checks completion/start facts, and observes that cold payloads do not cross worker messages. The timestamp case checks exactly 42 and absence of cold snapshot SQL or parsing. The body reports baseline failures and candidate passes, plus measured test costs and explicitly bounded component benchmarks; these execution claims were not rerun during this read-only review. (src/agents/subagents/registry/subagent-session-reconciliation.metadata-read.test.ts:77, 5b8c8579e723)
  • Still necessary on current main: Fetched main retains the full-read defaults at both reconciliation reads and the timestamp accessor. The main reconciliation blob exactly matches the pinned base blob, establishing that the requested optimization is not already present there. (src/config/sessions/session-accessor.sqlite-entry.ts:258, 4bf041c0d1f7)
  • Latest release check: The latest supplied release, v2026.9.8, also calls the timestamp row reader without the list projection. (src/config/sessions/session-accessor.sqlite-entry.ts:289, fc23bc864e45)
  • Related work has a distinct boundary: fix(sessions): read remaining metadata-only session listings at the list projection #149358 remains an open proposal for whole-store listing consumers and an optional plugin runtime parameter. This PR addresses keyed reconciliation and timestamp reads, so the related proposal does not supersede it.

Likely related people:

  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (1 earlier review cycle)
  • reviewed 2026-10-03T07:26:28.759Z sha cddc914 :: needs maintainer review before merge. :: none

@steipete
steipete merged commit cec6d9d into main Oct 3, 2026
126 checks passed
@steipete
steipete deleted the steipete/sqlite-session-read-projection branch October 3, 2026 09:22
@steipete

steipete commented Oct 3, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 4, 2026
openclaw#164125)

Avoid cold snapshot selection, decoding, and worker transfer for metadata-only reconciliation and activity timestamps. Preserve the existing session owner, canonical validation, public full-read defaults, and mutation fences.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S 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