Fix: Correct Client State Management in LaravelHttpTransport #17
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR addresses a bug in
LaravelHttpTransportthat caused issues with tracking active clients, leading to "inactive or unknown client" errors when attempting to send messages.Problem:
The
LaravelHttpTransportpreviously maintained an internal, in-memory$activeClientsarray. In a standard Laravel request-response environment (without persistent workers like Octane), this transport instance is re-created for almost every HTTP interaction (initial SSE GET, message POSTs, SSE stream polls). This meant the in-memory$activeClientslist was unreliable and often out of sync with the actual client state managed byClientStateManager(which uses a persistent cache).As a result, even if
ClientStateManagerknew a client was active (e.g., afterclient_connectedwas emitted in the SSE GET request), a subsequentsendToClientAsynccall triggered by a server-side event might find the$activeClientsarray empty in the new transport instance handling that server-side logic, leading to failed message delivery.Solution:
$activeClientsarray fromLaravelHttpTransport.client_connectedandclient_disconnectedevent listeners withinLaravelHttpTransportthat were managing this local array. Client connection and disconnection events are still emitted for theProtocollayer to handle withClientStateManager.LaravelHttpTransport::sendToClientAsyncnow directly queues messages viaClientStateManagerwithout checking the local$activeClientsarray.messageevent listener inLaravelHttpTransportthat callsclientStateManager->updateClientActivity()remains, as this is the correct way to signal activity to the persistent state manager.Closes #13