Skip to content

Commit 6b04170

Browse files
committed
fix(agents): stabilize Linux fallback tests
1 parent bcf756c commit 6b04170

7 files changed

Lines changed: 121 additions & 25 deletions

‎CHANGELOG.md‎

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

5252
### Fixes
5353

54+
- Agents: let embedded compaction fallback retries proceed when PI-compatible candidates do not need agent harness plugin preparation.
5455
- Agents/tools: honor configured custom provider API keys when deciding whether media, image-generation, video-generation, music-generation, and PDF tools are available. (#85570)
5556
- StepFun: stop advertising stale generic API key auth choices so onboarding only offers runtime-backed Standard and Step Plan choices.
5657
- Diagnostics: keep OpenTelemetry log bodies behind explicit content capture and scrub scoped agent-session keys from OpenTelemetry and Prometheus labels while preserving bounded queue-lane prefixes.

‎src/agents/bash-tools.exec-gateway-approval.e2e.test.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const TEST_ENV_KEYS = [
2828
"OPENCLAW_SKIP_CANVAS_HOST",
2929
"OPENCLAW_SKIP_BROWSER_CONTROL_SERVER",
3030
"OPENCLAW_SKIP_PROVIDERS",
31+
"OPENCLAW_TEST_MINIMAL_GATEWAY",
3132
];
3233

3334
type Cleanup = () => Promise<void> | void;
@@ -107,6 +108,7 @@ describe("gateway-hosted exec approvals", () => {
107108
process.env.OPENCLAW_SKIP_CANVAS_HOST = "1";
108109
process.env.OPENCLAW_SKIP_BROWSER_CONTROL_SERVER = "1";
109110
process.env.OPENCLAW_SKIP_PROVIDERS = "1";
111+
process.env.OPENCLAW_TEST_MINIMAL_GATEWAY = "1";
110112
clearRuntimeConfigSnapshot();
111113
clearConfigCache();
112114
clearSessionStoreCacheForTest();
@@ -115,6 +117,7 @@ describe("gateway-hosted exec approvals", () => {
115117
bind: "loopback",
116118
auth: { mode: "token", token },
117119
controlUiEnabled: false,
120+
deferStartupSidecars: true,
118121
});
119122
cleanup.push(() => server.close());
120123

@@ -125,6 +128,7 @@ describe("gateway-hosted exec approvals", () => {
125128
clientDisplayName: "approval operator",
126129
mode: GATEWAY_CLIENT_MODES.TEST,
127130
scopes: [ADMIN_SCOPE],
131+
timeoutMs: 60_000,
128132
});
129133
cleanup.push(() => disconnectGatewayClient(operator));
130134

@@ -167,5 +171,5 @@ describe("gateway-hosted exec approvals", () => {
167171
expect(outcome.status).toBe("completed");
168172
expect(outcome.exitCode).toBe(0);
169173
expect(outcome.aggregated).toBe("smoke");
170-
});
174+
}, 120_000);
171175
});

‎src/agents/model-fallback.test.ts‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,56 @@ describe("runWithModelFallback", () => {
558558
expect(result.attempts[0].reason).toBe("unknown");
559559
});
560560

561+
it("does not prepare agent harness plugins for forced PI candidates", async () => {
562+
const cfg = makeCfg({
563+
models: {
564+
providers: {
565+
openai: {
566+
baseUrl: "https://api.openai.com/v1",
567+
agentRuntime: { id: "pi" },
568+
models: [],
569+
},
570+
},
571+
},
572+
});
573+
const prepareAgentHarnessRuntime = vi.fn(() => {
574+
throw new Error("PI candidates should not prepare plugin harnesses");
575+
});
576+
const run = vi.fn().mockResolvedValueOnce("ok");
577+
578+
const result = await runWithModelFallback({
579+
cfg,
580+
provider: "openai",
581+
model: "gpt-5.5",
582+
prepareAgentHarnessRuntime,
583+
run,
584+
});
585+
586+
expect(result.result).toBe("ok");
587+
expect(prepareAgentHarnessRuntime).not.toHaveBeenCalled();
588+
expect(run).toHaveBeenCalledTimes(1);
589+
});
590+
591+
it("does not prepare agent harness plugins for implicit Codex candidates", async () => {
592+
const cfg = makeCfg();
593+
const prepareAgentHarnessRuntime = vi.fn(() => {
594+
throw new Error("implicit Codex candidates should stay PI-compatible");
595+
});
596+
const run = vi.fn().mockResolvedValueOnce("ok");
597+
598+
const result = await runWithModelFallback({
599+
cfg,
600+
provider: "openai",
601+
model: "gpt-5.5",
602+
prepareAgentHarnessRuntime,
603+
run,
604+
});
605+
606+
expect(result.result).toBe("ok");
607+
expect(prepareAgentHarnessRuntime).not.toHaveBeenCalled();
608+
expect(run).toHaveBeenCalledTimes(1);
609+
});
610+
561611
it("fails closed when a strict plugin harness is missing", async () => {
562612
const cfg = makeCfg({
563613
agents: {

‎src/agents/model-fallback.ts‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -374,17 +374,19 @@ async function assertModelFallbackCandidateHarnessAvailable(
374374
if (isCliAgentRuntime(agentRuntime, params.cfg)) {
375375
return;
376376
}
377+
if (
378+
agentRuntime === "auto" ||
379+
agentRuntime === "pi" ||
380+
(agentRuntime === "codex" && agentRuntimeSource === "implicit")
381+
) {
382+
return;
383+
}
377384
await params.prepareAgentHarnessRuntime?.({
378385
provider: params.provider,
379386
model: params.model,
380387
agentHarnessRuntimeOverride,
381388
});
382-
if (
383-
agentRuntime !== "auto" &&
384-
agentRuntime !== "pi" &&
385-
!(agentRuntime === "codex" && agentRuntimeSource === "implicit") &&
386-
!getRegisteredAgentHarness(agentRuntime)
387-
) {
389+
if (!getRegisteredAgentHarness(agentRuntime)) {
388390
throw new MissingAgentHarnessError(agentRuntime);
389391
}
390392
}

‎src/agents/subagent-registry.announce-loop-guard.test.ts‎

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,28 @@ describe("announce loop guard (#18264)", () => {
7777
return entry;
7878
}
7979

80+
async function flushAsync() {
81+
await Promise.resolve();
82+
await Promise.resolve();
83+
}
84+
85+
async function waitForRun(
86+
runId: string,
87+
predicate: (run: SubagentRunRecord) => boolean,
88+
): Promise<SubagentRunRecord> {
89+
for (let attempt = 0; attempt < 40; attempt += 1) {
90+
const run = registry
91+
.listSubagentRunsForRequester("agent:main:main")
92+
.find((candidate) => candidate.runId === runId);
93+
if (run && predicate(run)) {
94+
return run;
95+
}
96+
await vi.advanceTimersByTimeAsync(1);
97+
await flushAsync();
98+
}
99+
throw new Error(`subagent run ${runId} did not reach expected state`);
100+
}
101+
80102
beforeAll(async () => {
81103
vi.resetModules();
82104
registry = await import("./subagent-registry.js");
@@ -184,8 +206,7 @@ describe("announce loop guard (#18264)", () => {
184206
// Initialization attempts resume once, then gives up for exhausted entries.
185207
const beforeInit = Date.now();
186208
registry.initSubagentRegistry();
187-
await Promise.resolve();
188-
await Promise.resolve();
209+
await flushAsync();
189210

190211
expect(mocks.runSubagentAnnounceFlow).not.toHaveBeenCalled();
191212
expect(entry.cleanupCompletedAt).toBeGreaterThanOrEqual(beforeInit);
@@ -220,8 +241,7 @@ describe("announce loop guard (#18264)", () => {
220241
);
221242

222243
registry.initSubagentRegistry();
223-
await Promise.resolve();
224-
await Promise.resolve();
244+
await flushAsync();
225245

226246
expect(mocks.runSubagentAnnounceFlow).toHaveBeenCalledTimes(1);
227247
});
@@ -254,14 +274,13 @@ describe("announce loop guard (#18264)", () => {
254274
);
255275

256276
registry.initSubagentRegistry();
257-
await Promise.resolve();
258-
await Promise.resolve();
277+
await flushAsync();
259278

260-
const runs = registry.listSubagentRunsForRequester("agent:main:main");
261-
const stored = runs.find((run) => run.runId === runId);
262-
expect(stored?.cleanupHandled).toBe(false);
263-
expect(stored?.cleanupCompletedAt).toBeUndefined();
264-
expect(stored?.announceRetryCount).toBe(1);
265-
expect(stored?.lastAnnounceRetryAt).toBeTypeOf("number");
279+
const stored = await waitForRun(
280+
runId,
281+
(run) => run.cleanupHandled === false && run.announceRetryCount === 1,
282+
);
283+
expect(stored.cleanupCompletedAt).toBeUndefined();
284+
expect(stored.lastAnnounceRetryAt).toBeTypeOf("number");
266285
});
267286
});

‎src/agents/subagent-registry.lifecycle-retry-grace.e2e.test.ts‎

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ type LifecycleEvent = {
2323
};
2424

2525
type SessionStoreEntry = {
26-
sessionId?: string;
27-
updatedAt?: number;
26+
sessionId: string;
27+
updatedAt: number;
2828
channel?: string;
2929
lastChannel?: string;
3030
to?: string;
@@ -193,6 +193,20 @@ describe("subagent registry lifecycle error grace", () => {
193193
subagentAnnounceOutputTesting.setDepsForTest({
194194
callGateway: callGatewayMock as typeof import("../gateway/call.js").callGateway,
195195
getRuntimeConfig: loadConfigMock as typeof import("../config/config.js").getRuntimeConfig,
196+
readLatestAssistantReply: async (params) => {
197+
const sessionKey = params?.sessionKey ?? "";
198+
const messages = chatHistoryBySessionKey.get(sessionKey) ?? [];
199+
for (const message of messages.toReversed()) {
200+
if (message.role !== "assistant") {
201+
continue;
202+
}
203+
return typeof message.content === "string" ? message.content : undefined;
204+
}
205+
return undefined;
206+
},
207+
readSessionEntry: (_storePath, sessionKey) => sessionStore[sessionKey],
208+
resolveAgentIdFromSessionKey: (key) => key?.match(/^agent:([^:]+)/)?.[1] ?? "main",
209+
resolveStorePath: () => "/tmp/test-store",
196210
});
197211
});
198212

‎src/gateway/test-helpers.e2e.ts‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,23 +68,29 @@ export async function connectGatewayClient(params: {
6868
);
6969
return await new Promise<InstanceType<typeof GatewayClient>>((resolve, reject) => {
7070
let settled = false;
71-
const stop = (err?: Error, client?: InstanceType<typeof GatewayClient>) => {
71+
let client: InstanceType<typeof GatewayClient> | undefined;
72+
const stop = (err?: Error, connectedClient?: InstanceType<typeof GatewayClient>) => {
7273
if (settled) {
7374
return;
7475
}
7576
settled = true;
7677
clearTimeout(timer);
7778
if (err) {
79+
void client?.stopAndWait({ timeoutMs: 1_000 }).catch(() => {
80+
client?.stop();
81+
});
7882
reject(err);
7983
} else {
80-
resolve(client as InstanceType<typeof GatewayClient>);
84+
resolve(connectedClient as InstanceType<typeof GatewayClient>);
8185
}
8286
};
83-
const client = new GatewayClient({
87+
client = new GatewayClient({
8488
url: params.url,
8589
token: params.token,
8690
deviceToken: params.deviceToken,
87-
connectChallengeTimeoutMs: params.connectChallengeTimeoutMs ?? 0,
91+
...(params.connectChallengeTimeoutMs !== undefined
92+
? { connectChallengeTimeoutMs: params.connectChallengeTimeoutMs }
93+
: {}),
8894
clientName: params.clientName ?? GATEWAY_CLIENT_NAMES.TEST,
8995
clientDisplayName: params.clientDisplayName ?? "vitest",
9096
clientVersion: params.clientVersion ?? "dev",

0 commit comments

Comments
 (0)