[PR #5208] [CLOSED] fix(cli): clamp failure token windows past the available range #6814

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

📋 Pull Request Information

Original PR: https://github.com/morluto/rea/pull/5208
Author: @abundantbeing
Created: 10/19/2026
Status: ❌ Closed

Base: main ← Head: fix/cli-failure-token-window


📝 Commits (1)

  • 2f7b122 fix(cli): clamp failure token windows past the available range

📊 Changes

2 files changed (+31 additions, -1 deletions)

View changed files

📝 src/cli/cliResultOutput.ts (+3 -1)
📝 tests/boundary/cli/cliOutput.test.ts (+28 -0)

📄 Description

Summary

Fixes #5110. A full-output failure window whose --token-offset is past the
available token count reported a reversed range, for example
showing tokens 100000–91 of 91, with an empty selection.

Problem and expected behavior

node scripts/rea.mjs evidence-import missing.json --format toon --full-output --token-offset 100000

On main this prints [truncated: showing tokens 100000–91 of 91]; adding
--token-limit 3 prints the same reversed range. The start exceeds both the
end and the total, so callers cannot tell where the window actually lands.

Expected: a window past the end reports a valid empty range within the total,
never a start greater than the end or the total.

Change and scope

fullFailureEnvelope in src/cli/cliResultOutput.ts now clamps the requested
start to the available token count before computing the end. A start beyond the
last token becomes an empty range at the end (93–93 of 93) with no
nextOffset, matching the existing window contract.

Intentionally not included: token counting, successful-result windows, and the
--token-limit/--token-offset parsing rules.

Contract and boundary impact

  • Semantic owner and earliest changed stage: CLI result-output boundary;
    fullFailureEnvelope owns the failure token window and its displayed range.
  • Contribution scope fit and linked maintainer decision: ordinary fix within an
    existing boundary; no target execution, injection, mutation, or protection
    recovery. Maintainer scope decision not applicable.
  • CLI and MCP/tool-catalog contract: no new or changed flags; only the displayed
    range for an out-of-range offset is corrected.
  • Provider, bridge, target-format, or platform compatibility: not applicable.
  • Evidence, artifact, provenance, or reconstruction contract: not applicable;
    failure text and meta.nextOffset semantics are unchanged for in-range windows.
  • Target selection, authority, upstream behavior, and cleanup details: not
    applicable; the formatter reads no target.
  • Generated metadata, package, or installation impact: none.

Expected effects (check known effects; use documentation-only on its own).
Unchecked items do not establish absence; leave uncertainties visible.

  • 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 or updated: tests/boundary/cli/cliOutput.test.ts adds CLI failure token windows, covering offsets past the end with and without
    --token-limit.
  • Base reproduction or other evidence: on origin/main (3927542), the command
    above printed showing tokens 100000–91 of 91. With this change it prints
    showing tokens 93–93 of 93, exit code 1, ok: false, no nextOffset.
  • User-visible CLI/MCP output (if applicable): [truncated: showing tokens 93–93 of 93] for the reproduction command.
  • Remaining proof gaps: the packaged executable was not run, and the regression
    exercises the TOON failure path only.

For evidence-bearing changes:

  • 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

  • node scripts/rea.mjs evidence-import missing.json --format toon --full-output --token-offset 100000 — prints a non-reversed empty range; exit 1.
  • npx vitest run tests/boundary/cli/cliOutput.test.ts — 38 passed, including the new regression. One pre-existing test (emits valid JSON when an output filter misses the top-level result) also fails on clean origin/main on this Windows host.
  • npm run check:fast — typecheck and lint passed.
  • npx oxfmt --check . — passed.

Compatibility, safety, and release

  • Breaking changes or migration steps: none. The displayed range for in-range
    windows and nextOffset behavior are unchanged.
  • Real Hopper/Ghidra, browser, or OS coverage: not applicable.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: output formatting only; no
    new input, authority, network, or file access.

Author readiness

Human owner: @abundantbeing

  • 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/5208 **Author:** [@abundantbeing](https://github.com/abundantbeing) **Created:** 10/19/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/cli-failure-token-window` --- ### 📝 Commits (1) - [`2f7b122`](https://github.com/morluto/rea/commit/2f7b122b4ea07294bd40448b4fe24df6e05be8b2) fix(cli): clamp failure token windows past the available range ### 📊 Changes **2 files changed** (+31 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `src/cli/cliResultOutput.ts` (+3 -1) 📝 `tests/boundary/cli/cliOutput.test.ts` (+28 -0) </details> ### 📄 Description ## Summary Fixes #5110. A full-output failure window whose `--token-offset` is past the available token count reported a reversed range, for example `showing tokens 100000–91 of 91`, with an empty selection. ## Problem and expected behavior ```sh node scripts/rea.mjs evidence-import missing.json --format toon --full-output --token-offset 100000 ``` On `main` this prints `[truncated: showing tokens 100000–91 of 91]`; adding `--token-limit 3` prints the same reversed range. The start exceeds both the end and the total, so callers cannot tell where the window actually lands. Expected: a window past the end reports a valid empty range within the total, never a start greater than the end or the total. ## Change and scope `fullFailureEnvelope` in `src/cli/cliResultOutput.ts` now clamps the requested start to the available token count before computing the end. A start beyond the last token becomes an empty range at the end (`93–93 of 93`) with no `nextOffset`, matching the existing window contract. Intentionally not included: token counting, successful-result windows, and the `--token-limit`/`--token-offset` parsing rules. ## Contract and boundary impact - Semantic owner and earliest changed stage: CLI result-output boundary; `fullFailureEnvelope` owns the failure token window and its displayed range. - Contribution scope fit and linked maintainer decision: ordinary fix within an existing boundary; no target execution, injection, mutation, or protection recovery. Maintainer scope decision not applicable. - CLI and MCP/tool-catalog contract: no new or changed flags; only the displayed range for an out-of-range offset is corrected. - Provider, bridge, target-format, or platform compatibility: not applicable. - Evidence, artifact, provenance, or reconstruction contract: not applicable; failure text and `meta.nextOffset` semantics are unchanged for in-range windows. - Target selection, authority, upstream behavior, and cleanup details: not applicable; the formatter reads no target. - Generated metadata, package, or installation impact: none. Expected effects (check known effects; use documentation-only on its own). Unchecked items do not establish absence; leave uncertainties visible. - [ ] 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. - [x] Documentation or usability only; no target interaction. - [ ] Not sure yet; investigation or maintainer guidance needed. ## Evidence and regression coverage - Tests added or updated: `tests/boundary/cli/cliOutput.test.ts` adds `CLI failure token windows`, covering offsets past the end with and without `--token-limit`. - Base reproduction or other evidence: on `origin/main` (3927542), the command above printed `showing tokens 100000–91 of 91`. With this change it prints `showing tokens 93–93 of 93`, exit code 1, `ok: false`, no `nextOffset`. - User-visible CLI/MCP output (if applicable): `[truncated: showing tokens 93–93 of 93]` for the reproduction command. - Remaining proof gaps: the packaged executable was not run, and the regression exercises the TOON failure path only. For evidence-bearing changes: - [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 - `node scripts/rea.mjs evidence-import missing.json --format toon --full-output --token-offset 100000` — prints a non-reversed empty range; exit 1. - `npx vitest run tests/boundary/cli/cliOutput.test.ts` — 38 passed, including the new regression. One pre-existing test (`emits valid JSON when an output filter misses the top-level result`) also fails on clean `origin/main` on this Windows host. - `npm run check:fast` — typecheck and lint passed. - `npx oxfmt --check .` — passed. ## Compatibility, safety, and release - Breaking changes or migration steps: none. The displayed range for in-range windows and `nextOffset` behavior are unchanged. - Real Hopper/Ghidra, browser, or OS coverage: not applicable. - Package or release metadata impact: none. - Security, privacy, process, or containment review: output formatting only; no new input, authority, network, or file access. ## Author readiness Human owner: @abundantbeing - [ ] 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. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-01 21:43:12 +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#6814
No description provided.