senpi icon indicating copy to clipboard operation
senpi copied to clipboard

host session read truncates its JSON line at 65536 bytes when stdout is a pipe

Open Momentum96 opened this issue 1 week ago • 0 comments

What happened?

senpi host session read <ref> --json (also reachable as omo host session read) cuts its output at exactly 65536 bytes when stdout is a pipe. The output stops in the middle of the single JSON line, the exit status is 0 and nothing is printed to stderr, so a consumer gets an unterminated JSON document. Redirected to a file the same command writes the full line.

Cause: emit() in packages/coding-agent/src/cli/host-emit.ts calls writeSync(1, line) once and ignores the return value. On a non-blocking pipe fs.writeSync writes only what fits in the pipe buffer and returns that byte count (or throws EAGAIN), so the rest of the line is dropped. The host and host session commands all answer through emit(), so any large answer (read, list, state, status --all) is affected.

Steps to reproduce

  1. Pick a session with a large transcript and read it twice:
    senpi host session read <ref> --tail 400 --json > /tmp/out.json; wc -c < /tmp/out.json   # 573826
    senpi host session read <ref> --tail 400 --json | wc -c                                  # 65536
    
  2. The piped output is not valid JSON (json.loads fails with "Unterminated string").
  3. Minimal reproduction of the primitive, on both Bun 1.4.4 and Node (macOS arm64), once process.stdout has been touched:
    import { writeSync } from "node:fs";
    process.stdout.write("");
    const s = "x".repeat(500000) + "\n";
    console.error(writeSync(1, s)); // 65536 (of 500001) when stdout is a pipe
    
    Piping that script into wc -c prints 65536.

Expected behavior

The pipe receives the same bytes as the file (573826 in the example above).

Version

senpi 2026.11.23 (installed through omo-ai 5.1.83), Bun 1.4.4, macOS 26 arm64; the same symptom was seen on Linux and Windows hosts over ssh. main at 481b281bd has the same emit().

Momentum96 avatar Nov 24 '26 11:11 Momentum96