@indigoai-us/hq-cloud 6.16.75-alpha.0 → 6.16.76-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,8 @@ 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, 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";
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";
24
25
  import { FullPassCapController, resetFullPassCapLogForTest, } from "../sync/full-pass-caps.js";
25
26
  import { AreaLedgerMigration, JournalStore, openJournalStateStoreForMigration, PERSONAL_VAULT_JOURNAL_SLUG, readJournal, readJournalScoped, writeJournal, } from "../journal.js";
26
27
  import { AreaLedger } from "../sync/area-ledger.js";
@@ -4636,28 +4637,13 @@ describe("advanceMonotonicDeadline", () => {
4636
4637
  });
4637
4638
  });
4638
4639
  });
4639
- describe("watch-loop reconcile environment resolvers", () => {
4640
+ describe("watch-loop reconcile configuration", () => {
4640
4641
  it("uses the shipped 10,000 event-batch default while allowing smaller and larger overrides", () => {
4641
4642
  expect(DEFAULT_EVENT_BATCH_LIMIT).toBe(10_000);
4642
4643
  expect(resolveEventBatchLimit({})).toBe(10_000);
4643
4644
  expect(resolveEventBatchLimit({ [EVENT_BATCH_LIMIT_ENV]: "5" })).toBe(5);
4644
4645
  expect(resolveEventBatchLimit({ [EVENT_BATCH_LIMIT_ENV]: "50000" })).toBe(50_000);
4645
4646
  });
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
- });
4661
4647
  });
4662
4648
  describe("runRunnerWithLoop — adaptive poll interval (no --poll-remote-ms)", () => {
4663
4649
  // Capture the ms handed to sleep on the FIRST poll, then hang so the loop
@@ -4873,10 +4859,8 @@ describe("runRunnerWithLoop — event-push wiring", () => {
4873
4859
  it("parallel coordinator activates every event surface after a partial completed full reconcile", async () => {
4874
4860
  const previousCoordinator = process.env.HQ_SYNC_PARALLEL_COORDINATOR;
4875
4861
  const previousEventSync = process.env.HQ_SYNC_EVENT_SYNC;
4876
- const previousFullReconcileMs = process.env.HQ_SYNC_FULL_RECONCILE_MS;
4877
4862
  process.env.HQ_SYNC_PARALLEL_COORDINATOR = "1";
4878
4863
  process.env.HQ_SYNC_EVENT_SYNC = "1";
4879
- process.env.HQ_SYNC_FULL_RECONCILE_MS = "60000";
4880
4864
  const watcher = makeWatcherStub();
4881
4865
  const receiver = {
4882
4866
  connected: false,
@@ -4936,19 +4920,13 @@ describe("runRunnerWithLoop — event-push wiring", () => {
4936
4920
  delete process.env.HQ_SYNC_EVENT_SYNC;
4937
4921
  else
4938
4922
  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;
4943
4923
  }
4944
4924
  });
4945
4925
  it("parallel coordinator activates event surfaces and advances cadence after a numeric-zero full reconcile", async () => {
4946
4926
  const previousCoordinator = process.env.HQ_SYNC_PARALLEL_COORDINATOR;
4947
4927
  const previousEventSync = process.env.HQ_SYNC_EVENT_SYNC;
4948
- const previousFullReconcileMs = process.env.HQ_SYNC_FULL_RECONCILE_MS;
4949
4928
  process.env.HQ_SYNC_PARALLEL_COORDINATOR = "1";
4950
4929
  process.env.HQ_SYNC_EVENT_SYNC = "1";
4951
- process.env.HQ_SYNC_FULL_RECONCILE_MS = "60000";
4952
4930
  const watcher = makeWatcherStub();
4953
4931
  const receiver = {
4954
4932
  connected: false,
@@ -5008,10 +4986,6 @@ describe("runRunnerWithLoop — event-push wiring", () => {
5008
4986
  delete process.env.HQ_SYNC_EVENT_SYNC;
5009
4987
  else
5010
4988
  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;
5015
4989
  }
5016
4990
  });
5017
4991
  it("parallel coordinator keeps event surfaces off for an auth-required full reconcile", async () => {
@@ -5144,7 +5118,7 @@ describe("runRunnerWithLoop — event-push wiring", () => {
5144
5118
  sleep.tick();
5145
5119
  await flushLoopMicrotasks();
5146
5120
  }
5147
- clockState.now = DEFAULT_FULL_RECONCILE_MS;
5121
+ clockState.now = DEFAULT_FULL_PASS_INTERVAL_MS;
5148
5122
  sleep.tick();
5149
5123
  await flushLoopMicrotasks();
5150
5124
  // Tick 1 and the first tick after an hour has elapsed are full
@@ -5212,7 +5186,7 @@ describe("runRunnerWithLoop — event-push wiring", () => {
5212
5186
  }
5213
5187
  expect(runPass).toHaveBeenCalledTimes(1);
5214
5188
  // The hourly cadence, not a tick count, schedules the next full pass.
5215
- clockState.now = DEFAULT_FULL_RECONCILE_MS;
5189
+ clockState.now = DEFAULT_FULL_PASS_INTERVAL_MS;
5216
5190
  sleep.tick();
5217
5191
  await flushLoopMicrotasks(30);
5218
5192
  expect(runPass).toHaveBeenCalledTimes(2);
@@ -6207,124 +6181,6 @@ describe("runRunnerWithLoop — event-push wiring", () => {
6207
6181
  process.env.HQ_SYNC_PARALLEL_COORDINATOR = previousCoordinator;
6208
6182
  }
6209
6183
  });
6210
- it("measures a queued realtime pass at the operation gate and marks append lock only after admission", async () => {
6211
- const previousCoordinator = process.env.HQ_SYNC_PARALLEL_COORDINATOR;
6212
- process.env.HQ_SYNC_PARALLEL_COORDINATOR = "1";
6213
- const hqRoot = fs.mkdtempSync(path.join(os.tmpdir(), "hq-telemetry-operation-gate-"));
6214
- const watcher = makeBatchWatcherStub();
6215
- let receiverSync;
6216
- let shutdown = () => { };
6217
- let releaseGuard = () => { };
6218
- const guard = new Promise((resolve) => { releaseGuard = resolve; });
6219
- let markGuardStarted = () => { };
6220
- const guardStarted = new Promise((resolve) => { markGuardStarted = resolve; });
6221
- let markTargetStarted = () => { };
6222
- const targetStarted = new Promise((resolve) => { markTargetStarted = resolve; });
6223
- let monotonicMs = 0;
6224
- let guardReleased = false;
6225
- let targetStartedAt;
6226
- const timings = [];
6227
- const stderr = vi.spyOn(process.stderr, "write").mockImplementation((chunk) => {
6228
- if (typeof chunk === "string" && chunk.startsWith("{")) {
6229
- try {
6230
- const record = JSON.parse(chunk);
6231
- if (typeof record === "object" &&
6232
- record !== null &&
6233
- record.event === "sync.realtime.timing")
6234
- timings.push(record);
6235
- }
6236
- catch {
6237
- // Non-telemetry diagnostics are outside this assertion.
6238
- }
6239
- }
6240
- return true;
6241
- });
6242
- const includesScope = (argv, basename) => argv.some((argument) => argument === basename || argument.endsWith(`/${basename}`));
6243
- const runPass = vi.fn(async (argv) => {
6244
- if (includesScope(argv, "guard.md")) {
6245
- markGuardStarted();
6246
- await guard;
6247
- return completedPassOutcome();
6248
- }
6249
- if (includesScope(argv, "target.md")) {
6250
- expect(guardReleased).toBe(true);
6251
- targetStartedAt = monotonicMs;
6252
- markTargetStarted();
6253
- monotonicMs += 1;
6254
- }
6255
- return completedPassOutcome();
6256
- });
6257
- const loop = runRunnerWithLoop(["--companies", "--watch", "--event-push", "--direction", "push", "--hq-root", hqRoot], {
6258
- runPass,
6259
- createWatcher: () => watcher,
6260
- createReceiver: ({ syncBatchFn }) => {
6261
- receiverSync = syncBatchFn;
6262
- return { connected: true, start: async () => { }, dispose: async () => { } };
6263
- },
6264
- monotonicNow: () => monotonicMs,
6265
- sleep: () => new Promise(() => { }),
6266
- onShutdownSignal: (handler) => {
6267
- shutdown = handler;
6268
- return () => { };
6269
- },
6270
- });
6271
- const event = (relativePath) => ({
6272
- kind: "upsert",
6273
- relativePath,
6274
- contentHash: "sha256:remote",
6275
- mtime: "2026-09-23T00:00:00.000Z",
6276
- originDeviceId: "peer-device",
6277
- originTenantId: "tenant-indigo",
6278
- sequenceNumber: 1,
6279
- eventTimestamp: "2026-09-23T00:00:00.000Z",
6280
- });
6281
- try {
6282
- await flushLoopMicrotasks(30);
6283
- runPass.mockClear();
6284
- const guardedPass = receiverSync({
6285
- events: [event("companies/alpha/guard.md")],
6286
- signal: new AbortController().signal,
6287
- });
6288
- await guardStarted;
6289
- const targetAbsolutePath = path.join(hqRoot, "companies", "beta", "target.md");
6290
- fs.mkdirSync(path.dirname(targetAbsolutePath), { recursive: true });
6291
- fs.writeFileSync(targetAbsolutePath, "x");
6292
- watcher.emit("companies/beta/target.md", {
6293
- paths: new Map([
6294
- [targetAbsolutePath, "companies/beta/target.md"],
6295
- ]),
6296
- changes: new Map(),
6297
- });
6298
- await flushLoopMicrotasks(30);
6299
- expect(targetStartedAt).toBeUndefined();
6300
- monotonicMs += 25;
6301
- guardReleased = true;
6302
- releaseGuard();
6303
- await guardedPass;
6304
- await targetStarted;
6305
- await flushLoopMicrotasks(30);
6306
- expect(targetStartedAt).toBe(25);
6307
- expect(timings).toHaveLength(2);
6308
- const targetTiming = timings.find((record) => record.source === "watcher" &&
6309
- record.direction === "push" &&
6310
- record.outcome === "durable");
6311
- expect(targetTiming).toBeDefined();
6312
- expect(targetTiming?.timingMs?.operationGate).toBe(25);
6313
- expect(targetTiming?.timingMs?.appendLock).toBe(0);
6314
- }
6315
- finally {
6316
- guardReleased = true;
6317
- releaseGuard();
6318
- shutdown();
6319
- await loop;
6320
- stderr.mockRestore();
6321
- fs.rmSync(hqRoot, { recursive: true, force: true });
6322
- if (previousCoordinator === undefined)
6323
- delete process.env.HQ_SYNC_PARALLEL_COORDINATOR;
6324
- else
6325
- process.env.HQ_SYNC_PARALLEL_COORDINATOR = previousCoordinator;
6326
- }
6327
- });
6328
6184
  it("REGRESSION: a fast receiver pull overtakes a slow watcher push and records admitted occupancy", async () => {
6329
6185
  const previousCoordinator = process.env.HQ_SYNC_PARALLEL_COORDINATOR;
6330
6186
  const previousAreaStorage = process.env.HQ_SYNC_AREA_STORAGE;
@@ -9050,7 +8906,7 @@ describe("runRunnerWithLoop — event-push wiring", () => {
9050
8906
  runPass,
9051
8907
  clock: new FakeClock(),
9052
8908
  createWatcher: () => watcher,
9053
- monotonicNow: () => (monotonic += DEFAULT_FULL_RECONCILE_MS),
8909
+ monotonicNow: () => (monotonic += DEFAULT_FULL_PASS_INTERVAL_MS),
9054
8910
  sleep: sleep.sleep,
9055
8911
  onShutdownSignal: (handler) => {
9056
8912
  triggerShutdown = handler;
@@ -10032,9 +9888,7 @@ describe("CooperativePassScheduler", () => {
10032
9888
  describe("first-tick realtime yield", () => {
10033
9889
  it("commits a watcher push at the first chore checkpoint within the admission deadline", async () => {
10034
9890
  const previousCoordinator = process.env.HQ_SYNC_PARALLEL_COORDINATOR;
10035
- const previousInterval = process.env.HQ_SYNC_FULL_RECONCILE_MS;
10036
9891
  process.env.HQ_SYNC_PARALLEL_COORDINATOR = "1";
10037
- process.env.HQ_SYNC_FULL_RECONCILE_MS = "10800000";
10038
9892
  const timings = [];
10039
9893
  const spy = vi.spyOn(process.stderr, "write").mockImplementation((chunk) => {
10040
9894
  const text = String(chunk);
@@ -10137,10 +9991,6 @@ describe("first-tick realtime yield", () => {
10137
9991
  delete process.env.HQ_SYNC_PARALLEL_COORDINATOR;
10138
9992
  else
10139
9993
  process.env.HQ_SYNC_PARALLEL_COORDINATOR = previousCoordinator;
10140
- if (previousInterval === undefined)
10141
- delete process.env.HQ_SYNC_FULL_RECONCILE_MS;
10142
- else
10143
- process.env.HQ_SYNC_FULL_RECONCILE_MS = previousInterval;
10144
9994
  }
10145
9995
  });
10146
9996
  });
@@ -10435,8 +10285,6 @@ describe("runRunnerWithLoop — accumulate-and-drain scoped push", () => {
10435
10285
  capture.restore();
10436
10286
  });
10437
10287
  it("logs event-push-surfaces-inactive without silently attributing the first tick", async () => {
10438
- const saved = process.env.HQ_SYNC_FULL_RECONCILE_MS;
10439
- process.env.HQ_SYNC_FULL_RECONCILE_MS = "10800000";
10440
10288
  const capture = captureFullReconcileDecisions();
10441
10289
  try {
10442
10290
  const sleep = makeSteppableSleep();
@@ -10465,10 +10313,6 @@ describe("runRunnerWithLoop — accumulate-and-drain scoped push", () => {
10465
10313
  }
10466
10314
  finally {
10467
10315
  capture.restore();
10468
- if (saved === undefined)
10469
- delete process.env.HQ_SYNC_FULL_RECONCILE_MS;
10470
- else
10471
- process.env.HQ_SYNC_FULL_RECONCILE_MS = saved;
10472
10316
  }
10473
10317
  });
10474
10318
  it("reports every matching trigger instead of short-circuiting at the first", async () => {
@@ -10523,9 +10367,7 @@ describe("runRunnerWithLoop — accumulate-and-drain scoped push", () => {
10523
10367
  });
10524
10368
  it("skips a 404 company route in a mixed drain and records a completed full reconcile", async () => {
10525
10369
  const previousCoordinator = process.env.HQ_SYNC_PARALLEL_COORDINATOR;
10526
- const previousInterval = process.env.HQ_SYNC_FULL_RECONCILE_MS;
10527
10370
  process.env.HQ_SYNC_PARALLEL_COORDINATOR = "1";
10528
- process.env.HQ_SYNC_FULL_RECONCILE_MS = "10800000";
10529
10371
  const failedLines = [];
10530
10372
  const decisions = [];
10531
10373
  const timingRecords = [];
@@ -10625,17 +10467,11 @@ describe("runRunnerWithLoop — accumulate-and-drain scoped push", () => {
10625
10467
  delete process.env.HQ_SYNC_PARALLEL_COORDINATOR;
10626
10468
  else
10627
10469
  process.env.HQ_SYNC_PARALLEL_COORDINATOR = previousCoordinator;
10628
- if (previousInterval === undefined)
10629
- delete process.env.HQ_SYNC_FULL_RECONCILE_MS;
10630
- else
10631
- process.env.HQ_SYNC_FULL_RECONCILE_MS = previousInterval;
10632
10470
  }
10633
10471
  });
10634
10472
  it("does not escalate a fully-enumerated over-limit batch to a full reconcile", async () => {
10635
10473
  const savedLimit = process.env.HQ_SYNC_EVENT_BATCH_LIMIT;
10636
- const savedInterval = process.env.HQ_SYNC_FULL_RECONCILE_MS;
10637
10474
  process.env.HQ_SYNC_EVENT_BATCH_LIMIT = "2";
10638
- process.env.HQ_SYNC_FULL_RECONCILE_MS = "10800000";
10639
10475
  const journal = captureWatchLoopJournal();
10640
10476
  try {
10641
10477
  const runPass = vi.fn().mockResolvedValue(completedPassOutcome());
@@ -10675,17 +10511,11 @@ describe("runRunnerWithLoop — accumulate-and-drain scoped push", () => {
10675
10511
  delete process.env.HQ_SYNC_EVENT_BATCH_LIMIT;
10676
10512
  else
10677
10513
  process.env.HQ_SYNC_EVENT_BATCH_LIMIT = savedLimit;
10678
- if (savedInterval === undefined)
10679
- delete process.env.HQ_SYNC_FULL_RECONCILE_MS;
10680
- else
10681
- process.env.HQ_SYNC_FULL_RECONCILE_MS = savedInterval;
10682
10514
  }
10683
10515
  });
10684
10516
  it("still escalates an overflowed batch with unknown routes to a full reconcile", async () => {
10685
10517
  const savedLimit = process.env.HQ_SYNC_EVENT_BATCH_LIMIT;
10686
- const savedInterval = process.env.HQ_SYNC_FULL_RECONCILE_MS;
10687
10518
  process.env.HQ_SYNC_EVENT_BATCH_LIMIT = "2";
10688
- process.env.HQ_SYNC_FULL_RECONCILE_MS = "10800000";
10689
10519
  const journal = captureWatchLoopJournal();
10690
10520
  try {
10691
10521
  const runPass = vi.fn().mockResolvedValue(completedPassOutcome());
@@ -10717,15 +10547,9 @@ describe("runRunnerWithLoop — accumulate-and-drain scoped push", () => {
10717
10547
  delete process.env.HQ_SYNC_EVENT_BATCH_LIMIT;
10718
10548
  else
10719
10549
  process.env.HQ_SYNC_EVENT_BATCH_LIMIT = savedLimit;
10720
- if (savedInterval === undefined)
10721
- delete process.env.HQ_SYNC_FULL_RECONCILE_MS;
10722
- else
10723
- process.env.HQ_SYNC_FULL_RECONCILE_MS = savedInterval;
10724
10550
  }
10725
10551
  });
10726
- it("logs scheduled-interval as the sole full-reconcile trigger on the default hourly cadence", async () => {
10727
- const saved = process.env.HQ_SYNC_FULL_RECONCILE_MS;
10728
- delete process.env.HQ_SYNC_FULL_RECONCILE_MS;
10552
+ it("logs scheduled-interval as the sole full-reconcile trigger on the six-hour default", async () => {
10729
10553
  const capture = captureFullReconcileDecisions();
10730
10554
  try {
10731
10555
  const clockState = { now: 0 };
@@ -10751,11 +10575,11 @@ describe("runRunnerWithLoop — accumulate-and-drain scoped push", () => {
10751
10575
  sleep.tick();
10752
10576
  await flushLoopMicrotasks();
10753
10577
  }
10754
- // A dozen ticks inside the hour: never a scheduled full pass.
10578
+ // A dozen ticks inside the interval: never a scheduled full pass.
10755
10579
  expect(runPass).not.toHaveBeenCalled();
10756
10580
  capture.clear();
10757
10581
  runPass.mockClear();
10758
- clockState.now = DEFAULT_FULL_RECONCILE_MS;
10582
+ clockState.now = DEFAULT_FULL_PASS_INTERVAL_MS;
10759
10583
  sleep.tick();
10760
10584
  await flushLoopMicrotasks();
10761
10585
  expectFullReconcileDecision(capture.records[0], "full", [
@@ -10767,10 +10591,6 @@ describe("runRunnerWithLoop — accumulate-and-drain scoped push", () => {
10767
10591
  }
10768
10592
  finally {
10769
10593
  capture.restore();
10770
- if (saved === undefined)
10771
- delete process.env.HQ_SYNC_FULL_RECONCILE_MS;
10772
- else
10773
- process.env.HQ_SYNC_FULL_RECONCILE_MS = saved;
10774
10594
  }
10775
10595
  });
10776
10596
  it("logs scoped passes with their batch path count and preserves the scoped route", async () => {
@@ -10791,8 +10611,6 @@ describe("runRunnerWithLoop — accumulate-and-drain scoped push", () => {
10791
10611
  capture.restore();
10792
10612
  });
10793
10613
  it("reports interval diagnostics while the configured interval has not elapsed", async () => {
10794
- const saved = process.env.HQ_SYNC_FULL_RECONCILE_MS;
10795
- process.env.HQ_SYNC_FULL_RECONCILE_MS = "1000";
10796
10614
  const capture = captureFullReconcileDecisions();
10797
10615
  try {
10798
10616
  const clockState = { now: 0 };
@@ -10801,6 +10619,7 @@ describe("runRunnerWithLoop — accumulate-and-drain scoped push", () => {
10801
10619
  const runPass = vi.fn().mockResolvedValue(completedPassOutcome());
10802
10620
  const loop = runRunnerWithLoop(watchArgv, {
10803
10621
  runPass,
10622
+ fullPassIntervalSource: { read: () => 1_000 },
10804
10623
  monotonicNow: () => clockState.now,
10805
10624
  createWatcher: () => makeBatchWatcherStub(),
10806
10625
  sleep: sleep.sleep,
@@ -10836,10 +10655,6 @@ describe("runRunnerWithLoop — accumulate-and-drain scoped push", () => {
10836
10655
  }
10837
10656
  finally {
10838
10657
  capture.restore();
10839
- if (saved === undefined)
10840
- delete process.env.HQ_SYNC_FULL_RECONCILE_MS;
10841
- else
10842
- process.env.HQ_SYNC_FULL_RECONCILE_MS = saved;
10843
10658
  }
10844
10659
  });
10845
10660
  it("startup runs one full reconcile, then watcher edits interrupt the pending wait", async () => {
@@ -11145,8 +10960,6 @@ describe("runRunnerWithLoop — accumulate-and-drain scoped push", () => {
11145
10960
  await loop;
11146
10961
  });
11147
10962
  it("drops an unroutable batch and leaves the next unexpired poll idle", async () => {
11148
- const saved = process.env.HQ_SYNC_FULL_RECONCILE_MS;
11149
- process.env.HQ_SYNC_FULL_RECONCILE_MS = "1000";
11150
10963
  const capture = captureFullReconcileDecisions();
11151
10964
  try {
11152
10965
  const runPass = vi.fn().mockResolvedValue(completedPassOutcome());
@@ -11172,10 +10985,6 @@ describe("runRunnerWithLoop — accumulate-and-drain scoped push", () => {
11172
10985
  }
11173
10986
  finally {
11174
10987
  capture.restore();
11175
- if (saved === undefined)
11176
- delete process.env.HQ_SYNC_FULL_RECONCILE_MS;
11177
- else
11178
- process.env.HQ_SYNC_FULL_RECONCILE_MS = saved;
11179
10988
  }
11180
10989
  });
11181
10990
  it("personal scoped ticks preserve personal mode for the pull leg", async () => {
@@ -11334,7 +11143,7 @@ describe("runRunnerWithLoop — accumulate-and-drain scoped push", () => {
11334
11143
  }
11335
11144
  expect(runPass).not.toHaveBeenCalled();
11336
11145
  runPass.mockClear();
11337
- clockState.now = DEFAULT_FULL_RECONCILE_MS;
11146
+ clockState.now = DEFAULT_FULL_PASS_INTERVAL_MS;
11338
11147
  sleep.tick();
11339
11148
  await flushLoopMicrotasks();
11340
11149
  expect(runPass.mock.calls.map((call) => call[0])).toEqual([fullArgv]);
@@ -11342,134 +11151,105 @@ describe("runRunnerWithLoop — accumulate-and-drain scoped push", () => {
11342
11151
  sleep.tick();
11343
11152
  await loop;
11344
11153
  });
11345
- it("schedules the full reconcile by elapsed time, not tick count, when the interval env is unset", async () => {
11154
+ it("schedules the full reconcile by elapsed time, not tick count, at the flag fallback", async () => {
11346
11155
  // Pre-fix the unset default was every tenth tick. Ticks fire on every
11347
11156
  // watcher batch, so an active vault ran a ~10-minute full pass every
11348
11157
  // 4-8 minutes — nearly continuous, and the runner's dominant CPU cost
11349
11158
  // once per-pass hashing was fixed.
11350
- const saved = process.env.HQ_SYNC_FULL_RECONCILE_MS;
11351
- delete process.env.HQ_SYNC_FULL_RECONCILE_MS;
11352
- try {
11353
- const clockState = { now: 0 };
11354
- const watcher = makeBatchWatcherStub();
11355
- const sleep = makeSteppableSleep();
11356
- let triggerShutdown = () => { };
11357
- const runPass = vi.fn().mockResolvedValue(completedPassOutcome());
11358
- const loop = runRunnerWithLoop(watchArgv, {
11359
- runPass,
11360
- clock: new FakeClock(),
11361
- monotonicNow: () => clockState.now,
11362
- createWatcher: () => watcher,
11363
- sleep: sleep.sleep,
11364
- onShutdownSignal: (handler) => {
11365
- triggerShutdown = handler;
11366
- return () => { };
11367
- },
11368
- });
11369
- await flushLoopMicrotasks();
11370
- expect(runPass.mock.calls.map((call) => call[0])).toEqual([fullArgv]);
11371
- runPass.mockClear();
11372
- // Twenty ticks in fifty-nine minutes: the old cadence would have run
11373
- // two full passes here.
11374
- for (let tick = 0; tick < 20; tick++) {
11375
- clockState.now += 177_000;
11376
- sleep.tick();
11377
- await flushLoopMicrotasks();
11378
- }
11379
- expect(runPass).not.toHaveBeenCalled();
11380
- runPass.mockClear();
11381
- clockState.now = DEFAULT_FULL_RECONCILE_MS;
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;
11382
11182
  sleep.tick();
11383
11183
  await flushLoopMicrotasks();
11384
- expect(runPass.mock.calls.map((call) => call[0])).toEqual([fullArgv]);
11385
- triggerShutdown();
11386
- await loop;
11387
- }
11388
- finally {
11389
- if (saved === undefined)
11390
- delete process.env.HQ_SYNC_FULL_RECONCILE_MS;
11391
- else
11392
- process.env.HQ_SYNC_FULL_RECONCILE_MS = saved;
11393
11184
  }
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;
11394
11193
  });
11395
- it("uses the configured elapsed-time interval instead of the tick count", async () => {
11396
- const saved = process.env.HQ_SYNC_FULL_RECONCILE_MS;
11397
- process.env.HQ_SYNC_FULL_RECONCILE_MS = "1000";
11398
- try {
11399
- const clockState = { now: 0 };
11400
- const watcher = makeBatchWatcherStub();
11401
- const sleep = makeSteppableSleep();
11402
- let triggerShutdown = () => { };
11403
- const runPass = vi.fn().mockResolvedValue(completedPassOutcome());
11404
- const loop = runRunnerWithLoop(watchArgv, {
11405
- runPass,
11406
- clock: new FakeClock(),
11407
- monotonicNow: () => clockState.now,
11408
- createWatcher: () => watcher,
11409
- sleep: sleep.sleep,
11410
- onShutdownSignal: (handler) => {
11411
- triggerShutdown = handler;
11412
- return () => { };
11413
- },
11414
- });
11415
- await flushLoopMicrotasks();
11416
- // Startup always forces the first full reconcile, and starts the interval.
11417
- expect(runPass.mock.calls.map((call) => call[0])).toEqual([fullArgv]);
11418
- runPass.mockClear();
11419
- clockState.now = 999;
11420
- sleep.tick();
11421
- await flushLoopMicrotasks();
11422
- expect(runPass).not.toHaveBeenCalled();
11423
- runPass.mockClear();
11424
- clockState.now = 1_000;
11425
- sleep.tick();
11426
- await flushLoopMicrotasks();
11427
- expect(runPass.mock.calls.map((call) => call[0])).toEqual([fullArgv]);
11428
- triggerShutdown();
11429
- await loop;
11430
- }
11431
- finally {
11432
- if (saved === undefined)
11433
- delete process.env.HQ_SYNC_FULL_RECONCILE_MS;
11434
- else
11435
- process.env.HQ_SYNC_FULL_RECONCILE_MS = saved;
11436
- }
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;
11437
11227
  });
11438
11228
  it("does not let a full-reconcile interval suppress event-push activation", async () => {
11439
- const saved = process.env.HQ_SYNC_FULL_RECONCILE_MS;
11440
- process.env.HQ_SYNC_FULL_RECONCILE_MS = "10800000";
11441
- try {
11442
- const watcher = makeBatchWatcherStub();
11443
- const sleep = makeSteppableSleep();
11444
- let triggerShutdown = () => { };
11445
- // A numeric partial result does not activate event-push surfaces, so the
11446
- // next tick must force another full pass even though three hours have not elapsed.
11447
- const runPass = vi.fn().mockResolvedValue(PARTIAL_SYNC_EXIT);
11448
- const loop = runRunnerWithLoop(watchArgv, {
11449
- runPass,
11450
- clock: new FakeClock(),
11451
- monotonicNow: () => 0,
11452
- createWatcher: () => watcher,
11453
- sleep: sleep.sleep,
11454
- onShutdownSignal: (handler) => {
11455
- triggerShutdown = handler;
11456
- return () => { };
11457
- },
11458
- });
11459
- await flushLoopMicrotasks();
11460
- runPass.mockClear();
11461
- sleep.tick();
11462
- await flushLoopMicrotasks();
11463
- expect(runPass.mock.calls.map((call) => call[0])).toEqual([fullArgv]);
11464
- triggerShutdown();
11465
- await loop;
11466
- }
11467
- finally {
11468
- if (saved === undefined)
11469
- delete process.env.HQ_SYNC_FULL_RECONCILE_MS;
11470
- else
11471
- process.env.HQ_SYNC_FULL_RECONCILE_MS = saved;
11472
- }
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;
11473
11253
  });
11474
11254
  it("overflow with known dropped-route hints fans out per touched route instead of a full reconcile", async () => {
11475
11255
  const capture = captureFullReconcileDecisions();
@@ -11604,50 +11384,40 @@ describe("runRunnerWithLoop — accumulate-and-drain scoped push", () => {
11604
11384
  await loop;
11605
11385
  });
11606
11386
  it("a batch above the shipped 10,000-path default stays on chunked targeted passes before the interval", async () => {
11607
- const saved = process.env.HQ_SYNC_FULL_RECONCILE_MS;
11608
- process.env.HQ_SYNC_FULL_RECONCILE_MS = "10800000";
11609
- try {
11610
- const watcher = makeBatchWatcherStub();
11611
- const sleep = makeSteppableSleep();
11612
- let triggerShutdown = () => { };
11613
- const runPass = vi.fn().mockResolvedValue(completedPassOutcome());
11614
- const loop = runRunnerWithLoop(watchArgv, {
11615
- runPass,
11616
- clock: new FakeClock(),
11617
- monotonicNow: () => 0,
11618
- createWatcher: () => watcher,
11619
- sleep: sleep.sleep,
11620
- onShutdownSignal: (handler) => {
11621
- triggerShutdown = handler;
11622
- return () => { };
11623
- },
11624
- });
11625
- await flushLoopMicrotasks();
11626
- runPass.mockClear();
11627
- watcher.emit("companies/indigo/a.md", {
11628
- paths: new Map(Array.from({ length: 10_001 }, (_, index) => [
11629
- `/tmp/hq/companies/indigo/${index}.md`,
11630
- `companies/indigo/${index}.md`,
11631
- ])),
11632
- });
11633
- sleep.tick();
11634
- await flushLoopMicrotasks(40);
11635
- const calls = runPass.mock.calls.map((call) => call[0]);
11636
- expect(calls).not.toContainEqual(fullArgv);
11637
- const pushScopeCounts = calls
11638
- .filter((argv) => argv.includes("push"))
11639
- .map((argv) => scopePathsFromArgv(argv).length);
11640
- expect(Math.max(0, ...pushScopeCounts)).toBeLessThanOrEqual(10_000);
11641
- expect(pushScopeCounts.reduce((sum, count) => sum + count, 0)).toBe(10_001);
11642
- triggerShutdown();
11643
- await loop;
11644
- }
11645
- finally {
11646
- if (saved === undefined)
11647
- delete process.env.HQ_SYNC_FULL_RECONCILE_MS;
11648
- else
11649
- process.env.HQ_SYNC_FULL_RECONCILE_MS = saved;
11650
- }
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;
11651
11421
  });
11652
11422
  it("a throwing targeted pass falls back to one full reconcile instead of dropping the change", async () => {
11653
11423
  const capture = captureFullReconcileDecisions();