Skip to content

fix(cli): deliver complete TOON beyond the string limit - #12074

Merged
morluto merged 6 commits into
morluto:mainfrom
ShuaixinHuang:fix/cli-stream-complete-toon
Nov 19, 2026
Merged

morluto merged 6 commits into
morluto:mainfrom
ShuaixinHuang:fix/cli-stream-complete-toon

Conversation

@ShuaixinHuang

@ShuaixinHuang ShuaixinHuang commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Deliver complete default TOON results beyond Node's single-string limit, while retaining private staging through interruption and cleanup failure. Resolves #12071.

The old CLI joined all encoded lines into one string. A 536,961,045-byte ASCII document raises RangeError: Invalid string length on Node 24.22.1 even though each row fits.

Fix

  • Use the installed TOON line iterator, keeping small documents in memory and completing large documents in a private stage before publishing stdout. Preserve ordinary bytes/newlines and existing backpressure handling.
  • Allocate stages through PrivateRuntimeRoot, including its Windows native DACL authority; refuse if privacy cannot be established. One retryable lease closes the exact descriptor before its root. Failed stages remain owned by CLI shutdown, and cleanup labels follow actual release.
  • Keep the existing signal owner through allocation, staging, delivery and final cleanup. Use the shared cancelledBy factory for the original caller reason; a weak sidecar records only this output owner's 130/143 disposition. Settle admitted I/O before stopping further writes; early iterator return leaves descriptor close to its owner. No replacement document is appended.
  • Preserve original capacity failures, publication receipts and JSON guidance alongside incomplete cleanup. Move acceptance fault injection to both encoder entrypoints, and race controlled phase acknowledgements against child settlement using the repository helper.

Addresses the verified cleanup, capacity-hook, cancellation, Windows privacy controlled-wait and canonical cancellation factory findings. No new provider, dependency, option or target execution.

Executed validation

Base: main f7849cad; final qualification: 1000e9d4. Affected TOON sources and contribution rules were also checked against refreshed main b236bcfe without relevant changes.

  • Before fixes: original ownership regressions 6 failed / 4 passed against 63459ee0; cancellation/private-root regressions 7 failed / 6 passed and capacity acceptance 7 failed / 16 passed against faf2aa34.
  • After fixes: 325 tests passed in 19 files. Six real compiled-CLI children cover SIGINT/SIGTERM during stage writes, slow stdout and final cleanup, checking 130/143, prefix bounds, removal and no second document. Final acknowledgement fixture: six cases passed again; forcing real children to exit before the marker makes all six fail through operation settlement rather than the gate deadline.
  • Repeated the actual large witness: old encode() throws; the CLI result writer delivers 536,961,045 bytes in 8,194 writes. SHA-256 4daa6decb73ebf848d02bfdfcbe10a207c32002804525b6d083a805c4424c627 matches independent header/row calculation; stage removed. Used private Linux tmpfs because workspace storage was insufficient.
  • Passed serial Turbo typecheck/lint/format:check/Knip/metadata, architecture guards, production reachability, npm run docs:check and npm run verify:test-discovery. Normal commit/pre-push hooks passed; reviewed-file hashes verified.
  • Repeated full type-aware lint after the final production edit: 7,722 files, zero errors, four nonoverlapping serial batches with the same inventory/rules within 8 GiB; every source hash unchanged. All required check components ran; the unmodified single-process npm run check command was not run.

Hosted verification

CI for 1000e9d4 passed: 15 jobs succeeded / 24 skipped, testing merge bfb0d905 against main b236bcfe. The affected-test shards passed 2,109 tests in 84 files, with 2 skipped, including the new TOON capacity/cancellation/cleanup cases. Clean-runner npm run verify:package, real Node Inspector discovery/observation, runtime compatibility and Portable tests passed. The earlier unrelated main fixture failure was repaired by #12088 before this qualification.

Greptile reviewed all 10 changed files with 0 new comments; all six verified review threads are resolved. Main retired the automated PR readiness workflow in #12095 (b60836a1); earlier declaration-check failures are historical records. The Author readiness section below is preserved verbatim from the remote PR. This status update changes neither source code nor declarations.

Limits

Linux, Node 24.22.1/npm 11.16.0; no actual Windows/Darwin runtime or full local deterministic suite. Windows authority tests mock the native boundary; filesystem denials do not establish real failing-device behavior. Cancellation awaits admitted I/O and can leave an already delivered prefix. Temporary space scales with output; individual lines and token presentations remain string-limited. --format json avoids TOON staging.

Focused regression command
npm run test:focused -- \
  tests/boundary/filesystem/toonOutputCleanup.test.ts \
  tests/boundary/filesystem/toonOutput.test.ts \
  tests/boundary/cli/cliOutputFormatter.test.ts \
  tests/boundary/cli/cliTokenWindowOutput.test.ts \
  tests/boundary/cli/cliFullOutputTokenCount.test.ts \
  tests/boundary/cli/filteredFailureOutput.test.ts \
  tests/boundary/cli/filteredArrayOutput.test.ts \
  tests/boundary/cli/jsonOutput.test.ts \
  tests/boundary/cli/cliOutput.test.ts \
  tests/boundary/filesystem/jsonOutputOwnership.test.ts \
  tests/boundary/filesystem/jsonOutputResourceFailure.test.ts \
  tests/boundary/cli/evidenceOutputPublicationCli.test.ts \
  tests/acceptance/cliFormattingCapacity.test.ts \
  tests/acceptance/cliToonCancellation.test.ts \
  tests/boundary/cli/androidCliCancellation.test.ts \
  tests/boundary/cli/wasmLateCancellationCli.test.ts \
  tests/process-global/commandFinalizationCancellation.test.ts \
  tests/process-global/oneShotSourceClosure.test.ts \
  src/windows/WindowsPrivateRuntime.test.ts

Maintainer recheck on refreshed main: 40 TOON staging, cleanup, capacity and cancellation tests passed. The guide now describes the encoded-output buffering limit separately from the encoder's full-tree normalization. The existing Author readiness declaration is preserved.

Author readiness

Human owner: @ShuaixinHuang

  • 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.

@greptile-apps

greptile-apps Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5 Tier: plus

[Medium impact] The PR appears safe to merge; no new blocking issues were found.

Summary

Large default TOON results now avoid one document-sized string by finishing encoding in memory or a private temporary file before delivery.

  • Large TOON results are staged privately before the CLI publishes them.
  • Interrupts keep the CLI's signal owner through staged output cleanup.

No new actionable issues found. The four supplied earlier findings are addressed in the current code. The target branch still uses whole-string TOON output, so this fix is not superseded there. Tests were not rerun because dependencies are not installed.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Result] --> B[Encode TOON lines]
  B --> C{Fits in memory?}
  C -->|Yes| D[Deliver completed output]
  C -->|No| E[Allocate private stage]
  E --> F[Finish encoding into stage]
  F --> D
  D --> G[Close file, then remove root]
  G -->|Cleanup fails| H[Keep owner for shutdown retry]
  H --> G
Loading

Reviews (6) · Last reviewed commit: "docs(cli): clarify TOON encoding memory ..." · Reviewed by Greptile

Comment thread src/cli/toonOutput.ts Resolved
@ShuaixinHuang
ShuaixinHuang marked this pull request as ready for review November 18, 2026 17:29
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-19T01:20:17.560169Z ed67b41 New commits
ℹ️ 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.

Comment thread src/cli/toonOutput.ts Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: faf2aa34aa

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/cli/toonOutput.ts Resolved
Comment thread src/cli/toonOutput.ts Resolved
Comment thread src/cli/toonOutput.ts Resolved
@morluto
morluto merged commit f10d557 into morluto:main Nov 19, 2026
44 checks passed
@morluto morluto added area: cli CLI adapter and one-shot commands bug Something isn't working labels Nov 22, 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.

[Feature] Stream large TOON results without partial documents

2 participants