Repository navigation
fix(cron): resolve delivery target for delivery.mode "none" jobs - #241
Conversation
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]>
There was a problem hiding this comment.
All reported issues were addressed across 2 files
Reply with feedback, questions, or to request a fix.
Fix all with cubic | Re-trigger cubic
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
left a comment
There was a problem hiding this comment.
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.
… 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]>
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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.
…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]>
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: anydelivery.mode: "none"job without an explicit channel/to/threadId/accountId on its own delivery config (!hasExplicitCronDeliveryTarget) got a hard-coded, emptyresolvedDelivery(ok: false,channel: undefined,to: undefined) —resolveDeliveryTarget()was never called at all.That short-circuit conflated two different things:
mode: "none"is supposed to suppress — already handled independently viadeliveryPlan.requested(resolveCronDeliveryPlansetsrequested: resolvedMode === "announce", so it'sfalsefor"none"regardless of this fix).message(action="send")call, whichresolveCronSourceDeliveryPlan'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-awarenesstargetfromresolvedDelivery— but the short-circuit above had already wipedresolvedDeliveryto nothing before it got there, so a browser-handoff recheck (session-scopedmode: "none", no explicit per-job channel/to) had no channel ortofor its own message-tool send to fall back to.Removed the short-circuit so
mode: "none"runs through the sameresolveDeliveryTarget()call as every other mode.deliveryRequestedstill staysfalsefor"none"(driven independently bydeliveryPlan.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
#91613keyless-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/sessionKeyset) 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
journalctl --user -u openclaw-gateway.serviceshowed[tools] message failed: Action send requires a target.immediately after amode: "none"recheck's terminal message attempt); traced the exact code path viamessage-action-normalization.ts→run-executor.ts'sresolveCurrentChannelTarget→run.ts'sresolveCronDeliveryContext.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 (assertedresolveDeliveryTargetwas skipped / target stayed unresolved for baremode: "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 inrun.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."mode: "none"jobs without an explicit per-job channel/to short-circuited to an empty resolved delivery target, skippingresolveDeliveryTarget(). Now they resolve a target like every other mode; cron's own auto-announcement stays suppressed for"none", sincedeliveryRequestedis driven independently by the delivery plan.dmScope:"main", peer runSessionKeys collapse toagent:<id>:main; undersession.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.resolveDeliveryTargetis called with the job's ownsessionKey, and the fixture helper gained anoverridesparam instead of spreading anever-typed value.Written for commit 144a80f. Summary will update on new commits.