feat(FN-3302): restore Claude usage tracking with Fusion Anthropic auth sto

Restores Claude usage tracking across the dashboard by integrating with Fusion Anthropic auth storage, and adds detection and testing for the `model_context_window_exceeded` stop reason to handle context limit errors gracefully. The work spans planning logic, usage tracking, mission management UI, a

Fusion-Task-Id: FN-3302
This commit is contained in:
Fusion
2026-05-03 11:06:27 -07:00
committed by gsxdsm
parent dc3deed964
commit ec80d98d2a
2 changed files with 25 additions and 0 deletions

View File

@@ -88,6 +88,28 @@ describe("isContextLimitError", () => {
expect(isContextLimitError("Context Window Exceeds limit")).toBe(true); expect(isContextLimitError("Context Window Exceeds limit")).toBe(true);
}); });
// ── Anthropic model_context_window_exceeded stop_reason ──────────────
it("matches full pi-ai error 'Unhandled stop reason: model_context_window_exceeded'", () => {
expect(isContextLimitError("Unhandled stop reason: model_context_window_exceeded")).toBe(true);
});
it("matches standalone 'model_context_window_exceeded'", () => {
expect(isContextLimitError("model_context_window_exceeded")).toBe(true);
});
it("matches 'model_context_window_exceeded' case-insensitively", () => {
expect(isContextLimitError("Model_Context_Window_Exceeded")).toBe(true);
});
it("does NOT match 'model_context_window' without 'exceeded'", () => {
expect(isContextLimitError("model_context_window")).toBe(false);
});
it("does NOT match 'context_window' alone", () => {
expect(isContextLimitError("context_window")).toBe(false);
});
// ── Negative matches: must NOT trigger ───────────────────────────── // ── Negative matches: must NOT trigger ─────────────────────────────
it("returns false for empty string", () => { it("returns false for empty string", () => {

View File

@@ -42,6 +42,9 @@ const CONTEXT_OVERFLOW_PATTERNS: RegExp[] = [
// Provider JSON error envelope variant: "context window exceeds limit (2013)" // Provider JSON error envelope variant: "context window exceeds limit (2013)"
// Matches when "context window" and "exceeds" appear together (order-flexible) // Matches when "context window" and "exceeds" appear together (order-flexible)
/context\s+window\s+exceeds/i, /context\s+window\s+exceeds/i,
// Anthropic API stop_reason: model_context_window_exceeded
// Surfaces as "Unhandled stop reason: model_context_window_exceeded" from pi-ai's mapStopReason()
/model_context_window_exceeded/i,
]; ];
/** /**