Skip to content

fix: cap extract size so long sessions can't stall saves (#96)#109

Merged
fdaviddpt merged 1 commit into
mainfrom
fix/96-extract-size-cap
Jun 21, 2026
Merged

fix: cap extract size so long sessions can't stall saves (#96)#109
fdaviddpt merged 1 commit into
mainfrom
fix/96-extract-size-cap

Conversation

@fdaviddpt

Copy link
Copy Markdown
Contributor

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-prompt embedded the full extract with no size cap, so the Haiku call failed, the save aborted (set -e), and daily rotation (now.mdtoday-*.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_prompt gains max_extract_bytes (default 0 = 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.sh passes thresholds.extract_max_bytes (default 300 KB ≈ 75K tokens, generous headroom under Haiku's 200K window) via the existing config helper.
  • Configurable in 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.
  • Updated test_main_dispatches_build_prompt for the new kwarg + added a 7th-arg dispatch case.

Full suite: 448 passed, 41 skipped.

Credit

Diagnosis + tested patch by @selvi5006-commits in #96.

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>
@fdaviddpt fdaviddpt merged commit e6bc862 into main Jun 21, 2026
12 checks passed
@fdaviddpt fdaviddpt deleted the fix/96-extract-size-cap branch June 21, 2026 21:16
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.

save-session: no cap on extract size → oversized Haiku prompt exceeds context window → silent rotation stop (complements #94)

1 participant