Skip to content

fix(cron): preserve CLI-backed cron topic route - #147283

Open
KirDE wants to merge 30 commits into
openclaw:mainfrom
KirDE:fix/cross-chat-async-route
Open

KirDE wants to merge 30 commits into
openclaw:mainfrom
KirDE:fix/cross-chat-async-route

Conversation

@KirDE

@KirDE KirDE commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #138316. Builds on #138406 and retains contributor ancestry. Related: #162034 (durable source authority, outside this PR).

What Problem This Solves

Fixes CLI-backed isolated cron completions losing their Telegram recipient/topic and falling back to the owner DM.

User Impact

CLI cron runs receive the selected account and conversation/thread context, matching the embedded runner. Unthreaded targets still use the channel plugin's normalization. No new configuration or storage changes.

Why This Change Was Made

Fresh main (db6449d3f6091740dbddcf02fdc0e34dc94ca424, fetched October 10) still populated only channel/account for CLI runs; recipient resolution remained embedded-only. The shared runner parameters now carry the channel-native target and normalized thread into the CLI loopback grant.

Integrated main to resolve actual merge conflicts after cron runtime refactoring, then incorporated the maintainer-owned Kysely migration-witness fix db6449d3f6 after exact-head CI exposed that inherited architecture failure. Kept upstream's lifecycle/admission changes and removed tests intact; the PR remains limited to two cron production files and two focused test files. Shared conversation-context assembly lives in the existing channel-output-policy module so the executor does not grow beyond the line-cap ratchet.

This is route propagation, not durable source-generation fencing or final transport authorization. Revocation, queue/recovery migration, and downgrade compatibility remain in #162034.

Evidence

  • On the updated candidate: 18/18 focused tests passed across run.message-tool-policy.test.ts and channel-output-policy.test.ts, including CLI grant recipient/topic/account and plugin normalization for unthreaded targets.
  • Measured one-worker invocation: 324.29 seconds wall on the 4 GiB host; Vitest reported 314.20 seconds, including 217.74 seconds cold compiled-worker preparation. The new CLI regression took 30.59 seconds including first-fixture initialization. The integration file exceeds 30 seconds on this host: it exercises the real isolated-cron entry point through real CLI grant assembly; a helper-only test would miss the original missing producer fields. Existing cron integration fixtures account for the cold import/setup cost; no new Gateway/process boots or real timers were added.
  • Targeted oxfmt, oxlint, diff-check, line-cap, and mock-factory ratchets passed.
  • Core typecheck was bounded to 180 seconds on this 4 GiB host and timed out; no typecheck pass is claimed. Heavy extension type lanes were not run.
  • Fresh independent Codex autoreview of the exact candidate tree is scoped-clean for P0–P2; no actionable defects identified. Source context covered runner assembly, channel target resolution, and real MCP grant construction. After the second main integration, all four PR files and the reviewed MCP grant source context remain byte-identical to the independently reviewed candidate.
  • Prior exact-head CI 38040705236 at b3f2743: production/test types and lint passed; architecture Kysely and UI e2e failed. The real checker replayed the same 14 Kysely violations on main's cdeb source tree; the owning upstream fix is now integrated. Kysely verification: passed on the final integrated candidate (Kysely guardrails OK).
  • The two session-dashboard.e2e.test.ts Canvas pin click failures are inherited: the same cases and Details pointer-event interception occur in main CI 38038570610, at 02a2bd2. UI source/config is byte-identical between that main baseline and cdeb. This cron PR does not change UI files or suppress these failures.
  • Current exact-head CI 38042206895 completed FAILURE at 881b26f8524cd15bbafecd9a78fa255c19ec2bed: 33 jobs succeeded, 2 failed, 28 skipped. Production types, test types (including all five core stripes), lint, architecture/Kysely, selected Node tests, security-fast, and baseline ratchets passed. The only product-job failure is UI E2E shard 1; openclaw/ci-gate fails because that selected lane failed. Its two failing Canvas pin tests have the same 30-second click timeout and Details chat-gutter-stack pointer interception as the cited main baseline; current direct job logs were compared against baseline job 114174218095. Upstream UI changes since cdeb are not attributed to this four-file cron patch. No unrelated UI patch, failure suppression, or rerun-for-green was made.
  • Latest completed exact-head PR context/evidence run 38042237366 succeeded; the older cancelled run 38042204760 is historical.
  • Latest ClawSweeper review, updated October 10 at 09:48 UTC, explicitly reviews this head and finds no discrete introduced bug, but remains blocked before merge on configured Telegram completion and final-effect rejection proof (wrong account/chat/topic and source replacement/revocation). These are not established by focused mocks or the independent scoped patch review.
  • Live-proof readiness was checked with the repository Telegram Test Server doctor: it exited 1 with PROJECT_ACCESS from both existing Convex and offline npx launchers; bunx is unavailable and no private broker environment pair is configured. The QA broker owner must grant existing CLI/project access or supply the private broker pair before Test Server proof can run. uv is also unavailable on this host. No installation, login, credential publication, live production Telegram probe, or Gateway restart was attempted.

No live Telegram Test Server delivery is claimed. Tests use mocked channel integrations and validate the real grant assembly; final Telegram transport effects and stale-authority rejection are not proven by this PR.

Current head: 881b26f8524cd15bbafecd9a78fa255c19ec2bed. No merge or default-branch push.

ylcn91 and others added 4 commits September 13, 2026 18:39
The isolated cron executor resolved the channel-native current-channel id
only inside its embedded branch, so a CLI-backed run (Codex app-server and
every other CLI provider) reached `runCliAgent` with `messageChannel` and
`agentAccountId` but no recipient/thread. `buildCliMcpGrantContext` then
minted a loopback grant without `currentChannelId`/`currentThreadTs`, and
`createExecTool` built `notifyDeliveryContext` with an empty target — so a
background exec completion carried no route and the later heartbeat relay
fell back to the owner DM.

Resolve the route once above the runtime branch and hand it to both
runners; the CLI runner takes it as `currentChannelId` plus
`currentThreadTs`, its vocabulary for the embedded `messageTo`/
`messageThreadId` pair.

User impact: Telegram forum-topic (and any threaded-channel) automations on
a CLI runtime keep background exec completions and message-tool sends in
their originating topic instead of leaking topic-local operational output
into the owner's DM.

Fixes openclaw#138316
…gets

`resolveCurrentChannelTarget` loaded the channel-plugin runtime for every
targeted cron run, but only a thread needs channel-specific conversion (the
one implementer returns the target unchanged without one). An unthreaded
route now returns its target directly, so CLI-backed runs regain the direct
path they had before the route was resolved above the runtime split.
The existing regression test stops at the executor-to-CLI parameters, so no
proof covered the four production owners the route crosses afterwards. This
drives the real loopback grant, gateway tool resolution, exec notify queue,
and heartbeat delivery with a real background process and asserts the delayed
completion is delivered to the originating forum topic.

On the merge-base the same test fails at the delivery boundary:
`expected '<owner-dm>' to be '<chat>:topic:47'`.
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. proof: telegram-e2e This PR needs Telegram Test Server proof with the repository E2E skill. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 13, 2026
@clawsweeper

clawsweeper Bot commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge.

What this changes

The PR passes the resolved channel recipient and normalized thread through shared CLI and embedded cron runner parameters.

Example: An isolated CLI cron job targets Telegram account ops, chat -100123, topic 47.

  • Before: The CLI tool grant carries channel/account but lacks the recipient and topic.
  • After: The grant carries currentChannelId -100123:topic:47 and currentThreadTs 47; actual Telegram delivery remains unproven.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The focused patch is useful and has no discrete introduced finding, but required runtime and authority evidence is absent.
Proof confidence 🧂 unranked krab (1/6) Real behavior proof is necessary before merge. See Before merge.
Patch quality 🦐 gold shrimp (3/6) Security review found an item that needs attention.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: CLI-backed cron tools lose the selected recipient/topic, allowing delayed results to miss or leave the intended conversation.
Reason: A focused producer repair restores existing runner routing parity; the separate durable-authority design is outside this PR's stated scope.

Merge readiness

⛔ Blocked before merge - 2 items remain

Keep this PR open: current main still omits CLI cron recipient/thread context, and the focused patch contains no discrete introduced bug.

Priority: P1
Reviewed head: 881b26f8524cd15bbafecd9a78fa255c19ec2bed

Before merge

  • Add real behavior proof - Authority-chain proof required: the isolated-cron harness and real CLI grant builder receive ops, -100123, and topic 47 with mocked integrations, but no configured after-fix completion or wrong-account/chat/topic and source-replacement/revocation rejection before Telegram I/O is supplied. Provide redacted Test Server logs, live output, or terminal captures through current session-event and final transport owners, excluding keys, IPs, phone numbers, and non-public endpoints. The contributor reports QA broker access is blocked. Existing route fields are populated without changing config, schema, or serialized data formats, so no migration is required. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • Resolve security review attention item - Final-effect authorization for the newly propagated delayed-delivery route remains unverified.

Findings

None.

Tests

  • Missing end-to-end proof: Missing configured CLI cron Telegram completion and final-effect negative cases; the current added regression's failure on the base is not demonstrated.
Agent review details

How this fits together

The isolated cron executor converts resolved delivery settings into runner context; CLI grant construction forwards that context to tools, whose background completions enter the session-event delivery owner.

flowchart TD
A[Cron delivery settings] --> B[Channel target normalization]
B --> C[Shared runner parameters]
C --> D[CLI tool grant]
C --> E[Embedded runner]
D --> F[Background exec completion]
F --> G[Session event delivery]
G --> H[Telegram transport]
Loading

Technical review

Best possible solution:

Retain the shared route-propagation repair and establish correct delivery plus final-effect rejection through the existing delivery owners.

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

Current-main source establishes the CLI recipient/thread omission and its grant/notification consumers; no runtime reproduction was performed during this read-only review.

Is this the best way to solve the issue?

Resolving context once before runtime branching fixes the producer omission while preserving plugin normalization; it does not establish the broader delayed-delivery authority guarantees.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 8b677154aef0.

Provenance checked

  • Channel-native target normalization keeps the original intent (40719bc: Move cron output and threading policy to channel plugins.)
  • Shared runner parameter assembly keeps the original intent (084d51d: Simplify worker and model fallback handling while retaining shared execution context.)

Testing

Proof path: in-process harness.

Security

Needs attention: Final-effect authorization for the newly propagated delayed-delivery route remains unverified.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 40719bc adds src/cron/isolated-agent/channel-output-policy.ts:37 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 40719bcb7462; files: src/cron/isolated-agent/channel-output-policy.ts)
  • Ayaan Zaidi: Raw commit dd8de93 adds src/cron/isolated-agent/run-executor.ts:196 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: dd8de93b0eb8; files: src/cron/isolated-agent/run-executor.ts)
  • Peter Lee: Raw commit cab8040 adds src/cron/isolated-agent/run-executor.ts:289 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: cab8040b1436; files: src/cron/isolated-agent/run-executor.ts)

PR surface

Source +15, Tests +63. Total +78 across 4 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 2 23 8 +15
Tests 2 64 1 +63
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 87 9 +78

Review metrics

Metric Value Why it matters
Production versus tests Production +23/-8; tests +64/-1 Production growth centralizes shared conversation-context assembly; test growth covers the missing CLI grant fields and preserved normalization contracts.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #138316
Summary: This PR and the original contribution address the same CLI route omission; durable source authority is separate overlapping work.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Labels

Label changes:

No label changes.

Label justifications:

  • P1: The repair addresses a reported broken cron completion workflow with cross-chat routing consequences.
  • merge-risk: 🚨 message-delivery: The changed fields select recipient/topic for CLI tools and delayed completion delivery; grant assertions alone establish no transport outcome.
  • merge-risk: 🚨 security-boundary: Captured destinations cross conversation boundaries and can outlive their producing turn; final-effect rejection remains unverified.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦐 gold shrimp.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.
  • proof: telegram-e2e: This PR needs Telegram Test Server proof with the repository E2E skill. The intended account/chat/topic of a CLI cron completion is observable on Telegram's Test Server.

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Capture a configured CLI cron background completion in Telegram account ops and its intended topic.
  • Prove wrong-destination and source replacement or revocation rejection before final transport I/O.

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.

History

Review history (22 earlier review cycles; latest 8 shown)
  • reviewed 2026-09-30T17:15:02.276Z sha 39e267d :: needs real behavior proof before merge. :: [P2] Move source-generation reads off Gateway delivery paths
  • reviewed 2026-09-30T17:43:02.324Z sha e905bad :: needs real behavior proof before merge. :: [P2] Move source-generation reads off Gateway delivery paths
  • reviewed 2026-09-30T18:34:20.898Z sha 5325d6c :: needs real behavior proof before merge. :: [P1] Preserve unthreaded channel-plugin target resolution
  • reviewed 2026-09-30T18:56:54.834Z sha 5325d6c :: needs real behavior proof before merge. :: [P1] Preserve unthreaded channel-plugin target resolution
  • reviewed 2026-09-30T20:08:25.268Z sha c9d7673 :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-10T09:22:16.563Z sha b3f2743 :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-10T09:47:27.472Z sha 881b26f :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-10T10:07:11.336Z sha 881b26f :: needs real behavior proof before merge. :: none

Reviewed October 10, 2026, 7:55 AM ET / 11:55 UTC (Revision 23).

@KirDE

KirDE commented Sep 13, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Sep 13, 2026

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

@clawsweeper

clawsweeper Bot commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added the merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. label Sep 13, 2026
@clawsweeper clawsweeper Bot removed the merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. label Sep 13, 2026
@clawsweeper clawsweeper Bot added merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. and removed merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. labels Sep 14, 2026
@openclaw-barnacle openclaw-barnacle Bot added the gateway Gateway runtime label Sep 17, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. label Sep 30, 2026
@openclaw-barnacle openclaw-barnacle Bot added size: S and removed docs Improvements or additions to documentation gateway Gateway runtime agents Agent runtime and tooling size: XL labels Sep 30, 2026
@KirDE KirDE changed the title fix(cron): keep async completions in their originating chat fix(cron): preserve CLI-backed cron topic route Sep 30, 2026
@openclaw-barnacle openclaw-barnacle Bot added triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. and removed triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. labels Sep 30, 2026
@KirDE

KirDE commented Sep 30, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

The PR is now narrowed to CLI-backed cron topic-route propagation (four changed files); durable source fencing, queue recovery, and downgrade have moved to #162034. Exact head: 5325d6c. The PR body and title describe the reduced scope and evidence. Targeted tests 32/32 plus format/lint passed; PR context/evidence check rerun succeeded: https://github.com/openclaw/openclaw/actions/runs/36758598354. Independent diff review found no changed-code defects; no live Telegram Test Server send is claimed.

The exact-head CI gate currently fails two tests outside the four changed files: server-runtime-subscriptions.shutdown.test.ts:110 (defaultCompleteModel 0/1) and update-cli.windows-lifecycle.test.ts (ExitError during SIGINT). Logs: https://github.com/openclaw/openclaw/actions/runs/36757849444. A failed-jobs rerun was attempted but GitHub returned HTTP 403 (repository admin rights required). A maintainer with rerun access: please rerun those failed jobs or advise on any reproducible branch-specific failure. No merge requested.

@clawsweeper

clawsweeper Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@KirDE

KirDE commented Sep 30, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Follow-up to the exact-head P1 finding: c9d7673 restores channel-plugin normalization for unthreaded targets while keeping no-channel/no-address paths from loading the plugin. Added regression tests for both paths; 33/33 targeted tests, format/lint/diff checks passed. The final PR diff is three cron files and the body was updated. No durable source-generation or queue changes were reintroduced; #162034 retains that work. No live Telegram transport proof is claimed. Please review the current SHA, not prior 5325d6c.

@clawsweeper

clawsweeper Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot removed the merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. label Sep 30, 2026
@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Oct 10, 2026
@KirDE

KirDE commented Oct 10, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Please re-review exact head 881b26f8524cd15bbafecd9a78fa255c19ec2bed with the consolidated evidence below. No merge or autofix is requested.

Relevance and scope

Current main still omits the resolved recipient/thread from CLI cron runner context. This PR remains a focused repair: four cron files, +87/-9 against integrated main db6449d3f6091740dbddcf02fdc0e34dc94ca424. Plugin-owned target normalization is preserved. Durable source-generation fencing, queue recovery and downgrade design remain separate in #162034.

Verified checks

Remaining proof and access blocker

We acknowledge the current review requirements: configured delayed CLI completion reaches its intended Telegram account/chat/topic; wrong account/chat/topic is rejected before transport; source replacement/revocation is rejected by final-delivery owners. Mocked grant assertions and scoped code review are NOT substitutes for that proof. No live Telegram Test Server result or complete authority-chain validation is claimed.

The repository Telegram E2E doctor currently returns PROJECT_ACCESS for the QA credential-broker project through the existing authenticated CLI. No broker environment credential pair is configured. A broker project owner needs to grant access or provide the approved private credential path before this proof can be produced. No production Telegram fallback was used.

Please assess the focused patch and the CI baseline evidence separately from the missing live-proof gates, and identify any concrete introduced defect or exact additional evidence required. We are not requesting a rating increase without evidence, nor claiming this PR is merge-ready. A maintainer disposition/rerun of the UI lane remains external.

@clawsweeper

clawsweeper Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@openclaw-barnacle

Copy link
Copy Markdown

This assigned pull request has been automatically marked as stale after being open for 27 days.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle Bot added the stale Marked as stale due to inactivity label Oct 11, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P1 High-priority user-facing bug, regression, or broken workflow. proof: telegram-e2e This PR needs Telegram Test Server proof with the repository E2E skill. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: S stale Marked as stale due to inactivity status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Codex CLI cron drops Telegram topic route from background exec completions

4 participants