Skip to content

QA skill: add small-diff fast path to skip sub-agents for trivial changes #465

Closed

Description

@admarble

Problem

The /qa skill unconditionally spawns 3 sub-agents for quality checks (type-safety, scope/size, security) regardless of diff size. For trivial fixes (e.g., #461 — 9 line substitutions, 57 additions), this adds ~30s latency and ~3x token cost compared to running the same checks inline.

The mandatory output template also includes ~15 sections, most of which are N/A for small mechanical fixes (Quality Plan Verification, Incremental QA, Call-Site Review, Product Review, Smoke Test, CLI Registration, etc.).

Acceptance Criteria

  • AC-1: Add a size gate in the Quality Checks section: if additions + deletions < 100 AND no new dependencies (package.json unchanged) AND no security-sensitive paths changed, allow inline quality checks instead of spawning sub-agents
  • AC-2: Add a "simple fix" output mode that omits N/A-heavy sections (Quality Plan, Incremental QA, Call-Site Review, Product Review, Smoke Test, CLI Registration, Skill Command Verification) when the diff is below the size gate
  • AC-3: The size gate threshold (default: 100 lines) should be configurable via .sequant/settings.json (e.g., qa.smallDiffThreshold)
  • AC-4: Security-sensitive path detection uses the existing anti-pattern detection heuristic (auth|payment|security|middleware|admin)

Context

  • Origin: /reflect after QA of Use exact label matching instead of substring includes() for phase detection #461
  • The QA skill SKILL.md is ~800+ lines; the output template alone is ~200 lines
  • Sub-agents use model="haiku" with mode="bypassPermissions" — the token cost is moderate per-agent but adds up across many small issues
  • The full QA pipeline remains the default for diffs >= threshold or when security-sensitive files are touched

References

Activity

  1. added
    enhancement
    planned
    cli
    on Mar 26, 2026
  2. admarble commented on Mar 26, 2026

    @admarble
    ContributorAuthor

    → PROCEED — Clear ACs, planned label, QA skill optimization

    spec → exec → qa · 4 ACs · -q (configurable threshold + output mode change)

  3. admarble commented on Mar 26, 2026

    @admarble
    ContributorAuthor

    Spec Plan for #465: QA Skill Small-Diff Fast Path

    AC Checklist with Verification Criteria

    AC-1: Size gate for inline quality checks

    Verification Method: Integration Test

    • Given: Feature branch with diff < threshold, no package.json changes, no security-sensitive paths
    • When: /qa invoked
    • Then: Quality checks run inline (no sub-agent spawn), results equivalent to sub-agent output
    • Given: Feature branch with diff >= threshold
    • When: /qa invoked
    • Then: Sub-agents spawned as before (no behavioral change)

    AC-2: Simple fix output mode

    Verification Method: Integration Test

    • Given: Diff below size gate
    • When: /qa completes
    • Then: Output omits: Quality Plan Verification, Incremental QA, Call-Site Review, Smoke Test, CLI Registration, Skill Command Verification, Script Verification Override, Skill Change Review
    • And: Output retains: AC Coverage, Quality Metrics, Code Review, Test Coverage Analysis, Anti-Pattern Detection, Self-Evaluation, Verdict, Documentation, Next Steps

    AC-3: Configurable threshold via settings.json

    Verification Method: Unit Test

    • Given: {"qa": {"smallDiffThreshold": 50}} in settings
    • When: Size gate evaluates a 75-line diff
    • Then: Treated as "not small" (above 50)
    • Given: No qa.smallDiffThreshold in settings
    • When: Size gate evaluates a 75-line diff
    • Then: Treated as "small" (below default 100)

    AC-4: Security-sensitive path detection reuses existing heuristic

    Verification Method: Unit Test

    • Given: Changed files include src/middleware/auth.ts
    • When: Security path detection runs
    • Then: Flagged as security-sensitive → full QA forced
    • Given: Changed files include only src/lib/utils.ts
    • When: Security path detection runs
    • Then: No flag → size gate applies normally

    Derived ACs

    Source Derived AC Priority
    Error Handling AC-5: If size gate evaluation fails, fall back to full QA pipeline High
    Best Practices AC-6: Log size gate decision in QA output Medium

    Implementation Plan

    Phase 1: Settings schema (AC-3)

    1. Add QASettings interface to src/lib/settings.ts with smallDiffThreshold: number (default: 100)
    2. Add qa field to SequantSettings and DEFAULT_SETTINGS

    Phase 2: Size gate logic in QA SKILL.md (AC-1, AC-4)
    3. Insert size gate section before "Quality Checks (Multi-Agent)" (~line 836):

    • Read threshold from .sequant/settings.json
    • Compute additions + deletions from git diff --stat
    • Check package.json in changed files
    • Check security paths via existing regex: auth|payment|security|server-action|middleware|admin
    • Set SMALL_DIFF=true/false flag
    1. Add inline quality check instructions for SMALL_DIFF=true path

    Phase 3: Simple fix output template (AC-2)
    5. Add conditional annotations to existing output template sections (omit N/A-heavy sections when SMALL_DIFF=true)

    Phase 4: Sync templates
    6. Mirror all SKILL.md changes to templates/skills/qa/SKILL.md


    Design Review

    1. Where: QA skill SKILL.md (prompt engineering) + src/lib/settings.ts (settings interface)
    2. Simplest approach: Conditional SMALL_DIFF flag in SKILL.md, branching quality checks and output template. No new files or abstractions.
    3. Existing pattern: Mirrors SEQUANT_ISSUE_TYPE=docs detection (line 844-861) — same early-detect-and-branch pattern. Settings follow staleBranchThreshold convention.
    4. Reviewer challenge: "Won't conditional template diverge?" → Annotations on existing sections (not a copy) reduce drift risk.

    Open Questions

    1. Conditional vs separate template? → Recommend: conditional annotations within existing template (lower maintenance)
    2. Include server-action in security regex? → Yes, AC-4 says "existing heuristic" which includes it

    Recommended Workflow

    Phases: spec → exec → qa
    Quality Loop: enabled (scope spans 4 directories)

    Label Review

    Current: enhancement, planned, cli
    Recommended: Remove cli — no CLI interface changes, only skill prompt + settings interface
    → gh issue edit 465 --remove-label cli

  4. added a commit that references this issue on Mar 26, 2026
  5. admarble commented on Mar 26, 2026

    @admarble
    ContributorAuthor

    Exec Progress Update

    AC Coverage

    AC Source Description Status Evidence
    AC-1 Original Size gate for inline quality checks ✅ Implemented .claude/skills/qa/SKILL.md:836-905 — size gate evaluates diff size, package.json, security paths
    AC-2 Original Simple fix output mode ✅ Implemented .claude/skills/qa/SKILL.md — simplified template omits 9 N/A-heavy sections
    AC-3 Original Configurable threshold via settings.json ✅ Implemented src/lib/settings.ts — QASettings.smallDiffThreshold with default 100, merged in getSettings()
    AC-4 Original Security-sensitive path detection reuses existing heuristic ✅ Implemented Size gate uses `auth
    AC-5 Derived (Error Handling) Fallback to full pipeline on error ✅ Implemented Size gate decision table specifies SMALL_DIFF=false on evaluation errors
    AC-6 Derived (Best Practices) Log size gate decision ✅ Implemented Size Gate markdown table in output template

    Files Changed

    • src/lib/settings.ts — Added QASettings interface, DEFAULT_QA_SETTINGS, wired into SequantSettings and getSettings()
    • src/lib/qa-settings.test.ts — 6 unit tests for QA settings (default, custom threshold, merge behavior)
    • .claude/skills/qa/SKILL.md — Size gate section + inline checks + simplified output template
    • templates/skills/qa/SKILL.md — Synced copy
    • CHANGELOG.md — Added [Unreleased] entry

    Quality Checks

    Check Result
    npm run build ✅ Passed
    npm run lint ✅ Passed
    npm test ✅ 2271/2272 passed (1 pre-existing timeout in state-utils)
    New tests ✅ 6/6 passed

    Quality Plan Alignment: N/A — No quality plan in issue

    PR: #469

  6. admarble commented on Mar 26, 2026

    @admarble
    ContributorAuthor

    QA Review for Issue #465

    Size Gate

    This QA itself runs as standard (diff > 100 lines: 528 additions across 5 files). Meta-verified: the size gate would correctly route this PR to sub-agents.

    Stale Branch Check

    Check Value
    Commits behind main 0
    Status ✅ OK

    CI Status

    Check State Impact
    build (20.x) SUCCESS ✅
    build (22.x) SUCCESS ✅
    validate-skills SUCCESS ✅
    typecheck SUCCESS ✅
    validate-plugin SUCCESS ✅

    CI Summary: 5 passed, 0 pending, 0 failed

    AC Coverage

    AC Source Description Status Notes
    AC-1 Original Size gate for inline quality checks MET SKILL.md:836-905 — evaluates diff size, package.json, security paths before spawning sub-agents. Inline checks for type safety, deleted tests, scope, security when SMALL_DIFF=true
    AC-2 Original Simple fix output mode MET Output Verification section lists 9 omitted sections; Simple Fix Template is complete with all required sections (Size Gate, AC Coverage, Quality Metrics, Code Review, Test Coverage, Anti-Patterns, Self-Eval, Verdict, Docs, Next Steps)
    AC-3 Original Configurable threshold via settings.json MET QASettings.smallDiffThreshold in settings.ts with default 100; getSettings() merges parsed.qa over defaults; 6/6 unit tests pass covering default, custom threshold, merge behavior
    AC-4 Original Security-sensitive path detection reuses existing heuristic MET Regex auth|payment|security|server-action|middleware|admin confirmed in size gate bash block (matches anti-pattern detection heuristic)
    AC-5 Derived (Error Handling) Fallback to full pipeline on error MET Decision table explicitly states: "Size gate evaluation errors → SMALL_DIFF=false — fall back to full pipeline"
    AC-6 Derived (Best Practices) Log size gate decision MET Size Gate markdown table template included in output with diff size, threshold, package.json status, security paths, and decision

    Coverage: 6/6 AC items fully met


    Quality Metrics

    Metric Value Status
    Type issues (any) 0 OK
    Deleted tests 0 OK
    Files changed 5 OK
    Lines added +528 OK (mostly prompt template)
    Lines deleted -4 OK
    Security patterns 0 OK

    Build Verification

    N/A — Build passed (tsc clean)

    Test Coverage Analysis

    Changed File Tier Has Tests? Test File
    src/lib/settings.ts Standard ✅ Yes src/lib/qa-settings.test.ts (new, 6 tests)
    .claude/skills/qa/SKILL.md Standard N/A Skill prompt (not TypeScript)
    templates/skills/qa/SKILL.md Standard N/A Template sync of skill prompt
    CHANGELOG.md Optional N/A Documentation

    Coverage: 1/1 changed source files have tests


    Code Review

    Strengths:

    • Clean separation: TypeScript layer handles settings schema/defaults, skill prompt handles runtime behavior
    • Follows existing patterns: QASettings mirrors AgentSettings/ScopeAssessmentSettings pattern
    • All grep -c commands in skill have || echo "0" safety (per known pitfall)
    • Threshold extraction via grep -o with fallback || echo "100" is robust
    • .claude/skills/qa/SKILL.md and templates/skills/qa/SKILL.md are byte-identical (verified via diff)
    • CHANGELOG entry follows existing format with issue reference

    Issues:

    • None found

    Suggestions:

    • None — implementation is minimal and well-scoped

    Anti-Pattern Detection

    Category Count Details
    N+1 queries 0 N/A
    Empty catch 0 N/A
    Hardcoded secrets 0 N/A
    Security patterns 0 N/A

    No dependency changes (package.json unchanged).


    Skill Change Review

    • Command verified: Tested grep -o '"smallDiffThreshold"...' extraction — produces correct output for {"qa":{"smallDiffThreshold":50}}
    • Fields verified: All bash commands use standard git/grep — no JSON field dependencies on external tools
    • Patterns complete: Size gate covers: below threshold, above threshold, evaluation error fallback, package.json change, security paths
    • Dependencies explicit: Requires only git, grep, wc — all standard POSIX tools

    Skill Command Verification

    Skill files changed: 2

    File Commands Found Verification Status
    .claude/skills/qa/SKILL.md 8 (in size gate section) ✅ Passed
    templates/skills/qa/SKILL.md 8 (identical) ✅ Passed

    All commands use standard POSIX tools (cat, grep, git diff). No gh JSON field dependencies in the new sections.

    Verification Status: Passed


    CHANGELOG Verification

    Check Status
    CHANGELOG.md exists ✅
    User-facing changes ✅ (feat: skill optimization)
    [Unreleased] entry ✅ Present
    Entry format ✅ Action verb, includes (#465), correct section (Added)

    Self-Evaluation

    • Verified working: Yes — built successfully, 6/6 new tests pass, all CI green, bash commands in skill tested manually
    • Test efficacy: Medium — unit tests cover settings schema/merge; the skill prompt behavior itself is tested implicitly through use (prompt engineering, not executable code)
    • Likely failure mode: An LLM agent might not correctly parse the size gate threshold from settings.json if the JSON structure is unusual (e.g., nested or with comments). The grep -o approach is brittle compared to jq, but has the advantage of zero external dependencies.
    • Verdict confidence: High — changes are well-scoped (settings interface + prompt template), follow existing patterns, and all automated checks pass

    Verdict: READY_FOR_MERGE

    All 6 ACs (4 original + 2 derived) are met. Code quality is high:

    • TypeScript changes are minimal and follow existing settings patterns
    • Skill prompt changes are clearly structured with decision tables and fallback behavior
    • All grep commands are exit-code safe
    • Templates are in sync
    • CI is fully green (5/5 checks)
    • CHANGELOG entry present

    Documentation

    • CHANGELOG entry added
    • N/A — No new user-facing CLI commands or config documentation needed (settings.json field is self-documenting via existing patterns)

    Documentation: Before merging, run /docs 465 to generate feature documentation.

    Next Steps

    1. Merge PR feat(#465): add small-diff fast path to QA skill #469
    2. The fast path will be exercised automatically on the next /qa run against a small diff
  7. added
    ready-for-review
    on Mar 26, 2026
  8. added 2 commits that reference this issue on Mar 26, 2026
  9. added 2 commits that reference this issue on Sep 9, 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

    clienhancementplannedready-for-review

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions