Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions changelog.d/2026-11-29-agent-history-summary-bounded.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
### Changed
- **An agent's summary of a long-running project or task no longer grows
without end, and its older parts are no longer rewritten.** The summary is
kept in sections: a finished one is set aside as written, and only the
newest is ever updated, so earlier decisions cannot be dropped by a later
rewrite. The agent reads the most recent sections and can search the older
ones.
76 changes: 76 additions & 0 deletions docs/adr/0174-a-log-summary-is-frozen-sections-and-one-open-one.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# ADR 0174: A Log Summary Is Frozen Sections and One Open One

- Status: Accepted
- Date: 2026-11-29
- Concepts: [agent memory and compaction](../../knowledge/features/agents/memory-and-compaction.md)
- Amends: [ADR 0017](./0017-deterministic-log-compaction.md) — the shape of a
checkpoint's text; its coverage and selection are untouched
- Replaces, for the event log: the hierarchy
[ADR 0057](./0057-decade-scale-agent-memory.md) decision 3 proposed

## Context

A summary checkpoint held one running text. Every fold handed the whole of it
back to the model, with the newly folded entries, to be written again.

Two things follow, and the long-log run measured both
([agent log summary](../evaluations/agent_log_summarizer.md)). The text grows
with the log — 56 to 97 words a fold on a busy one, with nothing to stop it —
and a rewrite of everything is where history is lost: cut at the completion
cap, or collapsed to a fraction of what it was given. ADR 0172 refuses those
results, which turns loss into a stall: a summary that has outgrown the cap
is refused on every wake and nothing more is compacted.

ADR 0057 proposed a hierarchy above the running summary: quarters folded into
epoch summaries, epochs into years. That is more rewriting of summaries by
models, which is the step that fails.

## Decision

1. **A summary is sections.** Frozen ones, oldest first, and one open
section. A checkpoint's payload stores them (`summarySections`,
`summaryOpen`, `summaryOpenFrom`) beside the text a prompt shows.
2. **A fold rewrites only the open section.** The model is given the open
section's text and the folded entries, a batch of at most 12,000 tokens at
a time. Frozen sections are carried from checkpoint to checkpoint by code.
No model is handed one again, so it cannot be cut, collapsed or drift.
3. **An open section past 600 words is frozen**, with the days its entries
span, and the next fold starts a new one from the entries alone. 600 is
the size every model in the run rewrote without loss.
4. **A prompt shows the newest sections it has room for.** Frozen sections
newest first within 3,000 tokens — the newest always — then the open one,
each under its days. When older ones do not fit, one line says how many
there are, what days they cover, and that `search_memory` reaches
everything in them (ADR 0173).
5. **Nothing changes until a section is frozen.** With none, the summary is
its open text, byte for byte the single running summary it was.
6. **One checkpoint, as before.** A checkpoint still covers a log prefix up
to a cutoff, is still selected by the longest valid prefix, and still dies
when a late event sorts before its cutoff (ADRs 0017, 0071). Only its text
has structure. `summaryText` remains the rendered text, so a build from
before this reads a new checkpoint as it always has, and a checkpoint from
before this is one open section of its whole text.

## Consequences

- What a wake reads of its older history is bounded: about 3,000 tokens of
frozen sections, an open section of at most 600 words and a fold's growth,
and one line. Before, it grew without limit.
- A fold costs the same however old the log is: it reads one section, not
the whole summary.
- **Old sections leave the prompt.** A decision from a section no longer
shown is in the agent's view only if it searches. The index line tells it
there is something to search; nothing keeps an early decision always in
view. If that proves to matter, the answer is a small keyed store of
standing decisions (ADR 0057 decision 1 has one for goal agents), not a
summary of summaries.
- A checkpoint invalidated by a late arrival is rebuilt from the whole log,
as before, and its sections with it: a batch at a time, freezing as they
fill. Rebuilding only the sections after the late event would be cheaper
and is not done.
- The stall ADR 0172 left is gone: the model never rewrites more than one
section, so the summary cannot outgrow the completion cap.
- Run on three models, twelve folds and 120 planted decisions each: every
model holds all 120, with the first section frozen at the seventh to tenth
fold. Twelve folds freeze one section, which fits the prompt, so sections
leaving the prompt is held by unit tests, not by a live run.
28 changes: 22 additions & 6 deletions docs/evaluations/agent_log_summarizer.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,30 @@ Gemini and Ollama were not run. Their adapters dropped the reason a
completion stopped; they now report a cut the same way, held by unit tests on
each adapter, not by a live run.

## 2026-11-29 — with ADR 0174: the summary as sections

The same log, folded as production now folds it: frozen sections the model
never sees again, and one open section each fold extends. Two counts a fold:
decisions the summary still holds, and decisions in the text a wake is shown.

| Model | Decisions held after 12 folds | Shown to a wake | First section frozen | Folds refused |
| --- | ---: | ---: | --- | ---: |
| glm-5.3 | 120 of 120 | 120 of 120 | eighth fold | 0 |
| DeepSeek Flash v4.1 | 120 of 120 | 120 of 120 | seventh fold | 0 |
| Mistral Large 4 | 120 of 120 | 120 of 120 | tenth fold | 0 |

Each model keeps everything, and no fold rewrites more than one section. The
shown and held counts are the same because twelve folds freeze one section,
which fits the 3,000 tokens a wake is shown: this run does not reach the
point where an old section leaves the prompt. That is held by
`summary_sections_test.dart`, deterministically; a live run of it needs a
log three or four times this long.

## What this does not settle

- **The summary still grows with the log.** 56 to 97 words a fold here, and
nothing bounds it. At 8,000 tokens a log this busy reaches the cap after
some fifty folds; from then on every fold is refused and nothing more is
compacted. That is visible rather than silent, and it is not a fix. A
bounded summary — frozen pieces, an index, and recall for the rest, as the
goal agents' digests have — is the work this leaves.
- **Sections leaving the prompt.** Once they do, a decision in one is in the
agent's view only if it searches (ADR 0173). Whether the models then search
when they should has not been run.
- One sample a cell, two for DeepSeek. The 2,048 failures repeated in every
run; their exact fold did not.
- No model was run past twelve folds.
Expand Down
39 changes: 39 additions & 0 deletions knowledge/features/agents/memory-and-compaction.md
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,45 @@ in the summary prose and are never reloaded.
compaction this wake") rather than persisting an empty checkpoint that would
erase folded memory.

## The summary is sections

A checkpoint's text is not one running summary but **sections** (ADR 0174,
`lib/features/agents/projection/summary_sections.dart`): frozen ones, oldest
first, and one open section.

```mermaid
stateDiagram-v2
[*] --> Open: first fold writes it from the folded entries
Open --> Open: a later fold rewrites it with the next entries
Open --> Frozen: past 600 words — stamped with the days it covers
Frozen --> Frozen: carried to the next checkpoint by code, never rewritten
Frozen --> [*]: checkpoint invalidated by a late arrival — rebuilt from the log
```

- **`foldIntoSections`** hands the model only the open section and the folded
entries, a batch of at most `summaryFoldBatchTokens` (12,000) at a time,
and freezes the open section once it passes `summarySectionFreezeWords`
(600). A frozen section is never sent to a model again, so the failures a
rewrite of everything had — a cut, a collapse, a text that grows with the
log — cannot reach it. A fold costs the same however old the log is.
- **`renderSummarySections`** is the text a prompt shows, stored as the
checkpoint's `summaryText`: the newest frozen sections that fit
`summaryShownSectionTokens` (3,000) — the newest always — then the open
one, each under the days it covers. When older sections do not fit, one
line ahead of them says how many there are, what days they cover, and that
`search_memory` reaches everything in them.
- **With nothing frozen the summary is its open text alone**, byte for byte
the single running summary it was; a log changes shape only once it has
outgrown one section.
- **The payload stores the structure** (`summarySections`, `summaryOpen`,
`summaryOpenFrom`) beside `summaryText`. A build from before sections reads
`summaryText` as it always has; a checkpoint from before sections is one
open section of its whole text, frozen by the fold that takes it past the
limit.
- **Coverage is untouched.** One checkpoint still covers a log prefix up to
its cutoff, and `selectActiveSummary` neither knows nor cares what shape
the text has.

## Cadence and prefix caching

`AgentLogCompactor.compactAndAssemble` uses two watermarks:
Expand Down
Loading
Loading