fix: inherit parent instance's active model in subagents#210
Open
ravshansbox wants to merge 1 commit into
Open
fix: inherit parent instance's active model in subagents#210ravshansbox wants to merge 1 commit into
ravshansbox wants to merge 1 commit into
Conversation
When a subagent has no explicit model set (either via params or agent frontmatter), the spawned child pi process receives no --model flag and falls back to reading settings.json. This means whichever pi instance last wrote to settings.json determines the model, not the instance that spawned the subagent. Fix by passing ctx.model?.fullId as a final fallback in all four resolveModelCandidate call sites (single, async single, parallel, chain). The fully-qualified model id (e.g. anthropic/claude-sonnet-4) passes through resolveModelCandidate unchanged since it already contains a provider prefix. Priority is now: 1. Explicit model in subagent call params 2. model: field in agent frontmatter 3. Current instance's active model (ctx.model?.fullId) 4. Nothing → child pi reads settings.json
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.
Fixes #209
Problem
When multiple Pi instances run simultaneously with different models, subagents always fall back to
settings.json(shared on disk). Whichever instance last changed its model wins — not the instance that spawned the subagent.The parent's active model (
ctx.model?.fullId) was available but only used for provider disambiguation, never forwarded to the child.Fix
Add
ctx.model?.fullIdas a final fallback in all fourresolveModelCandidatecall sites (single, async single, parallel, chain) insubagent-executor.ts:Priority order after fix
modelin subagent call paramsmodel:in agent frontmattersettings.jsonSince
ctx.model?.fullIdis already fully qualified (e.g.anthropic/claude-sonnet-4), it passes throughresolveModelCandidateunchanged via the existingmodel.includes("/")early return.Testing
Pre-existing test suite: 415 pass, 9 fail — identical before and after (failures are due to missing peer dependency in test environment, unrelated to this change).