Skip to content

bug: sync silently no-ops with misleading 'Already up to date' when target path has detached HEAD #574

@kengwei

Description

@kengwei

Summary

gbrain sync --repo <path> exits 0 with output Already up to date. when the target path's git working tree is in detached HEAD state. New files in that path are never ingested. The underlying git pull --ff-only failure is logged as a warning, but no error surfaces to the caller — making this very confusing to debug.

Repro

# Set up a worktree in detached HEAD state
git worktree add /tmp/brain-detached <commit-sha>   # detached
echo "test content" > /tmp/brain-detached/test.md

# Try to sync
gbrain sync --repo /tmp/brain-detached --source my-source

Observed output

You are not currently on a branch.
Please specify which branch you want to merge with.
See git-pull(1) for details.

    git pull <remote> <branch>

Warning: git pull failed: Command failed: git -C /tmp/brain-detached pull --ff-only
You are not currently
Already up to date.

Exit code 0. gbrain.get_ingest_log shows zero new entries. The new file is never ingested.

Expected

One of the following:

  • (a) Hard-fail when git pull fails so callers see the error and exit non-zero
  • (b) Detect detached HEAD upfront, skip the pull, and still ingest local-only changes from the working tree
  • (c) Print "Sync skipped — worktree in detached HEAD" and exit non-zero, instead of "Already up to date."

Why this happens in real workflows

This isn't an exotic state. The gstack gstack-brain-sync helper creates a worktree at ~/.gstack-brain-worktree for federation; if the user's main worktree (~/.gstack) is on main, the brain worktree gets stuck in detached HEAD because git won't let two worktrees check out the same branch. Every subsequent manual gbrain sync --repo <worktree> silently no-ops without warning the user.

Environment

  • gbrain v0.27.0
  • macOS 25.4.0 (arm64)
  • Bun 1.x
  • Reproduced in production federation setup

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions