Skip to content

perf(sessions): reuse branch summaries across unrelated writes - #186127

Merged
steipete merged 2 commits into
mainfrom
steipete/perf-sessions-branches-list-20261027
Oct 27, 2026
Merged

steipete merged 2 commits into
mainfrom
steipete/perf-sessions-branches-list-20261027

Conversation

@steipete

@steipete steipete commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Listing conversation branches repeats a transcript-worker read whenever any other session writes to the same database, even when the selected conversation has not changed.

User Impact

Branch lists keep the same response while avoiding worker traffic caused by unrelated conversations. This affects sessions.branches.list, which lists transcript branches and does not run Git commands.

Why This Change Was Made

Reuse the database owner's existing scoped receipts for the session-key aliases and shared transcript ID. The existing database-wide token remains the cheap unchanged-store check. A scoped receipt is retained only when the original database token still matches after the snapshot arrives, so an overtaking write cannot certify an older snapshot. Rewrites, replacement, cold storage, retirement, unscoped writes, and caller-owned response copies retain their existing behavior.

Runtime code grows by 32 lines (non-test diff: +218 including the 185-line benchmark and one script-entry registration): the existing bounded 64-entry cache needs the scoped dependency token and the snapshot-publication check. There is no new cache, schema, configuration option, TTL, or worker protocol. Actual transcript changes still use the existing worker owner.

Evidence

Acceptance was written in the benchmark header before measurement: identical response checksums, fewer branch-worker requests, lower main-thread CPU/allocation under unrelated-write churn, and no material unchanged-store regression.

The committed scripts/perf/session-branches-cache-measure.ts uses an offline synthetic fixture with 10,000 sessions and 30,000 participants. Each arm makes 2,048 real accessor calls across 32 conversations, with 64 real writes to an unrelated session. CPU/allocation includes that identical write workload; per-call latency excludes writes. Timing order was base/candidate, candidate/base. Allocation used separate processes and two runs per side. These are owner measurements, not whole-Gateway latency or total-process CPU claims.

Metric Base Candidate
Branch-worker requests per 2,048 calls, both pairs 2,048 0
Main-thread CPU, timing pair 1 1,391 ms 506 ms
Main-thread CPU, timing pair 2 1,413 ms 564 ms
Sampled allocation, pass 1 238.29 MB 150.88 MB
Sampled allocation, pass 2 236.40 MB 150.90 MB
Accessor p50 / p99, pair 1 (2,048 samples/side) 1.241 / 25.188 ms 0.093 / 0.758 ms
Accessor p50 / p99, pair 2 (2,048 samples/side) 1.855 / 28.996 ms 0.098 / 2.503 ms
No-write control CPU, 2,048 calls 184.45 ms 184.02 ms
No-write control p50 / p99 0.085 / 0.196 ms 0.085 / 0.179 ms
Git subprocesses 0 0

Mean main-thread CPU falls 61.8%; sampled allocation falls 36.4%. Every arm produced the same response checksum. Host one-minute load was 56.4→58.8 and 78.9→74.0 for timing baselines, 64.4→72.2 and 71.8→90.9 for candidates. Wall-time spread is substantial on this shared host; the deterministic work counts and allocation reduction are the primary evidence. The no-write control preserves the existing fast path.

Reproduce with the seed/run commands in the script header; save the base version of src/config/sessions/session-accessor.sqlite-branches.ts for --base-file. No production state or Team server was accessed. The scoped duplicate-work fast-path protocol was used; no multi-pair ten-minute Gateway campaign was run.

The existing sibling-session regression fails on the base with two branch-worker reads instead of one. Candidate coverage includes unchanged sibling results, changed transcript results, writes overtaking replies, alias rewrites/forks/switches, physical database replacement, cold storage, incognito storage, detached caller copies, and large branch graphs.

Validation: 12 branch-owner tests, 12 branch-summary tests, 34 Gateway storage tests, and 32 source-closure tests passed. The owner file took 27.08 s including setup (about 19 s of tests); two final assertion-only consolidations retain the same checks. Changed-file formatting/lint and export-name collision checks passed. The test-line ratchet has zero net added test lines; its existing ceiling is unchanged. The initial PR CI caught a benchmark-only suppression ratchet failure; the benchmark now observes native worker replies without patching methods or adding a lint suppression. Its 14 suppression-guard tests and changed-file lint pass; the revised benchmark was remeasured in full. Final-head CI completed: lint, production/test types, artifact checks, all three PostgreSQL conformance shards, and the repaired benchmark guard pass. Four inherited test shards fail as documented below; the aggregate gate is red.

Commands: node scripts/run-vitest.mjs <focused files> --maxWorkers=1; the files are src/config/sessions/session-accessor.sqlite-branches.test.ts, src/config/sessions/session-accessor.sqlite-branch-summaries.test.ts, src/gateway/server-methods/sessions-rewind.storage.test.ts, test/scripts/eager-import-closure.test.ts, and test/scripts/pr-wrapper-source-closure.test.ts. No Testbox lease or full local suite was used.

Review: independent subagent review (autoreview route unavailable), no actionable P2-or-higher findings. The configured Codex autoreview route refused to start because its provider did not match the operator configuration; the authorized fallback inspected the diff, receipt owners, tests, and benchmark.

CI attribution on final head c036dd5253d44df7cbdf5b43cec4fb61ccc29bac: the benchmark suppression shard, lint, and production typecheck pass. The remaining observed failures are inherited:

  • Readonly session-row assertion: this head, same failure on main.

  • Canvas retained-receipt archive expectation: this head, same failure on main.

  • Recovery-state assertion: this head. node scripts/run-vitest.mjs src/gateway/server.chat.orphaned-recovery.test.ts --maxWorkers=1 also fails on unchanged base 843abed3a886e62c272b9ed11e91ec55b4a73534 at line 126 with the same recovery revision 7→9, charged attempts 1→2, and retired writer. Baseline result: 1 passed, 1 failed, 75.18 s including wrapper. The first cold attempt timed out during startup and is not counted as attribution evidence; the warm compiler-cache run reaches and reproduces the assertion.

  • Idle archive retirement timeout: this head, same timeout on main.

Final CI run 40547395899 is complete on the exact head. All four failed test shards have baseline evidence; there is no unclassified failure. The requested green aggregate gate is not satisfied because of those inherited failures. No CI rerun was requested to chase green. The PR remains open for the coordinating maintainer; it has not been merged.

@clawsweeper

clawsweeper Bot commented Oct 27, 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 scripts Repository scripts size: M labels Oct 27, 2026
@steipete
steipete marked this pull request as ready for review October 27, 2026 16:41
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-27T17:08:13.156903Z c036dd5 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. 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. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 27, 2026
@clawsweeper

clawsweeper Bot commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge.

What this changes

This PR reuses cached conversation branch summaries when unrelated sessions write to the same database.

Example: Read 32 unchanged conversations after writing to agent:main:team-shape-session-9999.

  • Before: The reported benchmark dispatches 2,048 branch-worker requests across 2,048 reads.
  • After: The reported benchmark dispatches zero branch-worker requests and returns identical response checksums.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Useful, focused cache work with credible owner-level measurements; one introduced CI failure prevents a clean verdict.
Proof confidence 🦐 gold shrimp (3/6) The ordinary contributor proof gate is exempt for this maintainer-authored PR; its supplied evidence exercises real accessor calls, SQLite writes, and worker dispatch on synthetic storage, with explicit limits on Gateway-wide claims.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: Refreshing an unchanged conversation’s branch list repeats worker work whenever another conversation writes to the shared database.
Reason: The maintainer-authored direction has deterministic work-count savings and preserves the response contract without adding a new owner or user setting.

Merge readiness

⛔ Needs changes before merge - 1 item remains

Keep this PR open: the scoped-cache optimization has measurable value, but its benchmark introduces a deterministic CI failure.

Priority: P2
Reviewed head: 251c96f2d39339c0c0a83e73ccb9762d87a0994e

Before merge

Findings

  • [P2] Register the benchmark’s intentional lint suppression — scripts/perf/session-branches-cache-measure.ts:70-71

Tests

  • Missing end-to-end proof: The supplied measurements exercise the accessor and real worker directly; they do not establish after-fix Gateway RPC latency.
Agent review details

How this fits together

The Gateway branch-list handler calls the session accessor, which serves compact cached summaries or requests a fresh SQLite snapshot from the maintenance worker.

flowchart LR
  A[Gateway branch request] --> B[Session accessor]
  B --> C[Bounded summary cache]
  D[Database write receipts] --> C
  C --> E[Maintenance worker on miss]
  E --> F[SQLite transcript snapshot]
  F --> C
  C --> G[Detached branch response]
Loading

Technical review

Best possible solution:

Keep the existing cache and receipt owners, and register the benchmark’s justified suppression in the existing explicit allowlist.

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

Current-main source shows database-wide writes invalidating unchanged branch summaries, and the PR reports a failing base work-count regression; no target code was executed during this review.

Is this the best way to solve the issue?

The patch follows the smallest complete repair: reuse existing scoped receipts, preserve the cheap unchanged-database check, and refuse to certify an overtaken snapshot.

Full review comments:

Overall correctness: patch is incorrect
Overall confidence: 0.96

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Host branch-summary invalidation changes intended behavior with a stated reason (d43f11c: Move selection and watermark SQL into the existing worker and use database receipts for cheap host-cache validation.)
  • Retained summary cache and worker ownership keeps the original intent (7e9e7e6: Retain compact summaries across worker retirement and reuse the maintenance reader while preserving transcript freshness.)
  • Concurrent reads and detached caller results keeps the original intent (b476ed9: Coalesce duplicate misses and avoid restoration work on valid cache hits while returning independent results.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

Acceptance criteria:

  • node scripts/run-vitest.mjs test/scripts/lint-suppressions.test.ts --maxWorkers=1
  • git diff --check

What I checked:

  • Pinned introduced change: The introduced diff extends the existing 64-entry cache with scoped receipts and a snapshot-publication check; it adds no competing cache, schema, configuration, or worker protocol. (src/config/sessions/session-accessor.sqlite-branches.ts:33, 251c96f2d393)
  • Current-main behavior: Current main still binds cache hits solely to the database-wide write token, so unrelated writes force another worker request. (src/config/sessions/session-accessor.sqlite-branch-list.ts:59, f39b480c874d)
  • Invalidation ownership: Existing receipts include physical database identity, generation, unscoped writes, lookup-key scopes, and session-ID scopes; transcript and entry writers publish through these owners. (src/infra/sqlite-database-write-receipts.ts:386, 251c96f2d393)
  • Measured owner behavior: The PR reports real accessor and worker measurements on synthetic storage, identical response checksums, reduced worker traffic and allocation, and an unchanged-store control; the committed script matches that workload. (scripts/perf/session-branches-cache-measure.ts:94, 251c96f2d393)
  • Diff-caused CI failure: The exact-head suppression-ratchet check reports one unexpected entry: scripts/perf/session-branches-cache-measure.ts|typescript/unbound-method|1. The benchmark adds that suppression, but the explicit allowlist does not include it. (scripts/perf/session-branches-cache-measure.ts:70, 251c96f2d393)
  • Other CI failures remain unattributed: Annotations identify failures in session-row, orphaned-recovery, and canvas-session-read tests. No base comparison or causal repair establishes their relationship to this diff, so they are not assigned as contributor defects. (251c96f2d393)

Likely related people:

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

PR surface

Source +32, Tests 0, Other +170. Total +202 across 5 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 2 33 1 +32
Tests 1 26 26 0
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 2 170 0 +170
Total 5 229 27 +202

Labels

Label changes:

  • add P2: This is a bounded performance improvement with a narrow, deterministic validation defect.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp 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 performance improvement with a narrow, deterministic validation defect.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp 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 27, 2026, 12:58 PM ET / 16:58 UTC.

@steipete

Copy link
Copy Markdown
Contributor Author

Admin-merging over four checks-node-changed-* failures and the ci-gate that rolls them up. All four are inherited from main and unrelated to this branches.list change. Three reproduce locally at main bf72e96b39a2; the fourth fails on main CI:

None of these files are in this PR's diff. Every other check is green at c036dd5253d4.

@steipete
steipete merged commit 8692929 into main Oct 27, 2026
173 of 181 checks passed
@steipete
steipete deleted the steipete/perf-sessions-branches-list-20261027 branch October 27, 2026 18:39
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 28, 2026
…law#186127)

* perf(sessions): reuse branch summaries across unrelated writes

* test(perf): observe branch worker replies without method patches
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. scripts Repository scripts 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