Skip to content

gbrain sync --strategy code deleted the working directory (federated source with local_path, no --url) #1881

@zaqwery

Description

@zaqwery

Summary

Running /sync-gbrain (incremental) deleted my entire working directory. The code-index stage (gbrain sync --strategy code) removed the source's local_path — which was my actual repo working tree, not a managed clone.

/Users/.../tt-flutter-app  →  gone (not in Trash, no APFS snapshot)

Environment

  • gstack: v1.55.1.0 (auto-upgraded from v1.55.0.0 at the start of the same /sync-gbrain run)
  • gbrain: gbrain0.42.8.0
  • engine: pglite (local-stdio MCP mode)
  • macOS (Darwin 25.1.0, APFS), zsh

The source that got wiped

{
  "id": "gstack-code-app-3556c6de-e0c7ab",
  "local_path": "/Users/.../tt-flutter-app",
  "federated": true,
  "page_count": 8018,
  "last_sync_at": null
}

It was registered (by an earlier /setup-gbrain / /sync-gbrain --full) pointing local_path directly at the live repo working tree. Note last_sync_at: null.

What happened (from ~/.gstack/.gbrain-sync-state.json)

code        ran=true ok=false  "gbrain sync --strategy code --source gstack-code-app-3556c6de-e0c7ab exited 1"  (status: failed, source_path = the repo)
memory      ran=true ok=true   "gbrain import: 3 imported, 128 unchanged"
brain-sync  ran=true ok=false  "gstack-brain-sync exited undefined"

The orchestrator surfaced code … ERR exited 1 but did not warn that the source tree had been removed. The very next shell command failed with Working directory ... was deleted; shell cwd recovered. The directory and its .git were gone.

Top of the code-stage output also showed:

Embedding model "openai:text-embedding-3-large" requires OPENAI_API_KEY.

so the code stage was already in a failing/degraded path when whatever destructive step ran.

Impact

  • Working tree + .git destroyed. Two unpushed local commits lost (recovered manually from the session transcript + remote).
  • The CLAUDE.md guidance even warns "URL-managed sources can auto-reclone" — but this source had no --url, just a path. A path-registered source should never delete its local_path.

Expected

  • gbrain sync --strategy code must treat local_path as read-only. It should index, never rm/reclone over a user's working tree.
  • If a reclone is ever attempted, require an explicit opt-in AND refuse when the path is a git working tree with uncommitted changes or unpushed commits.
  • On code-stage failure, abort before any destructive filesystem op and report loudly.

Repro (suspected)

  1. Register a federated code source with local_path = a live git repo (no --url).
  2. Have the configured embedding model require an API key that isn't set (forces the code stage to error).
  3. Run /sync-gbrain. Code stage exits 1; the local_path tree is removed.

Originally filed at garrytan/gstack#1854

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