Skip to content

feat: anchor the 5h window and detect it reliably - #4

Merged
ShawnKung merged 2 commits into
mainfrom
feat/anchor-5h-window
Sep 8, 2026
Merged

ShawnKung merged 2 commits into
mainfrom
feat/anchor-5h-window

Conversation

@ShawnKung

Copy link
Copy Markdown
Owner

Summary

  • fix(usage): judge a 5h window as active when used_percent > 0 or remaining is clearly below the window length (i.e. reset_at has frozen). A rolling window is not anchored until its first post-reset request; before that the backend returns a placeholder reset_at that advances with time, so remaining stays at the full length and used_percent rounds to 0 even after a lightweight ping anchors the window. This makes status and metrics reflect a window that is already counting down.
  • feat(cli): add ping --until-anchored, which sends pings until the window is observed to be counting. It re-reads usage first and stops early if already counting; otherwise it starts from a larger input and doubles the input each round to raise per-call consumption, re-reading usage after each ping until anchored or a round limit is reached. Long input goes through stdin to codex exec; --dry-run only prints the command.
  • docs: add docs/five-hour-window-anchoring.md explaining the anchoring mechanism, the active judgement, and the new command; link it from the README.

Test plan

  • make check (gofmt, go vet, go test ./...)
  • git diff --check
  • TestWindowActiveByCounting covers placeholder vs. frozen vs. used vs. expired windows
  • TestAnchorPromptLength and TestPingUntilAnchoredFlag
  • ping --until-anchored --dry-run and ping --help verified locally

A rolling window is not anchored until its first request after reset.
Before that, the backend returns a placeholder reset_at that advances
with the current time, so remaining stays at the full window length and
used_percent rounds to 0 even after a very small ping anchors the window.

Judge a window as active when used_percent is non-zero or remaining is
clearly below the window length (reset_at has frozen), with a few seconds
of slack for sub-second truncation. This lets status and metrics reflect
a window that is already counting down after a lightweight ping.
When the 5h allowance is full, the rolling window has not started
counting until the first request anchors it. This flag sends pings until
the window is observed to be counting: it re-reads usage first and stops
early if already counting, otherwise it starts from a larger input and
doubles the input each round to raise per-call consumption, checking
usage after each ping until anchored or a round limit is reached.

Long input is passed via stdin to codex exec to avoid oversized argv, and
--dry-run only prints the command. Document the anchoring mechanism, the
active judgement, and this command under docs/.
@ShawnKung
ShawnKung merged commit 759e48f into main Sep 8, 2026
10 checks passed
@ShawnKung
ShawnKung deleted the feat/anchor-5h-window branch September 8, 2026 02:41
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