Skip to content

Commit 2b231a5

Browse files
fix(copilot): don't strip placed custom blocks when the definition load fails (null vs empty set)
1 parent a8b7c24 commit 2b231a5

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

apps/sim/lib/copilot/vfs/workspace-vfs.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -415,8 +415,13 @@ export class WorkspaceVFS {
415415
* still resolves/renders). Populated by {@link materializeCustomBlocks}; used to
416416
* drop a placed custom block from a workflow's state when its definition has been
417417
* deleted, so the copilot never sees a block it can't render.
418+
*
419+
* `null` means "not loaded" — either not materialized yet or the load FAILED. In
420+
* that case {@link dropDeletedCustomBlocks} strips nothing, so a transient failure
421+
* can't wrongly nuke every placed custom block. An empty `Set` is distinct: it
422+
* means the org genuinely has no custom blocks, so any placed one IS deleted.
418423
*/
419-
private _customBlockTypes = new Set<string>()
424+
private _customBlockTypes: Set<string> | null = null
420425

421426
get workspaceId(): string {
422427
return this._workspaceId
@@ -455,12 +460,15 @@ export class WorkspaceVFS {
455460
private dropDeletedCustomBlocks(
456461
normalized: Awaited<ReturnType<typeof loadWorkflowFromNormalizedTables>>
457462
): Awaited<ReturnType<typeof loadWorkflowFromNormalizedTables>> {
458-
if (!normalized) return normalized
463+
// `null` = definitions never loaded (or the load failed) — strip nothing rather
464+
// than treat every placed custom block as deleted.
465+
if (!normalized || this._customBlockTypes === null) return normalized
466+
const validTypes = this._customBlockTypes
459467
const dropped = new Set<string>()
460468
const blocks: Record<string, unknown> = {}
461469
for (const [id, block] of Object.entries(normalized.blocks)) {
462470
const type = (block as { type?: string }).type
463-
if (isCustomBlockType(type) && !this._customBlockTypes.has(type)) {
471+
if (isCustomBlockType(type) && !validTypes.has(type)) {
464472
dropped.add(id)
465473
continue
466474
}
@@ -565,7 +573,7 @@ export class WorkspaceVFS {
565573
this.lazy = new Map()
566574
this.normalizedCache = new Map()
567575
this.deploymentCache = new Map()
568-
this._customBlockTypes = new Set()
576+
this._customBlockTypes = null
569577
this._workspaceId = workspaceId
570578
this._betaEnabled = await isFeatureEnabled('mothership-beta', { userId })
571579

0 commit comments

Comments
 (0)