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.3
Repro
- 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.json
Actual 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.variant instead of messages[].info.model.variant
summary.diffs[*].before/after without patch
I wrote a local converter that:
- moves
messages[].info.variant -> messages[].info.model.variant
- replaces legacy
summary.diffs[*].before/after with a schema-valid patch string
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
variant fields: 53
- legacy diff entries with
before/after and no patch: 73
After converting the JSON file, import succeeds.
After importing the converted file and re-exporting that same session:
- legacy user
variant fields: 53
- legacy diff entries with
before/after and no patch: 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:
export should normalize legacy session/message data before writing JSON, or
import should accept and migrate legacy export shapes, or
- both
Relevant code paths
These looked relevant when I checked source:
packages/opencode/src/cli/cmd/export.ts
packages/opencode/src/cli/cmd/import.ts
packages/opencode/src/snapshot/index.ts
packages/opencode/src/session/message-v2.ts
Summary
opencode 1.4.3can export a session JSON file thatopencode 1.4.3cannot import again.The failure happens with sessions that still contain legacy pre-1.4 data shapes.
exportappears to serialize that legacy shape as-is, whileimportvalidates against the new 1.4 schema.Version
opencode --version # 1.4.3Repro
Actual 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
variantin the exported JSON.Expected result
A file produced by
opencode exportshould be importable byopencode importin the same version.What I found
The exported file contains legacy-shaped data such as:
messages[].info.variantinstead ofmessages[].info.model.variantsummary.diffs[*].before/afterwithoutpatchI wrote a local converter that:
messages[].info.variant->messages[].info.model.variantsummary.diffs[*].before/afterwith a schema-validpatchstringAfter that conversion,
opencode importsucceeds.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:
variantfields:53before/afterand nopatch:73After converting the JSON file, import succeeds.
After importing the converted file and re-exporting that same session:
variantfields:53before/afterand nopatch:73And raw import fails again with the same
summary.diffs[0].patcherror.Likely cause
exportappears to serialize raw stored session data without normalizing legacy shapes, whileimportstrictly validates against current schemas.So either:
exportshould normalize legacy session/message data before writing JSON, orimportshould accept and migrate legacy export shapes, orRelevant 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