You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
sequant run exits 0 on pre-flight rejections (not-initialized, --stacked/--no-chain conflict) #848
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.
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.
Verification: Unit Test Scenario: Given no manifest (uninitialized project) → When runCommand runs → Then it prints the red error andprocess.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.
Verification: Unit Test Scenario: Given { stacked: true, chain: false } → When runCommand runs → Then red conflict message andprocess.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)
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)
update.ts:80 — add process.exitCode = 1; (corrects the issue's own faulty premise; identical not-initialized pattern).
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.
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
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
Where does this logic belong? The command-adapter layer (src/commands/*.ts), exactly where the rejections already print. No new abstraction warranted.
What's the simplest correct approach? One line — process.exitCode = 1; — before each return. Use process.exitCode, notprocess.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.
What existing pattern does this follow?sync.ts:271-275 — the canonical not-initialized handler. This change makes the outliers conform.
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
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.tsupgradeSkills) 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.
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:
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
Scope boundary: recommend fixing sites 1–8 (run.ts ×4, update.ts, state.ts ×3); confirm whether init.ts:690 (upgradeSkills) is in scope.
--json failure branches in state.ts must also set exit 1 for scripted consumers — will verify.
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.
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).
-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:
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.
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.
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.
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
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).
npx vitest run src/commands/cli.integration.test.ts → green; push.
Re-run /qa 848 — expected verdict READY_FOR_MERGE once CI is green.
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.
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
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).
--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.
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/commandschalk.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.
(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.
Activity
admarble commentedon Jul 29, 2026
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-
returnerror 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.sync.tsandupdate.tsalready setprocess.exitCode = 1on the same not-initialized branch." Onlysync.tsdoes (sync.ts:274).update.ts's not-initialized branch (update.ts:74-81) bare-returns with no exit code — theprocess.exitCode = 1atupdate.ts:61lives in the unrelatedrefuseNonInteractive()helper. Soupdate.tsis 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).
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
runCommandruns → Then it prints the red error andprocess.exitCode === 1, then returns.Assumptions:
getManifest()returns falsy when uninitialized (confirmed,run.ts:50-51). Fix = insertprocess.exitCode = 1;before thereturnatrun.ts:55, matchingsync.ts:274.AC-2:
--stacked+--no-chainconflict sets non-zero exit codeVerification: Unit Test
Scenario: Given
{ stacked: true, chain: false }→ WhenrunCommandruns → Then red conflict message andprocess.exitCode === 1, then returns.Assumptions: Fix = insert
process.exitCode = 1;before thereturnatrun.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(...))+ barereturnacrosssrc/commands/(test files excluded):run.ts:55run.ts:64--stacked+--no-chainrun.ts:73--chain+--batchconflictrun.ts:84--concurrencyupdate.ts:80state.ts:76stateInitCommand: discovery failedstate.ts:178stateRebuildCommand: rebuild failedstate.ts:314stateCleanCommand: cleanup failedinit.ts:690upgradeSkills: no skills dirawaited atinit.ts:139, no return handlingSo 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):Implementation Plan
Phase 1: Fix the four
run.tsCLI rejections (AC-1, AC-2, + trivially co-located siblings 3–4)process.exitCode = 1;before thereturn;atrun.ts:55,:64,:73,:84. All four live inrunCommand, 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 forrun.ts.Phase 2: Fold in the cross-file audit findings (5–8; 9 pending Open Question)
update.ts:80— addprocess.exitCode = 1;(corrects the issue's own faulty premise; identical not-initialized pattern).state.ts:76,:178,:314— addprocess.exitCode = 1;on each!successfailure branch. Careful: these commands support--json; keep the exit-code write on the failure path only, and confirm the--jsonbranches that print a{ success:false }object also set exit 1 (a machine consumer needs both). Check the sibling JSON branch atstate.ts:172-177.init.ts:690(upgradeSkills"no skills dir") — see Open Question; if in scope, setprocess.exitCode = 1in the helper (theawaited helper can'treturna code toinitCommand, so settingprocess.exitCodedirectly is correct).Phase 3: Tests
assess-render.test.ts(save/restoreprocess.exitCodeinbeforeEach/afterEach, asserttoBe(1)). Cover each fixed site. MockgetManifest/getSettingsas needed. Add a negative test: a successful pre-flight leavesprocess.exitCodeundefined (guards against globally clobbering it).Design Review
src/commands/*.ts), exactly where the rejections already print. No new abstraction warranted.process.exitCode = 1;— before eachreturn. Useprocess.exitCode, notprocess.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.sync.ts:271-275— the canonical not-initialized handler. This change makes the outliers conform.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, matchingsync.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:
--jsonconsumers (state.ts): the JSON failure branches must also set exit 1, or scripted callers still can't gate on$?. Checkstate.ts:172-177and the two other JSON branches.process.exit()vsprocess.exitCode: must use the latter to avoid truncating output/cleanup.Open Questions
run.tsrejections +update.tsnot-initialized + the threestate.tsfailure paths) — they're the same defect and cheap to bundle. Treat 9 (init.tsupgradeSkills) 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.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 trustupdate.tsas 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 notestphase. Testgen optional — the test target is unambiguous (assess-render.test.tspattern) 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:
bugReason: 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.tssites, and the AC-3 audit found the bug is wider than described:run.ts:55not-initialized (AC-1),run.ts:64--stacked+--no-chain(AC-2) — both bare-return, exit 0. ✅run.ts:73(--chain+--batch),run.ts:84(invalid--concurrency) — same function, also exit 0.update.tsis not a correct reference. Its not-initialized branch (update.ts:80) bare-returns; theexitCode=1at:61is the unrelatedrefuseNonInteractive()helper. Onlysync.ts:274sets the code on not-initialized.state.ts:76/178/314(init/rebuild/clean failure paths),init.ts:690(upgradeSkillsno-skills-dir).Fix: insert
process.exitCode = 1;before eachreturn(thesync.ts:271-275pattern). Useprocess.exitCode, notprocess.exit(1).AC checklist
process.exitCode === 1onrun.tsnot-initialized. Unit test (save/restoreprocess.exitCode, perassess-render.test.ts).process.exitCode === 1on--stacked+--no-chain. Unit test.Open questions
init.ts:690(upgradeSkills) is in scope.--jsonfailure branches instate.tsmust also set exit 1 for scripted consumers — will verify.Workflow: spec → exec → qa · quality loop enabled.
admarble commentedon Jul 29, 2026
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
run.ts:55; unit + e2e (exit 1)--stacked+--no-chainsets non-zero exitrun.ts:64; unit + e2e (exit 1)AC-3 audit result
Fixed (each now sets
process.exitCode = 1):run.ts— not-initialized,--stacked+--no-chain, plus--chain+--batchand invalid--concurrency(same class, not named)update.ts— not-initialized.update.tswas not a correct reference; its not-initialized branch had the identical bug. Onlysync.tsset the code there.state.ts— init / rebuild / clean failure paths (+ their--jsonbranches)status.ts—--rebuild,--cleanup, and state-read failures.init.ts—--upgrade-skills"no skills directory" path (site 9)No change needed:
locks.ts(×3) anddashboard.tsalready set exit codes.Design
process.exitCode = 1, notprocess.exit(1), matching thesync.ts:274reference (drains output/cleanup).--jsonfailure branches instate/statusalso set the code so scripted consumers can gate on$?.Files changed
src/commands/run.ts,update.ts,state.ts,status.ts,init.tsrun-preflight-exit.test.ts,state-exit-code.test.ts,status-exit-code.test.ts(new);update.test.ts,init.test.ts(extended)CHANGELOG.mdChecks
npm run build✅ ·npm run lint✅ (0 warnings) · targeted tests ✅ (216 passed)run 999999 --dry-runin an uninitialized dir now exits1(was0);updateand the--stacked+--no-chainconflict likewise.admarble commentedon Jul 29, 2026
QA Review for Issue #848
AC Coverage
run.ts:55setsprocess.exitCode = 1; e2e (uninitialized dir):run 999999 --dry-run→ exit 1. Mutation-verified.--stacked+--no-chainsets non-zero exitrun.ts:64; e2e → exit 1.chalk.redsite insrc/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 3status.tssites the issue's own table missed are fixed.Coverage: 3/3 ACs implemented correctly in source — but see the blocking regression below.
CI Status
build (22.x)typecheckvalidate-skillsvalidate-pluginnode-floor-guardCI Summary: 4 passed, 1 failed. Not infra-blocked (only one check failed, runners started,
typecheckgreen).Build Verification (regression triage)
Run tests(node 22)mainrunexits 0)Failing tests:
src/commands/cli.integration.test.ts:218–233— reproduced locally (4 failed / 12 passed).Root cause: these tests verify Commander flag parsing by running
sequant run 1 <flag> --dry-runin 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), soexecSyncnow 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.tscarries 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(therunDryRunhelper, lines ~199–233) so they no longer depend on exit-0 for an uninitialized project. Options:Sequant is not initialized(which only prints after successful flag parsing), and only fail on an actual Commander usage error.runDryRun, so--dry-runproceeds past the guard.Then re-run
npx vitest run src/commands/cli.integration.test.tsand 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
run.tsrun-preflight-exit.test.ts(new, 5 tests incl. negative)update.tsupdate.test.ts(extended)state.tsstate-exit-code.test.ts(new)status.tsstatus-exit-code.test.ts(new)init.tsinit.test.ts(extended)New unit tests are strong: mutation-verified (reverting the
run.tsAC-1 fix and thestate.tsJSON-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
any)as anyon mock fixtures)Code Review
Strengths:
process.exitCode = 1+return, matching thesync.ts:274reference — noprocess.exit(1)(output/cleanup drains).--jsonfailure branches instate/statusalso set the code, so scripted consumers reading structured output can gate on$?. This is the correct, complete reading of AC-3.status.tssites the issue missed, and corrected the issue's false premise aboutupdate.ts.Issues:
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
fix:commit)Result: CHANGELOG requirements met.
Risk Assessment
.integration.suite locally — which is exactly what caught this. Now verified.chalk.red/error path insrc/commands/inspected; no other error path exits 0.abort.ts,sync.ts,locks.ts,dashboard.tsalready correct.run.tsguards + bothstate/statusJSON branches fixed consistently; no adjacent error-and-return left at exit 0.Adversarial Re-Read
Findings: Ran the implementation e2e against all four
run.tsreproduction 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
Next Steps
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).npx vitest run src/commands/cli.integration.test.ts→ green; push./qa 848— expected verdictREADY_FOR_MERGEonce CI is green.fix(#848): update flag-parse tests that relied on exit-0 in an uninit…
admarble commentedon Jul 29, 2026
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 fourrunflag-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 exit1, that proxy is no longer valid.Replaced the
runDryRunhelper withexpectFlagAccepted, implementing QA's preferred option 1:spawnSyncthe command in the repo root (an uninitialized project).Sequant is not initialized— that guard prints only after Commander parses every flag, so reaching it proves the flag under test was accepted.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).--definitely-not-a-real-flag) fails the assertion — the check is not tautological.npm run build✅ ·npm run lint✅ (0 warnings).Re-run
/qa 848once CI is green — expectedREADY_FOR_MERGE.fix(#848): keep run.ts under the 200-line thin-adapter cap after exit…
admarble commentedon Jul 29, 2026
Quality Loop Complete (/loop)
Issue: #848 · Iterations: 0/3 (no fix pass needed) · Final Status: READY_FOR_MERGE (pending fresh /qa)
The previous
qaphase ended without a parseable verdict, but the last substantive QA verdict wasAC_NOT_METwith a single required fix — update the 4 flag-parsing tests incli.integration.test.ts. That fix, plus a second CI blocker surfaced during CI, are already committed, so/loophad no remaining actionable findings and made no new changes (per the no-diff guard).QA findings → resolution
AC_NOT_MET— 4 flag-parse tests relied on exit-0 in an uninitialized dir0c37132d— replacedrunDryRunwithexpectFlagAccepted(asserts the flag reached the not-initialized guard, independent of exit code; mutation-verified)run.tsexceeded the 200-line thin-adapter cap (#503 AC-2) after the 4 exit-code inserts37554ba0— consolidated the four pre-flight rejections into arejectPreflight()helper;run.tsback to 200 linesQuality gates (latest commit
37554ba0)build (22.x)typecheck/validate-skills/validate-plugin/node-floor-guardAll 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 848for a final verdict — expectedREADY_FOR_MERGEnow that CI is green.admarble commentedon Jul 29, 2026
QA Review for Issue #848
Re-run after the two fix commits (
0c37132d,37554ba0). Prior verdict wasAC_NOT_METon a CI regression; both blockers are now resolved and CI is fully green.AC Coverage
run.tsnot-initialized →process.exitCode = 1viarejectPreflight(). E2E in uninitialized dir:run 999999 --dry-run→ exit 1. Unit:run-preflight-exit.test.tsAC-1.--stacked+--no-chainconflict sets non-zero exitoptions.stacked && options.chain === false→ exit 1. Unit test exercises the branch directly ({stacked:true, chain:false}). See--no-chainobservation below (pre-existing, out of scope).chalk.rederror site insrc/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=1at :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
CI Summary: 5 passed, 0 pending, 0 failed. PR #852 MERGEABLE. Branch 0 commits behind main.
Quality Metrics
any)as anyon test-fixture mocks, eslint-disabledTest Coverage Analysis
run.tsrun-preflight-exit.test.ts(5 tests incl. negative)update.tsupdate.test.ts(extended)state.tsstate-exit-code.test.tsstatus.tsstatus-exit-code.test.tsinit.tsinit.test.ts(extended)Coverage: 5/5 changed source files have corresponding tests. The negative test pins that a passing pre-flight leaves
process.exitCodeundefined.CLI Registration Verification
run.tsis in the trigger set, butbatch-executor.ts(whereRunOptionslives) is unchanged and no new option fields were added → N/A.Code Review
Strengths:
rejectPreflight()cleanly consolidates the fourrun.tsguards, usesprocess.exitCode(notprocess.exit()) so output/cleanup drains — matches thesync.tsreference. Keepsrun.tsat the 200-line thin-adapter cap (arch: extract RunOrchestrator — decouple execution engine from CLI wiring #503 AC-2).--jsonfailure branches instate/statusalso set the code, so scripted consumers can gate on$?.cli.integration.test.tsfix (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-chainis not a registered CLI flag —--chainis a plain boolean and Commander rejects--no-chainas unknown (same onmain). AC-2's conflict is reachable programmatically (and unit-tested) but not via the literal--stacked --no-chaininvocation. Orthogonal to #848 and predates it.Execution Evidence
run 999999 --dry-run(empty dir)update 999999Evidence 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
fix:#848)Result: CHANGELOG requirements met.
Risk Assessment
run.tspaths plusupdate. Lowest-risk change class.--no-chainCLI path (pre-existing, unreachable — noted above); not a regression.chalk.rederror site acrosssrc/commands/audited; no other error path exits 0.run.tsguards + bothstate/status--jsonbranches 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/commandschalk.redsites); traced the--no-chainobservation 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-chainreachability) is pre-existing and orthogonal.Documentation
Next Steps
--no-chainshould be a registered CLI flag so the AC-2 conflict is reachable from the command line. File separately if desired.fix(#848): pre-flight rejections exit non-zero across run/update/stat…
docs: 2.10 release-notes section + coverage gaps found by release audit