perf(cli): avoid unrelated transcript reads on latest-session lookup

Open
#2,475 0 comments 0 reactions 0 assignees View on GitHub

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

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from github/squad

All issues in github/squad

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.