Skip to content

Commit 6f2e804

Browse files
authored
fix(agents): prefer background completion wake over polling (#60877)
* fix(agents): prefer completion wake over polling * fix(changelog): note completion wake guidance * fix(agents): qualify quiet exec completion wake * fix(agents): qualify disabled exec completion wake * fix(agents): split process polling from control actions
1 parent 0c3ec06 commit 6f2e804

6 files changed

Lines changed: 26 additions & 2 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ Docs: https://docs.openclaw.ai
9797
- Gateway/auth: serialize async shared-secret auth attempts per client so concurrent Tailscale-capable failures cannot overrun the intended auth rate-limit budget. Thanks @Telecaster2147.
9898
- Doctor/config: compare normalized `talk` configs by deep structural equality instead of key-order-sensitive serialization so `openclaw doctor --fix` stops repeatedly reporting/applying no-op `talk.provider/providers` normalization. (#59911) Thanks @ejames-dev.
9999
- Gateway/device auth: reuse cached device-token scopes only for cached-token reconnects, while keeping explicit `deviceToken` scope requests and empty-cache fallbacks intact so reconnects preserve `operator.read` without breaking explicit auth flows. (#46032) Thanks @caicongyang.
100+
- Agents/scheduling: steer background-now work toward automatic completion wake and treat `process` polling as on-demand inspection or intervention instead of default completion handling. (#60877) Thanks @vincentkoc.
100101
- Google Gemini CLI auth: improve OAuth credential discovery across Windows nvm and Homebrew libexec installs, and align Code Assist metadata so Gemini login stops failing on packaged CLI layouts. (#40729) Thanks @hughcube.
101102
- Mattermost/config schema: accept `groups.*.requireMention` again so existing Mattermost configs no longer fail strict validation after upgrade. (#58271) Thanks @MoerAI.
102103
- Agents/failover: scope Anthropic `An unknown error occurred` failover matching by provider so generic internal unknown-error text no longer triggers retryable timeout fallback. (#59325) Thanks @aaron-he-zhu.

‎src/agents/bash-tools.exec.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1119,6 +1119,7 @@ export function describeExecTool(params?: { agentId?: string; hasCronTool?: bool
11191119
const base = [
11201120
"Execute shell commands with background continuation for work that starts now.",
11211121
"Use yieldMs/background to continue later via process tool.",
1122+
"For long-running work started now, rely on automatic completion wake when it is enabled and the command emits output or fails; otherwise use process to confirm completion. Use process whenever you need logs, status, input, or intervention.",
11221123
params?.hasCronTool
11231124
? "Do not use exec sleep or delay loops for reminders or deferred follow-ups; use cron instead."
11241125
: undefined,

‎src/agents/bash-tools.process.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ function resetPollRetrySuggestion(sessionId: string): void {
120120
export function describeProcessTool(params?: { hasCronTool?: boolean }): string {
121121
return [
122122
"Manage running exec sessions for commands already started: list, poll, log, write, send-keys, submit, paste, kill.",
123+
"Use poll/log when you need status, logs, quiet-success confirmation, or completion confirmation when automatic completion wake is unavailable. Use write/send-keys/submit/paste/kill for input or intervention.",
123124
params?.hasCronTool
124125
? "Do not use process polling to emulate timers or reminders; use cron for scheduled follow-ups."
125126
: undefined,

‎src/agents/bash-tools.test.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,15 @@ describe("tool descriptions", () => {
415415
const execWithCron = createTestExecTool({ hasCronTool: true });
416416
const processWithCron = createProcessTool({ hasCronTool: true });
417417

418+
expect(execWithCron.description).toContain(
419+
"rely on automatic completion wake when it is enabled and the command emits output or fails; otherwise use process to confirm completion. Use process whenever you need logs, status, input, or intervention.",
420+
);
421+
expect(processWithCron.description).toContain(
422+
"completion confirmation when automatic completion wake is unavailable.",
423+
);
424+
expect(processWithCron.description).toContain(
425+
"Use write/send-keys/submit/paste/kill for input or intervention.",
426+
);
418427
expect(execWithCron.description).toContain(
419428
"Do not use exec sleep or delay loops for reminders or deferred follow-ups; use cron instead.",
420429
);
@@ -423,6 +432,9 @@ describe("tool descriptions", () => {
423432
);
424433
expect(execTool.description).not.toContain("use cron instead");
425434
expect(processTool.description).not.toContain("scheduled follow-ups");
435+
expect(execTool.description).toContain("otherwise use process to confirm completion");
436+
expect(processTool.description).toContain("completion confirmation when automatic completion wake is unavailable");
437+
expect(processTool.description).toContain("Use write/send-keys/submit/paste/kill for input or intervention.");
426438
});
427439
});
428440

‎src/agents/system-prompt.test.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,9 @@ describe("buildAgentSystemPrompt", () => {
124124
expect(prompt).toContain(
125125
"Use exec/process only for commands that start now and continue running in the background.",
126126
);
127+
expect(prompt).toContain(
128+
"For long-running work that starts now, start it once and rely on automatic completion wake when it is enabled and the command emits output or fails; otherwise use process to confirm completion, and use it for logs, status, input, or intervention.",
129+
);
127130
expect(prompt).toContain(
128131
"Do not emulate scheduling with sleep loops, timeout loops, or repeated polling.",
129132
);
@@ -295,6 +298,9 @@ describe("buildAgentSystemPrompt", () => {
295298
expect(prompt).toContain(
296299
"Use exec/process only for commands that start now and continue running in the background.",
297300
);
301+
expect(prompt).toContain(
302+
"For long-running work that starts now, start it once and rely on automatic completion wake when it is enabled and the command emits output or fails; otherwise use process to confirm completion, and use it for logs, status, input, or intervention.",
303+
);
298304
expect(prompt).toContain("Completion is push-based: it will auto-announce when done.");
299305
expect(prompt).toContain("Do not poll `subagents list` / `sessions_list` in a loop");
300306
expect(prompt).toContain(

‎src/agents/system-prompt.ts‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,9 @@ export function buildAgentSystemPrompt(params: {
244244
const sandboxedRuntime = params.sandboxInfo?.enabled === true;
245245
const acpSpawnRuntimeEnabled = acpEnabled && !sandboxedRuntime;
246246
const execToolSummary =
247-
"Run shell commands (pty available for TTY-required CLIs; use for work that starts now, not delayed follow-ups)";
248-
const processToolSummary = "Manage background exec sessions for commands already started";
247+
"Run shell commands (pty available for TTY-required CLIs; use for work that starts now, not delayed follow-ups; background completion may wake automatically when enabled)";
248+
const processToolSummary =
249+
"Manage background exec sessions for commands already started (poll/log for inspection, debugging, input, intervention, or completion confirmation when auto-wake is unavailable)";
249250
const cronToolSummary =
250251
"Manage cron jobs and wake events (use for reminders, delayed follow-ups, and recurring tasks; for requests like 'check back in 10 minutes' or 'remind me later', use cron instead of exec sleep, yieldMs delays, or process polling; when scheduling a reminder, write the systemEvent text as something that will read like a reminder when it fires, and mention that it is a reminder depending on the time gap between setting and firing; include recent context in reminder text if appropriate)";
251252
const coreToolSummaries: Record<string, string> = {
@@ -477,10 +478,12 @@ export function buildAgentSystemPrompt(params: {
477478
? [
478479
`For follow-up at a future time (for example "check back in 10 minutes", reminders, run-later work, or recurring tasks), use cron instead of ${execToolName} sleep, yieldMs delays, or ${processToolName} polling.`,
479480
`Use ${execToolName}/${processToolName} only for commands that start now and continue running in the background.`,
481+
`For long-running work that starts now, start it once and rely on automatic completion wake when it is enabled and the command emits output or fails; otherwise use ${processToolName} to confirm completion, and use it for logs, status, input, or intervention.`,
480482
"Do not emulate scheduling with sleep loops, timeout loops, or repeated polling.",
481483
]
482484
: [
483485
`For long waits, avoid rapid poll loops: use ${execToolName} with enough yieldMs or ${processToolName}(action=poll, timeout=<ms>).`,
486+
`For long-running work that starts now, start it once and rely on automatic completion wake when it is enabled and the command emits output or fails; otherwise use ${processToolName} to confirm completion, and use it for logs, status, input, or intervention.`,
484487
]),
485488
"If a task is more complex or takes longer, spawn a sub-agent. Completion is push-based: it will auto-announce when done.",
486489
...(acpHarnessSpawnAllowed

0 commit comments

Comments
 (0)