Skip to content

Fix: concurrent tool execution fails with ProcessDriver due to $this capture and circular references#1009

Open
vinitkadam03 wants to merge 1 commit intoprism-php:mainfrom
vinitkadam03:fix/concurrency-serializable-closure
Open

Fix: concurrent tool execution fails with ProcessDriver due to $this capture and circular references#1009
vinitkadam03 wants to merge 1 commit intoprism-php:mainfrom
vinitkadam03:fix/concurrency-serializable-closure

Conversation

@vinitkadam03
Copy link
Copy Markdown
Contributor

@vinitkadam03 vinitkadam03 commented Apr 11, 2026

Summary

Fixes #893 — concurrent tool execution via Laravel's Concurrency::run() fails because closures capture $this (the handler object), causing SerializableClosure to serialize the entire application container. This also fixes the ->using($this) circular reference issue for class-based invokable tools.

Changes

CallsTools trait — eliminate $this capture in concurrent closures

Tool class — fix circular reference and named argument handling

  • using() now detects $fn === $this and skips the assignment, preventing the Tool -> $fn -> Tool circular reference that breaks SerializableClosure.
  • handle() auto-detects __invoke() on subclasses when $fn is null, so invokable tool classes work with or without ->using($this).
  • handle() unwraps SerializableClosure\Serializers\Native wrappers via getClosure() before invocation, restoring PHP 8 named argument forwarding that Native::__invoke() breaks.

@vinitkadam03 vinitkadam03 force-pushed the fix/concurrency-serializable-closure branch from d1f308a to 9c08434 Compare April 12, 2026 16:26
… circular references in invokable subclasses
@vinitkadam03 vinitkadam03 force-pushed the fix/concurrency-serializable-closure branch from 9c08434 to a207a10 Compare April 12, 2026 17:59
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.

Concurrent tool execution fails with Laravel's ProcessDriver due to circular reference and $this capture in closures

1 participant