Skip to content

Claude SDK ambient 429 result with success subtype bypasses model fallback #1169

Description

@jezFAM

What happened?

A Claude subscription/session-limit response can bypass retry.fallbackChains when claude-sdk-oauth uses tokenInjection: "ambient". This is distinct from #505: Claude Agent SDK 0.3.241 returned a result with a successful subtype but an explicit error flag:

{
  "type": "result",
  "subtype": "success",
  "is_error": true,
  "api_error_status": 429,
  "terminal_reason": "api_error",
  "result": "You've hit your session limit · resets 2:50pm (Asia/Seoul)"
}

Senpi treats the turn as successful, so the retry/fallback controller receives no provider error and emits no fallback_applied event. This breaks Claude-primary setups that depend on another provider after the 5-hour limit.

On current main (488d672), sdkFailure() only checks result messages when message.subtype !== "success", while the ambient branch directly yield*s createAttemptMessages(...) without calling sdkFailure().

A local patch that also checks message.is_error === true, preserves message.result for classification, and inspects ambient messages produced FALLBACK_QA_OK plus fallback_applied: claude-sdk-oauth/claude-opus-5 -> openai-codex/gpt-5.6-sol-fast (reason: transient).

Steps to reproduce

  1. Configure claude-sdk-oauth with tokenInjection: "ambient" and a fallback chain from claude-opus-5 to another provider.
  2. Exhaust the Claude CLI 5-hour/session limit.
  3. Run an isolated print turn:
senpi -ne --model claude-sdk-oauth/claude-opus-5:max -p --no-session --no-tools --no-skills --no-context-files "Return exactly FALLBACK_QA_OK"
  1. Observe the limit text is surfaced without switching models and no fallback_applied event appears.

Expected behavior

is_error: true should enter retry/fallback classification even when subtype is success, and the configured fallback model should serve the turn. A regression should cover both this contradictory error result and a normal subtype: success, is_error: false pass-through.

Version

Senpi 2026.8.27; @anthropic-ai/claude-agent-sdk 0.3.241; Windows 11; ambient auth lane

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions