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

Abierto
#2,475 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
35/100
Tipo de issue
Refactorización
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
node.js, typescript
Área
cli

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
TypeScript
Estrellas
3.4k
Forks
516
Merge medio
1 d 15 h
PR fusionados (30 d)
116

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de github/squad

Todos los issues de github/squad

Issues similares

Más issues de TypeScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.