mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-15 21:03:19 +00:00
fix(coding-agent): handle auto-compaction failures gracefully
When auto-compaction fails (e.g., quota exceeded), emit the error via the auto_compaction_end event instead of throwing. The UI now displays the error message, allowing users to take action (switch models, wait for quota reset, etc.) instead of crashing. fixes #792
This commit is contained in:
parent
5c59caee4e
commit
20f5fcc79d
4 changed files with 25 additions and 8 deletions
|
|
@ -62,7 +62,13 @@ import type { BashOperations } from "./tools/bash.js";
|
|||
export type AgentSessionEvent =
|
||||
| AgentEvent
|
||||
| { type: "auto_compaction_start"; reason: "threshold" | "overflow" }
|
||||
| { type: "auto_compaction_end"; result: CompactionResult | undefined; aborted: boolean; willRetry: boolean }
|
||||
| {
|
||||
type: "auto_compaction_end";
|
||||
result: CompactionResult | undefined;
|
||||
aborted: boolean;
|
||||
willRetry: boolean;
|
||||
errorMessage?: string;
|
||||
}
|
||||
| { type: "auto_retry_start"; attempt: number; maxAttempts: number; delayMs: number; errorMessage: string }
|
||||
| { type: "auto_retry_end"; success: boolean; attempt: number; finalError?: string };
|
||||
|
||||
|
|
@ -1544,13 +1550,17 @@ export class AgentSession {
|
|||
}, 100);
|
||||
}
|
||||
} catch (error) {
|
||||
this._emit({ type: "auto_compaction_end", result: undefined, aborted: false, willRetry: false });
|
||||
|
||||
if (reason === "overflow") {
|
||||
throw new Error(
|
||||
`Context overflow: ${error instanceof Error ? error.message : "compaction failed"}. Your input may be too large for the context window.`,
|
||||
);
|
||||
}
|
||||
const errorMessage = error instanceof Error ? error.message : "compaction failed";
|
||||
this._emit({
|
||||
type: "auto_compaction_end",
|
||||
result: undefined,
|
||||
aborted: false,
|
||||
willRetry: false,
|
||||
errorMessage:
|
||||
reason === "overflow"
|
||||
? `Context overflow recovery failed: ${errorMessage}`
|
||||
: `Auto-compaction failed: ${errorMessage}`,
|
||||
});
|
||||
} finally {
|
||||
this._autoCompactionAbortController = undefined;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1820,6 +1820,10 @@ export class InteractiveMode {
|
|||
timestamp: Date.now(),
|
||||
});
|
||||
this.footer.invalidate();
|
||||
} else if (event.errorMessage) {
|
||||
// Compaction failed (e.g., quota exceeded, API error)
|
||||
this.chatContainer.addChild(new Spacer(1));
|
||||
this.chatContainer.addChild(new Text(theme.fg("error", event.errorMessage), 1, 0));
|
||||
}
|
||||
void this.flushCompactionQueue({ willRetry: event.willRetry });
|
||||
this.ui.requestRender();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue