refactor(orchestrate): extract 3 helpers from 255-line runOrchestration#3347
Open
refactor(orchestrate): extract 3 helpers from 255-line runOrchestration#3347
Conversation
De-duplicate model ID resolution, env config building, and agent install logic that was copied between the fast-mode and sequential orchestration paths. Changes to these operations now only need to happen in one place. - resolveModelId(agentName, agent) — reads MODEL_ID / preferences / default - buildEnvConfig(agent, apiKey, modelId, betaFeatures, spawnId) — builds .spawnrc - installAgentWithRetry(cloud, agent, agentName, options, allowTarball) — tarball-first with retry The local-cloud tarball guard is preserved: fast path passes useTarball directly (already gated by cloudName !== "local"), sequential path passes cloudName !== "local" && useTarball. Agent: complexity-hunter Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Why: The fast-mode and sequential orchestration paths in
runOrchestrationduplicated model ID resolution, env config building, and agent install logic. Any change to these operations had to be applied in two places, risking divergence bugs.Changes
Extract 3 shared helpers to eliminate the duplication:
resolveModelId(agentName, agent)— readsMODEL_IDenv / saved preferences / agent default, validates withvalidateModelId()buildEnvConfig(agent, apiKey, modelId, betaFeatures, spawnId)— builds env pairs, appends model + recursive vars, callsgenerateEnvConfig()installAgentWithRetry(cloud, agent, agentName, options, allowTarball)— tarball-first install with fallback to live install retry loopThe behavioral difference in tarball eligibility between paths is preserved:
useTarballdirectly (already gated bycloudName !== "local"at the branch level)cloudName !== "local" && useTarballrunOrchestrationdrops from 255 to ~195 lines. Version bumped to 1.0.21.Test plan
bunx @biomejs/biome check src/— zero errorsbun test— 2167 pass, 2 pre-existing flaky failures indigitalocean-token.test.ts(addressed by fix(tests): use URL-aware fetch mocks to fix concurrent test pollution #3341)-- spawn-refactor/complexity-hunter