Skip to content

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

Merged
waleedlatif1 merged 7 commits into
stagingfrom
feat/desktop-executor-web
Oct 7, 2026
Merged

waleedlatif1 merged 7 commits into
stagingfrom
feat/desktop-executor-web

Conversation

@waleedlatif1

@waleedlatif1 waleedlatif1 commented Oct 6, 2026 •

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.

Based on staging, now that #8650 is squashed; the desktop side is #8668. 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 chat row's tooltip adds one of:

    • "Running on <device>";
    • "Needs input";
    • "Waiting for <device> to come back online".
  • 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. Its reads have a rate-limit bucket of their own, apart from the device's lease renewals.

  • Only a workspace chat's turn binds to a desktop. An organization chat stays with its chat view.

Notifications.

  • With the flag on, a chat this user's own desktop was running that finishes its turn while the user is looking elsewhere is announced, and clicking the notification opens it. Workspace chat events carry every member's chats, so a teammate's chat is never announced. The chat on screen still announces itself as before, so nothing is announced twice.
  • Such a background completion is shown even while Sim is focused on another page. Every other notification keeps the existing rule exactly: with "Notify only when Sim isn't focused", which is unchanged, a focused window holds it back wherever the user is.
  • 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 7, 2026 12:26am 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 Outdated
Comment thread apps/sim/lib/desktop/application/executor.ts Outdated
Comment thread apps/sim/scripts/test-desktop-inbox-e2e.ts Outdated
Comment thread apps/sim/hooks/use-mothership-chat-events.ts Outdated
Comment thread apps/sim/lib/api/server/routes/desktop-executor.ts Outdated
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 Outdated
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: 5/5

[Medium risk] Adds background chat execution tracking to desktop and web views.

The PR appears safe to merge; no new actionable finding or outstanding previous finding remains.

Summary

The PR makes desktop-executed workspace turns display-only in the chat view, adds per-chat desktop activity and background-completion notifications, and updates send-recovery and CI teardown behavior.

  • Stream headers and replay data identify turns whose desktop tools run on the device.
  • The sidebar reads the user’s desktop activity; notification handling distinguishes background chat completions from ordinary notices.
  • Follow-up changes pace busy-send retries and guard queued messages across chat deletion, restoration, and navigation.
Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A[Admitted workspace turn] --> B{Desktop bound?}
  B -->|Yes| C[Stream marks device executor]
  C --> D[Chat view displays desktop calls]
  C --> E[Desktop executes and reports calls]
  E --> F[Activity and completion events]
  F --> G[Sidebar status and background notice]
  B -->|No| H[Chat view runs eligible client tools]
Loading

Reviews (11) · Last reviewed commit: "style(desktop): color the background act..." · Reviewed by Greptile

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.

  • P1 Held messages become stranded apps/sim/app/workspace/[workspaceId]/home/hooks/use-chat.ts:5021 ▶

    When “Send now” interrupts the first turn on a new-chat page and Stop fails, the message is put back under that page’s temporary queue key without a heldSurface marker. If the page remounts or resets, it gets a new key, and the replacement page cannot adopt the message. The user’s message remains in the old queue instead of appearing in the composer. The direct-send path at lines 4395–4399 also omits the marker for held messages.

@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
@waleedlatif1
waleedlatif1 force-pushed the feat/desktop-executor-web branch from 401be2d to ac8cdc3 Compare October 6, 2026 17:27
@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

@waleedlatif1
waleedlatif1 changed the base branch from feat/desktop-executor-binding to staging October 6, 2026 18:14
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@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 31 files

Confidence score: 5/5

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

You've manually re-run cubic several times on this PR. Each manual re-review checks the full PR again and counts toward your usage quota. To preserve your usage limits, we recommend letting cubic automatically review new commits.

Turn on auto-fix | Re-trigger cubic

@waleedlatif1
waleedlatif1 force-pushed the feat/desktop-executor-web branch from 473c5c1 to 1aa2322 Compare October 7, 2026 00:00
@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 7, 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 31 files

Confidence score: 5/5

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

You've manually re-run cubic several times on this PR. Each manual re-review checks the full PR again and counts toward your usage quota. To preserve your usage limits, we recommend letting cubic automatically review new commits.

Turn on auto-fix | Re-trigger cubic

Comment thread apps/sim/app/workspace/[workspaceId]/w/components/sidebar/sidebar.tsx Outdated
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.
…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.
…nnounce only the user's own chats

- Every existing notification is held back whenever the window is focused,
  as before. Only a background chat's completion, now marked as such, is
  shown when the focused window is somewhere else. With the flag off, a
  flag-off user watching the workflow panel is no longer told about the
  chat they are looking at. The settings label is back to its original
  wording.
- Workspace chat events carry every member's chats. A completion is now
  announced only for a chat this user's own desktop was running, so a
  teammate's finished chat raises nothing.
- The sidebar's activity reads get their own rate-limit bucket, so polling
  tabs can never spend the tokens a device needs to renew its leases.
- An offline desktop's chat now says it is waiting for the device to come
  back, not that it is blocked.
- The rule for which turns bind to a desktop is a named function, tested on
  its outcome.
… the desktop ran

Desktop activity now names each bound turn's stream, and a completion is
announced only when that turn was seen running on the user's own desktop.
An earlier desktop turn no longer makes a later chat-view turn in the same
chat look eligible.
@waleedlatif1
waleedlatif1 force-pushed the feat/desktop-executor-web branch from 1aa2322 to 684261b Compare October 7, 2026 00:26
@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 7, 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 31 files

Confidence score: 5/5

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

You've manually re-run cubic several times on this PR. Each manual re-review checks the full PR again and counts toward your usage quota. To preserve your usage limits, we recommend letting cubic automatically review new commits.

Turn on auto-fix | Re-trigger cubic

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

This is about send-recovery code already on staging, not this PR's diff. A follow-up queued on the chatless surface could be stranded on remount; that is fixed in #8707 (with a regression test).

@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 7, 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 31 files

Confidence score: 5/5

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

You've manually re-run cubic several times on this PR. Each manual re-review checks the full PR again and counts toward your usage quota. To preserve your usage limits, we recommend letting cubic automatically review new commits.

Turn on auto-fix | Re-trigger cubic

@waleedlatif1
waleedlatif1 merged commit 0d74834 into staging Oct 7, 2026
36 checks passed
@waleedlatif1
waleedlatif1 deleted the feat/desktop-executor-web branch October 7, 2026 02:05

This branch was previously deployed

1 inactive deployment
Preview — 684261b1 Deployed Oct 7, 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