Skip to content

bug(exec/hooks): parallel-group marker filename is global — one project's /exec run redirects worktree enforcement for every concurrent session #881

Closed

Description

@admarble

The /exec parallel-group marker filename is a global constant, so a parallel group in one project silently redirects worktree enforcement for every concurrently-running Claude session on the machine — including sessions in unrelated repos.

Mechanism

/exec creates the marker with a hardcoded name (skills/exec/SKILL.md, and both mirrors):

touch /tmp/claude-parallel-group-1.marker

pre-tool.sh then resolves the worktree it enforces as: SEQUANT_WORKTREE, else the first matching marker file, with no project scoping:

# pre-tool.sh:63
PARALLEL_MARKER_PREFIX="${_TMPDIR}/claude-parallel-"
...
# pre-tool.sh:571-579
for marker in "${PARALLEL_MARKER_PREFIX}"*.marker; do
    if [[ -f "$marker" ]]; then
        EXPECTED_WORKTREE=$(head -1 "$marker" 2>/dev/null || true)
        break
    fi
done

${_TMPDIR} is the shared user temp dir, and the group id (group-1) carries no project or session identity. Every session on the box globs the same namespace and takes the first hit.

Observed

While editing files in sequant's own worktree during work on #856, an Edit was rejected with a worktree path belonging to a different project's test run:

HOOK_BLOCKED: File operation must be within worktree
  Worktree: /tmp/matcha-maps-worktree-test-59691-1785383831275/worktrees/feature/540-test
  File:     /Users/tony/Projects/worktrees/feature/856-.../src/lib/locks/lock-manager.integration.test.ts

It cleared on retry once the other run finished, which is what makes it nasty — it presents as a transient, unreproducible glitch rather than a namespace collision. Note the two failure branches are distinguishable: a marker pointing at a deleted directory yields HOOK_BLOCKED: Worktree does not exist, so the message above proves the foreign worktree was live at the time.

Impact

  • Blocks legitimate edits in the correct worktree, with a confusing path from an unrelated repo.
  • Worse — the inverse. Worktree enforcement exists to stop agents editing the main repo instead of the worktree. Whichever session loses the race gets its guard pointed somewhere meaningless, so the protection silently stops protecting for the duration.
  • Cross-project by construction. The dogfood testbed (sequant npm-linked into ad-motion / matcha-maps) makes concurrent runs routine rather than exotic.

Acceptance Criteria

  • AC-1: The marker filename includes a per-project component (e.g. a hash of the project root) so two projects running parallel groups simultaneously cannot collide.
  • AC-2: pre-tool.sh and post-tool.sh match only markers belonging to the current project root, rather than globbing the whole ${_TMPDIR} namespace and taking the first hit.
  • AC-3: A marker whose worktree path does not contain the current project root is ignored rather than enforced, so a stale or foreign marker cannot block edits.
  • AC-4: The marker name is defined in exactly one place shared by the skill and both hooks, so the writer and the readers cannot drift apart.
  • AC-5: A regression test starts a foreign marker pointing at an unrelated live directory and asserts an edit inside the real worktree is still permitted.

Non-Goals

Notes

All three skill copies must change together (skills/, templates/skills/, .claude/skills/), plus both hook mirrors (hooks/, templates/hooks/) — check-skill-sync and the sync lint cover the drift.

Found while working #856; unrelated to that issue's cause.

Activity

  1. added
    bug
    on Jul 30, 2026
  2. admarble commented on Jul 31, 2026

    @admarble
    ContributorAuthor

    📋 Plan Review — #881 (parallel-group marker is global)

    Complexity: Standard (5 ACs, 3 mirrored dir-sets)

    AC Quality Check

    ACs are measurable and testable. One design tension to flag ⚠️:

    • AC-3 is a prescription that contradicts its own requirement. It says "a marker whose worktree path does not contain the current project root is ignored." But worktrees are siblings of the repo, not children — the legitimate marker's own path (/Users/tony/Projects/worktrees/feature/856-…) does not contain the project root (…/sequant) either. Implementing AC-3 literally would reject the legitimate marker too. The requirement (a foreign marker must not be enforced) is sound; the prescribed check is not. Recommendation: satisfy AC-3 by storing the owning project root inside the marker and comparing that to the current project — not by substring-matching the worktree path. Flagging per prior guidance that an AC's suggested design can violate its own requirement.

    Scope Assessment

    Non-Goals: present and clear (no protocol redesign; SEQUANT_WORKTREE stays authoritative). ✅

    Metric Value Status
    Feature count 1 (one mechanism) ✅
    AC items 5 ✅
    Directory spread skills ×3, hooks ×2×3, __tests__ ✅ (mirrored, cohesive)

    Verdict: ✅ SCOPE_OK

    Root Cause (verified in code)

    • Skill writes a hardcoded marker: skills/exec/SKILL.md:1526 touch /tmp/claude-parallel-group-1.marker (empty file today).
    • Hooks glob the whole temp namespace and take the first hit, no project scoping: hooks/pre-tool.sh:63,636-642 (PARALLEL_MARKER_PREFIX="${_TMPDIR}/claude-parallel-").
    • Two glob sites per hook, not one — AC-2 must cover both:
      • Enforcement glob: pre-tool.sh:636
      • Agent-enumeration/timing globs: pre-tool.sh:250 and post-tool.sh:84 (post-tool has no enforcement, only enumeration).

    Acceptance Criteria + Verification

    AC-1 — marker filename includes a per-project component.
    Integration Test — Given a project root → When the marker path is computed → Then the filename contains md5(project_root). Writer must also write worktree path (line 1) + owning project root (line 2) into the marker (today's touch writes an empty file — the worktree-path contract is currently vacuous; fix must populate it).

    AC-2 — hooks match only current-project markers at all three glob sites.
    Integration Test — Given a foreign-project marker in ${_TMPDIR} → When pre/post-tool run → Then it is not selected at pre-tool.sh:250/636 or post-tool.sh:84.

    AC-3 — foreign marker ignored (see tension above).
    Integration Test — Given a marker whose stored owning project root ≠ current → Then it is ignored. (Implement via stored project root, not worktree-path containment.)

    AC-4 — marker name defined in exactly one shared place.
    Integration Test / drift check — grep asserts no independent hardcoded claude-parallel-group literal survives in >1 site; covered additionally by check-skill-sync + sync-hooks.sh.

    AC-5 — regression test: foreign live marker present, edit inside the real worktree still permitted.
    Integration Test — extend __tests__/pre-tool-hook.integration.test.ts (parametrized over all 3 hook copies). Set TMPDIR to a hermetic dir; drop a foreign marker pointing at a real live unrelated dir; assert an Edit inside the real worktree exits 0. Mutation-verify (per repo testing rule): revert the scoping fix → confirm exactly AC-5 fails → restore → record in PR body.

    Implementation Plan

    Phase 1 — single source of truth (AC-1, AC-4)

    1. Add a shared helper hooks/parallel-marker.sh exposing the naming scheme + a parallel_marker_path <group-id> function that emits ${_TMPDIR}/claude-parallel-${PROJECT_HASH}-<group-id>.marker. Reuse the existing md5 -q … || md5sum idiom (pre-tool.sh:703) for cross-platform hashing.
    2. Both hooks source the helper; skill calls it instead of hardcoding: MARKER=$(…); { echo "$WORKTREE"; echo "$PROJECT_ROOT"; } > "$MARKER".

    Phase 2 — scope the readers (AC-2, AC-3)
    3. Replace the glob at pre-tool.sh:636, pre-tool.sh:250, post-tool.sh:84 with the project-hashed prefix.
    4. AC-3 defense-in-depth: skip any marker whose line-2 owning project root ≠ current project root.

    Phase 3 — mirror + regression (AC-5)
    5. Apply identically across all mirrors: skills/, templates/skills/, .claude/skills/ (exec SKILL.md ×3) and hooks/, templates/hooks/ (pre + post ×2). Run check-skill-sync + sync-hooks.sh.
    6. Add the mutation-verified AC-5 test.

    Design Review

    1. Where does this belong? The marker naming scheme is the shared contract between one writer (exec skill) and two readers (hooks) — it must live in one sourced shell helper, not be re-derived per site.
    2. Simplest correct approach? Project-hash in the filename (AC-1/AC-2) does the real isolation cheaply; stored owning-project-root (AC-3) is belt-and-suspenders. Rejected: substring-matching worktree paths (breaks legit siblings, see AC-3 tension).
    3. Existing pattern? Same md5-with-fallback used by the per-file lock at pre-tool.sh:703; same 3-copy mirroring + drift lint already guarding hooks/skills.
    4. What a reviewer would challenge: "How do writer and readers derive the same project root?" → key open question below.

    Open Questions

    1. Project-root derivation must be identical in skill-context and hook-context. Options: (a) CLAUDE_PROJECT_DIR env if Claude Code sets it in both; (b) git rev-parse --show-toplevel / --git-common-dir from the file/cwd. A mismatch silently re-introduces the collision. Recommendation: verify CLAUDE_PROJECT_DIR is present in the hook env; fall back to git toplevel of the file's dir. Impact if wrong: markers never match → enforcement silently disabled (the exact failure mode we're fixing).
    2. Minor sibling namespaces (out of scope, noted): claude-lock-* (pre-tool.sh:703) and TIMING_LOG also live in shared ${_TMPDIR}. Locks are keyed by file-path hash so they lack the first-hit collision; timing-log coupling is fix(hooks): ^gh (issue|pr) prefix skip disarms all 5 pre-tool guards for compound commands, and re-breaks on any cd prefix #763. Not expanding scope — flagging only.

    Recommended Workflow

    Phases: spec → exec → qa
    Quality Loop: disabled (SCOPE_OK) — but this weakens a safety guard across 6 mirrored files, so treat the AC-5 mutation-verification as a hard gate.
    Testgen: skip a separate phase — the one required regression test slots into the existing pre-tool-hook.integration.test.ts harness.
    Reasoning: cohesive single-mechanism bug fix with an established test harness; no UI, no new schema, no security phase (local dev hook, not auth/payments).

    Label Review

    Current: bug — Recommended: keep bug. No label change needed.

  3. added
    planned
    on Jul 31, 2026
  4. admarble commented on Jul 31, 2026

    @admarble
    ContributorAuthor

    ✅ Exec complete — PR #888

    Implemented the project-scoped parallel-group marker per the spec plan.

    AC Verification

    AC Description Status Evidence
    AC-1 Marker filename includes a per-project component ✅ Implemented parallel-marker.sh:parallel_marker_prefix → claude-parallel-<md5(project-root)>-<group-id>.marker
    AC-2 Hooks match only current-project markers at all glob sites ✅ Implemented pre-tool.sh enforcement + agent-id; post-tool.sh agent-id — all scoped to the project prefix
    AC-3 Foreign marker ignored, not enforced ✅ Implemented Line-2 owning-root guard at the enforcement reader — implemented via stored project root, not worktree-path containment (resolving the spec's flagged tension: worktrees are siblings, so containment would reject the legit marker too)
    AC-4 Marker name defined in exactly one shared place ✅ Implemented parallel-marker.sh (mirrored ×3) is the sole constructor; hooks + /exec skill source it. claude-parallel-group literal now survives in zero other sites
    AC-5 Regression test: foreign live marker still permits real-worktree edit ✅ Implemented New #881 block in pre-tool-hook.integration.test.ts, parametrized over all 3 hook copies, + a positive control

    Design notes (per spec)

    • Project-root derivation (spec Open Question feat: Complete remaining v1.0 features (AC-10, AC-13, AC-14) #1): shared helper uses CLAUDE_PROJECT_DIR (set by Claude Code in both skill- and hook-context) with a git rev-parse --show-toplevel fallback — identical in writer and readers so they can't re-collide.
    • AC-3 tension (spec flag): satisfied via the stored owning-project-root comparison, not worktree-path substring matching, since worktrees are siblings of the repo.

    Mutation verification (AC-5 — hard gate)

    Reverted the reader scoping in one hook copy (global glob + neutralized owner guard) → exactly AC-5 [templates/hooks/pre-tool.sh] failed (1 failed / 5 passed), reproducing the original cross-project block. Restored via git checkout; all 6 #881 assertions pass.

    Checks

    • npm run build ✅ (tsc clean) · npm run lint ✅ (eslint clean)
    • pre-tool-hook.integration.test.ts + hook-sync.test.ts + check-skill-sync.test.ts → 198 passed
    • check-skill-sync (3 skill dirs) + sync-hooks (templates → .claude) in sync; hooks/ plugin mirror updated too

    Files changed

    • templates/hooks/parallel-marker.sh (new) + hooks/, .claude/hooks/ mirrors
    • pre-tool.sh / post-tool.sh ×3 hook dirs
    • exec/SKILL.md ×3 skill dirs
    • __tests__/pre-tool-hook.integration.test.ts, CHANGELOG.md

    Quality Plan Alignment: N/A — no Feature Quality Planning section in the spec comment.

  5. admarble commented on Jul 31, 2026

    @admarble
    ContributorAuthor

    QA Review for Issue #881

    Reviewed at commit 6915217917df7b3acc894c99b93c1c56105dc939 (PR #888). Standard QA (522 insertions across 14 files; shell hooks + skill md + integration test).

    AC Coverage

    AC Description Status Notes
    AC-1 Marker filename includes a per-project component MET parallel-marker.sh:parallel_marker_prefix → ${TMPDIR}/claude-parallel-<md5(project-root)>-<group-id>.marker; reuses the established md5/md5sum-fallback idiom
    AC-2 Hooks match only current-project markers at every glob site MET All 3 sites scoped to $PARALLEL_MARKER_PREFIX: pre-tool agent-id find (pre-tool.sh:272), pre-tool enforcement glob (:656), post-tool agent-id find. No unscoped claude-parallel-* glob survives except the intentional helper-missing fallback
    AC-3 Foreign marker ignored, not enforced MET Enforcement reader reads stored owning-root (line 2) and continues past any marker whose root ≠ current. Correctly implemented via stored project root, not worktree-path containment — resolving the spec's flagged AC-3 tension (worktrees are siblings, so containment would reject the legit marker)
    AC-4 Marker name defined in exactly one shared place MET grep claude-parallel-group returns zero hits across all hook + skill dirs; parallel-marker.sh is the sole constructor, sourced by both hooks and the /exec skill
    AC-5 Regression test: foreign live marker still permits real-worktree edit MET New #881 describe block parametrized over all 3 hook copies, + a positive control proving same-project enforcement still fires. Mutation-verified in exec (reverting the reader scoping fails exactly AC-5). Independently re-ran: 198/198 pass (integration + hook-sync + skill-sync)

    Coverage: 5/5 AC items MET on the merits.

    CI Status

    Check State Impact
    (none dispatched) — ⏳ PENDING

    mergeable: CONFLICTING, mergeStateStatus: DIRTY, statusCheckRollup empty. CI has not dispatched because the branch conflicts with origin/main. The conflict is CHANGELOG.md only — origin/main's fix(#856) (97b08e9) added an entry to the top of the same ### Fixed section, overlapping the #881 entry. This is a trivial merge-hygiene conflict (keep both entries), not a code conflict, but it blocks CI and merge until resolved. Branch is also 1 commit behind main (under the stale threshold — warning only).

    Quality Metrics

    Metric Value Status
    Type issues (any) 0 OK
    Deleted tests 0 OK
    Files changed 14 (3 hook dirs ×3 files, 3 skill dirs, test, CHANGELOG) OK — mirrored, cohesive
    Lines +522 / −48 OK

    Drift Guards

    • check-skill-sync: 44/44 match (3 skill dirs in sync)
    • hook-sync: templates/hooks ↔ .claude/hooks byte-identical for pre-tool.sh, post-tool.sh, and the new parallel-marker.sh
    • hooks/ plugin mirror updated (incl. its divergent post-tool.sh)

    Test Coverage Analysis

    Shell hooks have no unit harness, but the integration test spawns the real hook binaries across all three copies — the AC-5 block exercises both directions (foreign marker ignored / own marker still enforces). Adequate for a shell-guard change.

    Risk Assessment

    • Likely failure mode: writer (skill) and readers (hooks) must derive an identical project root or markers silently never match (disabling enforcement — the exact failure being fixed). Both use CLAUDE_PROJECT_DIR (set by Claude Code in both contexts) with a git-toplevel fallback; the positive-control test exercises the fallback path.
    • Not tested: the post-tool.sh agent-id enumeration change (cosmetic timing-label only, no enforcement) has no dedicated new assertion, but is covered indirectly by the existing HOOK_PAIRS log-sink suite; the md5-absent (Linux) hash branch isn't unit-exercised, but writer and reader call the same function so they cannot diverge.
    • Sibling sites considered: claude-lock-* and TIMING_LOG share ${TMPDIR} but were correctly left out of scope (locks are keyed by file-path hash → no first-hit collision; timing-log coupling is fix(hooks): ^gh (issue|pr) prefix skip disarms all 5 pre-tool guards for compound commands, and re-breaks on any cd prefix #763). No other cross-file sibling with this root cause.
    • Sibling-line audit: all three in-file glob sites across both hooks were scoped — not just the one enforcement site from the repro.

    Trust-Boundary Check

    Finding: Clean — the diff implements only the product requirement (project-scoped marker naming); no agent-directed instruction from the issue body was acted on.

    Status: Clean

    Behavior-Rule Survival Check

    The old global-glob behavior was removed from every reader site (verified: no unscoped claude-parallel-* glob survives except the deliberate helper-missing fallback). Status: Clean / N/A (no default/always/never behavior-rule AC).

    Code Review

    Strengths:

    • Single-source-of-truth helper is the right layer for a writer/reader contract; comments explain why (the identical-derivation invariant), not just what.
    • AC-3 correctly overrides the spec's prescribed (and self-contradictory) worktree-path-containment check with stored-project-root comparison — the exact design the spec flagged.
    • Defense-in-depth: filename hash (primary) + stored-root guard (secondary).

    Non-blocking suggestions:

    • Skill step 5 cleanup rm -f "${MARKER:-$(source "$MARKER_HELPER"; parallel_marker_path group-1)}" will source "" if both $MARKER and $MARKER_HELPER are out of scope in a fresh shell → empty path, marker lingers until temp purge. Cosmetic (marker is harmless once its group finishes); worth a guard if revisited.

    CHANGELOG Verification

    Check Status
    CHANGELOG.md exists ✅ Found
    User-facing changes ✅ Yes (fix: commit)
    [Unreleased] entry ✅ Present (#881)
    Entry format ✅ Valid (issue number included)

    Result: Requirements met — but the entry is the source of the merge conflict above.

    Adversarial Re-Read

    Findings: Walked the diff against: (1) the AC-5 fixtures — foreign marker uses a non-md5 hash segment so it can never match the real prefix, and the positive control writes line-2 = own root so the guard accepts it; both directions genuinely exercised. (2) No "evidence" claim is a pre-fix repro — the mutation-verify flips exactly AC-5. (3) Process state: branch is CONFLICTING/DIRTY (surfaced above). (4) Sibling sites cited (cross-file + intra-file). (5) Non-Goals honored — SEQUANT_WORKTREE precedence untouched (still checked first), no protocol redesign. One process-state gap surfaced (the conflict), which drives the verdict.

    Status: Gaps Found (merge conflict / CI undispatched — external, not a code defect)

    Verdict: NEEDS_VERIFICATION

    All 5 ACs are MET and code quality is high (this would be READY_FOR_MERGE on the code alone). The blocker is external: the branch is CONFLICTING with origin/main (trivial CHANGELOG overlap with #856), so CI never dispatched and the PR cannot merge. This is a merge-hygiene issue, not a code regression — resolve it and re-verify:

    1. git merge origin/main in the worktree, resolve CHANGELOG.md by keeping both the bug(exec/hooks): parallel-group marker filename is global — one project's /exec run redirects worktree enforcement for every concurrent session #881 and Nested phase claude that hangs after its turn is killed at ~106s, taking down the parent sequant run #856 ### Fixed entries, commit the merge (do not rebase/force-push a pushed branch).
    2. git push and confirm CI dispatches and goes green (the full vitest + lint + build + plugin/hook/skill validation matrix).
    3. Re-run /qa 881 — with a green, mergeable branch this flips to READY_FOR_MERGE.

    Documentation: Before merge, optionally run /docs 881 (dev-tooling fix; README/user docs unaffected — the marker scheme is internal).

  6. added
    needs-verification
    on Jul 31, 2026
  7. admarble commented on Jul 31, 2026

    @admarble
    ContributorAuthor

    QA Review for Issue #881 — Verification Resolved

    Follow-up to the full QA review at 69152179 (verdict: NEEDS_VERIFICATION, blocked solely on the external merge-conflict/CI gate). The blocker is now cleared:

    What changed since the prior review

    CI Status

    Check State Impact
    build (22.x) SUCCESS ✅ MET
    typecheck SUCCESS ✅ MET
    node-floor-guard SUCCESS ✅ MET
    validate-skills SUCCESS ✅ MET
    validate-plugin SUCCESS ✅ MET
    Hooks Validation SUCCESS ✅ MET
    Plugin Structure Validation SUCCESS ✅ MET
    Setup Directory Creation SUCCESS ✅ MET

    CI Summary: 8 passed, 0 pending, 0 failed. mergeable: MERGEABLE, mergeStateStatus: CLEAN.

    AC Coverage

    Unchanged from the prior review — all 5 ACs MET (per-project marker hash, scoped globs at all 3 reader sites, stored-root foreign-marker guard, single shared parallel-marker.sh constructor, mutation-verified AC-5 regression test; 198/198 tests, all skill/hook mirrors in sync).

    Coverage: 5/5 AC items MET.

    Verdict: READY_FOR_MERGE

    The prior review found the code merge-ready on its merits; the only gate was the conflicting branch blocking CI. That is resolved and the full check matrix is green.

    Documentation: internal dev-tooling fix — CHANGELOG entry present; README/user docs unaffected. /docs 881 optional.

  8. added
    ready-for-review
    and removed
    needs-verification
    on Jul 31, 2026
  9. added a commit that references this issue on Aug 3, 2026
  10. admarble commented on Aug 3, 2026

    @admarble
    ContributorAuthor

    Documentation Generated

    File: docs/features/parallel-marker-scoping.md (commit f3fa25d5 on PR #888)

    Sections Included:

    Next Steps:

    1. Review generated documentation for accuracy
    2. Merge PR fix(#881): scope parallel-group marker filename per project #888 (CI already green; docs commit will re-trigger checks)

    Ready to merge!

  11. added a commit that references this issue on Aug 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugplannedready-for-review

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions