fix: classify upstream failures and prevent empty billed responses

This commit is contained in:
wlx committed 2026-09-28 04:55:00 +08:00
1 parent b455d8d79f
commit 9acc69d4c7
28 files changed
+1449 -131

No files matched your search

@@ -50,6 +50,7 @@ moyi:
tasks:
max-queued-per-model: ${TASK_MAX_QUEUED_PER_MODEL:100}
worker-interval-ms: ${MOYI_TASK_WORKER_INTERVAL_MS:1000}
provider-timeout-ms: ${MOYI_TASK_PROVIDER_TIMEOUT_MS:3600000}
web:
cors-origins: ${CONTROL_PLANE_CORS_ORIGINS:http://localhost:5173,http://127.0.0.1:5173}
auth:
@@ -0,0 +1,10 @@
-- Persist the polling deadline: process restarts must not reset the timeout.
ALTER TABLE model_tasks ADD COLUMN provider_deadline_at timestamptz;
-- Existing accepted tasks also need a finite deadline. Unsubmitted queued
-- tasks receive theirs only after the upstream accepts their submission.
UPDATE model_tasks
SET provider_deadline_at = created_at + INTERVAL '1 hour'
WHERE status IN ('queued', 'running')
AND provider_task_id IS NOT NULL
AND provider_task_id <> 'mock';
@@ -2,8 +2,18 @@ local time = redis.call('TIME')
local now = tonumber(time[1]) * 1000 + math.floor(tonumber(time[2]) / 1000)
redis.call('ZREMRANGEBYSCORE', KEYS[1], '-inf', now)
redis.call('ZREMRANGEBYSCORE', KEYS[2], '-inf', now)
if redis.call('ZCARD', KEYS[1]) >= tonumber(ARGV[1]) then return 0 end
if redis.call('ZCARD', KEYS[2]) >= tonumber(ARGV[2]) then return 2 end
redis.call('ZREMRANGEBYSCORE', KEYS[3], '-inf', now)
local busy = nil
if redis.call('ZCARD', KEYS[1]) >= tonumber(ARGV[1]) then busy = 0
elseif redis.call('ZCARD', KEYS[2]) >= tonumber(ARGV[2]) then busy = 2 end
if busy ~= nil then
if tonumber(ARGV[5]) > 0 then
redis.call('ZADD', KEYS[3], now + tonumber(ARGV[5]), ARGV[4])
redis.call('PEXPIRE', KEYS[3], ARGV[6])
end
return busy
end
redis.call('ZREM', KEYS[3], ARGV[4])
redis.call('ZADD', KEYS[1], now + tonumber(ARGV[3]), ARGV[4])
redis.call('ZADD', KEYS[2], now + tonumber(ARGV[3]), ARGV[4])
redis.call('PEXPIRE', KEYS[1], ARGV[3])