fix(tui): isolate OpenCode model config from profiles#1086
fix(tui): isolate OpenCode model config from profiles#1086RGutierrezWind wants to merge 2 commits into
Conversation
📝 WalkthroughWalkthroughThe TUI reloads base OpenCode assignments when configuration opens from profile context, clears profile state, and verifies that profile-specific assignments are removed. ChangesOpenCode assignment isolation
Estimated code review effort: 2 (Simple) | ~10 minutes Sequence Diagram(s)sequenceDiagram
participant Model
participant Assignments
participant Selection
participant Picker
Model->>Assignments: Read base OpenCode assignments
Assignments->>Selection: Populate ModelAssignments
Model->>Selection: Clear profile edit and draft state
Model->>Picker: Open OpenCode model configuration
Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@internal/tui/model_test.go`:
- Around line 2258-2268: Extend the test around confirmSelection to explicitly
assert that profile context is cleared, not just that model assignments are
replaced. Inspect the state fields managed by withoutProfileAssignmentContext
and add assertions verifying each relevant profile-state field is empty or unset
after reload, alongside the existing ModelAssignments checks.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: d2dddb4a-4bf0-4125-b7fe-0bd1b93530af
📒 Files selected for processing (2)
internal/tui/model.gointernal/tui/model_test.go
fdb5093 to
2ff7a1b
Compare
2ff7a1b to
1519b54
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@internal/tui/model.go`:
- Around line 169-176: Update withBaseOpenCodeModelAssignments to handle errors
from readCurrentAssignmentsFn by surfacing the same ConfigWarning behavior used
by NewModelPickerState for opencode.json read/parse failures, while preserving
the existing assignment sanitization for successful non-empty reads.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 5d6f17c4-40b0-433a-9b6e-e34df04aa4e7
📒 Files selected for processing (2)
internal/tui/model.gointernal/tui/model_test.go
| func (m Model) withBaseOpenCodeModelAssignments() Model { | ||
| m.Selection.ModelAssignments = nil | ||
| settingsPath := opencode.DefaultSettingsPath() | ||
| if current, err := readCurrentAssignmentsFn(settingsPath); err == nil && len(current) > 0 { | ||
| m.Selection.ModelAssignments = sanitizeKnownModelEfforts(current, m.ModelPicker.SDDModels) | ||
| } | ||
| return m | ||
| } |
There was a problem hiding this comment.
🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win
Silent failure on opencode.json read error.
When readCurrentAssignmentsFn returns an error, the assignments are silently dropped with no indication to the user. Elsewhere in the same subsystem, NewModelPickerState surfaces a ConfigWarning for the equivalent read/parse failure of opencode.json. Since this helper feeds directly into a user-initiated action ("Configure OpenCode models"), a silent empty picker on read failure could look identical to a config with no assignments, hiding the real cause.
♻️ Suggested fix
func (m Model) withBaseOpenCodeModelAssignments() Model {
m.Selection.ModelAssignments = nil
settingsPath := opencode.DefaultSettingsPath()
- if current, err := readCurrentAssignmentsFn(settingsPath); err == nil && len(current) > 0 {
- m.Selection.ModelAssignments = sanitizeKnownModelEfforts(current, m.ModelPicker.SDDModels)
+ current, err := readCurrentAssignmentsFn(settingsPath)
+ if err != nil {
+ m.ModelPicker.ConfigWarning = fmt.Sprintf("Could not load current OpenCode model assignments: %v", err)
+ } else if len(current) > 0 {
+ m.Selection.ModelAssignments = sanitizeKnownModelEfforts(current, m.ModelPicker.SDDModels)
}
return m
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| func (m Model) withBaseOpenCodeModelAssignments() Model { | |
| m.Selection.ModelAssignments = nil | |
| settingsPath := opencode.DefaultSettingsPath() | |
| if current, err := readCurrentAssignmentsFn(settingsPath); err == nil && len(current) > 0 { | |
| m.Selection.ModelAssignments = sanitizeKnownModelEfforts(current, m.ModelPicker.SDDModels) | |
| } | |
| return m | |
| } | |
| func (m Model) withBaseOpenCodeModelAssignments() Model { | |
| m.Selection.ModelAssignments = nil | |
| settingsPath := opencode.DefaultSettingsPath() | |
| current, err := readCurrentAssignmentsFn(settingsPath) | |
| if err != nil { | |
| m.ModelPicker.ConfigWarning = fmt.Sprintf("Could not load current OpenCode model assignments: %v", err) | |
| } else if len(current) > 0 { | |
| m.Selection.ModelAssignments = sanitizeKnownModelEfforts(current, m.ModelPicker.SDDModels) | |
| } | |
| return m | |
| } |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@internal/tui/model.go` around lines 169 - 176, Update
withBaseOpenCodeModelAssignments to handle errors from readCurrentAssignmentsFn
by surfacing the same ConfigWarning behavior used by NewModelPickerState for
opencode.json read/parse failures, while preserving the existing assignment
sanitization for successful non-empty reads.
🔗 Linked Issue
Closes #950
🏷️ PR Type
What kind of change does this PR introduce?
type:bug— Bug fix (non-breaking change that fixes an issue)type:feature— New feature (non-breaking change that adds functionality)type:docs— Documentation onlytype:refactor— Code refactoring (no functional changes)type:chore— Build, CI, or tooling changestype:breaking-change— Breaking change (fix or feature that changes existing behavior)📝 Summary
📂 Changes
internal/tui/model.gointernal/tui/model_test.go🧪 Test Plan
Unit Tests
go test ./...E2E Tests (Docker required)
go test ./...)cd e2e && ./docker-test.sh)Additional focused validation:
🤖 Automated Checks
The following checks run automatically on this PR:
additions + deletions) or usesize:exceptionCloses/Fixes/Resolves #Nstatus:approvedtype:*Labeltype:*label must be appliedgo test ./...must passcd e2e && ./docker-test.shmust pass✅ Contributor Checklist
status:approvedsize:exceptionwith rationale documentedtype:*label to this PRgo test ./...)cd e2e && ./docker-test.sh)Co-Authored-Bytrailers💬 Notes for Reviewers
E2E tests were not run locally because this change is isolated to TUI model assignment state and regression coverage was added at the unit-test level.
This PR needs a maintainer to apply exactly one
type:*label:type:bug. GitHub denied label application from this fork withAddLabelsToLabelablepermission error.Summary by CodeRabbit