Files
DeepTutor/web/features/chat
Wenjun Li fdebb2761e fix(chat): keep parked ask_user turns alive across deletion and reload (#1789)
* fix(session): delete a message's own turn and refuse active-turn deletion

Resolve the owning turn via `turns.assistant_message_id` for assistant rows
and the user row's `metadata.turn_id`, falling back to the last turn created
at or before the user row for legacy data. The previous `created_at >=` match
selected the *next* turn, because a turn row is always written before its user
row (`begin_turn` -> `add_message`); deleting a completed turn's message could
therefore destroy a later `waiting_input` turn's record while its task still
held the session lease.

Refuse the delete whenever the resolved turn is in `ACTIVE_TURN_STATUSES`
(queued/running/waiting_input) instead of only "running"; the API answers 409
with "running or waiting for input".

* fix(chat): resubscribe a parked turn on load so its ask_user card survives a reload

A `waiting_input` turn keeps the session lease while it waits, and its
ask_user card exists only in the live event stream: no assistant row is
persisted until the turn settles. Loading a session only resubscribed
"running" turns, and through `sendThroughRunner`, whose retry gate drops a
non-streaming session -- so after a reload the card was unreachable while the
turn kept waiting, and the conversation could neither be answered nor used.

Parked turns now subscribe through the client's durable command queue (sent
once the socket opens), once per turn per tab. The replayed stream rebuilds
the card so it can be answered.

* test(chat): align the loader-gate assertion with the parked-turn resubscribe

The source-shape assertion pinned the previous loader line
(`if (loadedStatus === "running" && (activeTurn?.turn_id || activeTurn?.id))`).
The parked-turn resubscribe extracts `activeTurnId` first and adds a
`waiting_input` branch, so update the assertion to the new gate and cover the
parked branch's status check as well.
2026-10-07 20:37:04 +08:00
..
2026-09-21 02:30:40 +08:00
2026-09-03 01:38:54 +08:00
2026-09-03 01:38:54 +08:00