Skip to content

feat(desktop): show background desktop chats and keep the chat view display-only for them - #8670

Open
waleedlatif1 wants to merge 4 commits into
feat/desktop-executor-bindingfrom
feat/desktop-executor-web
Open

waleedlatif1 wants to merge 4 commits into
feat/desktop-executor-bindingfrom
feat/desktop-executor-web

Conversation

@waleedlatif1

Copy link
Copy Markdown
Collaborator

Summary

Phase 2b of the desktop background executor: the web app's side. All of it applies only to turns a desktop's background executor runs, which only happens behind mothership-desktop-background-executor. With the flag off, or on an old desktop build, nothing changes.

Stacked on #8650; the desktop side is #8668. It will be rebased onto staging once #8650 is squashed. It builds on the unopened background-activity commit (its first commit), reviewed and corrected against the final binding contract.

Display only, decided by Sim, not by a cache.

  • Sim marks a turn that its desktop's executor runs on the stream that serves it:
    • an x-mothership-desktop-executor: device header on the send response and on every reconnect;
    • desktopToolsOnDevice on the replay batch that a reloaded view attaches with.
  • For such a turn, the chat view shows its desktop calls (browser, terminal, local files) and their results, but never starts or reports them. It therefore never calls authorize or confirm for them, and it has no tool lifetime to cancel on unmount or stream recovery. Workflow tools are unaffected.
  • The first commit decided this from the cached activity list, which a new turn's first desktop call could beat. That would have sent the view down the authorize-409 path this PR exists to avoid.

Status per chat (sidebar).

  • The sidebar dot's tooltip reads one of:

    • "Running on <device>";
    • "Needs input";
    • "Blocked: <device> is offline".
  • The existing unread dot stays as Ready.

  • Needs input now comes from the durable record:

    • a call Sim asked the user about that they have not answered (permission_requested_at set, no decision);
    • or a running terminal handoff or browser_request_takeover.

    An auto-allowed command no longer shows as needing input.

  • Presence that Sim cannot read is shown as running, not offline.

  • The activity list refreshes as soon as a turn starts or ends, not only on its timer.

Notifications.

  • A chat that finishes its turn while the user is looking elsewhere is announced, and clicking the notification opens it. The chat on screen still announces itself as before, so nothing is announced twice.
  • "Notify only for chats in the background", which is the existing default (renamed from "Notify only when Sim isn't focused"), now means exactly that: a background chat is announced even while Sim is focused, and the chat on screen is not.
  • Approval notifications come from the desktop executor (feat(desktop): run a chat's desktop tools in the background executor #8668) and open the chat at its approval card. There is never an approve button in the notification.

Test plan

  • Integration against real Postgres and Redis (bun run test:integration):
    • app/api/copilot/chat/stream/desktop-executor.integration.ts: the live tail and the replay batch of a turn bound to a desktop are marked, and an unbound turn's are not.
    • lib/desktop/application/activity.integration.ts:
      • running, needs input and blocked;
      • an allowed pending command that is not needing input;
      • handoff and takeover counted as needing input;
      • a declined call that no longer waits;
      • no other user's or workspace's chats.
  • Unit tests:
    • the stream handler only shows browser, terminal and local-file calls when the turn runs on the device, and still starts workflow tools;
    • background completion notifications: announced elsewhere, quiet for the chat on screen and outside the desktop, activity refreshed on start and end;
    • the desktop notification focus rule.
  • type-check, check:audits, and the affected Vitest suites (251 files).

@waleedlatif1 waleedlatif1 changed the title fix(desktop): show background desktop chats and keep the chat view display-only for them feat(desktop): show background desktop chats and keep the chat view display-only for them Oct 6, 2026
@vercel

vercel Bot commented Oct 6, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
docs Skipped Skipped Oct 6, 2026 5:30pm UTC

Request Review

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@waleedlatif1 I have started the AI code review. It will take a few minutes to complete.

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 81 files

Re-trigger cubic

Comment thread apps/sim/lib/mothership/request/tools/desktop-wait.ts
Comment thread apps/sim/lib/desktop/application/executor.ts Outdated
Comment thread apps/sim/scripts/test-desktop-inbox-e2e.ts
Comment thread apps/sim/hooks/use-mothership-chat-events.ts
Comment thread apps/sim/lib/api/server/routes/desktop-executor.ts
Comment thread apps/sim/app/api/copilot/confirm/route.ts
Comment thread apps/sim/lib/mothership/request/application/controls.ts Outdated
Comment thread apps/sim/lib/desktop/executor/repository.ts
Comment thread apps/sim/lib/desktop/application/executor.integration.ts
@greptile-apps

greptile-apps Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 4/5

[Medium risk] Adds background desktop chat execution with view-only display mode.

The effort-pick overwrite should be addressed, and the explicit testing requirement must be satisfied before merging.

Findings

  1. P2 Tests assert mock calls ▶

Summary

The PR adds stream-authoritative display-only handling for desktop-executed tools, workspace sidebar activity, and background-chat notifications. Since the previous review, it also restricts desktop binding to workspace chats, adjusts desktop call deadlines and Stop handling, and changes how a pending new-chat effort pick is saved.

Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A[Admitted workspace turn] --> B{Desktop bound?}
  B -->|Yes| C[Stream marks desktop executor]
  C --> D[Chat view displays desktop calls]
  C --> E[Desktop claims and runs calls]
  E --> F[Activity query updates sidebar]
  B -->|No| G[Chat view runs client tools]
Loading

Reviews (2) · Last reviewed commit: "fix(desktop): keep background chat signa..."

Comment thread apps/sim/app/o/[organizationId]/layout.tsx
Comment thread apps/sim/lib/desktop/executor/inbox.ts
@waleedlatif1
waleedlatif1 force-pushed the feat/desktop-executor-web branch from 0c63239 to 401be2d Compare October 6, 2026 15:41
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@waleedlatif1 I have started the AI code review. It will take a few minutes to complete.

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@waleedlatif1 I have started the AI code review. It will take a few minutes to complete.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 29 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Turn on auto-fix | Re-trigger cubic

Comment thread apps/sim/app/workspace/[workspaceId]/home/hooks/stream/handle-tool-event.test.ts Outdated
@greptile-apps

greptile-apps Bot commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

Comments Outside Diff

These findings could not be posted inline.

  • P2 Retry overwrites newer effort apps/sim/app/workspace/[workspaceId]/home/hooks/use-chat.ts:3455 ▶

    When a chatless send is retried after its first attempt created a chat, the 409 response can name a chat whose effort the user has since changed. This code replaces that newer choice with the retry’s new-chat or send-time choice and saves it, silently undoing the user’s selection.

@waleedlatif1
waleedlatif1 force-pushed the feat/desktop-executor-binding branch from 48920e2 to 0a5f255 Compare October 6, 2026 15:52
@waleedlatif1
waleedlatif1 requested a review from a team as a code owner October 6, 2026 15:52
Behind mothership-desktop-background-executor (resolved server-side and
passed through the workspace feature flags):

- GET /api/desktop/activity lists the caller's chats in a workspace whose
  turn runs on one of their desktops, as running, needs input (a call waits
  for approval) or blocked (that desktop is offline), with the device name.
- The sidebar marks those chats with a status dot whose tooltip reads
  "Running on <device>", "Needs input" or "Blocked: <device> is offline";
  unread replies keep the existing Ready dot.
- A chat view showing a turn a desktop runs in the background only displays
  its desktop calls and never executes them.
…ckground chats

Builds on the background activity commit, against the final binding contract.

- Display only, deterministically. Sim marks a turn its desktop's executor runs
  on the stream that serves it: a response header on the send and on every
  reconnect, and a flag on the replay batch a reload attaches with. The chat
  view only shows that turn's desktop calls and never starts or reports them.
  This replaces reading the cached activity list, which a new turn's first call
  could beat.
- Needs input comes from the durable record: a call Sim asked the user about and
  they have not answered, or a running terminal handoff or browser takeover.
  An auto-allowed command no longer reads as needing input. Presence Sim cannot
  read is not reported as offline.
- Turn-complete notifications for chats in the background: a chat that finishes
  while the user is elsewhere is announced and opens on click; the chat on
  screen announces itself as before. "Notify only for chats in the background"
  (the existing default) now means exactly that, so a background chat is
  announced even while Sim is focused.
- The activity list refreshes when a turn starts or ends.
…kspace chats

- Turn-complete notifications for chats in the background follow the
  background executor flag, so a flag-off user sees exactly what they saw
  before.
- Only a workspace chat's turn binds to a desktop. Its sidebar shows the
  status and an approval notification links back to it; an organization
  chat stays with its chat view.
- A desktop's status reads as running when Sim cannot track presence at all,
  not as blocked.
- "Running on <device>" shows in the chat row's tooltip. The status dot sits
  in the row's indicator slot, which takes no pointer and gives way to the
  row's actions on hover, so a tooltip on the dot itself could never open.
@waleedlatif1
waleedlatif1 force-pushed the feat/desktop-executor-web branch from 401be2d to ac8cdc3 Compare October 6, 2026 17:27
…d of asserting mock calls

The background-chat tests now record the calls a view starts and the
notifications it asks the desktop app to show, and read whether the
desktop activity query went stale from a real query client, instead of
asserting that mocks were called.

This branch was previously deployed

1 inactive deployment
Preview — 00f770c2 Deployed Oct 6, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant