Skip to content

Fix route:cache failing on signal webhook routes (Serialization of 'ReflectionMethod' is not allowed)#398

Merged
rmcdaniel merged 1 commit into
durable-workflow:masterfrom
jakobkollerup:fix/signal-webhook-route-cache-serialization
Jul 17, 2026
Merged

Fix route:cache failing on signal webhook routes (Serialization of 'ReflectionMethod' is not allowed)#398
rmcdaniel merged 1 commit into
durable-workflow:masterfrom
jakobkollerup:fix/signal-webhook-route-cache-serialization

Conversation

@jakobkollerup

@jakobkollerup jakobkollerup commented Jul 17, 2026

Copy link
Copy Markdown

Problem

With any workflow that has a #[SignalMethod] + #[Webhook] method registered via Webhooks::routes(), php artisan route:cache fails:

Exception: Serialization of 'ReflectionMethod' is not allowed

Laravel serializes closure-based routes with SerializableClosure (all supported versions, 9 through 13, do this in Route::prepareForSerialization()), which serializes the closure's captured variables. The signal webhook closure captures the ReflectionMethod instance:

static function (Request $request, $workflowId) use ($workflow, $method) {

and PHP refuses to serialize reflection objects. Since route:cache/optimize runs in most production deploys, adding the first #[Webhook] signal method breaks deployment. The start webhook closure is fine — it only captures the class-name string.

Fix

Capture the method name (a string) instead of the ReflectionMethod; the closure only ever used $method->getName().

Test

testWebhookRoutesCanBeSerializedForRouteCaching mirrors what route:cache does (prepareForSerialization() + serialize() on each registered webhook route). It fails on master with the exception above and passes with this change.

Note: the v2 branch has the same capture in its src/Webhooks.php, so this is worth porting there too.

Signal webhook route closures captured the ReflectionMethod instance,
so php artisan route:cache failed with "Serialization of
'ReflectionMethod' is not allowed" for any app with a #[Webhook]
signal method. Capture the method name instead.
@jakobkollerup
jakobkollerup force-pushed the fix/signal-webhook-route-cache-serialization branch from b2fe9ca to 77d32d4 Compare July 17, 2026 10:07
@jakobkollerup
jakobkollerup marked this pull request as ready for review July 17, 2026 10:15
@codecov

codecov Bot commented Jul 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (530c376) to head (77d32d4).

Additional details and impacted files
@@             Coverage Diff             @@
##              master      #398   +/-   ##
===========================================
  Coverage     100.00%   100.00%           
  Complexity       666       666           
===========================================
  Files             63        63           
  Lines           2266      2267    +1     
===========================================
+ Hits            2266      2267    +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes Laravel route:cache failures caused by webhook signal routes capturing a ReflectionMethod inside a closure (which is not serializable). It updates webhook route registration to capture only the signal method name (string) and adds a unit test that mirrors Laravel’s route caching serialization behavior.

Changes:

  • Update signal webhook route closure to capture $signalMethod (string) instead of a ReflectionMethod instance.
  • Invoke the signal method via the captured name to avoid serializing reflection objects during route:cache.
  • Add a unit test that calls prepareForSerialization() + serialize() on workflow webhook routes to ensure route caching compatibility.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/Webhooks.php Avoids capturing ReflectionMethod in signal webhook route closures by capturing the method name string instead.
tests/Unit/WebhooksTest.php Adds coverage ensuring workflow webhook routes can be prepared and serialized like php artisan route:cache does.

@rmcdaniel
rmcdaniel merged commit d502e26 into durable-workflow:master Jul 17, 2026
3 checks passed
@rmcdaniel

Copy link
Copy Markdown
Member

Confirmed this also affected the v2 branch. The v2 fix is now released in durable-workflow/workflow:2.0.0-alpha.291 from commit 518a27492d38bd92bca3e2bb91b9ccf82da9589b. Thanks for flagging the cross-branch impact.

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.

3 participants