From e45711aa74008ccacb23d67fd7847d924962cbe1 Mon Sep 17 00:00:00 2001 From: Saty <5752427+SatyPardus@users.noreply.github.com> Date: Tue, 20 Oct 2026 02:09:31 +0200 Subject: [PATCH] Returned batches drop their saved compile and merged files Only a merge uses them and a returned batch never merges; verification returns left them behind (32 GB of saved checks, 9.5 GB of results on the live database). Co-Authored-By: Claude Opus 5.5 --- src/server/batches.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/server/batches.js b/src/server/batches.js index 5c2bb2f..578ec48 100644 --- a/src/server/batches.js +++ b/src/server/batches.js @@ -21,10 +21,17 @@ export function returnBatch(store, batchId, reason) { ); } store.run(`UPDATE batches SET state = 'returned', result_json = json_set(COALESCE(result_json, '{}'), '$.returned', ?) WHERE id = ?`, reason, batchId); - store.run('DELETE FROM batch_checks WHERE batch_id = ?', batchId); + dropMergeData(store, batchId); store.event('batch_returned', b.user_id, { batch: batchId, reason }); } +// What only a merge needs (the verification's compile, the merged files): a returned batch never +// merges, and with a header change it can be hundreds of megabytes. +export function dropMergeData(store, batchId) { + store.run('DELETE FROM batch_checks WHERE batch_id = ?', batchId); + store.run(`UPDATE batches SET result_json = json_remove(result_json, '$.check', '$.mergedFiles') WHERE id = ? AND json_valid(result_json)`, batchId); +} + // Attempts still on their way to main; the others were sent back or rejected. export const LIVE_STATES = ['queued', 'verifying', 'peer_review', 'in_review', 'approved', 'merging']; @@ -33,7 +40,8 @@ export function settleBatch(store, batchId, reason) { if (!batchId) return; const ph = LIVE_STATES.map(() => '?').join(','); if (store.get(`SELECT 1 FROM attempts WHERE batch_id = ? AND state IN (${ph})`, batchId, ...LIVE_STATES)) return; - store.run(`UPDATE batches SET state = 'returned', result_json = json_set(COALESCE(result_json, '{}'), '$.returned', ?) WHERE id = ? AND state = 'open'`, reason, batchId); + const r = store.run(`UPDATE batches SET state = 'returned', result_json = json_set(COALESCE(result_json, '{}'), '$.returned', ?) WHERE id = ? AND state = 'open'`, reason, batchId); + if (r.changes) dropMergeData(store, batchId); } /** Attempts of a batch with their task's symbol. */