Repository navigation
github-backup(drain): ack webhook events only after a successful fetch - #3290
Conversation
Events were acked (deleted from the Worker KV queue) even when the fetch failed or the mirror was missing, and the coalesce stamp was advanced anyway — a transient failure silently became up to a week of staleness with no log. Now: ack only on fetch ok; failures stay queued, are appended to fetch.log with the oldest event age, and are counted per repo; at 5 consecutive failures the run logs DRAIN-CHRONIC and exits non-zero (event still kept). Coalesce-window events stay queued until a drain fetches them. Unplanned repos keep the previous behavior (acked + noted for the weekly reconcile). Regression test: infra/github-backup/tests/test_drain_queue.py (32 checks). Fixes #3219
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 19 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 50bf3c579c
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| failed.append({"repo": repo, "result": res, | ||
| "consecutive_failures": fs["count"]}) |
There was a problem hiding this comment.
Allow queue polling to progress past retained failed events
If the queue contains 500 older events for unavailable planned mirrors, retaining those events now prevents later events for healthy repositories from being processed. The Worker in infra/github-backup/worker/src/index.js:55–61 returns only the first 500 entries and neither follows nor exposes a pagination cursor, so every drain retries the same failed batch until recovery or expiration of the seven-day TTL. I reproduced this with 500 missing-mirror events followed by one healthy-repository event: repeated drains never attempted the healthy repository. Preserve failed events, but add pagination or another mechanism that allows polling to advance past them.
Useful? React with 👍 / 👎.
Fixes #3219
The bug
drain_queue.pyappended every event id to the ack list up front and POSTed it to the Worker at the end of the run — including events whose fetch had just returned"fail"or"missing". The Worker deletes acked events from KV, so a transient fetch failure silently converted into up-to-a-week of staleness: the failure was written to no log, the 15-min coalesce stamp was advanced anyway, and the run summary printed the repo underfetchedregardless of outcome.The fix
An event is now acked only once the drainer has made the mirror reflect it:
fetch_reporeturned"ok". On"fail"/"missing"the event stays queued for the next drain tick, the failure is appended tofetch.login the daily pass's leading format (plus drain context: oldest event age, consecutive-failure count), and the coalesce stamp is not advanced.fetch.lognote — preserved behavior (mirror creation is the weekly reconcile's decision).state.jsonkeydrain_fail::<repo>). At 5 consecutive failures the failure is logged loudly (DRAIN-CHRONIC … event(s) kept queued, needs attention) and the run exits non-zero so systemd surfaces it — mirroring the daily pass's chronic-failure pattern. The event is kept, never silently dropped; a later success clears the counter.fetchedvsfailed(with per-repo result + failure count) vsunplannedvscoalesced_pending, plus the acked count.plan.jsonis loaded once instead of per repo.Tests — before / after
New regression test
infra/github-backup/tests/test_drain_queue.pydrives the realdrain_queue.main()with a stub Worker + stubfetch_repo(same shape as the probe in #3219): 32 checks across success / fail / missing / unplanned / coalesce-window / coalesce-expired / chronic / recovery / mixed-batch cases.Before (test run against the pre-fix
drain_queue.pyon this branch's base):After:
including: fail → not acked +
fetch.logline with event age + no stamp + counter incremented; missing → same; coalesce window → not acked and no fetch attempted, fetched+acked once the window passes; 5th consecutive failure → exit 1 +DRAIN-CHRONICinfetch.log+ event still queued; success after failures clears the counter.Run locally on the laptop:
python3 infra/github-backup/tests/test_drain_queue.py.Need help on this PR? Tag
@codesmith-botwith what you need.