Skip to content

fix(fetch): clone repos whose history was rewritten by a force push - #92

Merged
sanity merged 5 commits into
mainfrom
fix/86-force-push-clone
Nov 26, 2026
Merged

sanity merged 5 commits into
mainfrom
fix/86-force-push-clone

Conversation

@sanity

@sanity sanity commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Problem

After a git push --force that rewrites history, every fresh git clone of the repo fails with fetch could not converge: ... no bundle in object_index advertises them (#86). Existing clones keep working. This was reproduced 3 times on the live network with 0.1.27.

The fetch finds the next bundle by looking for one whose tip is the missing parent commit. After a force push, the new bundle holds only the new commits. Their parent lives inside an older bundle whose tip is the abandoned commit, so no tip matches and the fetch gives up even though every object is in object_index. The same shape also affected a single-branch fetch of a branch that forked from a mid-history commit.

Approach

Client-side only. No contract, WASM, wire-format or dependency change.

  • The convergence loop moves from handle_fetch into converge_fetch, which takes a BundleInstaller so it can be tested without a gateway. The decision step is a pure function, plan_unresolved_downloads.
  • When commits are still missing and no undownloaded bundle is tipped at any of them, the fetch now downloads every remaining bundle and re-walks. It fails with the original, byte-identical error only when everything is downloaded and commits are still missing.
  • The fallback downloads everything rather than one bundle at a time. A review round showed why: a pack built against the old ref can omit objects such as a reused blob, which then live only in an abandoned bundle that no missing commit points at, so stopping once the commits resolve could leave checkout broken.
  • Healthy repos are unaffected. The fallback is reached only where the old code failed, and snapshot mirrors (orphan commits) never reach it, so dead-weight skipping is unchanged.
  • This also removes a latent infinite loop: the old "resolvable" check ignored already-downloaded bundles.

Repos already in this state become clonable again once this is released. No republish is needed.

Testing

The reproduction test went in first (9286ce7). It failed with "fetch could not converge" on the old code and passes now. All tests use real git repos and packs:

  • converge_fetch_recovers_parent_buried_in_untipped_bundle_after_force_push
  • converge_fetch_fallback_fetches_blob_reused_from_abandoned_bundle: fails on the one-at-a-time variant.
  • converge_fetch_two_successive_force_pushes_span_two_untipped_bundles
  • converge_fetch_fallback_installs_every_remaining_bundle
  • converge_fetch_fallback_does_not_reinstall_seeded_legacy_bundle
  • converge_fetch_converges_when_wanted_is_an_annotated_tag_of_the_new_tip
  • converge_fetch_skips_dead_weight_bundle_when_history_is_complete: pins that healthy repos skip dead weight.
  • converge_fetch_errors_when_parent_is_in_no_bundle
  • converge_fetch_downloads_everything_then_errors_when_parent_still_missing
  • plan_unresolved_downloads_decisions

All converge_fetch test calls run under a timeout, so a termination regression fails rather than hangs. fmt, clippy (CI flags) and cargo test -p freenet-git are clean.

Review: Codex (two passes), a skeptical lens and a testing lens. Codex's second pass found the reused-blob gap in a one-at-a-time variant, and it is fixed here. No other blocking findings. A related, pre-existing edge case with annotated tags is filed as #90.

Closes #86

[AI-assisted - Claude]

…sh (#86)

Extracts the bundle-convergence loop from handle_fetch into converge_fetch
behind a BundleInstaller trait (behaviour unchanged) so it can be tested
without a gateway. The new force-push test fails on this commit.

[AI-assisted - Claude]
…d bundle (#86)

After a history-rewriting force push the needed parent lives inside an
older bundle whose tip is an abandoned commit, so no bundle tip matched
and a fresh clone bailed. When no unresolved parent is the tip of an
undownloaded bundle, download the remaining bundles and re-walk; bail
only when every bundle in the object_index is downloaded and commits are
still missing. The decision is a pure function
(plan_unresolved_downloads). Snapshot repos never reach the fallback.

[AI-assisted - Claude]
…fetch tests (#86)

The remaining-bundles fallback now installs a single bundle and re-walks,
stopping as soon as the missing parent appears. Tests run under a timeout
and cover several abandoned bundles, a seeded legacy bundle, two
successive force pushes, and an annotated-tag want.

[AI-assisted - Claude]
Finding every missing commit does not mean every blob is present: a
force-push pack can omit objects reused from the abandoned history, and
those may live in a bundle no missing commit points at. Revert to
installing all remaining bundles and add a regression test.

[AI-assisted - Claude]
@sanity
sanity force-pushed the fix/86-force-push-clone branch from aedd2ab to e613fed Compare November 26, 2026 04:10
@sanity
sanity merged commit 2d02103 into main Nov 26, 2026
6 checks passed
@sanity
sanity deleted the fix/86-force-push-clone branch November 26, 2026 04:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fresh clone fails after a history-rewriting force push

1 participant