fix(browser): harden desktop tool lifecycle - #7253
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
Greptile SummaryThis PR hardens the desktop browser and terminal tool lifecycle across authorization, cancellation, execution, confirmation delivery, and renderer unloads.
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains.
|
| Filename | Overview |
|---|---|
| apps/desktop/src/main/ipc.ts | Adds an authorization deadline, lifecycle diagnostics, and current-tool validation before native browser or terminal execution. |
| apps/sim/app/api/copilot/confirm/route.ts | Extends confirmation handling for known pre-claim terminal outcomes and claimed indeterminate native exits. |
| apps/sim/lib/copilot/async-runs/repository.ts | Adds state- and claimant-specific async tool completion transitions used to reconcile lifecycle races. |
| apps/sim/lib/copilot/tools/client/completion.ts | Adds compact retry, keepalive, and beacon delivery paths for client tool completion. |
| apps/sim/lib/browser-agent/transport.ts | Aligns browser authorization, queueing, execution, and bridge-delivery timeout behavior. |
| apps/desktop/src/main/browser-agent/driver.ts | Normalizes wait budgets, strengthens screenshot coordinate verification, validates scroll direction, and improves scoped execution observability. |
| packages/browser-protocol/src/index.ts | Separates current and retired browser tool classifications while centralizing wait-time normalization. |
Sequence Diagram
sequenceDiagram
participant R as Renderer
participant M as Electron main
participant A as Authorization API
participant N as Native tool
participant C as Confirmation API
R->>M: Execute tool call
M->>A: Claim pending call
alt Authorization accepted
A-->>M: Authorized tool, args, and scope
M->>N: Execute authorized action
N-->>M: Known result
M-->>R: Native outcome
R->>C: Deliver completion
else Authorization rejected or times out
A-->>M: Rejection or timeout
M-->>R: Known pre-dispatch error
R->>C: Deliver failed completion
end
Reviews (7): Last reviewed commit: "fix(copilot): interrupt pending tool wai..." | Re-trigger Greptile
There was a problem hiding this comment.
2 issues found across 25 files
Confidence score: 2/5
- In
apps/desktop/src/main/ipc.ts, the 8-second abort can race with the server marking an authorization request asrunning, causing a false authorization failure and skipped native execution; coordinate timeout handling with server-side claim state. - In
apps/desktop/src/main/browser-agent/cdp.ts, successful CDP metrics can suppress the page URL and title inbrowser_screenshot; retaingetViewportInfofor metadata while using CDP only for dimensions.
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="apps/desktop/src/main/browser-agent/cdp.ts">
<violation number="1" location="apps/desktop/src/main/browser-agent/cdp.ts:447">
P2: When CDP metrics succeed, `browser_screenshot` stops returning the page URL and title because this non-null viewport bypasses `getViewportInfo`. Preserve those fields while sourcing only dimensions from CDP.</violation>
</file>
<file name="apps/desktop/src/main/ipc.ts">
<violation number="1" location="apps/desktop/src/main/ipc.ts:516">
P1: The 8-second fetch abort can race with the server-side claim: if the authorization route moves the call to `running` just before the timeout, this handler returns an authorization failure and skips native execution, leaving the one-shot call stuck. Add claim reconciliation/cancellation for timed-out authorizations, or make the claim reversible until the client confirms receipt.</violation>
</file>
Reply with feedback, questions, or to request a fix.
Fix all with cubic | Re-trigger cubic
663c840 to
e6e69db
Compare
|
@cubic review |
@waleedlatif1 I have started the AI code review. It will take a few minutes to complete. |
There was a problem hiding this comment.
4 issues found across 27 files
Confidence score: 2/5
apps/sim/lib/copilot/request/lifecycle/run.tscan let a hung tool run inherit a concurrent confirmation’s one-hour wait budget instead of its 60-second watchdog, delaying or stalling request completion; preserve per-tool watchdog enforcement.apps/desktop/src/main/browser-agent/cdp.tsandapps/desktop/src/main/browser-agent/driver.tscan associate a captured image with stale viewport metadata when the browser resizes or navigates during capture, producing inconsistent screenshots for downstream consumers; revalidate and reject mismatched captures after capture.apps/sim/app/api/copilot/confirm/route.tsmay finalize a retired browser call when it reportserrororcancelled, treating the result as an executable native outcome; restrict the preclaim exception to the current browser call.
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="apps/sim/lib/copilot/request/lifecycle/run.ts">
<violation number="1" location="apps/sim/lib/copilot/request/lifecycle/run.ts:1033">
P1: When a confirmation wait and an unrelated tool run in parallel, this maximum budget makes the hung tool wait for the approval's one-hour budget instead of its 60-second watchdog. Preserve per-tool watchdog enforcement for bounded tools while allowing the approval promise to remain durable.</violation>
</file>
<file name="apps/desktop/src/main/browser-agent/cdp.ts">
<violation number="1" location="apps/desktop/src/main/browser-agent/cdp.ts:427">
P2: When the page resizes or navigates between `Page.getLayoutMetrics` and `Page.captureScreenshot`, `cssViewport` describes the pre-capture surface but the returned image can belong to the new surface. Revalidate the viewport after capture, or retain the post-capture consistency check for the CSS-metrics path, before exposing coordinates to the agent.</violation>
</file>
<file name="apps/desktop/src/main/browser-agent/driver.ts">
<violation number="1" location="apps/desktop/src/main/browser-agent/driver.ts:2147">
P2: When the visible browser resizes between CDP layout metrics and screenshot capture, `shot.viewport` describes the pre-capture viewport, but this branch skips any post-capture consistency check. Reject mismatched capture metadata or retain a post-capture viewport check before returning coordinates for `browser_click_at`.</violation>
</file>
<file name="apps/sim/app/api/copilot/confirm/route.ts">
<violation number="1" location="apps/sim/app/api/copilot/confirm/route.ts:272">
P2: When a pending retired browser call reports `error` or `cancelled`, this new preclaim exception treats it as an executable native outcome and finalizes the retired call. Restrict the preclaim exception to current browser tool names; retain the broader classification only for already-running legacy completions if that compatibility is required.</violation>
</file>
Reply with feedback, questions, or to request a fix.
Fix all with cubic | Re-trigger cubic
|
@cubic-dev-ai review this PR |
@waleedlatif1 I have started the AI code review. It will take a few minutes to complete. |
There was a problem hiding this comment.
1 issue found across 29 files
Confidence score: 3/5
- In
apps/sim/app/api/copilot/confirm/route.ts, a page-unload race can let desktop authorization claim the row after the request readspending, causing a 404 while the row remainsrunningand the native completion is suppressed; handle this race so the authorization flow can complete reliably.
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="apps/sim/app/api/copilot/confirm/route.ts">
<violation number="1" location="apps/sim/app/api/copilot/confirm/route.ts:397">
P1: When page unload races desktop authorization, the authorization claim can win after this request reads `pending`; this branch returns 404 and leaves the row `running`. The unload path then suppresses the native completion because cancellation already occurred, so settle the claimed action as an indeterminate, non-retryable failure or coordinate cancellation so the row cannot remain running.</violation>
</file>
Tip: cubic can generate docs of your entire codebase and keep them up to date. Try it here.
Fix all with cubic | Re-trigger cubic
d2486c6 to
6029ab6
Compare
|
@cubic-dev-ai review this PR |
@waleedlatif1 I have started the AI code review. It will take a few minutes to complete. |
There was a problem hiding this comment.
1 issue found across 32 files
Confidence score: 3/5
- In
apps/sim/lib/copilot/request/lifecycle/run.ts, an abort with an unresolved pending tool can remain blocked until the watchdog deadline, delaying lifecycle shutdown and potentially user-visible cancellation; race the lifecycle abort signal withwatchdogControllerso the wait exits promptly.
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="apps/sim/lib/copilot/request/lifecycle/run.ts">
<violation number="1" location="apps/sim/lib/copilot/request/lifecycle/run.ts:1120">
P1: When the lifecycle aborts with an unresolved pending tool, this race waits until the watchdog deadline because it listens only to `watchdogController`. Race the lifecycle abort signal and exit the wait so the existing cancellation path runs immediately.</violation>
</file>
Tip: cubic can generate docs of your entire codebase and keep them up to date. Try it here.
Fix all with cubic | Re-trigger cubic
|
@cubic-dev-ai review this PR |
@waleedlatif1 I have started the AI code review. It will take a few minutes to complete. |
There was a problem hiding this comment.
No issues found across 32 files
Confidence score: 5/5
- Automated review surfaced no issues in the provided summaries.
- No files require special attention.
Tip: cubic can generate docs of your entire codebase and keep them up to date. Try it here.
Re-trigger cubic
3724ef3 to
b1aabef
Compare
|
@cubic-dev-ai review this PR |
@waleedlatif1 I have started the AI code review. It will take a few minutes to complete. |
There was a problem hiding this comment.
No issues found across 32 files
Confidence score: 5/5
- Automated review surfaced no issues in the provided summaries.
- No files require special attention.
Tip: cubic can generate docs of your entire codebase and keep them up to date. Try it here.
Re-trigger cubic
Summary
Type of Change
Testing
bun run lintandbun run lint:checkbun run check:audits(39 audits)@sim/app,@sim/desktop,@sim/browser-protocol,@sim/desktop-bridgegit diff --checkReview focus: native execution versus confirmation-delivery lifecycle, exact cancellation scoping, timeout hierarchy, and current/retired browser tool classification.
Checklist
Screenshots/Videos
N/A — no UI changes.