Repository navigation
feat(cron): on-exit schedule β wake on a watched command's exit - #92037
Conversation
|
@clawsweeper review New PR (not a stack β builds on merged #83738). Adds an Highlights:
|
|
π¦π§Ή I asked ClawSweeper to review this item again. Re-review progress:
|
|
@clawsweeper re-review |
|
π¦π Command router queued. I will update this comment with the next step. |
|
Codex review: needs maintainer review before merge. Reviewed July 1, 2026, 1:30 PM ET / 17:30 UTC. Summary PR surface: Source +552, Tests +1043, Docs +29, Other +200. Total +1824 across 45 files. Reproducibility: not applicable. as a bug reproduction; this is a new cron trigger capability. Current main source proves Review metrics: 2 noteworthy metrics.
Stored data model Merge readiness Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Risk before merge
Maintainer options:
Next step before merge
Security Review detailsBest possible solution: Land only after maintainers explicitly accept the gateway-level command authority and persisted schedule-kind upgrade contract, or require a redesign through shared execution policy and versioned cron storage before merge. Do we have a high-confidence way to reproduce the issue? Not applicable as a bug reproduction; this is a new cron trigger capability. Current main source proves Is this the best way to solve the issue? Unclear until maintainer acceptance; the gateway ProcessSupervisor is a plausible owner for a watcher that must survive turn teardown, but the execution-policy and downgrade contracts are product/security decisions. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 4895a00b94f0. Label changesLabel changes:
Label justifications:
Evidence reviewedPR surface: Source +552, Tests +1043, Docs +29, Other +200. Total +1824 across 45 files. View PR surface stats
Security concerns:
What I checked:
Likely related people:
What the crustacean ranks mean
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics. How this review workflow works
|
|
@clawsweeper re-review Addressed the [P1] (restart replay). Pushed On the second [P1] (durable gateway-level arbitrary-shell authority): that's inherent to the feature and a maintainer-acceptance call β the watched command is exactly what the agent could already run via its exec tool; on-exit just relocates it to the gateway supervisor so it survives turn teardown. Flagging it explicitly for owner sign-off rather than narrowing, same as #83738's compatibility note. |
|
π¦π§Ή I asked ClawSweeper to review this item again. |
|
@clawsweeper re-review Addressed all three lifecycle [P1]s (
New tests cover all three: persist-failure β no fire, command-change β cancel+re-arm, in-flight-spawn removal β orphan killed + no fire. Watcher suite 40 green; lint + test-types clean. On the two [P2]/ownership notes (second persistent command-execution model alongside cron command payloads; upgrade/rollback semantics for the new schedule kind on older releases): those are product/security ownership decisions, flagged for maintainer sign-off rather than narrowed here β same posture as #83738's compatibility note. |
|
π¦π§Ή I asked ClawSweeper to review this item again. Re-review progress:
|
|
I think the fix would involve adjusting ui. Would that work for your use case? |
could you please elaborate? |
|
@clawsweeper re-review |
2 similar comments
|
@clawsweeper re-review |
|
@clawsweeper re-review |
|
π¦π§Ή I asked ClawSweeper to review this item again. |
|
@clawsweeper re-review |
1 similar comment
|
@clawsweeper re-review |
|
π¦π§Ή I asked ClawSweeper to review this item again. |
|
@clawsweeper re-review |
|
π¦π§Ή I asked ClawSweeper to review this item again. |
β¦mmand exits Adds an `on-exit` cron schedule kind: a job fires once when a watched command/process exits, via gateway ProcessSupervisor exit watchers. Covers CLI (`--on-exit`/`--on-exit-cwd`), tool/protocol schema, RPC list-filter, Control UI + macOS read-only display, SQLite round-trip, and origin-aware wake routing. Restart-safe one-shot (persists completion before firing); platform-aware shell; bounded watched-command execution. Squashed from 22 iterative commits for a clean rebase onto current main.
Summary
Adds an
on-exitcron schedule kind: a job that fires once when a watched shell command exits, starting a fresh agent turn in the originating conversation. It's "a #83738 cron wake, triggered by a process exit instead of by the tool call" β it reuses the merged origin-aware wake as its delivery mechanism and only adds the trigger.task_completioninternal events consumed by the embedded-agent runtime. But nothing watches an arbitrary external command, and the CLI backends can't participate in that internal system at all: a command aclaude-cliagent runs via its exec tool lives inside the per-turn process tree that'ssignalProcessTree(SIGTERMβSIGKILL)'d at turn end (claude-cli provider: session abort triggers gateway-wide SIGTERM (v2026.4.23)Β #71662), so it dies before it can observe an exit or fire a wake. The only pre-existing workaround is a pollingevery:Nmcron that burns a turn per poll.CronSchedulekind{ kind: "on-exit", command, cwd? }, executed by a gateway-ProcessSupervisor-owned watcher (cron-exit-watchers.ts). The watcher runs the command as a child of the gateway supervisor β outside any agent turn's process tree β so it survives turn teardown by construction. On exit it fires fix(cron): capture originating session/agent on the cron wake tool callΒ #83738's origin-aware wake on the job's captured session, so the woken turn continues the originating conversation (nativeclaude-cli --resume, see proof), with the exit code folded into the woken turn's text. One-shot per arm.on-exitis accepted by the protocol schema, the cron tool (schedule.kind:"on-exit"+command/cwd), and the CLI (cron add --on-exit <shell> [--on-exit-cwd <path>]). Watchers arm on job add/update and on gateway-startup reconcile (so persisted jobs re-arm after a restart) and cancel on remove/disable/shutdown.Why a non-internally-managed wake (and why it works for every backend)
The internal
task_completionmachinery is embedded-runtime-bound and command-agnostic β it has no "watch a shell command" task type, for any backend. Aclaude-cli(orclaude-cli-interactive/proxy) agent can't register an external command with it, and a command it runs inline dies at turn teardown. So the watcher must live outside the turn and outside the embedded-agent event system β the gateway ProcessSupervisor. Because the wake then rides the gateway command lane (busy-detection isgetQueueSize(Main), acquired at the dispatch layer above the backend), it behaves identically on plainclaude-cliand the interactive MITM backend: if the watched command exits mid-turn, the wake hitsrequests-in-flight, re-queues, and fires when the lane frees β never concurrently. Proven below on plainclaude-cli; the interactive path is the same lane mechanism.Real behavior proof
Real OpenClaw gateway (built from this branch) + real
claude-cli(claude-sonnet-4-6) backend with native session resume (resumeArgs), in a Linux container. A persistedon-exitjob (command: "sleep 22") is loaded at gateway startup; a binding turn establishes the session; the watched command exits; the watcher fires the origin wake. Gateway logs (gw-clean.log, cron-exit-structured.log):The wake turn ran after the binding turn finished, so it is unambiguously the on-exit wake β and it natively
--resumed the binding turn's claude-cli session, continuing the conversation. A separate run also exercised the mid-turn case: the watched command exited while a turn was in flight, the wake hitrequests-in-flight, re-queued, and the woken turn ran after the in-flight turn ended (never concurrently).claude-cli) cannot reliably arm "wake me when this external command exits" β managedtask_completiondoesn't cover external commands and an agent-spawned command dies at turn teardown.claude-clibackend withresumeArgs, Linux container; on-exit job persisted to the store and armed at startup.on-exitjob (sleep 22, sessionKey bound), start the gateway, run a binding turn, let the command exit.--resumed the originating session.Bug caught by the live proof
getInvalidPersistedCronJobReasononly allowedat/every/cron, so on-exit jobs failed persistence validation β they couldn't be saved to the store or survive a restart (the watcher arms from the store at startup). Fixed + regression test. This is exactly the class of issue unit tests around the schema/codec missed and the live store-seed proof surfaced.Limitations & maintainer notes
OPENCLAW_CLIenv marker β consistent with how croncommand-payload jobs run (runCommandWithTimeout). It does not apply the fulltools.execpolicy (host approvals, sandbox selection, unsafe-command guards, script preflight); neither do cron command-payload jobs. Unifying an approvals/sandbox policy across both gateway-level command-execution paths is a cross-cutting product/security decision flagged for maintainer ownership, not narrowed here.on-exitis a new schedule kind. A rollback to a release predating it will not decode these rows (older code filters unknown schedule kinds on load), and a later cron write can drop them β inherent to introducing any new schedule kind. Treat on-exit jobs as not downgrade-preserved until a versioned-store strategy lands.Tests / CI
cron-exit-watchers.test.ts(arm/fire-on-exit/skip-timer-and-disabled/idempotent/cancel/no-fire-after-cancel/one-shot),persisted-shape.onexit.test.ts,schedule-options.onexit.test.ts(CLI),row-codec.schedule.test.ts(store round-trip), plus on-exit cases in schedule/normalize.Proof re-verified on current head
Rebased onto current
mainand re-ran the live harnesspnpm exec tsx scripts/proof-cron-on-exit.mtsin a real crabbox box β ALL PASS against the realcreateCronExitWatchers+getProcessSupervisor+ real child commands: arm β watched command exits (code 7) βpersistCompletionruns before fire (fail-closed) β origin wake fires with the exit code folded into the woken turn's text; cancel-before-exit never fires;reconcile([])cancels the watcher.Reviewβchange history (every reviewer finding + disposition): https://gist.github.com/ec8f0d0d7607bb1246d8708221fd66e0