hotfix: autoscaler queue_depth NULL depends_on blinded scaler

queue_depth turned a NULL depends_on into [None], and
ready_tasks then required None to be in completed_ids, so
such tasks never counted as ready. Worker pick_next was
unaffected (_task_from_row maps NULL to []), which is why
tasks still ran while the scaler always saw depth 0 and
never scaled up (proven live: depth probe with 1 queued
task returned 0). NULL now means no dependencies, with a
regression test.
This commit is contained in:
host committed 2026-10-26 07:13:45 +08:00
1 parent 951730e224
commit b74deffb26
2 files changed
+27 -1

No files matched your search

+18
View File
@@ -85,6 +85,24 @@ class QueueDepthTestCase(unittest.TestCase):
_set_status(self.db_path, "A", "completed")
self.assertEqual(queue_depth(self.db_path), 1)
def test_null_depends_on_counts_as_ready(self):
# 回归:depends_on 为 NULL 时必须算无依赖,不能变成
# [None] 导致任务永远不算就绪(scaler 致盲)。
conn = sqlite3.connect(self.db_path)
try:
now = time.time()
conn.execute(
"INSERT INTO tasks(id, project_id, prompt, status,"
" idempotency_key, depends_on, priority, created_by,"
" created_at, updated_at, last_heartbeat)"
" VALUES('N', 'p1', 'x', 'queued', NULL, NULL, 0,"
" 'tester', ?, ?, NULL)",
(now, now))
conn.commit()
finally:
conn.close()
self.assertEqual(queue_depth(self.db_path), 1)
def test_dependency_cycle_counts_zero(self):
_insert_task(self.db_path, "A", depends_on='["B"]')
_insert_task(self.db_path, "B", depends_on='["A"]')