Skip to content

v1.92.46.0 fix(brain-sync): never commit a synced JSON file that does not parse (#3763) - #3796

Merged
capy-ai[bot] merged 10 commits into
mainfrom
gsta209-json-sync-guard
Nov 1, 2026
Merged

capy-ai[bot] merged 10 commits into
mainfrom
gsta209-json-sync-guard

Conversation

@garrytan

@garrytan garrytan commented Nov 1, 2026 •

Copy link
Copy Markdown
Owner
{
  "schema_version": 1,
  "pr": 3796,
  "head": "b8e9ca416218ec00ce784e6a15133809b5812b2d",
  "version": "1.92.28.0",
  "base": "main",
  "gate": {
    "focused": {
      "pass": 265,
      "fail": 0,
      "skip": 0
    }
  },
  "session_kind": "unattended",
  "head_tree": "77e0f266dc763e0232ff6d2f71cfdd4536cdbcbc",
  "product_patch_id": "202dd16afec028ce2781a977f80d507815d76bae",
  "gstack_version": "1.92.30.0",
  "review_depth": {
    "depth": "standard",
    "class": "code",
    "runtime_lines": 109,
    "rules": "150435b0a543019a",
    "base": "ab2852fb40219669c583f34a6f69b08f623543b4",
    "registry": "ab2852fb40219669c583f34a6f69b08f623543b4",
    "gate_scan": {
      "tagged": 0,
      "head": "b8e9ca416218ec00ce784e6a15133809b5812b2d"
    },
    "reasons": [
      "runtime=109>50"
    ]
  },
  "pregate": "requires-remote cleared @77e0f266dc76 (1 checks, current for b8e9ca416218)",
  "requires_remote": [
    "free-tests.yml/macos-named-regressions: https://github.com/garrytan/gstack/actions/runs/41346172918",
    "windows-free-tests.yml/windows-free-shard: https://github.com/garrytan/gstack/actions/runs/41346172917",
    "pregate.json/remote_gate: remote-gate tree=77e0f266dc76 tests=4925"
  ],
  "issues": {
    "fixes": [
      3763
    ],
    "refs": [],
    "flakes": []
  },
  "docs": {
    "status": "updated",
    "scope": "docs/ and README.md (brain-sync held/blocked states, --profile, conflict markers)"
  },
  "review_loop": {
    "passes": 2,
    "blocking_found": 0,
    "deferred": 0,
    "noted": 0,
    "fixed": 0,
    "scope": "frozen",
    "fix_checks": 1,
    "dispatches": {
      "specialist": 6,
      "red-team": 1
    }
  },
  "carry": {
    "from": "df2b5662bf82040094f20f9f4c9b570e535b406a",
    "reason": "base merge + base context moved (scoped review by anthropic/claude-opus-5-5: docs/gbrain-sync.md) + test-only change + release metadata",
    "product_patch_id": "202dd16afec028ce2781a977f80d507815d76bae",
    "changed_paths": [
      "metadata:CHANGELOG.md",
      "product:TODOS.md",
      "metadata:VERSION",
      "metadata:agents-digest/gstack-AGENTS.md",
      "product:bin/gstack-brain-sync",
      "test:browse/test/cookie-import-native.test.ts",
      "test:browse/test/cookie-import-node.test.ts",
      "test:browse/test/terminal-agent-publication-lock.test.ts",
      "test:browse/test/xvfb.test.ts",
      "product:docs/TESTING_INTERNALS.md",
      "product:docs/evals/detector-inventory.md",
      "product:docs/gbrain-sync-errors.md",
      "product:docs/gbrain-sync.md",
      "product:docs/pregate.md",
      "product:docs/recommended-harness.md",
      "product:docs/review-policy.md",
      "product:docs/ship-policy.md",
      "product:docs/troubleshooting.md",
      "test:ios-qa/daemon/test/daemon-integration.test.ts",
      "product:lib/pregate/checks/lanes.ts",
      "product:lib/pregate/config.ts",
      "product:lib/pregate/context.ts",
      "product:lib/pregate/head-policy.ts",
      "product:lib/pregate/index.ts",
      "product:lib/pregate/lane-selection.ts",
      "product:lib/pregate/starter.ts",
      "product:lib/pregate/types.ts",
      "product:lib/result-codes-release.ts",
      "product:lib/review-brief.ts",
      "product:lib/review-ledger.ts",
      "product:lib/review-scope.ts",
      "product:lib/ship-queue-wave.ts",
      "metadata:package.json",
      "product:scripts/free-test-durations-windows.json",
      "product:scripts/free-test-durations.json",
      "product:scripts/harness-version.json",
      "product:scripts/lib/windows-curation.ts",
      "product:scripts/typecheck-test-baseline.json",
      "product:scripts/ubicloud/ubi-runner.sh",
      "test:test/brain-sync.test.ts",
      "test:test/claude-overlay-setup-installs.test.ts",
      "test:test/claude-overlay-setup-lifecycle.test.ts",
      "test:test/claude-overlay-setup-project.test.ts",
      "test:test/claude-overlay-setup-recovery.test.ts",
      "test:test/coverage-audit-evidence.test.ts",
      "test:test/docsync-authority.test.ts",
      "test:test/docsync-command-grammar.test.ts",
      "test:test/docsync-fault-interface-faults.test.ts",
      "test:test/docsync-fault-interface-legacy.test.ts",
      "test:test/docsync-fault-interface.test.ts"
    ],
    "merge_commits": 1,
    "range_diff": "1:  1a781375 = 1:  1a781375 test: synced JSON that does not parse is never committed and is reported (#3763)\n2:  a2b189e6 = 2:  a2b189e6 fix(brain-sync): hold a synced JSON file that does not parse; --profile and doctor report it (#3763)\n3:  f8926c74 = 3:  f8926c74 fix(brain-sync): read JSON index blobs with one cat-file batch, no python subprocess (#3763)\n4:  9d095fdf = 4:  9d095fdf fix(brain-sync): block instead of committing a one-sided merge when a held file is mid-merge (#3763)\n5:  4490647d = 5:  4490647d fix(brain-sync): merge-block status names the real recovery and waiting files (#3763)\n6:  df2b5662 = 6:  df2b5662 docs(brain-sync): JSON holds in the --status, held-files and two-machine sections (#3763)\n-:  -------- > 7:  c938b6f7 test(brain-sync): #3704 fixtures write valid JSON to developer-profile.json (#3763)\n-:  -------- > 8:  b8e9ca41 docs(brain-sync): keep the reviewed JSON paragraph wording after the main merge (#3763)",
    "covers": [
      "pre-landing review",
      "adversarial review",
      "gate integrity",
      "documentation audit"
    ],
    "reruns": [
      "CI at head (gstack-ship-queue ready requires it); test and helper code changed since the reviewed head runs there unreviewed"
    ],
    "ancestry": "linear",
    "trees": [
      "eabcc0690be473bfe67171ae12a857788dd5bff5"
    ]
  }
}

What changes

  • brain-sync holds back a synced .json file that doesn't parse (bin/gstack-brain-sync). After the secret scan, hold_flagged_paths parses the index copy of every staged *.json file. Today those are developer-profile.json and projects/*/decisions.active.json. A file that fails to parse becomes an invalid-json hit and goes through the existing hold path, so nothing new is needed for:

    • unstaging the file and any coupled files (the decisions.jsonl / decisions.active.json group),
    • keeping it queued and listing it in held[],
    • syncing everything else as usual.

    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 --status note, the status-schema comments, gstack-doctor's held row (it now counts the files that aren't valid JSON), docs/gbrain-sync-errors.md and docs/gbrain-sync.md.

  • gstack-developer-profile --profile exits 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-doctor warns by name when developer-profile.json or a projects/*/decisions.active.json has 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:
    • a queued profile with conflict markers
    • a marker-free syntax error
    • an invalid decisions.active.json holding its coupled decisions.jsonl until it's repaired
    • two machines editing the profile (the remote copy doesn't parse)
  • gstack-developer-profile.test.ts: --profile on 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:

Security read

  • No network calls, no environment-variable reads beyond the existing GSTACK_HOME and PROFILE_FILE paths, no permission changes, and no new dependencies.
  • The new Python helper runs git -C $GSTACK_HOME cat-file blob :<path> as an argument list, not through a shell.
  • The profile check runs bun -e with the isolation flags and passes the file path through an environment variable, not by interpolation.

Open in Capy

What changed

gstack-developer-profile --profile on 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)
--- Before · before.txt · captured output
+++ After · after.txt · captured output
+$ gstack-developer-profile --profile; echo "exit=$?"   # this branch
+gstack-developer-profile: ~/.gstack/developer-profile.json is not valid JSON: JSON Parse error: Unrecognized token '<' (it holds git conflict markers from a merge); repair the file or restore it from git -C ~/.gstack log -- developer-profile.json
+exit=1
-$ gstack-developer-profile --profile; echo "exit=$?"   # main
-{
-  "sessions": [],
-<<<<<<< HEAD
-  "v": "local"
-=======
-  "v": "peer"
->>>>>>> origin/main
-}
-exit=0
 

Why

"When two machines edit developer-profile.json before 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, and gstack-developer-profile --profile and gstack-doctor both 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 .json files (today developer-profile.json and projects/*/decisions.active.json) with one git 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 while MERGE_HEAD exists 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). --profile callers now get exit 1 and empty stdout on a broken profile. plan-tune pipes --profile into JSON.parse, which already failed on a broken profile, so that path fails the same way as before.

Approvals

Date Asked Exact words Outcome Covers Still pending
2026-11-01 Approve the plan "GSTA-209 item 3: synced JSON never committed unparseable (#3763)" (autoplan run autoplan-3763-20261101140638, 3 decisions) “Approved: do it (A1 B1 C1). This is a bug fix with proof, so it doesn't need Garry's plan approval.” (GStack Minder (Captain), relayed by agent:jam_01M69H5VCA272WFHCN181RXDXP) approved the reviewed plan (sha256 a75326f5eb40), every recommendation taken none

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 .json file that doesn't parse (rule invalid-json) and syncs everything else. Its only fix is to repair the file, because --skip-file would 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 reports blocked. 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 --profile exits 1 on an unparseable profile. gstack-doctor names 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 in brain-sync.test.ts, the --profile case in gstack-developer-profile.test.ts, and the conflict-marker warning and secret-scan wording in gstack-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 status held. Both pass after 9d095fd.

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 --batch from bash, with no Python subprocess. The profile check runs bun -e with 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-sync hold path). It was fixed in 9d095fd with 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 in 4490647, 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:

  • No test stages the deletion of a synced .json file, so the batch reader's missing branch is checked by reading only. QA could not reach it through a real command, because brain-sync does not stage deletions.
  • No test covers a drain that holds both a secret-flagged file and an invalid JSON file at once (the two-count status note).
  • The merge guard checks MERGE_HEAD only. A stopped manual git pull --rebase or cherry-pick is not guarded.
  • plan-tune/SKILL.md.tmpl pipes --profile into JSON.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-json and the clean file syncs. Pass: --profile exits 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.md on 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, --profile and conflict markers.

Documentation health:

  • docs/gbrain-sync.md: Updated. --status description now covers JSON holds; Two-machine conflicts explains that JSON files have no merge driver and how the invalid-json hold and doctor warning work.
  • docs/gbrain-sync-errors.md: Updated. Held-files section now covers invalid-json holds and their single repair fix (--skip-file not offered). The branch's attention-table edits were already current.
  • docs/troubleshooting.md: Current. Its ARTIFACT_INVALID_JSON anchor is unrelated.
  • plan-tune/SKILL.md.tmpl: Current as prose; a caller of --profile, whose exit-1 behavior is noted as a follow-up.

Coverage debt: the invalid-json hold, the unfinished-merge blocked state and the gstack-developer-profile --profile exit 1 have reference coverage only (no how-to). Consider /document-generate for 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 fail
  • bun run typecheck: exit 0
  • Remote pregate (gstack-pregate --stage tests --remote, Ubicloud): 4911 tests, 0 failed on tree eabcc0690be4

Main 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 ~/.gstack never 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.

garrytan and others added 2 commits November 1, 2026 14:18
…ted (#3763)

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
…le and doctor report it (#3763)

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

trunk-io Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

😎 This pull request was merged.

garrytan and others added 8 commits November 1, 2026 14:31
…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>
@github-actions github-actions Bot changed the title fix(brain-sync): never commit a synced JSON file that does not parse (#3763) v1.92.46.0 fix(brain-sync): never commit a synced JSON file that does not parse (#3763) Nov 1, 2026
@capy-ai
capy-ai Bot merged commit dd2416f into main Nov 1, 2026
64 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

1 participant