Skip to content

bug(worktree): new-feature.sh and sequant run derive different branch names for the same issue #1145

Description

@admarble

What happens

Two producers name the feature branch for an issue, and they disagree once the title slug exceeds 45 characters:

Producer Rule Example for #1123
templates/scripts/new-feature.sh:84-90 (standalone /exec, /fullsolve) slugify the title, then cut the whole branch at 58 chars feature/1123-fix-init-yes-init-replaces-a-user-modified-agen
src/lib/workflow/worktree-manager.ts slugify() (sequant run) slugify the title, cut the slug at 50 chars feature/1123-fix-init-yes-init-replaces-a-user-modified-agents-

ensureWorktree looks an existing branch up by exact name (findExistingWorktree(branch)), so a branch created by the script for a long-titled issue is not found by a later sequant run phase, which creates a second feature/1123-… branch. sequant worktree resolve keys on the issue number and is unaffected, so the two branches then resolve as WORKTREE_AMBIGUOUS.

Evidence

Measured during #1136's QA (2026-09-24): recomputing the branch name from the issue title for the 10 most recently merged feature/ PRs gives 0/10 matches under the script's rule and 10/10 under slugify() — every recent branch came from sequant run. The #1136 in-place block was corrected to the slugify() rule for the same reason (PR #1139, commit 283560c1→7f6d0ba1), and slugify is now exported @internal so a gate can assert parity.

Expected

One rule. new-feature.sh (both templates/scripts/ and the scripts/ symlink) cuts the slug at 50 like slugify(), with a gate test that compares the script's output to slugify() for a title whose slug exceeds 50 characters, mutation-verified. Existing worktrees are unaffected; only new branches for long titles change.

Related

#1136 (the in-place block already uses the slugify() rule) · #899 (resolver keys on issue number) · #1123 (the branch that surfaced it)

Acceptance criteria

Tier: mechanical · Graph: 2026-09-w3 (docs/internal/graph-2026-09-w3/issue-graph.md)

  • AC-1: new-feature.sh derives the branch as feature/<N>-<slug> where slug is exactly slugify(title) — lowercase, runs of non-[a-z0-9] → -, strip leading/trailing -, then cut at 50 with no trailing-dash strip afterwards — and the whole-branch cut at 58 is removed — Verify: npx vitest run src/lib/workflow/__tests__/new-feature-branch-parity.test.ts
  • AC-2: a gate test executes the script's naming logic in a real bash subprocess (not a regex-literal comparison, PM_CONFIG.yarn.ciInstall uses Yarn 2+ --immutable, which Yarn 1 rejects — no berry detection exists #871) and compares it to exported slugify() for a title whose slug exceeds 50 chars with - at position 50, a short title, and a title with leading punctuation — Verify: npx vitest run src/lib/workflow/__tests__/new-feature-branch-parity.test.ts
  • AC-3: the PR body carries a SEQUANT_MUTATION marker for AC-2 (mutation: restore cut -c1-58; failedTest begins with the test file path) — Verify: /qa §6i resolves the marker

Exec decides the network-free entry point for the test (e.g. a branch_name_for function behind a --print-branch <N> <title> flag); the AC only requires real bash execution.

Activity

  1. added
    bug
    on Sep 24, 2026
  2. admarble commented on Sep 25, 2026

    @admarble
    ContributorAuthor

    Runner context (graph 2026-09-w3, docs/internal/graph-2026-09-w3/issue-graph.md, PR #1154) — these rules apply to the spec, exec AND qa phases:

    • qa phase: do not run the full npm test. Verify each AC with its own verify command and run only the named test files. The runner runs the full suite once per PR, serially — three phase agents share this machine and a full-suite call inside a phase can hit the 30-minute no-progress wall.
    • exec phase: commit WIP before any long command; run the full suite at most once, in the foreground, with a timeout; never run_in_background.
    • Gate-test ACs: the PR body's <!-- SEQUANT_MUTATION: {...} --> marker needs failedTest to start with the test file path (src/.../x.test.ts > describe > case), or /qa §6i floors it to AC_NOT_MET.
    • CHANGELOG: add exactly one [Unreleased] line.
    • Stop at the PR — do not merge.
  3. admarble commented on Sep 25, 2026

    @admarble
    ContributorAuthor

    Complexity: Standard (3 ACs, 3 directories)

    AC Quality Check

    No vague/unmeasurable patterns. Two notes: (1) AC-1/AC-2 name src/lib/workflow/__tests__/new-feature-branch-parity.test.ts, but that directory does not exist. Workflow tests here are co-located (src/lib/workflow/*.test.ts) and the script's tests live in root __tests__/*.integration.test.ts. The path is fine to create as written. (2) A file without .integration. in its name runs in the unit project (5s timeout, #842). Bash subprocesses are fast, but a .integration. name is safer, and it would change the Verify path in AC-1/AC-2. See Open Questions.

    Scope Assessment

    Non-Goals: Existing worktrees are unaffected; only new branches for long titles change (from the issue body).

    Metric Value Status
    Feature count 1 ✅
    AC items 3 ✅
    Directory spread 3 (templates/scripts, src/lib/workflow, PR body) ✅

    Verdict: ✅ SCOPE_OK

    Acceptance Criteria

    AC-1: new-feature.sh derives feature/<N>-<slug> exactly as slugify()

    Verification: Integration Test
    Scenario: Given a title whose slug is >50 chars → When the script names the branch → Then the branch equals feature/<N>- + slugify(title) (cut at 50, no trailing-dash strip afterwards), and the 58-char whole-branch cut is gone.
    Assumptions: scripts/new-feature.sh is a symlink to templates/scripts/new-feature.sh (verified), so one edit covers both.

    AC-2: gate test runs the script's naming logic in real bash and compares to slugify()

    Verification: Integration Test
    Scenario: Given three titles (slug >50 with - at position 50, short, leading punctuation) → When bash computes the branch and TS calls slugify() → Then outputs are equal for each.
    Assumptions: slugify is exported (worktree-manager.ts:112, verified).

    AC-3: PR body carries a SEQUANT_MUTATION marker for AC-2

    Verification: Manual Test (/qa §6i resolves the marker)
    Scenario: Given the marker names mutation "restore cut -c1-58" → When /qa parses it → Then failedTest starts with the test file path and resolves.

    Implementation Plan

    Phase 1: Script

    1. In templates/scripts/new-feature.sh:84-90, extract a branch_name_for <N> <title> function that returns feature/<N>-<slug>. The slug pipeline stays as is (tr, sed collapse, strip lead/trail -), then cut -c1-50 on the slug only. Delete the 58-char branch cut and its stale comment.
    2. Add a network-free entry point --print-branch <N> <title>, handled in the arg loop before the gh, auth and fetch checks. It prints the branch and exits 0. The function must be defined above the arg loop, or the flag handler must call it after the definition.
      • Trailing dash: cut at 50 may leave a trailing -, which is intentional parity with slugify(). Do not re-strip.
      • Byte vs char: cut -c on multibyte input. The slug is ASCII-only after sed, so this is a non-issue.

    Phase 2: Gate test

    1. Create src/lib/workflow/__tests__/new-feature-branch-parity.test.ts. For each of the 3 titles, spawn bash templates/scripts/new-feature.sh --print-branch <N> <title> via spawnSync and compare stdout to feature/<N>-${slugify(title)}. Import slugify from ../worktree-manager.js.
    2. Mutation-verify: restore cut -c1-58 on the branch, confirm only the long-slug case fails, restore. Commit before mutating. Record the Mutation-verified: line plus the SEQUANT_MUTATION marker in the PR body. failedTest must be src/lib/workflow/__tests__/new-feature-branch-parity.test.ts > <describe> > <case>.
    3. Add one [Unreleased] CHANGELOG line. Stop at the PR, do not merge.

    Design Review

    1. Where does this logic belong? In the script, aligned to slugify(), which is the canonical source (sequant run produced 10/10 recent branches).
    2. Simplest correct approach? Change the cut. Rejected: making slugify() match the script (would rename branches for every existing long-titled issue and break findExistingWorktree lookups for them).
    3. Existing pattern? The feat(exec/qa): explicit in-place checkout mode — run a phase on a branch in the current clone without creating or resolving a worktree #1136 in-place block in exec/SKILL.md:234 already applies the 50-slug rule. Its slug pipeline already strips before cutting, so it matches slugify() and needs no change.
    4. Reviewer challenge: "Why not have the script call the TS slugify?" It runs in consumer repos with no sequant dist guaranteed. Parity is enforced by the gate test instead.

    Feature Quality Planning

    All standard checks pass. Notable items:

    • The exec worktree feature/1145-bug-worktree-new-feature-sh-and-sequant-run-derive already exists (created at aa865de). Its name is 58-cut style and is left as is; the fix only affects new branches.
    • Sibling scan: the other producer sites (exec/SKILL.md in-place block, slugify()) already use the 50 rule. No other 58-char cut was found in the skills, docs or README (grep).
    • All 3 skill dirs are unaffected, since no SKILL.md edit is needed. If exec wants a comment update, mirror it across all 3 dirs.

    Rule Touchpoints

    Behavior-rule detector not run: the ACs do not use ≥2 of the rule keywords, so the touchpoints section is omitted.

    Open Questions

    1. Test filename .integration.? — Recommendation: keep the path exactly as the AC states (the AC pins it), and set an explicit testTimeout inside the file if it runs in unit. Impact if wrong: a 5s flake under full-suite load (fix(test): tsx-spawning integration tests blow vitest's 5s default — phase-registry should use the prebuilt dist like its five siblings #842).
    2. --print-branch interface — Recommendation: as in the plan, since the AC leaves this to exec.

    Recommended Workflow

    Phases: exec → qa
    Quality Loop: disabled
    Reasoning: Small mechanical bug fix, one script and one gate test. The Testgen skip rule for bug-only issues applies. The runner comment says qa must not run the full npm test.

    Label Review

    Current: bug · Recommended: bug, planned · Quality Loop: won't auto-enable.

  4. added
    planned
    on Sep 25, 2026
  5. admarble commented on Sep 25, 2026

    @admarble
    ContributorAuthor

    QA Review for Issue #1145 (Simple Fix)

    Verdict: AC_NOT_MET — all three ACs are met, but the diff turns the required canary check red. Settled mechanically: canary is 4/4 green at origin/main and 2/4 red at f2f9dbf4 in the same worktree, and reverting only templates/scripts/new-feature.sh (keeping the test + CHANGELOG) makes it green again.

    AC Coverage

    AC Status Evidence
    AC-1 MET branch_name_for cuts the slug at 50; the whole-branch cut -c1-58 is gone (grep -rn 'c1-58|-gt 58' → no hits repo-wide). Differential over 100 real issue titles (97 hit the 50-cap): 0 mismatches vs exported slugify(). The issue's own example reproduces: feature/1123-fix-init-yes-init-replaces-a-user-modified-agents-.
    AC-2 MET new-feature-branch-parity.test.ts spawns real bash (spawnSync, not a regex-literal compare, #871) for all three required cases; a 4th test pins that the long fixture really exceeds 50 with - at index 49. npx vitest run …new-feature-branch-parity.test.ts → 4 passed.
    AC-3 MET parseMutationMarkers classifies the PR-body marker valid (failedTest begins with the test file path).

    Regression — required canary check (blocking)

    Live ruleset CC requires test and canary.

    ### Settled against base
    Test:  __tests__/canary/downstream.integration.test.ts  (SETTLE_TEST_CMD="npx vitest run --project canary")
    HEAD (f2f9dbf4):      2 failed | 2 passed
    Base (origin/main):   4 passed
    Isolation: reverting only templates/scripts/new-feature.sh → 4 passed
    

    Failure: sequant sync predicts scripts/dev/new-feature.sh will be rewritten but does not rewrite it, so the fixture is left permanently drifted and the next sync exits 1 with Version current, but 1 file(s) differ from bundled content.

    Root cause is #1122 (update/init/sync don't write through an existing symlink at a sequant-owned destination) — scripts/dev/*.sh is synced as symlinks (templates.ts:1111). This PR is simply the first change to templates/scripts/new-feature.sh content since the previous minor release, so it is the first to expose it. The defect is not in this diff's logic, but the red required check is caused by this diff.

    Remediation (either): land #1122 first and rebase, or fix the writer here.

    Quality Metrics

    Metric Value
    Diff size 63 lines (threshold 100) → Simple Fix
    Type issues (any) 0
    Deleted tests 0
    Files changed 3 (+56 / −7)

    Trust-Boundary Check

    Finding: Clean — issue body contains no HTML comments and no agent-directed instruction; the diff implements only product requirements.
    Status: Clean

    Behavior-Rule Survival Check

    Detector not triggered for AC-1/AC-2. Manual survival grep: no cut -c1-58 / -gt 58 anywhere. All three exec SKILL.md mirrors already carry the cut-at-50 rule (#1136).
    Status: Clean

    Declared-Evidence Execution

    AC Evidence Executed? Result
    AC-1 / AC-2 npx vitest run src/lib/workflow/__tests__/new-feature-branch-parity.test.ts Yes 4 passed
    AC-3 /qa §6i marker resolution Yes valid

    Status: Complete

    Mutation Verification

    AC-2 → src/lib/workflow/__tests__/new-feature-branch-parity.test.ts > new-feature.sh branch name parity with slugify() > long slug with dash at position 50 — Verified. The gate also fails under the original bug (whole-branch cut at 58 yields a 45-char slug for #1123), not just the recorded mutation.

    Status: Verified

    CHANGELOG Verification

    Entry present under [Unreleased] → Fixed with (#1145). Result: met.

    Other findings (non-blocking)

    • §11 Script verification: Not Verified. templates/scripts/ changed with no /verify evidence and no approved override. Would floor at AC_MET_BUT_NOT_A_PLUS on its own.
    • scripts/ruleset-main.sh --print lists only test; the live CC ruleset requires test and canary. The checked-in ruleset script has drifted from what is enforced — worth a follow-up.
    • --print-branch is undocumented in the script's usage header, and --print-branch with missing args prints feature/- instead of erroring. The early-exit sits before argument validation.
    • Zero-arg and normal invocation paths still behave correctly (usage error printed).

    Risk Assessment

    Next Steps

    1. Land fix(writers): update/init/sync write through an existing symlink at a sequant-owned destination (#1053 class) #1122 (or fix the symlink-writing path) so canary goes green, then rebase this branch. Re-run npx vitest run --project canary locally before pushing — npm test excludes the canary project, which is why the PR body's "full npm test passes" did not catch this.
    2. Optional: document --print-branch in the usage header and make it error on missing args.
  6. admarble commented on Sep 25, 2026

    @admarble
    ContributorAuthor

    QA Verdict: AC_NOT_MET

  7. admarble commented on Sep 25, 2026

    @admarble
    ContributorAuthor

    Runner verification (PR #1156). All 3 ACs pass per QA. The required canary check fails on this branch, and I reproduced it: npx vitest run --project canary at f2f9dbf → 2 failed | 2 passed (QA: base passes 4/4, and reverting only templates/scripts/new-feature.sh restores green). The cause is #1122. The canary fixture's scripts/dev/new-feature.sh is a symlink, and sync doesn't write through it, so the fixture drifts once the template changes.

    New graph edge: #1145 must merge after #1122. When #1122 lands, merge main into this branch and re-run the canary.

  8. added a commit that references this issue on Sep 25, 2026
  9. admarble commented on Sep 25, 2026

    @admarble
    ContributorAuthor

    Correction to the runner comment above: this is not blocked by #1122. I merged #1122's branch (aef6c9db) into this one and ran npx vitest run --project canary: the same 2 failures. The actual cause is #1159. sync points scripts/dev/new-feature.sh at the older copy in the project's node_modules, following the #991 design, while the drift check compares it against the running bundle. I reproduced this against a real [email protected] project.

  10. added 2 commits that reference this issue on Sep 25, 2026
  11. added a commit that references this issue on Sep 25, 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

    bugplanned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions