Skip to content

Custom agent roles discard explicit spawn model/reasoning when the role leaves them unset #32831

Open

Description

@pma1999

What version of Codex CLI is running?

codex-cli 0.144.3

Runtime reproduction: Windows 10.0.26200 x64, PowerShell 7.5.8, GPT-5.6 Sol parent using Multi-Agent V2.

I also source-checked current main after #32749. The same role-application order remains in both V1 and V2.

What issue are you seeing?

An explicit model / reasoning_effort supplied to spawn_agent is discarded when a custom agent_type is selected, even when that role does not configure either field.

The role itself is selected correctly and its developer instructions are loaded, but the child falls back to the parent model/reasoning instead of using the explicit spawn request.

This is distinct from #31814 and the schema fix merged in #32749. #32749 makes V2 model overrides callable by default, but selecting a custom role still discards them during role application.

What steps can reproduce the bug?

Register a custom role:

# config.toml
[agents.probe]
description = "Minimal custom role used to verify spawn routing."
config_file = "agents/probe.toml"

Give the role instructions but deliberately leave model and reasoning unset:

# agents/probe.toml
developer_instructions = "Reply with exactly PROBE_OK."

For Codex CLI 0.144.3, expose the V2 routing fields:

[features.multi_agent_v2]
hide_spawn_agent_metadata = false
tool_namespace = "agents"

From a GPT-5.6 Sol parent, issue a context-free V2 spawn equivalent to:

{
  "task_name": "probe",
  "message": "Reply with exactly PROBE_OK.",
  "fork_turns": "none",
  "agent_type": "probe",
  "model": "gpt-5.6-luna",
  "reasoning_effort": "low"
}

Observed child configuration:

agent_role = probe
model = gpt-5.6-sol
reasoning_effort = low

The custom developer instructions are active, confirming that the role resolved successfully. A follow-up sent to the same child remains on Sol/low.

Control: spawning the built-in worker with the same explicit Luna/low request produces a Luna/low child, and follow-up retains Luna/low.

A custom role that explicitly pins Terra/high produces Terra/high. That locked-role behavior is expected and should remain unchanged.

Root cause

Both handlers apply the explicit model override first and the role second:

apply_role_to_config() rebuilds Config from the layer stack. A transient spawn-time model/reasoning override is not represented in that stack, so applying a role with no model settings restores the parent values:

https://github.com/openai/codex/blob/main/codex-rs/core/src/agent/role.rs#L56-L84

Role-defined model/reasoning settings are intentionally locked. That contract is surfaced in role guidance and was also used as the precedence model in #22169. The unexpected case is specifically a role that leaves one or both settings unspecified.

What is the expected behavior?

Resolve model and reasoning independently:

  1. If the effective role configuration defines model, the role model remains locked and wins.
  2. If it does not define model, an explicit spawn-time model survives role application.
  3. Apply the same rule independently to model_reasoning_effort.
  4. With no explicit spawn override, preserve current inheritance behavior.
  5. Keep full-history fork restrictions and service-tier behavior unchanged.

This is backwards-compatible for pinned roles while allowing custom roles to provide instructions, tools, permissions, and sandbox settings without preventing per-task model routing.

The effective-role check should account for profile-scoped values, not only top-level TOML keys.

Suggested regression coverage:

  • V1 and V2: model-free role + explicit model/reasoning preserves both.
  • V1 and V2: pinned role continues to override conflicting spawn values.
  • Partial lock: role pins only model or only reasoning; the other explicit field survives.
  • No explicit override continues to inherit.
  • Follow-up retains the resolved child configuration.
  • Full-history override rejection remains unchanged.

Additional information

No open issue or PR matching this narrower precedence bug was found.

Per the repository's invitation-only contribution policy, I have not opened an unsolicited PR. If maintainers agree with this behavior, I would be happy to prepare a focused implementation with V1/V2 integration coverage.

Activity

  1. added
    bug
    CLI
    windows-os
    subagent
    config
    on Jul 13, 2026
  2. eitsupi commented on Jul 18, 2026

    @eitsupi

    I investigated this against current main at 23899f7.
    The fresh-spawn role precedence reported here appears to have been addressed by #33631/#33656, but I found a related lifecycle regression that still loses the effective child settings after a cold reload.

    ensure_v2_agent_loaded and the rollout resume path read the stored child thread but did not restore its persisted model and reasoning_effort; they rebuilt the child from the parent config and then reapplied the role. As a result, an instructions-only custom role plus explicit spawn-time overrides worked initially, but a later cold followup_task/resume could silently revert to the parent model/effort.

    I prepared a reference implementation here:

    eitsupi@e43cd46c3

    It:

    • restores persisted effective model/effort before reapplying the role, preserving role-pinned values as the higher precedence;
    • changes the existing cold-resume integration test to cover an unpinned custom role plus spawn-time overrides;
    • clarifies reasoning_effort (tool field) vs model_reasoning_effort (role TOML);
    • carries effective model/effort through MultiAgent V2 activity metadata and the TUI, with protocol/integration/unit coverage.

    The app-server protocol/schema generator completed successfully and codex-protocol / codex-app-server-protocol compiled.

    I have not opened a PR because the repository contribution policy requires an explicit maintainer invitation, but the commit is available for maintainers to reuse or cherry-pick.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    CLIbugconfigsubagentwindows-os

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions