Files
DeepTutor/deeptutor/app
Bingxi Zhao (Frank) 491a5a15cb follow-up to #1361: reclaim turns parked in waiting_input
Two paths left a durable row that blocked its whole session, because
`_begin_turn_sync` counts `waiting_input` as active and refuses every
later message with "Session already has an active turn" (#1297, #1359).

The terminal write on cancellation CAS'd on `expected_status="running"`
alone. A turn parked on `ask_user` sits at `waiting_input`, and the
waiter's restore to `running` is fired through `asyncio.shield` — so it
races that write and loses about as often as it wins. When it lost, nothing
terminal was written, no `done` event went out, and the row stayed
`waiting_input` forever: pressing Stop on a question was enough, no restart
needed. Both states are live and owned by the same execution, so both are
valid predecessors of its terminal state; the fencing token is still what
proves ownership.

`cancel_turn` also returned False when nothing held the lease, so Stop on a
card whose worker was gone was reported as a refusal the UI could not act on
while the row kept blocking the session. It now reaps, for the same reason
`submit_user_reply` does — and the reaper is widened to every live status
and renamed, since `queued` and `running` orphans block a session exactly
as `waiting_input` ones do.

NOT covered, deliberately: nothing sweeps rows left behind by a process that
died, because `MemoryCoordinator._known_turns` is per-process and
`list_expired_turn_ids()` is empty after a restart. That needs an age
threshold to avoid reaping a turn between its INSERT and its first lease
renewal, which is not a change to make unattended. This fixes the path that
*creates* the zombies; pre-existing rows still need that sweep.

(cherry picked from commit 5f040dbc9fc8be02f2281cf91c25e86f5991fa92)
2026-09-11 00:00:42 +08:00
..
2026-09-02 04:09:11 +08:00