[GH-ISSUE #5110] [Bug] Exhausted CLI failure token windows display a reversed range #3146

Closed
opened 2026-10-31 00:37:10 +00:00 by bsakaguchi · 1 comment
Owner

Originally created by @coygeek on GitHub (Oct 18, 2026).
Original GitHub issue: https://github.com/morluto/rea/issues/5110

Before submitting

  • I searched the open and closed issues for a related report.
  • I removed credentials, tokens, private paths, and sensitive target data.

Area

CLI

Observed behavior

With --format toon --full-output --token-offset 100000, the production evidence-import command registration and CLI output boundary return an empty selected error text followed by showing tokens 100000–100 of 100. The displayed start exceeds both the end and total. Adding --token-limit 3 produces the same reversed range. Both retain ok: false, exit status 1 and no nextOffset.

This was executed through source command registration and the production formatter, with a real missing local file and no provider mocks. The packaged executable was not run.

Reproduction

In a checkout of the source revision below with locked dependencies installed, create an empty scratch directory $WORK and save this as $WORK/repro.mts:

import { Writable } from 'node:stream';
import { resolve, dirname } from 'node:path';
import { pathToFileURL, fileURLToPath } from 'node:url';
const root = resolve(process.argv[2]);
const load = (p: string) => import(pathToFileURL(resolve(root, p)).href);
const { Cli } = await load('node_modules/incur/dist/index.js');
const { registerEvidenceCommands } = await load('src/cliEvidenceCommands.ts');
const { silentLogger } = await load('src/logger.ts');
const { createCliResultOutput, streamCliCommandResults } =
  await load('src/cli/cliResultOutput.ts');
process.chdir(dirname(fileURLToPath(import.meta.url)));
const args = ['evidence-import', 'missing-bundle.json', '--format', 'toon',
  '--full-output', '--token-offset', '100000'];
let text = '';
const destination = new Writable({write(chunk, _, done) {
  text += chunk.toString(); done();
}});
const output = createCliResultOutput(args, destination);
const cli = Cli.create('rea-repro', {sync: false});
registerEvidenceCommands(cli, silentLogger);
streamCliCommandResults(cli, output);
await cli.serve(args, {stdout: () => undefined});
console.log(text);
console.log('exitCode:', process.exitCode);

From the checkout root, run:

mkdir -p "$WORK/home" "$WORK/config"
env -i PATH="$PATH" HOME="$WORK/home" XDG_CONFIG_HOME="$WORK/config" \
  node --import tsx "$WORK/repro.mts" "$PWD"

Ensure $WORK/missing-bundle.json does not exist. The script exits 1 because the import fails. The exact end/total token count depends on the scratch path embedded in the diagnostic. The executed run printed 100000–100 of 100.

Also executed: add --token-limit 3 to the arguments, and compare with offset 0/limit 3 and with no token controls. Only the two beyond-end cases displayed a reversed range.

Expected behavior

For an accepted exhausted token window, display an empty range whose start does not exceed its end or total, or return a clear out-of-range error. The displayed coordinates should describe the selected text accurately. The existing token-window regression associates the displayed end with the next offset; CLI documentation advertises token controls and preserves operation status.

Impact and scope

Incorrect display text for beyond-end offsets on full-output TOON failures. The underlying missing-file failure still returns exit 1 and ok: false; exhausted pages have no next offset. No data loss or downstream consumer failure was observed. Removing token-window controls returned the complete diagnostic in the control run.

NOT_ENOUGH_INFO: production frequency and behavior of downstream paging clients are unknown.

REA version

Source revision 3537e58c1ab29309f06eabf50bc52adba9817a0c, package version 6.7.0.

Runtime and platform

Node.js v26.12.0; macOS 27.0.1; darwin arm64. No optional analysis provider was invoked.

Target and artifact context

A nonexistent local Evidence bundle JSON file in an empty scratch directory.

Interface

CLI

Earliest failure stage

Transport or result projection

Relevant output or evidence

Observed source command-registration/output-boundary output:

ok: false
error: "\n[truncated: showing tokens 100000–100 of 100]"
meta:
  command: evidence-import
  duration: 4ms

exitCode: 1

The no-window control returned code: invalid_request, category: invalid_input and the missing-file diagnostic. Offset 0/limit 3 returned showing tokens 0–3 of 100 and nextOffset: 3.

Command registration, accepted numeric controls, format validation, and failure window calculation establish the supported caller path.

Typed outcome or recovery expected

Retain the underlying failure status while describing the exhausted selection accurately. No next offset is needed when the window is exhausted.

Analysis or suspected cause

Source-derived: fullFailureEnvelope clamps the upper coordinate to the total but prints the original requested offset as the lower coordinate. The source CLI validator accepts finite offsets with TOON, so this branch is reachable through the supported command output path.

Additional context

The relevant command-registration, CLI and output source files have no differences between the rea-agents-6.7.0 tag and the tested main revision. The stable packaged runtime was not executed. NOT_ENOUGH_INFO: first affected release and last known good revision.

Related closed issues #2273 and #2673 concern envelope selection, rather than reversed token coordinates.

Originally created by @coygeek on GitHub (Oct 18, 2026). Original GitHub issue: https://github.com/morluto/rea/issues/5110 ## Before submitting - [x] I searched the open and closed issues for a related report. - [x] I removed credentials, tokens, private paths, and sensitive target data. ## Area CLI ## Observed behavior With `--format toon --full-output --token-offset 100000`, the production `evidence-import` command registration and CLI output boundary return an empty selected error text followed by `showing tokens 100000–100 of 100`. The displayed start exceeds both the end and total. Adding `--token-limit 3` produces the same reversed range. Both retain `ok: false`, exit status 1 and no `nextOffset`. This was executed through source command registration and the production formatter, with a real missing local file and no provider mocks. The packaged executable was not run. ## Reproduction In a checkout of the source revision below with locked dependencies installed, create an empty scratch directory `$WORK` and save this as `$WORK/repro.mts`: ```ts import { Writable } from 'node:stream'; import { resolve, dirname } from 'node:path'; import { pathToFileURL, fileURLToPath } from 'node:url'; const root = resolve(process.argv[2]); const load = (p: string) => import(pathToFileURL(resolve(root, p)).href); const { Cli } = await load('node_modules/incur/dist/index.js'); const { registerEvidenceCommands } = await load('src/cliEvidenceCommands.ts'); const { silentLogger } = await load('src/logger.ts'); const { createCliResultOutput, streamCliCommandResults } = await load('src/cli/cliResultOutput.ts'); process.chdir(dirname(fileURLToPath(import.meta.url))); const args = ['evidence-import', 'missing-bundle.json', '--format', 'toon', '--full-output', '--token-offset', '100000']; let text = ''; const destination = new Writable({write(chunk, _, done) { text += chunk.toString(); done(); }}); const output = createCliResultOutput(args, destination); const cli = Cli.create('rea-repro', {sync: false}); registerEvidenceCommands(cli, silentLogger); streamCliCommandResults(cli, output); await cli.serve(args, {stdout: () => undefined}); console.log(text); console.log('exitCode:', process.exitCode); ``` From the checkout root, run: ```sh mkdir -p "$WORK/home" "$WORK/config" env -i PATH="$PATH" HOME="$WORK/home" XDG_CONFIG_HOME="$WORK/config" \ node --import tsx "$WORK/repro.mts" "$PWD" ``` Ensure `$WORK/missing-bundle.json` does not exist. The script exits 1 because the import fails. The exact end/total token count depends on the scratch path embedded in the diagnostic. The executed run printed `100000–100 of 100`. Also executed: add `--token-limit 3` to the arguments, and compare with offset 0/limit 3 and with no token controls. Only the two beyond-end cases displayed a reversed range. ## Expected behavior For an accepted exhausted token window, display an empty range whose start does not exceed its end or total, or return a clear out-of-range error. The displayed coordinates should describe the selected text accurately. The existing [token-window regression](https://github.com/morluto/rea/blob/3537e58c1ab29309f06eabf50bc52adba9817a0c/tests/boundary/cli/jsonOutput.test.ts#L299-L340) associates the displayed end with the next offset; [CLI documentation](https://github.com/morluto/rea/blob/3537e58c1ab29309f06eabf50bc52adba9817a0c/docs/cli.md#L323-L329) advertises token controls and preserves operation status. ## Impact and scope Incorrect display text for beyond-end offsets on full-output TOON failures. The underlying missing-file failure still returns exit 1 and `ok: false`; exhausted pages have no next offset. No data loss or downstream consumer failure was observed. Removing token-window controls returned the complete diagnostic in the control run. NOT_ENOUGH_INFO: production frequency and behavior of downstream paging clients are unknown. ## REA version Source revision `3537e58c1ab29309f06eabf50bc52adba9817a0c`, package version 6.7.0. ## Runtime and platform Node.js v26.12.0; macOS 27.0.1; darwin arm64. No optional analysis provider was invoked. ## Target and artifact context A nonexistent local Evidence bundle JSON file in an empty scratch directory. ## Interface CLI ## Earliest failure stage Transport or result projection ## Relevant output or evidence Observed source command-registration/output-boundary output: ```text ok: false error: "\n[truncated: showing tokens 100000–100 of 100]" meta: command: evidence-import duration: 4ms exitCode: 1 ``` The no-window control returned `code: invalid_request`, `category: invalid_input` and the missing-file diagnostic. Offset 0/limit 3 returned `showing tokens 0–3 of 100` and `nextOffset: 3`. [Command registration](https://github.com/morluto/rea/blob/3537e58c1ab29309f06eabf50bc52adba9817a0c/src/cliEvidenceCommands.ts#L20-L29), [accepted numeric controls](https://github.com/morluto/rea/blob/3537e58c1ab29309f06eabf50bc52adba9817a0c/src/cliOutput.ts#L131-L140), [format validation](https://github.com/morluto/rea/blob/3537e58c1ab29309f06eabf50bc52adba9817a0c/src/cliOutput.ts#L182-L201), and [failure window calculation](https://github.com/morluto/rea/blob/3537e58c1ab29309f06eabf50bc52adba9817a0c/src/cli/cliResultOutput.ts#L353-L373) establish the supported caller path. ## Typed outcome or recovery expected Retain the underlying failure status while describing the exhausted selection accurately. No next offset is needed when the window is exhausted. ## Analysis or suspected cause Source-derived: `fullFailureEnvelope` clamps the upper coordinate to the total but prints the original requested offset as the lower coordinate. The source CLI validator accepts finite offsets with TOON, so this branch is reachable through the supported command output path. ## Additional context The relevant command-registration, CLI and output source files have no differences between the `rea-agents-6.7.0` tag and the tested main revision. The stable packaged runtime was not executed. NOT_ENOUGH_INFO: first affected release and last known good revision. Related closed issues [#2273](https://github.com/morluto/rea/issues/2273) and [#2673](https://github.com/morluto/rea/issues/2673) concern envelope selection, rather than reversed token coordinates.
Author
Owner

@XinwangTao commented on GitHub (Oct 19, 2026):

Confirmed: when the failure window start exceeds the token total, the CLI prints an empty selection plus a reversed range (100000–100), which is actively misleading for debugging — the user can't tell whether the window logic or the offset input is wrong.

Clamping the start to the token total as PR #5119 does is correct, but I'd suggest centralizing the clamp so every token-window renderer (failure window, normal output, summary) shares one helper — this is the second paging/range boundary bug in this batch of reports, and a single clamp helper with a unit test for start > total would prevent the class rather than the instance.

<!-- gh-comment-id:6260149845 --> @XinwangTao commented on GitHub (Oct 19, 2026): Confirmed: when the failure window start exceeds the token total, the CLI prints an empty selection plus a reversed range (100000–100), which is actively misleading for debugging — the user can't tell whether the window logic or the offset input is wrong. Clamping the start to the token total as PR #5119 does is correct, but I'd suggest centralizing the clamp so every token-window renderer (failure window, normal output, summary) shares one helper — this is the second paging/range boundary bug in this batch of reports, and a single clamp helper with a unit test for start > total would prevent the class rather than the instance.
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#3146
No description provided.