-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
feat(supervisor): verify warm-start delivery, cold-start silently lost dispatches #3918
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
Open
myftija
wants to merge
3
commits into
main
Choose a base branch
from
tri-10659-warm-start-delivery-verification
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| area: supervisor | ||
| type: feature | ||
| --- | ||
|
|
||
| Verify warm-start dispatches were acted on and cold-start the run within seconds when a dispatch is silently lost (opt-in via TRIGGER_WARM_START_VERIFY_ENABLED). |
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
132 changes: 132 additions & 0 deletions
132
apps/supervisor/src/services/warmStartVerificationService.test.ts
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,132 @@ | ||
| import { describe, expect, it, vi } from "vitest"; | ||
| import { setTimeout as sleep } from "node:timers/promises"; | ||
| import { WarmStartVerificationService } from "./warmStartVerificationService.js"; | ||
| import type { DequeuedMessage } from "@trigger.dev/core/v3"; | ||
| import type { SupervisorHttpClient } from "@trigger.dev/core/v3/workers"; | ||
|
|
||
| // The TimerWheel ticks every 100ms, so a 1000ms delay (the env minimum) | ||
| // fires within ~1.1s. | ||
| const DELAY_MS = 1_000; | ||
| // Long enough that a pending verification would certainly have fired. | ||
| const SETTLE_MS = 1_600; | ||
|
|
||
| const DEQUEUED_SNAPSHOT_ID = "snapshot_dequeued"; | ||
|
|
||
| function makeMessage(runFriendlyId = "run_1"): DequeuedMessage { | ||
| return { | ||
| run: { friendlyId: runFriendlyId }, | ||
| snapshot: { friendlyId: DEQUEUED_SNAPSHOT_ID }, | ||
| } as unknown as DequeuedMessage; | ||
| } | ||
|
|
||
| function createService(opts: { | ||
| latestSnapshotId?: string; | ||
| probeError?: boolean; | ||
| }) { | ||
| const getLatestSnapshot = vi.fn(async (_runId: string) => | ||
| opts.probeError | ||
| ? { success: false as const, error: "connection refused" } | ||
| : { | ||
| success: true as const, | ||
| data: { execution: { snapshot: { friendlyId: opts.latestSnapshotId } } }, | ||
| } | ||
| ); | ||
|
|
||
| const createWorkload = vi.fn(async () => {}); | ||
|
|
||
| const service = new WarmStartVerificationService({ | ||
| workerClient: { getLatestSnapshot } as unknown as SupervisorHttpClient, | ||
| delayMs: DELAY_MS, | ||
| createWorkload, | ||
| wideEventOpts: { service: "supervisor-test", env: {}, enabled: false }, | ||
| }); | ||
|
|
||
| return { service, getLatestSnapshot, createWorkload }; | ||
| } | ||
|
|
||
| describe("WarmStartVerificationService", () => { | ||
| it("falls back to a cold create when the snapshot is unchanged", async () => { | ||
| const { service, createWorkload } = createService({ | ||
| latestSnapshotId: DEQUEUED_SNAPSHOT_ID, | ||
| }); | ||
| try { | ||
| const message = makeMessage(); | ||
| const timings = { warmStartCheckMs: 12 }; | ||
| service.schedule(message, timings); | ||
|
|
||
| await vi.waitFor(() => expect(createWorkload).toHaveBeenCalledTimes(1), { | ||
| timeout: 3_000, | ||
| }); | ||
| expect(createWorkload).toHaveBeenCalledWith(message, timings); | ||
| } finally { | ||
| service.stop(); | ||
| } | ||
| }); | ||
|
|
||
| it("does nothing when the snapshot has moved on (delivered)", async () => { | ||
| const { service, getLatestSnapshot, createWorkload } = createService({ | ||
| latestSnapshotId: "snapshot_executing", | ||
| }); | ||
| try { | ||
| service.schedule(makeMessage(), { warmStartCheckMs: 12 }); | ||
|
|
||
| await vi.waitFor(() => expect(getLatestSnapshot).toHaveBeenCalledTimes(1), { | ||
| timeout: 3_000, | ||
| }); | ||
| await sleep(100); | ||
| expect(createWorkload).not.toHaveBeenCalled(); | ||
| } finally { | ||
| service.stop(); | ||
| } | ||
| }); | ||
|
|
||
| it("never falls back when the probe errors", async () => { | ||
| const { service, getLatestSnapshot, createWorkload } = createService({ probeError: true }); | ||
| try { | ||
| service.schedule(makeMessage(), { warmStartCheckMs: 12 }); | ||
|
|
||
| await vi.waitFor(() => expect(getLatestSnapshot).toHaveBeenCalledTimes(1), { | ||
| timeout: 3_000, | ||
| }); | ||
| await sleep(100); | ||
| expect(createWorkload).not.toHaveBeenCalled(); | ||
| } finally { | ||
| service.stop(); | ||
| } | ||
| }); | ||
|
|
||
| it("cancel before the delay prevents the probe entirely", async () => { | ||
| const { service, getLatestSnapshot, createWorkload } = createService({ | ||
| latestSnapshotId: DEQUEUED_SNAPSHOT_ID, | ||
| }); | ||
| try { | ||
| service.schedule(makeMessage(), { warmStartCheckMs: 12 }); | ||
|
|
||
| expect(service.cancel("run_1")).toBe(true); | ||
|
|
||
| await sleep(SETTLE_MS); | ||
| expect(getLatestSnapshot).not.toHaveBeenCalled(); | ||
| expect(createWorkload).not.toHaveBeenCalled(); | ||
| } finally { | ||
| service.stop(); | ||
| } | ||
| }); | ||
|
|
||
| it("re-scheduling the same run replaces the pending verification", async () => { | ||
| const { service, getLatestSnapshot } = createService({ | ||
| latestSnapshotId: "snapshot_executing", | ||
| }); | ||
| try { | ||
| service.schedule(makeMessage(), { warmStartCheckMs: 1 }); | ||
| service.schedule(makeMessage(), { warmStartCheckMs: 2 }); | ||
|
|
||
| await vi.waitFor(() => expect(getLatestSnapshot).toHaveBeenCalledTimes(1), { | ||
| timeout: 3_000, | ||
| }); | ||
| await sleep(SETTLE_MS); | ||
| expect(getLatestSnapshot).toHaveBeenCalledTimes(1); | ||
| } finally { | ||
| service.stop(); | ||
| } | ||
| }); | ||
| }); |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📝 Info: recordPhaseSince is a silent no-op when called from the verification fallback path
When
createWorkloadis invoked from the verification service's timer callback (the fallback cold-create path), it runs outside anyrunWideEventcontext. TherecordPhaseSincecalls atapps/supervisor/src/index.ts:576andapps/supervisor/src/index.ts:584-588usefromContext()which returnsnullin this case, makingrecordPhasea no-op (apps/supervisor/src/wideEvents/record.ts:27). This means theworkload_createphase timing data is silently dropped for fallback cold-creates. The separateemitOneShotcall with outcome"fallback"in the verification service (warmStartVerificationService.ts:140) does capture the event, so there is observability — just not at the same phase-level granularity as the normal dequeue path.Was this helpful? React with 👍 or 👎 to provide feedback.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The condition you flagged holds: recordPhaseSince -> recordPhase guards with
if (!state) return(apps/supervisor/src/wideEvents/record.ts:27), and fromContext() returns null outside the ALS scope (wideEvents/context.ts:12) - so from the verifier's timer path it's a clean no-op, no throw, no corrupted phase data. The fallback path's observability instead comes from the warmstart.verify wide event plus the runId-attributed error log in createWorkload's catch.