Skip to content

feat(desktop): keep the machine awake for background chats and yield the page to the user - #8671

Open
waleedlatif1 wants to merge 4 commits into
feat/desktop-executor-mainfrom
feat/desktop-executor-takeover
Open

waleedlatif1 wants to merge 4 commits into
feat/desktop-executor-mainfrom
feat/desktop-executor-takeover

Conversation

@waleedlatif1

@waleedlatif1 waleedlatif1 commented Oct 6, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Phase 2c of the desktop background executor. Stacked on #8668.

Prevent sleep while a chat is running

  • While any chat has desktop work claimed on this machine, the app holds a prevent-app-suspension power blocker. It releases the blocker as soon as the last result is delivered. It never holds one while idle.
  • The behaviour is on by default, with a switch in Settings → Desktop. A one-line note says a closed lid still puts the computer to sleep, because the switch can't prevent that. The switch shows only when Sim runs chats on this device in the background.
  • A result that keeps failing to reach Sim holds the machine awake for at most 10 minutes. Delivery keeps retrying after that.
  • The switch is a new optional bridge method, settings.setPreventSleepWhileRunning, so older desktop builds don't show it.

The agent yields the page to the user (takeover)

  • Only calls from the background executor yield. A call from the chat view the user is watching behaves exactly as on staging, because there the user steers the agent directly.
  • A background call that only reads the page (snapshot, read text, list tabs) never waits, since it cannot collide with the user.
  • When the user clicks, scrolls or types in the page a background chat's agent is driving, that chat's next acting browser action waits. While it waits, the tab is marked as needing attention.
  • The action resumes in the same page once the user has left it alone for 4 seconds.
  • The wait is bounded at 30 seconds, or half the action's watchdog if that is shorter. A user who keeps working past that gets a clear "not run" rather than a timeout.
  • A user who starts working mid-action (between a batch's steps, or during a click's target probes) stops it before its next input. The result says earlier steps may have taken effect.
  • The activity counts only on the tab the user acted in.
  • A Stop still cancels an action while it waits.
  • browser_request_takeover keeps its own explicit hand-back flow.
  • Other chats' browsers are unaffected.

Not in this PR: a background chat's page dialog can still take focus

A page in a hidden chat that calls confirm() or alert() still takes focus from the user's window. Electron shows its native message box before the driver's CDP handler answers the dialog. This happens whether or not the executor runs the chat, and it overlaps with #8432's dialog work. Suppressing native dialogs (disableDialogs) would also break the agent's dialog: {accept: true} answers. I reproduced it in a packaged-app E2E and left it out of this PR so it can be decided with #8432.

Test plan

  • Unit tests (sleep-blocker.test.ts):

    • one blocker is held only while work runs;
    • the switch is followed live;
    • an idle machine never starts one.
  • Packaged-app E2E (background-executor.spec.ts):

    • I: synthetic user input in the agent's tab holds a background browser_click until 4 s of quiet. The click then runs exactly once.
    • J: the blocker is taken when a background command starts and released once its result is delivered.

    Both fail with the change reverted (mutation-checked). The full suite, A to J, passes in 1.1 min.

  • type-check, check:audits, check:desktop-ipc, check:desktop-bridge, and the desktop Vitest suite (931 tests).

@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 10:47pm 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 14 files

Fix all with cubic | Re-trigger cubic

Comment thread apps/desktop/src/main/browser-agent/driver.ts Outdated
Comment thread apps/desktop/src/main/browser-agent/session.ts Outdated

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

Fix all with cubic | Re-trigger cubic

Comment thread apps/desktop/src/main/index.ts
Comment thread apps/desktop/src/main/browser-agent/session.ts Outdated
@greptile-apps

greptile-apps Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 4/5

[Medium risk] Agent yields page control to user during background work.

The PR’s behavior appears sound, but the new terminal test must satisfy the repository’s testing instruction before merging.

Summary

The PR adds an opt-in desktop sleep blocker for background chat work and makes background browser actions yield when the user is active in the same page. Since the previous review, it also adjusts executor reconnection and terminal-run cleanup. One new test conflicts with the repository’s testing instruction.

Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart LR
  Claim[Background desktop claim] --> Busy[Executor busy state]
  Busy -->|Busy and setting enabled| Block[Hold power blocker]
  Busy -->|Idle or setting disabled| Release[Release power blocker]
  Browser[Background browser action] --> Activity{User active in target tab?}
  Activity -->|Yes| Yield[Wait for quiet period]
  Activity -->|No| Act[Dispatch guarded input]
  Yield -->|Quiet| Act
  Yield -->|Wait limit reached| Refuse[Report not run]
Loading

Reviews (12) · Last reviewed commit: "fix(desktop): yield the page only for ba..."

Comment thread apps/desktop/src/main/browser-agent/driver.ts Outdated
Comment thread apps/desktop/src/main/browser-agent/driver.ts Outdated
Comment thread apps/desktop/src/main/browser-agent/session.ts Outdated
Comment thread apps/desktop/src/main/desktop-executor/sleep-blocker.ts
@waleedlatif1
waleedlatif1 force-pushed the feat/desktop-executor-main branch from 8c2b3fd to de04c40 Compare October 6, 2026 15:39
@waleedlatif1
waleedlatif1 requested a review from a team as a code owner October 6, 2026 15:39
@waleedlatif1
waleedlatif1 force-pushed the feat/desktop-executor-takeover branch from 0d8b513 to 4024e1f Compare October 6, 2026 15:40
@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.

All reported issues were addressed across 16 files

Reply with feedback, questions, or to request a fix.

Fix all with cubic | Turn on auto-fix | Re-trigger cubic

Comment thread packages/desktop-bridge/src/index.ts
Comment thread apps/desktop/src/main/desktop-executor/executor.ts
@waleedlatif1
waleedlatif1 force-pushed the feat/desktop-executor-main branch from de04c40 to 93a0f75 Compare October 6, 2026 16:15
@waleedlatif1
waleedlatif1 force-pushed the feat/desktop-executor-takeover branch from 4024e1f to ccdaab7 Compare October 6, 2026 17:27
@waleedlatif1
waleedlatif1 force-pushed the feat/desktop-executor-takeover branch from ccdaab7 to d23e403 Compare October 6, 2026 17:30
@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 14 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

@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 18 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 force-pushed the feat/desktop-executor-takeover branch from 9a69412 to 13848af Compare October 6, 2026 21:32
@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 18 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

@greptile-apps

This comment has been minimized.

@waleedlatif1
waleedlatif1 force-pushed the feat/desktop-executor-takeover branch from 13848af to 808259c Compare October 6, 2026 22:01
@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 18 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 force-pushed the feat/desktop-executor-takeover branch from 808259c to ede95e9 Compare October 6, 2026 22:30
@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 18 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

…the page to the user

- Prevent sleep: while any chat has desktop work claimed on this machine, the
  app holds a prevent-app-suspension power blocker, released as soon as the
  last result is delivered. On by default, with a switch in Desktop settings
  that notes a closed lid still sleeps the computer. The switch is a new
  optional bridge method, so older shells simply do not show it.
- Takeover: when the user clicks, scrolls or types in the page an agent drives,
  that chat's next browser action waits, marked as needing attention, until
  the user has left the page alone for a few seconds, then resumes in the same
  page. A Stop still cancels it while it waits.
- A browser action now rechecks, right before each input it sends, whether the
  user is working in the page. Between a batch's steps or during a click's
  target probes, the user wins and the action stops before its next input.
- The wait for the user is bounded inside the action's own deadline. A user
  who keeps working gets the model a clear "not run" instead of a timeout with
  an unknown outcome.
- The user's activity belongs to the tab they acted in. Once the agent drives
  another tab (the old one closed or replaced, the session reopened), that
  activity no longer holds anything up.
- `createSleepBlocker` is documented.
- Only a call from the background executor yields the page to the user.
  A call from the chat view the user is watching acts exactly as before:
  there the user steers the agent directly.
- A background call that only reads the page (snapshot, read text, list
  tabs) never waits for the user, since it cannot collide with their input.
- Which browser tools only observe the page now lives in
  @sim/browser-protocol, shared by the chat view's replay policy and the
  driver.
- The prevent-sleep switch shows only when Sim runs chats on this device
  in the background.
- Tests: a chat-view call acts at once under user input; a background call
  waits, and a background read does not; a user who starts working
  mid-action stops it before its next input; sign-out releases the sleep
  blocker while a call is still running.
@waleedlatif1
waleedlatif1 force-pushed the feat/desktop-executor-takeover branch from ede95e9 to 4fda09e Compare October 6, 2026 22:47
@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 18 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

This branch was previously deployed

1 inactive deployment
Preview — 4fda09ed 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