#6007: fix(cron): auto-map agentId to accountId for Discord deliveries
Cluster:
Cron Job Enhancements
## Summary
When a cron job with `agentId` is configured to deliver to Discord, this change automatically uses the matching Discord `accountId` if one exists with the same name.
## Problem
Currently, isolated cron jobs with `agentId: "agent-b"` that use `deliver: true` send messages from the default Discord account instead of the matching `agent-b` account.
## Solution
In `resolveDeliveryTarget()`, after resolving the `accountId` from the session:
1. If `accountId` is still undefined
2. And the channel is `discord`
3. And `agentId` matches a configured Discord account ID
Then use `agentId` as the `accountId`.
## Example
Config:
```yaml
agents:
list:
- id: agent-b
channels:
discord:
accounts:
agent-b:
token: "..."
default:
token: "...(agent-a's token)..."
```
Before: Cron job with `agentId: "agent-b"` sends from default account.
After: Cron job with `agentId: "agent-b"` sends from agent-b account.
Fixes #3985
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This PR updates `resolveDeliveryTarget` for isolated-agent cron jobs to prefer a Discord `accountId` that matches the cron job’s `agentId` when the session doesn’t already provide an `accountId`. The goal is to prevent Discord deliveries from falling back to the default account when running agent-scoped cron jobs.
The change fits into the outbound routing flow by keeping session-based resolution as the primary source of truth, then adding a Discord-specific fallback before `resolveOutboundTarget` docks/normalizes the destination.
<h3>Confidence Score: 4/5</h3>
- This PR is likely safe to merge; the change is localized and low-risk but has one edge-case behavior change to confirm.
- Only one file changes, and it adds a straightforward fallback for Discord `accountId` resolution. Main risk is unintended override when `agentId` equals a reserved/shared Discord account ID (e.g., `default`).
- src/cron/isolated-agent/delivery-target.ts
<!-- greptile_other_comments_section -->
<sub>(4/5) You can add custom instructions or style guidelines for the agent [here](https://app.greptile.com/review/github)!</sub>
**Context used:**
- Context from `dashboard` - CLAUDE.md ([source](https://app.greptile.com/review/custom-context?memory=fd949e91-5c3a-4ab5-90a1-cbe184fd6ce8))
- Context from `dashboard` - AGENTS.md ([source](https://app.greptile.com/review/custom-context?memory=0d0c8278-ef8e-4d6c-ab21-f5527e322f13))
<!-- /greptile_comment -->
Most Similar PRs
#13638: fix: pass delivery context to cron isolated agent subagents
by dario-github · 2026-02-10
82.9%
#11216: Fix nightly failures: cron webchat delivery result + media cleanup ...
by DeanoC · 2026-02-07
80.1%
#8097: fix: auto-convert one-shot reminders for reliable delivery
by Gerrald12312 · 2026-02-03
79.1%
#8507: fix: preserve accountId for multi-account agent-to-agent messaging
by djh58 · 2026-02-04
78.8%
#16390: fix(cron): jobs land in wrong agent session when agentId isn't in a...
by yinghaosang · 2026-02-14
78.5%
#13383: fix(cron): route text-only payloads through direct delivery
by Masha-L · 2026-02-10
78.3%
#16259: fix(cron): pass accountId through delivery path for multi-account c...
by ComputClaw · 2026-02-14
78.0%
#12310: cron: pass agentDir to embedded runner for isolated sessions
by magendary · 2026-02-09
77.7%
#7350: fix(cron): pass agentId and AccountId through heartbeat chain for m...
by codeslayer44 · 2026-02-02
77.6%
#22707: fix: pass agentDir to runEmbeddedPiAgent in cron isolated sessions
by mrlerner · 2026-02-21
77.4%