Skip to content

fix(desktop): keep a chat-view import alive while it works, by the lease its session renews - #8742

Merged
waleedlatif1 merged 7 commits into
stagingfrom
fix/desktop-long-import-budget
Oct 7, 2026
Merged

waleedlatif1 merged 7 commits into
stagingfrom
fix/desktop-long-import-budget

Conversation

@waleedlatif1

@waleedlatif1 waleedlatif1 commented Oct 7, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • The bug: an import the chat view runs was force-failed as "result lost" once it ran past the default tool budget: 60 s, plus the 30 s resume grace. It was still working (a large file uploading). Only device-bound desktop calls got a lease-backed budget.
  • The fix, reusing the device lease machinery:
    • an import claimed by the chat view takes the execution lease under the claiming session (chat-view:<sessionId> owner token);
    • the chat view renews it through the existing /api/desktop/tool/lease route and renewDesktopToolLease use case, every 20 s while the import runs;
    • the turn's resume watchdog extends the call's deadline to the end of a live lease, and fails it only once the lease lapses.
  • Scope: only import_local_files. Imports run as long as their files take (up to 1,000 entries of up to 64 MB each). Reads finish in seconds (64 KB of text, or an 8 MB rendered visual) and keep the default budget. Browser and terminal claims are unchanged.
  • Ungated behaviour:
    • With no renewals (an older desktop), the lease set at claim usually lapses within the old budget, so the call fails at 60 s + 30 s as today. Two exceptions:
      • a claim made more than 30 s after the wait starts carries its lease past the old deadline, which can extend the wait by up to about 30 s;
      • for any tool, a lease lookup that fails at the deadline is retried for up to one lease (60 s) before the call is failed.
    • With renewals, the call lives while renewed. A closed or crashed window settles as outcome unknown about one lease after the renewals stop.
    • However long the renewals go on, the wait is capped at the start plus CLIENT_TOOL_RESULT_TIMEOUT_MS, the cap device-bound calls have. So an import that hangs while its page stays alive still settles.
    • The page renews every 20 s from when the import starts. The desktop claims the call before it scans the folder, within its 8 s authorization timeout, so every renewal follows the claim, and the claim's own 60 s lease covers the time until the first one. The renewal lives with the import, not the chat view, so switching chats doesn't stop it (fix(mothership): keep local file tools running when the chat view changes #8666).
    • A call at the cap is failed without reading its lease.
    • The force-fail log says what ended the wait: the plain budget, the cap, a lease that is no longer live, or lease lookups that failed for a whole lease. It also gives how long the wait lasted, and the wait span's budget includes any extension.
  • Renew auth: a renewal extends only a call the caller's own session claimed. It must be the same user, the call still running, claimed by the chat view on an unbound run, and its lease not yet lapsed. Another session, another user, a settled call and a device-held call are all refused (410).
  • Fixes the native-files.ts sign-out comment: nobody reports a tool cancelled at sign-out; the server's resume watchdog settles it.

Type of Change

  • Bug fix

Testing

  • Real Postgres and Redis integration (desktop-tool-chat-view-lease.integration.ts):
    • the claim takes a lease as long as the default budget, which lapses without renewals;
    • the claiming session renews it;
    • a read takes no lease;
    • another session, another user, a settled call and a device-held call can't renew.
  • Lifecycle unit tests:
    • a renewed import isn't failed at the 90 s budget, and is failed once the lease lapses;
    • a failed lease lookup is checked again;
    • a lookup that keeps failing gives up after one lease;
    • renewals that go on past the client cap still settle at the cap, without a lease read at the cap;
    • a lookup that stalls counts as failed;
    • a call replaced while its lease is read is left to its new watchdog;
    • the force-fail log names the reason in each case.
    • Each goes red without its code.
  • Client heartbeat unit tests: against a fake lease server, the lease stays live through a 70 s scan and a long upload and lapses once the import ends. Renewals continue when the claim takes 7 s. They stop on 410, and keep going through a 401, a 429 and a 503 that arrive after the claim. Each goes red without its code.
  • Live-Sim Electron E2E (cold, netns, 8 cores):
    • an import whose first upload takes 120 s, while the user is in another chat, completes;
    • a window crashed mid-import settles as outcome unknown within about one lease.
    • On staging without the fix, the first test fails: Sim logs "exceeded its resume wait budget; force-failing" with waitBudgetMs: 90000, and the model gets "result never came back".

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel

vercel Bot commented Oct 7, 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 2:56pm UTC

Request Review

@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 11 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/lib/mothership/tools/client/native-files.ts Outdated
Comment thread apps/sim/lib/mothership/request/lifecycle/run.ts Outdated
@greptile-apps

greptile-apps Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[High risk] Adds session-based lease renewal for long-running imports.

The change since the last review appears safe to merge.

Summary

The PR keeps long-running desktop imports alive through a lease renewed by the claiming session.

  • Since the last review, only the integration test’s starting lease changed, from 2 to 10 seconds.
  • The longer starting lease gives slow test runs more time without weakening the renewal check.
  • No new findings. The supplied previous threads were unnumbered; matching test-rule concerns were not reposted.
Diagram
sequenceDiagram
  participant Page as Chat page
  participant Desktop
  participant Server
  participant Watchdog
  Page->>Desktop: Request import manifest
  Desktop->>Server: Claim import under current session
  Server-->>Desktop: Grant 60-second lease
  loop Every 20 seconds while import runs
    Page->>Server: Renew claimed import lease
  end
  Watchdog->>Server: Read lease after default wait
  Server-->>Watchdog: Time remaining
  Watchdog->>Watchdog: Extend wait within client cap
  Page->>Server: Report import result and stop renewals
Loading

Reviews (8) · Last reviewed commit: "test(desktop): give the renewal test's l..." · Reviewed by Greptile

Comment thread apps/sim/lib/mothership/tools/client/native-files.ts Outdated
Comment thread apps/sim/lib/mothership/request/lifecycle/run.ts Outdated
Comment thread apps/sim/lib/mothership/request/lifecycle/run.test.ts Outdated
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptileai review

…ase its session renews

An import the chat view runs was failed as lost once it ran past the default tool budget (60 s plus
the 30 s resume grace), though it was still uploading. Its claim now takes the execution lease
under the claiming session, the chat view renews it through the existing lease route while the
import runs, and the turn's wait budget runs to the end of that lease. Without renewals the lease
lapses with the default budget, so a closed or crashed window still settles within about a lease.
…res, and retry a failed lease lookup

- The chat view stops renewing only when the server refuses the call (410)
- The resume watchdog retries a failed lease lookup for up to one lease instead of treating it as a lapse
- The lifecycle tests assert what the agent is resumed with, and when
…enew at once, and report the extended wait

- A chat-view import's lease extends its wait only up to the cap every client tool has
  (CLIENT_TOOL_RESULT_TIMEOUT_MS), so an import that hangs with its page alive still settles
- The page renews the lease as soon as the import starts, then every heartbeat
- The force-fail log names an extended wait and how long it lasted; the wait span's budget
  includes the extension
- Tests for the cap, the bound on failed lease lookups, and the client heartbeat
@waleedlatif1
waleedlatif1 force-pushed the fix/desktop-long-import-budget branch from e310c4c to d7bfc58 Compare October 7, 2026 12:23
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptileai review

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review

@cubic-dev-ai

cubic-dev-ai Bot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review

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

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

Turn on auto-fix | Re-trigger cubic

Comment thread apps/sim/lib/mothership/request/lifecycle/run.ts
Comment thread apps/sim/lib/mothership/request/lifecycle/run.ts Outdated
Comment thread apps/sim/lib/mothership/tools/client/native-files.ts Outdated
Comment thread apps/sim/lib/mothership/tools/client/native-files.ts Outdated
Comment thread apps/sim/lib/mothership/request/lifecycle/run.ts
Comment thread apps/sim/lib/mothership/tools/client/native-files.test.ts Outdated
…new from the start of an import

- Each lease lookup gets 5 s (and Stop) before it counts as failed, so a stalled read cannot hold
  the wait past its deadlines
- A call replaced while its lease was read is left to its new watchdog
- The page renews from the moment it asks for the manifest; a refusal counts only once the claim
  is confirmed, and renewing stops on every exit
- Heartbeat tests check the lease a fake server holds, not request counts
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptileai review

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review

@cubic-dev-ai

cubic-dev-ai Bot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review

@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 12 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/lib/mothership/tools/client/native-files.ts Outdated
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptileai review

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review

@cubic-dev-ai

cubic-dev-ai Bot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review

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

…a capped call up without reading its lease

The first heartbeat now comes one beat in, after the desktop's bounded claim, so every renewal
follows the claim and a refusal always means the call was stopped, settled, or lapsed. A call at
its ceiling is given up before its lease is read, and the force-fail log names whether the
budget, the cap, a lapsed lease, or failed lease lookups ended the wait.
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptileai review

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review

@cubic-dev-ai

cubic-dev-ai Bot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review

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

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/lib/mothership/tools/client/desktop-tool-chat-view-lease.integration.ts Outdated
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptileai review

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review

@cubic-dev-ai

cubic-dev-ai Bot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review

@waleedlatif1 I have started the AI code review. It will take a few minutes to complete.

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptileai review

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review

@cubic-dev-ai

cubic-dev-ai Bot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review

@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 12 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 5d3806b into staging Oct 7, 2026
38 checks passed
@waleedlatif1
waleedlatif1 deleted the fix/desktop-long-import-budget branch October 7, 2026 16:32

This branch was previously deployed

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