Files
coder/enterprise/coderd/dormancy
Ethan 9b8d880d63 fix: exempt service accounts from user dormancy (#30824)
Closes CODAGT-1344

The Slack bot for Coder Agents (CODAGT-1098) runs inside coderd and acts
as a service account that an admin picks. It creates chats and sends
messages as that account through Go calls, not HTTP requests. Two
dormancy rules break it:

1. **New service accounts start dormant.** The CLI and the web "Create
user" page send no status, and `InsertUser` falls back to `dormant`. So
the bot's account is dormant from the start.
2. **Accounts go dormant after 90 days without a "last seen" update.**
Only the API key middleware updates `last_seen_at`, and only on HTTP
requests. The bot never sends any, so its account goes dormant on day
90, even if people use the bot every day.

A chat owner must be active, so once the bot's account is dormant, every
Slack mention fails. Any other in-process integration that acts as a
service account has the same problem.

Dormancy does nothing useful for service accounts:

- It exists to free license seats, and service accounts never take a
license seat (#24401, #27279).
- It isn't a lock. Any API request activates a dormant account again.
- System users already skip the dormancy job for the same reason.

So this PR:

- creates service accounts as active when the request doesn't set a
status,
- rejects an explicit dormant status for a service account with a 400,
- skips service accounts in the dormancy job, the same way it already
skips system users.

Side effects: a service account that nobody uses for 90 days now stays
active. That has no effect on license seats. If the account has ever
sent traffic through AI Gateway, it also keeps its AI Governance seat
until an admin suspends or deletes it. That matters less than it sounds:
AI Governance is now included with Premium rather than sold per seat
(#27545), so the seat only counts on a license that still has an AI
Governance seat limit, and there it only feeds the seat-limit warning.
The dormancy job also no longer writes "marked dormant" audit entries
for service accounts.

I've left existing dormant service accounts alone rather than adding a
migration. An admin can activate one, and any API request from it
activates it too.

---

_This PR description was written by Coder Agents._
2026-10-23 12:53:40 +11:00
..