Skip to content

feat: add model state persistence and improve model selection sync#209

Merged
chriswritescode-dev merged 5 commits intomainfrom
feature/opencode-model-state
Apr 30, 2026
Merged

feat: add model state persistence and improve model selection sync#209
chriswritescode-dev merged 5 commits intomainfrom
feature/opencode-model-state

Conversation

@chriswritescode-dev
Copy link
Copy Markdown
Owner

@chriswritescode-dev chriswritescode-dev commented Apr 29, 2026

Summary

  • Add persistent model state storage with database backend for user model preferences
  • Implement model/variant sync from session agents to store when messages load
  • Include model, agent, and variant in optimistic user messages
  • Fix useSessionAgent to check isFetching during message loading
  • Ensure model state table exists when accessing (fixes existing databases)
  • Update env.ts to use getter for BASE_PATH for dynamic resolution

Changes

  • frontend/src/stores/modelStore.ts - Add setActiveModel method
  • frontend/src/hooks/useModelSelection.ts - Add setActiveModel with provider validation
  • frontend/src/hooks/useSessionAgent.ts - Add isFetching check, prevent stale model restoration
  • frontend/src/hooks/useOpenCode.ts - Include model/agent/variant in optimistic messages
  • frontend/src/components/message/PromptInput.tsx - Sync session agent model to store
  • backend/src/db/model-state.ts - Ensure table exists on access
  • backend/src/routes/providers.ts - Migrate to database storage
  • shared/src/config/env.ts - Change BASE_PATH to getter function

Type of Change

  • Bug fix
  • New feature
  • Refactor
  • Documentation

Checklist

  • Code follows project style (no comments, named imports)
  • TypeScript types are properly defined
  • Tests added/updated (80% coverage target)
  • pnpm lint passes locally
  • pnpm typecheck passes locally

- Create opencode_model_state table for storing user model preferences
- Implement database-backed model state management (recent, favorite, variant)
- Add atomic JSON file utilities with file locking for concurrent safety
- Migrate providers routes from file-based to database storage
- Add backfill migration to preserve existing model.json data
- Include comprehensive tests for model-state and atomic-json modules
- Refactor useSessionAgent hook to simplify agent/model resolution logic
- Update getFileApiUrl to use consistent query parameter approach
- Add setActiveModel to modelStore and useModelSelection for direct model updates
- Sync session agent model/variant to store when messages load
- Include model, agent, and variant in optimistic user messages
- Fix useSessionAgent to check isFetching during message loading
- Update env.ts to use getter for BASE_PATH for dynamic resolution
- Fix test environment variable from OPENCODE_WORKSPACE_PATH to WORKSPACE_PATH
@chriswritescode-dev chriswritescode-dev changed the title fix: ensure model state table exists for existing databases feat: add model state persistence and improve model selection sync Apr 30, 2026
@chriswritescode-dev chriswritescode-dev merged commit 549e0ac into main Apr 30, 2026
4 checks passed
@chriswritescode-dev chriswritescode-dev deleted the feature/opencode-model-state branch April 30, 2026 01:45
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.

1 participant