Repository navigation
feat(#818): merge --watch — wait for CI checks to finish, then run merge-check and report - #831
Merged
admarble merged 2 commits intoJul 28, 2026
Conversation
…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
6 tasks
…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.
6 tasks
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a
--watchmode tosequant 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.--watchonly decides when the existing report runs; the human merge gate stays.GitHubProvider.getStatusCheckRollupSyncusingstatusCheckRollup(not the broken--json checks).--interval(30s) /--timeout(1800s); a watch timeout exits with a distinct code (3), reserving 0/1/2 for READY/NEEDS_ATTENTION/BLOCKED.CONFLICTINGmergeable state, zero checks after a dispatch block, and a runner-never-started billing lockout (reusessrc/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).--check/--scan/--reviewand--post; shares one wall-clock deadline across multiple PRs.docs/reference/merge-command.md.Pre-PR AC Verification
--watchpolls rollup to terminal, then runs merge-check + prints reportwatch.ts:waitForChecks,merge.ts:runWatchGate→ falls through torunMergeChecksmerge.ts), blocked → 2; nogh pr mergeanywhereclassifyTick(CONFLICTING, all-fail-fast annotation scan); tests inwatch.test.tsGitHubProvider+statusCheckRollup; configurable interval/timeout; foreground loopgithub.ts:getStatusCheckRollupSync;bin/cli.tsflags;await sleeploop--check/--scan/--reviewand--postrunMergeChecks, which receives the sameoptionsREADME.md,scripts/prepare-marketplace.ts,docs/reference/merge-command.mdgithub.tswrappers return[]/UNKNOWN/nullon error; test inwatch.test.tsTest plan
npm run build— passesnpm run lint— passes (0 warnings)npm run test(merge-check + merge command) — 96 passed;watch.test.tsadds 20 tests covering classify/poll/dispatch-block/timeoutsequant merge <open-pr-issue> --watchagainst a live PR with in-flight CICloses #818
🤖 Generated with Claude Code