Skip to content

docs(templates): warn before parallel background spawns in a shared worktree#1484

Merged
bradygaster merged 1 commit into
bradygaster:devfrom
omercangumus:omercangumus/1014-parallel-spawn-warning
Jul 19, 2026
Merged

docs(templates): warn before parallel background spawns in a shared worktree#1484
bradygaster merged 1 commit into
bradygaster:devfrom
omercangumus:omercangumus/1014-parallel-spawn-warning

Conversation

@omercangumus

Copy link
Copy Markdown
Contributor

What

The coordinator template's Parallel Fan-Out section now includes a shared-worktree guard: before spawning 2+ background agents in one turn without worktree mode, the coordinator shows the user a one-shot warning about the git race, then proceeds. Warn-only — no behavior change, no auto-isolation.

Why

Closes #1014

The issue documents a real incident: two background agents on one worktree, agent B's commit workflow ran a global git stash, and agent A's three untracked files vanished mid-session. Git doesn't error — only the in-session context remembers the files existed. The failure is probabilistic (fires only when one stream has untracked files at the exact moment another runs stash/clean/restore), so teams parallelize happily until it bites, then lose trust in parallelism entirely.

This ships the issue author's own Option A. Option B (auto-enable worktree isolation at N≥2 spawns) stays a follow-up — it changes spawn behavior and costs coordination overhead, which deserves its own discussion.

One correction against the issue text: the sample warning there references SQUAD_WORKTREES=1 / worktrees: true, but no such flag exists in the codebase — worktree isolation is governance-driven (worktree mode via the Pre-Spawn: Worktree Setup section and worktree-reference.md). The added warning points at the real mechanism instead of inventing a config surface.

How

  • .squad-templates/squad.agent.md (canonical): a **Shared-worktree guard.** block at the end of the Parallel Fan-Out MUST-list — check worktree mode, warn once per session when off, proceed after warning ("a caution, not a gate"). Warning text names the exact failure (stash/clean/restore eating another agent's untracked files).
  • .squad-templates/worktree-reference.md: the "multiple agents can work in the same worktree concurrently if they modify different files" line now carries the untracked-files caveat — that safety claim never covered untracked files, which is exactly what the incident hit.
  • Propagated via node scripts/sync-templates.mjs --sync to all governed copies: .github/agents/squad.agent.md, templates/, packages/squad-cli/templates/, packages/squad-sdk/templates/ (5 agent.md copies, 4 worktree-reference copies — byte-identical, test/template-sync.test.ts parity passes).

Testing

  • New test/ci/parallel-spawn-warning.test.ts (4 tests, same structural pattern as test/ci/datetime-template.test.ts): guard present inside the Parallel Fan-Out section specifically, stash/clean/restore named, the worktree-reference caveat present, and all governed copies carrying the guard.
  • npx vitest run test/ci/parallel-spawn-warning.test.ts test/template-sync.test.ts — 253 passed.
  • Per CONTRIBUTING, .squad-templates/*.md changes call for an E2E template session on top of unit tests. Copilot CLI isn't available in this environment, so that run hasn't happened — flagging honestly rather than claiming it. The change is purely additive guidance text (no spawn-template variables, no conditional blocks touched), so the structural tests cover what's mechanically checkable; happy to run the E2E matrix on a machine with copilot if wanted before merge.
  • Diff hygiene: git diff vs git diff -w identical; the sync script's known CRLF churn on unrelated workflow-wiring files was reverted before commit — the diff is 11 files, +129/−4, all of it the guard, the caveat, the test, and the changeset.

⚠️ Quick Check

  • Changeset added: .changeset/fix-1014-parallel-spawn-warning.md (patch, both packages — governed template paths ship in both)

PR Readiness Checklist

Branch & Commit

  • Branch created from dev
  • Branch is up to date with dev
  • Verified diff contains only intended changes
  • PR is not in draft mode
  • Commit history is clean (single commit)

Build & Test

  • npm run build — N/A for template text, passes regardless
  • Targeted tests pass (253 across the new test + template-sync parity)
  • npm run lint passes
  • npm run lint:eslint — 0 errors on the new test file

Changeset

  • Changeset added (patch, both packages)

Docs

  • N/A — the change IS coordinator/reference documentation

Exports

  • N/A

Breaking Changes

None. Warn-only; shared-worktree mode keeps working exactly as before.

Waivers

E2E template session not run in this environment (no copilot CLI) — see Testing.

…orktree

A real incident (bradygaster#1014): two background agents on one worktree, agent
B's commit workflow ran a global git stash and swept agent A's three
untracked files. Git doesn't complain — the files just vanish, and only
the in-session context remembers they existed.

This is the issue's Option A, warn-only: the Parallel Fan-Out section
of the coordinator template now tells the coordinator to check worktree
mode before spawning 2+ background agents in one turn and show the user
a one-shot warning when isolation is off. Once per session, proceed
after warning — a caution, not a gate. No behavior change, no
auto-isolation (that's Option B, a possible follow-up).

Also drops the worktree reference's claim that shared-worktree
concurrency is safe when agents modify different files — untracked
files were never covered by that safety argument.

The issue's sample warning referenced a SQUAD_WORKTREES env var that
doesn't exist in the codebase; the added text points at the real
mechanism (worktree mode via Pre-Spawn: Worktree Setup) instead.

Fixes bradygaster#1014

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions

Copy link
Copy Markdown
Contributor

🟠 Impact Analysis — PR #1484

Risk tier: 🟠 HIGH

📊 Summary

Metric Count
Files changed 11
Files added 2
Files modified 9
Files deleted 0
Modules touched 6

🎯 Risk Factors

  • 11 files changed (6-20 → MEDIUM)
  • 6 modules touched (5-8 → HIGH)

📦 Modules Affected

ci-workflows (1 file)
  • .github/agents/squad.agent.md
root (3 files)
  • .changeset/fix-1014-parallel-spawn-warning.md
  • templates/squad.agent.md.template
  • templates/worktree-reference.md
squad-cli (2 files)
  • packages/squad-cli/templates/squad.agent.md.template
  • packages/squad-cli/templates/worktree-reference.md
squad-sdk (2 files)
  • packages/squad-sdk/templates/squad.agent.md.template
  • packages/squad-sdk/templates/worktree-reference.md
templates (2 files)
  • .squad-templates/squad.agent.md
  • .squad-templates/worktree-reference.md
tests (1 file)
  • test/ci/parallel-spawn-warning.test.ts

This report is generated automatically for every PR. See #733 for details.

@github-actions

Copy link
Copy Markdown
Contributor

🛫 PR Readiness Check

ℹ️ This comment updates on each push. Last checked: commit 46ac329

PR Scope: 🔧 Infrastructure

⚠️ 2 item(s) to address before review

Status Check Details
Single commit 1 commit — clean history
Not in draft Ready for review
Branch up to date Up to date with dev
Copilot review No Copilot review yet — it may still be processing
Changeset present Changeset file found
Scope clean No .squad/ or docs/proposals/ files
No merge conflicts No merge conflicts
Copilot threads resolved No Copilot review threads
CI passing 6 check(s) still running

Files Changed (11 files, +129 −4)

File +/−
.changeset/fix-1014-parallel-spawn-warning.md +6 −0
.github/agents/squad.agent.md +11 −0
.squad-templates/squad.agent.md +11 −0
.squad-templates/worktree-reference.md +1 −1
packages/squad-cli/templates/squad.agent.md.template +11 −0
packages/squad-cli/templates/worktree-reference.md +1 −1
packages/squad-sdk/templates/squad.agent.md.template +11 −0
packages/squad-sdk/templates/worktree-reference.md +1 −1
templates/squad.agent.md.template +11 −0
templates/worktree-reference.md +1 −1
test/ci/parallel-spawn-warning.test.ts +64 −0

Total: +129 −4


This check runs automatically on every push. Fix any ❌ items and push again.
See CONTRIBUTING.md and PR Requirements for details.

@bradygaster
bradygaster merged commit 849b800 into bradygaster:dev Jul 19, 2026
14 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.

Coordinator should detect concurrent background spawns on a shared worktree and warn (or auto-isolate) — real-world git-race incident observed

2 participants