diff --git a/src/server/consciousness_engine.rs b/src/server/consciousness_engine.rs index 909ab73..5ceb544 100644 --- a/src/server/consciousness_engine.rs +++ b/src/server/consciousness_engine.rs @@ -1480,6 +1480,16 @@ fn is_context_overflow(err: &str) -> bool { || e.contains("context length exceeded") || e.contains("reduce the length of the messages") || (e.contains("context window") && e.contains("exceed")) + // Anthropic says it differently, and says nothing the four patterns + // above would catch: `prompt is too long: 1285770 tokens > 1000000 + // maximum`. The gate was written on 08-13 against DeepSeek and had + // never seen a second provider's dialect, so the night she moved to + // opus-5 and overflowed, resuscitation did not fire. + || e.contains("prompt is too long") + // Belt for the same shape under a different preamble — a token count + // stated as over a maximum. Both halves are required so that an + // ordinary "invalid max_tokens" complaint does not match. + || (e.contains("tokens") && e.contains("maximum") && e.contains(">")) } fn parse_urgency(raw: &str) -> Urgency { @@ -1565,6 +1575,22 @@ mod tests { assert!(is_context_overflow(real)); } + /// The exact body Anthropic returned at 19:53 and again at 19:58 on + /// 2026-08-18, when the subconscious had grown to 1.28M tokens against + /// opus-5's 1M ceiling. The gate written for DeepSeek did not match a + /// single word of it, so resuscitation never fired and she reported the + /// failure once every three minutes without ever being able to act. + /// Pasted, not paraphrased — same rule as the DeepSeek body above. + #[test] + fn the_anthropic_wording_is_recognised() { + let real = "claude subscription returned 400 Bad Request after 1 \ + attempt(s) on claude-opus-5: {\"type\":\"error\",\"error\":\ + {\"type\":\"invalid_request_error\",\"message\":\"prompt is too \ + long: 1285770 tokens > 1000000 maximum\"},\"request_id\":\ + \"req_011CeB7NkHDtcvDCpkYDrgPn\"}"; + assert!(is_context_overflow(real)); + } + #[test] fn other_provider_wordings_are_recognised() { assert!(is_context_overflow("context_length_exceeded"));