Skip to content

fix(cron): resolve delivery target for delivery.mode "none" jobs - #241

Merged
convyusboy merged 5 commits into
boonfrom
ridho/cron-none-delivery-target-resolution
Sep 25, 2026
Merged

convyusboy merged 5 commits into
boonfrom
ridho/cron-none-delivery-target-resolution

Conversation

@convyusboy

@convyusboy convyusboy commented Sep 23, 2026 •

Copy link
Copy Markdown
Collaborator

What Problem This Solves

Live testing of the browser-handoff recheck flow (a cron job with delivery.mode: "none", scoped to the originating session) showed the agent's own terminal-result message silently failing: [tools] message failed: Action send requires a target. The customer saw a blank reply instead of the automatic "you're signed in" follow-up.

Why This Change Was Made

resolveCronDeliveryContext (src/cron/isolated-agent/run.ts) had a short-circuit: any delivery.mode: "none" job without an explicit channel/to/threadId/accountId on its own delivery config (!hasExplicitCronDeliveryTarget) got a hard-coded, empty resolvedDelivery (ok: false, channel: undefined, to: undefined) — resolveDeliveryTarget() was never called at all.

That short-circuit conflated two different things:

  • cron's own auto-announcement, which mode: "none" is supposed to suppress — already handled independently via deliveryPlan.requested (resolveCronDeliveryPlan sets requested: resolvedMode === "announce", so it's false for "none" regardless of this fix).
  • the agent's own explicit message(action="send") call, which resolveCronSourceDeliveryPlan's existing "cron_none" branch was already designed to support (see its standing comment: "delivery=none still allows explicit message-tool sends from the agent, but cron itself must not auto-announce a final reply"). That branch builds its message-tool-awareness target from resolvedDelivery — but the short-circuit above had already wiped resolvedDelivery to nothing before it got there, so a browser-handoff recheck (session-scoped mode: "none", no explicit per-job channel/to) had no channel or to for its own message-tool send to fall back to.

Removed the short-circuit so mode: "none" runs through the same resolveDeliveryTarget() call as every other mode. deliveryRequested still stays false for "none" (driven independently by deliveryPlan.requested), so cron itself still never auto-announces — only the agent's own explicit message-tool send benefits from having a real target.

Verified this is safe against the existing #91613 keyless-inherited-delivery regression guard (src/cron/isolated-agent/delivery-target.ts:321-359): that refusal only fires for jobs with !rawSessionKey (genuinely keyless, inheriting from the shared agent-main session's last-writer-wins bucket). A session-scoped job like browser-handoff's recheck (sessionTarget/sessionKey set) resolves via its own session and is never routed through that refusal, so this change cannot resurrect the cross-conversation leakage bug that guard exists to prevent.

User Impact

Cron jobs using delivery.mode: "none" with no explicit per-job channel/to (the pattern browser-handoff's automatic sign-in recheck uses) can now have the agent's own terminal-result message actually reach the customer, instead of silently failing with "Action send requires a target." No change to cron's own auto-announcement behavior (still suppressed for "none", unchanged for "announce"/"webhook").

Evidence

  • Live: reproduced the failure on arief-openclaw-test (journalctl --user -u openclaw-gateway.service showed [tools] message failed: Action send requires a target. immediately after a mode: "none" recheck's terminal message attempt); traced the exact code path via message-action-normalization.ts → run-executor.ts's resolveCurrentChannelTarget → run.ts's resolveCronDeliveryContext.
  • node scripts/run-vitest.mjs src/cron/isolated-agent/run.message-tool-policy.test.ts — 52/52 passing. Updated/renamed 3 existing tests that encoded the old short-circuited behavior (asserted resolveDeliveryTarget was skipped / target stayed unresolved for bare mode: "none" jobs); their new versions assert the target now resolves and the agent's message-tool send is verified against it.
  • node scripts/run-vitest.mjs src/cron — 112 test files / 1176 tests passing, no regressions.
  • pnpm tsgo:core — clean.
  • pnpm check:import-cycles — 0 cycles.
  • node scripts/run-oxlint.mjs src/cron/isolated-agent/run.ts src/cron/isolated-agent/run.message-tool-policy.test.ts — clean.
  • oxfmt --check — both changed files clean (5 unrelated pre-existing formatting drifts elsewhere in the repo, untouched by this change).
  • git diff --numstat — net LOC decreases in run.ts (deletes a hard-coded short-circuit branch, replaced by a comment); test file grows only from the 3 updated assertions plus explanatory comments.

🤖 Generated with Claude Code


Summary by cubic

Fixes cron jobs with delivery.mode: "none" so the agent's own explicit message-tool sends reach a real target, instead of silently failing with "Action send requires a target."

  • Previously, mode: "none" jobs without an explicit per-job channel/to short-circuited to an empty resolved delivery target, skipping resolveDeliveryTarget(). Now they resolve a target like every other mode; cron's own auto-announcement stays suppressed for "none", since deliveryRequested is driven independently by the delivery plan.
  • The [Bug] Gateway reply-queue state not flushed on restart — stale queued replies drain to wrong Matrix room after restart openclaw/openclaw#91613 shared-bucket refusal is extended to any session key that canonicalizes to the shared agent-main bucket: under dmScope:"main", peer runSessionKeys collapse to agent:<id>:main; under session.scope:"global", the literal "global" key is used. Both now resolve the main session key correctly and refuse implicit rechecks that would otherwise deliver to another peer's last-written room. Regression tests cover the direct, interleaved two-peer, and global-scope cases.
  • Tests that encoded the old short-circuited behavior were updated: a duplicate test was merged, assertions verify resolveDeliveryTarget is called with the job's own sessionKey, and the fixture helper gained an overrides param instead of spreading a never-typed value.

Written for commit 144a80f. Summary will update on new commits.

Review in cubic

Cron jobs with delivery.mode:"none" and no explicit per-job
channel/to/threadId/accountId were short-circuited to a hard-coded,
unresolved delivery target -- resolveDeliveryTarget() was never
called. That broke more than cron's own suppressed auto-announce: it
also left the agent's own explicit message(action="send") call (the
one resolveCronSourceDeliveryPlan's "cron_none" branch is designed to
support) with no channel/to to fall back to, so a session-scoped
recheck job reporting a terminal result failed with "Action send
requires a target."

Removed the short-circuit so mode:"none" now resolves a delivery
target the same way every other mode does. deliveryRequested still
stays false for "none" (driven independently by deliveryPlan.requested),
so cron itself still never auto-announces -- only the agent's own
message-tool send benefits from having a real target. Verified safe
against the openclaw#91613 keyless-inherited-delivery regression guard, which
only fires for genuinely keyless jobs and never for session-scoped
ones like this.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@convyusboy
convyusboy requested a review from a team September 23, 2026 11:09

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 2 files

Reply with feedback, questions, or to request a fix.

Fix all with cubic | Re-trigger cubic

convyusboy and others added 2 commits September 23, 2026 21:49
cubic review feedback on #241:
- The bare and explicit-channel:"last" "still resolves" tests fed the
  identical resolver input (deliveryPlan.channel ?? "last" makes them
  equivalent) and asserted the identical result, so the second added
  no coverage. Merged them into one.
- Neither that test nor the "marks bare no-deliver runs delivered..."
  test actually asserted resolveDeliveryTarget was called with the
  job's session identity -- the openclaw#91613 keyless-refusal guard this PR's
  safety argument leans on was asserted about, never exercised. Both
  jobs used sessionTarget:"isolated" with no job-level sessionKey, so
  resolveCronDeliverySessionKey returned undefined regardless of what
  ran. Added an explicit sessionKey to each job and strengthened both
  assertions to check resolveDeliveryTarget's actual call args
  (channel + sessionKey), so a regression that silently drops the
  sessionKey through would now fail these tests.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
CI (check-test-types) caught what my local tsgo:core run didn't:
tsgo:core only type-checks production code, not test files -- the
actual test-type-checking lane is check:test-types, a separate
command I hadn't run for the previous commit.

`{ ...makeMessageToolPolicyJob(...), sessionKey }` spreads a value
whose static type is `never` (the helper casts its return with
`as never`), which TypeScript rejects: "Spread types may only be
created from object types." Added an `overrides` param to the helper
itself so the extra field gets folded in before the `as never` cast,
instead of spreading a never-typed expression at each call site.

Co-Authored-By: Claude Sonnet 5 <[email protected]>

@augusteo augusteo left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blocking finding: delivery.mode: none can resolve to a shared main-session recipient and send a recheck result to the wrong peer. See the inline P1 finding. Please preserve the trusted origin route or fail closed for shared-main sessions, and add a two-peer regression.

Comment thread src/cron/isolated-agent/run.ts Resolved
… crons

Review feedback on #241 (P1, real bug, not the automated bot): the
openclaw#91613 keyless-inherited-delivery refusal only fires when
`!rawSessionKey` -- but under `dmScope: "main"`, every DM peer's
runSessionKey collapses onto the identical `agent:<id>:main` key.
That key is non-empty (so the refusal never triggered), but it's
still the exact same shared, last-writer-wins bucket openclaw#91613 exists to
guard. browser-handoff schedules its recheck as
`session:<runSessionKey>` with delivery mode "none" -- exactly this
shape under dmScope:"main".

Concretely: peer A's browser-handoff flow schedules a recheck against
the shared session. Before it fires, peer B messages the same agent,
overwriting the shared bucket's lastChannel/lastTo to B's room. When
A's recheck resolves delivery via channel:"last", it reads B's
lastTo -- A's terminal result (e.g. "you're signed in") would be
delivered to B's room instead of A's.

Added `sessionKeyIsSharedMainBucket`: true when a job's OWN sessionKey
canonicalizes to the literal shared main-session key, independent of
whether resolution happened to fall through to `mainEntry` by
reference. Kept it a separate OR term rather than folding into
`usedSharedMainFallback` unconditionally -- a cron with its own
distinct, not-yet-materialized sessionKey also has
`main === mainEntry` by coincidence (loadSessionEntry returns
undefined for a session that doesn't exist yet), and that case must
stay exempt (existing "KEYED cron... falls back to the main entry"
test covers it, confirmed still passing).

Added two regression tests: a direct case (job's own sessionKey IS the
shared bucket) and the interleaved two-peer scenario from the review
comment (peer B overwrites the bucket before peer A's recheck fires).
Both confirmed via deliberate revert-then-fail before restoring the
fix.

A fuller fix -- letting scheduleSessionTurn callers pin the true
originating channel/recipient as turnSource* at schedule time, so
resolution never needs the shared bucket at all for session-scoped
jobs -- would require adding new fields to the public plugin-sdk
`PluginSessionTurnScheduleParams` contract (host-hooks.ts) plus
runtime wiring and a BrowserHandoffToolContext update to carry
current-channel info. That's real, valuable follow-up work but
separate SDK-boundary scope from this fix; noting it here rather than
scope-creeping this PR.

Co-Authored-By: Claude Sonnet 5 <[email protected]>

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 2 files (changes from recent commits).

Heads up: you’re close to your included review allowance. Set a flex budget so reviews don’t pause.

Tip: Review your code locally with the cubic CLI to iterate faster.

Fix all with cubic | Re-trigger cubic

…pe:"global"

cubic-dev-ai flagged that sessionKeyIsSharedMainBucket (62609f7) still let a
global-scope agent's implicit recheck inherit an unrelated peer's last-written
target: resolveAgentMainSessionKey ignores session.scope, and
resolveCronAgentSessionKey mangled the literal "global" session key into a
synthetic "agent:<id>:global" key nothing ever writes to, so neither side of
the comparison pointed at the real shared session file.

- delivery-target.ts: compute mainSessionKey via resolveMainSessionKey(cfg)
  under scope:"global", mirroring the existing
  resolveCronAwarenessMainSessionKey pattern in delivery-dispatch.ts.
- session-key.ts: bypass per-agent key mangling for a literal "global"
  sessionKey under scope:"global", matching gateway's
  canonicalizeSessionKeyForAgent global-literal handling.
- Added a regression test; verified via revert-then-fail on each of the two
  changes independently before restoring.

Co-Authored-By: Claude Sonnet 5 <[email protected]>

@augusteo augusteo left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-reviewed exact head 144a80f against base 476b3aa. The prior shared-recipient finding is addressed: the delivery resolver now refuses keyed sessions that canonicalize to the shared agent-main bucket under dmScope:"main", and to the literal global bucket under session.scope:"global", instead of inheriting another peer's lastTo. Exact-head CI passed; the isolated-agent shard executed run.message-tool-policy.test.ts (51 tests) and delivery-target.issue-91613.test.ts (8 tests), and check-test-types passed. git diff --check passed. Local tests were not run separately.

Scope note: in shared-main/global sessions with no captured origin route or explicit recipient, delivery intentionally fails closed; the message tool still has no implicit destination in those configurations. That prevents misdelivery but is not a successful send path there. Non-blocking cleanup: run.ts:406-408 still describes the refusal as limited to !rawSessionKey, while the guard now also covers keyed shared buckets.

@convyusboy
convyusboy merged commit 21933b7 into boon Sep 25, 2026
146 of 147 checks passed
@convyusboy
convyusboy deleted the ridho/cron-none-delivery-target-resolution branch September 25, 2026 16:41
convyusboy added a commit that referenced this pull request Sep 28, 2026
…249)

* chore(release): bump version 2026.6.11-boon.46 -> 2026.6.11-boon.47

Root version, 135 plugin manifests synced via scripts/sync-plugin-versions.ts, changed npm-shrinkwrap.json files regenerated, CHANGELOG section for boon.47.

Shipping: #236/#239 (a plugin tool's own execute() handler can now reliably schedule/unschedule a cron-backed session turn, fixing the browser-handoff recheck across three sequential live-found bugs), #240 (recheck backoff cap tightened 5m -> 2m), #242 (recheck messages the customer before attaching the browser), #241 (delivery.mode: "none" cron jobs can deliver an explicit message-tool send), #243 (Chrome MCP stderr drained before connect, not after), #247 (distinct exec-trajectory label for boon-projects schedule append/list), ENG-20030 (shared turn-resume-instruction wording for boon-core/anychat-boon-web), #248 (Docker build no longer OOMs 8 GB CI runners).

Base = 2026.6.11-boon.46. Gateway plus @openclaw/slack, @openclaw/msteams and @openclaw/diagnostics-prometheus bumped in lockstep; no separately published plugin source changed in this train, so a gateway roll delivers all of it.

Co-Authored-By: Claude Sonnet 5 <[email protected]>

* fix(release): regenerate stale extension npm-shrinkwrap.json versions for boon.47

pnpm plugins:sync bumps each plugin's package.json version but does not touch its checked-in npm-shrinkwrap.json, so 65 published extension shrinkwraps still embedded version 2026.6.11-boon.46 despite package.json already reading boon.47. Since npm-shrinkwrap.json ships inside the npm artifact, this would have published every affected plugin with a mismatched embedded version.

Bumped the version field(s) in all 65 (plus the openclaw peerDependency range where present) to 2026.6.11-boon.47, matching the pattern boon.46's bump commit already applied to these same files.

Co-Authored-By: Claude Sonnet 5 <[email protected]>

---------

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants