fix(session): tolerate pre-#24512 model JSON shape in fromRow#26572
Closed
kitlangton wants to merge 1 commit into
Closed
fix(session): tolerate pre-#24512 model JSON shape in fromRow#26572kitlangton wants to merge 1 commit into
kitlangton wants to merge 1 commit into
Conversation
Closes #26435. Sessions created before #24512 (commit a3bc5d3, 2026-05-02) wrote the `model` column as { providerID, modelID }. That PR renamed the shape to { id, providerID, variant } and updated `fromRow` to read row.model.id, but only updated the Drizzle \$type<>() annotation — the on-disk JSON of existing rows was not migrated. fromRow now crashes on those legacy rows with 'Expected string, got undefined', killing the whole session list (no per-row containment). Fall back to row.model.modelID when row.model.id is absent. Newly written rows still use the new shape; this only affects reads of legacy data.
Contributor
Author
|
Closing for further investigation. Review agents flagged factual issues with the PR's root-cause story, missing coverage in v2/session.ts:132, and an unsafe |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #26435.
What broke
Sessions store their selected model as a JSON-typed SQLite column. On 2026-05-02, commit
a3bc5d35b(PR #24512 "Refactor v2 session events as schemas" by @thdxr) renamed the JSON shape:{ "providerID": "opencode", "modelID": "big-pickle" }{ "id": "big-pickle", "providerID": "opencode", "variant": "..." }The PR updated:
session.sql.tsfrom$type<{ providerID, modelID }>()to$type<{ id, providerID, variant }>()fromRowinsession.tsto readrow.model.idBut
$type<>()is a compile-time-only TypeScript cast. It does not transform, validate, or migrate the underlying JSON bytes. No data migration was added, so existing on-disk rows still contain{ providerID, modelID }.When
fromRowreads one of those legacy rows it computesModelID.make(row.model.id)—row.model.idisundefined, theSchema.brand("ModelID")decoder throwsExpected string, got undefined, and the wholeSession.listcall rejects (no per-row containment inlistByProject). One bad row hides every other valid session.Why this slipped through review
opencode session listor anything else that hitslistByProject. Many users create a fresh session each chat and never triggerlist.The fix
fromRowreadsrow.model.id ?? row.model.modelIDso legacy rows decode using the old field name. Newly-written rows still use the new shape; this is read-side compatibility, not a write-side change. No data migration needed; no risk of corrupting existing data.Reproducer
packages/opencode/test/session/session-legacy-model-shape.test.tscreates a session through the normal API, then directly mutates itsmodelcolumn to the legacy shape, then assertsSession.listreturns it (and a sibling valid session) without crashing.Verified red → green → red → green: pre-fix the test fails with the exact
Expected string, got undefinederror; post-fix it passes; reverting the fix makes it fail again.Follow-up worth considering (not in this PR)
listByProjectso a corrupt row never tanks the whole list, regardless of shape.SessionTableand rewrites legacymodelJSON to the new shape, eventually letting us drop this fallback.