@@ -9,7 +9,6 @@ import { prisma, PrismaClientOrTransaction } from "~/db.server";
99import { AuthenticatedEnvironment } from "~/services/apiAuth.server" ;
1010import { handleMetadataPacket } from "~/utils/packets" ;
1111import { BaseService , ServiceValidationError } from "~/v3/services/baseService.server" ;
12- import { isFinalRunStatus } from "~/v3/taskStatus" ;
1312
1413import { Effect , Schedule , Duration } from "effect" ;
1514import { type RuntimeFiber } from "effect/Fiber" ;
@@ -18,6 +17,8 @@ import { singleton } from "~/utils/singleton";
1817import { env } from "~/env.server" ;
1918import { setTimeout } from "timers/promises" ;
2019
20+ const RUN_UPDATABLE_WINDOW_MS = 60 * 60 * 1000 ; // 1 hour
21+
2122type BufferedRunMetadataChangeOperation = {
2223 runId : string ;
2324 timestamp : number ;
@@ -246,6 +247,7 @@ export class UpdateMetadataService extends BaseService {
246247 } ,
247248 select : {
248249 id : true ,
250+ completedAt : true ,
249251 status : true ,
250252 metadata : true ,
251253 metadataType : true ,
@@ -269,7 +271,7 @@ export class UpdateMetadataService extends BaseService {
269271 return ;
270272 }
271273
272- if ( isFinalRunStatus ( taskRun . status ) ) {
274+ if ( ! this . #isRunUpdatable ( taskRun ) ) {
273275 throw new ServiceValidationError ( "Cannot update metadata for a completed run" ) ;
274276 }
275277
@@ -391,6 +393,17 @@ export class UpdateMetadataService extends BaseService {
391393 }
392394 }
393395
396+ // Checks to see if a run is updatable
397+ // if there is no completedAt, the run is updatable
398+ // if the run is completed, but the completedAt is within the last 10 minutes, the run is updatable
399+ #isRunUpdatable( run : { completedAt : Date | null } ) {
400+ if ( ! run . completedAt ) {
401+ return true ;
402+ }
403+
404+ return run . completedAt . getTime ( ) > Date . now ( ) - RUN_UPDATABLE_WINDOW_MS ;
405+ }
406+
394407 async #updateRunMetadataDirectly(
395408 runId : string ,
396409 body : UpdateMetadataRequestBody ,
0 commit comments