Skip to content

fix(session): sync model switch to server immediately - #33471

Closed
lexlian wants to merge 2 commits into
anomalyco:devfrom
lexlian:fix/33199-model-switch-sync
Closed

lexlian wants to merge 2 commits into
anomalyco:devfrom
lexlian:fix/33199-model-switch-sync

Conversation

@lexlian

@lexlian lexlian commented Jun 23, 2026 •

Copy link
Copy Markdown

Issue for this PR

Closes #33199

Type of change

  • Bug fix

What does this PR do?

Root cause: When the user switched models in the UI, local.model.set() only updated the local persisted store. The server's SessionTable.model was only updated when a prompt arrived with a different model: field in the payload. The session runner resolved models using SessionTable.model, causing image/vision capability checks to use the stale model between the UI switch and the next message.

Fix: Added POST /api/session/{sessionID}/model endpoint that publishes a ModelSwitched event. When the user changes models in the UI, the app now immediately calls client.session.switchModel() to sync the change to the server. The projector (already wired in core/src/session.ts) handles persisting the new model to SessionTable.model.

Files changed:

  • packages/app/src/context/local.tsx — calls switchModel() after model.set()
  • packages/opencode/src/server/routes/instance/httpapi/groups/session.ts — new endpoint + SwitchModelPayload schema
  • packages/opencode/src/server/routes/instance/httpapi/handlers/session.ts — handler calling session.switchModel()
  • packages/opencode/src/session/session.ts — added switchModel to Interface and implemented via events.publish(SessionEvent.ModelSwitched, ...)

How did you verify your code works?

  • bun test test/server/httpapi-session.test.ts — 19/19 pass including new test "switchModel endpoint updates session model and returns 204"
  • bun test test/session-projector.test.ts — 7/7 pass
  • cd packages/opencode && bun typecheck — clean

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

…mediately

When the user switches models in the UI, the local persisted store was updated but
the server's SessionTable.model was not — causing image/vision capabilities
to be stale until the next message was sent. This change adds a
POST /api/session/{sessionID}/model endpoint that publishes a ModelSwitched
event, keeping server-side session state consistent with UI model selection
in real time.

Closes anomalyco#33199
@github-actions github-actions Bot added needs:compliance This means the issue will auto-close after 2 hours. and removed needs:compliance This means the issue will auto-close after 2 hours. labels Jun 23, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

@lexlian lexlian changed the title feat(session): sync model changes immediately via switchModel endpoint fix(session): sync model switch to server immediately Jun 23, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Automated PR Cleanup

Thank you for contributing to opencode.

Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions.

This PR was closed because it matched the following cleanup criteria:

  • The PR was created more than 1 month ago
  • The PR had fewer than 2 positive reactions
  • Positive reactions are counted as thumbs-up, heart, celebration, or rocket reactions on the PR

PRs created within the last month are not affected by this cleanup.

If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate.

Thanks again for taking the time to contribute.

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.

Image input is rejected after switching from a non-vision model within the same session

1 participant