@wildo-ai/dev-companion 1.1.12 → 1.1.13

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 (88) hide show
  1. package/dist/esm/.tsbuildinfo +1 -1
  2. package/dist/esm/claude-cli/services/coding-agent-dispatch.companion.service.d.ts.map +1 -1
  3. package/dist/esm/claude-cli/services/coding-agent-dispatch.companion.service.js +8 -6
  4. package/dist/esm/claude-cli/services/coding-agent-dispatch.companion.service.js.map +1 -1
  5. package/dist/esm/companion-api/controllers/companion.controller.d.ts +6 -0
  6. package/dist/esm/companion-api/controllers/companion.controller.d.ts.map +1 -1
  7. package/dist/esm/companion-api/controllers/companion.controller.js +13 -1
  8. package/dist/esm/companion-api/controllers/companion.controller.js.map +1 -1
  9. package/dist/esm/core/introspection/resources/creation-home-projection.companion.d.ts.map +1 -1
  10. package/dist/esm/core/introspection/resources/creation-home-projection.companion.js +7 -0
  11. package/dist/esm/core/introspection/resources/creation-home-projection.companion.js.map +1 -1
  12. package/dist/esm/core/introspection/resources/launch-blockers.companion.d.ts +5 -1
  13. package/dist/esm/core/introspection/resources/launch-blockers.companion.d.ts.map +1 -1
  14. package/dist/esm/core/introspection/resources/launch-blockers.companion.js +37 -4
  15. package/dist/esm/core/introspection/resources/launch-blockers.companion.js.map +1 -1
  16. package/dist/esm/core/introspection/services/companion-introspection.companion.service.d.ts +14 -0
  17. package/dist/esm/core/introspection/services/companion-introspection.companion.service.d.ts.map +1 -1
  18. package/dist/esm/core/introspection/services/companion-introspection.companion.service.js +48 -0
  19. package/dist/esm/core/introspection/services/companion-introspection.companion.service.js.map +1 -1
  20. package/dist/esm/core/introspection/services/introspection-dependency-tree.companion.d.ts +128 -0
  21. package/dist/esm/core/introspection/services/introspection-dependency-tree.companion.d.ts.map +1 -0
  22. package/dist/esm/core/introspection/services/introspection-dependency-tree.companion.js +180 -0
  23. package/dist/esm/core/introspection/services/introspection-dependency-tree.companion.js.map +1 -0
  24. package/dist/esm/core/introspection/services/introspection-worker-pool.companion.d.ts +9 -0
  25. package/dist/esm/core/introspection/services/introspection-worker-pool.companion.d.ts.map +1 -1
  26. package/dist/esm/core/introspection/services/introspection-worker-pool.companion.js +25 -3
  27. package/dist/esm/core/introspection/services/introspection-worker-pool.companion.js.map +1 -1
  28. package/dist/esm/core/runtime/restart-drain.companion.d.ts +107 -0
  29. package/dist/esm/core/runtime/restart-drain.companion.d.ts.map +1 -0
  30. package/dist/esm/core/runtime/restart-drain.companion.js +237 -0
  31. package/dist/esm/core/runtime/restart-drain.companion.js.map +1 -0
  32. package/dist/esm/executions/services/companion-executions.companion.service.d.ts +18 -1
  33. package/dist/esm/executions/services/companion-executions.companion.service.d.ts.map +1 -1
  34. package/dist/esm/executions/services/companion-executions.companion.service.js +34 -8
  35. package/dist/esm/executions/services/companion-executions.companion.service.js.map +1 -1
  36. package/dist/esm/i18n/resources/workbenchSpecificationArtifacts.en.d.ts +40 -0
  37. package/dist/esm/i18n/resources/workbenchSpecificationArtifacts.en.d.ts.map +1 -1
  38. package/dist/esm/i18n/resources/workbenchSpecificationArtifacts.en.js +13 -0
  39. package/dist/esm/i18n/resources/workbenchSpecificationArtifacts.en.js.map +1 -1
  40. package/dist/esm/i18n/resources/workbenchSpecificationArtifacts.fr.d.ts +40 -0
  41. package/dist/esm/i18n/resources/workbenchSpecificationArtifacts.fr.d.ts.map +1 -1
  42. package/dist/esm/i18n/resources/workbenchSpecificationArtifacts.fr.js +40 -0
  43. package/dist/esm/i18n/resources/workbenchSpecificationArtifacts.fr.js.map +1 -1
  44. package/dist/esm/i18n/system_enums/application-creation.en.d.ts +5 -0
  45. package/dist/esm/i18n/system_enums/application-creation.en.d.ts.map +1 -1
  46. package/dist/esm/i18n/system_enums/application-creation.en.js +6 -0
  47. package/dist/esm/i18n/system_enums/application-creation.en.js.map +1 -1
  48. package/dist/esm/i18n/system_enums/application-creation.fr.d.ts +5 -0
  49. package/dist/esm/i18n/system_enums/application-creation.fr.d.ts.map +1 -1
  50. package/dist/esm/i18n/system_enums/application-creation.fr.js +5 -0
  51. package/dist/esm/i18n/system_enums/application-creation.fr.js.map +1 -1
  52. package/dist/esm/i18n/system_enums/workbench-build.en.d.ts +2 -0
  53. package/dist/esm/i18n/system_enums/workbench-build.en.d.ts.map +1 -1
  54. package/dist/esm/i18n/system_enums/workbench-build.en.js +2 -0
  55. package/dist/esm/i18n/system_enums/workbench-build.en.js.map +1 -1
  56. package/dist/esm/meta-workflows/models/application-coding-agent.actors-system.definitions.d.ts +5 -1
  57. package/dist/esm/meta-workflows/models/application-coding-agent.actors-system.definitions.d.ts.map +1 -1
  58. package/dist/esm/meta-workflows/models/application-coding-agent.actors-system.definitions.js +5 -1
  59. package/dist/esm/meta-workflows/models/application-coding-agent.actors-system.definitions.js.map +1 -1
  60. package/dist/esm/meta-workflows/models/playbook-run-record.models.d.ts +12 -0
  61. package/dist/esm/meta-workflows/models/playbook-run-record.models.d.ts.map +1 -1
  62. package/dist/esm/meta-workflows/models/playbook-run-record.models.js +9 -0
  63. package/dist/esm/meta-workflows/models/playbook-run-record.models.js.map +1 -1
  64. package/dist/esm/meta-workflows/services/application-build-dispatch.companion.service.d.ts +80 -4
  65. package/dist/esm/meta-workflows/services/application-build-dispatch.companion.service.d.ts.map +1 -1
  66. package/dist/esm/meta-workflows/services/application-build-dispatch.companion.service.js +235 -42
  67. package/dist/esm/meta-workflows/services/application-build-dispatch.companion.service.js.map +1 -1
  68. package/dist/esm/meta-workflows/services/application-build-follow-up-derivation.companion.d.ts +56 -3
  69. package/dist/esm/meta-workflows/services/application-build-follow-up-derivation.companion.d.ts.map +1 -1
  70. package/dist/esm/meta-workflows/services/application-build-follow-up-derivation.companion.js +182 -33
  71. package/dist/esm/meta-workflows/services/application-build-follow-up-derivation.companion.js.map +1 -1
  72. package/dist/esm/meta-workflows/services/application-build-generation-step.companion.service.d.ts +58 -0
  73. package/dist/esm/meta-workflows/services/application-build-generation-step.companion.service.d.ts.map +1 -1
  74. package/dist/esm/meta-workflows/services/application-build-generation-step.companion.service.js +116 -2
  75. package/dist/esm/meta-workflows/services/application-build-generation-step.companion.service.js.map +1 -1
  76. package/dist/esm/meta-workflows/services/application-build-task-coding-policy.companion.service.d.ts +12 -0
  77. package/dist/esm/meta-workflows/services/application-build-task-coding-policy.companion.service.d.ts.map +1 -1
  78. package/dist/esm/meta-workflows/services/application-build-task-coding-policy.companion.service.js +31 -7
  79. package/dist/esm/meta-workflows/services/application-build-task-coding-policy.companion.service.js.map +1 -1
  80. package/dist/esm/meta-workflows/services/creation-run-report.companion.service.d.ts +2 -2
  81. package/dist/esm/meta-workflows/services/creation-run-report.companion.service.d.ts.map +1 -1
  82. package/dist/esm/meta-workflows/services/creation-run-report.companion.service.js +10 -8
  83. package/dist/esm/meta-workflows/services/creation-run-report.companion.service.js.map +1 -1
  84. package/dist/esm/meta-workflows/services/playbook-run.companion.service.d.ts +67 -2
  85. package/dist/esm/meta-workflows/services/playbook-run.companion.service.d.ts.map +1 -1
  86. package/dist/esm/meta-workflows/services/playbook-run.companion.service.js +243 -48
  87. package/dist/esm/meta-workflows/services/playbook-run.companion.service.js.map +1 -1
  88. package/package.json +17 -17
@@ -0,0 +1,128 @@
1
+ import { type DependencyInstallStatus } from '@wildo-ai/platform-core-shared/dev-runtime';
2
+ /**
3
+ * An introspection derivation survives a dependency install under the live companion (#3703).
4
+ *
5
+ * ## Why
6
+ *
7
+ * Every derivation runs in a child process that resolves its packages (`zod` first, then the engine and the
8
+ * application) from the application's `node_modules` AT THE MOMENT IT STARTS. The companion process itself loaded
9
+ * its graph long before, so it keeps running while a `pnpm install` re-creates that tree under it, but every child
10
+ * started during the install dies on its first bare import. Reference run 42886943490 (2026-11-09) logged 788 such
11
+ * failures in six windows of 6 s to 2.5 min, every one `ERR_MODULE_NOT_FOUND: Cannot find package 'zod' imported from
12
+ * …/companion-introspection-child.js`: a foundation install, a monorepo reinjection (`[sync] reinjecting via pnpm`,
13
+ * which writes no install record), and installs nobody recorded (the backend's compile lost `react/jsx-runtime` and
14
+ * `@types/node` at the same instant, which is a tree being re-created, not a missing declaration). Each failure read as
15
+ * "unanswerable" to a landing probe, and held the build's labels step.
16
+ *
17
+ * #3552 taught the supervisors and the compile watchers to wait an install out; nothing taught this lane, whose
18
+ * children are started on demand rather than supervised.
19
+ *
20
+ * ## The two decisions
21
+ *
22
+ * 1. **Before a derivation starts**, {@link IntrospectionDependencyTreeGate.holdWhileInstallInFlight}: while a RECORDED
23
+ * install is in flight (the #3552 record, written by the foundation step and the CLI), start nothing. The record's
24
+ * own deadline and writer liveness bound the wait (`classifyDependencyInstall`).
25
+ * 2. **After a derivation failed**, {@link IntrospectionDependencyTreeGate.settleAfterFailure}: when the failure is a
26
+ * bare package the importer DECLARES that the resolver could not find, the tree was in motion. Wait until that
27
+ * package resolves again from that importer (and no recorded install is in flight), then the caller derives once
28
+ * more, in a process started after the tree settled. This covers the installs nobody recorded, because it asks the
29
+ * file system the same question Node's resolver asked rather than trusting a record.
30
+ *
31
+ * ## What is NOT waited for
32
+ *
33
+ * - A failure that names no unresolved package: every other failure is the derivation's own and is returned at once.
34
+ * - A package the importer does not declare: no install can make an undeclared import resolve, so it is a defect in
35
+ * the importing code, reported at once rather than after a wait.
36
+ * - The same package from the same importer once more, over the same installed tree: a wait that already ran to its
37
+ * ceiling is remembered against pnpm's `node_modules/.modules.yaml` time, so a package that is really missing (a
38
+ * lockfile that never installed it) costs one wait, not one per derivation. A later install moves that time and
39
+ * lifts the memory.
40
+ */
41
+ /** A bare package the module resolver could not find, and the file that imported it. */
42
+ export interface UnresolvedPackageImport {
43
+ readonly packageName: string;
44
+ readonly importerPath: string;
45
+ }
46
+ /** What the gate concluded about a failed derivation. */
47
+ export declare enum DependencyTreeSettleVerdict {
48
+ /** The failure names no unresolved bare package: it is the derivation's own, and stands. */
49
+ NOT_A_DEPENDENCY_FAILURE = "NOT_A_DEPENDENCY_FAILURE",
50
+ /** The package is not one its importer declares: no install will bring it, so the failure stands. */
51
+ UNDECLARED_PACKAGE = "UNDECLARED_PACKAGE",
52
+ /** The package resolves again and no recorded install is running: derive once more, in a fresh process. */
53
+ SETTLED = "SETTLED",
54
+ /** The package still does not resolve after the ceiling (or did not over this same tree before): the failure stands. */
55
+ STILL_UNRESOLVED = "STILL_UNRESOLVED"
56
+ }
57
+ export interface DependencyTreeSettleOutcome {
58
+ readonly verdict: DependencyTreeSettleVerdict;
59
+ readonly unresolved?: UnresolvedPackageImport;
60
+ readonly waitedMs: number;
61
+ /** When the tree was judged settled ({@link DependencyTreeSettleVerdict.SETTLED} only): a process started before it may hold the moved tree. */
62
+ readonly settledAtMs?: number;
63
+ }
64
+ /** How often the gate re-reads the record and the resolver's answer while it waits. */
65
+ export declare const DEPENDENCY_TREE_POLL_MS = 1000;
66
+ /**
67
+ * The longest the gate waits for a package to resolve again when no recorded install explains the gap.
68
+ *
69
+ * The longest window measured (reference run 42886943490, 18:35:50 → 18:38:20) was 2.5 min, a reinjection that failed
70
+ * and was retried several times. Twice that leaves room for a slower host, and a package that is really missing pays it
71
+ * once (see the memory above). A RECORDED install extends the wait to its own deadline instead.
72
+ */
73
+ export declare const DEPENDENCY_TREE_SETTLE_CEILING_MS: number;
74
+ /**
75
+ * The package name of a BARE specifier (`zod`, `zod/v4` → `zod`; `@scope/pkg/sub` → `@scope/pkg`), or null for a
76
+ * relative, absolute, URL or builtin specifier, which no install moves.
77
+ */
78
+ export declare function packageNameOfBareSpecifier(specifier: string): string | null;
79
+ /** The unresolved bare package a failure text names, or null when it names none. */
80
+ export declare function findUnresolvedPackageImport(text: string): UnresolvedPackageImport | null;
81
+ /**
82
+ * Whether `packageName` resolves from `importerPath` the way Node's resolver looks for it: the first
83
+ * `node_modules/<name>/package.json` found walking up from the importer's directory. `existsSync` follows the symlink
84
+ * pnpm links a package through, so a link whose target is being re-created reads as absent, which is exactly the gap.
85
+ */
86
+ export declare function isPackageResolvableFrom(packageName: string, importerPath: string, exists?: (path: string) => boolean): boolean;
87
+ /**
88
+ * Whether the importer's own package DECLARES `packageName`: the nearest `package.json` above it that has a `name` (a
89
+ * `dist/esm/package.json` carrying only `"type"` is not a package boundary for this question).
90
+ */
91
+ export declare function importerDeclaresPackage(packageName: string, importerPath: string, readText?: (path: string) => string | null): boolean;
92
+ export interface IntrospectionDependencyTreeGateOptions {
93
+ /** The application root: where the #3552 install record and pnpm's `.modules.yaml` live. */
94
+ readonly appRoot: string;
95
+ readonly log?: (message: string, context?: Record<string, unknown>) => void;
96
+ /** Test seams; production reads the record, the file system and the clock. */
97
+ readonly readInstall?: () => DependencyInstallStatus;
98
+ readonly readNodeModulesInstalledAtMs?: () => number | null;
99
+ readonly isResolvable?: (unresolved: UnresolvedPackageImport) => boolean;
100
+ readonly declares?: (unresolved: UnresolvedPackageImport) => boolean;
101
+ readonly now?: () => number;
102
+ readonly sleep?: (ms: number) => Promise<void>;
103
+ readonly pollMs?: number;
104
+ readonly settleCeilingMs?: number;
105
+ }
106
+ /** See the module comment. One per companion introspection service. */
107
+ export declare class IntrospectionDependencyTreeGate {
108
+ private readonly options;
109
+ private readonly readInstall;
110
+ private readonly readInstalledAtMs;
111
+ private readonly isResolvable;
112
+ private readonly declares;
113
+ private readonly now;
114
+ private readonly sleep;
115
+ private readonly pollMs;
116
+ private readonly settleCeilingMs;
117
+ /** `<package>\0<importer>` → the `.modules.yaml` time over which a wait for it already ran out. */
118
+ private readonly exhausted;
119
+ constructor(options: IntrospectionDependencyTreeGateOptions);
120
+ /** Wait while a recorded install is in flight; returns how long it waited. Bounded by the record's deadline. */
121
+ holdWhileInstallInFlight(): Promise<number>;
122
+ /**
123
+ * Judge a failed derivation's text (its error message and stderr). Waits only when the failure is a declared
124
+ * package the resolver could not find; see the module comment for every case.
125
+ */
126
+ settleAfterFailure(failureText: string): Promise<DependencyTreeSettleOutcome>;
127
+ }
128
+ //# sourceMappingURL=introspection-dependency-tree.companion.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"introspection-dependency-tree.companion.d.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AAQ,CAAC,GAAG,CAAe;IACnC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAgC;IACtD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAS;IACzC,mGAAmG;IACnG,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAoC;gBAE1B,OAAO,EAAE,sCAAsC;IAWnF,gHAAgH;IACnG,wBAAwB,IAAI,OAAO,CAAC,MAAM,CAAC;IAaxD;;;OAGG;IACU,kBAAkB,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,2BAA2B,CAAC;CA6B3F"}
@@ -0,0 +1,180 @@
1
+ import { existsSync, readFileSync } from 'node:fs';
2
+ import { dirname, isAbsolute, join } from 'node:path';
3
+ import { LocalDevDependencyInstallPhase } from '@wildo-ai/platform-core-shared';
4
+ import { classifyDependencyInstall, readDependencyInstallRecord, readNodeModulesInstalledAtMs, } from '@wildo-ai/platform-core-shared/dev-runtime';
5
+ /** What the gate concluded about a failed derivation. */
6
+ export var DependencyTreeSettleVerdict;
7
+ (function (DependencyTreeSettleVerdict) {
8
+ /** The failure names no unresolved bare package: it is the derivation's own, and stands. */
9
+ DependencyTreeSettleVerdict["NOT_A_DEPENDENCY_FAILURE"] = "NOT_A_DEPENDENCY_FAILURE";
10
+ /** The package is not one its importer declares: no install will bring it, so the failure stands. */
11
+ DependencyTreeSettleVerdict["UNDECLARED_PACKAGE"] = "UNDECLARED_PACKAGE";
12
+ /** The package resolves again and no recorded install is running: derive once more, in a fresh process. */
13
+ DependencyTreeSettleVerdict["SETTLED"] = "SETTLED";
14
+ /** The package still does not resolve after the ceiling (or did not over this same tree before): the failure stands. */
15
+ DependencyTreeSettleVerdict["STILL_UNRESOLVED"] = "STILL_UNRESOLVED";
16
+ })(DependencyTreeSettleVerdict || (DependencyTreeSettleVerdict = {}));
17
+ /** How often the gate re-reads the record and the resolver's answer while it waits. */
18
+ export const DEPENDENCY_TREE_POLL_MS = 1_000;
19
+ /**
20
+ * The longest the gate waits for a package to resolve again when no recorded install explains the gap.
21
+ *
22
+ * The longest window measured (reference run 42886943490, 18:35:50 → 18:38:20) was 2.5 min, a reinjection that failed
23
+ * and was retried several times. Twice that leaves room for a slower host, and a package that is really missing pays it
24
+ * once (see the memory above). A RECORDED install extends the wait to its own deadline instead.
25
+ */
26
+ export const DEPENDENCY_TREE_SETTLE_CEILING_MS = 5 * 60_000;
27
+ // Both `ERR_MODULE_NOT_FOUND` shapes, the ESM resolver's and `require`'s. ANSI colour codes are stripped first: the
28
+ // text arrives as a child's stderr.
29
+ const ESM_UNRESOLVED_PACKAGE = /Cannot find package '([^']+)' imported from (.+?)(?:\r?\n|$)/;
30
+ const CJS_UNRESOLVED_MODULE = /Cannot find module '([^']+)'(?:[^\n]*)\r?\nRequire stack:\r?\n- (.+?)(?:\r?\n|$)/;
31
+ const ANSI_ESCAPE = /\u001b\[[0-9;]*m/g;
32
+ /**
33
+ * The package name of a BARE specifier (`zod`, `zod/v4` → `zod`; `@scope/pkg/sub` → `@scope/pkg`), or null for a
34
+ * relative, absolute, URL or builtin specifier, which no install moves.
35
+ */
36
+ export function packageNameOfBareSpecifier(specifier) {
37
+ if (specifier.length === 0 || specifier.startsWith('.') || isAbsolute(specifier) || specifier.startsWith('node:') || /^[a-z][a-z0-9+.-]*:/i.test(specifier)) {
38
+ return null;
39
+ }
40
+ const segments = specifier.split('/');
41
+ if (specifier.startsWith('@'))
42
+ return segments.length >= 2 && segments[1] ? `${segments[0]}/${segments[1]}` : null;
43
+ return segments[0] ?? null;
44
+ }
45
+ /** The unresolved bare package a failure text names, or null when it names none. */
46
+ export function findUnresolvedPackageImport(text) {
47
+ const plain = text.replace(ANSI_ESCAPE, '');
48
+ const match = ESM_UNRESOLVED_PACKAGE.exec(plain) ?? CJS_UNRESOLVED_MODULE.exec(plain);
49
+ if (!match)
50
+ return null;
51
+ const packageName = packageNameOfBareSpecifier(match[1] ?? '');
52
+ const importerPath = (match[2] ?? '').trim();
53
+ if (packageName === null || !isAbsolute(importerPath))
54
+ return null;
55
+ return { packageName, importerPath };
56
+ }
57
+ /**
58
+ * Whether `packageName` resolves from `importerPath` the way Node's resolver looks for it: the first
59
+ * `node_modules/<name>/package.json` found walking up from the importer's directory. `existsSync` follows the symlink
60
+ * pnpm links a package through, so a link whose target is being re-created reads as absent, which is exactly the gap.
61
+ */
62
+ export function isPackageResolvableFrom(packageName, importerPath, exists = existsSync) {
63
+ let directory = dirname(importerPath);
64
+ for (;;) {
65
+ if (exists(join(directory, 'node_modules', packageName, 'package.json')))
66
+ return true;
67
+ const parent = dirname(directory);
68
+ if (parent === directory)
69
+ return false;
70
+ directory = parent;
71
+ }
72
+ }
73
+ /**
74
+ * Whether the importer's own package DECLARES `packageName`: the nearest `package.json` above it that has a `name` (a
75
+ * `dist/esm/package.json` carrying only `"type"` is not a package boundary for this question).
76
+ */
77
+ export function importerDeclaresPackage(packageName, importerPath, readText = readTextOrNull) {
78
+ let directory = dirname(importerPath);
79
+ for (;;) {
80
+ const text = readText(join(directory, 'package.json'));
81
+ if (text !== null) {
82
+ try {
83
+ const manifest = JSON.parse(text);
84
+ if (typeof manifest.name === 'string') {
85
+ return ['dependencies', 'devDependencies', 'peerDependencies', 'optionalDependencies'].some((field) => {
86
+ const declared = manifest[field];
87
+ return declared !== null && typeof declared === 'object' && Object.prototype.hasOwnProperty.call(declared, packageName);
88
+ });
89
+ }
90
+ }
91
+ catch {
92
+ // An unreadable manifest is not a boundary; keep walking.
93
+ }
94
+ }
95
+ const parent = dirname(directory);
96
+ if (parent === directory)
97
+ return false;
98
+ directory = parent;
99
+ }
100
+ }
101
+ function readTextOrNull(path) {
102
+ try {
103
+ return readFileSync(path, 'utf8');
104
+ }
105
+ catch {
106
+ return null;
107
+ }
108
+ }
109
+ /** See the module comment. One per companion introspection service. */
110
+ export class IntrospectionDependencyTreeGate {
111
+ options;
112
+ readInstall;
113
+ readInstalledAtMs;
114
+ isResolvable;
115
+ declares;
116
+ now;
117
+ sleep;
118
+ pollMs;
119
+ settleCeilingMs;
120
+ /** `<package>\0<importer>` → the `.modules.yaml` time over which a wait for it already ran out. */
121
+ exhausted = new Map();
122
+ constructor(options) {
123
+ this.options = options;
124
+ this.readInstall = options.readInstall ?? (() => classifyDependencyInstall(readDependencyInstallRecord(options.appRoot), Date.now()));
125
+ this.readInstalledAtMs = options.readNodeModulesInstalledAtMs ?? (() => readNodeModulesInstalledAtMs(options.appRoot));
126
+ this.isResolvable = options.isResolvable ?? ((unresolved) => isPackageResolvableFrom(unresolved.packageName, unresolved.importerPath));
127
+ this.declares = options.declares ?? ((unresolved) => importerDeclaresPackage(unresolved.packageName, unresolved.importerPath));
128
+ this.now = options.now ?? Date.now;
129
+ this.sleep = options.sleep ?? ((ms) => new Promise((resolveSleep) => setTimeout(resolveSleep, ms)));
130
+ this.pollMs = options.pollMs ?? DEPENDENCY_TREE_POLL_MS;
131
+ this.settleCeilingMs = options.settleCeilingMs ?? DEPENDENCY_TREE_SETTLE_CEILING_MS;
132
+ }
133
+ /** Wait while a recorded install is in flight; returns how long it waited. Bounded by the record's deadline. */
134
+ async holdWhileInstallInFlight() {
135
+ const startedAtMs = this.now();
136
+ let announced = false;
137
+ while (this.readInstall().phase === LocalDevDependencyInstallPhase.IN_FLIGHT) {
138
+ if (!announced) {
139
+ announced = true;
140
+ this.options.log?.('Introspection derivation held: a dependency install is re-creating node_modules', { appRoot: this.options.appRoot });
141
+ }
142
+ await this.sleep(this.pollMs);
143
+ }
144
+ return this.now() - startedAtMs;
145
+ }
146
+ /**
147
+ * Judge a failed derivation's text (its error message and stderr). Waits only when the failure is a declared
148
+ * package the resolver could not find; see the module comment for every case.
149
+ */
150
+ async settleAfterFailure(failureText) {
151
+ const startedAtMs = this.now();
152
+ const unresolved = findUnresolvedPackageImport(failureText);
153
+ if (unresolved === null)
154
+ return { verdict: DependencyTreeSettleVerdict.NOT_A_DEPENDENCY_FAILURE, waitedMs: 0 };
155
+ if (!this.declares(unresolved))
156
+ return { verdict: DependencyTreeSettleVerdict.UNDECLARED_PACKAGE, unresolved, waitedMs: 0 };
157
+ const memoryKey = `${unresolved.packageName}\u0000${unresolved.importerPath}`;
158
+ if (this.exhausted.has(memoryKey)
159
+ && this.exhausted.get(memoryKey) === this.readInstalledAtMs()
160
+ && this.readInstall().phase !== LocalDevDependencyInstallPhase.IN_FLIGHT
161
+ && !this.isResolvable(unresolved)) {
162
+ return { verdict: DependencyTreeSettleVerdict.STILL_UNRESOLVED, unresolved, waitedMs: 0 };
163
+ }
164
+ for (;;) {
165
+ const inFlight = this.readInstall().phase === LocalDevDependencyInstallPhase.IN_FLIGHT;
166
+ if (!inFlight && this.isResolvable(unresolved)) {
167
+ this.exhausted.delete(memoryKey);
168
+ const settledAtMs = this.now();
169
+ return { verdict: DependencyTreeSettleVerdict.SETTLED, unresolved, waitedMs: settledAtMs - startedAtMs, settledAtMs };
170
+ }
171
+ // A recorded install is bounded by its own deadline; only an unexplained gap is bounded by the ceiling.
172
+ if (!inFlight && this.now() - startedAtMs >= this.settleCeilingMs) {
173
+ this.exhausted.set(memoryKey, this.readInstalledAtMs());
174
+ return { verdict: DependencyTreeSettleVerdict.STILL_UNRESOLVED, unresolved, waitedMs: this.now() - startedAtMs };
175
+ }
176
+ await this.sleep(this.pollMs);
177
+ }
178
+ }
179
+ }
180
+ //# sourceMappingURL=introspection-dependency-tree.companion.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"introspection-dependency-tree.companion.js","sourceRoot":"","sources":["../../../../../src/core/introspection/services/introspection-dependency-tree.companion.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEtD,OAAO,EAAE,8BAA8B,EAAE,MAAM,gCAAgC,CAAC;AAChF,OAAO,EACL,yBAAyB,EACzB,2BAA2B,EAC3B,4BA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D,IAAI,CAAC,WAAW,EAAE,CAAC,KAAK,KAAK,8BAA8B,CAAC,SAAS;eACrE,CAAC,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,EACjC,CAAC;YACD,OAAO,EAAE,OAAO,EAAE,2BAA2B,CAAC,gBAAgB,EAAE,UAAU,EAAE,QAAQ,EAAE,CAAC,EAAE,CAAC;QAC5F,CAAC;QACD,SAAS,CAAC;YACR,MAAM,QAAQ,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC,KAAK,KAAK,8BAA8B,CAAC,SAAS,CAAC;YACvF,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,EAAE,CAAC;gBAC/C,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;gBACjC,MAAM,WAAW,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;gBAC/B,OAAO,EAAE,OAAO,EAAE,2BAA2B,CAAC,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,WAAW,GAAG,WAAW,EAAE,WAAW,EAAE,CAAC;YACxH,CAAC;YACD,wGAAwG;YACxG,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,GAAG,EAAE,GAAG,WAAW,IAAI,IAAI,CAAC,eAAe,EAAE,CAAC;gBAClE,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,SAAS,EAAE,IAAI,CAAC,iBAAiB,EAAE,CAAC,CAAC;gBACxD,OAAO,EAAE,OAAO,EAAE,2BAA2B,CAAC,gBAAgB,EAAE,UAAU,EAAE,QAAQ,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,WAAW,EAAE,CAAC;YACnH,CAAC;YACD,MAAM,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAChC,CAAC;IACH,CAAC;CACF","sourcesContent":["import { existsSync, readFileSync } from 'node:fs';\nimport { dirname, isAbsolute, join } from 'node:path';\n\nimport { LocalDevDependencyInstallPhase } from '@wildo-ai/platform-core-shared';\nimport {\n classifyDependencyInstall,\n readDependencyInstallRecord,\n readNodeModulesInstalledAtMs,\n type DependencyInstallStatus,\n} from '@wildo-ai/platform-core-shared/dev-runtime';\n\n/**\n * An introspection derivation survives a dependency install under the live companion (#3703).\n *\n * ## Why\n *\n * Every derivation runs in a child process that resolves its packages (`zod` first, then the engine and the\n * application) from the application's `node_modules` AT THE MOMENT IT STARTS. The companion process itself loaded\n * its graph long before, so it keeps running while a `pnpm install` re-creates that tree under it, but every child\n * started during the install dies on its first bare import. Reference run 42886943490 (2026-11-09) logged 788 such\n * failures in six windows of 6 s to 2.5 min, every one `ERR_MODULE_NOT_FOUND: Cannot find package 'zod' imported from\n * …/companion-introspection-child.js`: a foundation install, a monorepo reinjection (`[sync] reinjecting via pnpm`,\n * which writes no install record), and installs nobody recorded (the backend's compile lost `react/jsx-runtime` and\n * `@types/node` at the same instant, which is a tree being re-created, not a missing declaration). Each failure read as\n * \"unanswerable\" to a landing probe, and held the build's labels step.\n *\n * #3552 taught the supervisors and the compile watchers to wait an install out; nothing taught this lane, whose\n * children are started on demand rather than supervised.\n *\n * ## The two decisions\n *\n * 1. **Before a derivation starts**, {@link IntrospectionDependencyTreeGate.holdWhileInstallInFlight}: while a RECORDED\n * install is in flight (the #3552 record, written by the foundation step and the CLI), start nothing. The record's\n * own deadline and writer liveness bound the wait (`classifyDependencyInstall`).\n * 2. **After a derivation failed**, {@link IntrospectionDependencyTreeGate.settleAfterFailure}: when the failure is a\n * bare package the importer DECLARES that the resolver could not find, the tree was in motion. Wait until that\n * package resolves again from that importer (and no recorded install is in flight), then the caller derives once\n * more, in a process started after the tree settled. This covers the installs nobody recorded, because it asks the\n * file system the same question Node's resolver asked rather than trusting a record.\n *\n * ## What is NOT waited for\n *\n * - A failure that names no unresolved package: every other failure is the derivation's own and is returned at once.\n * - A package the importer does not declare: no install can make an undeclared import resolve, so it is a defect in\n * the importing code, reported at once rather than after a wait.\n * - The same package from the same importer once more, over the same installed tree: a wait that already ran to its\n * ceiling is remembered against pnpm's `node_modules/.modules.yaml` time, so a package that is really missing (a\n * lockfile that never installed it) costs one wait, not one per derivation. A later install moves that time and\n * lifts the memory.\n */\n\n/** A bare package the module resolver could not find, and the file that imported it. */\nexport interface UnresolvedPackageImport {\n readonly packageName: string;\n readonly importerPath: string;\n}\n\n/** What the gate concluded about a failed derivation. */\nexport enum DependencyTreeSettleVerdict {\n /** The failure names no unresolved bare package: it is the derivation's own, and stands. */\n NOT_A_DEPENDENCY_FAILURE = 'NOT_A_DEPENDENCY_FAILURE',\n /** The package is not one its importer declares: no install will bring it, so the failure stands. */\n UNDECLARED_PACKAGE = 'UNDECLARED_PACKAGE',\n /** The package resolves again and no recorded install is running: derive once more, in a fresh process. */\n SETTLED = 'SETTLED',\n /** The package still does not resolve after the ceiling (or did not over this same tree before): the failure stands. */\n STILL_UNRESOLVED = 'STILL_UNRESOLVED',\n}\n\nexport interface DependencyTreeSettleOutcome {\n readonly verdict: DependencyTreeSettleVerdict;\n readonly unresolved?: UnresolvedPackageImport;\n readonly waitedMs: number;\n /** When the tree was judged settled ({@link DependencyTreeSettleVerdict.SETTLED} only): a process started before it may hold the moved tree. */\n readonly settledAtMs?: number;\n}\n\n/** How often the gate re-reads the record and the resolver's answer while it waits. */\nexport const DEPENDENCY_TREE_POLL_MS = 1_000;\n\n/**\n * The longest the gate waits for a package to resolve again when no recorded install explains the gap.\n *\n * The longest window measured (reference run 42886943490, 18:35:50 → 18:38:20) was 2.5 min, a reinjection that failed\n * and was retried several times. Twice that leaves room for a slower host, and a package that is really missing pays it\n * once (see the memory above). A RECORDED install extends the wait to its own deadline instead.\n */\nexport const DEPENDENCY_TREE_SETTLE_CEILING_MS = 5 * 60_000;\n\n// Both `ERR_MODULE_NOT_FOUND` shapes, the ESM resolver's and `require`'s. ANSI colour codes are stripped first: the\n// text arrives as a child's stderr.\nconst ESM_UNRESOLVED_PACKAGE = /Cannot find package '([^']+)' imported from (.+?)(?:\\r?\\n|$)/;\nconst CJS_UNRESOLVED_MODULE = /Cannot find module '([^']+)'(?:[^\\n]*)\\r?\\nRequire stack:\\r?\\n- (.+?)(?:\\r?\\n|$)/;\nconst ANSI_ESCAPE = /\\u001b\\[[0-9;]*m/g;\n\n/**\n * The package name of a BARE specifier (`zod`, `zod/v4` → `zod`; `@scope/pkg/sub` → `@scope/pkg`), or null for a\n * relative, absolute, URL or builtin specifier, which no install moves.\n */\nexport function packageNameOfBareSpecifier(specifier: string): string | null {\n if (specifier.length === 0 || specifier.startsWith('.') || isAbsolute(specifier) || specifier.startsWith('node:') || /^[a-z][a-z0-9+.-]*:/i.test(specifier)) {\n return null;\n }\n const segments = specifier.split('/');\n if (specifier.startsWith('@')) return segments.length >= 2 && segments[1] ? `${segments[0]}/${segments[1]}` : null;\n return segments[0] ?? null;\n}\n\n/** The unresolved bare package a failure text names, or null when it names none. */\nexport function findUnresolvedPackageImport(text: string): UnresolvedPackageImport | null {\n const plain = text.replace(ANSI_ESCAPE, '');\n const match = ESM_UNRESOLVED_PACKAGE.exec(plain) ?? CJS_UNRESOLVED_MODULE.exec(plain);\n if (!match) return null;\n const packageName = packageNameOfBareSpecifier(match[1] ?? '');\n const importerPath = (match[2] ?? '').trim();\n if (packageName === null || !isAbsolute(importerPath)) return null;\n return { packageName, importerPath };\n}\n\n/**\n * Whether `packageName` resolves from `importerPath` the way Node's resolver looks for it: the first\n * `node_modules/<name>/package.json` found walking up from the importer's directory. `existsSync` follows the symlink\n * pnpm links a package through, so a link whose target is being re-created reads as absent, which is exactly the gap.\n */\nexport function isPackageResolvableFrom(packageName: string, importerPath: string, exists: (path: string) => boolean = existsSync): boolean {\n let directory = dirname(importerPath);\n for (;;) {\n if (exists(join(directory, 'node_modules', packageName, 'package.json'))) return true;\n const parent = dirname(directory);\n if (parent === directory) return false;\n directory = parent;\n }\n}\n\n/**\n * Whether the importer's own package DECLARES `packageName`: the nearest `package.json` above it that has a `name` (a\n * `dist/esm/package.json` carrying only `\"type\"` is not a package boundary for this question).\n */\nexport function importerDeclaresPackage(packageName: string, importerPath: string, readText: (path: string) => string | null = readTextOrNull): boolean {\n let directory = dirname(importerPath);\n for (;;) {\n const text = readText(join(directory, 'package.json'));\n if (text !== null) {\n try {\n const manifest = JSON.parse(text) as Record<string, unknown>;\n if (typeof manifest.name === 'string') {\n return ['dependencies', 'devDependencies', 'peerDependencies', 'optionalDependencies'].some((field) => {\n const declared = manifest[field];\n return declared !== null && typeof declared === 'object' && Object.prototype.hasOwnProperty.call(declared, packageName);\n });\n }\n } catch {\n // An unreadable manifest is not a boundary; keep walking.\n }\n }\n const parent = dirname(directory);\n if (parent === directory) return false;\n directory = parent;\n }\n}\n\nfunction readTextOrNull(path: string): string | null {\n try {\n return readFileSync(path, 'utf8');\n } catch {\n return null;\n }\n}\n\nexport interface IntrospectionDependencyTreeGateOptions {\n /** The application root: where the #3552 install record and pnpm's `.modules.yaml` live. */\n readonly appRoot: string;\n readonly log?: (message: string, context?: Record<string, unknown>) => void;\n /** Test seams; production reads the record, the file system and the clock. */\n readonly readInstall?: () => DependencyInstallStatus;\n readonly readNodeModulesInstalledAtMs?: () => number | null;\n readonly isResolvable?: (unresolved: UnresolvedPackageImport) => boolean;\n readonly declares?: (unresolved: UnresolvedPackageImport) => boolean;\n readonly now?: () => number;\n readonly sleep?: (ms: number) => Promise<void>;\n readonly pollMs?: number;\n readonly settleCeilingMs?: number;\n}\n\n/** See the module comment. One per companion introspection service. */\nexport class IntrospectionDependencyTreeGate {\n private readonly readInstall: () => DependencyInstallStatus;\n private readonly readInstalledAtMs: () => number | null;\n private readonly isResolvable: (unresolved: UnresolvedPackageImport) => boolean;\n private readonly declares: (unresolved: UnresolvedPackageImport) => boolean;\n private readonly now: () => number;\n private readonly sleep: (ms: number) => Promise<void>;\n private readonly pollMs: number;\n private readonly settleCeilingMs: number;\n /** `<package>\\0<importer>` → the `.modules.yaml` time over which a wait for it already ran out. */\n private readonly exhausted = new Map<string, number | null>();\n\n public constructor(private readonly options: IntrospectionDependencyTreeGateOptions) {\n this.readInstall = options.readInstall ?? (() => classifyDependencyInstall(readDependencyInstallRecord(options.appRoot), Date.now()));\n this.readInstalledAtMs = options.readNodeModulesInstalledAtMs ?? (() => readNodeModulesInstalledAtMs(options.appRoot));\n this.isResolvable = options.isResolvable ?? ((unresolved) => isPackageResolvableFrom(unresolved.packageName, unresolved.importerPath));\n this.declares = options.declares ?? ((unresolved) => importerDeclaresPackage(unresolved.packageName, unresolved.importerPath));\n this.now = options.now ?? Date.now;\n this.sleep = options.sleep ?? ((ms) => new Promise((resolveSleep) => setTimeout(resolveSleep, ms)));\n this.pollMs = options.pollMs ?? DEPENDENCY_TREE_POLL_MS;\n this.settleCeilingMs = options.settleCeilingMs ?? DEPENDENCY_TREE_SETTLE_CEILING_MS;\n }\n\n /** Wait while a recorded install is in flight; returns how long it waited. Bounded by the record's deadline. */\n public async holdWhileInstallInFlight(): Promise<number> {\n const startedAtMs = this.now();\n let announced = false;\n while (this.readInstall().phase === LocalDevDependencyInstallPhase.IN_FLIGHT) {\n if (!announced) {\n announced = true;\n this.options.log?.('Introspection derivation held: a dependency install is re-creating node_modules', { appRoot: this.options.appRoot });\n }\n await this.sleep(this.pollMs);\n }\n return this.now() - startedAtMs;\n }\n\n /**\n * Judge a failed derivation's text (its error message and stderr). Waits only when the failure is a declared\n * package the resolver could not find; see the module comment for every case.\n */\n public async settleAfterFailure(failureText: string): Promise<DependencyTreeSettleOutcome> {\n const startedAtMs = this.now();\n const unresolved = findUnresolvedPackageImport(failureText);\n if (unresolved === null) return { verdict: DependencyTreeSettleVerdict.NOT_A_DEPENDENCY_FAILURE, waitedMs: 0 };\n if (!this.declares(unresolved)) return { verdict: DependencyTreeSettleVerdict.UNDECLARED_PACKAGE, unresolved, waitedMs: 0 };\n const memoryKey = `${unresolved.packageName}\\u0000${unresolved.importerPath}`;\n if (\n this.exhausted.has(memoryKey)\n && this.exhausted.get(memoryKey) === this.readInstalledAtMs()\n && this.readInstall().phase !== LocalDevDependencyInstallPhase.IN_FLIGHT\n && !this.isResolvable(unresolved)\n ) {\n return { verdict: DependencyTreeSettleVerdict.STILL_UNRESOLVED, unresolved, waitedMs: 0 };\n }\n for (;;) {\n const inFlight = this.readInstall().phase === LocalDevDependencyInstallPhase.IN_FLIGHT;\n if (!inFlight && this.isResolvable(unresolved)) {\n this.exhausted.delete(memoryKey);\n const settledAtMs = this.now();\n return { verdict: DependencyTreeSettleVerdict.SETTLED, unresolved, waitedMs: settledAtMs - startedAtMs, settledAtMs };\n }\n // A recorded install is bounded by its own deadline; only an unexplained gap is bounded by the ceiling.\n if (!inFlight && this.now() - startedAtMs >= this.settleCeilingMs) {\n this.exhausted.set(memoryKey, this.readInstalledAtMs());\n return { verdict: DependencyTreeSettleVerdict.STILL_UNRESOLVED, unresolved, waitedMs: this.now() - startedAtMs };\n }\n await this.sleep(this.pollMs);\n }\n }\n}\n"]}
@@ -88,6 +88,15 @@ export declare class IntrospectionWorkerPool {
88
88
  * relies on each worker exiting by itself when the companion exits, because its IPC channel closes.
89
89
  */
90
90
  shutdown(): void;
91
+ /**
92
+ * Retire every worker started before `instantMs` (#3703): an idle one now, a busy one as soon as its request settles.
93
+ *
94
+ * For a dependency tree that moved under the pool. A worker started before a `pnpm install` re-created the
95
+ * application's `node_modules` holds modules read from the old tree, and Node keeps a failed import failed for the
96
+ * life of the process, so a derivation that failed there would fail there again. The caller asks this once the tree
97
+ * has settled, so its retry, and every later request, runs in a process started after it.
98
+ */
99
+ retireWorkersStartedBefore(instantMs: number, reason: string): void;
91
100
  private acquire;
92
101
  private spawn;
93
102
  private onMessage;
@@ -1 +1 @@
1
- {"version":3,"file":"introspection-worker-pool.companion.d.ts","sourceRoot":"","sources":["../../../../../src/core/introspection/services/introspection-worker-pool.companion.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAIvD,OAAO,EAIL,KAAK,kCAAkC,EACvC,KAAK,kCAAkC,EACvC,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AAC;IACzC,QAAQ,CAAC,YAAY,EAAE,CAAC,OAAO,EAAE,SAAS,sBAAsB,EAAE,EAAE,gBAAgB,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;CACnH;AAED,qBAAa,uBAAuB;IAIf,OAAO,CAAC,QAAQ,CAAC,OAAO;IAH3C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAsB;IAC9C,OAAO,CAAC,YAAY,CAAK;gBAEW,OAAO,EAAE,8BAA8B;IAE3E,+DAA+D;IAC/D,IAAW,eAAe,IAAI,MAAM,CAEnC;IAED;;;;;OAKG;IACU,GAAG,CACd,gBAAgB,EAAE,MAAM,EACxB,OAAO,EAAE,kCAAkC,EAC3C,KAAK,CAAC,EAAE,wBAAwB,GAC/B,OAAO,CAAC,0BAA0B,CAAC;IA2DtC;;;OAGG;IACI,QAAQ,IAAI,IAAI;YAIT,OAAO;IA4CrB,OAAO,CAAC,KAAK;IA+Bb,OAAO,CAAC,SAAS;IAoDjB,OAAO,CAAC,OAAO;IAoBf,OAAO,CAAC,WAAW;IAMnB,OAAO,CAAC,MAAM;CAiCf"}
1
+ {"version":3,"file":"introspection-worker-pool.companion.d.ts","sourceRoot":"","sources":["../../../../../src/core/introspection/services/introspection-worker-pool.companion.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAIvD,OAAO,EAIL,KAAK,kCAAkC,EACvC,KAAK,kCAAkC,EACvC,KAAK,4BAA4B,EAElC,MAAM,0CAA0C,CAAC;AAClD,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,wCAAwC,CAAC;AAGrF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,MAAM,WAAW,8BAA8B;IAC7C,+FAA+F;IAC/F,QAAQ,CAAC,WAAW,EAAE,MAAM,YAAY,CAAC;IACzC,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,4CAA4C;IAC5C,QAA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,+DAA+D;IAC/D,IAAW,eAAe,IAAI,MAAM,CAEnC;IAED;;;;;OAKG;IACU,GAAG,CACd,gBAAgB,EAAE,MAAM,EACxB,OAAO,EAAE,kCAAkC,EAC3C,KAAK,CAAC,EAAE,wBAAwB,GAC/B,OAAO,CAAC,0BAA0B,CAAC;IA2DtC;;;OAGG;IACI,QAAQ,IAAI,IAAI;IAIvB;;;;;;;OAOG;IACI,0BAA0B,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI;YAQ5D,OAAO;IA4CrB,OAAO,CAAC,KAAK;IAgCb,OAAO,CAAC,SAAS;IAsDjB,OAAO,CAAC,OAAO;IAoBf,OAAO,CAAC,WAAW;IAMnB,OAAO,CAAC,MAAM;CAiCf"}
@@ -95,6 +95,24 @@ export class IntrospectionWorkerPool {
95
95
  for (const worker of [...this.workers])
96
96
  this.retire(worker, 'pool shut down');
97
97
  }
98
+ /**
99
+ * Retire every worker started before `instantMs` (#3703): an idle one now, a busy one as soon as its request settles.
100
+ *
101
+ * For a dependency tree that moved under the pool. A worker started before a `pnpm install` re-created the
102
+ * application's `node_modules` holds modules read from the old tree, and Node keeps a failed import failed for the
103
+ * life of the process, so a derivation that failed there would fail there again. The caller asks this once the tree
104
+ * has settled, so its retry, and every later request, runs in a process started after it.
105
+ */
106
+ retireWorkersStartedBefore(instantMs, reason) {
107
+ for (const worker of [...this.workers]) {
108
+ if (worker.startedAtMs >= instantMs)
109
+ continue;
110
+ if (worker.busy)
111
+ worker.retireAfterRequest = true;
112
+ else
113
+ this.retire(worker, reason);
114
+ }
115
+ }
98
116
  async acquire(sourceStateToken, reuse) {
99
117
  const claim = (worker) => {
100
118
  if (worker.idleTimer)
@@ -103,7 +121,7 @@ export class IntrospectionWorkerPool {
103
121
  worker.busy = true;
104
122
  return worker;
105
123
  };
106
- const idle = this.workers.find((worker) => !worker.busy && !worker.retiring && worker.sourceStateToken === sourceStateToken);
124
+ const idle = this.workers.find((worker) => !worker.busy && !worker.retiring && !worker.retireAfterRequest && worker.sourceStateToken === sourceStateToken);
107
125
  if (idle)
108
126
  return claim(idle);
109
127
  /*
@@ -114,7 +132,7 @@ export class IntrospectionWorkerPool {
114
132
  * requests never take one worker.
115
133
  */
116
134
  if (reuse?.sharedToken !== undefined) {
117
- for (const worker of this.workers.filter((candidate) => !candidate.busy && !candidate.retiring && candidate.sharedToken === reuse.sharedToken && !candidate.loadedUnknown)) {
135
+ for (const worker of this.workers.filter((candidate) => !candidate.busy && !candidate.retiring && candidate.sharedToken === reuse.sharedToken && !candidate.loadedUnknown && !candidate.retireAfterRequest)) {
118
136
  /*
119
137
  * Asked again, because the list is a snapshot and this loop awaits between candidates: another request may have
120
138
  * claimed (or retired) a worker the snapshot still names. Claiming it anyway put two requests on one worker, and the
@@ -153,6 +171,7 @@ export class IntrospectionWorkerPool {
153
171
  spawned.catch(() => undefined);
154
172
  const worker = {
155
173
  id, child, sourceStateToken, sharedToken, loaded: new Map(), loadedUnknown: false, spawned, pending: null, busy: true, idleTimer: null, served: 0, retiring: false,
174
+ startedAtMs: Date.now(), retireAfterRequest: false,
156
175
  };
157
176
  this.workers.push(worker);
158
177
  const capture = (stream) => (chunk) => {
@@ -224,7 +243,10 @@ export class IntrospectionWorkerPool {
224
243
  stderr: pending.stderr,
225
244
  ...(readSet === undefined ? {} : { readSet }),
226
245
  });
227
- if (!worker.retiring) {
246
+ if (worker.retireAfterRequest) {
247
+ this.retire(worker, 'started before the dependency tree moved');
248
+ }
249
+ else if (!worker.retiring) {
228
250
  worker.idleTimer = setTimeout(() => this.retire(worker, 'idle'), this.options.idleMs);
229
251
  worker.idleTimer.unref?.();
230
252
  }