Skip to content

Advance the gbrain worktree at the end of every sync, after its commit (#2516 follow-up) - #4179

Closed
extremenelson wants to merge 5 commits into
garrytan:mainfrom
extremenelson:fix/brain-worktree-advance-after-commit
Closed

extremenelson wants to merge 5 commits into
garrytan:mainfrom
extremenelson:fix/brain-worktree-advance-after-commit

Conversation

@extremenelson

@extremenelson extremenelson commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Why (in your own words)

gbrain indexes ~/.gstack-brain-worktree, a detached worktree of ~/.gstack. Since #2516 the drain advanced that worktree, but at the start of gstack-brain-sync --once, before the drain's own commit, and at most once per 24h (~/.gstack/.brain-worktree-last-advance). So the brain was always missing what gstack had just published: a new learning or plan reached gbrain only after a later drain, a day or more afterwards. I hit this on my own machine, where the worktree kept lagging ~/.gstack and I had to git checkout --detach it by hand to get new artifacts into search.

This PR moves the advance to the drain's EXIT trap, after its commit and any merge from the remote, and drops the 24h window: every drain that finds the worktree behind advances it. An interrupted drain (INT/TERM) skips it. A failed or refused advance (for example a dirty worktree) warns once and holds retries for 24h via ~/.gstack/.brain-worktree-advance-failed, so the warning does not repeat at every skill start; a successful advance clears the hold. The no-force-remove guarantees of --advance-only are unchanged.

A second, smaller fix rides along: gstack-artifacts-init asked gh auth status and glab auth status on every run, but only the "which git host?" choice uses the answers. Without a glab config, glab auth status can block for ~30s, so every init --remote paid that wait, and the brain-sync tests that set up an artifacts repo sat right on their 30s timeout (most of brain-sync.test.ts timed out on my machine, on main as well). The checks now run only inside the branch that makes the choice.

Live evidence

Before/after with the same script: a fresh HOME, gstack-artifacts-init --remote <bare repo>, a detached brain worktree, one queued learning, one gstack-brain-sync --once.

=== BEFORE (main @ aa46032f2) ===
$ gstack-brain-sync --once
  advance-only: up-to-date at 3b6d0ea8e8df9d4d1ae72ec39c791200e6c9c924
~/.gstack HEAD:               8a0c154 sync: 1 file(s) | 2026-11-09T00:40:36Z
~/.gstack-brain-worktree HEAD: 3b6d0ea chore: gstack-artifacts-init
learnings.jsonl in worktree:  NO

=== AFTER (this branch) ===
$ gstack-brain-sync --once
  advance-only: advanced .../.gstack-brain-worktree to 0f543205022b527c13eb48ad76524cb73319d760
~/.gstack HEAD:               0f54320 sync: 1 file(s) | 2026-11-09T00:40:37Z
~/.gstack-brain-worktree HEAD: 0f54320 sync: 1 file(s) | 2026-11-09T00:40:37Z
learnings.jsonl in worktree:  yes

The glab wait, traced with a timestamped PS4 on main, and timed directly:

31s before: + gstack-artifacts-init:118: glab auth status

$ time (HOME=$(mktemp -d) glab auth status)   # no glab config
  30.235 total
$ time (glab auth status)                       # my real config
  0.767 total

Tests (macOS, Bun):

# related suites, with a glab that exits at once so both sides avoid the 30s wait
branch: 202 pass / 1 fail / 0 timeouts
main:   200 pass / 1 fail / 0 timeouts
failing on branch only: (none)
# the shared failure, also on main:
#   brain-sync.test.ts:756 "publish-removals refuses to push a retained commit that adds a case alias"
#   Expected "error", Received "push_failed"

# test/gbrain-source-worktree-advance.test.ts, real glab on PATH
9 pass / 0 fail, 3.0s   (the 3 new tests fail on main)

# test/gstack-artifacts-init.test.ts
32 pass / 1 fail — the 2 new "never asks gh or glab for their auth status" tests
fail on main and pass here; the failure ("partial allowlist assembly failure
preserves the original…") fails identically with main's script.

Scope

  • Changed: bin/gstack-brain-sync (advance moved to the EXIT trap, 24h throttle replaced by a 24h hold after a failure), bin/gstack-artifacts-init (auth checks only where the host choice is made), bin/gstack-brain-uninstall (removes the new stamp), comments in bin/gstack-gbrain-source-wireup, docs/gbrain-sync.md, tests, changelog fragment.
  • Verified live by: the before/after reproduction above; deploying the branch to my own ~/.claude/skills/gstack and running a drain against my real ~/.gstack (worktree and parent on the same commit, no failure stamp).
  • Did NOT test: Linux or Windows; the full bun run test suite; paid evals (eval:bg:pr). I ran only the brain-sync, wireup, artifacts-init, egress, migration and decision suites listed above.

Liveness proof (required for external contributors)

image

Checklist

🤖 Generated with Claude Code

extremenelson and others added 5 commits November 8, 2026 18:15
…garrytan#2516)

gstack-brain-sync --once moved ~/.gstack-brain-worktree forward at the
start of the drain, before the drain's own commit, and at most once per
24h. gbrain therefore always indexed a snapshot that was missing the
artifacts gstack had just published, often for more than a day.

The advance now runs from the EXIT trap, after the commit and any merge
from the remote, whenever the worktree is behind. An interrupted drain
(INT/TERM) skips it. An advance that leaves the worktree behind (an
error, or a refusal such as local changes) warns and records
~/.gstack/.brain-worktree-advance-failed, which holds further attempts
for 24h so the warning does not repeat at every skill start; a
successful advance clears it. gstack-brain-uninstall removes the new
stamp along with the old .brain-worktree-last-advance.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…oice is needed

The auth status of gh and glab only feeds the "which git host?" choice,
which runs when there is no --remote, no existing remote and no --host.
init still asked both CLIs every time, and `glab auth status` with no
glab config blocks for ~30s on some machines. Every `init --remote` paid
that wait, including each test that sets up an artifacts repo, which
pushed those tests past their 30s timeout.

The checks now run inside the branch that makes the choice.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@trunk-io

trunk-io Bot commented Nov 9, 2026

Copy link
Copy Markdown

Merging to main in this repository is managed by Trunk.

  • To merge this pull request, check the box to the left or comment /trunk merge below.

After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here

@extremenelson
extremenelson marked this pull request as ready for review November 9, 2026 01:11
@capy-ai

capy-ai Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

Thanks @extremenelson, the before/after makes this clear. On main at 119ed92 the brain-worktree advance runs near the start of the drain and at most once per 24 hours, so gbrain misses what that drain just committed. We're picking this up for a crew rewrite on current main, crediting you as co-author. It touches bin/gstack-brain-sync, where another fix is in flight, so it will follow that one.

@capy-ai

capy-ai Bot commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

Following up: we're taking this. Advancing the brain worktree before the drain's own commit leaves gbrain a drain behind on every new learning and plan. It will be rebuilt on current main with you credited as co-author, and this PR will be closed with a link when it lands, after November 21.

@capy-ai

capy-ai Bot commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Thank you for this. We're picking up the idea. A maintainer agent working through a batch of fixes (our tracking thread GSTA-804) will first reproduce the problem on current main. If it reproduces, the agent rebuilds the fix on main with you credited as co-author, because we don't merge outside branches directly, and we'll close this PR with a link when it lands. If it no longer reproduces, we'll close this and say what changed.

capy-ai Bot added a commit that referenced this pull request Nov 22, 2026
…west timeline rows (#4685)

`/sync-gbrain` and `gstack-decision-search --semantic` now find a brain
host's artifacts source through `GSTACK_BRAIN_SOURCE_ID`, planning
skills read their product and brand digests from current gbrain, and the
brain gets each sync's newest artifacts and timeline rows.

Why: five outside reports (#4443, #4327, #4265, #4179, #4362), each
reproduced on main by a test that fails before this change and passes
after it.

Nothing to do unless your artifacts source lives outside
`~/.gstack-brain-worktree`; then set `GSTACK_BRAIN_SOURCE_ID` to its id.

Co-authored-by: Barack-zero-to-one <[email protected]>
Co-authored-by: exGeni <[email protected]>
Co-authored-by: atharva081106 <[email protected]>
Co-authored-by: extremenelson <[email protected]>
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
Review-Finding: p1/specialist-batched#1 reader=testing
Review-Finding: p1v/outside-voice#2 reader=outside-voice
@capy-ai capy-ai Bot closed this in #4685 Nov 22, 2026
@capy-ai

capy-ai Bot commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Thank you! We rebuilt the worktree-advance fix on current main in #4685, which is now merged, with you credited as co-author. Every drain now advances the brain worktree after its own commit, and the advance is skipped on drains that refuse a publish. The glab auth status change was left out to keep the PR focused.

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.

1 participant