Repository navigation
Description
Problem
When ensureWorktree() finds a pre-existing worktree, it returns early at run.ts:281-293 with existed: true, rebased: false — completely bypassing the chain mode rebase logic at lines 358-411. This causes --chain to silently produce independent branches instead of chained ones.
Reproduction
# Run 1: creates worktree for #40 from origin/main (aborted early or without --chain)
npx sequant run 40 --sequential -q
# Run 2: intended chain — but #40's worktree already exists
npx sequant run 40 41 42 --sequential --chain -qExpected: main → #40 → #41 → #42 (each branch contains previous commits)
Actual: All 3 branch independently from main. #41 does NOT contain #40's commits.
Root Cause
ensureWorktree() at line 280-293:
const existingPath = findExistingWorktree(branch);
if (existingPath) {
return {
issue: issueNumber,
path: existingPath,
branch,
existed: true,
rebased: false, // ← never checks chainMode
};
}The early return skips:
- The
chainMode && baseBranchcheck at line 359 - The rebase logic at lines 377-411
- The
baseRefcalculation at lines 311-319
So when ensureWorktreesChain() iterates issues and the first worktree already exists, previousBranch is set to that branch name (line 564), but the second worktree is created from origin/main instead of being based on the first branch — because the rebase only happens for branches that are newly discovered (existing branch but no worktree, line 352-361), not for pre-existing worktrees.
Secondary Issue: RunConfig doesn't log chain/qaGate flags
run-log-schema.ts:123-132 — RunConfigSchema only records phases, sequential, qualityLoop, maxIterations. The chain and qaGate flags are not persisted in run logs, making it impossible to diagnose chain issues from logs alone.
Suggested Fix
In the existing-worktree early return block (line 281), add chain mode handling:
const existingPath = findExistingWorktree(branch);
if (existingPath) {
// In chain mode, rebase existing worktree onto previous chain link
if (chainMode && baseBranch) {
const rebaseResult = spawnSync(
"git", ["-C", existingPath, "rebase", baseBranch],
{ stdio: "pipe" }
);
return {
issue: issueNumber,
path: existingPath,
branch,
existed: true,
rebased: rebaseResult.status === 0,
};
}
return {
issue: issueNumber,
path: existingPath,
branch,
existed: true,
rebased: false,
};
}Also add chain and qaGate to RunConfigSchema.
Evidence
Observed during sequant run 40 41 42 46 --sequential --chain -q on sequant-landing. Three run log files were created:
run-2026-02-17T23-50-44— only feat: Add orchestration context awareness to skills #40, 17s (worktree created)run-2026-02-17T23-51-36— only feat: Add orchestration context awareness to skills #40, 25s (worktree reused)run-2026-02-17T23-53-07— all 4 issues, 928s (successful but not chained)
Git verification confirmed all 4 branches forked independently from main:
git log main..feature/41-* --oneline | grep "checkpoint(#40)" → 0 results
Acceptance Criteria
- Existing worktrees are rebased onto
previousBranchwhenchainModeis true - Run logs record
chainandqaGateflags inRunConfig - Chain mode works correctly even when some worktrees pre-exist from earlier runs
- Add test case: chain with pre-existing first worktree
Activity
fix(chain): rebase pre-existing worktrees onto chain base
admarble commentedon Feb 18, 2026
Implementation Progress Update
AC Coverage
src/commands/run.ts:290-360chain/qaGateto RunConfigSchemasrc/lib/workflow/run-log-schema.ts:130-133src/commands/run.test.tsandrun-log-schema.test.tsFiles Changed
src/commands/run.ts- Added rebase logic inensureWorktree()for chain modesrc/lib/workflow/run-log-schema.ts- Added optionalchainandqaGatefieldssrc/commands/run.test.ts- Added tests for pre-existing worktree handlingsrc/lib/workflow/run-log-schema.test.ts- Added tests for new schema fieldsQuality Checks
npm run buildnpm run lintnpm testPR Created
PR #291: #291
Quality Plan Alignment
N/A - No quality plan in issue (no /spec run)
admarble commentedon Feb 18, 2026
QA Review for Issue #289
AC Coverage
previousBranchwhenchainModeis truesrc/commands/run.ts:289-360. CheckschainMode && baseBranchand performs rebase usingspawnSync("git", ["-C", existingPath, "rebase", baseBranch])chainandqaGateflags inRunConfigchainandqaGatefields toRunConfigSchemainsrc/lib/workflow/run-log-schema.ts:132-135, with values passed inrun.ts:1767-1768src/commands/run.test.ts:641-728covering rebase behavior, conflict handling, and success/failure scenariosCoverage: 4/4 AC items fully met
CI Status
build (18.x)build (20.x)build (22.x)validate-skillstypecheckvalidate-pluginCI Summary: 5 passed, 1 pending (build 18.x)
CI-related AC items: N/A - No CI-specific AC items
Quality Metrics
any)Test Coverage Analysis
src/commands/run.tssrc/commands/run.test.tssrc/lib/workflow/run-log-schema.tssrc/lib/workflow/run-log-schema.test.tsCoverage: 2/2 changed source files have corresponding tests
Critical paths without tests: None
Code Review
Strengths:
Issues:
Suggestions:
Test Quality Review
spawnSyncis mocked, appropriate for testing git operationsIssues Found: None
Anti-Pattern Detection
Dependency Audit
N/A - No dependency changes
Code Patterns
run.ts:298-302spawnSyncwith array argsrun.ts:324-326rebase --abortCritical Issues: 0
Warnings: 0
Execution Evidence
N/A - No standalone scripts modified (changes are to main run command logic)
Self-Evaluation
Verdict: NEEDS_VERIFICATION
All acceptance criteria are fully met. The implementation is clean, well-tested, and follows the suggested fix from the issue description. However, CI build (18.x) is still pending - re-run QA after CI completes to confirm READY_FOR_MERGE status.
Documentation
Next Steps
/qa 289to confirm READY_FOR_MERGE once all CI checks passadmarble commentedon Feb 18, 2026
QA Review for Issue #289 (Re-run)
AC Coverage
previousBranchwhenchainModeis truerun.ts:289-360. CheckschainMode && baseBranch, performsspawnSync("git", ["-C", existingPath, "rebase", baseBranch])chainandqaGateflags inRunConfigchainandqaGatefields toRunConfigSchema(run-log-schema.ts:132-135), values passed atrun.ts:1767-1768run.test.ts:641-729+ 4 schema tests inrun-log-schema.test.ts:198-226Coverage: 4/4 AC items fully met
Quality Plan Verification
N/A - No quality plan found in issue comments
CI Status
build (18.x)build (20.x)build (22.x)typecheckvalidate-skillsvalidate-pluginCI Summary: 6 passed, 0 pending, 0 failed (previously 1 pending — now all green)
Quality Metrics
any)Cache Status
N/A - Fresh run
Build Verification
N/A - Build passed
Test Coverage Analysis
src/commands/run.tssrc/commands/run.test.tssrc/lib/workflow/run-log-schema.tssrc/lib/workflow/run-log-schema.test.tsCoverage: 2/2 changed source files have corresponding tests
Critical paths without tests: None
Code Review
Strengths:
ensureWorktree()now includes chain mode handlingrebasedflag in return value enables accurate operation reportingIssues:
spawnSync). This is acceptable for documenting expected decision paths but doesn't verify actual git interaction."CONFLICT","could not apply") may miss edge cases in different git versions. Exit code check (status !== 0) provides the primary safety net.Suggestions:
Test Quality Review
Anti-Pattern Detection
Dependency Audit
N/A - No dependency changes
Code Patterns
run.ts:298spawnSyncwith array argsrun.ts:324rebase --abortcleanupCritical Issues: 0
Warnings: 0
Execution Evidence
N/A - No standalone scripts modified. Changes are to main
runcommand internals.Skill Command Verification
N/A - No skill files changed
Self-Evaluation
chainMode && baseBranch, with proper abort on failure.Verdict: READY_FOR_MERGE
All 4 AC items fully met. CI now fully green (6/6 checks passed — previously had 1 pending). Code quality is high with robust error handling and backwards-compatible schema changes.
Documentation
Next Steps
QA re-run completed: All AC met, CI fully green (previously NEEDS_VERIFICATION → now READY_FOR_MERGE)
fix(chain): rebase pre-existing worktrees onto chain base (#291)
admarble commentedon Feb 18, 2026
Documentation Updated
This issue is a bug fix for chain mode with pre-existing worktrees. The fix makes existing
--chainmode work correctly when worktrees already exist.Documentation Change:
docs/reference/run-command.mdStatus:
--chain,--qa-gate)chainandqaGateflags now recorded in run logs (internal, no user doc needed)Documentation updated and ready to merge.
docs: update what-weve-built and run-command for v1.15.1 changes