Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): usage-limit sweep stops scanning every run each tick #21191

MergedAlyx-ML(GitHub profile, opens in a new tab)merged 1 commit intomain fromrefs/pull/21191/headmerged by juliusmarminge View on GitHub

Showing 1 changed file with 8 additions and 0 deletions.

x
0 of 1 viewed, 1 left
8 additions and 0 deletionsapps/server/src/orchestration-v2/ProjectionStore.tsModified
View file
@@ -3580,6 +3580,14 @@
LIMIT 1
WHERE t.deleted_at IS NULL
+ -- The sweep runs every scheduler tick. Without this list the latest-run
+ -- lookup above sorts every run of every thread, tens of milliseconds
+ -- for one long thread; only threads with a usage-limit failure qualify.
+ AND t.thread_id IN (
+ SELECT failure.thread_id FROM orchestration_v2_projection_turn_items failure
+ WHERE failure.type = 'error' AND failure.status = 'failed'
+ AND json_extract(failure.payload_json, '$.failure.class') = 'usage_limit'
+ )
AND json_extract(t.payload_json, '$.archivedAt') IS NULL
AND json_extract(t.payload_json, '$.settledOverride') IS NOT 'settled'
AND json_extract(item.payload_json, '$.failure.class') = 'usage_limit'