fix: correctly iterate quote outcomes using computed_at
All checks were successful
deploy / deploy (push) Successful in 43s

Proof:
The quote outcomes logic was limited to checking the 1000 most recent submissions, meaning old trades during the 2 day downtime were never checked for completion once they fell out of the recent window. Fixed by using a LEFT JOIN to quote_outcome_attributions and filtering by computed_at so we correctly process batches of the backlog.

Assumptions:
The computed_at logic behaves identically to intent_request_outcomes.

Still fake:
N/A
This commit is contained in:
philipp 2026-06-16 16:18:22 +02:00
parent 35628de07a
commit 44b1b3128d

View file

@ -4475,18 +4475,26 @@ export async function refreshQuoteOutcomes(pool, {
submissionLimit = 1000,
inventoryLimit = 50000,
} = {}) {
const safeSubmissionLimit = Math.max(1, Number(submissionLimit) || 50000);
const safeSubmissionLimit = Math.max(1, Number(submissionLimit) || 1000);
const safeInventoryLimit = Math.max(1, Number(inventoryLimit) || 50000);
const submissionsResult = await pool.query(
`
SELECT event_id, observed_at, ingested_at, quote_id, payload
FROM (
SELECT event_id, observed_at, ingested_at, quote_id, payload
FROM trade_execution_results
WHERE payload->>'status' = 'submitted'
ORDER BY COALESCE(observed_at, ingested_at) DESC
WITH recent_submissions AS (
SELECT s.event_id, s.observed_at, s.ingested_at, s.quote_id, s.payload
FROM trade_execution_results s
LEFT JOIN ${QUOTE_OUTCOMES_TABLE} o
ON o.quote_id = s.quote_id
WHERE s.payload->>'status' = 'submitted'
AND (
o.quote_id IS NULL
OR o.outcome_status IN ('not_filled', 'submitted', 'awaiting_outcome')
OR COALESCE(s.observed_at, s.ingested_at) > o.computed_at
)
ORDER BY COALESCE(s.observed_at, s.ingested_at) DESC
LIMIT $1
) recent_submissions
)
SELECT event_id, observed_at, ingested_at, quote_id, payload
FROM recent_submissions
ORDER BY COALESCE(observed_at, ingested_at) ASC
`,
[safeSubmissionLimit],