Skip to content

feat(#818): merge --watch — wait for CI checks to finish, then run merge-check and report - #831

Merged
admarble merged 2 commits into
mainfrom
feature/818-feat-merge-watch-wait-for-ci-checks-to-finish-then
Jul 28, 2026
Merged

admarble merged 2 commits into
mainfrom
feature/818-feat-merge-watch-wait-for-ci-checks-to-finish-then

Conversation

@admarble

Copy link
Copy Markdown
Contributor

Summary

Adds a --watch mode to sequant merge <issue> that kills the "merge after green" polling loop: it waits for each resolved PR's CI checks to finish before running merge-check, so the verdict is real the moment the command exits.

  • It never merges — --watch only decides when the existing report runs; the human merge gate stays.
  • Foreground poll loop (no daemon, no OS notifier) via GitHubProvider.getStatusCheckRollupSync using statusCheckRollup (not the broken --json checks).
  • Configurable --interval (30s) / --timeout (1800s); a watch timeout exits with a distinct code (3), reserving 0/1/2 for READY/NEEDS_ATTENTION/BLOCKED.
  • Dispatch blocks short-circuit to BLOCKED with the cause instead of timing out: CONFLICTING mergeable state, zero checks after a dispatch block, and a runner-never-started billing lockout (reuses src/lib/qa/infra-blocked-ci.ts, fix(qa): classify runner-never-started CI (billing lockout) as infra-blocked, not NOT_MET — keep it out of /loop #820).
  • Composes with --check/--scan/--review and --post; shares one wall-clock deadline across multiple PRs.
  • Docs in main README, marketplace README template, and docs/reference/merge-command.md.

Pre-PR AC Verification

AC Description Status Evidence
AC-1 --watch polls rollup to terminal, then runs merge-check + prints report ✅ watch.ts:waitForChecks, merge.ts:runWatchGate → falls through to runMergeChecks
AC-2 Exit codes preserved; timeout exits non-zero with distinct message; never merges ✅ timeout → exit 3 (merge.ts), blocked → 2; no gh pr merge anywhere
AC-3 CONFLICTING / zero-checks / billing-lockout → BLOCKED with cause, not timeout ✅ classifyTick (CONFLICTING, all-fail-fast annotation scan); tests in watch.test.ts
AC-4 Polling via GitHubProvider + statusCheckRollup; configurable interval/timeout; foreground loop ✅ github.ts:getStatusCheckRollupSync; bin/cli.ts flags; await sleep loop
AC-5 Composes with --check/--scan/--review and --post ✅ gate runs before runMergeChecks, which receives the same options
AC-6 Docs in main README, marketplace README, and docs/ ✅ README.md, scripts/prepare-marketplace.ts, docs/reference/merge-command.md
AC-D1 Annotation/rollup fetch errors degrade to non-blocking, never crash the loop ✅ github.ts wrappers return []/UNKNOWN/null on error; test in watch.test.ts

Test plan

  • npm run build — passes
  • npm run lint — passes (0 warnings)
  • npm run test (merge-check + merge command) — 96 passed; watch.test.ts adds 20 tests covering classify/poll/dispatch-block/timeout
  • Manual: sequant merge <open-pr-issue> --watch against a live PR with in-flight CI

Closes #818

🤖 Generated with Claude Code

…rge-check and report

Adds a `--watch` mode to `sequant merge <issue>` that polls each resolved PR's
`statusCheckRollup` until every check is terminal, then runs the normal
merge-check phases and prints the usual report. It never merges — it only moves
*when* the existing report runs.

- Foreground poll loop (no daemon/notifier) with configurable `--interval`
  (30s) and `--timeout` (1800s); timeout exits with a distinct code (3),
  reserving 0/1/2 for READY/NEEDS_ATTENTION/BLOCKED.
- Three dispatch-block signatures short-circuit to BLOCKED with the cause
  instead of polling until timeout: CONFLICTING mergeable state, zero checks
  after a dispatch block, and a runner-never-started billing lockout (reusing
  src/lib/qa/infra-blocked-ci.ts).
- All gh access via GitHubProvider using statusCheckRollup (not the broken
  --json checks field); fetch errors degrade to non-blocking.
- Composes with --check/--scan/--review and --post; shares one deadline across
  multiple PRs.
- Docs in main README, marketplace README template, and merge-command.md.

Entire-Checkpoint: eb469040af98
…hang the watch loop

QA on #818 found that both watch flags were coerced with a bare
`parseInt`, then defaulted with `??`. `NaN` is not nullish, so a
malformed value flowed straight through: `deadline = start + NaN` makes
`now >= deadline` permanently false and `setTimeout(NaN)` degrades to a
zero delay, so `merge --watch --timeout abc` became an unbounded, no-sleep
`gh` spawn loop that never exits — and silently voided AC-2's guarantee
that a watch timeout exits with a distinct code. `--timeout 30m` also
parsed to 30 *seconds*.

This diverged from the numeric-input guards already used elsewhere,
including in the same file: batch-executor.ts (`maxIter`, `autoWait`) and
merge.ts:249 (issue-number parsing).

Fixed at two layers:

- bin/cli.ts: `parsePositiveSeconds` rejects anything that is not a whole
  positive integer via `InvalidArgumentError`, following the existing
  `validatePhasesFlag` pattern. Catches `abc` and the silent `30m` misparse
  instead of accepting a value that is unusable or quietly wrong.
- watch.ts: `resolveWatchTiming` owns the defaults and sanitises them for
  programmatic callers of `MergeCommandOptions`, and `waitForChecks`
  normalises its own interval/deadline so the loop is structurally
  incapable of running away regardless of caller. `timeoutMs: 0` is
  preserved — `runWatchGate` uses it to mean "shared deadline exhausted".

Tests: +12 (32 total). Regression cases assert the loop always terminates
and never sleeps below the 1s floor for NaN/zero/negative inputs, and
`resolveWatchTiming` is covered directly. Verified against the original
reproduction: all four runaway cases now exit `timeout` with 0 zero-delay
sleeps, and the CLI rejects `abc`/`30m`/`0`/`-1` with clear messages.

Docs and CHANGELOG updated for the accepted range.
@admarble
admarble merged commit 7e17cca into main Jul 28, 2026
5 checks passed
admarble added a commit that referenced this pull request Jul 29, 2026
…m to NaN (#836)

* fix(#833): reject malformed numeric CLI flags instead of coercing them to NaN

`--timeout` on `run` and `ready` was coerced with a bare `parseInt`.
`parseInt("abc", 10)` is `NaN`, which is not nullish, so it survived
`phaseTimeout: mergedOptions.timeout ?? DEFAULT_CONFIG.phaseTimeout` and
reached `setTimeout(abort, phaseTimeout * 1000)` — a `NaN` delay clamps to
0, so every phase aborted on its first tick and the run read as a phase
fault rather than a bad flag. `--timeout 30m` was the quiet half: the user
asked for 30 minutes and got 30 seconds.

Sibling of #818/#831, deferred out of that PR because narrowing `run`/`ready`
input is user-visible and deserved its own check on whether `--timeout 0`
meant anything. It does not: on `run` it reached `setTimeout` as a 0ms delay
(the same instant-abort), and on `ready` an existing `> 0` guard already
discarded it. So it is now rejected, per #831.

The AC-6 audit found three more flags whose malformed value was load-bearing:
  --max-iterations  `while (iteration < NaN)` is false on entry → zero phases
  --grace           `Math.max(0, NaN * 1000)` is NaN → grace period skipped
  --concurrency / --auto-wait / ready --budget / ready --max-iterations
                    guarded against NaN downstream, but each silently
                    misparsed `3x` → 3 and `10k` → 10

`buildExecutionConfig` also no longer resolves `phaseTimeout`/`maxIterations`
through a bare `??` — non-finite and non-positive values fall back *to* the
default rather than through it, closing the gap for programmatic callers and
settings.json, not just today's CLI.

The validator moves to src/lib/cli-flags.ts so it can be unit-tested directly
(bin/cli.ts calls program.parse() at import time). Subprocess tests pin that
it is actually wired to each command — the #305 inert-flag failure mode.

Both guards mutation-verified: reverting the resolver guard fails 20/25 of its
tests; reverting `run --timeout` alone fails exactly its 4 assertions and
leaves `ready` green.

* test(#833): make the numeric-flag positive controls non-vacuous

The `ready` / `abort` positive controls asserted only the *absence* of a
coercion error. That stays green if the command starts failing before the
flag is ever parsed — the test would report success having proven nothing.
Each case now also pins the specific downstream message it should reach
("No worktree found", "No relay PID found", "Unknown phase 'bogus'"), which
is only reachable if argument coercion accepted the value.

Replaces the separate exit-during-parsing guard, which covered only the
`run` cases and is now subsumed per-case.

* fix(#833): close the ready path and the settings.json entry point

QA's own follow-up review found the first fix covered only one of the two
producers of `phaseTimeout`.

`sequant ready` never passes through `buildExecutionConfig` — `ready-gate.ts`'s
`buildPhaseConfig` assembles its own ExecutionConfig — so the resolver guard
did not protect it. Its `typeof x === "number" && x > 0` checks stopped a bad
CLI value but fell through unchecked to `settings.run.*`, which was itself
`z.number()` with no constraint. A `"timeout": 0` in settings.json therefore
reached `setTimeout` as a 0ms delay and aborted every ready-gate phase on its
first tick, with no warning: the #833 defect, on the uncovered path.

- Export `positiveOr` and chain it CLI -> settings -> default in BOTH
  producers, so neither layer is unchecked and the two cannot drift again.
  `ready.ts`'s resolution moves into `resolveReadyLimits` so it is testable.
- Constrain `run.timeout` / `concurrency` / `maxIterations` with `.positive()`
  so a bad key is NAMED at load instead of silently swapped for a default.
  Left unconstrained where 0 is meaningful (staleBranchThreshold,
  resolvedIssueTTL, autoWaitMinutes).
- Fix `validateSettings` salvage. It re-parsed `{}` on any Zod failure, so one
  bad value discarded the user's ENTIRE settings.json and reverted every
  unrelated key to its default — while its comment claimed it stripped invalid
  fields. It now drops only the rejected paths (whole arrays on a bad index,
  since deleting by index leaves a hole that re-fails) and re-parses.
  Without this, adding constraints above would have widened that blast radius.

`__tests__/settings-schema.test.ts` asserted `run.timeout: 0` parses. That
pinned the permissiveness AC-2 proved is a defect, so the case moves to
`staleBranchThreshold`, where 0 is genuinely meaningful, plus a new case
asserting the three guarded fields reject it.

Also restructured the new tests to call production functions directly instead
of through describe-scope aliases. The tautology detector counted 10 blocks as
vacuous (52.6%, over its blocking threshold) because the calls were hidden
behind local helpers. Fixed by making the coupling visible, not by
@tautology-skip.

* docs(#833): record the settings.json constraints in the generated reference

The `run.timeout` / `concurrency` / `maxIterations` rows now state the positive
constraint and what happens on a bad value, and the CHANGELOG covers the ready
path and the settings entry point alongside the original flag fix.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant