Repository navigation
v1.92.38.0 fix(brain-sync): set local edits aside around the retry merge and say why it failed (#3704) - #3728
Merged
Merged
Conversation
…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>
|
😎 This pull request was merged. |
Merged
3 tasks done
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.
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/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.
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: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 itsMERGE_HEADcheck, so this run does not show the leftoverMERGE_HEADdirectly. The old code rangit mergewith 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
~/.gstacksat inpush_failedfor about a day, retried at the end of every skill, with 1085 items queued in.brain-queue.dand 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, andpush_failedcarries 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 insubcmd_once, plus thepush_failedstatus text. It runs only local git commands inside~/.gstack:diff,stash push/pop,mergeandmerge --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 andorigin/<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.tsreproduces each case (93 pass), and the remote pregate ran the selected free tier (160 files, 3754 tests, 0 failed).Approvals
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 popfails 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.
stash popfailing without a conflict reportspush_failedand keeps the stash, with no dedicated test.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:
push failedentry now explains git's error line and the addedmerging origin failed: <reason>suffix.Coverage debt: the new behavior has reference text only, with no how-to or tutorial. This is reported, not filled. A follow-up
/document-generatecould cover it. No architecture diagrams were affected.Test plan
bun test test/brain-sync.test.ts: 93 pass, 0 fail. Run locally with/usr/bin/git.realfirst on PATH, because Capy's git shim overrides the brain-sync commit author.bun test test/brain-sync-windows-paths.test.ts: 5 passbun run typecheck: exit 0Fixes #3704