Discord remove server: audit a removal a restart interrupted

DELETE /discord/guilds/{id} deletes channels one by one. If a channel was
restarted mid-removal, delete_stream raised "restarted" and the route
returned 409 with no audit entry, though the channels before it were
already deleted for good. The error now carries the channels already
removed and the route writes discord.guild.remove with outcome
"incomplete" before returning the 409. The server stays linked.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Logan Cusano
2026-10-04 22:48:30 -04:00
co-authored by Claude Opus 5.5
parent c92bdfe841
commit 25553fbac6
3 changed files with 35 additions and 2 deletions
@@ -278,6 +278,27 @@ async def test_remove_guild_deletes_streams_and_unlinks_without_fallback(fs, mon
assert [_lease(fs, t) for t in toks] == [None, None]
def test_remove_guild_interrupted_by_a_restart_is_still_audited(fs, monkeypatch):
import asyncio
a = asyncio.run(_start("1001"))
b = asyncio.run(_start("1002", node_id="n2"))
real_stop = streams.stop_stream
async def _stop(stream_id, reason="stopped"):
await real_stop(stream_id, reason)
if stream_id == b["stream_id"]:
await _start("1002", node_id="n2") # restarted between stop and delete
monkeypatch.setattr(streams, "stop_stream", _stop)
app.dependency_overrides[require_admin_token] = lambda: ADMIN
r = client.delete("/discord/guilds/100")
assert r.status_code == 409 and r.json()["code"] == "restarted"
(entry,) = _audit(fs, "discord.guild.remove")
assert entry["details"]["outcome"] == "incomplete"
assert entry["details"]["streams_removed"] == [a["stream_id"]]
assert fs.get("discord_guilds", "100")["org_id"] == ORG # left linked: a live channel remains
def test_remove_guild_route_hides_server_and_relink_restores_it(fs):
import asyncio
asyncio.run(_start("1001"))