Repository navigation
feat: anchor the 5h window and detect it reliably - #4
Merged
Merged
Conversation
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/.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
fix(usage): judge a 5h window as active whenused_percent > 0orremainingis clearly below the window length (i.e.reset_athas frozen). A rolling window is not anchored until its first post-reset request; before that the backend returns a placeholderreset_atthat advances with time, soremainingstays at the full length andused_percentrounds to 0 even after a lightweight ping anchors the window. This makesstatusand metrics reflect a window that is already counting down.feat(cli): addping --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 tocodex exec;--dry-runonly prints the command.docs: adddocs/five-hour-window-anchoring.mdexplaining 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 --checkTestWindowActiveByCountingcovers placeholder vs. frozen vs. used vs. expired windowsTestAnchorPromptLengthandTestPingUntilAnchoredFlagping --until-anchored --dry-runandping --helpverified locally