Skip to content

opencode export can write session JSON that opencode import cannot read in 1.4.3 #21941

@christianknauer

Description

@christianknauer

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

  1. Export an existing session:
sid=$(opencode session list --format json -n 1 | jq -r '.[0].id')
opencode export "$sid" > /tmp/session.json
  1. 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:

  1. export should normalize legacy session/message data before writing JSON, or
  2. import should accept and migrate legacy export shapes, or
  3. 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

Metadata

Metadata

Assignees

Labels

coreAnything pertaining to core functionality of the application (opencode server stuff)

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