GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — github-backup(state): plan.json, state.json and MANIFEST.json are written non-atomically and loaded with bare json.load — one torn write wedges the daily fetch, the drainer and manifest regeneration · Issue #3240 · developing-today/code

github-backup(state): plan.json, state.json and MANIFEST.json are written non-atomically and loaded with bare json.load — one torn write wedges the daily fetch, the drainer and manifest regeneration #3240

New issue
Copy link
New issue
Copy link
Closed
#7723
Closed
github-backup(state): plan.json, state.json and MANIFEST.json are written non-atomically and loaded with bare json.load — one torn write wedges the daily fetch, the drainer and manifest regeneration#3240
#7723
Copy link
Assignees
dezren39
Labels
app/github-backupinfra/github-backup estate mirror systemeffort/sSmall: expected under 2 hours of workkind/bugSomething isn't working (prefixed form of the classic bug label)priority/normalOrdinary priority (the default)source/creatorFiled by the new-issue-creator jobsource/design-architectFiled by the repo design architect jobtask/small-fixQueue packet kind: bounded fix with reproduction and targeted tests

Description

@dezren39
dezren39
opened on Oct 31, 2026
Issue body actions

Problem

Every generated-state file in the github-backup system is written by truncating the live file and dumping into it, and every reader loads those files with a bare json.load that raises on a torn file. There is no temp-file + rename, no fsync, and no backup copy anywhere in infra/github-backup/bin/ (no os.replace/os.rename/fsync in any of the five scripts).

Writers (all open(path, "w") + json.dump on the live path):

  • reconcile.py:39 — plan.json (the weekly sweep's output, consumed by everything else)
  • fetch_mirrors.py:69 — state.json (fetch timestamps / failure history)
  • drain_queue.py:74 — state.json again (the 5-minute webhook drainer shares the file with the daily fetch)
  • manifest.py:67 — MANIFEST.json, the file the runbook calls the disaster-recovery source of truth

Readers that crash on a torn file:

  • fetch_mirrors.py:51 — json.load(open(state_path)) at startup: a torn state.json kills the daily fetch before it fetches anything.
  • drain_queue.py:44 and :64 — the drainer loads state.json and (per event) plan.json the same way: one torn write wedges the 5-minute freshness loop too.
  • clone_all.py:24 — json.load(open(plan.json)) at startup: a torn plan.json kills the clone pass.
  • manifest.py:31 — json.load(open(plan_path)) (the os.path.exists guard does not help): a torn plan.json also kills manifest regeneration, so the DR record stops updating.

The writers and readers run on timers on a laptop that sleeps, reboots, and loses power — the same interruption class as #3233/#3238. A crash, kill, or sleep during any of these writes (they grow with the estate; plan.json/state.json cover every mirror) leaves a truncated JSON file, and from then on every subsequent run of the affected scripts dies at startup with a JSONDecodeError traceback until a human repairs the file by hand. Nothing distinguishes "corrupt state" from any other crash, and the file holds data that cannot be regenerated from the tree alone (state.json's last_fetch coalescing timestamps and fail_days chronic-failure history).

Evidence (verified this run, main 357ec7f)

Laptop probe ~/git/fleet/probe-2026-10-31-laneA-validmirror/ (on the laptop), driving the real scripts (sha256 f0115270… fetch_mirrors.py, 59a0abd6… clone_all.py, a489798e… manifest.py — identical in the sandbox clone, the laptop clone, and the probe copies), with backup_root pointed at a scratch tree:

  1. Torn state.json (truncated mid-object, exactly what a killed json.dump leaves) → fetch_mirrors.main() crashes: JSONDecodeError: Expecting ',' delimiter: line 1 column 40. The daily fetch never runs.
  2. Torn plan.json → clone_all.main() crashes: JSONDecodeError: Unterminated string starting at: line 1 column 11.
  3. Torn plan.json → manifest.build() crashes with the same JSONDecodeError — MANIFEST.json regeneration is wedged by the same file.
  4. Control — valid plan.json + state.json: fetch_mirrors.main() runs clean ({"results": {"ok": 0, "fail": 0, "skip": 0, "missing": 1}, "chronic_failures": []}, return 0) and regenerates MANIFEST.json/FAMILIES.md.

Why it matters

This is a backup system: its state files are part of the product, and its whole purpose is surviving interruptions. Today a single ill-timed laptop sleep during a state write silently converts into a persistent outage of the daily fetch, the webhook drainer, and the DR manifest — the failure surfaces only as a traceback in a timer log, and recovery is manual file surgery on files whose history (fetch coalescing, chronic-failure tracking) is lost in the repair. Atomic replace (write temp file in the same directory, fsync, os.replace) is a few lines per writer and makes a torn live file impossible; tolerant loading (keep a last-good copy, or treat a torn file as empty-with-a-loud-warning) is the complementary half.

Acceptance criteria

  • All generated-state writes (plan.json, state.json, MANIFEST.json, and the markdown reports if in scope) are atomic: write to a temp file in the same directory, fsync, then os.replace — a reader never observes a partial file.
  • Readers survive a pre-existing torn file instead of dying at startup: on JSONDecodeError they fall back (empty state / last-good copy) and surface a loud, named warning (log line + non-zero exit or report section), so the corruption is visible rather than silent.
  • The shared state.json writers (fetch_mirrors daily + drain_queue every 5 min) cannot interleave into a corrupt file under the atomic scheme (replace is per-writer atomic; any remaining lost-update window between the two writers is either closed or explicitly documented).
  • Regression tests: (a) torn state.json → fetch run proceeds with fallback + warning (fails on current code with JSONDecodeError), (b) torn plan.json → clone pass and manifest build proceed likewise, (c) a writer killed mid-dump leaves the previous complete file intact, (d) valid files → behaviour unchanged (control passes before and after).

Dedup (this run): title/keyword searches for github-backup + atomic/torn/state.json/plan.json return no covering issue. Related but distinct: #3233 (partial clone destination wedge), #3238 (valid_mirror false positive), #3229 (inventory null owner), #3219 (drain ack path), #3215 (umbrella estate issue).

Activity

Next
  1. dezren39
    added
    queue/queuedHas a queued queue task
    source/creatorFiled by the new-issue-creator job
    task/triageQueue packet kind: verify, reproduce, and route this item
    status/needs-triageNot yet triaged; needs a first look
    priority/normalOrdinary priority (the default)
    app/github-backupinfra/github-backup estate mirror system
    kind/bugSomething isn't working (prefixed form of the classic bug label)
    effort/sSmall: expected under 2 hours of work
    on Oct 31, 2026
  2. dezren39 commented on Oct 31, 2026

    @dezren39
    dezren39
    on Oct 31, 2026
    MemberAuthor
    More actions

    🤖 Agent note · filed

    • Agent: new-issue-creator job (new-issue-creator-code-a)
    • Session / ID: cron job new-issue-creator-code-a, run 2026-10-31T23:20Z
    • Found via: filed this run
    • Task: Triage github-backup(state): plan.json, state.json and MANIFEST.json are written non-atomically and loaded with bare json.load — one torn write wedges the daily fetch, the drainer and manifest regeneration #3240: github-backup plan.json/state.json/MANIFEST.json are written non-atomically and read with bare json.load — one torn write wedges the daily fetch, the 5-minute drainer and manifest regeneration
    • Expectation: effort/s — triage confirms the non-atomic writes and crash-on-torn loads against infra/github-backup/bin on main, then routes the fix (temp+fsync+os.replace writers; tolerant loaders with a loud fallback warning)
    • Links: github-backup(state): plan.json, state.json and MANIFEST.json are written non-atomically and loaded with bare json.load — one torn write wedges the daily fetch, the drainer and manifest regeneration #3240
  3. dezren39
    added a parent issue on Nov 1, 2026
    • Design: a mirror is what it can prove — one validity, outcome and alarm contract for the github-backup estate mirror #3282
  4. dezren39
    added
    source/design-architectFiled by the repo design architect job
    on Nov 1, 2026
  5. dezren39 commented on Nov 1, 2026

    @dezren39
    dezren39
    on Nov 1, 2026
    MemberAuthor
    More actions

    🤖 Design-architect pass 29 (2026-10-31) — agent note: this issue is ADOPTED as a phase of design #3282 ("a mirror is what it can prove — one validity, outcome and alarm contract for the github-backup estate mirror", design doc: files/designs/code-github-backup-mirror-contract.md in the keep-the-four-repos-healthy goal workspace), linked as a sub-issue of #3282 and labelled source/design-architect. Triage: do NOT re-file, re-scope or split this issue — record the phase structure instead. Phase mapping: Phase 1 (validity & destinations) = #3238 + #3233; Phase 2 (recorded outcomes & the alarm) = #3250 + #3219 + #3270 + #3257; Phase 3 (durable state & plan retention) = #3240 + #3229 + closing audit #3283 (gated on Phases 1–2). The design records the pins that span the phases: validity = bare + HEAD resolves, with no emptiness exception inside the plan (build_plan excludes zero-commit repos); destinations are absent / valid / skeleton (remove + clone) / debris (quarantine to .partial-<timestamp> + clone); every fetch attempt ends in one recorded outcome shared by the daily loop and the drainer, and the drainer acks only on ok; the chronic alarm is a streak of 3 consecutive unavailable days (fail, timeout and missing all count); generated state is written atomically only through ghb_common helpers; reconcile retains a failed owner's previously planned entries. Where an origin's acceptance left a choice open (the streak-vs-window rule, missing-counts-vs-immediate, report-vs-retain, skeleton handling), the design doc records the decision — triage follows the design's pin, not the open alternative. Each origin keeps its own acceptance criteria and its already-queued triage packet — no new packet was created for it this pass.

  6. github-actions
    assigned
    dezren39
    on Nov 1, 2026
  7. dezren39
    removed
    status/needs-triageNot yet triaged; needs a first look
    queue/queuedHas a queued queue task
    on Nov 1, 2026
  8. 71 remaining items

  9. dezren39
    added
    queue/claimedQueue worker lifecycle state
    status/in-progressQueue worker lifecycle state
    on Nov 8, 2026
  10. dezren39 commented on Nov 8, 2026

    @dezren39
    dezren39
    on Nov 8, 2026
    MemberAuthor
    More actions

    🤖 Agent note · picked up

    • Agent: queue worker (repo-worker-code), lane openchamber-scheduled-lane (c29174f1-48e0-4b13-b4ff-9b73ab67e9ab)
    • Session / ID: task 12104 (ses_e5e452f48e0ffephqMu1gXqYCy)
    • Found via: queue claim
    • Task: task 12104 (triage) on issue github-backup(state): plan.json, state.json and MANIFEST.json are written non-atomically and loaded with bare json.load — one torn write wedges the daily fetch, the drainer and manifest regeneration #3240 — github-backup(state) atomic/tolerant generated state. Revalidating phase gate and current source.
    • Expectation: verify whether phase 1/2 gates (github-backup(valid_mirror): a bare skeleton with zero refs passes as a verified mirror — clone_all records it ok and MANIFEST.json reports it 'mirrored' #3238, github-backup(clone_all): a clone killed mid-flight leaves a partial destination every rerun rejects — the 'resumable' driver never resumes that repo #3233, github-backup(fetch): a git fetch that hits the 3600s timeout raises TimeoutExpired out of fetch_mirrors.main() — every later repo is skipped, no failure is recorded, and state.json/MANIFEST.json are never written #3250, github-backup(drain): webhook events are acked even when the fetch failed or the mirror is missing — freshness signal silently dropped #3219, github-backup(fetch): a missing mirror can never trip the chronic alarm — 'missing' returns before any fail_days record, so the daily run exits 0 forever #3270, github-backup(fetch): fail_days counts every failure day since the last success, not 3 days in a row — intermittent failures weeks apart trip the chronic alarm and latch exit 1 #3257) cleared; if not, park the existing implementation follow-up with no code changes. Do not re-file/split; issue adopted under design Design: a mirror is what it can prove — one validity, outcome and alarm contract for the github-backup estate mirror #3282.
    • Links: issue github-backup(state): plan.json, state.json and MANIFEST.json are written non-atomically and loaded with bare json.load — one torn write wedges the daily fetch, the drainer and manifest regeneration #3240 · design Design: a mirror is what it can prove — one validity, outcome and alarm contract for the github-backup estate mirror #3282 · implementation task 5683
  11. dezren39 commented on Nov 8, 2026

    @dezren39
    dezren39
    on Nov 8, 2026
    MemberAuthor
    More actions

    🤖 Agent note · triaged

    • Agent: queue worker (repo-worker-code), lane openchamber-scheduled-lane (c29174f1-48e0-4b13-b4ff-9b73ab67e9ab)
    • Session / ID: task 12104 (ses_e5e452f48e0ffephqMu1gXqYCy)
    • Found via: queue claim
    • Task: task 12104 — triage of github-backup(state): plan.json, state.json and MANIFEST.json are written non-atomically and loaded with bare json.load — one torn write wedges the daily fetch, the drainer and manifest regeneration #3240, adopted Phase 3 of design Design: a mirror is what it can prove — one validity, outcome and alarm contract for the github-backup estate mirror #3282.
    • Fresh gate verification (2026-11-08): Phase 1 issue github-backup(valid_mirror): a bare skeleton with zero refs passes as a verified mirror — clone_all records it ok and MANIFEST.json reports it 'mirrored' #3238 is OPEN and Phase 2 issue github-backup(fetch): a missing mirror can never trip the chronic alarm — 'missing' returns before any fail_days record, so the daily run exits 0 forever #3270 is OPEN; github-backup(clone_all): a clone killed mid-flight leaves a partial destination every rerun rejects — the 'resumable' driver never resumes that repo #3233, github-backup(fetch): a git fetch that hits the 3600s timeout raises TimeoutExpired out of fetch_mirrors.main() — every later repo is skipped, no failure is recorded, and state.json/MANIFEST.json are never written #3250, github-backup(drain): webhook events are acked even when the fetch failed or the mirror is missing — freshness signal silently dropped #3219, and github-backup(fetch): fail_days counts every failure day since the last success, not 3 days in a row — intermittent failures weeks apart trip the chronic alarm and latch exit 1 #3257 are CLOSED. The hard gate therefore remains uncleared. No code edits or worktree were created, per the existing task/design instructions.
    • Verdict: issue remains real/current and must stay open. Existing Phase 3 implementation task design(id): residency & boundaries framework — opt-in evidence, sanctions, and intranet-mode capabilities #5683 is gate-bound; no parallel implementation was started. Broker created follow-on fix task docs(mcpx): document published install channels and service modes #13613 for the remaining work.
    • Resume: after github-backup(valid_mirror): a bare skeleton with zero refs passes as a verified mirror — clone_all records it ok and MANIFEST.json reports it 'mirrored' #3238 and github-backup(fetch): a missing mirror can never trip the chronic alarm — 'missing' returns before any fail_days record, so the daily run exits 0 forever #3270 close, revalidate the complete Phase 1/2 gate, then proceed with Design: a mirror is what it can prove — one validity, outcome and alarm contract for the github-backup estate mirror #3282 Phase 3; until then make no implementation edits.
    • Links: task 12104 · task 13613 · issue github-backup(state): plan.json, state.json and MANIFEST.json are written non-atomically and loaded with bare json.load — one torn write wedges the daily fetch, the drainer and manifest regeneration #3240 · design Design: a mirror is what it can prove — one validity, outcome and alarm contract for the github-backup estate mirror #3282 · gate issues github-backup(valid_mirror): a bare skeleton with zero refs passes as a verified mirror — clone_all records it ok and MANIFEST.json reports it 'mirrored' #3238/github-backup(fetch): a missing mirror can never trip the chronic alarm — 'missing' returns before any fail_days record, so the daily run exits 0 forever #3270
  12. dezren39
    added
    queue/queuedHas a queued queue task
    task/small-fixQueue packet kind: bounded fix with reproduction and targeted tests
    and removed
    task/triageQueue packet kind: verify, reproduce, and route this item
    status/in-progressQueue worker lifecycle state
    queue/claimedQueue worker lifecycle state
    work/assignedQueue worker lifecycle state
    on Nov 8, 2026
  13. dezren39
    added a commit that references this issue on Nov 8, 2026

    Merge pull request #7723 from developing-today/queue/12622-3282-mirro…

    752357c
  14. dezren39
    closed this as completedin #7723on Nov 8, 2026
  15. developing-today commented on Nov 8, 2026

    @developing-today
    developing-todayBot
    on Nov 8, 2026 – with developing.today
    Contributor
    More actions

    Agent note - done (already done)

    • Agent: queue worker (repo-worker-code), lane code-w
    • Session / ID: task 13613
    • Found via: queue claim
    • Task: task 13613 for issue github-backup(state): plan.json, state.json and MANIFEST.json are written non-atomically and loaded with bare json.load — one torn write wedges the daily fetch, the drainer and manifest regeneration #3240 completed as already_done. Fresh evidence this shift: issue github-backup(state): plan.json, state.json and MANIFEST.json are written non-atomically and loaded with bare json.load — one torn write wedges the daily fetch, the drainer and manifest regeneration #3240 is CLOSED as completed (closed 2026-11-08T15:04:07Z); the fix is landed on origin/main in commit fc1c796 (github-backup mirror contract remainder - atomic state (github-backup(state): plan.json, state.json and MANIFEST.json are written non-atomically and loaded with bare json.load — one torn write wedges the daily fetch, the drainer and manifest regeneration #3240)); infra/github-backup/bin/ghb_common.py carries the _atomic_replace and atomic_write_text helpers the issue required (temp file in same directory, fsync, os.replace). The stale queue/queued label is being removed in the same pass.
    • Expectation: closed; no further work.
    • Links: issue github-backup(state): plan.json, state.json and MANIFEST.json are written non-atomically and loaded with bare json.load — one torn write wedges the daily fetch, the drainer and manifest regeneration #3240; commit fc1c796
  16. developing-today
    removed
    queue/queuedHas a queued queue task
    on Nov 8, 2026
  17. developing-today commented on Nov 8, 2026

    @developing-today
    developing-todayBot
    on Nov 8, 2026 – with developing.today
    Contributor
    More actions

    Agent note - correction (full SHA)

    • Agent: queue worker (repo-worker-code), lane code-w
    • Session / ID: task 13613
    • Correction to the task 13613 completion record: the merge_sha stored on the queue result was truncated with a placeholder suffix in error. The correct full SHA of the landing commit for issue github-backup(state): plan.json, state.json and MANIFEST.json are written non-atomically and loaded with bare json.load — one torn write wedges the daily fetch, the drainer and manifest regeneration #3240 is fc1c796 (short fc1c796, named in the done note 6728390360). The already_done verdict and its evidence are unchanged.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @dezren39
    dezren39

Labels

app/github-backupinfra/github-backup estate mirror systemeffort/sSmall: expected under 2 hours of workkind/bugSomething isn't working (prefixed form of the classic bug label)priority/normalOrdinary priority (the default)source/creatorFiled by the new-issue-creator jobsource/design-architectFiled by the repo design architect jobtask/small-fixQueue packet kind: bounded fix with reproduction and targeted tests

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.