@@ -908,15 +908,8 @@ export class TaskHistoryStore {
908908 }
909909 }
910910
911- /**
912- * Return only the fields in `incoming` that differ from `cached`.
913- */
914- private computeDelta ( cached : HistoryItem , incoming : Partial < HistoryItem > ) : Partial < HistoryItem > {
915- return computeHistoryDelta ( cached , incoming )
916- }
917-
918911 private buildDelta ( id : string , cached : HistoryItem , incoming : Partial < HistoryItem > ) : Partial < HistoryItem > {
919- return { id, ...this . computeDelta ( cached , incoming ) }
912+ return { id, ...computeHistoryDelta ( cached , incoming ) }
920913 }
921914
922915 /**
@@ -954,10 +947,9 @@ export class TaskHistoryStore {
954947 } ,
955948 } )
956949 return written
957- } else {
958- await safeWriteJson ( filePath , item )
959- return item
960950 }
951+ await safeWriteJson ( filePath , item )
952+ return item
961953 }
962954
963955 private async reconcileTaskCache ( taskId : string ) : Promise < void > {
@@ -1252,13 +1244,11 @@ export class TaskHistoryStore {
12521244 const firstFileLock =
12531245 suppliedFirstFileLock ??
12541246 ( holdFirstFileLock ? await lockJsonFile ( await this . getTaskFilePath ( firstId ) ) : undefined )
1255- const ownsFirstFileLock = Boolean ( firstFileLock && ! suppliedFirstFileLock )
12561247
12571248 try {
12581249 let firstDiskSnapshot ! : TaskFilePreImage
1259- const firstDiskGuard = options ?. firstDiskGuard
12601250 const firstDelta = this . buildDelta ( firstId , first , updatedFirst )
1261- const writtenFirst = await this . writeTaskFile ( mergedFirst , firstDelta , firstDiskGuard , {
1251+ const writtenFirst = await this . writeTaskFile ( mergedFirst , firstDelta , options ?. firstDiskGuard , {
12621252 heldLock : firstFileLock ,
12631253 capturePreImage : ( preImage ) => ( firstDiskSnapshot = preImage ) ,
12641254 } )
@@ -1275,11 +1265,13 @@ export class TaskHistoryStore {
12751265 const firstRestoration = [ firstId , firstDiskSnapshot , expectedFirst , firstFileLock ] as const
12761266 const restorations = Array . of < TaskFileRestoration > ( firstRestoration )
12771267 if ( secondDiskSnapshot ) {
1278- const mergeSecond = mergeWithDisk ( secondDelta )
12791268 const secondPreImage = isValidTaskFilePreImage ( secondDiskSnapshot )
12801269 ? secondDiskSnapshot
12811270 : null
1282- const expectedSecond = mergeSecond ( secondPreImage , mergedSecond ) as HistoryItem
1271+ const expectedSecond = mergeWithDisk ( secondDelta ) (
1272+ secondPreImage ,
1273+ mergedSecond ,
1274+ ) as HistoryItem
12831275 const persistedSecond = JSON . parse ( JSON . stringify ( expectedSecond ) ) as HistoryItem
12841276 const expectedSecondStates = expectedTaskFileStates ( persistedSecond , secondDiskSnapshot )
12851277 restorations . unshift ( [ secondId , secondDiskSnapshot , expectedSecondStates ] )
@@ -1323,12 +1315,12 @@ export class TaskHistoryStore {
13231315 }
13241316 }
13251317
1326- const callbackErrors = Array . of ( error , ... compensationErrors )
1327- if ( compensationErrors . length ) throw new AggregateError ( callbackErrors , "Pair compensation failed" )
1318+ if ( compensationErrors . length )
1319+ throw new AggregateError ( Array . of ( error , ... compensationErrors ) , "Pair compensation failed" )
13281320 throw error
13291321 }
13301322 } finally {
1331- if ( ownsFirstFileLock ) await firstFileLock ! ( )
1323+ if ( firstFileLock && ! suppliedFirstFileLock ) await firstFileLock ( )
13321324 }
13331325 }
13341326 return options ?. storeLockAcquired ? update ( ) : this . withLock ( update )
0 commit comments