@indigoai-us/hq-cli 5.345.222 → 5.345.223

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/dist/command-catalog.generated.d.ts +1 -1
  3. package/dist/command-catalog.generated.js +1 -1
  4. package/dist/commands/bot.d.ts +1 -1
  5. package/dist/commands/bot.js +34 -33
  6. package/dist/commands/core-delegate-w1b.js +207 -187
  7. package/dist/commands/packs.js +13 -2
  8. package/dist/commands/sync-core.js +31 -12
  9. package/dist/lib/bot/fleet-cron.d.ts +26 -3
  10. package/dist/lib/bot/fleet-cron.js +44 -4
  11. package/dist/lib/bot/run.d.ts +4 -4
  12. package/dist/lib/bot/run.js +5 -3
  13. package/dist/lib/bot/signals-engine-flag.d.ts +53 -13
  14. package/dist/lib/bot/signals-engine-flag.js +202 -9
  15. package/dist/lib/daemon/machine-checks.d.ts +45 -0
  16. package/dist/lib/daemon/machine-checks.js +95 -11
  17. package/dist/lib/daemon/native-notice-ledger.d.ts +9 -0
  18. package/dist/lib/daemon/native-notice-ledger.js +43 -0
  19. package/dist/lib/daemon/run.js +3 -2
  20. package/dist/lib/daemon/supervisor.d.ts +10 -0
  21. package/dist/lib/daemon/supervisor.js +86 -0
  22. package/dist/lib/flag-registry-worker-source.generated.d.ts +1 -1
  23. package/dist/lib/flag-registry-worker-source.generated.js +1 -1
  24. package/dist/lib/flag-registry-worker.js +33 -3
  25. package/dist/lib/flag-registry.js +13 -0
  26. package/dist/lib/scan-packages/index.js +8 -9
  27. package/dist/lib/signals/engine.d.ts +8 -0
  28. package/dist/lib/signals/engine.js +15 -5
  29. package/dist/lib/sync-core/flag.d.ts +18 -0
  30. package/dist/lib/sync-core/flag.js +66 -0
  31. package/dist/lib/sync-core/reconcile.d.ts +6 -0
  32. package/dist/lib/sync-core/reconcile.js +15 -0
  33. package/dist/lib/sync-core/rollout-state.d.ts +2 -0
  34. package/dist/lib/sync-core/rollout-state.js +7 -0
  35. package/dist/lib/sync-core/vault-settings.d.ts +12 -1
  36. package/dist/lib/sync-core/vault-settings.js +23 -7
  37. package/dist/utils/pack-contributions.d.ts +14 -2
  38. package/dist/utils/pack-contributions.js +31 -5
  39. package/package.json +7 -7
  40. package/scripts/bench-core.mjs +34 -3
@@ -40,7 +40,7 @@ import { coreNextEnabled } from "../../utils/core-next-flag.js";
40
40
  import { coreNextKillReason } from "../../utils/core-next-kill.js";
41
41
  import { isExcludedWindowsBash, resolveWindowsBash } from "../../utils/windows-bash.js";
42
42
  import { anyNativeSessionStartRegistered } from "./machine-check-registration.js";
43
- import { nativeNoticeLedgerUsable } from "./native-notice-ledger.js";
43
+ import { nativeNoticeLedgerUsable, nativeNoticeShownFingerprints } from "./native-notice-ledger.js";
44
44
  import { openStoreDir } from "../safe-store.js";
45
45
  import { readStoreFile, writeStoreFile } from "./paths.js";
46
46
  import { cutUtf8, MACHINE_CHECK_DETAIL_BYTES } from "./state-file.js";
@@ -185,6 +185,31 @@ export function checkMachineCheckScript(hqRoot, relative, platform = process.pla
185
185
  store.close();
186
186
  }
187
187
  }
188
+ /** The core.yaml key that advertises collect-only support. */
189
+ export const MACHINE_CHECK_COLLECT_ONLY_KEY = "machineCheckCollectOnly";
190
+ const COLLECT_ONLY_LINE = /^machineCheckCollectOnly:[ \t]*1[ \t]*(?:#.*)?$/m;
191
+ /**
192
+ * Whether the installed core's scripts support collect-only mode: a
193
+ * top-level `machineCheckCollectOnly: 1` line in `<root>/core/core.yaml`
194
+ * (hq-core-staging, Q47). In that mode a script reports its finding but
195
+ * leaves its delivery stamp (the setup nag's .last file, the welcome-brief
196
+ * marker, client-health's and ensure-hq-desktop's show-once records) to the
197
+ * session that shows the finding. Operational caches and throttles are kept.
198
+ * An older core, or a core.yaml that cannot be read, answers false and the
199
+ * batch runs as before.
200
+ */
201
+ export function machineCheckCollectOnlySupported(hqRoot) {
202
+ try {
203
+ const file = path.join(path.resolve(hqRoot), "core", "core.yaml");
204
+ const stat = fs.statSync(file);
205
+ if (!stat.isFile() || stat.size > 256 * 1024)
206
+ return false;
207
+ return COLLECT_ONLY_LINE.test(fs.readFileSync(file, "utf8"));
208
+ }
209
+ catch {
210
+ return false;
211
+ }
212
+ }
188
213
  function payload(event, hqRoot) {
189
214
  return event === "SessionStart"
190
215
  ? JSON.stringify({ hook_event_name: "SessionStart", source: "startup", session_id: SESSION_ID, cwd: hqRoot })
@@ -199,21 +224,26 @@ function payload(event, hqRoot) {
199
224
  * TerminateProcess for either signal (there are no POSIX process groups), so
200
225
  * the first kill already ends it and the second is a no-op.
201
226
  */
202
- function runScript(shell, file, spec, hqRoot, env, killGraceMs, drainMs) {
227
+ function runScript(shell, file, spec, hqRoot, env, killGraceMs, drainMs, collectOnly) {
203
228
  return new Promise((resolve) => {
204
229
  const chunks = [];
205
230
  let kept = 0;
206
231
  let child;
232
+ const scriptEnv = {
233
+ ...env,
234
+ CLAUDE_PROJECT_DIR: hqRoot,
235
+ HQ_ROOT: hqRoot,
236
+ HQ_MACHINE_CHECK: "1",
237
+ HQ_MACHINE_CHECKS_RUNNING: "1",
238
+ };
239
+ if (collectOnly)
240
+ scriptEnv.HQ_MACHINE_CHECK_COLLECT_ONLY = "1";
241
+ else
242
+ delete scriptEnv.HQ_MACHINE_CHECK_COLLECT_ONLY;
207
243
  try {
208
244
  child = spawn(shell, [file], {
209
245
  cwd: hqRoot,
210
- env: {
211
- ...env,
212
- CLAUDE_PROJECT_DIR: hqRoot,
213
- HQ_ROOT: hqRoot,
214
- HQ_MACHINE_CHECK: "1",
215
- HQ_MACHINE_CHECKS_RUNNING: "1",
216
- },
246
+ env: scriptEnv,
217
247
  stdio: ["pipe", "pipe", "ignore"],
218
248
  shell: false,
219
249
  windowsHide: true,
@@ -269,7 +299,7 @@ async function runOne(spec, options, env, disabled, shell) {
269
299
  const checked = checkMachineCheckScript(options.hqRoot, spec.path, options.platform ?? process.platform);
270
300
  if (!checked.ok)
271
301
  return { id: spec.id, status: "unknown", checked_at: at(), summary: checked.summary };
272
- const run = await runScript(shell, checked.file, spec, path.resolve(options.hqRoot), env, options.killGraceMs ?? MACHINE_CHECK_KILL_GRACE_MS, options.drainMs ?? MACHINE_CHECK_DRAIN_MS);
302
+ const run = await runScript(shell, checked.file, spec, path.resolve(options.hqRoot), env, options.killGraceMs ?? MACHINE_CHECK_KILL_GRACE_MS, options.drainMs ?? MACHINE_CHECK_DRAIN_MS, options.collectOnly === true && !(options.commitIds?.has(spec.id) ?? false));
273
303
  if (run.outcome === "timed-out") {
274
304
  return { id: spec.id, status: "unknown", checked_at: at(), summary: `timed out after ${Math.round(spec.timeoutMs / 1000)}s` };
275
305
  }
@@ -399,6 +429,22 @@ export function machineChecksKillSwitchSet(env, home) {
399
429
  export function machineChecksScheduleOn(env, home) {
400
430
  return !machineChecksKillSwitchSet(env, home) && machineChecksCoreNextOn(env);
401
431
  }
432
+ /**
433
+ * The checks to commit in this batch: each whose last result (the results
434
+ * file the native notice reads) carries a fingerprint the native notice has
435
+ * recorded as delivered, unless this schedule already committed that same
436
+ * fingerprint.
437
+ */
438
+ export function machineChecksToCommit(previous, shown, committed) {
439
+ const out = new Map();
440
+ for (const result of previous) {
441
+ const print = result.fingerprint;
442
+ if (!print || !shown.has(print) || committed.get(result.id) === print)
443
+ continue;
444
+ out.set(result.id, print);
445
+ }
446
+ return out;
447
+ }
402
448
  /**
403
449
  * The daemon's machine-check timer. Each tick runs a batch only when the new
404
450
  * hook core (`core.next`) is on for this machine and no kill switch is set;
@@ -409,6 +455,13 @@ export function machineChecksScheduleOn(env, home) {
409
455
  * here would run them a second time and leave cooldown stamps that silence
410
456
  * the legacy run, so neither path would show the finding. A batch already running finishes. A failed batch
411
457
  * logs one line with the error's name only.
458
+ *
459
+ * When the installed core advertises collect-only support
460
+ * (machineCheckCollectOnlySupported), the batch runs its scripts in that mode
461
+ * and they write no delivery stamp. That also covers the split-HOME edge the
462
+ * ledger rule cannot see: the daemon's HOME passes the rule while the
463
+ * session's is refused, both run, and the session's legacy run still shows
464
+ * the finding. With an older core nothing changes.
412
465
  */
413
466
  export function startMachineCheckSchedule(options) {
414
467
  const now = options.now ?? (() => Date.now());
@@ -417,6 +470,8 @@ export function startMachineCheckSchedule(options) {
417
470
  const enabled = options.enabled ?? machineChecksScheduleOn;
418
471
  let lastStart;
419
472
  let closed = false;
473
+ /** Check id to the fingerprint last committed for it (in memory; a restart may commit once more, which is harmless). */
474
+ const committed = new Map();
420
475
  const tick = async () => {
421
476
  try {
422
477
  if (closed)
@@ -437,7 +492,36 @@ export function startMachineCheckSchedule(options) {
437
492
  return;
438
493
  }
439
494
  lastStart = now();
440
- await run({ hqRoot, env: options.env, resultsFile: options.resultsFile });
495
+ // Q47: the batch only collects. A core that supports it leaves every
496
+ // delivery stamp to the session that shows the finding, so a batch can
497
+ // never silence a session that would otherwise have shown it.
498
+ //
499
+ // While the daemon owns the checks the native notice shows the finding
500
+ // and records only its fingerprint, never the script's own record
501
+ // (the setup nag's stamp, the desktop result claim, client-health's
502
+ // pending files). So a check whose last finding the notice has
503
+ // delivered runs once in normal mode, which writes that record. In the
504
+ // split-HOME edge the session's notice refused its ledger and recorded
505
+ // nothing, so the check stays collect-only and the legacy run shows it.
506
+ // If the owner flips from daemon to legacy between the notice's show
507
+ // and this commit, the legacy run finds the record unwritten and shows
508
+ // the finding once more, then writes the record itself: one repeat at
509
+ // most, inside one batch interval.
510
+ const collectOnly = (options.collectOnlySupported ?? machineCheckCollectOnlySupported)(hqRoot);
511
+ let commit = new Map();
512
+ if (collectOnly) {
513
+ const shown = (options.shownFingerprints ?? nativeNoticeShownFingerprints)(options.env, options.home);
514
+ if (shown.size > 0)
515
+ commit = machineChecksToCommit(readMachineCheckResults(options.resultsFile), shown, committed);
516
+ }
517
+ const results = await run({ hqRoot, env: options.env, resultsFile: options.resultsFile, collectOnly, commitIds: new Set(commit.keys()) });
518
+ // A commit run that timed out, crashed or exited non-zero may not have
519
+ // written the script's record. It is not marked committed, so the next
520
+ // batch that collects the same finding commits it again.
521
+ for (const [id, print] of commit) {
522
+ if (results.some((each) => each.id === id && each.status !== "unknown"))
523
+ committed.set(id, print);
524
+ }
441
525
  }
442
526
  catch (error) {
443
527
  options.log("warn", `machine checks failed (${error instanceof Error ? error.name : "UnknownError"})`);
@@ -24,4 +24,13 @@ export declare const NATIVE_NOTICE_LEDGER_REFUSED = "the native notice cannot us
24
24
  * shared. Reading is by lstat, a handful of calls, no process.
25
25
  */
26
26
  export declare function nativeNoticeLedgerUsable(env: NodeJS.ProcessEnv, home: string): boolean;
27
+ /**
28
+ * The fingerprints (lowercase hex) the native SessionStart notice recorded as
29
+ * delivered, read from this environment's ledger (`HQ_HOOK_STATE_DIR`, or
30
+ * `<home>/.hq/state/hq-hook`). Read-only and without the notice's lock: a
31
+ * read that races a write can miss an entry, which only delays the commit to
32
+ * the next batch. Empty when the ledger is unusable (nativeNoticeLedgerUsable),
33
+ * missing, not a single-link regular file, or not the expected size and magic.
34
+ */
35
+ export declare function nativeNoticeShownFingerprints(env: NodeJS.ProcessEnv, home: string): Set<string>;
27
36
  //# sourceMappingURL=native-notice-ledger.d.ts.map
@@ -110,4 +110,47 @@ export function nativeNoticeLedgerUsable(env, home) {
110
110
  return stat.isFile() && stat.nlink === 1 && ownedOk(stat) && !looseBits(stat);
111
111
  }
112
112
  }
113
+ /** Ledger layout (`MAGIC`, `HEADER_BYTES`, `SLOT`, `SLOTS` in crates/hq-hook/src/session_start.rs). */
114
+ const LEDGER_MAGIC = Buffer.from("HQMCSN1\n", "latin1");
115
+ const LEDGER_HEADER_BYTES = 16;
116
+ const LEDGER_SLOT = 32;
117
+ const LEDGER_SLOTS = 256;
118
+ const LEDGER_SIZE = LEDGER_HEADER_BYTES + LEDGER_SLOT * LEDGER_SLOTS;
119
+ /**
120
+ * The fingerprints (lowercase hex) the native SessionStart notice recorded as
121
+ * delivered, read from this environment's ledger (`HQ_HOOK_STATE_DIR`, or
122
+ * `<home>/.hq/state/hq-hook`). Read-only and without the notice's lock: a
123
+ * read that races a write can miss an entry, which only delays the commit to
124
+ * the next batch. Empty when the ledger is unusable (nativeNoticeLedgerUsable),
125
+ * missing, not a single-link regular file, or not the expected size and magic.
126
+ */
127
+ export function nativeNoticeShownFingerprints(env, home) {
128
+ const shown = new Set();
129
+ if (!nativeNoticeLedgerUsable(env, home))
130
+ return shown;
131
+ const override = env.HQ_HOOK_STATE_DIR;
132
+ const folder = override ? override : `${home}/.hq/state/hq-hook`;
133
+ const file = path.posix.join(folder, NATIVE_NOTICE_LEDGER_FILE);
134
+ let bytes;
135
+ try {
136
+ const stat = fs.lstatSync(file);
137
+ if (!stat.isFile() || stat.nlink !== 1 || stat.size !== LEDGER_SIZE)
138
+ return shown;
139
+ bytes = fs.readFileSync(file);
140
+ }
141
+ catch {
142
+ return shown;
143
+ }
144
+ if (bytes.length !== LEDGER_SIZE || !bytes.subarray(0, LEDGER_MAGIC.length).equals(LEDGER_MAGIC))
145
+ return shown;
146
+ for (let index = 0; index < LEDGER_SLOTS; index += 1) {
147
+ const start = LEDGER_HEADER_BYTES + index * LEDGER_SLOT;
148
+ const slot = bytes.subarray(start, start + LEDGER_SLOT);
149
+ // An all-zero slot is empty (the notice never records an all-zero print).
150
+ if (slot.every((byte) => byte === 0))
151
+ continue;
152
+ shown.add(slot.toString("hex"));
153
+ }
154
+ return shown;
155
+ }
113
156
  //# sourceMappingURL=native-notice-ledger.js.map
@@ -27,7 +27,7 @@ import { effectiveSyncOwner, readDaemonConfig } from "./config.js";
27
27
  import { inspectEngineHome } from "../sync-core/engine-home.js";
28
28
  import { fullModeHold } from "../sync-core/reconcile.js";
29
29
  import { readSyncCoreRolloutState } from "../sync-core/rollout-state.js";
30
- import { readSyncCoreVaultSettings } from "../sync-core/vault-settings.js";
30
+ import { effectiveEngineSettings, readSyncCoreVaultSettings } from "../sync-core/vault-settings.js";
31
31
  import { assertPersonalServiceSessionCapability, readRemoteControlPoolsConfig, remoteControlPoolSecretsEnv, } from "./remote-control-pools.js";
32
32
  import { loadLanesConfig } from "../lanes/config.js";
33
33
  import { daemonLanesReconcileHandler } from "../lanes/daemon-reconcile.js";
@@ -86,6 +86,7 @@ export function syncCoreVaultPlans(home, hqRoot, platform) {
86
86
  return [];
87
87
  const settings = readSyncCoreVaultSettings(home);
88
88
  return state.vaults.map((vault) => {
89
+ const effective = effectiveEngineSettings(settings.get(vault.uid), vault.downloadStreams);
89
90
  const plan = inspectEngineHome(home, hqRoot, {
90
91
  uid: vault.uid,
91
92
  kind: vault.kind,
@@ -95,7 +96,7 @@ export function syncCoreVaultPlans(home, hqRoot, platform) {
95
96
  binaryPath: state.binaryPath,
96
97
  release: state.release,
97
98
  ...(vault.legacyOffSince ? { legacyOffSince: vault.legacyOffSince } : {}),
98
- ...(settings.has(vault.uid) ? { settings: settings.get(vault.uid) } : {}),
99
+ ...(effective ? { settings: effective } : {}),
99
100
  }, platform);
100
101
  const releaseHold = vault.phase === "full" ? fullModeHold(vault, state.release, platform) : undefined;
101
102
  return releaseHold ? { ...plan, blockedReason: releaseHold } : plan;
@@ -41,6 +41,16 @@ export declare const EPISODE_MAX_FAILURES = 6;
41
41
  export declare const EPISODE_HEALTHY_RESET_MS: number;
42
42
  export declare const STOP_ESCALATION_MS = 10000;
43
43
  export declare const SYNC_RUNNER_PERSIST_GRACE_MS = 60000;
44
+ /**
45
+ * Longest wait for a sync-core engine's cycle to end before a parallel-download
46
+ * settings change restarts it anyway. A first-sync cycle can run about 14 minutes.
47
+ */
48
+ export declare const SYNC_CORE_SETTINGS_IDLE_MAX_MS: number;
49
+ /**
50
+ * True when two sync-core plans differ only in the parallel-download env keys,
51
+ * so the change can wait for the engine to finish its cycle.
52
+ */
53
+ export declare function onlySyncCoreSettingsChanged(before: UnitPlan, after: UnitPlan): boolean;
44
54
  export declare const CLI_UPDATE_SYNC_IDLE_KILL_GRACE_MS = 60000;
45
55
  /** After a handoff, how long a replaced unit must stay up before the next one is replaced. */
46
56
  export declare const HANDOFF_STAGGER_MS = 15000;
@@ -44,6 +44,32 @@ export const EPISODE_HEALTHY_RESET_MS = 30 * 60_000;
44
44
  export const STOP_ESCALATION_MS = 10_000;
45
45
  export const SYNC_RUNNER_PERSIST_GRACE_MS = 60_000;
46
46
  const CLI_UPDATE_SYNC_IDLE_MAX_MS = 10 * 60_000;
47
+ /**
48
+ * Longest wait for a sync-core engine's cycle to end before a parallel-download
49
+ * settings change restarts it anyway. A first-sync cycle can run about 14 minutes.
50
+ */
51
+ export const SYNC_CORE_SETTINGS_IDLE_MAX_MS = 30 * 60_000;
52
+ /** Engine env keys whose change waits for the engine to be between cycles. */
53
+ const SYNC_CORE_IDLE_RESTART_ENV_KEYS = new Set(["HQ_SYNC_PARALLEL_DOWNLOADS", "HQ_SYNC_DOWNLOAD_STREAMS"]);
54
+ /**
55
+ * True when two sync-core plans differ only in the parallel-download env keys,
56
+ * so the change can wait for the engine to finish its cycle.
57
+ */
58
+ export function onlySyncCoreSettingsChanged(before, after) {
59
+ if (before.service !== "sync-core" || after.service !== "sync-core")
60
+ return false;
61
+ const strip = (plan) => ({
62
+ ...plan,
63
+ env: Object.fromEntries(Object.entries(plan.env ?? {}).filter(([key]) => !SYNC_CORE_IDLE_RESTART_ENV_KEYS.has(key))),
64
+ });
65
+ const b = strip(before);
66
+ const a = strip(after);
67
+ if (planKey(b) !== planKey(a))
68
+ return false;
69
+ if ((b.blocked === undefined) !== (a.blocked === undefined))
70
+ return false;
71
+ return planKey(before) !== planKey(after);
72
+ }
47
73
  export const CLI_UPDATE_SYNC_IDLE_KILL_GRACE_MS = 60_000;
48
74
  const MESH_OWNER_RECHECK_MS = 15_000;
49
75
  const MESH_OWNER_LOG_INTERVAL_MS = 10 * 60_000;
@@ -398,6 +424,50 @@ export function createSupervisor(deps) {
398
424
  pending.timer = setT(() => finishPendingSyncCommandRestart(true), CLI_UPDATE_SYNC_IDLE_MAX_MS);
399
425
  }
400
426
  };
427
+ const clearEngineIdleRestart = (slot) => {
428
+ const pending = slot.engineIdleRestart;
429
+ if (!pending)
430
+ return;
431
+ if (pending.timer !== undefined)
432
+ clearT(pending.timer);
433
+ slot.engineIdleRestart = undefined;
434
+ };
435
+ const runEngineIdleRestart = (slot) => {
436
+ const pending = slot.engineIdleRestart;
437
+ if (!pending)
438
+ return;
439
+ clearEngineIdleRestart(slot);
440
+ pending.run();
441
+ };
442
+ /**
443
+ * Restart a sync-core engine whose parallel-download settings changed once it
444
+ * is between cycles (after its all-complete), or after
445
+ * SYNC_CORE_SETTINGS_IDLE_MAX_MS. Each engine unit has its own pending restart.
446
+ */
447
+ const deferEngineRestartUntilIdle = (slot) => {
448
+ const run = () => {
449
+ deps.log("info", `restarting ${slot.plan.id}: its parallel download settings changed`);
450
+ terminate(slot, () => activate(slot));
451
+ };
452
+ if (slot.engineCycleActive === false) {
453
+ clearEngineIdleRestart(slot);
454
+ run();
455
+ return;
456
+ }
457
+ if (slot.engineIdleRestart) {
458
+ slot.engineIdleRestart.run = run;
459
+ return;
460
+ }
461
+ deps.log("info", `deferring restart of ${slot.plan.id} until its sync cycle ends (maximum ${SYNC_CORE_SETTINGS_IDLE_MAX_MS / 60_000} minutes)`);
462
+ const pending = { run };
463
+ slot.engineIdleRestart = pending;
464
+ pending.timer = setT(() => {
465
+ if (slot.engineIdleRestart !== pending)
466
+ return;
467
+ deps.log("warn", `${slot.plan.id} did not finish its sync cycle within ${SYNC_CORE_SETTINGS_IDLE_MAX_MS / 60_000} minutes; restarting it to apply the changed settings`);
468
+ runEngineIdleRestart(slot);
469
+ }, SYNC_CORE_SETTINGS_IDLE_MAX_MS);
470
+ };
401
471
  const setBlocked = (slot) => {
402
472
  const block = slot.plan.blocked;
403
473
  slot.state.status = block.state;
@@ -559,6 +629,7 @@ export function createSupervisor(deps) {
559
629
  */
560
630
  const terminate = (slot, then, drain = false, killGraceMs = slot.plan.stopGraceMs ?? STOP_ESCALATION_MS) => {
561
631
  clearPendingSyncCommandRestart(slot);
632
+ clearEngineIdleRestart(slot);
562
633
  clearTimer(slot);
563
634
  clearHeartbeatTimer(slot);
564
635
  const child = slot.child;
@@ -703,6 +774,12 @@ export function createSupervisor(deps) {
703
774
  }
704
775
  }
705
776
  if (slot.plan.service === "sync-core") {
777
+ if (event.type === "fanout-plan")
778
+ slot.engineCycleActive = true;
779
+ else if (event.type === "all-complete") {
780
+ slot.engineCycleActive = false;
781
+ runEngineIdleRestart(slot);
782
+ }
706
783
  const bytes = heartbeatProgressBytes(event);
707
784
  if (bytes !== null) {
708
785
  // The first progress heartbeat of a run is the baseline: counters are
@@ -758,6 +835,8 @@ export function createSupervisor(deps) {
758
835
  if (slot.child !== child)
759
836
  return;
760
837
  slot.child = undefined;
838
+ // The next start uses the current plan, so a waiting settings restart is moot.
839
+ clearEngineIdleRestart(slot);
761
840
  if (pendingSyncCommandRestart?.slot === slot) {
762
841
  clearPendingSyncCommandRestart(slot);
763
842
  if (deferredCliRestart)
@@ -919,6 +998,7 @@ export function createSupervisor(deps) {
919
998
  delete slot.lastProtocolLine;
920
999
  delete slot.lastProtocolStatus;
921
1000
  delete slot.syncPassActive;
1001
+ delete slot.engineCycleActive;
922
1002
  delete slot.progressBytes;
923
1003
  delete slot.progressedThisRun;
924
1004
  let child;
@@ -1193,6 +1273,7 @@ export function createSupervisor(deps) {
1193
1273
  existing.adopted = false;
1194
1274
  const hadDrainSignal = existing.plan.drainSignal !== undefined;
1195
1275
  const key = planKey(plan, deps.cliVersion);
1276
+ const settingsOnly = onlySyncCoreSettingsChanged(existing.plan, plan);
1196
1277
  const wasBlocked = existing.plan.blocked !== undefined;
1197
1278
  const changed = key !== existing.key;
1198
1279
  existing.plan = plan;
@@ -1259,6 +1340,11 @@ export function createSupervisor(deps) {
1259
1340
  deps.log("info", `will replace ${plan.id}: it runs an older CLI or command`);
1260
1341
  handoffQueue.push(existing);
1261
1342
  }
1343
+ else if (changed && settingsOnly && existing.child && !existing.expectingExit) {
1344
+ existing.attempts = 0;
1345
+ existing.state.restarts = 0;
1346
+ deferEngineRestartUntilIdle(existing);
1347
+ }
1262
1348
  else if (changed) {
1263
1349
  deps.log("info", `restarting ${plan.id}: its command changed`);
1264
1350
  existing.attempts = 0;