Commit Graph
3 Commits
Author SHA1 Message Date
陈大猫 42c69902e8 fix(ai): strip Anthropic signed thinking when context prefix mutates (#4073) (#4074)
* fix(ai): strip Anthropic signed thinking when context prefix mutates (#4073)

Anthropic preserved-thinking signatures bind to the exact conversation
prefix. Step compression/prune and durable summary keep-tail were
replaying later signed blocks after mutating earlier tool_results,
causing stable 400 Invalid signature errors on long tool chats.

Strip signed reasoning when prepareStep didAdjust, skip signatures on
durable-summary tails, and one-shot retry after matching 400.

* fix(ai): propagate Anthropic signature stream errors with progress-aware retry (#4074)

P1-1: rethrow signature failures from cattyStreamProcessor error chunks
(and reader catch) via createCattyAnthropicSignatureRetryError so the
turn-driver strip-and-retry path can see them.

P1-2: mirror the 413 hadToolProgress path on signature retry — rebuild
from latest session, retain completed tool results, new assistant
message, and enable write replay before stripping/retrying.

* fix(ai): preserve plain-object Anthropic signature messages in retry wrapper (#4074)

* fix(ai): only strip Anthropic signed thinking when provider allows removal (#4074)

DeepSeek Anthropic-compat requires thinking blocks with replayed tool calls;
gate durable-summary and prepareStep strips behind providerAllowsAnthropicSignedThinkingRemoval. Keep 400 invalid-signature strip-and-retry unchanged.

* chore: retrigger CI after runner shutdown cancel on lint-and-test (#4074)
2026-10-30 21:36:19 -07:00
陈大猫andCursor 2a10a28cc8 fix(ai): cap Catty agent request payload to prevent HTTP 413 (#1323) (#1324)
* fix(ai): cap Catty agent request payload to prevent HTTP 413

Long-running chats accumulated full terminal tool outputs in SDK history
while token-based compaction only triggered near the model context window,
so nginx gateways could reject oversized JSON bodies before the model saw them.

Add a byte-budget pass that compresses verbose output, tail-preserving
truncation, and a safe sliding window before each Catty agent turn.

Fixes #1323

Co-authored-by: Cursor <cursoragent@cursor.com>

* fix(ai): compaction was using unfiltered sdkMessages, fix didAdjust and emergency loop

* fix(ai): compact and retry oversized Catty requests

* fix(ai): preserve current input while guarding 413 retries

* fix(ai): avoid false 413 detection and fit oversized current input

* fix(ai): pair replayed tool results chronologically

---------

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-09 11:51:03 +08:00
陈大猫andClaude Opus 4.7 30f5346035 Classify AI proxy / size-limit errors instead of showing raw Zod output (#765) (#768)
Symptom: when an AI request is proxied through nginx (or any gateway)
and the request body exceeds client_max_body_size, the proxy returns a
413 HTML error page. The Vercel AI SDK then fails to parse the HTML
as a chat completion and surfaces a cryptic Zod validation error like
"Expected 'id' to be a string." through the UI — users have no idea
what's wrong.

Root cause: classifyError only did light sanitization and returned the
raw SDK message. It also string-coerced the error before inspection, so
the structured statusCode / responseBody fields that APICallError
attaches were thrown away.

Fix: classifyError now accepts `unknown` and inspects the full error
shape. Adds explicit branches for:

- HTTP 413 (from statusCode, cause.statusCode, or message text) →
  "Request too large — exceeded proxy size limit. Try shorter
  message, fewer attachments, or raise client_max_body_size."
- HTTP 502/503/504 → retryable upstream-gateway message
- HTML response body (starts with <!DOCTYPE/<html> or contains such
  tags anywhere) → "Server returned HTML error page, likely a proxy
  intercept."
- Zod/schema parse shapes ("Expected 'X' to be …", "Invalid JSON
  response", "Type validation failed") → "Response could not be
  parsed; proxy may have replaced/truncated the body."

In every classified case the raw SDK text is still appended ("Raw: …")
so users can report the underlying error verbatim.

useAIChatStreaming.ts callers now pass the raw error to classifyError
instead of `.message`, so the new structured branches actually fire.
Also wired infrastructure/ai/*.test.ts into the npm test glob.

Closes #765

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-18 22:50:25 +08:00