Skip to content

8 numeric CLI options still use bare parseInt — #833's unit-suffix misparse is unaddressed (--max-age fails open) #845

Closed

Description

@admarble

Found during pre-2.10.0 release verification.

#833 added parseWholeNumber/parsePositiveSeconds guards to 10 numeric flags. Eight numeric options in bin/cli.ts still use bare parseInt:

status [issue] (:232), status --max-age (:238), prompt --wait (:424), logs --last (:588), logs --issue (:590), dashboard --port (:617), serve --port (:630), state clean --max-age (:672).

PR #836's AC-6 table inventories all eight and justifies each as safe — but every justification reasons only about NaN. The failure #833 is named for is the unit-suffix misparse (30m to 30), which none of them address.

Demonstrated end-to-end against the current build:

sequant logs --last 30m      -> renders 30 runs (identical output to --last 30)
sequant logs --issue 817x    -> filters to issue 817
sequant status 999999x       -> treated as 999999
sequant dashboard --port 3100x -> binds port 3100
sequant serve --port 3199x   -> binds port 3199

The PR describes the two port flags as "fails loudly". True for NaN, false for the misparse — it binds the truncated port silently.

--max-age is the one that fails open. The justification relies on state-cleanup.ts:181 (options.maxAgeDays && ...), where NaN is falsy so the age rule is skipped. But --max-age 1w parses to 1, so an intended 7-day retention silently becomes 1 day and cleanup removes more than asked.

Acceptance Criteria

Activity

  1. admarble commented on Jul 29, 2026

    @admarble
    ContributorAuthor

    /spec Plan — #845

    Complexity: Standard (4 ACs, 2 directories)

    AC Quality Check

    Scope Assessment

    Non-Goals: Not stated in the issue. Implied out of scope: adding a max port bound (65535), changing any flag's semantics, or touching the 10 flags #833 already hardened.

    Metric Value Status
    Feature count 1 (harden numeric coercion) ✅
    AC items 4 ✅
    Directory spread 2 (bin/, src/lib/) ✅

    Verdict: ✅ SCOPE_OK


    Root Cause

    All eight sites pass commander the bare parseInt coercion. parseInt("30m",10) === 30: the unit suffix is silently truncated. #833 already built the correct guard — parseWholeNumber (rejects any value that isn't ^\d+$ after trim) and parsePositiveSeconds — and wired it into 10 other flags. This issue simply extends that same guard to the eight that were missed. PR #836's AC-6 table justified leaving them as parseInt by reasoning only about NaN; the misparse (a valid-but-wrong number) was never the NaN case.

    --max-age is the sharp edge: state-cleanup.ts:181 gates on options.maxAgeDays && …, so NaN (falsy) safely skips the age rule — but 1w parses to a truthy 1, silently narrowing a 7-day retention to 1 day and deleting more than asked.


    Acceptance Criteria

    AC-1: All eight options reject a unit-suffixed value with #833's message shape

    Verification: Integration Test (spawn CLI) + Unit Test (coercions called directly)
    Scenario: Given the built CLI → When invoked with logs --last 30m (and the other seven with 30m/1w/3100x) → Then it exits non-zero with <flag> expects a whole number… (got '…').

    AC-2: --max-age rejects 1w rather than narrowing retention to 1 day

    Verification: Integration Test
    Scenario: Given status --max-age 1w / state clean --max-age 1w → When run → Then rejected before any cleanup executes (no fail-open).

    AC-3: Both port flags reject 3100x instead of binding the truncated port

    Verification: Integration Test
    Scenario: Given dashboard --port 3100x / serve --port 3100x → When run → Then rejected, no server bound.

    AC-4: Legitimate boundary values that currently parse continue to parse

    Verification: Unit Test
    Scenario: Given each boundary — --wait 0 (means "don't block", see below), plain positive integers, whitespace-padded (" 60 ") — → When coerced → Then accepted unchanged.
    Assumptions: --wait 0 must stay valid (prompt.ts:259 guards on waitSeconds > 0, so 0 = no-wait). Using parsePositiveSeconds (min 1) here would regress AC-4 — use min: 0 instead.


    Implementation Plan

    Single phase, mechanical. Import already present (bin/cli.ts:28-29). Replace each parseInt with the mapped coercion:

    # Site Line Coercion
    1 status [issue] 232 parseWholeNumber("issue", { min: 1 })
    2 status --max-age 238 parseWholeNumber("--max-age", { min: 1, unit: "days" })
    3 prompt --wait 424 parseWholeNumber("--wait", { min: 0, unit: "seconds", unitSingular: "second" }) ⚠️ min:0, not parsePositiveSeconds
    4 logs --last 588 parseWholeNumber("--last", { min: 1 })
    5 logs --issue 590 parseWholeNumber("--issue", { min: 1 })
    6 dashboard --port 617 parseWholeNumber("--port", { min: 1 })
    7 serve --port 630 parseWholeNumber("--port", { min: 1 })
    8 state clean --max-age 672 parseWholeNumber("--max-age", { min: 1, unit: "days" })

    Then add tests in src/lib/cli-flags.test.ts — a data-driven case asserting each of the 8 configured coercions rejects a suffixed value (AC-1) and preserves its boundary (AC-4), plus a targeted --max-age 1w rejection (AC-2) and --port 3100x rejection (AC-3). The end-to-end reproductions in the issue body are mandatory fixtures.


    Design Review

    1. Where does this logic belong? Coercion lives in src/lib/cli-flags.ts (already the home); bin/cli.ts only wires it. No new module.
    2. What's the simplest correct approach? Reuse the existing tested guard. No new helper needed — the only judgment call is per-flag min/unit.
    3. What existing pattern does this follow? The exact #833 pattern applied to the 10 sibling flags. Message shape is inherited verbatim → satisfies AC-1 "same message shape".
    4. What would a senior reviewer challenge? (a) "Why min:0 on --wait but min:1 elsewhere?" — because --wait 0 is a documented no-wait boundary (prompt.ts:259); the others have no meaningful 0. (b) "Should ports also cap at 65535?" — deliberately out of scope (see Open Questions); AC-4 says values that currently parse should keep parsing.

    Feature Quality Planning

    All standard checks pass. Notable items:

    • The reproductions must be encoded as tests, not just verified manually — otherwise a future refactor silently reintroduces the misparse.
    • Mutation-check the --max-age test: revert the coercion and confirm the test fails (AC-2 is the fail-open case that motivated the whole issue).

    Open Questions

    1. --last 0 / --issue 0 boundary — min: 1 will reject 0. These aren't meaningful (0 runs / issue #0 doesn't exist), so I recommend min: 1. Impact if wrong: a script passing --last 0 starts erroring. Low risk; confirm during exec.
    2. Port upper bound (65535)? — Recommendation: leave out of scope. AC-3 only requires rejecting the suffix misparse; adding a max is a new behavior and risks AC-4. File as a follow-up only if desired.

    Recommended Workflow

    Phases: exec → qa
    Quality Loop: disabled
    Reasoning: Mechanical fix wiring a pre-tested helper into 8 sites; no new logic. Tests are added inline in exec (cli-flags.test.ts already exists), so a separate testgen phase is optional overhead. QA must verify the 8-site mapping table and the two boundary decisions (--wait 0, ports).


    Label Review

    Current: (none)
    Recommended: bug
    Reason: Correctness fix for a silent misparse (--max-age fails open). No UI, no browser test needed.
    Quality Loop: Won't auto-enable (SCOPE_OK, small diff).

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

    @admarble
    ContributorAuthor

    /exec Progress Update — #845

    Status: ✅ Implemented — PR #855 opened.

    AC Coverage

    AC Description Status Evidence
    AC-1 All eight options reject a unit-suffixed value with #833's message shape ✅ 8 sites in bin/cli.ts; numeric-flags.integration.test.ts (spawns real CLI) + per-flag table in cli-flags.test.ts
    AC-2 --max-age rejects 1w rather than narrowing retention to 1 day ✅ status/state clean --max-age rejected before cleanup; mutation-checked (revert → reaches "🧹 Cleaning up…", test fails)
    AC-3 Both port flags reject 3100x instead of binding the truncated port ✅ dashboard/serve --port integration cases
    AC-4 Legitimate boundary values continue to parse ✅ --wait 0 (min:0) accepted e2e; boundaries 123/7/30/817/3100/3199 pinned

    Approach

    Purely the #833 pattern applied to the eight missed flags — parseWholeNumber(flag, opts) replaces each bare parseInt, no new module. Per-flag min/unit per the /spec table; --wait gets min: 0 (a documented no-wait boundary), all others min: 1.

    End-to-end reproductions (against the built CLI)

    logs --last 30m        -> error: --last expects a whole number (got '30m').
    dashboard --port 3100x -> error: --port expects a whole number (got '3100x').
    serve --port 3199x     -> error: --port expects a whole number (got '3199x').
    status 999999x         -> error: issue expects a whole number (got '999999x').
    state clean --max-age 1w -> error: --max-age expects a whole number of days (got '1w').
    logs --last 30         -> SEQUANT RUN LOGS        (boundary preserved)
    prompt 999999 test --wait 0 -> No relay PID found  (min:0 boundary preserved)
    

    Files changed

    • bin/cli.ts — 8 parseInt → parseWholeNumber coercions
    • src/lib/cli-flags.test.ts — data-driven per-flag reject/boundary table
    • src/commands/numeric-flags.integration.test.ts — 8 e2e reproductions + --wait 0 positive control
    • CHANGELOG.md — ### Fixed entry

    Quality Plan Alignment

    Dimension Status Notes
    Reproductions encoded as tests ✅ All 8 issue-body repros are integration fixtures
    Mutation-check --max-age ✅ Reverting the coercion reaches the fail-open cleanup; the AC-2 test fails as required

    Checks

    PR

  4. admarble commented on Jul 29, 2026

    @admarble
    ContributorAuthor

    QA Review for Issue #845

    Scope: Reviewed the #845 commit (b0f02db4) only — 4 files, ~235 lines. The branch is stacked on the unmerged #846 commit; those files were excluded from AC review (see Merge Hygiene note).

    AC Coverage

    AC Description Status Evidence (runtime, against built CLI)
    AC-1 All eight options reject a unit-suffixed value with #833's message shape ✅ MET status 999999x, logs --last 30m, logs --issue 817x, prompt … --wait 30m all exit 1 with … expects a whole number… (got '…')
    AC-2 --max-age rejects 1w rather than narrowing retention to 1 day ✅ MET status --max-age 1w and state clean --max-age 1w both exit 1 with the coercion error before any 🧹 Cleaning… output; mutation-checked (reverting reaches the fail-open cleanup and the test fails)
    AC-3 Both port flags reject 3100x instead of binding the truncated port ✅ MET dashboard --port 3100x, serve --port 3199x exit 1, no bind
    AC-4 Legitimate boundary values continue to parse ✅ MET prompt … --wait 0 passes coercion (reaches liveness check); logs --last 30 exit 0; status --max-age 7 exit 0; unit table pins 123/7/30/817/3100/3199

    Coverage: 4/4 AC items MET (all runtime-verified).

    CI Status

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

    CI Summary: 5 passed, 0 pending, 0 failed. No CI-dependent ACs.

    Quality Metrics

    Metric Value Status
    Type issues (any) 0 OK
    Deleted tests 0 OK
    Files changed (#845) 4 OK
    Lines +226 / -9 -
    Build / Lint / Targeted tests pass / pass / 66 passed OK

    Test Coverage Analysis

    Changed source file Tier Has Tests?
    bin/cli.ts Standard ✅ Yes — numeric-flags.integration.test.ts spawns the real dist/bin/cli.js for all 8 flags (proves wiring, not just coercion); cli-flags.test.ts per-flag reject/boundary table

    Coverage: 1/1 changed source file has tests.

    Code Review

    Strengths:

    • Exact reuse of the fix(cli): bare parseInt on run --timeout lets a malformed value abort every phase instantly (sibling of #818) #833 parseWholeNumber guard — no new module, message shape inherited verbatim (satisfies AC-1's "same message shape" literally).
    • Per-flag min/unit are correct: --wait gets min: 0 (documented no-wait boundary via prompt.ts:259), all others min: 1.
    • Coercion runs during commander's parse phase, so every rejection exits before the action handler — this is what structurally guarantees AC-2 (no fail-open cleanup) and AC-3 (no server bind).
    • Test design is strong: integration tests use the issue's verbatim e2e reproductions as fixtures; the --max-age case was mutation-verified.

    Issues: None blocking.

    Notes (non-blocking):

    • min: 1 now rejects 0 on status [issue] / logs --last / logs --issue, where bare parseInt("0") previously yielded 0. Deliberate and spec-documented — 0 is not a legitimate value for these flags (issue #0 / 0 runs / issue-0 filter are meaningless), so AC-4 ("legitimate boundary values") is satisfied. Flagged for transparency: a script passing --last 0 would now error.

    Anti-Pattern Detection

    No any, no hardcoded secrets, no 0.0.0.0 binds, no empty catches introduced. N/A for dependency audit (no package.json change).

    Trust-Boundary Check

    Finding: Clean — the issue body is benign product requirements (an inventory of 8 flags + 4 ACs). No agent-directed instruction (command/network/file/exfiltration) is embedded or acted on.
    Status: Clean

    Behavior-Rule Survival Check

    Status: N/A — no AC triggers the behavior-rule heuristic (no default/always/never rule; ACs are input-validation assertions).

    CLI Registration Verification

    Status: N/A — no option-interface (RunOptions) fields added. The 8 flags were already registered/wired; only their coercion functions changed. Confirmed no bare parseInt remains as a commander .option()/.argument() coercion in bin/cli.ts.

    CHANGELOG Verification

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

    Result: CHANGELOG requirements met.

    Risk Assessment

    • Likely failure mode: None functional — coercion is pure and unit+integration tested. The only behavioral change beyond rejecting bad input is 0 now erroring on three read/display flags (see Notes).
    • Not tested: No automated test asserts status 0 / logs --last 0 are rejected; low value (deliberate narrowing, covered by the general min:1 unit cases).
    • Sibling sites considered (cross-file): Command handlers parse a positional issue arg with bare parseInt/Number.parseInt inside the action body — prompt.ts:63, ready.ts:136, watch.ts:102, merge.ts:245, abort.ts:93, locks.ts. Same truncation class (prompt 817x → 817) but a different layer (in-handler, not commander coercion) and outside 8 numeric CLI options still use bare parseInt — #833's unit-suffix misparse is unaddressed (--max-age fails open) #845's enumerated 8. Recommend a follow-up issue; not in scope here — do not widen this PR.
    • Sibling-line audit (intra-file): All 8 commander coercions in bin/cli.ts migrated; zero bare-parseInt coercions remain.

    Adversarial Re-Read

    Findings: Ran all 4 ACs against the built CLI (exit codes captured); confirmed the evidence is post-fix validation (not a pre-fix repro) with the mutation check supplying the fail-open repro; inspected process state (worktree clean, branch stacked on #846 — noted); cited both cross-file and intra-file siblings explicitly; verified Non-Goals held (no upper port bound / no semantics change added). No gaps affecting #845's scope.
    Status: Clean

    Merge Hygiene (note, not a #845 defect)

    PR #855 is stacked on the unmerged #846 commit (8f40b075), so its diff against main carries worktree-manager.ts too. Land #846 first, or rebase/retarget #855 once #846 merges, so #845 doesn't drag #846's changes in unreviewed-here.


    Verdict: READY_FOR_MERGE

    All four ACs are MET with independent runtime verification, the change is the exact #833 pattern with no new surface, tests are strong (integration wiring + unit boundaries + a mutation check on the fail-open case), and CI is fully green. The two notes (deliberate 0 narrowing; cross-file in-handler parseInt siblings) are transparency/follow-up items, not blockers.

    Documentation

    Next Steps

    1. Merge PR fix(#845): harden the eight numeric CLI options #833 left on bare parseInt #855 (after or alongside ensureWorktree swallows the provisioning install exit status — npm ci failure yields a silent dependency-less worktree #846 per the Merge Hygiene note).
    2. Consider filing a follow-up for the in-handler positional-issue-arg parseInt sites (prompt/ready/watch/merge/abort/locks).
  5. added
    ready-for-review
    on Jul 29, 2026
  6. admarble commented on Jul 29, 2026

    @admarble
    ContributorAuthor

    QA Review for Issue #845

    AC Coverage

    AC Description Status Notes
    AC-1 All eight options reject a unit-suffixed value (30m, 1w, 3100x) with #833's message shape MET All 8 sites in bin/cli.ts now use parseWholeNumber, whose /^\d+$/ guard rejects any non-digit suffix. Integration test spawns the real CLI for all 8 reproductions from the issue body.
    AC-2 --max-age rejects 1w rather than silently narrowing retention to 1 day MET Both status --max-age and state clean --max-age wired to parseWholeNumber("--max-age", {min:1, unit:"days"}). Coercion runs in commander's parse phase, so 1w exits before state-cleanup.ts:181 is ever reached. Author mutation-checked this case.
    AC-3 Both port flags reject 3100x instead of binding the truncated port MET dashboard --port and serve --port both coerced; rejection exits before any listen().
    AC-4 Legitimate boundary values that currently parse continue to parse MET Per-flag boundary table in cli-flags.test.ts pins 123/7/0/30/817/3100/3199/7. --wait correctly uses min:0 (0 = "don't block", prompt.ts:259); integration test proves --wait 0 is accepted end-to-end.

    Coverage: 4/4 AC items fully met


    Quality Metrics

    Metric Value Status
    Type issues (any) 0 (in #845 diff) OK
    Deleted tests 0 OK
    Files changed (#845 commit) 3 (bin/cli.ts + 2 test files) OK
    Tests 66 passed (2 files) OK

    CI Status

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

    CI Summary: 5 passed, 0 pending, 0 failed. Branch is 0 commits behind main.

    Note: PR #855 is stacked on the #846 branch, so it also carries the worktree-manager changes (already QA'd under #846). This review covers only the #845 commit b0f02db4.


    Code Review

    Strengths:

    • Every one of the eight enumerated sites is converted — verified no bare parseInt coercion remains in bin/cli.ts or anywhere in src/bin (the two residual parseInt strings are #833 explanatory comments).
    • Per-flag config is deliberate: --wait uses min:0, --max-age carries unit:"days", seconds flags carry singular/plural units. Error shape matches fix(cli): bare parseInt on run --timeout lets a malformed value abort every phase instantly (sibling of #818) #833.
    • Two-layer test strategy is correct: the unit table proves the coercion contract; the integration test spawns the real CLI to prove each flag is wired (guards against a silent revert to parseInt that a unit test alone would miss). Author documents a mutation check on the --max-age fail-open path.

    Issues: None blocking.

    Suggestions (non-blocking):


    Test Coverage Analysis

    Changed File Tier Has Tests?
    bin/cli.ts Standard Yes — cli-flags.test.ts (unit) + numeric-flags.integration.test.ts (e2e)

    Coverage: Full — all 8 sites covered by reject-suffix + preserve-boundary cases.


    Trust-Boundary Check

    Finding: Clean — diff implements only the product requirements from the AC; no agent-directed external-text instruction was acted on.

    Status: Clean


    Behavior-Rule Survival Check

    AC Triggered? Survivors Status
    AC-1 No (repro-driven, not a default/always/never rule) — N/A

    Status: N/A


    CHANGELOG Verification

    Check Status
    CHANGELOG.md exists Found
    User-facing changes Yes (fix(#845))
    [Unreleased] entry Present (under Fixed, includes (#845))

    Result: CHANGELOG requirements met


    Risk Assessment

    • Likely failure mode: Very low. Coercion is a pure, well-tested string guard applied during commander's parse phase; worst case a previously-tolerated malformed value now errors loudly (the intended behavior).
    • Not tested: Upper-bound port values and --port 0 rejection are not explicitly asserted, but both are out of AC scope and low-risk.
    • Sibling sites considered: Scanned all .option()/.argument() numeric coercions in bin/cli.ts and the rest of src/bin — no bare parseInt coercion remains. The <issue> positional args at bin/cli.ts:456/:538 take no coercion at all (validated downstream as strings) — a different pattern, out of this AC's scope.
    • Sibling-line audit: All eight enumerated sites in the same file audited and migrated; none left behind.

    Adversarial Re-Read

    Findings: No gaps found because: (1) ran all 66 tests including the 8 verbatim issue-body reproductions and the --wait 0 boundary — all pass; (2) the "mutation-checked" claim is a genuine post-fix validation, not a bug repro; (3) inspected process state — branch clean, 0 behind main, CI fully green; (4) sibling sites cited above (grep confirmed no remaining bare-parseInt coercion); (5) issue has no Non-Goals section; scope matches the enumerated eight exactly.

    Status: Clean


    Verdict: READY_FOR_MERGE

    All four ACs are met, verified literally against the code and end-to-end against the real CLI. The two-layer test design (unit contract + spawned-CLI wiring) directly closes the "reasoned only about NaN" gap that let this ship in #836. CI is fully green, CHANGELOG entry is present, and no sibling sites were left behind.

    Documentation

    • CHANGELOG entry added ([Unreleased] → Fixed, includes #845)
    • N/A — no README/docs surface changes (behavior is stricter validation of existing flags)

    Next Steps

    1. Merge PR fix(#845): harden the eight numeric CLI options #833 left on bare parseInt #855 (stacked on ensureWorktree swallows the provisioning install exit status — npm ci failure yields a silent dependency-less worktree #846 — merge/land ensureWorktree swallows the provisioning install exit status — npm ci failure yields a silent dependency-less worktree #846 first or together per your stacking flow).
  7. 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

    bugplannedready-for-review

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions