Skip to content

fix app crash restoring messages without model#25062

Merged
Hona merged 1 commit into
anomalyco:devfrom
Hona:fix/session-restore-missing-model
Apr 30, 2026
Merged

fix app crash restoring messages without model#25062
Hona merged 1 commit into
anomalyco:devfrom
Hona:fix/session-restore-missing-model

Conversation

@Hona
Copy link
Copy Markdown
Member

@Hona Hona commented Apr 30, 2026

Summary

  • Avoid crashing when restoring session model state from old user messages that do not include a model field.
  • Preserve the existing default/no-variant behavior by storing null for the variant when the model is missing.

Verification

  • bun typecheck from packages/app
  • bun test --preload ./happydom.ts ./src/context/model-variant.test.ts ./src/pages/session/session-model-helpers.test.ts ./src/components/prompt-input/submit.test.ts from packages/app

Copilot AI review requested due to automatic review settings April 30, 2026 04:43
@Hona Hona requested a review from adamdotdevin as a code owner April 30, 2026 04:43
@Hona Hona merged commit 9bddf7f into anomalyco:dev Apr 30, 2026
11 checks passed
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.variant during session restore by using optional chaining.
  • Persist variant: null when 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,
})
Copy link

Copilot AI Apr 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants