@indigoai-us/hq-cloud 6.16.76-alpha.0 → 6.16.77-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,8 +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, EVENT_BATCH_LIMIT_ENV, FAST_LANE_MAX_BYTES_ENV, FAST_LANE_MAX_FILES_ENV, isFastLocalBatch, isFastReceiverBatch, partitionLocalBatch, journalEntriesForWatcherDelete, resolveEventBatchLimit, 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
- import { DEFAULT_FULL_PASS_INTERVAL_MS } from "../sync/full-pass-interval.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";
25
24
  import { FullPassCapController, resetFullPassCapLogForTest, } from "../sync/full-pass-caps.js";
26
25
  import { AreaLedgerMigration, JournalStore, openJournalStateStoreForMigration, PERSONAL_VAULT_JOURNAL_SLUG, readJournal, readJournalScoped, writeJournal, } from "../journal.js";
27
26
  import { AreaLedger } from "../sync/area-ledger.js";
@@ -4637,13 +4636,28 @@ describe("advanceMonotonicDeadline", () => {
4637
4636
  });
4638
4637
  });
4639
4638
  });
4640
- describe("watch-loop reconcile configuration", () => {
4639
+ describe("watch-loop reconcile environment resolvers", () => {
4641
4640
  it("uses the shipped 10,000 event-batch default while allowing smaller and larger overrides", () => {
4642
4641
  expect(DEFAULT_EVENT_BATCH_LIMIT).toBe(10_000);
4643
4642
  expect(resolveEventBatchLimit({})).toBe(10_000);
4644
4643
  expect(resolveEventBatchLimit({ [EVENT_BATCH_LIMIT_ENV]: "5" })).toBe(5);
4645
4644
  expect(resolveEventBatchLimit({ [EVENT_BATCH_LIMIT_ENV]: "50000" })).toBe(50_000);
4646
4645
  });
4646
+ it("defaults the full-reconcile cadence to one elapsed hour for an unset or invalid interval", () => {
4647
+ // The legacy default was "every tenth tick" with no elapsed-time floor.
4648
+ // Ticks fire on every watcher batch, not just polls, so on an active
4649
+ // vault that meant a full pass every 4-8 minutes — and each pass on a
4650
+ // real install lasts ~10 minutes. Full reconcile is the correctness
4651
+ // backstop behind event-push, so elapsed time is the right clock.
4652
+ expect(DEFAULT_FULL_RECONCILE_MS).toBe(3_600_000);
4653
+ expect(resolveFullReconcileMs({})).toBe(DEFAULT_FULL_RECONCILE_MS);
4654
+ for (const raw of ["", "0", "0.5", "-1", "NaN", "not-a-number", "Infinity"]) {
4655
+ expect(resolveFullReconcileMs({ [FULL_RECONCILE_MS_ENV]: raw })).toBe(DEFAULT_FULL_RECONCILE_MS);
4656
+ }
4657
+ });
4658
+ it("accepts a positive millisecond full-reconcile interval", () => {
4659
+ expect(resolveFullReconcileMs({ [FULL_RECONCILE_MS_ENV]: "10800000" })).toBe(10_800_000);
4660
+ });
4647
4661
  });
4648
4662
  describe("runRunnerWithLoop — adaptive poll interval (no --poll-remote-ms)", () => {
4649
4663
  // Capture the ms handed to sleep on the FIRST poll, then hang so the loop
@@ -4859,8 +4873,10 @@ describe("runRunnerWithLoop — event-push wiring", () => {
4859
4873
  it("parallel coordinator activates every event surface after a partial completed full reconcile", async () => {
4860
4874
  const previousCoordinator = process.env.HQ_SYNC_PARALLEL_COORDINATOR;
4861
4875
  const previousEventSync = process.env.HQ_SYNC_EVENT_SYNC;
4876
+ const previousFullReconcileMs = process.env.HQ_SYNC_FULL_RECONCILE_MS;
4862
4877
  process.env.HQ_SYNC_PARALLEL_COORDINATOR = "1";
4863
4878
  process.env.HQ_SYNC_EVENT_SYNC = "1";
4879
+ process.env.HQ_SYNC_FULL_RECONCILE_MS = "60000";
4864
4880
  const watcher = makeWatcherStub();
4865
4881
  const receiver = {
4866
4882
  connected: false,
@@ -4920,13 +4936,19 @@ describe("runRunnerWithLoop — event-push wiring", () => {
4920
4936
  delete process.env.HQ_SYNC_EVENT_SYNC;
4921
4937
  else
4922
4938
  process.env.HQ_SYNC_EVENT_SYNC = previousEventSync;
4939
+ if (previousFullReconcileMs === undefined)
4940
+ delete process.env.HQ_SYNC_FULL_RECONCILE_MS;
4941
+ else
4942
+ process.env.HQ_SYNC_FULL_RECONCILE_MS = previousFullReconcileMs;
4923
4943
  }
4924
4944
  });
4925
4945
  it("parallel coordinator activates event surfaces and advances cadence after a numeric-zero full reconcile", async () => {
4926
4946
  const previousCoordinator = process.env.HQ_SYNC_PARALLEL_COORDINATOR;
4927
4947
  const previousEventSync = process.env.HQ_SYNC_EVENT_SYNC;
4948
+ const previousFullReconcileMs = process.env.HQ_SYNC_FULL_RECONCILE_MS;
4928
4949
  process.env.HQ_SYNC_PARALLEL_COORDINATOR = "1";
4929
4950
  process.env.HQ_SYNC_EVENT_SYNC = "1";
4951
+ process.env.HQ_SYNC_FULL_RECONCILE_MS = "60000";
4930
4952
  const watcher = makeWatcherStub();
4931
4953
  const receiver = {
4932
4954
  connected: false,
@@ -4986,6 +5008,10 @@ describe("runRunnerWithLoop — event-push wiring", () => {
4986
5008
  delete process.env.HQ_SYNC_EVENT_SYNC;
4987
5009
  else
4988
5010
  process.env.HQ_SYNC_EVENT_SYNC = previousEventSync;
5011
+ if (previousFullReconcileMs === undefined)
5012
+ delete process.env.HQ_SYNC_FULL_RECONCILE_MS;
5013
+ else
5014
+ process.env.HQ_SYNC_FULL_RECONCILE_MS = previousFullReconcileMs;
4989
5015
  }
4990
5016
  });
4991
5017
  it("parallel coordinator keeps event surfaces off for an auth-required full reconcile", async () => {
@@ -5118,7 +5144,7 @@ describe("runRunnerWithLoop — event-push wiring", () => {
5118
5144
  sleep.tick();
5119
5145
  await flushLoopMicrotasks();
5120
5146
  }
5121
- clockState.now = DEFAULT_FULL_PASS_INTERVAL_MS;
5147
+ clockState.now = DEFAULT_FULL_RECONCILE_MS;
5122
5148
  sleep.tick();
5123
5149
  await flushLoopMicrotasks();
5124
5150
  // Tick 1 and the first tick after an hour has elapsed are full
@@ -5186,7 +5212,7 @@ describe("runRunnerWithLoop — event-push wiring", () => {
5186
5212
  }
5187
5213
  expect(runPass).toHaveBeenCalledTimes(1);
5188
5214
  // The hourly cadence, not a tick count, schedules the next full pass.
5189
- clockState.now = DEFAULT_FULL_PASS_INTERVAL_MS;
5215
+ clockState.now = DEFAULT_FULL_RECONCILE_MS;
5190
5216
  sleep.tick();
5191
5217
  await flushLoopMicrotasks(30);
5192
5218
  expect(runPass).toHaveBeenCalledTimes(2);
@@ -8906,7 +8932,7 @@ describe("runRunnerWithLoop — event-push wiring", () => {
8906
8932
  runPass,
8907
8933
  clock: new FakeClock(),
8908
8934
  createWatcher: () => watcher,
8909
- monotonicNow: () => (monotonic += DEFAULT_FULL_PASS_INTERVAL_MS),
8935
+ monotonicNow: () => (monotonic += DEFAULT_FULL_RECONCILE_MS),
8910
8936
  sleep: sleep.sleep,
8911
8937
  onShutdownSignal: (handler) => {
8912
8938
  triggerShutdown = handler;
@@ -9888,7 +9914,9 @@ describe("CooperativePassScheduler", () => {
9888
9914
  describe("first-tick realtime yield", () => {
9889
9915
  it("commits a watcher push at the first chore checkpoint within the admission deadline", async () => {
9890
9916
  const previousCoordinator = process.env.HQ_SYNC_PARALLEL_COORDINATOR;
9917
+ const previousInterval = process.env.HQ_SYNC_FULL_RECONCILE_MS;
9891
9918
  process.env.HQ_SYNC_PARALLEL_COORDINATOR = "1";
9919
+ process.env.HQ_SYNC_FULL_RECONCILE_MS = "10800000";
9892
9920
  const timings = [];
9893
9921
  const spy = vi.spyOn(process.stderr, "write").mockImplementation((chunk) => {
9894
9922
  const text = String(chunk);
@@ -9991,6 +10019,10 @@ describe("first-tick realtime yield", () => {
9991
10019
  delete process.env.HQ_SYNC_PARALLEL_COORDINATOR;
9992
10020
  else
9993
10021
  process.env.HQ_SYNC_PARALLEL_COORDINATOR = previousCoordinator;
10022
+ if (previousInterval === undefined)
10023
+ delete process.env.HQ_SYNC_FULL_RECONCILE_MS;
10024
+ else
10025
+ process.env.HQ_SYNC_FULL_RECONCILE_MS = previousInterval;
9994
10026
  }
9995
10027
  });
9996
10028
  });
@@ -10285,6 +10317,8 @@ describe("runRunnerWithLoop — accumulate-and-drain scoped push", () => {
10285
10317
  capture.restore();
10286
10318
  });
10287
10319
  it("logs event-push-surfaces-inactive without silently attributing the first tick", async () => {
10320
+ const saved = process.env.HQ_SYNC_FULL_RECONCILE_MS;
10321
+ process.env.HQ_SYNC_FULL_RECONCILE_MS = "10800000";
10288
10322
  const capture = captureFullReconcileDecisions();
10289
10323
  try {
10290
10324
  const sleep = makeSteppableSleep();
@@ -10313,6 +10347,10 @@ describe("runRunnerWithLoop — accumulate-and-drain scoped push", () => {
10313
10347
  }
10314
10348
  finally {
10315
10349
  capture.restore();
10350
+ if (saved === undefined)
10351
+ delete process.env.HQ_SYNC_FULL_RECONCILE_MS;
10352
+ else
10353
+ process.env.HQ_SYNC_FULL_RECONCILE_MS = saved;
10316
10354
  }
10317
10355
  });
10318
10356
  it("reports every matching trigger instead of short-circuiting at the first", async () => {
@@ -10367,7 +10405,9 @@ describe("runRunnerWithLoop — accumulate-and-drain scoped push", () => {
10367
10405
  });
10368
10406
  it("skips a 404 company route in a mixed drain and records a completed full reconcile", async () => {
10369
10407
  const previousCoordinator = process.env.HQ_SYNC_PARALLEL_COORDINATOR;
10408
+ const previousInterval = process.env.HQ_SYNC_FULL_RECONCILE_MS;
10370
10409
  process.env.HQ_SYNC_PARALLEL_COORDINATOR = "1";
10410
+ process.env.HQ_SYNC_FULL_RECONCILE_MS = "10800000";
10371
10411
  const failedLines = [];
10372
10412
  const decisions = [];
10373
10413
  const timingRecords = [];
@@ -10467,11 +10507,17 @@ describe("runRunnerWithLoop — accumulate-and-drain scoped push", () => {
10467
10507
  delete process.env.HQ_SYNC_PARALLEL_COORDINATOR;
10468
10508
  else
10469
10509
  process.env.HQ_SYNC_PARALLEL_COORDINATOR = previousCoordinator;
10510
+ if (previousInterval === undefined)
10511
+ delete process.env.HQ_SYNC_FULL_RECONCILE_MS;
10512
+ else
10513
+ process.env.HQ_SYNC_FULL_RECONCILE_MS = previousInterval;
10470
10514
  }
10471
10515
  });
10472
10516
  it("does not escalate a fully-enumerated over-limit batch to a full reconcile", async () => {
10473
10517
  const savedLimit = process.env.HQ_SYNC_EVENT_BATCH_LIMIT;
10518
+ const savedInterval = process.env.HQ_SYNC_FULL_RECONCILE_MS;
10474
10519
  process.env.HQ_SYNC_EVENT_BATCH_LIMIT = "2";
10520
+ process.env.HQ_SYNC_FULL_RECONCILE_MS = "10800000";
10475
10521
  const journal = captureWatchLoopJournal();
10476
10522
  try {
10477
10523
  const runPass = vi.fn().mockResolvedValue(completedPassOutcome());
@@ -10511,11 +10557,17 @@ describe("runRunnerWithLoop — accumulate-and-drain scoped push", () => {
10511
10557
  delete process.env.HQ_SYNC_EVENT_BATCH_LIMIT;
10512
10558
  else
10513
10559
  process.env.HQ_SYNC_EVENT_BATCH_LIMIT = savedLimit;
10560
+ if (savedInterval === undefined)
10561
+ delete process.env.HQ_SYNC_FULL_RECONCILE_MS;
10562
+ else
10563
+ process.env.HQ_SYNC_FULL_RECONCILE_MS = savedInterval;
10514
10564
  }
10515
10565
  });
10516
10566
  it("still escalates an overflowed batch with unknown routes to a full reconcile", async () => {
10517
10567
  const savedLimit = process.env.HQ_SYNC_EVENT_BATCH_LIMIT;
10568
+ const savedInterval = process.env.HQ_SYNC_FULL_RECONCILE_MS;
10518
10569
  process.env.HQ_SYNC_EVENT_BATCH_LIMIT = "2";
10570
+ process.env.HQ_SYNC_FULL_RECONCILE_MS = "10800000";
10519
10571
  const journal = captureWatchLoopJournal();
10520
10572
  try {
10521
10573
  const runPass = vi.fn().mockResolvedValue(completedPassOutcome());
@@ -10547,9 +10599,15 @@ describe("runRunnerWithLoop — accumulate-and-drain scoped push", () => {
10547
10599
  delete process.env.HQ_SYNC_EVENT_BATCH_LIMIT;
10548
10600
  else
10549
10601
  process.env.HQ_SYNC_EVENT_BATCH_LIMIT = savedLimit;
10602
+ if (savedInterval === undefined)
10603
+ delete process.env.HQ_SYNC_FULL_RECONCILE_MS;
10604
+ else
10605
+ process.env.HQ_SYNC_FULL_RECONCILE_MS = savedInterval;
10550
10606
  }
10551
10607
  });
10552
- it("logs scheduled-interval as the sole full-reconcile trigger on the six-hour default", async () => {
10608
+ it("logs scheduled-interval as the sole full-reconcile trigger on the default hourly cadence", async () => {
10609
+ const saved = process.env.HQ_SYNC_FULL_RECONCILE_MS;
10610
+ delete process.env.HQ_SYNC_FULL_RECONCILE_MS;
10553
10611
  const capture = captureFullReconcileDecisions();
10554
10612
  try {
10555
10613
  const clockState = { now: 0 };
@@ -10575,11 +10633,11 @@ describe("runRunnerWithLoop — accumulate-and-drain scoped push", () => {
10575
10633
  sleep.tick();
10576
10634
  await flushLoopMicrotasks();
10577
10635
  }
10578
- // A dozen ticks inside the interval: never a scheduled full pass.
10636
+ // A dozen ticks inside the hour: never a scheduled full pass.
10579
10637
  expect(runPass).not.toHaveBeenCalled();
10580
10638
  capture.clear();
10581
10639
  runPass.mockClear();
10582
- clockState.now = DEFAULT_FULL_PASS_INTERVAL_MS;
10640
+ clockState.now = DEFAULT_FULL_RECONCILE_MS;
10583
10641
  sleep.tick();
10584
10642
  await flushLoopMicrotasks();
10585
10643
  expectFullReconcileDecision(capture.records[0], "full", [
@@ -10591,6 +10649,10 @@ describe("runRunnerWithLoop — accumulate-and-drain scoped push", () => {
10591
10649
  }
10592
10650
  finally {
10593
10651
  capture.restore();
10652
+ if (saved === undefined)
10653
+ delete process.env.HQ_SYNC_FULL_RECONCILE_MS;
10654
+ else
10655
+ process.env.HQ_SYNC_FULL_RECONCILE_MS = saved;
10594
10656
  }
10595
10657
  });
10596
10658
  it("logs scoped passes with their batch path count and preserves the scoped route", async () => {
@@ -10611,6 +10673,8 @@ describe("runRunnerWithLoop — accumulate-and-drain scoped push", () => {
10611
10673
  capture.restore();
10612
10674
  });
10613
10675
  it("reports interval diagnostics while the configured interval has not elapsed", async () => {
10676
+ const saved = process.env.HQ_SYNC_FULL_RECONCILE_MS;
10677
+ process.env.HQ_SYNC_FULL_RECONCILE_MS = "1000";
10614
10678
  const capture = captureFullReconcileDecisions();
10615
10679
  try {
10616
10680
  const clockState = { now: 0 };
@@ -10619,7 +10683,6 @@ describe("runRunnerWithLoop — accumulate-and-drain scoped push", () => {
10619
10683
  const runPass = vi.fn().mockResolvedValue(completedPassOutcome());
10620
10684
  const loop = runRunnerWithLoop(watchArgv, {
10621
10685
  runPass,
10622
- fullPassIntervalSource: { read: () => 1_000 },
10623
10686
  monotonicNow: () => clockState.now,
10624
10687
  createWatcher: () => makeBatchWatcherStub(),
10625
10688
  sleep: sleep.sleep,
@@ -10655,6 +10718,10 @@ describe("runRunnerWithLoop — accumulate-and-drain scoped push", () => {
10655
10718
  }
10656
10719
  finally {
10657
10720
  capture.restore();
10721
+ if (saved === undefined)
10722
+ delete process.env.HQ_SYNC_FULL_RECONCILE_MS;
10723
+ else
10724
+ process.env.HQ_SYNC_FULL_RECONCILE_MS = saved;
10658
10725
  }
10659
10726
  });
10660
10727
  it("startup runs one full reconcile, then watcher edits interrupt the pending wait", async () => {
@@ -10960,6 +11027,8 @@ describe("runRunnerWithLoop — accumulate-and-drain scoped push", () => {
10960
11027
  await loop;
10961
11028
  });
10962
11029
  it("drops an unroutable batch and leaves the next unexpired poll idle", async () => {
11030
+ const saved = process.env.HQ_SYNC_FULL_RECONCILE_MS;
11031
+ process.env.HQ_SYNC_FULL_RECONCILE_MS = "1000";
10963
11032
  const capture = captureFullReconcileDecisions();
10964
11033
  try {
10965
11034
  const runPass = vi.fn().mockResolvedValue(completedPassOutcome());
@@ -10985,6 +11054,10 @@ describe("runRunnerWithLoop — accumulate-and-drain scoped push", () => {
10985
11054
  }
10986
11055
  finally {
10987
11056
  capture.restore();
11057
+ if (saved === undefined)
11058
+ delete process.env.HQ_SYNC_FULL_RECONCILE_MS;
11059
+ else
11060
+ process.env.HQ_SYNC_FULL_RECONCILE_MS = saved;
10988
11061
  }
10989
11062
  });
10990
11063
  it("personal scoped ticks preserve personal mode for the pull leg", async () => {
@@ -11143,7 +11216,7 @@ describe("runRunnerWithLoop — accumulate-and-drain scoped push", () => {
11143
11216
  }
11144
11217
  expect(runPass).not.toHaveBeenCalled();
11145
11218
  runPass.mockClear();
11146
- clockState.now = DEFAULT_FULL_PASS_INTERVAL_MS;
11219
+ clockState.now = DEFAULT_FULL_RECONCILE_MS;
11147
11220
  sleep.tick();
11148
11221
  await flushLoopMicrotasks();
11149
11222
  expect(runPass.mock.calls.map((call) => call[0])).toEqual([fullArgv]);
@@ -11151,105 +11224,134 @@ describe("runRunnerWithLoop — accumulate-and-drain scoped push", () => {
11151
11224
  sleep.tick();
11152
11225
  await loop;
11153
11226
  });
11154
- it("schedules the full reconcile by elapsed time, not tick count, at the flag fallback", async () => {
11227
+ it("schedules the full reconcile by elapsed time, not tick count, when the interval env is unset", async () => {
11155
11228
  // Pre-fix the unset default was every tenth tick. Ticks fire on every
11156
11229
  // watcher batch, so an active vault ran a ~10-minute full pass every
11157
11230
  // 4-8 minutes — nearly continuous, and the runner's dominant CPU cost
11158
11231
  // once per-pass hashing was fixed.
11159
- const clockState = { now: 0 };
11160
- const watcher = makeBatchWatcherStub();
11161
- const sleep = makeSteppableSleep();
11162
- let triggerShutdown = () => { };
11163
- const runPass = vi.fn().mockResolvedValue(completedPassOutcome());
11164
- const loop = runRunnerWithLoop(watchArgv, {
11165
- runPass,
11166
- clock: new FakeClock(),
11167
- monotonicNow: () => clockState.now,
11168
- createWatcher: () => watcher,
11169
- sleep: sleep.sleep,
11170
- onShutdownSignal: (handler) => {
11171
- triggerShutdown = handler;
11172
- return () => { };
11173
- },
11174
- });
11175
- await flushLoopMicrotasks();
11176
- expect(runPass.mock.calls.map((call) => call[0])).toEqual([fullArgv]);
11177
- runPass.mockClear();
11178
- // Twenty ticks in fifty-nine minutes: the old cadence would have run
11179
- // two full passes here.
11180
- for (let tick = 0; tick < 20; tick++) {
11181
- clockState.now += 177_000;
11232
+ const saved = process.env.HQ_SYNC_FULL_RECONCILE_MS;
11233
+ delete process.env.HQ_SYNC_FULL_RECONCILE_MS;
11234
+ try {
11235
+ const clockState = { now: 0 };
11236
+ const watcher = makeBatchWatcherStub();
11237
+ const sleep = makeSteppableSleep();
11238
+ let triggerShutdown = () => { };
11239
+ const runPass = vi.fn().mockResolvedValue(completedPassOutcome());
11240
+ const loop = runRunnerWithLoop(watchArgv, {
11241
+ runPass,
11242
+ clock: new FakeClock(),
11243
+ monotonicNow: () => clockState.now,
11244
+ createWatcher: () => watcher,
11245
+ sleep: sleep.sleep,
11246
+ onShutdownSignal: (handler) => {
11247
+ triggerShutdown = handler;
11248
+ return () => { };
11249
+ },
11250
+ });
11251
+ await flushLoopMicrotasks();
11252
+ expect(runPass.mock.calls.map((call) => call[0])).toEqual([fullArgv]);
11253
+ runPass.mockClear();
11254
+ // Twenty ticks in fifty-nine minutes: the old cadence would have run
11255
+ // two full passes here.
11256
+ for (let tick = 0; tick < 20; tick++) {
11257
+ clockState.now += 177_000;
11258
+ sleep.tick();
11259
+ await flushLoopMicrotasks();
11260
+ }
11261
+ expect(runPass).not.toHaveBeenCalled();
11262
+ runPass.mockClear();
11263
+ clockState.now = DEFAULT_FULL_RECONCILE_MS;
11182
11264
  sleep.tick();
11183
11265
  await flushLoopMicrotasks();
11266
+ expect(runPass.mock.calls.map((call) => call[0])).toEqual([fullArgv]);
11267
+ triggerShutdown();
11268
+ await loop;
11269
+ }
11270
+ finally {
11271
+ if (saved === undefined)
11272
+ delete process.env.HQ_SYNC_FULL_RECONCILE_MS;
11273
+ else
11274
+ process.env.HQ_SYNC_FULL_RECONCILE_MS = saved;
11184
11275
  }
11185
- expect(runPass).not.toHaveBeenCalled();
11186
- runPass.mockClear();
11187
- clockState.now = DEFAULT_FULL_PASS_INTERVAL_MS;
11188
- sleep.tick();
11189
- await flushLoopMicrotasks();
11190
- expect(runPass.mock.calls.map((call) => call[0])).toEqual([fullArgv]);
11191
- triggerShutdown();
11192
- await loop;
11193
11276
  });
11194
- it("uses the hq-flag interval source instead of the tick count", async () => {
11195
- const clockState = { now: 0 };
11196
- const watcher = makeBatchWatcherStub();
11197
- const sleep = makeSteppableSleep();
11198
- let triggerShutdown = () => { };
11199
- const runPass = vi.fn().mockResolvedValue(completedPassOutcome());
11200
- const loop = runRunnerWithLoop(watchArgv, {
11201
- runPass,
11202
- fullPassIntervalSource: { read: () => 1_000 },
11203
- clock: new FakeClock(),
11204
- monotonicNow: () => clockState.now,
11205
- createWatcher: () => watcher,
11206
- sleep: sleep.sleep,
11207
- onShutdownSignal: (handler) => {
11208
- triggerShutdown = handler;
11209
- return () => { };
11210
- },
11211
- });
11212
- await flushLoopMicrotasks();
11213
- // Startup always forces the first full reconcile, and starts the interval.
11214
- expect(runPass.mock.calls.map((call) => call[0])).toEqual([fullArgv]);
11215
- runPass.mockClear();
11216
- clockState.now = 999;
11217
- sleep.tick();
11218
- await flushLoopMicrotasks();
11219
- expect(runPass).not.toHaveBeenCalled();
11220
- runPass.mockClear();
11221
- clockState.now = 1_000;
11222
- sleep.tick();
11223
- await flushLoopMicrotasks();
11224
- expect(runPass.mock.calls.map((call) => call[0])).toEqual([fullArgv]);
11225
- triggerShutdown();
11226
- await loop;
11277
+ it("uses the configured elapsed-time interval instead of the tick count", async () => {
11278
+ const saved = process.env.HQ_SYNC_FULL_RECONCILE_MS;
11279
+ process.env.HQ_SYNC_FULL_RECONCILE_MS = "1000";
11280
+ try {
11281
+ const clockState = { now: 0 };
11282
+ const watcher = makeBatchWatcherStub();
11283
+ const sleep = makeSteppableSleep();
11284
+ let triggerShutdown = () => { };
11285
+ const runPass = vi.fn().mockResolvedValue(completedPassOutcome());
11286
+ const loop = runRunnerWithLoop(watchArgv, {
11287
+ runPass,
11288
+ clock: new FakeClock(),
11289
+ monotonicNow: () => clockState.now,
11290
+ createWatcher: () => watcher,
11291
+ sleep: sleep.sleep,
11292
+ onShutdownSignal: (handler) => {
11293
+ triggerShutdown = handler;
11294
+ return () => { };
11295
+ },
11296
+ });
11297
+ await flushLoopMicrotasks();
11298
+ // Startup always forces the first full reconcile, and starts the interval.
11299
+ expect(runPass.mock.calls.map((call) => call[0])).toEqual([fullArgv]);
11300
+ runPass.mockClear();
11301
+ clockState.now = 999;
11302
+ sleep.tick();
11303
+ await flushLoopMicrotasks();
11304
+ expect(runPass).not.toHaveBeenCalled();
11305
+ runPass.mockClear();
11306
+ clockState.now = 1_000;
11307
+ sleep.tick();
11308
+ await flushLoopMicrotasks();
11309
+ expect(runPass.mock.calls.map((call) => call[0])).toEqual([fullArgv]);
11310
+ triggerShutdown();
11311
+ await loop;
11312
+ }
11313
+ finally {
11314
+ if (saved === undefined)
11315
+ delete process.env.HQ_SYNC_FULL_RECONCILE_MS;
11316
+ else
11317
+ process.env.HQ_SYNC_FULL_RECONCILE_MS = saved;
11318
+ }
11227
11319
  });
11228
11320
  it("does not let a full-reconcile interval suppress event-push activation", async () => {
11229
- const watcher = makeBatchWatcherStub();
11230
- const sleep = makeSteppableSleep();
11231
- let triggerShutdown = () => { };
11232
- // A numeric partial result does not activate event-push surfaces, so the
11233
- // next tick must force another full pass even though three hours have not elapsed.
11234
- const runPass = vi.fn().mockResolvedValue(PARTIAL_SYNC_EXIT);
11235
- const loop = runRunnerWithLoop(watchArgv, {
11236
- runPass,
11237
- clock: new FakeClock(),
11238
- monotonicNow: () => 0,
11239
- createWatcher: () => watcher,
11240
- sleep: sleep.sleep,
11241
- onShutdownSignal: (handler) => {
11242
- triggerShutdown = handler;
11243
- return () => { };
11244
- },
11245
- });
11246
- await flushLoopMicrotasks();
11247
- runPass.mockClear();
11248
- sleep.tick();
11249
- await flushLoopMicrotasks();
11250
- expect(runPass.mock.calls.map((call) => call[0])).toEqual([fullArgv]);
11251
- triggerShutdown();
11252
- await loop;
11321
+ const saved = process.env.HQ_SYNC_FULL_RECONCILE_MS;
11322
+ process.env.HQ_SYNC_FULL_RECONCILE_MS = "10800000";
11323
+ try {
11324
+ const watcher = makeBatchWatcherStub();
11325
+ const sleep = makeSteppableSleep();
11326
+ let triggerShutdown = () => { };
11327
+ // A numeric partial result does not activate event-push surfaces, so the
11328
+ // next tick must force another full pass even though three hours have not elapsed.
11329
+ const runPass = vi.fn().mockResolvedValue(PARTIAL_SYNC_EXIT);
11330
+ const loop = runRunnerWithLoop(watchArgv, {
11331
+ runPass,
11332
+ clock: new FakeClock(),
11333
+ monotonicNow: () => 0,
11334
+ createWatcher: () => watcher,
11335
+ sleep: sleep.sleep,
11336
+ onShutdownSignal: (handler) => {
11337
+ triggerShutdown = handler;
11338
+ return () => { };
11339
+ },
11340
+ });
11341
+ await flushLoopMicrotasks();
11342
+ runPass.mockClear();
11343
+ sleep.tick();
11344
+ await flushLoopMicrotasks();
11345
+ expect(runPass.mock.calls.map((call) => call[0])).toEqual([fullArgv]);
11346
+ triggerShutdown();
11347
+ await loop;
11348
+ }
11349
+ finally {
11350
+ if (saved === undefined)
11351
+ delete process.env.HQ_SYNC_FULL_RECONCILE_MS;
11352
+ else
11353
+ process.env.HQ_SYNC_FULL_RECONCILE_MS = saved;
11354
+ }
11253
11355
  });
11254
11356
  it("overflow with known dropped-route hints fans out per touched route instead of a full reconcile", async () => {
11255
11357
  const capture = captureFullReconcileDecisions();
@@ -11384,40 +11486,50 @@ describe("runRunnerWithLoop — accumulate-and-drain scoped push", () => {
11384
11486
  await loop;
11385
11487
  });
11386
11488
  it("a batch above the shipped 10,000-path default stays on chunked targeted passes before the interval", async () => {
11387
- const watcher = makeBatchWatcherStub();
11388
- const sleep = makeSteppableSleep();
11389
- let triggerShutdown = () => { };
11390
- const runPass = vi.fn().mockResolvedValue(completedPassOutcome());
11391
- const loop = runRunnerWithLoop(watchArgv, {
11392
- runPass,
11393
- clock: new FakeClock(),
11394
- monotonicNow: () => 0,
11395
- createWatcher: () => watcher,
11396
- sleep: sleep.sleep,
11397
- onShutdownSignal: (handler) => {
11398
- triggerShutdown = handler;
11399
- return () => { };
11400
- },
11401
- });
11402
- await flushLoopMicrotasks();
11403
- runPass.mockClear();
11404
- watcher.emit("companies/indigo/a.md", {
11405
- paths: new Map(Array.from({ length: 10_001 }, (_, index) => [
11406
- `/tmp/hq/companies/indigo/${index}.md`,
11407
- `companies/indigo/${index}.md`,
11408
- ])),
11409
- });
11410
- sleep.tick();
11411
- await flushLoopMicrotasks(40);
11412
- const calls = runPass.mock.calls.map((call) => call[0]);
11413
- expect(calls).not.toContainEqual(fullArgv);
11414
- const pushScopeCounts = calls
11415
- .filter((argv) => argv.includes("push"))
11416
- .map((argv) => scopePathsFromArgv(argv).length);
11417
- expect(Math.max(0, ...pushScopeCounts)).toBeLessThanOrEqual(10_000);
11418
- expect(pushScopeCounts.reduce((sum, count) => sum + count, 0)).toBe(10_001);
11419
- triggerShutdown();
11420
- await loop;
11489
+ const saved = process.env.HQ_SYNC_FULL_RECONCILE_MS;
11490
+ process.env.HQ_SYNC_FULL_RECONCILE_MS = "10800000";
11491
+ try {
11492
+ const watcher = makeBatchWatcherStub();
11493
+ const sleep = makeSteppableSleep();
11494
+ let triggerShutdown = () => { };
11495
+ const runPass = vi.fn().mockResolvedValue(completedPassOutcome());
11496
+ const loop = runRunnerWithLoop(watchArgv, {
11497
+ runPass,
11498
+ clock: new FakeClock(),
11499
+ monotonicNow: () => 0,
11500
+ createWatcher: () => watcher,
11501
+ sleep: sleep.sleep,
11502
+ onShutdownSignal: (handler) => {
11503
+ triggerShutdown = handler;
11504
+ return () => { };
11505
+ },
11506
+ });
11507
+ await flushLoopMicrotasks();
11508
+ runPass.mockClear();
11509
+ watcher.emit("companies/indigo/a.md", {
11510
+ paths: new Map(Array.from({ length: 10_001 }, (_, index) => [
11511
+ `/tmp/hq/companies/indigo/${index}.md`,
11512
+ `companies/indigo/${index}.md`,
11513
+ ])),
11514
+ });
11515
+ sleep.tick();
11516
+ await flushLoopMicrotasks(40);
11517
+ const calls = runPass.mock.calls.map((call) => call[0]);
11518
+ expect(calls).not.toContainEqual(fullArgv);
11519
+ const pushScopeCounts = calls
11520
+ .filter((argv) => argv.includes("push"))
11521
+ .map((argv) => scopePathsFromArgv(argv).length);
11522
+ expect(Math.max(0, ...pushScopeCounts)).toBeLessThanOrEqual(10_000);
11523
+ expect(pushScopeCounts.reduce((sum, count) => sum + count, 0)).toBe(10_001);
11524
+ triggerShutdown();
11525
+ await loop;
11526
+ }
11527
+ finally {
11528
+ if (saved === undefined)
11529
+ delete process.env.HQ_SYNC_FULL_RECONCILE_MS;
11530
+ else
11531
+ process.env.HQ_SYNC_FULL_RECONCILE_MS = saved;
11532
+ }
11421
11533
  });
11422
11534
  it("a throwing targeted pass falls back to one full reconcile instead of dropping the change", async () => {
11423
11535
  const capture = captureFullReconcileDecisions();