← Back to PRs

#6007: fix(cron): auto-map agentId to accountId for Discord deliveries

by dwfinkelstein open 2026-02-01 06:04 View on GitHub →
## 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