Skip to content

refactor(orchestrate): extract 3 helpers from 255-line runOrchestration#3347

Open
la14-1 wants to merge 1 commit intomainfrom
refactor/extract-orchestration-helpers
Open

refactor(orchestrate): extract 3 helpers from 255-line runOrchestration#3347
la14-1 wants to merge 1 commit intomainfrom
refactor/extract-orchestration-helpers

Conversation

@la14-1
Copy link
Copy Markdown
Member

@la14-1 la14-1 commented Apr 23, 2026

Why: The fast-mode and sequential orchestration paths in runOrchestration duplicated 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) — reads MODEL_ID env / saved preferences / agent default, validates with validateModelId()
  • buildEnvConfig(agent, apiKey, modelId, betaFeatures, spawnId) — builds env pairs, appends model + recursive vars, calls generateEnvConfig()
  • installAgentWithRetry(cloud, agent, agentName, options, allowTarball) — tarball-first install with fallback to live install retry loop

The behavioral difference in tarball eligibility between paths is preserved:

  • Fast path passes useTarball directly (already gated by cloudName !== "local" at the branch level)
  • Sequential path passes cloudName !== "local" && useTarball

runOrchestration drops from 255 to ~195 lines. Version bumped to 1.0.21.

Test plan

-- spawn-refactor/complexity-hunter

@la14-1 la14-1 force-pushed the refactor/extract-orchestration-helpers branch from a4babc2 to f7c88ac Compare April 25, 2026 08:21
@la14-1
Copy link
Copy Markdown
Member Author

la14-1 commented Apr 25, 2026

Rebased onto main to resolve merge conflicts (package.json version bump).

-- refactor/pr-maintainer

@la14-1
Copy link
Copy Markdown
Member Author

la14-1 commented Apr 25, 2026

Fixed CI: removed duplicate "version" key in packages/cli/package.json that was introduced during the rebase. bun install was failing with Duplicate key "version" in object literal. CI should pass now.

-- refactor/pr-maintainer

@la14-1
Copy link
Copy Markdown
Member Author

la14-1 commented Apr 26, 2026

This PR has been open for 3+ days with all CI checks passing (ShellCheck, Mock Tests, Biome Lint, Unit Tests, macOS Compatibility — all SUCCESS). It is mergeable with no conflicts.

Requesting human review when convenient.

-- refactor/pr-maintainer

@la14-1 la14-1 force-pushed the refactor/extract-orchestration-helpers branch from d5fc3ad to 2c8eb2a Compare April 29, 2026 06:48
@la14-1
Copy link
Copy Markdown
Member Author

la14-1 commented Apr 29, 2026

Rebased onto main (dropped the now-redundant duplicate-version-key fix commit). Branch is clean with 1 commit. Awaiting human review.

-- refactor/pr-maintainer

@la14-1 la14-1 force-pushed the refactor/extract-orchestration-helpers branch from 2c8eb2a to d0d1e05 Compare April 30, 2026 05:08
@la14-1
Copy link
Copy Markdown
Member Author

la14-1 commented May 3, 2026

This PR is ready for review. All CI checks pass and there are no merge conflicts.

-- refactor/pr-maintainer

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>
@la14-1 la14-1 force-pushed the refactor/extract-orchestration-helpers branch from d0d1e05 to 83683cd Compare May 3, 2026 14:19
@la14-1
Copy link
Copy Markdown
Member Author

la14-1 commented May 3, 2026

Rebased onto main (was 4 commits behind). Clean rebase, no conflicts.

-- refactor/pr-maintainer

@la14-1
Copy link
Copy Markdown
Member Author

la14-1 commented May 4, 2026

Verified in worktree: tests pass (2236/2238, same 2 pre-existing failures as main), lint clean (biome 0 errors). PR is mergeable and ready for review.

-- refactor/pr-maintainer

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.

2 participants