Skip to content

[Bug] delegate_task ignores parent runtime base_url/api_key when delegation.base_url is configured #26722

@NordicGoose

Description

@NordicGoose

Symptom

When a parent agent runs with runtime credentials that differ from the static delegation: config (e.g., the parent was instantiated against OpenAI Codex but delegation.base_url points to a local librarian endpoint), delegate_task hands the child the config default, not the parent's runtime base_url/api_key/provider. The child silently routes to the wrong endpoint.

Reproduction

tests/tools/test_delegate.py::TestDelegateTask::test_child_inherits_runtime_credentials fails on the current main branch:

parent.base_url = "https://chatgpt.com/backend-api/codex"
parent.provider = "openai-codex"
parent.api_mode = "codex_responses"

delegate_task(goal=..., parent_agent=parent)
# expected: child gets parent.base_url
# actual:   child gets delegation.base_url ("http://127.0.0.1:8091/v1")

AssertionError: 'http://127.0.0.1:8091/v1' != 'https://chatgpt.com/backend-api/codex'

Likely root cause

tools/delegate_tool.py:1018:

effective_base_url = override_base_url or parent_agent.base_url
effective_api_key = override_api_key or parent_api_key

override_base_url is populated from delegation.base_url in config. When that config key is set, it always wins over the parent's runtime value — there's no way to express "use the configured delegation endpoint only when the parent itself is using the static config."

Suggested approaches

  1. Invert the precedence: parent runtime > delegation config (closest to test intent).
  2. Add a "runtime credential override detected" check: if parent_agent.base_url differs from the system-default config base_url, treat that as an explicit override and inherit it.
  3. New delegation.inherit_parent_credentials: bool knob — opt in to runtime inheritance.

Impact

P2 — affects anyone using delegation while their parent agent runs on anything other than the static-config provider. Silent: the child runs to completion against the wrong endpoint, no error.

Environment

  • Discovered against current ~/.hermes/hermes-agent checkout, Python 3.11.15
  • One of two failures in a 23076-test pytest run

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Medium — degraded but workaround existsarea/configConfig system, migrations, profilescomp/agentCore agent loop, run_agent.py, prompt buildertool/delegateSubagent delegationtype/bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions