Skip to content

fix: make spawned subagents follow the parent session's model - #115

Open
SergioGen wants to merge 1 commit into
vtemian:mainfrom
SergioGen:fix/subagent-model-follow
Open

fix: make spawned subagents follow the parent session's model#115
SergioGen wants to merge 1 commit into
vtemian:mainfrom
SergioGen:fix/subagent-model-follow

Conversation

@SergioGen

@SergioGen SergioGen commented Aug 23, 2026

Copy link
Copy Markdown

Problem

Subagents spawned via the spawn_agent tool create sessions through session.prompt without passing a model, so they fall back to the model baked into the agent config at plugin startup. Switching models with /models only affects the running session, so subagents keep using the stale model - after a rate limit they error out even though the user switched models.

Fix

  • Capture the live model from each chat.message into a per-session map
  • Inject it into the subagent session's session.prompt body, so subagents follow the parent session's model
  • Propagate the model to child sessions so nested spawns (e.g. executor -> implementer) keep following it
  • Clean up the map entry on session.deleted

Changes

  • src/session-model.ts (new): in-memory session model map with get/set/delete accessors
  • src/index.ts: capture model in chat.message, clean up on session.deleted
  • src/tools/spawn-agent.ts: inject and propagate the parent session model
  • tests/session-model.test.ts (new): 3 unit tests for the map helpers

Verification

  • tsc --noEmit: pass
  • eslint: pass
  • biome check: pass
  • bun test: not run locally (no bun available) - CI should run it

Summary by cubic

Spawned subagents now inherit the parent session’s active model. Previously, spawn_agent sessions ignored /models and fell back to the startup-baked model, which could trigger rate-limit errors.

  • Capture the active model from each chat.message, store it in-memory per session, and include it in spawn_agent session.prompt; also set it on the child so nested spawns follow.
  • Delete the stored model on session.deleted.
  • Add src/session-model.ts and unit tests for get/set/delete of the session model map.

Written for commit fb01e92. Summary will update on new commits.

Review in cubic

The spawn_agent tool created subagent sessions via session.prompt without
passing a model, so they fell back to the model baked into the agent config
at plugin startup. Switching models with /models only affects the running
session, so subagents kept using the stale model and errored out after a
rate limit.

Capture the active model from each chat.message and replay it onto child
sessions (including nested spawns like executor -> implementer).
@SergioGen
SergioGen force-pushed the fix/subagent-model-follow branch from 9da58cd to fb01e92 Compare August 23, 2026 05:36

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found and verified against the latest diff

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="src/tools/spawn-agent.ts">

<violation number="1" location="src/tools/spawn-agent.ts:68">
P2: When an agent has a `micode.json` model override, this request-level `model` replaces that explicit per-agent choice for every spawned run. Resolve the task agent's configured override first, and inherit the parent model only when no per-agent model is configured.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread src/tools/spawn-agent.ts
body: {
parts: [{ type: "text", text: task.prompt }],
agent: task.agent,
...(model ? { model } : {}),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: When an agent has a micode.json model override, this request-level model replaces that explicit per-agent choice for every spawned run. Resolve the task agent's configured override first, and inherit the parent model only when no per-agent model is configured.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/tools/spawn-agent.ts, line 68:

<comment>When an agent has a `micode.json` model override, this request-level `model` replaces that explicit per-agent choice for every spawned run. Resolve the task agent's configured override first, and inherit the parent model only when no per-agent model is configured.</comment>

<file context>
@@ -58,15 +59,20 @@ async function executeAgentSession(ctx: PluginInput, task: AgentTask): Promise<s
     body: {
       parts: [{ type: "text", text: task.prompt }],
       agent: task.agent,
+      ...(model ? { model } : {}),
     },
     query: { directory: ctx.directory },
</file context>

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.

1 participant