@principles/codex-adapter 0.15.1 → 0.16.1
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.
|
@@ -77,10 +77,18 @@ export interface CodexWorkerCycleOptions {
|
|
|
77
77
|
/**
|
|
78
78
|
* WHO drove this cycle (PRI-1264 attribution, Phase 2 extension). The
|
|
79
79
|
* Service Host sets `PD_INVOCATION_SOURCE=service_host` on its Worker
|
|
80
|
-
* children
|
|
81
|
-
*
|
|
80
|
+
* children; without the second value the stall attribution would misreport
|
|
81
|
+
* service-driven cycles as manual (TD §5.2).
|
|
82
|
+
*
|
|
83
|
+
* PRI-1278 Phase 5 (Companion-runtime removal): the companion worker driver
|
|
84
|
+
* is retired — there is no Companion runtime left that could legitimately
|
|
85
|
+
* produce it. A process still self-declaring `PD_INVOCATION_SOURCE=companion`
|
|
86
|
+
* (a legacy env leftover) is not authoritative: no resident supervisor backs
|
|
87
|
+
* it, so it is attributed as what it factually is — manual. Historical
|
|
88
|
+
* liveness records already persisted with `lastCycleDriver: 'companion'`
|
|
89
|
+
* stay readable as-is; they are durable facts and are never rewritten.
|
|
82
90
|
*/
|
|
83
|
-
export declare function codexWorkerCycleDriver(): '
|
|
91
|
+
export declare function codexWorkerCycleDriver(): 'service_host' | 'manual';
|
|
84
92
|
export declare function readCodexWorkerLiveness(workspaceDir: string): Record<string, unknown> | null;
|
|
85
93
|
/**
|
|
86
94
|
* SPEC §9.1 fair-share pick (review P1): pending and due-retry are both
|
|
@@ -27,12 +27,13 @@
|
|
|
27
27
|
*/
|
|
28
28
|
import fs from 'node:fs';
|
|
29
29
|
import path from 'node:path';
|
|
30
|
-
import { computeFeatureFlagsFromConfig, createRuntimeStateHandle, createPainSignalBridge, isRetryWaitBackoffElapsed, pickDiagnosticianCandidate, reconcileWaitingTargetEvidenceTasks, PrincipleTreeLedgerAdapter, resolveDiagnosticianCapability, } from '@principles/core/runtime';
|
|
30
|
+
import { computeFeatureFlagsFromConfig, createRuntimeStateHandle, createPainSignalBridge, isRetryWaitBackoffElapsed, pickDiagnosticianCandidate, reconcileWaitingTargetEvidenceTasks, PrincipleTreeLedgerAdapter, resolveDiagnosticianCapability, PDRuntimeError, } from '@principles/core/runtime';
|
|
31
31
|
import { createWorkspaceBehaviorEvidencePort, createCodexArtificerTrustedFactsPort, loadPdConfigForPlugin, loadFeatureFlagFromConfig, reconcileGovernanceContinuation, runInternalizationConsumerCycle, runStage2CorrectionCycle, createSignalClassifierForWorkspace, createConsentLedgerSourceMaterialAuthorization, resolveWorkspacePipelineHostDeps, saveHostToolDeclaration, HOST_TOOL_DECLARATION_VERSION, } from '@principles/host-runtime';
|
|
32
32
|
import { catchUpCodexIngestion } from '../ingestion/catch-up.js';
|
|
33
33
|
import { readCodexTargetTurnEvidence } from '../ingestion/pain-receipt-fallback.js';
|
|
34
34
|
import { CODEX_TOOL_SEMANTIC_MAPPINGS, CODEX_TOOL_SEMANTICS } from '../tool-semantics.js';
|
|
35
|
-
|
|
35
|
+
// Lease/consumer owner label written by the Service-Host-spawned worker.
|
|
36
|
+
const WORKER_OWNER = 'service-host-worker';
|
|
36
37
|
const DEFAULT_DIAG_CANDIDATE_LIMIT = 5;
|
|
37
38
|
/** CR-05 §9.1: bounded per-cycle post-processing continuation budget. */
|
|
38
39
|
const DEFAULT_POST_PROCESSING_LIMIT = 2;
|
|
@@ -51,13 +52,19 @@ const LIVENESS_STAGE_DEADLINE_MS = {
|
|
|
51
52
|
/**
|
|
52
53
|
* WHO drove this cycle (PRI-1264 attribution, Phase 2 extension). The
|
|
53
54
|
* Service Host sets `PD_INVOCATION_SOURCE=service_host` on its Worker
|
|
54
|
-
* children
|
|
55
|
-
*
|
|
55
|
+
* children; without the second value the stall attribution would misreport
|
|
56
|
+
* service-driven cycles as manual (TD §5.2).
|
|
57
|
+
*
|
|
58
|
+
* PRI-1278 Phase 5 (Companion-runtime removal): the companion worker driver
|
|
59
|
+
* is retired — there is no Companion runtime left that could legitimately
|
|
60
|
+
* produce it. A process still self-declaring `PD_INVOCATION_SOURCE=companion`
|
|
61
|
+
* (a legacy env leftover) is not authoritative: no resident supervisor backs
|
|
62
|
+
* it, so it is attributed as what it factually is — manual. Historical
|
|
63
|
+
* liveness records already persisted with `lastCycleDriver: 'companion'`
|
|
64
|
+
* stay readable as-is; they are durable facts and are never rewritten.
|
|
56
65
|
*/
|
|
57
66
|
export function codexWorkerCycleDriver() {
|
|
58
67
|
const source = process.env.PD_INVOCATION_SOURCE;
|
|
59
|
-
if (source === 'companion')
|
|
60
|
-
return 'companion';
|
|
61
68
|
if (source === 'service_host')
|
|
62
69
|
return 'service_host';
|
|
63
70
|
return 'manual';
|
|
@@ -66,9 +73,9 @@ export function codexWorkerCycleDriver() {
|
|
|
66
73
|
* F13 (TD §5.2): the coordinator passes a unique invocation id; when
|
|
67
74
|
* present it lands in the liveness record so the shared per-workspace file
|
|
68
75
|
* can be correlated back to the exact Service Host invocation.
|
|
69
|
-
* R5 review fix: a manual
|
|
70
|
-
* patch must CLEAR the field — otherwise a completed manual run
|
|
71
|
-
* masquerading under the previous shadow run's id.
|
|
76
|
+
* R5 review fix: a manual (non-Service-Host) cycle carries NO invocation
|
|
77
|
+
* id, so the patch must CLEAR the field — otherwise a completed manual run
|
|
78
|
+
* would keep masquerading under the previous shadow run's id.
|
|
72
79
|
*/
|
|
73
80
|
function invocationIdLivenessPatch() {
|
|
74
81
|
const invocationId = process.env.PD_INVOCATION_ID;
|
|
@@ -159,6 +166,14 @@ function finalizeLiveness(workspaceDir, cycleStartedAt, settlement) {
|
|
|
159
166
|
...invocationIdLivenessPatch(),
|
|
160
167
|
});
|
|
161
168
|
}
|
|
169
|
+
function workerCycleNextAction(error, fallback) {
|
|
170
|
+
if (error instanceof PDRuntimeError
|
|
171
|
+
&& error.category === 'storage_unavailable'
|
|
172
|
+
&& typeof error.details?.nextAction === 'string') {
|
|
173
|
+
return error.details.nextAction;
|
|
174
|
+
}
|
|
175
|
+
return fallback;
|
|
176
|
+
}
|
|
162
177
|
/**
|
|
163
178
|
* SPEC §9.1 fair-share pick (review P1): pending and due-retry are both
|
|
164
179
|
* continuously-eligible classes; neither may starve the other while new
|
|
@@ -198,11 +213,13 @@ export async function runCodexWorkspaceWorkerCycle(options) {
|
|
|
198
213
|
// PRI-1264 review round (2026-11-18): an intentional CONFIG pause must
|
|
199
214
|
// keep the liveness heartbeat alive — the worker process IS alive and
|
|
200
215
|
// cycling, it is just deliberately idle. Without this heartbeat the
|
|
201
|
-
//
|
|
202
|
-
//
|
|
203
|
-
//
|
|
204
|
-
//
|
|
205
|
-
//
|
|
216
|
+
// stall attribution reading this record (last-completed-cycle age —
|
|
217
|
+
// originally the retired Companion's detector, now the `pd codex worker
|
|
218
|
+
// --status` verdict and the Service Host health projection) read the
|
|
219
|
+
// stale pre-pause record and reported a deliberately idle worker as
|
|
220
|
+
// stalled — guidance no restart could ever fix, because the pause is
|
|
221
|
+
// config-intentional. The workspace directory and config were already
|
|
222
|
+
// proven readable above (CR-08 ordering), so the write is legitimate.
|
|
206
223
|
writeLiveness(workspaceDir, {
|
|
207
224
|
runningStage: 'paused',
|
|
208
225
|
// Explicit null: a paused state has no in-flight stage, and the merge
|
|
@@ -221,9 +238,10 @@ export async function runCodexWorkspaceWorkerCycle(options) {
|
|
|
221
238
|
runningStage: 'catch_up',
|
|
222
239
|
stageDeadline: new Date(cycleStartedAt.getTime() + LIVENESS_STAGE_DEADLINE_MS.catch_up).toISOString(),
|
|
223
240
|
// PRI-1264: record WHO drove this cycle. `pd codex worker --status` reads
|
|
224
|
-
// the marker so the Owner can tell a
|
|
225
|
-
//
|
|
226
|
-
//
|
|
241
|
+
// the marker so the Owner can tell a Service-Host-driven cycle (a bounded
|
|
242
|
+
// worker spawned by the OS-scheduled Service Host, expected to recur on
|
|
243
|
+
// its interval) from a manual one-shot — "registered" alone says nothing
|
|
244
|
+
// about whether a driver is actually alive.
|
|
227
245
|
lastCycleDriver: codexWorkerCycleDriver(),
|
|
228
246
|
});
|
|
229
247
|
const consumerFlag = loadFeatureFlagFromConfig(workspaceDir, 'internalization_auto_consumer', { info: (m) => logger.info(m), warn: (m) => logger.warn(m) });
|
|
@@ -288,7 +306,7 @@ export async function runCodexWorkspaceWorkerCycle(options) {
|
|
|
288
306
|
// consumer flag is on — an intentional capability pause never reaches
|
|
289
307
|
// candidate picking or any provider call.)
|
|
290
308
|
try {
|
|
291
|
-
const handle = await createRuntimeStateHandle({ workspaceDir, readonly: false });
|
|
309
|
+
const handle = await createRuntimeStateHandle({ workspaceDir, readonly: false, bootstrapIfMissing: false });
|
|
292
310
|
try {
|
|
293
311
|
const sweep = await handle.stateManager.runRecoverySweep();
|
|
294
312
|
if (sweep.recovered > 0 || sweep.errors.length > 0) {
|
|
@@ -406,7 +424,7 @@ export async function runCodexWorkspaceWorkerCycle(options) {
|
|
|
406
424
|
...base,
|
|
407
425
|
mode: 'degraded',
|
|
408
426
|
reason,
|
|
409
|
-
nextAction: 'Inspect the Workspace runtime profile and provider configuration; the task keeps its pending/retry state and no evidence was mutated.',
|
|
427
|
+
nextAction: workerCycleNextAction(error, 'Inspect the Workspace runtime profile and provider configuration; the task keeps its pending/retry state and no evidence was mutated.'),
|
|
410
428
|
report: { catchUp, reconcile, postProcessing: null, diagnostician: null, downstream: null },
|
|
411
429
|
};
|
|
412
430
|
}
|
|
@@ -422,7 +440,7 @@ export async function runCodexWorkspaceWorkerCycle(options) {
|
|
|
422
440
|
writeLiveness(workspaceDir, { runningStage: 'post_processing', stageDeadline: new Date(Date.now() + LIVENESS_STAGE_DEADLINE_MS.post_processing).toISOString() });
|
|
423
441
|
if (consumerFlag.enabled && !diagnosticianDisabled) {
|
|
424
442
|
try {
|
|
425
|
-
const handle = await createRuntimeStateHandle({ workspaceDir, readonly: false });
|
|
443
|
+
const handle = await createRuntimeStateHandle({ workspaceDir, readonly: false, bootstrapIfMissing: false });
|
|
426
444
|
try {
|
|
427
445
|
const { eligible: backlog, corrupt } = await handle.stateManager.listDiagnosisPostProcessingBacklog({ limit: DEFAULT_POST_PROCESSING_LIMIT });
|
|
428
446
|
const { eligible: backlogAll, corrupt: corruptAll } = await handle.stateManager.listDiagnosisPostProcessingBacklog({ limit: 200 });
|
|
@@ -514,7 +532,7 @@ export async function runCodexWorkspaceWorkerCycle(options) {
|
|
|
514
532
|
...base,
|
|
515
533
|
mode: 'degraded',
|
|
516
534
|
reason,
|
|
517
|
-
nextAction: 'Inspect the workspace state.db principle_candidates/tasks; the worker retries automatically on the next cycle.',
|
|
535
|
+
nextAction: workerCycleNextAction(error, 'Inspect the workspace state.db principle_candidates/tasks; the worker retries automatically on the next cycle.'),
|
|
518
536
|
report: { catchUp, reconcile, postProcessing: null, diagnostician, downstream: null, ...(targetEvidenceReconcile !== null ? { targetEvidenceReconcile } : {}) },
|
|
519
537
|
};
|
|
520
538
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@principles/codex-adapter",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.16.1",
|
|
4
4
|
"description": "Codex CLI host adapter for Principles Disciple — implements HostAdapter interface for OpenAI Codex CLI's stdin/stdout JSON hook model (ADR-0020).",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -33,14 +33,14 @@
|
|
|
33
33
|
"lint": "eslint \"src/**/*.ts\""
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@principles/core": "^8.
|
|
37
|
-
"@principles/host-runtime": "^4.
|
|
38
|
-
"@principles/install-layout": "^0.
|
|
36
|
+
"@principles/core": "^8.6.0",
|
|
37
|
+
"@principles/host-runtime": "^4.9.4",
|
|
38
|
+
"@principles/install-layout": "^0.12.0"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@types/node": "^26.6.6",
|
|
42
42
|
"typescript": "^7.0.2",
|
|
43
|
-
"vite": "^8.
|
|
43
|
+
"vite": "^8.4.0",
|
|
44
44
|
"vitest": "^5.1.0"
|
|
45
45
|
},
|
|
46
46
|
"license": "Apache-2.0",
|
|
@@ -52,5 +52,5 @@
|
|
|
52
52
|
"publishConfig": {
|
|
53
53
|
"access": "public"
|
|
54
54
|
},
|
|
55
|
-
"gitHead": "
|
|
55
|
+
"gitHead": "2d34c8c2614e1b84e4ea2b4c0bb56bab173da97c"
|
|
56
56
|
}
|