[BUG FIX] Preserve model context across agent handoffs and background tasks #208
+79
−10
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
Fixes #191 - Resolves model selection reverting to hardcoded Anthropic models instead of preserving user's OAuth/configured model across agent handoffs and background task continuations.
Changes
1. Background Agent Manager Model Preservation
src/features/background-agent/types.ts: AddedparentModelfield toBackgroundTaskandLaunchInputinterfacessrc/features/background-agent/manager.ts:parentModelwith fallback tofindNearestMessageWithFields()for resilience2. Librarian Agent Factory Pattern
src/agents/librarian.ts:createLibrarianAgent(model?: string)DEFAULT_MODELconstantlibrarianAgentconstantsrc/agents/utils.ts: Uses newcreateLibrarianAgentfactory3. Background Task Tool Model Context Capture
src/tools/background-task/tools.ts:findNearestMessageWithFields()parentModeltomanager.launch()for proper context preservationImpact
✅ Fixes
🔧 Technical Improvements
🛡️ Backward Compatibility
Testing
Files Changed
src/features/background-agent/types.ts- Add model context fieldssrc/features/background-agent/manager.ts- Preserve and pass model contextsrc/agents/librarian.ts- Convert to factory with configurable modelsrc/agents/utils.ts- Use librarian factorysrc/tools/background-task/tools.ts- Capture and pass model contextassets/oh-my-opencode.schema.json- Regenerated JSON schemaRelated Issues
Closes #191
Additional Notes
This is a targeted fix addressing the core issue without over-engineering. The solution:
Future work could include making all agents use factory patterns and adding global model persistence configuration options, but this PR focuses on fixing the immediate bug.