Repository navigation
fix(cron): let scheduled scripts inspect and remove their own jobs - #138337
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. Reviewed September 4, 2026, 11:15 AM ET / 15:15 UTC. ClawSweeper reviewWhat this changesThe branch gives scheduled scripts a live, owner-bound ability to inspect and remove their own cron job while retaining operator cancellation. Merge readiness✅ Ready for maintainer review Keep open. This is a distinct, source-supported cron repair that current main does not contain; the authority and cancellation boundaries are correctly guarded. Priority: P1 Review scores
Verification
How this fits togetherCron runs scripts through the Gateway’s agent-tool path. This change supplies a per-run admission identity to that path so cron mutations and final run receipts are tied to the live scheduled execution. flowchart LR
A[Scheduled cron job] --> B[Script trigger]
B --> C[Per-run admission]
C --> D[Agent tool call]
D --> E{Own live job?}
E -->|yes| F[Remove job and finish receipt]
E -->|no| G[Reject mutation or cancel]
F --> H[Automation history]
G --> H
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource -31, Tests +439. Total +408 across 16 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Land the owner-bound admission path after normal exact-head repository checks, preserving self-removal solely for the initiating live scheduled execution. Do we have a high-confidence way to reproduce the issue? Yes—current source provides a bounded scheduled-script path, and the supplied Gateway evidence exercises both accepted self-removal and rejected operator removal. Is this the best way to solve the issue? Yes—the repair establishes authorization at the cron run owner and revalidates it before side effects instead of treating a job identifier as reusable authority. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against bf14f768cb5e. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (1 earlier review cycle)
|
|
Merged via squash.
|
* refactor: consolidate command and cron preparation paths Keep one sub-CLI metadata/registration catalog, common cron payload updates, canonical agent migration visitors, and shared account-state projection. Trust typed internal adapters while retaining external validation, effect authority, cancellation settlement, supported migrations and path containment. Wave-5 y10: BELOW-500, 353 net production lines removed (+440/-793 in 19 files). Branch-only handoff for the coordinator's bundle; no standalone PR. Best-effort tradeoffs accepted: - Cron mid-setup reload recovery (#146582): synthetic retirement, no human incident. Setup may fail; the next invocation refreshes the cache. - Recursive shared preparation retry (#102494/#138337): synthetic concurrent callers; production serializes same-job work. Duplicate direct callers may share cancellation. Failed-owner eviction preserves the next sequential run. - Progress publication generation (#143621): synthetic held update/reset. Presentation dedupe may briefly be stale until a subsequent render/reset. - Doctor adapter schema mirror (#69919): malformed synthetic hooks. Invalid executable adapters fail visibly; missing-hook fallbacks and config checks stay. - Setup adapter schema mirror (#165492): typed internal union. Invalid internal adapters fail when used; both supported wizard forms remain. - Injected process schema mirror (#84381): malformed injection was not human SIGTERM report #71710. Invalid adapters fail registration; cancellation stays. - Loaded registry row revalidation/copy (#114942/#158830/#114476): rows already admitted/normalized. Corrupt trusted rows can fail; first-wins authority stays. - Custom compatibility duplicate check (#14223): all callers parse/type it. Hand-crafted invalid JS uses the default branch; external flags still reject it. - Log probe identity matching (#88159, superseded by #168587): abort now joins the sole probe, so replacement cannot race its result. Recovery/settlement stay. - Whole-config deep copy (#71218): no detached-copy incident. Structural copy updates agents/defaults; unrelated future mutation must respect config ownership. - Repeated plugin-root probes (#70012): no disappearing-root incident. Resolve roots once; root replacement can fail discovery. Symlink containment stays. - Second payload getter read (#135319): synthetic review/corpus, not a human report. Ordinary decoded records are read once; stateful accessors may differ. Proof: fresh independent review clean; core types, targeted lint/format, runtime and static cycles, assertion/line-cap ratchets, and suppression suite passed. Focused CLI cohort: 8 files / 41 tests passed. Earlier unchanged account/setup and cold-import checks passed. Cron and commands cohorts were interrupted after partial results; complete owner tests, payload merging, test-graph types, broad check-changed and build/smoke remain unproved at commit preparation. Unattributed local 120-second timeouts retained: two root-command-descriptions catalog cases and agent-via-gateway's Gateway attempt-budget case. No timeout, retry, skip or kept-behavior expectation changes. Env-name budget mismatch (455 vs 454) also exists at original HEAD and pinned main 7dccff5. All runtime proof used isolated HOME/OpenClaw/XDG state; Phase E untouched. * refactor: consolidate cron payload and lazy CLI paths Share daemon and cron method forwarding through the existing lazy binder, remove the cron CLI reexport shim, and consolidate normalization and merge handling without changing public fields, explicit clears, or effect authority. Remove the obsolete bundled discovery reentry mechanism and impossible Doctor issue helper. The full lane now removes 475 net production lines. Best-effort tradeoffs accepted: - Unknown Doctor issue variants supplied by hand-crafted JavaScript return the invalid value rather than a custom error. Typed local producers and exhaustive switches remain; reporting feature #95979 cites no human unknown-kind incident. - Synchronous bundled-module self-discovery may fail through the existing loader diagnostic instead of returning empty inventory. Commit 65f18d6 only pins injected Jiti reentry, not a human incident; ordinary caches remain. - Cron defaults trust staggerMs normalized earlier in the same synchronous call. No await or mutation boundary intervenes; externally supplied invalid values remain rejected by the normalizer. * fix(channels): retain replacement preview deduplication Withdraw the progress compositor generation removal after the Mattermost retiring-publication case failed CI and bounded serial head/base replays remained inconclusive under load. Restore that file exactly to the branch base and keep all Mattermost tests unchanged, following the campaign fallback. Prune the single obsolete mock-export allowance left by the removed bundled discovery reentry fixture. The local mock ratchet passes with 9586 factories. The remaining lane reduction is 471 net production lines across 25 paths.
…#173036) * refactor: consolidate command and cron preparation paths Keep one sub-CLI metadata/registration catalog, common cron payload updates, canonical agent migration visitors, and shared account-state projection. Trust typed internal adapters while retaining external validation, effect authority, cancellation settlement, supported migrations and path containment. Wave-5 y10: BELOW-500, 353 net production lines removed (+440/-793 in 19 files). Branch-only handoff for the coordinator's bundle; no standalone PR. Best-effort tradeoffs accepted: - Cron mid-setup reload recovery (openclaw#146582): synthetic retirement, no human incident. Setup may fail; the next invocation refreshes the cache. - Recursive shared preparation retry (openclaw#102494/openclaw#138337): synthetic concurrent callers; production serializes same-job work. Duplicate direct callers may share cancellation. Failed-owner eviction preserves the next sequential run. - Progress publication generation (openclaw#143621): synthetic held update/reset. Presentation dedupe may briefly be stale until a subsequent render/reset. - Doctor adapter schema mirror (openclaw#69919): malformed synthetic hooks. Invalid executable adapters fail visibly; missing-hook fallbacks and config checks stay. - Setup adapter schema mirror (openclaw#165492): typed internal union. Invalid internal adapters fail when used; both supported wizard forms remain. - Injected process schema mirror (openclaw#84381): malformed injection was not human SIGTERM report openclaw#71710. Invalid adapters fail registration; cancellation stays. - Loaded registry row revalidation/copy (openclaw#114942/openclaw#158830/openclaw#114476): rows already admitted/normalized. Corrupt trusted rows can fail; first-wins authority stays. - Custom compatibility duplicate check (openclaw#14223): all callers parse/type it. Hand-crafted invalid JS uses the default branch; external flags still reject it. - Log probe identity matching (openclaw#88159, superseded by openclaw#168587): abort now joins the sole probe, so replacement cannot race its result. Recovery/settlement stay. - Whole-config deep copy (openclaw#71218): no detached-copy incident. Structural copy updates agents/defaults; unrelated future mutation must respect config ownership. - Repeated plugin-root probes (openclaw#70012): no disappearing-root incident. Resolve roots once; root replacement can fail discovery. Symlink containment stays. - Second payload getter read (openclaw#135319): synthetic review/corpus, not a human report. Ordinary decoded records are read once; stateful accessors may differ. Proof: fresh independent review clean; core types, targeted lint/format, runtime and static cycles, assertion/line-cap ratchets, and suppression suite passed. Focused CLI cohort: 8 files / 41 tests passed. Earlier unchanged account/setup and cold-import checks passed. Cron and commands cohorts were interrupted after partial results; complete owner tests, payload merging, test-graph types, broad check-changed and build/smoke remain unproved at commit preparation. Unattributed local 120-second timeouts retained: two root-command-descriptions catalog cases and agent-via-gateway's Gateway attempt-budget case. No timeout, retry, skip or kept-behavior expectation changes. Env-name budget mismatch (455 vs 454) also exists at original HEAD and pinned main 89f8219. All runtime proof used isolated HOME/OpenClaw/XDG state; Phase E untouched. * refactor: consolidate cron payload and lazy CLI paths Share daemon and cron method forwarding through the existing lazy binder, remove the cron CLI reexport shim, and consolidate normalization and merge handling without changing public fields, explicit clears, or effect authority. Remove the obsolete bundled discovery reentry mechanism and impossible Doctor issue helper. The full lane now removes 475 net production lines. Best-effort tradeoffs accepted: - Unknown Doctor issue variants supplied by hand-crafted JavaScript return the invalid value rather than a custom error. Typed local producers and exhaustive switches remain; reporting feature openclaw#95979 cites no human unknown-kind incident. - Synchronous bundled-module self-discovery may fail through the existing loader diagnostic instead of returning empty inventory. Commit ca10460 only pins injected Jiti reentry, not a human incident; ordinary caches remain. - Cron defaults trust staggerMs normalized earlier in the same synchronous call. No await or mutation boundary intervenes; externally supplied invalid values remain rejected by the normalizer. * fix(channels): retain replacement preview deduplication Withdraw the progress compositor generation removal after the Mattermost retiring-publication case failed CI and bounded serial head/base replays remained inconclusive under load. Restore that file exactly to the branch base and keep all Mattermost tests unchanged, following the campaign fallback. Prune the single obsolete mock-export allowance left by the removed bundled discovery reentry fixture. The local mock ratchet passes with 9586 factories. The remaining lane reduction is 471 net production lines across 25 paths.
Additional instructions
Maintainers can update this branch through normal repository access.
What Problem This Solves
Fixes an issue where scheduled script automations could see the automation tool but calls to inspect or remove their own job failed. A script that successfully removed its own schedule could also lose its final completion.
Why This Change Was Made
The script runner now creates fresh canonical admission for each invocation after preparing its tools, binds the exact Gateway caller, and closes that authority when execution ends. Warm cached tools retain no run authority. Conditions keep a separate lifecycle and do not claim the payload's execution-start binding.
Validated self-removal records an in-memory fact on the existing active marker so completion can reuse the existing owned-running-receipt check. Operator deletion still cancels the run; closed, replaced or copied owners cannot continue. Agent availability and the exact live receipt remain mandatory. The process-global marker associations from #138231 are preserved, and this branch includes #138313's condition cancellation boundary.
Duplicated context projection, result/error parsing and deadline cleanup are removed: production +262/−293, net −31; tests/support +512/−73, net +439. The preparation and guest deadline scopes remain separate. No configuration, protocol, schema, query, stored format, write/commit semantics, migration or privilege policy changes are introduced.
User Impact
Scheduled scripts can use their permitted automation tools, finish accepted final work after removing their own schedule, and stop when an operator cancels them. Access to sibling jobs and stale invocations remains denied.
Evidence
4b732d72e65b7cbb45d34049985eb4786750fe22; all 16 changed files are byte-identical to the verified candidate. Required exact-head CI will be checked before landing.These runs use real local Gateway and command execution with synthetic task data; no external model-service claim is made. Release-note context: let scheduled scripts execute their authorized automation tools and complete after accepted self-removal while retaining cancellation and stale-owner fencing.
Final-effect evidence for the authority review
The requested allowed/rejected boundary was exercised in the normal isolated Gateway. The record below combines the captured terminal results with the host file observation and the runner's asserted post-removal rejection. The successful self-removal case performs a real
execwrite afterautomations.remove; its owncron.getthen rejects. The operator-removal control observes the command's start marker, removes the job through the operator RPC, and waits beyond the command's intended late write. No late file is created, its receipt reports failure, and a subsequent own-job read succeeds.All IDs and file contents below are synthetic task data. The run uses normal production admission, script tools, Gateway cron mutation and receipt completion, with plugins disabled and exec explicitly enabled only in its isolated fixture. No tool or authority owner is mocked. Closure/replacement/copied-marker rejection is additionally covered by the receipt/admission tests; those tests are separate from this live operator-cancellation trace.
{ "candidateHead": "33e9772e929ab92bdf1c7de1eb6b51380414d592", "sourceIdentity": "All 16 changed files are byte-identical to the final reviewed candidate after rebase; the executed candidate differs only by the documented final comments.", "selfRemoval": { "runId": "manual:15dae63a-b2cf-46df-879a-e8097a1a1a17:1788532426042:4", "entry": { "ts": 1788532426270, "jobId": "15dae63a-b2cf-46df-879a-e8097a1a1a17", "action": "finished", "status": "ok", "completionStatus": "succeeded", "summary": "Self cleanup completed", "runId": "manual:15dae63a-b2cf-46df-879a-e8097a1a1a17:1788532426042:4", "runAtMs": 1788532426049, "durationMs": 221, "deliveryStatus": "not-requested", "delivery": { "intended": { "source": "explicit" } } }, "finalHostFile": { "name": "after-self-removal.txt", "contents": "completed", "sha256": "4ddb3e96801a1ee2b77dc5247c0db478d5f97a93b90e7cdb09f5f51d43764b08" }, "postRemovalCronGet": "rejected; asserted before recording success" }, "operatorRemoval": { "runId": "manual:3beca067-e4f5-41a8-9ede-0d801d7d5bff:1788532426350:5", "entry": { "ts": 1788532426465, "jobId": "3beca067-e4f5-41a8-9ede-0d801d7d5bff", "action": "finished", "status": "error", "completionStatus": "failed", "error": "Cron job removed by operator.", "runId": "manual:3beca067-e4f5-41a8-9ede-0d801d7d5bff:1788532426350:5", "diagnostics": { "summary": "Cron job removed by operator.", "entries": [ { "ts": 1788532426465, "source": "cron-setup", "severity": "error", "message": "Cron job removed by operator." } ] }, "runAtMs": 1788532426354, "durationMs": 111, "deliveryStatus": "not-requested" }, "lateEffect": false, "observation": "start marker observed before operator removal; waited3500ms after terminal for a command scheduled to write after3000ms" }, "recovery": { "ts": 1788532430010, "jobId": "24a50fa7-9e78-489f-b820-608cc8cbea83", "action": "finished", "status": "ok", "completionStatus": "succeeded", "summary": "Healthy after cancellation", "runId": "manual:24a50fa7-9e78-489f-b820-608cc8cbea83:1788532429982:6", "runAtMs": 1788532429985, "durationMs": 25, "deliveryStatus": "not-requested", "delivery": { "intended": { "source": "explicit" } }, "jobName": "Synthetic admission warm read" }, "cleanup": { "gatewayClosed": true, "clientStopped": true, "portClosed": true }, "rawResultSha256": "eddee06356051052e2cc1220fbb9210cf01c76dd242fc7dec0ba43bd4c30decf", "runnerSha256": "61ad57cb9055523ad258327d18920e7d5d1f109f3e6d2279f7097b025671e31f" }This addresses the September 4 14:56 UTC review's final-effect proof request and Rank-up move. The exact Gateway run completed before the comment-only type annotation and mechanical parent rebase; the source identity checks retain that distinction. No production change was needed for this evidence update.