fix: cap extract size so long sessions can't stall saves (#96)#109
Merged
Conversation
A single long-lived session can grow an extract larger than Haiku's context window. build-prompt embedded the full extract with no size cap, so the Haiku call failed, the save aborted, and daily rotation stopped. It was self-reinforcing: a failed save never advanced the saved position, so the same session re-extracted the full transcript and failed identically on every later save. cmd_build_prompt now caps the extract at thresholds.extract_max_bytes (default 300 KB), keeping the most-recent tail with a truncation note so the summary still reflects current work. 0 disables the cap. Wired through the CLI dispatcher and save-session.sh via config. Distinct from #94 (timeout + reachable error handler) — complementary, not a replacement. Thanks to @selvi5006-commits for the diagnosis and a tested patch. Co-Authored-By: Max <noreply>
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.
What
Caps the session extract before it's embedded in the Haiku prompt, so a very long session can't overflow the model's context window and silently halt memory saves. Fixes #96.
Why
A single long-lived session can grow an extract larger than Haiku's context window.
build-promptembedded the full extract with no size cap, so the Haiku call failed, the save aborted (set -e), and daily rotation (now.md→today-*.md) stopped.It was self-reinforcing: a failed save never advances the saved position, so the same session re-extracts the full transcript and fails identically on every subsequent save — until an unrelated small session happens to run.
Distinct from #94 (which makes a residual failure visible via
timeout+ a reachable error handler). This PR prevents the failure. Complementary, not a replacement — neither alone is sufficient.How
cmd_build_promptgainsmax_extract_bytes(default0= disabled). When the extract's UTF-8 size exceeds it, keep only the most-recent tail and prepend a truncation note (the summary should reflect current work).save-session.shpassesthresholds.extract_max_bytes(default 300 KB ≈ 75K tokens, generous headroom under Haiku's 200K window) via the existingconfighelper.config.example.json+ README config table.Tests
test_build_prompt_caps_oversized_extract— tail kept, head dropped, NOTE present, body within cap.test_build_prompt_keeps_small_extract_intact— under-cap passthrough.test_build_prompt_cap_disabled_with_zero— back-compat default.test_main_dispatches_build_promptfor the new kwarg + added a 7th-arg dispatch case.Full suite: 448 passed, 41 skipped.
Credit
Diagnosis + tested patch by @selvi5006-commits in #96.