feat(quota): auto-expire stale cooldown data on read #87

Merged
lz merged 8 commits from feat/cooldown-reset into main 2026-07-22 13:02:54 +02:00
Owner

Summary

  • The Nexus header badge and worker terminal statusline both used to keep showing a rate-limit window's last-known percentage and reset countdown forever, even after resets_at had already passed — claude-code only refreshes rate_limits on a real inference call, so an idle session never self-corrects.
  • getAccountQuota() (nexus/src/lib/server/quota/store.ts) now prunes an expired window as a pure read-time filter (not a mutation) instead of fabricating a 0% or leaving stale data in place.
  • worker/nexus-statusline.sh does the equivalent inline on every render, via a new expired() POSIX helper comparing resets_at against date +%s.
  • No frontend changes: an expired window serializes as null, identical to "never reported" — QuotaBadge.svelte already renders that as the dashed "unknown" state.
  • Write path (the POST to /api/agent/quota) is deliberately untouched — expiry is a display-layer concern on both sides, not a storage concern.
  • AGENTS.md fact #19 documents the behavior for future readers.

Test plan

  • pnpm test (nexus/) — 843 tests passing
  • sh worker/nexus-statusline.test.sh — 30 tests passing (7 original + 3 more closing gaps found in review)
  • Per-task spec-compliance + code-quality review during implementation (subagent-driven-development)
  • Whole-diff final review before this PR
  • Independent 4-agent review pass (general code quality, test coverage, comment accuracy, silent-failure hunting) — all gaps found (two test-coverage gaps, one doc-precision nit) closed before opening this PR

Design doc: docs/superpowers/specs/2026-07-16-quota-statusline-design.md ("Addendum (2026-07-21)"). Plan: docs/superpowers/plans/2026-07-21-cooldown-reset.md.

## Summary - The Nexus header badge and worker terminal statusline both used to keep showing a rate-limit window's last-known percentage and reset countdown forever, even after `resets_at` had already passed — claude-code only refreshes `rate_limits` on a real inference call, so an idle session never self-corrects. - `getAccountQuota()` (`nexus/src/lib/server/quota/store.ts`) now prunes an expired window as a pure read-time filter (not a mutation) instead of fabricating a 0% or leaving stale data in place. - `worker/nexus-statusline.sh` does the equivalent inline on every render, via a new `expired()` POSIX helper comparing `resets_at` against `date +%s`. - No frontend changes: an expired window serializes as `null`, identical to "never reported" — `QuotaBadge.svelte` already renders that as the dashed "unknown" state. - Write path (the POST to `/api/agent/quota`) is deliberately untouched — expiry is a display-layer concern on both sides, not a storage concern. - `AGENTS.md` fact #19 documents the behavior for future readers. ## Test plan - [x] `pnpm test` (nexus/) — 843 tests passing - [x] `sh worker/nexus-statusline.test.sh` — 30 tests passing (7 original + 3 more closing gaps found in review) - [x] Per-task spec-compliance + code-quality review during implementation (subagent-driven-development) - [x] Whole-diff final review before this PR - [x] Independent 4-agent review pass (general code quality, test coverage, comment accuracy, silent-failure hunting) — all gaps found (two test-coverage gaps, one doc-precision nit) closed before opening this PR Design doc: `docs/superpowers/specs/2026-07-16-quota-statusline-design.md` ("Addendum (2026-07-21)"). Plan: `docs/superpowers/plans/2026-07-21-cooldown-reset.md`.
lz added 8 commits 2026-07-22 12:46:33 +02:00
getAccountQuota() now drops a window once its resets_at has passed,
instead of returning a stale percentage indefinitely until the next
session happens to report. Pure read-time filter, not a mutation.
Mirrors the Nexus-side store fix: a resets_at that has already
passed falls back to the existing 'quota —' display instead of an
increasingly wrong percentage, checked inline on every render.
test(quota): close statusline fail-safe and wire-format test gaps found in PR review
All checks were successful
ci / nexus (pull_request) Successful in 5m37s
ci / images (pull_request) Successful in 16m13s
pr-image-cleanup / delete-pr-images (pull_request) Successful in 8s
3d40eee464
lz merged commit 119e930325 into main 2026-07-22 13:02:54 +02:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
lz/agent-nexus!87
No description provided.