gestalt-mobile 0.55.3 → 0.55.5
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/README.md +36 -16
- package/dist/server/server/composition.contracts.js +363 -6
- package/dist/server/server/composition.js +58 -5
- package/dist/server/server/features/autopilot/application/policy.js +5 -2
- package/dist/server/server/features/autopilot/application/service.js +14 -1
- package/dist/server/server/features/plans/application/executor-launch-validation.js +91 -0
- package/dist/server/server/features/plans/application/executor-model-evidence.js +9 -3
- package/dist/server/server/features/plans/application/parse-model-policy.js +1 -1
- package/dist/server/server/features/plans/application/parse-supervised-plan.js +10 -0
- package/dist/server/server/features/plans/domain/model-policy-admission.js +32 -5
- package/dist/server/server/platform/codex/session-runtime.js +66 -7
- package/dist/server/shared/contracts/org-plan-health.js +1 -1
- package/gestalt-supervision-capabilities.json +3 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -102,22 +102,42 @@ session-relative interpretation.
|
|
|
102
102
|
|
|
103
103
|
### Versioned model policy
|
|
104
104
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
105
|
+
Version-1 plans separate requested model choices from assurance. Existing plans
|
|
106
|
+
without `#+MODEL_POLICY_ASSURANCE` use disclosed **configured compatibility**;
|
|
107
|
+
their policy metadata and file bytes need no migration. An explicit
|
|
108
|
+
`#+MODEL_POLICY_ASSURANCE: configured` selects the same mode. Mobile validates
|
|
109
|
+
allowed models/efforts and higher-effort necessity, checks the active runtime
|
|
110
|
+
catalog before versioned root dispatch, and directs the root to launch the exact
|
|
111
|
+
L1 model/effort through supported overrides with inherited sandbox and approval
|
|
112
|
+
policy. Automatic executor resumes use that L1 policy rather than session defaults.
|
|
113
|
+
|
|
114
|
+
`#+MODEL_POLICY_ASSURANCE: runtime-attested` explicitly requires strict runtime
|
|
115
|
+
receipts. The current adapter cannot supply runtime-issued settings revisions;
|
|
116
|
+
strict plans fail with `RUNTIME_ATTESTATION_UNAVAILABLE` and remain strict until
|
|
117
|
+
the user authorizes a change. Repeated approvals or attention resolution cannot
|
|
118
|
+
provide that capability. Manual Off is independently respected. Legacy plans
|
|
119
|
+
without model policy keep their existing behavior.
|
|
120
|
+
|
|
121
|
+
`gestalt_org_plan_health` reports `executionAdmission.allowed`, configured
|
|
122
|
+
assurance and `executorLaunch`, which checks the requested L1 model/effort using
|
|
123
|
+
the owning runtime's `model/list` before any executor exists. `CATALOG_MATCH`
|
|
124
|
+
includes a normalized-content fingerprint and observation time, never a fabricated
|
|
125
|
+
server revision. Child `modelPolicy.catalogRevision:null` does not mean the
|
|
126
|
+
prelaunch catalog is unavailable. `CHILD_NOT_LAUNCHED` is expected before dispatch.
|
|
127
|
+
Actual missing/incompatible catalogs retain explicit failure codes.
|
|
128
|
+
|
|
129
|
+
Health retains `runtimeEnforcement:false`. Its `modelPolicy` evidence separately
|
|
130
|
+
reports `admissionScope: runtime-attestation`, `admitted:false`, `attested:false`,
|
|
131
|
+
requested values and observed configured thread settings. Unknown values remain
|
|
132
|
+
null, never copied from requests. A configured match is not runtime attestation.
|
|
133
|
+
Controller-owned resume guards reject stale identities and observed mismatches,
|
|
134
|
+
and recheck authority immediately before dispatch and after thread recovery.
|
|
135
|
+
Native collaboration spawn/followup calls remain cooperatively root-supervised;
|
|
136
|
+
Mobile does not intercept them or guarantee universal pre-spawn enforcement.
|
|
137
|
+
One writer per L1, independent review, evidence gates, checkpoint continuation
|
|
138
|
+
and terminal whole-branch review remain required. See
|
|
139
|
+
[update and rollback guidance](docs/org-plan-policy-compatibility.md) and
|
|
140
|
+
[prelaunch catalog recovery](docs/org-plan-prelaunch-catalog.md).
|
|
121
141
|
|
|
122
142
|
## Skill profiles
|
|
123
143
|
|
|
@@ -17,6 +17,7 @@ import WebSocket from 'ws';
|
|
|
17
17
|
import { composeRelayApp } from './composition.js';
|
|
18
18
|
import { autopilotExecutorLaunchPrompt } from './features/autopilot/application/policy.js';
|
|
19
19
|
import { CodexJsonRpcError } from './platform/codex/json-rpc-client.js';
|
|
20
|
+
import { CodexSessionRuntime } from './platform/codex/session-runtime.js';
|
|
20
21
|
import { SqliteAuthorizationStore } from './platform/auth/sqlite-authorization-store.js';
|
|
21
22
|
import { SqliteEventJournal } from './platform/persistence/sqlite-event-journal.js';
|
|
22
23
|
import { authorizationSessionId, authorizedDeviceId, localOwnerId, webAuthnCredentialId, } from './features/auth/domain/identifiers.js';
|
|
@@ -182,14 +183,17 @@ const acceptedL1WithNextTodoPlanText = () => `${completedAutopilotPlanText()}
|
|
|
182
183
|
- Tests :: Exercise the next continuation.
|
|
183
184
|
- Done when :: The next L1 starts exactly once.
|
|
184
185
|
`;
|
|
185
|
-
async function installAutopilotPlan(app, sessionId, workspacePath, name, childState = 'TODO', reason = 'supervision-start') {
|
|
186
|
+
async function installAutopilotPlan(app, sessionId, workspacePath, name, childState = 'TODO', reason = 'supervision-start', source) {
|
|
186
187
|
const planPath = join(workspacePath, `${name}.org`);
|
|
187
|
-
await writeFile(planPath, autopilotPlanText(childState));
|
|
188
|
+
await writeFile(planPath, source ?? autopilotPlanText(childState));
|
|
188
189
|
await writeFile(planStatusFilePath(planStatusDirectoryPath(workspacePath, sessionId), planPath), JSON.stringify({
|
|
189
190
|
schemaVersion: 1,
|
|
190
191
|
planPath,
|
|
191
192
|
reason,
|
|
192
193
|
updatedAt: new Date().toISOString(),
|
|
194
|
+
...(source?.includes('#+MODEL_POLICY_VERSION: 1')
|
|
195
|
+
? { modelPolicyVersion: 1, requiredCapabilities: ['l1-model-policy-v1'] }
|
|
196
|
+
: {}),
|
|
193
197
|
}));
|
|
194
198
|
await expect
|
|
195
199
|
.poll(async () => (await app.inject(`/api/sessions/${sessionId}/plan`)).statusCode)
|
|
@@ -197,7 +201,7 @@ async function installAutopilotPlan(app, sessionId, workspacePath, name, childSt
|
|
|
197
201
|
expect((await app.inject({ method: 'POST', url: `/api/sessions/${sessionId}/restore` })).statusCode).toBe(200);
|
|
198
202
|
return planPath;
|
|
199
203
|
}
|
|
200
|
-
async function createProductionAutopilotFixture(overrides = {}) {
|
|
204
|
+
async function createProductionAutopilotFixture(overrides = {}, source) {
|
|
201
205
|
const root = await mkdtemp(join(tmpdir(), 'gestalt-mobile-root-'));
|
|
202
206
|
const dataDir = await mkdtemp(join(tmpdir(), 'gestalt-mobile-state-'));
|
|
203
207
|
ownTemporaryPaths(root, dataDir);
|
|
@@ -222,7 +226,7 @@ async function createProductionAutopilotFixture(overrides = {}) {
|
|
|
222
226
|
state: 'ready',
|
|
223
227
|
threadId: expect.any(String),
|
|
224
228
|
}));
|
|
225
|
-
await installAutopilotPlan(app, sessionId, workspacePath, 'autopilot');
|
|
229
|
+
await installAutopilotPlan(app, sessionId, workspacePath, 'autopilot', 'TODO', 'supervision-start', source);
|
|
226
230
|
return { app, dataDir, handles, root, sessionId, workspacePath };
|
|
227
231
|
}
|
|
228
232
|
async function holdCheckpointRequest(fixture, timers, requestId, expectHeld = true, compact = false) {
|
|
@@ -383,8 +387,361 @@ async function createUnauthorizedProductionApp(root, dataDir) {
|
|
|
383
387
|
}
|
|
384
388
|
describe('production composition', () => {
|
|
385
389
|
describeCompositionConcern('autopilot', () => {
|
|
386
|
-
|
|
387
|
-
|
|
390
|
+
const versionedText = (state = 'TODO', strict = false) => '#+MODEL_POLICY_VERSION: 1\n' +
|
|
391
|
+
(strict ? '#+MODEL_POLICY_ASSURANCE: runtime-attested\n' : '') +
|
|
392
|
+
autopilotPlanText(state).replace(':REVIEW_STATUS: UNREVIEWED', `:REVIEW_STATUS: UNREVIEWED
|
|
393
|
+
:MODEL: gpt-6.1-sol
|
|
394
|
+
:REASONING_EFFORT: medium
|
|
395
|
+
:MODEL_RATIONALE: Composition contract with explicit launch choices.
|
|
396
|
+
:MODEL_FALLBACKS: none
|
|
397
|
+
:MODEL_ESCALATION_TRIGGER: A focused invariant fails.`);
|
|
398
|
+
const policyCatalog = {
|
|
399
|
+
data: [{ id: 'gpt-6.1-sol', supportedReasoningEfforts: [{ reasoningEffort: 'medium' }] }],
|
|
400
|
+
};
|
|
401
|
+
it('activates existing v1, validates catalog, dispatches launch instructions and records a report checkpoint', async () => {
|
|
402
|
+
const timers = [];
|
|
403
|
+
const fixture = await createProductionAutopilotFixture({
|
|
404
|
+
autopilotSchedule: (callback) => {
|
|
405
|
+
const timer = { callback, cancelled: false };
|
|
406
|
+
timers.push(timer);
|
|
407
|
+
return () => {
|
|
408
|
+
timer.cancelled = true;
|
|
409
|
+
};
|
|
410
|
+
},
|
|
411
|
+
}, versionedText());
|
|
412
|
+
const { app, sessionId, handles, workspacePath } = fixture;
|
|
413
|
+
onTestFinished(() => app.close());
|
|
414
|
+
for (const handle of handles)
|
|
415
|
+
handle.respond = (method) => (method === 'model/list' ? policyCatalog : undefined);
|
|
416
|
+
expect((await app.inject(`/api/sessions/${sessionId}`)).json()).toMatchObject({
|
|
417
|
+
autopilot: {
|
|
418
|
+
enabled: true,
|
|
419
|
+
executionAdmission: { allowed: true, assurance: 'configured', runtimeEnforcement: false },
|
|
420
|
+
},
|
|
421
|
+
});
|
|
422
|
+
timers.find((timer) => !timer.cancelled).callback();
|
|
423
|
+
await vi.waitFor(() => expect(handles
|
|
424
|
+
.flatMap((handle) => handle.requests)
|
|
425
|
+
.filter((call) => call.method === 'turn/start')).toHaveLength(1));
|
|
426
|
+
const handle = handles.find((candidate) => candidate.requests.some((call) => call.method === 'turn/start'));
|
|
427
|
+
const start = handle.requests.find((call) => call.method === 'turn/start');
|
|
428
|
+
expect(start.params).toMatchObject({
|
|
429
|
+
input: [
|
|
430
|
+
{
|
|
431
|
+
text: expect.stringContaining('explicit model gpt-6.1-sol and reasoning_effort medium'),
|
|
432
|
+
},
|
|
433
|
+
],
|
|
434
|
+
});
|
|
435
|
+
expect(JSON.stringify(start.params)).not.toContain('reasoning_effort high');
|
|
436
|
+
const session = (await app.inject(`/api/sessions/${sessionId}`)).json();
|
|
437
|
+
const requestsBeforeHealth = handle.requests.length;
|
|
438
|
+
const healthResponse = (await handle.request({
|
|
439
|
+
id: 9900,
|
|
440
|
+
method: 'item/tool/call',
|
|
441
|
+
params: {
|
|
442
|
+
threadId: session.threadId,
|
|
443
|
+
turnId: session.activeTurnId,
|
|
444
|
+
tool: 'gestalt_org_plan_health',
|
|
445
|
+
arguments: {},
|
|
446
|
+
},
|
|
447
|
+
}));
|
|
448
|
+
expect(healthResponse.success).toBe(true);
|
|
449
|
+
expect(JSON.parse(healthResponse.contentItems[0].text)).toMatchObject({
|
|
450
|
+
executionAdmission: { allowed: true, assurance: 'configured' },
|
|
451
|
+
executorLaunch: {
|
|
452
|
+
scope: 'prelaunch-catalog',
|
|
453
|
+
validated: true,
|
|
454
|
+
code: 'CATALOG_MATCH',
|
|
455
|
+
requested: { model: 'gpt-6.1-sol', reasoningEffort: 'medium' },
|
|
456
|
+
catalog: {
|
|
457
|
+
source: 'runtime-model-list',
|
|
458
|
+
fingerprint: expect.stringMatching(/^[a-f0-9]{64}$/),
|
|
459
|
+
revisionSource: 'normalized-content-digest',
|
|
460
|
+
},
|
|
461
|
+
},
|
|
462
|
+
modelPolicy: {
|
|
463
|
+
code: 'CHILD_NOT_LAUNCHED',
|
|
464
|
+
catalogRevision: null,
|
|
465
|
+
effective: { model: null, reasoningEffort: null },
|
|
466
|
+
attested: false,
|
|
467
|
+
},
|
|
468
|
+
});
|
|
469
|
+
expect(handle.requests.slice(requestsBeforeHealth).map((call) => call.method)).toEqual([
|
|
470
|
+
'model/list',
|
|
471
|
+
]);
|
|
472
|
+
// Synthetic executor report: real composition validates the authoritative plan boundary.
|
|
473
|
+
await writeFile(join(workspacePath, 'autopilot.org'), versionedText('DONE'));
|
|
474
|
+
const result = await handle.request({
|
|
475
|
+
id: 9901,
|
|
476
|
+
method: 'item/tool/call',
|
|
477
|
+
params: {
|
|
478
|
+
threadId: session.threadId,
|
|
479
|
+
turnId: session.activeTurnId,
|
|
480
|
+
tool: 'gestalt_org_plan_checkpoint',
|
|
481
|
+
arguments: { kind: 'l2Completed' },
|
|
482
|
+
},
|
|
483
|
+
});
|
|
484
|
+
expect(result).toEqual(toOrgPlanCheckpointToolResponse('recorded'));
|
|
485
|
+
const db = new DatabaseSync(join(fixture.dataDir, 'relay.sqlite'));
|
|
486
|
+
try {
|
|
487
|
+
expect(db
|
|
488
|
+
.prepare("SELECT count(*) AS n FROM session_events WHERE type='org-plan.step-checkpointed'")
|
|
489
|
+
.get()).toMatchObject({ n: 1 });
|
|
490
|
+
}
|
|
491
|
+
finally {
|
|
492
|
+
db.close();
|
|
493
|
+
}
|
|
494
|
+
handle.notify({
|
|
495
|
+
method: 'turn/completed',
|
|
496
|
+
params: {
|
|
497
|
+
threadId: session.threadId,
|
|
498
|
+
turn: { id: session.activeTurnId, status: 'completed' },
|
|
499
|
+
},
|
|
500
|
+
});
|
|
501
|
+
await vi.waitFor(async () => expect((await app.inject(`/api/sessions/${sessionId}`)).json().activeTurnId).toBeNull());
|
|
502
|
+
expect((await app.inject(`/api/sessions/${sessionId}/plan`)).json().steps[0]).toMatchObject({
|
|
503
|
+
reviewStatus: 'UNREVIEWED',
|
|
504
|
+
});
|
|
505
|
+
expect(handles.flatMap((handle) => handle.requests).filter((call) => call.method === 'turn/start')).toHaveLength(1);
|
|
506
|
+
});
|
|
507
|
+
it.each(['missing', 'model', 'effort', 'manual-off'])('exposes prechild catalog evidence without changing admission or Manual Off: %s', async (scenario) => {
|
|
508
|
+
const f = await createProductionAutopilotFixture({ autopilotSchedule: () => () => { } }, versionedText());
|
|
509
|
+
onTestFinished(() => f.app.close());
|
|
510
|
+
const session = (await f.app.inject(`/api/sessions/${f.sessionId}`)).json();
|
|
511
|
+
const handle = f.handles.find((candidate) => candidate.request);
|
|
512
|
+
for (const candidate of f.handles)
|
|
513
|
+
candidate.respond = (method) => method !== 'model/list'
|
|
514
|
+
? undefined
|
|
515
|
+
: scenario === 'missing'
|
|
516
|
+
? {}
|
|
517
|
+
: scenario === 'model'
|
|
518
|
+
? {
|
|
519
|
+
data: [
|
|
520
|
+
{
|
|
521
|
+
id: 'gpt-6-sol',
|
|
522
|
+
supportedReasoningEfforts: [{ reasoningEffort: 'medium' }],
|
|
523
|
+
},
|
|
524
|
+
],
|
|
525
|
+
}
|
|
526
|
+
: scenario === 'effort'
|
|
527
|
+
? {
|
|
528
|
+
data: [
|
|
529
|
+
{
|
|
530
|
+
id: 'gpt-6.1-sol',
|
|
531
|
+
supportedReasoningEfforts: [{ reasoningEffort: 'low' }],
|
|
532
|
+
},
|
|
533
|
+
],
|
|
534
|
+
}
|
|
535
|
+
: policyCatalog;
|
|
536
|
+
if (scenario === 'manual-off')
|
|
537
|
+
await f.app.inject({
|
|
538
|
+
method: 'PUT',
|
|
539
|
+
url: `/api/sessions/${f.sessionId}/autopilot`,
|
|
540
|
+
payload: { enabled: false },
|
|
541
|
+
});
|
|
542
|
+
const beforeHealth = f.handles
|
|
543
|
+
.flatMap((candidate) => candidate.requests)
|
|
544
|
+
.filter((call) => ['turn/start', 'thread/read', 'thread/resume'].includes(call.method));
|
|
545
|
+
const response = (await handle.request({
|
|
546
|
+
id: 9902,
|
|
547
|
+
method: 'item/tool/call',
|
|
548
|
+
params: {
|
|
549
|
+
threadId: session.threadId,
|
|
550
|
+
tool: 'gestalt_org_plan_health',
|
|
551
|
+
arguments: {},
|
|
552
|
+
},
|
|
553
|
+
}));
|
|
554
|
+
const health = JSON.parse(response.contentItems[0].text);
|
|
555
|
+
expect(health).toMatchObject({
|
|
556
|
+
executionAdmission: { allowed: true },
|
|
557
|
+
executorLaunch: {
|
|
558
|
+
validated: scenario === 'manual-off',
|
|
559
|
+
code: scenario === 'missing'
|
|
560
|
+
? 'CATALOG_UNAVAILABLE'
|
|
561
|
+
: scenario === 'model'
|
|
562
|
+
? 'MODEL_UNAVAILABLE'
|
|
563
|
+
: scenario === 'effort'
|
|
564
|
+
? 'EFFORT_UNSUPPORTED'
|
|
565
|
+
: 'CATALOG_MATCH',
|
|
566
|
+
},
|
|
567
|
+
});
|
|
568
|
+
if (scenario === 'manual-off')
|
|
569
|
+
expect(health).toMatchObject({ enabled: false, reason: 'manualDisabled' });
|
|
570
|
+
expect(f.handles
|
|
571
|
+
.flatMap((candidate) => candidate.requests)
|
|
572
|
+
.filter((call) => ['turn/start', 'thread/read', 'thread/resume'].includes(call.method))).toEqual(beforeHealth);
|
|
573
|
+
});
|
|
574
|
+
it('keeps explicit strict v1 blocked at production activation without scheduling', async () => {
|
|
575
|
+
const timers = [];
|
|
576
|
+
const f = await createProductionAutopilotFixture({
|
|
577
|
+
autopilotSchedule: (callback) => {
|
|
578
|
+
timers.push(callback);
|
|
579
|
+
return () => { };
|
|
580
|
+
},
|
|
581
|
+
}, versionedText('TODO', true));
|
|
582
|
+
onTestFinished(() => f.app.close());
|
|
583
|
+
const response = await f.app.inject({
|
|
584
|
+
method: 'PUT',
|
|
585
|
+
url: `/api/sessions/${f.sessionId}/autopilot`,
|
|
586
|
+
payload: { enabled: true },
|
|
587
|
+
});
|
|
588
|
+
expect(response.statusCode).toBe(409);
|
|
589
|
+
expect(response.json()).toMatchObject({
|
|
590
|
+
reason: 'RUNTIME_ATTESTATION_UNAVAILABLE',
|
|
591
|
+
action: expect.stringContaining('explicitly requires'),
|
|
592
|
+
});
|
|
593
|
+
expect(timers).toHaveLength(0);
|
|
594
|
+
expect(f.handles
|
|
595
|
+
.flatMap((handle) => handle.requests)
|
|
596
|
+
.filter((call) => call.method === 'turn/start')).toHaveLength(0);
|
|
597
|
+
});
|
|
598
|
+
it.each([
|
|
599
|
+
'match',
|
|
600
|
+
'mismatch',
|
|
601
|
+
'off-during-read',
|
|
602
|
+
'policy-during-read',
|
|
603
|
+
'same-plan-during-read',
|
|
604
|
+
'off-on-during-recovery',
|
|
605
|
+
])('guards configured executor dispatch in production: %s', async (scenario) => {
|
|
606
|
+
const timers = [];
|
|
607
|
+
const f = await createProductionAutopilotFixture({
|
|
608
|
+
autopilotActivity: (sessionId) => {
|
|
609
|
+
const observedAt = new Date().toISOString();
|
|
610
|
+
return {
|
|
611
|
+
sessionId,
|
|
612
|
+
rootThreadId: 'thread-1',
|
|
613
|
+
root: {
|
|
614
|
+
state: 'idle',
|
|
615
|
+
reason: 'turnCompleted',
|
|
616
|
+
observedAt,
|
|
617
|
+
lastActivityAt: observedAt,
|
|
618
|
+
},
|
|
619
|
+
subagents: [
|
|
620
|
+
{
|
|
621
|
+
id: 'child-1',
|
|
622
|
+
threadId: 'child-1',
|
|
623
|
+
taskPath: '/root/l1',
|
|
624
|
+
canonicalTaskName: 'l1',
|
|
625
|
+
canonicalPosition: 'L1',
|
|
626
|
+
continuationGeneration: 1,
|
|
627
|
+
outcome: 'partial',
|
|
628
|
+
ownedProcesses: [],
|
|
629
|
+
state: 'idle',
|
|
630
|
+
reason: 'turnCompleted',
|
|
631
|
+
observedAt,
|
|
632
|
+
lastActivityAt: observedAt,
|
|
633
|
+
},
|
|
634
|
+
],
|
|
635
|
+
aggregateSubagents: 'idle',
|
|
636
|
+
confidence: 'fresh',
|
|
637
|
+
};
|
|
638
|
+
},
|
|
639
|
+
autopilotSchedule: (callback) => {
|
|
640
|
+
const timer = { callback, cancelled: false };
|
|
641
|
+
timers.push(timer);
|
|
642
|
+
return () => {
|
|
643
|
+
timer.cancelled = true;
|
|
644
|
+
};
|
|
645
|
+
},
|
|
646
|
+
}, versionedText());
|
|
647
|
+
onTestFinished(() => f.app.close());
|
|
648
|
+
const actualRootThreadId = (await f.app.inject(`/api/sessions/${f.sessionId}`)).json()
|
|
649
|
+
.threadId;
|
|
650
|
+
const pendingRead = Promise.withResolvers();
|
|
651
|
+
const pendingRecovery = Promise.withResolvers();
|
|
652
|
+
const resumeOperation = vi.spyOn(CodexSessionRuntime.prototype, 'startExecutorTurn');
|
|
653
|
+
onTestFinished(() => {
|
|
654
|
+
pendingRead.resolve({});
|
|
655
|
+
pendingRecovery.resolve({});
|
|
656
|
+
resumeOperation.mockRestore();
|
|
657
|
+
});
|
|
658
|
+
let sawRead = false, sawRecovery = false;
|
|
659
|
+
let childStarts = 0;
|
|
660
|
+
for (const handle of f.handles)
|
|
661
|
+
handle.respond = async (method, params) => {
|
|
662
|
+
if (method === 'model/list')
|
|
663
|
+
return policyCatalog;
|
|
664
|
+
if (method === 'thread/read' && params.threadId === 'child-1') {
|
|
665
|
+
sawRead = true;
|
|
666
|
+
if (['off-during-read', 'policy-during-read', 'same-plan-during-read'].includes(scenario))
|
|
667
|
+
await pendingRead.promise;
|
|
668
|
+
return {
|
|
669
|
+
thread: {
|
|
670
|
+
id: 'child-1',
|
|
671
|
+
parentThreadId: actualRootThreadId,
|
|
672
|
+
source: { subAgent: { thread_spawn: { agent_path: '/root/l1' } } },
|
|
673
|
+
status: { type: 'idle' },
|
|
674
|
+
model: scenario === 'mismatch' ? 'gpt-6-sol' : 'gpt-6.1-sol',
|
|
675
|
+
reasoningEffort: 'medium',
|
|
676
|
+
agentRole: 'default',
|
|
677
|
+
},
|
|
678
|
+
};
|
|
679
|
+
}
|
|
680
|
+
if (method === 'turn/start' && params.threadId === 'child-1') {
|
|
681
|
+
childStarts++;
|
|
682
|
+
if (scenario === 'off-on-during-recovery')
|
|
683
|
+
throw new CodexJsonRpcError(-32600, 'thread not found: child-1');
|
|
684
|
+
}
|
|
685
|
+
if (method === 'thread/resume' &&
|
|
686
|
+
params.threadId === 'child-1') {
|
|
687
|
+
sawRecovery = true;
|
|
688
|
+
await pendingRecovery.promise;
|
|
689
|
+
}
|
|
690
|
+
return undefined;
|
|
691
|
+
};
|
|
692
|
+
timers.find((timer) => !timer.cancelled).callback();
|
|
693
|
+
await vi.waitFor(() => expect(sawRead).toBe(true));
|
|
694
|
+
if (scenario === 'off-during-read' || scenario === 'off-on-during-recovery') {
|
|
695
|
+
if (scenario === 'off-on-during-recovery')
|
|
696
|
+
await vi.waitFor(() => expect(sawRecovery).toBe(true));
|
|
697
|
+
await f.app.inject({
|
|
698
|
+
method: 'PUT',
|
|
699
|
+
url: `/api/sessions/${f.sessionId}/autopilot`,
|
|
700
|
+
payload: { enabled: false },
|
|
701
|
+
});
|
|
702
|
+
if (scenario === 'off-on-during-recovery')
|
|
703
|
+
await f.app.inject({
|
|
704
|
+
method: 'PUT',
|
|
705
|
+
url: `/api/sessions/${f.sessionId}/autopilot`,
|
|
706
|
+
payload: { enabled: true },
|
|
707
|
+
});
|
|
708
|
+
}
|
|
709
|
+
if (scenario === 'policy-during-read') {
|
|
710
|
+
await writeFile(join(f.workspacePath, 'autopilot.org'), versionedText().replace(':MODEL: gpt-6.1-sol', ':MODEL: gpt-6-sol'));
|
|
711
|
+
await f.app.inject(`/api/sessions/${f.sessionId}/plan`);
|
|
712
|
+
}
|
|
713
|
+
if (scenario === 'same-plan-during-read') {
|
|
714
|
+
const planPath = join(f.workspacePath, 'autopilot.org');
|
|
715
|
+
await writeFile(planStatusFilePath(planStatusDirectoryPath(f.workspacePath, f.sessionId), planPath), JSON.stringify({
|
|
716
|
+
schemaVersion: 1,
|
|
717
|
+
planPath,
|
|
718
|
+
reason: 'supervision-start',
|
|
719
|
+
updatedAt: new Date().toISOString(),
|
|
720
|
+
modelPolicyVersion: 1,
|
|
721
|
+
requiredCapabilities: ['l1-model-policy-v1'],
|
|
722
|
+
}));
|
|
723
|
+
await f.app.inject(`/api/sessions/${f.sessionId}/plan`);
|
|
724
|
+
}
|
|
725
|
+
pendingRead.resolve({});
|
|
726
|
+
pendingRecovery.resolve({});
|
|
727
|
+
if (scenario === 'match' || scenario === 'same-plan-during-read') {
|
|
728
|
+
await vi.waitFor(() => expect(childStarts).toBe(1));
|
|
729
|
+
const call = f.handles
|
|
730
|
+
.flatMap((handle) => handle.requests)
|
|
731
|
+
.find((call) => call.method === 'turn/start');
|
|
732
|
+
expect(call?.params).toMatchObject({
|
|
733
|
+
threadId: 'child-1',
|
|
734
|
+
model: 'gpt-6.1-sol',
|
|
735
|
+
effort: 'medium',
|
|
736
|
+
});
|
|
737
|
+
}
|
|
738
|
+
else {
|
|
739
|
+
await vi.waitFor(() => expect(resumeOperation.mock.settledResults[0]?.type).toBe('rejected'));
|
|
740
|
+
expect(childStarts).toBe(scenario === 'off-on-during-recovery' ? 1 : 0);
|
|
741
|
+
}
|
|
742
|
+
});
|
|
743
|
+
it.each(['idle', 'active', 'retry', 'configured'])('delivers acknowledged attention guidance to the %s supervisor and retains its explanation beyond the journal tail', async (mode) => {
|
|
744
|
+
const fixture = await createProductionAutopilotFixture({}, mode === 'configured' ? versionedText() : undefined);
|
|
388
745
|
const { app, sessionId, handles } = fixture;
|
|
389
746
|
onTestFinished(() => app.close());
|
|
390
747
|
const handle = handles.filter((value) => value.request).at(-1);
|
|
@@ -87,7 +87,9 @@ import { autopilotWaitLeaseToolResponse, } from '../shared/contracts/autopilot-w
|
|
|
87
87
|
import { agentCapacityRecoveryToolResponse } from '../shared/contracts/agent-capacity-recovery.js';
|
|
88
88
|
import { isOrgPlanHealthCall } from '../shared/contracts/org-plan-health.js';
|
|
89
89
|
import { ExecutorModelEvidenceReader } from './features/plans/application/executor-model-evidence.js';
|
|
90
|
+
import { ExecutorLaunchValidationReader } from './features/plans/application/executor-launch-validation.js';
|
|
90
91
|
import { requireModelPolicyAdmission } from './features/plans/domain/model-policy-admission.js';
|
|
92
|
+
import { currentExecutableL1Index } from './features/plans/domain/supervised-plan.js';
|
|
91
93
|
import { pwaIconUrl } from './features/pwa/register-routes.js';
|
|
92
94
|
const generatedProtocolVersion = 'codex-cli 0.144.3';
|
|
93
95
|
const checkpointDiagnostic = debuglog('gestalt-mobile:checkpoint');
|
|
@@ -313,14 +315,22 @@ export async function composeRelayApp(options) {
|
|
|
313
315
|
const writer = await runtime.ensureWriter(session, new Date().toISOString());
|
|
314
316
|
if (!current() || writer.session.activeTurnId || blockingInteractions(sessionId).length)
|
|
315
317
|
throw new Error('AUTOPILOT_START_UNAVAILABLE');
|
|
318
|
+
const selectedPlan = supervisedPlans.find(sessionId);
|
|
319
|
+
const selectedPlanFence = JSON.stringify(selectedPlan);
|
|
320
|
+
const selectedPolicy = selectedPlan?.modelPolicyVersion === 1
|
|
321
|
+
? selectedPlan.steps[currentExecutableL1Index(selectedPlan)]?.modelPolicy
|
|
322
|
+
: undefined;
|
|
323
|
+
if (selectedPolicy)
|
|
324
|
+
await runtime.validateExecutorPolicy(sessionId, selectedPolicy);
|
|
316
325
|
await options.autopilotBeforeTurnAccepted?.({ sessionId, controlId });
|
|
317
326
|
requireOrgExecutionAdmission(sessionId);
|
|
318
327
|
if (!current() ||
|
|
328
|
+
JSON.stringify(supervisedPlans.find(sessionId)) !== selectedPlanFence ||
|
|
319
329
|
sessions.find(sessionId)?.activeTurnId ||
|
|
320
330
|
blockingInteractions(sessionId).length)
|
|
321
331
|
throw new Error('AUTOPILOT_START_UNAVAILABLE');
|
|
322
332
|
const continuationPrompt = launchIdentity
|
|
323
|
-
? autopilotExecutorLaunchPrompt(launchIdentity)
|
|
333
|
+
? autopilotExecutorLaunchPrompt(launchIdentity, supervisedPlans.find(sessionId))
|
|
324
334
|
: AUTOPILOT_CONTINUATION_PROMPT;
|
|
325
335
|
const recovery = autopilotStore.find(sessionId);
|
|
326
336
|
const executorRecovery = recovery?.supervision?.outcome === 'probeRequired' &&
|
|
@@ -703,7 +713,7 @@ export async function composeRelayApp(options) {
|
|
|
703
713
|
let closing = false;
|
|
704
714
|
let runtime = null;
|
|
705
715
|
let kimiRuntime = null;
|
|
706
|
-
const
|
|
716
|
+
const executorPolicyContext = (sessionId) => {
|
|
707
717
|
const session = sessions.find(sessionId);
|
|
708
718
|
const plan = supervisedPlans.find(sessionId);
|
|
709
719
|
if (!session || session.provider !== 'codex' || plan?.modelPolicyVersion !== 1)
|
|
@@ -713,13 +723,19 @@ export async function composeRelayApp(options) {
|
|
|
713
723
|
provider: session.provider,
|
|
714
724
|
rootThreadId: session.threadId ?? null,
|
|
715
725
|
planIdentity: supervisedPlans.identity(sessionId),
|
|
726
|
+
modelPolicyStatus: supervisedPlans.modelPolicyStatus(sessionId),
|
|
716
727
|
plan,
|
|
717
728
|
executor: autopilotStore.find(sessionId)?.executor ?? null,
|
|
718
729
|
};
|
|
719
|
-
}
|
|
730
|
+
};
|
|
731
|
+
const executorModelEvidence = new ExecutorModelEvidenceReader(executorPolicyContext, {
|
|
720
732
|
read: (input) => runtime?.readExecutorConfiguration(input) ??
|
|
721
733
|
Promise.resolve({ kind: 'unavailable', code: 'RUNTIME_UNAVAILABLE' }),
|
|
722
734
|
});
|
|
735
|
+
const executorLaunchValidation = new ExecutorLaunchValidationReader(executorPolicyContext, {
|
|
736
|
+
read: (input) => runtime?.readExecutorPolicyCatalog(input) ??
|
|
737
|
+
Promise.resolve({ kind: 'unavailable', code: 'RUNTIME_UNAVAILABLE' }),
|
|
738
|
+
});
|
|
723
739
|
/**
|
|
724
740
|
* Shared acceptance path for a provider-neutral pending interaction: it
|
|
725
741
|
* enters the durable store, requests human attention, and notifies autopilot.
|
|
@@ -900,8 +916,9 @@ export async function composeRelayApp(options) {
|
|
|
900
916
|
if (!session)
|
|
901
917
|
return false;
|
|
902
918
|
if (isOrgPlanHealthCall(request)) {
|
|
903
|
-
const snapshot = autopilot.snapshot(sessionId);
|
|
904
919
|
const modelPolicy = await executorModelEvidence.read(sessionId);
|
|
920
|
+
const executorLaunch = await executorLaunchValidation.read(sessionId);
|
|
921
|
+
const snapshot = autopilot.snapshot(sessionId);
|
|
905
922
|
return (runtime?.resolveServerRequest(sessionId, String(request.id), {
|
|
906
923
|
success: true,
|
|
907
924
|
contentItems: [
|
|
@@ -916,6 +933,7 @@ export async function composeRelayApp(options) {
|
|
|
916
933
|
? { executionAdmission: snapshot.executionAdmission }
|
|
917
934
|
: {}),
|
|
918
935
|
...(modelPolicy ? { modelPolicy } : {}),
|
|
936
|
+
...(executorLaunch ? { executorLaunch } : {}),
|
|
919
937
|
}),
|
|
920
938
|
},
|
|
921
939
|
],
|
|
@@ -1097,7 +1115,42 @@ export async function composeRelayApp(options) {
|
|
|
1097
1115
|
});
|
|
1098
1116
|
},
|
|
1099
1117
|
verify: (rpc, threadId, state) => capabilities.verify(rpc, threadId, state),
|
|
1100
|
-
},
|
|
1118
|
+
}, async (sessionId, threadId) => {
|
|
1119
|
+
requireOrgExecutionAdmission(sessionId);
|
|
1120
|
+
const plan = supervisedPlans.find(sessionId);
|
|
1121
|
+
if (plan?.modelPolicyVersion !== 1)
|
|
1122
|
+
return;
|
|
1123
|
+
const planFence = JSON.stringify(plan);
|
|
1124
|
+
const fence = () => {
|
|
1125
|
+
const state = autopilotStore.find(sessionId);
|
|
1126
|
+
return state?.requestedEnabled && state.executor?.threadId === threadId
|
|
1127
|
+
? JSON.stringify([state.generation, state.planIdentity, state.executor])
|
|
1128
|
+
: null;
|
|
1129
|
+
};
|
|
1130
|
+
const before = fence();
|
|
1131
|
+
const assertCurrent = () => {
|
|
1132
|
+
requireOrgExecutionAdmission(sessionId);
|
|
1133
|
+
if (!before ||
|
|
1134
|
+
fence() !== before ||
|
|
1135
|
+
JSON.stringify(supervisedPlans.find(sessionId)) !== planFence ||
|
|
1136
|
+
blockingInteractions(sessionId).length)
|
|
1137
|
+
throw new Error('EXECUTOR_AUTHORITY_CHANGED');
|
|
1138
|
+
};
|
|
1139
|
+
assertCurrent();
|
|
1140
|
+
const report = await executorModelEvidence.read(sessionId);
|
|
1141
|
+
assertCurrent();
|
|
1142
|
+
if (!report ||
|
|
1143
|
+
report.child.threadId !== threadId ||
|
|
1144
|
+
report.configuration === 'mismatch' ||
|
|
1145
|
+
[
|
|
1146
|
+
'CONTROLLER_BINDING_INVALID',
|
|
1147
|
+
'CONTEXT_CHANGED',
|
|
1148
|
+
'CHILD_BINDING_MISMATCH',
|
|
1149
|
+
'OBSERVATION_CHANGED',
|
|
1150
|
+
].includes(report.code))
|
|
1151
|
+
throw new Error(`EXECUTOR_POLICY_BLOCKED:${report?.code ?? 'CHILD_BINDING_UNKNOWN'}`);
|
|
1152
|
+
return { ...report.requested, assertCurrent };
|
|
1153
|
+
})
|
|
1101
1154
|
: null;
|
|
1102
1155
|
const handleKimiNotification = (sessionId, event) => {
|
|
1103
1156
|
const occurredAt = new Date().toISOString();
|
|
@@ -9,8 +9,11 @@ export const AUTOPILOT_PROMPT_VERSION = 'v13';
|
|
|
9
9
|
export const AUTOPILOT_CONTINUATION_PROMPT = 'Inspect the active supervised Org Plan. Refer to every L1 as L<a> and each nested L2 as L<a>.<b>, using one-based positions. Spawn exactly one executor per L1 and pass the exact literal task_name l<a>: l1 for L1, l2 for L2, and so on. Never create an L2-specific task name or append a title, role, nickname, plan name, or generated label. A validated DONE L2 and an accepted L1 are mandatory answer boundaries. The corresponding gestalt_org_plan_checkpoint call must be the last tool call of that root turn: immediately emit exactly one boundary final and end the turn, without followup_task, review, executor launch, or later milestone work. An accepted L1 always ends the root turn with a chat answer: never continue into the next L1 or emit post-acceptance documentation as commentary. Roll up commentary, files, verification, and commands since the previous boundary into that one answer; all later milestone activity belongs to a new root turn. On this later Autopilot turn, resume the same executor after an L2 boundary or launch exactly one fresh canonical executor for the next L1 after an accepted-L1 boundary. Treat a status question as an interruption: answer briefly, then perform the applicable continuation in the same turn. Before sending any blocker response or yielding because progress cannot continue safely, call gestalt_org_plan_attention for the matching decision-table blocker; never rely on blocker prose as the signal. When explicit human permission is required for a physical executor replacement, include executorReplacement with the exact canonicalTaskName; Mobile alone computes and persists the physical generation. Do not call attention for routine progress or a recoverable failure. Before yielding for known long work, call gestalt_autopilot_wait_lease version 2 with relevant observable wake conditions and a bounded maxWaitMs; it is one episode, so reassess before registering another in a later turn. Yield only when its response contains accepted:true; accepted:false means no continuation was registered and requires same-turn supervision. For GitHub PR CI, start an owned gh pr checks --watch process and lease processExited plus processResultAvailable while it runs. Timestamp watcher state-change and terminal observations in UTC; distinguish observation time from upstream updated_at and process exit time. When the Autopilot probe is active, register the compatible wait lease, declare genuine attention, or immediately do actionable work; never acknowledge waiting in prose. Do not send a status-only response.';
|
|
10
10
|
export const AUTOPILOT_EXECUTOR_CONTINUATION_PROMPT = 'Continue the same assigned Org L1 from its durable state. A prior turn ending did not complete the objective. Consume any supplied process result and take the next legal L2 action. Whenever an L2 reaches DONE, return its concise structured evidence and end the executor turn so the root can publish that mandatory answer boundary. Also report at the L1 review boundary or through structured attention.';
|
|
11
11
|
/** Builds a physical launch instruction while keeping durable L1 identity canonical. */
|
|
12
|
-
export function autopilotExecutorLaunchPrompt(identity) {
|
|
13
|
-
const
|
|
12
|
+
export function autopilotExecutorLaunchPrompt(identity, plan) {
|
|
13
|
+
const policy = plan?.steps.find((_, index) => `L${index + 1}` === identity.canonicalPosition)?.modelPolicy;
|
|
14
|
+
const launch = policy
|
|
15
|
+
? `Launch task_name ${identity.taskName} for canonical ${identity.canonicalPosition}, preferring agent_type default, fork_turns none, explicit model ${policy.model} and reasoning_effort ${policy.reasoningEffort}. If explicit overrides are unavailable, use the verified fixed org-plan-executor role only when both pins exactly match ${policy.model}/${policy.reasoningEffort}, omitting ineffective overrides. Load the executor duties and full L1 assignment from the Org-plan launch contract. Validate actual host support and sandbox/approval inheritance before spawning; unsupported routes are capability blockers. Assurance is configured compatibility: unavailable runtime metadata remains unknown and does not require repeated human approval. Reject observed settings mismatches; never call requested settings observed or runtime-enforced. Preserve one writer, independent review, checkpoint and terminal review gates.`
|
|
16
|
+
: `Launch task_name ${identity.taskName} for canonical ${identity.canonicalPosition} with agent_type org-plan-executor and reasoning_effort high; the profile selects gpt-5.6-terra by default, so do not override its model. Retain the canonical label in status and review output.`;
|
|
14
17
|
if (identity.generation === 1)
|
|
15
18
|
return `${AUTOPILOT_CONTINUATION_PROMPT} ${launch}`;
|
|
16
19
|
return `${AUTOPILOT_CONTINUATION_PROMPT} ${launch} This exact replacement generation ${identity.generation} is durably authorized by Mobile; do not infer another generation from this prompt or the roster; the durable ${identity.canonicalTaskName} slot may remain reserved. Do not reuse that task_name or attempt to change an existing agent's model in place. Interrupt the previous physical executor if it is still running, then spawn the authorized ${identity.taskName}. Transfer sole ${identity.canonicalPosition} ownership and continue from its durable Org Plan and worktree state.`;
|
|
@@ -2830,7 +2830,9 @@ export class AutopilotCoordinator {
|
|
|
2830
2830
|
observedAt: now,
|
|
2831
2831
|
}),
|
|
2832
2832
|
supervisionDelta: this.supervisionDelta(next),
|
|
2833
|
-
...(
|
|
2833
|
+
...(admission.allowed && admission.scope === 'legacy'
|
|
2834
|
+
? {}
|
|
2835
|
+
: { executionAdmission: admission }),
|
|
2834
2836
|
};
|
|
2835
2837
|
}
|
|
2836
2838
|
modelPolicyAdmission(sessionId) {
|
|
@@ -3325,6 +3327,17 @@ function fingerprint(plan) {
|
|
|
3325
3327
|
step.state,
|
|
3326
3328
|
step.reviewStatus,
|
|
3327
3329
|
step.children.map((child) => [child.id, child.state]),
|
|
3330
|
+
...(plan.modelPolicyVersion
|
|
3331
|
+
? [
|
|
3332
|
+
{
|
|
3333
|
+
version: plan.modelPolicyVersion,
|
|
3334
|
+
assurance: plan.modelPolicyAssurance ?? 'configured',
|
|
3335
|
+
model: step.modelPolicy?.model,
|
|
3336
|
+
reasoningEffort: step.modelPolicy?.reasoningEffort,
|
|
3337
|
+
necessity: step.modelPolicy?.necessity,
|
|
3338
|
+
},
|
|
3339
|
+
]
|
|
3340
|
+
: []),
|
|
3328
3341
|
])));
|
|
3329
3342
|
}
|
|
3330
3343
|
function boundedUnique(values, limit) {
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (C) 2026 Dyne.org foundation
|
|
3
|
+
* Designed by Denis Roio <jaromil@dyne.org>
|
|
4
|
+
* SPDX-License-Identifier: AGPL-3.0-or-later
|
|
5
|
+
*/
|
|
6
|
+
import { assessModelPolicyAdmission, } from '../domain/model-policy-admission.js';
|
|
7
|
+
import { currentExecutableL1Index } from '../domain/supervised-plan.js';
|
|
8
|
+
import { executionPolicyDigest, } from './executor-model-evidence.js';
|
|
9
|
+
/** Read-only selection evidence, never an enduring dispatch authorization or receipt. */
|
|
10
|
+
export class ExecutorLaunchValidationReader {
|
|
11
|
+
context;
|
|
12
|
+
runtime;
|
|
13
|
+
constructor(context, runtime) {
|
|
14
|
+
this.context = context;
|
|
15
|
+
this.runtime = runtime;
|
|
16
|
+
}
|
|
17
|
+
async read(sessionId) {
|
|
18
|
+
const context = this.context(sessionId);
|
|
19
|
+
if (!context ||
|
|
20
|
+
context.sessionId !== sessionId ||
|
|
21
|
+
context.provider !== 'codex' ||
|
|
22
|
+
context.plan?.modelPolicyVersion !== 1)
|
|
23
|
+
return null;
|
|
24
|
+
const index = currentExecutableL1Index(context.plan);
|
|
25
|
+
const step = context.plan.steps[index];
|
|
26
|
+
const policy = step?.modelPolicy;
|
|
27
|
+
if (!policy)
|
|
28
|
+
return null;
|
|
29
|
+
const admission = assessModelPolicyAdmission(context.plan, context.modelPolicyStatus);
|
|
30
|
+
const l1Id = Buffer.byteLength(JSON.stringify(step.id), 'utf8') <= 96 ? step.id : null;
|
|
31
|
+
const report = {
|
|
32
|
+
scope: 'prelaunch-catalog',
|
|
33
|
+
assurance: context.plan.modelPolicyAssurance ?? 'configured',
|
|
34
|
+
l1: { id: l1Id, position: index + 1 },
|
|
35
|
+
policyDigest: executionPolicyDigest(policy),
|
|
36
|
+
requested: { model: policy.model, reasoningEffort: policy.reasoningEffort },
|
|
37
|
+
validated: false,
|
|
38
|
+
code: 'CATALOG_UNAVAILABLE',
|
|
39
|
+
catalog: null,
|
|
40
|
+
runtimeEnforcement: false,
|
|
41
|
+
action: 'Read the active runtime catalog through health; child catalogRevision is not a prelaunch prerequisite.',
|
|
42
|
+
};
|
|
43
|
+
const finish = (code, action) => ({ ...report, code, action });
|
|
44
|
+
if (!admission.allowed)
|
|
45
|
+
return finish(admission.reason, admission.action);
|
|
46
|
+
if (!context.rootThreadId || !context.planIdentity || !l1Id)
|
|
47
|
+
return finish('ROOT_BINDING_MISMATCH', 'Restore the owning root/session binding before validating launch settings.');
|
|
48
|
+
const before = launchFence(context);
|
|
49
|
+
let result;
|
|
50
|
+
try {
|
|
51
|
+
result = await this.runtime.read({ sessionId, rootThreadId: context.rootThreadId });
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
return finish('CATALOG_UNAVAILABLE', 'The active runtime model/list read failed; inspect its capability without inventing catalog evidence.');
|
|
55
|
+
}
|
|
56
|
+
if (launchFence(this.context(sessionId)) !== before)
|
|
57
|
+
return finish('CONTEXT_CHANGED', 'Plan, policy or root ownership changed during the read; refresh health once before launch.');
|
|
58
|
+
if (result.kind !== 'observed')
|
|
59
|
+
return finish(result.code, 'The owning runtime catalog is unavailable; inspect the returned capability/binding code. No child receipt is required.');
|
|
60
|
+
report.catalog = {
|
|
61
|
+
source: result.source,
|
|
62
|
+
fingerprint: result.catalog.revision,
|
|
63
|
+
revisionSource: 'normalized-content-digest',
|
|
64
|
+
observedAt: result.observedAt,
|
|
65
|
+
};
|
|
66
|
+
const available = result.catalog.models.find((model) => model.id === policy.model);
|
|
67
|
+
if (!available)
|
|
68
|
+
return finish('MODEL_UNAVAILABLE', 'The runtime catalog does not support the requested exact model. Do not substitute a fallback silently.');
|
|
69
|
+
if (!available.reasoningEfforts.includes(policy.reasoningEffort))
|
|
70
|
+
return finish('EFFORT_UNSUPPORTED', 'The runtime catalog does not support the requested effort. Do not change effort silently.');
|
|
71
|
+
report.validated = true;
|
|
72
|
+
return finish('CATALOG_MATCH', 'Requested model/effort are supported by the owning runtime catalog. Proceed with the validated launch recipe within current controller authority; child settings remain unknown until observed.');
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
function launchFence(context) {
|
|
76
|
+
const index = context?.plan ? currentExecutableL1Index(context.plan) : -1;
|
|
77
|
+
const step = context?.plan?.steps[index];
|
|
78
|
+
return JSON.stringify([
|
|
79
|
+
context?.sessionId,
|
|
80
|
+
context?.provider,
|
|
81
|
+
context?.rootThreadId,
|
|
82
|
+
context?.planIdentity,
|
|
83
|
+
context?.plan?.modelPolicyVersion,
|
|
84
|
+
context?.modelPolicyStatus,
|
|
85
|
+
context?.plan?.modelPolicyAssurance ?? 'configured',
|
|
86
|
+
index,
|
|
87
|
+
step?.id,
|
|
88
|
+
step?.state,
|
|
89
|
+
step?.modelPolicy ? executionPolicyDigest(step.modelPolicy) : null,
|
|
90
|
+
]);
|
|
91
|
+
}
|
|
@@ -74,8 +74,12 @@ export class ExecutorModelEvidenceReader {
|
|
|
74
74
|
catalogRevisionSource: 'normalized-content-digest',
|
|
75
75
|
configuration: 'unknown',
|
|
76
76
|
admitted: false,
|
|
77
|
+
attested: false,
|
|
78
|
+
admissionScope: 'runtime-attestation',
|
|
77
79
|
runtimeEnforcement: false,
|
|
80
|
+
assurance: context.plan.modelPolicyAssurance ?? 'configured',
|
|
78
81
|
code: 'CHILD_BINDING_UNKNOWN',
|
|
82
|
+
action: 'Child-only evidence. Use executorLaunch for prelaunch catalog validation; this report is not launch admission.',
|
|
79
83
|
unknown: [],
|
|
80
84
|
};
|
|
81
85
|
const finish = (code) => {
|
|
@@ -91,8 +95,9 @@ export class ExecutorModelEvidenceReader {
|
|
|
91
95
|
];
|
|
92
96
|
return report;
|
|
93
97
|
};
|
|
94
|
-
if (!executor
|
|
95
|
-
|
|
98
|
+
if (!executor)
|
|
99
|
+
return finish('CHILD_NOT_LAUNCHED');
|
|
100
|
+
if (!identity ||
|
|
96
101
|
!context.rootThreadId ||
|
|
97
102
|
!context.planIdentity ||
|
|
98
103
|
!child.threadId ||
|
|
@@ -109,7 +114,7 @@ export class ExecutorModelEvidenceReader {
|
|
|
109
114
|
(executor.assignment.threadId !== executor.threadId ||
|
|
110
115
|
executor.assignment.taskPath !== executor.taskPath ||
|
|
111
116
|
executor.assignment.generation !== identity.generation)))
|
|
112
|
-
return finish('
|
|
117
|
+
return finish('CONTROLLER_BINDING_INVALID');
|
|
113
118
|
const fence = contextFence(context);
|
|
114
119
|
let result;
|
|
115
120
|
try {
|
|
@@ -175,6 +180,7 @@ function contextFence(context) {
|
|
|
175
180
|
root: context?.rootThreadId,
|
|
176
181
|
plan: context?.planIdentity,
|
|
177
182
|
policyVersion: context?.plan?.modelPolicyVersion,
|
|
183
|
+
assurance: context?.plan?.modelPolicyAssurance,
|
|
178
184
|
l1: step?.id,
|
|
179
185
|
state: step?.state,
|
|
180
186
|
policy: step?.modelPolicy ? executionPolicyDigest(step.modelPolicy) : null,
|
|
@@ -25,7 +25,7 @@ export function parseModelPolicy(properties, level, version) {
|
|
|
25
25
|
const invalid = () => {
|
|
26
26
|
throw new Error('INVALID_MODEL_POLICY');
|
|
27
27
|
};
|
|
28
|
-
if (properties.has('MODEL_POLICY_VERSION'))
|
|
28
|
+
if (properties.has('MODEL_POLICY_VERSION') || properties.has('MODEL_POLICY_ASSURANCE'))
|
|
29
29
|
invalid();
|
|
30
30
|
if (declared.length && (level === 2 || version === undefined))
|
|
31
31
|
invalid();
|
|
@@ -26,6 +26,15 @@ export function parseSupervisedPlan(input) {
|
|
|
26
26
|
declarations.some(({ line, index }) => line !== '#+MODEL_POLICY_VERSION: 1' || index >= firstHeading))
|
|
27
27
|
return unavailable('INVALID_MODEL_POLICY');
|
|
28
28
|
const modelPolicyVersion = declarations.length ? 1 : undefined;
|
|
29
|
+
const assurances = lines
|
|
30
|
+
.map((line, index) => ({ line, index }))
|
|
31
|
+
.filter(({ line }) => /^#\+MODEL_POLICY_ASSURANCE:/i.test(line));
|
|
32
|
+
if (assurances.length > 1 ||
|
|
33
|
+
assurances.some(({ line, index }) => !modelPolicyVersion ||
|
|
34
|
+
index >= firstHeading ||
|
|
35
|
+
!/^#\+MODEL_POLICY_ASSURANCE: (configured|runtime-attested)$/.test(line)))
|
|
36
|
+
return unavailable('INVALID_MODEL_POLICY');
|
|
37
|
+
const modelPolicyAssurance = assurances[0]?.line.split(': ')[1];
|
|
29
38
|
for (let index = 0; index < lines.length;) {
|
|
30
39
|
const line = lines[index];
|
|
31
40
|
const metadataMatch = /^#\+([A-Z_]+):(?:[ \t](.*))?$/.exec(line);
|
|
@@ -138,6 +147,7 @@ export function parseSupervisedPlan(input) {
|
|
|
138
147
|
...(metadata.has('DATE') ? { date: metadata.get('DATE') } : {}),
|
|
139
148
|
...(metadata.has('KEYWORDS') ? { keywords: metadata.get('KEYWORDS') } : {}),
|
|
140
149
|
...(modelPolicyVersion ? { modelPolicyVersion } : {}),
|
|
150
|
+
...(modelPolicyAssurance ? { modelPolicyAssurance } : {}),
|
|
141
151
|
steps: built,
|
|
142
152
|
totalSteps: allSteps.length,
|
|
143
153
|
doneSteps: allSteps.filter((step) => step.state === 'DONE').length,
|
|
@@ -9,7 +9,9 @@ export function assessModelPolicyAdmission(plan, status = 'legacy') {
|
|
|
9
9
|
allowed: false,
|
|
10
10
|
code: 'AUTOPILOT_MODEL_POLICY_UNAVAILABLE',
|
|
11
11
|
reason,
|
|
12
|
-
action:
|
|
12
|
+
action: reason === 'RUNTIME_ATTESTATION_UNAVAILABLE'
|
|
13
|
+
? 'This plan explicitly requires runtime-attested assurance. This adapter has no settings receipt/revision API. Use a runtime with attestation support, or explicitly authorize changing MODEL_POLICY_ASSURANCE to configured; repeating approval cannot provide attestation.'
|
|
14
|
+
: 'Repair the plan policy or its publication, then retry supervision. Manual Off and user authorization are separate from policy admission.',
|
|
13
15
|
});
|
|
14
16
|
if (status === 'unavailable')
|
|
15
17
|
return blocked('POLICY_PROJECTION_UNAVAILABLE');
|
|
@@ -23,10 +25,35 @@ export function assessModelPolicyAdmission(plan, status = 'legacy') {
|
|
|
23
25
|
return blocked('POLICY_FIELDS_INVALID');
|
|
24
26
|
if (plan.steps.some((step) => !['gpt-6-luna', 'gpt-6-sol', 'gpt-6.1-sol'].includes(step.modelPolicy.model)))
|
|
25
27
|
return blocked('MODEL_PROHIBITED');
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
if (plan.steps.some((step) => {
|
|
29
|
+
const policy = step.modelPolicy;
|
|
30
|
+
const necessity = policy.necessity;
|
|
31
|
+
return (!['medium', 'high', 'xhigh'].includes(policy.reasoningEffort) ||
|
|
32
|
+
(policy.reasoningEffort === 'medium'
|
|
33
|
+
? necessity !== null
|
|
34
|
+
: !necessity ||
|
|
35
|
+
!['unresolved-correctness', 'specific-reasoning'].includes(necessity.kind) ||
|
|
36
|
+
![
|
|
37
|
+
necessity.whyMediumInadequate,
|
|
38
|
+
necessity.evidence,
|
|
39
|
+
necessity.affectedScope,
|
|
40
|
+
necessity.returnToMedium,
|
|
41
|
+
...(policy.reasoningEffort === 'xhigh' ? [necessity.scopeReassessment] : []),
|
|
42
|
+
].every((value) => typeof value === 'string' && value.trim())));
|
|
43
|
+
}))
|
|
44
|
+
return blocked('EFFORT_UNSUPPORTED');
|
|
45
|
+
const assurance = plan.modelPolicyAssurance ?? 'configured';
|
|
46
|
+
if (!['configured', 'runtime-attested'].includes(assurance))
|
|
47
|
+
return blocked('ASSURANCE_UNSUPPORTED');
|
|
48
|
+
if (assurance === 'runtime-attested')
|
|
49
|
+
return blocked('RUNTIME_ATTESTATION_UNAVAILABLE');
|
|
50
|
+
return {
|
|
51
|
+
allowed: true,
|
|
52
|
+
scope: 'configured',
|
|
53
|
+
assurance: 'configured',
|
|
54
|
+
runtimeEnforcement: false,
|
|
55
|
+
action: 'Compatibility mode: validate exact L1 launch settings and controller-owned executor identity. Observed mismatches block continuation. Missing runtime settings remain unknown; no runtime attestation is claimed.',
|
|
56
|
+
};
|
|
30
57
|
}
|
|
31
58
|
export class ModelPolicyAdmissionError extends Error {
|
|
32
59
|
admission;
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import { ORG_PLAN_CAPABILITIES } from '../plans/org-plan-capabilities.js';
|
|
7
7
|
import { readExecutorConfiguration } from './executor-configuration.js';
|
|
8
|
+
import { decodeCodexPolicyCatalog } from './codex-model-catalog.js';
|
|
8
9
|
import { RelaySession, } from '../../features/sessions/model/relay-session.js';
|
|
9
10
|
import { randomUUID } from 'node:crypto';
|
|
10
11
|
import { createPlanMeasurementSnapshot, } from '../../features/plans/application/measurement-snapshot.js';
|
|
@@ -277,7 +278,7 @@ export class CodexSessionRuntime {
|
|
|
277
278
|
return RelaySession.rehydrate(session).startTurn(result, now).snapshot;
|
|
278
279
|
}
|
|
279
280
|
async startExecutorTurn(session, childThreadId, text, clientUserMessageId) {
|
|
280
|
-
this.requireExecutorAdmission?.(session.id);
|
|
281
|
+
const policy = await this.requireExecutorAdmission?.(session.id, childThreadId);
|
|
281
282
|
const resource = this.sessions.get(session.id);
|
|
282
283
|
if (!resource)
|
|
283
284
|
throw new Error('CODEX_SESSION_NOT_RUNNING');
|
|
@@ -285,15 +286,16 @@ export class CodexSessionRuntime {
|
|
|
285
286
|
threadId: childThreadId,
|
|
286
287
|
input: [{ type: 'text', text, text_elements: [] }],
|
|
287
288
|
clientUserMessageId,
|
|
288
|
-
...(session.modelSettings?.executorModel
|
|
289
|
-
? { model: session.modelSettings
|
|
289
|
+
...((policy?.model ?? session.modelSettings?.executorModel)
|
|
290
|
+
? { model: policy?.model ?? session.modelSettings?.executorModel }
|
|
290
291
|
: {}),
|
|
291
|
-
...(session.modelSettings?.executorReasoningEffort
|
|
292
|
-
? { effort: session.modelSettings
|
|
292
|
+
...((policy?.reasoningEffort ?? session.modelSettings?.executorReasoningEffort)
|
|
293
|
+
? { effort: policy?.reasoningEffort ?? session.modelSettings?.executorReasoningEffort }
|
|
293
294
|
: {}),
|
|
294
295
|
};
|
|
295
296
|
let response;
|
|
296
297
|
try {
|
|
298
|
+
policy?.assertCurrent();
|
|
297
299
|
response = await resource.process.rpc.request('turn/start', params);
|
|
298
300
|
}
|
|
299
301
|
catch (error) {
|
|
@@ -305,9 +307,13 @@ export class CodexSessionRuntime {
|
|
|
305
307
|
error.code !== -32600 ||
|
|
306
308
|
error.message !== `thread not found: ${childThreadId}`)
|
|
307
309
|
throw error;
|
|
308
|
-
this.requireExecutorAdmission?.(session.id);
|
|
310
|
+
await this.requireExecutorAdmission?.(session.id, childThreadId);
|
|
309
311
|
await resource.process.rpc.request('thread/resume', { threadId: childThreadId });
|
|
310
|
-
this.requireExecutorAdmission?.(session.id);
|
|
312
|
+
const refreshed = await this.requireExecutorAdmission?.(session.id, childThreadId);
|
|
313
|
+
policy?.assertCurrent();
|
|
314
|
+
if (JSON.stringify(refreshed) !== JSON.stringify(policy))
|
|
315
|
+
throw new Error('EXECUTOR_POLICY_CHANGED');
|
|
316
|
+
refreshed?.assertCurrent();
|
|
311
317
|
response = await resource.process.rpc.request('turn/start', params);
|
|
312
318
|
}
|
|
313
319
|
const result = decodeTurnStart(response);
|
|
@@ -315,6 +321,59 @@ export class CodexSessionRuntime {
|
|
|
315
321
|
resource.turnThreads.set(result, childThreadId);
|
|
316
322
|
return result;
|
|
317
323
|
}
|
|
324
|
+
/** The same session-owned catalog source for health and pre-dispatch validation. */
|
|
325
|
+
async readExecutorPolicyCatalog(input) {
|
|
326
|
+
const resource = this.sessions.get(input.sessionId);
|
|
327
|
+
if (!resource?.active)
|
|
328
|
+
return { kind: 'unavailable', code: 'RUNTIME_UNAVAILABLE' };
|
|
329
|
+
if (!input.rootThreadId || resource.threadId !== input.rootThreadId)
|
|
330
|
+
return { kind: 'unavailable', code: 'ROOT_BINDING_MISMATCH' };
|
|
331
|
+
let timer;
|
|
332
|
+
let catalog;
|
|
333
|
+
try {
|
|
334
|
+
catalog = decodeCodexPolicyCatalog(await Promise.race([
|
|
335
|
+
resource.process.rpc.request('model/list', {}),
|
|
336
|
+
new Promise((_, reject) => {
|
|
337
|
+
timer = setTimeout(() => reject(new Error('EXECUTOR_CATALOG_UNAVAILABLE')), 5_000);
|
|
338
|
+
}),
|
|
339
|
+
]));
|
|
340
|
+
}
|
|
341
|
+
catch {
|
|
342
|
+
return { kind: 'unavailable', code: 'CATALOG_UNAVAILABLE' };
|
|
343
|
+
}
|
|
344
|
+
finally {
|
|
345
|
+
if (timer)
|
|
346
|
+
clearTimeout(timer);
|
|
347
|
+
}
|
|
348
|
+
if (this.sessions.get(input.sessionId) !== resource ||
|
|
349
|
+
!resource.active ||
|
|
350
|
+
resource.threadId !== input.rootThreadId)
|
|
351
|
+
return { kind: 'unavailable', code: 'CONTEXT_CHANGED' };
|
|
352
|
+
if (!catalog)
|
|
353
|
+
return { kind: 'unavailable', code: 'CATALOG_UNAVAILABLE' };
|
|
354
|
+
return {
|
|
355
|
+
kind: 'observed',
|
|
356
|
+
source: 'runtime-model-list',
|
|
357
|
+
observedAt: new Date().toISOString(),
|
|
358
|
+
catalog,
|
|
359
|
+
};
|
|
360
|
+
}
|
|
361
|
+
/** Uses the active writer's catalog; never upgrades requested settings to observations. */
|
|
362
|
+
async validateExecutorPolicy(sessionId, policy) {
|
|
363
|
+
const resource = this.sessions.get(sessionId);
|
|
364
|
+
const result = await this.readExecutorPolicyCatalog({
|
|
365
|
+
sessionId,
|
|
366
|
+
rootThreadId: resource?.threadId ?? '',
|
|
367
|
+
});
|
|
368
|
+
if (result.kind !== 'observed')
|
|
369
|
+
throw new Error('EXECUTOR_CATALOG_UNAVAILABLE');
|
|
370
|
+
const catalog = result.catalog;
|
|
371
|
+
const model = catalog.models.find((entry) => entry.id === policy.model);
|
|
372
|
+
if (!model)
|
|
373
|
+
throw new Error('EXECUTOR_MODEL_UNAVAILABLE');
|
|
374
|
+
if (!model.reasoningEfforts.includes(policy.reasoningEffort))
|
|
375
|
+
throw new Error('EXECUTOR_EFFORT_UNSUPPORTED');
|
|
376
|
+
}
|
|
318
377
|
/** The sole authoritative in-process ownership probe. It never launches a child. */
|
|
319
378
|
ownsWriter(sessionId) {
|
|
320
379
|
return this.sessions.get(sessionId)?.active === true;
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
export const gestaltOrgPlanHealthDynamicTool = {
|
|
7
7
|
type: 'function',
|
|
8
8
|
name: 'gestalt_org_plan_health',
|
|
9
|
-
description: 'Read
|
|
9
|
+
description: 'Read current Org execution health. executorLaunch validates requested model/effort against the owning runtime catalog before a child exists; modelPolicy describes child-only settings and may remain unknown. Read-only; does not enable, resume, checkpoint, or change the Org Plan.',
|
|
10
10
|
inputSchema: { type: 'object', additionalProperties: false, properties: {} },
|
|
11
11
|
};
|
|
12
12
|
export function isOrgPlanHealthCall(input) {
|