Repository navigation
fix(server): read usage limits again after a usage limit in own mode - #313
Merged
Merged
Conversation
Upstream's ProviderEventIngestor has the instance read its limits again once it stored a turn terminal that failed on the usage limit. Own mode ingests in Rust and never did, so the limits kept the use from before the limit until the next provider check. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The fake Claude CLI answers the usage probe from a file and reports a rate_limit_event, and own_usage_limits times both changes to the config stream in own mode and upstream. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
The thread panel's usage limits updated much more slowly in tern than in T3 Code for the same work. Both clients only show what the server's config stream pushes; neither refreshes after a turn. The gap is in own mode's server:
rate_limit_event): the Claude adapter runs in the bridge and callssnapshot.applyUsageLimits, and the registry's change reachessubscribeServerConfig. This already matched upstream.ProviderEventIngestorhas the instance read its limits again (snapshot.refreshUsage) once it stored that terminal. Own mode ingests turns in Rust and never did, so the panel kept the use from before the limit until the next provider check, which runs only while a client reports activity and every 5 minutes (balanced profile).The client side of #128 still holds in own mode: activity reports reach upstream's
BackgroundPolicyin the bridge, and the panel's paced refresh and the refresh at a window's reset callserver.refreshProviderswithlimitsOnly, which the bridge answers with upstream's handler.What
crates/server-threads/src/turns/run.rs: once aturn.terminalthat failed with classusage_limitis stored, own mode tells the bridgeproviders.refreshUsagefor the run's instance.bridge/src/providers.ts,main.ts:providers.refreshUsageruns the instance'ssnapshot.refreshUsage, as upstream does.crates/server/tests/own_usage_limits.rs(new differential harness): the fake Claude CLI answersget_usagefrom a file and reports arate_limit_event(RATE <n>). The harness times each change from the CLI's report to the config stream in upstream and own mode, and compares the windows. Added toscripts/run-harnesses.sh's table.docs/server-orchestration.md: a bullet under "Providers in own mode".Delays, CLI report to
subscribeServerConfig(fake Claude CLI, debug build)rate_limit_eventduring a turnAbout 200 ms of each is the config stream's debounce, which matches upstream's
PROVIDER_STATUS_DEBOUNCE_MS.Checks
cargo fmt --all,cargo clippy --workspace --all-targets --locked -- -D warnings,cargo test --workspace --locked(scratch HOME,TERN_KEYCHAIN=off): pass.scripts/check-bridge.sh: pass.scripts/run-harnesses.sh own_background_work own_limit_stop own_usage_limits: all pass against upstream9677111.Timing only; the panel looks the same.
🤖 Generated with Claude Code