fix: gstack-brain-sync advances the artifacts worktree after push#1513
Open
alexputici wants to merge 1 commit into
Open
fix: gstack-brain-sync advances the artifacts worktree after push#1513alexputici wants to merge 1 commit into
alexputici wants to merge 1 commit into
Conversation
Without this, the worktree at ~/.gstack-brain-worktree stays at the init commit forever while the parent repo's main branch accumulates artifact commits. gbrain indexes from the worktree path, so users see `gbrain sources list` reporting 0 pages and recent CEO plans / test plans / reviews never become searchable locally. Reproduction: enable artifacts sync, run a few /autoplan or /ship sessions to produce committed artifacts, then `gbrain query` for a filename you just created — no results. Inspection shows `git -C ~/.gstack worktree list` has the worktree pinned at the init SHA while `git -C ~/.gstack rev-parse main` has moved ahead. The fix adds an advance_brain_worktree_to_head helper and calls it on both successful push paths in subcmd_once (normal + rebased retry). It's a no-op when the worktree doesn't exist or the parent HEAD can't be read, so installs that haven't run gstack-gbrain-source-wireup yet are unaffected. Regression test runs --once against a real detached worktree and asserts the worktree HEAD matches the parent HEAD afterwards, plus that the synced file actually appears at the worktree path. Verified the test fails without the fix (worktree stuck at init SHA). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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
gstack-brain-sync --oncecommits + pushes artifacts to the remote, but never advances the local detached worktree at~/.gstack-brain-worktree. gbrain indexes from that worktree path, so the worktree stays at the init commit forever,gbrain sources listreports0 pagesfor the artifacts source, and recent CEO plans / test plans / reviews never become searchable locally.Reproduction
gstack-config set artifacts_sync_mode artifacts-onlyorfull) and rungstack-artifacts-init./autoplan,/ship, etc. so brain-sync runs--discover-newthen--once, producing committed artifacts under~/.gstack/projects/*/.The artifact files exist in
~/.gstackonmainand on the GitHub remote. They just never reach the worktree gbrain scans.Fix
Add a tiny
advance_brain_worktree_to_headhelper and call it on both successful-push paths insubcmd_once(the normal path and the fetch+merge retry path). It's a no-op when the worktree doesn't exist or the parent HEAD can't be read, so installs that haven't rungstack-gbrain-source-wireupyet are unaffected.Why not call
ensure_worktreefromgstack-gbrain-source-wireup? That helper has additional side effects (source registration, jq probes, gbrain CLI calls) and lives in a scriptgstack-brain-syncdoesn't currently source. A 12-line inline helper keeps the patch minimal and the push-success path side-effect-free on the gbrain CLI.Test plan
'--once advances the brain worktree HEAD to match parent after push'intest/brain-sync.test.ts: sets up a real detached worktree at the init commit (mirroringgstack-gbrain-source-wireup), runs--onceagainst it, asserts the worktree HEAD matches the parent HEAD afterwards AND that the synced file appears on the worktree path.bun test test/brain-sync.test.ts— 28/28 pass.bun test test/brain-sync.test.ts test/gbrain-sync-skip.test.ts test/gstack-gbrain-sync.test.ts— 53/53 pass.Diff size
+17 in
bin/gstack-brain-sync(helper + 2 call sites), +45 intest/brain-sync.test.ts(1 regression test). 2 files changed, 62 insertions.🤖 Generated with Claude Code