Skip to content

perf(token-spy): bound memory for local session status polls - #4569

Merged
gabsprogrammer merged 1 commit into
Osmantic:public-betafrom
0xacee:perf/token-spy-stream-local-session-history
Sep 13, 2026
Merged

gabsprogrammer merged 1 commit into
Osmantic:public-betafrom
0xacee:perf/token-spy-stream-local-session-history

Conversation

@0xacee

@0xacee 0xacee commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

Why this matters: A local-model agent with a long JSONL conversation causes every authenticated session-status poll to load the entire history into memory. A 12,000-turn fixture (~13 MB) allocated 13,724,595 bytes in the existing HTTP fallback. Read the file incrementally while preserving turn counts, tool counts, history characters, malformed-line handling, file size and recommendations.

Evidence and validation:

  • Regression exercises GET /api/session-status with database fallback and a real local history, including a measured peak-memory budget of 3 MB after warming HTTP machinery.
  • Before: 1 regression failed, 1 counting control passed. After: full Token Spy suite 24 passed, 1 skipped. Changed-file Ruff E/F/W checks and git diff --check pass.
  • Separate mixed-record fixture verifies blank/malformed lines and string-encoded messages.
  • Overlap check: open/closed title and changed-file searches found fix(token-spy): narrow broad excepts in local session-status helpers #2691 (narrow exception handling in these helpers); its patch does not stream the history. This uses its intended I/O exception boundary for the stream. No remote SSH behavior or reset selection is changed.

AI assistance: implemented and validated with Codex. Local HTTP tests use synthetic session files and no live agent. Review required before merge: independent review of session monitoring, which feeds automatic reset decisions.

Combined validation: c08b6695ff14 on public-beta base 9fc9f61. Token Spy: 64 passed, 1 skipped, including the public HTTP memory-budget regression.

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".

@0xacee
0xacee marked this pull request as ready for review September 13, 2026 04:15
@gabsprogrammer
gabsprogrammer merged commit a35e3b6 into Osmantic:public-beta Sep 13, 2026
42 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