Repository navigation
Description
Summary
opencode 1.4.3 can export a session JSON file that opencode 1.4.3 cannot import again.
The failure happens with sessions that still contain legacy pre-1.4 data shapes. export appears to serialize that legacy shape as-is, while import validates against the new 1.4 schema.
Version
opencode --version
# 1.4.3Repro
- Export an existing session:
sid=$(opencode session list --format json -n 1 | jq -r '.[0].id')
opencode export "$sid" > /tmp/session.json- Try to import the exported file:
opencode import /tmp/session.jsonActual result
Import fails with:
[
{
"expected": "string",
"code": "invalid_type",
"path": ["summary", "diffs", 0, "patch"],
"message": "Invalid input: expected string, received undefined"
}
]I also see legacy user message fields like top-level variant in the exported JSON.
Expected result
A file produced by opencode export should be importable by opencode import in the same version.
What I found
The exported file contains legacy-shaped data such as:
messages[].info.variantinstead ofmessages[].info.model.variantsummary.diffs[*].before/afterwithoutpatch
I wrote a local converter that:
- moves
messages[].info.variant->messages[].info.model.variant - replaces legacy
summary.diffs[*].before/afterwith a schema-validpatchstring
After that conversion, opencode import succeeds.
Important follow-up finding
Even after importing the converted JSON successfully, re-exporting that same session still produces legacy-shaped data again, and raw re-import fails again.
So import success does not appear to normalize the stored session permanently.
Evidence from one real session
On my exported session JSON:
- legacy user
variantfields:53 - legacy diff entries with
before/afterand nopatch:73
After converting the JSON file, import succeeds.
After importing the converted file and re-exporting that same session:
- legacy user
variantfields:53 - legacy diff entries with
before/afterand nopatch:73
And raw import fails again with the same summary.diffs[0].patch error.
Likely cause
export appears to serialize raw stored session data without normalizing legacy shapes, while import strictly validates against current schemas.
So either:
exportshould normalize legacy session/message data before writing JSON, orimportshould accept and migrate legacy export shapes, or- both
Relevant code paths
These looked relevant when I checked source:
packages/opencode/src/cli/cmd/export.tspackages/opencode/src/cli/cmd/import.tspackages/opencode/src/snapshot/index.tspackages/opencode/src/session/message-v2.ts
Activity
kirillp commentedon Jun 19, 2026
I have the same issue, exported file by "version": "1.15.4", cannot import it with the current version 1.17.8
kirillp commentedon Jun 19, 2026
I ask opencode to investigate and it found the following:
It works. The session imported successfully after converting to UTF-8 without BOM. Root cause: The file ses_1bf8a86b1ffeNAd6lVyuCurdUt.json was exported by opencode 1.15.4 in UTF-16 LE encoding (with BOM). The opencode import command (1.17.8) uses a Rust binary that expects UTF-8 without BOM and fails with a misleading "File not found" error when it can't decode the file. Fix: Convert the file to UTF-8 (without BOM): $content = Get-Content -LiteralPath "ses_1bf8a86b1ffeNAd6lVyuCurdUt.json" -Raw [System.IO.File]::WriteAllText("ses_utf8.json", $content, [System.Text.UTF8Encoding]::new($false)) opencode import ses_utf8.json The session format itself (1.15.4) was compatible with 1.17.8 import — only the encoding was the issue.github-actions commentedon Aug 19, 2026
To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.