Skip to content

perf(sessions): hydrate only requested entry snapshots - #165181

Merged
steipete merged 1 commit into
mainfrom
steipete/perf-micro-exact-entries-hydration-20260919
Oct 4, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/perf-micro-exact-entries-hydration-20260919

Conversation

@steipete

@steipete steipete commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Exact session reads load and decode saved prompts and diff baselines even when reply finalization, authorization, or ownership checks only need metadata, prolonging the reader's SQLite transaction.

User Impact

Metadata callers stop loading unused saved snapshots. Usage context reads only the system-prompt report; session diff reads only its baseline. No configuration or migration is required. Initialization, creation callbacks, cron reuse, replacement/CAS, and public SDK reads retain complete entries so saved snapshots survive writeback.

Why This Change Was Made

The existing snapshot owner selects requested fields alongside hot entry facts in the same SQL statement. Worker requests carry this choice independently of lifecycle, authorization, and membership selection. Canonical admission, per-key failures, current authority, and the original transaction boundary remain intact.

The change removes duplicate full/metadata prepared-query setup and an unused rowid projection. Ordinary and ordered readers now share one request capture function. No row cache or second hydration owner is added.

Production LOC: +198 / −155, net +43 (excluding tests, test support, and docs). The full-entry SDK and writeback/CAS contracts prevent replacing the default with metadata. Explicit field selection and propagation through the existing worker/Gateway boundaries account for the remaining growth; full reads are retained for those concrete contracts.

Evidence

Synthetic Linux rig, Node 26.8.1 / pnpm 12.5.1; base 0e936b88c4bf72c5114e792c6f3496c8dd43998f, candidate tree eaaed01346023c6fbd37000165a4f0d9ec8227f7. Nine warm samples per request shape. A second run reversed revision order and shuffled request order; both runs showed the metadata savings below. Values shown are medians from the shuffled run.

Caller/request class Keys JSON bytes before → after Hold ms before → after
Metadata with lifecycle facts 1 1,351,025 → 32,936 6.680 → 0.667
Metadata with lifecycle facts 32 43,232,866 → 1,053,974 218.219 → 2.311
Metadata with authorization, members, and participant records 1 1,351,025 → 32,936 7.064 → 0.613
Metadata with authorization, members, and participant records 32 43,232,866 → 1,053,974 244.195 → 2.804
Exact metadata / reply finalization 1 1,351,025 → 32,936 6.455 → 0.146
System-prompt report / usage context 1 1,351,025 → 689,513 6.420 → 2.513
Diff baseline / session diff 1 1,351,025 → 170,135 6.137 → 1.320

Per entry, hot JSON is 32,936 bytes, saved skills 524,313, prompt report 656,577, and diff baseline 137,199. Metadata reads remove 97.6% of JSON bytes. For the 32-key metadata cohort, JSON parsing falls from 85.488 to 0.640 ms. Initial status recovery has no explicit transaction in this path; its 32-row total time falls from 234.492 to 2.191 ms, alongside the metadata-list reference at 2.180 ms.

Timing includes instrumentation and varies with scheduling/GC. Full-read controls moved in both directions between runs, so no speedup is claimed for retained full reads. Validation/projection is recorded with other residual JavaScript work, not as an isolated timer. These synthetic warm measurements do not establish a new production latency percentile; large-file cold canonical admission is unchanged and was not reproduced.

Validation:

  • blacksmith-testbox, profile openclaw-check, final lease tbx_01m44f84y9bjzyfw5zrtmd85xg (runner), following focused runs on tbx_01m44cceyb8a0f6x2bnntp9wxg. The base commit and complete staged Git tree were verified in an isolated checkout before execution.
  • Focused sessions entry/read, exact-read, readonly-worker, status, creation, replacement, Gateway worker, and session-diff suites: 176 distinct tests passing across the runs and focused rerun. The new owner/transport regression passes in 426 ms; its 20-test file takes 26.36 s wall time with node scripts/run-vitest.mjs <file> --maxWorkers=1, including preparation.
  • Two setup failures were corrected: test scratch inside the checkout made the non-Git fixture discover a parent repository; the new snapshot fixture initially bypassed the transactional writer. A Git-boundary probe established the first cause; the fixture now uses the existing replacement owner. The production implementation did not change for either correction.
  • node scripts/check-changed.mjs --staged: passed, exit 0, 22m57.63s on final tree ef0b3fd7eded0b74323fa09105726a83f3399c6b.
  • The regression fails on the unpatched base with AssertionError: expected { …(2) } to deeply equal undefined because an unrequested snapshot is present; it passes on the candidate. Measured single-worker wall times: entry worker 26.36 s (20 tests), prepared reads 16.93 s (4 tests), session diff 23.68 s (47 tests). The additional unchanged Gateway lookup suite passed 32 tests in 76.81 s.
  • Fresh independent Codex review of this rebased candidate: scoped-clean, no actionable P0–P2 findings.

The final candidate additionally JSON-serializes the projection in the request cache key, fixing the type-aware lint error caused by implicit array coercion. Its SQL read owner is identical to the measured tree. An earlier rig changed-check caught line-cap growth; consolidating the duplicated request capture fixed it. The superseded rig check was stopped after Testbox became ready, and final gate proof comes from the lease above. The rig was used for synthetic measurements only after the queue exceeded the authorized fallback threshold.

The final lease used the repository source-capsule wrapper after native full sync timed out. The wrapper receipt binds the final tree and exit 0; the runner link can show cancellation after lease cleanup. All task-owned leases and rig worktrees are closed.

GitHub CI run 37242258120 succeeded for head 4b9522008e8ee6c6048df589ac1112138f775d8d; workflow wall time was 581 seconds (9m41s).

Select saved snapshots in the existing SQL reader without changing canonical
admission or lifecycle, membership, and authorization snapshots. Preserve full
SDK and mutation/CAS entries, and share ordinary/ordered worker request capture.

Release-note context: Reduce metadata read payloads and transaction holds during
reply finalization, authorization, and recovery. Load only the saved report or
diff baseline needed by usage context and session diff consumers.
@clawsweeper

clawsweeper Bot commented Oct 4, 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.

@github-actions

github-actions Bot commented Oct 4, 2026

Copy link
Copy Markdown
Contributor

⚠️ Security sensitive changes

This maintainer PR changes sensitive security components.

No secops approval is required. This comment is informational because the PR author has Maintain or Admin access.

  • Current SHA: 4b9522008e8ee6c6048df589ac1112138f775d8d
  • Maintainer: @steipete
  • Repository role: admin

These security sensitive changes were made:

  • src/agents/git-coauthor-attribution.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/agents/harness/native-session/binding-authority.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.

Carefully review these changes before merging.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime agents Agent runtime and tooling size: M labels Oct 4, 2026
@steipete
steipete enabled auto-merge (squash) October 4, 2026 23:05
@clawsweeper

clawsweeper Bot commented Oct 4, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 4, 2026, 7:06 PM ET / 23:06 UTC.

ClawSweeper review

What this changes

The PR makes session readers load only requested saved snapshots while preserving complete entries for SDK reads and writeback flows.

Merge readiness

✅ Ready for maintainer review

This optimization remains useful on current main. No actionable correctness or security defect was found in the introduced changes.

Priority: P2
Reviewed head: 4b9522008e8ee6c6048df589ac1112138f775d8d

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused optimization with useful reported measurements, meaningful regressions, and no identified blocking defect.
Proof confidence 🌊 off-meta tidepool Not applicable: The verified admin author is exempt from external-contributor proof requirements, and the diff does not materially change authority. Reported SQLite measurements exercise selective hydration, with worker and WAL regressions as supplemental coverage; 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 verified admin author is exempt from external-contributor proof requirements, and the diff does not materially change authority. Reported SQLite measurements exercise selective hydration, with worker and WAL regressions as supplemental coverage; no stored-data contract changes.
Evidence reviewed 10 items Pinned change and merge ownership: Reviewed the merge-base-to-head introduced diff. The raw test-merge commit records the pinned main parent followed by the exact PR head; its comparison preserves the snapshot-selection changes.
Existing snapshot owner: Snapshot selection filters the existing same-statement SQL projections. The default remains full hydration; snapshot splitting and transactional writes are unchanged.
Still necessary on main: Fetched main's snapshot selector still selects all three fields and lacks the requested field-selection parameter. No implementation-on-main or shipped-fix claim is established.
Findings None None.
Security None None.

How this fits together

Session readers retrieve persisted metadata and saved prompt or diff snapshots from agent SQLite databases. Gateway and agent callers use these entries for reply finalization, authorization, recovery, usage reporting, and checkout diffs.

flowchart TD
  A[Gateway and agent callers] --> B[Requested snapshot fields]
  B --> C[Existing session read worker]
  C --> D[SQLite metadata and snapshots]
  D --> E[Selected entry fields]
  E --> F[Reply and authorization checks]
  E --> G[Usage reports and session diffs]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +43, Tests +123, Docs +3. Total +169 across 35 files.

View PR surface stats
Area Files Added Removed Net
Source 31 198 155 +43
Tests 3 127 4 +123
Docs 1 6 3 +3
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 35 331 162 +169

Review metrics

Metric Value Why it matters
Production and regression growth production net +43 lines; tests net +123 lines Explicit selection propagation accounts for production growth while preserving full-entry writeback contracts.

Technical review

Best possible solution:

Keep selective hydration in the existing SQL reader, with complete entries remaining the default for SDK and mutation flows.

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

Not applicable to a functional bug: source confirms unnecessary full snapshot hydration, and the PR supplies before/after synthetic measurements; this review did not execute them.

Is this the best way to solve the issue?

Yes. Selecting fields through the existing SQL owner avoids a competing hydration cache and preserves complete-entry defaults.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P2: This is a bounded session-read performance improvement with focused measurements and no demonstrated urgent user-facing failure.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.

Label justifications:

  • P2: This is a bounded session-read performance improvement with focused measurements and no demonstrated urgent user-facing failure.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.

Evidence

What I checked:

  • Pinned change and merge ownership: Reviewed the merge-base-to-head introduced diff. The raw test-merge commit records the pinned main parent followed by the exact PR head; its comparison preserves the snapshot-selection changes. (2d0dcee0b028)
  • Existing snapshot owner: Snapshot selection filters the existing same-statement SQL projections. The default remains full hydration; snapshot splitting and transactional writes are unchanged. (src/config/sessions/session-entry-snapshots.ts:32, 4b9522008e8e)
  • Still necessary on main: Fetched main's snapshot selector still selects all three fields and lacks the requested field-selection parameter. No implementation-on-main or shipped-fix claim is established. (src/config/sessions/session-entry-snapshots.ts:29, d2167f41b6d3)
  • Worker and writeback compatibility: Exact reads retain full hydration when snapshotFields is omitted. Creation and replacement branches retain their existing complete-entry readers. Startup orphan repair rereads a full current entry before replacement, and main-session recovery consumes the mutation owner's fresh entry. (src/config/sessions/session-entry-read.worker.ts:358, 4b9522008e8e)
  • Authority remains with existing owners: The native binding change omits snapshots while retaining sessionId and previousSessionId. Ordered consumption, lineage checks, and current-authority assertions remain intact; no material authorization transfer is introduced. (src/agents/harness/native-session/binding-authority.ts:77, 4b9522008e8e)
  • Focused regression coverage: The new test exercises persisted SQLite entries, selective hydration, lifecycle and authorization facts, retained full reads, status recovery, and actual worker transport. The extended WAL test checks selected snapshots against the caller's transaction. These tests were inspected, not executed during this read-only review. (src/config/sessions/session-entry-read.worker.test.ts:42, 4b9522008e8e)

Likely related people:

  • Peter Steinberger: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; 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.

@steipete
steipete merged commit 5837209 into main Oct 4, 2026
139 of 141 checks passed
@steipete
steipete deleted the steipete/perf-micro-exact-entries-hydration-20260919 branch October 4, 2026 23:12
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 5, 2026
Select saved snapshots in the existing SQL reader without changing canonical
admission or lifecycle, membership, and authorization snapshots. Preserve full
SDK and mutation/CAS entries, and share ordinary/ordered worker request capture.

Release-note context: Reduce metadata read payloads and transaction holds during
reply finalization, authorization, and recovery. Load only the saved report or
diff baseline needed by usage context and session diff consumers.
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 security-sensitive-changed size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant