Skip to content

sequant run exits 0 on pre-flight rejections (not-initialized, --stacked/--no-chain conflict) #848

Closed

Description

@admarble

Found during pre-2.10.0 release verification.

sequant run prints a red error and returns exit code 0 on two pre-flight rejection paths:

  • src/commands/run.ts:51-56 — "Sequant is not initialized. Run sequant init first."
  • the --stacked + --no-chain conflict immediately below it

Both use a bare return rather than setting process.exitCode = 1. Verified:

cd /tmp && sequant run 999999 --dry-run   # prints the error
echo $?                                   # 0

Any CI wrapper or shell script gating on the exit status reads these failures as success. The actual run result does propagate exit codes correctly (:157, :194) — this is specific to the pre-flight rejections. sync.ts and update.ts already set process.exitCode = 1 on the same not-initialized branch, so run.ts is the outlier.

Pre-existing since #503 — not a 2.10.0 regression. Adjacent in spirit to #833: the parser layer now fails loudly, but the command layer still exits 0.

Acceptance Criteria

  • AC-1: The not-initialized path sets a non-zero exit code, matching sync.ts and update.ts.
  • AC-2: The --stacked + --no-chain conflict sets a non-zero exit code.
  • AC-3: An audit of the remaining console.log(chalk.red(...)) + bare-return pairs across src/commands/ confirms no other error path exits 0.

Activity

  1. admarble commented on Jul 29, 2026

    @admarble
    ContributorAuthor

    Complexity: Standard (3 ACs, 1 directory / 4 files)

    AC Quality Check

    All three ACs are measurable and testable. AC-3 is an audit AC — its literal wording ("confirms no other error path exits 0") is falsifiable, and the audit below falsifies it: there are more bare-return error paths than the two named. That's not an AC defect — it's the AC doing its job. See the audit results under AC-3.

    ⚠️ Factual correction to the issue premise: the body states "sync.ts and update.ts already set process.exitCode = 1 on the same not-initialized branch." Only sync.ts does (sync.ts:274). update.ts's not-initialized branch (update.ts:74-81) bare-returns with no exit code — the process.exitCode = 1 at update.ts:61 lives in the unrelated refuseNonInteractive() helper. So update.ts is a second instance of the same bug, not a correct reference.


    Scope Assessment

    Non-Goals: ⚠️ No Non-Goals section in the issue. The natural scope boundary is the Open Question below (how far the AC-3 audit fix extends).

    Metric Value Status
    Feature count 1 (consistent non-zero exit on rejection) ✅
    AC items 3 ✅
    Directory spread 1 (src/commands/) ✅

    Verdict: ✅ SCOPE_OK for the two named sites; ⚠️ SCOPE_WARNING once AC-3's audit findings are folded in (touches 4 files). Recommend enabling the quality loop given the audit expansion.


    Acceptance Criteria

    AC-1: not-initialized path sets non-zero exit code

    Verification: Unit Test
    Scenario: Given no manifest (uninitialized project) → When runCommand runs → Then it prints the red error and process.exitCode === 1, then returns.
    Assumptions: getManifest() returns falsy when uninitialized (confirmed, run.ts:50-51). Fix = insert process.exitCode = 1; before the return at run.ts:55, matching sync.ts:274.

    AC-2: --stacked + --no-chain conflict sets non-zero exit code

    Verification: Unit Test
    Scenario: Given { stacked: true, chain: false } → When runCommand runs → Then red conflict message and process.exitCode === 1, then returns.
    Assumptions: Fix = insert process.exitCode = 1; before the return at run.ts:64.

    AC-3: audit confirms no other error path exits 0

    Verification: Unit Test (per-site) + audit table in the PR/QA comment.
    Scenario: Given each command's rejection path → When triggered → Then a non-zero exit code is set.

    Audit result — console.log(chalk.red(...)) + bare return across src/commands/ (test files excluded):

    # Site Path In issue? Exits 0 today?
    1 run.ts:55 not-initialized AC-1 ✅ yes (fix)
    2 run.ts:64 --stacked + --no-chain AC-2 ✅ yes (fix)
    3 run.ts:73 --chain + --batch conflict no ✅ yes — same function, same class
    4 run.ts:84 invalid --concurrency no ✅ yes — same function, same class
    5 update.ts:80 not-initialized no (issue wrongly calls this correct) ✅ yes — identical to AC-1
    6 state.ts:76 stateInitCommand: discovery failed no ✅ yes (top-level handler)
    7 state.ts:178 stateRebuildCommand: rebuild failed no ✅ yes (top-level handler)
    8 state.ts:314 stateCleanCommand: cleanup failed no ✅ yes (top-level handler)
    9 init.ts:690 upgradeSkills: no skills dir no ✅ yes — helper awaited at init.ts:139, no return handling

    So AC-3 as literally written cannot pass without also touching sites 3–9. The requirement behind AC-3 is: every command-level rejection/failure path sets a non-zero exit code. The Open Question bounds how many of 3–9 land in this PR.

    Reference-correct pattern (sync.ts:271-275):

    console.log(chalk.red("❌ ..."));
    process.exitCode = 1;   // set, then return — NOT process.exit(1) (skips cleanup)
    return;

    Implementation Plan

    Phase 1: Fix the four run.ts CLI rejections (AC-1, AC-2, + trivially co-located siblings 3–4)

    1. Insert process.exitCode = 1; before the return; at run.ts:55, :64, :73, :84. All four live in runCommand, are the same class (pre-flight CLI rejection), and are one-line each — bundling them is cheaper than a follow-up and makes AC-3 truthful for run.ts.

    Phase 2: Fold in the cross-file audit findings (5–8; 9 pending Open Question)

    1. update.ts:80 — add process.exitCode = 1; (corrects the issue's own faulty premise; identical not-initialized pattern).
    2. state.ts:76, :178, :314 — add process.exitCode = 1; on each !success failure branch. Careful: these commands support --json; keep the exit-code write on the failure path only, and confirm the --json branches that print a { success:false } object also set exit 1 (a machine consumer needs both). Check the sibling JSON branch at state.ts:172-177.
    3. init.ts:690 (upgradeSkills "no skills dir") — see Open Question; if in scope, set process.exitCode = 1 in the helper (the awaited helper can't return a code to initCommand, so setting process.exitCode directly is correct).

    Phase 3: Tests

    1. New unit tests modeled on assess-render.test.ts (save/restore process.exitCode in beforeEach/afterEach, assert toBe(1)). Cover each fixed site. Mock getManifest/getSettings as needed. Add a negative test: a successful pre-flight leaves process.exitCode undefined (guards against globally clobbering it).

    Design Review

    1. Where does this logic belong? The command-adapter layer (src/commands/*.ts), exactly where the rejections already print. No new abstraction warranted.
    2. What's the simplest correct approach? One line — process.exitCode = 1; — before each return. Use process.exitCode, not process.exit(1): the codebase convention (sync.ts, update.ts:61) sets the code and lets the process drain naturally; process.exit() would skip pending I/O/cleanup.
    3. What existing pattern does this follow? sync.ts:271-275 — the canonical not-initialized handler. This change makes the outliers conform.
    4. What would a senior reviewer challenge? (a) "Why not extract a rejectPreflight(msg) helper?" — 9 sites across 4 files is borderline, but the print formats differ (❌ vs ✗) and a helper adds indirection for a one-liner; keep inline, matching sync.ts. (b) "Scope creep past the two named sites?" — answered by AC-3, which mandates the audit; the Open Question bounds it explicitly.

    Feature Quality Planning

    All standard checks pass. Notable items:

    • Silent exit-code clobber risk: verify the fix only fires on the rejection path, never on success (negative test in Phase 3 step 5).
    • --json consumers (state.ts): the JSON failure branches must also set exit 1, or scripted callers still can't gate on $?. Check state.ts:172-177 and the two other JSON branches.
    • process.exit() vs process.exitCode: must use the latter to avoid truncating output/cleanup.

    Open Questions

    1. How far does the AC-3 fix extend? — Recommendation: fix 1–8 in this PR (all run.ts rejections + update.ts not-initialized + the three state.ts failure paths) — they're the same defect and cheap to bundle. Treat 9 (init.ts upgradeSkills) as in-scope-but-confirm: it's a helper, not a top-level pre-flight, and "no skills directory" is arguably a soft/no-op condition rather than a hard error. Impact if wrong: excluding it leaves one error path at exit 0, so AC-3's "no other error path" is technically unmet — I lean toward fixing it too for a clean audit. Please confirm the boundary.
    2. Is update.ts's not-initialized bug worth its own note in the PR body? — Recommendation: yes, call out that the issue premise was inaccurate so reviewers don't trust update.ts as the reference. Impact if wrong: low.

    Recommended Workflow

    Phases: spec → exec → qa
    Quality Loop: enabled (SCOPE_WARNING from the audit expansion across 4 files)
    Reasoning: Small, mechanical, well-patterned fix with a clear reference (sync.ts). Not UI, so no test phase. Testgen optional — the test target is unambiguous (assess-render.test.ts pattern) and tests are mandatory within exec; a separate testgen phase adds little for a one-line-per-site fix. QA must verify the audit table (AC-3) site-by-site, not just the two named ACs.


    Label Review

    Current: (none)
    Recommended: bug
    Reason: Pure correctness fix (exit-code semantics); no feature/UI surface.
    Quality Loop: Will auto-enable via SCOPE_WARNING once the audit findings (4 files) are in scope.

    → gh issue edit 848 --add-label bug


    --- DRAFT GITHUB ISSUE COMMENT (PLAN) ---

    Plan (/spec)

    Confirmed the two named run.ts sites, and the AC-3 audit found the bug is wider than described:

    • run.ts:55 not-initialized (AC-1), run.ts:64 --stacked+--no-chain (AC-2) — both bare-return, exit 0. ✅
    • Not named but same class: run.ts:73 (--chain+--batch), run.ts:84 (invalid --concurrency) — same function, also exit 0.
    • ⚠️ Issue premise correction: update.ts is not a correct reference. Its not-initialized branch (update.ts:80) bare-returns; the exitCode=1 at :61 is the unrelated refuseNonInteractive() helper. Only sync.ts:274 sets the code on not-initialized.
    • Also exit 0: state.ts:76/178/314 (init/rebuild/clean failure paths), init.ts:690 (upgradeSkills no-skills-dir).

    Fix: insert process.exitCode = 1; before each return (the sync.ts:271-275 pattern). Use process.exitCode, not process.exit(1).

    AC checklist

    • AC-1 — process.exitCode === 1 on run.ts not-initialized. Unit test (save/restore process.exitCode, per assess-render.test.ts).
    • AC-2 — process.exitCode === 1 on --stacked+--no-chain. Unit test.
    • AC-3 — audit fixes every remaining bare-return error path; per-site unit tests + negative test (success path leaves exit code unset). Unit tests.

    Open questions

    1. Scope boundary: recommend fixing sites 1–8 (run.ts ×4, update.ts, state.ts ×3); confirm whether init.ts:690 (upgradeSkills) is in scope.
    2. --json failure branches in state.ts must also set exit 1 for scripted consumers — will verify.

    Workflow: spec → exec → qa · quality loop enabled.

  2. added
    planned
    on Jul 29, 2026
  3. admarble commented on Jul 29, 2026

    @admarble
    ContributorAuthor

    Progress Update (/exec) — PR #852

    Implemented and pushed. All three ACs satisfied; the AC-3 audit expanded the fix beyond the two named sites.

    AC Coverage

    AC Status Evidence
    AC-1 — not-initialized sets non-zero exit ✅ Implemented run.ts:55; unit + e2e (exit 1)
    AC-2 — --stacked+--no-chain sets non-zero exit ✅ Implemented run.ts:64; unit + e2e (exit 1)
    AC-3 — audit confirms no other error path exits 0 ✅ Implemented full audit below, every site fixed + tested

    AC-3 audit result

    Fixed (each now sets process.exitCode = 1):

    • run.ts — not-initialized, --stacked+--no-chain, plus --chain+--batch and invalid --concurrency (same class, not named)
    • update.ts — not-initialized. ⚠️ The issue premise was wrong: update.ts was not a correct reference; its not-initialized branch had the identical bug. Only sync.ts set the code there.
    • state.ts — init / rebuild / clean failure paths (+ their --json branches)
    • status.ts — --rebuild, --cleanup, and state-read failures. ⚠️ These three were missed by the issue's own audit table but are the same defect.
    • init.ts — --upgrade-skills "no skills directory" path (site 9)

    No change needed: locks.ts (×3) and dashboard.ts already set exit codes.

    Design

    • process.exitCode = 1, not process.exit(1), matching the sync.ts:274 reference (drains output/cleanup).
    • --json failure branches in state/status also set the code so scripted consumers can gate on $?.

    Files changed

    • src/commands/run.ts, update.ts, state.ts, status.ts, init.ts
    • Tests: run-preflight-exit.test.ts, state-exit-code.test.ts, status-exit-code.test.ts (new); update.test.ts, init.test.ts (extended)
    • CHANGELOG.md

    Checks

    • npm run build ✅ · npm run lint ✅ (0 warnings) · targeted tests ✅ (216 passed)
    • Mutation-verified: reverting the AC-1 fix fails only the AC-1 test.
    • E2E: run 999999 --dry-run in an uninitialized dir now exits 1 (was 0); update and the --stacked+--no-chain conflict likewise.
  4. admarble commented on Jul 29, 2026

    @admarble
    ContributorAuthor

    QA Review for Issue #848

    AC Coverage

    AC Source Description Status Notes
    AC-1 Original not-initialized path sets non-zero exit MET run.ts:55 sets process.exitCode = 1; e2e (uninitialized dir): run 999999 --dry-run → exit 1. Mutation-verified.
    AC-2 Original --stacked+--no-chain sets non-zero exit MET run.ts:64; e2e → exit 1.
    AC-3 Original audit confirms no other error path exits 0 MET Independently re-audited every chalk.red site in src/commands/. All genuine error paths now set a code; remaining sites are status/diff coloring or already correct (abort.ts:199, sync.ts:285, locks.ts, dashboard.ts). The 3 status.ts sites the issue's own table missed are fixed.

    Coverage: 3/3 ACs implemented correctly in source — but see the blocking regression below.


    CI Status

    Check State Bucket Impact
    build (22.x) FAILURE fail ❌ NOT_MET (regression)
    typecheck SUCCESS pass ✅
    validate-skills SUCCESS pass ✅
    validate-plugin SUCCESS pass ✅
    node-floor-guard SUCCESS pass ✅

    CI Summary: 4 passed, 1 failed. Not infra-blocked (only one check failed, runners started, typecheck green).


    Build Verification (regression triage)

    Check Status
    Feature branch Run tests (node 22) ❌ Failed (4 tests)
    Same on main ✅ Passes (on main run exits 0)
    Regression Yes — introduced by this PR

    Failing tests: src/commands/cli.integration.test.ts:218–233 — reproduced locally (4 failed / 12 passed).

    -q parses without error (AC-1)                       × exit code 1
    -Q parses without error (AC-1)                        × exit code 1
    --experimental-tui still parses as a hidden no-op ... × exit code 1
    --no-tui parses without error (AC-4)                  × exit code 1
    

    Root cause: these tests verify Commander flag parsing by running sequant run 1 <flag> --dry-run in an uninitialized temp dir and asserting the CLI does not crash (expect(() => runDryRun(flag)).not.toThrow()). They used exit-0 as the "parsed OK" proxy. This PR correctly makes the not-initialized guard exit 1 (AC-1), so execSync now throws on a non-zero exit and the assertion fails. The behavior change is correct; the tests that depended on the old exit-0 behavior were not updated.

    Why it wasn't caught in /exec: the exec ran only the unit suite. cli.integration.test.ts carries the .integration. infix and is not part of the targeted unit runs, so the exit-code change slipped past locally and surfaced only in CI.


    Required Fix (blocking)

    Update the four flag-parsing tests in src/commands/cli.integration.test.ts (the runDryRun helper, lines ~199–233) so they no longer depend on exit-0 for an uninitialized project. Options:

    1. Preferred: assert that parsing succeeded by checking the failure is the not-initialized guard, not a Commander parse error — e.g. accept a non-zero exit whose stdout contains Sequant is not initialized (which only prints after successful flag parsing), and only fail on an actual Commander usage error.
    2. Or initialize a minimal Sequant project in the test's temp dir before runDryRun, so --dry-run proceeds past the guard.

    Then re-run npx vitest run src/commands/cli.integration.test.ts and push. Scope is contained: the other 5 subprocess integration files (run-tui, chain-resume, update, numeric-flags, locks-cli) all pass (46/46), so no further test updates are expected.


    Test Coverage Analysis

    Changed File Tier Has Tests?
    run.ts Standard ✅ run-preflight-exit.test.ts (new, 5 tests incl. negative)
    update.ts Standard ✅ update.test.ts (extended)
    state.ts Standard ✅ state-exit-code.test.ts (new)
    status.ts Standard ✅ status-exit-code.test.ts (new)
    init.ts Standard ✅ init.test.ts (extended)

    New unit tests are strong: mutation-verified (reverting the run.ts AC-1 fix and the state.ts JSON-branch guard each failed exactly the corresponding test), and a negative test pins that a passing pre-flight leaves the exit code unset. Coverage gap is the pre-existing integration test that wasn't updated for the new behavior — the required fix above.


    Quality Metrics

    Metric Value Status
    Type issues (any) 2 (in new test file, as any on mock fixtures) OK — test-only
    Deleted tests 0 OK
    Files changed 11 OK
    Lines added / deleted +400 / -0 OK

    Code Review

    Strengths:

    • Every fix uses process.exitCode = 1 + return, matching the sync.ts:274 reference — no process.exit(1) (output/cleanup drains).
    • --json failure branches in state/status also set the code, so scripted consumers reading structured output can gate on $?. This is the correct, complete reading of AC-3.
    • The audit went beyond the issue's table and caught the 3 status.ts sites the issue missed, and corrected the issue's false premise about update.ts.

    Issues:

    • ❌ Blocking: the exit-code change broke cli.integration.test.ts (above). A behavior change to CLI exit codes must be accompanied by updates to the integration tests that assert on those exit codes.

    Trust-Boundary Check

    Finding: Clean — the diff implements only the product requirement (non-zero exit on rejection); no agent-directed instruction from the issue/comments was acted on.

    Status: Clean


    CHANGELOG Verification

    Check Status
    CHANGELOG.md exists ✅ Found
    User-facing changes ✅ Yes (fix: commit)
    [Unreleased] entry ✅ Present
    Entry format ✅ Valid (includes #848)

    Result: CHANGELOG requirements met.


    Risk Assessment

    • Likely failure mode: none in the shipped behavior — the fix is correct and e2e-verified. The risk is purely the red CI: merging now would land a failing test suite.
    • Not tested (by exec): the .integration. suite locally — which is exactly what caught this. Now verified.
    • Sibling sites considered: cross-file audit complete — every chalk.red/error path in src/commands/ inspected; no other error path exits 0. abort.ts, sync.ts, locks.ts, dashboard.ts already correct.
    • Sibling-line audit: all four run.ts guards + both state/status JSON branches fixed consistently; no adjacent error-and-return left at exit 0.

    Adversarial Re-Read

    Findings: Ran the implementation e2e against all four run.ts reproduction paths (all exit 1) and confirmed the source audit is complete. The gap the structured pipeline surfaced: the exec's PR "test plan" claimed the suite was green, but only the unit suite was run — the .integration. suite is CI-red with a real regression (cli.integration.test.ts), which is an evidence gap (green claimed, integration not actually run), not a source defect. That is why the verdict is blocked despite all three ACs being individually MET.

    Status: Severe Gap (regression not run/caught pre-PR)


    Verdict: AC_NOT_MET

    The three ACs are correctly and completely implemented in source (independently audited and e2e-verified), but the PR is not mergeable: it introduces a real CI regression — cli.integration.test.ts (4 tests) depended on the old exit-0 behavior and was not updated. Fix those four flag-parsing tests (Required Fix above), push, and re-run /qa.

    Documentation

    • N/A — bug fix; CHANGELOG entry present.

    Next Steps

    1. Update src/commands/cli.integration.test.ts (runDryRun, lines ~199–233) so the 4 flag-parsing tests don't rely on exit-0 in an uninitialized dir (prefer: assert the non-zero exit is the not-initialized guard, not a Commander parse error).
    2. npx vitest run src/commands/cli.integration.test.ts → green; push.
    3. Re-run /qa 848 — expected verdict READY_FOR_MERGE once CI is green.
  5. added
    needs-work
    on Jul 29, 2026
  6. added a commit that references this issue on Jul 29, 2026
  7. admarble commented on Jul 29, 2026

    @admarble
    ContributorAuthor

    Progress Update (/exec) — PR #852, follow-up commit

    Fixed the blocking regression QA found (AC_NOT_MET). The three ACs were already correctly implemented in source; the only issue was 4 pre-existing flag-parsing tests that depended on the old exit-0 behavior.

    What changed

    src/commands/cli.integration.test.ts — the four run flag-parsing tests (-q, -Q, --experimental-tui, --no-tui) used exit-0 as a "Commander parsed OK" proxy. Since #848 makes the not-initialized pre-flight guard exit 1, that proxy is no longer valid.

    Replaced the runDryRun helper with expectFlagAccepted, implementing QA's preferred option 1:

    • spawnSync the command in the repo root (an uninitialized project).
    • Assert output contains Sequant is not initialized — that guard prints only after Commander parses every flag, so reaching it proves the flag under test was accepted.
    • Assert stderr has no error: unknown option — a genuine usage error never reaches the guard.

    This asserts the tests' actual intent (the flag is accepted by Commander) independent of the exit code, so it won't re-break if exit semantics change again.

    Verification

    • npx vitest run src/commands/cli.integration.test.ts → 16/16 pass (was 12/16).
    • Mutation-verified: swapping in an unknown flag (--definitely-not-a-real-flag) fails the assertion — the check is not tautological.
    • npm run build ✅ · npm run lint ✅ (0 warnings).
    • No other files touched; the source exit-code fixes are unchanged.

    Note: src/commands/__tests__/prompt-wait.test.ts fails locally on this machine (ENOENT on a temp relay inbox.jsonl). It is unchanged by this branch, is a relay unit test unrelated to #848, and passed in the CI run QA cited — a local-only environmental flake, out of scope here.

    Re-run /qa 848 once CI is green — expected READY_FOR_MERGE.

  8. added a commit that references this issue on Jul 29, 2026
  9. admarble commented on Jul 29, 2026

    @admarble
    ContributorAuthor

    Quality Loop Complete (/loop)

    Issue: #848 · Iterations: 0/3 (no fix pass needed) · Final Status: READY_FOR_MERGE (pending fresh /qa)

    The previous qa phase ended without a parseable verdict, but the last substantive QA verdict was AC_NOT_MET with a single required fix — update the 4 flag-parsing tests in cli.integration.test.ts. That fix, plus a second CI blocker surfaced during CI, are already committed, so /loop had no remaining actionable findings and made no new changes (per the no-diff guard).

    QA findings → resolution

    Finding (source) Status Where
    AC_NOT_MET — 4 flag-parse tests relied on exit-0 in an uninitialized dir ✅ Fixed 0c37132d — replaced runDryRun with expectFlagAccepted (asserts the flag reached the not-initialized guard, independent of exit code; mutation-verified)
    CI: run.ts exceeded the 200-line thin-adapter cap (#503 AC-2) after the 4 exit-code inserts ✅ Fixed 37554ba0 — consolidated the four pre-flight rejections into a rejectPreflight() helper; run.ts back to 200 lines

    Quality gates (latest commit 37554ba0)

    Gate Result
    CI build (22.x) ✅ SUCCESS
    CI typecheck / validate-skills / validate-plugin / node-floor-guard ✅ SUCCESS
    PR mergeable ✅ MERGEABLE
    Local build / lint ✅ Pass (0 warnings)
    Affected suites (run-orchestrator.integration, run-preflight-exit, cli.integration, run.test) ✅ 175/175

    All three ACs remain MET (source unchanged since the last QA audit); the only work was making the test suite reflect the corrected exit-code behavior.

    Recommended next step

    Re-run /qa 848 for a final verdict — expected READY_FOR_MERGE now that CI is green.

  10. added
    ready-for-review
    and removed
    needs-work
    on Jul 29, 2026
  11. admarble commented on Jul 29, 2026

    @admarble
    ContributorAuthor

    QA Review for Issue #848

    Re-run after the two fix commits (0c37132d, 37554ba0). Prior verdict was AC_NOT_MET on a CI regression; both blockers are now resolved and CI is fully green.

    AC Coverage

    AC Source Description Status Notes
    AC-1 Original not-initialized path sets non-zero exit MET run.ts not-initialized → process.exitCode = 1 via rejectPreflight(). E2E in uninitialized dir: run 999999 --dry-run → exit 1. Unit: run-preflight-exit.test.ts AC-1.
    AC-2 Original --stacked+--no-chain conflict sets non-zero exit MET options.stacked && options.chain === false → exit 1. Unit test exercises the branch directly ({stacked:true, chain:false}). See --no-chain observation below (pre-existing, out of scope).
    AC-3 Original audit confirms no other error path exits 0 MET Independently re-audited: every chalk.red error site in src/commands/ now sets a non-zero code or is display-only. Fixed: run.ts (4 guards), update.ts, state.ts (init/rebuild/clean + --json), status.ts (read/rebuild/cleanup + --json), init.ts (--upgrade-skills). Already-correct/non-error: sync.ts, abort.ts (exitCode=1 at :200 covers the :218 failure msg), dashboard.ts, locks.ts, logs.ts (status coloring only).

    Coverage: 3/3 original ACs MET. No derived ACs.

    CI Status

    Check State Impact
    build (22.x) SUCCESS ✅ MET
    typecheck SUCCESS ✅ MET
    validate-skills SUCCESS ✅ MET
    validate-plugin SUCCESS ✅ MET
    node-floor-guard SUCCESS ✅ MET

    CI Summary: 5 passed, 0 pending, 0 failed. PR #852 MERGEABLE. Branch 0 commits behind main.

    Quality Metrics

    Metric Value Status
    Type issues (any) 2 OK — both as any on test-fixture mocks, eslint-disabled
    Deleted tests 0 OK
    Files changed 12 OK
    Lines +434 / -34 OK (mostly new test files)

    Test Coverage Analysis

    Changed source file Tier Has Tests?
    run.ts Standard ✅ run-preflight-exit.test.ts (5 tests incl. negative)
    update.ts Standard ✅ update.test.ts (extended)
    state.ts Standard ✅ state-exit-code.test.ts
    status.ts Standard ✅ status-exit-code.test.ts
    init.ts Standard ✅ init.test.ts (extended)

    Coverage: 5/5 changed source files have corresponding tests. The negative test pins that a passing pre-flight leaves process.exitCode undefined.

    CLI Registration Verification

    run.ts is in the trigger set, but batch-executor.ts (where RunOptions lives) is unchanged and no new option fields were added → N/A.

    Code Review

    Strengths:

    • rejectPreflight() cleanly consolidates the four run.ts guards, uses process.exitCode (not process.exit()) so output/cleanup drains — matches the sync.ts reference. Keeps run.ts at the 200-line thin-adapter cap (arch: extract RunOrchestrator — decouple execution engine from CLI wiring #503 AC-2).
    • --json failure branches in state/status also set the code, so scripted consumers can gate on $?.
    • cli.integration.test.ts fix (expectFlagAccepted) asserts the real intent — the flag is accepted by Commander — independent of exit code. Mutation-verified.

    Issues: None blocking.

    Observation (non-blocking, pre-existing): --no-chain is not a registered CLI flag — --chain is a plain boolean and Commander rejects --no-chain as unknown (same on main). AC-2's conflict is reachable programmatically (and unit-tested) but not via the literal --stacked --no-chain invocation. Orthogonal to #848 and predates it.

    Execution Evidence

    Test Command Exit Result
    not-initialized run 999999 --dry-run (empty dir) 1 ✅ prints not-init error, exits 1
    update not-init update 999999 1 ✅ exits 1

    Evidence status: Complete.

    Trust-Boundary Check

    Finding: Clean — the diff implements only the product requirement (non-zero exit on rejection); no agent-directed instruction from the issue/comments was acted on.

    Status: Clean

    CHANGELOG Verification

    Check Status
    CHANGELOG.md exists ✅ Found
    User-facing changes ✅ Yes (fix: #848)
    [Unreleased] entry ✅ Present (includes #848)

    Result: CHANGELOG requirements met.

    Risk Assessment

    • Likely failure mode: None in shipped behavior — one-line-per-site, e2e-verified across all four run.ts paths plus update. Lowest-risk change class.
    • Not tested: The --no-chain CLI path (pre-existing, unreachable — noted above); not a regression.
    • Sibling sites considered: Cross-file scan complete — every chalk.red error site across src/commands/ audited; no other error path exits 0.
    • Sibling-line audit: All four run.ts guards + both state/status --json branches fixed consistently.

    Adversarial Re-Read

    Findings: No blocking gaps. Ran e2e against the issue's repro paths (all exit 1); independently re-audited the AC-3 corpus (all src/commands chalk.red sites); traced the --no-chain observation to a pre-existing CLI-registration quirk (out of scope); confirmed the negative test guards against exit-code clobbering; inspected process state (clean tree, 0 behind main).

    Status: Clean

    Verdict: READY_FOR_MERGE

    All three ACs are MET and independently verified (source audit + e2e + unit tests, mutation-verified in exec). CI is fully green, PR mergeable, coverage complete with a negative test, code quality high. The two CI regressions from the prior QA are resolved. The lone observation (--no-chain reachability) is pre-existing and orthogonal.

    Documentation

    • N/A — bug fix; CHANGELOG entry present.

    Next Steps

    1. Merge PR fix(#848): pre-flight rejections exit non-zero across run/update/state/status/init #852.
    2. (Optional follow-up) Decide whether --no-chain should be a registered CLI flag so the AC-2 conflict is reachable from the command line. File separately if desired.
  12. added a commit that references this issue on Jul 29, 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

    plannedready-for-review

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions