Skip to content

Commit f427ddc

Browse files
committed
fix(cli): keep update completion refresh lightweight
1 parent 1ee893b commit f427ddc

7 files changed

Lines changed: 55 additions & 9 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Docs: https://docs.openclaw.ai
1212

1313
### Fixes
1414

15+
- CLI/update: keep the automatic post-update completion refresh on the core-command tree so it no longer stages bundled plugin runtime deps before the Gateway restart path, avoiding `.24` update hangs and 1006 disconnect cascades. Fixes #72665. Thanks @sakalaboator and @He-Pin.
1516
- Agents/Bedrock: stop heartbeat runs from persisting blank user transcript turns and repair existing blank user text messages before replay, preventing AWS Bedrock `ContentBlock` blank-text validation failures. Fixes #72640 and #72622. Thanks @goldzulu.
1617
- LM Studio: allow interactive onboarding to leave the API key blank for unauthenticated local servers, using local synthetic auth while clearing stale LM Studio auth profiles. Fixes #66937. Thanks @olamedia.
1718
- Process/Windows: decode command stdout and stderr from raw bytes with console-codepage awareness, while preserving valid UTF-8 output and multibyte characters split across chunks. Fixes #50519. Thanks @iready, @kevinten10, @zhangyongjie1997, @knightplat-blip, @heiqishi666, and @slepybear.

‎docs/cli/update.md‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,10 @@ The Gateway core auto-updater (when enabled via config) reuses this same update
8787
For package-manager installs, `openclaw update` resolves the target package
8888
version before invoking the package manager. Even when the installed version
8989
already matches the target, the command refreshes the global package install,
90-
then runs plugin sync, completion refresh, and restart work. This keeps packaged
91-
sidecars and channel-owned plugin records aligned with the installed OpenClaw
92-
build.
90+
then runs plugin sync, a core-command completion refresh, and restart work. This
91+
keeps packaged sidecars and channel-owned plugin records aligned with the
92+
installed OpenClaw build while leaving full plugin-command completion rebuilds to
93+
explicit `openclaw completion --write-state` runs.
9394

9495
## Git checkout flow
9596

‎src/cli/completion-cli.ts‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
} from "./completion-fish.js";
1111
import {
1212
COMPLETION_SHELLS,
13+
COMPLETION_SKIP_PLUGIN_COMMANDS_ENV,
1314
installCompletion,
1415
isCompletionShell,
1516
resolveCompletionCachePath,
@@ -106,10 +107,12 @@ export function registerCompletionCli(program: Command) {
106107
// Eagerly register all subcommands except completion itself to build the full tree.
107108
await registerSubcommandsForCompletion(program);
108109

109-
const { registerPluginCliCommandsFromValidatedConfig } = await import("../plugins/cli.js");
110-
await registerPluginCliCommandsFromValidatedConfig(program, undefined, undefined, {
111-
mode: "eager",
112-
});
110+
if (process.env[COMPLETION_SKIP_PLUGIN_COMMANDS_ENV] !== "1") {
111+
const { registerPluginCliCommandsFromValidatedConfig } = await import("../plugins/cli.js");
112+
await registerPluginCliCommandsFromValidatedConfig(program, undefined, undefined, {
113+
mode: "eager",
114+
});
115+
}
113116

114117
if (options.writeState) {
115118
const writeShells = options.shell ? [shell] : [...COMPLETION_SHELLS];

‎src/cli/completion-cli.write-state.test.ts‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,4 +106,35 @@ describe("completion-cli write-state", () => {
106106
await fs.rm(stateDir, { recursive: true, force: true });
107107
await fs.rm(homeDir, { recursive: true, force: true });
108108
});
109+
110+
it("can skip plugin command registration for update-triggered cache writes", async () => {
111+
const [{ COMPLETION_SKIP_PLUGIN_COMMANDS_ENV }, { registerCompletionCli }] = await Promise.all([
112+
import("./completion-runtime.js"),
113+
import("./completion-cli.js"),
114+
]);
115+
const stateDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-completion-state-"));
116+
const homeDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-completion-home-"));
117+
118+
process.env.OPENCLAW_STATE_DIR = stateDir;
119+
process.env.HOME = homeDir;
120+
process.env[COMPLETION_SKIP_PLUGIN_COMMANDS_ENV] = "1";
121+
122+
try {
123+
const program = new Command();
124+
program.name("openclaw");
125+
registerCompletionCli(program);
126+
127+
await program.parseAsync(["completion", "--write-state"], { from: "user" });
128+
129+
expect(registerSubCliByNameMock).toHaveBeenCalledWith(program, "qa");
130+
expect(registerPluginCliCommandsFromValidatedConfigMock).not.toHaveBeenCalled();
131+
expect(await fs.readdir(path.join(stateDir, "completions"))).toEqual(
132+
expect.arrayContaining(["openclaw.bash", "openclaw.fish", "openclaw.ps1", "openclaw.zsh"]),
133+
);
134+
} finally {
135+
delete process.env[COMPLETION_SKIP_PLUGIN_COMMANDS_ENV];
136+
await fs.rm(stateDir, { recursive: true, force: true });
137+
await fs.rm(homeDir, { recursive: true, force: true });
138+
}
139+
});
109140
});

‎src/cli/completion-runtime.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { pathExists } from "../utils.js";
1010

1111
export const COMPLETION_SHELLS = ["zsh", "bash", "powershell", "fish"] as const;
1212
export type CompletionShell = (typeof COMPLETION_SHELLS)[number];
13+
export const COMPLETION_SKIP_PLUGIN_COMMANDS_ENV = "OPENCLAW_COMPLETION_SKIP_PLUGIN_COMMANDS";
1314

1415
export function isCompletionShell(value: string): value is CompletionShell {
1516
return COMPLETION_SHELLS.includes(value as CompletionShell);

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,12 @@ describe("update-cli", () => {
540540
expect(spawnSync).toHaveBeenCalledWith(
541541
expect.any(String),
542542
[path.join(root, "openclaw.mjs"), "completion", "--write-state"],
543-
expect.objectContaining({ timeout: 30_000 }),
543+
expect.objectContaining({
544+
env: expect.objectContaining({
545+
OPENCLAW_COMPLETION_SKIP_PLUGIN_COMMANDS: "1",
546+
}),
547+
timeout: 30_000,
548+
}),
544549
);
545550
});
546551

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { defaultRuntime } from "../../runtime.js";
2222
import { normalizeLowercaseStringOrEmpty } from "../../shared/string-coerce.js";
2323
import { theme } from "../../terminal/theme.js";
2424
import { pathExists } from "../../utils.js";
25+
import { COMPLETION_SKIP_PLUGIN_COMMANDS_ENV } from "../completion-runtime.js";
2526

2627
export type UpdateCommandOptions = {
2728
json?: boolean;
@@ -268,7 +269,10 @@ export async function tryWriteCompletionCache(root: string, jsonMode: boolean):
268269

269270
const result = spawnSync(resolveNodeRunner(), [binPath, "completion", "--write-state"], {
270271
cwd: root,
271-
env: process.env,
272+
env: {
273+
...process.env,
274+
[COMPLETION_SKIP_PLUGIN_COMMANDS_ENV]: "1",
275+
},
272276
encoding: "utf-8",
273277
timeout: COMPLETION_CACHE_WRITE_TIMEOUT_MS,
274278
});

0 commit comments

Comments
 (0)