mirror of
https://github.com/HKUDS/DeepTutor.git
synced 2026-12-02 17:40:18 +08:00
`_begin_turn_sync` refuses a new turn while the session owns any row in queued/running/waiting_input. That is right while a turn is alive and catastrophic once one is not: a single row left behind by a lost worker, a dropped socket or a restart blocked every later message in that session, with no way out from the UI. Reporters described it precisely — one window, no refresh, a conversation that never accepted another word (#1297, #1359). v1.6.7 closed the paths that manufacture those rows, but said nothing about the ones already there. It shipped with "existing rows still need clearing by hand" as a known issue, because the obvious fix — a periodic sweep — needs an age threshold or it cancels a turn between its INSERT and its first lease renewal, the worst failure a chat product has. Reclaiming at the point of conflict removes that hazard rather than managing it. The only rows ever considered are ones already blocking a real request, so there is no window to get wrong, no timer, and no threshold to guess. On a restart the leases are gone, so the first message the user sends clears the row and goes through — the outcome the sweep was for, without the sweep. Liveness is the lease, never the row's age. A turn parked on an `ask_user` card emits no events, so `updated_at` stops advancing while a person is simply taking their time to answer; a live worker renews its lease every few seconds whether or not it is producing output. So "no lease" is the one signal that separates a zombie from a slow reader, and a turn whose lease is live still gets its conflict — pinned by a test, because that is what keeps this from becoming a way to run two turns on one session. Also names the exception. Both stores raised a bare RuntimeError with the conflict spelled in the message; `ActiveTurnConflict` subclasses it, so every existing handler keeps working, and a caller that can do something about a stale row no longer has to match on text. 6921 passed, 24 skipped.