Scene-Aligned Summaries

Status: ✅ shipped (2026-10-28, memory M8; kb-audit 2026-10-29). Built and pushed as the M8 push unit of docs-internal/architecture/chat-engine/MEMORY_DELIVERY_PLAN.md: the Hybrid director calls scene breaks (M8a, 5501f30f2), a Classic story's tracker eval marks them on a disjoint turn (M8b, f8d6f69b0), and a summary pass ends its chapter at the first scene start at least Summarization.MinSceneMessages (default 6) in, within two batches, else at the batch size (M8c, 9ff843bc7 + 16c9cb5ee). The Acceptance Criteria boxes below are not ticked on this page; what M8 changed from this design is in the delivery plan. Planned 2026-09-24. The first producer of scene breaks is the Hybrid director — see The director decides each reply's length and marks scene breaks. This builds out Journal §2a, which proposed the idea with the tracker eval as the producer.

Overview

A conversation's older messages are folded into summaries, and summaries roll up into memories. Today the cut is a fixed count: once the unsummarized backlog outgrows what a turn carries, the oldest Summarization.SummaryWindowSize messages (10 by default) become one summary (WebSummarizationTriggerService). A fixed count ignores the story, so a summary routinely covers the second half of one scene and the first half of the next, and every memory built from it inherits the seam. A memory of "the tavern scene" is a unit a writer, and semantic recall, can use; a memory of "messages 31–40" is not.

This feature summarizes whole scenes: when the story marks that a scene closed, the scene is summarized, as long as it is at least a minimum size. The count-based trigger stays as the backstop for scenes that run long, and it now also counts the director's window, not only the writer's.

What a summary does to a turn on web — the fact this design rests on

A summary never removes a message from the history read. The web history read (WebMessageRepository.GetRecentAsync, the only one WebMessageHistoryProvider uses) takes the newest messages by count and token fit, whether or not they are summarized. A summary sits beside the verbatim window, and the two overlap until the window slides past the summarized messages. (Discord differs: it reads unsummarized messages only.)

So the trigger's real job is "no gap": summarize a message before it slides out of a model's verbatim window, so that everything a model can't see verbatim is in a summary it can. Three consequences drive this design:

Two notes for the build:

Design Goals

  1. A summary covers whole scenes whenever the story marks them.
  2. No gap for either leg. Nothing slides out of the writer's or the director's verbatim window before a summary covers it.
  3. A summary never covers fewer than the minimum (Summarization.MinSceneMessages). A scene too short to stand alone is summarized together with its neighbour. The one exception is a backlog pass that finds no scene start between M and 2·W — that is today's cut, whatever size it comes to.
  4. No scene signal, no change. A conversation that never marks a break (every Classic chat today) is summarized over exactly the same messages as before, unless a director window is involved — with one deliberate fix, below: the summaries switch is honoured by every caller.
  5. One source of truth for a break: the turn's stored beat, where it is written and corrected.

Non-Goals

When a pass runs

Two triggers feed the one existing loop in CheckAndTriggerAsync:

  1. A scene closed. When a stored Hybrid beat marks new, everything unsummarized in front of that turn is a closed scene — or several, if earlier ones were too short to summarize on their own. A pass runs when that span holds at least M messages. This is the new trigger: the summary lands when the scene ends, while its messages are still in every window.
  2. The backlog outgrew a window — today's trigger, with the director counted. The threshold is the smaller of today's (DynamicContextThreshold.Resolve: the message cap, or the writer's capacity under Dynamic Context) and the director's capacity, when it has one (below), floored at ContextSettingsAdvisor.HistoryFloorMessages like the writer's so a director whose always-on block swallows its window doesn't summarize every turn. It applies with Dynamic Context on or off: the beat leg is fitted either way.

The director's capacity follows the writer's rule — capacity, never occupancy (LegAssembly.HistoryCapacity): a kept count taken when nothing was dropped would equal the whole backlog on a young conversation and summarize every turn. So it is recorded only when the director's fit dropped history, and is null otherwise:

The early return moves. CheckAndTriggerAsync returns "not needed" today the moment the backlog is below the threshold, before it reads a single row — so trigger 1 needs it restructured: not needed only when the backlog is below the threshold and no scene start sits at position M or later. Finding that out is a read on every Hybrid turn below the threshold, so it is a narrow one (id, role, beat_json of the oldest unsummarized rows), not the SELECT * the pass itself uses; Classic conversations skip it.

The loop then runs while the backlog is at or above the threshold, or a scene start sits at position M or later.

Every caller honours the summaries switch. Landed ahead of this feature (2026-09-24). Features.EnableSummaries used to be checked only by the per-turn stage (SummarizationStageBase), so the summary catch-up endpoint (POST …/summarize-catchup, fired whenever the chat's settings modal closes and from the context-fit hint) summarized a chat whose summaries were off. The check now lives in CheckAndTriggerAsync (web and Discord) and nowhere else, so scene passes added inside the trigger sit behind it automatically. The catch-up endpoint builds a bare context with no leg plan, so it has no director capacity — no pull-forward there, closed scenes still caught up.

Evals follow real progress. Landed ahead of this feature (2026-09-24). The journal and tracker on_summarization evals used to be dispatched on every call that got past the early return, so a pass that could make no progress (no character on the context) re-dispatched both evals on every turn. They are now dispatched only when a pass in the call wrote a summary — including a call that wrote some and then failed, and one whose backlog stayed flat because a turn was stored mid-pass. Scene passes inherit this.

Regenerations. The summarization stage skips regenerated turns, so a scene break set by a regeneration is picked up on the next turn.

Where a pass cuts

Names: W = Summarization.SummaryWindowSize (default 10), M = Summarization.MinSceneMessages (default 6, read as Math.Min(Math.Max(M, 2), W): at least 2, never above W. Both sliders floor at 2, so a W of 1 only comes from a hand-set value, where the cap wins. A plain Math.Clamp(M, 2, W) would throw there, and a throw here fails summarization on every turn of that chat).

Each pass cuts at the first scene start at position M through 2·W; with none there, at W, exactly as today. Positions count from the oldest unsummarized message, so a position is also the size the summary would have.

Examples with the defaults (W = 10, M = 6):

Situation Passes
The director marks new on a turn whose user message sits at position 14 One pass, cut at 14: the closed scene
It marks new at position 4 (a short interlude since the last summary) None; at the next break, at 11, one pass covering both
It marks new at position 30 (a long scene the writer's window still held) Cut at 10 (no start between 6 and 20), then at 20: the second summary ends on the boundary
No breaks; the director's window fit leaves it 16 messages, the writer 50 The backlog trigger fires at 16 instead of 50, cut at 10
A mid-scene cut left 3 messages before the next break That break is skipped; the 3 join the next scene's summary

The spin guard still holds: every pass summarizes at least M messages (at least 2) or W, so each pass makes progress, and the existing no-progress break stays.

Scene starts

Turn-aligned. A break is decided on turn N's beat, and the turn that moves the story opens the new scene, so the scene starts at turn N's user message: the exchange that caused the transition stays with the scene it began. When the assistant row carrying the break has no user message directly in front of it, the row itself is the start. Only assistant rows (role = 1) are read.

Enough rows to see them. The break sits on the assistant row after the start, so seeing a start at position p needs row p + 1. Each pass reads the oldest max(threshold, 2·W) + 2 unsummarized rows (today it reads W) — enough to see every start the pass could cut at and every start that keeps the loop running. No start is missed for good: at or above the threshold the backlog trigger drains the backlog, and below it the read covers the whole backlog.

Read from the stored beat. web_messages.beat_json carries the director's scene field on each Hybrid assistant row, and the pass already loads rows with their beats (Hybrid summaries read the beat, not the prose, via HybridExtraction). A break is a beat whose scene parses as new; continue, a missing field or an unreadable beat is no break.

The selected version. The pass reads the selected version of each turn, so after a regeneration or a version switch the break is whatever the shown beat says.

Corrections. Editing the scene call in the Story-beat panel rewrites beat_json through the existing beat-raw PATCH (which reparses with BeatParser and re-serializes with ToBeatJson, so the companion change must teach both the scene field), and the next pass reads the correction. On a turn a summary already covers, the panel says so next to the toggle: the correction still reaches the director's history, but that summary is not re-cut. The chat message payload has no summarized flag today (clientConsole/src/types/chat.ts); it gains one.

Why not a column. A scene_break column would be a second copy of a fact that already lives in the beat and is edited there. When the Classic producer is built it needs storage of its own, and the pass will read both through the same scene-start function — that is where a column may earn its place.

The scene name. On a new break, the beat's extraction text (HybridBeatState.ToExtractionText, what the summarizer reads for a Hybrid window) carries Scene: new — <name> — only when the beat has story content, so a beat that is nothing but a scene line still falls back to the prose for extraction.

Cost

Stated in full, because a scene close now costs more than one call:

M is the writer's dial for all of this, next to Summary Window Size.

Where it lives

Decided (mine to decide)

Acceptance Criteria

The feature is not done until every box below is verified ✅ against the running product.

User use cases — satisfiable + accessible (verify by driving the UI, not the code):

Behavior:

Invariants that must stay true (carve-outs):

Edges: