@indigoai-us/hq-cloud 6.16.18 → 6.16.19

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.
@@ -4247,7 +4247,13 @@ describe("watch-loop reconcile environment resolvers", () => {
4247
4247
  expect(resolveEventBatchLimit({ [EVENT_BATCH_LIMIT_ENV]: "5" })).toBe(5);
4248
4248
  expect(resolveEventBatchLimit({ [EVENT_BATCH_LIMIT_ENV]: "50000" })).toBe(50_000);
4249
4249
  });
4250
- it("uses the legacy tick cadence for an unset or invalid full-reconcile interval", () => {
4250
+ it("defaults the full-reconcile cadence to one elapsed hour for an unset or invalid interval", () => {
4251
+ // The legacy default was "every tenth tick" with no elapsed-time floor.
4252
+ // Ticks fire on every watcher batch, not just polls, so on an active
4253
+ // vault that meant a full pass every 4-8 minutes — and each pass on a
4254
+ // real install lasts ~10 minutes. Full reconcile is the correctness
4255
+ // backstop behind event-push, so elapsed time is the right clock.
4256
+ expect(DEFAULT_FULL_RECONCILE_MS).toBe(3_600_000);
4251
4257
  expect(resolveFullReconcileMs({})).toBe(DEFAULT_FULL_RECONCILE_MS);
4252
4258
  for (const raw of ["", "0", "0.5", "-1", "NaN", "not-a-number", "Infinity"]) {
4253
4259
  expect(resolveFullReconcileMs({ [FULL_RECONCILE_MS_ENV]: raw })).toBe(DEFAULT_FULL_RECONCILE_MS);
@@ -4717,6 +4723,7 @@ describe("runRunnerWithLoop — event-push wiring", () => {
4717
4723
  return watcher;
4718
4724
  });
4719
4725
  const runPass = vi.fn().mockResolvedValue(completedPassOutcome());
4726
+ const clockState = { now: 0 };
4720
4727
  let triggerShutdown = () => { };
4721
4728
  const loop = runRunnerWithLoop([
4722
4729
  "--companies",
@@ -4729,6 +4736,7 @@ describe("runRunnerWithLoop — event-push wiring", () => {
4729
4736
  ], {
4730
4737
  runPass,
4731
4738
  createWatcher,
4739
+ monotonicNow: () => clockState.now,
4732
4740
  sleep: sleep.sleep,
4733
4741
  onShutdownSignal: (handler) => {
4734
4742
  triggerShutdown = handler;
@@ -4736,12 +4744,16 @@ describe("runRunnerWithLoop — event-push wiring", () => {
4736
4744
  },
4737
4745
  });
4738
4746
  await flushLoopMicrotasks();
4739
- for (let i = 0; i < 9; i++) {
4747
+ for (let i = 0; i < 8; i++) {
4740
4748
  sleep.tick();
4741
4749
  await flushLoopMicrotasks();
4742
4750
  }
4743
- // Tick 1 and tick 10 are full reconciles; the intervening idle polls must
4744
- // leave the healthy watcher in place without running all-vault pulls.
4751
+ clockState.now = DEFAULT_FULL_RECONCILE_MS;
4752
+ sleep.tick();
4753
+ await flushLoopMicrotasks();
4754
+ // Tick 1 and the first tick after an hour has elapsed are full
4755
+ // reconciles; the intervening idle polls must leave the healthy watcher
4756
+ // in place without running all-vault pulls.
4745
4757
  expect(runPass).toHaveBeenCalledTimes(2);
4746
4758
  expect(createWatcher).toHaveBeenCalledTimes(1);
4747
4759
  expect(watchers).toHaveLength(1);
@@ -4759,6 +4771,7 @@ describe("runRunnerWithLoop — event-push wiring", () => {
4759
4771
  const slug = PERSONAL_VAULT_JOURNAL_SLUG;
4760
4772
  let now = 0;
4761
4773
  Date.now = () => now;
4774
+ const clockState = { now: 0 };
4762
4775
  process.env.HQ_SYNC_PARALLEL_COORDINATOR = "1";
4763
4776
  process.env.HQ_SYNC_AREA_STORAGE = "1";
4764
4777
  writeJournal(slug, { version: "2", lastSync: "", pulls: [], files: {} });
@@ -4779,6 +4792,7 @@ describe("runRunnerWithLoop — event-push wiring", () => {
4779
4792
  const loop = runRunnerWithLoop(["--companies", "--watch", "--poll-remote-ms", "1000", "--hq-root", hqRoot], {
4780
4793
  runPass,
4781
4794
  runBackupPrune,
4795
+ monotonicNow: () => clockState.now,
4782
4796
  sleep: sleep.sleep,
4783
4797
  onShutdownSignal: (handler) => {
4784
4798
  shutdown = handler;
@@ -4796,10 +4810,15 @@ describe("runRunnerWithLoop — event-push wiring", () => {
4796
4810
  journalSlug: slug,
4797
4811
  layoutEpoch: 1,
4798
4812
  }).read()).toMatchObject({ nextIndex: 1 });
4799
- for (let i = 0; i < 8; i++) {
4813
+ for (let i = 0; i < 7; i++) {
4800
4814
  sleep.tick();
4801
4815
  await flushLoopMicrotasks(30);
4802
4816
  }
4817
+ expect(runPass).toHaveBeenCalledTimes(1);
4818
+ // The hourly cadence, not a tick count, schedules the next full pass.
4819
+ clockState.now = DEFAULT_FULL_RECONCILE_MS;
4820
+ sleep.tick();
4821
+ await flushLoopMicrotasks(30);
4803
4822
  expect(runPass).toHaveBeenCalledTimes(2);
4804
4823
  }
4805
4824
  finally {
@@ -5337,6 +5356,21 @@ describe("runRunnerWithLoop — event-push wiring", () => {
5337
5356
  const company = readJournal("indigo");
5338
5357
  company.files["knowledge/brief.md"] = { ...row };
5339
5358
  writeJournal("indigo", company);
5359
+ // Two kinds of stale journal file that every start otherwise turns into
5360
+ // phantom unlinks: a company whose local folder is gone (retired test
5361
+ // company, journal file left behind) and the pre-vault legacy `personal`
5362
+ // file that `migratePersonalVaultJournal` copied into the vault journal
5363
+ // but never removed. On a real install these were ~1,000 paths per start,
5364
+ // each ending in a "does not exist, skipping" warning.
5365
+ const orphan = readJournal("company-w");
5366
+ orphan.files["README.md"] = { ...row };
5367
+ orphan.files["knowledge/old.md"] = { ...row };
5368
+ writeJournal("company-w", orphan);
5369
+ const legacy = readJournal("personal");
5370
+ legacy.files["personal/workers/public/retired/pnpm-lock.yaml"] = { ...row };
5371
+ writeJournal("personal", legacy);
5372
+ const hqRoot = fs.mkdtempSync(path.join(os.tmpdir(), "hq-warmup-rows-"));
5373
+ fs.mkdirSync(path.join(hqRoot, "companies", "indigo"), { recursive: true });
5340
5374
  const watcher = makeBatchWatcherStub();
5341
5375
  let markReady = () => { };
5342
5376
  watcher.onReady = (listener) => {
@@ -5352,7 +5386,7 @@ describe("runRunnerWithLoop — event-push wiring", () => {
5352
5386
  let shutdown = () => { };
5353
5387
  const loop = runRunnerWithLoop([
5354
5388
  "--companies", "--watch", "--event-push", "--direction", "push",
5355
- "--hq-root", "/tmp/hq", "--poll-remote-ms", "60000",
5389
+ "--hq-root", hqRoot, "--poll-remote-ms", "60000",
5356
5390
  ], {
5357
5391
  runPass,
5358
5392
  createWatcher: () => watcher,
@@ -5379,6 +5413,7 @@ describe("runRunnerWithLoop — event-push wiring", () => {
5379
5413
  finally {
5380
5414
  shutdown();
5381
5415
  await loop;
5416
+ fs.rmSync(hqRoot, { recursive: true, force: true });
5382
5417
  }
5383
5418
  });
5384
5419
  it("keeps the parallel watch loop alive after an all-refused warm-up catch-up", async () => {
@@ -7435,11 +7470,16 @@ describe("runRunnerWithLoop — event-push wiring", () => {
7435
7470
  }
7436
7471
  return 1;
7437
7472
  });
7473
+ // Every clock read advances a full cadence interval, so the tick after
7474
+ // the partial pass is a scheduled full reconcile that returns the exit
7475
+ // code this test asserts on.
7476
+ let monotonic = 0;
7438
7477
  try {
7439
7478
  const code = await runRunnerWithLoop(["--companies", "--watch", "--event-push", "--hq-root", "/tmp/hq"], {
7440
7479
  runPass,
7441
7480
  clock: new FakeClock(),
7442
7481
  createWatcher: () => watcher,
7482
+ monotonicNow: () => (monotonic += DEFAULT_FULL_RECONCILE_MS),
7443
7483
  sleep: () => Promise.resolve(),
7444
7484
  onShutdownSignal: () => () => { },
7445
7485
  });
@@ -8087,11 +8127,12 @@ describe("runRunnerWithLoop — accumulate-and-drain scoped push", () => {
8087
8127
  process.env.HQ_SYNC_FULL_RECONCILE_MS = savedInterval;
8088
8128
  }
8089
8129
  });
8090
- it("logs scheduled-interval as the sole full-reconcile trigger on the legacy cadence", async () => {
8130
+ it("logs scheduled-interval as the sole full-reconcile trigger on the default hourly cadence", async () => {
8091
8131
  const saved = process.env.HQ_SYNC_FULL_RECONCILE_MS;
8092
8132
  delete process.env.HQ_SYNC_FULL_RECONCILE_MS;
8093
8133
  const capture = captureFullReconcileDecisions();
8094
8134
  try {
8135
+ const clockState = { now: 0 };
8095
8136
  const sleep = makeSteppableSleep();
8096
8137
  let shutdown = () => { };
8097
8138
  const runPass = vi.fn().mockResolvedValue(completedPassOutcome());
@@ -8100,6 +8141,7 @@ describe("runRunnerWithLoop — accumulate-and-drain scoped push", () => {
8100
8141
  "--poll-remote-ms", "60000",
8101
8142
  ], {
8102
8143
  runPass,
8144
+ monotonicNow: () => clockState.now,
8103
8145
  sleep: sleep.sleep,
8104
8146
  onShutdownSignal: (handler) => {
8105
8147
  shutdown = handler;
@@ -8109,12 +8151,15 @@ describe("runRunnerWithLoop — accumulate-and-drain scoped push", () => {
8109
8151
  await flushLoopMicrotasks();
8110
8152
  capture.clear();
8111
8153
  runPass.mockClear();
8112
- for (let tick = 0; tick < 8; tick++) {
8154
+ for (let tick = 0; tick < 12; tick++) {
8113
8155
  sleep.tick();
8114
8156
  await flushLoopMicrotasks();
8115
8157
  }
8158
+ // A dozen ticks inside the hour: never a scheduled full pass.
8159
+ expect(runPass).not.toHaveBeenCalled();
8116
8160
  capture.clear();
8117
8161
  runPass.mockClear();
8162
+ clockState.now = DEFAULT_FULL_RECONCILE_MS;
8118
8163
  sleep.tick();
8119
8164
  await flushLoopMicrotasks();
8120
8165
  expectFullReconcileDecision(capture.records[0], "full", [
@@ -8660,7 +8705,8 @@ describe("runRunnerWithLoop — accumulate-and-drain scoped push", () => {
8660
8705
  tick();
8661
8706
  await loop;
8662
8707
  });
8663
- it("overflow and every tenth tick run a full unscoped reconcile", async () => {
8708
+ it("overflow and an elapsed hour run a full unscoped reconcile", async () => {
8709
+ const clockState = { now: 0 };
8664
8710
  const watcher = makeBatchWatcherStub();
8665
8711
  const sleep = makeSteppableSleep();
8666
8712
  let triggerShutdown = () => { };
@@ -8668,6 +8714,7 @@ describe("runRunnerWithLoop — accumulate-and-drain scoped push", () => {
8668
8714
  const loop = runRunnerWithLoop(watchArgv, {
8669
8715
  runPass,
8670
8716
  clock: new FakeClock(),
8717
+ monotonicNow: () => clockState.now,
8671
8718
  createWatcher: () => watcher,
8672
8719
  sleep: sleep.sleep,
8673
8720
  onShutdownSignal: (handler) => {
@@ -8685,12 +8732,13 @@ describe("runRunnerWithLoop — accumulate-and-drain scoped push", () => {
8685
8732
  await flushLoopMicrotasks();
8686
8733
  expect(runPass.mock.calls.map((call) => call[0])).toEqual([fullArgv]);
8687
8734
  runPass.mockClear();
8688
- for (let i = 0; i < 7; i++) {
8735
+ for (let i = 0; i < 12; i++) {
8689
8736
  sleep.tick();
8690
8737
  await flushLoopMicrotasks();
8691
8738
  }
8692
8739
  expect(runPass).not.toHaveBeenCalled();
8693
8740
  runPass.mockClear();
8741
+ clockState.now = DEFAULT_FULL_RECONCILE_MS;
8694
8742
  sleep.tick();
8695
8743
  await flushLoopMicrotasks();
8696
8744
  expect(runPass.mock.calls.map((call) => call[0])).toEqual([fullArgv]);
@@ -8698,10 +8746,15 @@ describe("runRunnerWithLoop — accumulate-and-drain scoped push", () => {
8698
8746
  sleep.tick();
8699
8747
  await loop;
8700
8748
  });
8701
- it("keeps the legacy every-tenth-tick full-reconcile cadence when the interval env is unset", async () => {
8749
+ it("schedules the full reconcile by elapsed time, not tick count, when the interval env is unset", async () => {
8750
+ // Pre-fix the unset default was every tenth tick. Ticks fire on every
8751
+ // watcher batch, so an active vault ran a ~10-minute full pass every
8752
+ // 4-8 minutes — nearly continuous, and the runner's dominant CPU cost
8753
+ // once per-pass hashing was fixed.
8702
8754
  const saved = process.env.HQ_SYNC_FULL_RECONCILE_MS;
8703
8755
  delete process.env.HQ_SYNC_FULL_RECONCILE_MS;
8704
8756
  try {
8757
+ const clockState = { now: 0 };
8705
8758
  const watcher = makeBatchWatcherStub();
8706
8759
  const sleep = makeSteppableSleep();
8707
8760
  let triggerShutdown = () => { };
@@ -8709,6 +8762,7 @@ describe("runRunnerWithLoop — accumulate-and-drain scoped push", () => {
8709
8762
  const loop = runRunnerWithLoop(watchArgv, {
8710
8763
  runPass,
8711
8764
  clock: new FakeClock(),
8765
+ monotonicNow: () => clockState.now,
8712
8766
  createWatcher: () => watcher,
8713
8767
  sleep: sleep.sleep,
8714
8768
  onShutdownSignal: (handler) => {
@@ -8719,12 +8773,16 @@ describe("runRunnerWithLoop — accumulate-and-drain scoped push", () => {
8719
8773
  await flushLoopMicrotasks();
8720
8774
  expect(runPass.mock.calls.map((call) => call[0])).toEqual([fullArgv]);
8721
8775
  runPass.mockClear();
8722
- for (let tick = 0; tick < 8; tick++) {
8776
+ // Twenty ticks in fifty-nine minutes: the old cadence would have run
8777
+ // two full passes here.
8778
+ for (let tick = 0; tick < 20; tick++) {
8779
+ clockState.now += 177_000;
8723
8780
  sleep.tick();
8724
8781
  await flushLoopMicrotasks();
8725
8782
  }
8726
8783
  expect(runPass).not.toHaveBeenCalled();
8727
8784
  runPass.mockClear();
8785
+ clockState.now = DEFAULT_FULL_RECONCILE_MS;
8728
8786
  sleep.tick();
8729
8787
  await flushLoopMicrotasks();
8730
8788
  expect(runPass.mock.calls.map((call) => call[0])).toEqual([fullArgv]);