fix(gbrain-sync): fold hostname into code-source id hash#1468
Open
0xDevNinja wants to merge 1 commit into
Open
fix(gbrain-sync): fold hostname into code-source id hash#14680xDevNinja wants to merge 1 commit into
0xDevNinja wants to merge 1 commit into
Conversation
Pre-fix `deriveCodeSourceId` hashed the absolute repo path alone, so two
machines with identical home-dir layouts (chezmoi-managed dotfiles,
ansible-provisioned VMs) derived the same id and clobbered each other's
`local_path` in a federated brain. Last-writer-wins, with cryptic "Not a
git repository" errors on the loser.
Hash key is now `${hostname}::${path}`. Conductor worktrees on a single
host stay distinct (path entropy unchanged within a host); cross-machine
federations stop colliding. Legacy path-only-hashed sources age out
naturally — in-place migration would force a brain-wide rewrite for a
minority workflow, and the existing `deriveLegacyCodeSourceId` orphan
cleanup pattern can pick them up in a follow-up if needed.
`GSTACK_HOSTNAME` env var is a test-only knob; production uses
`os.hostname()`.
Fixes garrytan#1414
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
deriveCodeSourceIdnow keys its 8-char hash off${hostname}::${absolute repo path}instead of the path alone.Fixes #1414.
Why
pathHash = sha1(repoPath).slice(0,8)was a function of absolute filesystem path only. Two machines with identical home-dir layouts (chezmoi dotfiles, ansible-provisioned VMs, single-user multi-host fleets) produce identical source ids when both run against a shared brain DB. Last-writer-wins onsources.local_path; baregbrain syncon the loser surfaces a crypticNot a git repositoryagainst the cwd that is a git repo.The v1.29.0.0 "Conductor worktrees of the same repo coexist as separate sources" promise holds within one host because Conductor worktrees live at different paths. It breaks across hosts because the path is the same on both.
Fix
os.hostname()is the cheapest stable host identifier that works on every platform without a privileged read./etc/machine-idis stabler across rename but Linux-specific.GSTACK_HOSTNAMEis a test-only knob; production leaves it unset.Migration
Legacy path-only-hashed sources age out naturally. In-place migration would force a brain-wide rewrite for a minority workflow; the existing
deriveLegacyCodeSourceIdorphan-cleanup pattern can pick them up in a follow-up if a one-shot rewrite is preferred.Out of scope: the TODOS.md P3 entry about cross-remote-host collisions (
github.com/acme/foovsgitlab.com/acme/fooon the same machine). Different axis.Tests
test/gstack-gbrain-sync.test.tscasederives distinct source ids for the same absolute path on different hosts:GSTACK_HOSTNAME=machine-avsGSTACK_HOSTNAME=machine-b→ distinct gbrain-valid ids.gbrainshim is dropped on PATH so the dry-run code stage runs.Rest of file matches the pre-existing baseline on
upstream/main(10 fail locally becausegbrainCLI is not installed in this environment; unchanged by this diff).Need help on this PR? Tag
@codesmithwith what you need.