MCPcopy Create free account
hub / github.com/MoonshotAI/kimi-code / startBackgroundInstall

Function startBackgroundInstall

apps/kimi-code/src/cli/update/preflight.ts:511–621  ·  view source on GitHub ↗
(
  state: UpdateInstallState,
  currentVersion: string,
  target: UpdateTarget,
  source: InstallSource,
  platform: NodeJS.Platform,
  track: RunUpdatePreflightOptions['track'],
  logger: UpdateLogger,
  rolloutTelemetry: RolloutTelemetry,
)

Source from the content-addressed store, hash-verified

509}
510
511async function startBackgroundInstall(
512 state: UpdateInstallState,
513 currentVersion: string,
514 target: UpdateTarget,
515 source: InstallSource,
516 platform: NodeJS.Platform,
517 track: RunUpdatePreflightOptions['track'],
518 logger: UpdateLogger,
519 rolloutTelemetry: RolloutTelemetry,
520): Promise<void> {
521 const lock = await tryAcquireUpdateInstallLock({ version: target.version });
522 if (lock === null) return;
523
524 try {
525 const freshState = await readUpdateInstallState().catch(() => state);
526 if (
527 hasFreshActiveInstall(freshState, target) ||
528 failureAttemptsFor(freshState, target) >= AUTO_INSTALL_FAILURE_PROMPT_THRESHOLD
529 ) {
530 return;
531 }
532
533 const startedState: UpdateInstallState = {
534 ...freshState,
535 active: {
536 version: target.version,
537 source,
538 startedAt: nowIso(),
539 },
540 };
541 await writeUpdateInstallState(startedState);
542 trackUpdateEvent(track, 'update_background_install_started', {
543 current_version: currentVersion,
544 target_version: target.version,
545 source,
546 ...rolloutTelemetry,
547 });
548 logUpdateInfo(logger, 'background update install started', {
549 currentVersion,
550 targetVersion: target.version,
551 source,
552 });
553
554 const { cmd, args } = spawnForSource(source, target.version, platform);
555 let settled = false;
556
557 const finish = (succeeded: boolean): void => {
558 if (settled) return;
559 settled = true;
560 const attempts = failureAttemptsFor(startedState, target) + 1;
561
562 const nextState: UpdateInstallState = succeeded
563 ? {
564 ...startedState,
565 active: null,
566 lastFailure: null,
567 lastSuccess: {
568 version: target.version,

Callers 1

Calls 13

readUpdateInstallStateFunction · 0.90
writeUpdateInstallStateFunction · 0.90
hasFreshActiveInstallFunction · 0.85
failureAttemptsForFunction · 0.85
nowIsoFunction · 0.85
trackUpdateEventFunction · 0.85
logUpdateInfoFunction · 0.85
spawnForSourceFunction · 0.85
finishFunction · 0.70
onceMethod · 0.65
releaseMethod · 0.65

Tested by

no test coverage detected