Skip to content

Commit b67d9bf

Browse files
committed
fix: propagate update timeout to plugin installs
1 parent d1f4073 commit b67d9bf

6 files changed

Lines changed: 99 additions & 6 deletions

File tree

‎src/cli/update-cli.test.ts‎

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -524,11 +524,11 @@ describe("update-cli", () => {
524524
it("respawns into the updated package root before running post-update tasks", async () => {
525525
const { entrypoints } = setupUpdatedRootRefresh();
526526

527-
await updateCommand({ yes: true });
527+
await updateCommand({ yes: true, timeout: "1800" });
528528

529529
expect(spawn).toHaveBeenCalledWith(
530530
expect.stringMatching(/node/),
531-
[entrypoints[0], "update", "--yes"],
531+
[entrypoints[0], "update", "--yes", "--timeout", "1800"],
532532
expect.objectContaining({
533533
stdio: "inherit",
534534
env: expect.objectContaining({
@@ -625,6 +625,22 @@ describe("update-cli", () => {
625625
expect(spawn).not.toHaveBeenCalled();
626626
});
627627

628+
it("passes the update timeout budget into post-core plugin updates", async () => {
629+
await withEnvAsync(
630+
{
631+
OPENCLAW_UPDATE_POST_CORE: "1",
632+
OPENCLAW_UPDATE_POST_CORE_CHANNEL: "stable",
633+
},
634+
async () => {
635+
await updateCommand({ restart: false, timeout: "1800" });
636+
},
637+
);
638+
639+
expect(updateNpmInstalledPlugins).toHaveBeenCalledWith(
640+
expect.objectContaining({ timeoutMs: 1_800_000 }),
641+
);
642+
});
643+
628644
it("uses a fail-closed integrity policy for post-core plugin updates", async () => {
629645
await withEnvAsync(
630646
{

‎src/cli/update-cli/update-command.ts‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ import { suppressDeprecations } from "./suppress-deprecations.js";
8989

9090
const CLI_NAME = resolveCliName();
9191
const SERVICE_REFRESH_TIMEOUT_MS = 60_000;
92+
const DEFAULT_UPDATE_STEP_TIMEOUT_MS = 20 * 60_000;
9293
const POST_CORE_UPDATE_ENV = "OPENCLAW_UPDATE_POST_CORE";
9394
const POST_CORE_UPDATE_CHANNEL_ENV = "OPENCLAW_UPDATE_POST_CORE_CHANNEL";
9495
const POST_CORE_UPDATE_RESULT_PATH_ENV = "OPENCLAW_UPDATE_POST_CORE_RESULT_PATH";
@@ -455,7 +456,7 @@ async function runGitUpdate(params: {
455456
devTargetRef?: string;
456457
}): Promise<UpdateRunResult> {
457458
const updateRoot = params.switchToGit ? resolveGitInstallDir() : params.root;
458-
const effectiveTimeout = params.timeoutMs ?? 20 * 60_000;
459+
const effectiveTimeout = params.timeoutMs ?? DEFAULT_UPDATE_STEP_TIMEOUT_MS;
459460
const installEnv = await createGlobalInstallEnv();
460461

461462
const cloneStep = params.switchToGit
@@ -537,6 +538,7 @@ async function updatePluginsAfterCoreUpdate(params: {
537538
channel: "stable" | "beta" | "dev";
538539
configSnapshot: Awaited<ReturnType<typeof readConfigFileSnapshot>>;
539540
opts: UpdateCommandOptions;
541+
timeoutMs: number;
540542
}): Promise<PostCorePluginUpdateResult> {
541543
if (!params.configSnapshot.valid) {
542544
if (!params.opts.json) {
@@ -589,6 +591,7 @@ async function updatePluginsAfterCoreUpdate(params: {
589591

590592
const npmResult = await updateNpmInstalledPlugins({
591593
config: pluginConfig,
594+
timeoutMs: params.timeoutMs,
592595
skipIds: new Set(syncResult.summary.switchedToNpm),
593596
logger: pluginLogger,
594597
onIntegrityDrift: async (drift) => {
@@ -896,12 +899,14 @@ async function runPostCorePluginUpdate(params: {
896899
channel: "stable" | "beta" | "dev";
897900
configSnapshot: Awaited<ReturnType<typeof readConfigFileSnapshot>>;
898901
opts: UpdateCommandOptions;
902+
timeoutMs: number;
899903
}): Promise<PostCorePluginUpdateResult> {
900904
return await updatePluginsAfterCoreUpdate({
901905
root: params.root,
902906
channel: params.channel,
903907
configSnapshot: params.configSnapshot,
904908
opts: params.opts,
909+
timeoutMs: params.timeoutMs,
905910
});
906911
}
907912

@@ -954,6 +959,9 @@ async function continuePostCoreUpdateInFreshProcess(params: {
954959
if (params.opts.yes) {
955960
argv.push("--yes");
956961
}
962+
if (params.opts.timeout) {
963+
argv.push("--timeout", params.opts.timeout);
964+
}
957965
const resultDir =
958966
params.opts.json === true
959967
? await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-update-post-core-"))
@@ -1018,6 +1026,7 @@ export async function updateCommand(opts: UpdateCommandOptions): Promise<void> {
10181026
if (timeoutMs === null) {
10191027
return;
10201028
}
1029+
const updateStepTimeoutMs = timeoutMs ?? DEFAULT_UPDATE_STEP_TIMEOUT_MS;
10211030

10221031
const root = await resolveUpdateRoot();
10231032
if (postCoreUpdateResume) {
@@ -1036,6 +1045,7 @@ export async function updateCommand(opts: UpdateCommandOptions): Promise<void> {
10361045
channel: postCoreUpdateChannel,
10371046
configSnapshot: await readConfigFileSnapshot(),
10381047
opts,
1048+
timeoutMs: updateStepTimeoutMs,
10391049
});
10401050
if (opts.json) {
10411051
await writePostCorePluginUpdateResultFile(
@@ -1146,7 +1156,7 @@ export async function updateCommand(opts: UpdateCommandOptions): Promise<void> {
11461156
mode = await resolveGlobalManager({
11471157
root,
11481158
installKind,
1149-
timeoutMs: timeoutMs ?? 20 * 60_000,
1159+
timeoutMs: updateStepTimeoutMs,
11501160
});
11511161
}
11521162

@@ -1271,7 +1281,7 @@ export async function updateCommand(opts: UpdateCommandOptions): Promise<void> {
12711281
root,
12721282
installKind,
12731283
tag,
1274-
timeoutMs: timeoutMs ?? 20 * 60_000,
1284+
timeoutMs: updateStepTimeoutMs,
12751285
startedAt,
12761286
progress,
12771287
jsonMode: Boolean(opts.json),
@@ -1414,6 +1424,7 @@ export async function updateCommand(opts: UpdateCommandOptions): Promise<void> {
14141424
channel,
14151425
configSnapshot: postUpdateConfigSnapshot,
14161426
opts,
1427+
timeoutMs: updateStepTimeoutMs,
14171428
});
14181429
}
14191430

‎src/plugins/clawhub.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,7 @@ async function resolveCompatiblePackageVersion(params: {
594594
requestedVersion?: string;
595595
baseUrl?: string;
596596
token?: string;
597+
timeoutMs?: number;
597598
}): Promise<
598599
| {
599600
ok: true;
@@ -617,6 +618,7 @@ async function resolveCompatiblePackageVersion(params: {
617618
version: requestedVersion,
618619
baseUrl: params.baseUrl,
619620
token: params.token,
621+
timeoutMs: params.timeoutMs,
620622
});
621623
} catch (error) {
622624
return mapClawHubRequestError(error, {
@@ -747,6 +749,7 @@ export async function installPluginFromClawHub(
747749
logger?: PluginInstallLogger;
748750
mode?: "install" | "update";
749751
extensionsDir?: string;
752+
timeoutMs?: number;
750753
dryRun?: boolean;
751754
expectedPluginId?: string;
752755
},
@@ -775,6 +778,7 @@ export async function installPluginFromClawHub(
775778
name: parsed.name,
776779
baseUrl: params.baseUrl,
777780
token: params.token,
781+
timeoutMs: params.timeoutMs,
778782
});
779783
} catch (error) {
780784
return mapClawHubRequestError(error, {
@@ -787,6 +791,7 @@ export async function installPluginFromClawHub(
787791
requestedVersion: parsed.version,
788792
baseUrl: params.baseUrl,
789793
token: params.token,
794+
timeoutMs: params.timeoutMs,
790795
});
791796
if (!versionState.ok) {
792797
return versionState;
@@ -821,6 +826,7 @@ export async function installPluginFromClawHub(
821826
version: versionState.version,
822827
baseUrl: params.baseUrl,
823828
token: params.token,
829+
timeoutMs: params.timeoutMs,
824830
});
825831
} catch (error) {
826832
return buildClawHubInstallFailure(formatErrorMessage(error));
@@ -864,6 +870,7 @@ export async function installPluginFromClawHub(
864870
logger: params.logger,
865871
mode: params.mode,
866872
extensionsDir: params.extensionsDir,
873+
timeoutMs: params.timeoutMs,
867874
dryRun: params.dryRun,
868875
expectedPluginId: params.expectedPluginId,
869876
});

‎src/plugins/marketplace.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,6 +1156,7 @@ export async function installPluginFromMarketplace(
11561156
logger: params.logger,
11571157
mode: params.mode,
11581158
extensionsDir: params.extensionsDir,
1159+
timeoutMs: params.timeoutMs,
11591160
dryRun: params.dryRun,
11601161
expectedPluginId: params.expectedPluginId,
11611162
});

‎src/plugins/update.test.ts‎

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,12 +214,14 @@ function expectNpmUpdateCall(params: {
214214
spec: string;
215215
expectedIntegrity?: string;
216216
expectedPluginId?: string;
217+
timeoutMs?: number;
217218
}) {
218219
expect(installPluginFromNpmSpecMock).toHaveBeenCalledWith(
219220
expect.objectContaining({
220221
spec: params.spec,
221222
expectedIntegrity: params.expectedIntegrity,
222223
...(params.expectedPluginId ? { expectedPluginId: params.expectedPluginId } : {}),
224+
...(params.timeoutMs ? { timeoutMs: params.timeoutMs } : {}),
223225
}),
224226
);
225227
}
@@ -355,6 +357,48 @@ describe("updateNpmInstalledPlugins", () => {
355357
},
356358
);
357359

360+
it("passes timeout budget to npm plugin metadata checks and installs", async () => {
361+
const installPath = createInstalledPackageDir({
362+
name: "@martian-engineering/lossless-claw",
363+
version: "0.9.0",
364+
});
365+
mockNpmViewMetadata({
366+
name: "@martian-engineering/lossless-claw",
367+
version: "0.10.0",
368+
integrity: "sha512-next",
369+
});
370+
installPluginFromNpmSpecMock.mockResolvedValue(
371+
createSuccessfulNpmUpdateResult({
372+
pluginId: "lossless-claw",
373+
targetDir: installPath,
374+
version: "0.10.0",
375+
}),
376+
);
377+
378+
await updateNpmInstalledPlugins({
379+
config: createNpmInstallConfig({
380+
pluginId: "lossless-claw",
381+
spec: "@martian-engineering/lossless-claw",
382+
installPath,
383+
resolvedName: "@martian-engineering/lossless-claw",
384+
resolvedSpec: "@martian-engineering/[email protected]",
385+
resolvedVersion: "0.9.0",
386+
}),
387+
pluginIds: ["lossless-claw"],
388+
timeoutMs: 1_800_000,
389+
});
390+
391+
const npmViewCall = runCommandWithTimeoutMock.mock.calls.find(
392+
([argv]) => Array.isArray(argv) && argv[0] === "npm" && argv[1] === "view",
393+
);
394+
expect(npmViewCall?.[1]).toEqual(expect.objectContaining({ timeoutMs: 1_800_000 }));
395+
expectNpmUpdateCall({
396+
spec: "@martian-engineering/lossless-claw",
397+
expectedPluginId: "lossless-claw",
398+
timeoutMs: 1_800_000,
399+
});
400+
});
401+
358402
it("skips npm reinstall and config rewrite when the installed artifact is unchanged", async () => {
359403
const installPath = createInstalledPackageDir({
360404
name: "@martian-engineering/lossless-claw",
@@ -798,6 +842,7 @@ describe("updateNpmInstalledPlugins", () => {
798842
clawhubChannel: "official",
799843
}),
800844
pluginIds: ["demo"],
845+
timeoutMs: 1_800_000,
801846
});
802847

803848
expect(installPluginFromClawHubMock).toHaveBeenCalledWith(
@@ -806,6 +851,7 @@ describe("updateNpmInstalledPlugins", () => {
806851
baseUrl: "https://clawhub.ai",
807852
expectedPluginId: "demo",
808853
mode: "update",
854+
timeoutMs: 1_800_000,
809855
}),
810856
);
811857
expect(result.config.plugins?.installs?.demo).toMatchObject({
@@ -930,6 +976,7 @@ describe("updateNpmInstalledPlugins", () => {
930976
marketplacePlugin: "claude-bundle",
931977
}),
932978
pluginIds: ["claude-bundle"],
979+
timeoutMs: 1_800_000,
933980
dryRun: true,
934981
});
935982

@@ -939,6 +986,7 @@ describe("updateNpmInstalledPlugins", () => {
939986
plugin: "claude-bundle",
940987
expectedPluginId: "claude-bundle",
941988
dryRun: true,
989+
timeoutMs: 1_800_000,
942990
}),
943991
);
944992
expect(result.outcomes).toEqual([

‎src/plugins/update.ts‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,7 @@ export async function updateNpmInstalledPlugins(params: {
469469
logger?: PluginUpdateLogger;
470470
pluginIds?: string[];
471471
skipIds?: Set<string>;
472+
timeoutMs?: number;
472473
dryRun?: boolean;
473474
dangerouslyForceUnsafeInstall?: boolean;
474475
specOverrides?: Record<string, string>;
@@ -567,7 +568,10 @@ export async function updateNpmInstalledPlugins(params: {
567568
});
568569

569570
if (!params.dryRun && record.source === "npm" && currentVersion) {
570-
const metadataResult = await resolveNpmSpecMetadata({ spec: effectiveSpec! });
571+
const metadataResult = await resolveNpmSpecMetadata({
572+
spec: effectiveSpec!,
573+
timeoutMs: params.timeoutMs,
574+
});
571575
if (metadataResult.ok) {
572576
if (
573577
shouldSkipUnchangedNpmInstall({
@@ -604,6 +608,7 @@ export async function updateNpmInstalledPlugins(params: {
604608
spec: effectiveSpec!,
605609
mode: "update",
606610
extensionsDir,
611+
timeoutMs: params.timeoutMs,
607612
dryRun: true,
608613
dangerouslyForceUnsafeInstall: params.dangerouslyForceUnsafeInstall,
609614
expectedPluginId: pluginId,
@@ -622,6 +627,7 @@ export async function updateNpmInstalledPlugins(params: {
622627
baseUrl: record.clawhubUrl,
623628
mode: "update",
624629
extensionsDir,
630+
timeoutMs: params.timeoutMs,
625631
dryRun: true,
626632
dangerouslyForceUnsafeInstall: params.dangerouslyForceUnsafeInstall,
627633
expectedPluginId: pluginId,
@@ -632,6 +638,7 @@ export async function updateNpmInstalledPlugins(params: {
632638
plugin: record.marketplacePlugin!,
633639
mode: "update",
634640
extensionsDir,
641+
timeoutMs: params.timeoutMs,
635642
dryRun: true,
636643
dangerouslyForceUnsafeInstall: params.dangerouslyForceUnsafeInstall,
637644
expectedPluginId: pluginId,
@@ -708,6 +715,7 @@ export async function updateNpmInstalledPlugins(params: {
708715
spec: effectiveSpec!,
709716
mode: "update",
710717
extensionsDir,
718+
timeoutMs: params.timeoutMs,
711719
dangerouslyForceUnsafeInstall: params.dangerouslyForceUnsafeInstall,
712720
expectedPluginId: pluginId,
713721
expectedIntegrity,
@@ -725,6 +733,7 @@ export async function updateNpmInstalledPlugins(params: {
725733
baseUrl: record.clawhubUrl,
726734
mode: "update",
727735
extensionsDir,
736+
timeoutMs: params.timeoutMs,
728737
dangerouslyForceUnsafeInstall: params.dangerouslyForceUnsafeInstall,
729738
expectedPluginId: pluginId,
730739
logger,
@@ -734,6 +743,7 @@ export async function updateNpmInstalledPlugins(params: {
734743
plugin: record.marketplacePlugin!,
735744
mode: "update",
736745
extensionsDir,
746+
timeoutMs: params.timeoutMs,
737747
dangerouslyForceUnsafeInstall: params.dangerouslyForceUnsafeInstall,
738748
expectedPluginId: pluginId,
739749
logger,

0 commit comments

Comments
 (0)