Skip to content

fix(delegate): lease child pool credentials per task - #5580

Closed
MestreY0d4-Uninter wants to merge 2 commits into
NousResearch:mainfrom
MestreY0d4-Uninter:fix/delegation-child-credential-leasing
Closed

fix(delegate): lease child pool credentials per task#5580
MestreY0d4-Uninter wants to merge 2 commits into
NousResearch:mainfrom
MestreY0d4-Uninter:fix/delegation-child-credential-leasing

Conversation

@MestreY0d4-Uninter

Copy link
Copy Markdown
Contributor

Summary

This PR adds lightweight lease management for delegated child agents that already have access to a credential pool.

Without leases, multiple parallel children can still stampede the same credential even when the pool has other available entries. That weakens the benefit of child pool participation under concurrent delegation.

This patch keeps the scope intentionally small:

  • add soft leases to CredentialPool
  • acquire a lease before a child runs
  • bind the child to the leased credential
  • release the lease in finally, even on errors

What changed

  • agent/credential_pool.py
    • add DEFAULT_MAX_CONCURRENT_PER_CREDENTIAL = 1
    • add acquire_lease()
    • add release_lease()
    • add active_lease_count()
  • tools/delegate_tool.py
    • _run_single_child() now acquires a lease when the child has a credential pool
    • binds the child to the leased entry via _swap_credential()
    • releases the lease in finally
  • tests added for:
    • least-leased selection
    • lease release
    • child acquire/release behavior on success
    • child acquire/release behavior on failure

Why

This is the next minimal extraction after #5576.

It still avoids the larger/more invasive pieces from #5374:

  • no task tiers
  • no structured failure classification
  • no Retry-After parsing
  • no fallback precedence rewrite

Validation

Automated

  • /home/ubuntu/.hermes/hermes-agent/venv/bin/python -m py_compile agent/credential_pool.py tools/delegate_tool.py tests/tools/test_delegate.py tests/test_credential_pool.py

  • /home/ubuntu/.hermes/hermes-agent/venv/bin/python -m pytest -q -o addopts='' tests/tools/test_delegate.py -k 'ChildCredentialPoolResolution or ChildCredentialLeasing or DelegationProviderIntegration'

  • Result: 15 passed, 44 deselected

  • /home/ubuntu/.hermes/hermes-agent/venv/bin/python -m pytest -q -o addopts='' tests/test_credential_pool.py -k 'acquire_lease or release_lease'

  • Result: 2 passed, 24 deselected

Additional combined focused check:

  • /home/ubuntu/.hermes/hermes-agent/venv/bin/python -m pytest -q -o addopts='' tests/tools/test_delegate.py tests/test_credential_pool.py -k 'ChildCredentialPoolResolution or ChildCredentialLeasing or DelegationProviderIntegration or acquire_lease or release_lease'
  • Result: 17 passed, 68 deselected

Related context

Scope notes

This PR should be reviewed as a follow-up slice, not as a standalone replacement for all credential-pool hardening work.

teknium1 pushed a commit that referenced this pull request Apr 7, 2026
Cherry-picked from PR #5580 by MestreY0d4-Uninter.

- Share parent's credential pool with child agents for key rotation
- Leasing layer spreads parallel children across keys (least-loaded)
- Thread-safe acquire_lease/release_lease in CredentialPool
- Reverted sneaked-in tool-name restoration change (kept original
  getattr + isinstance guard pattern)
teknium1 pushed a commit that referenced this pull request Apr 7, 2026
Cherry-picked from PR #5580 by MestreY0d4-Uninter.

- Share parent's credential pool with child agents for key rotation
- Leasing layer spreads parallel children across keys (least-loaded)
- Thread-safe acquire_lease/release_lease in CredentialPool
- Reverted sneaked-in tool-name restoration change (kept original
  getattr + isinstance guard pattern)
@teknium1

teknium1 commented Apr 7, 2026

Copy link
Copy Markdown
Contributor

Merged via PR #5748. Both commits cherry-picked with authorship preserved. Removed the sneaked-in tool-name restoration change (kept original getattr + isinstance guard). Thanks @MestreY0d4-Uninter!

gagan114662 added a commit to gagan114662/hermes-agent that referenced this pull request Apr 9, 2026
Five symbols were removed from our fork when the upstream merge used
--theirs on conflicting files:

- tools/registry.py: add ContextModifier dataclass + is_concurrency_safe
  support to ToolEntry and register() (our B9 feature)
- hermes_cli/plugins.py: add emit_hook() fire-and-forget helper (our B6 feature)
- model_tools.py: add coerce_tool_args/_coerce_value/_coerce_number/
  _coerce_boolean (exists in upstream, was absent in our fork)
- tools/environments/local.py: add _OUTPUT_FENCE, _clean_shell_noise,
  _extract_fenced_output helpers
- tools/delegate_tool.py: add _resolve_child_credential_pool (from
  PR NousResearch#5580 credential pool sharing)

All five were referenced by existing tests that were failing at collection.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Tommyeds pushed a commit to Tommyeds/hermes-agent that referenced this pull request Apr 12, 2026
Cherry-picked from PR NousResearch#5580 by MestreY0d4-Uninter.

- Share parent's credential pool with child agents for key rotation
- Leasing layer spreads parallel children across keys (least-loaded)
- Thread-safe acquire_lease/release_lease in CredentialPool
- Reverted sneaked-in tool-name restoration change (kept original
  getattr + isinstance guard pattern)
@MestreY0d4-Uninter
MestreY0d4-Uninter deleted the fix/delegation-child-credential-leasing branch April 27, 2026 01:42
angelburgosrosado pushed a commit to angelburgosrosado/hermes-agent that referenced this pull request Apr 27, 2026
Cherry-picked from PR NousResearch#5580 by MestreY0d4-Uninter.

- Share parent's credential pool with child agents for key rotation
- Leasing layer spreads parallel children across keys (least-loaded)
- Thread-safe acquire_lease/release_lease in CredentialPool
- Reverted sneaked-in tool-name restoration change (kept original
  getattr + isinstance guard pattern)
02356abc pushed a commit to 02356abc/hermes-agent that referenced this pull request May 14, 2026
Cherry-picked from PR NousResearch#5580 by MestreY0d4-Uninter.

- Share parent's credential pool with child agents for key rotation
- Leasing layer spreads parallel children across keys (least-loaded)
- Thread-safe acquire_lease/release_lease in CredentialPool
- Reverted sneaked-in tool-name restoration change (kept original
  getattr + isinstance guard pattern)
gweeteve pushed a commit to gweeteve/hermes-agent that referenced this pull request Jun 2, 2026
Cherry-picked from PR NousResearch#5580 by MestreY0d4-Uninter.

- Share parent's credential pool with child agents for key rotation
- Leasing layer spreads parallel children across keys (least-loaded)
- Thread-safe acquire_lease/release_lease in CredentialPool
- Reverted sneaked-in tool-name restoration change (kept original
  getattr + isinstance guard pattern)
waefrebeorn pushed a commit to waefrebeorn/slermes that referenced this pull request Jul 2, 2026
Cherry-picked from PR NousResearch#5580 by MestreY0d4-Uninter.

- Share parent's credential pool with child agents for key rotation
- Leasing layer spreads parallel children across keys (least-loaded)
- Thread-safe acquire_lease/release_lease in CredentialPool
- Reverted sneaked-in tool-name restoration change (kept original
  getattr + isinstance guard pattern)
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