Repository navigation
fix(token-spy): count new turns across partial session cleanup - #4640
Merged
gabsprogrammer merged 3 commits intoSep 13, 2026
Merged
gabsprogrammer merged 3 commits into
gabsprogrammer merged 3 commits into
Conversation
This was referenced Sep 12, 2026
0xacee
marked this pull request as ready for review
September 13, 2026 04:15
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
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.