Repository navigation
Permalink
Choose a base ref
{{ refName }}
default
Choose a head ref
{{ refName }}
default
Comparing changes
Choose two branches to see what’s changed or to start a new pull request.
If you need to, you can also or
learn more about diff comparisons.
Open a pull request
Create a new pull request by comparing changes across two branches. If you need to, you can also .
Learn more about diff comparisons here.
base repository: headroomlabs-ai/headroom
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.39.0
Could not load branches
Nothing to show
Loading
Could not load tags
Nothing to show
{{ refName }}
default
Loading
...
head repository: headroomlabs-ai/headroom
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v0.39.1
Could not load branches
Nothing to show
Loading
Could not load tags
Nothing to show
{{ refName }}
default
Loading
- 2 commits
- 22 files changed
- 4 contributors
Commits on Sep 26, 2026
-
fix(proxy): stop the 0.39.0 TPM limiter from refusing large-context r…
…equests forever (#3806) ## Description #3350 (shipped in 0.39.0) started enforcing the token-per-minute bucket, which has two problems for large-context coding agents. 1. **A request larger than the bucket is refused forever.** The bucket never holds more than `rate_limit_tokens_per_minute` (`refilled_tokens` caps it there), so a request whose input is over the limit can never be admitted. The 429's `Retry-After` never comes true, and retrying, or `/compact`, which sends the same large conversation, hits the same 429 again. Once a Claude Code session passes 100k input tokens it is stuck until the proxy is restarted. 2. **The implicit 100k default is now enforced on every proxy.** Before #3350 the token bucket was never consumed, so no one ran into the default. Now a stock `headroom proxy` / `headroom wrap claude` is a 100k tokens/minute throttle, which a single 1M-context turn exceeds on its own. Users see `{"detail":"Token rate limited. Retry after 79.2s"}` straight after upgrading. Fixes: 1. `consume_from_bucket` admits an oversized request once the bucket is full, then charges it in full. The balance goes negative and later requests wait it off, so the configured average rate still holds. A request that fits in the bucket behaves exactly as before. 2. The token limit is opt-in again: `rate_limit_tokens_per_minute` defaults to `None` (no token limit). `--tpm` / `HEADROOM_TPM` still enforce one, which is what #3347 asked for. The request-per-minute limit (default 60) is unchanged. Follows up #3347 / #3350. ## Type of Change - [x] Bug fix (non-breaking change that fixes an issue) - [ ] New feature (non-breaking change that adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to change) - [ ] Documentation update - [ ] Performance improvement - [ ] Code refactoring (no functional changes) ## Changes Made - `rate_limit_policy.consume_from_bucket`: a request larger than the bucket's capacity waits only for a full bucket, then is admitted and charged in full. - `TokenBucketRateLimiter`: `tokens_per_minute=None` never limits and creates no token buckets. - `ProxyConfig.rate_limit_tokens_per_minute`, `headroom proxy --tpm` and the `python -m headroom.proxy.server --tpm` default to `None`. The startup banner prints `unlimited`, and the docs table says so too. - Tests: three policy cases (oversized admitted when full, waits only for a full bucket, debt delays the next request); the four handler integration tests now check that the first oversized request is admitted and charged, and that the second is refused before upstream; the limiter defaults to no token limit; the CLI default is `None`. ## Testing - [x] Unit tests pass (`pytest`) - [x] Linting passes (`ruff check .`) - [x] Type checking passes (`mypy headroom`) - [x] New tests added for new functionality - [x] Manual testing performed ### Test Output ```text $ uv run --frozen --extra dev pytest tests/test_rate_limit_policy.py tests/test_rate_limiter.py tests/test_proxy_tpm_enforcement.py tests/test_proxy_config_rate_limit.py tests/test_proxy_openai_rate_limit_key.py tests/test_codex_rate_limits.py tests/test_cli_proxy_env.py -q 139 passed, 1 skipped, 1 warning in 4.37s # The same new policy/integration tests on the 0.39.0 consume_from_bucket: $ uv run --frozen --extra dev pytest tests/test_rate_limit_policy.py tests/test_proxy_tpm_enforcement.py -q 6 failed, 6 passed, 1 warning in 2.56s $ uvx ruff check <changed files> All checks passed! $ uvx ruff format --check <changed files> 6 files already formatted $ uv run --frozen --extra dev mypy headroom/proxy/rate_limiter.py headroom/proxy/models.py headroom/cli/proxy.py headroom/proxy/server.py Success: no issues found in 4 source files ``` ## Real Behavior Proof - Environment: macOS 15 (Darwin 24.6.0), Python 3.12. Stock headroom-ai 0.39.0 wheel on port 18902, this branch on port 18901, both `headroom proxy --no-optimize` with default settings. - Exact command / steps: POSTed the same ~435k-input-token `/v1/messages` request (claude-haiku-4-5, invalid API key so the upstream answers 401 instead of running it) twice to each proxy, then repeated against this branch started with `--tpm 100000`. - Observed result: Stock 0.39.0: 429 `Token rate limited. Retry after 200.8s` on both tries, the second in 6 ms, and the same on every retry after that. This branch, default settings: 401 from Anthropic on both tries (forwarded, no token limit). This branch with `--tpm 100000`: the first try was forwarded (401 from Anthropic) and the second got 429 `Retry after 260.6s`, the wait for the 335k-token debt plus a full bucket. That wait now actually ends. - Not tested: A real paid 1M-context session against Anthropic (the upstream 401 is enough to prove the proxy forwarded the request); Gemini and OpenAI Responses live (covered by the handler integration tests only). ## Runtime Rollout Safety - Rollout-managed feature(s): None. - Minimum rollout channel: Stable. - Stable/default behavior changed: Yes. The default token-per-minute limit goes back to unlimited, as it effectively was before 0.39.0; an explicit `--tpm` / `HEADROOM_TPM` still enforces one. - Kill switch / disable path: Set `--tpm` / `HEADROOM_TPM` to restore a token limit; `--no-rate-limit` disables rate limiting entirely. - Unsafe override required: No. - Qualification impact: None. - Rollback path: Revert this PR. ## Review Readiness - [x] I have performed a self-review - [x] This PR is ready for human review ## Checklist - [x] My code follows the project's style guidelines - [x] I have performed a self-review of my code - [x] I have commented my code, particularly in hard-to-understand areas - [x] I have made corresponding changes to the documentation - [x] My changes generate no new warnings - [x] I have added tests that prove my fix is effective or that my feature works - [x] New and existing unit tests pass locally with my changes - [x] I did **not** edit `CHANGELOG.md` — it is generated by release-please from my Conventional Commit PR title (a CI guard enforces this) ## Screenshots (if applicable) N/A ## Additional Notes The two commits can be taken separately. The first alone fixes the permanent 429 for anyone who sets `--tpm`. The second restores the pre-0.39.0 default. Headroom Desktop is working around this for now by launching the proxy with `--no-rate-limit`. --------- Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
Configuration menu - View commit details
-
Copy full SHA for 7968122 - Browse repository at this point
Copy the full SHA 7968122View commit details -
🤖 I have created a release *beep* *boop* --- ## [0.39.1](v0.39.0...v0.39.1) (2026-09-26) ### Bug Fixes * **proxy:** stop the 0.39.0 TPM limiter from refusing large-context requests forever ([#3806](#3806)) ([7968122](7968122)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Configuration menu - View commit details
-
Copy full SHA for d13e196 - Browse repository at this point
Copy the full SHA d13e196View commit details
Loading
This comparison is taking too long to generate.
Unfortunately it looks like we can’t render this comparison for you right now. It might be too big, or there might be something weird with your repository.
You can try running this command locally to see the comparison on your machine:
git diff v0.39.0...v0.39.1