Skip to content

QA skill: add stale worktree detection to pre-flight check #304

Closed

Description

@admarble

Problem

The /qa pre-flight sync check only verifies that main is in sync with origin/main. It does not check whether the feature worktree branch has diverged from main.

This means QA can run a full review on a feature branch that is dozens of commits behind main, give a READY_FOR_MERGE verdict, and then fail at merge time with conflicts — or worse, merge stale content.

Current pre-flight check

git fetch origin 2>/dev/null
git status -sb | head -1  # Only checks current branch vs its remote

This tells you nothing about whether the feature branch is current with main.

What's missing

cd <worktree-path>
behind=$(git log --oneline HEAD..main | wc -l | xargs)
if [[ $behind -gt 0 ]]; then
  echo "STALE: Feature branch is $behind commits behind main. Rebase before QA."
fi

Impact

  • Wasted QA cycles reviewing code that can't cleanly merge
  • False READY_FOR_MERGE verdicts
  • Wasted tokens and sessions when the merge fails and work needs to be redone

Acceptance Criteria

  • QA pre-flight checks how far behind main the feature branch is
  • If behind > 0, emit a warning with the count
  • If behind > N (configurable threshold, default ~5), block QA with STALE_BRANCH and recommend rebase
  • Same check should be added to /exec and /test pre-flight as well
  • Document the check in the skill's pre-flight section

Activity

  1. admarble commented on Mar 12, 2026

    @admarble
    ContributorAuthor

    Solve Analysis

    Recommended Phases: spec → exec → qa
    Skip Spec: No (needs pre-flight check design across multiple skills)
    Browser Testing: No (skill file changes, not UI)
    Quality Loop: Yes (part of 3-issue chain modifying QA skill)

    Reasoning

    Flags

    Flag Value Reasoning
    -q (quality-loop) ✓ Part of multi-issue chain modifying shared files
    --chain ✓ Shares .claude/skills/qa/SKILL.md with #254, #307
    --qa-gate ✗ Additive sections, low stale risk
    --base ✗ Branching from main
    --testgen ✗ Skill config changes, no unit test ACs

    📝 Generated by /solve

  2. admarble commented on Mar 12, 2026

    @admarble
    ContributorAuthor

    Spec Plan: Stale Worktree Detection for Pre-flight Checks

    Acceptance Criteria (with Verification)

    AC Description Verification Method
    AC-1 QA pre-flight checks how far behind main the feature branch is Integration Test
    AC-2 If behind > 0, emit a warning with the count Integration Test
    AC-3 If behind > N (configurable threshold, default ~5), block QA with STALE_BRANCH Integration Test
    AC-4 Same check added to /exec and /test pre-flight Integration Test
    AC-5 Document the check in each skill's pre-flight section Manual Test

    Implementation Plan

    Phase 1: Configuration

    1. Add staleBranchThreshold: number to RunSettings in src/lib/settings.ts
    2. Default value: 5 commits

    Phase 2: QA Skill
    3. Add "Stale Branch Detection" section to .claude/skills/qa/SKILL.md
    4. Implement: warn if 1-5 behind, block if >5 behind

    Phase 3: exec/test Skills
    5. Add stale detection to .claude/skills/exec/SKILL.md (warn only)
    6. Add stale detection to .claude/skills/test/SKILL.md (warn + block)

    Phase 4: Documentation
    7. Document behavior, thresholds, and rebase recommendations

    Files Changed

    File Change
    src/lib/settings.ts Add staleBranchThreshold to RunSettings
    .claude/skills/qa/SKILL.md Add stale detection section
    .claude/skills/exec/SKILL.md Add stale detection (warn only)
    .claude/skills/test/SKILL.md Add stale detection section

    Design Decisions

    1. Threshold: Configurable via staleBranchThreshold in settings (default: 5)
    2. QA behavior: Block if over threshold, recommend rebase
    3. exec behavior: Warn only (don't block implementation start)
    4. test behavior: Block if very stale (testing stale code is wasteful)
    5. Orchestration: Skip check when SEQUANT_ORCHESTRATOR is set

    Conflict Risk

    ⚠️ In-flight work: Issue #254 also modifies .claude/skills/qa/SKILL.md

    Quality Loop

    ✅ Enabled — Part of chain with #254, #307 modifying QA skill

    Assumptions to Validate

    • Default branch is main (not master)
    • Remote is named origin
    • Worktree path is detectable via git worktree list

    Ready for implementation. Run /exec 304 to begin.

  3. added a commit that references this issue on Mar 12, 2026
  4. admarble commented on Mar 12, 2026

    @admarble
    ContributorAuthor

    Implementation Progress Update

    AC Coverage

    AC Description Status Evidence
    AC-1 QA pre-flight checks how far behind main ✅ MET .claude/skills/qa/SKILL.md:230-290
    AC-2 If behind > 0, emit a warning ✅ MET Stale Branch Detection section in all skills
    AC-3 If behind > N, block QA with STALE_BRANCH ✅ MET QA/test block, exec warns only
    AC-4 Same check in /exec and /test ✅ MET Added to both skills
    AC-5 Document in pre-flight section ✅ MET Documentation included in each skill

    Files Changed

    File Change
    src/lib/settings.ts Add staleBranchThreshold: number (default: 5)
    .claude/skills/qa/SKILL.md Add "Stale Branch Detection" section
    .claude/skills/exec/SKILL.md Add section "0a. Stale Branch Detection (Warning Only)"
    .claude/skills/test/SKILL.md Add "Pre-flight: Stale Branch Detection" section
    CHANGELOG.md Add feature to [Unreleased]

    Check Results

    Check Status Notes
    npm run build ✅ Passed TypeScript compiles cleanly
    npm run lint ⚠️ 5 warnings Pre-existing, unrelated to these changes
    npm test ⚠️ 1 timeout Pre-existing flaky test in state-utils.test.ts

    Self-Evaluation

    • Worked as expected: Yes - all skill files updated with detection logic
    • Test coverage confidence: Medium - skill changes are documentation/config, no unit tests needed
    • Weakest part: The bash scripts in skills are examples, not enforced code
    • Honest assessment: Implementation follows spec; actual behavior depends on skill execution

    PR Status

    ✅ PR Created: #350

    Next Steps

    1. Run /qa 304 to verify implementation
    2. Merge after QA approval

    🤖 Generated by /exec 304

  5. admarble commented on Mar 12, 2026

    @admarble
    ContributorAuthor

    QA Review: #304 — Stale Worktree Detection for Pre-flight Checks

    PR: #350
    Branch: feature/304-qa-skill-add-stale-worktree-detection-to-pre-fligh
    Commit: d40c115 — feat(#304): add stale branch detection to pre-flight checks


    Stale Branch Check

    Check Value
    Commits behind main 0
    Threshold 5
    Status OK

    Phase 0b: Quality Plan Verification

    Spec plan exists (comment from 2026-03-12T03:53:29Z). Plan calls for:

    1. Add staleBranchThreshold to RunSettings — Done
    2. Add stale detection to QA skill — Done
    3. Add stale detection to exec skill (warn only) — Done
    4. Add stale detection to test skill (block) — Done
    5. Document in pre-flight section — Done

    Verdict: Spec plan fully followed.


    Phase 1: CI Status

    Job Status
    build (18.x) FAILURE (Lint)
    build (20.x) CANCELLED
    build (22.x) FAILURE (Lint)
    validate-skills SUCCESS
    typecheck SUCCESS
    validate-plugin SUCCESS

    Lint failures are PRE-EXISTING — 5 warnings in src/commands/run.ts and src/lib/workflow/batch-executor.ts (unused vars from prior refactor #347). None of the warnings reference files changed in this PR. This PR's changes compile cleanly (typecheck passes).


    AC Verification

    AC Description Status Evidence
    AC-1 QA pre-flight checks how far behind main the feature branch is MET .claude/skills/qa/SKILL.md — Stale Branch Detection section with git rev-list --count HEAD..origin/main
    AC-2 If behind > 0, emit a warning with the count MET Warning row in behavior table for 1-to-threshold range in all three skills
    AC-3 If behind > N (configurable threshold, default ~5), block QA with STALE_BRANCH MET QA and test skills block with exit 1; threshold configurable via staleBranchThreshold (default: 5)
    AC-4 Same check added to /exec and /test pre-flight MET .claude/skills/exec/SKILL.md (warn only) and .claude/skills/test/SKILL.md (warn + block)
    AC-5 Document the check in the skill's pre-flight section MET Each skill file includes Detection, Threshold Configuration, Behavior table, Implementation, and Output Format subsections

    Code Review Findings

    Type Safety

    • staleBranchThreshold: number properly typed in RunSettings interface
    • Default value 5 set in DEFAULT_SETTINGS
    • JSDoc comment explains the field's purpose

    Scope & Size

    • 5 files changed, +249 lines, 0 deletions — appropriate for the scope
    • Pure additions (no deletions) — low regression risk
    • Changes are self-contained: settings type + skill documentation

    Security

    • No secrets, credentials, or sensitive data exposed
    • Bash snippets use 2>/dev/null || true and || echo "0" for safe error handling
    • jq -r '.run.staleBranchThreshold // 5' uses jq default operator — safe fallback

    Design Review

    • exec warns, qa/test block — correct per spec and AC. Starting implementation on a stale branch is acceptable; running QA/tests on stale code is wasteful.
    • SEQUANT_ORCHESTRATOR skip — all three skills correctly skip the check when orchestrated.
    • Consistent output format across all three skills (markdown table).

    BLOCKING ISSUE: Skill Directory Sync

    The templates/skills/ and skills/ directories were NOT updated.

    Per project convention (documented in CLAUDE.md memory), three directories must stay in sync:

    • .claude/skills/ (updated)
    • templates/skills/ (NOT updated)
    • skills/ (NOT updated)

    This means sequant init will regenerate skill files WITHOUT the stale branch detection, and the skills/ reference copies will be stale.

    Files missing changes:

    • templates/skills/qa/SKILL.md
    • templates/skills/exec/SKILL.md
    • templates/skills/test/SKILL.md
    • skills/qa/SKILL.md
    • skills/exec/SKILL.md
    • skills/test/SKILL.md

    CHANGELOG

    CHANGELOG.md updated with clear entry under [Unreleased] > Added. Describes the feature, per-skill behavior, and configurability.


    Anti-Pattern Check

    Pattern Status
    Hardcoded secrets None
    TODO/FIXME left behind None
    Console.log debugging None
    Overly broad catch N/A (skill docs, not runtime code)
    Missing error handling in bash Handled with `

    Adversarial Self-Evaluation

    • Could I have missed something? The bash code in skill files is illustrative (not executed as code), so runtime bugs are unlikely. However, the missing sync across skill directories is a real correctness issue.
    • Am I being too lenient on CI? No — the lint warnings are clearly pre-existing in unrelated files (run.ts, batch-executor.ts), confirmed by examining the failure output. Typecheck and validate-skills both pass.
    • Is the threshold of 5 reasonable? Yes — it's a sensible default and is configurable, so users can adjust.

    Verdict

    REVISE — 1 blocking issue

    The implementation correctly addresses all 5 acceptance criteria, but the skill file changes were only applied to .claude/skills/ and not mirrored to templates/skills/ and skills/. This is a known sync requirement for this codebase. The fix is straightforward: copy the stale branch detection sections to the corresponding files in both templates/skills/ and skills/.

    Action items:

    1. Add stale branch detection sections to templates/skills/{qa,exec,test}/SKILL.md
    2. Add stale branch detection sections to skills/{qa,exec,test}/SKILL.md
    3. Push updated commit and re-trigger CI

    Generated by /qa 304

  6. added
    needs-work
    ready-for-review
    and removed
    needs-work
    on Mar 12, 2026
  7. admarble commented on Mar 12, 2026

    @admarble
    ContributorAuthor

    RE-QA Review: #304 — Stale Worktree Detection for Pre-flight Checks

    PR: #350
    Branch: feature/304-qa-skill-add-stale-worktree-detection-to-pre-fligh
    Commits: d40c115 (feat), b61cde0 (template sync fix)
    Previous QA Verdict: REVISE (template sync missing)


    Stale Branch Check

    Check Value
    Commits behind main 0
    Threshold 5
    Status OK

    Phase 0b: Quality Plan Verification

    Spec plan exists (comment from 2026-03-12T03:53:29Z). All 4 phases followed:

    1. Configuration (staleBranchThreshold in settings) — Done
    2. QA skill stale detection — Done
    3. exec/test skill stale detection — Done
    4. Documentation in pre-flight sections — Done

    Verdict: Spec plan fully followed.


    Phase 1: CI Status

    Job Status Notes
    build (18.x) FAILURE (Lint) Pre-existing: unused vars in run.ts, batch-executor.ts
    build (20.x) FAILURE (Lint) Same pre-existing lint warnings
    build (22.x) FAILURE (Lint) Same pre-existing lint warnings
    validate-skills SUCCESS
    typecheck SUCCESS
    validate-plugin SUCCESS
    Hooks Validation FAILURE Pre-existing: hooks test exit code handling
    Plugin Structure FAILURE Pre-existing: --local flag not available

    All failures are pre-existing and unrelated to this PR. The 5 lint warnings are in src/commands/run.ts (lines 24, 57) and src/lib/workflow/batch-executor.ts (lines 29, 34) — none of which are touched by this PR. Typecheck and validate-skills both pass.


    AC Verification

    AC Description Status Evidence
    AC-1 QA pre-flight checks how far behind main the feature branch is MET .claude/skills/qa/SKILL.md — Stale Branch Detection section with git rev-list --count HEAD..origin/main
    AC-2 If behind > 0, emit a warning with the count MET Warning row in behavior table for 1-to-threshold range in all three skills
    AC-3 If behind > N (configurable threshold, default ~5), block QA with STALE_BRANCH MET QA and test skills block with exit 1; threshold from staleBranchThreshold (default: 5)
    AC-4 Same check added to /exec and /test pre-flight MET exec SKILL.md (warn only) and test SKILL.md (warn + block)
    AC-5 Document the check in each skill's pre-flight section MET Detection, Threshold Configuration, Behavior table, Implementation, Output Format subsections in each skill

    Previous Blocking Issue: Template Sync — RESOLVED

    Directory Pair qa exec test
    .claude/skills/ vs skills/ Identical Identical Identical
    .claude/skills/ vs templates/skills/ Identical Identical Identical

    All six directory pairs confirmed identical via diff. The sync commit b61cde0 correctly resolved the previous blocking issue.


    Code Review Findings

    Type Safety:

    • staleBranchThreshold: number properly typed in RunSettings interface
    • Default value 5 set in DEFAULT_SETTINGS
    • JSDoc comment explains purpose

    Scope & Size:

    • 11 files changed — 5 unique changes (settings.ts + 3 skills + CHANGELOG) x 3 directories for skills
    • Pure additions — no regressions possible
    • No scope creep beyond the issue requirements

    Security:

    • No secrets, credentials, or sensitive data
    • Bash snippets use 2>/dev/null || true and || echo "0" for safe error handling
    • jq -r '.run.staleBranchThreshold // 5' uses jq default operator — safe fallback

    Design:

    • exec warns only (correct — don't block implementation start)
    • qa and test block above threshold (correct — wasteful to review/test stale code)
    • SEQUANT_ORCHESTRATOR skip in all three (correct — orchestrator manages freshness)
    • Consistent output format across all three skills (markdown table)

    Anti-Pattern Check

    Pattern Status
    Hardcoded secrets None
    TODO/FIXME left behind None
    Console.log debugging None
    Missing error handling in bash Handled with `

    CHANGELOG

    Updated under [Unreleased] > Added with clear entry describing the feature, per-skill behavior, and configurability.


    Adversarial Self-Evaluation

    • Template sync: Verified all 6 pairs are byte-identical. The previous blocking issue is fully resolved.
    • CI failures: Confirmed pre-existing by examining failure output — all 5 lint warnings reference files not touched by this PR.
    • Bash safety: All skill bash snippets use proper error suppression (|| true, || echo "0", 2>/dev/null) — consistent with project conventions.
    • Threshold default: 5 is reasonable and configurable — no hardcoded magic numbers.
    • Edge case: What if origin/main doesn't exist? git rev-list will fail silently via 2>/dev/null || echo "0", defaulting to 0 (proceed). This is acceptable — if remote is unavailable, the check is skipped gracefully.

    Verdict

    READY_FOR_MERGE

    All 5 acceptance criteria are met. The previous blocking issue (template sync) has been fully resolved — all three skill directories are confirmed identical. No new issues found. CI failures are pre-existing and unrelated.


  8. added a commit that references this issue on Mar 12, 2026
  9. admarble commented on Mar 12, 2026

    @admarble
    ContributorAuthor

    Documentation Generated

    File: docs/features/stale-branch-detection.md

    Sections Included:

    • Quick Start — what stale branch detection does and why it matters
    • How It Works — per-skill behavior table (qa blocks, exec warns)
    • Usage — default behavior, resolving stale branches, customizing threshold
    • Options & Settings — staleBranchThreshold configuration
    • Common Workflows — QA after active main development, orchestration bypass
    • Troubleshooting — stale after rebase, threshold tuning

    Key Details Covered:

    • Threshold default (5 commits) and how to override in .sequant/settings.json
    • Difference between /qa+/test (blocks) vs /exec (warns only)
    • SEQUANT_ORCHESTRATOR bypass during orchestrated runs
    • Rebase instructions for resolving blocked state

    Next Steps:

    1. Review generated documentation for accuracy
    2. Merge PR to deploy documentation

    Ready to merge!

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

    ready-for-review

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions