The signatureThe body says Input token exceed the limit, but the normalized error code is INVALID_REQUEST.

Classification decides whether recovery runs.

Recognized pathCONTEXT_WINDOW_EXCEEDEDprune → compact → retry

The compaction listener receives its exact machine code.

Missed path in rc.7INVALID_REQUESTfail → manual recovery

The same physical overflow bypasses the listener.

Read the body, not only the provider code.

{
  "message": "Input token exceed the limit",
  "type": "api_error",
  "code": "quota_limit_reached"
}
Do not widen blindly.

quota_limit_reached can also describe account or monthly usage limits. Match the context wording narrowly and retain the raw response beside the normalized error.

Budget the next request before sending it.

history tokens+tool and system tokens+requested output<model context window

Recover in a bounded order.

  1. 01Capture

    Save the raw body, normalized code, model, adapter, and request ID.

  2. 02Lower output

    Reduce maxTokens only if the history still leaves usable headroom.

  3. 03Compact once

    Try /compact once. Stop if its summarizer also exceeds context.

  4. 04Continue cleanly

    Open a new Session with a concise handoff and links to retained evidence.

Regression needs a positive and a negative.

Must classifyInput token exceed the limitCONTEXT_WINDOW_EXCEEDED
Must not classifyMonthly usage quota exceededusage or account limit

Acceptance gates.

Primary evidence.

Keep the complete runbook.

The canonical guide includes capture fields, decision branches, source boundaries, and a minimal incident report.

Read and star on GitHub