@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.
@@ -20,7 +20,7 @@ import { PresignObjectIO, S3SdkObjectIO } from "../object-io.js";
20
20
  import { setBandwidthGovernorForTesting } from "../bandwidth.js";
21
21
  import { POST_SYNC_FLAG_KEYS, } from "./sync-runner-post-sync-flags.js";
22
22
  import { FakeClock, TreeWatcher, } from "../watcher.js";
23
- import { adaptivePollMs, advanceMonotonicDeadline, DEFAULT_EVENT_BATCH_LIMIT, DEFAULT_FAST_LANE_MAX_BYTES, DEFAULT_FAST_LANE_MAX_FILE_BYTES, DEFAULT_FAST_LANE_MAX_FILES, DEFAULT_FULL_RECONCILE_MS, EVENT_BATCH_LIMIT_ENV, FAST_LANE_MAX_BYTES_ENV, FAST_LANE_MAX_FILES_ENV, FULL_RECONCILE_MS_ENV, isFastLocalBatch, isFastReceiverBatch, partitionLocalBatch, journalEntriesForWatcherDelete, resolveEventBatchLimit, resolveFullReconcileMs, resolveWatchPollMs, CHORE_STARVATION_CAP_MS, CooperativePassScheduler, REALTIME_ADMISSION_DEADLINE_MS, REALTIME_DRAIN_BURST_MS, RealtimeAdmissionTimeoutError, setRealtimeAdmissionDeadlineMsForTesting, setRealtimeDrainBurstMsForTesting, normalizeCoordinatorPaths, shouldQuarantineWatcherDeleteIntents, shouldUseAreaStorage, WATCHER_REDISCOVERY_RETRY_MS, WATCHER_REDISCOVERY_RETRY_MAX_MS, } from "./sync-runner-watch-loop.js";
23
+ import { adaptivePollMs, advanceMonotonicDeadline, DEFAULT_EVENT_BATCH_LIMIT, DEFAULT_FAST_LANE_MAX_BYTES, DEFAULT_FAST_LANE_MAX_FILE_BYTES, DEFAULT_FAST_LANE_MAX_FILES, DEFAULT_FULL_RECONCILE_MS, EVENT_BATCH_LIMIT_ENV, FAST_LANE_MAX_BYTES_ENV, FAST_LANE_MAX_FILES_ENV, FULL_RECONCILE_MS_ENV, isFastLocalBatch, isFastReceiverBatch, partitionLocalBatch, journalEntriesForWatcherDelete, resolveEventBatchLimit, resolveFullReconcileMs, resolveWatchPollMs, CHORE_STARVATION_CAP_MS, CooperativePassScheduler, REALTIME_ADMISSION_DEADLINE_MS, REALTIME_DRAIN_BURST_MS, REALTIME_WORKER_OCCUPANCY_CAP, RealtimeAdmissionTimeoutError, setRealtimeAdmissionDeadlineMsForTesting, setRealtimeDrainBurstMsForTesting, normalizeCoordinatorPaths, shouldQuarantineWatcherDeleteIntents, shouldUseAreaStorage, WATCHER_REDISCOVERY_RETRY_MS, WATCHER_REDISCOVERY_RETRY_MAX_MS, } from "./sync-runner-watch-loop.js";
24
24
  import { FullPassCapController, resetFullPassCapLogForTest, } from "../sync/full-pass-caps.js";
25
25
  import { AreaLedgerMigration, JournalStore, openJournalStateStoreForMigration, PERSONAL_VAULT_JOURNAL_SLUG, readJournal, readJournalScoped, writeJournal, } from "../journal.js";
26
26
  import { AreaLedger } from "../sync/area-ledger.js";
@@ -9262,7 +9262,7 @@ describe("CooperativePassScheduler", () => {
9262
9262
  "realtime-after-cap",
9263
9263
  ]);
9264
9264
  });
9265
- it("lets an in-flight realtime drain finish past the burst bound and admits no further items until the next checkpoint", async () => {
9265
+ it("lets an in-flight realtime drain finish past the burst bound without making a new arrival wait for it", async () => {
9266
9266
  expect(REALTIME_DRAIN_BURST_MS).toBe(REALTIME_ADMISSION_DEADLINE_MS);
9267
9267
  setRealtimeDrainBurstMsForTesting(40);
9268
9268
  let now = 0;
@@ -9272,6 +9272,10 @@ describe("CooperativePassScheduler", () => {
9272
9272
  const checkpointReady = new Promise((resolve) => {
9273
9273
  releaseCheckpoint = resolve;
9274
9274
  });
9275
+ let releaseFirst = () => { };
9276
+ const firstGate = new Promise((resolve) => {
9277
+ releaseFirst = resolve;
9278
+ });
9275
9279
  const chore = scheduler.submit(async ({ checkpoint }) => {
9276
9280
  order.push("chore-before");
9277
9281
  await checkpointReady;
@@ -9285,28 +9289,31 @@ describe("CooperativePassScheduler", () => {
9285
9289
  const first = scheduler.submit(async ({ signal }) => {
9286
9290
  order.push("realtime-start");
9287
9291
  now = 45;
9288
- await new Promise((resolve) => {
9289
- setTimeout(resolve, 60);
9290
- });
9292
+ await firstGate;
9291
9293
  expect(signal.aborted).toBe(false);
9292
9294
  order.push("realtime-done");
9293
9295
  return 0;
9294
9296
  }, "realtime");
9297
+ releaseCheckpoint();
9298
+ await new Promise((resolve) => setTimeout(resolve, 2));
9299
+ expect(order).toContain("realtime-start");
9295
9300
  const second = scheduler.submit(async () => {
9296
9301
  order.push("realtime-second");
9297
9302
  return 0;
9298
9303
  }, "realtime");
9299
- await new Promise((resolve) => setTimeout(resolve, 2));
9300
- releaseCheckpoint();
9304
+ await new Promise((resolve) => setTimeout(resolve, 5));
9305
+ expect(order).toContain("realtime-second");
9306
+ expect(order.indexOf("realtime-second")).toBeLessThan(order.includes("realtime-done") ? order.indexOf("realtime-done") : order.length);
9307
+ releaseFirst();
9301
9308
  await expect(first).resolves.toBe(0);
9309
+ await expect(second).resolves.toBe(0);
9302
9310
  await chore;
9303
- await second;
9304
9311
  expect(order).toEqual([
9305
9312
  "chore-before",
9306
9313
  "realtime-start",
9314
+ "realtime-second",
9307
9315
  "realtime-done",
9308
9316
  "chore-mid",
9309
- "realtime-second",
9310
9317
  "chore-after",
9311
9318
  ]);
9312
9319
  });
@@ -9343,13 +9350,26 @@ describe("CooperativePassScheduler", () => {
9343
9350
  return 0;
9344
9351
  }, "realtime");
9345
9352
  releaseCheckpoint();
9346
- const finished = Promise.all([chore, put]);
9347
- await vi.advanceTimersByTimeAsync(45_000);
9348
- await expect(finished).resolves.toEqual([0, 0]);
9353
+ await vi.advanceTimersByTimeAsync(0);
9354
+ expect(order).toContain("put-start");
9355
+ const arrivedAt = now;
9356
+ let nextStartedAt = null;
9357
+ const next = scheduler.submit(async () => {
9358
+ nextStartedAt = now;
9359
+ order.push("next-start");
9360
+ return 0;
9361
+ }, "realtime");
9362
+ await vi.advanceTimersByTimeAsync(30_000);
9363
+ expect(nextStartedAt).not.toBeNull();
9364
+ expect((nextStartedAt ?? Number.POSITIVE_INFINITY) - arrivedAt).toBeLessThanOrEqual(30_000);
9365
+ expect(order).not.toContain("put-done");
9366
+ await vi.advanceTimersByTimeAsync(15_000);
9367
+ await expect(Promise.all([chore, put, next])).resolves.toEqual([0, 0, 0]);
9349
9368
  expect(abortCount).toBe(0);
9350
9369
  expect(order).toEqual([
9351
9370
  "chore-before",
9352
9371
  "put-start",
9372
+ "next-start",
9353
9373
  "put-done",
9354
9374
  "chore-after",
9355
9375
  ]);
@@ -9358,6 +9378,70 @@ describe("CooperativePassScheduler", () => {
9358
9378
  vi.useRealTimers();
9359
9379
  }
9360
9380
  });
9381
+ it("starts a 1-item realtime push within 30s while a 24-item execute is still in flight", async () => {
9382
+ expect(REALTIME_WORKER_OCCUPANCY_CAP).toBe(2);
9383
+ expect(REALTIME_DRAIN_BURST_MS).toBe(30_000);
9384
+ vi.useFakeTimers();
9385
+ try {
9386
+ let now = 0;
9387
+ const scheduler = new CooperativePassScheduler(() => now);
9388
+ const order = [];
9389
+ let abortCount = 0;
9390
+ let releaseCheckpoint = () => { };
9391
+ const checkpointReady = new Promise((resolve) => {
9392
+ releaseCheckpoint = resolve;
9393
+ });
9394
+ const chore = scheduler.submit(async ({ checkpoint }) => {
9395
+ order.push("chore-before");
9396
+ await checkpointReady;
9397
+ await checkpoint();
9398
+ order.push("chore-after");
9399
+ return 0;
9400
+ }, "chore");
9401
+ await Promise.resolve();
9402
+ const batchMs = 15 * 60_000;
9403
+ const batch = scheduler.submit(async ({ signal }) => {
9404
+ order.push("batch-start");
9405
+ signal.addEventListener("abort", () => {
9406
+ abortCount += 1;
9407
+ }, { once: true });
9408
+ await new Promise((resolve) => {
9409
+ setTimeout(resolve, batchMs);
9410
+ });
9411
+ expect(signal.aborted).toBe(false);
9412
+ order.push("batch-done");
9413
+ return 0;
9414
+ }, "realtime");
9415
+ releaseCheckpoint();
9416
+ await vi.advanceTimersByTimeAsync(0);
9417
+ expect(order).toEqual(["chore-before", "batch-start"]);
9418
+ now = 2 * 60_000;
9419
+ const arrivedAt = now;
9420
+ let plantStartedAt = null;
9421
+ const plant = scheduler.submit(async () => {
9422
+ plantStartedAt = now;
9423
+ order.push("plant-start");
9424
+ return 0;
9425
+ }, "realtime");
9426
+ await vi.advanceTimersByTimeAsync(30_000);
9427
+ expect(plantStartedAt).not.toBeNull();
9428
+ expect((plantStartedAt ?? Number.POSITIVE_INFINITY) - arrivedAt).toBeLessThanOrEqual(30_000);
9429
+ expect(order).not.toContain("batch-done");
9430
+ await vi.advanceTimersByTimeAsync(batchMs);
9431
+ await expect(Promise.all([chore, batch, plant])).resolves.toEqual([0, 0, 0]);
9432
+ expect(abortCount).toBe(0);
9433
+ expect(order).toEqual([
9434
+ "chore-before",
9435
+ "batch-start",
9436
+ "plant-start",
9437
+ "batch-done",
9438
+ "chore-after",
9439
+ ]);
9440
+ }
9441
+ finally {
9442
+ vi.useRealTimers();
9443
+ }
9444
+ });
9361
9445
  afterEach(() => {
9362
9446
  setRealtimeAdmissionDeadlineMsForTesting(undefined);
9363
9447
  setRealtimeDrainBurstMsForTesting(undefined);