Repository navigation
fix(acp): wait for the relay to accept offline presence before closing - #8385
Draft
anthony-tarantini wants to merge 2 commits into
Draft
anthony-tarantini wants to merge 2 commits into
anthony-tarantini wants to merge 2 commits into
Conversation
On shutdown the harness queued the `offline` presence event and closed the socket ~1ms later. The relay handles each EVENT on a spawned task that snapshots the connection's auth when it runs; the close frame terminalizes auth first, so the presence was refused as unauthenticated and never fanned out. The relay then cleared the Redis entry on disconnect without any live event, leaving watchers (the desktop's Shutdown/Deploy control) showing the agent online until they re-queried. Add `RelayEventPublisher::publish_event_acked`, which resolves only on the relay's OK for that event id. A rate-gated, unsent, or disconnected publish drops the waiter so callers observe non-delivery, never success, and an `auth…` refusal reaches the waiter before the reconnect branch. Shutdown publishes offline through it under the existing 2s timeout and only then closes the socket; online heartbeats stay fire-and-forget. Signed-off-by: Tony <tony@tarantini.io>
🔐 Codex Security Review
|
…ough the rate gate Entering reconnect drops pending acknowledged-publish waiters, since the socket that carried them can no longer deliver an OK. The acknowledged publish is sent even while rate-gated: its caller waits on that one event, and a gated relay still answers with OK. Covers the shutdown path's switch to the acknowledged publish with a test through RelayEventPublisher::test_pair. Signed-off-by: Tony <tony@tarantini.io>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
After
!shutdown, other clients keep showing a remote agent online until they re-query presence. The agent publishesoffline, but the relay never delivers it.buzz-acpqueued theofflinepresence event and closed the socket about 1 ms later. The relay handles each EVENT on its own task, which checks the sender's auth when it runs. The close is processed first and ends the session, so the presence is refused as unauthenticated and never fanned out. The relay then deletes the agent's presence on disconnect without telling any client. On a live relay, the pod logged "presence set to offline" 0.7 ms before exiting, and the desktop never received an update.This adds
RelayEventPublisher::publish_event_acked, which resolves only on the relay'sOKfor that event id. Shutdown sendsofflinethrough it within the existing 2 s limit, and only then closes the socket. Online heartbeats are unchanged.OK, the waiter is dropped, and the caller sees non-delivery at once rather than success or a 2 s stall.OK.auth…refusal reaches the waiter before the existing auth branch returns early to reconnect.Presence can't go over
submit_eventinstead: the HTTP bridge rejects kind:20001.Related issue
Part of #4730 and #7724; #8386 is the desktop half. Possibly related: #7946 (a remote agent stays green in the DM sidebar after it goes offline).
Testing
acked_publish_resolves_only_on_its_own_okacked_publish_reports_an_auth_refusalacked_publish_without_a_socket_reports_non_deliveryacked_publish_reports_non_delivery_when_the_connection_drops(throughwait_for_reconnect)acked_publish_is_sent_while_rate_gatedoffline_presence_waits_for_the_relay_verdictcovers the shutdown path's publish, throughRelayEventPublisher::test_pair.OKresolution, its order before the auth branch, clearing waiters on reconnect, sending through the gate) fails a test.-D warnings) is clean, and allbuzz-acptests pass.buzz-acpin the agent image: after!shutdownthe pod logs "presence set to offline" about 5 ms later, once the relay accepts it, and the desktop shows offline within seconds without a refresh. Before, it stayed online until a refresh.Manual test: deploy a remote agent, watch it from another client, and send
!shutdown. It should go offline within a couple of seconds, and the agent log should end with "presence set to offline".Not in this PR
The relay clears presence on disconnect without a live update, so agents that crash or are killed still look online until clients re-query. That belongs in the relay.