perf(cli): avoid unrelated transcript reads on latest-session lookup
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
- Issue type
- Refactor
- Clarity
- Mostly clear
- Activity status
- Active
- Tech stack
- node.js, typescript
- Domain
- cli
Research direction
Start with loadLatestSession in packages/squad-cli/src/cli/shell/session-store.ts (lines 81-124) and its shell startup caller in shell/index.ts near line 221. Reproduce the benchmark from the issue's fixture description, counting transcript reads and bytes at 10, 100 and 1,000 archives. Done means the common metadata-current path reads and parses at most one transcript body, the focused tests for the 24-hour boundary, equal timestamps, malformed newest file and external stateDir pass, and before/after results are published.
Written by the indexing model from the issue text.
Description
Summary
loadLatestSession discovers saved sessions by parsing every archived transcript before loading the newest eligible session again. The common resume path scales with total retained history even when almost all archives are outside the 24-hour eligibility window.
Proposed primary owner: state-storage-dev.
Baseline evidence
Revision: 47082a81799710c3e457b594123d190c00596ebf, observed 2026-11-12.
Code: session-store.ts:81-124; shell startup caller at shell/index.ts:221.
Independent repeat with daily retained archives, 200 messages of 256 characters per archive, and only the newest archive recently active:
| Retained sessions | p50/resume lookup | p95 | Synchronous reads |
|---|---|---|---|
| 10 | 0.945 ms | 2.355 ms | 11 |
| 100 | 8.277 ms | 11.917 ms | 101 |
| 1,000 | 121.578 ms | 137.704 ms | 1,001 |
At 1,000 archives, separate untimed instrumentation observed 75,212,137 bytes read for the lookup. Original audit passes had p50 116.6-206.8 ms with differing timestamp distributions; these are baseline observations, not optimization speedups.
Environment: Apple M4 arm64, 16 GiB, Darwin 25.6, Node 24.15.0; three rounds of ten sequential observations per case, two warmups, warm filesystem caches, setup/imports outside timing. Assertions verified the selected session and message count. Source methods ran via Node's built-in TypeScript transformation/relative-import hook; the session store's two SDK barrel imports were bound directly to the exact production FSStorageProvider and safeTimestamp exports.
Limit: configured-feed E404 blocked locked dependency restoration, packaged build and startup measurements. These numbers measure session lookup only, not packaged shell startup. Shared reproduction fixtures/raw evidence are required before optimization acceptance.
Scope
Parent: github/squad#2481.
One change to latest-session discovery in session-store.ts; the shell caller is a correctness integration point, not a second optimization. No autosave redesign, history compaction, UI changes or broad storage migration.
Measurable acceptance and tests
For an optimization, use at least three interleaved built-baseline/change rounds with at least 30 observations per case per round; publish raw observations, per-round p50/p95, exact SHA/environment and correctly labeled CPU/I/O/memory evidence. The budgets below are proposed acceptance targets, not already-demonstrated gains. If a safe material win cannot be reproduced, record rejection/defer rather than broaden the implementation to chase the target.
- Fixed workload: 10/100/1,000 retained daily archives, each 200 messages of 256 characters, with only the newest eligible. Publish transcript read/parse counts and bytes as well as time.
- On the valid, metadata-current common path, read/parse at most one transcript body, independent of archive count. Metadata discovery is measured separately; explicitly label fallback scans.
- Target at least 25% lower p50 at 1,000 archives versus the same built baseline. Report all smaller-size and p95 results, not just the winning case.
- Focused tests verify the selected session and Date rehydration, equal-time ordering, the 24-hour boundary, a malformed newest file, and external stateDir.
- If metadata is introduced, tests remove/corrupt it and change a transcript from another process; discovery must recover the same eligible session. Recovery may scan, but cannot silently omit sessions.
- Publish a portable fixture/reproduction command and actual before/after table; preserve public API and error behavior.
Related work
The closed resume/rendering issue github/squad#663 does not cover this measured all-transcripts discovery cost. This is distinct from growing-history autosave write amplification.
Methodology: dotnet/aspnetcore#70219 and microsoft/waza#846.
- Dominant language
- TypeScript
- Stars
- 3.4k
- Forks
- 516
- Avg merge
- 1d 15h
- Merged PRs (30d)
- 116
Getting set up
- Ships a Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from github/squad
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 77/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
Similar issues
-
bot:ai-assisted component:platform-js status:untriaged
Difficulty 1/5 Under an hour Newbie friendliness 74/100
midnightntwrk/platform-js#38 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
ranxianglei/billion-context#7068 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
mybigday/whisper.rn#348 ·
-
enhancement severity:low
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Battle-Cattle/BCUK-Bot-4#1075 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 67/100
ilan-pinto/roaring-lions#1552 ·
Maintainers usually reply within 1 day