Skip to content

Comments

Support parallel delegation, fix circular detection, and fix Anthropic proxy URL#187

Merged
parruda merged 5 commits intomainfrom
parruda/parallel-delegation-support
Jan 29, 2026
Merged

Support parallel delegation, fix circular detection, and fix Anthropic proxy URL#187
parruda merged 5 commits intomainfrom
parruda/parallel-delegation-support

Conversation

@parruda
Copy link
Owner

@parruda parruda commented Jan 28, 2026

Summary

  • Fix Anthropic API 404 with proxy base URLs: Patch Anthropic::Chat#completion_url to return v1/messages (relative path) instead of /v1/messages (absolute). The leading slash caused Faraday to discard the base URL path component when anthropic_api_base includes a path segment (e.g., https://proxy.dev/apis/anthropic). Fixes both sync and streaming requests since stream_url delegates to completion_url.

  • Fix false circular delegation detection: Replace the shared delegation_call_stack array on Swarm with Fiber-local path tracking (Fiber[:delegation_path]). Each Async Fiber tracks its own delegation chain, so parallel fan-out (A→B, A→B) is no longer falsely flagged as circular while true cycles (A→B→A) are still caught.

  • Add concurrent delegation context isolation: When multiple parallel tool calls target the same delegate, only the first call preserves context; subsequent concurrent calls auto-clear via a new clear_context: parameter on Agent::Chat#ask. Clearing happens inside the ask_semaphore to prevent race conditions between parallel callers.

  • Fix ThreadError: Attempt to unlock a mutex which is not locked: Replace defined?(Sync) check in run_with_sync with Async::Task.current?. When already inside an async reactor, just yield directly — avoids creating a nested reactor whose Promise#wait triggers the mutex error.

  • Add request URL to llm_api_request event: Include the actual Faraday request URL in the llm_api_request event payload, enabling verification that LLM requests are sent to the correct endpoint.

Test plan

  • All 2224 existing tests pass (0 failures, 0 errors)
  • New test: circular detection uses Fiber-local path
  • New test: parallel delegation to same target is allowed
  • New test: concurrent delegation forces context clear (uses real Async barrier)
  • New test: sequential delegations preserve context normally
  • Rubocop clean on all changed files

🤖 Generated with Claude Code

parruda and others added 4 commits January 27, 2026 23:10
Replace the shared delegation_call_stack with Fiber-local path tracking
so parallel fan-out (A→B, A→B) is no longer falsely detected as circular.
Each Async Fiber tracks its own delegation chain via Fiber[:delegation_path],
while nested delegations correctly accumulate the full path through
Fiber storage inheritance.

Add concurrent delegation context isolation: when multiple parallel tool
calls target the same delegate, an active_count tracks concurrency.
The first call preserves context normally; subsequent concurrent calls
force clear_context: true. Context clearing happens inside Agent::Chat's
ask_semaphore to prevent race conditions between parallel callers.

Fix ThreadError in run_with_sync by checking Async::Task.current? instead
of defined?(Sync). When already inside an async reactor, just yield
directly — avoids creating a nested reactor whose Promise#wait triggers
"Attempt to unlock a mutex which is not locked".

Co-Authored-By: Claude (claude-fudge-eap-cc) <noreply@anthropic.com>
Include the actual Faraday request URL in the llm_api_request event
payload to enable verifying requests are sent to the correct endpoint.

Co-Authored-By: Claude (claude-fudge-eap-cc) <noreply@anthropic.com>
…vent

Co-Authored-By: Claude (claude-fudge-eap-cc) <noreply@anthropic.com>
… base URLs

When anthropic_api_base includes a path segment (e.g., https://proxy.dev/apis/anthropic),
the leading slash in `/v1/messages` caused Faraday to resolve against the host root,
discarding the path. Override Anthropic::Chat#completion_url to return `v1/messages`
(relative path). Since stream_url delegates to completion_url, this fixes both sync
and streaming requests.

Co-Authored-By: Claude (claude-fudge-flow[1m]) <noreply@anthropic.com>
@parruda parruda changed the title Support parallel delegation and fix circular detection Support parallel delegation, fix circular detection, and fix Anthropic proxy URL Jan 29, 2026
@parruda parruda merged commit ed53836 into main Jan 29, 2026
9 checks passed
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.

1 participant