Repository navigation
Add wait mode for manual cron runs - #81929
Conversation
|
Codex review: needs changes before merge. Summary Reproducibility: not applicable. this is an additive feature PR, not a broken existing behavior report. Source inspection confirms current main lacks the wait/run-id filter surfaces, and the PR body supplies live after-fix Gateway output for the intended behavior. Real behavior proof Next step before merge Security Review findings
Review detailsBest possible solution: Fix the wait-loop timeout bound, then land after maintainer approval and green CI while preserving the non-blocking Do we have a high-confidence way to reproduce the issue? Not applicable: this is an additive feature PR, not a broken existing behavior report. Source inspection confirms current main lacks the wait/run-id filter surfaces, and the PR body supplies live after-fix Gateway output for the intended behavior. Is this the best way to solve the issue? No: polling Full review comments:
Overall correctness: patch is incorrect Acceptance criteria:
What I checked:
Likely related people:
Remaining risk / open question:
Codex review notes: model gpt-5.5, reasoning high; reviewed against aa6ea4510ca9. Re-review progress:
|
This comment was marked as low quality.
This comment was marked as low quality.
bb8dd9b to
bb923dc
Compare
bb923dc to
333f376
Compare
Add an opt-in wait mode for manual cron runs that polls the exact run id until the run log records a terminal status. Document the new CLI behavior and sync protocol schema consumers. Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
333f376 to
99d1303
Compare
|
Maintainer verification for landing:
Commands run after the maintainer rebase/docs update: git diff --check upstream/main...HEAD
node scripts/check-changelog-attributions.mjs CHANGELOG.md
pnpm docs:list
node scripts/run-vitest.mjs src/cli/cron-cli.test.ts src/cron/run-log.test.ts src/gateway/protocol/cron-validators.test.ts src/gateway/protocol/native-protocol-levels.guard.test.ts
pnpm check:test-types
CRABBOX_AZURE_NETWORK=private CRABBOX_ID=quick-barnacle /home/galini/.codex/skills/crabbox-oc-evidence/scripts/collect-openclaw-evidence.sh --name pr-81929-check-test-types --command 'pnpm check:test-types'Focused Vitest result: 6 files, 116 tests passed. No known proof gaps for the changed cron CLI/run-log/protocol/docs surface. |
Adds wait mode for manual cron runs, exact run-id lookup for cron run logs, protocol/Swift schema support, and docs/changelog coverage.
Adds wait mode for manual cron runs, exact run-id lookup for cron run logs, protocol/Swift schema support, and docs/changelog coverage.
Adds wait mode for manual cron runs, exact run-id lookup for cron run logs, protocol/Swift schema support, and docs/changelog coverage.
Adds wait mode for manual cron runs, exact run-id lookup for cron run logs, protocol/Swift schema support, and docs/changelog coverage.
…call (#162481) ## What Problem This Solves Fixes: when an agent runs an automation with `automations run`, the call returns as soon as the run is queued, so the model never learns whether the run worked. It then posts guesses, or schedules a separate "verify" job. That job runs with only its own scope, can't see the result, and reports a false "blocked". ## User Impact User impact: when an agent runs an automation, it gets the finished run (status, error, delivery status and summary) in the same tool result if the run ends within the call's `timeoutMs` (default 60 s, capped at 10 min). A longer run returns its `runId` and a note to check it later with `runs jobId runId`, not with a scheduled check. The CLI is unchanged. ## Why This Change Was Made `cron.run` became enqueue-only in #40204 (closing #40192). Back then a synchronous run held the RPC until the 60 s gateway timeout and returned a misleading timeout error while the job kept running. #81929 later added `openclaw cron run --wait`, polling `cron.runs` from the client, and deliberately kept `cron.run` from holding the request open. The agent tool never got a wait at all. A client-side poller would not work for the tool anyway: management-grant turns can run a job, but `cron.runs` is not one of their allowed methods. This PR keeps that invariant (no unbounded request, no false failure) and gives the one owner of run completion a bounded, opt-in wait: - The cron service records each accepted manual run's settlement. `waitForManualRun(runId, timeoutMs, signal)` resolves when the run has written its history row. It is event-driven, with no polling. - `cron.run` accepts an optional `waitTimeoutMs`. When the run finishes in time, the ack also carries `run`, read through the existing `cron.runs` handler so the same visibility and authority rules apply. When the wait ends first, the ack is unchanged and the run continues. - When an agent turn runs a main-session job, or a `session:<key>` job in its own session, the call returns at once. The caller's turn holds the main lane and its own session lane: heartbeats skip while `CommandLane.Main` is busy, and a main-session run waits up to 2 min for that busy turn. Waiting there would only burn the budget. - The `automations` tool's `run` passes its `timeoutMs` as the wait. `runs` now forwards `runId`. The tool descriptions now steer models away from verify jobs. Against a shipped Gateway, which rejects the new param before enqueueing, the tool retries the plain call once, the same way it already does for `compact` on `cron.list`. - Accepted runs stay accepted, and outcomes go only to callers that may still read them. After the history read, the handler rechecks read authority (caller authority, agent runtime and any management grant), with no await between that check and the response. If the read or the recheck is refused, for example because a delegated grant lapsed or was revoked during a long wait, the caller gets the plain ack and nothing about the outcome. If the run finished but its history is not visible (for example a one-shot that deleted itself after succeeding), the ack carries `finished: true`. Management-only turns are pointed to the Automations page instead of `runs`. The CLI keeps its client-side `--wait` polling in this PR. Moving it onto the Gateway wait is a separate, compatibility-reviewed follow-up. ## Evidence - Real isolated Gateway, real Telegram plugin on the Crabline synthetic Bot API, and a deterministic Responses provider. An owner DM turn calls the `automations` tool (throwaway harness, not committed). - Before (origin/main build): every `run` returned only `{ ok, enqueued, runId, processInstanceId }` in under 1 s, with no outcome. The report still reached the chat, so the model couldn't tell the run had succeeded. - After: the isolated job's `run` returned in 4.3 s with `run { status: "ok", completionStatus: "succeeded", deliveryStatus: "delivered", summary: "FAST-REPORT-DELIVERED" }`, and the report reached the chat. A slow job (8 s, called with `timeoutMs: 2000`) returned after 2.6 s with its `runId` and the `runs jobId runId` note. The run kept going and delivered, and a later `runs` call with that `runId` returned the single finished entry. A main-session job run from the owner's main-session DM returned in 0.6 s with the note instead of blocking the turn. - Gateway regression (`src/gateway/server.cron.test.ts`): `waitTimeoutMs: 50` returns only the `runId` while the run is blocked. `waitTimeoutMs: 10000` returns `run { runId, status: "ok", completionStatus: "succeeded", summary }`. On origin/main this fails because the closed schema rejects `waitTimeoutMs`. - Same-session skip (`cron.validation.test.ts`): from an agent turn, `main` and `session:<own key>` jobs return the plain ack without waiting. `isolated` jobs wait. - Authority chain (`cron.validation.test.ts`, through the real `cron.run` and `cron.runs` handlers with a stored run record): a caller that is still authorized gets `run { runId, status: "ok" }`. A caller revoked during the history read gets only the accepted ack. Before this change the revoked case turned into a request error. - Tool (`cron-tool.test.ts`): the wait is capped at 10 min, and the RPC timeout is the wait plus 60 s. An unfinished run gets the `runs jobId runId` note. - Tool contract (`cron-tool.output-contract.test.ts`): a shipped Gateway that rejects `waitTimeoutMs` still enqueues through a single retry, and the result stays valid against the output schema. The `run` output type only declares the outcome fields, so the generated code-mode declarations stay within their size allowance. - Measured local wall times on head `cf942df0601` (one `node scripts/run-vitest.mjs <file>` per file; wrapper wall / Vitest duration): `cron-tool.output-contract` 5 tests, 24s / 7.0s; `cron-tool` 72 tests, 19s / 16.2s; `server-cron-lazy` 25 tests, 21s / 17.6s; `cron.validation` 261 tests, 24s / 21.4s; `server.cron` 17 tests, 46s / 43.8s. There are no CI seconds yet: CI skips the test jobs while the PR is a draft, and the only job that ran, "PR context and evidence", passed in 38s. - `pnpm tsgo:core` is clean. Targeted tests pass: `server.cron`, `cron.validation`, `cron-tool`, `server-cron-lazy`. ### Bounded cost - The wait is bounded by `timeoutMs` (default 60 s, capped at 10 min in the tool) and ends early if the caller aborts. The `cron.run` RPC timeout is the wait plus a 60 s enqueue budget, so the response always arrives before the client gives up. - No new model calls or job runs. The waiter only watches a run that was already accepted. It does not retry, re-run or alert. - No nested waits. Automation-run sessions are limited to self status/list/get/runs/remove, so a job's run cannot call `run`. A job running itself gets `already-running`. Main-session and same-session runs, which can only start after the caller's turn, skip the wait. ### Hermes Hermes `cronjob(action="run")` sends the job to its async-delegation pool and returns a handle with "Do not wait or poll". The outcome comes back into the conversation as a new turn, and Hermes runs the job inline when no session can receive it. This PR borrows "the tool owns the follow-up, so the model doesn't poll". Feeding completions back into the conversation is not done here: OpenClaw already delivers run output to the job's target. It's a possible follow-up for long runs. LOC (commit): production about +125/-12, tests about +96, docs +3. Co-authored-by: Ayaan Zaidi <[email protected]>
…call (openclaw#162481) ## What Problem This Solves Fixes: when an agent runs an automation with `automations run`, the call returns as soon as the run is queued, so the model never learns whether the run worked. It then posts guesses, or schedules a separate "verify" job. That job runs with only its own scope, can't see the result, and reports a false "blocked". ## User Impact User impact: when an agent runs an automation, it gets the finished run (status, error, delivery status and summary) in the same tool result if the run ends within the call's `timeoutMs` (default 60 s, capped at 10 min). A longer run returns its `runId` and a note to check it later with `runs jobId runId`, not with a scheduled check. The CLI is unchanged. ## Why This Change Was Made `cron.run` became enqueue-only in openclaw#40204 (closing openclaw#40192). Back then a synchronous run held the RPC until the 60 s gateway timeout and returned a misleading timeout error while the job kept running. openclaw#81929 later added `openclaw cron run --wait`, polling `cron.runs` from the client, and deliberately kept `cron.run` from holding the request open. The agent tool never got a wait at all. A client-side poller would not work for the tool anyway: management-grant turns can run a job, but `cron.runs` is not one of their allowed methods. This PR keeps that invariant (no unbounded request, no false failure) and gives the one owner of run completion a bounded, opt-in wait: - The cron service records each accepted manual run's settlement. `waitForManualRun(runId, timeoutMs, signal)` resolves when the run has written its history row. It is event-driven, with no polling. - `cron.run` accepts an optional `waitTimeoutMs`. When the run finishes in time, the ack also carries `run`, read through the existing `cron.runs` handler so the same visibility and authority rules apply. When the wait ends first, the ack is unchanged and the run continues. - When an agent turn runs a main-session job, or a `session:<key>` job in its own session, the call returns at once. The caller's turn holds the main lane and its own session lane: heartbeats skip while `CommandLane.Main` is busy, and a main-session run waits up to 2 min for that busy turn. Waiting there would only burn the budget. - The `automations` tool's `run` passes its `timeoutMs` as the wait. `runs` now forwards `runId`. The tool descriptions now steer models away from verify jobs. Against a shipped Gateway, which rejects the new param before enqueueing, the tool retries the plain call once, the same way it already does for `compact` on `cron.list`. - Accepted runs stay accepted, and outcomes go only to callers that may still read them. After the history read, the handler rechecks read authority (caller authority, agent runtime and any management grant), with no await between that check and the response. If the read or the recheck is refused, for example because a delegated grant lapsed or was revoked during a long wait, the caller gets the plain ack and nothing about the outcome. If the run finished but its history is not visible (for example a one-shot that deleted itself after succeeding), the ack carries `finished: true`. Management-only turns are pointed to the Automations page instead of `runs`. The CLI keeps its client-side `--wait` polling in this PR. Moving it onto the Gateway wait is a separate, compatibility-reviewed follow-up. ## Evidence - Real isolated Gateway, real Telegram plugin on the Crabline synthetic Bot API, and a deterministic Responses provider. An owner DM turn calls the `automations` tool (throwaway harness, not committed). - Before (origin/main build): every `run` returned only `{ ok, enqueued, runId, processInstanceId }` in under 1 s, with no outcome. The report still reached the chat, so the model couldn't tell the run had succeeded. - After: the isolated job's `run` returned in 4.3 s with `run { status: "ok", completionStatus: "succeeded", deliveryStatus: "delivered", summary: "FAST-REPORT-DELIVERED" }`, and the report reached the chat. A slow job (8 s, called with `timeoutMs: 2000`) returned after 2.6 s with its `runId` and the `runs jobId runId` note. The run kept going and delivered, and a later `runs` call with that `runId` returned the single finished entry. A main-session job run from the owner's main-session DM returned in 0.6 s with the note instead of blocking the turn. - Gateway regression (`src/gateway/server.cron.test.ts`): `waitTimeoutMs: 50` returns only the `runId` while the run is blocked. `waitTimeoutMs: 10000` returns `run { runId, status: "ok", completionStatus: "succeeded", summary }`. On origin/main this fails because the closed schema rejects `waitTimeoutMs`. - Same-session skip (`cron.validation.test.ts`): from an agent turn, `main` and `session:<own key>` jobs return the plain ack without waiting. `isolated` jobs wait. - Authority chain (`cron.validation.test.ts`, through the real `cron.run` and `cron.runs` handlers with a stored run record): a caller that is still authorized gets `run { runId, status: "ok" }`. A caller revoked during the history read gets only the accepted ack. Before this change the revoked case turned into a request error. - Tool (`cron-tool.test.ts`): the wait is capped at 10 min, and the RPC timeout is the wait plus 60 s. An unfinished run gets the `runs jobId runId` note. - Tool contract (`cron-tool.output-contract.test.ts`): a shipped Gateway that rejects `waitTimeoutMs` still enqueues through a single retry, and the result stays valid against the output schema. The `run` output type only declares the outcome fields, so the generated code-mode declarations stay within their size allowance. - Measured local wall times on head `cf942df0601` (one `node scripts/run-vitest.mjs <file>` per file; wrapper wall / Vitest duration): `cron-tool.output-contract` 5 tests, 24s / 7.0s; `cron-tool` 72 tests, 19s / 16.2s; `server-cron-lazy` 25 tests, 21s / 17.6s; `cron.validation` 261 tests, 24s / 21.4s; `server.cron` 17 tests, 46s / 43.8s. There are no CI seconds yet: CI skips the test jobs while the PR is a draft, and the only job that ran, "PR context and evidence", passed in 38s. - `pnpm tsgo:core` is clean. Targeted tests pass: `server.cron`, `cron.validation`, `cron-tool`, `server-cron-lazy`. ### Bounded cost - The wait is bounded by `timeoutMs` (default 60 s, capped at 10 min in the tool) and ends early if the caller aborts. The `cron.run` RPC timeout is the wait plus a 60 s enqueue budget, so the response always arrives before the client gives up. - No new model calls or job runs. The waiter only watches a run that was already accepted. It does not retry, re-run or alert. - No nested waits. Automation-run sessions are limited to self status/list/get/runs/remove, so a job's run cannot call `run`. A job running itself gets `already-running`. Main-session and same-session runs, which can only start after the caller's turn, skip the wait. ### Hermes Hermes `cronjob(action="run")` sends the job to its async-delegation pool and returns a handle with "Do not wait or poll". The outcome comes back into the conversation as a new turn, and Hermes runs the job inline when no session can receive it. This PR borrows "the tool owns the follow-up, so the model doesn't poll". Feeding completions back into the conversation is not done here: OpenClaw already delivers run output to the job's target. It's a possible follow-up for long runs. LOC (commit): production about +125/-12, tests about +96, docs +3. Co-authored-by: Ayaan Zaidi <[email protected]>
Summary
openclaw cron run <job-id>returned after enqueueing a manual run, so shutdown/pre-stop automation could not directly wait for the cron work to finish.openclaw cron run --wait, configurable--wait-timeoutand--poll-interval, exactrunIdfiltering forcron.runs, protocol/schema wiring, generated Swift protocol sync, focused tests, and docs.openclaw cron run <job-id>behavior remains non-blocking; the Gatewaycron.runRPC still enqueues rather than holding the request open; no cron scheduler semantics changed.Change Type (select all)
Scope (select all touched areas)
Linked Issue/PR
Real behavior proof (required for external PRs)
openclaw cron run <job-id> --waitwaits for the returned manual runrunIdto finish, returnscompleted: true, reports the terminal status, and exits successfully only forok.openclaw cron runs --run-idcan retrieve the exact completed run.node:24-bookworm, repository copied into a Linux volume, isolatedOPENCLAW_STATE_DIR, real OpenClaw Gateway on loopback with token auth, and CLI commands run throughcorepack pnpm openclawagainst that Gateway. Token value below is redacted.openclaw gateway run --dev --reset --port 18789 --bind loopback --auth token --token [redacted-test-token], created a real system-event cron job withopenclaw cron add --token [redacted-test-token] --name "wait proof" --every 1h --system-event "cron wait proof" --json, ranopenclaw cron run <job-id> --token [redacted-test-token] --wait --wait-timeout 30s --poll-interval 500ms, then queriedopenclaw cron runs --token [redacted-test-token] --id <job-id> --run-id <run-id> --limit 1.cron run --waitreturned the manualrunId, blocked until the run log entry reached terminal statusok, returnedcompleted: true, exited withexit_code=0, andcron runs --run-idreturned exactly one matching finished entry.{ ok: true, enqueued: true, runId }immediately fromenqueueRun, leaving wrappers to poll run history manually.Root Cause (if applicable)
runId, but the CLI did not provide a first-party wait mode or exact-run history filter.Regression Test Plan (if applicable)
src/cli/cron-cli.test.ts,src/cron/run-log.test.ts,src/gateway/protocol/cron-validators.test.ts,src/gateway/protocol/native-protocol-levels.guard.test.ts.--waitpolls the exactrunId, exits0forok, exits non-zero forerrorandskipped, and protocol/run-log filtering accepts and appliesrunId.User-visible / Behavior Changes
openclaw cron run <job-id>remains non-blocking by default. Users can now pass--wait,--wait-timeout <duration>, and--poll-interval <duration>to block until the queued manual run completes.openclaw cron runs --id <job-id> --run-id <run-id>filters run history to one exact run.Diagram (if applicable)
Security Impact (required)
Yes/No) NoYes/No) NoYes/No) NoYes/No) NoYes/No) NoYes, explain risk + mitigation: N/ARepro + Verification
Environment
node:24-bookworm, Node v24.15.0, pnpm 11.1.0 through CorepackOPENCLAW_STATE_DIR; test token redacted in evidenceSteps
cron add,cron run --wait, andcron runs --run-idagainst it.Expected
--waitpolls the exact returned run id and maps terminal statuses to the documented exit codes.cron.runsaccepts and filters byrunId.runId, terminal status, and exit code.Actual
runId, terminal statusok,completed: true,exit_code=0, and exactcron runs --run-idhistory lookup.Evidence
Attach at least one:
Human Verification (required)
What you personally verified (not just CI), and how:
ok,error, andskippedterminal statuses forcron run --wait; exactrunIdfiltering in cron run-log pages; protocol validator acceptance/rejection; generated Swift model includesrunId; docs cover new CLI usage; real Gateway cron wait path returnscompleted: true, statusok, and exit code0.runIdvalidation, non-okterminal statuses exiting non-zero, default non-wait behavior remaining unchanged.Review Conversations
Compatibility / Migration
Yes/No) YesYes/No) NoYes/No) NoRisks and Mitigations
--waitcould hang longer than expected if a run never records a terminal log entry.--wait-timeoutdefaults to a bounded duration and exits non-zero on timeout.cron.runsnow supports exactrunIdfiltering and--waituses it.