Repository navigation
feat(cron): let a failing automation's owner conversation repair it before alerting - #161007
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 30, 2026, 1:10 PM ET / 17:10 UTC (Revision 21). ClawSweeper reviewWhat this changesThe branch sends a failing automation's first eligible alert to its owner conversation as a repair turn, records that choice in the failure incident, and makes recovery notices silent. Merge readiness✅ Ready for maintainer review Current main and the latest release still use the alert-first flow, so this PR remains useful. The discussion accepts repair by default and silent recovery, and current-head Telegram traces support the new flow. Priority: P2 Review scores
Verification
How this fits togetherOpenClaw's cron scheduler records job outcomes and decides when failures warrant notification. The Gateway turns an eligible repair request into an agent turn in the owning conversation and delivers its reply through that conversation's route. flowchart LR
A[Scheduled job result] --> B[Failure threshold and route]
B --> C{Owner conversation eligible?}
C -->|Yes| D[Recorded repair request]
D --> E[Gateway agent turn]
E --> F[Owner conversation reply]
C -->|No or later failure| G[Failure alert]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +193, Tests +302, Docs +10, Other +253. Total +758 across 21 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Technical reviewBest possible solution: Keep the scheduler as the incident owner and use the Gateway's ordinary conversation turn for repair, with the accepted alert behavior documented for upgrades. Do we have a high-confidence way to reproduce the issue? Not applicable as a bug reproduction: this PR adds a new flow. Current main documents and implements alert-first behavior, while the PR body records current-head runs of the proposed flow. Is this the best way to solve the issue? Yes. The scheduler retains the failure decision, and the Gateway starts a normal turn in the owning conversation; this reuses the existing session and delivery path. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 450dba2dc67a. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (20 earlier review cycles; latest 8 shown)
|
|
@clawsweeper I'm the maintainer who asked for this. Here's where I stand on your review of Owner decisions (please treat these as accepted, not as open risks):
Agreed; we'll fix these next:
The open question where I'd like your recommendation: tool scope for the repair turn. Today it gets
Would you accept this narrower cap?
If you think |
|
🦞👀 I queued a lightweight read-only assist pass. It will post a separate answer comment and will not edit the durable ClawSweeper review comment or trigger close, merge, repair, label, or branch changes. Request: I'm the maintainer who asked for this. Here's where I stand on your review of |
361b5a9 to
e88ee05
Compare
|
ClawSweeper assist: I accept the stated default-repair and silent-recovery decisions as product choices. The proposed tool cap is narrower than Items 1–5 address the recorded findings and proof gaps. I would still need a full review of the current head and PR body, including proof that a job without those permissions cannot gain them, before calling this merge-ready. Evidence:
Suggested next action: Add the agreed changes and permission-boundary proof to the PR body, then request Source: #161007 (comment) |
|
@clawsweeper review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Landed in fb2052a (squash of
|
What Problem This Solves
When a scheduled automation keeps failing, OpenClaw posts "Automation X failed N times" to the chat and waits for the user to ask for a fix, even when the fix is something the agent in the conversation that created the job could make itself.
User Impact
When a job created from a conversation (it has an owner session) reaches its failure-alert threshold (default: 2 failures in a row, same cooldown and incident dedupe), OpenClaw sends one repair request to that owner conversation instead of the first chat alert. The conversation handles it as an ordinary agent turn, as if it had received a message: its own session and transcript, its workspace, its normal tool policy, and its reply goes to that conversation's own route (chat, thread or forum topic). The request tells it to:
Heartbeat settings do not apply to the repair:
heartbeat.target: "none",isolatedSession,lightContextandactiveHoursdo not route, isolate, trim or hold it, and it carries no first-heartbeat notice.The normal alert is still sent when the job has no owner conversation, for operator-only jobs (command payloads, on-exit and stream schedules), for webhook alert routes, and when the job fails again after the repair request (once, noting that a repair was requested). A successful run clears the streak silently.
Upgrade behavior change (intentional): repair is on by default. Opt-out is per job:
failureAlert: falsedisables both the repair request and the alert. No config key is added. The chat "Automation … recovered" notice is removed; recovery stays in automation history. This reverses the notice added in #146582.Why This Change Was Made
The owner conversation is where these jobs get fixed in practice: in our setup a user had to reply "just fix it" to a failure notice, and the agent in that conversation then repaired the job. This change starts that step automatically.
The repair is dispatched through the Gateway's existing
agentmethod on the instance's lifecycle principal (dispatchGatewayLifecycleMethod, the same owner restart-sentinel continuations and exec-approval follow-ups use), with the ownersessionKeyanddeliver: true, so the agent method resolves the reply route from that session's stored delivery context, thread included. The cron service reaches it through one injected dependency (runCronFailureRepair, wired inserver-cron.ts), sosrc/crondoes not import Gateway code. Nothing in thesessions_sendtool needed extracting: its default path also callsagent, but withdeliver: falseplus its own announce flow, which is what this does not want.An earlier revision carried the request on a heartbeat wake (system event plus
requestHeartbeat) and patched the result with aheartbeat: { target: "last" }override. That made the repair inherit heartbeat behavior it should not have: an isolated:heartbeatside session without the conversation's transcript, light context, the internal-handling prompt, and heartbeat routing. This revision removes that path (system event, heartbeat wake, override, and their docs and tests); heartbeat behavior is unchanged for everything else.Tradeoffs (maintainer decisions):
internal_systemprovenance (sourceTool: "cron_failure_repair"), so it carries no sender-owner identity. Under the existing trust model the turn gets the conversation's normal non-owner tool policy (workspace and exec tools, not owner-only control tools such asautomations); a change to the job itself goes through the user's reply turn. No new authority plumbing.agentdispatch rejects), nothing extra is sent at that moment; the job's next failure sends the normal alert naming the repair.Persisted state: the incident gains an optional
repair: { atMs }marker. It means "this incident's first alert became a repair request". It survives restarts, and the next alert of that incident clears it.Evidence
origin/main(merge baseaccde9e31a9, head435e097ee7c): production +233/−85 (net +148), docs +14/−4, tests/QA +649/−49; 21 files. To stay within the line-cap ratchet, the Gateway dispatch lives inserver-cron-notifications.tsnext to the failure-alert transport (2 lines of wiring inserver-cron.ts),reconcileCronExitWatchersmoved tocron-exit-watchers.ts, and two input helpers moved from the qa-lab mock server tomock-openai-input.ts.telegram-e2e-userbot, Convex-leased credential, the lease's forum supergroup with a run-owned topic created before recording and deleted after; fresh isolated gateway from this checkout via--source-gatewayon ports 19951/19952; provider slot = logging proxy to the OpenAI API). Config mirrors ours:agents.defaults.heartbeat = { every: "1h", activeHours: 08:00–23:00 Asia/Kolkata, target: "none", directPolicy: "allow", to: <the tester's DM>, lightContext: true, isolatedSession: true },cron.failureAlertandmessagesunset. The QA user posts in the topic, which creates the owner conversationagent:main:telegram:group:<forum>:topic:<n>. A command action seedsscripts/meeting-sync.md(step 1:sleep 150), adds an isolated agentTurn job "Meeting sync" owned by that topic and announcing to it (timeoutSeconds: 45), and force-runs it twice: both time out (consecutiveErrors: 2, notification statusnot-requested).E2E_MOCK_SERVER_PATH=<logging proxy to the OpenAI API> E2E_ROOT_CONFIG_PATCH=<live model + the heartbeat block above, messages: null> node <runner with forum-topic setup hooks> --backend mock --source-gateway --gateway-port 19951 --mock-port 19952 --chat <lease forum> --scenario <scenario> --timeout-ms 1000000 --record events.ndjson --output summary.json→ exit 0.Hi! This topic owns our hourly sync automations. Reply with one short sentence confirming you are here.I’m here in this topic for your hourly sync automations.Fixed scripts/meeting-sync.md by removing the 150-second wait that exceeded the automation’s 45-second timeout.(the repair turn)Sync: 3 new meetings.(third run,ok,consecutiveErrors: 0)Automation "Calendar sync" failed 2 times/Cause: timeout/Run started: …(the unowned control's alert)What did you change in the meeting sync automation earlier? One sentence.I updated scripts/meeting-sync.md to read the CSV immediately instead of waiting 150 seconds, which exceeded the automation’s 45-second timeout; the schedule stayed unchanged.chat.historyofagent:main:telegram:group:<forum>:topic:<n>holds, in order, the owner-ready exchange, the repair request (user role,internal_system),read→exec→exec→edit scripts/meeting-sync.md→exec, the one-line reply, the next run's result, and the follow-up exchange. No…:topic:<n>:heartbeatsession exists (sessions list). Its 6 main-model requests carried the brief with the topic's ordinary tool surface. The step file changed about 30 s after the second failure.Automation "Meeting sync" failed …alert and noFirst heartbeat alerttext anywhere (7 SUT messages). Control: an unowned job "Calendar sync" with the same broken step fails twice and alerts (delivery statusdelivered); its step file stays unchanged. The provider log also shows oneNO_REPLYturn without the brief right after the repair'sexeccalls that sent nothing.activeHoursexcluding now (same harness with--dm, window 06:00–07:00 Asia/Kolkata at 21:06 IST, otherwise the same heartbeat block). The DM creates the owner conversationagent:main:main; the same owned job fails twice (timeouts). DM timeline: 29.5 sI’m here in the chat that owns your hourly meeting sync automation., 310.8 sFixed meeting sync’s timeout by replacing its 150-second blocking wait with a nonblocking export-readiness check.(the repair turn; it chose to delegate the edit to a subagent viasessions_spawn/sessions_yield), 339.1 sSync: 3 new meetings.(third runok). The repair request and reply are inagent:main:main's transcript; no alert, no onboarding notice, 3 SUT messages.src/gateway/server.cron-failure-repair.test.ts, new file, "repairs an owned job with an ordinary owner-topic turn whatever the heartbeat config"; 4.3–5.8 s): a real Gateway with its real cron service andagentmethod (agent command mocked at the runtime boundary), heartbeattarget: "none",isolatedSession,lightContextand anactiveHourswindow that excludes now; an owned job owned by a Telegram topic session fails twice; the agent command runs once inagent:main:telegram:group:<g>:topic:42withdeliver: true,channel: "telegram",to: <g>,threadId: 42and the repair request as its message, and no announce is sent. Fails on the previous head (no agent run).cron-failure-repair-owner-conversation, real gateway child, qa-channel, mock-openai, isolated state):OPENCLAW_BUILD_PRIVATE_QA=1 OPENCLAW_ENABLE_PRIVATE_QA_CLI=1 pnpm openclaw --profile <isolated> qa suite --provider-mode mock-openai --scenario cron-failure-repair-owner-conversation→passed=1 failed=0. An owned job fails twice and no alert is sent; the owner conversation receives the repair request, its ordinary turn fixes the workspace step file (write), the reply lands in that conversation, and the request and reply are in the owner session's ownchat.history. Control: an unowned job with the same failures alerts, and the repaired job never does.src/cron/service.failure-repair.test.ts, 11 tests): threshold → onerunCronFailureRepairrequest to the owner session (no system event, no heartbeat wake) and no alert; the job's name, payload and error sit only inside<untrusted-text>; the next failure sends one alert naming the repair, later failures nothing more and never a second repair; a rejected repair request alerts on the next failure; success clears the incident silently; no owner → the old alert; agentTurn, systemEvent and script jobs repair, command jobs and on-exit or stream schedules alert. The heartbeat-route case insrc/cron/service.wake-now-real-heartbeat.test.tsis removed (the file is back tomain).435e097ee7c:node scripts/check-changed.mjsexit 0 (line-cap ratchet, all tsgo shards, lint, import cycles, dead exports); cron repair/alert/persistence/real-heartbeat, gateway cron, cron-exit-watchers, server-cron, notifications and qa-lab mock-openai suites pass (30 files, 538 tests);pnpm config:docs:checkis clean.[email protected]created an owner session, an owned and an unowned agentTurn job with an announce failure route and each job's first failure; its ownopenclaw update --tag <candidate tarball>succeeded and both streaks and owners survived; one more failure each reached the threshold: the owned job's incident gainedrepair: {atMs}with delivery statusnot-requestedand its repair request reached the model; the unowned job alerted. The persisted state is unchanged by this rework.config:docs:checkOK). The behavior change is the default for owned chat-alerting jobs, documented above; per-jobfailureAlert: falseopts out.repairmarker is an extra field older releases ignore; an incident that was mid-repair at downgrade keeps its signature there, so the older release dedupes that same-cause failure (no new alert until the cause changes or the job recovers), as it does for any already-alerted incident.owneris fixed at creation (CronJobPatchomits it), so it cannot be reassigned; dispatch reads the live job and sends nothing if the job is gone.