Skip to content

improvement(forking): unlink, settings page migration, deployed chats, public apis, external mcp servers/tools, special subblocks#5505

Merged
icecrasher321 merged 16 commits into
stagingfrom
improvement/fork-workspace
Jul 8, 2026
Merged

improvement(forking): unlink, settings page migration, deployed chats, public apis, external mcp servers/tools, special subblocks#5505
icecrasher321 merged 16 commits into
stagingfrom
improvement/fork-workspace

Conversation

@icecrasher321

@icecrasher321 icecrasher321 commented Jul 8, 2026

Copy link
Copy Markdown
Collaborator

Summary

Addresses UX issues by migrating to a settings page. Solves edge cases found during testing.

Type of Change

  • Bug fixes
  • Other: UX

Testing

Tested manually

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)

@vercel

vercel Bot commented Jul 8, 2026

Copy link
Copy Markdown

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

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

Request Review

@cursor

cursor Bot commented Jul 8, 2026

Copy link
Copy Markdown

PR Summary

Medium Risk
Touches fork sync, mapping, lineage authz, and bulk workflow promote/rollback paths, but changes are largely module relocation plus gated APIs and UI; server-side promote/unlink checks remain the enforcement boundary.

Overview
Moves workspace forking into @/ee/workspace-forking and replaces the sidebar Manage Forks / Sync modals with a dedicated Forks workspace settings section (nav + deep links via fork-id, fork-view, fork-direction).

API & behavior: Adds fork availability (member-readable gate) and unlink (audit on success). Lineage now returns child forks and a viewerAccessible flag per parent/child. Background-work and fork Activity use cursor pagination; activity copy includes otherWorkspaceId. Mapping PUT can persist dependentValues; diff pre-fills dependents for create (never-synced) workflows and loads stored values across all plan targets. Fork create can copy mcpServers; promote/rollback activity metadata gains actorName / otherWorkspaceId.

UI: Shared ActivityLog powers enterprise audit logs and fork activity (partner-aware titles, compact event badges). Settings sidebar shows Forks only when useForkingAvailable and workspace admin. Sync helpers add copy-vs-map parent resolution and effectiveCopyDependentValue; MCP cleared-ref blockers align with other copyables. RowActionsMenu supports disabled-item tooltips.

Reviewed by Cursor Bugbot for commit 1d0d647. Configure here.

@greptile-apps

greptile-apps Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR completes the workspace-forking EE module migration (from lib/workspaces/fork/ to ee/workspace-forking/), adds fork-edge unlinking, migrates the forking UI to the settings page, and closes several edge cases around deployed chats, public-API flags, and external MCP servers during fork/sync operations.

  • Unlink: new POST /fork/unlink route and unlinkForkEdge function that atomically nulls the child's forkedFromWorkspaceId and purges all four edge tables under the advisory lock; idempotent on a concurrent unlink.
  • Chat deployments & public-API propagation: copyForkChatDeployments carries source live chats to target workflows that have no chat row yet; isPublicApi is now propagated to both create and replace mode target workflows on sync.
  • External MCP servers now copyable at sync time: mcp-server added to forkCopyableKindSchema; copy resets connection state and never touches mcp_server_oauth tokens; previous TOCTOU issue in reconcileForkWorkflowMcpAttachments is fixed.
  • DB: workflow_mcp_server enum value added; two expression btree indexes on background_work_status.metadata JSONB extractions address the previously flagged sequential-scan issue.

Confidence Score: 5/5

Safe to merge; no correctness defects were found in the new paths.

The two previously flagged issues from earlier review rounds are both addressed: the TOCTOU window in reconcileForkWorkflowMcpAttachments is fixed (locks acquired before reads), and the JSONB full-scan is resolved by the two expression indexes added in the migration. The new unlink flow is transactionally correct and idempotent. The only observations are a minor N+1 in the lineage-children access check and a defensive-scope question in the chat identifier path — neither affects correctness.

No files require special attention. The migration file COMMIT-before-concurrent-index pattern is intentional and replay-safe.

Important Files Changed

Filename Overview
apps/sim/app/api/workspaces/[id]/fork/unlink/route.ts New unlink endpoint: validates session, parses contract, asserts admin access on the acting workspace only, calls unlinkForkEdge under an advisory lock, and records an audit event. Logic is clean and idempotent.
apps/sim/ee/workspace-forking/lib/lineage/unlink.ts New unlink implementation: runs in one transaction under the edge advisory lock, nulls forkedFromWorkspaceId, purges all four edge tables. Idempotent (returns unlinked: false if already dissolved). Well-tested.
apps/sim/ee/workspace-forking/lib/copy/copy-chats.ts New chat-deployment carry-over: copies source live chats to target workflows that have no chat row yet, with a fresh slug-based identifier. Collision-checked with 5 retries + long-random fallback. Auth config copied verbatim as intended. Minor: existingTargetRows check lacks workspace scope (workflow UUIDs are globally unique so not a correctness risk).
apps/sim/ee/workspace-forking/lib/copy/workflow-mcp-attachments.ts Previous TOCTOU issue is now fixed: server advisory locks are acquired BEFORE the source-attachment and existing-attachment reads, eliminating the window where a concurrent deploy-time sync could cause a unique-constraint abort.
apps/sim/ee/workspace-forking/lib/copy/deploy-bridge.ts New deploy bridge: lists deployed workflows (requires active deployment version), loads states pre-transaction to avoid pool deadlocks, adds isPublicApi to the summary shape so syncs can propagate the flag to target workflows.
packages/db/migrations/0257_majestic_chat.sql Adds workflow_mcp_server enum value and two expression btree indexes on background_work_status.metadata JSONB extractions. Correctly uses COMMIT before CREATE INDEX CONCURRENTLY and IF NOT EXISTS for replay safety.
apps/sim/app/api/workspaces/[id]/fork/lineage/route.ts Now returns children annotated with viewerAccessible. The withViewerAccess helper does one DB query per child — harmless for typical fork counts but could be batched for workspaces with many children.
apps/sim/app/api/workspaces/[id]/fork/diff/route.ts Loads stored dependent values for ALL plan targets so create-mode fields pre-fill. Calls collectForkDependentReconfigs twice with different modes — correctly producing a deduplicated union with mode-appropriate fallback logic.
apps/sim/lib/api/contracts/workspace-fork.ts Adds workflow_mcp_server resource type, promotes mcp-server to copyable kind, adds unlinkForkContract and getForkAvailabilityContract, adds forkLineageChildSchema with createdAt and viewerAccessible, adds pagination to background-work query.
apps/sim/ee/workspace-forking/lib/promote/promote.ts New promote implementation: reads source states pre-tx, acquires target then edge locks, propagates isPublicApi to synced targets, carries chat deployments for written non-skipped targets, reconciles MCP attachments, records background-work audit entry.

Reviews (3): Last reviewed commit: "move into ee folder + ui perm gates" | Re-trigger Greptile

Comment thread apps/sim/ee/workspace-forking/lib/background-work/store.ts
Comment thread apps/sim/ee/workspace-forking/lib/copy/workflow-mcp-attachments.ts
@icecrasher321

Copy link
Copy Markdown
Collaborator Author

@greptile

@icecrasher321

Copy link
Copy Markdown
Collaborator Author

bugbot run

Comment thread apps/sim/ee/workspace-forking/components/fork-sync/use-fork-sync.ts
@icecrasher321

Copy link
Copy Markdown
Collaborator Author

@greptile

@icecrasher321

Copy link
Copy Markdown
Collaborator Author

bugbot run

@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 1d0d647. Configure here.

@icecrasher321 icecrasher321 merged commit 4a80374 into staging Jul 8, 2026
16 checks passed
@waleedlatif1 waleedlatif1 deleted the improvement/fork-workspace branch July 9, 2026 01:10
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.

2 participants