Skip to content

v1.92.38.0 fix(brain-sync): set local edits aside around the retry merge and say why it failed (#3704) - #3728

Merged
capy-ai[bot] merged 5 commits into
mainfrom
gsta209-brain-sync-retry-merge
Nov 1, 2026
Merged

capy-ai[bot] merged 5 commits into
mainfrom
gsta209-brain-sync-retry-merge

Conversation

@garrytan

@garrytan garrytan commented Oct 31, 2026 •

Copy link
Copy Markdown
Owner
{
  "schema_version": 1,
  "pr": 3728,
  "head": "fc1aa530f8c0a347ceee0568b266bcbb185d0922",
  "version": "1.91.377.0",
  "base": "main",
  "gate": {
    "brain-sync": {
      "pass": 93,
      "fail": 0,
      "skip": 0
    },
    "brain-sync-windows-paths": {
      "pass": 5,
      "fail": 0,
      "skip": 0
    }
  },
  "session_kind": "unattended",
  "head_tree": "6c92fbe3be7e31ced0d55b863416405d129fe5f8",
  "product_patch_id": "d6f8a0b5920fc642e52231a5196cbfdc1f3d0b03",
  "gstack_version": "1.91.377.0",
  "review_depth": {
    "depth": "standard",
    "class": "code",
    "runtime_lines": 61,
    "rules": "150435b0a543019a",
    "base": "c830c9b8bafaf2a2327f6ef4cd3a133ad5939731",
    "registry": "c830c9b8bafaf2a2327f6ef4cd3a133ad5939731",
    "gate_scan": {
      "tagged": 0,
      "head": "fc1aa530f8c0a347ceee0568b266bcbb185d0922"
    },
    "reasons": [
      "runtime=61>50"
    ]
  },
  "pregate": "requires-remote cleared @6c92fbe3be7e (1 checks, current for fc1aa530f8c0)",
  "requires_remote": [
    "free-tests.yml/macos-named-regressions: https://github.com/garrytan/gstack/actions/runs/41231843190",
    "windows-free-tests.yml/windows-free-shard: https://github.com/garrytan/gstack/actions/runs/41231843288",
    "pregate.json/remote_gate: remote-gate tree=6c92fbe3be7e tests=3754"
  ],
  "issues": {
    "fixes": [
      3704
    ],
    "refs": [],
    "flakes": []
  },
  "docs": {
    "status": "updated",
    "scope": "docs/ and README.md (brain-sync references: docs/gbrain-sync.md, docs/gbrain-sync-errors.md, docs/troubleshooting.md)"
  },
  "review_loop": {
    "passes": 2,
    "blocking_found": 5,
    "deferred": 0,
    "noted": 5,
    "fixed": 3,
    "scope": "frozen",
    "fix_checks": 1,
    "dispatches": {
      "specialist": 6
    }
  }
}

What changed

Before: on main, a rejected push whose retry merge meets a local edit stays push_failed and hides git's reason. After: local edits to the files the merge changes are set aside and put back, the remote version wins a real conflict with the local edit kept in a named stash, and push_failed says why.

Before: on main, a rejected push whose retry merge meets a local edit stays push_failed and hides git's reason. After: local edits to the files the merge changes are set aside and put back, the remote version wins a real conflict with the local edit kept in a named stash, and push_failed says why.

Before/after as text: Before: on main, a rejected push whose retry merge meets a local edit stays push_failed and hides git's reason. After: local edits to the files the merge changes are set aside and put back, the remote version wins a real conflict with the local edit kept in a named stash, and push_failed says why.
--- Before · shot-before.txt · captured output
+++ After · shot-after.txt · captured output
+$ bun test test/brain-sync.test.ts   # this branch, b2d5e17
-$ bun test test/brain-sync.test.ts -t "without wedging (#3704)"   # main c830c9b, tests from 67234a6
 (pass) a dirty tracked file the remote did not touch rides through the merge
+(pass) a dirty tracked file the remote also changed no longer leaves the push failed
+(pass) a local deletion of a file the remote changed keeps the remote file and stashes the deletion
+(pass) a local edit of a file the remote deleted keeps the deletion and stashes the edit
+(pass) a conflicting file whose name looks like a pattern resets only itself
+(pass) a file that never checks out clean does not strand the other local edits
+(pass) a stash push that saves nothing never pops an older stash entry
+(pass) a conflicting merge is aborted and git's reason reaches the status
-Expected: "ok"
-Received: "push_failed"
-(fail) a dirty tracked file the remote also changed no longer leaves the push failed
-Expected to contain: "local edits to developer-profile.json conflicted"
-Received: "pushed 1 file(s) after rebase"
-(fail) a local deletion of a file the remote changed keeps the remote file and stashes the deletion
-Expected: "ok"
-Received: "push_failed"
-(fail) a local edit of a file the remote deleted keeps the deletion and stashes the edit
-Expected to contain: "Merge conflict in developer-profile.json"
-Received: "push failed: To /tmp/brain-sync-remote-Fe4wML; commit retained locally, will retry next run"
-(fail) a conflicting merge is aborted and git's reason reaches the status
 
+ 93 pass
+ 0 fail
+Ran 93 tests across 1 file. [152.71s]
- 1 pass
- 4 fail
 

Proof

The bug is real and reproduces on current main. Commit 67234a6 adds the five #3704 tests first. Run against main's bin/gstack-brain-sync (main is now c830c9b; the lane first saw the same result on 5ba425a), four of the five fail:

(fail) a dirty tracked file the remote also changed no longer leaves the push failed
  Expected: "ok"   Received: "push_failed"
(fail) a local deletion of a file the remote changed keeps the remote file and stashes the deletion
  Expected to contain: "local edits to developer-profile.json conflicted"   Received: "pushed 1 file(s) after rebase"
(fail) a local edit of a file the remote deleted keeps the deletion and stashes the edit
  Expected: "ok"   Received: "push_failed"
(fail) a conflicting merge is aborted and git's reason reaches the status
  Expected to contain: "Merge conflict in developer-profile.json"
  Received: "push failed: To /tmp/brain-sync-remote-Fe4wML; commit retained locally, will retry next run"
 1 pass
 4 fail

The status shows git's To <remote> banner instead of the reason, and the retry hits the same refusal on every run. On main, the committed-conflict test stops at that status check before it reaches its MERGE_HEAD check, so this run does not show the leftover MERGE_HEAD directly. The old code ran git merge with no --abort. The three tests added in review fail on the pre-fix head 0cbf009 and pass here. Two of them, the pattern-like file name and the never-clean file, also exercise behavior main doesn't have.

Why

"brain-sync: push_failed never clears when dirty tracked files overlap incoming commits" (#3704). The reporter's ~/.gstack sat in push_failed for about a day, retried at the end of every skill, with 1085 items queued in .brain-queue.d and the clone 2 commits ahead and 40 behind. Now the retry merge sets aside your uncommitted edits to the files it changes, merges, and puts them back. When an edit really conflicts, the other machine's version stays, your edit is kept in a stash the status names along with the command that restores it, and push_failed carries git's actual reason.

Blast radius

One function in bin/gstack-brain-sync (merge_origin_keeping_local_edits), called only on the rejected-push retry path in subcmd_once, plus the push_failed status text. It runs only local git commands inside ~/.gstack: diff, stash push/pop, merge and merge --abort, checkout, rm --cached, reset. It touches no network beyond the existing push, reads no new environment variables or secrets, and changes no file or shell permissions, workflows, setup or dependencies. Every path is passed with --literal-pathspecs. Only paths that differ between HEAD and origin/<branch> are stashed, so other local edits stay in place. Only a stash entry this run created is popped. A conflicting local edit is never published over the peer's change, because the merged version stays in the working tree and nothing re-queues the old copy. Evidence rung: test/brain-sync.test.ts reproduces each case (93 pass), and the remote pregate ran the selected free tier (160 files, 3754 tests, 0 failed).

Approvals

Date Asked Exact words Outcome Covers Still pending
2026-10-31 Approve the plan "GSTA-209: gbrain sync bugs (#3704, #3539 / PR #3552)" (autoplan run autoplan-20261031175420, 3 decisions) “do it” (GStack Minder, relayed by agent:jam_01M69H5VCA272WFHCN181RXDXP, relayed by agent:jam_01M69H5VCA272WFHCN181RXDXP) approved the reviewed plan (sha256 b19bf80a5332), every recommendation taken none
2026-10-31 Approve the plan "GSTA-209: gbrain sync bugs (#3704, #3539 / PR #3552)" (autoplan run autoplan-20261031175420, 3 decisions) “Do it: A1, B1, C1. ... For B1, the status must name the stash ref and give the exact command to get the local edit back, and add a test that the stashed edit survives a second sync run. ... Build, /ship, READY unstamped.” (GStack Minder, relayed by agent:jam_01M69H5VCA272WFHCN181RXDXP, relayed by agent:jam_01M69H5VCA272WFHCN181RXDXP) approved the reviewed plan (sha256 b19bf80a5332), every recommendation taken none

Source: gstack-approvals record for gsta209-brain-sync-retry-merge (display only; not an approval citation).

Summary

A rejected brain-sync push could stay stuck forever. The retry merge refused because of uncommitted edits, git's reason was thrown away, and every later run hit the same refusal. The retry merge now sets those edits aside and puts them back, aborts a failed merge cleanly, keeps the remote version on a real conflict with the local edit saved in a named stash, and reports git's reason. Review tightened the set-aside step, so it now covers only the paths the merge changes, reads them literally, and pops only this run's own stash entry.

Test Coverage

All new code paths have test coverage except the fallback when stash pop fails without a conflict (noted below).
Tests: 85 → 93 (+8 new) in test/brain-sync.test.ts.
Tests ran: brain-sync 93
Tests ran: brain-sync-windows-paths 5
Tests ran: typecheck count unavailable

Pre-Landing Review

Pass 1 (specialists for testing, security and state machines; native adversarial; outside voice on openai/gpt-6.1-sol) found three problems at the blocking floor, all fixed in b2d5e17 with tests that fail first: pattern-like file names reset unrelated local edits during conflict cleanup, a stash push that saved nothing made the pop consume an older stash, and stashing every dirty file let one never-clean file strand all local edits in the stash. A fix-check on the fix range found nothing blocking.
REVIEW_LOOP: passes=2 blocking_found=5 deferred=0 noted=5 fixed=3 scope=frozen fix_checks=1 dispatches=6
Gate edits: none detected (GATE_SCAN tagged=0 at b2d5e17)
Outside review: openai/gpt-6.1-sol, completed, 3 findings (two fixed, one noted below).

Review notes

Below the blocking floor; recorded here and not fixed in this PR.

  • Untracked files still block the merge (adversarial). When the remote adds a path that exists locally as an untracked file, git still refuses, as it does on main; the status now names it.
  • File-to-directory swap (outside voice). The local edit is kept in the named stash, but the printed restore command doesn't work for that case.
  • The stash note lives only in that run's status (adversarial). A later sync overwrites it, and stash entries are never dropped automatically.
  • A committed conflict still stops sync until it's resolved (adversarial); the status now says why.
  • Untested fallback (testing): stash pop failing without a conflict reports push_failed and keeps the stash, with no dedicated test.
  • Concurrent writers (testing): a tracked file rewritten mid-merge can make the pop fail. Stashing only the paths the merge changes narrows this window.
  • Staged-only change (fix-check): a staged change to a path the remote didn't touch now blocks the merge until the next drain commits the index.

Exploratory QA

Smoke probes passed on 0cbf009: the #3704 tests, and the merge helper run in a scratch repo with two conflicting files, one with a space in its name, where the printed restore command brought both edits back. No browser surface.

Design Review

No frontend files changed, so design review was skipped.

Eval Results

No prompt-related files changed, so evals were skipped.

Issues

Fixes #3704

TODOS

No TODO items completed in this PR.

Documentation

Status: updated. Two authored docs were edited to match the brain-sync retry-merge fix. No blockers.

Scope: base c830c9b to head b2d5e17 (bin/gstack-brain-sync, changelog.d/gsta209-brain-sync-retry-merge.md, test/brain-sync.test.ts). The tree had no staged, unstaged or untracked content. Docs were found by searching for brain-sync references and reading the matching sections of the gbrain-sync docs and troubleshooting.

Documentation health:

  • docs/gbrain-sync-errors.md: updated. The push failed entry now explains git's error line and the added merging origin failed: <reason> suffix.
  • docs/gbrain-sync.md: updated. Two-machine conflicts now covers the rejected-push merge, the stash that keeps conflicting local edits, and the restore command.
  • changelog.d fragment: reviewed, consistent with the code, not edited.

Coverage debt: the new behavior has reference text only, with no how-to or tutorial. This is reported, not filled. A follow-up /document-generate could cover it. No architecture diagrams were affected.

Test plan

Fixes #3704

garrytan and others added 5 commits October 31, 2026 18:07
…al edits (#3704)

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
… why it failed (#3704)

After a rejected push, git refused the fetch-and-merge whenever a file it would update had uncommitted local edits, and brain-sync discarded git's error, so every later run hit the same refusal and stayed push_failed. The merge now stashes tracked edits first and restores them after; a failed merge is aborted; a conflicting restore keeps the merged version in the working tree and names the stash and the restore command in the status. push_failed carries git's merge reason and the real push error line.

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
…ad them literally, and pop only our own stash entry (#3704)

Pre-landing review fixes: a pattern-like conflicting file name no longer resets unrelated local edits, a stash push that saves nothing no longer pops an older entry, and a file that never checks out clean no longer strands every other local edit in the stash.

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
…sh_failed reason (#3704)

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
@trunk-io

trunk-io Bot commented Oct 31, 2026 •

Copy link
Copy Markdown

😎 This pull request was merged.

@github-actions github-actions Bot changed the title fix(brain-sync): set local edits aside around the retry merge and say why it failed (#3704) v1.92.38.0 fix(brain-sync): set local edits aside around the retry merge and say why it failed (#3704) Nov 1, 2026
@capy-ai
capy-ai Bot merged commit ab2852f into main Nov 1, 2026
62 checks passed
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.

brain-sync: push_failed never clears when dirty tracked files overlap incoming commits (multi-machine artifacts repo)

1 participant