[PR #5578] [CLOSED] fix(cli): reject negative and fractional token window values #6976

Closed
opened 2026-11-01 21:44:26 +00:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/morluto/rea/pull/5578
Author: @Som0111
Created: 10/20/2026
Status: ❌ Closed

Base: main ← Head: fix/invalid-token-window-values


📝 Commits (3)

  • 66ecd3b fix(cli): reject negative and fractional token window valuesFixes #5532
  • 7680f78 fix(cli): reject negative and fractional token window valuesFixes #5532
  • 1ab5663 fix(cli): reject negative and fractional token window values

📊 Changes

3 files changed (+223 additions, -4 deletions)

View changed files

➕ src/cliOutput.test.ts (+176 -0)
📝 src/cliOutput.ts (+26 -4)
📝 tests/boundary/cli/cliOutput.test.ts (+21 -0)

📄 Description

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.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/morluto/rea/pull/5578 **Author:** [@Som0111](https://github.com/Som0111) **Created:** 10/20/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/invalid-token-window-values` --- ### 📝 Commits (3) - [`66ecd3b`](https://github.com/morluto/rea/commit/66ecd3b8431756b82a02deadcea908d650495124) fix(cli): reject negative and fractional token window valuesFixes #5532 - [`7680f78`](https://github.com/morluto/rea/commit/7680f782c7b3cd92ccab860e222d608eefaa8b21) fix(cli): reject negative and fractional token window valuesFixes #5532 - [`1ab5663`](https://github.com/morluto/rea/commit/1ab5663b79665f4501793214ebab37a919c679c8) fix(cli): reject negative and fractional token window values ### 📊 Changes **3 files changed** (+223 additions, -4 deletions) <details> <summary>View changed files</summary> ➕ `src/cliOutput.test.ts` (+176 -0) 📝 `src/cliOutput.ts` (+26 -4) 📝 `tests/boundary/cli/cliOutput.test.ts` (+21 -0) </details> ### 📄 Description ## 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: - [x] 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 - [x] Observed, derived, and inferred claims remain distinguishable. - [x] Artifact identity, source provenance, and failed attempts remain preserved. - [x] 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 - [x] 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. - [x] I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps. - [x] I declare this PR ready for initial maintainer review. ## Before merge - [x] This PR addresses a concrete problem or an agreed enhancement. - [x] Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff. - [x] The PR has one focused outcome and the title follows `type(scope): outcome`. - [x] Related issue is linked, or the reason for not linking one is stated above. - [x] Tests cover changed observable behavior and meaningful failure paths. - [x] Owning docs, contracts, and generated metadata are updated where needed. - [x] User-visible CLI/MCP changes include representative output. - [x] I checked the final diff for secrets, unrelated cleanup, and unsupported claims. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-01 21:44:26 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
morluto/rea#6976
No description provided.