Skip to content

Commit 4505a88

Browse files
committed
fix(agents): preserve fallback trace truth
1 parent dae9006 commit 4505a88

3 files changed

Lines changed: 41 additions & 12 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ Docs: https://docs.openclaw.ai
4141
- Control UI/usage: remove the duplicated inner Usage page heading so the shared dashboard header is the only page title. Thanks @BunsDev.
4242
- Control UI/logs: make the Gateway Logs stream height responsive to the viewport with a minimum height floor, so larger screens can show substantially more log lines without collapsing on shorter viewports. (#53916) Thanks @extrasmall0.
4343
- ACP/Codex: surface redacted Codex wrapper stderr for generic ACP internal failures and preserve safe Codex model/provider routing in isolated `CODEX_HOME`, making `sessions_spawn(runtime="acp", agentId="codex")` failures actionable. Fixes #80079. (#80718) Thanks @leoge007.
44+
- Agents/trace: mark execution traces as fallback-used when merged fallback attempts prove a primary model failed before the winning attempt, keeping `/trace raw` and agent JSON telemetry consistent. Addresses fallback telemetry in #81213. Thanks @BKF-Gitty.
4445
- ACP: treat rejected timeout config options as best-effort hints so ACP turns continue with adapters that do not support `session/set_config_option` timeout keys. Fixes #81250. (#81603) Thanks @qkal.
4546
- Cron/Codex: default exact-command scheduled agent turns to lightweight bootstrap context so automation runs the command before loading workspace identity or memory context.
4647
- Codex cron: disable native Codex project-doc loading for lightweight app-server cron turns so scheduled jobs avoid project-doc injection after OpenClaw suppresses bootstrap context. (#81822) Thanks @jalehman.

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

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1121,6 +1121,22 @@ describe("runReplyAgent Active Memory inline debug", () => {
11211121
"utf-8",
11221122
);
11231123

1124+
runWithModelFallbackMock.mockImplementationOnce(
1125+
async ({ run }: RunWithModelFallbackParams) => ({
1126+
result: await run("anthropic", "claude"),
1127+
provider: "anthropic",
1128+
model: "claude",
1129+
attempts: [
1130+
{
1131+
provider: "openai",
1132+
model: "gpt-5.5",
1133+
error: "LLM request timed out.",
1134+
reason: "timeout",
1135+
status: 408,
1136+
},
1137+
],
1138+
}),
1139+
);
11241140
runEmbeddedPiAgentMock.mockResolvedValueOnce({
11251141
payloads: [{ text: "Visible reply" }],
11261142
meta: {
@@ -1132,16 +1148,8 @@ describe("runReplyAgent Active Memory inline debug", () => {
11321148
winnerProvider: "anthropic",
11331149
winnerModel: "claude",
11341150
runner: "embedded",
1135-
fallbackUsed: true,
1151+
fallbackUsed: false,
11361152
attempts: [
1137-
{
1138-
provider: "minimax-portal",
1139-
model: "MiniMax-M2.5",
1140-
result: "timeout",
1141-
reason: "timeout",
1142-
stage: "assistant",
1143-
elapsedMs: 15000,
1144-
},
11451153
{
11461154
provider: "anthropic",
11471155
model: "claude",
@@ -1250,9 +1258,9 @@ describe("runReplyAgent Active Memory inline debug", () => {
12501258
expect(traceText).toContain("attempts=2");
12511259
expect(traceText).toContain("runner=embedded");
12521260
expect(traceText).toContain("🔎 Fallback Chain:");
1253-
expect(traceText).toContain("1. minimax-portal/MiniMax-M2.5");
1261+
expect(traceText).toContain("1. openai/gpt-5.5");
12541262
expect(traceText).toContain("result=timeout");
1255-
expect(traceText).toContain("elapsed=15.0s");
1263+
expect(traceText).toContain("status=408");
12561264
expect(traceText).toContain("2. anthropic/claude");
12571265
expect(traceText).toContain("result=success");
12581266
expect(traceText).toContain("🔎 Request Shaping:");
@@ -1787,6 +1795,20 @@ describe("runReplyAgent claude-cli routing", () => {
17871795
provider: "claude-cli",
17881796
model: "opus-4.5",
17891797
},
1798+
executionTrace: {
1799+
winnerProvider: "claude-cli",
1800+
winnerModel: "opus-4.5",
1801+
attempts: [
1802+
{
1803+
provider: "claude-cli",
1804+
model: "opus-4.5",
1805+
result: "error",
1806+
reason: "before_agent_run blocked the run",
1807+
},
1808+
],
1809+
fallbackUsed: false,
1810+
runner: "cli",
1811+
},
17901812
},
17911813
});
17921814

@@ -1892,6 +1914,7 @@ describe("runReplyAgent claude-cli routing", () => {
18921914
expect(texts).toContain(
18931915
"Your message could not be sent: The agent cannot read this message. (blocked by policy-plugin)",
18941916
);
1917+
expect(texts).toContain("fallbackUsed=no");
18951918
expect(texts).not.toContain("secret hitl prompt");
18961919
});
18971920

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,11 +405,16 @@ function mergeExecutionTrace(params: {
405405
if (!winnerProvider && !winnerModel && attempts.length === 0) {
406406
return undefined;
407407
}
408+
const fallbackAttemptCount = params.fallbackAttempts?.length ?? 0;
409+
const traceFallbackUsed = params.executionTrace?.fallbackUsed;
408410
return {
409411
winnerProvider,
410412
winnerModel,
411413
attempts: attempts.length > 0 ? attempts : undefined,
412-
fallbackUsed: params.executionTrace?.fallbackUsed ?? attempts.length > 1,
414+
fallbackUsed:
415+
traceFallbackUsed === true ||
416+
fallbackAttemptCount > 0 ||
417+
(traceFallbackUsed === undefined && attempts.length > 1),
413418
runner: params.executionTrace?.runner ?? params.runner,
414419
};
415420
}

0 commit comments

Comments
 (0)