Skip to content

fix(server): rotate Claude on hard usage rejection - #126

Merged
tusharbhardwaj-bk merged 2 commits into
bkmainfrom
expbkmain
Aug 21, 2026
Merged

fix(server): rotate Claude on hard usage rejection#126
tusharbhardwaj-bk merged 2 commits into
bkmainfrom
expbkmain

Conversation

@bk-agent-01

@bk-agent-01 bk-agent-01 commented Aug 20, 2026

Copy link
Copy Markdown

Closes TEC-961

What Changed

  • Listen for authoritative Claude SDK rate_limit_event rejections with a supported hard-limit type.
  • Invoke the host claude-autoswitch --hard-limit <type> --json contract and recycle only the affected provider thread after a validated switch.
  • Debounce repeated evidence, preserve unrelated sessions, and leave sessions running on no-op or failure paths.
  • Document the 30-second fallback timer, immediate rejection flow, staging checks, and rollback.

Why

Claude can reject a request before its cached utilization reflects exhaustion. The fallback timer therefore cannot always rotate accounts promptly. This hook uses the typed provider rejection as authoritative evidence while keeping credential selection in the host-owned elector.

Staging Evidence

  • PR fix(server): rotate Claude on hard usage rejection #125 CI passed, including focused handler tests: 7/7.
  • Tests inject the real provider event and prove one election call, one affected-thread recycle, debounce, unrelated-session preservation, and safe no-op/failure handling.
  • Before the selector proof, default was elected at 34% five-hour usage, below the 85% trip threshold.
  • /home/ubuntu/.local/bin/claude-autoswitch --hard-limit five_hour --json exited 0 with status=switched, from=default, and to=agent.
  • Autoswitch state recorded last_hard_limit_type=five_hour and last_to=agent; the timer was restored active and enabled.
  • A fresh ExpBkT3 Claude probe started after election and replied exactly RECOVERED in 5.265 seconds with lastError=null, then stopped cleanly.
  • expbkmain deployment SHA is a12718bda83ddd28ab2fdcf4bd6dda59b1bb0b2d; staging service and HTTP checks passed.

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • UI screenshots are not applicable
  • Interaction video is not applicable

Generated with GPT-5.6-SOL in T3 Code.


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

@github-actions github-actions Bot added vouch:unvouched PR author is not yet trusted in the VOUCHED list. size:L labels Aug 20, 2026
@github-actions

Copy link
Copy Markdown

Thread transfer impact

✅ Thread transfer remains within every enforced ceiling.

ℹ️ No successful main baseline artifact is available yet. This run establishes the initial measurement.

Provider Metric Main baseline This PR Impact PR ceiling
Codex Total thread wire 11.4 KiB 15.1 KiB
Codex Thread snapshot wire 5.7 KiB 7.3 KiB
Codex Live turn WebSocket wire 5.7 KiB 7.8 KiB
Codex Live turn WebSocket decoded 50.3 KiB 66.4 KiB
Codex Live turn messages 9 21
Claude Total thread wire 11.4 KiB 15.1 KiB
Claude Thread snapshot wire 5.7 KiB 7.3 KiB
Claude Live turn WebSocket wire 5.7 KiB 7.8 KiB
Claude Live turn WebSocket decoded 51.2 KiB 66.4 KiB
Claude Live turn messages 10 21

Baseline: unavailable · PR result: a12718b · Source CI: success

Scenario and decoded snapshot size

10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.

  • Codex decoded thread snapshot: 95.6 KiB
  • Claude decoded thread snapshot: 96.3 KiB

Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.

@tusharbhardwaj-bk
tusharbhardwaj-bk merged commit e484e44 into bkmain Aug 21, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L vouch:unvouched PR author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants