Skip to content

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

Merged
vtemian merged 2 commits into
vtemian:mainfrom
SergioGen:fix/subagent-model-follow
Sep 10, 2026
Merged

fix: make spawned subagents follow the parent session's model#115
vtemian merged 2 commits into
vtemian:mainfrom
SergioGen:fix/subagent-model-follow

Conversation

@SergioGen

@SergioGen SergioGen commented Aug 23, 2026

Copy link
Copy Markdown
Contributor

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 follow the parent session's active model instead of falling back to the model baked in at plugin startup, which caused rate-limit errors after switching with /models.

  • Capture the active model from each chat.message, replay it onto spawn_agent child sessions, and propagate it so nested spawns keep following it.
  • Agents with an explicit model in micode.json keep it—their override wins over the parent session's live model.
  • Delete the stored model on session.deleted.
  • Add src/session-model.ts and unit tests for the session-model map helpers.

Written for commit c0323ab. 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.

All reported issues were addressed

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

Re-trigger cubic

Comment thread src/tools/spawn-agent.ts
@vtemian
vtemian merged commit 7ec8a97 into vtemian:main Sep 10, 2026
2 checks passed
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