Session prep sheet not pulling end of last session #271

Closed
opened 2026-07-29 01:35:09 +00:00 by rbrooks · 1 comment
Owner

I'm trying to run the session prep sheet tool and it appears to only be pulling from the first paragraph of last session's summary.

I'm trying to run the session prep sheet tool and it appears to only be pulling from the first paragraph of last session's summary.
Contributor

Root-caused and fixed. Your read was exactly right, and the mechanism is a single shared constant.

Cause

recent_sessions_context (webapp/backend/app/services/generation_service.py:192) truncated every recent session summary to _DEFAULT_RECENT_SUMMARY_CHARS = 800. Real summaries on the live instance:

Session chars prep sheet saw (before) after
The Miller's Tale 1,725 46% 100%
Through Fire to Fate 1,977 40% 100%
The Shadowy and Withered Hands of Fate 2,874 28% 100%
A Shadowy Band of Goblins 2,558 31% 100%

So it was drafting prep from roughly the opening third — "the first paragraph", precisely as reported.

Two problems, not one

Raising the cap alone would have been a half-fix. _truncate keeps text[:limit] — the beginning. For a prep sheet the end of the previous summary is the most valuable sentence in it: the cliffhanger, the unresolved threat, the door that just opened. Head-truncation discarded exactly the part that informs what happens next, which is why the symptom read as "not pulling end of last session" rather than merely "truncated".

Fix

Budget per position rather than one flat cap:

  • most recent session — 3000 chars, and if a summary somehow exceeds that, _truncate_keeping_ends keeps the opening and the closing with a visible […] marker between them, weighted toward the tail
  • older sessions — 1000 chars, head-truncated; the gist is all they need to supply

Deliberately bounded rather than unlimited: worst case is 3000 + 2×1000 = 5000 chars (~1.2k tokens) of recent-session context. Prompt size is not free — oversized prompts are what drive this endpoint to emit malformed JSON (#279), and session_prep is itself a JSON-returning tool. Tripling the cap unbounded would have traded a visible bug for a quieter one.

Affects both consumers of the builder: session_prep (n=2) and arc_suggester (n=3).

Worth noting the codebase already disagreed with itself here — the "previously on" recap builder caps the same kind of content at 2000 (generation_service.py:1493), while this path used 800.

Tests

New tests/test_recent_sessions_context.py — 10 tests, since this builder had no coverage at all. Covers a realistic-length summary surviving intact, both ends surviving when over budget, the tail being favoured over the head, older sessions getting the smaller budget, total boundedness, and the empty/no-summary paths.

Full backend suite running; will confirm before the PR.

Root-caused and fixed. Your read was exactly right, and the mechanism is a single shared constant. ## Cause `recent_sessions_context` (`webapp/backend/app/services/generation_service.py:192`) truncated *every* recent session summary to `_DEFAULT_RECENT_SUMMARY_CHARS = 800`. Real summaries on the live instance: | Session | chars | prep sheet saw (before) | after | |---|---:|---:|---:| | The Miller's Tale | 1,725 | 46% | 100% | | Through Fire to Fate | 1,977 | 40% | 100% | | The Shadowy and Withered Hands of Fate | 2,874 | 28% | 100% | | A Shadowy Band of Goblins | 2,558 | 31% | 100% | So it was drafting prep from roughly the opening third — "the first paragraph", precisely as reported. ## Two problems, not one Raising the cap alone would have been a half-fix. `_truncate` keeps `text[:limit]` — the **beginning**. For a prep sheet the *end* of the previous summary is the most valuable sentence in it: the cliffhanger, the unresolved threat, the door that just opened. Head-truncation discarded exactly the part that informs what happens next, which is why the symptom read as "not pulling end of last session" rather than merely "truncated". ## Fix Budget per position rather than one flat cap: - **most recent session** — 3000 chars, and if a summary somehow exceeds that, `_truncate_keeping_ends` keeps the opening *and* the closing with a visible `[…]` marker between them, weighted toward the tail - **older sessions** — 1000 chars, head-truncated; the gist is all they need to supply Deliberately bounded rather than unlimited: worst case is 3000 + 2×1000 = 5000 chars (~1.2k tokens) of recent-session context. Prompt size is not free — oversized prompts are what drive this endpoint to emit malformed JSON (#279), and `session_prep` is itself a JSON-returning tool. Tripling the cap unbounded would have traded a visible bug for a quieter one. Affects both consumers of the builder: `session_prep` (n=2) and `arc_suggester` (n=3). Worth noting the codebase already disagreed with itself here — the "previously on" recap builder caps the same kind of content at 2000 (`generation_service.py:1493`), while this path used 800. ## Tests New `tests/test_recent_sessions_context.py` — 10 tests, since this builder had **no** coverage at all. Covers a realistic-length summary surviving intact, both ends surviving when over budget, the tail being favoured over the head, older sessions getting the smaller budget, total boundedness, and the empty/no-summary paths. Full backend suite running; will confirm before the PR.
rbrooks referenced this issue from a commit 2026-08-06 00:46:34 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
rbrooks/Quest-Board#271
No description provided.