Skip to content

fix(cron): a chat-created automation's failure notice reaches that chat - #203056

Merged
obviyus merged 3 commits into
mainfrom
fix/cron-failure-notice-owner-conversation
Nov 21, 2026
Merged

obviyus merged 3 commits into
mainfrom
fix/cron-failure-notice-owner-conversation

Conversation

@obviyus

@obviyus obviyus commented Nov 21, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

An automation created in a chat (sessionTarget: "current", delivery: { mode: "announce" }, no channel) sends its results back to that chat. Its failure notice did not go there.

The failure-alert transport called resolveDeliveryTarget without the job's sessionTarget (src/gateway/server-cron-notifications.ts:488). The resolver's rule "a conversation-bound job with no external route completes in its conversation" (src/cron/isolated-agent/delivery-target.ts:281) did not apply. The resolver then took whatever channel was configured. On a Gateway that has Telegram configured, it chose Telegram with no recipient and failed with Delivering to Telegram requires target <chatId>. The job recorded lastFailureNotificationDeliveryStatus: not-delivered. The in-app fallback did put a notice in the chat, but as a new user turn.

The result path does the right thing: it passes sessionTarget, gets "Channel is required when delivery.channel=last has no previous channel.", and commits the result to the creating conversation (fallbackUsed: true, delivered: true).

Solution

The failure-alert transport now:

  • Passes the job's sessionTarget to the same resolver, so the resolver does not pick an unrelated channel.
  • When a current job has no external route, commits the notice to its conversation through commitCronConversationResult, the same writer that results use. The notice uses its own idempotency key, so it cannot collide with that run's result row.
  • Keeps an explicit recipient, account or thread owed. requiresExternalCronDelivery (the existing obligation check) blocks the conversation fallback in that case, so an explicit target never becomes a local write recorded as delivered.

Evidence

  • Regression test in src/cron/service/failure-alerts.owner-conversation.test.ts. It runs the real CronService and the real Gateway transport: an owned current job, announce with no channel, a trigger that throws, and a run that comes due. It fails on main with Channel is required (no configured channels detected). With the fix, it passes and shows delivered plus the notice in the owner transcript.

  • Control test: an explicit to with channel last and no channel that can be selected stays not-delivered and writes nothing to the conversation. It fails on the first revision of this fix and passes now.

  • Isolated Gateway E2E (ocx, Telegram configured, a trigger that throws, a schedule that comes due by itself, job created by the owner chat with the automations tool):

    • On base: lastFailureNotificationDeliveryStatus: not-delivered with Delivering to Telegram requires target <chatId>. The log shows cron: failure alert delivery failed. The notice appears in the chat only as a fallback user turn.
    • On the fix: lastFailureNotificationDelivered: true with status delivered. The owner's chat.history has Automation "Thrower fix" failed / Cause: trigger script failed internally / Run started: 2026-11-21 16:09 GMT+5:30 with key cron-failure-alert:…. No Telegram send was tried.
  • pnpm tsgo and oxlint are clean. The notifications, completion, failure-repair and failure-alert suites pass (103 tests).

  • The local ClawSweeper review is clean at e00b1e658363. The first round's P2 about explicit recipients is fixed and has its own test.

  • src/cron/cron-delivery-outcomes.e2e.test.ts still expected the old two-failure threshold; 9a12f4d made the first failure alert by default. CI's changed-test shard ran it here and failed; the expectation now matches main's default and the file passes locally.

Follow-ups (not in this PR)

  • A chat-created job with operatorSource is turned off after one permanent trigger error (timer-outcomes.ts:341). Its failure therefore skips the owner repair turn and takes the plain alert path. That is what happened here.
  • Isolated jobs bound by sourceConversation have the same gap for failure notices, because the notification job does not carry sourceConversation.

@clawsweeper

clawsweeper Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: M labels Nov 21, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Nov 21, 2026
@clawsweeper

clawsweeper Bot commented Nov 21, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

Records failure notices for chat-created automations without an external route in the creating conversation.

Example: The chat-created automation “Thrower fix” encounters a trigger error on a Gateway with Telegram configured.

  • Before: Telegram delivery fails for lack of a recipient, and the chat receives a fallback user turn.
  • After: The chat receives the failure notice through the canonical conversation writer, and notification delivery is recorded as delivered.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused repair with supplied Gateway behavior evidence, distinct regression coverage, and no identified patch defects; the failed webhook assertion has independent inherited-failure evidence.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The PR records an isolated Gateway with Telegram configured, a chat-created automation whose due trigger fails, and after-fix delivery-state and chat.history output showing the notice in its creating conversation without a Telegram attempt.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: An automation created in a chat cannot deliver its plain failure notice through the same conversation path as its results.
Reason: The maintainer-authored direction restores an existing delivery expectation without adding settings or a competing writer; sourceConversation-only jobs are explicitly separate follow-up scope.

Merge readiness

✅ Ready for maintainer review

Keep open: this maintainer-authored PR fixes a current routing defect with a focused change and no identified correctness findings.

Priority: P2
Reviewed head: e00b1e658363ca5a457389c380484e5b6c3fb7e5

Before merge

None.

Findings

None.

Agent review details

How this fits together

The scheduler produces failure-notification intents; the Gateway resolves their destinations and delivers them through an external transport or the existing conversation-result writer.

flowchart TD
  A[Automation failure] --> B[Scheduler notification intent]
  B --> C[Gateway delivery resolver]
  C --> D[External delivery obligation]
  D --> E[Channel transport]
  C --> F[Current conversation without external route]
  F --> G[Canonical conversation writer]
Loading

Technical review

Best possible solution:

Land the focused resolver-and-writer repair while preserving explicit external delivery obligations and separate completion and failure-notice identities.

Do we have a high-confidence way to reproduce the issue?

Current main's resolver call omits the conversation-bound sessionTarget that prevents unrelated channel selection; the PR also records a matching base-versus-fix Gateway reproduction.

Is this the best way to solve the issue?

The patch restores the existing routing invariant using established owners, and its two tests cover local conversation delivery and rejection of a false local success for an explicit recipient.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 86b7d4044522.

Provenance checked

  • Failure-alert destination resolution keeps the original intent (e63e209: Route confirmed results to their destination conversation and remove competing transcript mirrors; the PR extends that existing ownership rule to route-free failure notices.)
  • Inherited owner-target and direct-message policy keeps the original intent (f59d9a8: Failure alerts must retain the primary route's owner targeting and directPolicy rather than inherit an unrelated last conversation.)
  • Canonical conversation writer and idempotency keeps the original intent (3fe7f1e: Consolidate visible outbound history through the background-result writer; the optional notice key preserves existing completion keys while distinguishing another message about the same run.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

PR surface

Source +29, Tests +137. Total +166 across 3 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 2 49 20 +29
Tests 1 137 0 +137
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 186 20 +166

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Labels

Label changes:

  • add P2: Failure notices for route-free chat-created automations use the wrong delivery path, with an existing in-app fallback limiting the impact.
  • add proof: sufficient: Contributor real behavior proof is sufficient.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P2: Failure notices for route-free chat-created automations use the wrong delivery path, with an existing in-app fallback limiting the impact.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed November 21, 2026, 6:13 AM ET / 11:13 UTC.

@obviyus
obviyus merged commit 3eb60f7 into main Nov 21, 2026
126 of 127 checks passed
@obviyus
obviyus deleted the fix/cron-failure-notice-owner-conversation branch November 21, 2026 12:03
vincentkoc added a commit that referenced this pull request Nov 21, 2026
…3044

* origin/main:
  refactor(test): remove duplicate token startup wait case (#203087)
  fix: keep Plugin SDK declarations within the build limit
  fix(ci): remove unused hook type exports (#203074)
  fix(test): exercise the sign-in callback path guard (#203075)
  refactor(tts): separate caption eligibility from text helpers (#203068)
  test: reuse worker preload options (#203058)
  refactor(test): share Bun native-policy test launcher (#203064)
  fix(cron): a chat-created automation's failure notice reaches that chat (#203056)
  refactor(test): remove duplicate claw origin rejection case (#203067)
  refactor(channels): move chunk-mode lookup to streaming readers (#203047)
  refactor: separate skill queries from workspace discovery (#203045)
  fix: resume new chat turns in retained tasks after a restart
  refactor: separate usage pricing preparation from formatting (#203043)
  fix: avoid repeated filesystem probes before agent turns (#203057)
  perf(agents): preserve sealed history during endpoint compaction (#203037)
  fix(test): give deferred identity fixtures read scope (#203053)
  refactor(test): remove redundant channel catalog facade (#203052)
  refactor(cli): isolate daemon port presentation (#203020)
  refactor(cron): isolate CLI input parsing (#203031)
vincentkoc added a commit that referenced this pull request Nov 21, 2026
* feat: open shared sessions in their source Control UI

* feat: open shared sessions in their source Control UI

OpenClaw-Publication: a3826b6b-5899-8ff2-a1b5-84961c64219f

* Merge remote-tracking branch 'origin/main' into land/open-original-203044

* origin/main:
  fix(ci): decouple boundary fixture from timing inventory (#203026)
  fix(ci): shard capable compatibility UI targets (#203042)
  perf(agents): restore selected subagent payloads once (#203039)
  fix: keep standalone context from completing QA tool steps
  perf(sessions): reuse sealed ownership for context projections (#203040)
  refactor(hooks): separate event predicates from hook registry (#203017)
  fix(ci): align update export audits with their consumers (#203030)
  fix: keep cold baseline checks within the existing heap limit

* fix(session-share): accept the runtime config snapshot in the source link resolver

The stored-session link resolver took a mutable config, so the plugin's readonly
runtime snapshot failed production and test typechecks. Accept the snapshot type.

Document the real Open original setup: allow the link command on the receiver
Gateway, set the source Control UI origin, reinstall the source node with all
three commands, then approve the widened surface. Move the section ahead of
Security boundary and add a troubleshooting entry.

Assert through the Gateway catalog list that a provider-supplied link survives
streamed and final rows, and drop the menu unit test the browser fixture covers.

* Merge remote-tracking branch 'origin/main' into land/open-original-203044

* origin/main:
  refactor(test): remove duplicate token startup wait case (#203087)
  fix: keep Plugin SDK declarations within the build limit
  fix(ci): remove unused hook type exports (#203074)
  fix(test): exercise the sign-in callback path guard (#203075)
  refactor(tts): separate caption eligibility from text helpers (#203068)
  test: reuse worker preload options (#203058)
  refactor(test): share Bun native-policy test launcher (#203064)
  fix(cron): a chat-created automation's failure notice reaches that chat (#203056)
  refactor(test): remove duplicate claw origin rejection case (#203067)
  refactor(channels): move chunk-mode lookup to streaming readers (#203047)
  refactor: separate skill queries from workspace discovery (#203045)
  fix: resume new chat turns in retained tasks after a restart
  refactor: separate usage pricing preparation from formatting (#203043)
  fix: avoid repeated filesystem probes before agent turns (#203057)
  perf(agents): preserve sealed history during endpoint compaction (#203037)
  fix(test): give deferred identity fixtures read scope (#203053)
  refactor(test): remove redundant channel catalog facade (#203052)
  refactor(cli): isolate daemon port presentation (#203020)
  refactor(cron): isolate CLI input parsing (#203031)

* chore(plugin-sdk): record the approved session-discussion surface growth

Open original adds two exports to openclaw/plugin-sdk/session-discussion: the
stored-session Control UI path resolver and the session path parser. Raise the
public export and callable budgets by two for them.

Use neutral fixtures for the rejected-origin and rejected-query URL tests so the
fixtures do not resemble credentials; the same rejections are covered.

Co-authored-by: Vincent Koc <[email protected]>
Co-authored-by: vincentkoc <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 22, 2026
…at (openclaw#203056)

## Problem

An automation created in a chat (`sessionTarget: "current"`, `delivery: { mode: "announce" }`, no channel) sends its results back to that chat. Its failure notice did not go there.

The failure-alert transport called `resolveDeliveryTarget` without the job's `sessionTarget` (`src/gateway/server-cron-notifications.ts:488`). The resolver's rule "a conversation-bound job with no external route completes in its conversation" (`src/cron/isolated-agent/delivery-target.ts:281`) did not apply. The resolver then took whatever channel was configured. On a Gateway that has Telegram configured, it chose Telegram with no recipient and failed with `Delivering to Telegram requires target <chatId>`. The job recorded `lastFailureNotificationDeliveryStatus: not-delivered`. The in-app fallback did put a notice in the chat, but as a new user turn.

The result path does the right thing: it passes `sessionTarget`, gets "Channel is required when delivery.channel=last has no previous channel.", and commits the result to the creating conversation (`fallbackUsed: true`, `delivered: true`).

## Solution

The failure-alert transport now:

- Passes the job's `sessionTarget` to the same resolver, so the resolver does not pick an unrelated channel.
- When a `current` job has no external route, commits the notice to its conversation through `commitCronConversationResult`, the same writer that results use. The notice uses its own idempotency key, so it cannot collide with that run's result row.
- Keeps an explicit recipient, account or thread owed. `requiresExternalCronDelivery` (the existing obligation check) blocks the conversation fallback in that case, so an explicit target never becomes a local write recorded as delivered.

## Evidence

- **Regression test** in `src/cron/service/failure-alerts.owner-conversation.test.ts`. It runs the real `CronService` and the real Gateway transport: an owned `current` job, announce with no channel, a trigger that throws, and a run that comes due. It fails on `main` with `Channel is required (no configured channels detected)`. With the fix, it passes and shows `delivered` plus the notice in the owner transcript.
- **Control test:** an explicit `to` with channel `last` and no channel that can be selected stays `not-delivered` and writes nothing to the conversation. It fails on the first revision of this fix and passes now.
- **Isolated Gateway E2E** (`ocx`, Telegram configured, a trigger that throws, a schedule that comes due by itself, job created by the owner chat with the automations tool):
  - On base: `lastFailureNotificationDeliveryStatus: not-delivered` with `Delivering to Telegram requires target <chatId>`. The log shows `cron: failure alert delivery failed`. The notice appears in the chat only as a fallback user turn.
  - On the fix: `lastFailureNotificationDelivered: true` with status `delivered`. The owner's `chat.history` has `Automation "Thrower fix" failed / Cause: trigger script failed internally / Run started: 2026-11-21 16:09 GMT+5:30` with key `cron-failure-alert:…`. No Telegram send was tried.
- `pnpm tsgo` and oxlint are clean. The notifications, completion, failure-repair and failure-alert suites pass (103 tests).
- The local ClawSweeper review is clean at `e00b1e658363`. The first round's P2 about explicit recipients is fixed and has its own test.

- `src/cron/cron-delivery-outcomes.e2e.test.ts` still expected the old two-failure threshold; f0db8f9 made the first failure alert by default. CI's changed-test shard ran it here and failed; the expectation now matches main's default and the file passes locally.

## Follow-ups (not in this PR)

- A chat-created job with `operatorSource` is turned off after one permanent trigger error (`timer-outcomes.ts:341`). Its failure therefore skips the owner repair turn and takes the plain alert path. That is what happened here.
- Isolated jobs bound by `sourceConversation` have the same gap for failure notices, because the notification job does not carry `sourceConversation`.

Co-authored-by: Ayaan Zaidi <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 22, 2026
* feat: open shared sessions in their source Control UI

* feat: open shared sessions in their source Control UI

OpenClaw-Publication: a3826b6b-5899-8ff2-a1b5-84961c64219f

* Merge remote-tracking branch 'origin/main' into land/open-original-203044

* origin/main:
  fix(ci): decouple boundary fixture from timing inventory (openclaw#203026)
  fix(ci): shard capable compatibility UI targets (openclaw#203042)
  perf(agents): restore selected subagent payloads once (openclaw#203039)
  fix: keep standalone context from completing QA tool steps
  perf(sessions): reuse sealed ownership for context projections (openclaw#203040)
  refactor(hooks): separate event predicates from hook registry (openclaw#203017)
  fix(ci): align update export audits with their consumers (openclaw#203030)
  fix: keep cold baseline checks within the existing heap limit

* fix(session-share): accept the runtime config snapshot in the source link resolver

The stored-session link resolver took a mutable config, so the plugin's readonly
runtime snapshot failed production and test typechecks. Accept the snapshot type.

Document the real Open original setup: allow the link command on the receiver
Gateway, set the source Control UI origin, reinstall the source node with all
three commands, then approve the widened surface. Move the section ahead of
Security boundary and add a troubleshooting entry.

Assert through the Gateway catalog list that a provider-supplied link survives
streamed and final rows, and drop the menu unit test the browser fixture covers.

* Merge remote-tracking branch 'origin/main' into land/open-original-203044

* origin/main:
  refactor(test): remove duplicate token startup wait case (openclaw#203087)
  fix: keep Plugin SDK declarations within the build limit
  fix(ci): remove unused hook type exports (openclaw#203074)
  fix(test): exercise the sign-in callback path guard (openclaw#203075)
  refactor(tts): separate caption eligibility from text helpers (openclaw#203068)
  test: reuse worker preload options (openclaw#203058)
  refactor(test): share Bun native-policy test launcher (openclaw#203064)
  fix(cron): a chat-created automation's failure notice reaches that chat (openclaw#203056)
  refactor(test): remove duplicate claw origin rejection case (openclaw#203067)
  refactor(channels): move chunk-mode lookup to streaming readers (openclaw#203047)
  refactor: separate skill queries from workspace discovery (openclaw#203045)
  fix: resume new chat turns in retained tasks after a restart
  refactor: separate usage pricing preparation from formatting (openclaw#203043)
  fix: avoid repeated filesystem probes before agent turns (openclaw#203057)
  perf(agents): preserve sealed history during endpoint compaction (openclaw#203037)
  fix(test): give deferred identity fixtures read scope (openclaw#203053)
  refactor(test): remove redundant channel catalog facade (openclaw#203052)
  refactor(cli): isolate daemon port presentation (openclaw#203020)
  refactor(cron): isolate CLI input parsing (openclaw#203031)

* chore(plugin-sdk): record the approved session-discussion surface growth

Open original adds two exports to openclaw/plugin-sdk/session-discussion: the
stored-session Control UI path resolver and the session path parser. Raise the
public export and callable budgets by two for them.

Use neutral fixtures for the rejected-origin and rejected-query URL tests so the
fixtures do not resemble credentials; the same rejections are covered.

Co-authored-by: Vincent Koc <[email protected]>
Co-authored-by: vincentkoc <[email protected]>
tideclaw-bot pushed a commit that referenced this pull request Nov 23, 2026
Adapted from 3eb60f7 (#203056), by Ayaan Zaidi. Preserve the lead270 explicit two-failure threshold expectation; retain the three-file routing repair and regression.

Co-authored-by: RomneyDa <[email protected]>
(cherry picked from commit 5493554d640589c2806671bd96f4626088cd0b7c)
(cherry picked from commit 69bdf07114198f77720d82d2df32e8d997b7027d)
tideclaw-bot added a commit that referenced this pull request Nov 24, 2026
…at (#203056)

Baseline adaptation: Reuse the baseline conversation writer and persisted notification ID for unrouted current-session alerts; preserve external delivery obligations and transport outcomes.

(cherry picked from commit 3eb60f7)

Co-authored-by: RomneyDa <[email protected]>
(cherry picked from commit 71a7e36143c905112a0b5f7433ec5b79b208cedc)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant