Skip to content

fix(delegation): honor api_key_env for direct endpoints#48605

Closed
Veritas-7 wants to merge 1 commit into
NousResearch:mainfrom
Veritas-7:veritas/delegation-api-key-env-t_03ef1d26-pub
Closed

fix(delegation): honor api_key_env for direct endpoints#48605
Veritas-7 wants to merge 1 commit into
NousResearch:mainfrom
Veritas-7:veritas/delegation-api-key-env-t_03ef1d26-pub

Conversation

@Veritas-7

Copy link
Copy Markdown
Contributor

Summary

  • Honor delegation.api_key_env for direct delegation endpoints when no literal delegation.api_key is configured.
  • Fail fast with a clear setup error if the configured env var is missing or empty, instead of silently inheriting the parent agent key.
  • Add regression coverage for env-present and env-missing direct endpoint cases.

Problem

Direct delegation endpoints can point at provider-specific APIs whose credentials live in provider-specific environment variables. Before this change, a direct endpoint config with api_key_env could still fall back to the parent agent key when the env value was unavailable, producing a confusing downstream 401 from the custom endpoint.

Tests

  • python -m py_compile tools/delegate_tool.py tests/tools/test_delegate.py
  • python -m pytest tests/tools/test_delegate.py -q -o 'addopts=' -k 'direct_endpoint_uses_configured_api_key_env or direct_endpoint_api_key_env_missing_or_empty_raises or DelegationCredentialResolution'
  • git diff --check origin/main..HEAD
  • gitleaks git --log-opts='origin/main..HEAD' --no-banner --redact
  • private/token regex scan over the final candidate diff

@alt-glitch alt-glitch added type/bug Something isn't working tool/delegate Subagent delegation area/auth Authentication, OAuth, credential pools P2 Medium — degraded but workaround exists duplicate This issue or pull request already exists labels Jun 18, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Duplicate of #48579 — same-author re-file of an identical fix to _resolve_delegation_credentials in tools/delegate_tool.py (honor delegation.api_key_env for direct endpoints, fail fast when the env var is missing). The chain is #48579 (earliest still-open, 18:31) then #48582 (closed), #48590 (closed), and this one (19:15). Anchoring to the earliest open twin #48579; the test fixtures (GLM_API_KEY/api.z.ai) and resolution logic are near-identical.

@Veritas-7 Veritas-7 force-pushed the veritas/delegation-api-key-env-t_03ef1d26-pub branch from 93b816e to a14a382 Compare June 18, 2026 19:26
@Veritas-7

Copy link
Copy Markdown
Contributor Author

Closing this as a duplicate/superseded branch for the same delegation api_key_env fix. Keeping #48579 as the canonical PR because it carries the same functional fix plus the attribution follow-up needed for CI. Local patch should remain retained until the canonical PR merges.

@Veritas-7 Veritas-7 closed this Jun 18, 2026
@Veritas-7

Copy link
Copy Markdown
Contributor Author

Thanks for flagging this, and apologies for the duplicate PR noise. #48605 was correctly closed as a duplicate of #48579. I'll keep #48579 as the canonical local-patch anchor until it merges, and I will avoid opening further duplicate PRs for this patch.

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

Labels

area/auth Authentication, OAuth, credential pools duplicate This issue or pull request already exists 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.

2 participants