[Session] Release aborted streaming turns through the normal release path (#42330)

This commit is contained in:
Liangsheng Yin
2026-10-03 22:30:25 -07:00
committed by GitHub
parent 1315d171a0
commit 048b2a07f3
3 changed files with 69 additions and 38 deletions
+14 -21
View File
@@ -182,8 +182,9 @@ class StreamingSession:
)
def try_cache_finished_req(self, req: Req) -> bool:
"""Handles a streaming-session finish (save slot / mid-abort nuke).
Returns True if handled; False means caller runs its raw path."""
"""Hands a turn's row to the session slot when it finishes or is
retracted. Returns False for non-streaming requests and aborts, which
the caller releases."""
if not _is_streaming(req):
return False
@@ -191,28 +192,20 @@ class StreamingSession:
session_id = req.session.session_id
slot = self.slots.get(session_id)
is_first = slot is None
# Mid-processing abort: free all session KV and drop the slot; req_nodes
# still points at the last finished request, so the next turn re-prefills.
if isinstance(req.finished_reason, FINISH_ABORT):
kv = req.detach_kv()
if slot is None:
# First turn: a throwaway slot lets release_session free the
# record (mamba refs included) and drop the tree lock.
slot = SessionSlot(
kv=kv,
last_node=req.last_node,
lock_receipt=req.lock_receipt,
swa_prefix_lock_released=req.swa_prefix_lock_released,
)
self.slots[session_id] = slot
else:
assert kv is slot.kv
self.release_session(session_id)
if slot is not None:
# The turn ran on the slot's record, which the caller releases
# (row and mamba state): drop the slot with its tree lock. The
# session keeps its last finished request and re-prefills next turn.
assert slot.kv is req.kv
del self.slots[session_id]
if slot.last_node is not None:
skip = {"skip_swa": True} if slot.swa_prefix_lock_released else {}
self.cache.dec_lock_ref(slot.last_node, slot.lock_receipt, **skip)
req.session.abort_req()
return True
return False
is_first = slot is None
if is_first:
slot = SessionSlot()
self.slots[session_id] = slot