Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
d84cba6
chore(self-hosting): add health check endpoint (#3562)
PlaneInABottle Mar 13, 2026
9229002
fix(execution): queued execution finalization and async correlation (…
PlaneInABottle Mar 13, 2026
7e740e6
improvement(copilot): state persistence, subflow recreation, dynamic …
icecrasher321 Mar 14, 2026
5b9f0d7
feat(mothership): mothership (#3411)
Sg312 Mar 14, 2026
d06aa1d
fix(connectors): align connector scopes with oauth config and fix kb …
waleedlatif1 Mar 14, 2026
b2d146c
improvement(mothership): message queueing for home chat (#3576)
waleedlatif1 Mar 14, 2026
8f15be2
fix(ashby): add secretToken to webhook creation and fix trigger UX (#…
waleedlatif1 Mar 14, 2026
c738226
fix(file): bun issues with new file creation (#3582)
icecrasher321 Mar 14, 2026
9ae656c
fix(files): default file name (#3585)
icecrasher321 Mar 14, 2026
e6b2b73
fix(execution): report cancellation durability truthfully (#3550)
PlaneInABottle Mar 14, 2026
e13f52f
fix(tools): support stringified HTTP request tables (#3565)
PlaneInABottle Mar 14, 2026
f347e3f
fix(firecrawl) fix firecrawl scrape credit usage calculation (#3583)
TheodoreSpeaks Mar 14, 2026
a2f8ed0
fix lint
icecrasher321 Mar 14, 2026
00ff21a
fix(workflow) Fix embedded workflow logs (#3587)
TheodoreSpeaks Mar 14, 2026
5ba3118
feat(byok-migration) byok migration script (#3584)
TheodoreSpeaks Mar 14, 2026
cbc9f42
improvement(cleanup): remove unused old ui components (#3589)
waleedlatif1 Mar 14, 2026
952915a
fix(sidebar): collapsed sidebar shows single icons with hover dropdow…
waleedlatif1 Mar 14, 2026
75bdf46
improvement(promos): promo codes should be only stripe codes (#3591)
icecrasher321 Mar 14, 2026
f077751
fix(mothership): file materialization tools (#3586)
Sg312 Mar 14, 2026
8837f14
feat(home): expand template examples with 83 categorized templates (#…
waleedlatif1 Mar 15, 2026
f572949
fix(embedded): viewport options breaking autolayout (#3596)
icecrasher321 Mar 15, 2026
aad620c
fix(mothership): run workflow tools (run from block, run until block)…
Sg312 Mar 15, 2026
b7b575c
fix(ui) reduce redundant rerenders (#3593)
TheodoreSpeaks Mar 15, 2026
743742d
Show rendered md by default (#3594)
TheodoreSpeaks Mar 15, 2026
7ecd377
fix(tasks-ui): update in progress to be amber, added status to dropdo…
waleedlatif1 Mar 15, 2026
ad68dc1
improvement(grain): make trigger names in line with API since resourc…
icecrasher321 Mar 15, 2026
8906439
fix(notifications): credentials connection notifs showing up in right…
icecrasher321 Mar 15, 2026
aa1f605
fix(kb): auto-refresh documents after connector sync and remove redun…
waleedlatif1 Mar 15, 2026
38c8922
improvement: landing, sidebar, globals, buttons (#3590)
emir-karabeg Mar 15, 2026
6818c51
improvement(connectors): audit and harden all 30 knowledge base conne…
waleedlatif1 Mar 15, 2026
680c9cd
improvement(ui): align all public pages with dark landing theme and i…
waleedlatif1 Mar 16, 2026
395a61d
fix(deploy): consolidate deployment detection into single source of t…
waleedlatif1 Mar 16, 2026
b0870f4
fix(subagent, streaming) fix deploy subagent and task streamnig (#3610)
TheodoreSpeaks Mar 16, 2026
738d51a
fix(ui): render block handles underneath current block content (#3611)
waleedlatif1 Mar 16, 2026
6df6512
feat(tables): upload csvs (#3607)
icecrasher321 Mar 16, 2026
36e502a
fix(workflow) fix mothership double-running workflows (#3614)
TheodoreSpeaks Mar 17, 2026
c090c82
fix(mothership): add promptForToolApproval to prevent tool hang in mo…
TheodoreSpeaks Mar 17, 2026
c867801
fix(ui) Live update resources in resource main view (#3617)
TheodoreSpeaks Mar 17, 2026
974cc66
fix(ui) add embedded workflow notifications, switch tab on workflow r…
TheodoreSpeaks Mar 17, 2026
2a7b07e
Fix row_count context (#3622)
TheodoreSpeaks Mar 17, 2026
e804ea3
fix(embedded): block layout should not be dependent on viewport (#3621)
icecrasher321 Mar 17, 2026
b930ee3
improvement(tables): tables multi-select, keyboard shortcuts, and doc…
waleedlatif1 Mar 17, 2026
b3d9e54
fix(ui) fix task switch causing duplicate text renderings (#3624)
TheodoreSpeaks Mar 17, 2026
8fa4f3f
fix(mothership): thinking and subagent text (#3613)
Sg312 Mar 17, 2026
3e3c160
fix(embedded): autolayout viewport calculation for resource view (#3629)
waleedlatif1 Mar 17, 2026
1873f2d
improvement(mothership): tool display titles, html sanitization, and …
waleedlatif1 Mar 17, 2026
101fcec
fix(mothership): stream management (#3623)
Sg312 Mar 17, 2026
70d8df5
fix(ui): add back file split view (#3632)
TheodoreSpeaks Mar 17, 2026
3bd2750
fix(ui): ensure new resource tab button is always visible (#3633)
TheodoreSpeaks Mar 17, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
improvement(copilot): state persistence, subflow recreation, dynamic …
…handle topologies (#3569)

* improvement(copilot): state persistence, subflow recreation, dynamic handle topologies

* address comments
  • Loading branch information
icecrasher321 authored Mar 14, 2026
commit 7e740e617b9be635c7d0db8edbb8b9588cf16ee5
5 changes: 5 additions & 0 deletions apps/sim/app/api/workflows/[id]/execute/route.async.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ const {

vi.mock('@/lib/auth/hybrid', () => ({
checkHybridAuth: mockCheckHybridAuth,
AuthType: {
SESSION: 'session',
API_KEY: 'api_key',
INTERNAL_JWT: 'internal_jwt',
},
}))

vi.mock('@/lib/workflows/utils', () => ({
Expand Down
12 changes: 10 additions & 2 deletions apps/sim/app/api/workflows/[id]/state/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { extractAndPersistCustomTools } from '@/lib/workflows/persistence/custom
import { saveWorkflowToNormalizedTables } from '@/lib/workflows/persistence/utils'
import { sanitizeAgentToolsInBlocks } from '@/lib/workflows/sanitization/validation'
import { authorizeWorkflowByWorkspacePermission } from '@/lib/workflows/utils'
import { validateEdges } from '@/stores/workflows/workflow/edge-validation'
import type { BlockState, WorkflowState } from '@/stores/workflows/workflow/types'
import { generateLoopBlocks, generateParallelBlocks } from '@/stores/workflows/workflow/utils'

Expand Down Expand Up @@ -180,12 +181,16 @@ export async function PUT(request: NextRequest, { params }: { params: Promise<{
)

const typedBlocks = filteredBlocks as Record<string, BlockState>
const validatedEdges = validateEdges(state.edges as WorkflowState['edges'], typedBlocks)
const validationWarnings = validatedEdges.dropped.map(
({ edge, reason }) => `Dropped edge "${edge.id}": ${reason}`
)
const canonicalLoops = generateLoopBlocks(typedBlocks)
const canonicalParallels = generateParallelBlocks(typedBlocks)

const workflowState = {
blocks: filteredBlocks,
edges: state.edges,
edges: validatedEdges.valid,
loops: canonicalLoops,
parallels: canonicalParallels,
lastSaved: state.lastSaved || Date.now(),
Expand Down Expand Up @@ -276,7 +281,10 @@ export async function PUT(request: NextRequest, { params }: { params: Promise<{
)
}

return NextResponse.json({ success: true, warnings }, { status: 200 })
return NextResponse.json(
{ success: true, warnings: [...warnings, ...validationWarnings] },
{ status: 200 }
)
} catch (error: any) {
const elapsed = Date.now() - startTime
logger.error(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { createLogger } from '@sim/logger'
import { ChevronDown, ChevronsUpDown, ChevronUp, Plus } from 'lucide-react'
import { useParams } from 'next/navigation'
import Editor from 'react-simple-code-editor'
import { useUpdateNodeInternals } from 'reactflow'
import {
Button,
Code,
Expand Down Expand Up @@ -173,7 +172,6 @@ export function ConditionInput({
const [visualLineHeights, setVisualLineHeights] = useState<{
[key: string]: number[]
}>({})
const updateNodeInternals = useUpdateNodeInternals()
const batchRemoveEdges = useWorkflowStore((state) => state.batchRemoveEdges)
const edges = useWorkflowStore((state) => state.edges)

Expand Down Expand Up @@ -352,17 +350,8 @@ export function ConditionInput({
if (newValue !== prevStoreValueRef.current) {
prevStoreValueRef.current = newValue
setStoreValue(newValue)
updateNodeInternals(blockId)
}
}, [
conditionalBlocks,
blockId,
subBlockId,
setStoreValue,
updateNodeInternals,
isReady,
isPreview,
])
}, [conditionalBlocks, blockId, subBlockId, setStoreValue, isReady, isPreview])

// Cleanup when component unmounts
useEffect(() => {
Expand Down Expand Up @@ -708,8 +697,6 @@ export function ConditionInput({

shouldPersistRef.current = true
setConditionalBlocks((blocks) => updateBlockTitles(blocks.filter((block) => block.id !== id)))

setTimeout(() => updateNodeInternals(blockId), 0)
}

const moveBlock = (id: string, direction: 'up' | 'down') => {
Expand Down Expand Up @@ -737,8 +724,6 @@ export function ConditionInput({
]
shouldPersistRef.current = true
setConditionalBlocks(updateBlockTitles(newBlocks))

setTimeout(() => updateNodeInternals(blockId), 0)
}

// Add useEffect to handle keyboard events for both dropdowns
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,14 +198,14 @@ export const SubflowNodeComponent = memo(({ data, id, selected }: NodeProps<Subf
</div>

{/*
* Click-catching background — selects this subflow when the body area is clicked.
* No event bubbling concern: ReactFlow renders child nodes as viewport-level siblings,
* not as DOM children of this component, so child clicks never reach this div.
* Subflow body background. Uses pointer-events: none so that edges rendered
* inside the subflow remain clickable. The subflow node wrapper also has
* pointer-events: none (set in workflow.tsx), so body-area clicks pass
* through to the pane. Subflow selection is done via the header above.
*/}
<div
className='absolute inset-0 top-[44px] rounded-b-[8px]'
style={{ pointerEvents: isPreview ? 'none' : 'auto' }}
onClick={() => setCurrentBlockId(id)}
style={{ pointerEvents: 'none' }}
/>

{!isPreview && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { createMcpToolId } from '@/lib/mcp/shared'
import { getProviderIdFromServiceId } from '@/lib/oauth'
import type { FilterRule, SortRule } from '@/lib/table/types'
import { BLOCK_DIMENSIONS, HANDLE_POSITIONS } from '@/lib/workflows/blocks/block-dimensions'
import { getConditionRows, getRouterRows } from '@/lib/workflows/dynamic-handle-topology'
import {
buildCanonicalIndex,
evaluateSubBlockCondition,
Expand Down Expand Up @@ -1049,6 +1050,9 @@ export const WorkflowBlock = memo(function WorkflowBlock({

const subBlockRows = subBlockRowsData.rows
const subBlockState = subBlockRowsData.stateToUse
const topologySubBlocks = data.isPreview
? (data.blockState?.subBlocks ?? {})
: (currentStoreBlock?.subBlocks ?? {})
const effectiveAdvanced = useMemo(() => {
const rawValues = Object.entries(subBlockState).reduce<Record<string, unknown>>(
(acc, [key, entry]) => {
Expand Down Expand Up @@ -1108,34 +1112,8 @@ export const WorkflowBlock = memo(function WorkflowBlock({
*/
const conditionRows = useMemo(() => {
if (type !== 'condition') return [] as { id: string; title: string; value: string }[]

const conditionsValue = subBlockState.conditions?.value
const raw = typeof conditionsValue === 'string' ? conditionsValue : undefined

try {
if (raw) {
const parsed = JSON.parse(raw) as unknown
if (Array.isArray(parsed)) {
return parsed.map((item: unknown, index: number) => {
const conditionItem = item as { id?: string; value?: unknown }
const title = index === 0 ? 'if' : index === parsed.length - 1 ? 'else' : 'else if'
return {
id: conditionItem?.id ?? `${id}-cond-${index}`,
title,
value: typeof conditionItem?.value === 'string' ? conditionItem.value : '',
}
})
}
}
} catch (error) {
logger.warn('Failed to parse condition subblock value', { error, blockId: id })
}

return [
{ id: `${id}-if`, title: 'if', value: '' },
{ id: `${id}-else`, title: 'else', value: '' },
]
}, [type, subBlockState, id])
return getConditionRows(id, topologySubBlocks.conditions?.value)
}, [type, topologySubBlocks, id])

/**
* Compute per-route rows (id/value) for router_v2 blocks so we can render
Expand All @@ -1144,31 +1122,8 @@ export const WorkflowBlock = memo(function WorkflowBlock({
*/
const routerRows = useMemo(() => {
if (type !== 'router_v2') return [] as { id: string; value: string }[]

const routesValue = subBlockState.routes?.value
const raw = typeof routesValue === 'string' ? routesValue : undefined

try {
if (raw) {
const parsed = JSON.parse(raw) as unknown
if (Array.isArray(parsed)) {
return parsed.map((item: unknown, index: number) => {
const routeItem = item as { id?: string; value?: string }
return {
// Use stable ID format that matches ConditionInput's generateStableId
id: routeItem?.id ?? `${id}-route${index + 1}`,
value: routeItem?.value ?? '',
}
})
}
}
} catch (error) {
logger.warn('Failed to parse router routes value', { error, blockId: id })
}

// Fallback must match ConditionInput's default: generateStableId(blockId, 'route1') = `${blockId}-route1`
return [{ id: `${id}-route1`, value: '' }]
}, [type, subBlockState, id])
return getRouterRows(id, topologySubBlocks.routes?.value)
}, [type, topologySubBlocks, id])

/**
* Compute and publish deterministic layout metrics for workflow blocks.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export { useBlockOutputFields } from './use-block-output-fields'
export { useBlockVisual } from './use-block-visual'
export { useCanvasContextMenu } from './use-canvas-context-menu'
export { type CurrentWorkflow, useCurrentWorkflow } from './use-current-workflow'
export { useDynamicHandleRefresh } from './use-dynamic-handle-refresh'
export { useNodeUtilities } from './use-node-utilities'
export { usePreventZoom } from './use-prevent-zoom'
export { useScrollManagement } from './use-scroll-management'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { useEffect, useMemo, useRef } from 'react'
import { useUpdateNodeInternals } from 'reactflow'
import {
collectDynamicHandleTopologySignatures,
getChangedDynamicHandleBlockIds,
} from '@/lib/workflows/dynamic-handle-topology'
import { useWorkflowStore } from '@/stores/workflows/workflow/store'

export function useDynamicHandleRefresh() {
const updateNodeInternals = useUpdateNodeInternals()
const blocks = useWorkflowStore((state) => state.blocks)
const previousSignaturesRef = useRef<Map<string, string>>(new Map())

const signatures = useMemo(() => collectDynamicHandleTopologySignatures(blocks), [blocks])

useEffect(() => {
const changedBlockIds = getChangedDynamicHandleBlockIds(
previousSignaturesRef.current,
signatures
)
previousSignaturesRef.current = signatures

if (changedBlockIds.length === 0) {
return
}

const frameId = requestAnimationFrame(() => {
changedBlockIds.forEach((blockId) => updateNodeInternals(blockId))
})

return () => cancelAnimationFrame(frameId)
}, [signatures, updateNodeInternals])
}
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export async function applyAutoLayoutAndUpdateStore(
lastSaved: Date.now(),
}

useWorkflowStore.setState(newWorkflowState)
useWorkflowStore.getState().replaceWorkflowState(newWorkflowState)

logger.info('Successfully updated workflow store with auto layout', { workflowId })

Expand Down Expand Up @@ -168,9 +168,9 @@ export async function applyAutoLayoutAndUpdateStore(
})

// Revert the store changes since database save failed
useWorkflowStore.setState({
useWorkflowStore.getState().replaceWorkflowState({
...workflowStore.getWorkflowState(),
blocks: blocks,
blocks,
lastSaved: workflowStore.lastSaved,
})

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export * from './auto-layout-utils'
export * from './block-protection-utils'
export * from './block-ring-utils'
export * from './node-derivation'
export * from './node-position-utils'
export * from './workflow-canvas-helpers'
export * from './workflow-execution-utils'
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import type { BlockState } from '@/stores/workflows/workflow/types'

export const Z_INDEX = {
ROOT_BLOCK: 10,
CHILD_BLOCK: 1000,
} as const

export function computeContainerZIndex(
block: Pick<BlockState, 'data'>,
allBlocks: Record<string, Pick<BlockState, 'data'>>
): number {
let depth = 0
let parentId = block.data?.parentId

while (parentId && depth < 100) {
depth++
parentId = allBlocks[parentId]?.data?.parentId
}

return depth
}

export function computeBlockZIndex(
block: Pick<BlockState, 'type' | 'data'>,
allBlocks: Record<string, Pick<BlockState, 'type' | 'data'>>
): number {
if (block.type === 'loop' || block.type === 'parallel') {
return computeContainerZIndex(block, allBlocks)
}

return block.data?.parentId ? Z_INDEX.CHILD_BLOCK : Z_INDEX.ROOT_BLOCK
}
Loading
Loading