Skip to content

fix(desktop): let remote agents be redeployed after shutdown or inactivity - #8386

Open
anthony-tarantini wants to merge 4 commits into
block:mainfrom
anthony-tarantini:fix/remote-agent-restart
Open

anthony-tarantini wants to merge 4 commits into
block:mainfrom
anthony-tarantini:fix/remote-agent-restart

Conversation

@anthony-tarantini

@anthony-tarantini anthony-tarantini commented Oct 16, 2026 •

Copy link
Copy Markdown

Summary

A remote agent (for example on Kubernetes) could not be restarted from the desktop once it stopped. After !shutdown, or after its pod exited for inactivity, the app kept showing it as running: the button stayed "Shutdown", the card never offered Start, and mentioning or re-adding the agent did nothing.

A provider agent's status becomes deployed on its first deploy and is never cleared (there is no undeploy in v1), and every "is it running?" check read that receipt. Per I3 in docs/remote-agents.md, presence is the status and the deployment axis is bookkeeping.

This adds isManagedAgentLive(agent, availability). A deployed agent counts as live until relay presence shows it offline. Unknown presence (relay disconnected, failed read) keeps the receipt, so the app never invents an offline agent. isManagedAgentActive keeps its bookkeeping meaning, the split proposed in #5138. Starting an offline agent deploys it again with its saved settings; the provider already replaces a finished pod.

  • Agent cards, the profile panel and the members sidebar offer Deploy and show Stopped for an offline remote agent.
  • An offline remote agent is redeployed when it is @mentioned, added to a channel, or added to a huddle. attachManagedAgentToChannel reads presence once itself, so every attach path is covered. The mention path re-checks cancellation after its read, and the composer gets no presence subscription.

This reverses a behavior agent-availability.spec.ts pinned on purpose ("an offline deployment keeps Shutdown; no inferred redeploy"). Nothing redeploys without a user action; a mention or huddle add already deployed agents that had never been deployed.

The UI updates live only once the agent's offline presence reaches the relay, which #8385 fixes. Without it, this PR still works but updates on the next presence fetch.

Related issue

Fixes #4730. Fixes #7724.

Overlaps three open PRs: #5138 (same liveness split, which this PR adopts and extends to the start paths), and #7072 and #7485 (profile panel only).

Testing

  • managedAgentControlActions.test.mjs: table tests over every status × presence combination for isManagedAgentLive, isManagedAgentActive and the displayed status, plus the Deploy label.
  • channelAgents.attach.test.mjs: an offline agent is redeployed through the real presence read; an online agent, a failed read, or a disconnected relay are not.
  • useEnsureAgentMentionsReady.test.mjs: an offline member is woken; a send cancelled during the presence read queues nothing.
  • I removed each guard one at a time and confirmed the matching test fails.
  • At the rebased head, the pre-push desktop check, typecheck, and test gates passed; pnpm build:e2e and the agent-availability integration test also passed.
  • Live, on a self-hosted relay and Kubernetes cluster with fix(acp): wait for the relay to accept offline presence before closing #8385: Shutdown switches to Deploy within seconds without a refresh, and Deploy starts a new pod under the same identity.
  • Not covered by an automated test: the huddle add path, which calls the tested live check after a one-shot presence read.

Manual test: deploy a remote agent and wait until it's online, then Shutdown. The card should show Start, and the profile should show Deploy and Stopped. Deploy it again; a new pod should start. Shut it down and @mention it, and it should redeploy.

Not in this PR

Screenshots

Profile panel for a deployed remote agent whose presence is offline.

Before (Shutdown) After (Deploy)
01-before-offline-deployment 02-after-offline-deployment

buzz-review-completed

@github-actions

github-actions Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

🔐 Codex Security Review

Status: review required for the current range.

The current range is 347ce88d5dd8bc631c073f1947fea6b75d5a43c0...fcf1239c7fdf5069f35cb8325f2fc6f2f0076157.
A new review must complete for this exact range. When manual authorization
is required, a user with write access must comment exactly
@buzz-security-review fcf1239c7fdf5069f35cb8325f2fc6f2f0076157 to authorize a new review.
Any previous review applies only to its recorded range.

Tony added 4 commits October 21, 2026 18:47
A provider agent's `deployed` status is a retained deploy receipt the
desktop never clears, so after `!shutdown` or an inactivity reap the UI
kept showing it as running: the primary action stayed "Shutdown" (aimed
at a body that no longer exists), the card never offered Start, and
mentioning the agent never redeployed it.

Established offline relay presence now overrides the receipt for
lifecycle routing (`isManagedAgentActive`). Unknown presence keeps the
receipt, so a failed or disconnected read never invents an offline
agent. Deploy re-converges the provider, which replaces a completed pod.

- Agent cards, profile panel and members sidebar route Deploy/Shutdown
  and their status badges through the presence-aware helper.
- Mentioning a deployed provider agent reads presence once at send time
  (no composer subscription) and queues a redeploy when it is offline,
  for both channel members and agents attached by the mention.
- The agent-availability E2E spec pinned "offline deployment keeps
  Shutdown, no inferred redeploy"; it now expects Deploy. Nothing
  redeploys without a user action beyond the mention path, which already
  deployed never-deployed provider agents.

Signed-off-by: Tony <tony@tarantini.io>
The remaining places that read a provider's `deployed` receipt as
"running" now consult relay presence too, so a shut-down or reaped
remote agent is no longer shown, ranked, or skipped as if it were live.

- Adding an offline remote agent to a huddle redeploys it; before, the
  add left it undeployed and it never joined.
- Choosing which instance to reuse when adding a persona to a channel
  reads presence once for deployed candidates, so a reaped deployment
  no longer outranks a running sibling. Persona cards pick their
  representative instance the same way.
- "Stop running agents" no longer counts offline remote agents.
- Pulse's fallback status for managed agents missing from the relay
  directory follows presence instead of the receipt.
- @mention ranking takes a remote agent's activity from the relay
  directory rather than the receipt.
- Changing the model of an offline remote agent no longer asks for a
  restart.

Signed-off-by: Tony <tony@tarantini.io>
Keep `isManagedAgentActive` as control-plane bookkeeping (a provider's
`deployed` receipt counts) and move the presence-aware check to a
separate `isManagedAgentLive(agent, availability)`, matching I3 in
docs/remote-agents.md (presence is the status; the deployment axis is
bookkeeping) and the vocabulary proposed in block#5138. Behavior is
unchanged: every caller that passed presence now calls the live check.

Signed-off-by: Tony <tony@tarantini.io>
…presence

Trim this PR to the reported bug: the lifecycle controls and badges, and
redeploying an offline remote agent wherever a start happens. Instance
reuse ranking, persona-card selection, Pulse, mention ranking, the model
picker prompt and the stop-all count move to a follow-up.

`attachManagedAgentToChannel` now reads presence itself for a deployed
agent, so every attach path (mention, add to channel, persona
provisioning in a regular channel) redeploys an offline remote agent
without each caller threading presence in. The mention path re-checks
cancellation after its presence read so a cancelled send queues no wake.

Signed-off-by: Tony <tony@tarantini.io>
@anthony-tarantini

Copy link
Copy Markdown
Author

@buzz-security-review fcf1239

@anthony-tarantini
anthony-tarantini marked this pull request as ready for review October 22, 2026 00:32
@anthony-tarantini
anthony-tarantini requested a review from a team as a code owner October 22, 2026 00:32

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant