Skip to content

fix(workflows): migrate Copilot application boundary - #6455

Open
TheodoreSpeaks wants to merge 5 commits into
improvement/v2-endpointsfrom
improvement/v2-copilot-workflow-boundary
Open

fix(workflows): migrate Copilot application boundary#6455
TheodoreSpeaks wants to merge 5 commits into
improvement/v2-endpointsfrom
improvement/v2-copilot-workflow-boundary

Conversation

@TheodoreSpeaks

Copy link
Copy Markdown
Collaborator

Summary

  • route protected Copilot workflow reads, mutations, and workflow VFS branches through scoped workflow application use cases with centralized audit and realtime effects
  • apply fail-closed pre-auth IP admission to anonymous v2 workflow execution before database lookup
  • emit human deployment analytics once, after durable activation, using outbox checkpoints

Testing

  • Focused Vitest: 12 suites, 124 tests passed
  • bun run --filter sim type-check
  • Biome on all touched files
  • bun run lint
  • bun run check:api-validation:strict
  • git diff --check

@vercel

vercel Bot commented Aug 8, 2026

Copy link
Copy Markdown

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

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped Aug 9, 2026 7:51am

Request Review

@cursor

cursor Bot commented Aug 8, 2026

Copy link
Copy Markdown

PR Summary

High Risk
Changes authentication/delegation for executor, Copilot, and public v2 execute paths plus deployment analytics timing; mistakes could leak reads, skip abuse limits, or mis-attribute analytics.

Overview
Moves workflow reads, deployments, and VFS mutations behind the workflow application layer instead of ad hoc route auth, orchestration helpers, and direct DB updates.

Copilot now enters operations via executeCopilotWorkflowUseCase, building a delegated principal only from trusted tool execution context (not forged userId in tool args). Deploy, promote, revert, status checks, diffs, and workflows/ VFS mv/cp/rm/mkdir call registered use cases; Copilot deploy/activate passes analytics: 'none'.

Human-facing deploy/activate passes analytics: 'human' into deploy/activate use cases and removes PostHog onSuccess hooks on v2 deploy/rollback and v1 deploy routes so product analytics run after durable activation, not at HTTP accept.

v1 workflows/[id] GET and /deployed become defineInternalJsonRoute handlers over readWorkflowDefinition (draft vs deployed), with session-or-executor auth and canonically bound executor delegation for Bearer calls.

v1 deploy route GET/POST/PATCH/DELETE lean on readWorkflowDeploymentStatus, deployWorkflow, undeployWorkflow, and updateWorkflowPublicApi with session principals and orchestration error mapping.

v2 public execute always runs admitOptionalV2Request: pre-auth IP rate limiting before workflow lookup, then optional API key auth; anonymous abuse can 429 without touching the database.

Workflow-in-workflow executor loads children with buildExecutorDelegationHeaders (subject user + parent workflow/execution) instead of generic internal JWT headers, and requires a human execution subject for reads.

Reviewed by Cursor Bugbot for commit b80a521. Bugbot is set up for automated code reviews on this repo. Configure here.

@greptile-apps

greptile-apps Bot commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR moves protected workflow operations behind scoped application use cases, adds fail-closed pre-auth admission for anonymous v2 execution, and defers deployment analytics until durable activation.

  • Routes Copilot workflow reads, mutations, and VFS operations through delegated workflow authorization.
  • Centralizes workflow audit and realtime effects in application use cases.
  • Adds durable, checkpointed deployment analytics to the outbox activation flow.
  • Applies IP admission before anonymous workflow lookup.

Confidence Score: 5/5

The PR appears safe to merge because no blocking failure remains.

No blocking failure remains.

Important Files Changed

Filename Overview
apps/sim/lib/copilot/application/execute-workflow-use-case.ts Establishes the delegated Copilot-to-workflow application boundary with scoped principal authorization.
apps/sim/lib/copilot/tools/handlers/vfs-mutate.ts Routes workflow VFS mutations through authorized workflow use cases while retaining direct checks for other VFS categories.
apps/sim/app/api/v2/workflows/[id]/execute/route.ts Applies optional API-key admission and fail-closed IP limiting before anonymous workflow lookup.
apps/sim/lib/workflows/deployment-outbox.ts Adds durable checkpoints for post-activation audit, realtime, and analytics effects.
apps/sim/lib/workflows/orchestration/deploy.ts Propagates actor and analytics intent into durable deployment preparation and activation.
apps/sim/lib/workflows/application/workflow-vfs.ts Implements authorized workflow VFS operations with workspace-scoped write requirements.
apps/sim/lib/workflows/application/authorization.ts Defines delegated workflow scope checks used by the migrated Copilot application boundary.
apps/sim/app/api/workflows/[id]/deploy/route.ts Replaces route-local workflow authorization and persistence with application use cases.

Sequence Diagram

sequenceDiagram
  participant Caller
  participant Route as Workflow API Route
  participant Admission as Auth / Admission
  participant UseCase as Workflow Application Use Case
  participant Authz as Workspace Authorization
  participant DB as Postgres
  participant Outbox as Deployment Outbox
  participant Effects as Audit / Realtime / Analytics

  Caller->>Route: Workflow request
  Route->>Admission: Authenticate or pre-auth admit
  Admission-->>Route: Scoped principal / anonymous admission
  Route->>UseCase: Execute operation
  UseCase->>Authz: Authorize principal and workspace
  Authz-->>UseCase: Allowed
  UseCase->>DB: Read or mutate workflow
  alt Deployment activation
    UseCase->>Outbox: Enqueue durable preparation
    Outbox->>DB: Activate deployment
    Outbox->>Effects: Emit checkpointed effects
  else Other workflow operation
    UseCase->>Effects: Emit centralized effects
  end
  UseCase-->>Route: Result
  Route-->>Caller: Response
Loading

Reviews (5): Last reviewed commit: "fix(workflows): preserve VFS validation ..." | Re-trigger Greptile

Comment thread apps/sim/lib/copilot/tools/handlers/vfs-mutate.ts Outdated
@TheodoreSpeaks
TheodoreSpeaks force-pushed the improvement/v2-copilot-workflow-boundary branch from 9fad504 to 448b493 Compare August 9, 2026 01:02
@TheodoreSpeaks

Copy link
Copy Markdown
Collaborator Author

@greptile

@TheodoreSpeaks

Copy link
Copy Markdown
Collaborator Author

@cursor review

@TheodoreSpeaks

Copy link
Copy Markdown
Collaborator Author

@greptile

@TheodoreSpeaks

Copy link
Copy Markdown
Collaborator Author

@cursor review

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 448b493. Configure here.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit d26ec3f. Configure here.

@TheodoreSpeaks

Copy link
Copy Markdown
Collaborator Author

@cursor review

@TheodoreSpeaks

Copy link
Copy Markdown
Collaborator Author

@greptile

Comment thread apps/sim/lib/workflows/application/workflow-vfs.ts
Comment thread apps/sim/lib/copilot/tools/handlers/vfs-mutate.ts Outdated
@TheodoreSpeaks
TheodoreSpeaks force-pushed the improvement/v2-copilot-workflow-boundary branch from 00d19ca to b80a521 Compare August 9, 2026 07:51
@TheodoreSpeaks

Copy link
Copy Markdown
Collaborator Author

@greptile

@TheodoreSpeaks

Copy link
Copy Markdown
Collaborator Author

@cursor review

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit b80a521. Configure here.

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