Skip to content

feat(merge): --watch — wait for CI checks to finish, then run merge-check and report (kills the merge-after-green polling loop) #818

Closed

Description

@admarble

Context

Session-log analysis (Jun 20–Jul 26) shows the post-PR step is pure polling toil: "merge after green", "merge if green", "push then merge the pr when green" appear repeatedly, plus a whole session dedicated to "Check CI on PR #764 and report final verdict." The human's job here is watching a spinner — the judgment (merge or not) only starts once checks are terminal and merge-check has run.

sequant merge already does the judgment half: --check/--scan/--review phases with READY=0 / NEEDS_ATTENTION=1 / BLOCKED=2 exit codes. What's missing is the wait: today you either poll by hand or run merge-check too early against incomplete checks.

Proposal

A --watch mode on sequant merge <issue> that polls the PR's check rollup until all checks reach a terminal state, then runs the normal merge-check phases and reports exactly as today. Terminal-output only — the deliverable is "when this command exits, the verdict is real."

Design constraints:

  • It never merges. Same contract as today; --watch only moves when the existing report runs.
  • No daemon, no OS notifications. Foreground poll with a configurable interval and timeout; cross-platform by construction (plain terminal output + exit codes). Users who want notification can chain on the exit code.
  • Reuse GitHubProvider, not raw gh calls in a loop (the Consolidate remaining gh CLI calls into GitHubProvider #443 consolidation). Use statusCheckRollup (the --json checks field is known-broken).
  • Handle the zero-checks trap explicitly. 0 checks after a push often means mergeable: CONFLICTING blocked CI dispatch entirely — --watch must detect that and exit BLOCKED with the reason, not wait forever on checks that will never start.

Acceptance Criteria

  • sequant merge <issue> --watch polls the PR check rollup until every check is terminal, then runs the standard merge-check phases and prints the normal report.
  • Exit codes are preserved (READY=0, NEEDS_ATTENTION=1, BLOCKED=2) and a watch timeout exits non-zero with a distinct message; the command never merges.
  • A PR whose mergeable state is CONFLICTING (or that has zero checks after a dispatch-blocking condition) is detected and reported as BLOCKED with the cause instead of polling until timeout.
  • Polling uses GitHubProvider with statusCheckRollup; interval and timeout are configurable with sensible defaults, and the implementation is a foreground loop (no background process, no OS-specific notifiers).
  • --watch composes with the existing --check/--scan/--review depth flags and --post.
  • Documentation covers the flag in the main README, marketplace README, and docs/.

Out of scope

Auto-merge on READY (human merge gate stays); watching multiple PRs concurrently; desktop/push notifications; re-running or triggering CI.

References

Activity

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

    @admarble
    ContributorAuthor

    Scope note for AC-3, from a live incident (admarble/ad-motion, 2026-07-26): there is a third dispatch-blocked case beyond CONFLICTING/zero-checks — checks exist but runners are never allocated (Actions billing/spending-limit lockout).

    Signature: every check concludes failure ~2s after starting with 0 steps, and the only statement of the cause is a check-runs annotation invisible to gh pr checks/gh run view:

    // gh api repos/{owner}/{repo}/commits/{head_sha}/check-runs → .check_runs[].output.annotations_url → .[0]
    {"annotation_level":"failure","path":".github",
     "message":"The job was not started because recent account payments have failed or your spending limit needs to be increased. Please check the 'Billing & plans' section in your settings"}

    Without handling this, --watch would see all checks terminal-failed, run merge-check, and report a red verdict whose cause the user cannot see anywhere. AC-3's contract ("detected and reported as BLOCKED with the cause instead of polling until timeout") should cover it: when all checks fail near-instantly, query the head SHA's check-runs annotations; on a job was not started match, exit BLOCKED with the annotation text verbatim. All-fail-fast is the trigger condition, so healthy and partially-failing repos never pay the extra API call.

    Skill-side sibling (same signature, /qa Phase 1 mapping + /loop exclusion): #820. Fixture JSON captured there — the live evidence disappears once the account's billing is fixed.

  3. admarble commented on Jul 27, 2026

    @admarble
    ContributorAuthor

    #818 — feat(merge): --watch — wait for CI checks to finish, then run merge-check and report
    Open · enhancement, cli
    ────────────────────────────────────────────────────────────────

    → PROCEED — GitHubProvider confirmed (src/lib/workflow/platforms/github.ts:72); requirements clear, no existing branch/PR

    Commands:
    sequant run 818 -Q

    spec → exec → qa · 6 ACs
    ────────────────────────────────────────────────────────────────
    ⚠ AC-3 scope grew via 2026-07-26 comment: third dispatch-blocked case (billing-lockout annotation, all-checks-fail-fast signature) — spec should treat it as in-scope
    ────────────────────────────────────────────────────────────────

  4. admarble commented on Jul 27, 2026

    @admarble
    ContributorAuthor

    Complexity: Standard (6 ACs, ~5 directories)

    AC Quality Check

    Issue checkboxes have no AC-N: labels, so the parser stored 0 — IDs assigned inline below (AC-1..AC-6). AC text is otherwise measurable (terminal state, exit codes, named field). No vague/unmeasurable patterns.


    Scope Assessment

    Non-Goals: Present ✅ ("Out of scope": auto-merge on READY, multi-PR concurrent watch, desktop/push notifications, re-running/triggering CI).

    Metric Value Status
    Feature count 1 (--watch + dispatch-block detection) ✅
    AC items 6 ⚠️
    Directory spread src/commands, src/lib/merge-check, src/lib/workflow/platforms, docs/, scripts/, bin/ ⚠️

    Verdict: ⚠️ SCOPE_WARNING — cohesive single feature, but new poll-loop module + a new GitHubProvider surface + 3 doc sites. Quality loop auto-enabled.


    Key architectural finding (read before AC verification)

    The current sequant merge does not poll CI at all. It runs local batch checks (combined-branch-test, mirroring, overlap-detection, residual-pattern-scan) on feature branches resolved from run logs (src/lib/merge-check/index.ts). It is multi-issue/batch by design, yet AC-1 says singular sequant merge <issue>. --watch is a new pre-step gate layered before the existing checks: resolve issue→PR, poll that PR's statusCheckRollup to terminal (or detect a dispatch-block → BLOCKED), then run the existing report unchanged. See Open Questions for multi-issue semantics.


    Acceptance Criteria

    AC-1: --watch polls the PR check rollup to terminal, then runs standard merge-check and prints the normal report

    Verification: Integration Test
    Scenario: Given a PR whose rollup returns PENDING then COMPLETED on a later poll → When sequant merge <issue> --watch runs → Then it loops until every entry is terminal, then invokes runMergeChecks and prints the existing report.
    Assumptions: "Terminal" = CheckRun status===COMPLETED, StatusContext state ∈ {SUCCESS,FAILURE,ERROR} (not PENDING/EXPECTED/QUEUED/IN_PROGRESS).

    AC-2: Exit codes preserved; watch timeout exits non-zero with a distinct message; never merges

    Verification: Unit Test
    Scenario: Given the timeout elapses before checks are terminal → Then the process exits with a distinct non-zero code (propose 3, reserving 0/1/2 for READY/NEEDS_ATTENTION/BLOCKED) and a "watch timed out after Ns" message; no gh pr merge is ever invoked.
    Assumptions: getExitCode (merge.ts:27) stays authoritative for the verdict path; timeout is a separate exit before checks run.

    AC-3: CONFLICTING / zero-checks / billing-lockout dispatch-blocks → BLOCKED with cause, not timeout

    Verification: Unit + Integration
    Scenario: Three dispatch-block signatures each short-circuit the poll and exit BLOCKED with the cause: (a) mergeable===CONFLICTING; (b) zero checks after a dispatch-blocking condition; (c) all checks fail-fast → query head-SHA check-run annotations, on job was not started exit BLOCKED with the annotation verbatim.
    Assumptions: Reuse src/lib/qa/infra-blocked-ci.ts (allChecksFailing, detectInfraBlockedCi, NOT_STARTED_SIGNATURE) — do NOT reimplement. All-fail-fast is the trigger gate so healthy/partial boards never pay the extra annotation API call.

    AC-4: Polling via GitHubProvider + statusCheckRollup; configurable interval/timeout; foreground loop only

    Verification: Unit Test
    Scenario: Given --watch → Then rollup is fetched through a new GitHubProvider method using statusCheckRollup (never --json checks); --interval/--timeout default sensibly (propose 30s / 30min); the loop is a plain in-process await sleep — no child process, no OS notifier.
    Assumptions: New .option() entries in the merge block of bin/cli.ts + fields on MergeCommandOptions.

    AC-5: --watch composes with --check/--scan/--review depth flags and --post

    Verification: Integration Test
    Scenario: Given --watch --scan --post → Then watch gates first, then the Phase 1+2 checks run and --post publishes — identical output to a non-watch invocation once checks are terminal.

    AC-6: Documentation in main README, marketplace README, and docs/

    Verification: Manual Test (grep-verified content, not file existence)
    Scenario: --watch/--interval/--timeout documented in: README.md (command table ~L242), scripts/prepare-marketplace.ts README_CONTENT template (the marketplace README is generated here, not a standalone file), and docs/reference/merge-command.md (options table + a usage section).


    Implementation Plan

    Phase 1: GitHubProvider surface (src/lib/workflow/platforms/github.ts)

    1. getStatusCheckRollupSync(prNumber) → gh pr view N --json statusCheckRollup; return typed entries + a mapRollupToTerminal/isTerminal helper.
    2. getMergeableStateSync(prNumber) → --json mergeable (MERGEABLE/CONFLICTING/UNKNOWN).
    3. getCheckRunAnnotationsSync(headSha) → gh api repos/{owner}/{repo}/commits/{sha}/check-runs → per-run annotations_url; return AnnotatedCheck[] shaped for detectInfraBlockedCi. Head SHA via gh pr view N --json headRefOid.

    Phase 2: Watch loop module (new src/lib/merge-check/watch.ts)

    1. waitForChecks(prNumber, {intervalMs, timeoutMs}, gh): resolve rollup each tick; classify → { status: 'terminal' | 'blocked' | 'timeout', reason? }. Dispatch-block order per tick: mergeable CONFLICTING → zero-checks-after-dispatch-block → all-fail-fast annotation scan (reuse infra-blocked-ci.ts).
    2. PR resolution: prefer run-log prNumber; else viewPRByBranchSync on the resolved feature branch (both already exist).

    Phase 3: Wire command + flags

    1. bin/cli.ts merge block: add --watch, --interval <seconds>, --timeout <seconds> (parseInt). Add fields to MergeCommandOptions (types.ts).
    2. mergeCommand (merge.ts): when --watch, run waitForChecks before runMergeChecks; on blocked print BLOCKED report + exit 2; on timeout print distinct message + exit 3; on terminal fall through to existing path unchanged.

    Phase 4: Docs (AC-6) — all three sites in one pass.


    Rule Touchpoints

    AC-4 ("foreground loop, no background process") and the "it never merges" contract are behavior rules with a single touchpoint — runtime TS only (no SKILL.md duplication, since merge is a CLI command, not a skill-driven phase). No skill/runtime split risk here; noted so QA doesn't hunt for a phantom second site.


    Design Review

    1. Where does this logic belong? Poll/classify loop in a new src/lib/merge-check/watch.ts; all gh access in GitHubProvider (honors the Consolidate remaining gh CLI calls into GitHubProvider #443 consolidation the issue mandates). merge.ts only orchestrates.
    2. Simplest correct approach? A while loop with await sleep(interval), a monotonic deadline, and a per-tick classifier. Rejected: any daemon/notifier (explicit non-goal); rejected reimplementing the billing detector (reuse infra-blocked-ci.ts).
    3. Existing pattern? Sync spawnSync gh wrappers on GitHubProvider (matches every sibling method); infra-blocked-ci.ts pure predicates for the annotation scan.
    4. What would a senior reviewer challenge? (a) "Why exit 3 not 2 for timeout?" — AC-2 demands a distinct non-zero message; 2 is BLOCKED-the-verdict, timeout is not a verdict. (b) "Multi-issue --watch?" — see Open Questions. (c) "statusCheckRollup terminal detection for mixed CheckRun/StatusContext entries" — must handle both shapes.

    Feature Quality Planning

    All standard checks pass. Notable items:

    • Zero-checks vs billing-lockout ambiguity: zero-checks-after-dispatch-block (AC-3b) and all-fail-fast (AC-3c) are distinct signatures — don't collapse them; billing lockout produces failing checks, not zero.
    • gh api failure resilience: annotation fetch must degrade to "not blocked" on 404/rate-limit (the reused detector already guards non-array payloads — preserve that).
    • Timeout must not swallow a late terminal: check terminal-state one final time on deadline before declaring timeout.

    Derived ACs

    Source Derived AC Priority
    Robustness AC-D1: annotation/rollup fetch errors degrade to non-blocking, never crash the loop Medium

    Open Questions

    1. Multi-issue --watch semantics. merge accepts [issues...]; AC-1 says <issue>. Recommendation: watch all resolved PRs — proceed only when every PR's rollup is terminal; any PR dispatch-blocked → BLOCKED naming that PR. Impact if wrong: a batch merge --watch either errors or silently watches only the first PR.
    2. Timeout exit code = 3. Recommendation: reserve 0/1/2 for verdicts, 3 for watch-timeout. Impact: consumers chaining on exit codes must learn code 3; documented in AC-6.
    3. Default interval/timeout = 30s / 30min. Impact if wrong: too-tight timeout aborts legitimately-slow CI. Make both --interval/--timeout overridable (AC-4).

    Recommended Workflow

    Phases: spec → testgen → exec → qa
    Quality Loop: enabled (SCOPE_WARNING)
    Reasoning: New logic module + GitHubProvider surface with Unit + Integration verification ACs → testgen stubs the poll/classify + dispatch-block tests before exec. No UI → no test phase. Matches the /assess recommendation (spec,exec,qa) plus testgen given the unit-test-heavy AC set.


    Label Review

    Current: enhancement, cli
    Recommended: enhancement, cli (+ planned on post)
    Reason: Accurate — CLI feature enhancement, no breaking/refactor. No ui label (no .tsx/.jsx).
    Quality Loop: Will auto-enable via SCOPE_WARNING.

  5. added
    planned
    on Jul 27, 2026
  6. admarble commented on Jul 28, 2026

    @admarble
    ContributorAuthor

    /exec Progress Update — PR #831

    Implementation complete. sequant merge <issue> --watch waits for CI to reach a terminal state, then runs the standard merge-check report. Never merges.

    AC Coverage

    AC Status Evidence
    AC-1 poll rollup → terminal → run merge-check ✅ watch.ts:waitForChecks → merge.ts:runWatchGate falls through to runMergeChecks
    AC-2 exit codes preserved; timeout distinct + never merges ✅ timeout → exit 3, blocked → 2; no gh pr merge in the path
    AC-3 CONFLICTING / zero-checks / billing-lockout → BLOCKED w/ cause ✅ classifyTick reuses qa/infra-blocked-ci.ts for the all-fail-fast annotation scan
    AC-4 GitHubProvider + statusCheckRollup; configurable; foreground ✅ new provider methods; --interval/--timeout in bin/cli.ts; await sleep loop
    AC-5 composes with depth flags + --post ✅ gate runs before runMergeChecks, same options object
    AC-6 docs in main README, marketplace README, docs/ ✅ README.md, scripts/prepare-marketplace.ts template, docs/reference/merge-command.md
    AC-D1 fetch errors degrade non-blocking, never crash ✅ gh wrappers return []/UNKNOWN/null on error

    Key files

    • src/lib/merge-check/watch.ts — poll/classify loop (pure core, DI-injected sleep/now/gh)
    • src/lib/merge-check/watch.test.ts — 20 unit tests (classify, poll, dispatch-blocks, timeout, degrade)
    • src/lib/workflow/platforms/github.ts — getStatusCheckRollupSync, getMergeableStateSync, getPRHeadShaSync, getCheckRunAnnotationsSync
    • src/commands/merge.ts — runWatchGate orchestration; bin/cli.ts + types.ts — flags/fields

    Checks

    • npm run build ✅ · npm run lint ✅ (0 warnings) · npm test (merge-check + merge) ✅ 96 passed

    Quality Plan Alignment

    Dimension Notes
    Robustness (AC-D1) Fetch errors degrade to non-blocking; verified by test
    Zero-checks vs billing-lockout Kept distinct — zero-checks stays pending→timeout; all-fail-fast triggers annotation scan
    Timeout not swallowing late terminal Fresh poll classified before deadline check; pinned by test

    Known gaps / notes

    • Multi-issue --watch watches PRs sequentially under one shared wall-clock deadline (per spec Open Question feat: Complete remaining v1.0 features (AC-10, AC-13, AC-14) #1).
    • The gh-wrapper methods on GitHubProvider are thin spawnSync shells (integration-only, matching every sibling method); the testable logic lives in watch.ts and is unit-covered.
  7. admarble commented on Jul 28, 2026

    @admarble
    ContributorAuthor

    QA Review for Issue #818

    Reviewed PR #831 @ 2d9204a. Core logic reviewed inline; 20 unit tests + build + lint verified locally.

    AC Coverage

    AC Source Description Status Notes
    AC-1 Original Poll rollup → terminal → run merge-check + print report MET waitForChecks loops until every entry terminal; runWatchGate returns false → falls through to runMergeChecks unchanged (merge.ts:230,284). Unit-tested (settles after N polls).
    AC-2 Original Exit codes preserved; timeout distinct + never merges MET getExitCode untouched (READY=0/NA=1/BLOCKED=2); timeout → exit 3 distinct message; blocked → 2. No gh pr merge anywhere in the diff (grep-verified).
    AC-3 Original CONFLICTING / zero-checks / billing-lockout → BLOCKED w/ cause MET classifyTick: CONFLICTING short-circuits regardless of check count (covers zero-checks-because-conflicting); all-fail-fast → head-SHA annotation scan reusing qa/infra-blocked-ci.ts. All three unit-tested.
    AC-4 Original GitHubProvider + statusCheckRollup; configurable; foreground MET getStatusCheckRollupSync uses --json statusCheckRollup (not the broken checks); --interval/--timeout registered in bin/cli.ts + --help verified; plain await sleep loop, no daemon/child/notifier.
    AC-5 Original Composes with --check/--scan/--review + --post MET Gate runs before runMergeChecks with the same options object; depth flags and --post flow through unchanged.
    AC-6 Original Docs in main README, marketplace README, docs/ MET Content-verified: README command table; prepare-marketplace.ts dedicated section; docs/reference/merge-command.md options table + exit codes + dispatch-block explanation.
    AC-D1 Derived (Robustness) Annotation/rollup fetch errors degrade non-blocking, never crash MET gh wrappers return []/UNKNOWN/null on any error; null-SHA path unit-tested to degrade to terminal, not crash.

    Coverage: 7/7 AC items met (6 original + 1 derived)

    CI Status

    Check State Bucket Impact
    validate-skills SUCCESS pass ✅
    validate-plugin SUCCESS pass ✅
    node-floor-guard SUCCESS pass ✅
    typecheck SUCCESS pass ✅
    build (22.x) IN_PROGRESS pending ⏳ gating

    CI Summary: 4 passed, 1 pending (build still running — not failing). This is the sole reason the verdict is NEEDS_VERIFICATION rather than READY_FOR_MERGE.

    Quality Metrics

    Metric Value Status
    Type issues (any) 0 OK
    Deleted tests 0 OK
    Files changed 11 (5 src, 4 docs/changelog, 1 test, 1 cli) OK
    Lines +1033 / −3 OK (mostly CHANGELOG + docs)

    Test Coverage Analysis

    Changed source Tier Has Tests?
    src/lib/merge-check/watch.ts Standard (core logic) ✅ watch.test.ts (20 tests)
    src/lib/workflow/platforms/github.ts (4 gh wrappers) Standard Integration-only spawnSync shells — matches every sibling method; degradation paths unit-covered via watch.test.ts fakes
    src/commands/merge.ts (runWatchGate) Standard Orchestration shell (git/gh + console); logic delegated to tested watch.ts
    src/lib/merge-check/index.ts Optional One-line export of resolveLogDir (no behavior change)
    src/lib/merge-check/types.ts Optional Types only

    Critical-tier (auth/payment/security) files: none.

    Code Review

    Strengths:

    • Pure poll/classify core (classifyTick, waitForChecks) with injected sleep/now/gh → deterministic, fast, well-tested.
    • Reuses infra-blocked-ci.ts for the billing-lockout detector instead of reimplementing it — no sibling divergence.
    • Lazy annotation fetch gated on all-fail-fast, so healthy/partial boards never pay the extra API call.
    • Timeout only declared after a fresh poll, so a check turning terminal on the final interval is never swallowed (unit-tested).
    • Shared wall-clock deadline across multiple PRs so --timeout bounds the whole gate.

    Suggestions (non-blocking):

    • resolveWatchTargets reuses resolveBranches, which also computes per-issue git-diff filesModified (unused by watch) and prints "No branch found" to stderr. Cosmetic/efficiency only — no correctness impact.

    Risk Assessment

    • Likely failure mode: A genuinely no-CI PR (mergeable, zero checks) polls to timeout rather than exiting fast — but this is by design (indistinguishable from slow dispatch without a detectable cause), and the timeout message names the zero-checks case. Matches the approved spec's AC-3 assumptions.
    • Not tested: The raw gh spawnSync wrappers and runWatchGate console/exit-code plumbing have no direct unit test (integration-only). Acceptable — all classification/timing logic lives in the unit-tested watch.ts.
    • Sibling sites considered: none — new feature; the billing-lockout detector is shared with /qa via infra-blocked-ci.ts rather than duplicated.
    • Sibling-line audit: none — not a bug-fix pattern.

    Adversarial Re-Read

    Findings: No blocking gaps. (1) Billing-lockout fixture from the issue's 2026-07-26 comment is mirrored by watch.test.ts BILLING_ANNOTATION and passes. (2) Exec's evidence (build/lint/20 tests green) is post-implementation validation, not a pre-fix repro. (3) Process state clean — committed, 0 behind main, PR open. (4) No cross-file sibling divergence (detector reused, gh wrappers follow sibling pattern). (5) Non-Goals honored: no auto-merge, multi-PR is watched sequentially not concurrently (concurrent watch is the out-of-scope item), no notifications, no CI triggering.

    Status: Clean

    Verdict: NEEDS_VERIFICATION

    All 7 ACs are MET with high code quality and strong unit coverage of the core logic. The only outstanding item is the build (22.x) CI check, still IN_PROGRESS (4/5 green, not failing). Per the gating-pending-CI rule, re-run /qa 818 once CI completes — expected to flip to READY_FOR_MERGE with no code changes.

    Documentation

    Next Steps

    1. Wait for build (22.x) to finish, then re-run /qa 818 (or merge if green — human merge gate).
    2. Optional: run /docs 818.
  8. added
    needs-verification
    on Jul 28, 2026
  9. admarble commented on Jul 28, 2026

    @admarble
    ContributorAuthor

    QA Review for Issue #818 (re-run — CI now terminal)

    Prior QA at this same SHA (2d9204a) returned NEEDS_VERIFICATION solely on a pending build (22.x). That check has since gone green, so this is the full-weight re-run rather than a short-circuit. It surfaced one finding the first pass did not.

    AC Coverage

    AC Source Description Status Notes
    AC-1 Original --watch polls rollup until terminal, then runs standard phases + normal report MET Live e2e run (merge 818 --watch --check against PR #831): Watching PR #831 … all checks terminal after 1 poll(s) → merge-check ran all 3 phases → normal READY report.
    AC-2 Original Exit codes preserved; timeout distinct; never merges MET getExitCode untouched (0/1/2); timeout → distinct exit 3 + distinct message. Diff grep for pr merge/--squash/--rebase: no merge invocation added.
    AC-3 Original CONFLICTING / zero-checks-after-dispatch-block → BLOCKED with cause MET classifyTick short-circuits on CONFLICTING regardless of check count, which is exactly the zero-checks-because-conflicting trap; plus billing-lockout via head-SHA annotations reusing qa/infra-blocked-ci.ts. All three unit-tested.
    AC-4 Original GitHubProvider + statusCheckRollup; configurable; foreground MET Verified against live gh: --json statusCheckRollup -q .statusCheckRollup returns the array, mergeable/headRefOid return raw strings — all three contracts confirmed, and the known-broken --json checks is not used. --interval/--timeout present in merge --help. Plain await sleep loop; no daemon/child/notifier.
    AC-5 Original Composes with --check/--scan/--review and --post MET Gate runs before runMergeChecks on the same options object; the live run above used --watch --check together successfully.
    AC-6 Original Docs in main README, marketplace README, docs/ MET Content-verified (not just file existence) in all three: README.md:242; prepare-marketplace.ts dedicated section; docs/reference/merge-command.md options table + exit-code table incl. 3 + dispatch-block explanation.
    AC-D1 Derived (Robustness) Fetch errors degrade non-blocking, never crash MET All four gh wrappers return []/UNKNOWN/null on any error; null-SHA path unit-tested.

    Coverage: 7/7 met (6 original + 1 derived).

    CI Status

    Check State Bucket
    validate-skills SUCCESS pass
    validate-plugin SUCCESS pass
    build (22.x) SUCCESS pass
    node-floor-guard SUCCESS pass
    typecheck SUCCESS pass

    CI Summary: 5 passed, 0 pending, 0 failed. The prior run's sole blocker is resolved.

    Quality Metrics

    Metric Value Status
    Type issues (any) 0 OK
    Deleted tests 0 OK
    Files changed 11 OK
    Lines +1033 / −3 OK
    Build (tsc) exit 0 OK
    Tests (watch.test.ts) 20/20 pass OK
    Worktree state clean, 0 behind main OK

    Execution Evidence

    Test Command Result
    Happy path (e2e) node dist/bin/cli.js merge 818 --watch --check ✅ polled → terminal → report READY
    CLI registration merge --help ✅ --watch, --interval, --timeout listed
    Build npm run build ✅ exit 0
    Unit vitest run watch.test.ts ✅ 20/20
    gh field contracts statusCheckRollup / mergeable / headRefOid ✅ all verified live

    Evidence status: Complete

    Code Review

    Strengths:

    • Pure classify/poll core with injected sleep/now/gh — deterministic and genuinely fast to test.
    • Reuses infra-blocked-ci.ts for the billing lockout instead of reimplementing it, so /qa and merge --watch cannot diverge.
    • Annotation fetch is lazily gated on a terminal-and-uniformly-failing board, so healthy boards never pay the extra API calls — and because that state is terminal, it happens at most once per PR, not per poll.
    • Timeout is only declared after a fresh poll, so a check turning terminal on the final interval is never swallowed.

    Issue — unvalidated --interval / --timeout produce an unbounded, un-slept poll loop:

    bin/cli.ts coerces both flags with a bare (v) => parseInt(v, 10), and merge.ts applies defaults with options.interval ?? DEFAULT. NaN is not nullish, so a malformed value flows straight through: deadline = start + NaN makes nowFn() >= deadline permanently false, and setTimeout(NaN) degrades to 0 delay. The result is an infinite tight loop spawning gh subprocesses with no delay and no exit.

    Reproduced against the real waitForChecks with a fake provider:

    NaN interval + NaN timeout (--timeout abc): RUNAWAY: 3001 polls, 3001 zero/NaN sleeps — loop never terminates
    valid interval + NaN timeout:               RUNAWAY: 3001 polls, 3001 zero/NaN sleeps — loop never terminates
    interval 0 + valid timeout:                 RUNAWAY (bounded by wall clock in production, but zero-delay API hammering for the full 30 min)
    baseline valid (30s/60s):                   status=timeout polls=3 zeroSleeps=0   ← correct
    

    Reachable by ordinary typos (--timeout abc, --timeout m30). Note --timeout 30m silently parses to 30 seconds — bounded, but wrong in a way the user won't notice.

    This also quietly defeats AC-2's guarantee: with a NaN timeout there is no timeout exit at all.

    Not a generic hardening nitpick — it diverges from this repo's own convention. The sibling numeric-input paths all validate:

    • src/lib/workflow/batch-executor.ts:360 — if (!isNaN(maxIter))
    • src/lib/workflow/batch-executor.ts:384 — if (!isNaN(autoWait) && autoWait >= 0)
    • src/commands/merge.ts:249 — .filter((n) => !isNaN(n)) (same file as the new code)

    Suggested fix (small, belongs in PR #831 rather than a follow-up): clamp in runWatchGate where the defaults are applied —

    const toSeconds = (v: number | undefined, fallback: number, min: number) =>
      typeof v === "number" && Number.isFinite(v) && v >= min ? v : fallback;
    
    const intervalMs = toSeconds(options.interval, DEFAULT_WATCH_INTERVAL_S, 1) * 1000;
    const timeoutMs  = toSeconds(options.timeout,  DEFAULT_WATCH_TIMEOUT_S,  1) * 1000;

    Suggestion (non-blocking, carried from the prior pass): resolveWatchTargets reuses resolveBranches, which also computes unused per-issue filesModified and prints "No branch found" to stderr. Cosmetic only.

    Test Coverage Analysis

    Changed source Tier Has Tests?
    src/lib/merge-check/watch.ts Standard (core logic) ✅ watch.test.ts (20 tests)
    src/lib/workflow/platforms/github.ts (4 gh wrappers) Standard Integration-only spawnSync shells — matches every sibling method; degradation covered via fakes
    src/commands/merge.ts (runWatchGate) Standard ⚠️ No unit test — and this is exactly where the unvalidated-flag defect lives
    types.ts / index.ts Optional Types + one-line export

    Critical-tier (auth/payment/security) files: none.

    Risk Assessment

    • Likely failure mode: A typo'd --interval/--timeout turns the gate into an unbounded zero-delay gh spawn loop — plausibly tripping GitHub rate limiting/abuse detection, with no timeout to stop it. Second: a genuinely no-CI PR polls to timeout rather than exiting fast, which is by design and named in the timeout message.
    • Not tested: runWatchGate's option handling, console output, and exit-code plumbing (the defect above sits in that untested seam); the raw spawnSync wrappers are integration-only.
    • Sibling sites considered: the billing-lockout detector is shared with /qa via infra-blocked-ci.ts rather than duplicated — no divergence. The numeric-flag-validation siblings in batch-executor.ts and merge.ts:249 do diverge from the new code (finding above).
    • Sibling-line audit: not a bug-fix pattern; new feature.

    Adversarial Re-Read

    Findings: (1) The unvalidated-flag runaway loop above — found by probing waitForChecks with malformed values rather than reading the diff, and confirmed as a convention divergence via the sibling scan. (2) Evidence audited: the e2e run, build, and 20 unit tests are post-implementation validations, not pre-fix repros — the one repro I produced (the runaway) is my own and is disclosed as such. (3) Process state inspected: worktree clean, 0 commits behind main, single commit, PR open and MERGEABLE. (4) Sibling sites cited explicitly above, not hand-waved. (5) Non-Goals honored: no auto-merge (grep-verified), multiple PRs are watched sequentially on a shared deadline — the out-of-scope item is concurrent watching — no notifications, no CI triggering.

    Status: Gaps Found

    CHANGELOG Verification

    Check Status
    CHANGELOG.md exists ✅
    User-facing change ✅ feat(#818):
    [Unreleased] entry ✅ present, includes (#818)

    Sections N/A

    Skill Command Verification, Detection Pattern Verification, Skill Change Review (no skills/**/*.md changed) · Build Verification (build passed) · Manual Test ACs (none in spec) · Browser testing (no .tsx) · Quality Plan (none in comments).

    Verdict: AC_MET_BUT_NOT_A_PLUS

    All 7 ACs are literally met and verified at runtime against live GitHub, CI is 5/5 green, and the core logic is well-factored and well-tested. Held back from READY_FOR_MERGE by one concrete defect: --interval/--timeout accept malformed values that produce an unbounded, zero-delay polling loop which never times out — diverging from the numeric-validation convention used elsewhere in this very file, and silently voiding AC-2's timeout guarantee. The fix is a few lines in runWatchGate.

    Next Steps

    1. Add the interval/timeout clamp in runWatchGate (PR feat(#818): merge --watch — wait for CI checks to finish, then run merge-check and report #831 — fill the gap in the open PR rather than farming a follow-up), ideally with a runWatchGate unit test covering malformed input.
    2. Re-run /qa 818 after the fix — expected to flip to READY_FOR_MERGE.
    3. This is AC_MET_BUT_NOT_A_PLUS, so it breaks to PR review — do not run /loop on it.
  10. added
    needs-improvement
    and removed
    needs-verification
    on Jul 28, 2026
  11. added a commit that references this issue on Jul 28, 2026
  12. admarble commented on Jul 28, 2026

    @admarble
    ContributorAuthor

    QA Re-Review for Issue #818 — gap fixed

    The AC_MET_BUT_NOT_A_PLUS finding from the previous review is fixed in a73c820 (PR #831). This is the adversarial pass over the fix itself, since gap-fixes introduce their own gaps.

    What was fixed

    --interval/--timeout were coerced with a bare parseInt and defaulted with ??. NaN is not nullish, so a malformed value reached the loop: deadline = start + NaN made now >= deadline permanently false and setTimeout(NaN) degraded to zero delay — an unbounded, no-sleep gh spawn loop that also silently voided AC-2's distinct-timeout-exit guarantee.

    Fixed at two layers, each with a distinct job:

    Layer Change Why this layer
    bin/cli.ts parsePositiveSeconds rejects non-integers via InvalidArgumentError, following the existing validatePhasesFlag pattern User-facing error at the boundary; also catches the silent --timeout 30m → 30 seconds misparse
    watch.ts resolveWatchTiming owns defaults + sanitisation; waitForChecks normalises its own interval/deadline The CLI is not the only caller — programmatic MergeCommandOptions callers get the same guarantee, and the loop becomes structurally incapable of running away

    timeoutMs: 0 is deliberately preserved — runWatchGate uses it to mean "shared multi-PR deadline exhausted, poll once then give up." A naive "reject falsy" guard would have broken that; the existing test at watch.test.ts covering it still passes.

    Verification — before vs after

    Re-ran the exact probe that produced the original finding against the real waitForChecks:

    Case Before After
    --timeout abc (NaN interval + NaN timeout) RUNAWAY: 3001 polls, 3001 zero-delay sleeps, never terminates status=timeout polls=1801 zeroSleeps=0
    valid interval, NaN timeout RUNAWAY status=timeout polls=61 zeroSleeps=0
    zero interval, valid timeout RUNAWAY status=timeout polls=61 zeroSleeps=0
    baseline valid (30s/60s) timeout polls=3 timeout polls=3 (unchanged)

    CLI layer, verified live:

    --timeout abc → error: option '--timeout <seconds>' argument 'abc' is invalid. --timeout expects a whole number of seconds (got 'abc').
    --timeout 30m → error: ... expects a whole number of seconds (got '30m').
    --timeout 0   → error: ... must be at least 1 second (got '0').
    --timeout -1  → error: ... expects a whole number of seconds (got '-1').
    

    Dogfooded on its own PR — merge --watch waited for the fix commit's CI, then reported:

    Watching PR #831 (issue #818)…
      #831: 4/5 checks terminal…   (×6, 20s interval)
      #831: all checks terminal after 7 poll(s).
    → Merge Readiness Report — Batch Verdict: ✅ READY
    

    Quality Metrics

    Metric Value
    Tests 32 pass (was 20; +12 regression/unit)
    Broader suite 609 pass / 35 files (merge-check, commands, qa)
    Build (tsc) exit 0
    CI on a73c820 5/5 SUCCESS
    Fix diff +190 / −13 across 6 files

    The regression tests are non-vacuous by construction: the fake clock only advances via the injected sleep, so an unguarded loop hangs rather than passing — hence the explicit poll ceiling and the ms >= 1000 floor assertion.

    Adversarial re-read of the fix

    • Floor vs existing tests: the 1s interval floor was checked against existing test values (intervalMs: 1000 — exactly at the floor, unaffected) before being chosen.
    • timeoutMs: 0: preserved deliberately; the shared-deadline semantic in runWatchGate depends on it and remains covered.
    • Sleep never oversleeps the deadline: Math.min(intervalMs, remaining) is unchanged, so the floor cannot push a poll past the deadline.
    • Overflow: Number.isSafeInteger rejects absurd values that would overflow the deadline arithmetic.
    • Blast radius: only the two merge flags changed; run's --timeout registrations are untouched (see sibling finding below).

    Sibling finding → filed as #833

    The cross-file sibling scan found the same root cause on run --timeout, which #818 does not touch: bin/cli.ts:286 / :527 use a bare parseInt, config-resolver.ts:242 applies the same ?? default, and phase-executor.ts:982 consumes it as setTimeout(..., phaseTimeout * 1000). A NaN there clamps to 0, so run --timeout abc should abort every phase instantly — a worse failure than the #818 symptom, and one that will look like an agent problem rather than a bad flag.

    Filed as #833 rather than folded in here: run is a different command and tightening its accepted input range needs its own check (notably whether --timeout 0 is meaningful there). #833's first AC is to reproduce it before fixing, since I read the call sites but did not execute that path.

    Gap deliberately not fixed

    resolveWatchTargets reuses resolveBranches, which also computes a per-issue git diff (filesModified) that watch never reads. I left it as-is: fixing it means adding an option parameter to a function shared with the merge-check report path, trading a real regression risk for one redundant subprocess per issue that runMergeChecks performs moments later anyway. The No branch found for issue #N stderr line it inherits is accurate and useful in watch mode too. Flagging rather than silently skipping — say the word if you'd rather have it changed.

    Verdict: READY_FOR_MERGE

    All 7 ACs met and verified at runtime, the blocking finding is fixed with before/after evidence and non-vacuous regression coverage, CI is 5/5 green on the fix commit, and the feature has now been exercised end-to-end on its own PR. The one remaining known gap is cosmetic and explicitly scoped out above; the sibling defect is tracked in #833.

    Next Steps

    1. Merge PR feat(#818): merge --watch — wait for CI checks to finish, then run merge-check and report #831 (human merge gate — --watch never merges, by design).
    2. Triage fix(cli): bare parseInt on run --timeout lets a malformed value abort every phase instantly (sibling of #818) #833.
  13. added
    ready-for-review
    and removed
    needs-improvement
    on Jul 28, 2026
  14. added 4 commits that reference this issue on Jul 28, 2026
  15. added 3 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