Skip to content

perf(rate-limits): throttle statusline usage posts to one curl per pane per 15s - #9829

Merged
brennanb2025 merged 7 commits into
mainfrom
brennanb2025/fix-statusline-curl-throttle
Jul 22, 2026
Merged

brennanb2025 merged 7 commits into
mainfrom
brennanb2025/fix-statusline-curl-throttle

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Jul 22, 2026 •

Copy link
Copy Markdown
Contributor

What

The managed Claude statusline script now spawns at most one curl per 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_limits payload to the local hook server — but with no client-side floor, every tick spawned a fresh curl (plus findstr on 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):

  • POSIX: the normal path reads Claude's monotonic cost.total_duration_ms with shell builtins, so throttled ticks spawn no replacement clock process; date +%s remains a fail-open fallback if the payload schema drifts.
  • Windows: all-builtin seconds-of-day parse of %TIME% (1%%x %% 100 defuses cmd's leading-zero-octal parse) — no extra process for the check, and the guard sits before findstr so throttled ticks skip that spawn too.
  • Fail-open everywhere: unparseable date output, 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.
  • Interval is CLAUDE_STATUSLINE_MIN_POST_INTERVAL_SECONDS = 15 in 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 curl and date: old script = 30 curl spawns; new script = 1 curl + 0 clock spawns on the normal Claude payload.

Tests

  • Behavioral (real sh, stub curl/date on 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.
  • Content: throttle ordering on both platforms (Windows: check before findstr, stamp write after all guards, before curl), filename-safe stable leaf IDs, numeric-stamp validation, fail-open shapes, and octal-defuse arithmetic.
  • pnpm typecheck green; 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-in cmd parsing before the existing fully qualified system executables.

Reliability contract

  • Invariant (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.
  • Failure source: fix(rate-limits): unstick Claude "Limited" usage — respect Retry-After and feed live usage from session statuslines #9617 added a statusline transport on a Claude update path debounced near 300ms, multiplying curl/findstr subprocesses by active panes.
  • Oracle: real POSIX shell tests count one curl and 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 one curl.
  • Gate: accepted gap; config/reliability-gates.jsonc has no statusline-usage gate. The deterministic real-shell test is the change-local gate, and the manifest validator remains green.
  • Provider/platform coverage: local macOS/Linux behavior is executed with sh and syntax-checked with sh, dash, and bash; local Windows is content-asserted because this host has no cmd.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.
  • Performance budget: normal payload ticks use shell/batch builtins only until the allowed post; no polling, provider fanout, session inventory, renderer wake loop, or growing in-memory cache was added. Schema drift may use one date fallback per tick so delivery fails open.
  • Diagnostics: subprocess/stamp counts are deterministic test artifacts; existing rate-limit attribution breadcrumbs diagnose server-side drops without adding hot-path logging.
  • Residual gaps: Windows batch behavior is not executed locally. The throttle is event-driven and leading-edge: a changed payload suppressed near the end of a short interaction is delivered by the next Claude statusline event, not by a new background timer. Per-pane stamp files remain tiny OS-temp artifacts.

…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).
@coderabbitai

coderabbitai Bot commented Jul 22, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@brennanb2025, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 19 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 08f34af6-33ae-4c94-a315-c68ac0737a10

📥 Commits

Reviewing files that changed from the base of the PR and between 57b7391 and abc2932.

📒 Files selected for processing (1)
  • src/main/claude/statusline-script.test.ts
📝 Walkthrough

Walkthrough

Adds 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)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description covers the change well, but it does not follow the required template and is missing Summary/Screenshots/Testing/AI Review/Security Audit/Notes. Rewrite the PR description using the repository template, adding the missing sections and the required testing checklist, review summary, security audit, and notes.
Docstring Coverage ⚠️ Warning Docstring coverage is 16.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: throttling statusline usage posts to one curl per pane every 15 seconds.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 61025e3d-8ae4-4f65-bd00-b0a12a388841

📥 Commits

Reviewing files that changed from the base of the PR and between 4d0e3f5 and 9d3dbbe.

📒 Files selected for processing (3)
  • src/main/claude/statusline-script.test.ts
  • src/main/claude/statusline-script.ts
  • src/shared/claude-statusline-rate-limits.ts

Comment thread src/main/claude/statusline-script.ts Resolved
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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 475c0683-44ed-483c-9c4d-07dc988bab6d

📥 Commits

Reviewing files that changed from the base of the PR and between 6e0b616 and 57b7391.

📒 Files selected for processing (2)
  • src/main/claude/statusline-script.test.ts
  • src/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.
@brennanb2025
brennanb2025 merged commit 586cf78 into main Jul 22, 2026
1 check passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…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.
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