@@ -194,6 +194,7 @@ export class RunAttemptSystem {
194194 runTags : true ,
195195 isTest : true ,
196196 idempotencyKey : true ,
197+ idempotencyKeyOptions : true ,
197198 startedAt : true ,
198199 maxAttempts : true ,
199200 taskVersion : true ,
@@ -261,7 +262,8 @@ export class RunAttemptSystem {
261262 isTest : run . isTest ,
262263 createdAt : run . createdAt ,
263264 startedAt : run . startedAt ?? run . createdAt ,
264- idempotencyKey : run . idempotencyKey ?? undefined ,
265+ idempotencyKey : this . #getUserProvidedIdempotencyKey( run ) ?? undefined ,
266+ idempotencyKeyScope : this . #getIdempotencyKeyScope( run ) ,
265267 maxAttempts : run . maxAttempts ?? undefined ,
266268 version : run . taskVersion ?? "unknown" ,
267269 maxDuration : run . maxDurationInSeconds ?? undefined ,
@@ -422,6 +424,7 @@ export class RunAttemptSystem {
422424 runTags : true ,
423425 isTest : true ,
424426 idempotencyKey : true ,
427+ idempotencyKeyOptions : true ,
425428 startedAt : true ,
426429 maxAttempts : true ,
427430 taskVersion : true ,
@@ -570,7 +573,8 @@ export class RunAttemptSystem {
570573 createdAt : updatedRun . createdAt ,
571574 tags : updatedRun . runTags ,
572575 isTest : updatedRun . isTest ,
573- idempotencyKey : updatedRun . idempotencyKey ?? undefined ,
576+ idempotencyKey : this . #getUserProvidedIdempotencyKey( updatedRun ) ?? undefined ,
577+ idempotencyKeyScope : this . #getIdempotencyKeyScope( updatedRun ) ,
574578 startedAt : updatedRun . startedAt ?? updatedRun . createdAt ,
575579 maxAttempts : updatedRun . maxAttempts ?? undefined ,
576580 version : updatedRun . taskVersion ?? "unknown" ,
@@ -1914,6 +1918,25 @@ export class RunAttemptSystem {
19141918 stackTrace : truncateString ( error . stackTrace , 1024 * 16 ) , // 16kb
19151919 } ;
19161920 }
1921+
1922+ #getUserProvidedIdempotencyKey(
1923+ run : { idempotencyKey : string | null ; idempotencyKeyOptions : unknown }
1924+ ) : string | null {
1925+ const options = run . idempotencyKeyOptions as { key ?: string ; scope ?: string } | null ;
1926+ // Return user-provided key if available, otherwise fall back to the hash
1927+ return options ?. key ?? run . idempotencyKey ;
1928+ }
1929+
1930+ #getIdempotencyKeyScope(
1931+ run : { idempotencyKeyOptions : unknown }
1932+ ) : "run" | "attempt" | "global" | undefined {
1933+ const options = run . idempotencyKeyOptions as { key ?: string ; scope ?: string } | null ;
1934+ const scope = options ?. scope ;
1935+ if ( scope === "run" || scope === "attempt" || scope === "global" ) {
1936+ return scope ;
1937+ }
1938+ return undefined ;
1939+ }
19171940}
19181941
19191942export function safeParseGitMeta ( git : unknown ) : GitMeta | undefined {
0 commit comments