@aiwg/cli 2026.11.0 → 2026.11.2
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/agentic/code/addons/aiwg-hooks/canonical/aiwg-prompt-discovery.yaml +9 -0
- package/agentic/code/addons/aiwg-hooks/hooks/aiwg-prompt-discovery.cjs +136 -0
- package/agentic/code/providers/flue/README.md +2 -1
- package/agentic/code/providers/model-capabilities.v1.json +27 -23
- package/agentic/code/providers/model-catalog.v1.json +3 -3
- package/dist/src/artifacts/cli.js +13 -13
- package/dist/src/artifacts/discover-cli-help.js +25 -0
- package/dist/src/artifacts/discover-facets.js +2 -0
- package/dist/src/artifacts/discover-session-facets.js +15 -0
- package/dist/src/artifacts/fortemi-core-prebuilt-freshness.js +28 -0
- package/dist/src/artifacts/fortemi-core-query-adapter.js +4 -4
- package/dist/src/artifacts/fortemi-core-sync.js +3 -0
- package/dist/src/artifacts/framework-capabilities.js +11 -3
- package/dist/src/artifacts/framework-source-digest.js +1 -1
- package/dist/src/artifacts/index-builder.js +12 -13
- package/dist/src/artifacts/index-dependencies.js +72 -0
- package/dist/src/artifacts/query-engine-discover-output.js +13 -5
- package/dist/src/artifacts/query-engine-discover.js +103 -28
- package/dist/src/artifacts/query-engine-entries.js +107 -10
- package/dist/src/artifacts/query-engine-installation.js +27 -0
- package/dist/src/artifacts/query-engine-options.js +14 -1
- package/dist/src/artifacts/query-engine-rules.js +1 -2
- package/dist/src/artifacts/query-engine-scoring.js +38 -32
- package/dist/src/artifacts/query-engine-show-card.js +8 -2
- package/dist/src/artifacts/query-engine-show-load.js +1 -1
- package/dist/src/artifacts/query-engine-show.js +5 -3
- package/dist/src/artifacts/query-engine-templates.js +33 -0
- package/dist/src/artifacts/query-engine-verbose.js +25 -0
- package/dist/src/artifacts/relations-builder.js +49 -4
- package/dist/src/artifacts/relations.js +26 -10
- package/dist/src/artifacts/template-references.js +42 -0
- package/dist/src/artifacts/types.js +1 -1
- package/dist/src/cli/handlers/bundle-reconciliation.js +7 -3
- package/dist/src/cli/handlers/checkpoint-handoff.js +48 -0
- package/dist/src/cli/handlers/checkpoint-record.js +20 -0
- package/dist/src/cli/handlers/checkpoint.js +176 -0
- package/dist/src/cli/handlers/decision.js +1 -1
- package/dist/src/cli/handlers/doctor-args.js +3 -1
- package/dist/src/cli/handlers/doctor-help.js +2 -1
- package/dist/src/cli/handlers/help.js +1 -0
- package/dist/src/cli/handlers/index.js +4 -2
- package/dist/src/cli/handlers/models-resource-sample.js +7 -3
- package/dist/src/cli/handlers/ralph-launcher.js +1 -1
- package/dist/src/cli/handlers/refresh-bundles.js +2 -1
- package/dist/src/cli/handlers/refresh-managed-deployment.js +196 -0
- package/dist/src/cli/handlers/refresh.js +10 -2
- package/dist/src/cli/handlers/script-runner.js +2 -1
- package/dist/src/cli/handlers/steward-signing.js +44 -0
- package/dist/src/cli/handlers/steward.js +5 -0
- package/dist/src/cli/handlers/subcommands-discovery.js +8 -1
- package/dist/src/cli/handlers/use-provider-results.js +17 -0
- package/dist/src/cli/handlers/use.js +19 -18
- package/dist/src/cli/router.js +12 -2
- package/dist/src/cli/services/deployment-verification.js +11 -7
- package/dist/src/cli/user-scope-mirror.js +3 -1
- package/dist/src/config/aiwg-config.js +5 -1
- package/dist/src/config/cli.js +1 -0
- package/dist/src/config/delivery-validation.js +21 -0
- package/dist/src/config/host-resource-report.d.mts +1 -1
- package/dist/src/config/host-resource-report.mjs +23 -4
- package/dist/src/config/host-resource-runtime.d.mts +8 -0
- package/dist/src/config/host-resource-runtime.mjs +67 -24
- package/dist/src/config/index-graph-overrides.js +4 -0
- package/dist/src/config/worker-attribution.d.mts +7 -0
- package/dist/src/config/worker-attribution.mjs +44 -0
- package/dist/src/config/worker-write.js +4 -10
- package/dist/src/decision/ledger.js +15 -15
- package/dist/src/decision/offload.js +6 -7
- package/dist/src/delivery/git.js +62 -0
- package/dist/src/delivery/pr.js +151 -0
- package/dist/src/delivery/template-sections.js +56 -0
- package/dist/src/delivery/tracker.js +33 -0
- package/dist/src/discovery/interview.js +1 -1
- package/dist/src/extensions/claude-hooks-installer.js +62 -53
- package/dist/src/extensions/loader.js +2 -1
- package/dist/src/extensions/managed-hook-script-state.js +48 -0
- package/dist/src/extensions/muse-managed-hooks.js +49 -0
- package/dist/src/issues/cli.js +15 -3
- package/dist/src/issues/external-cli.js +79 -0
- package/dist/src/issues/live.js +26 -2
- package/dist/src/issues/local.js +5 -1
- package/dist/src/issues/tracker-policy.js +27 -0
- package/dist/src/mcp/json-document.d.mts +2 -0
- package/dist/src/mcp/tools/worker-invoke.mjs +2 -1
- package/dist/src/mcp/tools/worker-stdin-runtime.mjs +12 -0
- package/dist/src/models/conductor-data-policy.d.mts +3 -2
- package/dist/src/models/conductor-data-policy.mjs +94 -5
- package/dist/src/models/model-capabilities.v1.json +27 -23
- package/dist/src/models/model-catalog.v1.json +3 -3
- package/dist/src/models/provider-policy.js +8 -0
- package/dist/src/models/worker-health-readiness.js +20 -4
- package/dist/src/models/worker-health-snapshot.js +29 -0
- package/dist/src/models/worker-installation.d.mts +5 -1
- package/dist/src/models/worker-installation.mjs +11 -5
- package/dist/src/models/worker-plan.js +3 -3
- package/dist/src/models/worker-qualification-policy.js +54 -0
- package/dist/src/models/worker-selection-policy.js +2 -1
- package/dist/src/providers/deployment-lock.js +77 -0
- package/dist/src/providers/deployment-ownership.d.mts +12 -2
- package/dist/src/providers/deployment-ownership.mjs +115 -21
- package/dist/src/providers/deployment-preservation.d.mts +2 -1
- package/dist/src/providers/deployment-preservation.mjs +3 -0
- package/dist/src/providers/provider-definitions.js +4 -0
- package/dist/src/providers/skill-ownership.d.mts +1 -0
- package/dist/src/providers/transformation-receipt-integration.js +4 -2
- package/dist/src/providers/transformation-receipt.js +4 -2
- package/dist/src/serve/worker-invocation-preparation.js +3 -1
- package/dist/src/serve/worker-invocation.js +6 -2
- package/dist/src/skills/run.js +5 -0
- package/dist/src/smiths/context-pipeline/workspace-audit.js +34 -17
- package/dist/src/smiths/context-pipeline/workspace-context-shared.js +12 -6
- package/dist/src/smiths/context-pipeline/workspace-doctor.js +44 -4
- package/dist/src/smiths/context-pipeline/workspace-document.js +5 -2
- package/dist/src/smiths/context-pipeline/workspace-migration.js +2 -1
- package/dist/src/smiths/hook-bridge/codex-translator.js +150 -92
- package/dist/src/smiths/hook-bridge/codex-trust.js +50 -0
- package/dist/src/smiths/hook-bridge/factory-hook-config.js +132 -0
- package/dist/src/smiths/hook-bridge/factory-translator.js +88 -33
- package/dist/src/smiths/hook-bridge/hermes-translator.js +3 -1
- package/dist/src/smiths/hook-bridge/index.js +3 -3
- package/dist/src/smiths/hook-bridge/loader.js +10 -2
- package/dist/src/smiths/hook-bridge/prompt-discovery-gaps.js +5 -0
- package/dist/src/storage/workspace-permissions-health.js +64 -0
- package/dist/src/storage/workspace-permissions.js +51 -0
- package/package.json +9 -2
- package/schemas/models/model-config-compatibility.v1.schema.json +4 -0
- package/tools/agents/deploy-agents.mjs +15 -0
- package/tools/agents/providers/base-contract.mjs +7 -1
- package/tools/agents/providers/base-files.mjs +2 -1
- package/tools/agents/providers/base-flat-artifacts.mjs +6 -3
- package/tools/agents/providers/base-inventory.mjs +35 -13
- package/tools/agents/providers/base-models-platforms.mjs +3 -3
- package/tools/agents/providers/base-skill-copy.mjs +2 -0
- package/tools/agents/providers/base.mjs +1 -1
- package/tools/agents/providers/bound-rules-pointer.mjs +21 -0
- package/tools/agents/providers/claude-post-deploy.mjs +9 -5
- package/tools/agents/providers/codex-post-deploy.mjs +10 -0
- package/tools/agents/providers/conductor-data-guard.mjs +35 -11
- package/tools/agents/providers/factory-hooks.mjs +43 -0
- package/tools/agents/providers/factory.mjs +4 -91
- package/tools/agents/providers/muse-hooks.mjs +6 -41
- package/tools/agents/providers/muse-prompt-discovery.mjs +18 -0
- package/tools/agents/providers/packaged-codex-agents.mjs +48 -0
- package/tools/agents/providers/provider-prepare-coordinator.mjs +15 -10
- package/tools/agents/providers/rule-delivery-surface.mjs +10 -7
- package/tools/agents/providers/rule-deployment-commit.mjs +10 -0
- package/tools/agents/providers/rule-presentation.mjs +6 -5
- package/tools/agents/providers/rule-projection.mjs +10 -2
- package/tools/agents/providers/rule-startup.mjs +8 -1
- package/tools/agents/providers/stale-artifact-prune.mjs +9 -8
- package/tools/cli/decision-offload-report.mjs +7 -2
- package/tools/plugin/issue-template-copies.mjs +24 -0
- package/tools/plugin/package-plugins.mjs +11 -3
- package/tools/ralph-external/lib/factory-adapter.mjs +7 -8
- package/tools/ralph-external/lib/worker-artifacts.mjs +4 -2
- package/tools/ralph-external/lib/worker-capture.mjs +157 -0
- package/tools/ralph-external/lib/worker-final.mjs +43 -8
- package/tools/ralph-external/lib/worker-health.mjs +3 -0
- package/tools/ralph-external/lib/worker-invocation-processes.mjs +9 -6
- package/tools/ralph-external/lib/worker-launch-cli.mjs +20 -2
- package/tools/ralph-external/lib/worker-process-identity.mjs +30 -0
- package/tools/ralph-external/lib/worker-prompt.mjs +35 -0
- package/tools/ralph-external/lib/worker-retry-evidence.mjs +87 -6
- package/tools/ralph-external/lib/worker-run-directory-refusal.mjs +8 -0
- package/tools/ralph-external/lib/worker-termination.mjs +56 -6
- package/tools/ralph-external/process-monitor.mjs +12 -18
- package/tools/ralph-external/session-launcher.mjs +53 -36
- package/vscode-extension/schemas/aiwg.config.v1.json +15 -0
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
// Authenticate predecessor records and optionally recheck owned descendant absence.
|
|
2
|
-
import { join } from 'node:path';
|
|
2
|
+
import { dirname, join, resolve } from 'node:path';
|
|
3
3
|
import { importImpl } from '../../_resolve-impl.mjs';
|
|
4
|
-
import { lstat } from 'node:fs/promises';
|
|
5
|
-
import { boundedPrivateRead } from './worker-inputs.mjs';
|
|
4
|
+
import { lstat, readdir, realpath } from 'node:fs/promises';
|
|
5
|
+
import { boundedPrivateRead, withWorkerPath } from './worker-inputs.mjs';
|
|
6
|
+
import { resolveRetryReference } from './worker-launch-cli.mjs';
|
|
7
|
+
import { verifyWorkerCaptureSeal } from './worker-capture.mjs';
|
|
6
8
|
import { realBeneath, stableTaskChainDigest, assertStopBeforeRetry, publishWorkerRecord, UNBOUND_RETRY_EVIDENCE_CODE } from '../session-launcher.mjs';
|
|
7
9
|
import { recheckWorkerTermination } from './worker-termination.mjs';
|
|
8
10
|
|
|
@@ -16,7 +18,15 @@ async function matchesLegacyTask(record, plan) {
|
|
|
16
18
|
brief: record.prompt.path, workdir: record.cwd, final_output: record.paths.final });
|
|
17
19
|
}
|
|
18
20
|
|
|
19
|
-
|
|
21
|
+
async function matchesTaskIdentity(record, plan) {
|
|
22
|
+
if (!record.prompt?.digest || !record.selected?.group || !await sameWorkspace(record.cwd, plan.request.workdir)) return false;
|
|
23
|
+
const oldPlan = { ...plan, request: { ...plan.request, group: record.selected.group },
|
|
24
|
+
invocation: { briefDigest: record.prompt.digest } };
|
|
25
|
+
const digest = await stableTaskChainDigest(oldPlan.request, oldPlan.invocation.briefDigest);
|
|
26
|
+
return (record.taskBindingDigest ?? record.taskDigest) === digest || await matchesLegacyTask(record, oldPlan);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export async function verifyRetryPredecessor(retryOf, { newInvocationPath, inspect, workerWritableRoots, checkDescendants = false, onVerified } = {}) {
|
|
20
30
|
const fail = (reason) => {
|
|
21
31
|
const error = new Error(`Retry predecessor evidence refused: ${reason}`);
|
|
22
32
|
error.code = UNBOUND_RETRY_EVIDENCE_CODE;
|
|
@@ -68,6 +78,9 @@ export async function verifyRetryPredecessor(retryOf, { newInvocationPath, inspe
|
|
|
68
78
|
fail('invocation.json identity does not match retryOf (or is not launcher-written)');
|
|
69
79
|
}
|
|
70
80
|
if (exitRecord?.invocationId !== prevId) fail('exit.json identity does not match retryOf');
|
|
81
|
+
let bindingDigest, correction;
|
|
82
|
+
try { await verifyWorkerCaptureSeal(prevRunDir, invocationRecord, exitRecord, inspect); }
|
|
83
|
+
catch (error) { fail(`capture seal verification failed (${error.message})`); }
|
|
71
84
|
if (newInvocationPath !== undefined) {
|
|
72
85
|
// #2915 review 4 (finding 4): the SAME stable task-chain identity
|
|
73
86
|
// `launchOneWorker` publishes — role/task/group plus the brief CONTENT
|
|
@@ -79,7 +92,18 @@ export async function verifyRetryPredecessor(retryOf, { newInvocationPath, inspe
|
|
|
79
92
|
newPlan = JSON.parse(newPlanBytes.toString('utf8'));
|
|
80
93
|
newTaskDigest = await stableTaskChainDigest(newPlan.request, newPlan.invocation?.briefDigest ?? null);
|
|
81
94
|
} catch { fail('new attempt plan is missing or invalid; cannot bind the retry to a task'); }
|
|
82
|
-
|
|
95
|
+
bindingDigest = newTaskDigest;
|
|
96
|
+
if ((invocationRecord.taskBindingDigest ?? invocationRecord.taskDigest) !== newTaskDigest && !await matchesLegacyTask(invocationRecord, newPlan)) {
|
|
97
|
+
if (retryOf.correction !== true) fail('predecessor task does not match the new attempt (task-chain binding); use --retry-correction for an explicit brief/group correction');
|
|
98
|
+
if (!await matchesTaskIdentity(invocationRecord, newPlan)) {
|
|
99
|
+
fail('correction must retain the predecessor role, task and workspace (task-chain binding)');
|
|
100
|
+
}
|
|
101
|
+
const { qualificationDigest } = await importImpl(import.meta.url, 'models/qualification-digest.mjs');
|
|
102
|
+
correction = {
|
|
103
|
+
oldBriefDigest: invocationRecord.prompt.digest, newBriefDigest: newPlan.invocation.briefDigest,
|
|
104
|
+
oldGroupDigest: qualificationDigest(invocationRecord.selected.group), newGroupDigest: qualificationDigest(newPlan.request.group),
|
|
105
|
+
};
|
|
106
|
+
}
|
|
83
107
|
}
|
|
84
108
|
if (exitRecord.termination !== 'confirmed') {
|
|
85
109
|
let evidence = null;
|
|
@@ -88,16 +112,73 @@ export async function verifyRetryPredecessor(retryOf, { newInvocationPath, inspe
|
|
|
88
112
|
const processRecord = JSON.parse((await boundedPrivateRead(join(prevRunDir, 'process.json'), 65536, inspect, true, true)).toString('utf8'));
|
|
89
113
|
evidence = await recheckWorkerTermination({ processRecord, exitRecord });
|
|
90
114
|
} catch (error) { evidence = { confirmed: false, missing: `readable, private launcher process.json (${error.message})` }; }
|
|
115
|
+
exitRecord = { ...exitRecord, terminationMissing: evidence.missing ?? null,
|
|
116
|
+
...(exitRecord.healthEvidence ? { healthEvidence: { ...exitRecord.healthEvidence, terminationMissing: evidence.missing ?? null } } : {}) };
|
|
91
117
|
if (evidence.confirmed) {
|
|
92
118
|
exitRecord = { ...exitRecord, termination: 'confirmed', descendants: 'none',
|
|
93
119
|
...(exitRecord.health ? { health: { ...exitRecord.health, termination: 'confirmed' } } : {}) };
|
|
94
|
-
await publishWorkerRecord(prevRunDir, 'exit.json', exitRecord, inspect);
|
|
95
120
|
}
|
|
121
|
+
await publishWorkerRecord(prevRunDir, 'exit.json', exitRecord, inspect);
|
|
96
122
|
}
|
|
97
123
|
if (exitRecord.termination !== 'confirmed') {
|
|
98
124
|
assertStopBeforeRetry(exitRecord, { expectedInvocationId: prevId, runDir: prevRunDir, missing: evidence?.missing });
|
|
99
125
|
}
|
|
100
126
|
}
|
|
101
127
|
assertStopBeforeRetry(exitRecord, { expectedInvocationId: prevId });
|
|
128
|
+
onVerified?.({ previousAttemptId: prevId, taskDigest: invocationRecord.taskDigest,
|
|
129
|
+
taskBindingDigest: bindingDigest, ...(correction ? { retryCorrection: correction } : {}) });
|
|
102
130
|
return exitRecord;
|
|
103
131
|
}
|
|
132
|
+
|
|
133
|
+
async function sameWorkspace(left, right) {
|
|
134
|
+
if (typeof left !== 'string' || typeof right !== 'string') return false;
|
|
135
|
+
try { return await realpath(left) === await realpath(right); }
|
|
136
|
+
catch (error) { if (error.code === 'ENOENT') return false; throw error; }
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// Existing capture siblings are the durable inventory, including captures from
|
|
140
|
+
// older launchers. Brief and group changes cannot hide an open task predecessor.
|
|
141
|
+
async function assertNoOpenPredecessor({ runDir, captureRoot, saved, inspect, retryOf, workerWritableRoots }) {
|
|
142
|
+
const taskDigest = await stableTaskChainDigest(saved.request, saved.invocation.briefDigest);
|
|
143
|
+
const roots = new Set([dirname(runDir), ...(captureRoot ? [captureRoot] : []), ...(retryOf ? [dirname(retryOf.runDir)] : [])]);
|
|
144
|
+
for (const root of roots) {
|
|
145
|
+
if (!await inspect(root, 'directory')) continue;
|
|
146
|
+
const entries = await withWorkerPath(root, target => readdir(target, { withFileTypes: true }));
|
|
147
|
+
for (const entry of entries) {
|
|
148
|
+
if (!entry.isDirectory()) continue;
|
|
149
|
+
const previousDir = join(root, entry.name);
|
|
150
|
+
if (resolve(previousDir) === resolve(runDir)) continue;
|
|
151
|
+
const filename = join(previousDir, 'invocation.json');
|
|
152
|
+
if (!await inspect(filename, 'file')) continue;
|
|
153
|
+
const record = JSON.parse((await boundedPrivateRead(filename, 1048576, inspect, true, true)).toString('utf8'));
|
|
154
|
+
if (record.origin !== 'launcher' || ((record.taskBindingDigest ?? record.taskDigest) !== taskDigest
|
|
155
|
+
&& !await matchesTaskIdentity(record, saved))) continue;
|
|
156
|
+
try {
|
|
157
|
+
// Reuse the authenticated owned-stop loader, including missing exits.
|
|
158
|
+
await verifyRetryPredecessor({ invocationId: record.invocationId, runDir: previousDir }, { inspect, workerWritableRoots });
|
|
159
|
+
} catch (cause) {
|
|
160
|
+
const error = new Error(`Worker launch refused: open predecessor ${record.invocationId} at ${previousDir}; termination is not confirmed. Retry with --retry-of-run-dir and owned-stop proof.`, { cause });
|
|
161
|
+
error.code = 'OPEN_TASK_PREDECESSOR';
|
|
162
|
+
error.previousAttemptId = record.invocationId;
|
|
163
|
+
error.runDir = previousDir;
|
|
164
|
+
throw error;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export async function prepareWorkerRetry(options, { saved, inspect, workerWritableRoots }) {
|
|
171
|
+
let evidence = null;
|
|
172
|
+
const retryOf = options.retryOf === undefined ? undefined : await resolveRetryReference(options.retryOf, { inspect });
|
|
173
|
+
if (retryOf !== undefined) {
|
|
174
|
+
await verifyRetryPredecessor(retryOf, { newInvocationPath: options.invocationPath, inspect, workerWritableRoots,
|
|
175
|
+
checkDescendants: options.checkDescendants, onVerified: value => { evidence = value; } });
|
|
176
|
+
}
|
|
177
|
+
await assertNoOpenPredecessor({ ...options, saved, inspect, retryOf, workerWritableRoots });
|
|
178
|
+
return evidence;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
export function workerRetryRecordFields(evidence) {
|
|
182
|
+
return { ...(evidence ? { taskBindingDigest: evidence.taskBindingDigest,
|
|
183
|
+
...(evidence.retryCorrection ? { retryCorrection: evidence.retryCorrection } : {}) } : {}) };
|
|
184
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// Format bounded, actionable diagnostics for a refused worker run directory.
|
|
2
|
+
export function workerRunDirectoryRefusal(entries) {
|
|
3
|
+
const reason = 'Worker run directory must be fresh, empty, private and owned';
|
|
4
|
+
if (!entries.length) return reason;
|
|
5
|
+
const names = entries.toSorted().slice(0, 5).map(name => JSON.stringify(name)).join(', ');
|
|
6
|
+
const remaining = entries.length > 5 ? ` (+${entries.length - 5} more)` : '';
|
|
7
|
+
return `${reason}. Unexpected entries: ${names}${remaining}. Keep the plan and other files outside the run dir, or pass a new run dir.`;
|
|
8
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
// Confirm owned containment is empty independently of semantic observer coverage.
|
|
2
|
+
import { readdirSync, readFileSync } from 'node:fs';
|
|
2
3
|
import { sampleWorkerIdentity, isSafeWorkerGroupTarget } from '../process-monitor.mjs';
|
|
3
4
|
import { getWorkerIsolationStatus } from './worker-isolation-status.mjs';
|
|
4
5
|
import { scanWorkerInvocationProcesses } from './worker-invocation-processes.mjs';
|
|
@@ -9,7 +10,7 @@ const TERMINATION_MAX_ATTEMPTS = 21;
|
|
|
9
10
|
|
|
10
11
|
export function observeWorkerTermination({ mode, native, workerExited, identity,
|
|
11
12
|
supervisor = sampleWorkerIdentity(process.pid), kill = process.kill, invocationId,
|
|
12
|
-
scan = scanWorkerInvocationProcesses, deadline, now = () => performance.now() } = {}) {
|
|
13
|
+
scan = scanWorkerInvocationProcesses, groupStates = sampleGroupStates, deadline, now = () => performance.now() } = {}) {
|
|
13
14
|
if (mode === 'systemd-unit') {
|
|
14
15
|
const exited = workerExited === true || [1, 2, 3].includes(native?.execMainCode);
|
|
15
16
|
return { confirmed: exited && native?.active === false && native?.cgroupEmpty === true,
|
|
@@ -22,22 +23,71 @@ export function observeWorkerTermination({ mode, native, workerExited, identity,
|
|
|
22
23
|
|| !isSafeWorkerGroupTarget(identity.pgid, supervisor)) {
|
|
23
24
|
return { confirmed: false, missing: 'launcher-owned process group identity on this host and boot' };
|
|
24
25
|
}
|
|
25
|
-
|
|
26
|
+
let groupEmpty = false;
|
|
27
|
+
try {
|
|
28
|
+
kill(-identity.pgid, 0);
|
|
29
|
+
// Signal 0 also reaches zombies. A reaper that never waits (a container's
|
|
30
|
+
// PID 1) can leave killed members as zombies indefinitely; a group whose
|
|
31
|
+
// remaining members are all zombies has no live process (#3853).
|
|
32
|
+
// Absence from /proc is never proof; only observed zombies explaining
|
|
33
|
+
// signal 0, with no live or unreadable member, count as an empty group.
|
|
34
|
+
const states = groupStates(identity.pgid);
|
|
35
|
+
groupEmpty = !!states && states.zombies > 0 && states.live === 0 && states.unreadable === 0;
|
|
36
|
+
}
|
|
26
37
|
catch (error) {
|
|
27
38
|
// Pass the recorded leader so the marker scan can tell a parallel
|
|
28
39
|
// hardened (non-dumpable) worker's tree apart from a genuine escapee via
|
|
29
40
|
// readable stat/cgroup links instead of failing closed on every
|
|
30
41
|
// unreadable post-start process.
|
|
31
42
|
if (error.code === 'ESRCH') {
|
|
32
|
-
//
|
|
33
|
-
// leaves the
|
|
43
|
+
// A standalone observation gets one scan, at most 2 s. An explicit
|
|
44
|
+
// deadline leaves the shared budget and retries to its caller.
|
|
34
45
|
return scan({ invocationId, startTicks: identity.startTicks, uid: identity.uid, now,
|
|
35
46
|
deadline: deadline ?? now() + TERMINATION_BUDGET_MS,
|
|
36
47
|
workerPid: identity.pid, workerPgid: identity.pgid, workerSession: identity.sessionId });
|
|
37
48
|
}
|
|
38
49
|
return { confirmed: false, missing: `empty owned process group (signal-0 returned ${error.code ?? 'unknown'})` };
|
|
39
50
|
}
|
|
40
|
-
|
|
51
|
+
if (groupEmpty) {
|
|
52
|
+
return scan({ invocationId, startTicks: identity.startTicks, uid: identity.uid, now,
|
|
53
|
+
deadline: deadline ?? now() + TERMINATION_BUDGET_MS,
|
|
54
|
+
workerPid: identity.pid, workerPgid: identity.pgid, workerSession: identity.sessionId });
|
|
55
|
+
}
|
|
56
|
+
return { confirmed: false, missing: 'empty owned process group (signal-0 still finds members)', retryable: true };
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** Count a process group's members by /proc state: zombies, live and unreadable. */
|
|
60
|
+
export function sampleGroupStates(pgid) {
|
|
61
|
+
if (!Number.isSafeInteger(pgid) || pgid <= 0 || process.platform !== 'linux') return null;
|
|
62
|
+
const states = { zombies: 0, live: 0, unreadable: 0 };
|
|
63
|
+
let entries;
|
|
64
|
+
try { entries = readdirSync('/proc'); } catch { return null; }
|
|
65
|
+
for (const entry of entries) {
|
|
66
|
+
if (!/^\d+$/.test(entry)) continue;
|
|
67
|
+
let stat;
|
|
68
|
+
try { stat = readFileSync(`/proc/${entry}/stat`, 'utf8'); }
|
|
69
|
+
catch (error) { if (error.code !== 'ENOENT' && error.code !== 'ESRCH') states.unreadable += 1; continue; }
|
|
70
|
+
const fields = stat.slice(stat.lastIndexOf(')') + 2).split(/\s+/);
|
|
71
|
+
if (Number(fields[2]) !== pgid) continue;
|
|
72
|
+
if (fields[0] === 'Z') states.zombies += 1; else states.live += 1;
|
|
73
|
+
}
|
|
74
|
+
return states;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// Share the exit-time budget across transient kernel observations; each scan
|
|
78
|
+
// gets all remaining time so a large inventory is never restarted at 100 ms.
|
|
79
|
+
export async function settleWorkerTermination({ now = () => performance.now(),
|
|
80
|
+
wait = ms => new Promise(resolve => setTimeout(resolve, ms)), ...options } = {}) {
|
|
81
|
+
const deadline = now() + TERMINATION_BUDGET_MS;
|
|
82
|
+
let evidence;
|
|
83
|
+
for (let attempt = 0; attempt < TERMINATION_MAX_ATTEMPTS; attempt++) {
|
|
84
|
+
if (evidence && now() >= deadline) return evidence;
|
|
85
|
+
evidence = observeWorkerTermination({ ...options, now, deadline });
|
|
86
|
+
if (evidence.confirmed || evidence.markerPresent || !evidence.retryable
|
|
87
|
+
|| now() >= deadline || attempt === TERMINATION_MAX_ATTEMPTS - 1) return evidence;
|
|
88
|
+
await wait(Math.min(TERMINATION_ATTEMPT_MS, Math.max(0, deadline - now())));
|
|
89
|
+
}
|
|
90
|
+
return evidence;
|
|
41
91
|
}
|
|
42
92
|
|
|
43
93
|
export function terminationRemedy(result, runDir) {
|
|
@@ -79,7 +129,7 @@ export async function recheckWorkerTermination({ processRecord, exitRecord,
|
|
|
79
129
|
catch { /* Unavailable is never empty. */ }
|
|
80
130
|
}
|
|
81
131
|
evidence = observe({ mode: processRecord.isolation, native, identity, invocationId: processRecord.invocationId,
|
|
82
|
-
deadline
|
|
132
|
+
deadline, now,
|
|
83
133
|
workerExited: Number.isInteger(exitRecord.exitCode) && exitRecord.exitCode >= 0 && exitRecord.exitCode <= 255
|
|
84
134
|
|| exitRecord.captureCoverage === 'complete' && exitRecord.workerTermination === 'confirmed' && /^SIG[A-Z0-9]+$/.test(exitRecord.signal ?? '') });
|
|
85
135
|
if (evidence.confirmed || evidence.markerPresent || now() >= deadline || attempt === TERMINATION_MAX_ATTEMPTS - 1) return evidence;
|
|
@@ -10,14 +10,14 @@
|
|
|
10
10
|
import { fileURLToPath } from 'node:url';
|
|
11
11
|
import { EventEmitter } from 'events';
|
|
12
12
|
import { execFileSync } from 'child_process';
|
|
13
|
-
import { existsSync, readFileSync, writeFileSync, mkdirSync,
|
|
14
|
-
import { hostname } from 'node:os';
|
|
13
|
+
import { existsSync, readFileSync, writeFileSync, mkdirSync, readdirSync } from 'fs';
|
|
15
14
|
import { join, dirname } from 'path';
|
|
16
15
|
import { constants } from 'node:fs';
|
|
17
16
|
import { open, opendir, rename, unlink } from 'node:fs/promises';
|
|
18
17
|
import { createHash, randomUUID } from 'node:crypto';
|
|
19
18
|
import path from 'node:path';
|
|
20
19
|
import { createWorkerHealthObserver } from './lib/worker-health.mjs';
|
|
20
|
+
import { sampleWorkerProcIdentity } from './lib/worker-process-identity.mjs';
|
|
21
21
|
|
|
22
22
|
// This module is loaded standalone in some contexts (e.g. staged/partial
|
|
23
23
|
// installs, or copied in isolation for a test) without its sibling
|
|
@@ -68,22 +68,16 @@ if (importImpl) {
|
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
-
/**
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
return { pid, pgid: Number(fields[2]), uid, parentPid: Number(fields[1]), sessionId: Number(fields[3]),
|
|
82
|
-
host: hostname(), bootId, startTicks: fields[19], executable, state: fields[0],
|
|
83
|
-
// /proc stat fields 14/15 are utime/stime; 16/17 are cutime/cstime
|
|
84
|
-
// accumulated for waited-for children, including child-heavy CLIs.
|
|
85
|
-
cpuTicks: Number(fields[11]) + Number(fields[12]) + Number(fields[13]) + Number(fields[14]) };
|
|
86
|
-
} catch { return null; }
|
|
71
|
+
/**
|
|
72
|
+
* Side-effect-free Linux sample. Unknown identity never grants signal authority.
|
|
73
|
+
* An exited, unreaped child (zombie without /proc/<pid>/exe) counts as gone, so
|
|
74
|
+
* liveness, group-member and ancestry checks never treat it as running. Only
|
|
75
|
+
* spawn-time identity capture passes `includeExited` to keep a fast-exiting
|
|
76
|
+
* worker's birth identity (#3835).
|
|
77
|
+
*/
|
|
78
|
+
export function sampleWorkerIdentity(pid, { includeExited = false } = {}) {
|
|
79
|
+
const identity = sampleWorkerProcIdentity(pid);
|
|
80
|
+
return identity && (includeExited || identity.executable !== null) ? identity : null;
|
|
87
81
|
}
|
|
88
82
|
|
|
89
83
|
export function sameWorkerIdentity(expected, actual) {
|
|
@@ -51,10 +51,12 @@ export { assertManagedWorkerLaunch } from './lib/managed-worker-attempt.mjs';
|
|
|
51
51
|
import { buildSessionEnvironment } from './lib/session-environment.mjs';
|
|
52
52
|
import { withWorkerPath, boundedPrivateRead } from './lib/worker-inputs.mjs';
|
|
53
53
|
import { collectWorkerFinal } from './lib/worker-final.mjs';
|
|
54
|
-
import {
|
|
55
|
-
import {
|
|
56
|
-
import {
|
|
57
|
-
import {
|
|
54
|
+
import { workerRunDirectoryRefusal } from './lib/worker-run-directory-refusal.mjs';
|
|
55
|
+
import { workerPromptBrief } from './lib/worker-prompt.mjs';
|
|
56
|
+
import { prepareWorkerRetry, workerRetryRecordFields } from './lib/worker-retry-evidence.mjs';
|
|
57
|
+
import { settleWorkerTermination, terminationRemedy } from './lib/worker-termination.mjs';
|
|
58
|
+
import { WorkerCaptureOwner, assertWorkerCapturePathsAvailable } from './lib/worker-capture.mjs';
|
|
59
|
+
import { buildWorkerInvocationEnvironment } from './lib/worker-invocation-processes.mjs';
|
|
58
60
|
import { launcherRecoveryEvidence, observeLauncherRecoveryOutcome, recordLauncherRecoveryHint } from './lib/launcher-recovery-evidence.mjs';
|
|
59
61
|
export { observeLauncherRecoveryOutcome } from './lib/launcher-recovery-evidence.mjs';
|
|
60
62
|
import { publishWorkerUnitExit, readRecordedWorkerUnitStop } from './lib/worker-unit-cleanup.mjs';
|
|
@@ -406,8 +408,9 @@ async function launchOneWorker(owner, options) {
|
|
|
406
408
|
const runExists = await inspect(runDir, 'directory');
|
|
407
409
|
if (runExists) {
|
|
408
410
|
const stat = await lstat(runDir);
|
|
409
|
-
|
|
410
|
-
|
|
411
|
+
const entries = stat.uid === process.getuid() && !(stat.mode & 0o077) ? await readdir(runDir) : [];
|
|
412
|
+
if (stat.uid !== process.getuid() || (stat.mode & 0o077) || entries.length) {
|
|
413
|
+
throw new Error(workerRunDirectoryRefusal(entries));
|
|
411
414
|
}
|
|
412
415
|
}
|
|
413
416
|
const writableRoots = inputs.drivers[invocation.selected.cli].qualification.installation?.workerWritableRoots ?? [invocation.cwd];
|
|
@@ -426,12 +429,8 @@ async function launchOneWorker(owner, options) {
|
|
|
426
429
|
// `writableRoots` is already computed above for the run-directory check)
|
|
427
430
|
// is what it takes to pass the SAME production-resolved roots into this
|
|
428
431
|
// check too.
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
const exitRecord = await verifyRetryPredecessor(await resolveRetryReference(options.retryOf, { inspect }),
|
|
432
|
-
{ newInvocationPath: options?.invocationPath, inspect, workerWritableRoots: writableRoots, checkDescendants: options.checkDescendants });
|
|
433
|
-
verifiedPreviousAttemptId = exitRecord.invocationId;
|
|
434
|
-
}
|
|
432
|
+
options = { ...options, retryEvidence: await prepareWorkerRetry(options, { saved, inspect, workerWritableRoots: writableRoots }) };
|
|
433
|
+
const verifiedPreviousAttemptId = options.retryEvidence?.previousAttemptId ?? null;
|
|
435
434
|
const paths = (await importImpl(import.meta.url, 'serve/worker-invocation-paths.js')).workerOutputPaths(invocation);
|
|
436
435
|
if (new Set(Object.values(paths)).size !== Object.keys(paths).length || Object.values(paths).some(filename =>
|
|
437
436
|
filename === options.invocationPath || filename === invocation.briefPath
|
|
@@ -440,6 +439,7 @@ async function launchOneWorker(owner, options) {
|
|
|
440
439
|
'stdout.log', 'stdout.events.jsonl', 'stderr.log', '.launch-owner'].some(name => filename === join(runDir, name)))) {
|
|
441
440
|
throw new Error('Worker output paths must be distinct from trusted metadata, capture files and artifact- paths');
|
|
442
441
|
}
|
|
442
|
+
await assertWorkerCapturePathsAvailable(paths, inspect, { runDir, writableRoots: [invocation.cwd, ...writableRoots] });
|
|
443
443
|
for (const filename of Object.values(paths)) {
|
|
444
444
|
if (await inspect(filename, 'output')) throw new Error('Fresh worker output paths are required');
|
|
445
445
|
if (!await inspect(dirname(filename), 'directory')) throw new Error('Worker output parent is missing');
|
|
@@ -449,7 +449,7 @@ async function launchOneWorker(owner, options) {
|
|
|
449
449
|
// Frame stdin before any spawn: brief-json delivers a conductor-built params
|
|
450
450
|
// document on the stdin pipe, never brief text in argv (#2911).
|
|
451
451
|
const { workerStdinBytes } = await importImpl(import.meta.url, 'serve/worker-stdin-frame.mjs');
|
|
452
|
-
const stdinBytes = workerStdinBytes(invocation, brief, inputs.drivers[invocation.selected.cli]);
|
|
452
|
+
const stdinBytes = workerStdinBytes(invocation, workerPromptBrief(brief, paths.final), inputs.drivers[invocation.selected.cli]);
|
|
453
453
|
let gate = (options.checkDispatch ?? checkWorkerDispatch)({ config: inputs.snapshot.config,
|
|
454
454
|
paths: await Promise.all([invocation.cwd, runDir].map(workerDispatchPath)) });
|
|
455
455
|
if (!gate.ok) throw workerDispatchRefusal(gate);
|
|
@@ -517,7 +517,7 @@ async function launchOneWorker(owner, options) {
|
|
|
517
517
|
// unconditionally here is exactly as safe as computing it conditionally
|
|
518
518
|
// was unsafe — this file no longer has two places that both decide
|
|
519
519
|
// "is this gated" and can disagree.
|
|
520
|
-
const taskDigest = await stableTaskChainDigest(saved.request, invocation.briefDigest);
|
|
520
|
+
const taskDigest = options.retryEvidence?.taskDigest ?? await stableTaskChainDigest(saved.request, invocation.briefDigest);
|
|
521
521
|
const dispatchClockNow = () => options.scopedBreaker?.nowMs?.() ?? Number(process.hrtime.bigint()) / 1e6;
|
|
522
522
|
const dispatchGuard = options.dispatchGuard ?? {
|
|
523
523
|
nowMs: dispatchClockNow,
|
|
@@ -639,7 +639,8 @@ async function launchOneWorker(owner, options) {
|
|
|
639
639
|
const profile = inputs.drivers[invocation.selected.cli].qualification.adapter.invocationProfiles[invocation.selected.profileRef];
|
|
640
640
|
const captures = { stdout: join(runDir, profile.health?.outputFraming === 'jsonl' ? 'stdout.events.jsonl' : 'stdout.log'),
|
|
641
641
|
stderr: join(runDir, 'stderr.log') };
|
|
642
|
-
const
|
|
642
|
+
const captureOwner = new WorkerCaptureOwner({ runDir, paths, captures, inspect, invocationId });
|
|
643
|
+
const writeRecord = captureOwner.writer(options.publishRecord ?? publishWorkerRecord, publishWorkerRecord);
|
|
643
644
|
const publishFailures = [];
|
|
644
645
|
let publishing = Promise.resolve();
|
|
645
646
|
// Each write must stay independent: one rejected publish must never block
|
|
@@ -668,7 +669,7 @@ async function launchOneWorker(owner, options) {
|
|
|
668
669
|
let outcome;
|
|
669
670
|
let artifacts;
|
|
670
671
|
try {
|
|
671
|
-
artifacts = await materializeWorkerArtifacts(invocation, runDir);
|
|
672
|
+
artifacts = await materializeWorkerArtifacts(invocation, runDir, { brief, invocationId });
|
|
672
673
|
const displayArgv = artifacts.argv.map((token, i) => i === 0 ? token : `<argument:${bytesDigest(token)}>`);
|
|
673
674
|
// #2915 review 4 (finding 4): a STABLE task-chain identity, never the
|
|
674
675
|
// raw request object — `qualificationDigest(saved.request)` included
|
|
@@ -685,6 +686,7 @@ async function launchOneWorker(owner, options) {
|
|
|
685
686
|
// owned, launcher-written, confirmed-terminal evidence for this exact
|
|
686
687
|
// task — never from an unverified caller claim.
|
|
687
688
|
previousAttemptId: verifiedPreviousAttemptId,
|
|
689
|
+
...workerRetryRecordFields(options.retryEvidence),
|
|
688
690
|
requestId: invocationId, taskDigest, role: saved.request.role,
|
|
689
691
|
...(options.managedAdmission ? { attempt: options.attempt } : {}),
|
|
690
692
|
selected: invocation.selected, planDigest: qualificationDigest(saved), invocationDigest: qualificationDigest(invocation),
|
|
@@ -693,9 +695,9 @@ async function launchOneWorker(owner, options) {
|
|
|
693
695
|
// Retain the legacy digest binding while naming both argv stages explicitly.
|
|
694
696
|
argvDigest: qualificationDigest(invocation.argv), placeholderArgvDigest: qualificationDigest(invocation.argv),
|
|
695
697
|
executedArgvDigest: qualificationDigest(artifacts.argv),
|
|
696
|
-
artifacts:
|
|
698
|
+
artifacts: artifacts.declarations.map(artifact => ({ name: artifact.name,
|
|
697
699
|
byteLength: Buffer.byteLength(artifact.content), sha256: bytesDigest(artifact.content) })),
|
|
698
|
-
envNames:
|
|
700
|
+
envNames: buildWorkerInvocationEnvironment(invocation.envNames, invocationId, {}, invocation).envNames, stdin: invocation.stdin,
|
|
699
701
|
prompt: { path: invocation.briefPath, digest: invocation.briefDigest }, cwd: invocation.cwd,
|
|
700
702
|
worktree: { path: invocation.cwd, baseRevision: null }, paths, captures, outputFraming: profile.health?.outputFraming ?? 'opaque',
|
|
701
703
|
health: invocation.health ?? null, transport: invocation.transport,
|
|
@@ -706,7 +708,7 @@ async function launchOneWorker(owner, options) {
|
|
|
706
708
|
// All captures (including the reserved final) open successfully BEFORE spawn.
|
|
707
709
|
for (const filename of [...Object.values(paths), ...Object.values(captures)]) {
|
|
708
710
|
const handle = await withWorkerPath(filename, target => (options.openCapture ?? open)(target, constants.O_RDWR | constants.O_CREAT | constants.O_EXCL | constants.O_NOFOLLOW, 0o600));
|
|
709
|
-
handles.push(handle);
|
|
711
|
+
handles.push(handle); await captureOwner.reserveOutput(filename);
|
|
710
712
|
}
|
|
711
713
|
// Recheck policy, prompt, installation and exact bindings after file preparation.
|
|
712
714
|
inputs = await loadInputs();
|
|
@@ -715,7 +717,7 @@ async function launchOneWorker(owner, options) {
|
|
|
715
717
|
paths: await Promise.all([invocation.cwd, runDir].map(workerDispatchPath)) });
|
|
716
718
|
if (!gate.ok) throw workerDispatchRefusal(gate);
|
|
717
719
|
if (bytesDigest(await boundedPrivateRead(invocation.briefPath, 262144, inspect)) !== invocation.briefDigest) throw new Error('Worker prompt changed before spawn');
|
|
718
|
-
const environment = buildWorkerInvocationEnvironment(invocation.envNames, invocationId);
|
|
720
|
+
const environment = buildWorkerInvocationEnvironment(invocation.envNames, invocationId, process.env, invocation);
|
|
719
721
|
const baselineContent = await sampleOwnedWorktreeContent(invocation.cwd, { files: options.healthArtifacts });
|
|
720
722
|
// #2915 round 8 (D2, replaces the former "debit immediately before this
|
|
721
723
|
// call" comment): the ledger debit now happens INSIDE the dispatch-
|
|
@@ -909,6 +911,7 @@ async function launchOneWorker(owner, options) {
|
|
|
909
911
|
await inspect(runDir, 'directory');
|
|
910
912
|
await withWorkerPath(runDir, async target => { const handle = await open(target, constants.O_RDONLY | constants.O_DIRECTORY | constants.O_NOFOLLOW);
|
|
911
913
|
try { await handle.chmod(0o700); } finally { await handle.close(); } });
|
|
914
|
+
await captureOwner.finish();
|
|
912
915
|
}
|
|
913
916
|
}
|
|
914
917
|
}
|
|
@@ -949,7 +952,8 @@ async function captureOneWorker(owner, ctx) {
|
|
|
949
952
|
const { child, outcome, invocation, invocationId, supervisor, launchTime, monotonicStart, publish, paths, handles, options,
|
|
950
953
|
canaryDeadlineMs = null, canaryNowMs = () => Date.now(), recoveryGated = false } = ctx;
|
|
951
954
|
const hasTransport = outcome.mode === 'systemd-unit' || outcome.transportSupervisor;
|
|
952
|
-
|
|
955
|
+
// Spawn-time capture keeps a fast-exiting worker's identity (#3835).
|
|
956
|
+
const sampleIdentity = options.sampleIdentity ?? (pid => sampleWorkerIdentity(pid, { includeExited: true }));
|
|
953
957
|
// Separate hook from `sampleIdentity` (the worker-side sampler): this one
|
|
954
958
|
// samples the launcher's own trusted transport child, never a worker PID,
|
|
955
959
|
// and tests need to control the two independently (e.g. the transport
|
|
@@ -1138,8 +1142,10 @@ async function captureOneWorker(owner, ctx) {
|
|
|
1138
1142
|
const native = outcome.unit ? readNative() ?? readRecordedWorkerUnitStop(outcome, { native: true }) : null;
|
|
1139
1143
|
const members = identity ? sampleWorkerGroup(identity.pgid) : null;
|
|
1140
1144
|
// Require positive kernel evidence of owned containment being empty.
|
|
1141
|
-
const
|
|
1142
|
-
|
|
1145
|
+
const terminationEvidence = outcome.mode !== 'systemd-unit' && child.pid === undefined
|
|
1146
|
+
? { confirmed: true, missing: null } : await settleWorkerTermination({ mode: outcome.mode, native,
|
|
1147
|
+
workerExited: sawExit, identity, supervisor, invocationId });
|
|
1148
|
+
const confirmed = terminationEvidence.confirmed;
|
|
1143
1149
|
// `worker-exit.json`/`worker-identity.json` are written into a directory
|
|
1144
1150
|
// the worker itself can reach (same UID, no filesystem confinement), so a
|
|
1145
1151
|
// worker can plant either file before the trusted transport ever writes
|
|
@@ -1175,7 +1181,7 @@ async function captureOneWorker(owner, ctx) {
|
|
|
1175
1181
|
: outcome.mode === 'systemd-unit' && native?.execMainCode === 1 ? native.execMainStatus : waitCode;
|
|
1176
1182
|
const result = { invocationId, exitCode, signal: resultSignal,
|
|
1177
1183
|
endedAt: new Date().toISOString(), termination: confirmed ? 'confirmed' : 'uncertain',
|
|
1178
|
-
descendants: confirmed ? 'none' : 'unknown', timedOut: resultTimedOut,
|
|
1184
|
+
terminationMissing: terminationEvidence.missing, descendants: confirmed ? 'none' : 'unknown', timedOut: resultTimedOut,
|
|
1179
1185
|
cancelled: stopReason === 'CANCELLED', stopReason, errorCode: errorCode ?? null, capturedBytes: Math.min(total, output.length),
|
|
1180
1186
|
// Unauthenticated: reported by the worker-writable transport record, not
|
|
1181
1187
|
// kernel-observed. Never used above for exitCode/signal/termination.
|
|
@@ -1547,7 +1553,8 @@ async function launchOneWorkerBaseline(owner, options, ctx) {
|
|
|
1547
1553
|
const profile = inputs.drivers[invocation.selected.cli].qualification.adapter.invocationProfiles[invocation.selected.profileRef];
|
|
1548
1554
|
const captures = { stdout: join(runDir, profile.health?.outputFraming === 'jsonl' ? 'stdout.events.jsonl' : 'stdout.log'),
|
|
1549
1555
|
stderr: join(runDir, 'stderr.log') };
|
|
1550
|
-
const
|
|
1556
|
+
const captureOwner = new WorkerCaptureOwner({ runDir, paths, captures, inspect, invocationId });
|
|
1557
|
+
const writeRecord = captureOwner.writer(options.publishRecord ?? publishWorkerRecord, publishWorkerRecord);
|
|
1551
1558
|
const publishFailures = [];
|
|
1552
1559
|
let publishing = Promise.resolve();
|
|
1553
1560
|
const artifactLifecycle = new WorkerArtifactLifecycle(invocation, invocationId);
|
|
@@ -1562,10 +1569,11 @@ async function launchOneWorkerBaseline(owner, options, ctx) {
|
|
|
1562
1569
|
let artifacts;
|
|
1563
1570
|
let managedSpawnAttempted = false;
|
|
1564
1571
|
try {
|
|
1565
|
-
artifacts = await materializeWorkerArtifacts(invocation, runDir);
|
|
1572
|
+
artifacts = await materializeWorkerArtifacts(invocation, runDir, { brief: ctx.brief, invocationId });
|
|
1566
1573
|
const displayArgv = artifacts.argv.map((token, i) => i === 0 ? token : `<argument:${bytesDigest(token)}>`);
|
|
1567
1574
|
await publish('invocation.json', { version: 1, origin: 'launcher', invocationId, attemptId: invocationId,
|
|
1568
|
-
previousAttemptId: verifiedPreviousAttemptId ?? null, requestId: options.managedAdmission?.requestId ?? invocationId, taskDigest: qualificationDigest(saved.request), role: saved.request.role,
|
|
1575
|
+
previousAttemptId: verifiedPreviousAttemptId ?? null, requestId: options.managedAdmission?.requestId ?? invocationId, taskDigest: options.retryEvidence?.taskDigest ?? qualificationDigest(saved.request), role: saved.request.role,
|
|
1576
|
+
...workerRetryRecordFields(options.retryEvidence),
|
|
1569
1577
|
...(options.managedAdmission ? { attempt: options.attempt } : {}),
|
|
1570
1578
|
selected: invocation.selected, planDigest: qualificationDigest(saved), invocationDigest: qualificationDigest(invocation),
|
|
1571
1579
|
policyDigest: invocation.policyDigest, catalogDigest: invocation.catalogDigest, profileDigest: invocation.profileDigest,
|
|
@@ -1573,9 +1581,9 @@ async function launchOneWorkerBaseline(owner, options, ctx) {
|
|
|
1573
1581
|
// Retain the legacy digest binding while naming both argv stages explicitly.
|
|
1574
1582
|
argvDigest: qualificationDigest(invocation.argv), placeholderArgvDigest: qualificationDigest(invocation.argv),
|
|
1575
1583
|
executedArgvDigest: qualificationDigest(artifacts.argv),
|
|
1576
|
-
artifacts:
|
|
1584
|
+
artifacts: artifacts.declarations.map(artifact => ({ name: artifact.name,
|
|
1577
1585
|
byteLength: Buffer.byteLength(artifact.content), sha256: bytesDigest(artifact.content) })),
|
|
1578
|
-
envNames:
|
|
1586
|
+
envNames: buildWorkerInvocationEnvironment(invocation.envNames, invocationId, {}, invocation).envNames, stdin: invocation.stdin,
|
|
1579
1587
|
prompt: { path: invocation.briefPath, digest: invocation.briefDigest }, cwd: invocation.cwd,
|
|
1580
1588
|
worktree: { path: invocation.cwd, baseRevision: null }, paths, captures, outputFraming: profile.health?.outputFraming ?? 'opaque',
|
|
1581
1589
|
health: invocation.health ?? null, transport: invocation.transport,
|
|
@@ -1586,7 +1594,7 @@ async function launchOneWorkerBaseline(owner, options, ctx) {
|
|
|
1586
1594
|
// All captures (including the reserved final) open successfully BEFORE spawn.
|
|
1587
1595
|
for (const filename of [...Object.values(paths), ...Object.values(captures)]) {
|
|
1588
1596
|
const handle = await withWorkerPath(filename, target => (options.openCapture ?? open)(target, constants.O_RDWR | constants.O_CREAT | constants.O_EXCL | constants.O_NOFOLLOW, 0o600));
|
|
1589
|
-
handles.push(handle);
|
|
1597
|
+
handles.push(handle); await captureOwner.reserveOutput(filename);
|
|
1590
1598
|
}
|
|
1591
1599
|
// Recheck policy, prompt, installation and exact bindings after file preparation.
|
|
1592
1600
|
inputs = await loadInputs();
|
|
@@ -1595,7 +1603,7 @@ async function launchOneWorkerBaseline(owner, options, ctx) {
|
|
|
1595
1603
|
paths: await Promise.all([invocation.cwd, runDir].map(workerDispatchPath)) });
|
|
1596
1604
|
if (!localGate.ok) throw workerDispatchRefusal(localGate);
|
|
1597
1605
|
if (bytesDigest(await boundedPrivateRead(invocation.briefPath, 262144, inspect)) !== invocation.briefDigest) throw new Error('Worker prompt changed before spawn');
|
|
1598
|
-
const environment = buildWorkerInvocationEnvironment(invocation.envNames, invocationId);
|
|
1606
|
+
const environment = buildWorkerInvocationEnvironment(invocation.envNames, invocationId, process.env, invocation);
|
|
1599
1607
|
const baselineContent = await sampleOwnedWorktreeContent(invocation.cwd, { files: options.healthArtifacts });
|
|
1600
1608
|
// The real `launchIsolatedWorker`, called with no `onDispatchCommit`
|
|
1601
1609
|
// (never passed anywhere in this frozen function), is synchronous —
|
|
@@ -1637,6 +1645,7 @@ async function launchOneWorkerBaseline(owner, options, ctx) {
|
|
|
1637
1645
|
await inspect(runDir, 'directory');
|
|
1638
1646
|
await withWorkerPath(runDir, async target => { const handle = await open(target, constants.O_RDONLY | constants.O_DIRECTORY | constants.O_NOFOLLOW);
|
|
1639
1647
|
try { await handle.chmod(0o700); } finally { await handle.close(); } });
|
|
1648
|
+
await captureOwner.finish();
|
|
1640
1649
|
}
|
|
1641
1650
|
}
|
|
1642
1651
|
}
|
|
@@ -1644,7 +1653,8 @@ async function launchOneWorkerBaseline(owner, options, ctx) {
|
|
|
1644
1653
|
async function captureOneWorkerBaseline(owner, ctx) {
|
|
1645
1654
|
const { child, outcome, invocation, invocationId, supervisor, launchTime, monotonicStart, publish, paths, handles, options } = ctx;
|
|
1646
1655
|
const hasTransport = outcome.mode === 'systemd-unit' || outcome.transportSupervisor;
|
|
1647
|
-
|
|
1656
|
+
// Spawn-time capture keeps a fast-exiting worker's identity (#3835).
|
|
1657
|
+
const sampleIdentity = options.sampleIdentity ?? (pid => sampleWorkerIdentity(pid, { includeExited: true }));
|
|
1648
1658
|
const sampleNativeSupervisor = options.sampleNativeSupervisor ?? sampleWorkerIdentity;
|
|
1649
1659
|
// For our own detached child, spawn waits through setsid/exec; one owned leader sample suffices.
|
|
1650
1660
|
const immediate = !hasTransport ? sampleIdentity(child.pid) : null;
|
|
@@ -1807,8 +1817,10 @@ async function captureOneWorkerBaseline(owner, ctx) {
|
|
|
1807
1817
|
// evidence is used wherever it is available.
|
|
1808
1818
|
const native = outcome.unit ? readNative() ?? readRecordedWorkerUnitStop(outcome, { native: true }) : null;
|
|
1809
1819
|
const members = identity ? sampleWorkerGroup(identity.pgid) : null;
|
|
1810
|
-
const
|
|
1811
|
-
|
|
1820
|
+
const terminationEvidence = outcome.mode !== 'systemd-unit' && child.pid === undefined
|
|
1821
|
+
? { confirmed: true, missing: null } : await settleWorkerTermination({ mode: outcome.mode, native,
|
|
1822
|
+
workerExited: sawExit, identity, supervisor, invocationId });
|
|
1823
|
+
const confirmed = terminationEvidence.confirmed;
|
|
1812
1824
|
const workerExit = hasTransport ? await transportRecord('worker-exit.json') : null;
|
|
1813
1825
|
if (!identity && hasTransport && nativeSupervisor) {
|
|
1814
1826
|
const workerStart = await transportRecord('worker-identity.json');
|
|
@@ -1827,7 +1839,7 @@ async function captureOneWorkerBaseline(owner, ctx) {
|
|
|
1827
1839
|
const result = { invocationId, exitCode, signal: resultSignal,
|
|
1828
1840
|
...(options.managedAdmission ? { managedAdmission: options.managedAdmission } : {}),
|
|
1829
1841
|
endedAt: new Date().toISOString(), termination: confirmed ? 'confirmed' : 'uncertain',
|
|
1830
|
-
descendants: confirmed ? 'none' : 'unknown', timedOut: resultTimedOut,
|
|
1842
|
+
terminationMissing: terminationEvidence.missing, descendants: confirmed ? 'none' : 'unknown', timedOut: resultTimedOut,
|
|
1831
1843
|
cancelled: stopReason === 'CANCELLED', stopReason, errorCode: errorCode ?? null, capturedBytes: Math.min(total, output.length),
|
|
1832
1844
|
workerTermination: hasTransport ? workerExit && !workerExit.errorCode ? 'confirmed' : 'uncertain' : sawExit ? 'confirmed' : 'uncertain',
|
|
1833
1845
|
workerReportedExit: workerExit ? { exitCode: workerExit.exitCode, signal: workerExit.signal, errorCode: workerExit.errorCode ?? null } : null,
|
|
@@ -2037,7 +2049,7 @@ export const UNBOUND_RETRY_EVIDENCE_CODE = 'UNBOUND_RETRY_EVIDENCE';
|
|
|
2037
2049
|
* retry and is surfaced with a code the conductor can act on — it must never
|
|
2038
2050
|
* silently spawn a duplicate writer.
|
|
2039
2051
|
*/
|
|
2040
|
-
export function stopBeforeRetryGate(previousResult, { expectedInvocationId = null, runDir, missing } = {}) {
|
|
2052
|
+
export function stopBeforeRetryGate(previousResult, { expectedInvocationId = null, runDir, missing = previousResult?.terminationMissing } = {}) {
|
|
2041
2053
|
if (previousResult?.termination !== 'confirmed') {
|
|
2042
2054
|
return {
|
|
2043
2055
|
ok: false,
|
|
@@ -4969,6 +4981,11 @@ export function planDirectWorkerLaunch({
|
|
|
4969
4981
|
// for the not-gated/disabled-CLI paths below, which must stay
|
|
4970
4982
|
// synchronous and byte-for-byte legacy — passing `undefined` through to
|
|
4971
4983
|
// `launchIsolatedWorker` is the dual-mode contract that keeps it so.
|
|
4984
|
+
if (invocation?.cwd && invocation?.selected?.group) {
|
|
4985
|
+
invocationId ??= invocation.invocationId ?? randomUUID();
|
|
4986
|
+
const marked = buildWorkerInvocationEnvironment(envNames ?? [], invocationId, env ?? process.env, invocation);
|
|
4987
|
+
envNames = marked.envNames; env = marked.env;
|
|
4988
|
+
}
|
|
4972
4989
|
let dispatchAttempt;
|
|
4973
4990
|
const launch = (onDispatchCommit) => launchIsolatedWorker({ name, memoryMaxGb, command, args, cwd, logFile, stdinPath, stdoutPath, stderrPath,
|
|
4974
4991
|
gate, config, allowDegraded, attached, ownedGroup,
|
|
@@ -516,6 +516,11 @@
|
|
|
516
516
|
],
|
|
517
517
|
"description": "How agents deliver code. direct = commit/push to default_branch; feature-branch = push branch, no PR; pr-required = branch + PR (default)"
|
|
518
518
|
},
|
|
519
|
+
"merge": {
|
|
520
|
+
"type": "string",
|
|
521
|
+
"enum": ["local-signed", "local", "tracker"],
|
|
522
|
+
"description": "Merge execution route. Defaults to tracker; local-signed is optional and requires signing configuration."
|
|
523
|
+
},
|
|
519
524
|
"default_branch": {
|
|
520
525
|
"type": "string",
|
|
521
526
|
"description": "Default branch name. Defaults to 'main'."
|
|
@@ -2486,6 +2491,16 @@
|
|
|
2486
2491
|
"type": "object",
|
|
2487
2492
|
"additionalProperties": false,
|
|
2488
2493
|
"properties": {
|
|
2494
|
+
"credential": {
|
|
2495
|
+
"type": "object",
|
|
2496
|
+
"additionalProperties": false,
|
|
2497
|
+
"properties": {
|
|
2498
|
+
"store": { "type": "string", "minLength": 1, "pattern": "^[A-Za-z0-9][A-Za-z0-9_.-]{0,127}$" },
|
|
2499
|
+
"env": { "type": "string", "pattern": "^[A-Za-z_][A-Za-z0-9_]*$" }
|
|
2500
|
+
},
|
|
2501
|
+
"oneOf": [{ "required": ["store"], "properties": { "store": {} } }, { "required": ["env"], "properties": { "env": {} } }],
|
|
2502
|
+
"description": "Sensitive-input reference only; never a literal token."
|
|
2503
|
+
},
|
|
2489
2504
|
"login": {
|
|
2490
2505
|
"type": "string",
|
|
2491
2506
|
"description": "Forge login that should author delivery writes."
|