fix: avoid imessage rpc restart loop

This commit is contained in:
Peter Steinberger
2026-01-17 00:34:44 +00:00
parent 64a2ef4a18
commit 6e5eddf292
4 changed files with 99 additions and 0 deletions

View File

@@ -92,6 +92,12 @@
- Discord: allow emoji/sticker uploads + channel actions in config defaults. (#870) — thanks @JDIVE. - Discord: allow emoji/sticker uploads + channel actions in config defaults. (#870) — thanks @JDIVE.
### Fixes ### Fixes
- WhatsApp: default response prefix only for self-chat, using identity name when set.
- Signal/iMessage: bound transport readiness waits to 30s with periodic logging. (#1014) — thanks @Szpadel.
- iMessage: treat missing `imsg rpc` support as fatal to avoid restart loops.
- Auth: merge main auth profiles into per-agent stores for sub-agents and document inheritance. (#1013) — thanks @marcmarg.
- Agents: avoid JSON Schema `format` collisions in tool params by renaming snapshot format fields. (#1013) — thanks @marcmarg.
- Fix: make `clawdbot update` auto-update global installs when installed via a package manager.
- Fix: list model picker entries as provider/model pairs for explicit selection. (#970) — thanks @mcinteerj. - Fix: list model picker entries as provider/model pairs for explicit selection. (#970) — thanks @mcinteerj.
- Fix: align OpenAI image-gen defaults with DALL-E 3 standard quality and document output formats. (#880) — thanks @mkbehr. - Fix: align OpenAI image-gen defaults with DALL-E 3 standard quality and document output formats. (#880) — thanks @mkbehr.
- Fix: persist `gateway.mode=local` after selecting Local run mode in `clawdbot configure`, even if no other sections are chosen. - Fix: persist `gateway.mode=local` after selecting Local run mode in `clawdbot configure`, even if no other sections are chosen.

View File

@@ -472,6 +472,9 @@ export async function monitorIMessageProvider(opts: MonitorIMessageOpts = {}): P
check: async () => { check: async () => {
const probe = await probeIMessage(2000, { cliPath, dbPath, runtime }); const probe = await probeIMessage(2000, { cliPath, dbPath, runtime });
if (probe.ok) return { ok: true }; if (probe.ok) return { ok: true };
if (probe.fatal) {
throw new Error(probe.error ?? "imsg rpc unavailable");
}
return { ok: false, error: probe.error ?? "unreachable" }; return { ok: false, error: probe.error ?? "unreachable" };
}, },
}); });

View File

@@ -0,0 +1,41 @@
import { beforeEach, describe, expect, it, vi } from "vitest";
import { probeIMessage } from "./probe.js";
const detectBinaryMock = vi.hoisted(() => vi.fn());
const runCommandWithTimeoutMock = vi.hoisted(() => vi.fn());
const createIMessageRpcClientMock = vi.hoisted(() => vi.fn());
vi.mock("../commands/onboard-helpers.js", () => ({
detectBinary: (...args: unknown[]) => detectBinaryMock(...args),
}));
vi.mock("../process/exec.js", () => ({
runCommandWithTimeout: (...args: unknown[]) => runCommandWithTimeoutMock(...args),
}));
vi.mock("./client.js", () => ({
createIMessageRpcClient: (...args: unknown[]) => createIMessageRpcClientMock(...args),
}));
beforeEach(() => {
detectBinaryMock.mockReset().mockResolvedValue(true);
runCommandWithTimeoutMock.mockReset().mockResolvedValue({
stdout: "",
stderr: 'unknown command "rpc" for "imsg"',
code: 1,
signal: null,
killed: false,
});
createIMessageRpcClientMock.mockReset();
});
describe("probeIMessage", () => {
it("marks unknown rpc subcommand as fatal", async () => {
const result = await probeIMessage(1000, { cliPath: "imsg" });
expect(result.ok).toBe(false);
expect(result.fatal).toBe(true);
expect(result.error).toMatch(/rpc/i);
expect(createIMessageRpcClientMock).not.toHaveBeenCalled();
});
});

View File

@@ -1,11 +1,13 @@
import { detectBinary } from "../commands/onboard-helpers.js"; import { detectBinary } from "../commands/onboard-helpers.js";
import { loadConfig } from "../config/config.js"; import { loadConfig } from "../config/config.js";
import { runCommandWithTimeout } from "../process/exec.js";
import type { RuntimeEnv } from "../runtime.js"; import type { RuntimeEnv } from "../runtime.js";
import { createIMessageRpcClient } from "./client.js"; import { createIMessageRpcClient } from "./client.js";
export type IMessageProbe = { export type IMessageProbe = {
ok: boolean; ok: boolean;
error?: string | null; error?: string | null;
fatal?: boolean;
}; };
export type IMessageProbeOptions = { export type IMessageProbeOptions = {
@@ -14,6 +16,44 @@ export type IMessageProbeOptions = {
runtime?: RuntimeEnv; runtime?: RuntimeEnv;
}; };
type RpcSupportResult = {
supported: boolean;
error?: string;
fatal?: boolean;
};
const rpcSupportCache = new Map<string, RpcSupportResult>();
async function probeRpcSupport(cliPath: string): Promise<RpcSupportResult> {
const cached = rpcSupportCache.get(cliPath);
if (cached) return cached;
try {
const result = await runCommandWithTimeout([cliPath, "rpc", "--help"], { timeoutMs: 2000 });
const combined = `${result.stdout}\n${result.stderr}`.trim();
const normalized = combined.toLowerCase();
if (normalized.includes("unknown command") && normalized.includes("rpc")) {
const fatal = {
supported: false,
fatal: true,
error: 'imsg CLI does not support the "rpc" subcommand (update imsg)',
};
rpcSupportCache.set(cliPath, fatal);
return fatal;
}
if (result.code === 0) {
const supported = { supported: true };
rpcSupportCache.set(cliPath, supported);
return supported;
}
return {
supported: false,
error: combined || `imsg rpc --help failed (code ${String(result.code ?? "unknown")})`,
};
} catch (err) {
return { supported: false, error: String(err) };
}
}
export async function probeIMessage( export async function probeIMessage(
timeoutMs = 2000, timeoutMs = 2000,
opts: IMessageProbeOptions = {}, opts: IMessageProbeOptions = {},
@@ -26,6 +66,15 @@ export async function probeIMessage(
return { ok: false, error: `imsg not found (${cliPath})` }; return { ok: false, error: `imsg not found (${cliPath})` };
} }
const rpcSupport = await probeRpcSupport(cliPath);
if (!rpcSupport.supported) {
return {
ok: false,
error: rpcSupport.error ?? "imsg rpc unavailable",
fatal: rpcSupport.fatal,
};
}
const client = await createIMessageRpcClient({ const client = await createIMessageRpcClient({
cliPath, cliPath,
dbPath, dbPath,