gestalt-mobile 0.65.3 → 0.65.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/dist/server/server/composition.contracts.js +190 -0
- package/dist/server/server/composition.js +5 -8
- package/dist/server/server/features/agent-activity/registry.js +7 -0
- package/dist/server/server/features/autopilot/application/service.js +14 -0
- package/dist/server/server/platform/codex/session-runtime.js +13 -5
- package/dist/server/shared/contracts/autopilot-wait-lease.js +2 -2
- package/package.json +1 -1
|
@@ -20,6 +20,8 @@ import { CodexJsonRpcError } from './platform/codex/json-rpc-client.js';
|
|
|
20
20
|
import { CodexSessionRuntime } from './platform/codex/session-runtime.js';
|
|
21
21
|
import { SqliteAuthorizationStore } from './platform/auth/sqlite-authorization-store.js';
|
|
22
22
|
import { SqliteEventJournal } from './platform/persistence/sqlite-event-journal.js';
|
|
23
|
+
import { SqliteAutopilotStore } from './platform/persistence/sqlite-autopilot-store.js';
|
|
24
|
+
import { startSupervisionProtocol } from './features/autopilot/domain/supervision-protocol.js';
|
|
23
25
|
import { exportControlPlaneTrace } from './features/control-plane-trace/export-trace.js';
|
|
24
26
|
import { authorizationSessionId, authorizedDeviceId, localOwnerId, webAuthnCredentialId, } from './features/auth/domain/identifiers.js';
|
|
25
27
|
import { deviceNickname } from './features/auth/domain/device-nickname.js';
|
|
@@ -388,6 +390,194 @@ async function createUnauthorizedProductionApp(root, dataDir) {
|
|
|
388
390
|
}
|
|
389
391
|
describe('production composition', () => {
|
|
390
392
|
describeCompositionConcern('autopilot', () => {
|
|
393
|
+
it('persists a bounded executor after 64 exited results and new active work, including a plan watcher update', async () => {
|
|
394
|
+
const handles = [];
|
|
395
|
+
const launch = liveAppServer(handles);
|
|
396
|
+
const diagnostic = vi.fn();
|
|
397
|
+
let coordinator;
|
|
398
|
+
const old = Array.from({ length: 64 }, (_, n) => ({
|
|
399
|
+
itemId: `old-item-${n}`,
|
|
400
|
+
processId: `old-${n}`,
|
|
401
|
+
}));
|
|
402
|
+
let active = old;
|
|
403
|
+
const fixture = await createProductionAutopilotFixture({
|
|
404
|
+
activitySchedule: () => () => { },
|
|
405
|
+
autopilotSchedule: () => () => { },
|
|
406
|
+
activityDiagnostic: diagnostic,
|
|
407
|
+
onAutopilotCoordinator: (value) => {
|
|
408
|
+
coordinator = value;
|
|
409
|
+
},
|
|
410
|
+
launchAppServer: () => {
|
|
411
|
+
const server = launch();
|
|
412
|
+
handles.at(-1).respond = (method, params) => {
|
|
413
|
+
if (method === 'thread/list')
|
|
414
|
+
return {
|
|
415
|
+
data: [
|
|
416
|
+
{
|
|
417
|
+
id: 'child-1',
|
|
418
|
+
status: { type: 'idle' },
|
|
419
|
+
source: { subAgent: { thread_spawn: { agent_path: '/root/l1' } } },
|
|
420
|
+
},
|
|
421
|
+
],
|
|
422
|
+
};
|
|
423
|
+
if (method === 'thread/backgroundTerminals/list')
|
|
424
|
+
return { data: active, nextCursor: null };
|
|
425
|
+
if (method === 'thread/read' && params.threadId === 'child-1')
|
|
426
|
+
return {
|
|
427
|
+
thread: {
|
|
428
|
+
id: 'child-1',
|
|
429
|
+
turns: [
|
|
430
|
+
{
|
|
431
|
+
items: old.map((item) => ({
|
|
432
|
+
id: item.itemId,
|
|
433
|
+
type: 'commandExecution',
|
|
434
|
+
status: 'completed',
|
|
435
|
+
exitCode: 0,
|
|
436
|
+
})),
|
|
437
|
+
},
|
|
438
|
+
],
|
|
439
|
+
},
|
|
440
|
+
};
|
|
441
|
+
return undefined;
|
|
442
|
+
};
|
|
443
|
+
return server;
|
|
444
|
+
},
|
|
445
|
+
});
|
|
446
|
+
onTestFinished(() => fixture.app.close());
|
|
447
|
+
const rootThreadId = (await fixture.app.inject(`/api/sessions/${fixture.sessionId}`)).json()
|
|
448
|
+
.threadId;
|
|
449
|
+
handles.find((handle) => handle.calls.includes('thread/start')).notify({
|
|
450
|
+
method: 'thread/started',
|
|
451
|
+
params: { thread: { id: rootThreadId, status: { type: 'idle' } } },
|
|
452
|
+
});
|
|
453
|
+
const database = new DatabaseSync(join(fixture.dataDir, 'relay.sqlite'));
|
|
454
|
+
onTestFinished(() => database.close());
|
|
455
|
+
const executor = () => {
|
|
456
|
+
const row = database
|
|
457
|
+
.prepare('SELECT lifecycle_json FROM autopilot_sessions WHERE session_id = ?')
|
|
458
|
+
.get(fixture.sessionId);
|
|
459
|
+
return JSON.parse(row.lifecycle_json).executor;
|
|
460
|
+
};
|
|
461
|
+
const refresh = async () => {
|
|
462
|
+
const response = await fixture.app.inject({
|
|
463
|
+
method: 'POST',
|
|
464
|
+
url: `/api/sessions/${fixture.sessionId}/activity/refresh`,
|
|
465
|
+
});
|
|
466
|
+
expect(response.statusCode).toBe(202);
|
|
467
|
+
await vi.waitFor(async () => expect((await fixture.app.inject(`/api/sessions/${fixture.sessionId}`)).json()).toMatchObject({
|
|
468
|
+
agentActivity: { confidence: 'fresh' },
|
|
469
|
+
autopilot: { enabled: true },
|
|
470
|
+
}));
|
|
471
|
+
};
|
|
472
|
+
await refresh();
|
|
473
|
+
expect(executor().ownedProcesses).toHaveLength(64);
|
|
474
|
+
active = [];
|
|
475
|
+
await refresh();
|
|
476
|
+
await vi.waitFor(() => {
|
|
477
|
+
expect(coordinator.reconcileExecutorBinding(fixture.sessionId)).toMatchObject({
|
|
478
|
+
status: 'ready',
|
|
479
|
+
});
|
|
480
|
+
expect(executor().ownedProcesses.some((process) => process.state === 'running')).toBe(false);
|
|
481
|
+
expect(executor().ownedProcesses.some((process) => process.state === 'exited-awaiting-result')).toBe(true);
|
|
482
|
+
});
|
|
483
|
+
active = Array.from({ length: 64 }, (_, n) => ({
|
|
484
|
+
itemId: `new-item-${n}`,
|
|
485
|
+
processId: `new-active-${n}`,
|
|
486
|
+
}));
|
|
487
|
+
await refresh();
|
|
488
|
+
await vi.waitFor(() => expect(executor().ownedProcesses[0]).toMatchObject({
|
|
489
|
+
processId: 'new-active-0',
|
|
490
|
+
state: expect.stringMatching(/^(running|detached-active)$/),
|
|
491
|
+
}));
|
|
492
|
+
expect(executor().ownedProcesses).toHaveLength(64);
|
|
493
|
+
await writeFile(join(fixture.workspacePath, 'autopilot.org'), autopilotPlanText('TODO').replace('Parent', 'Updated parent'));
|
|
494
|
+
await vi.waitFor(async () => {
|
|
495
|
+
expect((await fixture.app.inject(`/api/sessions/${fixture.sessionId}/plan`)).json()).toMatchObject({ steps: [{ title: 'Updated parent' }] });
|
|
496
|
+
});
|
|
497
|
+
expect(executor().ownedProcesses).toHaveLength(64);
|
|
498
|
+
expect(diagnostic).not.toHaveBeenCalled();
|
|
499
|
+
expect(database
|
|
500
|
+
.prepare("SELECT count(*) AS count FROM session_events WHERE session_id = ? AND type = 'autopilot.operation-failed'")
|
|
501
|
+
.get(fixture.sessionId)).toMatchObject({ count: 0 });
|
|
502
|
+
});
|
|
503
|
+
it.each([1, 2])('keeps a version %s wait validation error recoverable during a probe', async (version) => {
|
|
504
|
+
const fixture = await createProductionAutopilotFixture({
|
|
505
|
+
autopilotSchedule: () => () => { },
|
|
506
|
+
});
|
|
507
|
+
onTestFinished(() => fixture.app.close());
|
|
508
|
+
const started = await fixture.app.inject({
|
|
509
|
+
method: 'POST',
|
|
510
|
+
url: `/api/sessions/${fixture.sessionId}/turns`,
|
|
511
|
+
payload: { text: 'Synthetic wait validation fixture' },
|
|
512
|
+
});
|
|
513
|
+
expect(started.statusCode).toBe(202);
|
|
514
|
+
const session = (await fixture.app.inject(`/api/sessions/${fixture.sessionId}`)).json();
|
|
515
|
+
const handle = fixture.handles.find((candidate) => candidate.calls.includes('turn/start'));
|
|
516
|
+
handle.notify({
|
|
517
|
+
method: 'turn/started',
|
|
518
|
+
params: { threadId: session.threadId, turn: { id: session.activeTurnId } },
|
|
519
|
+
});
|
|
520
|
+
const database = new DatabaseSync(join(fixture.dataDir, 'relay.sqlite'));
|
|
521
|
+
onTestFinished(() => database.close());
|
|
522
|
+
const store = new SqliteAutopilotStore(database);
|
|
523
|
+
const state = store.find(fixture.sessionId);
|
|
524
|
+
store.save({
|
|
525
|
+
...state,
|
|
526
|
+
requestedEnabled: true,
|
|
527
|
+
state: 'monitoring',
|
|
528
|
+
supervision: {
|
|
529
|
+
...startSupervisionProtocol('probe-progress'),
|
|
530
|
+
outcome: 'probeRequired',
|
|
531
|
+
probeKey: 'probe-progress',
|
|
532
|
+
unchangedContinuations: 3,
|
|
533
|
+
},
|
|
534
|
+
});
|
|
535
|
+
let requestId = 9000;
|
|
536
|
+
const call = async (wakeConditions) => {
|
|
537
|
+
const response = (await handle.request({
|
|
538
|
+
id: ++requestId,
|
|
539
|
+
method: 'item/tool/call',
|
|
540
|
+
params: {
|
|
541
|
+
threadId: session.threadId,
|
|
542
|
+
turnId: session.activeTurnId,
|
|
543
|
+
tool: 'gestalt_autopilot_wait_lease',
|
|
544
|
+
arguments: {
|
|
545
|
+
version,
|
|
546
|
+
reportId: 'wait-validation-report',
|
|
547
|
+
leaseId: 'wait-validation-lease',
|
|
548
|
+
wakeConditions,
|
|
549
|
+
...(version === 2 ? { maxWaitMs: 180_000 } : {}),
|
|
550
|
+
},
|
|
551
|
+
},
|
|
552
|
+
}));
|
|
553
|
+
return JSON.parse(response.contentItems[0].text);
|
|
554
|
+
};
|
|
555
|
+
expect(await call(['unsupported'])).toEqual({
|
|
556
|
+
accepted: false,
|
|
557
|
+
reason: 'invalidWaitLease',
|
|
558
|
+
next: 'continueSameTurn',
|
|
559
|
+
});
|
|
560
|
+
expect(store.find(fixture.sessionId)).toMatchObject({
|
|
561
|
+
requestedEnabled: true,
|
|
562
|
+
state: 'monitoring',
|
|
563
|
+
supervision: { outcome: 'probeRequired' },
|
|
564
|
+
});
|
|
565
|
+
const wakeConditions = [
|
|
566
|
+
'processExited',
|
|
567
|
+
'processResultAvailable',
|
|
568
|
+
'planChanged',
|
|
569
|
+
'interactionChanged',
|
|
570
|
+
'executorChanged',
|
|
571
|
+
];
|
|
572
|
+
expect(await call(wakeConditions)).toEqual({ accepted: true });
|
|
573
|
+
expect(store.find(fixture.sessionId)).toMatchObject({
|
|
574
|
+
requestedEnabled: true,
|
|
575
|
+
supervision: { outcome: 'parked', waitLease: { wakeConditions } },
|
|
576
|
+
});
|
|
577
|
+
expect(database
|
|
578
|
+
.prepare("SELECT COUNT(*) AS count FROM session_events WHERE session_id = ? AND type = 'autopilot.safety-paused'")
|
|
579
|
+
.get(fixture.sessionId)?.count).toBe(0);
|
|
580
|
+
});
|
|
391
581
|
it('serves compact supervision deltas and wakes only for the selected host run', async () => {
|
|
392
582
|
let coordinator;
|
|
393
583
|
const f = await createProductionAutopilotFixture({
|
|
@@ -61,7 +61,7 @@ import { GitSummaryCache } from './platform/git/git-summary-cache.js';
|
|
|
61
61
|
import { SessionSupervisor } from './platform/runtime/session-supervisor.js';
|
|
62
62
|
import { mapWithConcurrency } from './platform/runtime/concurrency.js';
|
|
63
63
|
import { RelaySession, } from './features/sessions/model/relay-session.js';
|
|
64
|
-
import { AgentActivityRegistry } from './features/agent-activity/registry.js';
|
|
64
|
+
import { AgentActivityRegistry, } from './features/agent-activity/registry.js';
|
|
65
65
|
import { SupervisionTakeover } from './features/autopilot/application/takeover-supervision.js';
|
|
66
66
|
import { SqliteSupervisionTakeoverStore } from './platform/persistence/sqlite-supervision-takeover-store.js';
|
|
67
67
|
import { isOrgPlanTakeoverCall } from '../shared/contracts/org-plan-takeover.js';
|
|
@@ -237,7 +237,7 @@ export async function composeRelayApp(options) {
|
|
|
237
237
|
}),
|
|
238
238
|
now: () => new Date().toISOString(),
|
|
239
239
|
diagnostic: options.activityDiagnostic ??
|
|
240
|
-
((sessionId, code, detail) => console.warn(`agent activity ${code} session=${sessionId} attempt=${detail?.attempt ?? 0} rpcCode=${detail?.rpcCode ?? 'none'}`)),
|
|
240
|
+
((sessionId, code, detail) => console.warn(`agent activity ${code} session=${sessionId} attempt=${detail?.attempt ?? 0} rpcCode=${detail?.rpcCode ?? 'none'} errorCode=${detail?.errorCode ?? 'none'}`)),
|
|
241
241
|
reconcile: async (sessionId) => {
|
|
242
242
|
const session = sessions.find(sessionId);
|
|
243
243
|
if (!session)
|
|
@@ -1294,10 +1294,9 @@ export async function composeRelayApp(options) {
|
|
|
1294
1294
|
scheduleAgentCapacityRecovery(sessionId, () => runtime?.resolveServerRequest(sessionId, String(request.id), agentCapacityRecoveryToolResponse()) === true));
|
|
1295
1295
|
}
|
|
1296
1296
|
if (!rawInteraction && isAutopilotWaitLeaseCall(request)) {
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
return (runtime?.resolveServerRequest(sessionId, String(request.id), autopilotWaitLeaseToolResponse(false)) === true);
|
|
1297
|
+
// Invalid tool arguments are recoverable in this turn. They do not
|
|
1298
|
+
// establish that supervision is stalled or revoke continuation.
|
|
1299
|
+
return (runtime?.resolveServerRequest(sessionId, String(request.id), autopilotWaitLeaseToolResponse(false, 'invalidWaitLease')) === true);
|
|
1301
1300
|
}
|
|
1302
1301
|
if (!rawInteraction)
|
|
1303
1302
|
return false;
|
|
@@ -1319,8 +1318,6 @@ export async function composeRelayApp(options) {
|
|
|
1319
1318
|
wakeConditions: lease.wakeConditions,
|
|
1320
1319
|
}));
|
|
1321
1320
|
if (registration !== true) {
|
|
1322
|
-
if (rootOwned && registration === false)
|
|
1323
|
-
autopilot.rejectProbe(sessionId);
|
|
1324
1321
|
return (runtime?.resolveServerRequest(sessionId, rawInteraction.requestId, autopilotWaitLeaseToolResponse(false, registration === 'wakeAlreadySatisfied'
|
|
1325
1322
|
? 'wakeAlreadySatisfied'
|
|
1326
1323
|
: 'automaticContinuationUnavailable')) === true);
|
|
@@ -209,6 +209,13 @@ export class AgentActivityRegistry {
|
|
|
209
209
|
this.options.diagnostic?.(sessionId, 'reconcileExhausted', {
|
|
210
210
|
attempt,
|
|
211
211
|
...(rpcCode !== undefined ? { rpcCode } : {}),
|
|
212
|
+
// Fixed controller code only; arbitrary exception text stays private.
|
|
213
|
+
...(error &&
|
|
214
|
+
typeof error === 'object' &&
|
|
215
|
+
'code' in error &&
|
|
216
|
+
error.code === 'AUTOPILOT_STATE_INVALID'
|
|
217
|
+
? { errorCode: 'AUTOPILOT_STATE_INVALID' }
|
|
218
|
+
: {}),
|
|
212
219
|
});
|
|
213
220
|
this.disconnected(sessionId, this.options.now?.() ?? now);
|
|
214
221
|
return;
|
|
@@ -1281,6 +1281,16 @@ export class AutopilotCoordinator {
|
|
|
1281
1281
|
}
|
|
1282
1282
|
/** Handles only plan lifecycle safety; ordinary plan mutations are ignored. */
|
|
1283
1283
|
planStatusChanged(sessionId) {
|
|
1284
|
+
try {
|
|
1285
|
+
this.applyPlanStatusChanged(sessionId);
|
|
1286
|
+
}
|
|
1287
|
+
catch (error) {
|
|
1288
|
+
// Filesystem watchers invoke this synchronous boundary without a caller
|
|
1289
|
+
// that can handle rejection. Use the same durable recovery as queued work.
|
|
1290
|
+
this.containOperationFailure(sessionId, error);
|
|
1291
|
+
}
|
|
1292
|
+
}
|
|
1293
|
+
applyPlanStatusChanged(sessionId) {
|
|
1284
1294
|
this.reconcileExecutorBinding(sessionId);
|
|
1285
1295
|
const prior = this.deps.store.find(sessionId);
|
|
1286
1296
|
if (!prior)
|
|
@@ -3526,6 +3536,8 @@ function startFailureCode(error) {
|
|
|
3526
3536
|
}
|
|
3527
3537
|
/** Keep failure telemetry bounded and free of prompts, paths, and error prose. */
|
|
3528
3538
|
function operationFailureCode(error) {
|
|
3539
|
+
if (error instanceof AutopilotStateError)
|
|
3540
|
+
return 'PERSISTENCE';
|
|
3529
3541
|
const code = error && typeof error === 'object' && 'code' in error && typeof error.code === 'string'
|
|
3530
3542
|
? error.code
|
|
3531
3543
|
: error instanceof Error
|
|
@@ -3548,6 +3560,8 @@ function operationRpcCode(error) {
|
|
|
3548
3560
|
return undefined;
|
|
3549
3561
|
}
|
|
3550
3562
|
function operationErrorKind(error) {
|
|
3563
|
+
if (error instanceof AutopilotStateError)
|
|
3564
|
+
return 'AUTOPILOT_STATE_INVALID';
|
|
3551
3565
|
if (error &&
|
|
3552
3566
|
typeof error === 'object' &&
|
|
3553
3567
|
'kind' in error &&
|
|
@@ -961,9 +961,7 @@ export class CodexSessionRuntime {
|
|
|
961
961
|
error.code !== -32600 ||
|
|
962
962
|
error.message !== `thread not found: ${child.id}`)
|
|
963
963
|
throw error;
|
|
964
|
-
return
|
|
965
|
-
process.state !== 'result-consumed' &&
|
|
966
|
-
process.state !== 'terminated-for-budget');
|
|
964
|
+
return this.childProcessBatch(owned, child.id);
|
|
967
965
|
}
|
|
968
966
|
const activeIds = new Set(active.map((process) => process.processId));
|
|
969
967
|
for (const process of active)
|
|
@@ -985,9 +983,19 @@ export class CodexSessionRuntime {
|
|
|
985
983
|
});
|
|
986
984
|
}
|
|
987
985
|
}
|
|
988
|
-
return
|
|
986
|
+
return this.childProcessBatch(owned, child.id);
|
|
987
|
+
}
|
|
988
|
+
childProcessBatch(owned, childThreadId) {
|
|
989
|
+
// The active RPC is bounded, but exited results accumulate across reads.
|
|
990
|
+
// Keep that backlog until explicit consumption; only the lifecycle batch is
|
|
991
|
+
// bounded. Active work must remain visible even when older results fill it.
|
|
992
|
+
return [...owned.ownedChildProcesses.values()]
|
|
993
|
+
.filter((process) => process.ownerThreadId === childThreadId &&
|
|
989
994
|
process.state !== 'result-consumed' &&
|
|
990
|
-
process.state !== 'terminated-for-budget')
|
|
995
|
+
process.state !== 'terminated-for-budget')
|
|
996
|
+
.sort((left, right) => Number(right.state === 'running' || right.state === 'detached-active') -
|
|
997
|
+
Number(left.state === 'running' || left.state === 'detached-active'))
|
|
998
|
+
.slice(0, 64);
|
|
991
999
|
}
|
|
992
1000
|
consumeChildProcessResult(sessionId, childThreadId, processId, actionId) {
|
|
993
1001
|
const owned = this.sessions.get(sessionId);
|
|
@@ -32,7 +32,7 @@ export const gestaltAutopilotWaitLeaseDynamicTool = {
|
|
|
32
32
|
wakeConditions: {
|
|
33
33
|
type: 'array',
|
|
34
34
|
minItems: 1,
|
|
35
|
-
maxItems:
|
|
35
|
+
maxItems: autopilotWaitWakeConditions.length,
|
|
36
36
|
uniqueItems: true,
|
|
37
37
|
items: { type: 'string', enum: autopilotWaitWakeConditions },
|
|
38
38
|
},
|
|
@@ -55,7 +55,7 @@ export function parseAutopilotWaitLease(value) {
|
|
|
55
55
|
return null;
|
|
56
56
|
const wakeConditions = value.wakeConditions;
|
|
57
57
|
if (wakeConditions.length < 1 ||
|
|
58
|
-
wakeConditions.length >
|
|
58
|
+
wakeConditions.length > autopilotWaitWakeConditions.length ||
|
|
59
59
|
new Set(wakeConditions).size !== wakeConditions.length ||
|
|
60
60
|
!wakeConditions.every((condition) => typeof condition === 'string' &&
|
|
61
61
|
autopilotWaitWakeConditions.includes(condition)))
|