Commit graph dotfiles/claude/tests/statusline.isaacaudet.cache_test.sh
Author SHA1 Message Date
Jonny Barnes
35e170b40c
Back off after a failed usage fetch instead of retrying every redraw
A failed fetch left the cache mtime untouched, so with no network every
redraw — and a redraw happens on every keystroke — tried curl again and
could wait --max-time 10 for it. Cutting the TTL from an hour to five
minutes made that start 55 minutes sooner, so it is worth fixing now.

The marker is a separate file rather than a touch of the cached
response: a cold /tmp has no response to touch, and that is exactly the
case with no stale data to fall back on, where the timeout is paid in
full with nothing to show for it.

It goes down before the request and is cleared when that lands, not
written afterwards. A fetch is in flight for as long as curl takes to
give up, and this cache dir is shared by every session, so redraws
starting inside that window are real rather than hypothetical: they now
serve stale data instead of each launching their own doomed request.
Every attempt writes it, so a repeated failure restarts the backoff, and
only an attempt does, so the redraws it suppresses cannot keep
re-stamping it and it always lapses.

Missing credentials stays outside the backoff — it costs no timeout, and
the redraw after a login should show the bars rather than wait out a
retry window it had no part in earning.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-02 13:22:52 +01:00
Jonny Barnes
f2dbe61276
Refresh the usage bars every 5 minutes, not every hour
The 5h/7d bars were served from a cache with a one-hour TTL, so a bar
could sit unchanged for most of a 5-hour window. The TTL is now a named
config setting next to GIT_CACHE_SECS at 300s: worst case 12 requests an
hour, shared across every session through /tmp/claude.

The section header claimed "cached 60s" — inherited from upstream and
never true here — which is what set the expectation the code did not
meet. It now names the setting instead of a number that can drift.

The refresh is gated on the same width-tier check as the bars, so a
render that shows them is a render that refreshes them: the new tests
pin that from full width down to WRAP_FLOOR, and pin that one column
below it, where the bars are dropped, no request is paid for either.
Those widths are given in usable columns, as in the sibling width test,
so the suite does not depend on the padding in the live settings.json.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-02 13:07:19 +01:00