Skip to content

fix(agents): prefer background completion wake over polling - #60877

Merged
vincentkoc merged 8 commits into
openclaw:mainfrom
vincentkoc:codex/background-completion-wake-guidance
Apr 4, 2026
Merged

vincentkoc merged 8 commits into
openclaw:mainfrom
vincentkoc:codex/background-completion-wake-guidance

Conversation

@vincentkoc

Copy link
Copy Markdown
Member

Summary

  • Problem: agent guidance handled delayed follow-ups better after fix(agents): prefer cron for deferred follow-ups #60811, but still did not clearly steer "start this now and tell me when it finishes" toward background exec completion wake.
  • Why it matters: the model can still over-poll process for normal completion handling instead of relying on the existing push-style notify-on-exit path.
  • What changed: tightened system prompt and exec/process descriptions so background-now work prefers automatic completion wake, while process is framed as an inspection/intervention tool.
  • What did NOT change (scope boundary): no scheduler/runtime wiring changes; the existing notify-on-exit + heartbeat wake path is reused as-is.

Change Type (select all)

  • Bug fix
  • Feature
  • Refactor required for the fix
  • Docs
  • Security hardening
  • Chore/infra

Scope (select all touched areas)

  • Gateway / orchestration
  • Skills / tool execution
  • Auth / tokens
  • Memory / storage
  • Integrations
  • API / contracts
  • UI / DX
  • CI/CD / infra

Linked Issue/PR

Root Cause (if applicable)

  • Root cause: prompt and tool-description policy covered future-time scheduling via cron, but not the separate completion-based wake path for background work started now.
  • Missing detection / guardrail: no assertion pinned the emitted prompt/tool text for the automatic completion-wake path.
  • Contributing context (if known): process remained framed heavily around polling, even though exec completion already wakes the agent via system event + heartbeat.

Regression Test Plan (if applicable)

  • Coverage level that should have caught this:
    • Unit test
    • Seam / integration test
    • End-to-end test
    • Existing coverage already sufficient
  • Target test or file: src/agents/system-prompt.test.ts, src/agents/bash-tools.test.ts
  • Scenario the test should lock in: delayed follow-ups prefer cron, but long-running work started now prefers background exec completion wake and treats process as on-demand inspection/intervention.
  • Why this is the smallest reliable guardrail: the regression is in emitted prompt/tool copy, so prompt/description assertions are the direct seam.
  • Existing test that already covers this (if any): none for the completion-wake guidance.
  • If no new test is added, why not: N/A

User-visible / Behavior Changes

Agents should now be more likely to:

  • use cron for future-time follow-ups,
  • use background exec for work that starts now,
  • rely on automatic completion wake by default,
  • use process mainly for logs, status, input, or intervention.

Diagram (if applicable)

Before:
[user says "start this now and tell me when it finishes"] -> [agent sees exec/process] -> [agent may poll process repeatedly]

After:
[user says "start this now and tell me when it finishes"] -> [agent starts background exec] -> [runtime completion wake] -> [agent updates user]

Security Impact (required)

  • New permissions/capabilities? (No)
  • Secrets/tokens handling changed? (No)
  • New/changed network calls? (No)
  • Command/tool execution surface changed? (No)
  • Data access scope changed? (No)
  • If any Yes, explain risk + mitigation:

Repro + Verification

Environment

  • OS: macOS
  • Runtime/container: local Codex worktree
  • Model/provider: N/A
  • Integration/channel (if any): N/A
  • Relevant config (redacted): default local dev config

Steps

  1. Build agent prompt/tool descriptions with exec, process, and optionally cron enabled.
  2. Inspect the emitted guidance for delayed follow-ups vs long-running background-now work.
  3. Verify that completion-wake guidance is present and polling is framed as on-demand inspection.

Expected

  • Background-now work prefers automatic completion wake; delayed follow-ups prefer cron.

Actual

  • With this patch, the emitted prompt and tool descriptions now reflect that split.

Evidence

Attach at least one:

  • Failing test/log before + passing after
  • Trace/log snippets
  • Screenshot/recording
  • Perf numbers (if relevant)

Human Verification (required)

  • Verified scenarios: git diff --check; direct bun -e assertions for cron-enabled prompt guidance, no-cron fallback guidance, and exec/process descriptions.
  • Edge cases checked: both cron-present and cron-absent tool sets still emit the completion-wake guidance.
  • What you did not verify: focused pnpm test -- ... runs for src/agents/system-prompt.test.ts and src/agents/bash-tools.test.ts started Vitest but did not return a clean pass/fail signal in this environment.

Review Conversations

  • I replied to or resolved every bot review conversation I addressed in this PR.
  • I left unresolved only the conversations that still need reviewer or maintainer judgment.

Compatibility / Migration

  • Backward compatible? (Yes)
  • Config/env changes? (No)
  • Migration needed? (No)
  • If yes, exact upgrade steps:

Risks and Mitigations

  • Risk: stronger copy may bias agents slightly away from process poll even when a user explicitly wants active monitoring.
    • Mitigation: the prompt and tool descriptions still preserve process for logs, status, input, and intervention; only the default path changes.

@vincentkoc vincentkoc self-assigned this Apr 4, 2026
@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: XS maintainer Maintainer-authored PR labels Apr 4, 2026
@vincentkoc
vincentkoc marked this pull request as ready for review April 4, 2026 13:37

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5336e9d3ba

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/agents/system-prompt.ts Resolved
@greptile-apps

greptile-apps Bot commented Apr 4, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR tightens exec/process tool descriptions and the agent system prompt to steer "start now, tell me when done" work toward the existing automatic completion-wake path instead of repeated process polling. Changes are purely prompt/description copy — no scheduler or runtime wiring is touched.

The only gap worth noting: bash-tools.test.ts correctly covers the no-cron tool-description path, but both system-prompt tests that assert completion-wake text resolve hasCronTool = true (no explicit cron-absent toolNames case), leaving the new else-branch in system-prompt.ts (lines 484–487) untested there.

Confidence Score: 5/5

Safe to merge — changes are prompt/description copy only with no runtime behavior changes.

All findings are P2 (style/test-coverage gap). The code changes are correct, additive, and low-risk. Both cron and no-cron paths emit the completion-wake guidance as intended; the only gap is a missing explicit system-prompt test for the no-cron else-branch.

src/agents/system-prompt.test.ts — consider adding a no-cron toolNames test case to cover the else-branch added in system-prompt.ts.

Comments Outside Diff (1)

  1. src/agents/system-prompt.test.ts, line 293-312 (link)

    P2 No-cron branch in system-prompt.ts is untested

    The PR description states "both cron-present and cron-absent tool sets still emit the completion-wake guidance," but every system-prompt test that asserts the completion-wake text hits the cron-enabled path. When toolNames is omitted, hasCronTool resolves to true via usingDefaultToolFallback (see system-prompt.ts:358), so the else-branch added by this PR (the toolNames case that explicitly excludes cron) is never exercised here.

    bash-tools.test.ts does cover the no-cron tool-description case, but a matching assertion in system-prompt.test.ts would close the gap cleanly:

    it("emits completion-wake guidance without cron in tool list", () => {
      const prompt = buildAgentSystemPrompt({
        workspaceDir: "/tmp/openclaw",
        toolNames: ["exec", "process"],
      });
    
      expect(prompt).toContain(
        "For long-running work that starts now, start it once and rely on automatic completion wake by default",
      );
      expect(prompt).not.toContain("use cron instead");
    });
    Prompt To Fix With AI
    This is a comment left during a code review.
    Path: src/agents/system-prompt.test.ts
    Line: 293-312
    
    Comment:
    **No-cron branch in `system-prompt.ts` is untested**
    
    The PR description states "both cron-present and cron-absent tool sets still emit the completion-wake guidance," but every system-prompt test that asserts the completion-wake text hits the cron-enabled path. When `toolNames` is omitted, `hasCronTool` resolves to `true` via `usingDefaultToolFallback` (see `system-prompt.ts:358`), so the else-branch added by this PR (the `toolNames` case that explicitly excludes `cron`) is never exercised here.
    
    `bash-tools.test.ts` does cover the no-cron tool-description case, but a matching assertion in `system-prompt.test.ts` would close the gap cleanly:
    
    ```ts
    it("emits completion-wake guidance without cron in tool list", () => {
      const prompt = buildAgentSystemPrompt({
        workspaceDir: "/tmp/openclaw",
        toolNames: ["exec", "process"],
      });
    
      expect(prompt).toContain(
        "For long-running work that starts now, start it once and rely on automatic completion wake by default",
      );
      expect(prompt).not.toContain("use cron instead");
    });
    ```
    
    How can I resolve this? If you propose a fix, please make it concise.
Prompt To Fix All With AI
This is a comment left during a code review.
Path: src/agents/system-prompt.test.ts
Line: 293-312

Comment:
**No-cron branch in `system-prompt.ts` is untested**

The PR description states "both cron-present and cron-absent tool sets still emit the completion-wake guidance," but every system-prompt test that asserts the completion-wake text hits the cron-enabled path. When `toolNames` is omitted, `hasCronTool` resolves to `true` via `usingDefaultToolFallback` (see `system-prompt.ts:358`), so the else-branch added by this PR (the `toolNames` case that explicitly excludes `cron`) is never exercised here.

`bash-tools.test.ts` does cover the no-cron tool-description case, but a matching assertion in `system-prompt.test.ts` would close the gap cleanly:

```ts
it("emits completion-wake guidance without cron in tool list", () => {
  const prompt = buildAgentSystemPrompt({
    workspaceDir: "/tmp/openclaw",
    toolNames: ["exec", "process"],
  });

  expect(prompt).toContain(
    "For long-running work that starts now, start it once and rely on automatic completion wake by default",
  );
  expect(prompt).not.toContain("use cron instead");
});
```

How can I resolve this? If you propose a fix, please make it concise.

Reviews (1): Last reviewed commit: "Merge branch 'main' into codex/backgroun..." | Re-trigger Greptile

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 85640e9c20

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/agents/system-prompt.ts Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3012b0c5e2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/agents/bash-tools.process.ts Resolved
@vincentkoc
vincentkoc merged commit 6f2e804 into openclaw:main Apr 4, 2026
9 checks passed

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a1b6424edf

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

const processToolSummary = "Manage background exec sessions for commands already started";
"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)";
const processToolSummary =
"Manage background exec sessions for commands already started (poll/log for inspection, debugging, input, intervention, or completion confirmation when auto-wake is unavailable)";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Fix process summary to map poll/log to correct actions

The updated processToolSummary describes poll/log as tools for “input” and “intervention,” but those capabilities are handled by other process actions (write, send-keys, submit, paste, kill) rather than poll/log. In interactive sessions that block on stdin, this wording can steer the model toward repeated polling instead of sending input, leaving commands stuck and delaying user updates. Please align this summary with the actual action semantics so poll/log are framed as inspection/status only.

Useful? React with 👍 / 👎.

lovewanwan pushed a commit to lovewanwan/openclaw that referenced this pull request Apr 28, 2026
…#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
ogt-redknie pushed a commit to ogt-redknie/OPENX that referenced this pull request May 2, 2026
…#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
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 24, 2026
…#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
Nachx639 pushed a commit to Nachx639/clawdbot that referenced this pull request Jun 17, 2026
…#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
vixco pushed a commit to vixco/openclaw that referenced this pull request Aug 16, 2026
…#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
globalcaos pushed a commit to globalcaos/tinkerclaw that referenced this pull request Sep 29, 2026
…#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
lhfer pushed a commit to lhfer/openclaw that referenced this pull request Oct 11, 2026
…#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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling maintainer Maintainer-authored PR size: XS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant