-
Notifications
You must be signed in to change notification settings - Fork 3.6k
feat(block): Allow wait block to wait up to 30 days #4331
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
53 commits
Select commit
Hold shift + click to select a range
0b9019d
v0.6.23: MCP fixes, remove local state in favor of server state, moth…
waleedlatif1 a54dcbe
v0.6.24: copilot feedback wiring, captcha fixes
waleedlatif1 28af223
v0.6.25: cloudwatch, cloudformation, live kb sync, linear fixes, post…
waleedlatif1 d889f32
v0.6.26: ui improvements, multiple response blocks, docx previews, ol…
waleedlatif1 316bc8c
v0.6.27: new triggers, mothership improvements, files archive, queuei…
waleedlatif1 3f508e4
v0.6.28: new docs, delete confirmation standardization, dagster integ…
waleedlatif1 d6ec115
v0.6.29: login improvements, posthog telemetry (#4026)
TheodoreSpeaks d7da35b
v0.6.30: slack trigger enhancements, connectors performance improveme…
waleedlatif1 cf233bb
v0.6.31: elevenlabs voice, trigger.dev fixes, cloud whitelabeling for…
waleedlatif1 f8f3758
v0.6.32: BYOK fixes, ui improvements, cloudwatch tools, jsm tools ext…
waleedlatif1 3c8bb40
v0.6.33: polling improvements, jsm forms tools, credentials reactquer…
waleedlatif1 d33acf4
v0.6.34: trigger.dev fixes, CI speedup, atlassian error extractor
waleedlatif1 4f40c4c
v0.6.35: additional jira fields, HITL docs, logs cleanup efficiency
waleedlatif1 cbfab1c
v0.6.36: new chunkers, sockets state machine, google sheets/drive/cal…
waleedlatif1 4309d06
v0.6.37: audit logs page, isolated-vm worker rotation, permission gro…
waleedlatif1 8b57476
v0.6.38: models page
waleedlatif1 e3d0e74
v0.6.39: billing fixes, tools audit, landing fix
waleedlatif1 0ac0539
v0.6.40: mothership tool loop, new skills, agiloft, STS, IAM integrat…
waleedlatif1 3838b6e
v0.6.41: webhooks fix, workers removal
waleedlatif1 fc07922
v0.6.42: mothership nested file reads, search modal improvements
waleedlatif1 3a1b1a8
v0.6.43: mothership billing idempotency, env var resolution fixes
waleedlatif1 46ffc49
v0.6.44: streamdown, mothership intelligence, excel extension
waleedlatif1 010435c
v0.6.45: superagent, csp, brightdata integration, gemini response for…
Sg312 c0bc62c
Merge pull request #4190 from simstudioai/staging
icecrasher321 387cc97
v0.6.46: mothership queueing, web vitals
waleedlatif1 2dbc7fd
v0.6.47: files focusing, documentation, opus 4.7
waleedlatif1 8a50f18
v0.6.48: import csv into tables, subflow fixes, CSP updates
waleedlatif1 dcf3302
v0.6.49: deploy sockets event, resolver, logs improvements, monday.co…
waleedlatif1 bc09865
v0.6.50: ppt/doc/pdf worker isolation, docs, chat, sidebar improvements
icecrasher321 5f56e46
v0.6.51: tables improvements, billing fixes, 404 pages, code hygiene
waleedlatif1 ca3bbf1
v0.6.52: data retention, docs updates, slack manifest generator, secu…
waleedlatif1 bbf400f
v0.6.53: permissions groups migration, docs updates
waleedlatif1 7c619e7
Merge pull request #4261 from simstudioai/staging
icecrasher321 64cfda5
v0.6.54: mothership tracing, db pool size increase
icecrasher321 7ca736a
v0.6.55: standardize monorepo conventions, api key hash, thinking tex…
waleedlatif1 6066fc1
v0.6.56: data retention improvements, tables column double click resi…
waleedlatif1 3422f64
Merge pull request #4285 from simstudioai/staging
waleedlatif1 595c4c3
Merge pull request #4293 from simstudioai/staging
TheodoreSpeaks d6c1bc2
v0.6.58: queue abort state machine improvement, contributing guide
icecrasher321 58a3ae2
v0.6.59: gpt 5.5, security hardening, parallel subagents rendering
icecrasher321 489f2d3
v0.6.60: copilot security improvements, slack canvas ops, retention j…
icecrasher321 22ccaf1
feat(block): Allow wait block to wait up to 30 days
TheodoreSpeaks a4b5df1
restore ff
TheodoreSpeaks 6aa3fe3
v0.6.61: SAP integration, live URLs for browser use, 5xx error catego…
icecrasher321 ecbf5e5
Merge pull request #4342 from simstudioai/staging
TheodoreSpeaks 0c32dd4
Filter out waits from hitl endpoints
TheodoreSpeaks 7678245
Use correct count, filtering out wait blocks
TheodoreSpeaks 2aaf2b7
v0.6.62: firecrawl parse, new gmail tools, trace improvements, tool f…
waleedlatif1 d445b9c
v0.6.63: knowledgebase UI, folder search in mothership
waleedlatif1 c234b01
Merge remote-tracking branch 'origin/main' into feat/long-waits
TheodoreSpeaks 80202dd
improvement(wait): tighten poll route and pause-manager helpers
TheodoreSpeaks 491af0e
Merge branch 'staging' into feat/long-waits
TheodoreSpeaks 4d44471
Merge branch 'staging' into feat/long-waits
TheodoreSpeaks File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,175 @@ | ||
| import { db } from '@sim/db' | ||
| import { pausedExecutions } from '@sim/db/schema' | ||
| import { createLogger } from '@sim/logger' | ||
| import { toError } from '@sim/utils/errors' | ||
| import { generateShortId } from '@sim/utils/id' | ||
| import { and, asc, eq, isNotNull, lte } from 'drizzle-orm' | ||
| import { type NextRequest, NextResponse } from 'next/server' | ||
| import { verifyCronAuth } from '@/lib/auth/internal' | ||
| import { acquireLock, releaseLock } from '@/lib/core/config/redis' | ||
| import { withRouteHandler } from '@/lib/core/utils/with-route-handler' | ||
| import { | ||
| computeEarliestResumeAt, | ||
| PauseResumeManager, | ||
| } from '@/lib/workflows/executor/human-in-the-loop-manager' | ||
| import type { PausePoint } from '@/executor/types' | ||
|
|
||
| const logger = createLogger('TimePauseResumePoll') | ||
|
|
||
| export const dynamic = 'force-dynamic' | ||
| export const maxDuration = 120 | ||
|
|
||
| const LOCK_KEY = 'time-pause-resume-poll-lock' | ||
| const LOCK_TTL_SECONDS = 180 | ||
| const POLL_BATCH_LIMIT = 200 | ||
|
|
||
| interface DispatchFailure { | ||
| executionId: string | ||
| contextId: string | ||
| error: string | ||
| } | ||
|
|
||
| interface RowResult { | ||
| dispatched: number | ||
| failures: DispatchFailure[] | ||
| } | ||
|
|
||
| export const GET = withRouteHandler(async (request: NextRequest) => { | ||
| const requestId = generateShortId() | ||
|
|
||
| const authError = verifyCronAuth(request, 'Time-pause resume poll') | ||
| if (authError) return authError | ||
|
|
||
| const lockAcquired = await acquireLock(LOCK_KEY, requestId, LOCK_TTL_SECONDS) | ||
| if (!lockAcquired) { | ||
| return NextResponse.json( | ||
| { success: true, message: 'Polling already in progress – skipped', requestId }, | ||
| { status: 202 } | ||
| ) | ||
| } | ||
|
|
||
| try { | ||
| const now = new Date() | ||
|
|
||
| const dueRows = await db | ||
| .select({ | ||
| id: pausedExecutions.id, | ||
| executionId: pausedExecutions.executionId, | ||
| workflowId: pausedExecutions.workflowId, | ||
| pausePoints: pausedExecutions.pausePoints, | ||
| metadata: pausedExecutions.metadata, | ||
| }) | ||
| .from(pausedExecutions) | ||
| .where( | ||
| and( | ||
| eq(pausedExecutions.status, 'paused'), | ||
| isNotNull(pausedExecutions.nextResumeAt), | ||
| lte(pausedExecutions.nextResumeAt, now) | ||
| ) | ||
| ) | ||
| .orderBy(asc(pausedExecutions.nextResumeAt)) | ||
| .limit(POLL_BATCH_LIMIT) | ||
|
|
||
| const results = await Promise.all(dueRows.map((row) => dispatchRow(row, now))) | ||
| const dispatched = results.reduce((sum, r) => sum + r.dispatched, 0) | ||
| const failures = results.flatMap((r) => r.failures) | ||
|
|
||
| logger.info('Time-pause resume poll completed', { | ||
| requestId, | ||
| claimedRows: dueRows.length, | ||
| dispatched, | ||
| failureCount: failures.length, | ||
| }) | ||
|
|
||
| return NextResponse.json({ | ||
| success: true, | ||
| requestId, | ||
| claimedRows: dueRows.length, | ||
| dispatched, | ||
| failures, | ||
| }) | ||
| } catch (error) { | ||
| const message = toError(error).message | ||
| logger.error('Time-pause resume poll failed', { requestId, error: message }) | ||
| return NextResponse.json({ success: false, requestId, error: message }, { status: 500 }) | ||
| } finally { | ||
| await releaseLock(LOCK_KEY, requestId).catch(() => {}) | ||
| } | ||
| }) | ||
|
|
||
| interface DueRow { | ||
| id: string | ||
| executionId: string | ||
| workflowId: string | ||
| pausePoints: unknown | ||
| metadata: unknown | ||
| } | ||
|
|
||
| async function dispatchRow(row: DueRow, now: Date): Promise<RowResult> { | ||
| const points = (row.pausePoints ?? {}) as Record<string, PausePoint> | ||
| const metadata = (row.metadata ?? {}) as Record<string, unknown> | ||
| const userId = typeof metadata.executorUserId === 'string' ? metadata.executorUserId : '' | ||
|
|
||
| const eligiblePoints = Object.values(points).filter( | ||
| (point) => | ||
| point.pauseKind === 'time' && (!point.resumeStatus || point.resumeStatus === 'paused') | ||
| ) | ||
| const duePoints = eligiblePoints.filter((point) => { | ||
| if (!point.resumeAt) return false | ||
| const at = new Date(point.resumeAt) | ||
| return !Number.isNaN(at.getTime()) && at <= now | ||
| }) | ||
|
|
||
| const failures: DispatchFailure[] = [] | ||
| let dispatched = 0 | ||
|
|
||
| for (const point of duePoints) { | ||
| if (!point.contextId) continue | ||
| try { | ||
| const enqueueResult = await PauseResumeManager.enqueueOrStartResume({ | ||
| executionId: row.executionId, | ||
| contextId: point.contextId, | ||
| resumeInput: {}, | ||
| userId, | ||
| allowedPauseKinds: ['time'], | ||
| }) | ||
|
TheodoreSpeaks marked this conversation as resolved.
|
||
|
|
||
| if (enqueueResult.status === 'starting') { | ||
| PauseResumeManager.startResumeExecution({ | ||
| resumeEntryId: enqueueResult.resumeEntryId, | ||
| resumeExecutionId: enqueueResult.resumeExecutionId, | ||
| pausedExecution: enqueueResult.pausedExecution, | ||
| contextId: enqueueResult.contextId, | ||
| resumeInput: enqueueResult.resumeInput, | ||
| userId: enqueueResult.userId, | ||
| }).catch((error) => { | ||
| logger.error('Background time-pause resume failed', { | ||
| executionId: row.executionId, | ||
| contextId: point.contextId, | ||
| error: toError(error).message, | ||
| }) | ||
| }) | ||
| } | ||
| dispatched++ | ||
| } catch (error) { | ||
| const message = toError(error).message | ||
| logger.warn('Failed to dispatch time-pause resume', { | ||
| executionId: row.executionId, | ||
| contextId: point.contextId, | ||
| error: message, | ||
| }) | ||
| failures.push({ executionId: row.executionId, contextId: point.contextId, error: message }) | ||
| } | ||
| } | ||
|
|
||
| // We never auto-retry a failed dispatch: workflow blocks aren't idempotent, and | ||
| // an operator must investigate stranded rows by hand. The status='paused' guard | ||
| // also prevents clobbering when a concurrent manual resume has already advanced | ||
| // the row's state since we read it. | ||
| await PauseResumeManager.setNextResumeAt({ | ||
| pausedExecutionId: row.id, | ||
| nextResumeAt: computeEarliestResumeAt(eligiblePoints, { after: now }), | ||
| }) | ||
|
|
||
| return { dispatched, failures } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.