Repository navigation
perf(rate-limits): throttle statusline usage posts to one curl per pane per 15s - #9829
Conversation
…ne per 15s The managed Claude statusline script posted on every statusLine tick carrying rate_limits — ~3 curl spawns/sec per streaming pane, multiplied across concurrent panes. The service drops same-value posts inside its 30s dedupe window anyway, so most spawns bought nothing. Gate the post on a per-pane stamp file: POSIX compares date +%s against the stamp; Windows uses an all-builtin seconds-of-day parse of %TIME% (octal-safe, no extra process). Both fail open — unparseable time, garbage stamp, or midnight wrap posts rather than darkening the live usage feed — and the stamp only advances when a post actually fires, so skipped ticks never defer the next one. Measured: 30 rapid rate-limit ticks spawn 1 curl (was 30).
|
Warning Review limit reached
Next review available in: 19 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughAdds a shared 15-second minimum post interval for Claude statusline updates. Windows scripts now use pane-specific payload and stamp files with elapsed-time checks. POSIX scripts derive stable pane and tab identifiers, use payload duration or clock time, and gate curl posts based on the previous stamp. Tests cover Windows control flow and POSIX execution, fallback behavior, filename isolation, repeated ticks, and payloads without rate limits. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Use Claude's monotonic session duration for the POSIX throttle so skipped ticks do not replace curl churn with date churn, while retaining a fail-open date fallback. Key temp files by the stable leaf UUID so path-like or long host tab IDs cannot disable the throttle.
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 61025e3d-8ae4-4f65-bd00-b0a12a388841
📒 Files selected for processing (3)
src/main/claude/statusline-script.test.tssrc/main/claude/statusline-script.tssrc/shared/claude-statusline-rate-limits.ts
…usline-curl-throttle
All-digits validation still admitted values like 008, which are invalid octal inside $(( )) — and dash treats that expansion error as fatal, so the script died before rewriting the stamp and the pane's live usage feed stayed dark until the file was deleted. Allow-list canonical decimals (same pattern as the duration parse) on both the stamp and the computed clock so malformed values fail open to posting. Verified under dash: the old digits-only check aborts at the arithmetic (Illegal number: 008); the allow-list survives and posts.
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 475c0683-44ed-483c-9c4d-07dc988bab6d
📒 Files selected for processing (2)
src/main/claude/statusline-script.test.tssrc/main/claude/statusline-script.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- src/main/claude/statusline-script.ts
The stamp check/write is deliberately lock-free (a lock could wedge the feed closed; fail-open is the contract), so a truly concurrent burst may post more than once, bounded by overlap width — an exact at-most-one assertion would be flaky by design. Assert the invariants that do hold: every overlapping run exits 0, the raced stamp lands valid, and it throttles the following ticks.
…ne per 15s (stablyai#9829) * perf(rate-limits): throttle statusline usage posts to one curl per pane per 15s The managed Claude statusline script posted on every statusLine tick carrying rate_limits — ~3 curl spawns/sec per streaming pane, multiplied across concurrent panes. The service drops same-value posts inside its 30s dedupe window anyway, so most spawns bought nothing. Gate the post on a per-pane stamp file: POSIX compares date +%s against the stamp; Windows uses an all-builtin seconds-of-day parse of %TIME% (octal-safe, no extra process). Both fail open — unparseable time, garbage stamp, or midnight wrap posts rather than darkening the live usage feed — and the stamp only advances when a post actually fires, so skipped ticks never defer the next one. Measured: 30 rapid rate-limit ticks spawn 1 curl (was 30). * perf(rate-limits): keep throttled statusline ticks process-free Use Claude's monotonic session duration for the POSIX throttle so skipped ticks do not replace curl churn with date churn, while retaining a fail-open date fallback. Key temp files by the stable leaf UUID so path-like or long host tab IDs cannot disable the throttle. * fix(rate-limits): preserve throttle isolation across upgrades * fix(rate-limits): reject leading-zero stamp values before arithmetic All-digits validation still admitted values like 008, which are invalid octal inside $(( )) — and dash treats that expansion error as fatal, so the script died before rewriting the stamp and the pane's live usage feed stayed dark until the file was deleted. Allow-list canonical decimals (same pattern as the duration parse) on both the stamp and the computed clock so malformed values fail open to posting. Verified under dash: the old digits-only check aborts at the arithmetic (Illegal number: 008); the allow-list survives and posts. * perf(rate-limits): eliminate POSIX statusline cat churn * test(rate-limits): exercise overlapping statusline ticks The stamp check/write is deliberately lock-free (a lock could wedge the feed closed; fail-open is the contract), so a truly concurrent burst may post more than once, bounded by overlap width — an exact at-most-one assertion would be flaky by design. Assert the invariants that do hold: every overlapping run exits 0, the raced stamp lands valid, and it throttles the following ticks.
What
The managed Claude statusline script now spawns at most one
curlper pane per 15 seconds instead of one per statusline tick (~3/sec per streaming pane, × concurrent panes).Why
#9617 wired live usage by POSTing the statusline's
rate_limitspayload to the local hook server — but with no client-side floor, every tick spawned a freshcurl(plusfindstron Windows). A 10-pane orchestration burned ~30 process spawns/sec for the duration of streaming. The service already drops same-value posts inside its 30s dedupe window (LIVE_CLAUDE_INGEST_DEDUPE_MS), so most of those spawns bought nothing. Flagged as a P2 in the v1.4.150-rc.0 release audit; matches the perf skill's "subprocess churn" anti-pattern (process count multiplied on a timer).How
Per-pane stamp file keyed by the filename-safe stable leaf UUID (or the legacy tab + numeric pane identity for PTYs surviving an upgrade), checked before the spawn and written only when a post actually fires (skipped ticks never defer the next post):
cost.total_duration_mswith shell builtins, so throttled ticks spawn no replacement clock process;date +%sremains a fail-open fallback if the payload schema drifts.%TIME%(1%%x %% 100defuses cmd's leading-zero-octal parse) — no extra process for the check, and the guard sits beforefindstrso throttled ticks skip that spawn too.dateoutput, garbage stamp content, unreadable file, or midnight wrap all post rather than throttle — a broken throttle can only cost spawns, never silently dark the live usage feed.CLAUDE_STATUSLINE_MIN_POST_INTERVAL_SECONDS = 15in the shared contract file, deliberately under the server's 30s same-value dedupe, so active streams refresh at least every 15s; if an interaction ends entirely inside the floor, its final value arrives on the next Claude statusline event.Measurement
30 rapid rate-limit ticks against stubbed
curlanddate: old script = 30 curl spawns; new script = 1 curl + 0 clock spawns on the normal Claude payload.Tests
sh, stubcurl/dateon PATH, skipped on win32): 30 rapid ticks produce one curl and zero clock spawns; posts again after the interval; schema-drift payloads use the clock fallback; garbage stamps fail open even early in a session; path-like/overlong tab IDs still throttle; legacy numeric panes remain isolated across tabs; non-rate-limit payloads touch neither subprocess nor stamp.pnpm typecheckgreen; focused statusline/hook/rate-limit suites green under Node 24 (106 passed, 3 platform skips).Residual
Windows batch behavior remains content-asserted rather than executed locally because this environment has no
cmd.exe; the implementation uses only built-incmdparsing before the existing fully qualified system executables.Reliability contract
statusline-usage.delivery-and-process-budget): each local pane may start at most one usage post per floor while valid clocks advance; malformed clocks/stamps must fail open, and one pane must never throttle another.curl/findstrsubprocesses by active panes.curland zero clock subprocesses across 30 rapid ticks, prove interval recovery/schema fallback/guard ordering, and isolate current UUID plus pre-migration numeric pane identities. Twenty additional 30-way concurrent stress rounds each produced exactly onecurl.config/reliability-gates.jsonchas no statusline-usage gate. The deterministic real-shell test is the change-local gate, and the manifest validator remains green.shand syntax-checked withsh,dash, andbash; local Windows is content-asserted because this host has nocmd.exe. SSH/WSL remote installs do not install this statusline route and are unaffected; daemon-backed local panes use the same script and identity contract.datefallback per tick so delivery fails open.