#11474: fix(cron): respect subagents.model in isolated cron sessions
agents
stale
Cluster:
Cron Session Enhancements
#### Summary
Fixes #11461
`agents.defaults.subagents.model` is ignored when spawning isolated cron sessions. All isolated sessions fall back to `agents.defaults.model.primary`, regardless of the subagents config. This means users can't use cheaper local models (e.g. Ollama) for background cron work while keeping premium models for interactive sessions.
lobster-biscuit
#### Repro Steps
1. Configure `agents.defaults.subagents.model` to a different model than the main agent model:
```json
{
"agents": {
"defaults": {
"model": { "primary": "anthropic/claude-sonnet-4-5" },
"subagents": { "model": "ollama/llama3.2:3b" }
}
}
}
```
2. Create a cron job with `sessionTarget: "isolated"` (no explicit `--model`)
3. Run the job
4. Observe the session uses `anthropic/claude-sonnet-4-5` instead of `ollama/llama3.2:3b`
#### Root Cause
In `src/cron/isolated-agent/run.ts`, `resolveConfiguredModelRef()` only checks `cfg.agents.defaults.model.primary` and never checks `cfg.agents.defaults.subagents.model`. The correct pattern already exists in `sessions-spawn-tool.ts` which properly resolves subagent models.
#### Behavior Changes
- Isolated cron sessions now respect `agents.defaults.subagents.model` (and per-agent `subagents.model`) when selecting the default model.
- Precedence chain: explicit job model > gmail hook model > subagents.model > main model.
- No change when `subagents.model` is not configured (falls back to main model as before).
- Extracted `normalizeModelSelection` from `sessions-spawn-tool.ts` into shared `model-selection.ts` to avoid duplication.
#### Codebase and GitHub Search
- Searched `sessions-spawn-tool.ts` for reference implementation of subagent model resolution.
- Verified `resolveConfiguredModelRef` only checks `agents.defaults.model`, confirmed the gap.
- Confirmed no existing PRs targeting #11461.
#### Tests
- **4 new integration tests** (`isolated-agent.subagent-model.test.ts`):
- Uses `subagents.model` when set (string format)
- Explicit job model override takes precedence over `subagents.model`
- Falls back to main model when `subagents.model` is unset
- Supports `{primary}` object format for `subagents.model`
- **5 new unit tests** (`model-selection.test.ts`): `normalizeModelSelection` utility coverage
- All 963 test files / 6523 tests pass
#### Manual Testing
N/A — fully covered by automated tests.
**Sign-Off**
- Models used: Claude (AI-assisted)
- Submitter effort: read issue, traced code, implemented fix + tests, ran full gate
- Agent notes: The fix mirrors the existing `sessions-spawn-tool.ts` pattern. `normalizeModelSelection` was extracted to a shared module to avoid duplication.
Made with [Cursor](https://cursor.com)
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This change fixes isolated cron sessions to respect `agents.defaults.subagents.model` (and per-agent `subagents.model`) when choosing the default model, matching the existing behavior in `sessions-spawn-tool.ts`. To avoid duplication, it extracts `normalizeModelSelection` into `src/agents/model-selection.ts` and adds unit + integration coverage for the new resolution behavior.
<h3>Confidence Score: 3/5</h3>
- This PR is close to mergeable but has a model-allowlist enforcement gap in cron isolated sessions.
- Core change is small and well-tested, but the new `subagents.model` resolution path in `runCronIsolatedAgentTurn` does not enforce the model allowlist in the way the explicit job override does, which can lead to running disallowed models in allowlist configurations.
- src/cron/isolated-agent/run.ts
<!-- greptile_other_comments_section -->
**Context used:**
- Context from `dashboard` - CLAUDE.md ([source](https://app.greptile.com/review/custom-context?memory=fd949e91-5c3a-4ab5-90a1-cbe184fd6ce8))
- Context from `dashboard` - AGENTS.md ([source](https://app.greptile.com/review/custom-context?memory=0d0c8278-ef8e-4d6c-ab21-f5527e322f13))
<!-- /greptile_comment -->
Most Similar PRs
#16303: fix: apply cron payload.model override to session entry and pass au...
by superlowburn · 2026-02-14
84.7%
#21279: Fix/sessions list cron model override
by altaywtf · 2026-02-19
83.1%
#12310: cron: pass agentDir to embedded runner for isolated sessions
by magendary · 2026-02-09
82.6%
#19385: fix: pass authProfileId from cron session to runEmbeddedPiAgent
by gigi-trifle · 2026-02-17
82.2%
#11562: Fix #10883: Enforce subagent model configuration
by divol89 · 2026-02-08
81.6%
#11816: fix(cron): forward agent-specific exec config to isolated cron sess...
by AnonO6 · 2026-02-08
81.1%
#20712: fix(subagents): prioritize agent runtime default model over global ...
by sourcesavant · 2026-02-19
81.0%
#16390: fix(cron): jobs land in wrong agent session when agentId isn't in a...
by yinghaosang · 2026-02-14
80.8%
#13376: fix: pass model directly to agent for sub-agent runs
by jrbobbyhansen-pixel · 2026-02-10
78.8%
#23501: fix(cron): force new session ID for isolated cron jobs (#23470)
by stakeswky · 2026-02-22
78.5%