Skip to content

Commit 7d05f7c

Browse files
NehoraiHadadNehoraiHadadobviyus
authored
fix(auto-reply): suppress fallback notices in rooms (#107209)
Hide model fallback and recovery notices in group and channel conversations while preserving direct-chat notices, persisted state, and lifecycle events. Co-authored-by: NehoraiHadad <[email protected]> Co-authored-by: Ayaan Zaidi <[email protected]>
1 parent 3554109 commit 7d05f7c

3 files changed

Lines changed: 133 additions & 106 deletions

File tree

‎docs/concepts/model-failover.md‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ The selection source controls whether the fallback chain is allowed:
5252
- **Legacy session override**: older session entries may have `modelOverride` without `modelOverrideSource`. OpenClaw treats those as user overrides so an explicit old selection is not silently converted into fallback behavior.
5353
- **Cron payload model**: a cron job `payload.model` / `--model` is a job primary, not a user session override. It uses configured fallbacks unless the job provides `payload.fallbacks`; `payload.fallbacks: []` makes the cron run strict.
5454

55-
OpenClaw sends a visible notice when a turn moves onto fallback and another notice when a later turn succeeds on the selected primary. Persisted notice state prevents repeated notices when consecutive turns use the same selected/active pair, while model selection itself remains unchanged.
55+
Outside group and channel conversations, OpenClaw sends a visible notice when a turn moves onto fallback and another notice when a later turn succeeds on the selected primary. Group and channel conversations keep the same fallback state and lifecycle events without posting these notices. Persisted notice state prevents repeated notices when consecutive turns use the same selected/active pair, while model selection itself remains unchanged.
5656

5757
## Auth failure skip cache
5858

@@ -70,7 +70,7 @@ The value is a TTL in milliseconds. `0` or unset disables the cache. Positive va
7070

7171
## User-visible fallback notices
7272

73-
When a session moves onto an auto-selected fallback, OpenClaw sends a status notice in the same reply surface:
73+
Outside group and channel conversations, OpenClaw sends a status notice in the same reply surface when a session moves onto an auto-selected fallback:
7474

7575
```text
7676
↪️ Model Fallback: <fallback> (selected <primary>; <reason>)
@@ -82,7 +82,7 @@ When a later probe succeeds and the session returns to the selected primary, Ope
8282
↪️ Model Fallback cleared: <primary> (was <fallback>)
8383
```
8484

85-
These notices are operational messages, not assistant content. They deliver once per state change, including side-effect-only turns when feasible, but repeated turn-local fallback transitions do not repeat them. Delivery bypasses normal source-reply suppression, does not consume the first assistant reply slot for threaded channels, and is excluded from text-to-speech.
85+
These notices are operational messages, not assistant content. They deliver once per state change outside group and channel conversations, including side-effect-only turns when feasible, but repeated turn-local fallback transitions do not repeat them. Group and channel conversations suppress the visible notices while retaining the same fallback state and lifecycle events. Delivery bypasses normal source-reply suppression, does not consume the first assistant reply slot for threaded channels, and is excluded from text-to-speech.
8686

8787
## Auth storage (keys + OAuth)
8888

@@ -326,7 +326,7 @@ Live model switching follows these rules:
326326
- User-driven model overrides are treated as exact selections for fallback policy, so an unreachable selected provider surfaces as a failure instead of being masked by `agents.defaults.model.fallbacks`.
327327
- Runtime fallback candidates remain turn-local. The next turn starts from the current selected model, including a manual selection that arrived during the previous run.
328328
- Previously stored auto fallback overrides remain supported: OpenClaw periodically probes their configured origin and clears the override when it recovers; `/new`, `/reset`, and `sessions.reset` clear auto-sourced overrides immediately.
329-
- User replies announce fallback transitions and fallback-cleared recovery once per state change. Repeated turns with the same selected/active pair do not repeat the notice.
329+
- Outside group and channel conversations, user replies announce fallback transitions and fallback-cleared recovery once per state change. Repeated turns with the same selected/active pair do not repeat the notice; group and channel conversations retain the same fallback state and lifecycle events without posting it.
330330
- `/status` shows the selected model and, when fallback state differs, the active fallback model and reason.
331331
- Live-session reconciliation prefers persisted session overrides over stale runtime model fields.
332332
- If a live-switch error points at a later candidate in the active fallback chain, OpenClaw jumps directly to that selected model instead of walking unrelated candidates first.

‎src/auto-reply/reply/agent-runner-result-payloads.ts‎

Lines changed: 35 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
} from "../../agents/embedded-agent-runner/delivery-evidence.js";
77
import { hasDeliberateSilentTerminalReply } from "../../agents/embedded-agent-runner/result-fallback-classifier.js";
88
import { deriveContextPromptTokens, hasNonzeroUsage } from "../../agents/usage.js";
9+
import { normalizeChatType } from "../../channels/chat-type.js";
910
import { emitAgentEvent } from "../../infra/agent-events.js";
1011
import { emitTrustedDiagnosticEvent, isDiagnosticsEnabled } from "../../infra/diagnostic-events.js";
1112
import {
@@ -279,12 +280,17 @@ export async function prepareReplyAgentPayloads(state: {
279280
);
280281
return returnPreparedFallbackPayload(silentFallbackFailurePayload);
281282
};
282-
const fallbackNoticePayloads: ReplyPayload[] = [];
283-
if (
283+
const fallbackNoticeChanged =
284284
!fallbackExhausted &&
285285
!preserveUserFacingSessionState &&
286-
fallbackTransition.fallbackTransitioned
287-
) {
286+
(fallbackTransition.fallbackTransitioned || fallbackTransition.fallbackCleared);
287+
const fallbackNoticeChatType = fallbackNoticeChanged
288+
? normalizeChatType(sessionCtx.ChatType)
289+
: undefined;
290+
const shouldDeliverFallbackNotice =
291+
fallbackNoticeChatType !== "group" && fallbackNoticeChatType !== "channel";
292+
let fallbackNoticeText: string | null = null;
293+
if (fallbackNoticeChanged && fallbackTransition.fallbackTransitioned) {
288294
emitAgentEvent({
289295
runId,
290296
sessionKey,
@@ -300,24 +306,18 @@ export async function prepareReplyAgentPayloads(state: {
300306
attempts: fallbackAttempts,
301307
},
302308
});
303-
const fallbackNotice = buildFallbackNotice({
304-
selectedProvider,
305-
selectedModel,
306-
activeProvider: providerUsed,
307-
activeModel: modelUsed,
308-
attempts: fallbackAttempts,
309-
cfg,
310-
});
311-
if (fallbackNotice) {
312-
fallbackNoticePayloads.push(
313-
markReplyPayloadForSourceSuppressionDelivery({
314-
text: fallbackNotice,
315-
isFallbackNotice: true,
316-
}),
317-
);
309+
if (shouldDeliverFallbackNotice) {
310+
fallbackNoticeText = buildFallbackNotice({
311+
selectedProvider,
312+
selectedModel,
313+
activeProvider: providerUsed,
314+
activeModel: modelUsed,
315+
attempts: fallbackAttempts,
316+
cfg,
317+
});
318318
}
319319
}
320-
if (!fallbackExhausted && !preserveUserFacingSessionState && fallbackTransition.fallbackCleared) {
320+
if (fallbackNoticeChanged && fallbackTransition.fallbackCleared) {
321321
emitAgentEvent({
322322
runId,
323323
sessionKey,
@@ -331,17 +331,22 @@ export async function prepareReplyAgentPayloads(state: {
331331
previousActiveModel: fallbackTransition.previousState.activeModel,
332332
},
333333
});
334-
fallbackNoticePayloads.push(
335-
markReplyPayloadForSourceSuppressionDelivery({
336-
text: buildFallbackClearedNotice({
337-
selectedProvider,
338-
selectedModel,
339-
previousActiveModel: fallbackTransition.previousState.activeModel,
340-
}),
341-
isFallbackNotice: true,
342-
}),
343-
);
334+
if (shouldDeliverFallbackNotice) {
335+
fallbackNoticeText = buildFallbackClearedNotice({
336+
selectedProvider,
337+
selectedModel,
338+
previousActiveModel: fallbackTransition.previousState.activeModel,
339+
});
340+
}
344341
}
342+
const fallbackNoticePayloads: ReplyPayload[] = fallbackNoticeText
343+
? [
344+
markReplyPayloadForSourceSuppressionDelivery({
345+
text: fallbackNoticeText,
346+
isFallbackNotice: true,
347+
}),
348+
]
349+
: [];
345350

346351
// Drain any late tool/block deliveries before deciding there's "nothing to send".
347352
// Otherwise, a late typing trigger (e.g. from a tool callback) can outlive the run and

‎src/auto-reply/reply/agent-runner.runreplyagent.e2e.test.ts‎

Lines changed: 94 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -4704,84 +4704,106 @@ describe("runReplyAgent typing (heartbeat)", () => {
47044704
}
47054705
});
47064706

4707-
it("announces fallback-cleared once when runtime returns to selected model", async () => {
4708-
const sessionEntry = makeSessionEntry();
4709-
const sessionStore = { main: sessionEntry };
4710-
let callCount = 0;
4707+
it.each([
4708+
{ label: "direct chats", chatType: "direct" as const, noticeVisible: true },
4709+
{ label: "group chats", chatType: "group" as const, noticeVisible: false },
4710+
{ label: "channels", chatType: "channel" as const, noticeVisible: false },
4711+
])(
4712+
"controls fallback notices for $label without changing state or lifecycle",
4713+
async ({ chatType, noticeVisible }) => {
4714+
const { sessionEntry, sessionStore, storePath } = await makeSessionFixture();
4715+
let callCount = 0;
47114716

4712-
state.runEmbeddedAgentMock.mockResolvedValue({
4713-
payloads: [{ text: "final" }],
4714-
meta: {},
4715-
});
4716-
const fallbackSpy = vi
4717-
.spyOn(modelFallbackModule, "runWithModelFallback")
4718-
.mockImplementation(
4719-
async ({
4720-
provider,
4721-
model,
4722-
run,
4723-
}: {
4724-
provider: string;
4725-
model: string;
4726-
run: (provider: string, model: string) => Promise<unknown>;
4727-
}) => {
4728-
callCount += 1;
4729-
if (callCount === 1) {
4717+
state.runEmbeddedAgentMock.mockResolvedValue({
4718+
payloads: [{ text: "final" }],
4719+
meta: {},
4720+
});
4721+
const fallbackSpy = vi
4722+
.spyOn(modelFallbackModule, "runWithModelFallback")
4723+
.mockImplementation(
4724+
async ({
4725+
provider,
4726+
model,
4727+
run,
4728+
}: {
4729+
provider: string;
4730+
model: string;
4731+
run: (provider: string, model: string) => Promise<unknown>;
4732+
}) => {
4733+
callCount += 1;
4734+
if (callCount === 1) {
4735+
return {
4736+
outcome: "completed" as const,
4737+
result: await run("deepinfra", "moonshotai/Kimi-K2.5"),
4738+
provider: "deepinfra",
4739+
model: "moonshotai/Kimi-K2.5",
4740+
attempts: [
4741+
{
4742+
provider: "fireworks",
4743+
model: "fireworks/accounts/fireworks/routers/kimi-k2p5-turbo",
4744+
error: "Provider fireworks is in cooldown (all profiles unavailable)",
4745+
reason: "rate_limit",
4746+
},
4747+
],
4748+
};
4749+
}
47304750
return {
47314751
outcome: "completed" as const,
4732-
result: await run("deepinfra", "moonshotai/Kimi-K2.5"),
4733-
provider: "deepinfra",
4734-
model: "moonshotai/Kimi-K2.5",
4735-
attempts: [
4736-
{
4737-
provider: "fireworks",
4738-
model: "fireworks/accounts/fireworks/routers/kimi-k2p5-turbo",
4739-
error: "Provider fireworks is in cooldown (all profiles unavailable)",
4740-
reason: "rate_limit",
4741-
},
4742-
],
4752+
result: await run(provider, model),
4753+
provider,
4754+
model,
4755+
attempts: [],
47434756
};
4757+
},
4758+
);
4759+
try {
4760+
const { run } = createMinimalRun({
4761+
resolvedVerboseLevel: "on",
4762+
sessionEntry,
4763+
sessionStore,
4764+
sessionKey: "main",
4765+
storePath,
4766+
sessionCtx: { ChatType: chatType },
4767+
});
4768+
const phases: string[] = [];
4769+
const off = onAgentEvent((evt) => {
4770+
const phase = typeof evt.data?.phase === "string" ? evt.data.phase : null;
4771+
if (evt.stream === "lifecycle" && phase) {
4772+
phases.push(phase);
47444773
}
4745-
return {
4746-
outcome: "completed" as const,
4747-
result: await run(provider, model),
4748-
provider,
4749-
model,
4750-
attempts: [],
4751-
};
4752-
},
4753-
);
4754-
try {
4755-
const { run } = createMinimalRun({
4756-
resolvedVerboseLevel: "on",
4757-
sessionEntry,
4758-
sessionStore,
4759-
sessionKey: "main",
4760-
});
4761-
const phases: string[] = [];
4762-
const off = onAgentEvent((evt) => {
4763-
const phase = typeof evt.data?.phase === "string" ? evt.data.phase : null;
4764-
if (evt.stream === "lifecycle" && phase) {
4765-
phases.push(phase);
4774+
});
4775+
const first = await run();
4776+
const activeFallback = {
4777+
kind: "active" as const,
4778+
selectedModel: "anthropic/claude",
4779+
activeModel: "deepinfra/moonshotai/Kimi-K2.5",
4780+
reason: "rate limit",
4781+
};
4782+
expect(sessionEntry.fallbackNotice).toEqual(activeFallback);
4783+
expect(requireStoredSessionEntry(storePath).fallbackNotice).toEqual(activeFallback);
4784+
const second = await run();
4785+
const third = await run();
4786+
off();
4787+
4788+
const firstText = Array.isArray(first) ? first[0]?.text : first?.text;
4789+
const secondText = Array.isArray(second) ? second[0]?.text : second?.text;
4790+
const thirdText = Array.isArray(third) ? third[0]?.text : third?.text;
4791+
expect(firstText?.includes("Model Fallback:")).toBe(noticeVisible);
4792+
expect(secondText?.includes("Model Fallback cleared:")).toBe(noticeVisible);
4793+
expect(thirdText).not.toContain("Model Fallback cleared:");
4794+
if (!noticeVisible) {
4795+
expect(firstText).toBe("final");
4796+
expect(secondText).toBe("final");
47664797
}
4767-
});
4768-
const first = await run();
4769-
const second = await run();
4770-
const third = await run();
4771-
off();
4772-
4773-
const firstText = Array.isArray(first) ? first[0]?.text : first?.text;
4774-
const secondText = Array.isArray(second) ? second[0]?.text : second?.text;
4775-
const thirdText = Array.isArray(third) ? third[0]?.text : third?.text;
4776-
expect(firstText).toContain("Model Fallback:");
4777-
expect(secondText).toContain("Model Fallback cleared:");
4778-
expect(thirdText).not.toContain("Model Fallback cleared:");
4779-
expect(countMatching(phases, (phase) => phase === "fallback")).toBe(1);
4780-
expect(countMatching(phases, (phase) => phase === "fallback_cleared")).toBe(1);
4781-
} finally {
4782-
fallbackSpy.mockRestore();
4783-
}
4784-
});
4798+
expect(countMatching(phases, (phase) => phase === "fallback")).toBe(1);
4799+
expect(countMatching(phases, (phase) => phase === "fallback_cleared")).toBe(1);
4800+
expect(sessionEntry.fallbackNotice).toBeUndefined();
4801+
expect(requireStoredSessionEntry(storePath).fallbackNotice).toBeUndefined();
4802+
} finally {
4803+
fallbackSpy.mockRestore();
4804+
}
4805+
},
4806+
);
47854807

47864808
it("announces fallback transitions and emits lifecycle events while verbose is off", async () => {
47874809
const sessionEntry = makeSessionEntry();

0 commit comments

Comments
 (0)