Skip to content

fix(gateway): guard request_overrides None crash in message flow - #8176

Closed
atongrun wants to merge 2 commits into
NousResearch:mainfrom
atongrun:fix/request-overrides-none-crash
Closed

fix(gateway): guard request_overrides None crash in message flow#8176
atongrun wants to merge 2 commits into
NousResearch:mainfrom
atongrun:fix/request-overrides-none-crash

Conversation

@atongrun

Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes a gateway crash path where turn_route.get("request_overrides") can be None, but downstream agent code assumes a dict and calls .get("speed"). In messaging flows this breaks request construction before the provider call and can also trigger a secondary api_kwargs error while handling the failure.

Related Issue

Fixes #

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • ✨ New feature (non-breaking change that adds functionality)
  • 🔒 Security fix
  • 📝 Documentation update
  • ✅ Tests (adding or improving test coverage)
  • ♻️ Refactor (no behavior change)
  • 🎯 New skill (bundled or hub)

Changes Made

  • In gateway/run.py, normalize turn_route.get("request_overrides") to an empty dict before assigning it to the cached agent.
  • In run_agent.py, guard the Anthropic fast_mode lookup with an empty-dict fallback.
  • In run_agent.py, initialize api_kwargs = None before the retry loop and only dump API request debug data when it exists, preventing a secondary UnboundLocalError from masking the original failure.

How to Test

  1. Configure a gateway flow where turn_route omits request_overrides or returns None.
  2. Send a Telegram or gateway message that reaches GatewayRunner._run_agent().
  3. Confirm the agent no longer crashes with NoneType object has no attribute get in _build_api_kwargs and does not emit the secondary UnboundLocalError for api_kwargs.
  4. Manual validation performed on Ubuntu 24.04 against a live Telegram-backed Hermes gateway instance.

Checklist

Code

  • I have read the Contributing Guide
  • My commit messages follow Conventional Commits
  • I searched for existing PRs to make sure this is not a duplicate
  • My PR contains only changes related to this fix
  • I have run pytest tests/ -q and all tests pass
  • I have added tests for my changes
  • I have tested on my platform: Ubuntu 24.04

Documentation & Housekeeping

  • Documentation update not needed
  • Config example update not needed
  • CONTRIBUTING or AGENTS update not needed
  • Cross-platform impact considered
  • Tool descriptions or schemas update not needed

Screenshots / Logs

Observed failure before the fix in a live gateway session:

  • AttributeError: NoneType object has no attribute get at run_agent.py while building API kwargs
  • Followed by a secondary UnboundLocalError for api_kwargs during error handling

@teknium1

Copy link
Copy Markdown
Contributor

Thanks for this careful bug report and fix, @atongrun! After reviewing main, all three crash paths this PR addresses are already resolved by prior commits.

Automated hermes-sweeper review — verifying against current main:

The one gap (gateway's direct attribute assignment at gateway/run.py:10182 can still set request_overrides = None) is latent but harmless since the only consumer already uses (self.request_overrides or {}). Closing as implemented on main.

@teknium1 teknium1 closed this Apr 28, 2026
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.

2 participants