Skip to content

Write Pi's summary at the extension's threshold - #4

Merged
HugoLopes45 merged 3 commits into
mainfrom
feat/soft-early-threshold
Oct 6, 2026
Merged

HugoLopes45 merged 3 commits into
mainfrom
feat/soft-early-threshold

Conversation

@HugoLopes45

Copy link
Copy Markdown
Owner

Stacked on #3. Merge #3 first; GitHub then retargets this PR to main.

Why

Pi compacts at contextWindow - reserveTokens, about 983k tokens on 1M-window models. thresholdTokens compacted only through a handoff note. When the note failed or did not fit, or when soft came first in methodOrder, nothing compacted until Pi's own threshold. A separate context-window cap extension was needed to compact at 150k.

Change

  • soft writes Pi's summary (generateSummaryWithUsage) at the end of the turn. It does this when the context is still above the extension's threshold and that threshold is below Pi's. The run is not aborted.
  • Like Pi, it passes the previous summary to the update prompt and does not summarize it as history.
  • It writes nothing when no history comes before the retained context.
  • After a failed summary, it does not retry until the next compaction. Pi then compacts at its own threshold.
  • README and CHANGELOG are updated.

Tests

New integration tests in test/extension.test.ts. Each one fails without the change it covers.

  • A failed handoff falls back to Pi's summary, and the run continues.
  • A failed summary is requested only once.
  • No early summary is written when soft is not in methodOrder or when the threshold equals Pi's.
  • No summary request is made when only the previous summary comes before the retained context.
  • The previous summary uses the <previous-summary> update prompt.

npm run check: 97/97 passed.

Anthropic invalidates the cached message prefix when tool_choice or thinking parameters differ from the conversation's requests. Handoff notes sent toolChoice "none" without reasoning, so in the recorded sessions they read only 5-14% of their prompt from cache (3.96M of 20.5M tokens over 170 notes). A reply that calls a tool is now rejected, since tool use is no longer disabled.
Pi's own compaction waits for contextWindow - reserveTokens, about 983k
tokens on 1M-window models. When the handoff note failed, did not fit,
or soft came first in methodOrder, thresholdTokens therefore did not
compact, and a context-window cap was needed to compact at 150k.

soft now writes Pi's summary at end of turn when the extension's threshold
is below Pi's, so the run is not aborted. Like Pi, it updates the previous
summary instead of summarizing it as history, writes nothing when no
history precedes the retained context, and does not retry a failed
summary until the next compaction.
@HugoLopes45 HugoLopes45 self-assigned this Oct 6, 2026
@HugoLopes45
HugoLopes45 changed the base branch from fix/handoff-cache-reuse to main October 6, 2026 09:35
@HugoLopes45
HugoLopes45 merged commit 3cc7019 into main Oct 6, 2026
2 checks passed
@HugoLopes45
HugoLopes45 deleted the feat/soft-early-threshold branch October 6, 2026 09:37
HugoLopes45 added a commit that referenced this pull request Oct 6, 2026
The old README assumed knowledge of compaction, tokens and thresholds.
This rewrite, in ASD-STE100 style:

- explains the terms and the sequence of a session;
- documents every `contextKit` setting with its allowed values, default
and an example;
- adds recipes, limits and questions.

Checked against the code:
- Defaults, validation rules and the warning text match `src/config.ts`
and `extensions/index.ts`.
- `soft` writes Pi's summary at the extension threshold (#4). Only `[]`
waits for Pi's own limit.
- The release section is unchanged from #5.
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