66import {
77 cancelWatch ,
88 claimWatchAlertDispatch ,
9- deleteTerminalWatchesOlderThan ,
10- deleteWatchSubmissionsOlderThan ,
119 listExpiredActiveWatches ,
1210 listWatchBatchGroupsToArm ,
1311 listWatchesAwaitingDelivery ,
@@ -57,12 +55,6 @@ export const WATCH_DELIVERY_GRACE_MS = 5 * 60 * 1000;
5755/** Per-run cap for each half of the sweep. Oldest first, so the rest land next run. */
5856const SWEEP_BATCH_LIMIT = 100 ;
5957
60- /** How long a terminal watch is kept. Its outcome also lives in the chat transcript. */
61- export const WATCH_RETENTION_MS = 7 * 24 * 60 * 60 * 1000 ;
62-
63- /** Higher than the other caps: retention is one statement, not a row-at-a-time loop. */
64- const RETENTION_BATCH_LIMIT = 500 ;
65-
6658/**
6759 * How many rows one sweep handles at once. An incident expires a whole group together, and a
6860 * bound is what stops one slow tenant spending the entire visibility window.
@@ -91,10 +83,6 @@ export type WatchSweepResult = {
9183 redelivered : number ;
9284 /** Decided but not handed over, with no agent project. They stay owed. */
9385 deliveryDeferred : number ;
94- /** Long-terminal rows dropped by retention. */
95- purged : number ;
96- /** Ledger rows dropped by retention. */
97- purgedSubmissions : number ;
9886 failed : number ;
9987} ;
10088
@@ -113,10 +101,6 @@ export type WatchSweepDeps = {
113101 deliver ?: ( watch : Watch ) => Promise < void > ;
114102 /** Gates the delivery half only. Finalization never depends on it. */
115103 configured ?: ( ) => boolean ;
116- /** Drop terminal rows older than `before`. Returns how many went. */
117- purgeTerminal ?: ( params : { before : Date ; limit : number } ) => Promise < number > ;
118- /** Drop submission-ledger rows older than `before`. */
119- purgeSubmissions ?: ( params : { before : Date ; limit : number } ) => Promise < number > ;
120104 /** How many rows are handled at once. */
121105 concurrency ?: number ;
122106} ;
@@ -332,11 +316,6 @@ export async function sweepDashboardAgentWatches(
332316 const listAwaitingDelivery =
333317 deps . listAwaitingDelivery ??
334318 ( ( params ) => listWatchesAwaitingDelivery ( dashboardAgentDb , params ) ) ;
335- const purgeTerminal =
336- deps . purgeTerminal ?? ( ( params ) => deleteTerminalWatchesOlderThan ( dashboardAgentDb , params ) ) ;
337- const purgeSubmissions =
338- deps . purgeSubmissions ??
339- ( ( params ) => deleteWatchSubmissionsOlderThan ( dashboardAgentDb , params ) ) ;
340319
341320 const result : WatchSweepResult = {
342321 overdue : 0 ,
@@ -347,8 +326,6 @@ export async function sweepDashboardAgentWatches(
347326 undelivered : 0 ,
348327 redelivered : 0 ,
349328 deliveryDeferred : 0 ,
350- purged : 0 ,
351- purgedSubmissions : 0 ,
352329 failed : 0 ,
353330 } ;
354331
@@ -435,18 +412,6 @@ export async function sweepDashboardAgentWatches(
435412 }
436413 }
437414
438- // Retention runs last, over rows both halves are finished with. Its own try/catch so a
439- // lost retention pass can't mask the other failures.
440- try {
441- const before = new Date ( now . getTime ( ) - WATCH_RETENTION_MS ) ;
442- result . purged = await purgeTerminal ( { before, limit : RETENTION_BATCH_LIMIT } ) ;
443- // The ledger's rows age out on the same window: past it no client is still retrying.
444- result . purgedSubmissions = await purgeSubmissions ( { before, limit : RETENTION_BATCH_LIMIT } ) ;
445- } catch ( error ) {
446- result . failed ++ ;
447- logger . error ( "Dashboard agent watch sweep: failed to purge terminal watches" , { error } ) ;
448- }
449-
450415 if ( result . failed > 0 ) {
451416 throw new Error ( `The dashboard agent watch sweep failed on ${ result . failed } watches` ) ;
452417 }
0 commit comments