#13638: fix: pass delivery context to cron isolated agent subagents
stale
Cluster:
Cron Job Enhancements
## Problem
Subagents spawned from cron isolated sessions lose the Slack delivery context, causing `Delivering to Slack requires target` errors when the announce flow tries to deliver results.
## Root Cause
In `src/cron/isolated-agent/run.ts`, the call to `runEmbeddedPiAgent()` was missing `messageTo` and `messageThreadId` parameters. These values were correctly resolved from `resolvedDelivery` but never passed through, so all downstream tools (including `sessions_spawn`) received `undefined` as the delivery target.
The cron job's own direct announce path correctly uses `resolvedDelivery.to`. The bug is specifically in the subagent spawn path where delivery context is lost at the `runEmbeddedPiAgent` boundary.
## Fix
Pass `messageTo` and `messageThreadId` from `resolvedDelivery` to `runEmbeddedPiAgent()`, matching the pattern used in `src/auto-reply/reply/agent-runner-execution.ts`.
2 lines added.
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This PR fixes a delivery context propagation bug in cron isolated agent sessions. The fix adds `messageTo` and `messageThreadId` parameters to the `runEmbeddedPiAgent()` call, ensuring that subagents spawned from cron jobs inherit the Slack delivery context from their parent.
- Adds `messageTo: resolvedDelivery.to` and `messageThreadId: resolvedDelivery.threadId` to the `runEmbeddedPiAgent()` call in `src/cron/isolated-agent/run.ts:410-411`
- Matches the pattern used in `src/auto-reply/reply/agent-runner-execution.ts:264-265`
- Prevents `Delivering to Slack requires target` errors when subagents attempt to announce results
<h3>Confidence Score: 5/5</h3>
- This PR is safe to merge with minimal risk
- The fix is a straightforward 2-line addition that passes existing delivery context parameters to `runEmbeddedPiAgent()`. The parameters (`messageTo` and `messageThreadId`) are already defined in the function signature, already resolved from `resolvedDelivery`, and already used consistently throughout the file in other delivery paths. This pattern exactly matches the established pattern in `agent-runner-execution.ts:264-265`.
- No files require special attention
<!-- greptile_other_comments_section -->
<sub>(2/5) Greptile learns from your feedback when you react with thumbs up/down!</sub>
<!-- /greptile_comment -->
Most Similar PRs
#13383: fix(cron): route text-only payloads through direct delivery
by Masha-L · 2026-02-10
84.5%
#12310: cron: pass agentDir to embedded runner for isolated sessions
by magendary · 2026-02-09
83.9%
#22845: Pass agentDir through cron and followup embedded runs
by seilk · 2026-02-21
83.7%
#22707: fix: pass agentDir to runEmbeddedPiAgent in cron isolated sessions
by mrlerner · 2026-02-21
83.5%
#11216: Fix nightly failures: cron webchat delivery result + media cleanup ...
by DeanoC · 2026-02-07
83.1%
#6007: fix(cron): auto-map agentId to accountId for Discord deliveries
by dwfinkelstein · 2026-02-01
82.9%
#6522: fix(cron): deliver original message when agent response is heartbea...
by sidmohan0 · 2026-02-01
82.5%
#21646: fix(cron): pass agentDir to runEmbeddedPiAgent for correct auth res...
by zhangjunmengyang · 2026-02-20
81.6%
#11816: fix(cron): forward agent-specific exec config to isolated cron sess...
by AnonO6 · 2026-02-08
81.6%
#8097: fix: auto-convert one-shot reminders for reliable delivery
by Gerrald12312 · 2026-02-03
81.3%