@evomap/evolver-proxy 2.0.46 → 2.0.48

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 (44) hide show
  1. package/dist/bin/evolver-proxy.d.ts +4 -0
  2. package/dist/bin/evolver-proxy.js +49 -5
  3. package/dist/bin/proxyStopSignal.d.ts +8 -0
  4. package/dist/bin/proxyStopSignal.js +13 -0
  5. package/dist/bin/triggerFeedbackStartup.d.ts +8 -0
  6. package/dist/bin/triggerFeedbackStartup.js +23 -0
  7. package/dist/daemon/localRecall.d.ts +37 -0
  8. package/dist/daemon/localRecall.js +112 -0
  9. package/dist/daemon/proxyDaemon.d.ts +33 -1
  10. package/dist/daemon/proxyDaemon.js +263 -18
  11. package/dist/daemon/publishBindingLedger.d.ts +38 -0
  12. package/dist/daemon/publishBindingLedger.js +171 -1
  13. package/dist/daemon/recallContext.d.ts +3 -0
  14. package/dist/daemon/recallContext.js +10 -0
  15. package/dist/lifecycle/claimNudge.js +1 -1
  16. package/dist/lifecycle/deployGuard.js +1 -1
  17. package/dist/lifecycle/legacyNodeId.js +1 -1
  18. package/dist/lifecycle/manager.js +1 -1
  19. package/dist/llm/index.js +1 -1
  20. package/dist/llm/server.js +1 -1
  21. package/dist/llm/traceBackfill.js +1 -1
  22. package/dist/llm/traceConfig.js +1 -1
  23. package/dist/llm/traceControl.js +1 -1
  24. package/dist/llm/traceEnvelope.js +1 -1
  25. package/dist/llm/traceSink.js +1 -1
  26. package/dist/llm/traceUploadPayload.js +1 -1
  27. package/dist/llm/upstream.js +1 -1
  28. package/dist/router/cachePassthrough.js +1 -1
  29. package/dist/router/features.js +1 -1
  30. package/dist/router/index.js +1 -1
  31. package/dist/router/messagesRoute.js +1 -1
  32. package/dist/router/modelRouter.js +1 -1
  33. package/dist/router/providerRoutes.js +1 -1
  34. package/dist/router/sseScan.js +1 -1
  35. package/dist/selfUpdate/bootstrap.js +29 -23
  36. package/dist/selfUpdate/bootstrapReadiness.js +4 -1
  37. package/dist/selfUpdate/fileMetadata.d.ts +2 -0
  38. package/dist/selfUpdate/fileMetadata.js +25 -0
  39. package/dist/selfUpdate/migration.js +19 -13
  40. package/dist/selfUpdate/recoveryChildStartGate.js +4 -2
  41. package/dist/selfUpdate/transaction.js +278 -64
  42. package/dist/selfUpdate/windowsUpdater.js +2 -1
  43. package/dist/sync/engine.js +1 -1
  44. package/package.json +3 -3
@@ -146,6 +146,12 @@ function boundedBootstrapDetail(value) {
146
146
  }
147
147
  return normalized.slice(0, MAX_BOOTSTRAP_DETAIL_LENGTH);
148
148
  }
149
+ function bootstrapPathMetadata(path) {
150
+ const stat = lstatSync(path, { bigint: true });
151
+ // Reuse the native file witness; a missing Windows volume is not an identity.
152
+ return process.platform === 'win32' && stat.dev === 0n && stat.isFile() && !stat.isSymbolicLink()
153
+ ? util.statRegularFileIdentity(path) : stat;
154
+ }
149
155
  function readBoundedBootstrapStateFile(path, options, maxBytes = MAX_BOOTSTRAP_STATE_BYTES) {
150
156
  const injected = options.exists !== undefined || options.readFile !== undefined;
151
157
  try {
@@ -158,7 +164,7 @@ function readBoundedBootstrapStateFile(path, options, maxBytes = MAX_BOOTSTRAP_S
158
164
  }
159
165
  return { status: 'present', raw };
160
166
  }
161
- const before = lstatSync(path, { bigint: true });
167
+ const before = bootstrapPathMetadata(path);
162
168
  if (!before.isFile() || before.isSymbolicLink() || before.nlink !== 1n
163
169
  || before.size > BigInt(maxBytes)
164
170
  || before.dev <= 0n || before.ino <= 0n) {
@@ -190,7 +196,7 @@ function readBoundedBootstrapStateFile(path, options, maxBytes = MAX_BOOTSTRAP_S
190
196
  return { status: 'invalid', detail: `changed durable state: ${basename(path)}` };
191
197
  }
192
198
  (options.assertIntentFileTrust ?? assertNativeBootstrapIntentFileTrust)(path);
193
- const settled = lstatSync(path, { bigint: true });
199
+ const settled = bootstrapPathMetadata(path);
194
200
  if (!settled.isFile() || settled.isSymbolicLink() || settled.nlink !== 1n
195
201
  || settled.dev !== opened.dev || settled.ino !== opened.ino || settled.size !== opened.size
196
202
  || settled.mtimeNs !== opened.mtimeNs || settled.ctimeNs !== opened.ctimeNs) {
@@ -268,7 +274,7 @@ function readLegacyBootstrapProofFile(receipt, options) {
268
274
  const directory = dirname(receipt.path);
269
275
  assertDirectoryTrust(directory);
270
276
  assertFileTrust(receipt.path);
271
- const before = lstatSync(receipt.path, { bigint: true });
277
+ const before = bootstrapPathMetadata(receipt.path);
272
278
  if (!before.isFile() || before.isSymbolicLink()
273
279
  || before.dev <= 0n || before.ino <= 0n
274
280
  || before.size !== BigInt(receipt.size)
@@ -310,7 +316,7 @@ function readLegacyBootstrapProofFile(receipt, options) {
310
316
  }
311
317
  assertDirectoryTrust(directory);
312
318
  assertFileTrust(receipt.path);
313
- const settled = lstatSync(receipt.path, { bigint: true });
319
+ const settled = bootstrapPathMetadata(receipt.path);
314
320
  if (!settled.isFile() || settled.isSymbolicLink()
315
321
  || settled.dev !== opened.dev || settled.ino !== opened.ino
316
322
  || settled.size !== opened.size
@@ -2037,7 +2043,7 @@ function syncBootstrapDirectory(path) {
2037
2043
  function readBootstrapRegistrationIntentFile(options, path, registrationPath, terminalPath, clearingPath, expectedLinkCount = 1n) {
2038
2044
  try {
2039
2045
  assertBootstrapIntentFileTrust(options, path, Number(expectedLinkCount));
2040
- const before = lstatSync(path, { bigint: true });
2046
+ const before = bootstrapPathMetadata(path);
2041
2047
  if (!before.isFile() || before.isSymbolicLink() || before.nlink !== expectedLinkCount
2042
2048
  || before.dev <= 0n || before.ino <= 0n
2043
2049
  || before.size > BigInt(MAX_BOOTSTRAP_REGISTRATION_INTENT_BYTES)
@@ -2083,7 +2089,7 @@ function readBootstrapRegistrationIntentFile(options, path, registrationPath, te
2083
2089
  finally {
2084
2090
  closeSync(descriptor);
2085
2091
  }
2086
- const after = lstatSync(path, { bigint: true });
2092
+ const after = bootstrapPathMetadata(path);
2087
2093
  if (!after.isFile() || after.isSymbolicLink() || after.nlink !== expectedLinkCount
2088
2094
  || after.dev !== before.dev || after.ino !== before.ino || after.size !== before.size
2089
2095
  || after.mtimeNs !== before.mtimeNs || after.ctimeNs !== before.ctimeNs) {
@@ -2173,7 +2179,7 @@ function readBootstrapRegistrationPublisherClaim(options, stateDir) {
2173
2179
  const path = join(stateDir, name);
2174
2180
  try {
2175
2181
  assertBootstrapIntentFileTrust(options, path);
2176
- const before = lstatSync(path, { bigint: true });
2182
+ const before = bootstrapPathMetadata(path);
2177
2183
  if (!before.isFile() || before.isSymbolicLink() || before.nlink !== 1n
2178
2184
  || before.size !== 0n || before.dev <= 0n || before.ino <= 0n) {
2179
2185
  return { status: 'invalid', detail: 'registration publisher claim is unsafe' };
@@ -2192,7 +2198,7 @@ function readBootstrapRegistrationPublisherClaim(options, stateDir) {
2192
2198
  if (descriptor !== undefined)
2193
2199
  closeSync(descriptor);
2194
2200
  }
2195
- const after = lstatSync(path, { bigint: true });
2201
+ const after = bootstrapPathMetadata(path);
2196
2202
  if (!after.isFile() || after.isSymbolicLink() || after.nlink !== 1n || after.size !== 0n
2197
2203
  || after.dev !== before.dev || after.ino !== before.ino
2198
2204
  || after.mtimeNs !== before.mtimeNs || after.ctimeNs !== before.ctimeNs) {
@@ -2466,7 +2472,7 @@ function createBootstrapRegistrationPublisherClaim(options, stateDir, owner) {
2466
2472
  throw new Error('bootstrap registration publisher claim failed');
2467
2473
  syncBootstrapDirectory(stateDir);
2468
2474
  assertBootstrapIntentFileTrust(options, path);
2469
- const settled = lstatSync(path, { bigint: true });
2475
+ const settled = bootstrapPathMetadata(path);
2470
2476
  if (!settled.isFile() || settled.isSymbolicLink() || settled.nlink !== 1n
2471
2477
  || settled.size !== 0n || settled.dev !== opened.dev || settled.ino !== opened.ino
2472
2478
  || settled.mtimeNs !== opened.mtimeNs || settled.ctimeNs !== opened.ctimeNs) {
@@ -2568,7 +2574,7 @@ function publishBootstrapRegistrationIntent(options) {
2568
2574
  if (!opened)
2569
2575
  throw new Error('bootstrap registration intent publication failed');
2570
2576
  assertBootstrapIntentFileTrust(options, publishingPath);
2571
- const prepared = lstatSync(publishingPath, { bigint: true });
2577
+ const prepared = bootstrapPathMetadata(publishingPath);
2572
2578
  if (!prepared.isFile() || prepared.isSymbolicLink() || prepared.nlink !== 1n
2573
2579
  || prepared.dev !== opened.dev || prepared.ino !== opened.ino
2574
2580
  || prepared.size !== opened.size || prepared.mtimeNs !== opened.mtimeNs
@@ -2581,8 +2587,8 @@ function publishBootstrapRegistrationIntent(options) {
2581
2587
  options.afterIntentPublicationStep?.('directory_fsync', stateDir);
2582
2588
  assertBootstrapIntentFileTrust(options, publishingPath, 2);
2583
2589
  assertBootstrapIntentFileTrust(options, path, 2);
2584
- const linkedTemp = lstatSync(publishingPath, { bigint: true });
2585
- const linkedCanonical = lstatSync(path, { bigint: true });
2590
+ const linkedTemp = bootstrapPathMetadata(publishingPath);
2591
+ const linkedCanonical = bootstrapPathMetadata(path);
2586
2592
  if (!linkedTemp.isFile() || linkedTemp.isSymbolicLink() || linkedTemp.nlink !== 2n
2587
2593
  || !linkedCanonical.isFile() || linkedCanonical.isSymbolicLink()
2588
2594
  || linkedCanonical.nlink !== 2n
@@ -2598,7 +2604,7 @@ function publishBootstrapRegistrationIntent(options) {
2598
2604
  throw new Error('bootstrap registration intent temp retirement is unconfirmed');
2599
2605
  }
2600
2606
  assertBootstrapIntentFileTrust(options, path);
2601
- const published = lstatSync(path, { bigint: true });
2607
+ const published = bootstrapPathMetadata(path);
2602
2608
  if (!published.isFile() || published.isSymbolicLink() || published.nlink !== 1n
2603
2609
  || published.dev !== opened.dev || published.ino !== opened.ino
2604
2610
  || published.size !== opened.size || published.mtimeNs !== opened.mtimeNs) {
@@ -2634,7 +2640,7 @@ function terminalizeBootstrapRegistrationIntent(options, lease, outcome, transac
2634
2640
  }
2635
2641
  assertBootstrapIntentDirectoryTrust(options, dirname(lease.currentPath), true);
2636
2642
  assertBootstrapIntentFileTrust(options, lease.currentPath);
2637
- const current = lstatSync(lease.currentPath, { bigint: true });
2643
+ const current = bootstrapPathMetadata(lease.currentPath);
2638
2644
  if (!current.isFile() || current.isSymbolicLink() || current.nlink !== 1n
2639
2645
  || current.dev !== lease.device || current.ino !== lease.inode || current.size !== lease.size
2640
2646
  || current.mtimeNs !== lease.mtimeNs || current.ctimeNs !== lease.ctimeNs) {
@@ -2688,7 +2694,7 @@ function terminalizeBootstrapRegistrationIntent(options, lease, outcome, transac
2688
2694
  if (!settled)
2689
2695
  throw new Error('bootstrap registration intent terminal publication failed');
2690
2696
  assertBootstrapIntentFileTrust(options, lease.terminalPath);
2691
- const after = lstatSync(lease.terminalPath, { bigint: true });
2697
+ const after = bootstrapPathMetadata(lease.terminalPath);
2692
2698
  if (!after.isFile() || after.isSymbolicLink() || after.nlink !== 1n
2693
2699
  || after.dev !== settled.dev || after.ino !== settled.ino
2694
2700
  || after.size !== settled.size || after.mtimeNs !== settled.mtimeNs
@@ -2698,7 +2704,7 @@ function terminalizeBootstrapRegistrationIntent(options, lease, outcome, transac
2698
2704
  const stateDir = dirname(lease.currentPath);
2699
2705
  syncBootstrapDirectory(stateDir);
2700
2706
  options.afterIntentTerminalPublish?.();
2701
- const active = lstatSync(lease.path, { bigint: true });
2707
+ const active = bootstrapPathMetadata(lease.path);
2702
2708
  if (!active.isFile() || active.isSymbolicLink() || active.nlink !== 1n
2703
2709
  || active.dev !== lease.device || active.ino !== lease.inode || active.size !== lease.size
2704
2710
  || active.mtimeNs !== lease.mtimeNs || active.ctimeNs !== lease.ctimeNs) {
@@ -2728,7 +2734,7 @@ function clearBootstrapRegistrationIntent(options, lease) {
2728
2734
  assertBootstrapIntentDirectoryTrust(options, stateDir, true);
2729
2735
  if (lease.staleRegistering) {
2730
2736
  assertBootstrapIntentFileTrust(options, lease.staleRegistering.path);
2731
- const stale = lstatSync(lease.staleRegistering.path, { bigint: true });
2737
+ const stale = bootstrapPathMetadata(lease.staleRegistering.path);
2732
2738
  if (!stale.isFile() || stale.isSymbolicLink() || stale.nlink !== 1n
2733
2739
  || stale.dev !== lease.staleRegistering.device || stale.ino !== lease.staleRegistering.inode
2734
2740
  || stale.size !== lease.staleRegistering.size
@@ -2743,7 +2749,7 @@ function clearBootstrapRegistrationIntent(options, lease) {
2743
2749
  }
2744
2750
  }
2745
2751
  assertBootstrapIntentFileTrust(options, lease.currentPath);
2746
- const current = lstatSync(lease.currentPath, { bigint: true });
2752
+ const current = bootstrapPathMetadata(lease.currentPath);
2747
2753
  if (!current.isFile() || current.isSymbolicLink() || current.nlink !== 1n
2748
2754
  || current.dev !== lease.device || current.ino !== lease.inode || current.size !== lease.size
2749
2755
  || current.mtimeNs !== lease.mtimeNs || current.ctimeNs !== lease.ctimeNs) {
@@ -2761,7 +2767,7 @@ function clearBootstrapRegistrationIntent(options, lease) {
2761
2767
  }
2762
2768
  renameSync(lease.terminalPath, lease.clearingPath);
2763
2769
  syncBootstrapDirectory(stateDir);
2764
- const renamed = lstatSync(lease.clearingPath, { bigint: true });
2770
+ const renamed = bootstrapPathMetadata(lease.clearingPath);
2765
2771
  if (!renamed.isFile() || renamed.isSymbolicLink() || renamed.nlink !== 1n
2766
2772
  || renamed.dev !== lease.device || renamed.ino !== lease.inode
2767
2773
  || renamed.size !== lease.size) {
@@ -2780,7 +2786,7 @@ function clearBootstrapRegistrationIntent(options, lease) {
2780
2786
  throw new Error('bootstrap registration intent path is unexpected');
2781
2787
  }
2782
2788
  assertBootstrapIntentFileTrust(options, clearingLease.currentPath);
2783
- const moved = lstatSync(clearingLease.currentPath, { bigint: true });
2789
+ const moved = bootstrapPathMetadata(clearingLease.currentPath);
2784
2790
  if (!moved.isFile() || moved.isSymbolicLink() || moved.nlink !== 1n
2785
2791
  || moved.dev !== clearingLease.device || moved.ino !== clearingLease.inode
2786
2792
  || moved.size !== clearingLease.size || moved.mtimeNs !== clearingLease.mtimeNs
@@ -2816,7 +2822,7 @@ function sameBootstrapIncompletePublication(left, right) {
2816
2822
  }
2817
2823
  function assertBootstrapRegistrationIntentFileIdentity(options, expected) {
2818
2824
  assertBootstrapIntentFileTrust(options, expected.path, Number(expected.linkCount));
2819
- const current = lstatSync(expected.path, { bigint: true });
2825
+ const current = bootstrapPathMetadata(expected.path);
2820
2826
  if (!current.isFile() || current.isSymbolicLink() || current.nlink !== expected.linkCount
2821
2827
  || current.dev !== expected.device || current.ino !== expected.inode
2822
2828
  || current.size !== expected.size || current.mtimeNs !== expected.mtimeNs
@@ -2842,7 +2848,7 @@ function clearBootstrapIncompletePublication(options, publication) {
2842
2848
  && publication.registration.identity.device === publication.publishing.device
2843
2849
  && publication.registration.identity.inode === publication.publishing.inode) {
2844
2850
  assertBootstrapIntentFileTrust(options, publication.publishing.path);
2845
- const remaining = lstatSync(publication.publishing.path, { bigint: true });
2851
+ const remaining = bootstrapPathMetadata(publication.publishing.path);
2846
2852
  if (!remaining.isFile() || remaining.isSymbolicLink() || remaining.nlink !== 1n
2847
2853
  || remaining.dev !== publication.publishing.device
2848
2854
  || remaining.ino !== publication.publishing.inode
@@ -3027,7 +3033,7 @@ function recoverBootstrapRegistrationIntent(options) {
3027
3033
  };
3028
3034
  }
3029
3035
  assertBootstrapIntentFileTrust(options, intent.terminalFile.path);
3030
- const partial = lstatSync(intent.terminalFile.path, { bigint: true });
3036
+ const partial = bootstrapPathMetadata(intent.terminalFile.path);
3031
3037
  if (!partial.isFile() || partial.isSymbolicLink() || partial.nlink !== 1n
3032
3038
  || partial.dev !== intent.terminalFile.device || partial.ino !== intent.terminalFile.inode) {
3033
3039
  throw new Error('incomplete terminal receipt ownership changed');
@@ -27,7 +27,10 @@ function syncDirectory(path) {
27
27
  }
28
28
  function readExistingReadiness(path) {
29
29
  try {
30
- const before = lstatSync(path, { bigint: true });
30
+ let before = lstatSync(path, { bigint: true });
31
+ if (process.platform === 'win32' && before.dev === 0n && before.isFile() && !before.isSymbolicLink()) {
32
+ before = util.statRegularFileIdentity(path);
33
+ }
31
34
  if (!before.isFile() || before.isSymbolicLink() || before.size > BigInt(MAX_READINESS_BYTES)
32
35
  || before.dev <= 0n || before.ino <= 0n) {
33
36
  throw new Error('bootstrap readiness path is not a bounded regular file');
@@ -0,0 +1,2 @@
1
+ import { type BigIntStats } from 'node:fs';
2
+ export declare function selfUpdateFileMetadata(path: string, access?: number): Promise<BigIntStats>;
@@ -0,0 +1,25 @@
1
+ import { constants } from 'node:fs';
2
+ import { lstat, open } from 'node:fs/promises';
3
+ import { SELF_UPDATE_FAILURE_CODES, selfUpdateFailure } from './failureCodes.js';
4
+ export async function selfUpdateFileMetadata(path, access = constants.O_RDONLY) {
5
+ const before = await lstat(path, { bigint: true });
6
+ if (process.platform !== 'win32' || before.dev !== 0n || before.isSymbolicLink() || !before.isFile())
7
+ return before;
8
+ // Windows pathname metadata can omit the volume supplied by the descriptor.
9
+ // Use the caller's existing access, never creation/truncation or missing-dev equality.
10
+ const handle = await open(path, access | (typeof constants.O_NOFOLLOW === 'number' ? constants.O_NOFOLLOW : 0));
11
+ try {
12
+ const opened = await handle.stat({ bigint: true });
13
+ const after = await lstat(path, { bigint: true });
14
+ if (!opened.isFile() || opened.dev <= 0n || opened.ino <= 0n || after.isSymbolicLink() || !after.isFile()
15
+ || opened.ino !== before.ino || opened.ino !== after.ino
16
+ || opened.birthtimeNs !== before.birthtimeNs || opened.birthtimeNs !== after.birthtimeNs
17
+ || after.dev !== 0n && opened.dev !== after.dev) {
18
+ throw selfUpdateFailure(SELF_UPDATE_FAILURE_CODES.UNSAFE_UPDATE_PATH, 'file_identity_changed');
19
+ }
20
+ return opened;
21
+ }
22
+ finally {
23
+ await handle.close();
24
+ }
25
+ }
@@ -27,6 +27,7 @@ import { homedir } from 'node:os';
27
27
  import { dirname, isAbsolute, join, parse as parsePath, relative, resolve as resolvePath, win32 } from 'node:path';
28
28
  import { ops, util } from '@evomap/evolver-core';
29
29
  import { SELF_UPDATE_FAILURE_CODES } from './failureCodes.js';
30
+ import { selfUpdateFileMetadata } from './fileMetadata.js';
30
31
  import { resolveSelfUpdatePublicKey } from './builtinKey.js';
31
32
  import { downloadGithubReleaseArtifact, releaseAssetName, resolveGithubReleaseManifest, } from './releaseBinary.js';
32
33
  import { preflightManagedStagedBinary } from './transaction.js';
@@ -83,8 +84,13 @@ function assertTrustedMigrationStateLeafSync(path, options = {}) {
83
84
  }
84
85
  return existing;
85
86
  }
87
+ function migrationPathMetadata(path) {
88
+ const stat = lstatSync(path, { bigint: true });
89
+ return process.platform === 'win32' && stat.dev === 0n && stat.isFile() && !stat.isSymbolicLink()
90
+ ? util.statRegularFileIdentity(path) : stat;
91
+ }
86
92
  function statMigrationStateLeafSync(path) {
87
- const existing = lstatSync(path, { bigint: true });
93
+ const existing = migrationPathMetadata(path);
88
94
  if (existing.isSymbolicLink() || !existing.isFile() || existing.nlink !== 1n) {
89
95
  throw new Error('unsafe_migration_state_leaf');
90
96
  }
@@ -198,7 +204,7 @@ const defaultWriteTextFile = (path, content) => {
198
204
  closeSync(fd);
199
205
  fd = undefined;
200
206
  renameSync(temporaryPath, path);
201
- const published = lstatSync(path, { bigint: true });
207
+ const published = migrationPathMetadata(path);
202
208
  if (published.isSymbolicLink() || !published.isFile() || published.nlink !== 1n) {
203
209
  throw new Error('unsafe_migration_state_publication');
204
210
  }
@@ -897,7 +903,7 @@ function sha256(bytes) {
897
903
  async function inspectExistingMigrationTarget(destPath, version, preflight, readBinary, expected, assertDirectoryTrust, assertFileTrust) {
898
904
  let before;
899
905
  try {
900
- before = await lstat(destPath, { bigint: true });
906
+ before = await selfUpdateFileMetadata(destPath);
901
907
  }
902
908
  catch (error) {
903
909
  if (isErrno(error, 'ENOENT'))
@@ -924,7 +930,7 @@ async function inspectExistingMigrationTarget(destPath, version, preflight, read
924
930
  throw new Error(`destination_exists_unowned_or_invalid:${errorDetail(error)}`, { cause: error });
925
931
  }
926
932
  await assertFileTrust(destPath);
927
- const after = await lstat(destPath, { bigint: true });
933
+ const after = await selfUpdateFileMetadata(destPath);
928
934
  if (!after.isFile() || after.isSymbolicLink() || after.nlink !== 1n
929
935
  || after.dev !== before.dev || after.ino !== before.ino || after.size !== before.size
930
936
  || after.mtimeNs !== before.mtimeNs || after.ctimeNs !== before.ctimeNs) {
@@ -1013,7 +1019,7 @@ function readBoundedMigrationLockFd(fd) {
1013
1019
  return bytes.subarray(0, offset);
1014
1020
  }
1015
1021
  function readMigrationLockAuthority(lockPath) {
1016
- const beforeOpen = lstatSync(lockPath, { bigint: true });
1022
+ const beforeOpen = migrationPathMetadata(lockPath);
1017
1023
  assertMigrationLockSnapshotShape(beforeOpen);
1018
1024
  const fd = openSync(lockPath, 'r');
1019
1025
  try {
@@ -1024,10 +1030,10 @@ function readMigrationLockAuthority(lockPath) {
1024
1030
  }
1025
1031
  const firstBytes = readBoundedMigrationLockFd(fd);
1026
1032
  const afterFirstFd = fstatSync(fd, { bigint: true });
1027
- const afterFirstPath = lstatSync(lockPath, { bigint: true });
1033
+ const afterFirstPath = migrationPathMetadata(lockPath);
1028
1034
  const secondBytes = readBoundedMigrationLockFd(fd);
1029
1035
  const finalFd = fstatSync(fd, { bigint: true });
1030
- const finalPath = lstatSync(lockPath, { bigint: true });
1036
+ const finalPath = migrationPathMetadata(lockPath);
1031
1037
  for (const snapshot of [afterFirstFd, afterFirstPath, finalFd, finalPath]) {
1032
1038
  assertMigrationLockSnapshotShape(snapshot);
1033
1039
  if (!sameMigrationLockSnapshot(opened, snapshot)) {
@@ -1152,7 +1158,7 @@ async function installVerifiedMigrationBinary(input) {
1152
1158
  await input.chmod(temporaryPath, 0o755);
1153
1159
  await input.syncFile(temporaryPath);
1154
1160
  const temporaryInfo = await input.stat(temporaryPath);
1155
- const temporaryIdentity = await lstat(temporaryPath, { bigint: true });
1161
+ const temporaryIdentity = await selfUpdateFileMetadata(temporaryPath);
1156
1162
  if (temporaryInfo.isSymbolicLink() || !temporaryInfo.isFile()
1157
1163
  || temporaryIdentity.isSymbolicLink() || !temporaryIdentity.isFile()
1158
1164
  || temporaryIdentity.nlink !== 1n || temporaryIdentity.dev <= 0n || temporaryIdentity.ino <= 0n) {
@@ -1267,7 +1273,7 @@ function migrationRegistrationTargetQuarantinePath(destPath, intentId) {
1267
1273
  }
1268
1274
  async function migrationPathIdentity(path) {
1269
1275
  try {
1270
- return await lstat(path, { bigint: true });
1276
+ return await selfUpdateFileMetadata(path);
1271
1277
  }
1272
1278
  catch (error) {
1273
1279
  if (isErrno(error, 'ENOENT'))
@@ -1279,7 +1285,7 @@ function sameMigrationFileId(left, right) {
1279
1285
  return left.dev === right.dev && left.ino === right.ino;
1280
1286
  }
1281
1287
  async function inspectExactMigrationCleanupFile(input) {
1282
- const before = await lstat(input.path, { bigint: true });
1288
+ const before = await selfUpdateFileMetadata(input.path);
1283
1289
  await input.assertFileTrust(input.path);
1284
1290
  if (before.isSymbolicLink()
1285
1291
  || !before.isFile()
@@ -1293,7 +1299,7 @@ async function inspectExactMigrationCleanupFile(input) {
1293
1299
  if (bytes.byteLength !== input.expected.size || sha256(bytes) !== input.expected.sha256) {
1294
1300
  throw new Error(input.hashError);
1295
1301
  }
1296
- const after = await lstat(input.path, { bigint: true });
1302
+ const after = await selfUpdateFileMetadata(input.path);
1297
1303
  if (after.isSymbolicLink()
1298
1304
  || !after.isFile()
1299
1305
  || after.dev !== before.dev
@@ -1506,7 +1512,7 @@ async function recoverPendingMigrationInstall(input) {
1506
1512
  if (pending.anchor.phase === 'planned') {
1507
1513
  let before;
1508
1514
  try {
1509
- before = await lstat(pending.anchor.temporaryPath, { bigint: true });
1515
+ before = await selfUpdateFileMetadata(pending.anchor.temporaryPath);
1510
1516
  }
1511
1517
  catch (error) {
1512
1518
  if (!isErrno(error, 'ENOENT'))
@@ -1525,7 +1531,7 @@ async function recoverPendingMigrationInstall(input) {
1525
1531
  throw new Error('migration_planned_temporary_unowned');
1526
1532
  }
1527
1533
  const bytes = await input.readBinary(pending.anchor.temporaryPath);
1528
- const after = await lstat(pending.anchor.temporaryPath, { bigint: true });
1534
+ const after = await selfUpdateFileMetadata(pending.anchor.temporaryPath);
1529
1535
  if (after.isSymbolicLink()
1530
1536
  || !after.isFile()
1531
1537
  || after.dev !== before.dev
@@ -92,8 +92,10 @@ export function deliverRecoveryChildStartGate(child, token, timeoutMs = DEFAULT_
92
92
  settled = true;
93
93
  clearTimeout(timer);
94
94
  gate.off('finish', onFinish);
95
- gate.off('error', onError);
96
95
  gate.off('close', onClose);
96
+ // Keep the error listener: fd4 stays readable after delivery, and stopping
97
+ // the child resets it (ECONNRESET on Linux). Without a listener that cleanup
98
+ // error is uncaught and crashes the long-lived controller.
97
99
  resolve(accepted);
98
100
  };
99
101
  const onFinish = () => { finish(true); };
@@ -109,7 +111,7 @@ export function deliverRecoveryChildStartGate(child, token, timeoutMs = DEFAULT_
109
111
  finish(false);
110
112
  }, positiveTimeout(timeoutMs));
111
113
  gate.once('finish', onFinish);
112
- gate.once('error', onError);
114
+ gate.on('error', onError);
113
115
  gate.once('close', onClose);
114
116
  gate.end(`${token}\n`);
115
117
  });