Skip to content

fix: Preserve unread exec output when max_output_tokens truncates a chunk #144

Closed

Description

@minorcell

Summary

exec_runtime drops output data when a response chunk is truncated by max_output_tokens.

  • Affected code: /Users/mcell/Desktop/workspace/memo-cli/packages/tools/src/tools/exec_runtime.ts:279
  • Related code: /Users/mcell/Desktop/workspace/memo-cli/packages/tools/src/tools/exec_runtime.ts:281

Why this matters

Tool output can be silently lost, which breaks correctness for long outputs and makes follow-up write_stdin polling incomplete.

Repro

  1. Start exec_command with a command that emits large output and keeps running briefly.
  2. Set small max_output_tokens (e.g. 10).
  3. First response shows Original token count much larger than returned output (expected truncation).
  4. Poll same session with write_stdin and no input.
  5. Observe Original token count: 0 and empty output, instead of remaining unread tail.

I confirmed locally with:

  • cmd: node -e "process.stdout.write('X'.repeat(5000)); setTimeout(() => {}, 4000)"
  • First chunk Original token count: 1250 but only 40 chars returned.
  • Second poll returned nothing.

Expected

If output is truncated, unread remainder should still be available in subsequent polls.

Actual

readOffset is advanced to full delta length before truncation remainder is retained, so tail is discarded.

Suggested fix

  • Advance readOffset only by delivered bytes/chars, not full delta.
  • Keep a per-session pending-output buffer (or ring buffer) for remainder.
  • Add regression test covering truncation + subsequent poll.

Requested implementer

Please let memo handle this fix.

Activity

  1. added
    bugSomething isn't working
    needs-triageIssue needs initial triage
    area:toolsBuilt-in tools and tool runtime
    area:coreCore runtime and session state
    on Feb 11, 2026
  2. minorcell commented on Feb 11, 2026

    @minorcell
    OwnerAuthor

    Fixed in commit ffb76bc.

    Changes:

    • Updated exec output truncation bookkeeping so readOffset advances only by delivered chars.
    • This preserves unread tail data for subsequent write_stdin polls.
    • Added regression test that reproduces truncation and verifies next poll returns remaining output.

    Validation:

    • pnpm test packages/tools/src/tools/codex_tools.test.ts
  3. minorcell commented on Feb 11, 2026

    @minorcell
    OwnerAuthor

    Closing as fixed by ffb76bc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:coreCore runtime and session statearea:toolsBuilt-in tools and tool runtimearea:tuiTerminal UI and interaction layerbugSomething isn't workingneeds-triageIssue needs initial triagepriority:p1High priority

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions