fix app crash restoring messages without model#25062
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Prevents the app from crashing when restoring session model state from legacy user messages that don’t include a model field, while preserving the “no variant selected” behavior.
Changes:
- Guard access to
msg.model.variantduring session restore by using optional chaining. - Persist
variant: nullwhen the model is missing to keep existing default/no-variant semantics.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
382
to
386
| setSaved("session", session, { | ||
| agent: msg.agent, | ||
| model: msg.model, | ||
| variant: msg.model.variant ?? null, | ||
| variant: msg.model?.variant ?? null, | ||
| }) |
There was a problem hiding this comment.
restore now defensively handles msg.model being missing at runtime, but its parameter type still requires model: ModelKey. Consider widening it to model?: ModelKey (or similar) so TypeScript reflects the real input shape and encourages callers/edits to keep the defensive checks.
Bojun-Vvibe
added a commit
to Bojun-Vvibe/oss-contributions
that referenced
this pull request
Apr 30, 2026
- anomalyco/opencode#25062 (merge-as-is) — defensive optional-chain on legacy session restore - anomalyco/opencode#25019 (merge-as-is) — per-server fail-soft on invalid MCP url - anomalyco/opencode#25032 (merge-as-is) — middleware-pair test + directory AGENTS.md - openai/codex#20278 (merge-after-nits) — workspace plugin sharing v2 RPCs
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.
Summary
nullfor the variant when the model is missing.Verification
bun typecheckfrompackages/appbun test --preload ./happydom.ts ./src/context/model-variant.test.ts ./src/pages/session/session-model-helpers.test.ts ./src/components/prompt-input/submit.test.tsfrompackages/app