Skip to content

A configured entry may not share a clone under another remote - #1548

Merged
zlareb1 merged 5 commits into
ClickHouse:mainfrom
KaloyanNaumov:clone-dir-per-remote
Nov 30, 2026
Merged

zlareb1 merged 5 commits into
ClickHouse:mainfrom
KaloyanNaumov:clone-dir-per-remote

Conversation

@KaloyanNaumov

@KaloyanNaumov KaloyanNaumov commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Closes: #1536

TL;DR: A fork and its upstream configured as two entries shared one clone directory, so one namespace indexed the other's commits. When two entries resolve to the same git_dir, the parser now compares their git_remote values after the defaults and skips the later entry if they differ, with a git_dir configuration error naming the holder.

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):

An entry in LOOM_CODE_REPOS_JSON whose git_dir an earlier entry holds with a different git_remote (a fork beside its upstream, or the same repository under a second spelling of its remote) is skipped with a git_dir:<namespace> configuration error instead of sharing that clone.

Why

A derived clone directory names the repository alone (<name>.git), so a fork and its upstream resolve to one bare clone, each fetch moves the other's branch refs, and one namespace indexes the other's commits. The parser keeps the first entry for a git_dir and skips a later entry whose git_remote is a different string. Both values are compared as _entry_clone_fields returns them: an entry that names no remote gets https://github.com/<repo>.git, and an entry for the scalar's repository inherits the scalar's git_dir and git_remote for the fields it does not set. The remotes are compared as strings; the git_dir values are compared by canonical path (symlinks and .. resolved) and by directory identity (st_dev, st_ino) once the directory exists, so a relative git_dir and its absolute path, a symlink, and a case alias on a case-insensitive volume are one clone. Branches of one repository share their clone by spelling the remote the same way. The error names the holder and says to use one spelling of the remote or set a separate git_dir. It counts in loom.code.repos_config_errors and loom code prints it for the skipped namespace.

Refusing keeps every existing deployment's clone where it is. Deriving the directory from host and owner, as repo_registry.git_dir_for does for self-service entries, would avoid the error, but it would move the clone of every existing operator entry on upgrade.

Known limit

On a case-insensitive volume, two spellings of one path that differ only in case pass the check before the clone exists, because neither a canonical path nor a directory identity tells them apart yet. Once the first clone exists, the identity check refuses the other spelling. docs/operations/code-index-operations.md says to use clone paths that differ by more than capitalization. On a case-sensitive volume, paths that differ only in case are distinct clones and both load.

Changed after review

The earlier revisions compared repo_key values and extended repo_key (SSH user, ports per scheme, path case per host, rooted paths) so that two spellings of one repository matched. Following the review, those changes are dropped and repo_key is as on main. The check compares git_remote strings after the defaults instead, so https://github.com/acme/widgets.git and git@github.com:acme/widgets.git on one git_dir are now refused, and the error tells the operator how to fix it. The comparison of git_dir by canonical path stays, and a directory that exists is also compared by identity. A lowercased path key, added in an earlier revision for fresh case-insensitive volumes, is dropped: it also refused distinct directories on a case-sensitive volume. The limit above replaces it.

Scope and risk

The operator-configuration parser only; repo_key, the page-add duplicate checks and self-service entries are untouched. A deployment that has two entries on one git_dir with different remotes (a fork and its upstream, or one repository under two spellings) sees the later entry skipped and reported; any other deployment sees no change. A skipped entry is a configuration error, and any configuration error stops the mirror sweep on every host (it removes nothing while loom.code.repos_config_errors is not 0), so the mirrors, checkouts and lock files of removed repositories stay until the operator fixes the entry; docs/operations/code-index-operations.md says so. Only this check resolves two spellings of one git_dir; mirror grouping and its lock files compare git_dir as written, as on main, so the docs ask for one spelling of a shared git_dir.

Compatibility, rollout and rollback

  • Wire: none.
  • Operator steps: where the new error appears, use one spelling of the remote in every entry on that git_dir, or set a separate git_dir for one entry. On a case-insensitive volume, use clone paths that differ by more than capitalization.
  • Rollback: leaves nothing behind.

Tests

  • tests/unit/test_repos_clone_dir_collision.py: a fork and its upstream on one derived git_dir are refused, and the error names the holder and the fix (test_a_fork_and_its_upstream_do_not_share_a_clone); two branches whose remotes are the same string after the defaults share their clone (test_branches_with_one_spelling_of_the_remote_share_their_clone); https://github.com/acme/widgets.git and git@github.com:acme/widgets.git on one git_dir are refused with the message (test_two_spellings_of_one_remote_are_refused); a separate git_dir admits a fork and its upstream (test_a_separate_git_dir_lets_both_in); a relative git_dir and its absolute path, and a symlink to a held clone, are each one clone and the later entry is refused (test_two_spellings_of_one_clone_are_one_clone, test_a_symlink_to_a_held_clone_is_the_same_clone); a case alias of a held clone and a missing spelling that resolves to a held clone are each one clone (test_a_case_alias_of_a_held_clone_is_the_same_clone, test_a_missing_spelling_of_a_held_clone_is_the_same_clone); two existing directories that differ only in case both load (test_clone_dirs_that_differ_only_in_case_stay_distinct_on_a_case_sensitive_volume, skipped on a case-insensitive volume). On main the fork-and-upstream, two-remote-spellings and the four git_dir spelling tests fail (main has no check); the other three pass on both.
  • The tests of every tests/unit/*repo*, *remote* and test_mirrors* file, plus test_doc_links.py and test_public_copy.py, pass. ruff check, ruff format --check, mypy on repos.py, the mypy and function-length gates and the codegen checks (docs_reference, settings_example, settings_schema, op_reach_census) pass. The full unit suite runs in 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 and the tests. Checked: I reviewed the whole diff and its tests; the gate 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 operator-config parsing only, but misconfigured fork/upstream pairs will see a later entry skipped and mirror sweeps paused while config errors remain; otherwise behavior is unchanged.

Overview
Fixes mis-indexing when two LOOM_CODE_REPOS_JSON entries resolve to the same bare clone but point at different remotes (e.g. fork vs upstream both deriving widgets.git).

While parsing operator config, the server now tracks which namespace “holds” each git_dir and skips later entries whose resolved git_remote (after defaults) does not match the holder, recording a git_dir:<namespace> config error that names the holder and tells operators to unify the remote spelling or use a separate git_dir. Same remote on one clone still allowed (release branches). Collision detection treats paths as one clone via realpath, existing-directory (st_dev, st_ino), and related spellings (symlinks, case aliases).

Operations docs now describe shared-clone rules, this error type, and that non-zero loom.code.repos_config_errors blocks mirror sweep cleanup until fixed. New unit tests cover fork/upstream, remote spelling mismatches, path aliases, and case-sensitive vs insensitive volumes.

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

@cla-assistant

cla-assistant Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@vercel

vercel Bot commented Nov 26, 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 30, 2026 11:39am UTC
loom-telemetry Ready Ready Preview Nov 30, 2026 11:39am UTC

Request Review

@zlareb1 zlareb1 self-assigned this Nov 26, 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.

Two spellings of one clone path still let different remotes share that clone.

Comment thread server/code/domain/index/repos.py Resolved

@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 relative-path collision is fixed and all five clone configuration tests passed. The same directory can still be assigned to different case-sensitive remotes.

Comment thread server/code/domain/index/repos.py Resolved
@KaloyanNaumov
KaloyanNaumov deleted the clone-dir-per-remote branch November 26, 2026 17:57
@KaloyanNaumov
KaloyanNaumov restored the clone-dir-per-remote branch November 26, 2026 17:58
@KaloyanNaumov KaloyanNaumov reopened this Nov 26, 2026
@KaloyanNaumov

Copy link
Copy Markdown
Contributor Author

Fixed in 046dd75 (rebased on main): repo_key keeps the path's case and lower-cases it only on github.com, gitlab.com and bitbucket.org, so /team/Widgets.git and /team/widgets.git on a custom host are two repositories and the later entry sharing a git_dir is refused; test_paths_differing_in_case_on_a_custom_host_are_two_repositories fails on the previous head and passes now. The host set is fixed to those three public hosts. The trade-off is that on a self-hosted forge that folds case (GitLab, Gitea, Forgejo), the page-add check now accepts a second spelling of one repository as a second entry, where main refused it. Is that the trade-off you want, or should an entry be able to say its host folds case?

@cursor cursor 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.

Stale Bugbot comment from a previous run.

Comment thread server/code/domain/index/remote.py Resolved

@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 case-sensitive path and clone-path spelling regressions are fixed. The configuration probe still accepts two distinct SSH remotes for the same clone.

Comment thread server/code/domain/index/repos.py Resolved
@KaloyanNaumov
KaloyanNaumov marked this pull request as draft November 26, 2026 20:49
@KaloyanNaumov

Copy link
Copy Markdown
Contributor Author

Thanks for the review. Converting to draft while I address it; a new head and the replies will follow, so no need to look at this head again.

@KaloyanNaumov
KaloyanNaumov marked this pull request as ready for review November 26, 2026 21:16

@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 two SCP forms now differ. The SSH URL form still aliases the home-relative form.

Comment thread server/code/domain/index/remote.py Resolved
@KaloyanNaumov
KaloyanNaumov marked this pull request as draft November 26, 2026 22:11
@KaloyanNaumov

Copy link
Copy Markdown
Contributor Author

Thanks, I've seen the new comments. Back to draft while I address them; a new head and the replies will follow.

@KaloyanNaumov
KaloyanNaumov marked this pull request as ready for review November 26, 2026 23:26

@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 absolute SSH path test passes. The clone guard still accepts distinct home-relative remotes when their SSH users differ.

Comment thread server/code/domain/index/remote.py Resolved

@cursor cursor 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.

Stale Bugbot comment from a previous run.

Comment thread server/code/domain/index/remote.py Resolved

@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 two-user home-relative SSH regression passes. The clone guard still treats different SSH endpoints on a custom host as one repository.

Comment thread server/code/domain/index/repos.py Resolved

@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 code.read fixture passes valid ranges where the test expects a rejection. The same assertion fails on clean main without the clone guard changes. PR shard · Main shard · Existing repair

@KaloyanNaumov

Copy link
Copy Markdown
Contributor Author

The pytest unit part 3 failure is test_arg_feedback.py::test_the_example_does_not_repeat_a_rejected_value[code.read-arguments0-ranges] (DID NOT RAISE). main at 6fe905b fails the same test in its own unit run, and this PR doesn't touch code.read or arg feedback.

@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 previous SSH port pair now yields distinct keys. The guard still accepts two default-port web endpoints on one clone.

Comment thread server/code/domain/index/remote.py Resolved
@KaloyanNaumov

Copy link
Copy Markdown
Contributor Author

I think it's somewhat wrong to treat Git repositories on the same URL as different, depending on the http or https flag. I also think it was wrong to make the SSH vs HTTP(s) treating them differently, but it's done already.

I'm somewhat unwilling to keep this running onwards, unless this is the confirmed Product Management decision. I've invested a lot in the PR set, so I will do the extra step to complete it. Yet I wouldn't treat them different from PM perspective.

@zlareb1

zlareb1 commented Nov 27, 2026 •

Copy link
Copy Markdown
Member

@KaloyanNaumov what do you mean? I think this is a really edge scenario

@zlareb1

zlareb1 commented Nov 27, 2026

Copy link
Copy Markdown
Member

I think it's somewhat wrong to treat Git repositories on the same URL as different, depending on the http or https flag.

I agree this is an edge case. The fork and upstream sharing a clone is worth fixing. I'd drop the changes to repo_key and keep the check in LOOM_CODE_REPOS_JSON.

When two entries resolve to the same git_dir, compare their git_remote values after applying defaults. Branches can share a clone by using the same remote spelling. If the remotes differ, the error should tell the operator to use one spelling or set a separate git_dir.

@zlareb1

zlareb1 commented Nov 27, 2026 •

Copy link
Copy Markdown
Member

The MCP integration job expects a retry example for a request that supplies its organization. Clean main failed the same assertion without this PR's changes. The merged fix checks bearer and explicit scope separately, and that main run passed. PR job · Failing main job · Merged fix #1634 · Passing main run

@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 two unit failures also reproduce on the exact clean base. The range fixture sends line pairs that code.read now accepts, and the tunable-constant check flags the fixed documentation cap. Both checks pass on current main after the fixes in #1634. Range job · Cap job · Passing main CI

A derived clone dir names the repository alone, so a fork and its upstream
resolve to one bare clone and each fetch moves the other's branch refs. When
two LOOM_CODE_REPOS_JSON entries resolve to the same git_dir, the parser
compares their git_remote values after the defaults and skips the later entry
if they differ, with a git_dir configuration error that names the holder and
says to use one spelling of the remote or set a separate git_dir.

Signed-off-by: Kaloyan Naumov <knaumov@gmail.com>
A relative git_dir and its absolute path, or a symlink to a held clone, are
one bare clone; compared as written, two remotes could still fetch into it.

Signed-off-by: Kaloyan Naumov <knaumov@gmail.com>
@KaloyanNaumov KaloyanNaumov changed the title A configured entry may not share a clone with another repository A configured entry may not share a clone under another remote Nov 28, 2026
@KaloyanNaumov

Copy link
Copy Markdown
Contributor Author

When two entries resolve to the same git_dir, compare their git_remote values after applying defaults.

Done in cd1401e, as you proposed. repo_key is back to main, and the check stays in the LOOM_CODE_REPOS_JSON parser: when two entries resolve to the same git_dir (canonical path, as before), it compares their git_remote after the defaults (an entry with no remote gets the scalar's remote for the scalar's repository, else https://github.com/<repo>.git). Branches with one spelling share the clone. Different remotes skip the later entry with a git_dir error that names the holder and says "use one spelling of the remote, or set a separate git_dir". Dropped: the repo_key changes (SSH user, ports, schemes, case, rooted paths) and their tests. The tests cover a fork plus upstream refused, two branches with one spelling shared, https://… plus git@github.com:… refused with the message, and two spellings of one git_dir (relative and absolute, and a symlink) still seen as one clone.

@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.

Comparing the final remote strings fixes the earlier endpoint cases. The clone guard still admits different remotes for one directory on a case-insensitive volume.

Comment thread server/code/domain/index/repos.py Resolved
`_clone_taken` keyed its holders by `realpath(git_dir)`, which keeps the
spelling it is given. On a case-insensitive volume `Widget.git` and
`widget.git` are one directory under two keys, so two entries with different
remotes both loaded and their fetches moved the same refs.

Each entry is now held under its canonical path and, once `git_dir` exists,
also under its `(st_dev, st_ino)`; it collides with a holder when either key is
held. Keying by identity alone would let a directory that does not exist yet
(`missing/../widgets.git`) and an existing `widgets.git` slip past each other,
as a path key and an identity key never compare. The cost is one `realpath`
per entry plus one `os.stat` while the directory exists, no walk over the held
clones. A stat that raises OSError (directory missing, or removed while the
config is parsed) leaves the path key alone. An entry with the held remote
still shares the clone; one with another remote is skipped with the `git_dir`
error.

Two entries naming a directory that is not created yet, with spellings that
differ in case, are still told apart until the first clone creates it.

`known_repo_count` no longer says it does no I/O.

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 inode check catches the earlier case once the clone directory exists. The same entries still pass validation on a fresh volume before either clone has been created.

Comment thread server/code/domain/index/repos.py Resolved

@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 format and unit jobs reproduce the adoption formatting and docstring cap failures from clean main. Both checks pass with the tracked repair. Format job · Unit job · Repair #1706

Two entries whose git_dir differ only in the case of the last component
passed validation on a fresh volume, because no directory existed yet to
compare by identity. Hold each clone dir under its canonical path with
the last component lowercased as well, so they collide with the existing
error. On a case-sensitive host this also refuses two distinct directories
spelled Widget.git and widget.git with different remotes; the error says
to set a separate git_dir.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Signed-off-by: Kaloyan Naumov <knaumov@gmail.com>
@KaloyanNaumov

Copy link
Copy Markdown
Contributor Author

You're right: on a fresh volume neither directory exists, so the inode key has nothing to compare. The clone dir is now also held under its canonical path with the last component lowercased, so Widget.git and widget.git with different remotes are refused before either exists, with the same git_dir error. On a case-sensitive host this also refuses two distinct directories that differ only in case; the error says to set a separate git_dir. Existing entries of that shape skip the later one after the upgrade, as the description now says. Test added for the fresh-volume case; it fails without the change.

@cursor cursor 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.

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

Reviewed by Cursor Bugbot for commit c97ad5e. Configure here.

Comment thread server/code/domain/index/repos.py Resolved

@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 clone guard still accepts fresh aliases when a parent directory differs in case. I also verified the case-sensitive volume finding. The same comparison rejects two distinct destinations there.

Comment thread server/code/domain/index/repos.py Resolved

@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 flags _COVERAGE_ROWS and DOCSTRING_MAX_LINES on this head and on clean main. The same test passes with both repairs applied. PR job · Coverage repair #1722 · Docstring repair #1706

… limit

The lowercased last component made two clone paths that differ only in case
collide, which also refused two distinct directories on a case-sensitive
volume. A clone dir is held under its canonical path and, once it exists,
under its (st_dev, st_ino), so case-sensitive volumes accept both spellings
and a case-insensitive volume is caught as soon as the directory exists.

Before the first clone, two spellings of one path on a case-insensitive volume
still pass. The operations guide names this and asks for clone paths that
differ by more than capitalization.

The test creates both directories and asserts both entries load; it is
skipped on a case-insensitive volume.

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 fork and upstream no longer share the derived clone path. I checked recovery of existing case aliases on a case-insensitive volume and ran the clone-collision suite. Eight tests passed and the case-sensitive-only case was skipped. The operator guide records the bootstrap limitation before a directory exists.

@zlareb1
zlareb1 merged commit 6e06f33 into ClickHouse:main Nov 30, 2026
83 of 84 checks passed
@KaloyanNaumov
KaloyanNaumov deleted the clone-dir-per-remote 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 fork and its upstream configured as two entries share one bare clone and overwrite each other's branches

2 participants