Skip to content

fix(workflow) fix mothership double-running workflows#3614

Merged
TheodoreSpeaks merged 2 commits intostagingfrom
fix/double-workflow
Mar 17, 2026
Merged

fix(workflow) fix mothership double-running workflows#3614
TheodoreSpeaks merged 2 commits intostagingfrom
fix/double-workflow

Conversation

@TheodoreSpeaks
Copy link
Collaborator

Summary

Previously mothership ran workflows ran twice - both client and server side. I switched the booleans to be client side so we don't run the same execution on the server.

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation
  • Other: ___________

Testing

Validated that executions only create a single run.

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)

Screenshots/Videos

@cursor
Copy link

cursor bot commented Mar 16, 2026

PR Summary

Medium Risk
Changes mothership chat orchestration to interactive mode, which can alter when/where tool/workflow executions run and could impact clients that don’t send tool decisions or completions.

Overview
Switches /api/mothership/chat orchestration from non-interactive to interactive execution (interactive: true). This moves tool/workflow execution handling into the interactive approval/completion flow (including client-executable tools), reducing the chance of server-side auto-execution that can lead to duplicate runs.

Written by Cursor Bugbot for commit a7a5443. This will update automatically on new commits. Configure here.

@vercel
Copy link

vercel bot commented Mar 16, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped Mar 16, 2026 11:54pm

Request Review

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Mar 16, 2026

Greptile Summary

This PR fixes a bug where workflows triggered through the Mothership chat were executed twice — once server-side (due to interactive: false + autoExecuteTools: true) and once client-side, resulting in duplicate runs. The fix changes the interactive flag to true so the orchestrator waits for client-side decisions rather than auto-executing tools on the server.

  • apps/sim/app/api/mothership/chat/route.ts: interactive: falseinteractive: true in the orchestrateOptions passed to createSSEStream. This is the root-cause fix.
  • apps/sim/lib/copilot/chat-streaming.ts: Adds a hardcoded interactive: true override inside createSSEStream's orchestrateCopilotStream call. This acts as a defensive layer, but silently overrides any interactive value a caller passes via orchestrateOptions, making it effectively dead configuration for future callers.

Confidence Score: 4/5

  • Safe to merge — the core fix is correct and well-targeted, with only a minor API design concern in the streaming helper.
  • The one-line change in route.ts correctly identifies and fixes the double-execution root cause. The additional change in chat-streaming.ts is safe for all existing callers but introduces a silent override that could confuse future contributors. No regressions expected.
  • apps/sim/lib/copilot/chat-streaming.ts — the hardcoded interactive: true override should be documented or the type updated to avoid misleading callers.

Important Files Changed

Filename Overview
apps/sim/app/api/mothership/chat/route.ts Single-line fix changing interactive: false to interactive: true in the orchestrator options — correctly prevents server-side auto-execution of tools that were also being handled client-side, fixing the double-run bug.
apps/sim/lib/copilot/chat-streaming.ts Adds a hardcoded interactive: true override inside orchestrateCopilotStream call, which is safe for all current callers but silently makes the interactive field in any caller-supplied orchestrateOptions dead code.

Sequence Diagram

sequenceDiagram
    participant Client
    participant MothershipRoute as /api/mothership/chat
    participant createSSEStream
    participant Orchestrator

    Client->>MothershipRoute: POST (message, workspaceId, ...)
    MothershipRoute->>createSSEStream: orchestrateOptions { interactive: true }
    createSSEStream->>Orchestrator: orchestrateCopilotStream(..., interactive: true [hardcoded])

    Note over Orchestrator: interactive=true → waits for client decisions
    Orchestrator-->>Client: SSE: tool_call event
    Client-->>Orchestrator: Tool decision / client-side execution result
    Orchestrator-->>Client: SSE: tool_result event
    Orchestrator-->>Client: SSE: done event

    Note over MothershipRoute: onComplete: persists assistant message to DB
    MothershipRoute-->>Client: Stream ends

    Note left of Orchestrator: Before fix (interactive=false):<br/>Server auto-executed tools AND<br/>client executed them too → double-run
Loading

Last reviewed commit: 5b586b0

@TheodoreSpeaks TheodoreSpeaks merged commit 36e502a into staging Mar 17, 2026
12 checks passed
@TheodoreSpeaks TheodoreSpeaks deleted the fix/double-workflow branch March 17, 2026 00:11
emir-karabeg pushed a commit that referenced this pull request Mar 17, 2026
* fix(workflow) fix mothership double-running workflows

* Remove interactive override

---------

Co-authored-by: Theodore Li <theo@sim.ai>
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