Skip to content

fix(mothership): fix workflow vfs reads#4156

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

fix(mothership): fix workflow vfs reads#4156
Sg312 merged 133 commits intostagingfrom
dev

Conversation

@Sg312
Copy link
Copy Markdown
Collaborator

@Sg312 Sg312 commented Apr 14, 2026

Summary

Fix nested workflow reads in vfs

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)

waleedlatif1 and others added 30 commits April 3, 2026 23:30
…ership workflow edits via sockets, ui improvements
…ration, signup method feature flags, SSO improvements
* feat(posthog): Add tracking on mothership abort (#4023)

Co-authored-by: Theodore Li <theo@sim.ai>

* fix(login): fix captcha headers for manual login  (#4025)

* fix(signup): fix turnstile key loading

* fix(login): fix captcha header passing

* Catch user already exists, remove login form captcha
…nts, secrets performance, polling refactors, drag resources in mothership
* 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
@vercel
Copy link
Copy Markdown

vercel bot commented Apr 14, 2026

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

Project Deployment Actions Updated (UTC)
docs Ready Ready Preview, Comment Apr 14, 2026 7:08pm

Request Review

@gitguardian
Copy link
Copy Markdown

gitguardian bot commented Apr 14, 2026

⚠️ GitGuardian has uncovered 1 secret following the scan of your pull request.

Please consider investigating the findings and remediating the incidents. Failure to do so may lead to compromising the associated services or software components.

🔎 Detected hardcoded secret in your pull request
GitGuardian id GitGuardian status Secret Commit Filename
29606901 Triggered Generic High Entropy Secret a54dcbe apps/sim/providers/utils.test.ts View secret
🛠 Guidelines to remediate hardcoded secrets
  1. Understand the implications of revoking this secret by investigating where it is used in your code.
  2. Replace and store your secret safely. Learn here the best practices.
  3. Revoke and rotate this secret.
  4. If possible, rewrite git history. Rewriting git history is not a trivial act. You might completely break other contributing developers' workflow and you risk accidentally deleting legitimate data.

To avoid such incidents in the future consider


🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Apr 14, 2026

Greptile Summary

This PR refactors the Mothership/copilot chat stack: it introduces a canonical message-persistence layer (persisted-message.ts, display-message.ts), extends the VFS serializer library with connectors, deployments, skills, jobs, and task-session entries, adds MCP server CRUD and deployment-version revert tools, and wires credential-aware env-var filtering into environment/utils.ts. All remaining findings are P2 style issues.

Confidence Score: 5/5

  • Safe to merge; all findings are P2 style/convention issues with no functional impact.
  • Auth flows, rate limiting, and data-access patterns are correct. The only issues found are crypto.randomUUID() used in place of the project-mandated generateId() (five occurrences across two files) and one any cast in a serializer — none of these affect runtime correctness.
  • apps/sim/lib/copilot/chat/post.ts and apps/sim/lib/copilot/chat/persisted-message.ts (crypto.randomUUID usages)

Important Files Changed

Filename Overview
apps/sim/lib/copilot/chat/post.ts Unified chat POST handler refactored to support both workflow and workspace branches; uses crypto.randomUUID() on lines 542, 695, 696 instead of the required generateId().
apps/sim/lib/copilot/chat/persisted-message.ts New message persistence layer with canonical/legacy block normalization; crypto.randomUUID() used on lines 174 and 460 instead of the project-mandated generateId().
apps/sim/lib/copilot/vfs/serializers.ts Extensive VFS serializer additions (connectors, deployments, skills, jobs, task sessions); serializeTaskChat uses (block as any) type casts where Record<string, unknown> would be correct.
apps/sim/lib/copilot/tools/handlers/deployment/manage.ts Adds MCP server CRUD operations and deployment version inspection/revert tools; correctly uses generateId() and has proper access-control guards on each operation.
apps/sim/lib/environment/utils.ts Adds credential-aware environment variable filtering and a short-lived in-process cache for decrypted env vars; implementation looks correct and follows project conventions.
apps/sim/app/api/mcp/copilot/route.ts MCP copilot server with OAuth and API-key auth, rate limiting, and subagent/direct-tool routing; auth flows, rate limiting, and error surfaces all look correct.

Sequence Diagram

sequenceDiagram
    participant Client
    participant PostHandler as lib/copilot/chat/post.ts
    participant PersistedMsg as persisted-message.ts
    participant DisplayMsg as display-message.ts
    participant DB as copilotChats (DB)
    participant Orchestrator as Copilot Orchestrator
    participant VFS as workspace-vfs.ts

    Client->>PostHandler: POST /api/copilot/chat
    PostHandler->>PostHandler: "resolveBranch (workflow | workspace)"
    PostHandler->>DB: persistUserMessage
    PostHandler->>Orchestrator: createSSEStream
    Orchestrator-->>PostHandler: OrchestratorResult (onComplete)
    PostHandler->>PersistedMsg: buildPersistedAssistantMessage(result)
    PostHandler->>DB: finalizeAssistantTurn (upsert messages)
    Client->>DisplayMsg: load chat history
    DisplayMsg->>PersistedMsg: normalizeMessage(rawRecord)
    DisplayMsg-->>Client: ChatMessage[]

    Client->>VFS: read("workflows/…/state.json")
    VFS->>DB: loadWorkflowFromNormalizedTables
    VFS-->>Client: serialized VFS content
Loading

Comments Outside Diff (3)

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

    P2 crypto.randomUUID() violates project ID generation rule

    The project requires using generateId() from @/lib/core/utils/uuid instead of crypto.randomUUID() directly. The same violation appears at line 460 of this file. generateId() already exists and works identically, including in non-secure (HTTP) browser contexts.

    Also fix line 460:

    id: (raw.id as string) ?? generateId(),

    Add the import at the top of the file:

    import { generateId } from '@/lib/core/utils/uuid'

    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!

  2. apps/sim/lib/copilot/chat/post.ts, line 542 (link)

    P2 crypto.randomUUID() violates project ID generation rule

    crypto.randomUUID() is used on this line, and again on lines 695–696. The project mandates generateId() from @/lib/core/utils/uuid for all ID generation. generateId is already imported at the top of this file and should be used consistently.

    Also update lines 695–696:

    const executionId = generateId()
    const runId = generateId()

    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!

  3. apps/sim/lib/copilot/vfs/serializers.ts, line 934-937 (link)

    P2 any cast violates TypeScript conventions

    block is already narrowed to object by the preceding guard, so it can be safely cast to Record<string, unknown> instead of using any.

    Context Used: TypeScript conventions and type safety (source)

Reviews (1): Last reviewed commit: "Merge branch 'staging', remote-tracking ..." | Re-trigger Greptile

@Sg312 Sg312 changed the title Dev fix(mothership): fix workflow vfs reads Apr 14, 2026
@Sg312 Sg312 merged commit ff2e369 into staging Apr 14, 2026
23 of 24 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