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

fix(agent-manager): add skip() to Pi, Grok and Copilot summary reducers for the bounded cold-start scan

Open codeaholicguy opened this issue 2 months ago • 0 comments

Problem

#261 makes IncrementalJsonlSummary do a bounded head/tail scan by default when it rebuilds large files (over head + tail = 5 MiB). It reads the first 1 MiB, skips the middle, then reads the last 4 MiB. Before folding the tail, it calls an optional reducer hook, skip(state), so the reducer can clear "latest" fields and stop tail entries from filling "first" fields.

The Pi (#262), Grok (#264) and Copilot (#265) reducers were written on the #256 base, before #261 existed, so none of them implements skip(). Once rebased onto #261:

  • A "first" field (e.g. Grok's firstUserMessage, and any first-* fields in the Pi and Copilot reducers) can be filled from the tail when its real value is in the skipped middle. The result is a wrong summary for large files.
  • "Latest" fields can mix head and tail state if they aren't cleared.

Proposed approach

For each of the Pi, Grok and Copilot reducers, either:

  • implement skip(state): keep head-derived "first" fields, clear "latest" fields, and set a pastHead flag so tail entries don't overwrite "first" fields; or
  • opt out with bounds: false if a full scan is needed for correctness. Document why.

Follow the Claude reducer's skip() in ClaudeSessionParser as the reference.

Acceptance criteria

  • [ ] The Pi, Grok and Copilot reducers each implement skip(), or explicitly opt out with a documented reason.
  • [ ] For each adapter, a [fixture, padding, fixture] test with small bounds (skippedBytes > 0) shows "first" fields come from the head only and "latest" fields from the tail only. This matches the SessionSummaryEquivalence pattern from #261.
  • [ ] A test covers the cap-reached case: a first-* value only in the skipped middle gives the documented, deterministic fallback, not a value from the tail.
  • [ ] Existing Pi, Grok and Copilot tests pass.

Depends on #261, #262, #264 and #265 being merged or rebased together.

codeaholicguy avatar Sep 28 '26 11:09 codeaholicguy