Skip to content

agent: warn when session model override is silently dropped by allowlist#37502

Closed
echoVic wants to merge 1 commit intoopenclaw:mainfrom
echoVic:fix/36134-sessions-spawn-model-ignored
Closed

agent: warn when session model override is silently dropped by allowlist#37502
echoVic wants to merge 1 commit intoopenclaw:mainfrom
echoVic:fix/36134-sessions-spawn-model-ignored

Conversation

@echoVic
Copy link
Copy Markdown
Contributor

@echoVic echoVic commented Mar 6, 2026

Summary

sessions_spawn targeting google/gemini-* models returns modelApplied: true but the sub-agent actually runs on the default Anthropic model. The model override is silently ignored with no log output, making this impossible to diagnose.

Root cause: In agentCommand (commands/agent.ts), there are two separate places where a stored session model override can be discarded if the model is not in allowedModelKeys and allowAnyModel=false:

  1. Lines 699–716: The override is cleared from the session entry and persisted back to disk (reset to default) — no log.
  2. Lines 726–733: The stored override is read but the if condition fails, so provider/model stay as default — no log.

Both drops are silent, so callers see modelApplied: true from the sessions.patch call (which only validates against the model catalog, not the runtime allowlist) but the agent runs on the wrong model.

Fix: Add log.warn() at both drop points with a message that identifies the model and points to the config keys needed to allow it (models.allowed / models.allowAny).

Fixes #36134

When sessions_spawn sets a google/gemini-* model override, modelApplied=true
is returned (the patch to the session store succeeds). But at agent run time,
if the model is not in the configured models.allowed set and models.allowAny
is false, the override is silently dropped and the agent runs on the default
Anthropic model instead.

Add log.warn() calls at both drop points in agentCommand so that the reason
is visible in gateway logs: once when the stored override is cleared from the
session entry, and once when the stored override is read but ignored at
provider/model assignment time.

Fixes openclaw#36134
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Mar 6, 2026

Greptile Summary

This PR adds log.warn() calls at the two code paths in agentCommandInternal where a session model override can be silently dropped because the model is not in the runtime allowlist — fixing a diagnosability gap where sessions_spawn callers would see modelApplied: true but the agent would run on the default model with no indication of why.

  • Block 1 (src/commands/agent.ts ~line 704): Warning is emitted before the stored override is cleared from the session entry and persisted to disk, giving the caller a clear signal that the stored override was invalid at runtime.
  • Block 2 (src/commands/agent.ts ~line 740): Warning is emitted in the new else branch for the case where the provider/model variables are not updated (e.g. when sessionStore or sessionKey is absent), so callers always see a warning regardless of whether the entry can be persisted.
  • No double-warning scenario exists: applyModelOverrideToSessionEntry(isDefault: true) deletes entry.modelOverride, ensuring Block 2's if (storedModelOverride) guard short-circuits when Block 1 has already run.
  • Both warning messages are actionable, naming the blocked model and pointing to the models.allowed / models.allowAny config keys.

Confidence Score: 5/5

  • Safe to merge — the change is purely additive (two log.warn calls) with no modifications to existing logic or state.
  • The diff is minimal and touches only two logging sites. The warning placement in both blocks is logically correct, the messages are actionable, and a double-warning race is provably impossible because applyModelOverrideToSessionEntry(isDefault: true) deletes modelOverride, causing Block 2's guard to short-circuit. No behavioural change was made to the actual model-selection logic.
  • No files require special attention.

Last reviewed commit: 5cd5e43

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

Labels

commands Command implementations size: XS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: sessions_spawn silently falls back to Anthropic (set fallback model) when targeting Google Gemini models on spawned subagent tasks.

2 participants