Skip to content

opencode export <id> | jq produces truncated / invalid JSON when piped (large sessions) #29330

@xqm32

Description

@xqm32

Note: This issue was prepared with AI assistance (via prompts) using opencode and the model xai/grok-build-0.1.

Summary

opencode export <id> | jq (and similar commands) produces truncated or invalid JSON when the output is piped and the data volume is large. Writing to a file first works correctly.

This is a recurring problem. Previous reports include:

A previous attempt to address the export case (#3049) changed the implementation from console.log to process.stdout.write, but the issue persists.

Reproduction

# Fails with parse error
opencode export <large-session-id> | jq .

# Works
opencode export <large-session-id> > /tmp/out.json && cat /tmp/out.json | jq .

The problem is data-size and backpressure dependent.

Workaround

Always redirect large machine-readable output to a file instead of piping directly.

Additional Context

The truncation occurs because large stdout writes are not fully flushed before the process exits. The same pattern exists across multiple CLI commands that produce significant output.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions