Repository navigation
Description
Story
Split 1 of 2 from #1863 (which timed out at dev-lead's maximum action budget and asked to be split). As the fleet maintainer, I want the retry cron to read the dry-run budget poller's published result to learn whether a Claude window is exhausted and when it really resets, so that a weekly cap suppresses re-dispatch until its reset instead of retrying every two hours for up to seven days.
Blocked by #2029 (PR 2031, the dry-run poller). Do not start until it has merged. Also blocked by #2148 (tests for the artifact trust filter in bp_download_latest_log, which this cron will rely on): do not start until that has merged too. The dev-lead label is removed until then and will be re-added by the maintainer.
Revision note (2026-10-09)
The first attempt (PR 2144, closed) had the cron call the usage endpoint itself. Reviewed against production, that cannot work: the retry workflow passes no CLAUDE_CODE_OAUTH_TOKEN, and the public agent-rate-limit.sh library exists only under tests/fixtures/, not in the production tree, so the hold would have logged "reader unavailable" on every run and done nothing. Its tests passed because they mocked both. The maintainer decided not to give a second workflow the Claude token. The cron gets no token and no copy of the library. One workflow (the poller) holds the credential; the cron consumes its output.
Why this does not parse prose
No real weekly-cap message exists anywhere in this repo, so a day-of-week parser would be built on a guessed format. Do not parse the rate-limit text. The poller's records already carry the authoritative values.
What the poller publishes (verify against the merged code, do not trust this summary)
The poller workflow uploads an artifact named budget-poller-log (JSONL, 14-day retention). Each record has a poll field ("ok" for a good read) and, among others, session_pct, weekly_all_pct, session_resets_at, weekly_all_resets_at. scripts/lib/budget-poller.sh already has bp_download_latest_log, bp_last_ok and bp_stale_hours. Reuse them; do not duplicate.
Scope
- In
scripts/dev-lead-retry.sh, once per cron run, download the latestbudget-poller-logartifact with the existing helper, take the latestpoll=="ok"record withbp_last_ok, and holdstatus=rate-limitedretries while a window in that record is at or above 100% and its*_resets_atis in the future. Hold until that reset. Honour bothweekly_allandsession; when both are exhausted, honour the later reset. Neverweekly_scoped(per-model, handled by model fallback). - Staleness bound. Ignore a record older than the poller's own staleness window (
bp_stale_hours). A stale reading means no hold. The poller being down must never silently extend a hold. - Fail open exactly as today for every failure: no artifact, expired artifact, download error, unparseable record, missing window, no
poll=="ok"record, or the poller not yet running. Behave as the current "unknown reset means retry" path. Do not invertis_reset_in_future's default. - Log the outcome once per run in a greppable form (for example
retry-cron: weekly window exhausted, holding retries until <ISO> (poll <age> old)), and log the fail-open cases distinctly. - Workflow change, minimal: add
actions: readtodev-lead-retry.ymlpermissions (needed to download the artifact) and nothing else. Do not add any secret (noCLAUDE_CODE_OAUTH_TOKEN) and do not widen any other permission. Say so in the PR.
Acceptance criteria
- Tests with a mocked artifact download: weekly window at 100% with a future reset suppresses the retry; the same with a past reset does not; a session window at 100% holds only until its own reset; below-limit windows do not hold.
- Tests that every failure mode in scope 3 and a stale record fall through to the existing retry behaviour unchanged.
- A test that the artifact is downloaded at most once per cron run however many items are retried.
- A test that the workflow file contains no
CLAUDE_CODE_OAUTH_TOKENand thatactions: readis the only permission added. - Log lines from scope 4 asserted by tests.
- No weekday literal anywhere in the change (a test greps for it). No live network in tests; shellcheck clean; existing tests pass unchanged.
- A test that proves the production wiring, not only the mocks: run the hold logic against a fixture copied byte-for-byte from a real record shape produced by the merged poller (generate it with the poller's own
bp_build_record), so the reader and the writer cannot drift apart.
Out of scope
Parsing the weekly message text (the capture issue), the _emit_reset_iso clamp, giving this workflow any credential, and any variable writes.
Activity
don-petry commentedon Oct 9, 2026
Dev-Lead Implementation Plan
Issue: #2139 — Retry cron should hold retries until a Claude window's real reset, read from the usage telemetry
Scope
Before re-dispatching a
status=rate-limiteditem, the retry cron consults the usage adapter once per run and holds rate-limited retries until an exhausted Claude window's (weekly_all/session) realresets_at; every telemetry failure falls open to today's behaviour.Implementation Checklist
scripts/dev-lead-retry.sh: sourcelib/usage-telemetry.sh; addusage_hold_init(called once frommain, before any scan subshell, so the result is inherited — one adapter call per run) that reads the envelope viausage_telemetry_fetchand the window fields via the public library'sarl_token_extract_percent/arl_token_extract_resets_at/arl_token_window_active(no body re-parsing, no weekday literals)usage_hold_active: true only while now < the honoured window'sresets_atstatus=rate-limited, review intents withstatus=rate-limited, issuestatus=rate-limited);blocked/history-unavailable/partial/failedare not quota and are untouched.is_reset_in_futureunchanged.retry-cron: <weekly|5-hour> window exhausted, holding retries until <ISO>resets_at.github/workflows/dev-lead-retry.ymldoes not exposeCLAUDE_CODE_OAUTH_TOKEN— no secret added; the step is a fail-open no-op there (stated in the PR).github/workflows/lint.yml: add the new bats file to the listTests to Write (
tests/dev-lead/unit/test_dev_lead_retry_usage_hold.bats, mocked curl, pinned public-library fixture)Test Command
bats tests/dev-lead/unit/test_dev_lead_retry_usage_hold.bats tests/dev-lead/unit/test_dev_lead_retry*.bats+bash .dev-lead/scripts/dev-lead-lint.shdon-petry commentedon Oct 9, 2026
Dev-Lead: Progress (in progress — not yet durable)
Plan Execution (intended)
usage_hold_initruns once frommainbefore the scan. Scan subshells inherit its result, so the endpoint is read once per cron run. It readsweekly_all/sessionthrougharl_token_window_active/arl_token_extract_percent/arl_token_extract_resets_at. When percent ≥ 100 andresets_atis in the future, it records a hold and logsretry-cron: <weekly|5-hour> window exhausted, holding retries until <ISO>once.usage_hold_activeis checked only on thestatus=rate-limitedpaths (fix-ci, review intents, issues), after the marker's ownreset=check.blocked,history-unavailable,partialandfailedare not quota and are not held.is_reset_in_futureis unchanged.resets_atScope item 4: token availability
.github/workflows/dev-lead-retry.ymldoes not exposeCLAUDE_CODE_OAUTH_TOKENto the scan step. The publicagent-rate-limit.shis also not present underscripts/lib/at runtime; it exists here only as the pinned test fixture. So in production the hold is a fail-open no-op today, and normal retries are unchanged. No secret, permission or workflow env was added.Turning it on is a separate, deliberate change with two parts:
scripts/lib/agent-rate-limit.shor throughAGENT_RATE_LIMIT_LIB.Files touched (this workspace, not yet pushed)
scripts/dev-lead-retry.sh: sourceslib/usage-telemetry.sh; adds the usage-window hold and wires it into the three rate-limited paths andmain.tests/dev-lead/unit/test_dev_lead_retry_usage_hold.bats: new suite. It uses a mocked curl and the pinned public library, with no network. It covers:weekly_scopedwindowsmainrun across 4 items.github/workflows/lint.yml: registers the new bats file.Notes
If both windows are exhausted, the later reset is honoured. The hold also stops the #2008 stale-edit re-dispatch on a held PR (
held=1), the same as an active marker reset already does.don-petry commentedon Oct 9, 2026
Dev-Lead: Implementation Complete — PR #2144
The implementation for issue #2139 is durable: commits are pushed and a pull request is open. This record is backed by verifiable artifacts you can confirm in one click.
195695000b49aa34de6a4a94db54b05412dd5753main: 3 file(s), +442/-0 linesReview happens on the PR. Acceptance criteria and test results are evidenced by the PR's diff and CI checks — not asserted here. If a later stage fails, this claim is retracted in place.
[-]Retry cron should hold retries until a Claude window's real reset, read from the usage telemetry (split 1 of 2 from the weekly-cap issue)[/-][+]Retry cron should hold retries until a Claude window's real reset, read from the budget poller's published result (split 1 of 2 from the weekly-cap issue)[/+]don-petry commentedon Oct 9, 2026
Dev-Lead Implementation Plan
Issue: #2139 — Retry cron should hold retries until a Claude window's real reset, read from the budget poller's published result
Scope
dev-lead-retry.shreads thebudget-poller-logartifact once per cron run, using the existingbp_download_latest_log,bp_last_okandbp_stalenesshelpers. If a freshpoll=="ok"record showssessionorweekly_allat 100% or more with a future*_resets_at,status=rate-limitedretries are held until the later of those resets. Every failure fails open, which matches today's behaviour. No token is added and no rate-limit text is parsed.Implementation Checklist
scripts/dev-lead-retry.sh: sourcelib/budget-poller.sh, then add:budget_hold_from_record <record> <now>(pure). Returns the window and the later future reset ISO among exhaustedsession/weekly_allwindows, neverweekly_scoped.budget_hold_init, called once frommainbefore the scan. It downloads the artifact, takes the last OK record, applies thebp_stale_hoursbound, setsBUDGET_HOLD_UNTILand logs one greppableretry-cron:line, with a distinct line for each fail-open case.budget_hold_active(usesis_reset_in_future, whose default is not inverted).status=rate-limitedmarkers: fix-ci, the retryable review intents (the newest matching marker) and issue retries. A held PR also setsheld=1, so the CodeRabbit's Security Architecture Review is throttled separately from its code review — findings in both sections must be addressed, and an in-place edit after disposition must re-open the comment #2008 edit re-dispatch waits as well..github/workflows/dev-lead-retry.yml: add onlyactions: read. No secret, and no other permission change.Tests to Write (
tests/dev-lead/unit/test_dev_lead_retry_budget_hold.bats)weekly_scopedis ignored.poll=="ok"record, missing window or reset, and a stale record.mainrun across several repos and items.CLAUDE_CODE_OAUTH_TOKEN, and permissions are exactlycontents: writeplusactions: read.date, so it contains no literals).bp_build_record, served throughbp_download_latest_logwith mockedgh/unzip, drives the hold end to end.Test Command
bats tests/dev-lead/unit/test_dev_lead_retry_budget_hold.bats tests/dev-lead/unit/test_dev_lead_retry*.bats tests/dev-lead/unit/test_budget_poller.bats+bash .dev-lead/scripts/dev-lead-lint.shdon-petry commentedon Oct 9, 2026
Dev-Lead: Implementation Complete — PR #2159
The implementation for issue #2139 is durable: commits are pushed and a pull request is open. This record is backed by verifiable artifacts you can confirm in one click.
bf54014adbc4c57b38ecb4036a7e97fd48d64402main: 3 file(s), +640/-0 linesReview happens on the PR. Acceptance criteria and test results are evidenced by the PR's diff and CI checks — not asserted here. If a later stage fails, this claim is retracted in place.
feat: implement issue #2139 — Retry cron should hold retries until a …