fix(cli): clarify completion cache timeout message after openclaw update

When the post-update completion cache refresh times out (slow disk,
large bundled plugin tree, Docker overlayfs), the user previously saw
the opaque 'Completion cache update failed: Error: spawnSync
/usr/bin/node ETIMEDOUT'. Detect ETIMEDOUT specifically, surface
'timed out after 30s', and append a manual refresh hint pointing at
'openclaw completion --write-state' so users know it's non-fatal and
how to recover.

Fixes #72842
This commit is contained in:
iot2edge
2026-04-27 16:29:52 +02:00
committed by Peter Steinberger
parent cdf88bcad4
commit 98928388db
2 changed files with 42 additions and 2 deletions

View File

@@ -549,6 +549,31 @@ describe("update-cli", () => {
);
});
it("logs friendly hint with manual refresh command when completion cache write times out", async () => {
const root = createCaseDir("openclaw-completion-timeout-msg");
pathExists.mockResolvedValue(true);
const timeoutErr = Object.assign(new Error("spawnSync /usr/bin/node ETIMEDOUT"), {
code: "ETIMEDOUT",
});
vi.mocked(spawnSync).mockReturnValueOnce({
pid: 0,
output: [],
stdout: "",
stderr: "",
status: null,
signal: null,
error: timeoutErr,
});
vi.mocked(runtimeCapture.log).mockClear();
await updateCliShared.tryWriteCompletionCache(root, false);
const logs = vi.mocked(runtimeCapture.log).mock.calls.map((call) => String(call[0]));
expect(logs.some((line) => line.includes("timed out after 30s"))).toBe(true);
expect(logs.some((line) => line.includes("openclaw completion --write-state"))).toBe(true);
expect(logs.some((line) => line.includes("Error: spawnSync"))).toBe(false);
});
it("respawns into the updated package root before running post-update tasks", async () => {
const { entrypoints } = setupUpdatedRootRefresh();

View File

@@ -260,6 +260,8 @@ export async function resolveGlobalManager(params: {
}
const COMPLETION_CACHE_WRITE_TIMEOUT_MS = 30_000;
const COMPLETION_CACHE_MANUAL_REFRESH_HINT =
"Shell tab-completion may be stale; refresh manually with: openclaw completion --write-state";
export async function tryWriteCompletionCache(root: string, jsonMode: boolean): Promise<void> {
const binPath = path.join(root, "openclaw.mjs");
@@ -279,7 +281,16 @@ export async function tryWriteCompletionCache(root: string, jsonMode: boolean):
if (result.error) {
if (!jsonMode) {
defaultRuntime.log(theme.warn(`Completion cache update failed: ${String(result.error)}`));
const err = result.error as NodeJS.ErrnoException;
const reason =
err.code === "ETIMEDOUT"
? `timed out after ${COMPLETION_CACHE_WRITE_TIMEOUT_MS / 1000}s`
: String(result.error);
defaultRuntime.log(
theme.warn(
`Completion cache update failed: ${reason}. ${COMPLETION_CACHE_MANUAL_REFRESH_HINT}`,
),
);
}
return;
}
@@ -287,7 +298,11 @@ export async function tryWriteCompletionCache(root: string, jsonMode: boolean):
if (result.status !== 0 && !jsonMode) {
const stderr = (result.stderr ?? "").trim();
const detail = stderr ? ` (${stderr})` : "";
defaultRuntime.log(theme.warn(`Completion cache update failed${detail}.`));
defaultRuntime.log(
theme.warn(
`Completion cache update failed${detail}. ${COMPLETION_CACHE_MANUAL_REFRESH_HINT}`,
),
);
}
}