Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix: recognize Claude Code's standalone session-limit banner as a usage limit
Stephen Hilderbrand84bbd4e41444
diff --git a/server/lib/aiToolkit/errorDetection.js b/server/lib/aiToolkit/errorDetection.jsindex c737c1b292..c993ce738c 100644--- a/server/lib/aiToolkit/errorDetection.js+++ b/server/lib/aiToolkit/errorDetection.js@@ -135,16 +135,33 @@ const ERROR_PATTERNS = [{// `upgrade your subscription to increase your limits` is Antigravity's// quota banner (see AGY_QUOTA_BANNER). Claude Code reports its rolling- // subscription exhaustion as `You've hit your monthly spend limit ...- // your session limit resets ...`, which is a usage limit too even though it- // does not contain the older `usage limit` wording. The existing- // usage-limit category is also used by the immediate-fallback signals; the- // CLI path needs this post-hoc match to bench the provider and reach a- // fallback rather than falling through to UNKNOWN. Kept to vendor/billing- // phrasing — a bare- // "quota reached" is a phrase story text can legitimately contain, and- // this scan reads the model's entire screen.- pattern: /(?:hit your usage limit|hit your (?:monthly )?spend limit|your session limit resets?|usage limit|Upgrade to Pro|upgrade your subscription to increase your limits|(?:^|\n)\s*(?:\[stderr\]\s*)?Now using extra usage\s*(?:\r?\n|$))/i,+ // subscription exhaustion as a `You've hit your <kind> limit` banner, which+ // is a usage limit too even though it does not contain the older+ // `usage limit` wording. The existing usage-limit category is also used by+ // the immediate-fallback signals; the CLI path needs this post-hoc match to+ // bench the provider and reach a fallback rather than falling through to+ // UNKNOWN. Kept to vendor/billing phrasing — a bare "quota reached" is a+ // phrase story text can legitimately contain, and this scan reads the+ // model's entire screen.+ //+ // `hit your (<word> ){1,2}limit` is ONE alternative covering the whole+ // banner family rather than an enumeration of limit kinds, because the kind+ // and the separator both vary and an enumeration kept missing live wordings.+ // At least one kind word is REQUIRED: every real banner names the kind+ // (`session`, `usage`, `weekly`, `5-hour`, `monthly spend`, `Opus usage`),+ // while a bare `hit your limit` is reachable by ordinary prose — "he had+ // hit your limit of patience" matched when the kind was optional.+ // The earlier `your session limit resets?` required `limit` to be adjacent+ // to `resets`, which only holds for the LONG combined banner+ // (`... monthly spend limit · ... · your session limit resets 7:15am (UTC)`).+ // Claude Code's standalone short form puts a `·` between them —+ // `You've hit your session limit · resets 12:40am (UTC)` — so it fell+ // through to UNKNOWN, which benched nothing and escalated a spent+ // subscription to a tier-4 investigation task instead of a fallback. The+ // `5-hour`/`weekly`/`Opus` kinds the CLI also emits were missing for the+ // same reason. Anchored on the second-person `hit your … limit` so the+ // bound wildcard cannot be reached by prose about a limit.+ pattern: /(?:hit your (?:[\w-]+ ){1,2}limit\b|usage limit|Upgrade to Pro|upgrade your subscription to increase your limits|(?:^|\n)\s*(?:\[stderr\]\s*)?Now using extra usage\s*(?:\r?\n|$))/i,category: ERROR_CATEGORIES.USAGE_LIMIT,requiresFallback: true,actionable: true,@@ -236,7 +253,18 @@ const ERROR_PATTERNS = [];const WAIT_TIME_PATTERNS = [- /resets?\s+(\d{1,2}(?:am|pm)?)\s*\(([^)]+)\)/i,+ // A reset CLOCK time, not a duration: `resets 12:40am (UTC)`. The minutes are+ // optional (`resets 3pm`) and so is the parenthesized zone — Claude Code emits+ // the bare form too (`resets 6:00 PM`), and requiring both meant the most+ // common wording, `H:MM<meridiem>`, extracted no wait time at all because+ // `\d{1,2}` stopped at the `:`.+ //+ // A meridiem or an `H:MM` is REQUIRED, so the hour cannot be a bare integer:+ // with the zone parens optional, a lone `\d{1,2}` would claim the number out+ // of a DURATION phrased off `resets` (`resets 5 minutes from now` → `5`),+ // which the general duration scan below reads correctly as `5 minutes`.+ // `resets in 3h51m14s` has no digit after `resets` and falls through either way.+ /resets?\s+(\d{1,2}(?::\d{2})?\s*(?:am|pm)|\d{1,2}:\d{2})\s*(?:\(([^)]+)\))?/i,/try again in\s+((?:\d+\s*(?:day|hour|minute|second)s?\s*)+)/i,/wait\s+((?:\d+\s*(?:day|hour|minute|second)s?\s*)+)/i,/in\s+(\d+)\s*(day|hour|minute|second)s?/i,diff --git a/server/lib/aiToolkit/errorDetection.test.js b/server/lib/aiToolkit/errorDetection.test.jsindex d080ffc55f..13b569d0df 100644--- a/server/lib/aiToolkit/errorDetection.test.js+++ b/server/lib/aiToolkit/errorDetection.test.js@@ -119,6 +119,35 @@ describe('Error Detection', () => {expect(result.requiresFallback).toBe(true);});+ // The STANDALONE short banner, which separates the limit from its reset+ // with a `·` instead of running them together as the long combined banner+ // above does. The pattern used to require `session limit resets` adjacent,+ // so a spent subscription reported this way classified as UNKNOWN: nothing+ // benched the provider, no fallback ran, and the run was escalated to a+ // tier-4 investigation task. The `5-hour` / `weekly` / `Opus` kinds the CLI+ // also emits were missed for the same reason.+ it.each([+ ['a session limit with a separated reset clock', "You've hit your session limit · resets 12:40am (UTC)"],+ ['a session limit with no timezone', "You've hit your session limit · resets 6:00 PM"],+ ['a rolling 5-hour limit', "You've hit your 5-hour limit · resets 3pm"],+ ['a weekly limit', "You've hit your weekly limit · resets Monday"],+ ['a per-model limit', "You've hit your Opus usage limit · /model to use best available model"],+ ])('classifies %s as a usage limit requiring fallback', (_label, text) => {+ const result = analyzeError(text, 1);+ expect(result.hasError).toBe(true);+ expect(result.category).toBe(ERROR_CATEGORIES.USAGE_LIMIT);+ expect(result.requiresFallback).toBe(true);+ });++ // The limit KIND is required, not optional. `analyzeError` reads an agent's+ // whole CLI screen, where a bare "hit your limit" is ordinary prose.+ it.each([+ ['prose about reaching a personal limit', 'He had hit your limit of patience, the narrator wrote.'],+ ['prose naming an unrelated limit', 'The hero hit your father with a limit break attack'],+ ])('does not classify %s as a usage limit', (_label, text) => {+ expect(analyzeError(text, 1).category).not.toBe(ERROR_CATEGORIES.USAGE_LIMIT);+ });+it('should detect Claude extra-usage status as a usage limit', () => {const result = analyzeError('Now using extra usage');expect(result.hasError).toBe(true);@@ -830,6 +859,29 @@ describe('Error Detection', () => {expect(result).toMatch(/5\s*min/i);});+ // A reset CLOCK time rather than a duration. `H:MM<meridiem>` is the+ // wording Claude Code actually emits and it extracted nothing, because the+ // hour matcher stopped at the `:` and the timezone parens were mandatory —+ // so a benched provider carried no reset time for the caller to wait out.+ it.each([+ ['a clock time with a timezone', 'resets 12:40am (UTC)', '12:40am UTC'],+ ['a clock time with no timezone', 'resets 6:00 PM', '6:00 PM'],+ ['a whole-hour reset', 'resets 3pm', '3pm'],+ ['a 24-hour clock reset', 'resets 18:30', '18:30'],+ ])('extracts %s', (_label, text, expected) => {+ expect(extractWaitTime(text)).toBe(expected);+ });++ // A DURATION phrased off `resets` is not a clock time. The clock pattern+ // requires a meridiem or an `H:MM`, so a lone hour cannot swallow the+ // number and leave the unit behind ("resets 5 minutes from now" → "5").+ it.each([+ ['minutes', 'Rate limit resets 5 minutes from now', '5 minutes'],+ ['hours', 'limit resets 3 hours from now', '3 hours'],+ ])('reads a duration in %s off "resets" as a duration, not a clock time', (_label, text, expected) => {+ expect(extractWaitTime(text)).toBe(expected);+ });+it('should return null for no time found', () => {const result = extractWaitTime('No time information here');expect(result).toBeNull();