fix: cancel abandoned generation tasks

- Propagate stream closure and stop-sequence termination into scheduler cancellation
- Defer active KV release to the scheduler owner and close metrics safely
- Expose lifecycle counters and cover waiting, active, and allocation-race cleanup
This commit is contained in:
0z5a
2026-09-02 12:55:05 +08:00
parent 90de5bc1bd
commit 9c3ef0c2a1
10 changed files with 410 additions and 130 deletions
+9 -3
View File
@@ -73,15 +73,21 @@ def test_task_manager_remove_task():
assert len(tm.waiting_queue) == 0
def test_task_manager_remove_active_task():
def test_task_manager_cancel_active_task_defers_removal():
tm = TaskManager(tokenizer=_make_mock_tokenizer())
tid = tm.add_task("test")
tasks = tm.pull_candidates(1)
tm.activate(tasks[0])
assert len(tm.active_tasks) == 1
removed = tm.remove_task(tid)
assert len(removed) == 1
immediate, cancelled = tm.cancel_task(tid)
assert cancelled is True
assert immediate == []
assert tm.active_tasks[0].status == TaskStatus.ABORTED
removed = tm.remove_finished_tasks([])
assert removed == tasks
assert len(tm.active_tasks) == 0
assert tm.get_stats()["cancelled_total"] == 1
def test_task_manager_pull_candidates_fifo():