Skip to content

fix(core): decode legacy media in compaction checkpoints - #51409

Merged
rekram1-node merged 2 commits into
v2from
checkpoint-media
Sep 25, 2026
Merged

rekram1-node merged 2 commits into
v2from
checkpoint-media

Conversation

@kitlangton

Copy link
Copy Markdown
Contributor

Why

Sessions with a pre-2.0.15 native compaction containing media fail to load after upgrading: Session.MessageDecodeError. #49181 changed the embedded AI media format, but existing checkpoints still contain the old shape under version: 1.

What changes

Read legacy media at the checkpoint boundary before applying the current message schema. Both SessionProviderContext.validate() and decode() use the same normalization.

flowchart LR
    A[Stored checkpoint] --> B{Media shape}
    B -->|mediaType + data| C[Convert to media.source]
    B -->|media asset| D[Current Message decoder]
    C --> D
    D --> E[Load and replay session]
Loading
Stored media Decoded source
Raw base64 Base64 asset with the original MIME type
Base64 data URL Base64 asset using the embedded MIME type, or the original MIME type when omitted
HTTP(S) URL URL asset
Current asset Preserved

Attachment metadata is preserved. Malformed current assets still fail validation.

Scope

One Core compatibility helper; recovery happens on read without rewriting the database. Frozen legacy JSON and a database-backed history test protect this boundary.

Verification

# packages/core
bun run test test/session-provider-context.test.ts
# repository root
bun run check
Decoder Checkpoint tests
Original decoder, new regression tests 5 pass, 3 fail
Backward-compatible decoder 8 pass, 0 fail

The history regression persists an old-format checkpoint, reloads it, and verifies native replay and original-transcript selection. Full lint/type checks pass (35 typecheck tasks). Simplification pass completed.

Before 2.0.15, Core built media parts only from prompt attachments, whose data Prompt.Base64 validates, so data URL and http(s) handling was unreachable. Keep the fixture to data 2.0.14 could have written.
@rekram1-node
rekram1-node merged commit 041885d into v2 Sep 25, 2026
8 checks passed
@rekram1-node
rekram1-node deleted the checkpoint-media branch September 25, 2026 23:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants