Skip to content

fix: main-session automations fail before the model call when the main session is used from a DM - #180603

Merged
obviyus merged 6 commits into
openclaw:mainfrom
masatohoshino:fix/cron-main-capability-key
Nov 12, 2026
Merged

obviyus merged 6 commits into
openclaw:mainfrom
masatohoshino:fix/cron-main-capability-key

Conversation

@masatohoshino

@masatohoshino masatohoshino commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Closes #180602
Closes #197181

Thanks @masatohoshino for the original fix and reproduction, and @Suiah98 for the detailed #197181 report and the isolated-session control run.

What Problem This Solves

When the main session is used from a channel DM (default session.dmScope), a scheduled turn bound to that session cannot use the message tool. On direct-delivery channels such as Telegram the run fails before the model call with plugin delivery capability is no longer active (#180602). On gateway-delivery channels such as WhatsApp the run reaches the model and every message send fails with message action turn capability is no longer active (#197181). Ordinary DM turns and isolated jobs are unaffected.

Why This Change Was Made

Since #178764, scheduled session turns mint their message-action turn capability under the execution session key (agent:main:main). The run's tools redeem it under the turn's runtime policy key, which is peer-scoped for a DM-routed main session, so the lookup misses. That is an identity mismatch, not a revocation: the token is never revoked early.

Ordinary replies already bind the capability correctly (#149131): they mint under the runtime policy key and record the execution session as sourceReplySessionKey. The scheduled mint now does the same. The first commit (by @masatohoshino) moves the key to the policy key; the second passes the execution key as sourceReplySessionKey. Without the second half, the personal-tool check that matches the run's own registration rejects the send with Personal-tool turn authority is no longer active. It is still one capability, for the same agent, run and session id, with the same lifetime and revocation. Nothing is granted, reissued or widened.

Evidence

Built Gateway in a secretless node:24.22.1 container, the real bundled Codex app-server (0.164.0) against a local Responses endpoint whose model calls message, the real WhatsApp channel with only the Baileys socket stood in, and a Telegram Bot API stand-in. Main 4092d358a35a and this branch each ran twice, with identical results.

Scenario main this PR
WhatsApp DM turn that calls message (control) delivered delivered
Heartbeat on session:agent:main:main, main session last used from a WhatsApp DM model calls message; tool result message action turn capability is no longer active; nothing sent delivered to WhatsApp
Telegram DM turn that calls message (control) delivered delivered
Same heartbeat, main session last used from a Telegram DM run fails before the model: plugin delivery capability is no longer active delivered to Telegram
Main-session job with --announce --channel telegram --to 1001 (control) delivered delivered
Isolated job (control) delivered delivered
Heartbeat whose job is removed while the model is still deciding (control) run fails earlier (as above) model calls message after the removal; nothing is sent

Cross-peer check on the built tree (no mocks): a turn grant bound to Alice's DM policy key and the main execution session, redeemed through the real built message tool. With Bob's policy key the send is refused at the capability check, before any outbound I/O; with Alice's key it passes that check and continues (it then stops on the missing Gateway runtime, as expected outside a Gateway). Same result on main and this branch, since redemption stays exact:

Bob's policy key   -> threw message action turn capability is no longer active
Alice's policy key -> threw Runtime config is not prepared. Await captureRuntimeConfigAsyncReader()() first.

Tests: the existing structured-result test now also checks that the scheduled grant redeems only under this peer's policy key and names the executing session (fails on main), paid for by consolidating the fallback table and the CLI static-prompt assertion in the same file (test lines net 0). The post-revocation assertions in the revoked-event tests are unchanged.

@clawsweeper

clawsweeper Bot commented Oct 22, 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.

@clawsweeper clawsweeper Bot added the clawsweeper:intake:bug Preliminary submission classification; full source review pending. label Oct 22, 2026
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Oct 22, 2026
@clawsweeper

clawsweeper Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

Bind scheduled message capabilities to the runtime policy session while retaining the executing session identity.

Example: A heartbeat runs in agent:main:main after that session was used from a Telegram DM.

  • Before: Tool preparation fails with “plugin delivery capability is no longer active” before the model runs.
  • After: The scheduled turn reaches the model and its message send succeeds.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) A small, complete repair with shipped-entry-point evidence, relevant authority controls and no remaining findings.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): Built-Gateway output exercises scheduled Telegram and WhatsApp sends through real runtime owners with transport stand-ins, showing failure before and delivery after the fix; cross-peer redemption fails before outbound I/O, and removing the job mid-run prevents delivery. The proof head and reviewed head have identical production changes.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Scheduled turns in a DM-routed main session cannot reliably reach inference or send their intended notifications.
Reason: This restores documented main-session automation behavior without adding configuration, permissions or another owner.

Regression provenance

Possible regression — probable (reviewed change; failure trace). No predecessor PR is attributed.

Merge readiness

✅ Ready for maintainer review

This PR fixes a current scheduled-message regression with a focused producer-side correction; no actionable defects remain, and the exact-head CI gate now passes.

Priority: P1
Reviewed head: ad946407b9c8b38d8220631e22f4da93711f9a51

Before merge

None.

Findings

None.

Agent review details

How this fits together

The reply admission layer converts scheduled occurrences into admitted agent runs and message capabilities consumed by tool preparation and outbound delivery.

flowchart TD
 A[Scheduled occurrence] --> B[Session turn admission]
 B --> C[Policy bound capability]
 C --> D[Message tool]
 D --> E[Live authority and delivery fence]
 E --> F[Channel transport]
Loading

Technical review

Best possible solution:

Merge the focused capability-binding repair while retaining exact peer matching and existing live delivery authority.

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

Source establishes the exact mint-versus-redemption mismatch, supported by reporter traces and supplied before/after Gateway runs; this read-only review executed no target code.

Is this the best way to solve the issue?

The repair follows ordinary reply identity binding at the producer and preserves strict consumers, avoiding a second authorization path.

AGENTS.md: found and applied where relevant.

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

Provenance checked

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 3d2f7ca adds src/auto-reply/reply/agent-runner-admission.ts:62 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 3d2f7ca06b26; files: src/auto-reply/reply/agent-runner-admission.ts)
  • Josh Lehman: Raw commit 2011274 adds src/auto-reply/reply/agent-runner-admission.ts:64 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 201127429a03; files: src/auto-reply/reply/agent-runner-admission.ts)
  • Josh Avant: Raw commit 187594c adds src/cron/run-admission.ts:92 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 187594c66309; files: src/cron/run-admission.ts)

PR surface

Source +4, Tests 0. Total +4 across 3 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 2 5 1 +4
Tests 1 21 21 0
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 26 22 +4

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.

Review metrics

Metric Value Why it matters
Production versus test changes Production +5/−1; tests +21/−21 The production growth forwards the existing execution identity; the regression extends an existing test while preserving revoked-event coverage.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #180602
Summary: Both linked reports reach the same scheduled capability identity mismatch through different channel delivery modes.

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: Current scheduled main-session DM workflows either fail before inference or reject every message-tool send.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • 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.

History

Review history (6 earlier review cycles)
  • reviewed 2026-10-22T12:45:42.187Z sha 7d1723c :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-22T13:33:23.824Z sha ac94710 :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-22T13:50:10.523Z sha ac94710 :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-30T17:33:13.799Z sha 69e2e69 :: needs real behavior proof before merge. :: none
  • reviewed 2026-11-12T03:54:33.648Z sha 202b1c5 :: needs real behavior proof before merge. :: [P3] Preserve the assertions after revoked work resumes
  • reviewed 2026-11-12T04:10:59.131Z sha ad94640 :: needs maintainer review before merge. :: none

Reviewed November 11, 2026, 11:17 PM ET / November 12, 2026, 04:17 UTC (Revision 7).

@masatohoshino

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Oct 22, 2026
@masatohoshino

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Oct 22, 2026
@openclaw-barnacle openclaw-barnacle Bot reopened this Oct 22, 2026
@masatohoshino

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Oct 30, 2026
@TheAngryPit

Copy link
Copy Markdown
Contributor

Note

🤖 Codex responding on behalf of TheAngryPit

We independently hit #180602 in a scheduled Telegram main-session turn and confirmed the same execution-key versus policy-key mismatch. Your producer-side correction fixed it in our integration without changing the delivery or revocation guards.

Our additional regression goes through native CronService occurrence admission, session-event dispatch, and embedded tool preparation with a synthetic provider. It reproduces the original error before the fix and reaches exactly one model request afterward. The regression and existing authority/delivery tests passed: 79 tests across four files. A manual run of the existing scheduled job then completed successfully, and we re-enabled it with its prompt, schedule, and delivery settings unchanged. That run intentionally produced no notification (NO_REPLY).

This is additional evidence from our integration, not testing of this PR's exact head, and it does not close the outstanding cross-peer transport-proof question.

We're happy to help carry this forward onto current main and contribute the regression/proof while preserving your authorship and the existing history. Are you still actively working on it? If not, we can pick up the remaining integration work here rather than open a competing PR.

…lity

The scheduled grant is redeemed under the turn's runtime policy key; personal-tool authority checks the run's own registration through sourceReplySessionKey, as ordinary replies already set it (openclaw#149131).
@obviyus

obviyus commented Nov 12, 2026

Copy link
Copy Markdown
Collaborator

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@obviyus

obviyus commented Nov 12, 2026

Copy link
Copy Markdown
Collaborator

Heads-up @steipete, since #178764 (3d2f7ca) introduced this: scheduled session turns mint their message-action capability under the execution key (agent:main:main), while the run's tools redeem it under the peer-scoped runtime policy key when the main session is used from a DM. The lookup misses, so message sends from main-session heartbeats fail (#197181, #180602); this PR binds the one capability the way ordinary replies already do (#149131): policy key for redemption, execution key as sourceReplySessionKey.

@clawsweeper clawsweeper Bot added the clawsweeper:intake:bug Preliminary submission classification; full source review pending. label Nov 12, 2026
@obviyus

obviyus commented Nov 12, 2026

Copy link
Copy Markdown
Collaborator

Proof captures on head 202b1c5 (production code built from 45292a186c6f; the head only reformats the test). Main 4092d358a35a. One line per scenario: what the model stand-in saw returned from message, and what reached the channel stand-ins. Run 2 matched run 1 on both builds.

== main (run 1)
A whatsapp DM turn (control): message calls 1; tool error -; delivered 1; gateway error -
B main-session heartbeat, whatsapp route: message calls 1; tool error message action turn capability is no longer active; delivered 0; gateway error -
C telegram DM turn (control): message calls 1; tool error -; delivered 1; gateway error -
D main-session heartbeat, telegram route: message calls 0; tool error -; delivered 0; gateway error "plugin delivery capability is no longer active"
E main-session job, --announce --to 1001 (control): message calls 1; tool error -; delivered 1; gateway error -
F isolated job (control): message calls 1; tool error -; delivered 1; gateway error -
G heartbeat whose job is removed mid-run (control): message calls 0; tool error -; delivered 0; gateway error 2026-11-12T03:24:41.066+00:00 Embedded agent failed before reply: plug
== this PR (run 1)
A whatsapp DM turn (control): message calls 1; tool error -; delivered 1; gateway error -
B main-session heartbeat, whatsapp route: message calls 1; tool error -; delivered 1; gateway error -
C telegram DM turn (control): message calls 1; tool error -; delivered 1; gateway error -
D main-session heartbeat, telegram route: message calls 1; tool error -; delivered 1; gateway error -
E main-session job, --announce --to 1001 (control): message calls 1; tool error -; delivered 1; gateway error -
F isolated job (control): message calls 1; tool error -; delivered 1; gateway error -
G heartbeat whose job is removed mid-run (control): message calls 1; tool error -; delivered 0; gateway error -

@obviyus

obviyus commented Nov 12, 2026

Copy link
Copy Markdown
Collaborator

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 12, 2026
@obviyus

obviyus commented Nov 12, 2026

Copy link
Copy Markdown
Collaborator

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Nov 12, 2026
@obviyus
obviyus merged commit 4f96534 into openclaw:main Nov 12, 2026
138 of 140 checks passed
@obviyus

obviyus commented Nov 12, 2026

Copy link
Copy Markdown
Collaborator

Landed in 4f96534. Thanks @masatohoshino and @Suiah98.

github-actions Bot pushed a commit to NehaChoudhary6NehaChoudhary69104/openclaw that referenced this pull request Nov 12, 2026
…n session is used from a DM (#180603)

fix(cron): bind scheduled message capabilities under the keys the run's tools use

Since scheduled conversation work moved through session admission (#178764), a cron or heartbeat run on the main session minted its message-action capability under the plain session key, while the run's own tools looked it up under the peer-scoped runtime policy key when the main session was used from a DM. The lookup missed, so every message send failed with "message action turn capability is no longer active", or the run failed earlier with "plugin delivery capability is no longer active". The scheduled grant is now redeemable under the turn's runtime policy key and records the execution session key as sourceReplySessionKey, as ordinary replies already do (#149131). It is still one capability for the same run with the same lifetime and revocation; nothing is granted, widened or skipped. No text changes.

Evidence: a built Gateway with the real bundled Codex app-server against a local model endpoint that calls message, the real WhatsApp channel with only the Baileys socket stood in, and a Telegram stand-in, two runs each. With the main session used from a WhatsApp DM, a heartbeat on agent:main:main failed the send on main and delivers with this change; from a Telegram DM it failed before the model call on main and delivers with this change. Ordinary DM turns, an isolated job and an announce job with --to deliver on both, a heartbeat whose job is removed mid-decision sends nothing, and a grant minted for one peer is refused for another peer on both. Net 0 test lines; the structured-result test fails on main. Details: openclaw/openclaw#180603 (comment).

Closes #180602. Closes #197181. Thanks @masatohoshino for the fix and @Suiah98 for the report.

Co-authored-by: Ayaan Zaidi <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 13, 2026
…n session is used from a DM (openclaw#180603)

fix(cron): bind scheduled message capabilities under the keys the run's tools use

Since scheduled conversation work moved through session admission (openclaw#178764), a cron or heartbeat run on the main session minted its message-action capability under the plain session key, while the run's own tools looked it up under the peer-scoped runtime policy key when the main session was used from a DM. The lookup missed, so every message send failed with "message action turn capability is no longer active", or the run failed earlier with "plugin delivery capability is no longer active". The scheduled grant is now redeemable under the turn's runtime policy key and records the execution session key as sourceReplySessionKey, as ordinary replies already do (openclaw#149131). It is still one capability for the same run with the same lifetime and revocation; nothing is granted, widened or skipped. No text changes.

Evidence: a built Gateway with the real bundled Codex app-server against a local model endpoint that calls message, the real WhatsApp channel with only the Baileys socket stood in, and a Telegram stand-in, two runs each. With the main session used from a WhatsApp DM, a heartbeat on agent:main:main failed the send on main and delivers with this change; from a Telegram DM it failed before the model call on main and delivers with this change. Ordinary DM turns, an isolated job and an announce job with --to deliver on both, a heartbeat whose job is removed mid-decision sends nothing, and a grant minted for one peer is refused for another peer on both. Net 0 test lines; the structured-result test fails on main. Details: openclaw#180603 (comment).

Closes openclaw#180602. Closes openclaw#197181. Thanks @masatohoshino for the fix and @Suiah98 for the report.

Co-authored-by: Ayaan Zaidi <[email protected]>
RomneyDa added a commit that referenced this pull request Nov 16, 2026
…n session is used from a DM (#180603)

fix(cron): bind scheduled message capabilities under the keys the run's tools use

Since scheduled conversation work moved through session admission (#178764), a cron or heartbeat run on the main session minted its message-action capability under the plain session key, while the run's own tools looked it up under the peer-scoped runtime policy key when the main session was used from a DM. The lookup missed, so every message send failed with "message action turn capability is no longer active", or the run failed earlier with "plugin delivery capability is no longer active". The scheduled grant is now redeemable under the turn's runtime policy key and records the execution session key as sourceReplySessionKey, as ordinary replies already do (#149131). It is still one capability for the same run with the same lifetime and revocation; nothing is granted, widened or skipped. No text changes.

Evidence: a built Gateway with the real bundled Codex app-server against a local model endpoint that calls message, the real WhatsApp channel with only the Baileys socket stood in, and a Telegram stand-in, two runs each. With the main session used from a WhatsApp DM, a heartbeat on agent:main:main failed the send on main and delivers with this change; from a Telegram DM it failed before the model call on main and delivers with this change. Ordinary DM turns, an isolated job and an announce job with --to deliver on both, a heartbeat whose job is removed mid-decision sends nothing, and a grant minted for one peer is refused for another peer on both. Net 0 test lines; the structured-result test fails on main. Details: #180603 (comment).

Closes #180602. Closes #197181. Thanks @masatohoshino for the fix and @Suiah98 for the report.

Co-authored-by: Ayaan Zaidi <[email protected]>

(cherry picked from commit 4f96534)

Co-authored-by: RomneyDa <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: XS status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

3 participants