gestalt-mobile 0.54.2 → 0.55.0
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 +19 -0
- package/dist/client/assets/{index-CRxjJEwq.js → index-DdEHicWt.js} +3 -3
- package/dist/client/index.html +1 -1
- package/dist/server/server/composition.contracts.js +379 -2
- package/dist/server/server/composition.js +38 -1
- package/dist/server/server/features/autopilot/application/service.js +174 -17
- package/dist/server/server/features/autopilot/domain/supervision-protocol.js +34 -0
- package/dist/server/server/features/plans/application/executor-model-evidence.js +192 -0
- package/dist/server/server/features/plans/application/parse-model-policy.js +77 -0
- package/dist/server/server/features/plans/application/parse-supervised-plan.js +23 -4
- package/dist/server/server/features/plans/application/supervised-plan-registry.js +16 -1
- package/dist/server/server/features/plans/domain/model-policy-admission.js +43 -0
- package/dist/server/server/platform/codex/codex-model-catalog.js +38 -0
- package/dist/server/server/platform/codex/executor-configuration.js +90 -0
- package/dist/server/server/platform/codex/session-runtime.js +33 -1
- package/dist/server/server/platform/plans/filesystem-plan-status-source.js +118 -13
- package/dist/server/server/platform/plans/org-plan-capabilities.js +2 -2
- package/gestalt-supervision-capabilities.json +8 -2
- package/package.json +1 -1
- package/scripts/watch-github-run.mjs +283 -51
package/dist/client/index.html
CHANGED
|
@@ -16,7 +16,7 @@ SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
16
16
|
<link rel="icon" href="/icons/gestalt-mobile-192.png" />
|
|
17
17
|
<link rel="apple-touch-icon" href="/icons/gestalt-mobile-180.png" />
|
|
18
18
|
<title>Gestalt Mobile</title>
|
|
19
|
-
<script type="module" crossorigin src="/assets/index-
|
|
19
|
+
<script type="module" crossorigin src="/assets/index-DdEHicWt.js"></script>
|
|
20
20
|
<link rel="stylesheet" crossorigin href="/assets/index-BRDqtTQi.css">
|
|
21
21
|
</head>
|
|
22
22
|
<body>
|
|
@@ -7,10 +7,11 @@ import { once } from 'node:events';
|
|
|
7
7
|
import { execFile } from 'node:child_process';
|
|
8
8
|
import { promisify } from 'node:util';
|
|
9
9
|
import { createHash } from 'node:crypto';
|
|
10
|
-
import { mkdtemp, mkdir, rm, symlink, writeFile } from 'node:fs/promises';
|
|
10
|
+
import { mkdtemp, mkdir, readFile, rm, symlink, writeFile } from 'node:fs/promises';
|
|
11
11
|
import { DatabaseSync } from 'node:sqlite';
|
|
12
12
|
import { tmpdir } from 'node:os';
|
|
13
13
|
import { join } from 'node:path';
|
|
14
|
+
import { pathToFileURL } from 'node:url';
|
|
14
15
|
import { describe, expect, it, onTestFinished, vi } from 'vitest';
|
|
15
16
|
import WebSocket from 'ws';
|
|
16
17
|
import { composeRelayApp } from './composition.js';
|
|
@@ -1392,7 +1393,7 @@ describe('production composition', () => {
|
|
|
1392
1393
|
expect(coordinator.registerProactiveWait(fixture.sessionId, {
|
|
1393
1394
|
id: 'pre-checkpoint-report',
|
|
1394
1395
|
leaseId: 'pre-checkpoint-lease',
|
|
1395
|
-
wakeConditions: ['executorChanged'],
|
|
1396
|
+
wakeConditions: ['executorChanged', 'processExited'],
|
|
1396
1397
|
maxWaitMs: 60_000,
|
|
1397
1398
|
})).toBe(true);
|
|
1398
1399
|
await writeFile(join(fixture.workspacePath, 'autopilot.org'), autopilotPlanText('DONE'));
|
|
@@ -1432,6 +1433,22 @@ describe('production composition', () => {
|
|
|
1432
1433
|
afterWriteDatabase.close();
|
|
1433
1434
|
expect(afterWrite.resolved_at).toEqual(expect.any(String));
|
|
1434
1435
|
expect(checkpointEvents.count).toBe(1);
|
|
1436
|
+
// Checkpoint ownership has priority over a process result that arrives
|
|
1437
|
+
// after acknowledgement but before the matching root final.
|
|
1438
|
+
handle.notify({
|
|
1439
|
+
method: 'item/completed',
|
|
1440
|
+
params: {
|
|
1441
|
+
threadId,
|
|
1442
|
+
turnId: active.active_turn_id,
|
|
1443
|
+
item: {
|
|
1444
|
+
id: 'checkpoint-process',
|
|
1445
|
+
type: 'commandExecution',
|
|
1446
|
+
status: 'completed',
|
|
1447
|
+
exitCode: 1,
|
|
1448
|
+
},
|
|
1449
|
+
},
|
|
1450
|
+
});
|
|
1451
|
+
await new Promise((resolve) => setImmediate(resolve));
|
|
1435
1452
|
expect(timers).toHaveLength(schedulesBeforeCheckpoint);
|
|
1436
1453
|
expect(coordinator.snapshot(fixture.sessionId).health).not.toMatchObject({
|
|
1437
1454
|
phase: 'waitingForAgentEvent',
|
|
@@ -2416,6 +2433,366 @@ describe('production composition', () => {
|
|
|
2416
2433
|
expect(controls).toHaveLength(2);
|
|
2417
2434
|
await fixture.app.close();
|
|
2418
2435
|
});
|
|
2436
|
+
it.each([
|
|
2437
|
+
'completion-before-deadline',
|
|
2438
|
+
'deadline-before-completion',
|
|
2439
|
+
'registration-after-final',
|
|
2440
|
+
'manual-off',
|
|
2441
|
+
'human-turn',
|
|
2442
|
+
'restored-wait',
|
|
2443
|
+
'owned-ci-watcher',
|
|
2444
|
+
'process-error',
|
|
2445
|
+
'restored-scheduled',
|
|
2446
|
+
'restored-accepted',
|
|
2447
|
+
])('production wake coalescing: %s', async (scenario) => {
|
|
2448
|
+
const timers = [];
|
|
2449
|
+
let coordinator;
|
|
2450
|
+
const fixture = await createProductionAutopilotFixture({
|
|
2451
|
+
activitySchedule: () => () => { },
|
|
2452
|
+
onAutopilotCoordinator: (value) => {
|
|
2453
|
+
coordinator = value;
|
|
2454
|
+
},
|
|
2455
|
+
autopilotSchedule: (callback) => {
|
|
2456
|
+
const timer = { callback, cancelled: false, fired: false };
|
|
2457
|
+
timers.push(timer);
|
|
2458
|
+
return () => {
|
|
2459
|
+
timer.cancelled = true;
|
|
2460
|
+
};
|
|
2461
|
+
},
|
|
2462
|
+
});
|
|
2463
|
+
onTestFinished(() => fixture.app.close());
|
|
2464
|
+
const starts = () => fixture.handles
|
|
2465
|
+
.flatMap((handle) => handle.requests)
|
|
2466
|
+
.filter((request) => request.method === 'turn/start');
|
|
2467
|
+
const runUntilStarts = async (count) => {
|
|
2468
|
+
for (let attempt = 0; attempt < 10 && starts().length < count; attempt += 1) {
|
|
2469
|
+
await vi.waitFor(() => expect(timers.some((timer) => !timer.cancelled && !timer.fired) || starts().length >= count).toBe(true));
|
|
2470
|
+
if (starts().length >= count)
|
|
2471
|
+
break;
|
|
2472
|
+
const timer = timers.find((entry) => !entry.cancelled && !entry.fired);
|
|
2473
|
+
timer.fired = true;
|
|
2474
|
+
timer.callback();
|
|
2475
|
+
await new Promise((resolve) => setImmediate(resolve));
|
|
2476
|
+
}
|
|
2477
|
+
await vi.waitFor(() => expect(starts()).toHaveLength(count));
|
|
2478
|
+
};
|
|
2479
|
+
await runUntilStarts(1);
|
|
2480
|
+
const session = (await fixture.app.inject(`/api/sessions/${fixture.sessionId}`)).json();
|
|
2481
|
+
const threadId = session.threadId;
|
|
2482
|
+
const turnId = session.activeTurnId;
|
|
2483
|
+
const handle = fixture.handles.find((candidate) => candidate.requests.some((request) => request.method === 'turn/start'));
|
|
2484
|
+
let rootActive = true;
|
|
2485
|
+
handle.respond = (method, params) => method === 'thread/read'
|
|
2486
|
+
? {
|
|
2487
|
+
thread: {
|
|
2488
|
+
id: params.threadId,
|
|
2489
|
+
status: { type: rootActive ? 'active' : 'idle' },
|
|
2490
|
+
turns: [],
|
|
2491
|
+
},
|
|
2492
|
+
}
|
|
2493
|
+
: undefined;
|
|
2494
|
+
handle.notify({ method: 'turn/started', params: { threadId, turn: { id: turnId } } });
|
|
2495
|
+
const finish = () => {
|
|
2496
|
+
rootActive = false;
|
|
2497
|
+
const completion = {
|
|
2498
|
+
method: 'turn/completed',
|
|
2499
|
+
params: { threadId, turn: { id: turnId, status: 'completed' } },
|
|
2500
|
+
};
|
|
2501
|
+
handle.notify(completion);
|
|
2502
|
+
handle.notify(completion);
|
|
2503
|
+
};
|
|
2504
|
+
const register = async (id) => {
|
|
2505
|
+
const response = (await handle.request({
|
|
2506
|
+
id,
|
|
2507
|
+
method: 'item/tool/call',
|
|
2508
|
+
params: {
|
|
2509
|
+
threadId,
|
|
2510
|
+
turnId,
|
|
2511
|
+
tool: 'gestalt_autopilot_wait_lease',
|
|
2512
|
+
arguments: {
|
|
2513
|
+
version: 2,
|
|
2514
|
+
reportId: 'race-report',
|
|
2515
|
+
leaseId: 'race-lease',
|
|
2516
|
+
wakeConditions: ['processExited'],
|
|
2517
|
+
maxWaitMs: 60_000,
|
|
2518
|
+
},
|
|
2519
|
+
},
|
|
2520
|
+
}));
|
|
2521
|
+
return JSON.parse(response.contentItems[0].text);
|
|
2522
|
+
};
|
|
2523
|
+
const completedProcess = () => handle.notify({
|
|
2524
|
+
method: 'item/completed',
|
|
2525
|
+
params: {
|
|
2526
|
+
threadId,
|
|
2527
|
+
turnId,
|
|
2528
|
+
item: {
|
|
2529
|
+
id: 'race-process',
|
|
2530
|
+
type: 'commandExecution',
|
|
2531
|
+
status: 'completed',
|
|
2532
|
+
exitCode: scenario === 'process-error' ? 1 : 0,
|
|
2533
|
+
},
|
|
2534
|
+
},
|
|
2535
|
+
});
|
|
2536
|
+
const audit = () => {
|
|
2537
|
+
const database = new DatabaseSync(join(fixture.dataDir, 'relay.sqlite'));
|
|
2538
|
+
try {
|
|
2539
|
+
return database
|
|
2540
|
+
.prepare('SELECT type,payload_json FROM session_events WHERE session_id = ? ORDER BY sequence')
|
|
2541
|
+
.all(fixture.sessionId);
|
|
2542
|
+
}
|
|
2543
|
+
finally {
|
|
2544
|
+
database.close();
|
|
2545
|
+
}
|
|
2546
|
+
};
|
|
2547
|
+
if (scenario === 'registration-after-final') {
|
|
2548
|
+
finish();
|
|
2549
|
+
await vi.waitFor(async () => expect((await fixture.app.inject(`/api/sessions/${fixture.sessionId}`)).json().activeTurnId).toBeNull());
|
|
2550
|
+
expect(await register(9100)).toMatchObject({
|
|
2551
|
+
accepted: false,
|
|
2552
|
+
reason: 'automaticContinuationUnavailable',
|
|
2553
|
+
});
|
|
2554
|
+
await runUntilStarts(2);
|
|
2555
|
+
expect(audit().filter((event) => event.type === 'autopilot.wait-registered')).toHaveLength(0);
|
|
2556
|
+
}
|
|
2557
|
+
else {
|
|
2558
|
+
expect(await register(9100)).toMatchObject({ accepted: true });
|
|
2559
|
+
if (scenario !== 'owned-ci-watcher')
|
|
2560
|
+
expect(await register(9101)).toMatchObject({ accepted: false });
|
|
2561
|
+
let deadline = timers.at(-1);
|
|
2562
|
+
// A fresh timestamp and repeated active observations cannot consume a process lease.
|
|
2563
|
+
const revision = coordinator.snapshot(fixture.sessionId).supervisionDelta.revision;
|
|
2564
|
+
vi.useFakeTimers({ toFake: ['Date'] });
|
|
2565
|
+
onTestFinished(() => {
|
|
2566
|
+
vi.useRealTimers();
|
|
2567
|
+
});
|
|
2568
|
+
vi.setSystemTime(Date.now() + 1_000);
|
|
2569
|
+
for (let index = 0; index < 3; index += 1)
|
|
2570
|
+
await fixture.app.inject({
|
|
2571
|
+
method: 'POST',
|
|
2572
|
+
url: `/api/sessions/${fixture.sessionId}/activity/refresh`,
|
|
2573
|
+
});
|
|
2574
|
+
expect(coordinator.snapshot(fixture.sessionId).supervisionDelta.revision).toBe(revision);
|
|
2575
|
+
expect(starts()).toHaveLength(1);
|
|
2576
|
+
finish();
|
|
2577
|
+
await vi.waitFor(async () => expect((await fixture.app.inject(`/api/sessions/${fixture.sessionId}`)).json().activeTurnId).toBeNull());
|
|
2578
|
+
expect(coordinator.snapshot(fixture.sessionId).health.phase).toBe('waitingForAgentEvent');
|
|
2579
|
+
if (scenario === 'restored-wait') {
|
|
2580
|
+
coordinator.dispose(fixture.sessionId);
|
|
2581
|
+
coordinator.restore(fixture.sessionId);
|
|
2582
|
+
deadline = timers.at(-1);
|
|
2583
|
+
}
|
|
2584
|
+
if (scenario === 'manual-off') {
|
|
2585
|
+
await fixture.app.inject({
|
|
2586
|
+
method: 'PUT',
|
|
2587
|
+
url: `/api/sessions/${fixture.sessionId}/autopilot`,
|
|
2588
|
+
payload: { enabled: false },
|
|
2589
|
+
});
|
|
2590
|
+
}
|
|
2591
|
+
else if (scenario === 'human-turn') {
|
|
2592
|
+
rootActive = true;
|
|
2593
|
+
expect((await fixture.app.inject({
|
|
2594
|
+
method: 'POST',
|
|
2595
|
+
url: `/api/sessions/${fixture.sessionId}/turns`,
|
|
2596
|
+
payload: { text: 'user continues work', clientUserMessageId: 'human-race' },
|
|
2597
|
+
})).statusCode).toBe(202);
|
|
2598
|
+
}
|
|
2599
|
+
if (scenario === 'owned-ci-watcher') {
|
|
2600
|
+
const gh = join(fixture.root, 'gh');
|
|
2601
|
+
const pollFile = join(fixture.root, 'polls');
|
|
2602
|
+
const evidenceDirectory = join(fixture.root, 'ci-evidence');
|
|
2603
|
+
await writeFile(gh, `#!${process.execPath}\nconst fs=require('fs');let polls=0;try{polls=Number(fs.readFileSync(${JSON.stringify(pollFile)},'utf8'))}catch{};fs.writeFileSync(${JSON.stringify(pollFile)},String(++polls));console.log(JSON.stringify({databaseId:123,attempt:2,headSha:'${'a'.repeat(40)}',status:polls<10?'in_progress':'completed',conclusion:polls<10?null:'success',jobs:[],updatedAt:'2026-10-21T08:00:00Z'}));`, { mode: 0o700 });
|
|
2604
|
+
const script = `import {watchGithubRun} from ${JSON.stringify(pathToFileURL(join(process.cwd(), 'scripts/watch-github-run.mjs')).href)};process.exitCode=await watchGithubRun({repository:'dyne/gestalt-mobile',runId:'123',attempt:2,candidate:'${'a'.repeat(40)}',evidenceDirectory:${JSON.stringify(evidenceDirectory)},gh:${JSON.stringify(gh)},pollIntervalMs:1});`;
|
|
2605
|
+
const { stdout } = await promisify(execFile)(process.execPath, [
|
|
2606
|
+
'--input-type=module',
|
|
2607
|
+
'-e',
|
|
2608
|
+
script,
|
|
2609
|
+
]);
|
|
2610
|
+
expect(stdout.trim().split('\n')).toHaveLength(3);
|
|
2611
|
+
const summary = JSON.parse(await readFile(join(evidenceDirectory, 'summary.json'), 'utf8'));
|
|
2612
|
+
expect(summary).toMatchObject({
|
|
2613
|
+
exitCode: 0,
|
|
2614
|
+
completeness: 'complete',
|
|
2615
|
+
counts: { polls: 10, changes: 2 },
|
|
2616
|
+
processExitedAt: null,
|
|
2617
|
+
});
|
|
2618
|
+
// No polling observation becomes a model turn. Only this owned
|
|
2619
|
+
// process's terminal command notification consumes the one lease.
|
|
2620
|
+
expect(starts()).toHaveLength(1);
|
|
2621
|
+
}
|
|
2622
|
+
vi.setSystemTime(Date.now() + 60_000);
|
|
2623
|
+
if (scenario === 'deadline-before-completion')
|
|
2624
|
+
deadline.callback();
|
|
2625
|
+
completedProcess();
|
|
2626
|
+
completedProcess();
|
|
2627
|
+
if (scenario === 'restored-scheduled') {
|
|
2628
|
+
// Reach the durable scheduled boundary first. Merely receiving a
|
|
2629
|
+
// command notification can still have an unfired quiescence timer.
|
|
2630
|
+
for (let attempt = 0; attempt < 5 && coordinator.snapshot(fixture.sessionId).state !== 'backoff'; attempt += 1) {
|
|
2631
|
+
const pending = timers.find((timer) => !timer.cancelled && !timer.fired);
|
|
2632
|
+
expect(pending).toBeDefined();
|
|
2633
|
+
pending.fired = true;
|
|
2634
|
+
pending.callback();
|
|
2635
|
+
await new Promise((resolve) => setImmediate(resolve));
|
|
2636
|
+
}
|
|
2637
|
+
expect(coordinator.snapshot(fixture.sessionId).state).toBe('backoff');
|
|
2638
|
+
coordinator.dispose(fixture.sessionId);
|
|
2639
|
+
coordinator.restore(fixture.sessionId);
|
|
2640
|
+
}
|
|
2641
|
+
// Delivery of an already-canceled deadline must be harmless too.
|
|
2642
|
+
deadline.callback();
|
|
2643
|
+
deadline.callback();
|
|
2644
|
+
if (scenario === 'manual-off' || scenario === 'human-turn') {
|
|
2645
|
+
await new Promise((resolve) => setImmediate(resolve));
|
|
2646
|
+
expect(starts()).toHaveLength(scenario === 'manual-off' ? 1 : 2);
|
|
2647
|
+
}
|
|
2648
|
+
else {
|
|
2649
|
+
await runUntilStarts(2);
|
|
2650
|
+
if (scenario === 'restored-accepted') {
|
|
2651
|
+
const acknowledgement = coordinator.snapshot(fixture.sessionId).supervisionDelta;
|
|
2652
|
+
coordinator.dispose(fixture.sessionId);
|
|
2653
|
+
coordinator.restore(fixture.sessionId);
|
|
2654
|
+
expect(coordinator.snapshot(fixture.sessionId).supervisionDelta).toEqual(acknowledgement);
|
|
2655
|
+
}
|
|
2656
|
+
const delivered = timers.filter((timer) => timer.fired);
|
|
2657
|
+
for (const timer of delivered)
|
|
2658
|
+
timer.callback();
|
|
2659
|
+
await new Promise((resolve) => setImmediate(resolve));
|
|
2660
|
+
expect(starts()).toHaveLength(2);
|
|
2661
|
+
}
|
|
2662
|
+
const events = audit();
|
|
2663
|
+
expect(events.filter((event) => event.type === 'autopilot.wait-registered')).toHaveLength(1);
|
|
2664
|
+
expect(events.filter((event) => event.type === 'autopilot.wait-woken' || event.type === 'autopilot.wait-expired')).toHaveLength(scenario === 'manual-off' || scenario === 'human-turn' ? 0 : 1);
|
|
2665
|
+
}
|
|
2666
|
+
const events = audit();
|
|
2667
|
+
const accepted = events
|
|
2668
|
+
.filter((event) => event.type === 'autopilot.turn-started')
|
|
2669
|
+
.map((event) => JSON.parse(event.payload_json));
|
|
2670
|
+
expect(accepted).toHaveLength(scenario === 'manual-off' || scenario === 'human-turn' ? 1 : 2);
|
|
2671
|
+
expect(new Set(accepted.map((event) => event.controlId)).size).toBe(accepted.length);
|
|
2672
|
+
expect(new Set(accepted.map((event) => event.turnId)).size).toBe(accepted.length);
|
|
2673
|
+
expect(accepted.every((event) => event.trafficClass === 'acceptedRootTurn')).toBe(true);
|
|
2674
|
+
expect(events.filter((event) => event.type === 'autopilot.continuation-scheduled')).toHaveLength(accepted.length);
|
|
2675
|
+
expect(events.filter((event) => event.type === 'autopilot.control-issued')).toHaveLength(accepted.length);
|
|
2676
|
+
});
|
|
2677
|
+
it('isolates identical process IDs and wait lease IDs across production sessions', async () => {
|
|
2678
|
+
const timers = [];
|
|
2679
|
+
const fixture = await createProductionAutopilotFixture({
|
|
2680
|
+
activitySchedule: () => () => { },
|
|
2681
|
+
autopilotSchedule: (callback) => {
|
|
2682
|
+
const timer = { callback, cancelled: false, fired: false };
|
|
2683
|
+
timers.push(timer);
|
|
2684
|
+
return () => {
|
|
2685
|
+
timer.cancelled = true;
|
|
2686
|
+
};
|
|
2687
|
+
},
|
|
2688
|
+
});
|
|
2689
|
+
onTestFinished(() => fixture.app.close());
|
|
2690
|
+
const peer = await createComposedSession(fixture.app);
|
|
2691
|
+
await installAutopilotPlan(fixture.app, peer, fixture.workspacePath, 'peer-plan');
|
|
2692
|
+
const starts = () => fixture.handles
|
|
2693
|
+
.flatMap((handle) => handle.requests)
|
|
2694
|
+
.filter((request) => request.method === 'turn/start');
|
|
2695
|
+
const drainTo = async (count) => {
|
|
2696
|
+
for (let attempt = 0; attempt < 12 && starts().length < count; attempt += 1) {
|
|
2697
|
+
const pending = timers.find((timer) => !timer.cancelled && !timer.fired);
|
|
2698
|
+
expect(pending).toBeDefined();
|
|
2699
|
+
pending.fired = true;
|
|
2700
|
+
pending.callback();
|
|
2701
|
+
await new Promise((resolve) => setImmediate(resolve));
|
|
2702
|
+
}
|
|
2703
|
+
await vi.waitFor(() => expect(starts()).toHaveLength(count));
|
|
2704
|
+
};
|
|
2705
|
+
await drainTo(2);
|
|
2706
|
+
const actors = [];
|
|
2707
|
+
for (const sessionId of [fixture.sessionId, peer]) {
|
|
2708
|
+
const session = (await fixture.app.inject(`/api/sessions/${sessionId}`)).json();
|
|
2709
|
+
const threadId = session.threadId;
|
|
2710
|
+
const turnId = session.activeTurnId;
|
|
2711
|
+
const handle = fixture.handles.find((candidate) => candidate.requests.some((request) => request.method === 'turn/start' &&
|
|
2712
|
+
request.params.threadId === threadId));
|
|
2713
|
+
const response = (await handle.request({
|
|
2714
|
+
id: 9300,
|
|
2715
|
+
method: 'item/tool/call',
|
|
2716
|
+
params: {
|
|
2717
|
+
threadId,
|
|
2718
|
+
turnId,
|
|
2719
|
+
tool: 'gestalt_autopilot_wait_lease',
|
|
2720
|
+
arguments: {
|
|
2721
|
+
version: 2,
|
|
2722
|
+
reportId: 'same-report',
|
|
2723
|
+
leaseId: 'same-lease',
|
|
2724
|
+
wakeConditions: ['processExited'],
|
|
2725
|
+
maxWaitMs: 60_000,
|
|
2726
|
+
},
|
|
2727
|
+
},
|
|
2728
|
+
}));
|
|
2729
|
+
expect(JSON.parse(response.contentItems[0].text)).toMatchObject({ accepted: true });
|
|
2730
|
+
handle.notify({
|
|
2731
|
+
method: 'turn/completed',
|
|
2732
|
+
params: { threadId, turn: { id: turnId, status: 'completed' } },
|
|
2733
|
+
});
|
|
2734
|
+
actors.push({ sessionId, handle, threadId, turnId });
|
|
2735
|
+
}
|
|
2736
|
+
expect(new Set(actors.map((actor) => actor.threadId)).size).toBe(2);
|
|
2737
|
+
for (const actor of actors)
|
|
2738
|
+
await vi.waitFor(async () => expect((await fixture.app.inject(`/api/sessions/${actor.sessionId}`)).json().autopilot.health
|
|
2739
|
+
.phase).toBe('waitingForAgentEvent'));
|
|
2740
|
+
const complete = (actor) => actor.handle.notify({
|
|
2741
|
+
method: 'item/completed',
|
|
2742
|
+
params: {
|
|
2743
|
+
threadId: actor.threadId,
|
|
2744
|
+
turnId: actor.turnId,
|
|
2745
|
+
item: {
|
|
2746
|
+
id: 'same-process',
|
|
2747
|
+
type: 'commandExecution',
|
|
2748
|
+
status: 'completed',
|
|
2749
|
+
exitCode: 1,
|
|
2750
|
+
},
|
|
2751
|
+
},
|
|
2752
|
+
});
|
|
2753
|
+
complete(actors[0]);
|
|
2754
|
+
complete(actors[0]);
|
|
2755
|
+
await drainTo(3);
|
|
2756
|
+
expect((await fixture.app.inject(`/api/sessions/${peer}`)).json()).toMatchObject({
|
|
2757
|
+
activeTurnId: null,
|
|
2758
|
+
autopilot: { health: { phase: 'waitingForAgentEvent' } },
|
|
2759
|
+
});
|
|
2760
|
+
const database = new DatabaseSync(join(fixture.dataDir, 'relay.sqlite'));
|
|
2761
|
+
try {
|
|
2762
|
+
const eventsFor = (sessionId, type) => database
|
|
2763
|
+
.prepare('SELECT count(*) AS count FROM session_events WHERE session_id = ? AND type = ?')
|
|
2764
|
+
.get(sessionId, type).count;
|
|
2765
|
+
expect(eventsFor(peer, 'autopilot.root-process-observed')).toBe(0);
|
|
2766
|
+
expect(eventsFor(peer, 'autopilot.wait-woken')).toBe(0);
|
|
2767
|
+
complete(actors[1]);
|
|
2768
|
+
await drainTo(4);
|
|
2769
|
+
for (const actor of actors) {
|
|
2770
|
+
expect(eventsFor(actor.sessionId, 'autopilot.wait-registered')).toBe(1);
|
|
2771
|
+
expect(eventsFor(actor.sessionId, 'autopilot.wait-woken')).toBe(1);
|
|
2772
|
+
expect(eventsFor(actor.sessionId, 'autopilot.control-issued')).toBe(2);
|
|
2773
|
+
expect(eventsFor(actor.sessionId, 'autopilot.turn-started')).toBe(2);
|
|
2774
|
+
const rows = database
|
|
2775
|
+
.prepare("SELECT sequence,type,payload_json FROM session_events WHERE session_id = ? AND type IN ('autopilot.root-process-observed','autopilot.wait-woken','autopilot.continuation-scheduled','autopilot.control-issued','autopilot.turn-started') ORDER BY sequence")
|
|
2776
|
+
.all(actor.sessionId);
|
|
2777
|
+
const woken = rows.find((row) => row.type === 'autopilot.wait-woken');
|
|
2778
|
+
const afterWake = rows.filter((row) => row.sequence > woken.sequence && row.type !== 'autopilot.root-process-observed');
|
|
2779
|
+
expect(afterWake.map((row) => row.type)).toEqual([
|
|
2780
|
+
'autopilot.continuation-scheduled',
|
|
2781
|
+
'autopilot.control-issued',
|
|
2782
|
+
'autopilot.turn-started',
|
|
2783
|
+
]);
|
|
2784
|
+
expect(new Set(afterWake.map((row) => JSON.parse(row.payload_json).controlId)).size).toBe(1);
|
|
2785
|
+
expect(JSON.parse(afterWake.at(-1).payload_json)).toMatchObject({
|
|
2786
|
+
trafficClass: 'acceptedRootTurn',
|
|
2787
|
+
turnId: expect.any(String),
|
|
2788
|
+
wakeReason: 'processExited',
|
|
2789
|
+
});
|
|
2790
|
+
}
|
|
2791
|
+
}
|
|
2792
|
+
finally {
|
|
2793
|
+
database.close();
|
|
2794
|
+
}
|
|
2795
|
+
});
|
|
2419
2796
|
it('production child-idle transition wakes an idle supervised autopilot', async () => {
|
|
2420
2797
|
const timers = [];
|
|
2421
2798
|
const fixture = await createProductionAutopilotFixture({
|
|
@@ -86,6 +86,8 @@ import { parseOrgPlanAttention, parseOrgPlanAttentionToolResponse, toOrgPlanAtte
|
|
|
86
86
|
import { autopilotWaitLeaseToolResponse, } from '../shared/contracts/autopilot-wait-lease.js';
|
|
87
87
|
import { agentCapacityRecoveryToolResponse } from '../shared/contracts/agent-capacity-recovery.js';
|
|
88
88
|
import { isOrgPlanHealthCall } from '../shared/contracts/org-plan-health.js';
|
|
89
|
+
import { ExecutorModelEvidenceReader } from './features/plans/application/executor-model-evidence.js';
|
|
90
|
+
import { requireModelPolicyAdmission } from './features/plans/domain/model-policy-admission.js';
|
|
89
91
|
import { pwaIconUrl } from './features/pwa/register-routes.js';
|
|
90
92
|
const generatedProtocolVersion = 'codex-cli 0.144.3';
|
|
91
93
|
const checkpointDiagnostic = debuglog('gestalt-mobile:checkpoint');
|
|
@@ -127,6 +129,7 @@ export async function composeRelayApp(options) {
|
|
|
127
129
|
const attentionAcknowledgementTimers = new Map();
|
|
128
130
|
const checkpointHandoffRecoveries = new Set();
|
|
129
131
|
const supervisedPlans = new SupervisedPlanRegistry();
|
|
132
|
+
const requireOrgExecutionAdmission = (sessionId) => requireModelPolicyAdmission(supervisedPlans.find(sessionId), supervisedPlans.modelPolicyStatus(sessionId));
|
|
130
133
|
const planStatusSource = new FilesystemPlanStatusSource(join(dirname(databasePath), 'plans'));
|
|
131
134
|
const planMeasurementHelperPath = options.planMeasurementHelperPath ?? process.env.GESTALT_MOBILE_ORG_PLAN_HELPER;
|
|
132
135
|
const pendingInteractionsWithReports = (sessionId) => interactions.list(sessionId).map((interaction) => ({
|
|
@@ -248,6 +251,7 @@ export async function composeRelayApp(options) {
|
|
|
248
251
|
},
|
|
249
252
|
});
|
|
250
253
|
const autopilot = new AutopilotCoordinator({
|
|
254
|
+
modelPolicyStatus: (sessionId) => supervisedPlans.modelPolicyStatus(sessionId),
|
|
251
255
|
store: autopilotStore,
|
|
252
256
|
now: () => new Date().toISOString(),
|
|
253
257
|
policy: defaultAutopilotPolicy,
|
|
@@ -298,6 +302,11 @@ export async function composeRelayApp(options) {
|
|
|
298
302
|
const session = sessions.find(sessionId);
|
|
299
303
|
if (!session || !runtime || session.activeTurnId || blockingInteractions(sessionId).length)
|
|
300
304
|
throw new Error('AUTOPILOT_START_UNAVAILABLE');
|
|
305
|
+
requireOrgExecutionAdmission(sessionId);
|
|
306
|
+
if (!current() ||
|
|
307
|
+
sessions.find(sessionId)?.activeTurnId ||
|
|
308
|
+
blockingInteractions(sessionId).length)
|
|
309
|
+
throw new Error('AUTOPILOT_START_UNAVAILABLE');
|
|
301
310
|
// A relay restart can leave a durable, otherwise eligible session without this
|
|
302
311
|
// process's writer. Reacquire through the normal ownership boundary before a
|
|
303
312
|
// synthetic start; never bypass its single-writer and replacement semantics.
|
|
@@ -305,6 +314,11 @@ export async function composeRelayApp(options) {
|
|
|
305
314
|
if (!current() || writer.session.activeTurnId || blockingInteractions(sessionId).length)
|
|
306
315
|
throw new Error('AUTOPILOT_START_UNAVAILABLE');
|
|
307
316
|
await options.autopilotBeforeTurnAccepted?.({ sessionId, controlId });
|
|
317
|
+
requireOrgExecutionAdmission(sessionId);
|
|
318
|
+
if (!current() ||
|
|
319
|
+
sessions.find(sessionId)?.activeTurnId ||
|
|
320
|
+
blockingInteractions(sessionId).length)
|
|
321
|
+
throw new Error('AUTOPILOT_START_UNAVAILABLE');
|
|
308
322
|
const continuationPrompt = launchIdentity
|
|
309
323
|
? autopilotExecutorLaunchPrompt(launchIdentity)
|
|
310
324
|
: AUTOPILOT_CONTINUATION_PROMPT;
|
|
@@ -337,6 +351,7 @@ export async function composeRelayApp(options) {
|
|
|
337
351
|
const session = sessions.find(sessionId);
|
|
338
352
|
if (!session || !runtime || blockingInteractions(sessionId).length)
|
|
339
353
|
throw new Error('AUTOPILOT_EXECUTOR_UNAVAILABLE');
|
|
354
|
+
requireOrgExecutionAdmission(sessionId);
|
|
340
355
|
const writer = await runtime.ensureWriter(session, new Date().toISOString());
|
|
341
356
|
if (blockingInteractions(sessionId).length)
|
|
342
357
|
throw new Error('AUTOPILOT_EXECUTOR_UNAVAILABLE');
|
|
@@ -688,6 +703,23 @@ export async function composeRelayApp(options) {
|
|
|
688
703
|
let closing = false;
|
|
689
704
|
let runtime = null;
|
|
690
705
|
let kimiRuntime = null;
|
|
706
|
+
const executorModelEvidence = new ExecutorModelEvidenceReader((sessionId) => {
|
|
707
|
+
const session = sessions.find(sessionId);
|
|
708
|
+
const plan = supervisedPlans.find(sessionId);
|
|
709
|
+
if (!session || session.provider !== 'codex' || plan?.modelPolicyVersion !== 1)
|
|
710
|
+
return null;
|
|
711
|
+
return {
|
|
712
|
+
sessionId,
|
|
713
|
+
provider: session.provider,
|
|
714
|
+
rootThreadId: session.threadId ?? null,
|
|
715
|
+
planIdentity: supervisedPlans.identity(sessionId),
|
|
716
|
+
plan,
|
|
717
|
+
executor: autopilotStore.find(sessionId)?.executor ?? null,
|
|
718
|
+
};
|
|
719
|
+
}, {
|
|
720
|
+
read: (input) => runtime?.readExecutorConfiguration(input) ??
|
|
721
|
+
Promise.resolve({ kind: 'unavailable', code: 'RUNTIME_UNAVAILABLE' }),
|
|
722
|
+
});
|
|
691
723
|
/**
|
|
692
724
|
* Shared acceptance path for a provider-neutral pending interaction: it
|
|
693
725
|
* enters the durable store, requests human attention, and notifies autopilot.
|
|
@@ -869,6 +901,7 @@ export async function composeRelayApp(options) {
|
|
|
869
901
|
return false;
|
|
870
902
|
if (isOrgPlanHealthCall(request)) {
|
|
871
903
|
const snapshot = autopilot.snapshot(sessionId);
|
|
904
|
+
const modelPolicy = await executorModelEvidence.read(sessionId);
|
|
872
905
|
return (runtime?.resolveServerRequest(sessionId, String(request.id), {
|
|
873
906
|
success: true,
|
|
874
907
|
contentItems: [
|
|
@@ -879,6 +912,10 @@ export async function composeRelayApp(options) {
|
|
|
879
912
|
enabled: snapshot.enabled,
|
|
880
913
|
health: snapshot.health,
|
|
881
914
|
reason: snapshot.reason,
|
|
915
|
+
...(snapshot.executionAdmission
|
|
916
|
+
? { executionAdmission: snapshot.executionAdmission }
|
|
917
|
+
: {}),
|
|
918
|
+
...(modelPolicy ? { modelPolicy } : {}),
|
|
882
919
|
}),
|
|
883
920
|
},
|
|
884
921
|
],
|
|
@@ -1060,7 +1097,7 @@ export async function composeRelayApp(options) {
|
|
|
1060
1097
|
});
|
|
1061
1098
|
},
|
|
1062
1099
|
verify: (rpc, threadId, state) => capabilities.verify(rpc, threadId, state),
|
|
1063
|
-
})
|
|
1100
|
+
}, requireOrgExecutionAdmission)
|
|
1064
1101
|
: null;
|
|
1065
1102
|
const handleKimiNotification = (sessionId, event) => {
|
|
1066
1103
|
const occurredAt = new Date().toISOString();
|