Skip to content

Commit ad5899c

Browse files
author
JooHyung Park
committed
[ai-assisted] fix: harden model retry recovery and mac universal runtime prep
1 parent 1a77f70 commit ad5899c

2 files changed

Lines changed: 29 additions & 2 deletions

File tree

scripts/prepare-llama-runtime.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ function resolveTargets(options) {
7878
return options.targets;
7979
}
8080

81-
if (process.platform === 'darwin' && process.env.CI) {
81+
if (process.platform === 'darwin') {
8282
return ['darwin-arm64', 'darwin-x64'];
8383
}
8484

src/main/assistant/ModelInstallService.ts

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ export class ModelInstallService {
217217

218218
const actualSha = await this.computeSha256(verificationPath);
219219
if (actualSha !== artifact.expectedSha256) {
220+
this.cleanupCorruptedArtifact(artifact);
220221
throw new Error(`Checksum mismatch for ${artifact.fileName}`);
221222
}
222223

@@ -478,7 +479,12 @@ export class ModelInstallService {
478479
unlinkSync(finalPath);
479480
}
480481

481-
const existingPartBytes = existsSync(partPath) ? statSync(partPath).size : 0;
482+
let existingPartBytes = existsSync(partPath) ? statSync(partPath).size : 0;
483+
if (existingPartBytes >= artifact.expectedSizeBytes) {
484+
this.safeDeleteFile(partPath);
485+
existingPartBytes = 0;
486+
}
487+
482488
const headers: Record<string, string> = {};
483489
if (existingPartBytes > 0) {
484490
headers.Range = `bytes=${existingPartBytes}-`;
@@ -488,6 +494,10 @@ export class ModelInstallService {
488494
...(Object.keys(headers).length > 0 ? { headers } : {}),
489495
signal,
490496
});
497+
if (response.status === 416) {
498+
this.safeDeleteFile(partPath);
499+
throw new Error(`Failed to resume download for ${artifact.fileName}: HTTP 416`);
500+
}
491501
if (!response.ok && response.status !== 206) {
492502
throw new Error(`Failed to download ${artifact.fileName}: HTTP ${response.status}`);
493503
}
@@ -544,6 +554,23 @@ export class ModelInstallService {
544554
});
545555
}
546556

557+
private cleanupCorruptedArtifact(artifact: DownloadArtifact): void {
558+
const partPath = this.getPartPath(artifact.fileName);
559+
this.safeDeleteFile(partPath);
560+
this.safeDeleteFile(artifact.destinationPath);
561+
}
562+
563+
private safeDeleteFile(filePath: string): void {
564+
if (!existsSync(filePath)) {
565+
return;
566+
}
567+
try {
568+
unlinkSync(filePath);
569+
} catch (error) {
570+
this.logger.warn(`Failed to delete file: ${filePath}, ${error}`);
571+
}
572+
}
573+
547574
private safeDeleteManagedFile(filePath: string): void {
548575
if (!filePath.startsWith(this.modelRootDir)) {
549576
return;

0 commit comments

Comments
 (0)