Skip to content

fix(brain-sync): verify staged content and reject new casefold collisions - #3245

Closed
Kkkkkuro wants to merge 2 commits into
garrytan:mainfrom
Kkkkkuro:codex/brain-sync-narrow-guards
Closed

Kkkkkuro wants to merge 2 commits into
garrytan:mainfrom
Kkkkkuro:codex/brain-sync-narrow-guards

Conversation

@Kkkkkuro

@Kkkkkuro Kkkkkuro commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Git can report a successful add without staging the requested spelling or current bytes, so brain-sync can acknowledge a queued artifact that was never committed. A sync can also introduce casefold aliases at any directory component, including when a rejected push fetches and merges another writer's safe-looking tree.

This is the narrow first step suggested in the triage comment on #3223, with two focused commits:

  • Verify exact stage-0 paths, reject unrelated staged entries, and compare queued content to index object IDs using Git's clean conversion. A refusal preserves the queue and index.
  • Reject newly introduced NFC/casefold component collisions in the requested/index paths and outgoing trees, including retained-commit retries and fetch/merge retries. Unchanged historical aliases remain historical data; refused merges/commits stay local for inspection.

Only brain-sync, one read-only Python helper, and its existing integration test file change. The writer-lease system, artifact publishers, identity migration, production repair, and the original #3223 branch are outside this contribution. This is cooperative validation at sync boundaries, not a filesystem exclusion or migration guarantee.

Refs #3220. The broader #3223 remains open and unchanged.

Validation (macOS, Bun 1.4.2; exact final revision recorded below):

  • Final focused command: bun test test/brain-sync.test.ts test/brain-sync-windows-paths.test.ts test/transcript-scope-brain-sync.test.ts test/spawnsync-timeout-tripwire.test.ts: 92 pass, 0 fail, 562 assertions.
  • Red/green evidence: the unmodified staging logic fails 3 new negative cases; the stage-only commit fails the 3 new collision cases; the pre-outgoing-check implementation also publishes a collision introduced by a retry merge. Each is green on the final tree. Positive controls cover clean conversion, historical aliases, batch staging, holds, and push retries.
  • bun run build, bun run typecheck, Bash/Python syntax, git diff --check, and the public-diff credential scan: passed (0 scanner findings).
  • bun run typecheck:test: failed on two checkout-path-escaped TS2339 diagnostic identities. The same command on untouched base d258bcff reproduces both; no type-debt baseline was widened.
  • bun run test: incomplete, not passed. The full free runner was attempted (1,275 planned parallel files plus one exclusive file); this macOS sandbox rejects localhost listeners, process operations and Swift module-cache writes, and Swift reports an SDK/compiler mismatch. Other observed failures remain untriaged; they are not all attributed to infrastructure. Cancellation was denied by the sandbox, so this is not a completed full-suite result. No retry or machine-policy change was made.
  • Native Linux/Windows checks and paid evals were not run locally. Fork CI and maintainer review remain necessary.

Final head: 61b7db90e594405e4a8f1df112f30dd547f7f509; base: d258bcffb0cb7bda5f133f3e957f932d816d282f.

Draft for maintainer review; no full-suite, native-Windows, release, deployment, or production-repair acceptance is claimed.

Refuse missing or unrelated staged paths and stale indexed content without consuming the queue or resetting the index.
Check component prefixes in requested/index and outgoing trees, including retained commits and fetch/merge retries. Preserve historical aliases, local commits, index, and queue on refusal.
@trunk-io

trunk-io Bot commented Oct 17, 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

capy-ai Bot added a commit that referenced this pull request Oct 17, 2026
…ad of reporting ok (#3220) (#3254)

* fix(brain-sync): verify requested index entries after add

Refuse missing or unrelated staged paths and stale indexed content without consuming the queue or resetting the index.

* fix(brain-sync): refuse new casefold path collisions

Check component prefixes in requested/index and outgoing trees, including retained commits and fetch/merge retries. Preserve historical aliases, local commits, index, and queue on refusal.

* fix(brain-sync): hold case-colliding paths instead of halting the sync (#3220)

Builds on Kkkkkuro's staged-index and casefold checks (#3245, from #3223).
A queued path whose spelling differs only by letter case from another path
in the index or the batch is held before staging: it stays queued, every
other file keeps syncing, and the status is "collision" rather than "ok".
An established spelling keeps syncing; only the new alias waits.

Skill start prints one ARTIFACTS_SYNC attention line naming the colliding
names and the repair anchor (docs/troubleshooting.md#artifact-case-collision);
gstack-doctor warns the same way. The outgoing check is cached by HEAD so
the empty-queue drain at every skill boundary stays near main's cost.
gstack-slug and skill start's slug path are unchanged.

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

* fix(brain-sync): close review gaps in the case-collision hold

- Windows: write the held-path list with LF and strip CR from helper output,
  so CRLF cannot let a held path through or blank case_names.
- --publish-removals runs the outgoing case check before it pushes.
- The cached outgoing verdict is keyed by every ref, not HEAD alone, so a
  moved remote baseline is re-checked.
- The repair snippet folds only JSONL logs and lists snapshots and other
  files for a manual decision.

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

* fix(brain-sync): second review pass on the case-collision hold

- The repair loop also folds the dropped spelling's untracked (held) files
  and says to check for leftovers before removing the folder on Linux.
- The cached outgoing verdict also keys on HEAD's symbolic target.
- The outgoing check no longer needs a temp file, so a failed mktemp can
  no longer skip it.

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

* test(brain-sync): give the retry-merge fixture a git identity

The retry merge commits with the ambient identity. CI and Ubicloud runners
have none under the test HOME, so the merge failed before the outgoing case
check ran and the drain reported push_failed instead of error.

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

* docs(changelog): unreleased entry for the #3220 case-collision hold

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

* v1.91.126.0 stamp

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

---------

Co-authored-by: KuroChen <[email protected]>
Co-authored-by: Kkkkkuro <[email protected]>
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
@capy-ai

capy-ai Bot commented Oct 17, 2026

Copy link
Copy Markdown
Contributor

Thank you, @Kkkkkuro. This narrow version is the basis of #3254 (v1.91.126.0, 4e4f295), which cherry-picks both of your commits with your authorship. It adds a hold (sync keeps going without colliding aliases), Windows CRLF and --publish-removals coverage, a skill-start warning and a repair doc. Closing as superseded by #3254.

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