Skip to content

Honor serve refresh interval - #398

Merged
tsouth89 merged 3 commits into
mainfrom
fix/issue-273
Aug 23, 2026
Merged

Honor serve refresh interval#398
tsouth89 merged 3 commits into
mainfrom
fix/issue-273

Conversation

@tsouth89

@tsouth89 tsouth89 commented Aug 23, 2026

Copy link
Copy Markdown
Owner

Fixes #273.

Caches successful usage and cost responses for the configured TTL, with separate route and provider keys. A zero interval disables caching, and provider failures are not cached. Includes deterministic cache tests and CLI documentation.


Note

Medium Risk
Changes local serve API freshness: clients can receive stale usage/cost for up to the TTL, and failed provider fetches are no longer cached. Loopback-only, no auth or credential changes.

Overview
codexbar serve --refresh-interval now actually caches responses (it was previously unused). Successful /usage and /cost bodies are stored in memory for that TTL, keyed separately by route and provider query.

/usage is cached only when every provider fetch succeeds; /cost only on HTTP 200. Failures are retried on the next request. --refresh-interval 0 disables the cache.

Clients polling within the TTL may see stale numbers. Docs and changelog updated for #273.

Reviewed by Cursor Bugbot for commit 29cf7b1. Bugbot is set up for automated code reviews on this repo. Configure here.

Note

Cache /usage and /cost responses in serve based on --refresh-interval

  • The serve --refresh-interval flag now sets the TTL for an in-memory cache of successful /usage and /cost HTTP responses, stored per route and per provider selection
  • ResponseCache in serve.rs skips reads and writes when TTL is zero; /usage responses containing any provider error are not cached, and /cost caches only 200 responses
  • On cache miss or expiry, responses are computed fresh and reinserted
  • Risk: route_request now holds a Mutex<HashMap> lock on every /usage and /cost request; contended access under high concurrency could add latency

Macroscope summarized 29cf7b1.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Aug 23, 2026

Copy link
Copy Markdown
Contributor

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
ceiling 29cf7b1 Commit Preview URL

Branch Preview URL
Aug 23 2026, 06:48 PM

@coderabbitai

coderabbitai Bot commented Aug 23, 2026

Copy link
Copy Markdown

Warning

Review limit reached

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

Next review available in: 20 minutes

Limit details: You’ve used the included review currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

Wait for the limit to reset, then comment @coderabbitai review or push new commits to the PR.

An organization admin can change what happens after included review limits in Billing.

How do review limits work?

CodeRabbit enforces per-developer PR review limits within each organization.

For paid Pro and Pro+ reviews, CodeRabbit uses a developer's included PR review attempts over the past 7 days to set the current hourly allowance. At typical activity levels, the full plan allowance applies. Higher sustained activity can lower the allowance until earlier attempts leave the 7-day window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: c73302d1-091e-4d16-a14f-f3a28453ed21

📥 Commits

Reviewing files that changed from the base of the PR and between 305265f and 29cf7b1.

📒 Files selected for processing (3)
  • CHANGELOG.md
  • docs/CLI.md
  • rust/src/cli/serve.rs

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.

@cursor

cursor Bot commented Aug 23, 2026

Copy link
Copy Markdown

Bugbot couldn't run - usage limit reached

Bugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit.

A user or team admin can review and increase usage limits in the Cursor dashboard.

(requestId: serverGenReqId_718ef1a8-a851-4017-86fe-f279e8c3714f)

@cursor

cursor Bot commented Aug 23, 2026

Copy link
Copy Markdown

Bugbot couldn't run - usage limit reached

Bugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit.

A user or team admin can review and increase usage limits in the Cursor dashboard.

(requestId: serverGenReqId_4da60165-c065-46f7-a812-51246aca3fad)

@cursor

cursor Bot commented Aug 23, 2026

Copy link
Copy Markdown

Bugbot couldn't run - usage limit reached

Bugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit.

A user or team admin can review and increase usage limits in the Cursor dashboard.

(requestId: serverGenReqId_752bc31c-1fa2-4212-be5c-e08e3f1d04eb)

@tsouth89
tsouth89 enabled auto-merge (squash) August 23, 2026 18:51
@tsouth89
tsouth89 merged commit fc8bca1 into main Aug 23, 2026
13 of 14 checks passed
@tsouth89
tsouth89 deleted the fix/issue-273 branch August 23, 2026 18:52
tsouth89 pushed a commit that referenced this pull request Aug 27, 2026
Closes #83.

Extends the `## serve` section of `docs/CLI.md` with a `### HTTP
endpoints` subsection, per your comment on the issue — no separate
`docs/SERVE.md`, and nothing else in the section touched.

What it documents:

- The three routes (`GET /health`, `GET /usage`, `GET /cost`) and the
`provider` query param, including `both` / `all` and the default of
querying the providers enabled in Settings when the param is omitted.
- The full error surface as a table: `400`, `401` (bearer token on
`/usage` and `/cost`, `/health` exempt), `403` (non-local `Host`),
`404`, `405`, `409` (`no_enabled_providers`), `503` (connection cap).
- Array response semantics: one object per requested provider,
per-provider fetch errors reported inside the entry with the HTTP status
still `200`, and error text normalized to `"provider request failed"`
without `--include-identity`.
- `/cost` scope: Claude, Codex, and Grok; `"supported": false` for the
rest; fixed 30-day window (the `cost` subcommand's `--days` flag does
not apply).
- The local-only posture: the `127.0.0.1` bind plus the `Host`-header
check, and that every route is read-only.
- Three `curl` examples with sample JSON shapes, reusing the `$TOKEN`
from the existing example above rather than repeating the token setup.

One note: your heads-up about the `--refresh-interval` prose resolved
itself while this was in flight — #398 wired the cache up, so the
section is written against current behavior (post-#398/#325, v1.5.36)
and doesn't touch the flag descriptions.

How verified (docs-only change, so verification was against the running
server):

```
cargo build --manifest-path rust/Cargo.toml -p codexbar
target/debug/codexbar serve --port 8124
```

Then curl-checked every documented behavior against the built 1.5.36
binary: `/health` unauthenticated (response matches the docs example
verbatim), `401` for both a missing and a wrong bearer token, `400` on
an unknown provider, `403` via a forged `Host: example.com`, `404`,
`405`, `/cost?provider=claude` matching the documented shape and key
order, and `/cost?provider=grok` returning `"supported": true`.


<!-- Macroscope's pull request summary starts here -->
<!-- Macroscope will only edit the content between these invisible
markers, and the markers themselves will not be visible in the GitHub
rendered markdown. -->
<!-- If you delete either of the start / end markers from your PR's
description, Macroscope will append its summary at the bottom of the
description. -->
> [!NOTE]
> ### Add HTTP endpoints section to `docs/CLI.md`
> Documents the serve HTTP API: routes (`GET /health`, `GET /usage`,
`GET /cost`), the `provider` query parameter, and response shapes
including per-provider error reporting. Also covers the 30-day scan
window limit, supported providers for `/cost`, the standardized JSON
error format with status-specific conditions (400, 401, 403, 404, 405,
409, 503), and example curl invocations.
>
> <!-- Macroscope's review summary starts here -->
>
> <sup><a href="https://app.macroscope.com">Macroscope</a> summarized
8337efa.</sup>
> <!-- Macroscope's review summary ends here -->
>
<!-- Macroscope's pull request summary ends here -->

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **Documentation**
  * Added documentation for the local server’s HTTP API.
* Clarified available read-only routes, authentication, provider
selection, response formats, and error handling.
* Documented localhost binding, Host validation, supported cost
providers, concurrency limits, and usage examples.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
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.

Honor the serve command refresh interval

1 participant