Description
The opencode export command fails with Error: Session not found: <session_id> for sessions whose part table data exceeds approximately 1GB, even though the sessions exist in the database and appear normally in opencode session list.
The error message is misleading — the session IS found during listing, but the export process crashes during JSON serialization of the session data, and the crash is caught and surfaced as a "not found" error.
Environment
- OpenCode version: 1.4.3
- OS: Windows 11 (10.0.26100), x64
- Node.js: v24.14.1
- System RAM: 32GB
- Database size: 9.36GB (~/.local/share/opencode/opencode.db)
- Total parts in DB: 152,977 entries, ~3.15GB of part data
The threshold appears to be around 1GB of serialized part data. Sessions below this threshold export successfully.
Root Cause Analysis
I investigated the SQLite database directly using better-sqlite3:
- Sessions exist in the database — all failing session IDs are present in the session table with complete metadata (id, title, slug, timestamps, etc.)
- Messages and parts exist — the message and part tables contain all expected records with valid JSON data
- Database integrity is fine — PRAGMA integrity_check returns ok
- No archiving or soft-delete — time_archived is NULL for all sessions
The export command is likely hitting a Node.js heap memory limit when it attempts to load and serialize 1+ GB of part data into a single JSON response. The OOM crash is caught and incorrectly reported as "Session not found".
Plugins
No response
OpenCode version
1.4.3
Steps to reproduce
- Have a session with large accumulated data (8,000+ messages with 38,000+ parts totaling >1GB in the part table)
- Run opencode session list — the session appears normally
- Run opencode export <session_id> — either via interactive selection or passing the ID directly
- Observe: Error: Session not found: <session_id>
Screenshot and/or share link
Operating System
Windows 11 (10.0.26100), x64
Terminal
PowerShell 7.6.0
Description
The opencode export command fails with Error: Session not found: <session_id> for sessions whose part table data exceeds approximately 1GB, even though the sessions exist in the database and appear normally in opencode session list.
The error message is misleading — the session IS found during listing, but the export process crashes during JSON serialization of the session data, and the crash is caught and surfaced as a "not found" error.
Environment
The threshold appears to be around 1GB of serialized part data. Sessions below this threshold export successfully.
Root Cause Analysis
I investigated the SQLite database directly using better-sqlite3:
The export command is likely hitting a Node.js heap memory limit when it attempts to load and serialize 1+ GB of part data into a single JSON response. The OOM crash is caught and incorrectly reported as "Session not found".
Plugins
No response
OpenCode version
1.4.3
Steps to reproduce
Screenshot and/or share link
Operating System
Windows 11 (10.0.26100), x64
Terminal
PowerShell 7.6.0