ai-devkit icon indicating copy to clipboard operation
ai-devkit copied to clipboard

perf(agent-manager): bounded head/tail scan for the first session summary (cold start)

Open codeaholicguy opened this issue 2 months ago • 0 comments

Problem

Even with the incremental summary cache (#256), the first refresh after startup, and any rebuild after truncation or rotation, still parses each live transcript from byte 0. Large transcripts (100 MB+) make console startup and the first agent list slow and push peak memory up (~4× file size).

Proposed approach

Compute the initial summary with a bounded head scan plus tail scan instead of a full parse:

  • Head (forward, capped at e.g. 1 MiB): session start timestamp, first user message.
  • Tail (backward, in chunks, capped at e.g. 4 MiB): last conversation entry type, interrupted flag, last activity timestamp, last cwd, last user message.
  • Seed the incremental cache with offset = size, so later refreshes are incremental.
  • If a cap is reached before a field is found, leave that field empty or fall back to its current default, and record this so the fallback can be tested. Don't do a hidden full scan.

Acceptance criteria

  • [ ] The first summary of a 400 MB fixture reads ≤ 5 MiB and takes ≤ 50 ms.
  • [ ] For all existing fixtures, the bounded summary equals the full-parse summary.
  • [ ] A test covers the cap-reached case, e.g. a first user message beyond the head cap, with documented, deterministic output.
  • [ ] Cold listAgents() on a ~30 agents / ~1 GB transcript fixture completes in ≤ 500 ms with peak RSS ≤ 150 MB.
  • [ ] Used by every adapter that adopts the #256 utility.

Depends on #256.

codeaholicguy avatar Sep 28 '26 08:09 codeaholicguy