Skip to content

fix(delegate): inherit parent fallback_chain in _build_child_agent - #19136

Closed
nftpoetrist wants to merge 2 commits into
NousResearch:mainfrom
nftpoetrist:fix/delegate-inherit-fallback-chain
Closed

fix(delegate): inherit parent fallback_chain in _build_child_agent#19136
nftpoetrist wants to merge 2 commits into
NousResearch:mainfrom
nftpoetrist:fix/delegate-inherit-fallback-chain

Conversation

@nftpoetrist

Copy link
Copy Markdown
Contributor

Root Cause

_build_child_agent constructed every child AIAgent without passing fallback_model, so _fallback_chain = [] for all subagents.

When a subagent hit a rate-limit or exhausted its credential pool, the runtime fallback check in run_agent.py found an empty chain and failed immediately — even though the parent agent had fallback_providers configured and would have recovered from the same error.

# run_agent.py — runtime fallback check (lines 7486, 12267)
if self._fallback_index >= len(self._fallback_chain):
    # child always lands here: 0 >= 0 → no fallback attempted

Parity Gap

The cron scheduler already propagates fallback_model correctly:

# cron/scheduler.py:1038
agent = AIAgent(..., fallback_model=fallback_model, ...)

_build_child_agent was missing the equivalent pass-through.

Fix

Read the parent's _fallback_chain (the normalised list form that AIAgent.__init__ already accepts via its fallback_model parameter) and pass it to the child:

parent_fallback = getattr(parent_agent, "_fallback_chain", None) or None

child = AIAgent(
    ...
    fallback_model=parent_fallback,
    ...
)

Empty chains coerce to None so AIAgent initialises _fallback_chain = [] as usual rather than re-filtering an empty list.

Test Plan

  • test_child_inherits_fallback_chain — verifies non-empty _fallback_chain is passed as fallback_model
  • test_child_gets_no_fallback_when_parent_chain_empty — verifies empty chain produces fallback_model=None
  • Both tests pass (2 passed)

_setup_slack() was the only platform setup function that did not prompt
for a home channel. All four sibling setups (_setup_telegram,
_setup_discord, _setup_mattermost, _setup_bluebubbles) close with an
identical home-channel block, and setup_gateway() already checks for
SLACK_HOME_CHANNEL presence at the end of the wizard — but the value
was never collected, leaving cron delivery and cross-platform
notifications silently broken for Slack after a fresh hermes setup run.

Add the standard home-channel prompt at the end of _setup_slack(),
symmetric with the Discord implementation. Add two unit tests that
verify the prompt is saved when provided and skipped when left blank.
_build_child_agent constructed child AIAgents without passing
fallback_model, leaving _fallback_chain=[] for every subagent.
When a subagent hit a rate-limit or credential exhaustion the
runtime fallback check (run_agent.py:7486 / 12267) found an empty
chain and failed immediately — even though the parent agent was
configured with fallback_providers and would have recovered.

The cron scheduler already propagates fallback_model correctly
(scheduler.py:1038). Fix closes the parity gap by reading the
parent's _fallback_chain (the normalised list form accepted by
AIAgent's fallback_model parameter) and threading it through.

Empty chains coerce to None so AIAgent initialises _fallback_chain=[]
as usual rather than iterating an empty list.
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists tool/delegate Subagent delegation comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint labels May 3, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Related to #15285 (closed, same fix). Verify #15285 was rejected vs just abandoned before merging this.

@alt-glitch

Copy link
Copy Markdown
Collaborator

Related to closed #15285.

@teknium1

teknium1 commented May 4, 2026

Copy link
Copy Markdown
Contributor

Salvaged via #19601 onto current main — the delegate fix commit was cherry-picked with your authorship preserved. The Slack setup commit from the same branch was salvaged separately as #19583. Thanks @nftpoetrist!

@teknium1 teknium1 closed this May 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint P2 Medium — degraded but workaround exists tool/delegate Subagent delegation type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants