Skip to content

fix(mothership): start no tool call with less than a minute of its deadline left - #9092

Merged
waleedlatif1 merged 2 commits into
stagingfrom
fix/tool-start-budget
Oct 16, 2026
Merged

waleedlatif1 merged 2 commits into
stagingfrom
fix/tool-start-budget

Conversation

@waleedlatif1

@waleedlatif1 waleedlatif1 commented Oct 15, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • A call whose deadline was nearly spent could still start: an approval granted seconds before the deadline, a workflow server fallback, or a client pickup would launch a handler that the deadline then abandoned with its outcome unknown. That is a real side-effect risk once the worker stamps deadlines on every call.
  • One shared minimum start budget, SIM_TOOL_MIN_START_BUDGET_MS = 60 s. It is the same constant takeover re-runs already used, now renamed for both.
  • Every start point refuses to start a call with less than that left, through toolStartWindowClosed / lastToolStartAt in deadline.ts:
    • the executor
    • opening and honoring an approval (the prompt wait now ends at the last start time)
    • the workflow server fallback
    • client pickup
  • The same window is enforced where a late client would start the call: claimWorkflowToolExecution and claimDesktopToolCall refuse a call whose saved deadline leaves less than the budget, and a client call nothing claimed by its deadline is settled as not run rather than outcome unknown.
  • A refused call is settled durably as "did not run". The executor commits the failure; a client call nothing claimed takes the unclaimed-only settlement.
  • Why 60 s: about 99% of non-workflow tool calls finish within a minute (p90 ≈ 7 s, p99 ≈ 82 s), so a call that starts with at least that much left almost always finishes.
  • Calls without a deadline behave exactly as before.

Release order

  1. This PR must be in a Sim release before the worker PR that stamps deadlineMs on handed frames (simstudioai/mothership#706) reaches prod.

Type of Change

  • Bug fix

Testing

Each new test fails on staging and passes here:

  • executor.test.ts: a handler with 30 s of its deadline left is not started
  • permission.test.ts: an approval granted with under a minute left is not honored
  • workflow-client-fallback.test.ts: no server takeover with under a minute left
  • handlers.test.ts: an unclaimed client call with under a minute left is settled as not run without being offered; one nothing claimed by its deadline is settled as not run
  • abandoned-runs.integration.ts / desktop-tool-authorization.integration.ts: browser and desktop claims are refused with under a minute left

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 15, 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 15, 2026 11:19pm UTC

Request Review

@greptile-apps

greptile-apps Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The changes since the previous review introduce no new blocking issue.

Summary

This PR requires at least one minute remaining before a tool call starts.

  • Deadline-bound tool calls start only when at least a minute remains.

No new actionable findings were identified in the changes since the previous review. Tests were inspected, not run.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Tool call] --> B{Deadline present?}
  B -->|No| C[Existing start rules]
  B -->|Yes| D{At least one minute left?}
  D -->|Yes| E[Check permission and ownership]
  E --> F[Start work]
  D -->|No| G[Refuse new start]
Loading

Reviews (2) · Last reviewed commit: "fix(mothership): refuse a late claim at ..." · Reviewed by Greptile

Comment thread apps/sim/lib/mothership/request/handlers/tool.ts
Comment thread apps/sim/lib/mothership/request/tools/workflow-client-fallback.ts

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

Turn on auto-fix | Re-trigger cubic

Comment thread apps/sim/lib/mothership/request/handlers/tool.ts
Comment thread apps/sim/lib/mothership/request/tools/workflow-client-fallback.ts
Comment thread apps/sim/lib/mothership/request/tools/permission.ts
Comment thread apps/sim/lib/mothership/request/tools/deadline.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 15, 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 13 files

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

Turn on auto-fix | Re-trigger cubic

Comment thread apps/sim/lib/mothership/async-runs/repository.ts
@waleedlatif1
waleedlatif1 merged commit 455c2bd into staging Oct 16, 2026
55 checks passed
@waleedlatif1
waleedlatif1 deleted the fix/tool-start-budget branch October 16, 2026 01:05

This branch was previously deployed

1 inactive deployment
Preview — 9430f1f1 Deployed Oct 15, 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