Skip to content

Conversation

@sisyphus-dev-ai
Copy link
Collaborator

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

  • Updated src/features/background-agent/types.ts: Added parentModel field to BackgroundTask and LaunchInput interfaces
  • Modified src/features/background-agent/manager.ts:
    • Captures and stores parent model context when launching background tasks
    • Preserves model field when notifying parent session after task completion
    • Uses stored parentModel with fallback to findNearestMessageWithFields() for resilience

2. Librarian Agent Factory Pattern

  • Converted src/agents/librarian.ts:
    • Changed from static config to factory function createLibrarianAgent(model?: string)
    • Added configurable model parameter with DEFAULT_MODEL constant
    • Maintained backward compatibility with exported librarianAgent constant
  • Updated src/agents/utils.ts: Uses new createLibrarianAgent factory

3. Background Task Tool Model Context Capture

  • Enhanced src/tools/background-task/tools.ts:
    • Captures current model context from parent session using findNearestMessageWithFields()
    • Passes parentModel to manager.launch() for proper context preservation
    • Ensures model selection persists through background task lifecycle

Impact

✅ Fixes

  • Users with OAuth providers (Google Antigravity, etc.) will have their model selection preserved
  • Background agents no longer revert to hardcoded defaults
  • Agent model configuration is now more flexible and user-controllable
  • Model context properly propagates through multi-level background tasks

🔧 Technical Improvements

  • Modular factory pattern for agent creation
  • Better separation of concerns (model selection vs agent config)
  • Improved context management across async operations

🛡️ Backward Compatibility

  • All existing tests pass (20/20)
  • Build succeeds with no errors
  • Existing configs continue to work unchanged
  • Exported constants maintain API compatibility

Testing

  • ✅ Type checking: Passed
  • ✅ Unit tests: 20/20 passing
  • ✅ Build: Successful with no errors
  • ✅ Schema: Regenerated and validated

Files Changed

  • src/features/background-agent/types.ts - Add model context fields
  • src/features/background-agent/manager.ts - Preserve and pass model context
  • src/agents/librarian.ts - Convert to factory with configurable model
  • src/agents/utils.ts - Use librarian factory
  • src/tools/background-task/tools.ts - Capture and pass model context
  • assets/oh-my-opencode.schema.json - Regenerated JSON schema

Related Issues

Closes #191

Additional Notes

This is a targeted fix addressing the core issue without over-engineering. The solution:

  • Preserves user intent across agent boundaries
  • Respects OAuth provider selections
  • Maintains the existing architecture
  • Sets foundation for future model selection enhancements

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.

Fixes #191

This commit addresses three critical issues with model selection:

1. **Background Agent Manager Model Preservation**
   - Updated BackgroundTask and LaunchInput types to include parentModel field
   - Modified manager.ts to capture and store parent model context
   - Updated notifyParentSession() to pass model field when resuming parent session
   - Background tasks now preserve the user's selected model across continuations

2. **Librarian Agent Factory Pattern**
   - Converted librarian agent from static config to factory function
   - Added createLibrarianAgent(model?: string) with configurable model parameter
   - Maintained backward compatibility with exported librarianAgent constant
   - Updated utils.ts to use the new factory function

3. **Background Task Tool Model Context Capture**
   - Updated background_task tool to capture current model context
   - Uses findNearestMessageWithFields() to get model info from parent session
   - Passes parentModel to manager.launch() for proper context preservation

Changes:
- src/features/background-agent/types.ts: Add parentModel field to BackgroundTask and LaunchInput
- src/features/background-agent/manager.ts: Store and preserve parent model context
- src/agents/librarian.ts: Convert to factory pattern with configurable model
- src/agents/utils.ts: Use createLibrarianAgent factory
- src/tools/background-task/tools.ts: Capture and pass model context
- assets/oh-my-opencode.schema.json: Regenerated schema

Impact:
- Users with OAuth providers (Google, Anthropic) will now have their model selection preserved
- Background agents no longer revert to hardcoded defaults
- Agent model configuration is now more flexible and user-controllable

Testing:
- All existing tests pass (20/20)
- Build succeeds with no errors
- Backward compatibility maintained
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.

[BUG] Model selection reverts to hardcoded Anthropic models instead of preserving user's OAuth/configured model

2 participants