Skip to content

fix(mothership): revert to deployment and set env var tools#4141

Merged
Sg312 merged 112 commits intostagingfrom
dev
Apr 14, 2026
Merged

fix(mothership): revert to deployment and set env var tools#4141
Sg312 merged 112 commits intostagingfrom
dev

Conversation

@Sg312
Copy link
Copy Markdown
Collaborator

@Sg312 Sg312 commented Apr 14, 2026

Summary

Fix revert to deployment and set env var tools

Type of Change

  • Bug fix

Testing

Manual

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)

icecrasher321 and others added 30 commits April 8, 2026 12:16
* feat(transport): replace shared chat transport with mothership-stream module

* improvement(contracts): regenerate contracts from go

* feat(tools): add tool catalog codegen from go tool contracts

* feat(tools): add tool-executor dispatch framework for sim side tool routing

* feat(orchestrator): rewrite tool dispatch with catalog-driven executor and simplified resume loop

* feat(orchestrator): checkpoint resume flow

* refactor(copilot): consolidate orchestrator into request/ layer

* refactor(mothership): reorganize lib/copilot into structured subdirectories

* refactor(mothership): canonical transcript layer, dead code cleanup, type consolidation

* refactor(mothership): rebase onto latest staging

* refactor(mothership): rename request continue to lifecycle

* feat(trace): add initial version of request traces

* improvement(stream): batch stream from redis

* fix(resume): fix the resume checkpoint

* fix(resume): fix resume client tool

* fix(subagents): subagent resume should join on existing subagent text block

* improvement(reconnect): harden reconnect logic

* fix(superagent): fix superagent integration tools

* improvement(stream): improve stream perf

* Rebase with origin dev

* fix(tests): fix failing test

* fix(build): fix type errors

* fix(build): fix build errors

* fix(build): fix type errors

* feat(mothership): add cli execution

* fix(mothership): fix function execute tests
Sg312 and others added 23 commits April 10, 2026 18:29
Adds `log` as a first-class mothership resource type so copilot can open
and display workflow execution logs as tabs alongside workflows, tables,
files, and knowledge bases.

- Add `log` to MothershipResourceType, all Zod enums, and VALID_RESOURCE_TYPES
- Register log in RESOURCE_REGISTRY (Library icon) and RESOURCE_INVALIDATORS
- Add EmbeddedLog and EmbeddedLogActions components in resource-content
- Export WorkflowOutputSection from log-details for reuse in EmbeddedLog
- Add log resolution branch in open_resource handler via new getLogById service
- Include log id in get_workflow_logs response and extract resources from output
- Exclude log from manual add-resource dropdown (enters via copilot tools only)
- Regenerate copilot contracts after adding log to open_resource Go enum
…closed on new task (#4113)

Co-authored-by: Theodore Li <theo@sim.ai>
Co-authored-by: Theodore Li <theo@sim.ai>
@vercel
Copy link
Copy Markdown

vercel bot commented Apr 14, 2026

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

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped Apr 14, 2026 1:22am

Request Review

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Apr 14, 2026

Greptile Summary

This PR adds a copilot revert-to-deployment-version tool (executeRevertToVersion) that delegates to the new shared performRevertToVersion orchestration helper, alongside a new set_environment_variables server tool and a companion HTTP route at /api/workflows/[id]/deployments/[version]/revert. It also consolidates the old tool-display-registry.ts display logic into store-utils.ts and ships tests for both new tools.

Confidence Score: 5/5

Safe to merge; all findings are style/guideline violations with no runtime impact.

The core logic — shared performRevertToVersion helper, the new HTTP route, and the set_environment_variables tool — is functionally correct and well-tested. All remaining findings are P2: two crypto.randomUUID() calls that violate the ID utility rule, any types in the env-vars tool, and a vi.importActual() in a test. None of these affect production behavior.

apps/sim/lib/copilot/chat/persisted-message.ts (crypto.randomUUID), apps/sim/lib/copilot/tools/server/user/set-environment-variables.ts (any types)

Important Files Changed

Filename Overview
apps/sim/app/api/workflows/[id]/deployments/[version]/revert/route.ts New HTTP POST route for reverting a workflow to a deployment version; correctly handles 'active' and numeric version params and delegates to the shared orchestration helper.
apps/sim/lib/copilot/tools/handlers/deployment/manage.ts Adds executeRevertToVersion copilot tool handler that delegates to performRevertToVersion; clean implementation with proper access checks.
apps/sim/lib/copilot/tools/server/user/set-environment-variables.ts New server tool for setting env vars via Mothership; uses any in interface and return type, violating the no-any TypeScript rule.
apps/sim/lib/copilot/chat/persisted-message.ts Adds normalization and mapping helpers for chat messages; two usages of crypto.randomUUID() violate the project ID generation rule.
apps/sim/lib/copilot/tools/handlers/deployment/manage.test.ts Tests for executeRevertToVersion; uses vi.importActual() for drizzle-orm, which is forbidden by testing guidelines.
apps/sim/lib/copilot/tools/client/store-utils.ts Consolidates old tool-display-registry.ts display logic; clean rename with correct imports and tests.
apps/sim/lib/workflows/orchestration/deploy.ts Adds performRevertToVersion shared helper used by both the HTTP route and the copilot tool; logic is correct and includes audit logging.
apps/sim/lib/environment/utils.ts Adds upsertPersonalEnvVars and upsertWorkspaceEnvVars helpers with proper encryption, merging, and credential sync.

Sequence Diagram

sequenceDiagram
    participant Client as Browser / Copilot
    participant Route as POST /deployments/[version]/revert
    participant CopilotTool as executeRevertToVersion (manage.ts)
    participant Orchestration as performRevertToVersion (deploy.ts)
    participant DB as Database

    Client->>Route: POST with version param
    Route->>Route: validateWorkflowPermissions (admin)
    Route->>Orchestration: performRevertToVersion
    Orchestration->>DB: SELECT deployment version state
    DB-->>Orchestration: deployedState
    Orchestration->>DB: saveWorkflowToNormalizedTables
    Orchestration->>DB: UPDATE workflow lastSynced
    Orchestration-->>Route: { success, lastSaved }
    Route-->>Client: 200 { message, lastSaved }

    Client->>CopilotTool: executeRevertToVersion
    CopilotTool->>CopilotTool: ensureWorkflowAccess (admin)
    CopilotTool->>Orchestration: performRevertToVersion
    Orchestration->>DB: SELECT deployment version state
    DB-->>Orchestration: deployedState
    Orchestration->>DB: saveWorkflowToNormalizedTables
    Orchestration-->>CopilotTool: { success, lastSaved }
    CopilotTool-->>Client: { success, output: { message, lastSaved } }
Loading

Comments Outside Diff (2)

  1. apps/sim/lib/copilot/chat/persisted-message.ts, line 174 (link)

    P2 crypto.randomUUID() instead of generateId()

    The project rule (CLAUDE.md / global.md) prohibits direct use of crypto.randomUUID() and requires generateId() from @/lib/core/utils/uuid — which uses crypto.getRandomValues() and works in non-HTTPS contexts where crypto.randomUUID may be unavailable. The same pattern appears on line 460 as well.

    Add the import at the top of the file: import { generateId } from '@/lib/core/utils/uuid'

    Context Used: CLAUDE.md (source)

  2. apps/sim/lib/copilot/chat/persisted-message.ts, line 460 (link)

    P2 Second crypto.randomUUID() usage

    Same rule violation as line 174 — use generateId() instead.

    Context Used: CLAUDE.md (source)

    Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Reviews (1): Last reviewed commit: "Clean code, fix bugs" | Re-trigger Greptile

@Sg312 Sg312 merged commit bd9dcf1 into staging Apr 14, 2026
25 checks passed
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.

4 participants