Repository navigation
perf(sessions): reuse branch summaries across unrelated writes - #186127
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex review: needs changes before merge. What this changesThis 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.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete 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 Before merge
Findings
Tests
Agent review detailsHow this fits togetherThe 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]
Technical reviewBest 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 AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against f39b480c874d. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceAcceptance criteria:
What I checked:
Likely related people:
PR surfaceSource +32, Tests 0, Other +170. Total +202 across 5 files. Added test files: 0. View PR surface stats
LabelsLabel changes:
Label justifications:
Rating scale6/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. WorkflowClawSweeper edits this one comment on every review. Comment Reviewed October 27, 2026, 12:58 PM ET / 16:58 UTC. |
251c96f to
c036dd5
Compare
|
Admin-merging over four
None of these files are in this PR's diff. Every other check is green at |
…law#186127) * perf(sessions): reuse branch summaries across unrelated writes * test(perf): observe branch worker replies without method patches
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.tsuses 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.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.tsfor--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 aresrc/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, andtest/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=1also fails on unchanged base843abed3a886e62c272b9ed11e91ec55b4a73534at 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.