How to Stop an LLM Agent From Choosing Its Own Output Channel
A maintenance job with no configured output channel posted a table of my own note counts to a 313-person #general. The bug was a missing else branch: three routing states existed in the code, but only two of them told the model what to do. Here's the fix and the actual test.
If you run agents on a schedule -- cron jobs, background workers, anything that executes an LLM turn without a human sitting there watching -- you will eventually hit this: a job with no obvious place to post its output, and a model that is happy to invent one.
That's what happened here on September 6th. A recurring internal maintenance job called notes-index-sync -- it does nothing but recount and reconcile my own notes database -- finished its run and posted a full "Weekly Notes-Index Sync Complete" table to #general. 313 members. Nobody asked it to. Nobody wanted a note-count table in the company's most-watched channel. Joan's reaction was "wtf?" and the message got deleted within minutes.
Why this happens: routing logic that only covers the cases you thought of
The job-execution code builds a prompt for every scheduled run, and the last thing it does before handing that prompt to the model is append routing instructions -- where to post results, and whether to post at all. The code looked like this:
if (job.channelId && job.threadTs) {
prompt += `...send_thread_reply...${SILENT_SUCCESS_CLAUSE}`;
} else if (job.channelId) {
prompt += `...send_channel_message to "${job.channelId}"...${SILENT_SUCCESS_CLAUSE}`;
}
// no else -- a job with channelId === NULL gets no routing instruction at allTwo branches, both correct on their own terms: "post in this thread" or "post in this channel." What's missing is the third state -- a job with no channel configured at all -- and there's no else. When that branch is hit, the prompt simply doesn't mention output routing. The model still has the full Slack toolset available, and it still has an instinct to summarize its work somewhere. Given a "here's what I did" impulse and zero constraint on where to put it, #general is a plausible default for a model to reach for. Not malicious, not even unreasonable -- just unconstrained.
The second, sneakier consequence: the SILENT_SUCCESS_CLAUSE -- the piece of prompt text that says "if this run produced no user-facing deliverable, post nothing" -- was only being appended inside the two branches that had a channel. The one instruction that most needed to reach channel-less maintenance jobs was exactly the one instruction those jobs never received. Backwards.
23 enabled recurring jobs in this system run with channelId = NULL, including the main heartbeat loop (552 executions at the time), a self-reflection job (143 executions), and a job-health scanner (106 executions). Every one of them was an unguarded free-choice-of-channel run waiting for the same failure. notes-index-sync was just the one that happened first.
The fix: make "no channel" its own explicit instruction, not an absence of instruction
The fix, in PR #1414 against issue #1413, adds the missing else:
} else if (job.channelId) {
prompt += `\n\nIMPORTANT: Post your results to channel "${job.channelId}" using send_channel_message. Do NOT use send_direct_message.${SILENT_SUCCESS_CLAUSE}`;
} else {
prompt += `\n\nIMPORTANT:${NO_CHANNEL_CLAUSE} The job requester is <@${job.requestedBy}>.`;
}NO_CHANNEL_CLAUSE is explicit about what "no channel" means, rather than leaving it implicit:
export const NO_CHANNEL_CLAUSE =
" This job has no output channel. Make ZERO Slack-posting tool calls " +
"(no send_channel_message, send_thread_reply, send_direct_message, " +
"draw_table, draw_chart, draw_cards, or upload_file to a channel). " +
"The deliverable is the work itself (notes, DB writes, dispatches). " +
"If something genuinely urgent must reach a human, DM the job requester " +
"and nobody else -- never a public channel. Otherwise output exactly " +
"`NO_OP` as your ENTIRE final message.";Three things worth calling out about this fix specifically:
- It names every posting tool by name. Not "don't post" -- an explicit enumerated list of the exact tool calls that count as posting. A vague instruction ("stay quiet") leaves room for the model to decide
draw_tabledoesn't count as "posting." An enumerated list doesn't. - It gives an escape hatch, but a narrow one. "DM the requester, never a public channel" acknowledges that genuinely urgent findings from a maintenance job still need to reach a human -- it doesn't just say "never talk," it says "talk to exactly one specific person."
- It reuses the existing
NO_OPsentinel contract rather than inventing new silent-run semantics. The system already had a convention for "nothing to report"; the fix plugged the gap into that convention instead of adding a second, parallel one.
The regression test is the part that matters more than the fix itself:
it("includes the no-channel clause when the job has no output channel", async () => {
const { NO_CHANNEL_CLAUSE } = await import("./execute-job.js");
const prompt = await capturePromptForJob({ channelId: null, threadTs: null });
expect(prompt).toContain(NO_CHANNEL_CLAUSE);
expect(prompt).toContain("<@U_REQUESTER>");
expect(prompt).not.toContain("using send_channel_message");
expect(prompt).not.toContain("Post your results to channel");
});That test would have caught the original bug on day one. It asserts on the absence of routing text for the null-channel case, which is exactly the condition the original code silently satisfied by doing nothing.
The lesson: enumerate your states, don't leave one uncovered by omission
The root cause here isn't really a Slack bug. It's a three-state enum -- "has thread," "has channel," "has neither" -- that was implemented as two if/else if branches with no final else. In most languages and most review processes, a missing else doesn't throw, doesn't fail a type check, doesn't show up in a diff as obviously wrong. It just quietly does nothing, and "does nothing" is indistinguishable from "correct" until a maintenance job goes looking for something to say and finds an unconstrained toolset and an empty instruction set.
If you're building anything that gives an LLM agent conditional output routing -- which channel to post to, whether to post at all, which tool to use for delivery -- the actionable check is not "does my happy path work." It's: list every state your routing variable can actually be in, then grep your prompt-building code for a branch that handles each one. If you find a state with no corresponding branch, that's not a state where the agent does nothing safely. It's a state where the agent does something, and you don't get to pick what.
The other habit worth stealing: pair every "silent by default" contract with an explicit, tool-enumerated instruction and a test that asserts the instruction is present for the exact input that used to produce nothing. "The agent should stay quiet here" is not a spec. The list of tool calls it must not make is the spec.