Skip to content

feat(desktop): import local files from the background executor - #8672

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

waleedlatif1 merged 9 commits into
stagingfrom
feat/desktop-executor-import

Conversation

@waleedlatif1

@waleedlatif1 waleedlatif1 commented Oct 6, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

A chat whose turn runs on the desktop can now import a local file or folder into the workspace while the user is in another chat, tab or workspace. Until now the background executor answered import_local_files as not run.

Builds on #8668 (the background executor), now on staging.

Sim

  • PUT /api/desktop/tool/import stores one entry of a claimed import, either a directory or a file whose bytes are the raw body, capped at 64 MB.
  • Before the body is read, the entry is admitted. All of these must hold:
    • the caller's session owns the device;
    • the call is a running import_local_files bound to that device;
    • the request carries the execution token that claimed it, in the x-sim-execution-token header rather than the query, so the token stays out of load balancer, CDN and trace URLs.
  • The target workspace and folder come from Sim's record of the call, never from the request. Writing there is authorized the same way any file creation is.
  • Each path segment becomes a folder under the target. Existing folders are reused with a find-or-create that converges when two requests land at once. A file never overwrites one already there.
  • An unrecognized device gets 401 so it registers again. Every other refusal is concealed the same way file routes conceal theirs.
  • A file must declare its length (411 otherwise), and a body that does not match it is refused (400), so a cut-off file is never stored. A file entry with no bytes is refused, folders an import creates are audited and announced, and a name a workspace cannot hold (blank, a dot segment, a backslash) is refused at the contract.
  • Proxy: /api/desktop/tool/import and /api/desktop/tool/file are left out of the proxy matcher. Running the proxy makes Next buffer the body and cut it at 10 MB, which also silently truncated staging's browser downloads above that. Both routes refuse the dedicated MCP host themselves, as the proxy did. The download route also checks a declared length against what arrived; a download without one is still accepted from shells already in use.

Desktop

  • The runner reads the manifest from the call's own arguments. It sends each directory first, then each file in chunks checked against the revision the manifest listed, and reports what landed.
  • If the import fails part way, it reports the partial result as outcome unknown and not to retry. Stop aborts between entries and during an upload. A rate-limited entry is sent again once the limit clears; if the limit outlasts every retry, the result lists exactly what landed, and an import where nothing landed stays safe to ask for again.
  • A name Sim cannot store stops the whole import before anything lands.
  • The chunked read, the size check and the result projections now live in @sim/desktop-bridge/tool-results. The chat view's import and the background import report the same shapes.

Tests

  • Integration (import.integration.ts, real Postgres and file storage):

    • a tree lands under the target folder;
    • existing folders merge and files never overwrite;
    • a wrong token is refused;
    • a call that is no longer running is refused;
    • another user's import is refused even with the right device id and token.
  • Unit (runner.test.ts, real files on disk):

    • a folder's tree reaches Sim with the bytes on disk;
    • a failure part way reports what landed;
    • Stop stores nothing more;
    • an unreadable source stores nothing.

    These were verified red against the previous runner.

  • E2E, scenario D in background-executor.spec.ts: a folder holding a 9 MB file, which crosses Electron in several chunks, is imported while the window shows another chat. Sim receives the tree once, byte for byte. The full suite (A–H) passes.

Type of Change

  • New feature

Checklist

  • Full local gate passes
  • Tests verified failing before the change

@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 1:41am 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.

@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 apps/sim/app/api/desktop/tool/import/route.ts
Comment thread packages/desktop-bridge/src/tool-results.ts Outdated
Comment thread apps/sim/lib/desktop/application/import.ts
Comment thread apps/sim/lib/desktop/application/import.integration.ts
@greptile-apps

greptile-apps Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[High risk] Adds file import capability to the background executor protocol.

The PR appears safe to merge based on the reviewed changes and resolved prior findings.

Summary

The PR enables a claimed desktop background executor call to import local files and folders into its recorded workspace, with bounded uploads and partial-result reporting.

  • Adds an authenticated, token-bound import route and shared file-read and result handling.
  • Adds integration, unit, and desktop end-to-end coverage for the import flow.
  • The latest revision also changes consent-aware analytics, restored-chat routing, and removes an unused table-update worker.
Diagram
sequenceDiagram
    participant D as Desktop executor
    participant S as Sim import route
    participant W as Workspace file service
    D->>D: Read manifest and file chunks
    loop Each directory or file
        D->>S: PUT entry with execution token header
        S->>S: Authenticate and validate running claim
        S->>W: Revalidate, create or reuse folders, store file
        W-->>S: Stored entry
        S-->>D: Entry ID and name
    end
    D->>S: Complete call with imported entries or partial result
Loading

Reviews (16) · Last reviewed commit: "docs(desktop): document the import entry..." · Reviewed by Greptile

Comment thread apps/sim/app/api/desktop/tool/import/route.ts
Comment thread apps/sim/lib/desktop/application/import.ts Outdated
Comment thread apps/sim/lib/desktop/application/import.ts Outdated
Comment thread apps/sim/lib/desktop/application/import.ts Outdated
@waleedlatif1
waleedlatif1 force-pushed the feat/desktop-executor-main branch from de04c40 to 93a0f75 Compare October 6, 2026 16:15
@waleedlatif1
waleedlatif1 requested a review from a team as a code owner October 6, 2026 16:15
@waleedlatif1
waleedlatif1 force-pushed the feat/desktop-executor-import branch from bd60686 to bf50837 Compare October 6, 2026 17:27
@waleedlatif1
waleedlatif1 force-pushed the feat/desktop-executor-import branch from bf50837 to 9da5c3c 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 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-main branch from f6d9127 to 6cf16e3 Compare October 6, 2026 18:05
@waleedlatif1
waleedlatif1 force-pushed the feat/desktop-executor-import branch from f8152fc to 262a715 Compare October 6, 2026 18:34
@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-import branch from 262a715 to 0dd29c7 Compare October 6, 2026 19:00
@waleedlatif1
waleedlatif1 force-pushed the feat/desktop-executor-web branch from 1aa2322 to 684261b Compare October 7, 2026 00:26
@waleedlatif1
waleedlatif1 force-pushed the feat/desktop-executor-import branch from 1e17305 to 90f104d 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 26 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

@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 26 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

A chat whose turn runs on the desktop can now import a local file or folder
into the workspace while the user is elsewhere, instead of the background
executor answering import_local_files as not run.

- Sim: PUT /api/desktop/tool/import stores one entry of a claimed import.
  The entry is admitted before its body is read: the caller's session must
  own the device, the call must be a running import_local_files bound to that
  device, and the request must carry the token that claimed it. The target
  workspace and folder come from Sim's record of the call, never from the
  request, and writing there is authorized as any file creation is. Each
  path segment becomes a folder under the target, reusing folders already
  there (find or create, converging when two land at once); a file never
  overwrites one already there.
- Desktop: the runner reads the manifest from the call's own arguments,
  sends each directory, then each file in chunks checked against the
  manifest's revision, and reports what landed. A failure part way reports
  the partial result as outcome unknown, not to be retried. Stop aborts
  between entries and mid-upload.
- The chunked read, the size check and the result projections move to
  @sim/desktop-bridge/tool-results, so the chat view's import and the
  background one report the same shapes.
…d their folders

- The proxy no longer runs for the desktop's raw upload routes (import, and
  the browser file transfer that has the same shape). Running it made Next
  buffer the body and cut it off at its 10 MB proxy limit. The import route
  also requires a declared length and refuses a body that does not match
  it, so a cut-off file is never stored as complete.
- A file entry with no body is refused instead of stored as an empty file.
- A name Sim cannot store (one with a backslash) is refused for the whole
  import before anything lands, and at the contract.
- A chunk that runs past the size the manifest listed is refused, like one
  that ends early.
- A rate-limited entry is sent again after the limit clears. A 429 means
  nothing was stored, so a large tree no longer fails part way.
- Folders an import creates are audited as folder creations and announced to
  the workspace's file views, as folders made by hand are.
- Tests record what the fake Sim stored instead of asserting mock calls. The
  integration suite removes its audit rows.
…ask for again

When Sim's rate limit outlasts every retry, it refused the entry outright,
so the result lists exactly what landed instead of being outcome unknown.
An import where nothing landed is no longer marked do-not-retry.
- The desktop import and browser file routes refuse the dedicated MCP host
  themselves, as the proxy did before they left its matcher.
- The import's execution token travels in a header, not the query string,
  so it stays out of load balancer, CDN and trace URLs.
- A name that trims to nothing or to a dot segment is refused at the
  contract and, for the whole import, before anything lands, through one
  shared rule. Such a name no longer surfaces as a 500 part way through.
- The browser download route also requires a declared length and refuses a
  body that does not match it.
- Route tests cover 411, 413, a length mismatch, an entry that is not
  admitted reading no body, the 401 mappings, the missing token header and
  an unstorable name.
…red length

The truncation check applies whenever a download declares its length. A
shell already in use that streams one without a length is still accepted
under the byte ceiling. The E2E fixture's import route now refuses a file
without a declared length, as Sim's does, so the device is proven to send
one.
@waleedlatif1
waleedlatif1 changed the base branch from feat/desktop-executor-web to staging October 7, 2026 01:41
@waleedlatif1
waleedlatif1 force-pushed the feat/desktop-executor-import branch from 797cb63 to 06877f0 Compare October 7, 2026 01: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 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 26 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 6713fab into staging Oct 7, 2026
36 of 37 checks passed
@waleedlatif1
waleedlatif1 deleted the feat/desktop-executor-import branch October 7, 2026 02:08

This branch was previously deployed

1 inactive deployment
Preview — 06877f02 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