feat: add auto-compaction retry hook for embedded consumers#1318
Closed
1kuna wants to merge 3 commits intobadlogic:mainfrom
Closed
feat: add auto-compaction retry hook for embedded consumers#13181kuna wants to merge 3 commits intobadlogic:mainfrom
1kuna wants to merge 3 commits intobadlogic:mainfrom
Conversation
Co-authored-by: Alyx <[email protected]>
Co-authored-by: Alyx <[email protected]>
Co-authored-by: Alyx <[email protected]>
Contributor
|
Hi @1kuna, thanks for your interest in contributing! We ask new contributors to open an issue first before submitting a PR. This helps us discuss the approach and avoid wasted effort. Next steps:
This PR will be closed automatically. See https://github.com/badlogic/pi-mono/blob/main/CONTRIBUTING.md for more details. |
This was referenced Feb 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Auto-compaction can recover from an overflow, but the automatic retry can still overflow if the session’s system prompt (or embedded consumers’ injected context) remains too large. This can create an overflow → compaction → retry → overflow cascade.
This PR adds a small, embedded-consumer-focused hook that runs after auto-compaction has been applied but before Pi schedules the overflow retry, so consumers can:
Refs #1317.
What changed
AgentSessionAPIsetAutoCompactionRetryHook(hook).AutoCompactionRetryHookContext,AutoCompactionRetryHookResult,AutoCompactionRetryHook.messages,systemPrompt, model + context window sizing, and token estimates (message/system/total/budget/overBy + overhead estimate).compaction.autoCompactionRetryHookTimeoutMs(default: 1000ms).auto_compaction_endnow includesretryCanceledMessagewhen compaction succeeds but the overflow retry is cancelled by the hook.Why this is useful
Embedded consumers may inject extra context (e.g. workspace files) into the system prompt. After compaction, the conversation may fit but the system prompt may still exceed the retry budget. The new hook provides a safe escape hatch to prevent runaway overflow cascades.
OpenClaw will use this hook to apply a slimmer retry prompt when needed.
Backward compatibility