Repository navigation
fix(mothership): take over runs whose controller died and re-run their interrupted tool - #9059
Conversation
…r interrupted tool A Chat run is driven by the Sim process that admitted it. When that process stops mid-run (a deploy's old task set is terminated, or a crash) and no browser is attached, nothing takes the run over: recovery only ran from a browser reconnect, the in-flight tool's result was never recorded, and the worker eventually ended the run as detached. - Every Sim process now looks every 20s for interactive runs whose chat lock is gone and takes each over through the same recovery a reconnect runs, acting as the run's user under a delegated principal that re-checks that user's current access. The chat lock and controller token still admit exactly one controller, so a racing reconnect or another process loses. - A user who lost access gets the run settled as an error and the worker is told to stop it. - A Sim tool whose owner died before recording a result (its execution lease lapsed while the call was still running) is claimed again under a new owner token and run again, by the server for a workflow tool. Each start is counted; after three, the call fails with a clear message instead. - A takeover waits while one of the run's Sim tools still holds its lease.
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
… dispose chat pubsub in tests
[High impact] The PR appears safe to merge; no new blocking issue was found. SummaryAdds automatic recovery for Chat runs whose controller died, with bounded tool retries and fresh ownership checks.
|
|
@greptileai review |
|
@cubic-dev-ai review |
@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 and verified against the latest diff
Confidence score: 3/5
- In
abandoned-runs.integration.ts, an unsetTEST_REDIS_URLbecomes the invalid string"undefined", so environment validation fails before the Redis-gated suite can skip. AssignREDIS_URLonly whenurlis set.
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="apps/sim/lib/mothership/request/application/abandoned-runs.integration.ts">
<violation number="1" location="apps/sim/lib/mothership/request/application/abandoned-runs.integration.ts:50">
P2: When `TEST_REDIS_URL` is unset, this assignment turns `undefined` into the invalid URL string `"undefined"`, so environment validation fails before the Redis-gated suite can skip. Assign `REDIS_URL` only when `url` is present, as the existing desktop-executor integration suite does.</violation>
</file>
Reply with feedback, questions, or to request a fix.
Turn on auto-fix | Re-trigger cubic
…ands, decline takeovers on shutdown - The abandoned-run scan resumes from a durable cursor and examines a bounded window per round, so runs whose controller is alive cannot hide later runs. - A re-run's earlier attempts' workbench commands are handed to the workbench recovery to stop before the re-run may use the workbench; each recorded command now names the attempt that started it. - Shutdown aborts a takeover still in flight at its controller claim. - Only an authorization denial settles a run as revoked; other takeover failures leave it recoverable, as a failed reconnect does. - The suite sets REDIS_URL only when a test Redis is configured.
|
@greptileai review |
|
@cubic-dev-ai review |
@waleedlatif1 I have started the AI code review. It will take a few minutes to complete. |
There was a problem hiding this comment.
All reported issues were addressed across 15 files
Reply with feedback, questions, or to request a fix.
Turn on auto-fix | Re-trigger cubic
…imant never started
|
@greptileai review |
|
@cubic-dev-ai review |
@waleedlatif1 I have started the AI code review. It will take a few minutes to complete. |
- Add the `mothership-abandoned-run-takeover-disabled` AppConfig kill switch, checked once per scan; off by default, so takeovers run unless it is on. - Stop a controller whose chat lock lapsed while every renewal threw, so a controller partitioned from Redis cannot keep driving a run taken over. - Never revoke another call awaiting its re-run from a sibling's wait or workbench access; the sibling's workbench access still stops that call's dead attempt's commands. - Treat a workspace access loss found inside recovery like an authorization denial, by error type; other recovery failures stay recoverable. - Cover organization Assistant takeover for a member and a removed member.
|
@greptileai review |
|
@cubic-dev-ai review |
@waleedlatif1 I have started the AI code review. It will take a few minutes to complete. |
There was a problem hiding this comment.
All reported issues were addressed across 21 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
…e-run predicates as conditions, revoke access mid-recovery in the test
|
@greptileai review |
|
@cubic-dev-ai review |
@waleedlatif1 I have started the AI code review. It will take a few minutes to complete. |
|
@greptileai review |
|
@cubic-dev-ai review |
@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 22 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
Summary
The Sim process that admitted a Chat run is the run's controller. Sometimes that process stops mid-run: a blue/green deploy terminates the old task set, or the process crashes. If no browser is attached when that happens, the run is stranded:
This PR lets Sim take such runs over by itself:
recoverStreamRun, shared by the two use cases).mothership.runs.takeover. It goes through the same authorization funnel and capability (copilot.use) as a reconnect, so the user's current access is checked again.execution_attemptscolumn. After three starts the call fails with a clear message, so a tool that kills its executor cannot loop.No worker change is needed. The worker already re-hands every parked call, including one that was in flight, to a newly attached leg.
Type of Change
Testing
abandoned-runs.integration.tsruns against real Postgres and Redis. It goes through the production takeover, the reconnect route and the chat lifecycle, with a stub worker. It covers:Fails before the fix: with the reclaim and live-lease guards reverted, 4 of the 8 tests fail. With only the live-lease guard reverted, its test fails. The existing
recover-stream.test.tspasses. The migration is backward-compatible (check:migrations).Checklist