@indigoai-us/hq-cloud 6.16.71-alpha.2 → 6.16.72-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin/sync-runner-watch-loop.d.ts +35 -5
- package/dist/bin/sync-runner-watch-loop.d.ts.map +1 -1
- package/dist/bin/sync-runner-watch-loop.js +156 -32
- package/dist/bin/sync-runner-watch-loop.js.map +1 -1
- package/dist/bin/sync-runner.test.js +96 -12
- package/dist/bin/sync-runner.test.js.map +1 -1
- package/package.json +1 -1
|
@@ -24,6 +24,14 @@ export declare const REALTIME_ADMISSION_DEADLINE_MS: number;
|
|
|
24
24
|
* that value only promotes a deferred chore to the front of the queue.
|
|
25
25
|
*/
|
|
26
26
|
export declare const REALTIME_DRAIN_BURST_MS: number;
|
|
27
|
+
/**
|
|
28
|
+
* How many realtime executes may run during one chore hand-off.
|
|
29
|
+
* HQ_SYNC_MAX_CONCURRENCY caps simultaneous S3 object transfers, not these
|
|
30
|
+
* workers. One long transfer keeps its worker; a realtime item that arrives
|
|
31
|
+
* while that execute() is in flight starts on the other slot instead of
|
|
32
|
+
* waiting for the whole batch. In-flight work is never aborted.
|
|
33
|
+
*/
|
|
34
|
+
export declare const REALTIME_WORKER_OCCUPANCY_CAP = 2;
|
|
27
35
|
export declare function setRealtimeAdmissionDeadlineMsForTesting(ms: number | undefined): void;
|
|
28
36
|
export declare function setRealtimeDrainBurstMsForTesting(ms: number | undefined): void;
|
|
29
37
|
export declare class RealtimeAdmissionTimeoutError extends Error {
|
|
@@ -56,11 +64,13 @@ export interface GuardedPassContext {
|
|
|
56
64
|
signal: AbortSignal;
|
|
57
65
|
}
|
|
58
66
|
/**
|
|
59
|
-
* One durable-state owner at a time for a full chore. Realtime work
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
67
|
+
* One durable-state owner at a time for a full chore. Realtime work runs only
|
|
68
|
+
* while that chore is suspended at `checkpoint()`. Up to
|
|
69
|
+
* {@link REALTIME_WORKER_OCCUPANCY_CAP} realtime executes may occupy that
|
|
70
|
+
* hand-off; an arrival does not wait out a transfer that is already running.
|
|
71
|
+
* A separately tracked, explicitly opted-in watcher fast pass may use the
|
|
72
|
+
* pre-existing scoped fast-over-slow exception, but never while a chore owns
|
|
73
|
+
* durable state.
|
|
64
74
|
*/
|
|
65
75
|
export declare class CooperativePassScheduler<T> {
|
|
66
76
|
private readonly now;
|
|
@@ -68,6 +78,13 @@ export declare class CooperativePassScheduler<T> {
|
|
|
68
78
|
private readonly options;
|
|
69
79
|
private readonly pending;
|
|
70
80
|
private active;
|
|
81
|
+
/** Realtime executes started by the current hand-off. Not the chore slot. */
|
|
82
|
+
private readonly realtimeOccupants;
|
|
83
|
+
private handoffBacklog;
|
|
84
|
+
private handoffDeferredAt;
|
|
85
|
+
private handoffAdmitted;
|
|
86
|
+
private occupantEpoch;
|
|
87
|
+
private occupantWaiters;
|
|
71
88
|
private activeFastRealtime;
|
|
72
89
|
private stopped;
|
|
73
90
|
private _handoffActive;
|
|
@@ -97,6 +114,19 @@ export declare class CooperativePassScheduler<T> {
|
|
|
97
114
|
private startFastRealtime;
|
|
98
115
|
private completeFastRealtime;
|
|
99
116
|
private execute;
|
|
117
|
+
private withinHandoffAdmission;
|
|
118
|
+
private waitOccupantChange;
|
|
119
|
+
private notifyOccupantChange;
|
|
120
|
+
/** Run one realtime execute without aborting it and without taking the chore slot. */
|
|
121
|
+
private startRealtimeOccupant;
|
|
122
|
+
/** Items that showed up while a transfer was already running take a free slot. */
|
|
123
|
+
private promoteOccupancyArrivals;
|
|
124
|
+
/**
|
|
125
|
+
* Pull at most one already-queued realtime item while the admission window
|
|
126
|
+
* is open and a worker slot is free. Further backlog waits for that
|
|
127
|
+
* execute() so pre-queued hand-offs stay one durable writer at a time.
|
|
128
|
+
*/
|
|
129
|
+
private admitHandoffBacklog;
|
|
100
130
|
private drainRealtime;
|
|
101
131
|
private checkpoint;
|
|
102
132
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sync-runner-watch-loop.d.ts","sourceRoot":"","sources":["../../src/bin/sync-runner-watch-loop.ts"],"names":[],"mappings":"AAwBA,OAAO,EAKL,KAAK,UAAU,EAEf,KAAK,eAAe,EACrB,MAAM,eAAe,CAAC;AAEvB,OAAO,EAUL,WAAW,EASZ,MAAM,eAAe,CAAC;AAavB,OAAO,EAIL,KAAK,aAAa,EACnB,MAAM,0BAA0B,CAAC;AASlC,OAAO,EACL,UAAU,EA0CX,MAAM,iCAAiC,CAAC;AAGzC,OAAO,EAEL,qBAAqB,EACtB,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EAGL,KAAK,uBAAuB,EAC7B,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAEL,KAAK,eAAe,EAIrB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAYhD,OAAO,KAAK,EACV,yBAAyB,EACzB,SAAS,EAET,cAAc,EACd,iBAAiB,EAElB,MAAM,kBAAkB,CAAC;AAG1B,yEAAyE;AACzE,eAAO,MAAM,uBAAuB,QAAiB,CAAC;AACtD;;;;;GAKG;AACH,eAAO,MAAM,8BAA8B,QACI,CAAC;AAChD;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB,QAAiC,CAAC;
|
|
1
|
+
{"version":3,"file":"sync-runner-watch-loop.d.ts","sourceRoot":"","sources":["../../src/bin/sync-runner-watch-loop.ts"],"names":[],"mappings":"AAwBA,OAAO,EAKL,KAAK,UAAU,EAEf,KAAK,eAAe,EACrB,MAAM,eAAe,CAAC;AAEvB,OAAO,EAUL,WAAW,EASZ,MAAM,eAAe,CAAC;AAavB,OAAO,EAIL,KAAK,aAAa,EACnB,MAAM,0BAA0B,CAAC;AASlC,OAAO,EACL,UAAU,EA0CX,MAAM,iCAA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AACH,wBAAgB,oCAAoC,CAClD,eAAe,EAAE,MAAM,EACvB,cAAc,EAAE,MAAM,GACrB,OAAO,CAIT;AAgDD,wBAAsB,2BAA2B,CAC/C,IAAI,EAAE,MAAM,EAAE,EACd,MAAM,EAAE,cAAc,EACtB,IAAI,EAAE,cAAc,EACpB,OAAO,EAAE,gBAAgB,GACxB,OAAO,CAAC,MAAM,CAAC,CAgBjB;AAED,wBAAsB,YAAY,CAChC,IAAI,EAAE,MAAM,EAAE,EACd,MAAM,EAAE,cAAc,EACtB,IAAI,EAAE,cAAc,EACpB,OAAO,EAAE,gBAAgB,GACxB,OAAO,CAAC,MAAM,CAAC,CAuyGjB"}
|
|
@@ -49,6 +49,14 @@ export const REALTIME_ADMISSION_DEADLINE_MS = 2 * DEFAULT_REALTIME_AUTHORIZATION
|
|
|
49
49
|
* that value only promotes a deferred chore to the front of the queue.
|
|
50
50
|
*/
|
|
51
51
|
export const REALTIME_DRAIN_BURST_MS = REALTIME_ADMISSION_DEADLINE_MS;
|
|
52
|
+
/**
|
|
53
|
+
* How many realtime executes may run during one chore hand-off.
|
|
54
|
+
* HQ_SYNC_MAX_CONCURRENCY caps simultaneous S3 object transfers, not these
|
|
55
|
+
* workers. One long transfer keeps its worker; a realtime item that arrives
|
|
56
|
+
* while that execute() is in flight starts on the other slot instead of
|
|
57
|
+
* waiting for the whole batch. In-flight work is never aborted.
|
|
58
|
+
*/
|
|
59
|
+
export const REALTIME_WORKER_OCCUPANCY_CAP = 2;
|
|
52
60
|
let realtimeAdmissionDeadlineMsForTest;
|
|
53
61
|
let realtimeDrainBurstMsForTest;
|
|
54
62
|
export function setRealtimeAdmissionDeadlineMsForTesting(ms) {
|
|
@@ -118,11 +126,13 @@ export function realtimeTelemetryReason(paths) {
|
|
|
118
126
|
return undefined;
|
|
119
127
|
}
|
|
120
128
|
/**
|
|
121
|
-
* One durable-state owner at a time for a full chore. Realtime work
|
|
122
|
-
*
|
|
123
|
-
*
|
|
124
|
-
*
|
|
125
|
-
*
|
|
129
|
+
* One durable-state owner at a time for a full chore. Realtime work runs only
|
|
130
|
+
* while that chore is suspended at `checkpoint()`. Up to
|
|
131
|
+
* {@link REALTIME_WORKER_OCCUPANCY_CAP} realtime executes may occupy that
|
|
132
|
+
* hand-off; an arrival does not wait out a transfer that is already running.
|
|
133
|
+
* A separately tracked, explicitly opted-in watcher fast pass may use the
|
|
134
|
+
* pre-existing scoped fast-over-slow exception, but never while a chore owns
|
|
135
|
+
* durable state.
|
|
126
136
|
*/
|
|
127
137
|
export class CooperativePassScheduler {
|
|
128
138
|
now;
|
|
@@ -130,6 +140,13 @@ export class CooperativePassScheduler {
|
|
|
130
140
|
options;
|
|
131
141
|
pending = [];
|
|
132
142
|
active = null;
|
|
143
|
+
/** Realtime executes started by the current hand-off. Not the chore slot. */
|
|
144
|
+
realtimeOccupants = new Set();
|
|
145
|
+
handoffBacklog = null;
|
|
146
|
+
handoffDeferredAt = null;
|
|
147
|
+
handoffAdmitted = false;
|
|
148
|
+
occupantEpoch = 0;
|
|
149
|
+
occupantWaiters = [];
|
|
133
150
|
// Scoped fast realtime work has the established in-process lock exception
|
|
134
151
|
// while a scoped slow realtime upload is in flight. Keep that slot separate
|
|
135
152
|
// from `active`: a chore still has exactly one durable-state owner.
|
|
@@ -180,6 +197,20 @@ export class CooperativePassScheduler {
|
|
|
180
197
|
if (this.canStartFastRealtime(directEntry)) {
|
|
181
198
|
return this.startFastRealtime(directEntry);
|
|
182
199
|
}
|
|
200
|
+
if (workClass === "realtime" &&
|
|
201
|
+
this._handoffActive &&
|
|
202
|
+
this.realtimeOccupants.size < REALTIME_WORKER_OCCUPANCY_CAP) {
|
|
203
|
+
return new Promise((resolve, reject) => {
|
|
204
|
+
const entry = {
|
|
205
|
+
...directEntry,
|
|
206
|
+
enqueuedAt: this.now(),
|
|
207
|
+
resolve,
|
|
208
|
+
reject,
|
|
209
|
+
occupancyArrival: true,
|
|
210
|
+
};
|
|
211
|
+
this.startRealtimeOccupant(entry);
|
|
212
|
+
});
|
|
213
|
+
}
|
|
183
214
|
if (this.active === null &&
|
|
184
215
|
this.activeFastRealtime === null &&
|
|
185
216
|
this.pending.length === 0) {
|
|
@@ -206,6 +237,9 @@ export class CooperativePassScheduler {
|
|
|
206
237
|
signal.addEventListener("abort", onAbort, { once: true });
|
|
207
238
|
entry.abort = () => signal.removeEventListener("abort", onAbort);
|
|
208
239
|
}
|
|
240
|
+
if (workClass === "realtime" && this._handoffActive) {
|
|
241
|
+
entry.occupancyArrival = true;
|
|
242
|
+
}
|
|
209
243
|
this.enqueuePending(entry);
|
|
210
244
|
this.drain();
|
|
211
245
|
});
|
|
@@ -258,6 +292,10 @@ export class CooperativePassScheduler {
|
|
|
258
292
|
drain() {
|
|
259
293
|
if (this.stopped || this.pending.length === 0)
|
|
260
294
|
return;
|
|
295
|
+
if (this._handoffActive) {
|
|
296
|
+
this.promoteOccupancyArrivals();
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
261
299
|
if (this.active !== null) {
|
|
262
300
|
const fastRealtime = this.nextFastRealtime();
|
|
263
301
|
if (fastRealtime && this.canStartFastRealtime(fastRealtime)) {
|
|
@@ -370,6 +408,90 @@ export class CooperativePassScheduler {
|
|
|
370
408
|
signal: entry.controller.signal,
|
|
371
409
|
});
|
|
372
410
|
}
|
|
411
|
+
withinHandoffAdmission() {
|
|
412
|
+
if (this.handoffDeferredAt === null)
|
|
413
|
+
return false;
|
|
414
|
+
return this.now() - this.handoffDeferredAt < realtimeDrainBurstMs();
|
|
415
|
+
}
|
|
416
|
+
waitOccupantChange(seenEpoch) {
|
|
417
|
+
if (this.occupantEpoch !== seenEpoch)
|
|
418
|
+
return Promise.resolve();
|
|
419
|
+
return new Promise((resolve) => {
|
|
420
|
+
this.occupantWaiters.push(resolve);
|
|
421
|
+
});
|
|
422
|
+
}
|
|
423
|
+
notifyOccupantChange() {
|
|
424
|
+
this.occupantEpoch += 1;
|
|
425
|
+
const waiters = this.occupantWaiters;
|
|
426
|
+
this.occupantWaiters = [];
|
|
427
|
+
for (const resolve of waiters)
|
|
428
|
+
resolve();
|
|
429
|
+
}
|
|
430
|
+
/** Run one realtime execute without aborting it and without taking the chore slot. */
|
|
431
|
+
startRealtimeOccupant(entry) {
|
|
432
|
+
this.clearAdmission(entry);
|
|
433
|
+
this.realtimeOccupants.add(entry);
|
|
434
|
+
this.handoffAdmitted = true;
|
|
435
|
+
let running;
|
|
436
|
+
try {
|
|
437
|
+
running = this.execute(entry);
|
|
438
|
+
}
|
|
439
|
+
catch (error) {
|
|
440
|
+
this.realtimeOccupants.delete(entry);
|
|
441
|
+
if (this.handoffBacklog === entry)
|
|
442
|
+
this.handoffBacklog = null;
|
|
443
|
+
entry.reject(error);
|
|
444
|
+
this.notifyOccupantChange();
|
|
445
|
+
return;
|
|
446
|
+
}
|
|
447
|
+
void running.then((outcome) => {
|
|
448
|
+
this.realtimeOccupants.delete(entry);
|
|
449
|
+
if (this.handoffBacklog === entry)
|
|
450
|
+
this.handoffBacklog = null;
|
|
451
|
+
entry.resolve(outcome);
|
|
452
|
+
this.notifyOccupantChange();
|
|
453
|
+
}, (error) => {
|
|
454
|
+
this.realtimeOccupants.delete(entry);
|
|
455
|
+
if (this.handoffBacklog === entry)
|
|
456
|
+
this.handoffBacklog = null;
|
|
457
|
+
entry.reject(error);
|
|
458
|
+
this.notifyOccupantChange();
|
|
459
|
+
});
|
|
460
|
+
}
|
|
461
|
+
/** Items that showed up while a transfer was already running take a free slot. */
|
|
462
|
+
promoteOccupancyArrivals() {
|
|
463
|
+
if (!this._handoffActive)
|
|
464
|
+
return;
|
|
465
|
+
while (this.realtimeOccupants.size < REALTIME_WORKER_OCCUPANCY_CAP) {
|
|
466
|
+
const index = this.pending.findIndex((pending) => pending.workClass === "realtime" && pending.occupancyArrival === true);
|
|
467
|
+
if (index < 0)
|
|
468
|
+
return;
|
|
469
|
+
const arrival = this.pending.splice(index, 1)[0];
|
|
470
|
+
this.startRealtimeOccupant(arrival);
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
/**
|
|
474
|
+
* Pull at most one already-queued realtime item while the admission window
|
|
475
|
+
* is open and a worker slot is free. Further backlog waits for that
|
|
476
|
+
* execute() so pre-queued hand-offs stay one durable writer at a time.
|
|
477
|
+
*/
|
|
478
|
+
admitHandoffBacklog() {
|
|
479
|
+
if (!this._handoffActive || this.handoffBacklog !== null)
|
|
480
|
+
return;
|
|
481
|
+
if (!this.withinHandoffAdmission())
|
|
482
|
+
return;
|
|
483
|
+
if (this.realtimeOccupants.size >= REALTIME_WORKER_OCCUPANCY_CAP)
|
|
484
|
+
return;
|
|
485
|
+
const realtimeIndex = this.nextRealtimeIndex();
|
|
486
|
+
if (realtimeIndex < 0)
|
|
487
|
+
return;
|
|
488
|
+
const pending = this.pending[realtimeIndex];
|
|
489
|
+
if (pending?.occupancyArrival)
|
|
490
|
+
return;
|
|
491
|
+
const realtime = this.pending.splice(realtimeIndex, 1)[0];
|
|
492
|
+
this.handoffBacklog = realtime;
|
|
493
|
+
this.startRealtimeOccupant(realtime);
|
|
494
|
+
}
|
|
373
495
|
async drainRealtime(entry) {
|
|
374
496
|
if (this.stopped ||
|
|
375
497
|
entry.workClass !== "chore" ||
|
|
@@ -377,46 +499,48 @@ export class CooperativePassScheduler {
|
|
|
377
499
|
!this.pending.some((pending) => pending.workClass === "realtime")) {
|
|
378
500
|
return false;
|
|
379
501
|
}
|
|
380
|
-
// `entry` is suspended at a caller-declared durable boundary.
|
|
381
|
-
//
|
|
382
|
-
//
|
|
383
|
-
//
|
|
384
|
-
// completion so a 45s upload is not retried every 30s.
|
|
385
|
-
const deferredAt = this.now();
|
|
386
|
-
const burstMs = realtimeDrainBurstMs();
|
|
502
|
+
// `entry` is suspended at a caller-declared durable boundary. The burst
|
|
503
|
+
// cap only stops admitting further backlog. An execute() that already
|
|
504
|
+
// started is never aborted. A realtime item that arrives while one is in
|
|
505
|
+
// flight starts on the free occupancy slot (see REALTIME_WORKER_OCCUPANCY_CAP).
|
|
387
506
|
this.active = null;
|
|
388
507
|
this._handoffActive = true;
|
|
508
|
+
this.handoffDeferredAt = this.now();
|
|
509
|
+
this.handoffAdmitted = false;
|
|
510
|
+
this.handoffBacklog = null;
|
|
389
511
|
this.options.caps?.suspendForHandoff();
|
|
390
|
-
let handedOff = false;
|
|
391
512
|
try {
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
if (
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
handedOff = true;
|
|
399
|
-
this.active = realtime;
|
|
400
|
-
try {
|
|
401
|
-
const outcome = await this.execute(realtime);
|
|
402
|
-
realtime.resolve(outcome);
|
|
403
|
-
}
|
|
404
|
-
catch (error) {
|
|
405
|
-
realtime.reject(error);
|
|
406
|
-
}
|
|
407
|
-
finally {
|
|
408
|
-
if (this.active === realtime)
|
|
409
|
-
this.active = null;
|
|
513
|
+
this.admitHandoffBacklog();
|
|
514
|
+
while (!this.stopped && (this.realtimeOccupants.size > 0 || this.withinHandoffAdmission())) {
|
|
515
|
+
if (this.realtimeOccupants.size === 0) {
|
|
516
|
+
this.admitHandoffBacklog();
|
|
517
|
+
if (this.realtimeOccupants.size === 0)
|
|
518
|
+
break;
|
|
410
519
|
}
|
|
520
|
+
const seen = this.occupantEpoch;
|
|
521
|
+
if (this.realtimeOccupants.size === 0)
|
|
522
|
+
break;
|
|
523
|
+
await this.waitOccupantChange(seen);
|
|
524
|
+
this.promoteOccupancyArrivals();
|
|
525
|
+
this.admitHandoffBacklog();
|
|
526
|
+
}
|
|
527
|
+
while (!this.stopped && this.realtimeOccupants.size > 0) {
|
|
528
|
+
const seen = this.occupantEpoch;
|
|
529
|
+
if (this.realtimeOccupants.size === 0)
|
|
530
|
+
break;
|
|
531
|
+
await this.waitOccupantChange(seen);
|
|
532
|
+
this.promoteOccupancyArrivals();
|
|
411
533
|
}
|
|
412
534
|
}
|
|
413
535
|
finally {
|
|
414
536
|
this._handoffActive = false;
|
|
537
|
+
this.handoffDeferredAt = null;
|
|
538
|
+
this.handoffBacklog = null;
|
|
415
539
|
if (!this.stopped)
|
|
416
540
|
this.active = entry;
|
|
417
541
|
this.options.caps?.resumeAfterHandoff();
|
|
418
542
|
}
|
|
419
|
-
return
|
|
543
|
+
return this.handoffAdmitted;
|
|
420
544
|
}
|
|
421
545
|
async checkpoint(entry) {
|
|
422
546
|
if (this.stopped || entry.workClass !== "chore" || this.active !== entry) {
|