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:
- Summarizing early is free for a leg that doesn't read summaries. The seeded prose mode ("Visceral Prose": an instruction and
persona) and the built-in prose template don't, so on the defaults the writer keeps exactly the history it would have kept. The price there is summarization calls. - It is not free for a leg that does. Every active summary is injected into a leg whose mode declares
summary— the seeded Beat Director does, and so may a creator's prose mode. The block is priced with the leg's history in one fit (HybridLegPlanner.FitAssembledBeatLegAsync→LegWindowFit), so when the leg doesn't fit an earlier summary costs it some of its oldest history first; facts, memories and searched lore only go once the history is down to the reserveContext.StaticPromptShareleaves it, and the summaries themselves last. The cost is bounded: at mostSummarization.SummaryCountlevel-1 summaries are active before they roll up. - The director can have a gap today. On Hybrid the director's history is fitted to the beat model's window, which can drop turns the writer keeps; the trigger's threshold counts only the writer (
EffectiveHistoryCapacityis the prose leg's). A turn the director dropped and no summary covers is invisible to the one model that plans the story.
Two notes for the build:
- Three comments say the history read "only ever returns unsummarized rows":
DynamicContextThreshold,IPipelineContext.EffectiveHistoryCapacity, andPromptLegAssembler'sLegAssembly.HistoryCapacity. That is true for Discord and false for web — the capacity-not-occupancy rule they explain still holds, but the sentence is corrected in this work. - The overlap itself is a standing decision this spec relies on (
docs-internal/product/competitive-research-latitude-aidungeon-voyage.md§4.9 records the audit and the option of making the layers disjoint). If the web read ever stops returning summarized messages, the scene trigger below would take a closed scene out of the writer's window at every scene change, and must be revisited then.
Design Goals
- A summary covers whole scenes whenever the story marks them.
- No gap for either leg. Nothing slides out of the writer's or the director's verbatim window before a summary covers it.
- 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 betweenMand2·W— that is today's cut, whatever size it comes to. - 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.
- One source of truth for a break: the turn's stored beat, where it is written and corrected.
Non-Goals
- A Classic producer. Journal §2a's tracker-eval producer comes next and brings its own storage when it is built. Classic chats are untouched.
Since built (M8b): the tracker eval marks Classic scene breaks — but only in a story whose tracker eval runs, so a
Classic story with no tracker bound (or its cadence off) still cuts chapters by count. Owner, 2026-10-30: keep the
scene mark with the trackers; built-in trackers will run by default with an opt-out (the Place tracker,
docs-internal/architecture/chat-engine/LOCATION_TRACKER.md, is the first), which gives every story the eval that marks its scenes. A reader who opts out of every tracker keeps count-based chapters. - Discord. Its trigger (
DiscordChat/Services/SummarizationTriggerService) has no producer and is not changed. - Making summaries and history disjoint on web — a separate context-composition decision (see above).
- Re-cutting summaries already written. Correcting a scene break moves future summaries only.
- Scene names on summaries or memories in the UI. The name reaches the summarizer through the beat's text (below), so a summary tends to name its scene, but no title column is added.
When a pass runs
Two triggers feed the one existing loop in CheckAndTriggerAsync:
- 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 leastMmessages. This is the new trigger: the summary lands when the scene ends, while its messages are still in every window. - 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 atContextSettingsAdvisor.HistoryFloorMessageslike 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:
- Assembled leg: the number of rows in the turn's history window (
TurnState.History) from the oldest row whose unit survivedFitAssembledBeatLegAsyncthrough the newest — beat-less rows inside that span count as rows (they were left out for register, not for room); 0 when every unit dropped.BeatHistoryUnitgains the window index it came from, which is what makes this countable. - Flattened leg: the conversation's own leg, fitted to the writer's window with the conversation mode's larger block, keeps fewer turns than the writer; when its
LegAssembly.Droppedis above 0, itsHistoryCapacity. - Carried on the beat leg of the turn's plan (
HybridBeatLegPrompt), read by the trigger throughcontext.HybridLegPlan?.BeatLeg— the plan is already a real property on the shared context object the summarization stage hands the trigger. A newIPipelineContextmember would need aPipelineContextBaseimplementation too, or its default setter would silently discard the value.
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.
- A summary is never smaller than
M, except a backlog pass that finds no scene start betweenMand2·W— that is today'sWcut. - A pass the director pulled forward never takes the newest exchange. With the director's floor at 6 and
Wat 10, a backlog pass can run on a backlog smaller thanW, and today's cut would sweep up the reply just written — which a regeneration would then replace under a summary describing the old version. When the director's capacity set the threshold, the backlog cut ismin(W, backlog − 2). (Classic keeps today's cut, including the existing edge where a tiny capacity sweeps up the newest exchange.) - Short scenes are summarized with their neighbour. A scene start before position
Mis skipped, so a four-message interlude joins the scene after it. - A summary is at most
2·W. A closed scene longer than that is cut atW, mid-scene, and its tail ends on the scene's own boundary in the next pass. - The trade-off, stated: the tail left by a mid-scene cut is also measured against
M. If it is shorter, it joins the next scene — one seam — rather than becoming a summary too small to recall anything by. That only happens to scenes long enough to be cut in the first place.
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:
- Calls per scene close. Every call that runs a pass also dispatches the
on_summarizationjournal and tracker evals — the default cadence for both (67_tables_journal.sql,68_tables_trackers.sql). So a scene close costs up to three LLM calls (summary, journal, tracker) plus, more often than today, a rollup and its embeddings. At most one summary perMmessages instead of one perW— up to about 1.7× the summary calls at the defaults. - Journal and trackers update at scene closes. On a Hybrid chat on those cadences, the journal and trackers now catch up when a scene ends instead of every
Wmessages past the threshold. That is intended: it is the "updates arrive at meaningful moments" argument the journal design makes for its per-summarization option (Journal, design debates). - The director pays for earlier summaries (above). A closed scene rides in its prompt twice — verbatim and summarized — until its window slides past it, and the summary block is fixed cost when its history is fitted, so the director keeps fewer of its oldest turns. Because the director's capacity is measured after that fit, each earlier summary also lowers the next turn's threshold: the pull-forward drifts down until a rollup shrinks the summary block. That drift is bounded by
Summarization.SummaryCount(at most that many level-1 summaries are active) and by the floor of 6. The summary section is the last one the static trim gives up (PromptKeyCatalog, sacrifice rank 5 of 5), so if the block does overflow its share, facts, memories and lore go first. The build measures this on a small beat model before calling the defaults done (an acceptance criterion below). - A narrow read on every Hybrid turn below the threshold, to find scene starts.
- The rollup code is unchanged, but each roll-up spans fewer messages when summaries are smaller.
M is the writer's dial for all of this, next to Summary Window Size.
Where it lives
SceneCut(Core, pure): given the scene-start positions,M,W, the backlog and the threshold, says whether a pass runs and where it cuts. No platform types, so a future Classic or Discord producer reuses it unchanged.- Scene starts (WebChat, next to
HybridExtraction): the turn-aligned positions ofnewbreaks in a list ofWebMessagerows, viaBeatParser. WebSummarizationTriggerService.CheckAndTriggerAsync: the restructured early return with its narrow scene read, the loop condition above, the larger read, and the cut fromSceneCut. (The summaries switch and eval dispatch only on progress are already there — the early return moves below the switch, which stays first.) The rest of the pass — the summary call, the tracker timeline, the atomic insert-and-link, the error-summary path — runs on the chosen span unchanged.SummarizeOldestMessagesAsync(context, count)keeps its exact-count contract (its only other callers are tests).- The director's capacity: computed by
HybridLegPlannerfrom the beat leg's fit (assembled or flattened, as defined above), carried onHybridBeatLegPrompt, read by the web trigger throughcontext.HybridLegPlan?.BeatLeg. - The setting
Summarization.MinSceneMessages:SettingsKeys,SettingsDefaults(slider 2–20, default 6, category Summarization,DisplayOrderrenumbered so it sits right after Summary Window Size), andclientConsole/src/constants/settingKeys.ts. NoSettingsViewConfigchange: the chat settings view already lists the whole Summarization category.SettingsInitializerseeds it on the next ServerAPI / AdminAPI start, andSettingsSeedingTestsrequires the key inSettingsDefaults. The code reads it with a?? 6fallback, because test fixtures never run the initializer. Its description says it only matters when the story marks scene breaks (Hybrid chats today).
Decided (mine to decide)
- Scene passes run as soon as a scene closes, not only when the backlog outgrows a window: on web that never changes what the writer reads on the defaults, and the summary is written while the scene is whole in every window. The costs are the ones listed under Cost;
Mbounds them. - The director's window counts toward the backlog threshold, with Dynamic Context on or off, and its capacity follows the writer's capacity-not-occupancy rule.
- The summaries switch is checked inside the trigger (landed 2026-09-24, closing the catch-up bypass).
Mdefaults to 6: three exchanges. Below that, a scene is an interlude, and a summary of it is a poor recall unit that still costs a call.- A summary is at most
2·W. - The first qualifying scene start wins, not the one closest to
W: one pass, one scene (plus any folded interlude). - A mid-scene tail shorter than
Mjoins the next scene (one seam) rather than becoming a tiny summary. - The minimum is a per-conversation user setting next to Summary Window Size.
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):
- As a writer on a Hybrid chat, when the story moves to a new scene, the scene I just left becomes one summary that ends where the scene ended — visible in the chat's How drawer → Memory → Browse summaries, and in that summary's covered period.
- As a writer, I can set the minimum scene size for a summary in the chat's settings, right after Summary Window Size, with a description that says when it applies.
- As a writer, I can mark or unmark a scene break from the Story-beat panel, and a later summary follows my correction; on a turn a summary already covers, the panel tells me that summary won't change.
Behavior:
- A stored beat that marks
new, with at leastMunsummarized messages in front of its turn, triggers a pass that ends exactly at that turn's user message — including when the backlog is far below the threshold (a scene start at 14, backlog 20, threshold 50 → one pass, cut at 14). - Fewer than
Min front of it triggers nothing; those messages join the next summary. - Each pass cuts at the first scene start at position
Mthrough2·W, else atW; a start at exactly2·Wis seen and used. - A scene-aligned cut never separates a user message from its reply.
- A closed scene longer than
2·Wbecomes aWcut followed by a summary that ends on the scene boundary. - When the director's fit drops history (assembled or flattened), the backlog trigger fires at the director's capacity (floored at 6), with Dynamic Context on and off; when it drops nothing, the capacity is null and the trigger fires exactly as before.
- A backlog pass the director pulled forward never includes the newest exchange.
- The scene name appears in the text the summarizer reads for that window.
- The summary catch-up endpoint also summarizes closed scenes.
- The journal and tracker
on_summarizationevals run after a pass that made progress, and not after a call that made none. (Backlog passes: landed 2026-09-24, pinned inWebSummarizationTriggerServiceTests; re-check with scene passes.) - A failed summarization writes its error summary over the chosen span, retryable from the summary browser as today.
Invariants that must stay true (carve-outs):
- A conversation with no scene breaks and no director — every Classic chat — is summarized over exactly the same messages as before.
- The history read is unchanged. With the seeded prose mode and with the built-in template, the writer's fitted history is unchanged.
- Discord summarization is unchanged.
- The rollup code is unchanged.
- Summaries already written are never re-cut by a later correction.
- With
Features.EnableSummariesoff, no pass of any kind runs — from the per-turn stage or fromPOST …/summarize-catchup. (Backlog passes: landed 2026-09-24, pinned inWebSummarizationTriggerServiceTests; re-check with scene passes.)
Edges:
- A scene start at position 0 is not a cut.
- A beat whose
sceneis missing,continue, unknown or unreadable is no break; a beat on a user row is never read. -
MinSceneMessagesaboveWis read asW, below 2 as 2, and a hand-setWof 1 does not throw. - After a regeneration or a version switch, the cut follows the selected version's beat; a break set by a regeneration is picked up on the next turn.
- A director whose always-on block leaves it fewer than 6 history messages pulls the threshold to 6, not below.
- A Classic conversation does no scene read on any turn.
- Measured, with a pass bar: the seeded director on an 8k-token beat window, over a 40-turn chat with scene breaks, keeps at least 6 history messages on every turn, and the threshold never sits at the floor for more than one rollup cycle. The numbers (from the "Beat leg window fit" and static-trim log lines) are recorded in this doc; a miss changes the defaults before this is called done.