feat(#61): Implement fallback mechanism for auto-compact token limit recovery

- Add FallbackState interface to track message removal attempts
- Implement getLastMessagePair() to identify last user+assistant message pair
- Add executeRevertFallback() to remove message pairs when compaction fails
- Configure max 3 revert attempts with min 2 messages requirement
- Trigger fallback after 5 compaction retries exceed
- Reset retry counter on successful message removal for fresh compaction attempt
- Clean fallback state on session deletion

Resolves: When massive context (context bomb) is loaded, compaction fails and session becomes completely broken. Now falls back to emergency message removal after all retry attempts fail, allowing session recovery.

🤖 GENERATED WITH ASSISTANCE OF [OhMyOpenCode](https://github.com/code-yeongyu/oh-my-opencode)
This commit is contained in:
YeonGyu-Kim
2025-12-15 21:18:03 +09:00
parent 151ebbf407
commit cea64e40b8
3 changed files with 169 additions and 5 deletions

View File

@@ -8,6 +8,7 @@ function createAutoCompactState(): AutoCompactState {
pendingCompact: new Set<string>(),
errorDataBySession: new Map<string, ParsedTokenLimitError>(),
retryStateBySession: new Map(),
fallbackStateBySession: new Map(),
}
}
@@ -23,6 +24,7 @@ export function createAnthropicAutoCompactHook(ctx: PluginInput) {
autoCompactState.pendingCompact.delete(sessionInfo.id)
autoCompactState.errorDataBySession.delete(sessionInfo.id)
autoCompactState.retryStateBySession.delete(sessionInfo.id)
autoCompactState.fallbackStateBySession.delete(sessionInfo.id)
}
return
}
@@ -120,6 +122,6 @@ export function createAnthropicAutoCompactHook(ctx: PluginInput) {
}
}
export type { AutoCompactState, ParsedTokenLimitError } from "./types"
export type { AutoCompactState, FallbackState, ParsedTokenLimitError } from "./types"
export { parseAnthropicTokenLimitError } from "./parser"
export { executeCompact, getLastAssistant } from "./executor"