@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.
- package/dist/esm/.tsbuildinfo +1 -1
- package/dist/esm/claude-cli/services/coding-agent-dispatch.companion.service.d.ts.map +1 -1
- package/dist/esm/claude-cli/services/coding-agent-dispatch.companion.service.js +8 -6
- package/dist/esm/claude-cli/services/coding-agent-dispatch.companion.service.js.map +1 -1
- package/dist/esm/companion-api/controllers/companion.controller.d.ts +6 -0
- package/dist/esm/companion-api/controllers/companion.controller.d.ts.map +1 -1
- package/dist/esm/companion-api/controllers/companion.controller.js +13 -1
- package/dist/esm/companion-api/controllers/companion.controller.js.map +1 -1
- package/dist/esm/core/introspection/resources/creation-home-projection.companion.d.ts.map +1 -1
- package/dist/esm/core/introspection/resources/creation-home-projection.companion.js +7 -0
- package/dist/esm/core/introspection/resources/creation-home-projection.companion.js.map +1 -1
- package/dist/esm/core/introspection/resources/launch-blockers.companion.d.ts +5 -1
- package/dist/esm/core/introspection/resources/launch-blockers.companion.d.ts.map +1 -1
- package/dist/esm/core/introspection/resources/launch-blockers.companion.js +37 -4
- package/dist/esm/core/introspection/resources/launch-blockers.companion.js.map +1 -1
- package/dist/esm/core/introspection/services/companion-introspection.companion.service.d.ts +14 -0
- package/dist/esm/core/introspection/services/companion-introspection.companion.service.d.ts.map +1 -1
- package/dist/esm/core/introspection/services/companion-introspection.companion.service.js +48 -0
- package/dist/esm/core/introspection/services/companion-introspection.companion.service.js.map +1 -1
- package/dist/esm/core/introspection/services/introspection-dependency-tree.companion.d.ts +128 -0
- package/dist/esm/core/introspection/services/introspection-dependency-tree.companion.d.ts.map +1 -0
- package/dist/esm/core/introspection/services/introspection-dependency-tree.companion.js +180 -0
- package/dist/esm/core/introspection/services/introspection-dependency-tree.companion.js.map +1 -0
- package/dist/esm/core/introspection/services/introspection-worker-pool.companion.d.ts +9 -0
- package/dist/esm/core/introspection/services/introspection-worker-pool.companion.d.ts.map +1 -1
- package/dist/esm/core/introspection/services/introspection-worker-pool.companion.js +25 -3
- package/dist/esm/core/introspection/services/introspection-worker-pool.companion.js.map +1 -1
- package/dist/esm/core/runtime/restart-drain.companion.d.ts +107 -0
- package/dist/esm/core/runtime/restart-drain.companion.d.ts.map +1 -0
- package/dist/esm/core/runtime/restart-drain.companion.js +237 -0
- package/dist/esm/core/runtime/restart-drain.companion.js.map +1 -0
- package/dist/esm/executions/services/companion-executions.companion.service.d.ts +18 -1
- package/dist/esm/executions/services/companion-executions.companion.service.d.ts.map +1 -1
- package/dist/esm/executions/services/companion-executions.companion.service.js +34 -8
- package/dist/esm/executions/services/companion-executions.companion.service.js.map +1 -1
- package/dist/esm/i18n/resources/workbenchSpecificationArtifacts.en.d.ts +40 -0
- package/dist/esm/i18n/resources/workbenchSpecificationArtifacts.en.d.ts.map +1 -1
- package/dist/esm/i18n/resources/workbenchSpecificationArtifacts.en.js +13 -0
- package/dist/esm/i18n/resources/workbenchSpecificationArtifacts.en.js.map +1 -1
- package/dist/esm/i18n/resources/workbenchSpecificationArtifacts.fr.d.ts +40 -0
- package/dist/esm/i18n/resources/workbenchSpecificationArtifacts.fr.d.ts.map +1 -1
- package/dist/esm/i18n/resources/workbenchSpecificationArtifacts.fr.js +40 -0
- package/dist/esm/i18n/resources/workbenchSpecificationArtifacts.fr.js.map +1 -1
- package/dist/esm/i18n/system_enums/application-creation.en.d.ts +5 -0
- package/dist/esm/i18n/system_enums/application-creation.en.d.ts.map +1 -1
- package/dist/esm/i18n/system_enums/application-creation.en.js +6 -0
- package/dist/esm/i18n/system_enums/application-creation.en.js.map +1 -1
- package/dist/esm/i18n/system_enums/application-creation.fr.d.ts +5 -0
- package/dist/esm/i18n/system_enums/application-creation.fr.d.ts.map +1 -1
- package/dist/esm/i18n/system_enums/application-creation.fr.js +5 -0
- package/dist/esm/i18n/system_enums/application-creation.fr.js.map +1 -1
- package/dist/esm/i18n/system_enums/workbench-build.en.d.ts +2 -0
- package/dist/esm/i18n/system_enums/workbench-build.en.d.ts.map +1 -1
- package/dist/esm/i18n/system_enums/workbench-build.en.js +2 -0
- package/dist/esm/i18n/system_enums/workbench-build.en.js.map +1 -1
- package/dist/esm/meta-workflows/models/application-coding-agent.actors-system.definitions.d.ts +5 -1
- package/dist/esm/meta-workflows/models/application-coding-agent.actors-system.definitions.d.ts.map +1 -1
- package/dist/esm/meta-workflows/models/application-coding-agent.actors-system.definitions.js +5 -1
- package/dist/esm/meta-workflows/models/application-coding-agent.actors-system.definitions.js.map +1 -1
- package/dist/esm/meta-workflows/models/playbook-run-record.models.d.ts +12 -0
- package/dist/esm/meta-workflows/models/playbook-run-record.models.d.ts.map +1 -1
- package/dist/esm/meta-workflows/models/playbook-run-record.models.js +9 -0
- package/dist/esm/meta-workflows/models/playbook-run-record.models.js.map +1 -1
- package/dist/esm/meta-workflows/services/application-build-dispatch.companion.service.d.ts +80 -4
- package/dist/esm/meta-workflows/services/application-build-dispatch.companion.service.d.ts.map +1 -1
- package/dist/esm/meta-workflows/services/application-build-dispatch.companion.service.js +235 -42
- package/dist/esm/meta-workflows/services/application-build-dispatch.companion.service.js.map +1 -1
- package/dist/esm/meta-workflows/services/application-build-follow-up-derivation.companion.d.ts +56 -3
- package/dist/esm/meta-workflows/services/application-build-follow-up-derivation.companion.d.ts.map +1 -1
- package/dist/esm/meta-workflows/services/application-build-follow-up-derivation.companion.js +182 -33
- package/dist/esm/meta-workflows/services/application-build-follow-up-derivation.companion.js.map +1 -1
- package/dist/esm/meta-workflows/services/application-build-generation-step.companion.service.d.ts +58 -0
- package/dist/esm/meta-workflows/services/application-build-generation-step.companion.service.d.ts.map +1 -1
- package/dist/esm/meta-workflows/services/application-build-generation-step.companion.service.js +116 -2
- package/dist/esm/meta-workflows/services/application-build-generation-step.companion.service.js.map +1 -1
- package/dist/esm/meta-workflows/services/application-build-task-coding-policy.companion.service.d.ts +12 -0
- package/dist/esm/meta-workflows/services/application-build-task-coding-policy.companion.service.d.ts.map +1 -1
- package/dist/esm/meta-workflows/services/application-build-task-coding-policy.companion.service.js +31 -7
- package/dist/esm/meta-workflows/services/application-build-task-coding-policy.companion.service.js.map +1 -1
- package/dist/esm/meta-workflows/services/creation-run-report.companion.service.d.ts +2 -2
- package/dist/esm/meta-workflows/services/creation-run-report.companion.service.d.ts.map +1 -1
- package/dist/esm/meta-workflows/services/creation-run-report.companion.service.js +10 -8
- package/dist/esm/meta-workflows/services/creation-run-report.companion.service.js.map +1 -1
- package/dist/esm/meta-workflows/services/playbook-run.companion.service.d.ts +67 -2
- package/dist/esm/meta-workflows/services/playbook-run.companion.service.d.ts.map +1 -1
- package/dist/esm/meta-workflows/services/playbook-run.companion.service.js +243 -48
- package/dist/esm/meta-workflows/services/playbook-run.companion.service.js.map +1 -1
- package/package.json +17 -17
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"introspection-worker-pool.companion.js","sourceRoot":"","sources":["../../../../../src/core/introspection/services/introspection-worker-pool.companion.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,OAAO,EAAE,kCAAkC,EAAE,MAAM,8CAA8C,CAAC;AAClG,OAAO,EACL,2CAA2C,EAC3C,0CAA0C,EAC1C,8BAA8B,GAK/B,MAAM,0CAA0C,CAAC;AAElD,OAAO,EAAE,yBAAyB,EAAE,MAAM,+CAA+C,CAAC;AA8C1F,oGAAoG;AACpG,MAAM,kCAAkC,GAAG,EAAE,GAAG,IAAI,CAAC;AAErD,0FAA0F;AAC1F,MAAM,mBAAmB,GAAG,KAAK,CAAC;AAElC,uEAAuE;AACvE,MAAM,4BAA4B,GAAG,IAAI,GAAG,CAAS,CAAC,SAAS,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC;AA6DtF,MAAM,OAAO,uBAAuB;IAIE;IAHnB,OAAO,GAAmB,EAAE,CAAC;IACtC,YAAY,GAAG,CAAC,CAAC;IAEzB,YAAoC,OAAuC;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,CAAC,KAAK,CAAC,CAAC;AAC3B,CAAC","sourcesContent":["import type { ChildProcess } from 'node:child_process';\nimport { randomUUID } from 'node:crypto';\n\nimport { CompanionIntrospectionResultSchema } from '../../../companion-api/companion-api.schemas';\nimport {\n COMPANION_INTROSPECTION_WORKER_REQUEST_KIND,\n INTROSPECTION_PARENT_TERMINATED_ERROR_NAME,\n recordIntrospectionPayloadText,\n type CompanionIntrospectionChildRequest,\n type CompanionIntrospectionErrorDetails,\n type CompanionIntrospectionResult,\n type CompanionIntrospectionWorkerRequest,\n} from '../models/companion-introspection.models';\nimport type { IntrospectionReadEntry } from '../subprocess/derivation-read-tracking';\nimport { parseIntrospectionReadSet } from './introspection-derivation-read-set.companion';\n\n/**\n * Re-use one introspection child for every derivation asked of the SAME source state (#3208).\n *\n * ## Why\n *\n * A derivation runs in a child process that imports the companion's handler graph, the engine and the\n * application before it does any work. Measured on app-creation-test-007 (15 resources, 96 landed build\n * tasks): each derivation cost 47-120 s of wall time, of which the behavior itself took 0.2-9.7 s, so\n * about 90 % of every recompile pass was children starting. A pass recompiles every derivation whose\n * inputs moved, and in a build wave nearly every task moves `specifications` or `shared-lib`, which every\n * derivation reads: thirty-odd child boots per pass, each ~1.2 GB and ~13 s of CPU, four at a time,\n * beside the coding agents. That was the host load the companion's event loop starved under.\n *\n * ## What is shared, and why that is safe\n *\n * A worker is bound to the SOURCE-STATE TOKEN the derivation state observed before compiling. Every\n * derivation compiled against that token is asked of a worker bound to it, so the application's modules\n * are imported once per state instead of once per question. A worker asked for a different token is\n * never reused: it is retired, and a fresh one imports the new state. That keeps the old guarantee — an\n * answer is computed from the tree the token names — while sharing the one thing that was pure overhead.\n *\n * Behaviors share a process, which a one-shot child never did. Two guards cover that:\n * - requests reach a worker one at a time, so no two behaviors interleave on one module state;\n * - a request that FAILS in a worker that already served another is asked once more of a fresh one-shot\n * child, and a success there is logged as a behavior that is not safe to share a process with. A real\n * failure (an unbuilt package, a refused input) fails again and is reported as before.\n *\n * ## What it costs\n *\n * At most {@link IntrospectionWorkerPoolOptions.maximumWorkers} live children, the same bound the\n * concurrency queue already put on running ones; an idle worker exits after\n * {@link IntrospectionWorkerPoolOptions.idleMs} so a quiet companion holds none.\n */\nexport interface IntrospectionWorkerPoolOptions {\n /** Start one worker child (argv, cwd and env are the caller's; `stdio` must include `ipc`). */\n readonly spawnWorker: () => ChildProcess;\n readonly maximumWorkers: number;\n /** An idle worker exits after this long. */\n readonly idleMs: number;\n /** One request may take this long before its worker is killed and the request fails as a timeout. */\n readonly requestTimeoutMs: number;\n readonly log: (message: string, context?: Record<string, unknown>) => void;\n}\n\n/** The longest stdout/stderr kept per request, so a chatty worker cannot grow the parent's heap. */\nconst MAXIMUM_CAPTURED_OUTPUT_CHARACTERS = 64 * 1024;\n\n/** How long a retired worker has to exit after its channel closes before it is killed. */\nconst RETIREMENT_GRACE_MS = 1_000;\n\n/** Signals that mean someone other than this pool stopped a worker. */\nconst EXTERNAL_TERMINATION_SIGNALS = new Set<string>(['SIGTERM', 'SIGINT', 'SIGHUP']);\n\ninterface PendingRequest {\n readonly requestId: string;\n readonly settle: (outcome: IntrospectionWorkerOutcome) => void;\n readonly timeout: NodeJS.Timeout;\n stdout: string;\n stderr: string;\n}\n\ninterface PooledWorker {\n readonly id: number;\n readonly child: ChildProcess;\n /** The token of the tree the worker last served: the one it was started for, or one it was kept for (#3452). */\n sourceStateToken: string;\n /** The shared component (framework roots, root manifests) it was started under; it is never kept across a change of it. */\n readonly sharedToken: string | undefined;\n /**\n * Every application file a request of this worker read, at its FIRST reading: the module code the worker holds for\n * the rest of its life (#3452). A worker is kept for a new token only while none of these moved.\n */\n readonly loaded: Map<string, IntrospectionReadEntry>;\n /** A request answered with no read set: what the worker holds is unknown, so it is never kept for another token. */\n loadedUnknown: boolean;\n readonly spawned: Promise<void>;\n pending: PendingRequest | null;\n /**\n * Taken by `acquire` synchronously and released when the request settles. `pending` alone is not\n * enough: it is set only once the worker has spawned, so two requests arriving together would both see\n * a fresh worker as free.\n */\n busy: boolean;\n idleTimer: NodeJS.Timeout | null;\n /** Requests this worker has answered; a failure after the first is retried in isolation. */\n served: number;\n retiring: boolean;\n}\n\n/** What one request through the pool came to. */\nexport type IntrospectionWorkerOutcome =\n | {\n readonly kind: 'result';\n readonly result: CompanionIntrospectionResult;\n readonly workerServedBefore: number;\n readonly stdout: string;\n readonly stderr: string;\n /** The files a successful request read (#3207); absent when the worker could not say. */\n readonly readSet?: readonly IntrospectionReadEntry[];\n }\n | { readonly kind: 'failure'; readonly error: CompanionIntrospectionErrorDetails; readonly workerServedBefore: number; readonly stdout: string; readonly stderr: string };\n\n/**\n * What lets an idle worker bound to another token serve a request (#3452): the shared component the request was\n * observed under, and a check that every file the worker loaded still reads as it did (the derivation state's read-set\n * checker, so one `stat` per path serves both).\n */\nexport interface IntrospectionWorkerReuse {\n readonly sharedToken: string | undefined;\n readonly stillMatches: (entries: readonly IntrospectionReadEntry[], observationToken: string) => Promise<boolean>;\n}\n\nexport class IntrospectionWorkerPool {\n private readonly workers: PooledWorker[] = [];\n private nextWorkerId = 1;\n\n public constructor(private readonly options: IntrospectionWorkerPoolOptions) {}\n\n /** Live workers, busy or idle. A diagnostic and a test pin. */\n public get liveWorkerCount(): number {\n return this.workers.length;\n }\n\n /**\n * Ask one derivation of a worker bound to `sourceStateToken`, starting one if none is idle.\n *\n * The caller bounds how many requests run at once (the service's concurrency queue), so there is always\n * an idle worker of this token or room for a new one once idle workers of other tokens are retired.\n */\n public async run(\n sourceStateToken: string,\n request: CompanionIntrospectionChildRequest,\n reuse?: IntrospectionWorkerReuse,\n ): Promise<IntrospectionWorkerOutcome> {\n const worker = await this.acquire(sourceStateToken, reuse);\n try {\n await worker.spawned;\n } catch (error) {\n this.retire(worker, 'spawn failed');\n const spawnError = error instanceof Error ? error : new Error(String(error));\n return { kind: 'failure', error: { message: spawnError.message, name: spawnError.name, stack: spawnError.stack }, workerServedBefore: 0, stdout: '', stderr: '' };\n }\n return new Promise<IntrospectionWorkerOutcome>((resolveOutcome) => {\n const requestId = randomUUID();\n const servedBefore = worker.served;\n let settled = false;\n if (worker.pending !== null) {\n /*\n * Never overwrite a pending request: the one replaced could then settle only through a slot that no longer names\n * it. `acquire` guarantees a worker holds one request at a time; should that ever fail again, both requests fail\n * here and the worker is retired, which is a visible failure the caller retries instead of a promise nobody settles.\n */\n this.failPending(worker, { message: 'Introspection worker was handed a second request while it held one.', name: 'CompanionIntrospectionWorkerProtocolError' });\n this.retire(worker, 'handed a second request', { kill: true });\n resolveOutcome({ kind: 'failure', error: { message: 'Introspection worker was handed a second request while it held one.', name: 'CompanionIntrospectionWorkerProtocolError' }, workerServedBefore: servedBefore, stdout: '', stderr: '' });\n return;\n }\n const pending: PendingRequest = {\n requestId,\n stdout: '',\n stderr: '',\n // Settles THIS request, not whatever the worker holds now: the deadline is the one guarantee a request has.\n timeout: setTimeout(() => {\n pending.settle({\n kind: 'failure',\n error: { message: `Companion introspection timed out after ${this.options.requestTimeoutMs}ms.`, name: 'CompanionIntrospectionTimeoutError' },\n workerServedBefore: 0,\n stdout: pending.stdout,\n stderr: pending.stderr,\n });\n this.retire(worker, 'request timed out', { kill: true });\n }, this.options.requestTimeoutMs),\n settle: (outcome) => {\n if (settled) return;\n settled = true;\n clearTimeout(pending.timeout);\n if (worker.pending === pending) worker.pending = null;\n worker.busy = false;\n resolveOutcome({ ...outcome, workerServedBefore: servedBefore });\n },\n };\n worker.pending = pending;\n const envelope: CompanionIntrospectionWorkerRequest = { kind: COMPANION_INTROSPECTION_WORKER_REQUEST_KIND, requestId, request };\n try {\n worker.child.send?.(envelope);\n } catch (error) {\n this.failPending(worker, { message: `Could not send the request to the introspection worker: ${String(error)}`, name: 'CompanionIntrospectionWorkerSendError' });\n this.retire(worker, 'send failed');\n }\n });\n }\n\n /**\n * Retire every worker. For a caller that wants them gone now (a test, a profiling run); a running companion\n * relies on each worker exiting by itself when the companion exits, because its IPC channel closes.\n */\n public shutdown(): void {\n for (const worker of [...this.workers]) this.retire(worker, 'pool shut down');\n }\n\n private async acquire(sourceStateToken: string, reuse: IntrospectionWorkerReuse | undefined): Promise<PooledWorker> {\n const claim = (worker: PooledWorker): PooledWorker => {\n if (worker.idleTimer) clearTimeout(worker.idleTimer);\n worker.idleTimer = null;\n worker.busy = true;\n return worker;\n };\n const idle = this.workers.find((worker) => !worker.busy && !worker.retiring && worker.sourceStateToken === sourceStateToken);\n if (idle) return claim(idle);\n /*\n * An idle worker of ANOTHER token is kept when nothing it holds moved (#3452): the same shared component, and every\n * file its requests loaded reading as it did. The token covers the whole tree, so any edit anywhere used to retire\n * every idle worker — measured on the reference runs, 246 of 313 workers retired as \"source state moved\" and 158\n * served one request, each paying a cold compile (median 9.5 s against 0.1 s warm). Claimed before the check, so two\n * requests never take one worker.\n */\n if (reuse?.sharedToken !== undefined) {\n for (const worker of this.workers.filter((candidate) => !candidate.busy && !candidate.retiring && candidate.sharedToken === reuse.sharedToken && !candidate.loadedUnknown)) {\n /*\n * Asked again, because the list is a snapshot and this loop awaits between candidates: another request may have\n * claimed (or retired) a worker the snapshot still names. Claiming it anyway put two requests on one worker, and the\n * second overwrote the first's pending slot, so the first never settled (reference run 42468505853: worker 167,\n * claimed twice within 200 ms, left `labelling-resource-specifications` in flight for good and froze the build).\n */\n if (worker.busy || worker.retiring) continue;\n claim(worker);\n if (await reuse.stillMatches([...worker.loaded.values()], sourceStateToken)) {\n this.options.log('Introspection worker kept for a moved tree it never read', { workerId: worker.id, sourceStateToken: abbreviate(sourceStateToken), loadedFiles: worker.loaded.size });\n worker.sourceStateToken = sourceStateToken;\n return worker;\n }\n worker.busy = false;\n this.retire(worker, 'a file it loaded moved');\n }\n }\n // No idle worker can serve this state: every idle one is of another and holds something that moved, so it is\n // retired at once, which also makes room. A busy worker is never taken; the caller's concurrency bound guarantees\n // room once the idle ones are gone.\n for (const worker of [...this.workers]) {\n if (!worker.busy) this.retire(worker, 'source state moved');\n }\n return this.spawn(sourceStateToken, reuse?.sharedToken);\n }\n\n private spawn(sourceStateToken: string, sharedToken: string | undefined): PooledWorker {\n const child = this.options.spawnWorker();\n const id = this.nextWorkerId++;\n const spawned = new Promise<void>((resolveSpawn, rejectSpawn) => {\n child.once('spawn', () => resolveSpawn());\n child.once('error', (error) => rejectSpawn(error));\n });\n // A spawn failure is reported through `run`; this keeps it from also being an unhandled rejection.\n spawned.catch(() => undefined);\n const worker: PooledWorker = {\n id, child, sourceStateToken, sharedToken, loaded: new Map(), loadedUnknown: false, spawned, pending: null, busy: true, idleTimer: null, served: 0, retiring: false,\n };\n this.workers.push(worker);\n\n const capture = (stream: 'stdout' | 'stderr') => (chunk: Buffer | string) => {\n const pending = worker.pending;\n if (!pending) return;\n pending[stream] = (pending[stream] + chunk.toString()).slice(-MAXIMUM_CAPTURED_OUTPUT_CHARACTERS);\n };\n child.stdout?.on('data', capture('stdout'));\n child.stderr?.on('data', capture('stderr'));\n child.on('message', (message: unknown) => this.onMessage(worker, message));\n child.on('error', (error) => {\n this.failPending(worker, { message: error.message, name: error.name, stack: error.stack });\n this.retire(worker, 'worker error');\n });\n child.on('close', (code, signal) => this.onClose(worker, code, signal));\n this.options.log('Introspection worker started', { workerId: id, sourceStateToken: abbreviate(sourceStateToken), liveWorkers: this.workers.length });\n return worker;\n }\n\n private onMessage(worker: PooledWorker, message: unknown): void {\n const pending = worker.pending;\n const requestId = message !== null && typeof message === 'object' ? (message as { requestId?: unknown }).requestId : undefined;\n if (!pending || requestId !== pending.requestId) {\n // An answer nobody is waiting for means the worker and this pool disagree about what it is doing.\n this.failPending(worker, { message: 'Introspection worker answered a request it was not asked.', name: 'CompanionIntrospectionWorkerProtocolError' });\n this.retire(worker, 'protocol mismatch');\n return;\n }\n // A success's data arrives as text (#3452): parsed once here, and the text kept beside the value for the change check.\n const dataJson = (message as { dataJson?: unknown }).dataJson;\n let rawResult = (message as { result?: unknown }).result;\n let data: unknown;\n if (typeof dataJson === 'string' && rawResult !== null && typeof rawResult === 'object') {\n try {\n data = JSON.parse(dataJson);\n } catch {\n this.failPending(worker, { message: 'Introspection worker returned unreadable result data.', name: 'CompanionIntrospectionWorkerProtocolError' });\n this.retire(worker, 'invalid result');\n return;\n }\n rawResult = { ...(rawResult as Record<string, unknown>), data };\n }\n const parsed = CompanionIntrospectionResultSchema.safeParse(rawResult);\n if (!parsed.success) {\n this.failPending(worker, { message: `Introspection worker returned an invalid result: ${parsed.error.message}`, name: 'CompanionIntrospectionWorkerProtocolError' });\n this.retire(worker, 'invalid result');\n return;\n }\n worker.served += 1;\n if (typeof dataJson === 'string' && parsed.data.success) recordIntrospectionPayloadText(parsed.data.data, dataJson);\n const readSet = parseIntrospectionReadSet((message as { readSet?: unknown }).readSet);\n // What the worker now holds: each file at its first reading, which is the code it keeps (#3452). That is every file\n // the request LOADED, which a behavior ignoring the families reports beside its narrower `readSet` (review F4).\n const rawLoaded = (message as { loadedReadSet?: unknown }).loadedReadSet;\n const loaded = rawLoaded === undefined ? readSet : parseIntrospectionReadSet(rawLoaded);\n if (loaded === undefined) worker.loadedUnknown = true;\n else for (const entry of loaded) if (!worker.loaded.has(entry.path)) worker.loaded.set(entry.path, entry);\n pending.settle({\n kind: 'result',\n result: parsed.data as CompanionIntrospectionResult,\n workerServedBefore: 0,\n stdout: pending.stdout,\n stderr: pending.stderr,\n ...(readSet === undefined ? {} : { readSet }),\n });\n if (!worker.retiring) {\n worker.idleTimer = setTimeout(() => this.retire(worker, 'idle'), this.options.idleMs);\n worker.idleTimer.unref?.();\n }\n }\n\n private onClose(worker: PooledWorker, code: number | null, signal: NodeJS.Signals | null): void {\n const index = this.workers.indexOf(worker);\n if (index !== -1) this.workers.splice(index, 1);\n if (worker.idleTimer) clearTimeout(worker.idleTimer);\n if (!worker.pending) return;\n // Nobody here asked this worker to stop while it held a request, so a termination signal came from\n // outside: the companion itself is stopping (see `wasTerminatedFromOutside` for the one-shot twin).\n const external = !worker.retiring && signal !== null && EXTERNAL_TERMINATION_SIGNALS.has(signal);\n const output = describeOutput(worker.pending);\n this.failPending(worker, external\n ? {\n message: `Companion introspection was terminated by ${signal} that this service did not send — the companion process itself is stopping, so the derivation was cut short rather than failing. Re-run it once the companion is ready.`,\n name: INTROSPECTION_PARENT_TERMINATED_ERROR_NAME,\n }\n : {\n message: `Companion introspection worker exited before answering (code=${code ?? 'null'}, signal=${signal ?? 'null'})${output ? ` — ${output}` : ''}.`,\n name: 'CompanionIntrospectionSubprocessExitError',\n });\n }\n\n private failPending(worker: PooledWorker, error: CompanionIntrospectionErrorDetails): void {\n const pending = worker.pending;\n if (!pending) return;\n pending.settle({ kind: 'failure', error, workerServedBefore: 0, stdout: pending.stdout, stderr: pending.stderr });\n }\n\n private retire(worker: PooledWorker, reason: string, options: { readonly kill?: boolean } = {}): void {\n if (worker.retiring) return;\n worker.retiring = true;\n if (worker.idleTimer) clearTimeout(worker.idleTimer);\n worker.idleTimer = null;\n const index = this.workers.indexOf(worker);\n if (index !== -1) this.workers.splice(index, 1);\n this.options.log('Introspection worker retired', { workerId: worker.id, reason, served: worker.served, liveWorkers: this.workers.length });\n // Closing the channel is the worker's signal to exit (it exits 0 on `disconnect`). A hung worker —\n // one retired over a timeout — cannot run that handler, so it is signalled at once; either way one\n // that is still there after the grace period is killed.\n try {\n if (worker.child.connected) worker.child.disconnect?.();\n } catch {\n // Already disconnected.\n }\n if (options.kill === true) {\n try {\n worker.child.kill('SIGTERM');\n } catch {\n // Already gone.\n }\n }\n const kill = setTimeout(() => {\n try {\n worker.child.kill('SIGKILL');\n } catch {\n // Already gone.\n }\n }, RETIREMENT_GRACE_MS);\n kill.unref?.();\n worker.child.once('close', () => clearTimeout(kill));\n }\n}\n\nfunction abbreviate(token: string): string {\n return token.length <= 16 ? token : `${token.slice(0, 16)}…`;\n}\n\nfunction describeOutput(pending: PendingRequest): string {\n const parts = [\n ...(pending.stdout.trim() ? [`stdout: ${pending.stdout.trim()}`] : []),\n ...(pending.stderr.trim() ? [`stderr: ${pending.stderr.trim()}`] : []),\n ];\n return parts.join(' | ');\n}\n"]}
|
|
1
|
+
{"version":3,"file":"introspection-worker-pool.companion.js","sourceRoot":"","sources":["../../../../../src/core/introspection/services/introspection-worker-pool.companion.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,OAAO,EAAE,kCAAkC,EAAE,MAAM,8CAA8C,CAAC;AAClG,OAAO,EACL,2CAA2C,EAC3C,0CAA0C,EAC1C,8BAA8B,GAK/B,MAAM,0CAA0C,CAAC;AAElD,OAAO,EAAE,yBAAyB,EAAE,MAAM,+CAA+C,CAAC;AA8C1F,oGAAoG;AACpG,MAAM,kCAAkC,GAAG,EAAE,GAAG,IAAI,CAAC;AAErD,0FAA0F;AAC1F,MAAM,mBAAmB,GAAG,KAAK,CAAC;AAElC,uEAAuE;AACvE,MAAM,4BAA4B,GAAG,IAAI,GAAG,CAAS,CAAC,SAAS,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC;AAiEtF,MAAM,OAAO,uBAAuB;IAIE;IAHnB,OAAO,GAAmB,EAAE,CAAC;IACtC,YAAY,GAAG,CAAC,CAAC;IAEzB,YAAoC,OAAuC;QAAvC,YAAO,GAAP,OAAO,CAAgC;IAAG,CAAC;IAE/E,+DAA+D;IAC/D,IAAW,eAAe;QACxB,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC;IAC7B,CAAC;IAED;;;;;OAKG;IACI,KAAK,CAAC,GAAG,CACd,gBAAwB,EACxB,OAA2C,EAC3C,KAAgC;QAEhC,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,gBAAgB,EAAE,KAAK,CAAC,CAAC;QAC3D,IAAI,CAAC;YACH,MAAM,MAAM,CAAC,OAAO,CAAC;QACvB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;YACpC,MAAM,UAAU,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,C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I,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;KACvE,CAAC;IACF,OAAO,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAC3B,CAAC","sourcesContent":["import type { ChildProcess } from 'node:child_process';\nimport { randomUUID } from 'node:crypto';\n\nimport { CompanionIntrospectionResultSchema } from '../../../companion-api/companion-api.schemas';\nimport {\n COMPANION_INTROSPECTION_WORKER_REQUEST_KIND,\n INTROSPECTION_PARENT_TERMINATED_ERROR_NAME,\n recordIntrospectionPayloadText,\n type CompanionIntrospectionChildRequest,\n type CompanionIntrospectionErrorDetails,\n type CompanionIntrospectionResult,\n type CompanionIntrospectionWorkerRequest,\n} from '../models/companion-introspection.models';\nimport type { IntrospectionReadEntry } from '../subprocess/derivation-read-tracking';\nimport { parseIntrospectionReadSet } from './introspection-derivation-read-set.companion';\n\n/**\n * Re-use one introspection child for every derivation asked of the SAME source state (#3208).\n *\n * ## Why\n *\n * A derivation runs in a child process that imports the companion's handler graph, the engine and the\n * application before it does any work. Measured on app-creation-test-007 (15 resources, 96 landed build\n * tasks): each derivation cost 47-120 s of wall time, of which the behavior itself took 0.2-9.7 s, so\n * about 90 % of every recompile pass was children starting. A pass recompiles every derivation whose\n * inputs moved, and in a build wave nearly every task moves `specifications` or `shared-lib`, which every\n * derivation reads: thirty-odd child boots per pass, each ~1.2 GB and ~13 s of CPU, four at a time,\n * beside the coding agents. That was the host load the companion's event loop starved under.\n *\n * ## What is shared, and why that is safe\n *\n * A worker is bound to the SOURCE-STATE TOKEN the derivation state observed before compiling. Every\n * derivation compiled against that token is asked of a worker bound to it, so the application's modules\n * are imported once per state instead of once per question. A worker asked for a different token is\n * never reused: it is retired, and a fresh one imports the new state. That keeps the old guarantee — an\n * answer is computed from the tree the token names — while sharing the one thing that was pure overhead.\n *\n * Behaviors share a process, which a one-shot child never did. Two guards cover that:\n * - requests reach a worker one at a time, so no two behaviors interleave on one module state;\n * - a request that FAILS in a worker that already served another is asked once more of a fresh one-shot\n * child, and a success there is logged as a behavior that is not safe to share a process with. A real\n * failure (an unbuilt package, a refused input) fails again and is reported as before.\n *\n * ## What it costs\n *\n * At most {@link IntrospectionWorkerPoolOptions.maximumWorkers} live children, the same bound the\n * concurrency queue already put on running ones; an idle worker exits after\n * {@link IntrospectionWorkerPoolOptions.idleMs} so a quiet companion holds none.\n */\nexport interface IntrospectionWorkerPoolOptions {\n /** Start one worker child (argv, cwd and env are the caller's; `stdio` must include `ipc`). */\n readonly spawnWorker: () => ChildProcess;\n readonly maximumWorkers: number;\n /** An idle worker exits after this long. */\n readonly idleMs: number;\n /** One request may take this long before its worker is killed and the request fails as a timeout. */\n readonly requestTimeoutMs: number;\n readonly log: (message: string, context?: Record<string, unknown>) => void;\n}\n\n/** The longest stdout/stderr kept per request, so a chatty worker cannot grow the parent's heap. */\nconst MAXIMUM_CAPTURED_OUTPUT_CHARACTERS = 64 * 1024;\n\n/** How long a retired worker has to exit after its channel closes before it is killed. */\nconst RETIREMENT_GRACE_MS = 1_000;\n\n/** Signals that mean someone other than this pool stopped a worker. */\nconst EXTERNAL_TERMINATION_SIGNALS = new Set<string>(['SIGTERM', 'SIGINT', 'SIGHUP']);\n\ninterface PendingRequest {\n readonly requestId: string;\n readonly settle: (outcome: IntrospectionWorkerOutcome) => void;\n readonly timeout: NodeJS.Timeout;\n stdout: string;\n stderr: string;\n}\n\ninterface PooledWorker {\n readonly id: number;\n readonly child: ChildProcess;\n /** The token of the tree the worker last served: the one it was started for, or one it was kept for (#3452). */\n sourceStateToken: string;\n /** The shared component (framework roots, root manifests) it was started under; it is never kept across a change of it. */\n readonly sharedToken: string | undefined;\n /**\n * Every application file a request of this worker read, at its FIRST reading: the module code the worker holds for\n * the rest of its life (#3452). A worker is kept for a new token only while none of these moved.\n */\n readonly loaded: Map<string, IntrospectionReadEntry>;\n /** A request answered with no read set: what the worker holds is unknown, so it is never kept for another token. */\n loadedUnknown: boolean;\n readonly spawned: Promise<void>;\n pending: PendingRequest | null;\n /**\n * Taken by `acquire` synchronously and released when the request settles. `pending` alone is not\n * enough: it is set only once the worker has spawned, so two requests arriving together would both see\n * a fresh worker as free.\n */\n busy: boolean;\n idleTimer: NodeJS.Timeout | null;\n /** Requests this worker has answered; a failure after the first is retried in isolation. */\n served: number;\n retiring: boolean;\n /** When the pool started this worker: what {@link IntrospectionWorkerPool.retireWorkersStartedBefore} compares. */\n readonly startedAtMs: number;\n /** Set on a busy worker that must not serve again: it is retired as soon as its request settles (#3703). */\n retireAfterRequest: boolean;\n}\n\n/** What one request through the pool came to. */\nexport type IntrospectionWorkerOutcome =\n | {\n readonly kind: 'result';\n readonly result: CompanionIntrospectionResult;\n readonly workerServedBefore: number;\n readonly stdout: string;\n readonly stderr: string;\n /** The files a successful request read (#3207); absent when the worker could not say. */\n readonly readSet?: readonly IntrospectionReadEntry[];\n }\n | { readonly kind: 'failure'; readonly error: CompanionIntrospectionErrorDetails; readonly workerServedBefore: number; readonly stdout: string; readonly stderr: string };\n\n/**\n * What lets an idle worker bound to another token serve a request (#3452): the shared component the request was\n * observed under, and a check that every file the worker loaded still reads as it did (the derivation state's read-set\n * checker, so one `stat` per path serves both).\n */\nexport interface IntrospectionWorkerReuse {\n readonly sharedToken: string | undefined;\n readonly stillMatches: (entries: readonly IntrospectionReadEntry[], observationToken: string) => Promise<boolean>;\n}\n\nexport class IntrospectionWorkerPool {\n private readonly workers: PooledWorker[] = [];\n private nextWorkerId = 1;\n\n public constructor(private readonly options: IntrospectionWorkerPoolOptions) {}\n\n /** Live workers, busy or idle. A diagnostic and a test pin. */\n public get liveWorkerCount(): number {\n return this.workers.length;\n }\n\n /**\n * Ask one derivation of a worker bound to `sourceStateToken`, starting one if none is idle.\n *\n * The caller bounds how many requests run at once (the service's concurrency queue), so there is always\n * an idle worker of this token or room for a new one once idle workers of other tokens are retired.\n */\n public async run(\n sourceStateToken: string,\n request: CompanionIntrospectionChildRequest,\n reuse?: IntrospectionWorkerReuse,\n ): Promise<IntrospectionWorkerOutcome> {\n const worker = await this.acquire(sourceStateToken, reuse);\n try {\n await worker.spawned;\n } catch (error) {\n this.retire(worker, 'spawn failed');\n const spawnError = error instanceof Error ? error : new Error(String(error));\n return { kind: 'failure', error: { message: spawnError.message, name: spawnError.name, stack: spawnError.stack }, workerServedBefore: 0, stdout: '', stderr: '' };\n }\n return new Promise<IntrospectionWorkerOutcome>((resolveOutcome) => {\n const requestId = randomUUID();\n const servedBefore = worker.served;\n let settled = false;\n if (worker.pending !== null) {\n /*\n * Never overwrite a pending request: the one replaced could then settle only through a slot that no longer names\n * it. `acquire` guarantees a worker holds one request at a time; should that ever fail again, both requests fail\n * here and the worker is retired, which is a visible failure the caller retries instead of a promise nobody settles.\n */\n this.failPending(worker, { message: 'Introspection worker was handed a second request while it held one.', name: 'CompanionIntrospectionWorkerProtocolError' });\n this.retire(worker, 'handed a second request', { kill: true });\n resolveOutcome({ kind: 'failure', error: { message: 'Introspection worker was handed a second request while it held one.', name: 'CompanionIntrospectionWorkerProtocolError' }, workerServedBefore: servedBefore, stdout: '', stderr: '' });\n return;\n }\n const pending: PendingRequest = {\n requestId,\n stdout: '',\n stderr: '',\n // Settles THIS request, not whatever the worker holds now: the deadline is the one guarantee a request has.\n timeout: setTimeout(() => {\n pending.settle({\n kind: 'failure',\n error: { message: `Companion introspection timed out after ${this.options.requestTimeoutMs}ms.`, name: 'CompanionIntrospectionTimeoutError' },\n workerServedBefore: 0,\n stdout: pending.stdout,\n stderr: pending.stderr,\n });\n this.retire(worker, 'request timed out', { kill: true });\n }, this.options.requestTimeoutMs),\n settle: (outcome) => {\n if (settled) return;\n settled = true;\n clearTimeout(pending.timeout);\n if (worker.pending === pending) worker.pending = null;\n worker.busy = false;\n resolveOutcome({ ...outcome, workerServedBefore: servedBefore });\n },\n };\n worker.pending = pending;\n const envelope: CompanionIntrospectionWorkerRequest = { kind: COMPANION_INTROSPECTION_WORKER_REQUEST_KIND, requestId, request };\n try {\n worker.child.send?.(envelope);\n } catch (error) {\n this.failPending(worker, { message: `Could not send the request to the introspection worker: ${String(error)}`, name: 'CompanionIntrospectionWorkerSendError' });\n this.retire(worker, 'send failed');\n }\n });\n }\n\n /**\n * Retire every worker. For a caller that wants them gone now (a test, a profiling run); a running companion\n * relies on each worker exiting by itself when the companion exits, because its IPC channel closes.\n */\n public shutdown(): void {\n for (const worker of [...this.workers]) this.retire(worker, 'pool shut down');\n }\n\n /**\n * Retire every worker started before `instantMs` (#3703): an idle one now, a busy one as soon as its request settles.\n *\n * For a dependency tree that moved under the pool. A worker started before a `pnpm install` re-created the\n * application's `node_modules` holds modules read from the old tree, and Node keeps a failed import failed for the\n * life of the process, so a derivation that failed there would fail there again. The caller asks this once the tree\n * has settled, so its retry, and every later request, runs in a process started after it.\n */\n public retireWorkersStartedBefore(instantMs: number, reason: string): void {\n for (const worker of [...this.workers]) {\n if (worker.startedAtMs >= instantMs) continue;\n if (worker.busy) worker.retireAfterRequest = true;\n else this.retire(worker, reason);\n }\n }\n\n private async acquire(sourceStateToken: string, reuse: IntrospectionWorkerReuse | undefined): Promise<PooledWorker> {\n const claim = (worker: PooledWorker): PooledWorker => {\n if (worker.idleTimer) clearTimeout(worker.idleTimer);\n worker.idleTimer = null;\n worker.busy = true;\n return worker;\n };\n const idle = this.workers.find((worker) => !worker.busy && !worker.retiring && !worker.retireAfterRequest && worker.sourceStateToken === sourceStateToken);\n if (idle) return claim(idle);\n /*\n * An idle worker of ANOTHER token is kept when nothing it holds moved (#3452): the same shared component, and every\n * file its requests loaded reading as it did. The token covers the whole tree, so any edit anywhere used to retire\n * every idle worker — measured on the reference runs, 246 of 313 workers retired as \"source state moved\" and 158\n * served one request, each paying a cold compile (median 9.5 s against 0.1 s warm). Claimed before the check, so two\n * requests never take one worker.\n */\n if (reuse?.sharedToken !== undefined) {\n for (const worker of this.workers.filter((candidate) => !candidate.busy && !candidate.retiring && candidate.sharedToken === reuse.sharedToken && !candidate.loadedUnknown && !candidate.retireAfterRequest)) {\n /*\n * Asked again, because the list is a snapshot and this loop awaits between candidates: another request may have\n * claimed (or retired) a worker the snapshot still names. Claiming it anyway put two requests on one worker, and the\n * second overwrote the first's pending slot, so the first never settled (reference run 42468505853: worker 167,\n * claimed twice within 200 ms, left `labelling-resource-specifications` in flight for good and froze the build).\n */\n if (worker.busy || worker.retiring) continue;\n claim(worker);\n if (await reuse.stillMatches([...worker.loaded.values()], sourceStateToken)) {\n this.options.log('Introspection worker kept for a moved tree it never read', { workerId: worker.id, sourceStateToken: abbreviate(sourceStateToken), loadedFiles: worker.loaded.size });\n worker.sourceStateToken = sourceStateToken;\n return worker;\n }\n worker.busy = false;\n this.retire(worker, 'a file it loaded moved');\n }\n }\n // No idle worker can serve this state: every idle one is of another and holds something that moved, so it is\n // retired at once, which also makes room. A busy worker is never taken; the caller's concurrency bound guarantees\n // room once the idle ones are gone.\n for (const worker of [...this.workers]) {\n if (!worker.busy) this.retire(worker, 'source state moved');\n }\n return this.spawn(sourceStateToken, reuse?.sharedToken);\n }\n\n private spawn(sourceStateToken: string, sharedToken: string | undefined): PooledWorker {\n const child = this.options.spawnWorker();\n const id = this.nextWorkerId++;\n const spawned = new Promise<void>((resolveSpawn, rejectSpawn) => {\n child.once('spawn', () => resolveSpawn());\n child.once('error', (error) => rejectSpawn(error));\n });\n // A spawn failure is reported through `run`; this keeps it from also being an unhandled rejection.\n spawned.catch(() => undefined);\n const worker: PooledWorker = {\n id, child, sourceStateToken, sharedToken, loaded: new Map(), loadedUnknown: false, spawned, pending: null, busy: true, idleTimer: null, served: 0, retiring: false,\n startedAtMs: Date.now(), retireAfterRequest: false,\n };\n this.workers.push(worker);\n\n const capture = (stream: 'stdout' | 'stderr') => (chunk: Buffer | string) => {\n const pending = worker.pending;\n if (!pending) return;\n pending[stream] = (pending[stream] + chunk.toString()).slice(-MAXIMUM_CAPTURED_OUTPUT_CHARACTERS);\n };\n child.stdout?.on('data', capture('stdout'));\n child.stderr?.on('data', capture('stderr'));\n child.on('message', (message: unknown) => this.onMessage(worker, message));\n child.on('error', (error) => {\n this.failPending(worker, { message: error.message, name: error.name, stack: error.stack });\n this.retire(worker, 'worker error');\n });\n child.on('close', (code, signal) => this.onClose(worker, code, signal));\n this.options.log('Introspection worker started', { workerId: id, sourceStateToken: abbreviate(sourceStateToken), liveWorkers: this.workers.length });\n return worker;\n }\n\n private onMessage(worker: PooledWorker, message: unknown): void {\n const pending = worker.pending;\n const requestId = message !== null && typeof message === 'object' ? (message as { requestId?: unknown }).requestId : undefined;\n if (!pending || requestId !== pending.requestId) {\n // An answer nobody is waiting for means the worker and this pool disagree about what it is doing.\n this.failPending(worker, { message: 'Introspection worker answered a request it was not asked.', name: 'CompanionIntrospectionWorkerProtocolError' });\n this.retire(worker, 'protocol mismatch');\n return;\n }\n // A success's data arrives as text (#3452): parsed once here, and the text kept beside the value for the change check.\n const dataJson = (message as { dataJson?: unknown }).dataJson;\n let rawResult = (message as { result?: unknown }).result;\n let data: unknown;\n if (typeof dataJson === 'string' && rawResult !== null && typeof rawResult === 'object') {\n try {\n data = JSON.parse(dataJson);\n } catch {\n this.failPending(worker, { message: 'Introspection worker returned unreadable result data.', name: 'CompanionIntrospectionWorkerProtocolError' });\n this.retire(worker, 'invalid result');\n return;\n }\n rawResult = { ...(rawResult as Record<string, unknown>), data };\n }\n const parsed = CompanionIntrospectionResultSchema.safeParse(rawResult);\n if (!parsed.success) {\n this.failPending(worker, { message: `Introspection worker returned an invalid result: ${parsed.error.message}`, name: 'CompanionIntrospectionWorkerProtocolError' });\n this.retire(worker, 'invalid result');\n return;\n }\n worker.served += 1;\n if (typeof dataJson === 'string' && parsed.data.success) recordIntrospectionPayloadText(parsed.data.data, dataJson);\n const readSet = parseIntrospectionReadSet((message as { readSet?: unknown }).readSet);\n // What the worker now holds: each file at its first reading, which is the code it keeps (#3452). That is every file\n // the request LOADED, which a behavior ignoring the families reports beside its narrower `readSet` (review F4).\n const rawLoaded = (message as { loadedReadSet?: unknown }).loadedReadSet;\n const loaded = rawLoaded === undefined ? readSet : parseIntrospectionReadSet(rawLoaded);\n if (loaded === undefined) worker.loadedUnknown = true;\n else for (const entry of loaded) if (!worker.loaded.has(entry.path)) worker.loaded.set(entry.path, entry);\n pending.settle({\n kind: 'result',\n result: parsed.data as CompanionIntrospectionResult,\n workerServedBefore: 0,\n stdout: pending.stdout,\n stderr: pending.stderr,\n ...(readSet === undefined ? {} : { readSet }),\n });\n if (worker.retireAfterRequest) {\n this.retire(worker, 'started before the dependency tree moved');\n } else if (!worker.retiring) {\n worker.idleTimer = setTimeout(() => this.retire(worker, 'idle'), this.options.idleMs);\n worker.idleTimer.unref?.();\n }\n }\n\n private onClose(worker: PooledWorker, code: number | null, signal: NodeJS.Signals | null): void {\n const index = this.workers.indexOf(worker);\n if (index !== -1) this.workers.splice(index, 1);\n if (worker.idleTimer) clearTimeout(worker.idleTimer);\n if (!worker.pending) return;\n // Nobody here asked this worker to stop while it held a request, so a termination signal came from\n // outside: the companion itself is stopping (see `wasTerminatedFromOutside` for the one-shot twin).\n const external = !worker.retiring && signal !== null && EXTERNAL_TERMINATION_SIGNALS.has(signal);\n const output = describeOutput(worker.pending);\n this.failPending(worker, external\n ? {\n message: `Companion introspection was terminated by ${signal} that this service did not send — the companion process itself is stopping, so the derivation was cut short rather than failing. Re-run it once the companion is ready.`,\n name: INTROSPECTION_PARENT_TERMINATED_ERROR_NAME,\n }\n : {\n message: `Companion introspection worker exited before answering (code=${code ?? 'null'}, signal=${signal ?? 'null'})${output ? ` — ${output}` : ''}.`,\n name: 'CompanionIntrospectionSubprocessExitError',\n });\n }\n\n private failPending(worker: PooledWorker, error: CompanionIntrospectionErrorDetails): void {\n const pending = worker.pending;\n if (!pending) return;\n pending.settle({ kind: 'failure', error, workerServedBefore: 0, stdout: pending.stdout, stderr: pending.stderr });\n }\n\n private retire(worker: PooledWorker, reason: string, options: { readonly kill?: boolean } = {}): void {\n if (worker.retiring) return;\n worker.retiring = true;\n if (worker.idleTimer) clearTimeout(worker.idleTimer);\n worker.idleTimer = null;\n const index = this.workers.indexOf(worker);\n if (index !== -1) this.workers.splice(index, 1);\n this.options.log('Introspection worker retired', { workerId: worker.id, reason, served: worker.served, liveWorkers: this.workers.length });\n // Closing the channel is the worker's signal to exit (it exits 0 on `disconnect`). A hung worker —\n // one retired over a timeout — cannot run that handler, so it is signalled at once; either way one\n // that is still there after the grace period is killed.\n try {\n if (worker.child.connected) worker.child.disconnect?.();\n } catch {\n // Already disconnected.\n }\n if (options.kill === true) {\n try {\n worker.child.kill('SIGTERM');\n } catch {\n // Already gone.\n }\n }\n const kill = setTimeout(() => {\n try {\n worker.child.kill('SIGKILL');\n } catch {\n // Already gone.\n }\n }, RETIREMENT_GRACE_MS);\n kill.unref?.();\n worker.child.once('close', () => clearTimeout(kill));\n }\n}\n\nfunction abbreviate(token: string): string {\n return token.length <= 16 ? token : `${token.slice(0, 16)}…`;\n}\n\nfunction describeOutput(pending: PendingRequest): string {\n const parts = [\n ...(pending.stdout.trim() ? [`stdout: ${pending.stdout.trim()}`] : []),\n ...(pending.stderr.trim() ? [`stderr: ${pending.stderr.trim()}`] : []),\n ];\n return parts.join(' | ');\n}\n"]}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Drain before a held restart (#3204; #265's first candidate shape, never built until now).
|
|
3
|
+
*
|
|
4
|
+
* `wildo local dev` runs the companion under `runtime-supervisor.mjs`, which HOLDS a restart (a dependency install, an
|
|
5
|
+
* engine rebuild) while work is in flight, because the restart kills the companion's process tree. During an unattended
|
|
6
|
+
* build a playbook run is always in flight, so the hold only ever ended at its ceiling (`HOLD_EXCEEDED`, 65 min), which
|
|
7
|
+
* then killed the wave's live coding runs: reference run 43237839187 lost nine at 15:43. Nothing told the companion a
|
|
8
|
+
* restart was waiting, so it kept starting work.
|
|
9
|
+
*
|
|
10
|
+
* Now the supervisor publishes the held restart in its observation, and this module answers three things for the rest of
|
|
11
|
+
* the companion:
|
|
12
|
+
* - {@link CompanionRestartDrain.isRestartHeld}: the build wave stops filling (`ApplicationBuildWaveStop.RESTART_PENDING`);
|
|
13
|
+
* - {@link CompanionRestartDrain.awaitRestartWindow}: the creation loop and every choreography wait at the TOP of each
|
|
14
|
+
* round, before reading the tree or asking a model, until the restart comes (the process ends) or the hold is withdrawn;
|
|
15
|
+
* - when nothing is BUSY, the companion writes its drained marker, `{ pid, at }`, every few seconds. The supervisor's
|
|
16
|
+
* `decideRestartHold` reads it as `DRAINED` and restarts at once.
|
|
17
|
+
*
|
|
18
|
+
* ## What counts as busy (review F1 of the first draft, which counted leaves only)
|
|
19
|
+
*
|
|
20
|
+
* EVERY run is counted for its whole life ({@link CompanionRestartDrain.whileWorking}, at the same entry points that beat
|
|
21
|
+
* the playbook-run heartbeat, settle included): a composite does work of its own between children (merging, a checkpoint,
|
|
22
|
+
* a tree read, the selector's model call), and a run's record is written after its work returns. A run stops being busy
|
|
23
|
+
* only while it is PAUSED: parked at the restart window, or waiting on the children its round dispatched
|
|
24
|
+
* ({@link CompanionRestartDrain.whilePaused}), each of which is counted itself. Busy is runs minus pauses; drained is none
|
|
25
|
+
* busy. A nested lane, which runs inside its parent's round rather than as a run of its own, is counted by the runtime
|
|
26
|
+
* through the same port. Agents (coding, research) keep their own heartbeats, which the supervisor checks first.
|
|
27
|
+
*
|
|
28
|
+
* The marker is deleted the moment anything becomes busy again, so a stale "drained" can never cover work that started
|
|
29
|
+
* after it (review F4).
|
|
30
|
+
*/
|
|
31
|
+
/** A COPY of `COMPANION_DRAINED_FOR_RESTART_RELATIVE_PATH` in `scripts/dev-orchestrator/runtime-supervisor-lifecycle.mjs`. */
|
|
32
|
+
export declare const COMPANION_DRAINED_FOR_RESTART_RELATIVE_PATH = ".wildo-saas/runtime-signals/wildo-dev-companion.drained-for-restart.json";
|
|
33
|
+
/** How often a parked loop re-reads the hold and the companion rewrites its drained marker. Under the supervisor's 30 s freshness. */
|
|
34
|
+
export declare const RESTART_DRAIN_POLL_MS = 5000;
|
|
35
|
+
/**
|
|
36
|
+
* The longest a round waits at the restart window (review F3): the supervisor's own ceiling (`CODING_RUN_HARD_MAX_MS`
|
|
37
|
+
* 60 min + 5 min margin), past which it restarts anyway. A hold still published after it is a supervisor fault, and the
|
|
38
|
+
* round goes on rather than parking the creation for ever.
|
|
39
|
+
*/
|
|
40
|
+
export declare const RESTART_WINDOW_CEILING_MS: number;
|
|
41
|
+
/** A restart the running supervisor holds for this process. */
|
|
42
|
+
export interface HeldCompanionRestart {
|
|
43
|
+
readonly since: string;
|
|
44
|
+
readonly reason: string | null;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* The restart the supervisor running THIS process holds, or `undefined`. Counted only when the observation names this
|
|
48
|
+
* process as its child and its producer is alive, as `requestCompanionRestart` reads the same file: a record left by a
|
|
49
|
+
* supervisor that has exited, or describing another companion, must never park this one.
|
|
50
|
+
*/
|
|
51
|
+
export declare function readHeldCompanionRestart(saasRoot: string, options?: {
|
|
52
|
+
readonly processId?: number;
|
|
53
|
+
readonly isProcessAlive?: (pid: number) => boolean;
|
|
54
|
+
}): HeldCompanionRestart | undefined;
|
|
55
|
+
/** See the module comment. One per process ({@link companionRestartDrain}); constructed directly by tests. */
|
|
56
|
+
export declare class CompanionRestartDrain {
|
|
57
|
+
private readonly options;
|
|
58
|
+
private workInFlight;
|
|
59
|
+
private paused;
|
|
60
|
+
private saasRoot;
|
|
61
|
+
private ticker;
|
|
62
|
+
private cached;
|
|
63
|
+
constructor(options?: {
|
|
64
|
+
readonly now?: () => number;
|
|
65
|
+
readonly sleep?: (ms: number) => Promise<void>;
|
|
66
|
+
readonly processId?: number;
|
|
67
|
+
readonly isProcessAlive?: (pid: number) => boolean;
|
|
68
|
+
/** Tests drive {@link tick} themselves. */
|
|
69
|
+
readonly withoutTicker?: boolean;
|
|
70
|
+
});
|
|
71
|
+
/**
|
|
72
|
+
* The restart held for this process right now, or `undefined`; read at most every {@link OBSERVATION_CACHE_MS}. A hold
|
|
73
|
+
* published for longer than {@link RESTART_WINDOW_CEILING_MS} is a supervisor fault and is NOT held here (second review
|
|
74
|
+
* H2): one predicate for every reader, so a wave does not stop filling for ever after the window let its loop go on.
|
|
75
|
+
*/
|
|
76
|
+
heldRestart(saasRoot: string): HeldCompanionRestart | undefined;
|
|
77
|
+
/** What the supervisor publishes, ceiling not applied. */
|
|
78
|
+
private publishedRestart;
|
|
79
|
+
isRestartHeld(saasRoot: string): boolean;
|
|
80
|
+
/**
|
|
81
|
+
* Count work as in flight from NOW until the returned release is called (idempotent): for a run whose life spans a
|
|
82
|
+
* detached chain, counted before its first await so no marker is written between its start and its count (review L1).
|
|
83
|
+
*/
|
|
84
|
+
begin(saasRoot: string): () => void;
|
|
85
|
+
/** Run work counted as in flight for its whole life: busy, unless it is paused. */
|
|
86
|
+
whileWorking<T>(saasRoot: string, work: () => Promise<T>): Promise<T>;
|
|
87
|
+
/** Run `work` while the counted run calling it is PAUSED: it waits on children that are counted themselves. */
|
|
88
|
+
whilePaused<T>(work: () => Promise<T>): Promise<T>;
|
|
89
|
+
/**
|
|
90
|
+
* Wait at a round boundary while a restart is held: return at once when none is, and otherwise only once the hold is
|
|
91
|
+
* withdrawn. Normally it never returns: the supervisor reads the drained marker and restarts the process.
|
|
92
|
+
*/
|
|
93
|
+
awaitRestartWindow(saasRoot: string, onParked?: (held: HeldCompanionRestart) => void, onCeiling?: (held: HeldCompanionRestart) => void): Promise<void>;
|
|
94
|
+
/** Write the drained marker when a restart is held and nothing is busy. Called by the ticker and when a round parks. */
|
|
95
|
+
tick(): void;
|
|
96
|
+
/** How many counted runs are busy (in flight and not paused). For tests and logs. */
|
|
97
|
+
busy(): number;
|
|
98
|
+
/** Apply a change to the counts, deleting the drained marker the moment something becomes busy (review F4). */
|
|
99
|
+
private changeCounts;
|
|
100
|
+
private pastCeiling;
|
|
101
|
+
private attach;
|
|
102
|
+
private now;
|
|
103
|
+
private sleep;
|
|
104
|
+
}
|
|
105
|
+
/** The process's drain: one supervisor watches one companion process. */
|
|
106
|
+
export declare const companionRestartDrain: CompanionRestartDrain;
|
|
107
|
+
//# sourceMappingURL=restart-drain.companion.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"restart-drain.companion.d.ts","sourceRoot":"","sources":["../../../../src/core/runtime/restart-drain.companion.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,8HAA8H;AAC9H,eAAO,MAAM,2CAA2C,6EAA6E,CAAC;AAKtI,sIAAsI;AACtI,eAAO,MAAM,qBAAqB,OAAQ,CAAC;AAK3C;;;;GAIG;AACH,eAAO,MAAM,yBAAyB,QAAc,CAAC;AAErD,+DAA+D;AAC/D,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;CAChC;AAWD;;;;GAIG;AACH,wBAAgB,wBAAwB,CACtC,QAAQ,EAAE,MAAM,EAChB,OAAO,GAAE;IAAE,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,cAAc,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAA;CAAO,GAChG,oBAAoB,GAAG,SAAS,CAclC;AAED,8GAA8G;AAC9G,qBAAa,qBAAqB;IAOb,OAAO,CAAC,QAAQ,CAAC,OAAO;IAN3C,OAAO,CAAC,YAAY,CAAK;IACzB,OAAO,CAAC,MAAM,CAAK;IACnB,OAAO,CAAC,QAAQ,CAAqB;IACrC,OAAO,CAAC,MAAM,CAA6C;IAC3D,OAAO,CAAC,MAAM,CAA6F;gBAEvE,OAAO,GAAE;QAC3C,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;QAC5B,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;QAC/C,QAAQ,CAAC,SAAS,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renameSync, rmSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { dirname, join } from 'node:path';
|
|
3
|
+
/**
|
|
4
|
+
* Drain before a held restart (#3204; #265's first candidate shape, never built until now).
|
|
5
|
+
*
|
|
6
|
+
* `wildo local dev` runs the companion under `runtime-supervisor.mjs`, which HOLDS a restart (a dependency install, an
|
|
7
|
+
* engine rebuild) while work is in flight, because the restart kills the companion's process tree. During an unattended
|
|
8
|
+
* build a playbook run is always in flight, so the hold only ever ended at its ceiling (`HOLD_EXCEEDED`, 65 min), which
|
|
9
|
+
* then killed the wave's live coding runs: reference run 43237839187 lost nine at 15:43. Nothing told the companion a
|
|
10
|
+
* restart was waiting, so it kept starting work.
|
|
11
|
+
*
|
|
12
|
+
* Now the supervisor publishes the held restart in its observation, and this module answers three things for the rest of
|
|
13
|
+
* the companion:
|
|
14
|
+
* - {@link CompanionRestartDrain.isRestartHeld}: the build wave stops filling (`ApplicationBuildWaveStop.RESTART_PENDING`);
|
|
15
|
+
* - {@link CompanionRestartDrain.awaitRestartWindow}: the creation loop and every choreography wait at the TOP of each
|
|
16
|
+
* round, before reading the tree or asking a model, until the restart comes (the process ends) or the hold is withdrawn;
|
|
17
|
+
* - when nothing is BUSY, the companion writes its drained marker, `{ pid, at }`, every few seconds. The supervisor's
|
|
18
|
+
* `decideRestartHold` reads it as `DRAINED` and restarts at once.
|
|
19
|
+
*
|
|
20
|
+
* ## What counts as busy (review F1 of the first draft, which counted leaves only)
|
|
21
|
+
*
|
|
22
|
+
* EVERY run is counted for its whole life ({@link CompanionRestartDrain.whileWorking}, at the same entry points that beat
|
|
23
|
+
* the playbook-run heartbeat, settle included): a composite does work of its own between children (merging, a checkpoint,
|
|
24
|
+
* a tree read, the selector's model call), and a run's record is written after its work returns. A run stops being busy
|
|
25
|
+
* only while it is PAUSED: parked at the restart window, or waiting on the children its round dispatched
|
|
26
|
+
* ({@link CompanionRestartDrain.whilePaused}), each of which is counted itself. Busy is runs minus pauses; drained is none
|
|
27
|
+
* busy. A nested lane, which runs inside its parent's round rather than as a run of its own, is counted by the runtime
|
|
28
|
+
* through the same port. Agents (coding, research) keep their own heartbeats, which the supervisor checks first.
|
|
29
|
+
*
|
|
30
|
+
* The marker is deleted the moment anything becomes busy again, so a stale "drained" can never cover work that started
|
|
31
|
+
* after it (review F4).
|
|
32
|
+
*/
|
|
33
|
+
/** A COPY of `COMPANION_DRAINED_FOR_RESTART_RELATIVE_PATH` in `scripts/dev-orchestrator/runtime-supervisor-lifecycle.mjs`. */
|
|
34
|
+
export const COMPANION_DRAINED_FOR_RESTART_RELATIVE_PATH = '.wildo-saas/runtime-signals/wildo-dev-companion.drained-for-restart.json';
|
|
35
|
+
/** The supervisor's observation of this companion (`runtime-supervisor.mjs` `publishSupervisorState`). */
|
|
36
|
+
const SUPERVISOR_OBSERVATION_RELATIVE_PATH = '.wildo-saas/runtime-signals/supervisors/wildo-dev-companion.json';
|
|
37
|
+
/** How often a parked loop re-reads the hold and the companion rewrites its drained marker. Under the supervisor's 30 s freshness. */
|
|
38
|
+
export const RESTART_DRAIN_POLL_MS = 5_000;
|
|
39
|
+
/** How long one observation read is reused: every slot of a wave and every round asks, and the file changes rarely. */
|
|
40
|
+
const OBSERVATION_CACHE_MS = 2_000;
|
|
41
|
+
/**
|
|
42
|
+
* The longest a round waits at the restart window (review F3): the supervisor's own ceiling (`CODING_RUN_HARD_MAX_MS`
|
|
43
|
+
* 60 min + 5 min margin), past which it restarts anyway. A hold still published after it is a supervisor fault, and the
|
|
44
|
+
* round goes on rather than parking the creation for ever.
|
|
45
|
+
*/
|
|
46
|
+
export const RESTART_WINDOW_CEILING_MS = 65 * 60_000;
|
|
47
|
+
function defaultIsProcessAlive(pid) {
|
|
48
|
+
try {
|
|
49
|
+
process.kill(pid, 0);
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
return error.code === 'EPERM';
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* The restart the supervisor running THIS process holds, or `undefined`. Counted only when the observation names this
|
|
58
|
+
* process as its child and its producer is alive, as `requestCompanionRestart` reads the same file: a record left by a
|
|
59
|
+
* supervisor that has exited, or describing another companion, must never park this one.
|
|
60
|
+
*/
|
|
61
|
+
export function readHeldCompanionRestart(saasRoot, options = {}) {
|
|
62
|
+
let observation;
|
|
63
|
+
try {
|
|
64
|
+
observation = JSON.parse(readFileSync(join(saasRoot, SUPERVISOR_OBSERVATION_RELATIVE_PATH), 'utf8'));
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
return undefined;
|
|
68
|
+
}
|
|
69
|
+
if (observation.childPid !== (options.processId ?? process.pid))
|
|
70
|
+
return undefined;
|
|
71
|
+
if (typeof observation.producerPid !== 'number' || !(options.isProcessAlive ?? defaultIsProcessAlive)(observation.producerPid))
|
|
72
|
+
return undefined;
|
|
73
|
+
const held = observation.restartHeld;
|
|
74
|
+
if (held === null || typeof held !== 'object' || typeof held.since !== 'string')
|
|
75
|
+
return undefined;
|
|
76
|
+
// A hold taken for another child (one this process replaced) is not this process's (review F2).
|
|
77
|
+
if (typeof held.forChildPid === 'number' && held.forChildPid !== (options.processId ?? process.pid))
|
|
78
|
+
return undefined;
|
|
79
|
+
return { since: held.since, reason: typeof held.reason === 'string' ? held.reason : null };
|
|
80
|
+
}
|
|
81
|
+
/** See the module comment. One per process ({@link companionRestartDrain}); constructed directly by tests. */
|
|
82
|
+
export class CompanionRestartDrain {
|
|
83
|
+
options;
|
|
84
|
+
workInFlight = 0;
|
|
85
|
+
paused = 0;
|
|
86
|
+
saasRoot;
|
|
87
|
+
ticker;
|
|
88
|
+
cached;
|
|
89
|
+
constructor(options = {}) {
|
|
90
|
+
this.options = options;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* The restart held for this process right now, or `undefined`; read at most every {@link OBSERVATION_CACHE_MS}. A hold
|
|
94
|
+
* published for longer than {@link RESTART_WINDOW_CEILING_MS} is a supervisor fault and is NOT held here (second review
|
|
95
|
+
* H2): one predicate for every reader, so a wave does not stop filling for ever after the window let its loop go on.
|
|
96
|
+
*/
|
|
97
|
+
heldRestart(saasRoot) {
|
|
98
|
+
const held = this.publishedRestart(saasRoot);
|
|
99
|
+
return held === undefined || this.pastCeiling(held) ? undefined : held;
|
|
100
|
+
}
|
|
101
|
+
/** What the supervisor publishes, ceiling not applied. */
|
|
102
|
+
publishedRestart(saasRoot) {
|
|
103
|
+
this.attach(saasRoot);
|
|
104
|
+
const nowMs = this.now();
|
|
105
|
+
if (this.cached === undefined || nowMs - this.cached.readAtMs >= OBSERVATION_CACHE_MS) {
|
|
106
|
+
this.cached = {
|
|
107
|
+
readAtMs: nowMs,
|
|
108
|
+
held: readHeldCompanionRestart(saasRoot, {
|
|
109
|
+
...(this.options.processId !== undefined ? { processId: this.options.processId } : {}),
|
|
110
|
+
...(this.options.isProcessAlive ? { isProcessAlive: this.options.isProcessAlive } : {}),
|
|
111
|
+
}),
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
return this.cached.held;
|
|
115
|
+
}
|
|
116
|
+
isRestartHeld(saasRoot) {
|
|
117
|
+
return this.heldRestart(saasRoot) !== undefined;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Count work as in flight from NOW until the returned release is called (idempotent): for a run whose life spans a
|
|
121
|
+
* detached chain, counted before its first await so no marker is written between its start and its count (review L1).
|
|
122
|
+
*/
|
|
123
|
+
begin(saasRoot) {
|
|
124
|
+
this.attach(saasRoot);
|
|
125
|
+
this.changeCounts(1, 0);
|
|
126
|
+
let released = false;
|
|
127
|
+
return () => {
|
|
128
|
+
if (released)
|
|
129
|
+
return;
|
|
130
|
+
released = true;
|
|
131
|
+
this.changeCounts(-1, 0);
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
/** Run work counted as in flight for its whole life: busy, unless it is paused. */
|
|
135
|
+
async whileWorking(saasRoot, work) {
|
|
136
|
+
this.attach(saasRoot);
|
|
137
|
+
this.changeCounts(1, 0);
|
|
138
|
+
try {
|
|
139
|
+
return await work();
|
|
140
|
+
}
|
|
141
|
+
finally {
|
|
142
|
+
this.changeCounts(-1, 0);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
/** Run `work` while the counted run calling it is PAUSED: it waits on children that are counted themselves. */
|
|
146
|
+
async whilePaused(work) {
|
|
147
|
+
this.changeCounts(0, 1);
|
|
148
|
+
try {
|
|
149
|
+
return await work();
|
|
150
|
+
}
|
|
151
|
+
finally {
|
|
152
|
+
this.changeCounts(0, -1);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Wait at a round boundary while a restart is held: return at once when none is, and otherwise only once the hold is
|
|
157
|
+
* withdrawn. Normally it never returns: the supervisor reads the drained marker and restarts the process.
|
|
158
|
+
*/
|
|
159
|
+
async awaitRestartWindow(saasRoot, onParked, onCeiling) {
|
|
160
|
+
let held = this.publishedRestart(saasRoot);
|
|
161
|
+
if (held === undefined)
|
|
162
|
+
return;
|
|
163
|
+
if (this.pastCeiling(held)) {
|
|
164
|
+
onCeiling?.(held);
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
onParked?.(held);
|
|
168
|
+
await this.whilePaused(async () => {
|
|
169
|
+
while (held !== undefined) {
|
|
170
|
+
if (this.pastCeiling(held)) {
|
|
171
|
+
onCeiling?.(held);
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
this.tick();
|
|
175
|
+
await this.sleep(RESTART_DRAIN_POLL_MS);
|
|
176
|
+
this.cached = undefined;
|
|
177
|
+
held = this.publishedRestart(saasRoot);
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
/** Write the drained marker when a restart is held and nothing is busy. Called by the ticker and when a round parks. */
|
|
182
|
+
tick() {
|
|
183
|
+
const saasRoot = this.saasRoot;
|
|
184
|
+
if (saasRoot === undefined || this.busy() > 0 || !this.isRestartHeld(saasRoot))
|
|
185
|
+
return;
|
|
186
|
+
const markerPath = join(saasRoot, COMPANION_DRAINED_FOR_RESTART_RELATIVE_PATH);
|
|
187
|
+
try {
|
|
188
|
+
mkdirSync(dirname(markerPath), { recursive: true });
|
|
189
|
+
const temporary = `${markerPath}.tmp-${process.pid}`;
|
|
190
|
+
writeFileSync(temporary, `${JSON.stringify({ pid: this.options.processId ?? process.pid, at: new Date(this.now()).toISOString() })}\n`, 'utf8');
|
|
191
|
+
renameSync(temporary, markerPath);
|
|
192
|
+
}
|
|
193
|
+
catch {
|
|
194
|
+
// Best-effort: without the marker the supervisor holds to its ceiling, exactly as before.
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
/** How many counted runs are busy (in flight and not paused). For tests and logs. */
|
|
198
|
+
busy() {
|
|
199
|
+
return Math.max(0, this.workInFlight - this.paused);
|
|
200
|
+
}
|
|
201
|
+
/** Apply a change to the counts, deleting the drained marker the moment something becomes busy (review F4). */
|
|
202
|
+
changeCounts(work, paused) {
|
|
203
|
+
const wasBusy = this.busy() > 0;
|
|
204
|
+
this.workInFlight = Math.max(0, this.workInFlight + work);
|
|
205
|
+
this.paused = Math.max(0, this.paused + paused);
|
|
206
|
+
if (!wasBusy && this.busy() > 0 && this.saasRoot !== undefined) {
|
|
207
|
+
try {
|
|
208
|
+
rmSync(join(this.saasRoot, COMPANION_DRAINED_FOR_RESTART_RELATIVE_PATH), { force: true });
|
|
209
|
+
}
|
|
210
|
+
catch {
|
|
211
|
+
// Best-effort: the supervisor's freshness bound still retires it.
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
pastCeiling(held) {
|
|
216
|
+
const sinceMs = Date.parse(held.since);
|
|
217
|
+
return Number.isFinite(sinceMs) && this.now() - sinceMs > RESTART_WINDOW_CEILING_MS;
|
|
218
|
+
}
|
|
219
|
+
attach(saasRoot) {
|
|
220
|
+
if (this.saasRoot === saasRoot)
|
|
221
|
+
return;
|
|
222
|
+
this.saasRoot = saasRoot;
|
|
223
|
+
if (this.options.withoutTicker || this.ticker !== undefined)
|
|
224
|
+
return;
|
|
225
|
+
this.ticker = setInterval(() => this.tick(), RESTART_DRAIN_POLL_MS);
|
|
226
|
+
this.ticker.unref?.();
|
|
227
|
+
}
|
|
228
|
+
now() {
|
|
229
|
+
return (this.options.now ?? Date.now)();
|
|
230
|
+
}
|
|
231
|
+
sleep(ms) {
|
|
232
|
+
return this.options.sleep ? this.options.sleep(ms) : new Promise((resolveSleep) => setTimeout(resolveSleep, ms));
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
/** The process's drain: one supervisor watches one companion process. */
|
|
236
|
+
export const companionRestartDrain = new CompanionRestartDrain();
|
|
237
|
+
//# sourceMappingURL=restart-drain.companion.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"restart-drain.companion.js","sourceRoot":"","sources":["../../../../src/core/runtime/restart-drain.companion.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACrF,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAE1C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,8HAA8H;AAC9H,MAAM,CAAC,MAAM,2CAA2C,GAAG,0EAA0E,CAAC;AAEtI,0GAA0G;AAC1G,MAAM,oCAAoC,GAAG,kEAAkE,CAAC;AAEhH,sIAAsI;AACtI,MAAM,CAAC,MAAM,qBAAqB,GAAG,KAAK,CAAC;AAE3C,uHAAuH;AACvH,MAAM,oBAAoB,GAAG,KAAK,CAAC;AAEnC;;;;GAIG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,EAAE,GAAG,MAAM,CAAC;AAQrD,SAAS,qBAAqB,CAAC,GAAW;IACxC,IAAI,CAAC;QACH,OAAO,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;QACrB,O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AAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACvC,OAAO,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,IAAI,CAAC,GAAG,EAAE,GAAG,OAAO,GAAG,yBAAyB,CAAC;IACtF,CAAC;IAEO,MAAM,CAAC,QAAgB;QAC7B,IAAI,IAAI,CAAC,QAAQ,KAAK,QAAQ;YAAE,OAAO;QACvC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,IAAI,CAAC,OAAO,CAAC,aAAa,IAAI,IAAI,CAAC,MAAM,KAAK,SAAS;YAAE,OAAO;QACpE,IAAI,CAAC,MAAM,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE,qBAAqB,CAAC,CAAC;QACpE,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,EAAE,CAAC;IACxB,CAAC;IAEO,GAAG;QACT,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,IAAI,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;IAC1C,CAAC;IAEO,KAAK,CAAC,EAAU;QACtB,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,OAAO,CAAC,CAAC,YAAY,EAAE,EAAE,CAAC,UAAU,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC,CAAC;IACnH,CAAC;CACF;AAED,yEAAyE;AACzE,MAAM,CAAC,MAAM,qBAAqB,GAAG,IAAI,qBAAqB,EAAE,CAAC","sourcesContent":["import { mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from 'node:fs';\nimport { dirname, join } from 'node:path';\n\n/**\n * Drain before a held restart (#3204; #265's first candidate shape, never built until now).\n *\n * `wildo local dev` runs the companion under `runtime-supervisor.mjs`, which HOLDS a restart (a dependency install, an\n * engine rebuild) while work is in flight, because the restart kills the companion's process tree. During an unattended\n * build a playbook run is always in flight, so the hold only ever ended at its ceiling (`HOLD_EXCEEDED`, 65 min), which\n * then killed the wave's live coding runs: reference run 43237839187 lost nine at 15:43. Nothing told the companion a\n * restart was waiting, so it kept starting work.\n *\n * Now the supervisor publishes the held restart in its observation, and this module answers three things for the rest of\n * the companion:\n * - {@link CompanionRestartDrain.isRestartHeld}: the build wave stops filling (`ApplicationBuildWaveStop.RESTART_PENDING`);\n * - {@link CompanionRestartDrain.awaitRestartWindow}: the creation loop and every choreography wait at the TOP of each\n * round, before reading the tree or asking a model, until the restart comes (the process ends) or the hold is withdrawn;\n * - when nothing is BUSY, the companion writes its drained marker, `{ pid, at }`, every few seconds. The supervisor's\n * `decideRestartHold` reads it as `DRAINED` and restarts at once.\n *\n * ## What counts as busy (review F1 of the first draft, which counted leaves only)\n *\n * EVERY run is counted for its whole life ({@link CompanionRestartDrain.whileWorking}, at the same entry points that beat\n * the playbook-run heartbeat, settle included): a composite does work of its own between children (merging, a checkpoint,\n * a tree read, the selector's model call), and a run's record is written after its work returns. A run stops being busy\n * only while it is PAUSED: parked at the restart window, or waiting on the children its round dispatched\n * ({@link CompanionRestartDrain.whilePaused}), each of which is counted itself. Busy is runs minus pauses; drained is none\n * busy. A nested lane, which runs inside its parent's round rather than as a run of its own, is counted by the runtime\n * through the same port. Agents (coding, research) keep their own heartbeats, which the supervisor checks first.\n *\n * The marker is deleted the moment anything becomes busy again, so a stale \"drained\" can never cover work that started\n * after it (review F4).\n */\n\n/** A COPY of `COMPANION_DRAINED_FOR_RESTART_RELATIVE_PATH` in `scripts/dev-orchestrator/runtime-supervisor-lifecycle.mjs`. */\nexport const COMPANION_DRAINED_FOR_RESTART_RELATIVE_PATH = '.wildo-saas/runtime-signals/wildo-dev-companion.drained-for-restart.json';\n\n/** The supervisor's observation of this companion (`runtime-supervisor.mjs` `publishSupervisorState`). */\nconst SUPERVISOR_OBSERVATION_RELATIVE_PATH = '.wildo-saas/runtime-signals/supervisors/wildo-dev-companion.json';\n\n/** How often a parked loop re-reads the hold and the companion rewrites its drained marker. Under the supervisor's 30 s freshness. */\nexport const RESTART_DRAIN_POLL_MS = 5_000;\n\n/** How long one observation read is reused: every slot of a wave and every round asks, and the file changes rarely. */\nconst OBSERVATION_CACHE_MS = 2_000;\n\n/**\n * The longest a round waits at the restart window (review F3): the supervisor's own ceiling (`CODING_RUN_HARD_MAX_MS`\n * 60 min + 5 min margin), past which it restarts anyway. A hold still published after it is a supervisor fault, and the\n * round goes on rather than parking the creation for ever.\n */\nexport const RESTART_WINDOW_CEILING_MS = 65 * 60_000;\n\n/** A restart the running supervisor holds for this process. */\nexport interface HeldCompanionRestart {\n readonly since: string;\n readonly reason: string | null;\n}\n\nfunction defaultIsProcessAlive(pid: number): boolean {\n try {\n process.kill(pid, 0);\n return true;\n } catch (error) {\n return (error as NodeJS.ErrnoException).code === 'EPERM';\n }\n}\n\n/**\n * The restart the supervisor running THIS process holds, or `undefined`. Counted only when the observation names this\n * process as its child and its producer is alive, as `requestCompanionRestart` reads the same file: a record left by a\n * supervisor that has exited, or describing another companion, must never park this one.\n */\nexport function readHeldCompanionRestart(\n saasRoot: string,\n options: { readonly processId?: number; readonly isProcessAlive?: (pid: number) => boolean } = {},\n): HeldCompanionRestart | undefined {\n let observation: { readonly producerPid?: unknown; readonly childPid?: unknown; readonly restartHeld?: unknown };\n try {\n observation = JSON.parse(readFileSync(join(saasRoot, SUPERVISOR_OBSERVATION_RELATIVE_PATH), 'utf8')) as typeof observation;\n } catch {\n return undefined;\n }\n if (observation.childPid !== (options.processId ?? process.pid)) return undefined;\n if (typeof observation.producerPid !== 'number' || !(options.isProcessAlive ?? defaultIsProcessAlive)(observation.producerPid)) return undefined;\n const held = observation.restartHeld as { readonly since?: unknown; readonly reason?: unknown; readonly forChildPid?: unknown } | null | undefined;\n if (held === null || typeof held !== 'object' || typeof held.since !== 'string') return undefined;\n // A hold taken for another child (one this process replaced) is not this process's (review F2).\n if (typeof held.forChildPid === 'number' && held.forChildPid !== (options.processId ?? process.pid)) return undefined;\n return { since: held.since, reason: typeof held.reason === 'string' ? held.reason : null };\n}\n\n/** See the module comment. One per process ({@link companionRestartDrain}); constructed directly by tests. */\nexport class CompanionRestartDrain {\n private workInFlight = 0;\n private paused = 0;\n private saasRoot: string | undefined;\n private ticker: ReturnType<typeof setInterval> | undefined;\n private cached: { readonly readAtMs: number; readonly held: HeldCompanionRestart | undefined } | undefined;\n\n public constructor(private readonly options: {\n readonly now?: () => number;\n readonly sleep?: (ms: number) => Promise<void>;\n readonly processId?: number;\n readonly isProcessAlive?: (pid: number) => boolean;\n /** Tests drive {@link tick} themselves. */\n readonly withoutTicker?: boolean;\n } = {}) {}\n\n /**\n * The restart held for this process right now, or `undefined`; read at most every {@link OBSERVATION_CACHE_MS}. A hold\n * published for longer than {@link RESTART_WINDOW_CEILING_MS} is a supervisor fault and is NOT held here (second review\n * H2): one predicate for every reader, so a wave does not stop filling for ever after the window let its loop go on.\n */\n public heldRestart(saasRoot: string): HeldCompanionRestart | undefined {\n const held = this.publishedRestart(saasRoot);\n return held === undefined || this.pastCeiling(held) ? undefined : held;\n }\n\n /** What the supervisor publishes, ceiling not applied. */\n private publishedRestart(saasRoot: string): HeldCompanionRestart | undefined {\n this.attach(saasRoot);\n const nowMs = this.now();\n if (this.cached === undefined || nowMs - this.cached.readAtMs >= OBSERVATION_CACHE_MS) {\n this.cached = {\n readAtMs: nowMs,\n held: readHeldCompanionRestart(saasRoot, {\n ...(this.options.processId !== undefined ? { processId: this.options.processId } : {}),\n ...(this.options.isProcessAlive ? { isProcessAlive: this.options.isProcessAlive } : {}),\n }),\n };\n }\n return this.cached.held;\n }\n\n public isRestartHeld(saasRoot: string): boolean {\n return this.heldRestart(saasRoot) !== undefined;\n }\n\n /**\n * Count work as in flight from NOW until the returned release is called (idempotent): for a run whose life spans a\n * detached chain, counted before its first await so no marker is written between its start and its count (review L1).\n */\n public begin(saasRoot: string): () => void {\n this.attach(saasRoot);\n this.changeCounts(1, 0);\n let released = false;\n return () => {\n if (released) return;\n released = true;\n this.changeCounts(-1, 0);\n };\n }\n\n /** Run work counted as in flight for its whole life: busy, unless it is paused. */\n public async whileWorking<T>(saasRoot: string, work: () => Promise<T>): Promise<T> {\n this.attach(saasRoot);\n this.changeCounts(1, 0);\n try {\n return await work();\n } finally {\n this.changeCounts(-1, 0);\n }\n }\n\n /** Run `work` while the counted run calling it is PAUSED: it waits on children that are counted themselves. */\n public async whilePaused<T>(work: () => Promise<T>): Promise<T> {\n this.changeCounts(0, 1);\n try {\n return await work();\n } finally {\n this.changeCounts(0, -1);\n }\n }\n\n /**\n * Wait at a round boundary while a restart is held: return at once when none is, and otherwise only once the hold is\n * withdrawn. Normally it never returns: the supervisor reads the drained marker and restarts the process.\n */\n public async awaitRestartWindow(\n saasRoot: string,\n onParked?: (held: HeldCompanionRestart) => void,\n onCeiling?: (held: HeldCompanionRestart) => void,\n ): Promise<void> {\n let held = this.publishedRestart(saasRoot);\n if (held === undefined) return;\n if (this.pastCeiling(held)) {\n onCeiling?.(held);\n return;\n }\n onParked?.(held);\n await this.whilePaused(async () => {\n while (held !== undefined) {\n if (this.pastCeiling(held)) {\n onCeiling?.(held);\n return;\n }\n this.tick();\n await this.sleep(RESTART_DRAIN_POLL_MS);\n this.cached = undefined;\n held = this.publishedRestart(saasRoot);\n }\n });\n }\n\n /** Write the drained marker when a restart is held and nothing is busy. Called by the ticker and when a round parks. */\n public tick(): void {\n const saasRoot = this.saasRoot;\n if (saasRoot === undefined || this.busy() > 0 || !this.isRestartHeld(saasRoot)) return;\n const markerPath = join(saasRoot, COMPANION_DRAINED_FOR_RESTART_RELATIVE_PATH);\n try {\n mkdirSync(dirname(markerPath), { recursive: true });\n const temporary = `${markerPath}.tmp-${process.pid}`;\n writeFileSync(temporary, `${JSON.stringify({ pid: this.options.processId ?? process.pid, at: new Date(this.now()).toISOString() })}\\n`, 'utf8');\n renameSync(temporary, markerPath);\n } catch {\n // Best-effort: without the marker the supervisor holds to its ceiling, exactly as before.\n }\n }\n\n /** How many counted runs are busy (in flight and not paused). For tests and logs. */\n public busy(): number {\n return Math.max(0, this.workInFlight - this.paused);\n }\n\n /** Apply a change to the counts, deleting the drained marker the moment something becomes busy (review F4). */\n private changeCounts(work: number, paused: number): void {\n const wasBusy = this.busy() > 0;\n this.workInFlight = Math.max(0, this.workInFlight + work);\n this.paused = Math.max(0, this.paused + paused);\n if (!wasBusy && this.busy() > 0 && this.saasRoot !== undefined) {\n try {\n rmSync(join(this.saasRoot, COMPANION_DRAINED_FOR_RESTART_RELATIVE_PATH), { force: true });\n } catch {\n // Best-effort: the supervisor's freshness bound still retires it.\n }\n }\n }\n\n private pastCeiling(held: HeldCompanionRestart): boolean {\n const sinceMs = Date.parse(held.since);\n return Number.isFinite(sinceMs) && this.now() - sinceMs > RESTART_WINDOW_CEILING_MS;\n }\n\n private attach(saasRoot: string): void {\n if (this.saasRoot === saasRoot) return;\n this.saasRoot = saasRoot;\n if (this.options.withoutTicker || this.ticker !== undefined) return;\n this.ticker = setInterval(() => this.tick(), RESTART_DRAIN_POLL_MS);\n this.ticker.unref?.();\n }\n\n private now(): number {\n return (this.options.now ?? Date.now)();\n }\n\n private sleep(ms: number): Promise<void> {\n return this.options.sleep ? this.options.sleep(ms) : new Promise((resolveSleep) => setTimeout(resolveSleep, ms));\n }\n}\n\n/** The process's drain: one supervisor watches one companion process. */\nexport const companionRestartDrain = new CompanionRestartDrain();\n"]}
|
|
@@ -70,6 +70,17 @@ interface CompanionExecutionOwnership {
|
|
|
70
70
|
organizationId: string;
|
|
71
71
|
wildoApplicationId: string;
|
|
72
72
|
}
|
|
73
|
+
/**
|
|
74
|
+
* The stored fields an actor-execution listing leaves out unless its caller asks for whole rows (#3204,
|
|
75
|
+
* `RepositoryOptions.omitStoredFields`).
|
|
76
|
+
*
|
|
77
|
+
* `standaloneTasks.input.baseline.files` is a coding run's dirty-file map at admission: measured on the reference creation
|
|
78
|
+
* (run 42886943490), 15.7 KB of a 36 KB coding row, over 986 rows, re-read by the build loop's 2,000-row listings several
|
|
79
|
+
* times a minute — which kept the companion's thread blocked about 1.5 s in every 30. No reader of a LISTING uses it: the
|
|
80
|
+
* change-set and recovery paths read the baseline from the task row (`getActorTask`) or hold it in memory, and the
|
|
81
|
+
* listing readers take only `baseline.headSha` / `capturedAt`. The HTTP listing passes `[]` and keeps returning whole rows.
|
|
82
|
+
*/
|
|
83
|
+
export declare const ACTOR_EXECUTION_LISTING_OMITTED_FIELDS: readonly string[];
|
|
73
84
|
export declare class CompanionExecutionsCompanionService {
|
|
74
85
|
private readonly logger;
|
|
75
86
|
private readonly errorBuilder;
|
|
@@ -172,7 +183,13 @@ export declare class CompanionExecutionsCompanionService {
|
|
|
172
183
|
listActorExecutionsOwingCorrectionRecord(sessionContext?: CompanionExecutionSessionContext, after?: string): Promise<Wildo_Application_ActorSystem_Execution[]>;
|
|
173
184
|
getActorExecution(executionId: string, _sessionContext?: CompanionExecutionSessionContext): Promise<Wildo_Application_ActorSystem_Execution>;
|
|
174
185
|
getFlowExecution(executionId: string, _sessionContext?: CompanionExecutionSessionContext): Promise<Wildo_Application_FlowSystem_Execution>;
|
|
175
|
-
listActorExecutions(query: CompanionExecutionsListQuery, _sessionContext?: CompanionExecutionSessionContext
|
|
186
|
+
listActorExecutions(query: CompanionExecutionsListQuery, _sessionContext?: CompanionExecutionSessionContext,
|
|
187
|
+
/**
|
|
188
|
+
* Stored fields the rows leave out. Defaults to {@link ACTOR_EXECUTION_LISTING_OMITTED_FIELDS}; pass `[]` for whole rows.
|
|
189
|
+
*/
|
|
190
|
+
readOptions?: {
|
|
191
|
+
readonly omitStoredFields?: readonly string[];
|
|
192
|
+
}): Promise<Wildo_Application_ActorSystem_Execution[]>;
|
|
176
193
|
listFlowExecutions(query: CompanionExecutionsListQuery, _sessionContext?: CompanionExecutionSessionContext): Promise<Wildo_Application_FlowSystem_Execution[]>;
|
|
177
194
|
createActorTask(payload: CompanionCreateActorTaskRequest, sessionContext?: CompanionExecutionSessionContext): Promise<Wildo_Application_Actor_Task>;
|
|
178
195
|
getActorTask(taskId: string, _sessionContext?: CompanionExecutionSessionContext): Promise<Wildo_Application_Actor_Task>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"companion-executions.companion.service.d.ts","sourceRoot":"","sources":["../../../../src/executions/services/companion-executions.companion.service.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,0BAA0B,EAE1B,qCAAqC,EACrC,aAAa,EACb,yCAAyC,EACzC,2CAA2C,EAE3C,+BAA+B,EAE/B,gBAAgB,EAKjB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,KAAK,yBAAyB,EAE9B,qBAAqB,EACrB,kBAAkB,EAIlB,kBAAkB,EAClB,cAAc,EACd,oBAAoB,EAEpB,mBAAmB,EAKpB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAGL,KAAK,4BAA4B,EACjC,KAAK,uCAAuC,EAC5C,KAAK,sCAAsC,EAC5C,MAAM,gCAAgC,CAAC;AACxC,OAAO,KAAK,EACV,4BAA4B,EAC5B,+BAA+B,EAC/B,oCAAoC,EACpC,mCAAmC,EACnC,4BAA4B,EAC5B,oCAAoC,EACpC,+BAA+B,EAChC,MAAM,2CAA2C,CAAC;AACnD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sCAAsC,CAAC;AAE7E,OAAO,EAAE,4BAA4B,EAAE,MAAM,wDAAwD,CAAC;AACtG,OAAO,EAAuD,KAAK,gCAAgC,EAAE,MAAM,uDAAuD,CAAC;AAmDnK;;;;;;;;;;GAUG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,SAAS;IAAE,QAAQ,CAAC,SAAS,EAAE,IAAI,CAAC;IAAC,QAAQ,CAAC,MAAM,CAAC,EAAE;QAAE,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAE,CAAA;CAAE,EACjI,KAAK,EAAE,SAAS,KAAK,EAAE,EACvB,KAAK,EAAE;IAAE,Q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;IACU,wCAAwC,CACnD,cAAc,CAAC,EAAE,gCAAgC,EACjD,KAAK,CAAC,EAAE,MAAM,GACb,OAAO,CAAC,uCAAuC,EAAE,CAAC;IAYxC,iBAAiB,CAAC,WAAW,EAAE,MAAM,EAAE,eAAe,CAAC,EAAE,gCAAgC,GAAG,OAAO,CAAC,uCAAuC,CAAC;IA0D5I,gBAAgB,CAAC,WAAW,EAAE,MAAM,EAAE,eAAe,CAAC,EAAE,gCAAgC,GAAG,OAAO,CAAC,sCAAsC,CAAC;IA0D1I,mBAAmB,CAC9B,KAAK,EAAE,4BAA4B,EACnC,eAAe,CAAC,EAAE,gCAAgC,
|
|
1
|
+
{"version":3,"file":"companion-executions.companion.service.d.ts","sourceRoot":"","sources":["../../../../src/executions/services/companion-executions.companion.service.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,0BAA0B,EAE1B,qCAAqC,EACrC,aAAa,EACb,yCAAyC,EACzC,2CAA2C,EAE3C,+BAA+B,EAE/B,gBAAgB,EAKjB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,KAAK,yBAAyB,EAE9B,qBAAqB,EACrB,kBAAkB,EAIlB,kBAAkB,EAClB,cAAc,EACd,oBAAoB,EAEpB,mBAAmB,EAKpB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAGL,KAAK,4BAA4B,EACjC,KAAK,uCAAuC,EAC5C,KAAK,sCAAsC,EAC5C,MAAM,gCAAgC,CAAC;AACxC,OAAO,KAAK,EACV,4BAA4B,EAC5B,+BAA+B,EAC/B,oCAAoC,EACpC,mCAAmC,EACnC,4BAA4B,EAC5B,oCAAoC,EACpC,+BAA+B,EAChC,MAAM,2CAA2C,CAAC;AACnD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sCAAsC,CAAC;AAE7E,OAAO,EAAE,4BAA4B,EAAE,MAAM,wDAAwD,CAAC;AACtG,OAAO,EAAuD,KAAK,gCAAgC,EAAE,MAAM,uDAAuD,CAAC;AAmDnK;;;;;;;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