Waleed 76318e42df fix(fork): preserve folder structure across a fork edge for files, tables, and knowledge bases (#6752)
* fix(fork): carry folder structure across a fork edge for files, tables, and KBs

Only workflow folders were mirrored into the target workspace on fork
create and on sync. Copied files, tables, and knowledge bases were written
with a hardcoded `folderId: null`, so a push or pull flattened them all
into the target root and lost the source's grouping — visible as a fork
sync that drops folder structure when copying files to the parent.

`resolveForkFolderMapping` already did the real work (prune to folders
holding copied content plus ancestors, reuse same-named target folders,
remap parentId), but was pinned to `resourceType: 'workflow'` on both
reads and on the folder-ceiling check. Parameterize it by resource type
and run it per family, threading the resulting map into each copy instead
of nulling. The four folder-bearing families own disjoint trees and folder
ids are globally unique, so the per-family maps merge cleanly for the
`sim:folder/<id>` content rewrite, which previously resolved only for
workflow folders.

Existing forks are healed on their next sync rather than by a migration:
`rehomeFlattenedForkResources` re-homes mapped files/tables/KBs whose
target `folder_id` is still NULL — the exact signature of the old
flattening — so a placement chosen in the target is never overwritten and
the pass converges to a no-op.

`BlobCopyTask.targetFolderId` is optional so tasks queued by an earlier
deploy replay at the root exactly as before.

* refactor(fork): page the re-home lookups and reuse the plan's identity rows

Self-review of the folder-transit change surfaced two scaling problems in
the re-home pass, both of which grow with the size of the fork edge rather
than the size of the sync:

- The resource lookups built `IN (...)` lists straight from the edge's
  mapping rows, so a large fork could hand Postgres a list approaching the
  bind-parameter ceiling and a pathological query plan. Page them at 500,
  matching the paging the rest of the fork copy already uses.
- The pass re-read the whole edge mapping via `getEdgeMappingRows`, which
  the promote plan had already loaded in the same transaction — a second
  full load of identical rows. Expose them on `ForkPromotePlan` and pass
  them in, which also drops a mock from the re-home tests.

Also tally moved rows from `returning()` rather than the planned batch
size, so the log line reports what the `folder_id IS NULL` guard actually
wrote instead of what was attempted.

* fix(fork): drop the sync-time re-home pass, keep folder transit forward-only

Review surfaced three findings and every one of them was in the re-home
pass, none in the forward-looking fix:

- It keyed mapping orientation off `direction`, but the promote route
  resolves the edge from whichever workspace the caller is acting in, so a
  caller in the PARENT pushing to its child is `direction: 'push'` with the
  parent as source. The plan derives this as
  `sourceWorkspaceId === edge.parentWorkspaceId` for exactly that reason.
- Moving a file into a mirrored folder can violate
  `workspace_files_workspace_folder_name_active_unique`, which would abort
  the whole promote transaction and take the workflow sync down with it.
- `folder_id IS NULL` cannot distinguish "flattened by the old copy" from
  "the user moved this to the root", so the pass re-applied on every sync
  and would fight a deliberate placement indefinitely.

The first two are fixable; the third is not without a one-time marker per
edge, which means a migration. A heal that re-applies forever is worse
than no heal, so remove the pass entirely rather than ship it half-right.
Folder structure now transits correctly from this point forward, which is
the actual reported bug; healing already-flattened resources can be a
separate change with a marker to make it run exactly once.

Reverts the `ForkPromotePlan.mappingRows` field with it — it existed only
to feed this pass.
2026-08-15 17:50:57 -07:00

Sim.ai Documentation Slack X

Ask DeepWiki Set Up with Cursor

Sim — Integrate, Context, Build, and Monitor AI agents

A workspace to build, deploy and manage AI agents and workflows.

Quickstart

Cloud-hosted: sim.ai

Open sim.ai

Self-hosted

git clone https://github.com/simstudioai/sim.git && cd sim
bun install
bun run setup

Open http://localhost:3000

The Sim platform — chat on the left, the visual workflow builder on the right

Capabilities

  • Connect 1,000+ integrations and every major LLM
  • Add Slack, Notion, HubSpot, Salesforce, databases, and more
  • Build agents visually, conversationally, or with code
  • Ingest files, knowledge bases, and structured table data
  • Monitor runs, logs, schedules, and workflow activity

One workspace, every surface

Chat and workflows are just the start — tables, files, and knowledge all live in the same workspace.

Tables in Sim — structured data your agents can query

Tables — a database, built in

Files in Sim — documents for your team and every agent

Files — one store for your team and every agent

Knowledge bases in Sim — synced docs your agents can search

Knowledge — your agents' memory

Self-hosting

Requirements: Bun and Docker.

bun run setup is an interactive wizard: it provisions the database, generates secrets, writes your .env files, connects a Chat API key, and starts Sim the way you choose:

  • Local dev — run from source to contribute or hack on Sim
  • Docker Compose — a self-contained instance for testing self-hosting
  • Kubernetes (Helm) — deploy to a local cluster

When it finishes, open http://localhost:3000.

Reconfigure an optional capability without rerunning the full wizard:

bun run setup status
bun run setup email
bun run setup storage
bun run setup sandbox
bun run setup jobs
bun run setup cache
bun run setup knowledge
bun run setup llm
bun run setup integration slack

bun run setup status detects the effective local-dev, Docker Compose, or current-context Helm configuration and reports configured, missing, or invalid capabilities and OAuth integrations without printing credential values. This is separate from bun run sim status, which reports whether installed services are running and healthy.

Manage your install with bun run sim:

bun run sim start | stop | restart   # bring your install up / down / cycle
bun run sim update                   # pull/rebuild and apply Compose images
bun run sim status                    # what's installed and healthy
bun run sim logs                      # follow logs
bun run sim doctor                    # diagnose configuration problems
bun run sim down                      # remove containers (data kept)
bun run sim reset                     # archive .env and wipe managed data

sim detects how you're running (Docker Compose, local dev, or Kubernetes) and acts accordingly.

Prefer a bare sim? Run bun link once — but note sim lands in ~/.bun/bin, which Homebrew's bun doesn't add to your PATH, so you may need export PATH="$HOME/.bun/bin:$PATH" in your shell profile.

Sim also supports local models via Ollama and vLLM. See the self-hosting docs for details.

Chat API Keys

Chat is a Sim-managed service. bun run setup connects a Chat API key for you — sign in when it opens your browser and the key is stored automatically. To view, create, or revoke keys later, go to sim.ai/selfhost/settings/chat-keys.

Environment Variables

See the environment variables reference for the full list, or apps/sim/.env.example for defaults.

Tech Stack

Next.js · Bun · PostgreSQL · Drizzle · Better Auth · Tailwind — and the rest of the stack

Contributing

We welcome contributions! Please see our Contributing Guide for details.

License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details.

Built by the Sim team in San Francisco

Languages
TypeScript 77%
MDX 20.8%
JavaScript 1.9%
CSS 0.1%