Skip to content

fix(github-backup): validate plan/state shape at load — poison entries named and skipped (#6637) - #6696

Merged
dezren39 merged 3 commits into
mainfrom
queue/fallback-6637-ghb-shape-validation
Nov 7, 2026
Merged

dezren39 merged 3 commits into
mainfrom
queue/fallback-6637-ghb-shape-validation

Conversation

@dezren39

@dezren39 dezren39 commented Nov 7, 2026 •

Copy link
Copy Markdown
Member

Fixes #6637.

fetch_mirrors.py loaded plan.json/state.json with bare json.load and subscripted the results unguarded, so one valid-JSON-but-wrong-shape entry (a plan entry of 123, a state entry of "oops", a string fail_days) crashed the whole daily fetch with a raw TypeError/KeyError/AttributeError — and re-crashed every subsequent run, since the crashing run never rewrote the file. Triage by lane code-a confirmed every shape on current main and routed this issue as the fix vehicle.

Change — shared validation lands once, in ghb_common (per the #6637/#6653 coordination note)

Tests

Filed from a fallback-mode queue shift (queue backend down, code#6619): claimed and released via fleet-claim markers on #6637 by repo-worker-code-l.


Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

@dezren39
dezren39 requested a review from a team as a code owner November 7, 2026 02:36
@coderabbitai

coderabbitai Bot commented Nov 7, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You'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 52 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 0df32711-f51e-4814-9952-c3d66f7bfbc3
Commits

Reviewing files that changed from the base of the PR and between f76f83f and 23bd465.

Files selected for processing: 5

  • infra/github-backup/bin/clone_all.py
  • infra/github-backup/bin/fetch_mirrors.py
  • infra/github-backup/bin/ghb_common.py
  • infra/github-backup/bin/manifest.py
  • infra/github-backup/tests/test_plan_state_shape.py
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

Share

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-07T02:49:13.832447Z 23bd465 New commits
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3c8af48f5d

ℹ️ 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".

Comment on lines +190 to +194
for repo, entry in state.items():
if not isinstance(entry, dict):
problems.append(
f"{source}: entry for {repo!r} is {_shape(entry)}, "
f"expected an object — dropped"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve webhook-drainer timestamps when validating state

When the webhook drainer has successfully fetched a repository, state.json legitimately contains a numeric drain_last::<repo> timestamp, written by drain_queue.py:251–259 and used to enforce its 15-minute coalescing window. This validator treats those timestamps as malformed entries and drops them. Because fetch_mirrors.main() writes the sanitized state back to disk, every daily fetch erases the drainer's coalescing metadata, allowing the next webhook drain to fetch repositories again inside that window. Preserve and validate these bookkeeping entries separately from per-repository objects.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 2e06082 — thank you, this was a real catch. validate_state now validates the drainer's bookkeeping keys under their own shapes and preserves them: drain_last::<repo> must be a number (bool excluded) and drain_fail::<repo> stays on the object path; a wrong-shaped drain_last:: is named and dropped instead of silently kept. Two regression tests added (test_drain_bookkeeping_entries_are_preserved, test_drain_last_with_wrong_shape_is_named_and_dropped); full github-backup suite green, including test_drain_queue.py 82/82.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2e06082eee

ℹ️ 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".

Comment on lines +44 to +49
class ValidatePlanTests(unittest.TestCase):
def test_valid_plan_passes_through(self):
plan = [{"repo": "a/b", "size_kb": 1}, {"repo": "c/d"}]
entries, problems = ghb_common.validate_plan(plan)
self.assertEqual(entries, plan)
self.assertEqual(problems, [])

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Add property tests for the new shape-validation invariants

The new plan/state validation coverage consists entirely of fixed examples, but the root AGENTS.md explicitly requires property tests for parsers and other code with meaningful invariants. These validators fit that requirement: generated JSON inputs can check that accepted plan entries always have string repository names, malformed entries cannot invalidate valid siblings, and valid bookkeeping state survives validation unchanged. Add generated invariant coverage alongside these regression examples to satisfy the repository's testing doctrine.

AGENTS.md reference: AGENTS.md:L41-L45

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added in the follow-up commit just pushed — ShapePropertyTests in tests/test_plan_state_shape.py: a seeded stdlib generator (2,000 generated plans + 2,000 generated states per run, JSON round-tripped so the validators see only json.load-shaped data) checked against independent oracle restatements of the shape contracts — accepted plan entries are exactly the dict-with-string-repo entries in order with one problem per invalid entry; state validation matches the oracle (including drain_last::/drain_fail:: shapes), is idempotent, and a poison entry appended to a plan never changes the verdict on its siblings (500 generated cases). Suite is stdlib-only per the github-backup test convention (no hypothesis dependency); 20/20 tests pass in <0.1s.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant