Repository navigation
Conversation
A session that has started operator work carries a diff baseline: the path and content fingerprint of every file in the workspace checkout at that moment. Sessions on one host baseline the same checkout, so those records are byte-identical from row to row. Each row still parses its own JSON document, so each materializes its own copies, and the retained cost is O(rows x files) where the content is O(files). Any read that spans the store mints the whole set again. Intern the records at the parse chokepoint so every caller is covered rather than whichever read path happens to be patched. Baselines are read-only once parsed -- the sole consumer folds them into a path -> fingerprint map to decide which diff hunks predate the session -- so sharing one frozen instance per distinct pair is observationally identical, and freezing turns a future in-place write into a loud TypeError instead of silent cross-entry aliasing. The table is keyed by path and bounded with LRU eviction, so a rename wave cannot grow it without limit. Measured by session-diff-baseline-intern.measure.test.ts: 200 sessions over a 559-file checkout, read 10 times, return 1,118,000 references that resolve to 559 instances and retain 9.4 MB, against 213.2 MB if every reference were a copy. On a dev Slack gateway with 742 session rows, 22 of them carrying a baseline over a 559-file checkout, heap snapshots taken at matched process uptimes show 8,604 retained records (1.61 MB) before and 759 (0.14 MB) after -- a 91% reduction. Co-Authored-By: Claude Opus 5 <[email protected]>
|
Codex review: needs changes before merge. What this changesThis PR shares frozen file-fingerprint records across parsed session baselines and detaches them for plugin callers. Example: Two sessions baseline src/a.ts with fingerprint aaa.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Needs changes before merge - 2 items remain Keep open: this PR provides a useful memory optimization, but the previously reported native-read ownership regression remains unresolved. Priority: P2 Before merge
Findings
Provenance
Tests
Agent review detailsHow this fits togetherThe SQLite session reader decodes persisted baselines for native and plugin consumers; those baselines let session diffs exclude checkout changes that predate the session. flowchart TD
A[SQLite session snapshots] --> B[Session entry parser]
B --> C[Bounded baseline interning]
C --> D[Native session reads]
C --> E[Plugin projection]
E --> F[Detached plugin results]
D --> G[Session diff filtering]
Technical reviewBest possible solution: Share baseline records only within borrowed immutable owners and preserve detached mutable records at every native and plugin owned-read boundary. Do we have a high-confidence way to reproduce the issue? Source establishes both separate baseline decoding on current main and the patch's ownership failure: assigning fingerprint on a baseline returned by a native exact read or full listing reaches an Object.freeze record and throws in ESM; no code was executed. Is this the best way to solve the issue? Bounded sharing is useful, but the common parser cannot impose immutability on owned results; the existing borrowed-versus-owned boundary should decide when sharing is permitted. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 4c7a1654f8f4. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceAcceptance criteria:
What I checked:
PR surfaceSource +97, Tests +211, Other +4. Total +312 across 8 files. Added test files: 2. View PR surface stats
Review metrics
LabelsLabel changes: No label 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 HistoryReview history (8 earlier review cycles)
Reviewed October 20, 2026, 12:56 PM ET / 16:56 UTC (Revision 9). |
…orts The assertion ratchet requires a SAFETY invariant on every new non-const assertion, and the production Knip scan does not count test files as consumers, so the interning seams read as unused exports. Annotate the stored-JSON cast with the invariant the surrounding guards already enforce, stop exporting the record type that nothing outside the module uses, and scope the remaining focused-test seams the way the config already scopes equivalent ones. The bounded-LRU test needs the table-size seam to prove the cap, which no production caller observes.
…eline-record-interning
…tory session-accessor.sqlite-status.ts now imports session-diff-baseline-intern.ts, so the trusted-anchor PR wrapper no longer closes over its runtime imports and the sqlite-readonly-location worker loses a relative ESM dependency. Add the module to the inventory so the extracted wrapper keeps resolving it.
…eline-record-interning # Conflicts: # src/config/sessions/session-accessor.sqlite-status.ts
Stored baselines share one frozen record per checkout file across every parsed row, so getSessionEntry and listSessionEntries handed plugin callers frozen, shared nested values where owned mutable results are promised. Writing to entry.sessionDiffBaseline.files[0] threw instead of modifying a detached result. Detach the records in projectPluginSessionEntry, the single projection both reads already use, matching how restartRecoveryRuns is detached there.
…d rows The interned record literal ordered fingerprint before path, so an entry that held one re-serialized its diff baseline with reordered keys and stopped matching the stored snapshot bytes. Adopt the canonical path-first shape. Detaching for plugin callers also tripped oxc(no-map-spread); structuredClone expresses the same deep detach without the per-element spread.
|
This pull request has been automatically marked as stale due to inactivity. |
|
This pull request has been automatically marked as stale after 7 days without qualifying human activity. |
|
Closing due to inactivity. |
What Problem This Solves
A session that has started operator work carries a diff baseline: the path and content
fingerprint of every file in the workspace checkout at that moment
(
SessionDiffBaseline.files,src/config/sessions/types.ts). Sessions on one host baselinethe same checkout, so those records are byte-identical from row to row.
Every row still parses its own JSON document, so every row materializes its own copies. The
retained cost is
O(rows × files)where the content isO(files), and any read that spansthe store mints the whole set again.
This interns the records at the parse chokepoint (
parseSessionEntryJson), so all callers arecovered rather than whichever read path happens to be patched.
Why it is safe
Baselines are read-only once parsed. The only consumer folds them into a
path -> fingerprintmap to decide which diff hunks predate the session:Nothing writes a record back. Sharing one instance per distinct
(path, fingerprint)pair istherefore observationally identical to parsing fresh copies, and the shared records are
frozen, so a future in-place write is a loud
TypeErrorrather than silent cross-entryaliasing. A test covers that.
The table is keyed by path and bounded at 4096 entries with LRU eviction, so a rename wave
cannot grow it without limit. A changed fingerprint adopts a new record and leaves entries
already holding the old one untouched.
Evidence
src/config/sessions/session-diff-baseline-intern.measure.test.ts— 200 sessions over a559-file checkout, read 10 times at the
fullprojection:The 9.4 MB that remains is the per-entry pointer arrays, which are per-entry by design.
On a live gateway
A Slack gateway with 742 session rows, 22 of them carrying a baseline, over a 559-file
checkout. Heap snapshots taken with
--heapsnapshot-signalat matched process uptimes, beforeand after 18 agent sessions, with and without this change. Both runs used the same trivial
prompt, so these are a floor for a session rather than a typical one — but the record count is
rows carrying a baseline x files in the checkout, which does not vary with what the agentdoes:
{ path, fingerprint }records retainedA 91% reduction, holding at both points. (751 against 560 distinct values is the intended
behaviour: a path whose fingerprint differs between two rows' baselines adopts a new record,
and rows holding the old one keep it.)
Wider snapshot totals also moved — live heap 12.94 MB lower at idle — but those carry
run-to-run variation in lazily compiled code, so only the record delta is quoted as caused by
this change.
Why the shape matters more than today's number
On the same gateway running v2026.8.2, the same records grew from 24,312 (4.84 MB) to 79,014
(15.94 MB) across 18 sessions — 58% of all duplicate small-string growth in that window,
because the store was re-parsed and retained repeatedly. (Both halves of that ratio come from
the same pair of snapshots. The v2026.8.2 run drove real operator tasks and the v2026.9.2 runs
did not, so the two versions' absolute growth is not a controlled comparison and I am not
claiming one.)
#134891 removed the whole-store listing from the reply path, which is why the set no longer
multiplies per message. What it leaves is still
O(rows × files)and grows with every sessionthat starts operator work: 22 of 742 rows carry a baseline today; at 742 the same checkout
would retain roughly 414,000 records.
Test plan
src/config/sessions/session-diff-baseline-intern.test.ts— sharing, fingerprint change,LRU bound, cross-entry identity, the frozen-record guard, and ragged/absent baselines.
src/config/sessions/session-diff-baseline-intern.measure.test.ts— the table above.node scripts/run-vitest.mjs run src/config/sessions src/sessions— 2,916 passing. Twofailures reproduce unchanged on the same commit without this patch:
goals-operations.test.ts(a read-count budget, 12 vs 11) andsession-accessor.sqlite-reclamation-memory.test.ts("memory plugin unavailable").pnpm tsgo,pnpm oxlint,pnpm oxfmt --check— clean.ERR_MODULE_NOT_FOUND, and0
TypeError, so nothing in production writes to a baseline record.🤖 Generated with Claude Code