Skip to content

fix(cli): reject negative and fractional token window values - #5578

Closed
Som0111 wants to merge 3 commits into
morluto:mainfrom
Som0111:fix/invalid-token-window-values
Closed

Som0111 wants to merge 3 commits into
morluto:mainfrom
Som0111:fix/invalid-token-window-values

Conversation

@Som0111

@Som0111 Som0111 commented Oct 20, 2026 •

Copy link
Copy Markdown

Summary

--token-limit and --token-offset accepted negative and fractional values, producing negative nextOffset in failure envelopes (breaking paging callers) and fractional display markers like "tokens 2.5–7.5 of 518".

Fixes #5532

Problem and expected behavior

Trigger: inspect-plist --token-limit -5 or --token-offset 2.5

Violated invariant: Token window bounds must be non-negative integers. Negative limits caused Math.min(end, total) to preserve a negative end, making nextOffset negative. Fractional values produced fractional display markers.

Expected: A clear INVALID_TOKEN_VALUE error naming the offending flag. Zero remains valid as an empty window. Non-numeric input (e.g. abc) is still left to Incur to report.

Change and scope

Added invalidTokenValue tracking to parseCliOutputArguments. After the existing Number.isFinite guard, values that fail Number.isInteger(v) && v >= 0 are recorded as invalid. validateCliOutputArguments checks this and returns a new INVALID_TOKEN_VALUE error before any other validation. No changes to fullFailureEnvelope — invalid values never reach it.

Contribution scope: not applicable (input validation fix within existing CLI output boundary).

Contract and boundary impact

  • Semantic owner and earliest changed stage: CLI output argument parsing (src/cliOutput.ts)
  • Contribution scope fit and linked maintainer decision: not applicable
  • CLI and MCP/tool-catalog contract: new INVALID_TOKEN_VALUE error code added to CliOutputArgumentValidation; existing valid integer inputs are unaffected
  • Provider, bridge, target-format, or platform compatibility: none
  • Evidence, artifact, provenance, or reconstruction contract: none
  • Target selection, authority, upstream behavior, and cleanup details: not applicable
  • Generated metadata impact: none

Expected effects:

  • Read existing files or captured data.
  • Launch or attach to a process.
  • Inject instrumentation or run scripts/code.
  • Change process memory, registers, files, or configuration.
  • Contact network services.
  • Recover protected code or work around protections.
  • Documentation or usability only; no target interaction.
  • Not sure yet; investigation or maintainer guidance needed.

Evidence and regression coverage

  • Tests added: 17 new tests in src/cliOutput.test.ts covering valid integers, zero, negative limit/offset, fractional limit/offset, multi-flag combinations, format propagation, and precedence over UNSUPPORTED_OUTPUT_COMBINATION

  • Base reproduction: parseCliOutputArguments(["--token-limit", "-5"]) previously set tokenLimit = -5; now sets invalidTokenValue = "--token-limit" and leaves tokenLimit undefined

  • User-visible CLI output: {"ok":false,"error":{"code":"INVALID_TOKEN_VALUE","message":"--token-limit requires a non-negative integer (0, 1, 2, …)."}}

  • Remaining proof gaps: not tested against a live inspect-plist invocation

  • Observed, derived, and inferred claims remain distinguishable.

  • Artifact identity, source provenance, and failed attempts remain preserved.

  • Unsupported, incomplete, unavailable, or uncertain outcomes remain visible.

Validation performed

  • npm run test:local -- src/cliOutput.test.ts — 17 of 17 passed
  • npm run check:fast — typecheck and lint passed (2 of 2 tasks)

Compatibility, safety, and release

  • Breaking changes: none — new error code is additive; previously invalid inputs were silently mishandled
  • Real Hopper/Ghidra, browser, or OS coverage: not applicable
  • Package or release metadata impact: none
  • Security, privacy, process, or containment review: none

Author readiness

Human owner: @Som0111

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work.
  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.
  • I declare this PR ready for initial maintainer review.

Before merge

  • This PR addresses a concrete problem or an agreed enhancement.
  • Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff.
  • The PR has one focused outcome and the title follows type(scope): outcome.
  • Related issue is linked, or the reason for not linking one is stated above.
  • Tests cover changed observable behavior and meaningful failure paths.
  • Owning docs, contracts, and generated metadata are updated where needed.
  • User-visible CLI/MCP changes include representative output.
  • I checked the final diff for secrets, unrelated cleanup, and unsupported claims.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-10-20T15:10:57.894292Z 66ecd3b PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@greptile-apps

greptile-apps Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; the previous test placement issue is fixed.

Summary

The PR rejects negative and fractional token-window values with INVALID_TOKEN_VALUE. The latest change moves the four executable checks into the CLI boundary suite.

  • CLI token windows now accept only whole, non-negative bounds.

Reviews (3) · Last reviewed commit: "fix(cli): reject negative and fractional..." · Reviewed by Greptile

Comment thread src/cliOutput.test.ts Resolved
Comment thread src/cliOutput.test.ts Resolved
@matbrgz

matbrgz commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

Heads-up: Note that PR #5544 (fix(cli): reject invalid token-window bounds) was opened earlier by @chqcjq to address the same issue #5532. Cross-referencing to coordinate review with @morluto and avoid duplicate merge efforts.

@CassieFox23

Copy link
Copy Markdown
Contributor

TL;DR: The fix works on Linux. Negative and fractional token window values now stop with a clear INVALID_TOKEN_VALUE error, and zero still works. The new tests fail without the fix, and both bot threads are answered at this head.

Thanks, Som0111, for the fix. Thanks, coygeek, for the clear report in #5532. I tested head 1ab5663 on Linux.

Check Node 22.23.1 Node 24.18.0 Node 26.11.1
src/cliOutput.test.ts and tests/boundary/cli/cliOutput.test.ts on the head 59 passed 59 passed 59 passed
Same files with src/cliOutput.ts put back to its pre-PR version not run 16 failed, 43 passed not run

The 16 failures are your new tests: 12 helper tests and your 4 command-line cases. The 43 older tests still pass.

Does it fix #5532? Yes, in the "reject clearly" way the issue allows. I ran the built CLI with inspect-plist:

Arguments Before the fix With the fix (1ab5663)
missing file, --token-limit -5 footer "tokens 0–-5 of 219" INVALID_TOKEN_VALUE, exit 1
--token-offset 2.5 --token-limit 5 footer "tokens 2.5–7.5 of 100" INVALID_TOKEN_VALUE for --token-offset, exit 1
--token-offset -100 --token-limit 20 footer "tokens -100–-80 of 100" INVALID_TOKEN_VALUE for --token-offset, exit 1
--token-limit -5, --token-limit=-5, --token-limit 2.5 not run INVALID_TOKEN_VALUE, exit 1
--token-limit 5, --token-limit 0 not run accepted, footers "tokens 0–5 of 100" and "0–0 of 100"

The "before" rows use a copy of the head with only src/cliOutput.ts reverted.

Bot threads at this head:

Thread Finding Result
P2, CLI error path lacks coverage no test sends a bad value through the CLI Fixed. Four CLI cases now exist, and all four fail without the fix.
P1, source tests need a build the CLI cases sat in a test that has no built runtime Fixed. The CLI cases are in tests/boundary/cli/, and src/cliOutput.test.ts has 17 helper tests and no CLI calls. I did not re-run the failure on the earlier push.

Not run

Test setup
  • Box: Nobara 44 (Fedora 44 base), Linux 7.2.11
  • CPU: AMD Ryzen 9 5900X, 12 cores / 24 threads
  • RAM: 32 GB DDR4-3600
  • Node: 22.23.1, 24.18.0, 26.11.1
  • Head / base: 1ab5663 / e52a716
  • Other: the box was shared with other test jobs. The probe file was a small plist I wrote myself.
Commands
npm ci --ignore-scripts
npm run build:cached
npm run test:prepare
npm run test:focused -- src/cliOutput.test.ts tests/boundary/cli/cliOutput.test.ts
node scripts/rea.mjs inspect-plist <plist> --token-limit -5

Install, build and test:prepare ran on Node 24, exit 0 each. The two test files ran once per Node version on the head, exit 0 each. The no-fix copy ran on Node 24 only, exit 1. The CLI probes ran with HOME and the XDG folders pointed at a temp folder.

🤖 Generated with Claude Code (Sonnet 5.5, verified by Opus 5.5) 🦊

@morluto

morluto commented Oct 25, 2026

Copy link
Copy Markdown
Owner

Source-derived replacement: pinned main commit 4ed33ef validates --token-limit and --token-offset as nonnegative safe integers before dispatch in src/cliOutput.ts#L54-L70, so negative and fractional windows are rejected. tests/boundary/cli/cliOutput.test.ts#L80-L117 covers invalid negative/fractional values for both flags. Main reports the current generic INVALID_OUTPUT_VALUE contract; the requested rejection behavior and coverage are present.

@morluto morluto closed this Oct 25, 2026
@morluto morluto added area: cli CLI adapter and one-shot commands bug Something isn't working labels Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: cli CLI adapter and one-shot commands bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Negative and fractional token-window values produce inconsistent pages

4 participants