Title: feat(desktop): run a chat's desktop tools in the background executor by waleedlatif1 · Pull Request #8668 · simstudioai/sim · GitHub
Open Graph Title: feat(desktop): run a chat's desktop tools in the background executor by waleedlatif1 · Pull Request #8668 · simstudioai/sim
X Title: feat(desktop): run a chat's desktop tools in the background executor by waleedlatif1 · Pull Request #8668 · simstudioai/sim
Description: Summary Phase 2a of the desktop background executor. The Sim desktop app now picks up and runs the desktop tool calls of turns bound to it from Electron main, so a chat keeps working after the user switches chats, switches workspace, or reloads the window. It uses the device protocol from #8644 and #8650 as is, and stays dormant until Sim enables the executor for the user. Based on staging, now that #8650 is squashed. What the desktop app does Identity. It keeps a stable install id in userData. It registers that id with the app partition's own session on startup, on sign-in and session change, and when the browser or terminal is switched on or off. Signing out stops every action, clears the outbox and retires the id. A 409 (the id belongs to another account) mints a new one. Pickup. An SSE doorbell, plus the reconciling inbox read. The inbox is read on connect, on every ring, on wake (powerMonitor resume), when the network returns, and on Sim's reconcile timer. A missed doorbell is normal: the timer catches it inside the pickup window. Reconnects use backoffWithJitter, and a silent stream is replaced after two missed heartbeats. Claim, then queue. A call is claimed as soon as it is offered, then queued per chat and per surface. Its lease is renewed from the claim until Sim acknowledges the result, so a backlog never misses the pickup window. Calls in one chat run in the order they were offered, and different chats run side by side. Execution. Each call runs from Sim's record of it, in that chat's own browser scope, terminals or granted folders. This covers browser_*, terminal, read_local_file and user-local read/grep/glob. A surface switched off on the machine answers "not run". Outbox. An encrypted journal (claiming → claimed → started → result), written before the step it guards, using safeStorage like the other userData stores. After a restart: a call that never started is reported as not started; one that started is reported as outcome unknown; a finished one is reported with its real result. Nothing runs twice. Results are retried until Sim answers. Any answer acknowledges the result: recorded, duplicate or superseded. A refused token (404/410) is final and is dropped. Stop. An inbox cancel, or a 410 on lease renewal, stops the action through the browser's own cancel. Terminal runs get a real cancel: Ctrl-C, then SIGTERM, then SIGKILL to that command's own process group, with the shell left running. It also reaches input, kill and pane close, between keystrokes. A tmux run gets Ctrl-C in its own window, and the window is closed if that does not end it. Agent commands end with the session. Sign-out, an account change, and switching Terminal off each stop every command the agent started, including a run whose wait window has passed and any tmux run window, before the shells go. A command the user started is never touched: only commands a run started count as the agent's. A tmux run's pane carries a per-run @sim-run-id tag. Stops act on that pane only, and only while the tag still matches, so a pane the user split beside it, or an id a restarted tmux server handed to one of the user's panes, is never touched. Dormant while off. With the executor off for this user, the app opens neither the inbox nor the doorbell. It rechecks registration on launch, session change, settings toggles and every 15 minutes. Against a Sim without these routes (404 or 405) it stays dormant until the next of those triggers. Approvals. A chat in the background that waits on the user's approval raises a native notification. The notification only opens the chat at its approval card. It closes once the call is decided, and it never shows the command, since it can appear on a locked screen. Turn binding. The preload exposes desktopExecutor.getDevice(), so the composer from #8650 binds turns. It returns null while Sim reports the executor off. Shared projections. The browser, terminal and local-filesystem result projections move from the web app into @sim/desktop-bridge (tool-results, local-filesystem-tools). The chat view and the executor now build identical model-facing results. The renderer behaviour is unchanged; its existing tests pass as they are. The one code path removed, a REJECTED terminal code mapped to cancelled, was dead: nothing produces that code. Not in this PR import_local_files in the background is answered as "not run" here; #8672 adds the upload route and the runner. The web chat view going display-only for bound runs, sidebar status and turn-complete notifications are in the companion web PR. That PR must land before the flag is turned on. Prevent-sleep and browser takeover are in #8671. Test plan Unit tests, written first and red before the code existed: the executor state machine: claim, queue order, renewal while queued and running, delivery retry, 413 compaction, superseded and duplicate results, Stop of a queued call and of a running call, 410 revocation, crash recovery, 401 re-registration, the claim cap, pause on suspend, and write-ahead of started; the encrypted journal; the doorbell: rotation, reconnect, staleness and unregistered; approval notifications; terminal cancel and its escalation; Stop of input and kill; sign-out stopping the agent's running command and an in-flight tmux run, and leaving a user-started command alone; the agent's command staying the agent's after an interactive detach. Guards were checked by mutation: write-ahead off fails its test, and terminal cancel or journal recovery off fails E2E scenarios E and C. Packaged-app E2E (apps/desktop/e2e/background-executor.spec.ts), run with Playwright _electron against a fixture Sim that speaks the device protocol. The JSON report goes to BACKGROUND_EXECUTOR_REPORT_PATH, wired in desktop-e2e.yml. A. Chat A drives the browser (open, then 10 clicks) while chat B runs three terminal commands and a read_local_file. Meanwhile the window navigates to chat C, then to another workspace, then fully reloads. Every call completes exactly once with its own token. The page sees exactly 10 clicks, and the commands run once each, in order. Chat B cannot see chat A's tabs. Nothing touches /api/copilot/confirm or /authorize. p95 pickup is under 1.5 s. B. A result produced while Sim is unreachable is delivered once after reconnecting. C. A crash in the middle of a command is reported as outcome unknown after relaunch, and the command runs once. E. Stop from elsewhere ends a running browser_wait_for and a sleep command. The process is gone, and both results are acknowledged as superseded. F. An approval in a background chat raises one notification without the command. Nothing is claimed before approval, and the call is claimed within 1.5 s of approval. G. Of two installs, only the bound device claims the call. H. A device Sim has not enabled returns no device to the composer; an enabled one returns its device. All 7 scenarios pass. With the executor not started, all 7 fail. Full gate on the rebased branch: lint:check, type-check, check:audits, test, docs-manifest:check and the block registry check. Under heavy machine load, a few unrelated timing-bound tests (the route inventory, markdown perf) time out; each passes when run on its own.
Open Graph Description: Summary Phase 2a of the desktop background executor. The Sim desktop app now picks up and runs the desktop tool calls of turns bound to it from Electron main, so a chat keeps working after the user...
X Description: Summary Phase 2a of the desktop background executor. The Sim desktop app now picks up and runs the desktop tool calls of turns bound to it from Electron main, so a chat keeps working after the user...
Opengraph URL: https://github.com/simstudioai/sim/pull/8668
X: @github
Domain: github.com
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react-reconciler,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@d5750093facf |
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:c7218b6e-73a8-af0a-593c-7ae7fb6259c5 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | ECB0:2781FE:237BDC:319933:6AFB51D0 |
| html-safe-nonce | 0164fb21fbfd57aa1fb98b371375f934960adfb76175566c5a0997ef2c9e7f93 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFQ0IwOjI3ODFGRToyMzdCREM6MzE5OTMzOjZBRkI1MUQwIiwidmlzaXRvcl9pZCI6IjY5MzIyNzY1ODU2MjU3Njg0MDAiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 86c570444a021c1f13289d3d0e77cb312ed1448c02b1d62d1278ffafa49a66b1 |
| hovercard-subject-tag | pull_request:4754847126 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/simstudioai/sim/pull/8668/files |
| twitter:image | https://avatars.githubusercontent.com/u/40672544?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/40672544?s=400&v=4 |
| og:image:alt | Summary Phase 2a of the desktop background executor. The Sim desktop app now picks up and runs the desktop tool calls of turns bound to it from Electron main, so a chat keeps working after the user... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 7122bb414b542dba14d71a3f0b9f6fd2abce715b9f5912d082800563e6c806d1 |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/simstudioai/sim git https://github.com/simstudioai/sim.git |
| octolytics-dimension-user_id | 199344406 |
| octolytics-dimension-user_login | simstudioai |
| octolytics-dimension-repository_id | 912559512 |
| octolytics-dimension-repository_nwo | simstudioai/sim |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 912559512 |
| octolytics-dimension-repository_network_root_nwo | simstudioai/sim |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | cbf66c024bb6d10e6955baa7413c54cf13a201bb |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width