Repository navigation
v1.92.46.0 fix(brain-sync): never commit a synced JSON file that does not parse (#3763) - #3796
Merged
Merged
Conversation
|
😎 This pull request was merged. |
…thon subprocess (#3763) Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
… held file is mid-merge (#3763) Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
…ng files (#3763) Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
…ine sections (#3763) Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> # Conflicts: # docs/gbrain-sync.md
…e.json (#3763) Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
…main merge (#3763) Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
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 changes
brain-sync holds back a synced
.jsonfile that doesn't parse (bin/gstack-brain-sync). After the secret scan,hold_flagged_pathsparses the index copy of every staged*.jsonfile. Today those aredeveloper-profile.jsonandprojects/*/decisions.active.json. A file that fails to parse becomes aninvalid-jsonhit and goes through the existing hold path, so nothing new is needed for:decisions.jsonl/decisions.active.jsongroup),held[],The fix line says to repair the file. It doesn't offer
--skip-file, because that would stop the profile syncing for good. Staged deletions have no index copy, so they are never held.Held-status wording no longer blames the secret scan for every hold. This covers the skill-start attention line, the
--statusnote, the status-schema comments,gstack-doctor's held row (it now counts the files that aren't valid JSON),docs/gbrain-sync-errors.mdanddocs/gbrain-sync.md.gstack-developer-profile --profileexits 1 on an unparseable profile. It prints<file> is not valid JSON: <error>on stderr, notes conflict markers when it finds them at the start of a line, and prints nothing on stdout. This changes behavior for scripts that read--profile, and the changelog fragment says so.gstack-doctorwarns by name whendeveloper-profile.jsonor aprojects/*/decisions.active.jsonhas a conflict-marker line. It uses one POSIX grep.No JSON merge driver. A correct profile merge needs product choices: whether to union sessions, and whether to recompute inferred values. The commit-time guard makes a broken file impossible to publish, however it got broken. #3728 (fixes #3704) separately aborts a failed push-retry merge, so brain-sync's own merge no longer leaves markers behind. This guard still covers profiles that are already broken on machines today, manual git work in
~/.gstack, and any other writer.Proof
New tests on main 6bffa20 with this branch's test commit (
1a781375) and no fix: 7 of 8 fail, and the valid-profile control passes.brain-sync.test.ts, all four fail:decisions.active.jsonholding its coupleddecisions.jsonluntil it's repairedgstack-developer-profile.test.ts:--profileon an unparseable profile fails.gstack-doctor.test.ts: the conflict-marker warning and the JSON hold attributed to the secret scanner both fail.With the fix (
a2b189e6), all 8 pass.Tests
Run on this machine:
test/brain-sync.test.ts,test/gstack-developer-profile.test.ts,test/gstack-doctor.test.tsandtest/gstack-skill-start.test.ts: 256 pass, 3 fail.#2549 queue integritydetector tests. They fail only on Capy machines, where/usr/bin/gitexportsGIT_AUTHOR_NAME, and they passed in the remote pregate for v1.92.38.0 fix(brain-sync): set local edits aside around the retry merge and say why it failed (#3704) #3728. The remote pregate for this PR runs at READY.Security read
GSTACK_HOMEandPROFILE_FILEpaths, no permission changes, and no new dependencies.git -C $GSTACK_HOME cat-file blob :<path>as an argument list, not through a shell.bun -ewith the isolation flags and passes the file path through an environment variable, not by interpolation.What changed
gstack-developer-profile --profileon a profile with git conflict markers. Before: main prints the broken file and exits 0. After: this branch names the problem on stderr and exits 1. Image rendering failed on this machine (PR_SHOTS_RENDER_FAILED), so this is the text version.Before/after as text: gstack-developer-profile --profile on a profile with git conflict markers: main prints the broken file and exits 0; this branch names the problem on stderr and exits 1 (temp GSTACK_HOME shown as ~/.gstack)
Why
"When two machines edit
developer-profile.jsonbefore syncing, git can leave conflict markers in it" (#3763). On main, brain-sync commits and pushes that file, so every machine ends up with a profile that doesn't parse, andgstack-developer-profile --profileandgstack-doctorboth still say everything is fine. With this change a broken synced JSON file is never published, and both tools say when one is broken.Blast radius
Every brain-sync drain now parses the staged
.jsonfiles (todaydeveloper-profile.jsonandprojects/*/decisions.active.json) with onegit cat-file --batch. A file that fails goes through the existing hold path, so the queue, coupled groups and the rest of the sync behave as they do for a secret-scan hold. The new merge guard only fires whileMERGE_HEADexists and something would be held. Evidence: the focused suites ran (265 pass, 0 fail) and the remote pregate ran the selected free tier (4911 tests, 0 failed).--profilecallers now get exit 1 and empty stdout on a broken profile.plan-tunepipes--profileintoJSON.parse, which already failed on a broken profile, so that path fails the same way as before.Approvals
Source: gstack-approvals record for gsta209-json-sync-guard (display only; not an approval citation).
Summary
Fixes #3763. A git merge can leave conflict markers in
developer-profile.json, and brain-sync used to commit and push that file to every machine. Now brain-sync holds back any staged synced.jsonfile that doesn't parse (ruleinvalid-json) and syncs everything else. Its only fix is to repair the file, because--skip-filewould stop the profile syncing for good. If the held file is part of a git merge that isn't finished, brain-sync now commits nothing and reportsblocked. Committing that merge without the file would keep only this machine's version and silently drop the other machine's edit. The status message says to repair the file or finish the merge.gstack-developer-profile --profileexits 1 on an unparseable profile.gstack-doctornames a synced profile or decision snapshot that holds conflict markers. Held-status wording no longer blames the secret scan for every hold.No JSON merge driver. A correct profile merge needs product choices, like whether to union sessions and whether to recompute inferred values. The commit-time guard stops a broken file from being published, however it got broken. #3728 separately aborts a failed push-retry merge.
Proof (failing first). On main 6bffa20 with only the test commit (
1a781375), 7 of 8 new tests failed and the valid-profile control passed. That covered 4 inbrain-sync.test.ts, the--profilecase ingstack-developer-profile.test.ts, and the conflict-marker warning and secret-scan wording ingstack-doctor.test.ts. The review's one-sided-merge finding was also reproduced first. The extended two-machine test got the local profile on the remote instead of the peer's, and the new unfinished-merge test got statusheld. Both pass after9d095fd.Security read. No network calls, no new environment-variable reads, no permission changes and no new dependencies. Index blobs are read by one
git -C "$GSTACK_HOME" cat-file --batchfrom bash, with no Python subprocess. The profile check runsbun -ewith the isolation flags and passes the path through an environment variable.Test Coverage
Coverage: deterministic (each of 3 changed runtime files has a changed test naming it; no audit reader).
Tests ran: focused 265
Pre-Landing Review
Pass 1 (specialist batch: testing, security, state-machines; Red Team) found one CRITICAL issue. A held file in an unfinished merge produced a one-sided merge commit that dropped the peer's edit (
bin/gstack-brain-synchold path). It was fixed in9d095fdwith a failing test first. Pass 2 (specialists on the fix range), the native adversarial pass and the outside voice (openai/gpt-6.1-sol, a different model family) ran next. The outside voice found nothing. The adversarial pass's recovery-advice finding was fixed in4490647, and one fix-check read that fix and found nothing.REVIEW_LOOP: passes=2 blocking_found=0 deferred=0 noted=0 fixed=0 scope=frozen fix_checks=1 dispatches=7
Gate edits: none detected (GATE_SCAN tagged=0)
Outside review: completed, no findings.
Review notes
Informational, not looped:
.jsonfile, so the batch reader'smissingbranch is checked by reading only. QA could not reach it through a real command, because brain-sync does not stage deletions.MERGE_HEADonly. A stopped manualgit pull --rebaseor cherry-pick is not guarded.plan-tune/SKILL.md.tmplpipes--profileintoJSON.parse. On a broken profile it now gets empty stdin instead of broken JSON, and it fails in both cases.Exploratory QA
CLI surface only, run in a temporary state folder with local bare remotes. Pass: a queued conflicted profile is held with rule
invalid-jsonand the clean file syncs. Pass:--profileexits 1 and doctor warns with the file name. Pass: a repaired profile syncs next. Inconclusive: the staged-deletion batch branch was unreachable, so that risk was accepted (see Review notes). Report:.gstack/qa-reports/ship-921-20261101T143356Z/functional/report.mdon the ship machine.Design Review
No frontend files changed — design review skipped.
Eval Results
No prompt-related files changed — evals skipped.
Plan Completion
Plan completion audit: not run (no plan is bound to this branch and no docs/designs/ file matches). The approved plan is autoplan-3763 (gate_rev=1).
Issues
Fixes #3763
TODOS
No TODO items completed in this PR.
Documentation
Status: updated. Two authored docs were corrected for the brain-sync JSON guard; no blockers.
Scope: base 6bffa20..head 4490647 on gsta209-json-sync-guard (10 committed files; nothing staged, unstaged or untracked), covering bin/gstack-brain-sync, bin/gstack-developer-profile and bin/gstack-doctor, plus docs that mention brain-sync held/blocked states,
--profileand conflict markers.Documentation health:
--statusdescription now covers JSON holds; Two-machine conflicts explains that JSON files have no merge driver and how theinvalid-jsonhold and doctor warning work.invalid-jsonholds and their single repair fix (--skip-filenot offered). The branch's attention-table edits were already current.ARTIFACT_INVALID_JSONanchor is unrelated.--profile, whose exit-1 behavior is noted as a follow-up.Coverage debt: the
invalid-jsonhold, the unfinished-mergeblockedstate and thegstack-developer-profile --profileexit 1 have reference coverage only (no how-to). Consider/document-generatefor a conflict-recovery how-to.Diagram drift: none.
Test plan
bun test test/brain-sync.test.ts test/brain-sync-windows-paths.test.ts test/gstack-developer-profile.test.ts test/gstack-doctor.test.ts test/gstack-skill-start.test.ts: 265 pass, 0 failbun run typecheck: exit 0gstack-pregate --stage tests --remote, Ubicloud): 4911 tests, 0 failed on tree eabcc0690be4Main merge (rule 19 grant)
After #3728 landed, I merged main into this branch once, with no rebase.
Informational, not blocking: main's #3704 paragraph says
~/.gstacknever holds conflict markers after a failed retry merge. The next paragraph says a merge can leave them in JSON files, which means a merge run by hand or one left over from an older gstack. A follow-up could make that explicit.