@indigoai-us/hq-cloud 6.18.3-alpha.0 → 6.18.4-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.
Files changed (96) hide show
  1. package/dist/bandwidth.d.ts +44 -10
  2. package/dist/bandwidth.d.ts.map +1 -1
  3. package/dist/bandwidth.js +219 -17
  4. package/dist/bandwidth.js.map +1 -1
  5. package/dist/bandwidth.test.js +79 -4
  6. package/dist/bandwidth.test.js.map +1 -1
  7. package/dist/bin/sync-runner-company.d.ts +2 -0
  8. package/dist/bin/sync-runner-company.d.ts.map +1 -1
  9. package/dist/bin/sync-runner-company.js +15 -0
  10. package/dist/bin/sync-runner-company.js.map +1 -1
  11. package/dist/bin/sync-runner-company.test.js +56 -0
  12. package/dist/bin/sync-runner-company.test.js.map +1 -1
  13. package/dist/bin/sync-runner-events.test.js +15 -0
  14. package/dist/bin/sync-runner-events.test.js.map +1 -1
  15. package/dist/bin/sync-runner-watch-loop.d.ts +31 -5
  16. package/dist/bin/sync-runner-watch-loop.d.ts.map +1 -1
  17. package/dist/bin/sync-runner-watch-loop.js +228 -10
  18. package/dist/bin/sync-runner-watch-loop.js.map +1 -1
  19. package/dist/bin/sync-runner.d.ts +31 -2
  20. package/dist/bin/sync-runner.d.ts.map +1 -1
  21. package/dist/bin/sync-runner.js +14 -5
  22. package/dist/bin/sync-runner.js.map +1 -1
  23. package/dist/bin/sync-runner.test.js +120 -39
  24. package/dist/bin/sync-runner.test.js.map +1 -1
  25. package/dist/cli/share.d.ts +26 -8
  26. package/dist/cli/share.d.ts.map +1 -1
  27. package/dist/cli/share.js +206 -60
  28. package/dist/cli/share.js.map +1 -1
  29. package/dist/cli/share.test.js +224 -3
  30. package/dist/cli/share.test.js.map +1 -1
  31. package/dist/cli/sync.d.ts +21 -4
  32. package/dist/cli/sync.d.ts.map +1 -1
  33. package/dist/cli/sync.js +139 -18
  34. package/dist/cli/sync.js.map +1 -1
  35. package/dist/cli/sync.test.js +230 -1
  36. package/dist/cli/sync.test.js.map +1 -1
  37. package/dist/lib/machine-id.d.ts +7 -0
  38. package/dist/lib/machine-id.d.ts.map +1 -1
  39. package/dist/lib/machine-id.js +54 -7
  40. package/dist/lib/machine-id.js.map +1 -1
  41. package/dist/lib/machine-id.test.js +20 -1
  42. package/dist/lib/machine-id.test.js.map +1 -1
  43. package/dist/lib/ontology-entity-push.d.ts +51 -0
  44. package/dist/lib/ontology-entity-push.d.ts.map +1 -0
  45. package/dist/lib/ontology-entity-push.js +125 -0
  46. package/dist/lib/ontology-entity-push.js.map +1 -0
  47. package/dist/lib/ontology-entity-push.test.d.ts +2 -0
  48. package/dist/lib/ontology-entity-push.test.d.ts.map +1 -0
  49. package/dist/lib/ontology-entity-push.test.js +149 -0
  50. package/dist/lib/ontology-entity-push.test.js.map +1 -0
  51. package/dist/object-io.d.ts +33 -7
  52. package/dist/object-io.d.ts.map +1 -1
  53. package/dist/object-io.js +329 -140
  54. package/dist/object-io.js.map +1 -1
  55. package/dist/object-io.test.js +400 -1
  56. package/dist/object-io.test.js.map +1 -1
  57. package/dist/s3-download-stream-hash.test.d.ts +2 -0
  58. package/dist/s3-download-stream-hash.test.d.ts.map +1 -0
  59. package/dist/s3-download-stream-hash.test.js +70 -0
  60. package/dist/s3-download-stream-hash.test.js.map +1 -0
  61. package/dist/s3.d.ts +8 -3
  62. package/dist/s3.d.ts.map +1 -1
  63. package/dist/s3.js +304 -27
  64. package/dist/s3.js.map +1 -1
  65. package/dist/s3.test.js +163 -0
  66. package/dist/s3.test.js.map +1 -1
  67. package/dist/sync/event-sync.d.ts +14 -4
  68. package/dist/sync/event-sync.d.ts.map +1 -1
  69. package/dist/sync/event-sync.js +145 -14
  70. package/dist/sync/event-sync.js.map +1 -1
  71. package/dist/sync/event-sync.test.js +266 -1
  72. package/dist/sync/event-sync.test.js.map +1 -1
  73. package/dist/sync/inbound-event-admission.d.ts.map +1 -1
  74. package/dist/sync/inbound-event-admission.js +3 -0
  75. package/dist/sync/inbound-event-admission.js.map +1 -1
  76. package/dist/sync/inbound-event-admission.test.js +6 -0
  77. package/dist/sync/inbound-event-admission.test.js.map +1 -1
  78. package/dist/sync/push-transport.d.ts +15 -0
  79. package/dist/sync/push-transport.d.ts.map +1 -1
  80. package/dist/sync/push-transport.js +27 -0
  81. package/dist/sync/push-transport.js.map +1 -1
  82. package/dist/sync/push-transport.test.js +14 -1
  83. package/dist/sync/push-transport.test.js.map +1 -1
  84. package/dist/sync-core.d.ts +2 -1
  85. package/dist/sync-core.d.ts.map +1 -1
  86. package/dist/sync-core.js +5 -10
  87. package/dist/sync-core.js.map +1 -1
  88. package/dist/sync-core.test.js +16 -0
  89. package/dist/sync-core.test.js.map +1 -1
  90. package/dist/vault-client.d.ts +5 -0
  91. package/dist/vault-client.d.ts.map +1 -1
  92. package/dist/vault-client.js +7 -0
  93. package/dist/vault-client.js.map +1 -1
  94. package/dist/vault-client.test.js +39 -0
  95. package/dist/vault-client.test.js.map +1 -1
  96. package/package.json +1 -1
@@ -17,7 +17,7 @@ import { runRunner, runRunnerWithLoop, resolveDeletePolicy, resolveSkipPersonal,
17
17
  import { SESSION_LOGS_PUSH_ONLY_PREFIX } from "../sync/pull-scope.js";
18
18
  import { AUTH_WAIT_INITIAL_RECHECK_MS, AUTH_WAIT_RESUME_MESSAGE, AUTH_WAIT_START_MESSAGE, AUTH_WAIT_STEADY_RECHECK_MS, } from "./sync-runner-auth-wait.js";
19
19
  import { PresignObjectIO, S3SdkObjectIO } from "../object-io.js";
20
- import { setBandwidthGovernorForTesting } from "../bandwidth.js";
20
+ import { BandwidthGovernor, 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
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";
@@ -1669,6 +1669,62 @@ describe("automatic journal maintenance", () => {
1669
1669
  vi.useRealTimers();
1670
1670
  }
1671
1671
  });
1672
+ it("emits bandwidth diagnostics at the existing fanout heartbeat cadence", async () => {
1673
+ vi.useFakeTimers();
1674
+ vi.setSystemTime(0);
1675
+ const governor = new BandwidthGovernor({ maxBytesPerSec: 1 }, {
1676
+ sleep: async (ms) => new Promise((resolve) => setTimeout(resolve, ms)),
1677
+ });
1678
+ setBandwidthGovernorForTesting(governor);
1679
+ let releaseBody;
1680
+ const keepBodyOpen = new Promise((resolve) => {
1681
+ releaseBody = resolve;
1682
+ });
1683
+ const sync = vi.fn().mockImplementation(async () => {
1684
+ const body = (async function* () {
1685
+ yield Buffer.alloc(2);
1686
+ await keepBodyOpen;
1687
+ })();
1688
+ for await (const _chunk of governor.throttleBody(body)) {
1689
+ // Consume the chunk while holding the body open for the cadence sample.
1690
+ }
1691
+ return defaultSyncResult();
1692
+ });
1693
+ const deps = makeDeps({
1694
+ createVaultClient: () => makeVaultStub({
1695
+ memberships: [{ companyUid: "cmp_indigo" }],
1696
+ entityGet: (uid) => Promise.resolve({ uid, slug: "indigo" }),
1697
+ }),
1698
+ repairJournalStateIfNeeded: vi
1699
+ .fn()
1700
+ .mockReturnValue({ status: "not-needed", slug: "indigo" }),
1701
+ fanoutHeartbeatIntervalMs: 100,
1702
+ sync,
1703
+ });
1704
+ const running = runRunner(["--companies", "--skip-personal"], deps);
1705
+ try {
1706
+ await vi.waitFor(() => expect(sync).toHaveBeenCalledTimes(1));
1707
+ await vi.advanceTimersByTimeAsync(2_500);
1708
+ const diagnostic = deps.stderr
1709
+ .events()
1710
+ .filter((event) => event.type === "bandwidth-policy")
1711
+ .find((event) => "governorWaitMs" in event && (event.governorWaitMs ?? 0) > 0);
1712
+ expect(diagnostic).toMatchObject({
1713
+ type: "bandwidth-policy",
1714
+ message: "bandwidth governor: 1 B/s cap",
1715
+ effectiveRateBps: 1,
1716
+ activeChoreTransfers: 1,
1717
+ });
1718
+ expect(diagnostic
1719
+ .governorWaitMs).toBeGreaterThan(0);
1720
+ }
1721
+ finally {
1722
+ releaseBody();
1723
+ await running;
1724
+ setBandwidthGovernorForTesting(null);
1725
+ vi.useRealTimers();
1726
+ }
1727
+ });
1672
1728
  it("repairs every resolved journal shard before fanout and streams known heartbeat events", async () => {
1673
1729
  const order = [];
1674
1730
  const repairJournalStateIfNeeded = vi.fn().mockImplementation((slug, options) => {
@@ -4645,13 +4701,15 @@ describe("watch-loop reconcile environment resolvers", () => {
4645
4701
  expect(resolveEventBatchLimit({ [EVENT_BATCH_LIMIT_ENV]: "5" })).toBe(5);
4646
4702
  expect(resolveEventBatchLimit({ [EVENT_BATCH_LIMIT_ENV]: "50000" })).toBe(50_000);
4647
4703
  });
4648
- it("defaults the full-reconcile cadence to one elapsed hour for an unset or invalid interval", () => {
4704
+ it("defaults the full-reconcile cadence to six elapsed hours for an unset or invalid interval", () => {
4649
4705
  // The legacy default was "every tenth tick" with no elapsed-time floor.
4650
4706
  // Ticks fire on every watcher batch, not just polls, so on an active
4651
4707
  // vault that meant a full pass every 4-8 minutes — and each pass on a
4652
4708
  // real install lasts ~10 minutes. Full reconcile is the correctness
4653
- // backstop behind event-push, so elapsed time is the right clock.
4654
- expect(DEFAULT_FULL_RECONCILE_MS).toBe(3_600_000);
4709
+ // backstop behind event-push, so elapsed time is the right clock. Six
4710
+ // hours cuts the S3 list/HEAD and API cost of routine passes; startup,
4711
+ // wake, overflow and warm-up triggers still force a pass immediately.
4712
+ expect(DEFAULT_FULL_RECONCILE_MS).toBe(21_600_000);
4655
4713
  expect(resolveFullReconcileMs({})).toBe(DEFAULT_FULL_RECONCILE_MS);
4656
4714
  for (const raw of ["", "0", "0.5", "-1", "NaN", "not-a-number", "Infinity"]) {
4657
4715
  expect(resolveFullReconcileMs({ [FULL_RECONCILE_MS_ENV]: raw })).toBe(DEFAULT_FULL_RECONCILE_MS);
@@ -7361,7 +7419,6 @@ describe("runRunnerWithLoop — event-push wiring", () => {
7361
7419
  let shutdown = () => { };
7362
7420
  let isUntrackedDelete = (_relativePath) => false;
7363
7421
  const commits = [];
7364
- let submittedAt = 0;
7365
7422
  const aggregatePrime = vi.spyOn(AreaLedger.prototype, "primeAggregateCache");
7366
7423
  const runPass = vi.fn(async (argv) => {
7367
7424
  if (!argv.includes("--scope-path")) {
@@ -7377,7 +7434,7 @@ describe("runRunnerWithLoop — event-push wiring", () => {
7377
7434
  syncedAt: "2026-09-16T21:38:18.000Z",
7378
7435
  };
7379
7436
  writeJournal(slug, scoped);
7380
- commits.push({ slug, elapsedMs: performance.now() - submittedAt });
7437
+ commits.push({ slug });
7381
7438
  }
7382
7439
  return completedPassOutcome();
7383
7440
  });
@@ -7404,7 +7461,6 @@ describe("runRunnerWithLoop — event-push wiring", () => {
7404
7461
  expect(isUntrackedDelete(personalPath)).toBe(false);
7405
7462
  await new Promise((resolve) => setImmediate(resolve));
7406
7463
  }
7407
- submittedAt = performance.now();
7408
7464
  const batch = {
7409
7465
  paths: new Map(relativePaths.map((relativePath) => [path.join(hqRoot, relativePath), relativePath])),
7410
7466
  changes: new Map(relativePaths.map((relativePath) => [
@@ -7445,20 +7501,13 @@ describe("runRunnerWithLoop — event-push wiring", () => {
7445
7501
  await flushLoopMicrotasks(30);
7446
7502
  forceGarbageCollectionForTest();
7447
7503
  const retainedAfterWarmupBytes = retainedProcessBytes();
7448
- const postWarmCpuStart = process.cpuUsage();
7449
- const postWarmStartedAt = performance.now();
7450
7504
  resetStateStoreSnapshotRecoveryCountForTest();
7451
- const eventLoopDelay = monitorEventLoopDelay({ resolution: 10 });
7452
- eventLoopDelay.enable();
7453
7505
  await emitAndWait([personalPath, companyPath]);
7454
7506
  for (let round = 0; round < 3; round += 1) {
7455
7507
  await emitAndWait([personalPath]);
7456
7508
  await emitAndWait([companyPath]);
7457
7509
  }
7458
- eventLoopDelay.disable();
7459
7510
  const recoveryCount = getStateStoreSnapshotRecoveryCountForTest();
7460
- const maxDelayMs = Number(eventLoopDelay.max) / 1_000_000;
7461
- const maxCommitMs = Math.max(...commits.map((commit) => commit.elapsedMs));
7462
7511
  // A first area delta briefly retains the reverse-shadow mirror to
7463
7512
  // amortize a burst. Retained memory means after that documented linger
7464
7513
  // has released its second full-vault projection, not during it.
@@ -7466,15 +7515,9 @@ describe("runRunnerWithLoop — event-push wiring", () => {
7466
7515
  forceGarbageCollectionForTest();
7467
7516
  const retainedAfterChurnBytes = retainedProcessBytes();
7468
7517
  const retainedGrowthBytes = retainedAfterChurnBytes - retainedAfterWarmupBytes;
7469
- const postWarmCpu = process.cpuUsage(postWarmCpuStart);
7470
- const postWarmCpuPercent = ((postWarmCpu.user + postWarmCpu.system) /
7471
- ((performance.now() - postWarmStartedAt) * 1_000)) * 100;
7472
7518
  console.info({
7473
7519
  aggregatePrimeCount: aggregatePrime.mock.calls.length,
7474
7520
  recoveryCount,
7475
- maxDelayMs,
7476
- maxCommitMs,
7477
- postWarmCpuPercent,
7478
7521
  retainedAfterWarmupBytes,
7479
7522
  retainedAfterChurnBytes,
7480
7523
  retainedGrowthBytes,
@@ -7485,13 +7528,10 @@ describe("runRunnerWithLoop — event-push wiring", () => {
7485
7528
  // linger keeps all later scoped commits off snapshot recovery. This is
7486
7529
  // deliberately exact so a second cold bridge cannot hide as a cache hit.
7487
7530
  expect.soft(recoveryCount).toBe(1);
7488
- // The production-shape run remains bounded under the coverage job's
7489
- // concurrent workers: CI measured 1,090.52 ms of timer delay and
7490
- // 1,087.79 ms to commit. 1.5 s retains a concrete latency ceiling while
7491
- // leaving headroom for that instrumentation, rather than making the
7492
- // assertion depend on a single host's scheduling jitter.
7493
- expect.soft(maxDelayMs).toBeLessThan(1_500);
7494
- expect.soft(maxCommitMs).toBeLessThan(1_500);
7531
+ // One post-warm snapshot recovery is the expected reverse-shadow mirror
7532
+ // open; the remaining scoped batches must reuse it. This operation count
7533
+ // proves the cache lifetime without measuring host scheduling delay.
7534
+ expect(commits).toHaveLength(8);
7495
7535
  expect.soft(retainedGrowthBytes).toBeLessThan(32 * 1024 * 1024);
7496
7536
  expect(commits.map((commit) => commit.slug)).toEqual([
7497
7537
  PERSONAL_VAULT_JOURNAL_SLUG,
@@ -7569,7 +7609,6 @@ describe("runRunnerWithLoop — event-push wiring", () => {
7569
7609
  const watcher = makeBatchWatcherStub();
7570
7610
  let shutdown = () => { };
7571
7611
  const commits = [];
7572
- let submittedAt = 0;
7573
7612
  const runPass = vi.fn(async (argv) => {
7574
7613
  if (!argv.includes("--scope-path")) {
7575
7614
  readJournal(PERSONAL_VAULT_JOURNAL_SLUG);
@@ -7584,7 +7623,7 @@ describe("runRunnerWithLoop — event-push wiring", () => {
7584
7623
  syncedAt: "2026-09-16T21:38:18.000Z",
7585
7624
  };
7586
7625
  writeJournal(slug, scoped);
7587
- commits.push({ slug, elapsedMs: performance.now() - submittedAt });
7626
+ commits.push({ slug });
7588
7627
  }
7589
7628
  return completedPassOutcome();
7590
7629
  });
@@ -7599,7 +7638,6 @@ describe("runRunnerWithLoop — event-push wiring", () => {
7599
7638
  });
7600
7639
  const emitAndWait = async (relativePaths) => {
7601
7640
  const before = commits.length;
7602
- submittedAt = performance.now();
7603
7641
  const batch = {
7604
7642
  paths: new Map(relativePaths.map((relativePath) => [path.join(hqRoot, relativePath), relativePath])),
7605
7643
  changes: new Map(relativePaths.map((relativePath) => [
@@ -7617,21 +7655,14 @@ describe("runRunnerWithLoop — event-push wiring", () => {
7617
7655
  await flushLoopMicrotasks(30);
7618
7656
  runPass.mockClear();
7619
7657
  resetStateStoreSnapshotRecoveryCountForTest();
7620
- const eventLoopDelay = monitorEventLoopDelay({ resolution: 10 });
7621
- eventLoopDelay.enable();
7622
7658
  await emitAndWait([personalPath, companyPath]);
7623
7659
  for (let round = 0; round < 3; round += 1) {
7624
7660
  await emitAndWait([personalPath]);
7625
7661
  await emitAndWait([companyPath]);
7626
7662
  }
7627
- eventLoopDelay.disable();
7628
7663
  const recoveryCount = getStateStoreSnapshotRecoveryCountForTest();
7629
- const maxDelayMs = Number(eventLoopDelay.max) / 1_000_000;
7630
- const maxCommitMs = Math.max(...commits.map((commit) => commit.elapsedMs));
7631
- console.info({ recoveryCount, maxDelayMs, maxCommitMs, commits: commits.length });
7632
- expect.soft(recoveryCount).toBe(0);
7633
- expect.soft(maxDelayMs).toBeLessThan(100);
7634
- expect.soft(maxCommitMs).toBeLessThan(1_000);
7664
+ expect(recoveryCount).toBe(0);
7665
+ expect(commits).toHaveLength(8);
7635
7666
  expect(commits.map((commit) => commit.slug)).toEqual([
7636
7667
  PERSONAL_VAULT_JOURNAL_SLUG,
7637
7668
  "indigo",
@@ -9330,6 +9361,56 @@ describe("runRunnerWithLoop — U58 realtime scheduler guard", () => {
9330
9361
  });
9331
9362
  });
9332
9363
  describe("CooperativePassScheduler", () => {
9364
+ it("admits realtime during payload I/O and fences the next chore transfer until the result is committed", async () => {
9365
+ const scheduler = new CooperativePassScheduler(() => 0);
9366
+ const order = [];
9367
+ let markNetworkStarted = () => { };
9368
+ const networkStarted = new Promise((resolve) => {
9369
+ markNetworkStarted = resolve;
9370
+ });
9371
+ let releaseNetwork = () => { };
9372
+ const networkGate = new Promise((resolve) => {
9373
+ releaseNetwork = resolve;
9374
+ });
9375
+ const chore = scheduler.submit(async ({ checkpoint }) => {
9376
+ const first = await checkpoint.runChoreNetworkTransfer(async () => {
9377
+ order.push("network-1-start");
9378
+ markNetworkStarted();
9379
+ await networkGate;
9380
+ order.push("network-1-done");
9381
+ return "first";
9382
+ });
9383
+ order.push(`commit-${first.value}`);
9384
+ const secondPromise = checkpoint.runChoreNetworkTransfer(async () => {
9385
+ order.push("network-2-start");
9386
+ return "second";
9387
+ });
9388
+ await Promise.resolve();
9389
+ expect(order).not.toContain("network-2-start");
9390
+ order.push("commit-first-done");
9391
+ first.complete();
9392
+ const second = await secondPromise;
9393
+ order.push(`commit-${second.value}`);
9394
+ second.complete();
9395
+ return 0;
9396
+ }, "chore");
9397
+ await networkStarted;
9398
+ const realtime = scheduler.submit(async () => {
9399
+ order.push("realtime");
9400
+ return 0;
9401
+ }, "realtime");
9402
+ releaseNetwork();
9403
+ await Promise.all([chore, realtime]);
9404
+ expect(order).toEqual([
9405
+ "network-1-start",
9406
+ "realtime",
9407
+ "network-1-done",
9408
+ "commit-first",
9409
+ "commit-first-done",
9410
+ "network-2-start",
9411
+ "commit-second",
9412
+ ]);
9413
+ });
9333
9414
  it("admits an explicitly safe fast realtime pass while a slow scoped realtime pass remains in flight", async () => {
9334
9415
  const scheduler = new CooperativePassScheduler(() => 0);
9335
9416
  const order = [];