Skip to content

Commit b742909

Browse files
authored
fix(agents): prefer cron for deferred follow-ups (#60811)
* fix(agents): prefer cron for deferred follow-ups * fix(agents): gate cron scheduling guidance * fix(changelog): add scheduling guidance note * fix(agents): restore exec approval agent hint
1 parent d46eabb commit b742909

14 files changed

Lines changed: 164 additions & 25 deletions

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ Docs: https://docs.openclaw.ai
198198
- Browser/profiles: reject remote browser profile `cdpUrl` values that violate strict SSRF policy before saving config, with clearer validation errors for blocked endpoints. (#60477) Thanks @eleqtrizit.
199199
- Browser/screenshots: stop sending `fromSurface: false` on CDP screenshots so managed Chrome 146+ browsers can capture images again. (#60682) Thanks @mvanhorn.
200200
- Mattermost/slash commands: harden native slash-command callback token validation to use constant-time secret comparison, matching the existing interaction-token path.
201+
- Agents/scheduling: route delayed follow-up requests toward cron only when cron is actually available, while keeping background `exec`/`process` guidance scoped to work that starts now. (#60811) Thanks @vincentkoc.
201202
- Cron/security: reject unsafe custom `sessionTarget: "session:..."` IDs earlier during cron add, update, and execution so malformed custom session keys fail closed with clear errors.
202203

203204
## 2026.4.1

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type { SafeBinProfileFixture } from "../infra/exec-safe-bin-policy.js";
44
import type { BashSandboxConfig } from "./bash-tools.shared.js";
55

66
export type ExecToolDefaults = {
7+
hasCronTool?: boolean;
78
host?: ExecTarget;
89
security?: ExecSecurity;
910
ask?: ExecAsk;

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

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1115,9 +1115,17 @@ function deriveExecShortName(fullPath: string): string {
11151115
return base.replace(/\.exe$/i, "") || base;
11161116
}
11171117

1118-
function buildExecToolDescription(agentId?: string): string {
1119-
const base =
1120-
"Execute shell commands with background continuation. Use yieldMs/background to continue later via process tool. Use pty=true for TTY-required commands (terminal UIs, coding agents).";
1118+
export function describeExecTool(params?: { agentId?: string; hasCronTool?: boolean }): string {
1119+
const base = [
1120+
"Execute shell commands with background continuation for work that starts now.",
1121+
"Use yieldMs/background to continue later via process tool.",
1122+
params?.hasCronTool
1123+
? "Do not use exec sleep or delay loops for reminders or deferred follow-ups; use cron instead."
1124+
: undefined,
1125+
"Use pty=true for TTY-required commands (terminal UIs, coding agents).",
1126+
]
1127+
.filter(Boolean)
1128+
.join(" ");
11211129
if (process.platform !== "win32") {
11221130
return base;
11231131
}
@@ -1127,7 +1135,10 @@ function buildExecToolDescription(agentId?: string): string {
11271135
);
11281136
try {
11291137
const approvalsFile = loadExecApprovals();
1130-
const approvals = resolveExecApprovalsFromFile({ file: approvalsFile, agentId });
1138+
const approvals = resolveExecApprovalsFromFile({
1139+
file: approvalsFile,
1140+
agentId: params?.agentId,
1141+
});
11311142
const allowlist = approvals.allowlist.filter((entry) => {
11321143
const pattern = entry.pattern?.trim() ?? "";
11331144
return (
@@ -1208,7 +1219,7 @@ export function createExecTool(
12081219
name: "exec",
12091220
label: "exec",
12101221
get description() {
1211-
return buildExecToolDescription(agentId);
1222+
return describeExecTool({ agentId, hasCronTool: defaults?.hasCronTool === true });
12121223
},
12131224
parameters: execSchema,
12141225
execute: async (_toolCallId, args, signal, onUpdate) => {

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { encodeKeySequence, encodePaste, hasCursorModeSensitiveKeys } from "./pt
2121

2222
export type ProcessToolDefaults = {
2323
cleanupMs?: number;
24+
hasCronTool?: boolean;
2425
scopeKey?: string;
2526
};
2627

@@ -116,6 +117,17 @@ function resetPollRetrySuggestion(sessionId: string): void {
116117
}
117118
}
118119

120+
export function describeProcessTool(params?: { hasCronTool?: boolean }): string {
121+
return [
122+
"Manage running exec sessions for commands already started: list, poll, log, write, send-keys, submit, paste, kill.",
123+
params?.hasCronTool
124+
? "Do not use process polling to emulate timers or reminders; use cron for scheduled follow-ups."
125+
: undefined,
126+
]
127+
.filter(Boolean)
128+
.join(" ");
129+
}
130+
119131
export function createProcessTool(
120132
defaults?: ProcessToolDefaults,
121133
// oxlint-disable-next-line typescript/no-explicit-any
@@ -149,8 +161,7 @@ export function createProcessTool(
149161
return {
150162
name: "process",
151163
label: "process",
152-
description:
153-
"Manage running exec sessions: list, poll, log, write, send-keys, submit, paste, kill.",
164+
description: describeProcessTool({ hasCronTool: defaults?.hasCronTool === true }),
154165
parameters: processSchema,
155166
execute: async (_toolCallId, args, _signal, _onUpdate): Promise<AgentToolResult<unknown>> => {
156167
const params = args as {

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,22 @@ const runNotifyNoopCase = async ({ label, notifyOnExitEmptySuccess }: NotifyNoop
410410
expectNotifyNoopEvents(events, notifyOnExitEmptySuccess, label);
411411
};
412412

413+
describe("tool descriptions", () => {
414+
it("adds cron-specific deferred follow-up guidance only when cron is available", () => {
415+
const execWithCron = createTestExecTool({ hasCronTool: true });
416+
const processWithCron = createProcessTool({ hasCronTool: true });
417+
418+
expect(execWithCron.description).toContain(
419+
"Do not use exec sleep or delay loops for reminders or deferred follow-ups; use cron instead.",
420+
);
421+
expect(processWithCron.description).toContain(
422+
"Do not use process polling to emulate timers or reminders; use cron for scheduled follow-ups.",
423+
);
424+
expect(execTool.description).not.toContain("use cron instead");
425+
expect(processTool.description).not.toContain("scheduled follow-ups");
426+
});
427+
});
428+
413429
beforeEach(() => {
414430
callIdCounter = 0;
415431
resetProcessRegistryForTests();

‎src/agents/bash-tools.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ export type {
44
ExecToolDefaults,
55
ExecToolDetails,
66
} from "./bash-tools.exec.js";
7-
export { createExecTool, execTool } from "./bash-tools.exec.js";
7+
export { createExecTool, describeExecTool, execTool } from "./bash-tools.exec.js";
88
export type { ProcessToolDefaults } from "./bash-tools.process.js";
9-
export { createProcessTool, processTool } from "./bash-tools.process.js";
9+
export { createProcessTool, describeProcessTool, processTool } from "./bash-tools.process.js";
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { describe, expect, it } from "vitest";
2+
import { createOpenClawCodingTools } from "./pi-tools.js";
3+
4+
function findToolDescription(toolName: string, senderIsOwner: boolean) {
5+
const tools = createOpenClawCodingTools({ senderIsOwner });
6+
const tool = tools.find((entry) => entry.name === toolName);
7+
return {
8+
toolNames: tools.map((entry) => entry.name),
9+
description: tool?.description ?? "",
10+
};
11+
}
12+
13+
describe("createOpenClawCodingTools deferred follow-up guidance", () => {
14+
it("keeps cron-specific guidance when cron survives filtering", () => {
15+
const exec = findToolDescription("exec", true);
16+
const process = findToolDescription("process", true);
17+
18+
expect(exec.toolNames).toContain("cron");
19+
expect(exec.description).toContain("use cron instead");
20+
expect(process.description).toContain("use cron for scheduled follow-ups");
21+
});
22+
23+
it("drops cron-specific guidance when cron is unavailable", () => {
24+
const exec = findToolDescription("exec", false);
25+
const process = findToolDescription("process", false);
26+
27+
expect(exec.toolNames).not.toContain("cron");
28+
expect(exec.description).not.toContain("use cron instead");
29+
expect(process.description).not.toContain("use cron for scheduled follow-ups");
30+
});
31+
});

‎src/agents/pi-tools.ts‎

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import { createApplyPatchTool } from "./apply-patch.js";
1212
import {
1313
createExecTool,
1414
createProcessTool,
15+
describeExecTool,
16+
describeProcessTool,
1517
type ExecToolDefaults,
1618
type ProcessToolDefaults,
1719
} from "./bash-tools.js";
@@ -123,6 +125,28 @@ function applyModelProviderToolPolicy(
123125
return tools;
124126
}
125127

128+
function applyDeferredFollowupToolDescriptions(
129+
tools: AnyAgentTool[],
130+
params?: { agentId?: string },
131+
): AnyAgentTool[] {
132+
const hasCronTool = tools.some((tool) => tool.name === "cron");
133+
return tools.map((tool) => {
134+
if (tool.name === "exec") {
135+
return {
136+
...tool,
137+
description: describeExecTool({ agentId: params?.agentId, hasCronTool }),
138+
};
139+
}
140+
if (tool.name === "process") {
141+
return {
142+
...tool,
143+
description: describeProcessTool({ hasCronTool }),
144+
};
145+
}
146+
return tool;
147+
});
148+
}
149+
126150
function isApplyPatchAllowedForModel(params: {
127151
modelProvider?: string;
128152
modelId?: string;
@@ -654,9 +678,12 @@ export function createOpenClawCodingTools(options?: {
654678
const withAbort = options?.abortSignal
655679
? withHooks.map((tool) => wrapToolWithAbortSignal(tool, options.abortSignal))
656680
: withHooks;
681+
const withDeferredFollowupDescriptions = applyDeferredFollowupToolDescriptions(withAbort, {
682+
agentId,
683+
});
657684

658685
// NOTE: Keep canonical (lowercase) tool names here.
659686
// pi-ai's Anthropic OAuth transport remaps tool names to Claude Code-style names
660687
// on the wire and maps them back for tool dispatch.
661-
return withAbort;
688+
return withDeferredFollowupDescriptions;
662689
}

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ describe("buildAgentSystemPrompt", () => {
101101
skillsPrompt:
102102
"<available_skills>\n <skill>\n <name>demo</name>\n </skill>\n</available_skills>",
103103
heartbeatPrompt: "ping",
104-
toolNames: ["message", "memory_search"],
104+
toolNames: ["message", "memory_search", "cron"],
105105
docsPath: "/tmp/openclaw/docs",
106106
extraSystemPrompt: "Subagent details",
107107
ttsHint: "Voice (TTS) is enabled.",
@@ -119,7 +119,13 @@ describe("buildAgentSystemPrompt", () => {
119119
expect(prompt).not.toContain("## Heartbeats");
120120
expect(prompt).toContain("## Safety");
121121
expect(prompt).toContain(
122-
"For long waits, avoid rapid poll loops: use exec with enough yieldMs or process(action=poll, timeout=<ms>).",
122+
'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 exec sleep, yieldMs delays, or process polling.',
123+
);
124+
expect(prompt).toContain(
125+
"Use exec/process only for commands that start now and continue running in the background.",
126+
);
127+
expect(prompt).toContain(
128+
"Do not emulate scheduling with sleep loops, timeout loops, or repeated polling.",
123129
);
124130
expect(prompt).toContain("You have no independent goals");
125131
expect(prompt).toContain("Prioritize safety and human oversight");
@@ -287,7 +293,10 @@ describe("buildAgentSystemPrompt", () => {
287293
});
288294

289295
expect(prompt).toContain(
290-
"For long waits, avoid rapid poll loops: use exec with enough yieldMs or process(action=poll, timeout=<ms>).",
296+
'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 exec sleep, yieldMs delays, or process polling.',
297+
);
298+
expect(prompt).toContain(
299+
"Use exec/process only for commands that start now and continue running in the background.",
291300
);
292301
expect(prompt).toContain("Completion is push-based: it will auto-announce when done.");
293302
expect(prompt).toContain("Do not poll `subagents list` / `sessions_list` in a loop");

‎src/agents/system-prompt.ts‎

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,12 @@ export function buildAgentSystemPrompt(params: {
243243
const acpEnabled = params.acpEnabled !== false;
244244
const sandboxedRuntime = params.sandboxInfo?.enabled === true;
245245
const acpSpawnRuntimeEnabled = acpEnabled && !sandboxedRuntime;
246+
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 =
249+
"Manage background exec sessions for commands already started";
250+
const cronToolSummary =
251+
"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)";
246252
const coreToolSummaries: Record<string, string> = {
247253
read: "Read file contents",
248254
write: "Create or overwrite files",
@@ -251,15 +257,15 @@ export function buildAgentSystemPrompt(params: {
251257
grep: "Search file contents for patterns",
252258
find: "Find files by glob pattern",
253259
ls: "List directory contents",
254-
exec: "Run shell commands (pty available for TTY-required CLIs)",
255-
process: "Manage background exec sessions",
260+
exec: execToolSummary,
261+
process: processToolSummary,
256262
web_search: "Search the web",
257263
web_fetch: "Fetch and extract readable content from a URL",
258264
// Channel docking: add login tools here when a channel needs interactive linking.
259265
browser: "Control web browser",
260266
canvas: "Present/eval/snapshot the Canvas",
261267
nodes: "List/describe/notify/camera/screen on paired nodes",
262-
cron: "Manage cron jobs and wake events (use for reminders; 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)",
268+
cron: cronToolSummary,
263269
message: "Send messages and channel actions",
264270
gateway: "Restart, apply config, or run updates on the running OpenClaw process",
265271
agents_list: acpSpawnRuntimeEnabled
@@ -347,7 +353,9 @@ export function buildAgentSystemPrompt(params: {
347353
toolLines.push(summary ? `- ${name}: ${summary}` : `- ${name}`);
348354
}
349355

356+
const usingDefaultToolFallback = toolLines.length === 0;
350357
const hasGateway = availableTools.has("gateway");
358+
const hasCronTool = availableTools.has("cron") || usingDefaultToolFallback;
351359
const readToolName = resolveToolName("read");
352360
const execToolName = resolveToolName("exec");
353361
const processToolName = resolveToolName("process");
@@ -453,20 +461,28 @@ export function buildAgentSystemPrompt(params: {
453461
"- find: find files by glob pattern",
454462
"- ls: list directory contents",
455463
"- apply_patch: apply multi-file patches",
456-
`- ${execToolName}: run shell commands (supports background via yieldMs/background)`,
457-
`- ${processToolName}: manage background exec sessions`,
464+
`- ${execToolName}: ${execToolSummary.toLowerCase()}`,
465+
`- ${processToolName}: ${processToolSummary.toLowerCase()}`,
458466
"- browser: control OpenClaw's dedicated browser",
459467
"- canvas: present/eval/snapshot the Canvas",
460468
"- nodes: list/describe/notify/camera/screen on paired nodes",
461-
"- cron: manage cron jobs and wake events (use for reminders; 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)",
469+
`- cron: ${cronToolSummary.toLowerCase()}`,
462470
"- sessions_list: list sessions",
463471
"- sessions_history: fetch session history",
464472
"- sessions_send: send to another session",
465473
"- subagents: list/steer/kill sub-agent runs",
466474
'- session_status: show usage/time/model state and answer "what model are we using?"',
467475
].join("\n"),
468476
"TOOLS.md does not control tool availability; it is user guidance for how to use external tools.",
469-
`For long waits, avoid rapid poll loops: use ${execToolName} with enough yieldMs or ${processToolName}(action=poll, timeout=<ms>).`,
477+
...(hasCronTool
478+
? [
479+
`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.`,
480+
`Use ${execToolName}/${processToolName} only for commands that start now and continue running in the background.`,
481+
"Do not emulate scheduling with sleep loops, timeout loops, or repeated polling.",
482+
]
483+
: [
484+
`For long waits, avoid rapid poll loops: use ${execToolName} with enough yieldMs or ${processToolName}(action=poll, timeout=<ms>).`,
485+
]),
470486
"If a task is more complex or takes longer, spawn a sub-agent. Completion is push-based: it will auto-announce when done.",
471487
...(acpHarnessSpawnAllowed
472488
? [

0 commit comments

Comments
 (0)