Skip to content

A mirror fetch keeps what it receives as a pack, so shared checkouts see it - #1705

Merged
zlareb1 merged 6 commits into
ClickHouse:mainfrom
KaloyanNaumov:pr/mirror-fetch-keeps-packs
Nov 30, 2026
Merged

zlareb1 merged 6 commits into
ClickHouse:mainfrom
KaloyanNaumov:pr/mirror-fetch-keeps-packs

Conversation

@KaloyanNaumov

@KaloyanNaumov KaloyanNaumov commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Closes: #1702
Related: #1553

TL;DR: The mirror's fetches run with fetch.unpackLimit=1 and its clone with --no-local, so everything the mirror receives is in a pack that a shared compiler-tier checkout links on its next pass; past code_mirror_gc_pack_limit packs (500 by default), gc_if_due runs a geometric repack, when the disk has the room its gc needs. Before, a fetch of fewer than 100 objects stayed loose in the mirror, out of the checkout's sight, and the checkout's fetch had the mirror send the target's history again.

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in a release)

Changelog entry (one or two sentences a user of Loom can read without the diff; the release pull request collects these into the release notes):

With LOOM_CODE_COMPILER_SHARE_MIRROR_PACKS on, a commit the mirror fetched in a small fetch no longer makes a compiler-tier checkout fetch the repository's history again: the mirror keeps every fetch as a pack, which the checkout shares.

Why

_share_mirror_packs hard-links the mirror's packs into each checkout and nothing else. Git stores a fetch of fewer than fetch.unpackLimit objects (100 by default) as loose objects, so the usual one-commit fetch of the mirror stayed out of every checkout until the mirror's gc packed it. The checkout's fetch (checkout_fetch_args) then found the target's closure incomplete and fetched it from the mirror; a checkout with no ref yet had nothing to negotiate from and received the mirror's whole history as a pack of its own.

gitrepo._network_git, the runner of every fetch into the mirror (fetch, fetch_many, fetch_branches, fetch_shas, fetch_pull_heads), adds fetch.unpackLimit=1 to the job's git config, so each of them writes a pack. A clone from a local path copied the source's loose objects as they were; clone_mirror now passes --no-local, which makes git pack them.

One pack per fetch adds up between two weekly gcs, and a shared checkout's sandboxed job mounts every pack it links (one --ro-bind per file), so thousands of packs would push bwrap's argv past the kernel's limit. gc_if_due therefore also runs git repack -d -l --geometric=2 when a mirror or checkout holds more than 500 packs a gc may rewrite (code_mirror_gc_pack_limit, default 500), and only under the free-space check the gc has: the repack writes its pack beside the old ones, so when free space is below what a gc would rewrite plus code_mirror_gc_margin_gb, it is skipped with the gc's warning and tried again on the next round. The check asks for the worst case, a rewrite of the whole set; a volume that cannot hold that needs more space. In the mirror it merges the small packs and leaves the large one. The limit sits well below the few thousand packs at which the bind list overflows, and well above git's own 50, because of the checkout cost below.

Measured on a public repository (one 17 GB pack, 3.9 million objects, git 2.43.7), a new shared checkout's fetch of the mirror's head, timed with GIT_TRACE2_PERF:

Mirror state before the checkout's fetch Fetch time Written into the checkout Where the time goes
fully packed 534 s nothing rev-list --objects --not --all (connectivity walk)
one commit fetched with this change (its own pack) 406 s nothing the same walk
one commit fetched as on main (3 loose objects) 1,591 s a 15.4 GB pack pack-objects 746 s (enumerate-objects 404 s, write-pack-file 342 s), index-pack 705 s, then the walk 469 s

Each arm is a new checkout from resolve_checkout with sharing on, then GIT_TRACE2_PERF=<file> git -C <checkout> fetch with checkout_fetch_args(<mirror>, <head>) under auth_env. The middle arm's commit reached the mirror through git -c fetch.unpackLimit=1 fetch, the last one's through a plain git fetch.

Scope and risk

  • One setting on the mirror's network jobs. The same runner also runs ls-remote, which ignores it. The checkouts' own fetches are unchanged.
  • A clone from a local path now copies through the pack protocol (pack-objects in the source, index-pack in the mirror) instead of copying files, so it takes longer on a large repository: 5.6 s instead of 0.0 s for a 127k-object repository. Local-path remotes are meant for tests and small mirrors; a clone over the network already wrote a pack.
  • The mirror gains one small pack per fetch instead of loose objects. The geometric repack keeps them below about 500 between gcs, and the weekly gc --no-prune still merges everything into one pack. Nothing prunes.
  • Each mirror repack drops packs its shared checkouts link, so on its next pass every shared checkout runs its own gc --no-prune: a walk of every reachable object that rewrites almost nothing (0.6 s on a 127k-object repository; a history walk took 406 to 534 s on the 3.9-million-object one in the table). That gc ran once a week before; now it also runs after each repack, about once per 500 mirror fetches.
  • Objects a mirror already holds loose stay loose until its next gc; until then a checkout fetches them as before.
  • docs/operations/code-index-operations.md: the shared-packs paragraph says the mirror's clone and fetches write packs, and Mirror housekeeping names the repack.
  • Not covered: a new checkout's first fetch still spends minutes in git's connectivity walk (rev-list --objects --not --all with no ref to stop at, 406 to 534 s in the table), on a packed mirror too; that is a separate cause, left for its own change.

Compatibility, rollout and rollback

  • Wire: none. One new setting, LOOM_CODE_MIRROR_GC_PACK_LIMIT, default 500, the old constant's value; no default of an existing setting changes.
  • Operator steps: none.
  • Rollback: the mirror's extra packs stay until its next gc merges them.

Tests

  • tests/unit/test_code_compiler_checkout.py::test_a_small_mirror_fetch_keeps_its_objects_in_a_pack (red): one commit fetched into a packed mirror through gitrepo.fetch with real git leaves no loose object. On main it fails with assert 3 == 0.
  • tests/unit/test_code_compiler_checkout.py::test_a_checkout_fetch_after_small_and_large_mirror_fetches_transfers_nothing (red): a shared checkout's first pass, a one-commit mirror fetch, a 150-file mirror fetch, then a second pass with resolve_checkout and the tier's fetch and checkout. It expects no object file of the checkout's own, git rev-list --objects of the target to succeed, and both new files in the working tree; the test mirror is cloned with Loom's gc.auto=0 and maintenance.auto=false, so git's own maintenance does not repack it. On main the checkout's fetch writes a pack of its own and the first assertion fails.
  • tests/unit/test_mirrors.py::test_more_packs_than_the_limit_are_merged_before_the_gc_is_due (red): 55 one-commit fetches give a mirror 56 packs the day after its gc; with code_mirror_gc_pack_limit set to 50 for the test, gc_if_due leaves at most 2, and every object stays reachable. On main the 56 packs stay.
  • tests/unit/test_mirrors.py::test_the_repack_without_room_is_skipped_like_the_gc (red): the same 56 packs with code_mirror_gc_margin_gb above the free space; gc_if_due leaves all 56 and the gc mark untouched. Before the change it merges them.
  • tests/unit/test_mirror_ready.py::test_a_clone_from_a_local_path_keeps_its_objects_in_a_pack (red): clone_and_pin from a local source whose objects are loose gives a mirror with count: 0 and one pack. On main it has count: 3 and no pack.
  • Run here under git 2.56.1, the version CI uses: test_code_compiler_checkout, test_mirrors, test_mirror_ready, test_doc_links and test_public_copy: 388 passed. The checkout transfer test also passed 5 times in a row alone.
  • ruff check, ruff format --check, scripts/gates/mypy_gate.py, function_length_gate.py, check_no_secrets.py, and the docs_reference, settings_example, settings_schema, settings_reference and op_reach_census checks pass. The real-bubblewrap sandbox suite is left to CI.

AI assistance in the code (leave one; writing this description with AI is fine):

  • AI-generated (an agent wrote most of the diff): Claude Code wrote the diff, the tests and the measurement. Checked: I reviewed the whole diff and its tests; the runs listed under Tests are the agent's, against main at the same commit.

  • I can explain every line of this diff and how it interacts with the rest of Loom.

Checklist

  • Local format, lint, type checks and focused tests pass. The full make test-unit and applicable integration results are reported by CI; a full local run is not required before pushing.
  • Generated files are regenerated in this PR, not by hand: the SDK op tables, docs/reference/configuration.md and the docs/reference/ tables (python scripts/codegen/docs_reference.py), the reach manifest, schemas/schema.sql (make schema-dump) and the Codex plugin copies (python3 scripts/codegen/agent_plugin_sync.py).
  • A new migration is additive and numbered after the latest on main; no merged migration is edited.
  • A behaviour change to any file a plugin ships (hooks/, lib/, bin/, skills/, .mcp.json, the Codex plugin-defaults.json) bumps both plugin manifests' version, and no other open PR uses that version.
  • The frontend builds (npm --prefix frontend run build) and its tests pass, if frontend/ changed.
  • Docs under docs/ describe the system as it now is, and this description names any operator steps and wire changes.
  • Repository text has no dates, people, host names, internal namespaces, ticket or decision numbers; the history goes in this description (tests/unit/test_public_copy.py).
  • Commits are signed off (git commit -s), as CONTRIBUTING.md asks.

Note

Medium Risk
Changes mirror clone/fetch and periodic repack behavior on disk-heavy code-index hosts; mispacked mirrors or aggressive repacks could affect shared checkouts and sandbox bind limits, but scope is housekeeping and fetch packaging only.

Overview
Fixes shared compiler-tier checkouts when LOOM_CODE_COMPILER_SHARE_MIRROR_PACKS is on: mirror clone and fetch paths now always persist objects as packs (not loose files), so checkouts that hard-link mirror packs see every fetched commit without re-downloading history.

Mirror network git jobs set fetch.unpackLimit=1; bare clones from local remotes add --no-local so loose source objects are packed. gc_if_due can run git repack --geometric=2 when unkept pack count exceeds the new LOOM_CODE_MIRROR_GC_PACK_LIMIT (default 500), using the same disk headroom rules as git gc, via refactored low-priority git housekeeping.

Docs, example config, schema, and unit tests cover pack retention, repack limits, and skipped repack when disk is tight.

Reviewed by Cursor Bugbot for commit 2f18134. Bugbot is set up for automated code reviews on this repo. Configure here.

…see it

Git stores a fetch of fewer than fetch.unpackLimit objects (100 by default) as loose
objects. A compiler-tier checkout links only the mirror's packs, so the objects of such
a fetch were missing from it. The checkout's own fetch then found the target
incomplete and had the mirror send it again; a checkout with no ref yet received the
mirror's whole history. Mirror fetches now run with fetch.unpackLimit=1, so every
fetch writes a pack that the next tier pass links.

Signed-off-by: Kaloyan Naumov <knaumov@gmail.com>
…tes a pack

With every fetch writing a pack, a mirror between two weekly gcs could gather
thousands of packs, and a shared checkout's sandboxed job mounts each one. Past 50
packs a gc may rewrite (git's gc.autoPackLimit), gc_if_due now runs a geometric
repack, which merges the small packs and leaves the large one.

A clone from a local path copied the source's loose objects as they were; it now
runs with --no-local, so the mirror starts as a pack.

Signed-off-by: Kaloyan Naumov <knaumov@gmail.com>
Each repack makes every shared checkout of the mirror run a full gc, and the
sandbox's bind list overflows only at a few thousand packs, so the trigger sits well
above git's own limit of 50.

Signed-off-by: Kaloyan Naumov <knaumov@gmail.com>
@vercel

vercel Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
loom-docs Ready Ready Preview Nov 28, 2026 9:57pm UTC
loom-telemetry Ready Ready Preview Nov 28, 2026 9:57pm UTC

Request Review

@zlareb1 zlareb1 self-assigned this Nov 28, 2026

@zlareb1 zlareb1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The new repack path needs the disk-space guard used by scheduled GC. A busy mirror can reach the pack limit while the volume is already below its reserve.

Comment thread server/code/app/index/mirrors.py Resolved
The repack writes its new pack beside the old ones, so on a volume already below
the gc margin it could use up the space ingest needs. It now takes the same free
space check as the gc and is skipped, with a warning, when there is no room; the
next round tries again.

Signed-off-by: Kaloyan Naumov <knaumov@gmail.com>
@zlareb1

zlareb1 commented Nov 28, 2026

Copy link
Copy Markdown
Member

The format job fails on the adoption page with the same formatter output on clean main. The pinned formatter passes locally with the repair. PR job · Main job · Repair #1706

@KaloyanNaumov

Copy link
Copy Markdown
Contributor Author

The repack now takes the guard scheduled gc uses, so a mirror without room keeps its packs and waits. The change is in 13f7cf0, with the Mirror housekeeping paragraph updated to say so.

@zlareb1 zlareb1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The repack uses the same disk headroom check as scheduled GC. The low-space probe leaves the pack set and GC mark alone. With sufficient space, the repack starts. The checkout transfer test also passes on the merged tree.

@zlareb1 zlareb1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The completed unit job reports a new tunable-constant failure for the repack threshold. The disk-space finding is fixed. This review supersedes my earlier approval of this head.

Comment thread server/code/app/index/mirrors.py Resolved
@KaloyanNaumov

Copy link
Copy Markdown
Contributor Author

FYI, the git repack job is largely overestimating the needed spaces. My agents have implement accurate estimation, but I asked them to base the loom logic on the stock repack space estimate.

Do you think it's worth to base the logic on an accurate size ETA, or the stock double + margin is fine?

@zlareb1 zlareb1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The rename integration test returns about_naming on this head and on its CI base. The fixture describes a naming claim. Repair #1719 changes it to describe runtime behavior, and the same assertion passes. PR job · Main job · Repair #1719

The pack count past which gc_if_due runs a geometric repack was a module
constant, which test_no_new_tunable_constant rejects. It becomes
code_mirror_gc_pack_limit, default 500, beside the other mirror gc
settings. The tests that lowered the constant set the setting instead.

Signed-off-by: Kaloyan Naumov <knaumov@gmail.com>

@zlareb1 zlareb1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The tunable-constant check reports the same duplicate coverage limit on this head and on clean main. The coverage repair moves the bound report to the store. The same check passes on main with both the coverage and docstring repairs applied. PR job · Main job · Coverage repair #1722 · Docstring repair #1706

Loom's mirror clone writes gc.auto=0 and maintenance.auto=false, but the
_packed_bare fixture cloned with git's defaults. Under git 2.56 the
automatic maintenance repacked that mirror between the fetches, so the
checkout transfer test received objects and failed on every run. The
fixture now clones with the same two settings, and the operations page
names LOOM_CODE_MIRROR_GC_PACK_LIMIT where it described the threshold.

Signed-off-by: Kaloyan Naumov <knaumov@gmail.com>
@KaloyanNaumov

Copy link
Copy Markdown
Contributor Author

The tunable-constant failure is fixed by the setting code_mirror_gc_pack_limit (default 500; references regenerated). The other red jobs on the last run: integration part 1 is main's (1719), and unit part 6 (test_session_content_senders) is red on main too. Unit part 1 failed test_a_checkout_fetch_after_small_and_large_mirror_fetches_transfers_nothing on both heads: its test mirror was cloned without the gc.auto=0 and maintenance.auto=false config that Loom's own clone writes, and git 2.56's automatic maintenance repacked that mirror after the fetches. The fixture now clones as Loom does; the test passes under git 2.56.1.

@zlareb1 zlareb1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The settings catalog now supplies the pack threshold, and the generated defaults match. The pack-limit and low-disk tests pass. I also checked that the mirror fetch and checkout paths preserve the shared-pack behavior.

@zlareb1
zlareb1 merged commit 167d954 into ClickHouse:main Nov 30, 2026
76 of 80 checks passed
@KaloyanNaumov
KaloyanNaumov deleted the pr/mirror-fetch-keeps-packs branch December 1, 2026 10:15
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.

A small mirror fetch stays loose, so a shared compiler-tier checkout fetches its history again

2 participants