Skip to content

Commit 15360c3

Browse files
committed
fix(hitl): isolate cancelPausedExecution failure from successful cancellation
Wrap cancelPausedExecution in try/catch so a DB error does not mask a prior successful Redis or in-process cancellation. Also move the resource-collapse side effect in home.tsx to a useEffect to avoid the stale closure on the resources array.
1 parent 6780e00 commit 15360c3

2 files changed

Lines changed: 13 additions & 6 deletions

File tree

  • apps/sim/app
    • api/workflows/[id]/executions/[executionId]/cancel
    • workspace/[workspaceId]/home

apps/sim/app/api/workflows/[id]/executions/[executionId]/cancel/route.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,12 @@ export async function POST(
5151

5252
const cancellation = await markExecutionCancelled(executionId)
5353
const locallyAborted = abortManualExecution(executionId)
54-
const pausedCancelled = await PauseResumeManager.cancelPausedExecution(executionId)
54+
let pausedCancelled = false
55+
try {
56+
pausedCancelled = await PauseResumeManager.cancelPausedExecution(executionId)
57+
} catch (error) {
58+
logger.warn('Failed to cancel paused execution in database', { executionId, error })
59+
}
5560

5661
if (cancellation.durablyRecorded) {
5762
logger.info('Execution marked as cancelled in Redis', { executionId })

apps/sim/app/workspace/[workspaceId]/home/home.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,12 @@ export function Home({ chatId }: HomeProps = {}) {
215215
return () => cancelAnimationFrame(id)
216216
}, [resources])
217217

218+
useEffect(() => {
219+
if (resources.length === 0 && !isResourceCollapsedRef.current) {
220+
collapseResource()
221+
}
222+
}, [resources, collapseResource])
223+
218224
const handleStopGeneration = useCallback(() => {
219225
captureEvent(posthogRef.current, 'task_generation_aborted', {
220226
workspace_id: workspaceId,
@@ -288,12 +294,8 @@ export function Home({ chatId }: HomeProps = {}) {
288294
const resolved = resolveResourceFromContext(context)
289295
if (!resolved) return
290296
removeResource(resolved.type, resolved.id)
291-
const remaining = resources.filter((r) => !(r.type === resolved.type && r.id === resolved.id))
292-
if (remaining.length === 0) {
293-
collapseResource()
294-
}
295297
},
296-
[resolveResourceFromContext, removeResource, resources, collapseResource]
298+
[resolveResourceFromContext, removeResource]
297299
)
298300

299301
const handleWorkspaceResourceSelect = useCallback(

0 commit comments

Comments
 (0)