Skip to content

fix: suggest the earliest thread summary range, folding completed progress - #5583

Merged
leaf-agent merged 1 commit into
mainfrom
fix/issue-5531
Nov 6, 2026
Merged

leaf-agent merged 1 commit into
mainfrom
fix/issue-5531

Conversation

@leaf-agent

Copy link
Copy Markdown
Collaborator

The thread summary hint could suggest a range in the middle of a thread, so a summary that followed it left older messages in full above it. batch_threads split the earlier discussion at every progress (ephemeral) message and suggested the longest resulting run. One progress update completed early in a thread was enough to cut off the opening messages. That split dates from the automatic progress folds, which a hint must not overlap. #3534 removed those folds, and the browser now omits completed progress altogether, so the split no longer protects anything.

A run of messages now passes over completed progress. It still ends at pending progress, which is drawn and not yet answered, and at summaries in force. The hint takes the earliest run that qualifies instead of the longest, so it doesn't skip past an older qualifying run.

Tests in tests/model/test_thread_reading.py:

  • test_summary_hint_leaves_no_older_discussion_above_it reproduces the report: one completed progress update after the second message used to move the hint past the opening messages. It fails on main and passes here.
  • test_summary_hint_takes_the_earliest_qualifying_run fails on main and passes here.
  • test_summary_hint_folds_completed_progress_and_stops_at_pending replaces test_summary_hint_does_not_cross_ephemeral_updates, which asserted that no hint crossed completed progress. That is the behavior this PR changes.

The thread-reading and interact-product model tests pass locally (61).

What this leaves open. Two parts of the report remain:

  • leaf thread summarize still accepts any contiguous range. A range the agent picks itself can leave a gap above the summary. Refusing such ranges at admission is a contract decision, partly because the issue leaves open whether the thread's first message is kept on purpose, so it isn't made here.
  • The issue also saw a hint that overlapped an existing summary. In this code a hint is built only from messages no summary in force covers, and I couldn't reproduce an overlap from the report.

Refs #5531 — automated triage

…gress

The summary hint split a thread's earlier discussion at every progress
message and suggested the longest resulting run. Progress completed
mid-thread therefore cut off the older messages, and a summary following
the hint left them in full above it. The split dates from automatic
progress folds, which a hint must not overlap; #3534 removed those folds,
and completed progress is no longer drawn. A run now folds completed
progress, still stops at pending progress and at summaries in force, and
the hint takes the earliest run that qualifies.

Behavior change: `test_summary_hint_does_not_cross_ephemeral_updates`
asserted no hint across completed progress; it is replaced by a test that
the hint folds completed progress and stops at pending progress.

Refs #5531
@leaf-agent
leaf-agent merged commit d133d57 into main Nov 6, 2026
6 checks passed
@leaf-agent
leaf-agent deleted the fix/issue-5531 branch November 6, 2026 01:36
max-sixty added a commit that referenced this pull request Nov 15, 2026
…6049)

A summary of a long thread could fold a middle stretch and leave older
messages, just after the thread's first, in full above it. `leaf thread
summarize` admitted any contiguous range, and #5583 fixed only how the
hint picks its range, so a range the agent picked itself still left the
gap.

**The rule.** No message but the thread's opening one may stand in full
above a summary. `events.summary_range` holds the rule. Given the
summaries that stand once a new summary is written, it returns the range
that summary must cover: the asked range, widened over every message
left in full above the last drawn summary. Admission and the hint both
call it.
- The opening message may stay outside, since it says what the thread is
about.
- Progress that a later reply completed is drawn nowhere, so it doesn't
count. A summary of completed progress alone is drawn nowhere either, so
no message stands above it.
- Pending progress is drawn, so it counts.
- A reaction is a mark on another message and doesn't count.
- Folds without prose (`--text ''`) are held to the rule too. Completed
progress is already hidden (#3534), so a fold is no longer needed to
tuck it away.

**Admission.** Admission checks the thread as it will read once the new
summary stands and has replaced the summaries it overlaps. So a summary
that ends inside an earlier one can't uncover that one's tail above a
later summary. When `summary_range` widens the asked range, admission
refuses with `summary-gap` and names the wider range. That range is
always admitted, because everything it replaces lies inside it and the
messages it adds were all above the last summary. For example, with
summaries over m1–m5 and m6–m10, a request for m1–m3 is refused with:

```
summary would leave messages unsummarized above a summary, and only the thread's opening message may stay there; summarize --from 'm1' --through 'm5', with prose that covers the added messages too
```

**The hint.** `summary_hint` takes the earliest run of uncovered
messages that is long enough to suggest, and names the range
`summary_range` gives for it, which is the range admission takes.
Before, it could suggest a later run that left the gap. Without the
widening, a short stretch left above a summary would stop the hint for
good: when a rewrite retires a summary's prose, its messages stand
uncovered above a later summary, and every longer run after them would
leave them there. Now the hint names that later run widened over the
stretch, replacing the summary between them.

**Hints over a summary in force.** The issue expected that a hint never
overlaps a summary in force. A hint now does exactly that when it must
close a gap above that summary; otherwise it still stops at covered
messages. The issue's own report of an overlapping hint doesn't
reproduce on the code it was seen on, where every run stopped at covered
messages. The likeliest source is a hint computed before that summary
stood: a delivery captured before the summary was written, or a summary
whose prose a rewrite or a taken-back message retired. That is an
inference, not something I reproduced from the reported page.

**Call Max may reverse.** The thread's opening message may stay outside
a summary, so a summary can start at its second message. Requiring the
opener to be folded too would mean changing only the `thread["id"]`
clause in `summary_range`.

### Prose

- `events.md`, the threads reference ("Summarize a long discussion") and
the command's `--help` (regtest snapshot updated) state the rule,
including folds without prose.
- The threads reference keeps "Leave out messages whose wording still
matters to the current exchange" as it was, with the rule after it.
- The site's "How it works" page now states the rule. It no longer says
completed progress folds behind "Show N progress messages", which #3534
removed.

### Tests

In `tests/model/test_thread_reading.py`:
- `test_a_summary_leaves_no_older_discussion_in_full_above_it` fails on
main, where the gap-leaving range is admitted. It covers the opener, a
reaction and completed progress above an admitted summary, a range that
would replace a summary and uncover its start, and pending progress
counting. Each refusal's named range is then admitted.
- `test_a_summary_inside_an_earlier_one_leaves_no_gap_above_a_later_one`
covers summarizing m1–m3, and m2–m3, inside a summary over m1–m5 with
another over m6–m10. On the PR's first commit, which checked only above
the new summary's start, m1–m3 is admitted, and the m2–m3 refusal names
a range that leaves the same gap. Here each refusal names m1–m5, and
once that is admitted the summaries cover m1–m10.
- `test_a_summary_hint_names_only_a_range_admission_takes` replaces
`test_summary_hint_takes_the_earliest_qualifying_run`, whose setup
summarized a middle range that admission now refuses. A rewrite retires
a summary's prose and leaves its run above a later fold. Where that run
is long enough, the hint names it. Where it is too short, the hint names
the next run widened over it, which no earlier version of this PR
suggested. Both hinted ranges are admitted.

`test_a_fold_pressed_in_a_thread_s_view_stays_under_the_press` (browser)
summarized a range that left the agent's first answer above it. It now
starts at that answer. I read every other `thread summarize` caller in
the tests: each starts at the opener or its first reply.

I also ran a randomized check against the final code, without adding it
to the suite. It made random threads with replies, progress, reactions,
user edits and undos, and tried random summary ranges and every hint it
was given:
- 537 attempts were refused for a gap, and every refusal's named range
was admitted.
- No admitted summary left a message in full above a summary, judged
from the served thread as the panel draws it.
- 137 hints were followed, none refused and none leaving a gap.

### Ran

- `uv run pytest tests/model/test_thread_reading.py
tests/model/test_model_folds.py
tests/model/interact_contract/test_layer_contract.py
tests/model/test_interact_layer.py tests/model/test_product_page.py -n
4`, plus the summary and hint tests in `test_interact_product.py`: 279
passed
- `uv run pytest tests/browser/test_render_floating_panel.py
tests/browser/threads/test_summaries.py -n 2 -k
"fold_pressed_in_a_thread_s_view or keeps_completed_progress_hidden or
search_and_leaf_s_travel or later_summary_replaces"`: 4 passed
- `pre-commit` on the changed files

### Not verified

- The threads-reference wording was not scored with `evals/`. The
summary cases there (`thread-summary-after-topic-drift`,
`thread-summary-preserves-needed-exchange`) expect ranges starting at
the opener, which the rule still admits.
- The journey `tests/journeys/threads/test_layout.py` and the rest of
the browser summary tests didn't run. Each starts at the opener or its
first reply, which I checked by reading.
- The edited "How it works" page was not rendered. The change only
replaces text inside two existing paragraphs, and
`tests/model/test_product_page.py` passes.

Closes #5531
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.

1 participant