refactor: split runtime.go and extract pkg/modelerrors#2010
refactor: split runtime.go and extract pkg/modelerrors#2010dgageot wants to merge 1 commit intodocker:mainfrom
Conversation
Break up the oversized runtime.go (2510 lines) by extracting cohesive groups of functions into dedicated files, and move pure error classification utilities into a new reusable package. New files in pkg/runtime: - model_picker.go: model change/revert tool handlers - agent_delegation.go: sub-agent dispatch, task transfer, handoffs New package pkg/modelerrors: - ContextOverflowError type and detection - HTTP status code extraction (Anthropic, Gemini, OpenAI) - Retryable error classification - Exponential backoff with jitter - User-friendly error formatting Assisted-By: docker-agent
There was a problem hiding this comment.
Review Summary
Assessment: 🟢 APPROVE
This is a clean refactoring that successfully extracts error handling utilities into a new pkg/modelerrors package and splits the oversized runtime.go into more focused files:
- New package
pkg/modelerrors: Consolidates error classification, retry logic, and backoff calculations with comprehensive test coverage agent_delegation.go: Extracts agent delegation and task transfer logicmodel_picker.go: Isolates model picker tool handlers- Net reduction: ~238 lines through deduplication
Analysis
Reviewed 2803 lines across 7 files. The refactoring maintains identical behavior while improving code organization:
✅ All moved code preserves exact functionality
✅ Import paths correctly updated to new package structure
✅ Constants properly migrated (e.g., DefaultFallbackCooldown → modelerrors.DefaultCooldown)
✅ Comprehensive test coverage in new modelerrors_test.go
✅ No behavioral changes introduced
✅ Go 1.26.0 ensures goroutine-safe standard library usage
Findings
No bugs detected in the changed code. The extraction is methodical and preserves all existing semantics.
Summary
Break up the oversized
runtime.go(2510 lines) by extracting cohesive groups of functions into dedicated files, and move pure error classification utilities into a new reusable package.Changes
New files in
pkg/runtimemodel_picker.go:findModelPickerTool,handleChangeModel,handleRevertModel,setModelAndEmitInfoagent_delegation.go:CurrentAgentSubAgentNames,RunAgent,handleTaskTransfer,runSubSession,handleHandoff, plus shared helpers (validateAgentInList,buildTaskSystemMessage,agentNames)New package
pkg/modelerrorsContextOverflowErrortype and detectionIsRetryableModelError,IsRetryableStatusCode)CalculateBackoff,SleepWithContext)FormatError)modelerrors_test.goNet impact
runtime.go: 2510 → ~2050 lines