Skip to content

fix(server): read usage limits again after a usage limit in own mode - #313

Merged
opficdev merged 2 commits into
mainfrom
fix/usage-limits-refresh-2
Dec 6, 2026
Merged

opficdev merged 2 commits into
mainfrom
fix/usage-limits-refresh-2

Conversation

@opficdev

@opficdev opficdev commented Dec 6, 2026

Copy link
Copy Markdown
Member

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:

  • During a turn (rate_limit_event): the Claude adapter runs in the bridge and calls snapshot.applyUsageLimits, and the registry's change reaches subscribeServerConfig. This already matched upstream.
  • After a turn fails on the usage limit: upstream's ProviderEventIngestor has 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 BackgroundPolicy in the bridge, and the panel's paced refresh and the refresh at a window's reset call server.refreshProviders with limitsOnly, which the bridge answers with upstream's handler.

What

  • crates/server-threads/src/turns/run.rs: once a turn.terminal that failed with class usage_limit is stored, own mode tells the bridge providers.refreshUsage for the run's instance.
  • bridge/src/providers.ts, main.ts: providers.refreshUsage runs the instance's snapshot.refreshUsage, as upstream does.
  • crates/server/tests/own_usage_limits.rs (new differential harness): the fake Claude CLI answers get_usage from a file and reports a rate_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 to scripts/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)

upstream own mode before own mode after
rate_limit_event during a turn 238 to 278 ms same path, unchanged 264 to 265 ms
turn failed on the usage limit 357 to 464 ms never within 60 s (next provider check: up to 5 min, only while a client is in use) 327 to 333 ms

About 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 upstream 9677111.

Timing only; the panel looks the same.

🤖 Generated with Claude Code

opficdev and others added 2 commits December 6, 2026 09:57
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>
@opficdev
opficdev enabled auto-merge (squash) December 6, 2026 00:58
@opficdev
opficdev merged commit 2cbf04e into main Dec 6, 2026
38 of 40 checks passed
@opficdev
opficdev deleted the fix/usage-limits-refresh-2 branch December 6, 2026 01:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant