@indigoai-us/hq-cloud 6.16.76-alpha.0 → 6.16.78-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.
@@ -16,12 +16,11 @@ import { monitorEventLoopDelay } from "node:perf_hooks";
16
16
  import { runRunner, runRunnerWithLoop, resolveDeletePolicy, resolveSkipPersonal, resolveSkipCompanies, selectObjectIOFactory, routeChangeToTarget, buildTargetedPushArgv, resolvePullScope, readPinnedPrefixes, SESSIONS_SCOPE_PREFIX, defaultCollectTelemetry, AUTH_REQUIRED_PASS_EXIT, } from "./sync-runner.js";
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
- import { PresignObjectIO, S3SdkObjectIO } from "../object-io.js";
19
+ import { ObjectLockChecksumRequiredError, 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";
@@ -566,6 +565,79 @@ describe("mid-pass identity refusal", () => {
566
565
  expect(deps.stderr.events().some((e) => e.type === "auth-error")).toBe(false);
567
566
  });
568
567
  });
568
+ describe("remote failure contract", () => {
569
+ const person = {
570
+ uid: "ent_person_remote_failure_contract",
571
+ type: "person",
572
+ bucketName: "hq-vault-personal-contract",
573
+ status: "active",
574
+ };
575
+ it.each([
576
+ [
577
+ "terminal 403 refusal",
578
+ () => new CognitoRefreshError("session reauth required (403)", true, 403),
579
+ 0,
580
+ "auth-error",
581
+ "quick refresh",
582
+ ],
583
+ [
584
+ "404 route",
585
+ () => new VaultNotFoundError("remote route no longer exists (404)"),
586
+ PARTIAL_SYNC_EXIT,
587
+ "error",
588
+ "404",
589
+ ],
590
+ [
591
+ "429 throttle",
592
+ () => Object.assign(new Error("remote throttled (429)"), { statusCode: 429 }),
593
+ TRANSIENT_NETWORK_EXIT,
594
+ "transient-network",
595
+ "429",
596
+ ],
597
+ [
598
+ "503 throttle",
599
+ () => Object.assign(new Error("remote unavailable (503)"), { statusCode: 503 }),
600
+ TRANSIENT_NETWORK_EXIT,
601
+ "transient-network",
602
+ "503",
603
+ ],
604
+ [
605
+ "Object Lock checksum refusal",
606
+ () => new ObjectLockChecksumRequiredError("remote.md", "checksum required"),
607
+ PARTIAL_SYNC_EXIT,
608
+ "error",
609
+ "ObjectLockChecksumRequired",
610
+ ],
611
+ [
612
+ "timeout",
613
+ () => Object.assign(new Error("remote timed out"), { name: "TimeoutError" }),
614
+ TRANSIENT_NETWORK_EXIT,
615
+ "transient-network",
616
+ "timed out",
617
+ ],
618
+ [
619
+ "abort",
620
+ () => Object.assign(new Error("remote aborted"), { name: "AbortError" }),
621
+ TRANSIENT_NETWORK_EXIT,
622
+ "transient-network",
623
+ "aborted",
624
+ ],
625
+ ])("keeps the journal stable and records the runner outcome for %s", async (_description, makeFailure, expectedExit, telemetryType, telemetryReason) => {
626
+ const before = readJournal(PERSONAL_VAULT_JOURNAL_SLUG);
627
+ const deps = makeDeps({
628
+ sync: vi.fn().mockRejectedValue(makeFailure()),
629
+ createVaultClient: () => makeVaultStub({ listPersons: () => Promise.resolve([person]) }),
630
+ });
631
+ expect(await runRunner(["--personal"], deps)).toBe(expectedExit);
632
+ expect(readJournal(PERSONAL_VAULT_JOURNAL_SLUG).files).toEqual(before.files);
633
+ const events = [...deps.stdout.events(), ...deps.stderr.events()];
634
+ expect(events.some((event) => event.type === telemetryType)).toBe(true);
635
+ expect(`${deps.stdout.raw()}${deps.stderr.raw()}`).toContain(telemetryReason);
636
+ if (telemetryType === "transient-network") {
637
+ expect(events.some((event) => event.type === "error")).toBe(false);
638
+ }
639
+ });
640
+ });
569
641
  // ---------------------------------------------------------------------------
570
642
  // memberships retry (3x with backoff, then abort)
571
643
  // ---------------------------------------------------------------------------
@@ -4637,13 +4709,28 @@ describe("advanceMonotonicDeadline", () => {
4637
4709
  });
4638
4710
  });
4639
4711
  });
4640
- describe("watch-loop reconcile configuration", () => {
4712
+ describe("watch-loop reconcile environment resolvers", () => {
4641
4713
  it("uses the shipped 10,000 event-batch default while allowing smaller and larger overrides", () => {
4642
4714
  expect(DEFAULT_EVENT_BATCH_LIMIT).toBe(10_000);
4643
4715
  expect(resolveEventBatchLimit({})).toBe(10_000);
4644
4716
  expect(resolveEventBatchLimit({ [EVENT_BATCH_LIMIT_ENV]: "5" })).toBe(5);
4645
4717
  expect(resolveEventBatchLimit({ [EVENT_BATCH_LIMIT_ENV]: "50000" })).toBe(50_000);
4646
4718
  });
4719
+ it("defaults the full-reconcile cadence to one elapsed hour for an unset or invalid interval", () => {
4720
+ // The legacy default was "every tenth tick" with no elapsed-time floor.
4721
+ // Ticks fire on every watcher batch, not just polls, so on an active
4722
+ // vault that meant a full pass every 4-8 minutes — and each pass on a
4723
+ // real install lasts ~10 minutes. Full reconcile is the correctness
4724
+ // backstop behind event-push, so elapsed time is the right clock.
4725
+ expect(DEFAULT_FULL_RECONCILE_MS).toBe(3_600_000);
4726
+ expect(resolveFullReconcileMs({})).toBe(DEFAULT_FULL_RECONCILE_MS);
4727
+ for (const raw of ["", "0", "0.5", "-1", "NaN", "not-a-number", "Infinity"]) {
4728
+ expect(resolveFullReconcileMs({ [FULL_RECONCILE_MS_ENV]: raw })).toBe(DEFAULT_FULL_RECONCILE_MS);
4729
+ }
4730
+ });
4731
+ it("accepts a positive millisecond full-reconcile interval", () => {
4732
+ expect(resolveFullReconcileMs({ [FULL_RECONCILE_MS_ENV]: "10800000" })).toBe(10_800_000);
4733
+ });
4647
4734
  });
4648
4735
  describe("runRunnerWithLoop — adaptive poll interval (no --poll-remote-ms)", () => {
4649
4736
  // Capture the ms handed to sleep on the FIRST poll, then hang so the loop
@@ -4859,8 +4946,10 @@ describe("runRunnerWithLoop — event-push wiring", () => {
4859
4946
  it("parallel coordinator activates every event surface after a partial completed full reconcile", async () => {
4860
4947
  const previousCoordinator = process.env.HQ_SYNC_PARALLEL_COORDINATOR;
4861
4948
  const previousEventSync = process.env.HQ_SYNC_EVENT_SYNC;
4949
+ const previousFullReconcileMs = process.env.HQ_SYNC_FULL_RECONCILE_MS;
4862
4950
  process.env.HQ_SYNC_PARALLEL_COORDINATOR = "1";
4863
4951
  process.env.HQ_SYNC_EVENT_SYNC = "1";
4952
+ process.env.HQ_SYNC_FULL_RECONCILE_MS = "60000";
4864
4953
  const watcher = makeWatcherStub();
4865
4954
  const receiver = {
4866
4955
  connected: false,
@@ -4920,13 +5009,19 @@ describe("runRunnerWithLoop — event-push wiring", () => {
4920
5009
  delete process.env.HQ_SYNC_EVENT_SYNC;
4921
5010
  else
4922
5011
  process.env.HQ_SYNC_EVENT_SYNC = previousEventSync;
5012
+ if (previousFullReconcileMs === undefined)
5013
+ delete process.env.HQ_SYNC_FULL_RECONCILE_MS;
5014
+ else
5015
+ process.env.HQ_SYNC_FULL_RECONCILE_MS = previousFullReconcileMs;
4923
5016
  }
4924
5017
  });
4925
5018
  it("parallel coordinator activates event surfaces and advances cadence after a numeric-zero full reconcile", async () => {
4926
5019
  const previousCoordinator = process.env.HQ_SYNC_PARALLEL_COORDINATOR;
4927
5020
  const previousEventSync = process.env.HQ_SYNC_EVENT_SYNC;
5021
+ const previousFullReconcileMs = process.env.HQ_SYNC_FULL_RECONCILE_MS;
4928
5022
  process.env.HQ_SYNC_PARALLEL_COORDINATOR = "1";
4929
5023
  process.env.HQ_SYNC_EVENT_SYNC = "1";
5024
+ process.env.HQ_SYNC_FULL_RECONCILE_MS = "60000";
4930
5025
  const watcher = makeWatcherStub();
4931
5026
  const receiver = {
4932
5027
  connected: false,
@@ -4986,6 +5081,10 @@ describe("runRunnerWithLoop — event-push wiring", () => {
4986
5081
  delete process.env.HQ_SYNC_EVENT_SYNC;
4987
5082
  else
4988
5083
  process.env.HQ_SYNC_EVENT_SYNC = previousEventSync;
5084
+ if (previousFullReconcileMs === undefined)
5085
+ delete process.env.HQ_SYNC_FULL_RECONCILE_MS;
5086
+ else
5087
+ process.env.HQ_SYNC_FULL_RECONCILE_MS = previousFullReconcileMs;
4989
5088
  }
4990
5089
  });
4991
5090
  it("parallel coordinator keeps event surfaces off for an auth-required full reconcile", async () => {
@@ -5118,7 +5217,7 @@ describe("runRunnerWithLoop — event-push wiring", () => {
5118
5217
  sleep.tick();
5119
5218
  await flushLoopMicrotasks();
5120
5219
  }
5121
- clockState.now = DEFAULT_FULL_PASS_INTERVAL_MS;
5220
+ clockState.now = DEFAULT_FULL_RECONCILE_MS;
5122
5221
  sleep.tick();
5123
5222
  await flushLoopMicrotasks();
5124
5223
  // Tick 1 and the first tick after an hour has elapsed are full
@@ -5186,7 +5285,7 @@ describe("runRunnerWithLoop — event-push wiring", () => {
5186
5285
  }
5187
5286
  expect(runPass).toHaveBeenCalledTimes(1);
5188
5287
  // The hourly cadence, not a tick count, schedules the next full pass.
5189
- clockState.now = DEFAULT_FULL_PASS_INTERVAL_MS;
5288
+ clockState.now = DEFAULT_FULL_RECONCILE_MS;
5190
5289
  sleep.tick();
5191
5290
  await flushLoopMicrotasks(30);
5192
5291
  expect(runPass).toHaveBeenCalledTimes(2);
@@ -8906,7 +9005,7 @@ describe("runRunnerWithLoop — event-push wiring", () => {
8906
9005
  runPass,
8907
9006
  clock: new FakeClock(),
8908
9007
  createWatcher: () => watcher,
8909
- monotonicNow: () => (monotonic += DEFAULT_FULL_PASS_INTERVAL_MS),
9008
+ monotonicNow: () => (monotonic += DEFAULT_FULL_RECONCILE_MS),
8910
9009
  sleep: sleep.sleep,
8911
9010
  onShutdownSignal: (handler) => {
8912
9011
  triggerShutdown = handler;
@@ -9888,7 +9987,9 @@ describe("CooperativePassScheduler", () => {
9888
9987
  describe("first-tick realtime yield", () => {
9889
9988
  it("commits a watcher push at the first chore checkpoint within the admission deadline", async () => {
9890
9989
  const previousCoordinator = process.env.HQ_SYNC_PARALLEL_COORDINATOR;
9990
+ const previousInterval = process.env.HQ_SYNC_FULL_RECONCILE_MS;
9891
9991
  process.env.HQ_SYNC_PARALLEL_COORDINATOR = "1";
9992
+ process.env.HQ_SYNC_FULL_RECONCILE_MS = "10800000";
9892
9993
  const timings = [];
9893
9994
  const spy = vi.spyOn(process.stderr, "write").mockImplementation((chunk) => {
9894
9995
  const text = String(chunk);
@@ -9991,6 +10092,10 @@ describe("first-tick realtime yield", () => {
9991
10092
  delete process.env.HQ_SYNC_PARALLEL_COORDINATOR;
9992
10093
  else
9993
10094
  process.env.HQ_SYNC_PARALLEL_COORDINATOR = previousCoordinator;
10095
+ if (previousInterval === undefined)
10096
+ delete process.env.HQ_SYNC_FULL_RECONCILE_MS;
10097
+ else
10098
+ process.env.HQ_SYNC_FULL_RECONCILE_MS = previousInterval;
9994
10099
  }
9995
10100
  });
9996
10101
  });
@@ -10285,6 +10390,8 @@ describe("runRunnerWithLoop — accumulate-and-drain scoped push", () => {
10285
10390
  capture.restore();
10286
10391
  });
10287
10392
  it("logs event-push-surfaces-inactive without silently attributing the first tick", async () => {
10393
+ const saved = process.env.HQ_SYNC_FULL_RECONCILE_MS;
10394
+ process.env.HQ_SYNC_FULL_RECONCILE_MS = "10800000";
10288
10395
  const capture = captureFullReconcileDecisions();
10289
10396
  try {
10290
10397
  const sleep = makeSteppableSleep();
@@ -10313,6 +10420,10 @@ describe("runRunnerWithLoop — accumulate-and-drain scoped push", () => {
10313
10420
  }
10314
10421
  finally {
10315
10422
  capture.restore();
10423
+ if (saved === undefined)
10424
+ delete process.env.HQ_SYNC_FULL_RECONCILE_MS;
10425
+ else
10426
+ process.env.HQ_SYNC_FULL_RECONCILE_MS = saved;
10316
10427
  }
10317
10428
  });
10318
10429
  it("reports every matching trigger instead of short-circuiting at the first", async () => {
@@ -10367,7 +10478,9 @@ describe("runRunnerWithLoop — accumulate-and-drain scoped push", () => {
10367
10478
  });
10368
10479
  it("skips a 404 company route in a mixed drain and records a completed full reconcile", async () => {
10369
10480
  const previousCoordinator = process.env.HQ_SYNC_PARALLEL_COORDINATOR;
10481
+ const previousInterval = process.env.HQ_SYNC_FULL_RECONCILE_MS;
10370
10482
  process.env.HQ_SYNC_PARALLEL_COORDINATOR = "1";
10483
+ process.env.HQ_SYNC_FULL_RECONCILE_MS = "10800000";
10371
10484
  const failedLines = [];
10372
10485
  const decisions = [];
10373
10486
  const timingRecords = [];
@@ -10467,11 +10580,17 @@ describe("runRunnerWithLoop — accumulate-and-drain scoped push", () => {
10467
10580
  delete process.env.HQ_SYNC_PARALLEL_COORDINATOR;
10468
10581
  else
10469
10582
  process.env.HQ_SYNC_PARALLEL_COORDINATOR = previousCoordinator;
10583
+ if (previousInterval === undefined)
10584
+ delete process.env.HQ_SYNC_FULL_RECONCILE_MS;
10585
+ else
10586
+ process.env.HQ_SYNC_FULL_RECONCILE_MS = previousInterval;
10470
10587
  }
10471
10588
  });
10472
10589
  it("does not escalate a fully-enumerated over-limit batch to a full reconcile", async () => {
10473
10590
  const savedLimit = process.env.HQ_SYNC_EVENT_BATCH_LIMIT;
10591
+ const savedInterval = process.env.HQ_SYNC_FULL_RECONCILE_MS;
10474
10592
  process.env.HQ_SYNC_EVENT_BATCH_LIMIT = "2";
10593
+ process.env.HQ_SYNC_FULL_RECONCILE_MS = "10800000";
10475
10594
  const journal = captureWatchLoopJournal();
10476
10595
  try {
10477
10596
  const runPass = vi.fn().mockResolvedValue(completedPassOutcome());
@@ -10511,11 +10630,17 @@ describe("runRunnerWithLoop — accumulate-and-drain scoped push", () => {
10511
10630
  delete process.env.HQ_SYNC_EVENT_BATCH_LIMIT;
10512
10631
  else
10513
10632
  process.env.HQ_SYNC_EVENT_BATCH_LIMIT = savedLimit;
10633
+ if (savedInterval === undefined)
10634
+ delete process.env.HQ_SYNC_FULL_RECONCILE_MS;
10635
+ else
10636
+ process.env.HQ_SYNC_FULL_RECONCILE_MS = savedInterval;
10514
10637
  }
10515
10638
  });
10516
10639
  it("still escalates an overflowed batch with unknown routes to a full reconcile", async () => {
10517
10640
  const savedLimit = process.env.HQ_SYNC_EVENT_BATCH_LIMIT;
10641
+ const savedInterval = process.env.HQ_SYNC_FULL_RECONCILE_MS;
10518
10642
  process.env.HQ_SYNC_EVENT_BATCH_LIMIT = "2";
10643
+ process.env.HQ_SYNC_FULL_RECONCILE_MS = "10800000";
10519
10644
  const journal = captureWatchLoopJournal();
10520
10645
  try {
10521
10646
  const runPass = vi.fn().mockResolvedValue(completedPassOutcome());
@@ -10547,9 +10672,15 @@ describe("runRunnerWithLoop — accumulate-and-drain scoped push", () => {
10547
10672
  delete process.env.HQ_SYNC_EVENT_BATCH_LIMIT;
10548
10673
  else
10549
10674
  process.env.HQ_SYNC_EVENT_BATCH_LIMIT = savedLimit;
10675
+ if (savedInterval === undefined)
10676
+ delete process.env.HQ_SYNC_FULL_RECONCILE_MS;
10677
+ else
10678
+ process.env.HQ_SYNC_FULL_RECONCILE_MS = savedInterval;
10550
10679
  }
10551
10680
  });
10552
- it("logs scheduled-interval as the sole full-reconcile trigger on the six-hour default", async () => {
10681
+ it("logs scheduled-interval as the sole full-reconcile trigger on the default hourly cadence", async () => {
10682
+ const saved = process.env.HQ_SYNC_FULL_RECONCILE_MS;
10683
+ delete process.env.HQ_SYNC_FULL_RECONCILE_MS;
10553
10684
  const capture = captureFullReconcileDecisions();
10554
10685
  try {
10555
10686
  const clockState = { now: 0 };
@@ -10575,11 +10706,11 @@ describe("runRunnerWithLoop — accumulate-and-drain scoped push", () => {
10575
10706
  sleep.tick();
10576
10707
  await flushLoopMicrotasks();
10577
10708
  }
10578
- // A dozen ticks inside the interval: never a scheduled full pass.
10709
+ // A dozen ticks inside the hour: never a scheduled full pass.
10579
10710
  expect(runPass).not.toHaveBeenCalled();
10580
10711
  capture.clear();
10581
10712
  runPass.mockClear();
10582
- clockState.now = DEFAULT_FULL_PASS_INTERVAL_MS;
10713
+ clockState.now = DEFAULT_FULL_RECONCILE_MS;
10583
10714
  sleep.tick();
10584
10715
  await flushLoopMicrotasks();
10585
10716
  expectFullReconcileDecision(capture.records[0], "full", [
@@ -10591,6 +10722,10 @@ describe("runRunnerWithLoop — accumulate-and-drain scoped push", () => {
10591
10722
  }
10592
10723
  finally {
10593
10724
  capture.restore();
10725
+ if (saved === undefined)
10726
+ delete process.env.HQ_SYNC_FULL_RECONCILE_MS;
10727
+ else
10728
+ process.env.HQ_SYNC_FULL_RECONCILE_MS = saved;
10594
10729
  }
10595
10730
  });
10596
10731
  it("logs scoped passes with their batch path count and preserves the scoped route", async () => {
@@ -10611,6 +10746,8 @@ describe("runRunnerWithLoop — accumulate-and-drain scoped push", () => {
10611
10746
  capture.restore();
10612
10747
  });
10613
10748
  it("reports interval diagnostics while the configured interval has not elapsed", async () => {
10749
+ const saved = process.env.HQ_SYNC_FULL_RECONCILE_MS;
10750
+ process.env.HQ_SYNC_FULL_RECONCILE_MS = "1000";
10614
10751
  const capture = captureFullReconcileDecisions();
10615
10752
  try {
10616
10753
  const clockState = { now: 0 };
@@ -10619,7 +10756,6 @@ describe("runRunnerWithLoop — accumulate-and-drain scoped push", () => {
10619
10756
  const runPass = vi.fn().mockResolvedValue(completedPassOutcome());
10620
10757
  const loop = runRunnerWithLoop(watchArgv, {
10621
10758
  runPass,
10622
- fullPassIntervalSource: { read: () => 1_000 },
10623
10759
  monotonicNow: () => clockState.now,
10624
10760
  createWatcher: () => makeBatchWatcherStub(),
10625
10761
  sleep: sleep.sleep,
@@ -10655,6 +10791,10 @@ describe("runRunnerWithLoop — accumulate-and-drain scoped push", () => {
10655
10791
  }
10656
10792
  finally {
10657
10793
  capture.restore();
10794
+ if (saved === undefined)
10795
+ delete process.env.HQ_SYNC_FULL_RECONCILE_MS;
10796
+ else
10797
+ process.env.HQ_SYNC_FULL_RECONCILE_MS = saved;
10658
10798
  }
10659
10799
  });
10660
10800
  it("startup runs one full reconcile, then watcher edits interrupt the pending wait", async () => {
@@ -10960,6 +11100,8 @@ describe("runRunnerWithLoop — accumulate-and-drain scoped push", () => {
10960
11100
  await loop;
10961
11101
  });
10962
11102
  it("drops an unroutable batch and leaves the next unexpired poll idle", async () => {
11103
+ const saved = process.env.HQ_SYNC_FULL_RECONCILE_MS;
11104
+ process.env.HQ_SYNC_FULL_RECONCILE_MS = "1000";
10963
11105
  const capture = captureFullReconcileDecisions();
10964
11106
  try {
10965
11107
  const runPass = vi.fn().mockResolvedValue(completedPassOutcome());
@@ -10985,6 +11127,10 @@ describe("runRunnerWithLoop — accumulate-and-drain scoped push", () => {
10985
11127
  }
10986
11128
  finally {
10987
11129
  capture.restore();
11130
+ if (saved === undefined)
11131
+ delete process.env.HQ_SYNC_FULL_RECONCILE_MS;
11132
+ else
11133
+ process.env.HQ_SYNC_FULL_RECONCILE_MS = saved;
10988
11134
  }
10989
11135
  });
10990
11136
  it("personal scoped ticks preserve personal mode for the pull leg", async () => {
@@ -11143,7 +11289,7 @@ describe("runRunnerWithLoop — accumulate-and-drain scoped push", () => {
11143
11289
  }
11144
11290
  expect(runPass).not.toHaveBeenCalled();
11145
11291
  runPass.mockClear();
11146
- clockState.now = DEFAULT_FULL_PASS_INTERVAL_MS;
11292
+ clockState.now = DEFAULT_FULL_RECONCILE_MS;
11147
11293
  sleep.tick();
11148
11294
  await flushLoopMicrotasks();
11149
11295
  expect(runPass.mock.calls.map((call) => call[0])).toEqual([fullArgv]);
@@ -11151,105 +11297,134 @@ describe("runRunnerWithLoop — accumulate-and-drain scoped push", () => {
11151
11297
  sleep.tick();
11152
11298
  await loop;
11153
11299
  });
11154
- it("schedules the full reconcile by elapsed time, not tick count, at the flag fallback", async () => {
11300
+ it("schedules the full reconcile by elapsed time, not tick count, when the interval env is unset", async () => {
11155
11301
  // Pre-fix the unset default was every tenth tick. Ticks fire on every
11156
11302
  // watcher batch, so an active vault ran a ~10-minute full pass every
11157
11303
  // 4-8 minutes — nearly continuous, and the runner's dominant CPU cost
11158
11304
  // 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;
11305
+ const saved = process.env.HQ_SYNC_FULL_RECONCILE_MS;
11306
+ delete process.env.HQ_SYNC_FULL_RECONCILE_MS;
11307
+ try {
11308
+ const clockState = { now: 0 };
11309
+ const watcher = makeBatchWatcherStub();
11310
+ const sleep = makeSteppableSleep();
11311
+ let triggerShutdown = () => { };
11312
+ const runPass = vi.fn().mockResolvedValue(completedPassOutcome());
11313
+ const loop = runRunnerWithLoop(watchArgv, {
11314
+ runPass,
11315
+ clock: new FakeClock(),
11316
+ monotonicNow: () => clockState.now,
11317
+ createWatcher: () => watcher,
11318
+ sleep: sleep.sleep,
11319
+ onShutdownSignal: (handler) => {
11320
+ triggerShutdown = handler;
11321
+ return () => { };
11322
+ },
11323
+ });
11324
+ await flushLoopMicrotasks();
11325
+ expect(runPass.mock.calls.map((call) => call[0])).toEqual([fullArgv]);
11326
+ runPass.mockClear();
11327
+ // Twenty ticks in fifty-nine minutes: the old cadence would have run
11328
+ // two full passes here.
11329
+ for (let tick = 0; tick < 20; tick++) {
11330
+ clockState.now += 177_000;
11331
+ sleep.tick();
11332
+ await flushLoopMicrotasks();
11333
+ }
11334
+ expect(runPass).not.toHaveBeenCalled();
11335
+ runPass.mockClear();
11336
+ clockState.now = DEFAULT_FULL_RECONCILE_MS;
11182
11337
  sleep.tick();
11183
11338
  await flushLoopMicrotasks();
11339
+ expect(runPass.mock.calls.map((call) => call[0])).toEqual([fullArgv]);
11340
+ triggerShutdown();
11341
+ await loop;
11342
+ }
11343
+ finally {
11344
+ if (saved === undefined)
11345
+ delete process.env.HQ_SYNC_FULL_RECONCILE_MS;
11346
+ else
11347
+ process.env.HQ_SYNC_FULL_RECONCILE_MS = saved;
11184
11348
  }
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
11349
  });
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;
11350
+ it("uses the configured elapsed-time interval instead of the tick count", async () => {
11351
+ const saved = process.env.HQ_SYNC_FULL_RECONCILE_MS;
11352
+ process.env.HQ_SYNC_FULL_RECONCILE_MS = "1000";
11353
+ try {
11354
+ const clockState = { now: 0 };
11355
+ const watcher = makeBatchWatcherStub();
11356
+ const sleep = makeSteppableSleep();
11357
+ let triggerShutdown = () => { };
11358
+ const runPass = vi.fn().mockResolvedValue(completedPassOutcome());
11359
+ const loop = runRunnerWithLoop(watchArgv, {
11360
+ runPass,
11361
+ clock: new FakeClock(),
11362
+ monotonicNow: () => clockState.now,
11363
+ createWatcher: () => watcher,
11364
+ sleep: sleep.sleep,
11365
+ onShutdownSignal: (handler) => {
11366
+ triggerShutdown = handler;
11367
+ return () => { };
11368
+ },
11369
+ });
11370
+ await flushLoopMicrotasks();
11371
+ // Startup always forces the first full reconcile, and starts the interval.
11372
+ expect(runPass.mock.calls.map((call) => call[0])).toEqual([fullArgv]);
11373
+ runPass.mockClear();
11374
+ clockState.now = 999;
11375
+ sleep.tick();
11376
+ await flushLoopMicrotasks();
11377
+ expect(runPass).not.toHaveBeenCalled();
11378
+ runPass.mockClear();
11379
+ clockState.now = 1_000;
11380
+ sleep.tick();
11381
+ await flushLoopMicrotasks();
11382
+ expect(runPass.mock.calls.map((call) => call[0])).toEqual([fullArgv]);
11383
+ triggerShutdown();
11384
+ await loop;
11385
+ }
11386
+ finally {
11387
+ if (saved === undefined)
11388
+ delete process.env.HQ_SYNC_FULL_RECONCILE_MS;
11389
+ else
11390
+ process.env.HQ_SYNC_FULL_RECONCILE_MS = saved;
11391
+ }
11227
11392
  });
11228
11393
  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;
11394
+ const saved = process.env.HQ_SYNC_FULL_RECONCILE_MS;
11395
+ process.env.HQ_SYNC_FULL_RECONCILE_MS = "10800000";
11396
+ try {
11397
+ const watcher = makeBatchWatcherStub();
11398
+ const sleep = makeSteppableSleep();
11399
+ let triggerShutdown = () => { };
11400
+ // A numeric partial result does not activate event-push surfaces, so the
11401
+ // next tick must force another full pass even though three hours have not elapsed.
11402
+ const runPass = vi.fn().mockResolvedValue(PARTIAL_SYNC_EXIT);
11403
+ const loop = runRunnerWithLoop(watchArgv, {
11404
+ runPass,
11405
+ clock: new FakeClock(),
11406
+ monotonicNow: () => 0,
11407
+ createWatcher: () => watcher,
11408
+ sleep: sleep.sleep,
11409
+ onShutdownSignal: (handler) => {
11410
+ triggerShutdown = handler;
11411
+ return () => { };
11412
+ },
11413
+ });
11414
+ await flushLoopMicrotasks();
11415
+ runPass.mockClear();
11416
+ sleep.tick();
11417
+ await flushLoopMicrotasks();
11418
+ expect(runPass.mock.calls.map((call) => call[0])).toEqual([fullArgv]);
11419
+ triggerShutdown();
11420
+ await loop;
11421
+ }
11422
+ finally {
11423
+ if (saved === undefined)
11424
+ delete process.env.HQ_SYNC_FULL_RECONCILE_MS;
11425
+ else
11426
+ process.env.HQ_SYNC_FULL_RECONCILE_MS = saved;
11427
+ }
11253
11428
  });
11254
11429
  it("overflow with known dropped-route hints fans out per touched route instead of a full reconcile", async () => {
11255
11430
  const capture = captureFullReconcileDecisions();
@@ -11384,40 +11559,50 @@ describe("runRunnerWithLoop — accumulate-and-drain scoped push", () => {
11384
11559
  await loop;
11385
11560
  });
11386
11561
  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;
11562
+ const saved = process.env.HQ_SYNC_FULL_RECONCILE_MS;
11563
+ process.env.HQ_SYNC_FULL_RECONCILE_MS = "10800000";
11564
+ try {
11565
+ const watcher = makeBatchWatcherStub();
11566
+ const sleep = makeSteppableSleep();
11567
+ let triggerShutdown = () => { };
11568
+ const runPass = vi.fn().mockResolvedValue(completedPassOutcome());
11569
+ const loop = runRunnerWithLoop(watchArgv, {
11570
+ runPass,
11571
+ clock: new FakeClock(),
11572
+ monotonicNow: () => 0,
11573
+ createWatcher: () => watcher,
11574
+ sleep: sleep.sleep,
11575
+ onShutdownSignal: (handler) => {
11576
+ triggerShutdown = handler;
11577
+ return () => { };
11578
+ },
11579
+ });
11580
+ await flushLoopMicrotasks();
11581
+ runPass.mockClear();
11582
+ watcher.emit("companies/indigo/a.md", {
11583
+ paths: new Map(Array.from({ length: 10_001 }, (_, index) => [
11584
+ `/tmp/hq/companies/indigo/${index}.md`,
11585
+ `companies/indigo/${index}.md`,
11586
+ ])),
11587
+ });
11588
+ sleep.tick();
11589
+ await flushLoopMicrotasks(40);
11590
+ const calls = runPass.mock.calls.map((call) => call[0]);
11591
+ expect(calls).not.toContainEqual(fullArgv);
11592
+ const pushScopeCounts = calls
11593
+ .filter((argv) => argv.includes("push"))
11594
+ .map((argv) => scopePathsFromArgv(argv).length);
11595
+ expect(Math.max(0, ...pushScopeCounts)).toBeLessThanOrEqual(10_000);
11596
+ expect(pushScopeCounts.reduce((sum, count) => sum + count, 0)).toBe(10_001);
11597
+ triggerShutdown();
11598
+ await loop;
11599
+ }
11600
+ finally {
11601
+ if (saved === undefined)
11602
+ delete process.env.HQ_SYNC_FULL_RECONCILE_MS;
11603
+ else
11604
+ process.env.HQ_SYNC_FULL_RECONCILE_MS = saved;
11605
+ }
11421
11606
  });
11422
11607
  it("a throwing targeted pass falls back to one full reconcile instead of dropping the change", async () => {
11423
11608
  const capture = captureFullReconcileDecisions();