Skip to content

Commit d8125a5

Browse files
Alyx-MLclaude
andauthored
fix(server): usage-limit sweep stops scanning every run each tick (pingdotgg#21191)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent a523b00 commit d8125a5

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

‎apps/server/src/orchestration-v2/ProjectionStore.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3590,6 +3590,14 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =
35903590
LIMIT 1
35913591
)
35923592
WHERE t.deleted_at IS NULL
3593+
-- The sweep runs every scheduler tick. Without this list the latest-run
3594+
-- lookup above sorts every run of every thread, tens of milliseconds
3595+
-- for one long thread; only threads with a usage-limit failure qualify.
3596+
AND t.thread_id IN (
3597+
SELECT failure.thread_id FROM orchestration_v2_projection_turn_items failure
3598+
WHERE failure.type = 'error' AND failure.status = 'failed'
3599+
AND json_extract(failure.payload_json, '$.failure.class') = 'usage_limit'
3600+
)
35933601
AND json_extract(t.payload_json, '$.archivedAt') IS NULL
35943602
AND json_extract(t.payload_json, '$.settledOverride') IS NOT 'settled'
35953603
AND json_extract(item.payload_json, '$.failure.class') = 'usage_limit'

0 commit comments

Comments
 (0)