Skip to content

fix: guard against None model in call_utility_model to prevent crash#1460

Open
gdeyoung wants to merge 1 commit intoagent0ai:mainfrom
gdeyoung:fix/none-model-guard-utility-v17
Open

fix: guard against None model in call_utility_model to prevent crash#1460
gdeyoung wants to merge 1 commit intoagent0ai:mainfrom
gdeyoung:fix/none-model-guard-utility-v17

Conversation

@gdeyoung
Copy link
Copy Markdown
Contributor

@gdeyoung gdeyoung commented Apr 6, 2026

TL;DR — Agent crashes when utility model resolution returns None

call_utility_model() gets the model name from get_utility_model() but never checks if it's None. If model resolution fails (missing config, bad provider name, etc.), the agent crashes with an unhandled exception. A simple None guard logs a warning and returns an empty string, allowing the agent to continue operating.

One defensive check prevents a crash when model configuration is incomplete.


Problem

In agent.py, call_utility_model() at line ~759:

model = self.get_utility_model()

# Immediately used without checking if None
# call extensions
call_data = {"model": model, ...}

When get_utility_model() returns None (e.g., missing utility_model in settings, provider not configured), the agent crashes instead of gracefully degrading.

Solution

Add a None guard immediately after model resolution:

model = self.get_utility_model()

if model is None:
    self.context.log.log(
        type="warning",
        heading="Utility model unavailable",
        content="build_utility_model returned None — skipping utility call.",
    )
    return ""

The agent logs a warning and continues operating instead of crashing.

Impact

  • Before: Agent crashes when utility model is misconfigured or unavailable
  • After: Agent logs warning, skips the utility call, continues operating
  • Common trigger: Fresh installs, config migration, provider outages

Changes

File Change
agent.py Add if model is None guard after get_utility_model()

Testing

  • 2 regression tests verify None model returns empty string
  • 21/21 tests passing across all critical patches

Related

When get_utility_model() returns None (e.g., model resolution failure,
missing config), the agent crashes trying to use it. Add a defensive
guard that logs a warning and returns empty string instead.
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.

1 participant