Skip to content

fix(token-spy): count new turns across partial session cleanup - #4640

Merged
gabsprogrammer merged 3 commits into
Osmantic:public-betafrom
0xacee:fix/token-spy-count-new-turns-after-partial-purge
Sep 13, 2026
Merged

gabsprogrammer merged 3 commits into
Osmantic:public-betafrom
0xacee:fix/token-spy-count-new-turns-after-partial-purge

Conversation

@0xacee

@0xacee 0xacee commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

Why this matters: Local-agent lifetime turns are counted incorrectly after partial session cleanup. If two files contain 2 and 3 turns, deleting the first makes the summary rise from 5 to 8. If cleanup and a new session offset each other, new turns can instead be missed. One aggregate file count cannot distinguish these cases.

Persist a per-file observation checkpoint and add only each retained/new file's growth. Removed history stays in the lifetime total without recounting survivors. Preserve the existing user-turn/assistant fallback rule, migrate the legacy scalar total conservatively, keep the last complete snapshot after an unreadable scan, and serialize in-process summary updates.

Validation:

  • Authenticated GET /api/summary with real temporary JSONL histories, deletion, append and persisted legacy state.
  • Baseline: 6 failed. Final full Token Spy suite: 28 passed, 1 skipped.
  • Covers user/assistant histories, cleanup plus new files with equal or smaller aggregate size, legacy migration, and temporary read failures.
  • Changed-file Ruff E/F/W and git diff --check pass.

Overlap check: all-state semantic/file search and inspection of #2798 (atomic accumulated-turn state writes) and #2691 (I/O exception narrowing). Neither changes counting after partial cleanup. #4569 addresses current-session memory and #4583 the reset target, not lifetime counting.

AI assistance: implemented and tested with Codex. Review required before merge: independent review of persisted telemetry. Existing totals are retained, not retrospectively repaired. Counts describe observed file growth; work removed between observations cannot be reconstructed. The lock coordinates threads in one process; cross-process/crash-safe persistence remains a separate concern, including #2798.

Combined validation: c08b6695ff14 on public-beta base 9fc9f61. Token Spy: 64 passed, 1 skipped, including partial-cleanup accounting, poll responsiveness, and reset-target regressions.

Merge guidance: tested Token Spy main.py order is #4561, #4569, #4583, #4634, #4640. The #4583/#4634 poller conflict must retain await asyncio.to_thread for status and reset, include_session_id=True on assessment, session_id=status["_reset_session_id"] on deletion, and cooldown updates only after action == "killed". Backlog compatibility: candidate also includes #2798; all 64 Token Spy tests pass with atomic checkpoint replacement. This PR itself still uses the existing writer.

@gabsprogrammer
gabsprogrammer merged commit fe8c43a into Osmantic:public-beta Sep 13, 2026
36 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants