fix(desktop): report agent presence from the relay, not the profile default - #4537
Open
mikececco wants to merge 1 commit into
Open
fix(desktop): report agent presence from the relay, not the profile default#4537mikececco wants to merge 1 commit into
mikececco wants to merge 1 commit into
Conversation
…efault `agents_from_events` fills in `status: "offline"` whenever a kind:10100 agent profile does not carry a status string. Nothing in-tree ever writes that field — the only in-tree writer of kind:10100 sets `channel_add_policy` — so the fallback is taken for every relay-discovered agent, and the Pulse roster reported agents as offline whether or not they were running. Meanwhile the relay already tracks real presence: kind:20001 events backed by a Redis TTL, exposed to the client through `usePresenceQuery`. The two were never joined; the roster built its status map straight off the profile field. Join them, preferring presence where it has an entry. Agents absent from the lookup keep their incoming status, so locally-managed agents continue to use the live process handle — authoritative for the machine running them, and not something the relay can contradict. The merge is a pure function in `agents/lib/agentPresenceStatus.ts` with unit tests covering the offline-fallback override, away, missing entries, unrelated pubkeys, an unloaded lookup, and presence correcting a stale "online" handle. Refs block#3996, block#4169 Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: Mike Cecconello <mikececco2000@gmail.com>
This was referenced Aug 3, 2026
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.
Problem
agents_from_eventsfills in a default when akind:10100agent profile has nostatusstring:Nothing in-tree ever writes that field — the only in-tree writer of
kind:10100is
cmd_set_add_policy, which setschannel_add_policy— so the fallback istaken for every relay-discovered agent. The Pulse roster then builds its status
map straight off it:
So a running agent is reported offline. The only agents that showed a real state
were locally-managed ones, whose status the view synthesizes from the local
process handle.
Meanwhile the relay already tracks genuine presence —
kind:20001events behinda 180s Redis TTL, surfaced to the client by
usePresenceQuery. The two weresimply never joined.
Change
Join them, with presence taking precedence wherever it has an entry.
Agents absent from the presence lookup keep their incoming status. That is
deliberate: locally-managed agents derive theirs from the live process handle,
which is authoritative for the machine running them and isn't something the
relay should override. It also makes the merge a no-op before the presence query
resolves, so the roster never flickers to offline on load.
The merge itself is a pure function (
agents/lib/agentPresenceStatus.ts) ratherthan inline logic, so it is unit-testable and reusable by the other roster
surfaces (
useMentions,useNewMessageRecipients,useTrayMenu) in follow-ups.Scope
Deliberately narrow: this changes only status truthfulness, not rendering.
I've kept away from the roster/fleet UI in #3996 and #4169 since several PRs are
already in flight there — this composes with whichever lands rather than
competing with it. The most substantive comment on #3996 asks for exactly this
("derive online/offline from presence/heartbeat facts, not a static profile
field"), and as far as I can tell none of the open PRs do it.
Tests
Six cases in
agentPresenceStatus.test.mjs:awayis preserved, not flattened to online/offlineundefined) lookup is a no-op"online"handle to offlineGreen locally:
just desktop-check— passjust desktop-test— 3934 pass, 0 failUI note
No visual/layout change — the same status indicator now reflects real presence
instead of a constant. Happy to attach a before/after of the Pulse agents tab if
that's wanted for review.
Refs #3996, #4169