@@ -6,13 +6,17 @@ import { containerTest } from "@internal/testcontainers";
66import { createRedisClient } from "@internal/redis" ;
77import { generateInternalId } from "@trigger.dev/core/v3/isomorphic" ;
88import { PostgresRunStore } from "./PostgresRunStore.js" ;
9- import { RedisSnapshotStore , type CompletedWaitpointRecord } from "./redisSnapshotStore.js" ;
9+ import {
10+ RedisSnapshotStore ,
11+ type CompletedWaitpointRecord ,
12+ type PreparedPgUnit ,
13+ } from "./redisSnapshotStore.js" ;
1014import {
1115 SnapshotWriteUnavailableError ,
1216 TaskRunExecutionSnapshotStore ,
1317} from "./taskRunExecutionSnapshotStore.js" ;
1418import { SnapshotResidencyResolver } from "./snapshotResidencyResolver.js" ;
15- import { snapshotKeys } from "./snapshotKeys.js" ;
19+ import { preparedUnitKey , snapshotKeys } from "./snapshotKeys.js" ;
1620import {
1721 buildCreateRunData ,
1822 seedSnapshotEnvironment ,
@@ -365,4 +369,102 @@ describe("redis-primary lockRunToWorker carries the completed-waitpoint cycle (F
365369 }
366370 }
367371 ) ;
372+
373+ // Catches: a carry that passes hydrated waitpoints (as startRunAttempt does) putting every output
374+ // into the prepared unit's cycle refs, beside the records.
375+ containerTest (
376+ "a carry from hydrated waitpoints prepares only their ids and indexes, and keeps every record" ,
377+ async ( { prisma, redisOptions } ) => {
378+ const store = new RedisSnapshotStore ( { redisOptions, completedTtlMs : 60_000 } ) ;
379+ const raw = createRedisClient ( redisOptions ) ;
380+ const delegate = new PostgresRunStore ( { prisma, readOnlyPrisma : prisma } ) ;
381+ let runId = "" ;
382+ const preparedUnits : string [ ] = [ ] ;
383+ const preparedStaged : string [ ] = [ ] ;
384+ const decorator = new TaskRunExecutionSnapshotStore ( delegate , {
385+ store,
386+ mode : "redis-only" ,
387+ resolveDial : ( ) => "redis-only" ,
388+ residencyResolver : new SnapshotResidencyResolver ( { store } ) ,
389+ logicalRunStoreRoute : ROUTE ,
390+ hooks : {
391+ afterPrepare : async ( ) => {
392+ preparedUnits . push ( ( await store . readPreparedUnitRaw ( runId ) ) ?? "" ) ;
393+ preparedStaged . push ( ( await raw . hget ( preparedUnitKey ( runId ) , "staged" ) ) ?? "" ) ;
394+ } ,
395+ } ,
396+ } ) ;
397+ try {
398+ const env = await seedSnapshotEnvironment ( prisma ) ;
399+ runId = generateInternalId ( ) ;
400+ const birthId = generateInternalId ( ) ;
401+ await decorator . createRun ( {
402+ data : buildCreateRunData ( runId , env ) ,
403+ snapshot : birthSnapshot ( env , birthId ) ,
404+ } ) ;
405+ const rec = ( id : string ) : CompletedWaitpointRecord => ( {
406+ id,
407+ friendlyId : `waitpoint_${ id } ` ,
408+ type : "RUN" ,
409+ completedAt : "2026-01-01T00:00:00.000Z" ,
410+ outputType : "application/json" ,
411+ outputIsError : true ,
412+ output : { inline : `record of ${ id } ` } ,
413+ } ) ;
414+ const base = {
415+ run : { id : runId , status : "EXECUTING" as const , attemptNumber : 1 } ,
416+ environmentId : env . id ,
417+ environmentType : env . type ,
418+ projectId : env . projectId ,
419+ organizationId : env . organizationId ,
420+ } ;
421+ const queuedId = generateInternalId ( ) ;
422+ await decorator . createExecutionSnapshot ( {
423+ ...base ,
424+ id : queuedId ,
425+ createdAt : new Date ( ) ,
426+ snapshot : { executionStatus : "QUEUED" , description : "resumed" } ,
427+ previousSnapshotId : birthId ,
428+ completedWaitpoints : [ { id : "A" , index : 0 } , { id : "B" } ] ,
429+ resolveCompletedWaitpointRecords : async ( ) => [ rec ( "A" ) , rec ( "B" ) ] ,
430+ } ) ;
431+ const hydrated = [ "A" , "B" ] . map ( ( id , i ) => ( {
432+ id,
433+ ...( i === 0 ? { index : 0 } : { } ) ,
434+ friendlyId : `waitpoint_${ id } ` ,
435+ type : "RUN" ,
436+ output : `hydrated output of ${ id } ` ,
437+ outputIsError : true ,
438+ } ) ) ;
439+ const executingId = generateInternalId ( ) ;
440+ await decorator . createExecutionSnapshot ( {
441+ ...base ,
442+ id : executingId ,
443+ createdAt : new Date ( ) ,
444+ snapshot : { executionStatus : "EXECUTING" , description : "started" } ,
445+ previousSnapshotId : queuedId ,
446+ completedWaitpoints : hydrated ,
447+ } ) ;
448+
449+ const last = preparedUnits . length - 1 ;
450+ const carried = JSON . parse ( preparedUnits [ last ] ! ) as PreparedPgUnit ;
451+ expect ( carried . entries [ 0 ] ! . cycle ) . toEqual ( {
452+ kind : "carryForward" ,
453+ cycleSeq : 1 ,
454+ completedWaitpoints : [ { id : "A" , index : 0 } , { id : "B" } ] ,
455+ records : [ rec ( "A" ) , rec ( "B" ) ] ,
456+ } ) ;
457+ expect ( JSON . parse ( preparedStaged [ last ] ! ) [ 0 ] . records ) . toBe (
458+ JSON . stringify ( [ rec ( "A" ) , rec ( "B" ) ] )
459+ ) ;
460+ for ( const unitJson of preparedUnits ) expect ( unitJson ) . not . toContain ( "hydrated output" ) ;
461+ const read = await store . getSnapshotCompletedWaitpoints ( runId , executingId ) ;
462+ expect ( read . order ) . toEqual ( [ "A" ] ) ;
463+ expect ( read . records ) . toEqual ( [ rec ( "A" ) , rec ( "B" ) ] ) ;
464+ } finally {
465+ await raw . quit ( ) ;
466+ await store . quit ( ) ;
467+ }
468+ }
469+ ) ;
368470} ) ;
0 commit comments