Skip to content

Commit 10d5b88

Browse files
committed
Agents/logging: reduce orphaned-user warning noise for background runs
1 parent e4dc03f commit 10d5b88

4 files changed

Lines changed: 31 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ Docs: https://docs.openclaw.ai
212212
- Exec/node hosts: stop forwarding the gateway workspace cwd to remote node exec when no workdir was explicitly requested, so cross-platform node approvals fall back to the node default cwd instead of failing with `SYSTEM_RUN_DENIED`. (#58977) Thanks @Starhappysh.
213213
- TUI/chat: keep pending local sends visible and reconciled across history reloads, make busy/error recovery clearer through fallback and terminal-error paths, and reclaim transcript width for long links and paths. (#59800) Thanks @vincentkoc.
214214
- Exec approvals/channels: decouple initiating-surface approval availability from native delivery enablement so Telegram, Slack, and Discord still expose approvals when approvers exist and native target routing is configured separately. (#59776) Thanks @joelnishanth.
215+
- Agents/logging: keep orphaned-user transcript repair warnings focused on interactive runs, and downgrade background-trigger repairs (`heartbeat`, `cron`, `memory`, `overflow`) to debug logs to reduce false-alarm gateway noise.
215216

216217
## 2026.4.1
217218

src/agents/pi-embedded-runner/run/attempt.prompt-helpers.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,12 @@ export function shouldInjectHeartbeatPrompt(params: {
9696
return params.isDefaultAgent && shouldInjectHeartbeatPromptForTrigger(params.trigger);
9797
}
9898

99+
export function shouldWarnOnOrphanedUserRepair(
100+
trigger: EmbeddedRunAttemptParams["trigger"],
101+
): boolean {
102+
return trigger === "user" || trigger === "manual";
103+
}
104+
99105
export function resolveAttemptFsWorkspaceOnly(params: {
100106
config?: OpenClawConfig;
101107
sessionAgentId: string;

src/agents/pi-embedded-runner/run/attempt.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
resolveEmbeddedAgentStreamFn,
2020
resolvePromptBuildHookResult,
2121
resolvePromptModeForSession,
22+
shouldWarnOnOrphanedUserRepair,
2223
wrapStreamFnRepairMalformedToolCallArguments,
2324
wrapStreamFnSanitizeMalformedToolCalls,
2425
wrapStreamFnTrimToolCallNames,
@@ -224,6 +225,20 @@ describe("resolvePromptModeForSession", () => {
224225
});
225226
});
226227

228+
describe("shouldWarnOnOrphanedUserRepair", () => {
229+
it("warns for user and manual runs", () => {
230+
expect(shouldWarnOnOrphanedUserRepair("user")).toBe(true);
231+
expect(shouldWarnOnOrphanedUserRepair("manual")).toBe(true);
232+
});
233+
234+
it("does not warn for background triggers", () => {
235+
expect(shouldWarnOnOrphanedUserRepair("heartbeat")).toBe(false);
236+
expect(shouldWarnOnOrphanedUserRepair("cron")).toBe(false);
237+
expect(shouldWarnOnOrphanedUserRepair("memory")).toBe(false);
238+
expect(shouldWarnOnOrphanedUserRepair("overflow")).toBe(false);
239+
});
240+
});
241+
227242
describe("resolveEmbeddedAgentStreamFn", () => {
228243
it("injects authStorage api keys into provider-owned stream functions", async () => {
229244
const providerStreamFn = vi.fn(async (_model, _context, options) => options);

src/agents/pi-embedded-runner/run/attempt.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ import {
143143
resolveAttemptFsWorkspaceOnly,
144144
resolvePromptBuildHookResult,
145145
resolvePromptModeForSession,
146+
shouldWarnOnOrphanedUserRepair,
146147
shouldInjectHeartbeatPrompt,
147148
} from "./attempt.prompt-helpers.js";
148149
import {
@@ -192,6 +193,7 @@ export {
192193
resolveAttemptFsWorkspaceOnly,
193194
resolvePromptBuildHookResult,
194195
resolvePromptModeForSession,
196+
shouldWarnOnOrphanedUserRepair,
195197
shouldInjectHeartbeatPrompt,
196198
} from "./attempt.prompt-helpers.js";
197199
export {
@@ -1542,10 +1544,14 @@ export async function runEmbeddedAttempt(
15421544
}
15431545
const sessionContext = sessionManager.buildSessionContext();
15441546
activeSession.agent.replaceMessages(sessionContext.messages);
1545-
log.warn(
1547+
const orphanRepairMessage =
15461548
`Removed orphaned user message to prevent consecutive user turns. ` +
1547-
`runId=${params.runId} sessionId=${params.sessionId}`,
1548-
);
1549+
`runId=${params.runId} sessionId=${params.sessionId} trigger=${params.trigger}`;
1550+
if (shouldWarnOnOrphanedUserRepair(params.trigger)) {
1551+
log.warn(orphanRepairMessage);
1552+
} else {
1553+
log.debug(orphanRepairMessage);
1554+
}
15491555
}
15501556
const transcriptLeafId =
15511557
(sessionManager.getLeafEntry() as { id?: string } | null | undefined)?.id ?? null;

0 commit comments

Comments
 (0)