Skip to content

Commit 6328abd

Browse files
committed
fix copilot run workflow
1 parent de6bfe5 commit 6328abd

File tree

13 files changed

+333
-180
lines changed

13 files changed

+333
-180
lines changed

apps/sim/app/api/workflows/[id]/execute/route.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -865,15 +865,21 @@ export async function POST(req: NextRequest, { params }: { params: Promise<{ id:
865865
registerManualExecutionAborter(executionId, timeoutController.abort)
866866
isManualAbortRegistered = true
867867

868+
let localEventSeq = 0
868869
const sendEvent = (event: ExecutionEvent) => {
870+
const isBuffered = event.type !== 'stream:chunk' && event.type !== 'stream:done'
871+
if (isBuffered) {
872+
localEventSeq++
873+
event.eventId = localEventSeq
874+
}
869875
if (!isStreamClosed) {
870876
try {
871877
controller.enqueue(encodeSSEEvent(event))
872878
} catch {
873879
isStreamClosed = true
874880
}
875881
}
876-
if (event.type !== 'stream:chunk' && event.type !== 'stream:done') {
882+
if (isBuffered) {
877883
eventWriter.write(event).catch(() => {})
878884
}
879885
}

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { authorizeWorkflowByWorkspacePermission } from '@/lib/workflows/utils'
1313
const logger = createLogger('ExecutionStreamReconnectAPI')
1414

1515
const POLL_INTERVAL_MS = 500
16-
const MAX_POLL_DURATION_MS = 10 * 60 * 1000 // 10 minutes
16+
const MAX_POLL_DURATION_MS = 55 * 60 * 1000 // 55 minutes (just under Redis 1hr TTL)
1717

1818
function isTerminalStatus(status: ExecutionStreamStatus): boolean {
1919
return status === 'complete' || status === 'error' || status === 'cancelled'
@@ -101,6 +101,7 @@ export async function GET(
101101
const events = await readExecutionEvents(executionId, lastEventId)
102102
for (const entry of events) {
103103
if (closed) return
104+
entry.event.eventId = entry.eventId
104105
enqueue(formatSSEEvent(entry.event))
105106
lastEventId = entry.eventId
106107
}
@@ -119,6 +120,7 @@ export async function GET(
119120
const newEvents = await readExecutionEvents(executionId, lastEventId)
120121
for (const entry of newEvents) {
121122
if (closed) return
123+
entry.event.eventId = entry.eventId
122124
enqueue(formatSSEEvent(entry.event))
123125
lastEventId = entry.eventId
124126
}
@@ -128,6 +130,7 @@ export async function GET(
128130
const finalEvents = await readExecutionEvents(executionId, lastEventId)
129131
for (const entry of finalEvents) {
130132
if (closed) return
133+
entry.event.eventId = entry.eventId
131134
enqueue(formatSSEEvent(entry.event))
132135
lastEventId = entry.eventId
133136
}

0 commit comments

Comments
 (0)