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
LaravelHttpTransport
that caused issues with tracking active clients, leading to "inactive or unknown client" errors when attempting to send messages.Problem:
The
LaravelHttpTransport
previously maintained an internal, in-memory$activeClients
array. 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$activeClients
list was unreliable and often out of sync with the actual client state managed byClientStateManager
(which uses a persistent cache).As a result, even if
ClientStateManager
knew a client was active (e.g., afterclient_connected
was emitted in the SSE GET request), a subsequentsendToClientAsync
call triggered by a server-side event might find the$activeClients
array empty in the new transport instance handling that server-side logic, leading to failed message delivery.Solution:
$activeClients
array fromLaravelHttpTransport
.client_connected
andclient_disconnected
event listeners withinLaravelHttpTransport
that were managing this local array. Client connection and disconnection events are still emitted for theProtocol
layer to handle withClientStateManager
.LaravelHttpTransport::sendToClientAsync
now directly queues messages viaClientStateManager
without checking the local$activeClients
array.message
event listener inLaravelHttpTransport
that callsclientStateManager->updateClientActivity()
remains, as this is the correct way to signal activity to the persistent state manager.Closes #13