Skip to content

fix(mothership): Stop only cancels detached runs still running, and a held workflow run never blocks the next turn's workbench - #9532

Merged
waleedlatif1 merged 3 commits into
stagingfrom
fix/mothership-detached-run-stop
Oct 31, 2026
Merged

waleedlatif1 merged 3 commits into
stagingfrom
fix/mothership-detached-run-stop

Conversation

@waleedlatif1

Copy link
Copy Markdown
Collaborator

Summary

Follow-ups to #9507 found in the release audit:

  • Stop cancelled settled and paused runs. getDetachedWorkflowExecutions returned every execution a call in the stream ever detached, and Stop wrote the durable 14-day cancel flag for each. A run paused at a human-in-the-loop block resumes under the same execution id, read the flag, and was cancelled. Stop now cancels only runs whose log reads running (or that have no log yet, i.e. still starting); paused runs are left alone, matching the pre-feat(mothership): answer a long workflow tool run still running, and stop detached runs on Stop #9507 behaviour where a paused browser run was already settled
  • A held workflow run blocked the next turn's workbench. answerWithinWait retains the run so the call's executionSettledAt stays null while it runs; prepareWorkbenchAccess counted that as handlersPending, so every run_code/sandbox call in the next turn failed for up to 95 minutes. Workflow-tool rows (which never touch the chat's workbench) no longer count; their unsettled sandbox processes still feed recovery
  • Stop read full JSONB payloads inside transactions. The status/exit-code filters now run in SQL and only the argv and status fields are selected, so member/workspace/chat/account deletion no longer materializes every sim_cli stdout of a stopped turn
  • Reuse WORKFLOW_TOOL_NAMES instead of a duplicate list; explicit settled-state tracking in answerWithinWait instead of a Promise.race ordering trick; the admission log poll is capped at 60 s past the wait

Type of Change

  • Bug fix

Testing

  • workflow-client-settlement.integration.ts (real Postgres + Redis): detached CLI and tool runs whose log is pending/completed/failed/cancelled are not cancelled; a run answered still running with no log yet still is; a later turn's workbench access isn't blocked by an earlier still-running run_workflow, while an earlier function_execute still blocks (control). Ran locally: 21/21; with the pre-fix repository 5 fail
  • Unit tests in tools/handlers/workflow, async-runs, request/application, request/handlers (209 pass); biome; full gate in CI

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing (new tests pass the test-audit authoring gate)
  • 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 31, 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 31, 2026 6:21pm UTC

Request Review

@greptile-apps

greptile-apps Bot commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no actionable new issues were found.

Summary

This PR narrows Stop to detached workflow runs that are still running and lets a later turn use the workbench while an earlier workflow run continues.

  • Stop cancels detached workflow runs only while they are running.
  • A running workflow tool no longer blocks the next turn’s workbench.
  • Workflow tools return settled results when runs finish near the wait limit.

No actionable new issues were found. Tests were inspected, not run.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Stop] --> B[Find runs started by this turn]
  B --> C{Current log status}
  C -->|Running or no log| D[Cancel execution]
  C -->|Paused or finished| E[Leave execution alone]
  F[Later turn requests workbench] --> G[Check earlier tools and sandbox processes]
  G --> H[Workflow handler alone does not block]
  G --> I[Unfinished sandbox processes still require recovery]
Loading

Reviews (2) · Last reviewed commit: "fix(mothership): answer a workflow tool ..." · Reviewed by Greptile

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

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

Turn on auto-fix | Re-trigger cubic

@waleedlatif1
waleedlatif1 force-pushed the fix/mothership-detached-run-stop branch from e4ec6c3 to 19c9072 Compare October 31, 2026 18:16
waleedlatif1 and others added 3 commits October 31, 2026 11:21
… held workflow run never blocks the next turn's workbench
…and name the paused case

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…s read with its result

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@waleedlatif1
waleedlatif1 force-pushed the fix/mothership-detached-run-stop branch from 19c9072 to 335ad5c Compare October 31, 2026 18:21
@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 31, 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 6 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 merged commit 8c7bd74 into staging Oct 31, 2026
69 checks passed
@waleedlatif1
waleedlatif1 deleted the fix/mothership-detached-run-stop branch October 31, 2026 21:38

This branch was previously deployed

1 inactive deployment
Preview — 335ad5c1 Deployed Oct 31, 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