Problem
When spawning subagents with a specific agent_type (e.g. executor), the model is hardcoded in the agent TOML file (e.g. model = "gpt-5.6-sol"). If that model hits its usage limit (e.g. ChatGPT Plus quota exhausted), the subagent fails immediately with no recovery path:
Spawned 019f91d5-... (gpt-5.6-sol medium)
└ errored: "You've hit your usage limit..."
Currently there is no fallback mechanism — the model parameter in spawn_agent is a single string, and the agent TOML schema has no fallback_model or model_chain field. The autoSwitchThreshold only rotates between multiple accounts within the same provider, not across different models/providers.
Proposed Solution
A quota-aware model fallback chain for subagent spawning:
1. Model fallback chain in config
Allow subagentModels (or a new subagentModelFallback) to define a priority-ordered fallback list:
{
"subagentModelFallback": [
"gpt-5.6-sol",
"alibaba-token-plan/qwen3.8-max-preview",
"kimi/k3"
]
}
When the primary model fails with a quota/rate-limit error, automatically retry with the next model in the chain.
2. Periodic quota polling
A background task (or pre-flight check before each spawn) that queries usage/quota for each configured provider:
- OpenAI Codex account usage (already available via
getAccountQuota)
- Third-party provider health (e.g.
/v1/models reachability, recent error rates from usage.jsonl)
Cache the results with a short TTL (e.g. 60s) to avoid excessive polling.
3. Priority-based routing
When spawning a subagent:
- Check the agent TOML's
model field (current behavior)
- If that model's provider is known to be quota-exhausted or unhealthy, skip to the next available model in the fallback chain
- Optionally override the agent TOML model entirely if
subagentModelFallback is configured and the TOML model is unavailable
4. Agent TOML extension (optional)
Allow per-role fallback in the TOML itself:
name = "executor"
model = "gpt-5.6-sol"
model_fallback = ["alibaba-token-plan/qwen3.8-max-preview"]
Use Case
Users running opencodex with a ChatGPT Plus account (limited quota) plus third-party providers (Alibaba MaaS, Codebuddy, Kimi, etc.) as alternatives. When the Plus quota is exhausted, subagents should seamlessly fall back to available third-party models instead of failing.
Environment
- opencodex v2.7.31
- macOS (aarch64)
- Providers: openai (Plus), alibaba-token-plan, kimi, sports
autoSwitchThreshold: 0 (only one OpenAI account, so account rotation is not applicable)
Alternatives Considered
- Manually editing agent TOML files to change the model — works but fragile, overwritten by
omx setup
- Always passing
model explicitly in spawn_agent — puts the burden on the caller, no auto-recovery
- Not specifying
agent_type to inherit leader model — loses role-specific system prompts
Problem
When spawning subagents with a specific
agent_type(e.g.executor), the model is hardcoded in the agent TOML file (e.g.model = "gpt-5.6-sol"). If that model hits its usage limit (e.g. ChatGPT Plus quota exhausted), the subagent fails immediately with no recovery path:Currently there is no fallback mechanism — the
modelparameter inspawn_agentis a single string, and the agent TOML schema has nofallback_modelormodel_chainfield. TheautoSwitchThresholdonly rotates between multiple accounts within the same provider, not across different models/providers.Proposed Solution
A quota-aware model fallback chain for subagent spawning:
1. Model fallback chain in config
Allow
subagentModels(or a newsubagentModelFallback) to define a priority-ordered fallback list:{ "subagentModelFallback": [ "gpt-5.6-sol", "alibaba-token-plan/qwen3.8-max-preview", "kimi/k3" ] }When the primary model fails with a quota/rate-limit error, automatically retry with the next model in the chain.
2. Periodic quota polling
A background task (or pre-flight check before each spawn) that queries usage/quota for each configured provider:
getAccountQuota)/v1/modelsreachability, recent error rates fromusage.jsonl)Cache the results with a short TTL (e.g. 60s) to avoid excessive polling.
3. Priority-based routing
When spawning a subagent:
modelfield (current behavior)subagentModelFallbackis configured and the TOML model is unavailable4. Agent TOML extension (optional)
Allow per-role fallback in the TOML itself:
Use Case
Users running opencodex with a ChatGPT Plus account (limited quota) plus third-party providers (Alibaba MaaS, Codebuddy, Kimi, etc.) as alternatives. When the Plus quota is exhausted, subagents should seamlessly fall back to available third-party models instead of failing.
Environment
autoSwitchThreshold: 0(only one OpenAI account, so account rotation is not applicable)Alternatives Considered
omx setupmodelexplicitly inspawn_agent— puts the burden on the caller, no auto-recoveryagent_typeto inherit leader model — loses role-specific system prompts