MCPcopy Index your code
hub / github.com/claude-code-best/claude-code / persistAutonomyRunRecord

Function persistAutonomyRunRecord

src/utils/autonomyRuns.ts:397–456  ·  view source on GitHub ↗
(
  record: AutonomyRunRecord,
  rootDir: string,
  skipWhenActiveSource: boolean,
)

Source from the content-addressed store, hash-verified

395}
396
397async function persistAutonomyRunRecord(
398 record: AutonomyRunRecord,
399 rootDir: string,
400 skipWhenActiveSource: boolean,
401): Promise<{
402 created: boolean
403 recoveredStaleRuns: AutonomyRunRecord[]
404}> {
405 let created = false
406 const recoveredStaleRuns: AutonomyRunRecord[] = []
407 await withAutonomyPersistenceLock(rootDir, async () => {
408 const runs = await listAutonomyRuns(rootDir)
409 const sourceId = record.sourceId
410 if (skipWhenActiveSource && sourceId) {
411 let hasBlockingActiveRun = false
412 let staleRecoveriesApplied = false
413 for (let i = 0; i < runs.length; i++) {
414 const run = runs[i]!
415 if (
416 !matchesActiveAutonomyRunSource(run, {
417 trigger: record.trigger,
418 sourceId,
419 ownerKey: record.ownerKey,
420 })
421 ) {
422 continue
423 }
424 if (isStaleActiveAutonomyRun(run)) {
425 const recovered = recoverStaleActiveAutonomyRun(run, record.createdAt)
426 runs[i] = recovered
427 recoveredStaleRuns.push(recovered)
428 staleRecoveriesApplied = true
429 continue
430 }
431 if (
432 run.ownerProcessId === undefined &&
433 !warnedLegacyBlockRunIds.has(run.runId)
434 ) {
435 warnedLegacyBlockRunIds.add(run.runId)
436 logError(
437 new Error(
438 `[autonomyRuns] blocked by legacy un-owned active run ${run.runId} (createdAt=${run.createdAt}); cancel manually if this is a stale upgrade artifact`,
439 ),
440 )
441 }
442 hasBlockingActiveRun = true
443 }
444 if (hasBlockingActiveRun) {
445 if (staleRecoveriesApplied) {
446 await writeAutonomyRuns(runs, rootDir)
447 }
448 return
449 }
450 }
451 runs.unshift(record)
452 await writeAutonomyRuns(runs, rootDir)
453 created = true
454 })

Callers 1

createAutonomyRunCoreFunction · 0.85

Calls 10

listAutonomyRunsFunction · 0.85
isStaleActiveAutonomyRunFunction · 0.85
writeAutonomyRunsFunction · 0.85
logErrorFunction · 0.70
pushMethod · 0.45
hasMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected