gestalt-mobile 0.61.1 → 0.62.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +52 -5
- package/dist/client/assets/{index-Cp-JfcNd.css → index-CRnoGk06.css} +1 -1
- package/dist/client/assets/{index-DeNYHfGR.js → index-DehRk2EQ.js} +7 -3
- package/dist/client/index.html +2 -2
- package/dist/server/server/composition.contracts.js +106 -1
- package/dist/server/server/composition.js +126 -8
- package/dist/server/server/features/autopilot/application/service.js +7 -6
- package/dist/server/server/features/control-plane-trace/export-trace.js +2 -2
- package/dist/server/server/features/plans/application/parse-supervised-plan.js +5 -0
- package/dist/server/server/features/plans/application/supervised-plan-registry.js +11 -2
- package/dist/server/server/features/sessions/application/provider-recovery.js +109 -0
- package/dist/server/server/features/sessions/model/relay-session.js +17 -2
- package/dist/server/server/features/sessions/start-session/use-case.js +1 -0
- package/dist/server/server/features/skills/list-available/endpoint.js +1 -0
- package/dist/server/server/features/skills/list-profiles/endpoint.js +1 -0
- package/dist/server/server/features/skills/model/skill-profile.js +20 -7
- package/dist/server/server/features/skills/replace-profile/endpoint.js +6 -1
- package/dist/server/server/platform/codex/codex-playwright.js +399 -0
- package/dist/server/server/platform/codex/managed-playwright.js +150 -0
- package/dist/server/server/platform/codex/session-runtime.js +37 -2
- package/dist/server/server/platform/skills/codex-skill-catalog.js +1 -1
- package/dist/server/shared/contracts/managed-playwright.js +34 -0
- package/dist/server/shared/contracts/profile-capabilities.js +13 -0
- package/dist/server/shared/contracts/provider-failure.js +7 -0
- package/package.json +1 -1
package/dist/client/index.html
CHANGED
|
@@ -16,8 +16,8 @@ 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-
|
|
20
|
-
<link rel="stylesheet" crossorigin href="/assets/index-
|
|
19
|
+
<script type="module" crossorigin src="/assets/index-DehRk2EQ.js"></script>
|
|
20
|
+
<link rel="stylesheet" crossorigin href="/assets/index-CRnoGk06.css">
|
|
21
21
|
</head>
|
|
22
22
|
<body>
|
|
23
23
|
<div id="app"></div>
|
|
@@ -1511,6 +1511,111 @@ describe('production composition', () => {
|
|
|
1511
1511
|
expect(JSON.stringify(await app.inject('/api/sessions'))).not.toContain('Inspect the active supervised Org Plan');
|
|
1512
1512
|
await app.close();
|
|
1513
1513
|
});
|
|
1514
|
+
it.each(['autopilot', 'ordinary', 'manual-send', 'stopped'])('production provider recovery uses minimal continuation and respects %s ownership', async (mode) => {
|
|
1515
|
+
const timers = [];
|
|
1516
|
+
const fixture = await createProductionAutopilotFixture({
|
|
1517
|
+
autopilotSchedule: (callback, delay) => {
|
|
1518
|
+
const timer = { callback, delay, cancelled: false };
|
|
1519
|
+
timers.push(timer);
|
|
1520
|
+
return () => {
|
|
1521
|
+
timer.cancelled = true;
|
|
1522
|
+
};
|
|
1523
|
+
},
|
|
1524
|
+
});
|
|
1525
|
+
onTestFinished(() => fixture.app.close());
|
|
1526
|
+
const initial = timers.find((timer) => !timer.cancelled);
|
|
1527
|
+
initial.cancelled = true;
|
|
1528
|
+
initial.callback();
|
|
1529
|
+
const starts = () => fixture.handles
|
|
1530
|
+
.flatMap((handle) => handle.requests)
|
|
1531
|
+
.filter((request) => request.method === 'turn/start');
|
|
1532
|
+
await vi.waitFor(() => expect(starts()).toHaveLength(1));
|
|
1533
|
+
const session = (await fixture.app.inject(`/api/sessions/${fixture.sessionId}`)).json();
|
|
1534
|
+
const handle = fixture.handles.find((candidate) => candidate.calls.includes('turn/start'));
|
|
1535
|
+
if (mode !== 'autopilot')
|
|
1536
|
+
await fixture.app.inject({
|
|
1537
|
+
method: 'PUT',
|
|
1538
|
+
url: `/api/sessions/${fixture.sessionId}/autopilot`,
|
|
1539
|
+
payload: { enabled: false },
|
|
1540
|
+
});
|
|
1541
|
+
handle.notify({
|
|
1542
|
+
method: 'error',
|
|
1543
|
+
params: {
|
|
1544
|
+
threadId: session.threadId,
|
|
1545
|
+
turnId: session.activeTurnId,
|
|
1546
|
+
error: { codexErrorInfo: 'serverOverloaded', message: 'private capacity detail' },
|
|
1547
|
+
willRetry: false,
|
|
1548
|
+
},
|
|
1549
|
+
});
|
|
1550
|
+
handle.notify({
|
|
1551
|
+
method: 'turn/completed',
|
|
1552
|
+
params: {
|
|
1553
|
+
threadId: session.threadId,
|
|
1554
|
+
turn: {
|
|
1555
|
+
id: session.activeTurnId,
|
|
1556
|
+
status: 'failed',
|
|
1557
|
+
},
|
|
1558
|
+
},
|
|
1559
|
+
});
|
|
1560
|
+
const retry = timers.find((timer) => !timer.cancelled && timer.delay === 60_000);
|
|
1561
|
+
expect(retry).toBeDefined();
|
|
1562
|
+
expect(starts()).toHaveLength(1);
|
|
1563
|
+
if (mode === 'manual-send') {
|
|
1564
|
+
expect((await fixture.app.inject({
|
|
1565
|
+
method: 'POST',
|
|
1566
|
+
url: `/api/sessions/${fixture.sessionId}/turns`,
|
|
1567
|
+
payload: { text: 'new instruction' },
|
|
1568
|
+
})).statusCode).toBe(202);
|
|
1569
|
+
retry.callback();
|
|
1570
|
+
expect(starts()).toHaveLength(2);
|
|
1571
|
+
expect(starts().at(-1).params).toMatchObject({
|
|
1572
|
+
input: [{ type: 'text', text: 'new instruction' }],
|
|
1573
|
+
});
|
|
1574
|
+
}
|
|
1575
|
+
else if (mode === 'stopped') {
|
|
1576
|
+
expect((await fixture.app.inject({
|
|
1577
|
+
method: 'POST',
|
|
1578
|
+
url: `/api/sessions/${fixture.sessionId}/stop`,
|
|
1579
|
+
})).statusCode).toBe(202);
|
|
1580
|
+
retry.callback();
|
|
1581
|
+
expect(starts()).toHaveLength(1);
|
|
1582
|
+
}
|
|
1583
|
+
else {
|
|
1584
|
+
vi.useFakeTimers({ toFake: ['Date'] });
|
|
1585
|
+
onTestFinished(() => {
|
|
1586
|
+
vi.useRealTimers();
|
|
1587
|
+
});
|
|
1588
|
+
vi.setSystemTime(Date.now() + 60_000);
|
|
1589
|
+
retry.cancelled = true;
|
|
1590
|
+
retry.callback();
|
|
1591
|
+
if (mode === 'autopilot') {
|
|
1592
|
+
await vi.waitFor(() => expect(timers.some((timer) => !timer.cancelled)).toBe(true));
|
|
1593
|
+
const continuation = timers.find((timer) => !timer.cancelled);
|
|
1594
|
+
vi.setSystemTime(Date.now() + continuation.delay);
|
|
1595
|
+
continuation.cancelled = true;
|
|
1596
|
+
continuation.callback();
|
|
1597
|
+
}
|
|
1598
|
+
await vi.waitFor(async () => {
|
|
1599
|
+
const database = new DatabaseSync(join(fixture.dataDir, 'relay.sqlite'), {
|
|
1600
|
+
readOnly: true,
|
|
1601
|
+
});
|
|
1602
|
+
const rows = database
|
|
1603
|
+
.prepare("SELECT type,payload_json FROM session_events WHERE session_id=? AND type LIKE 'session.provider-retry-%'")
|
|
1604
|
+
.all(fixture.sessionId);
|
|
1605
|
+
database.close();
|
|
1606
|
+
expect(starts(), JSON.stringify(rows)).toHaveLength(2);
|
|
1607
|
+
});
|
|
1608
|
+
expect(starts().at(-1).params).toMatchObject({
|
|
1609
|
+
input: [{ type: 'text', text: 'Continue.' }],
|
|
1610
|
+
});
|
|
1611
|
+
expect((await fixture.app.inject(`/api/sessions/${fixture.sessionId}`)).json().autopilot
|
|
1612
|
+
.enabled).toBe(mode === 'autopilot');
|
|
1613
|
+
const trace = exportControlPlaneTrace(join(fixture.dataDir, 'relay.sqlite'), fixture.sessionId);
|
|
1614
|
+
if (mode === 'ordinary')
|
|
1615
|
+
expect(trace.events.some((event) => event.type === 'session.provider-retry-started')).toBe(true);
|
|
1616
|
+
expect(JSON.stringify(trace)).not.toContain('private capacity detail');
|
|
1617
|
+
}
|
|
1618
|
+
});
|
|
1514
1619
|
it('production correlates overload recovery with a settled root turn and cancels it on Off', async () => {
|
|
1515
1620
|
const timers = [];
|
|
1516
1621
|
const fixture = await createProductionAutopilotFixture({
|
|
@@ -1553,7 +1658,7 @@ describe('production composition', () => {
|
|
|
1553
1658
|
pending: true,
|
|
1554
1659
|
settled: true,
|
|
1555
1660
|
});
|
|
1556
|
-
const retry = timers.find((timer) => timer.delay ===
|
|
1661
|
+
const retry = timers.find((timer) => timer.delay === 60_000 && !timer.cancelled);
|
|
1557
1662
|
expect(retry).toBeDefined();
|
|
1558
1663
|
await fixture.app.inject({
|
|
1559
1664
|
method: 'PUT',
|
|
@@ -32,6 +32,8 @@ import { createRecentThreadLister } from './platform/codex/recent-thread-lister.
|
|
|
32
32
|
import { CodexSessionRuntime } from './platform/codex/session-runtime.js';
|
|
33
33
|
import { normalizeCodexNotification } from './platform/codex/normalizer.js';
|
|
34
34
|
import { decodeCodexFailure } from './platform/codex/codex-failure.js';
|
|
35
|
+
import { providerContinuationPrompt } from '../shared/contracts/provider-failure.js';
|
|
36
|
+
import { SessionProviderRecovery } from './features/sessions/application/provider-recovery.js';
|
|
35
37
|
import { parseMcpStartupStatus } from '../shared/contracts/mcp-startup-failure.js';
|
|
36
38
|
import { KimiSessionRuntime } from './platform/kimi/kimi-session-runtime.js';
|
|
37
39
|
import { KimiWebServerManager } from './platform/kimi/kimi-web-server-manager.js';
|
|
@@ -78,6 +80,9 @@ import { CodexXerj } from './platform/retrieval/codex-xerj.js';
|
|
|
78
80
|
import { CodexSerena } from './platform/codex/codex-serena.js';
|
|
79
81
|
import { ManagedSerena } from './platform/codex/managed-serena.js';
|
|
80
82
|
import { CodexCapabilities } from './platform/codex/codex-capabilities.js';
|
|
83
|
+
import { CodexPlaywright } from './platform/codex/codex-playwright.js';
|
|
84
|
+
import { ManagedPlaywright } from './platform/codex/managed-playwright.js';
|
|
85
|
+
import { isManagedPlaywrightCall } from '../shared/contracts/managed-playwright.js';
|
|
81
86
|
import { compileSkillOverride } from './features/skills/model/skill-profile.js';
|
|
82
87
|
import { SupervisedPlanRegistry } from './features/plans/application/supervised-plan-registry.js';
|
|
83
88
|
import { FilesystemPlanStatusSource } from './platform/plans/filesystem-plan-status-source.js';
|
|
@@ -343,10 +348,12 @@ export async function composeRelayApp(options) {
|
|
|
343
348
|
sessions.find(sessionId)?.activeTurnId ||
|
|
344
349
|
blockingInteractions(sessionId).length)
|
|
345
350
|
throw new Error('AUTOPILOT_START_UNAVAILABLE');
|
|
346
|
-
const continuationPrompt = launchIdentity
|
|
347
|
-
? autopilotExecutorLaunchPrompt(launchIdentity, supervisedPlans.find(sessionId))
|
|
348
|
-
: AUTOPILOT_CONTINUATION_PROMPT;
|
|
349
351
|
const recovery = autopilotStore.find(sessionId);
|
|
352
|
+
const continuationPrompt = recovery?.providerRetry?.resumeRoot
|
|
353
|
+
? providerContinuationPrompt
|
|
354
|
+
: launchIdentity
|
|
355
|
+
? autopilotExecutorLaunchPrompt(launchIdentity, supervisedPlans.find(sessionId))
|
|
356
|
+
: AUTOPILOT_CONTINUATION_PROMPT;
|
|
350
357
|
const executorRecovery = recovery?.supervision?.outcome === 'probeRequired' &&
|
|
351
358
|
recovery.executor?.commands?.some((command) => command.status === 'issued' && !command.processAction);
|
|
352
359
|
const recoveryInstruction = executorRecovery
|
|
@@ -484,6 +491,22 @@ export async function composeRelayApp(options) {
|
|
|
484
491
|
const xerj = new CodexXerj(retrievalCapability);
|
|
485
492
|
const serenaInstallation = new ManagedSerena();
|
|
486
493
|
const capabilities = new CodexCapabilities(xerj, new CodexSerena(serenaInstallation));
|
|
494
|
+
const playwright = new CodexPlaywright(new ManagedPlaywright());
|
|
495
|
+
const playwrightAuthority = (session) => {
|
|
496
|
+
const plan = supervisedPlans.findCurrent(session.id);
|
|
497
|
+
const active = plan?.steps[currentExecutableL1Index(plan)];
|
|
498
|
+
const control = autopilotStore.find(session.id);
|
|
499
|
+
return {
|
|
500
|
+
session,
|
|
501
|
+
planIdentity: supervisedPlans.identity(session.id),
|
|
502
|
+
activePlanId: active?.id ?? null,
|
|
503
|
+
declared: active?.state === 'WIP' && active.managedMcp?.includes('playwright') === true,
|
|
504
|
+
fenced: control?.stopReason === 'manualDisabled' ||
|
|
505
|
+
control?.state === 'safetyPaused' ||
|
|
506
|
+
control?.state === 'attentionRequired' ||
|
|
507
|
+
blockingInteractions(session.id).length > 0,
|
|
508
|
+
};
|
|
509
|
+
};
|
|
487
510
|
const skillCatalog = (provider, profile) => provider === 'kimi'
|
|
488
511
|
? kimiSkillCatalog
|
|
489
512
|
: new CodexSkillCatalog(profile, options.launchAppServer ?? launchCodexAppServer);
|
|
@@ -726,6 +749,49 @@ export async function composeRelayApp(options) {
|
|
|
726
749
|
};
|
|
727
750
|
let closing = false;
|
|
728
751
|
let runtime = null;
|
|
752
|
+
const providerRecovery = new SessionProviderRecovery({
|
|
753
|
+
find: (id) => sessions.find(id),
|
|
754
|
+
authority: (id) => {
|
|
755
|
+
const state = autopilotStore.find(id);
|
|
756
|
+
if (closing ||
|
|
757
|
+
!runtime?.ownsWriter(id) ||
|
|
758
|
+
blockingInteractions(id).length ||
|
|
759
|
+
(state && (state.requestedEnabled || state.state !== 'disabled')))
|
|
760
|
+
return null;
|
|
761
|
+
// Idle observations can advance Autopilot's generation even while Off.
|
|
762
|
+
// An explicit toggle/send clears this failure identity instead.
|
|
763
|
+
return state?.providerFailureTurnId ?? 'no-failure';
|
|
764
|
+
},
|
|
765
|
+
reconcile: async (id) => {
|
|
766
|
+
await activity.refresh(id);
|
|
767
|
+
const snapshot = activity.snapshot(id, new Date().toISOString());
|
|
768
|
+
return (snapshot.confidence === 'fresh' &&
|
|
769
|
+
snapshot.root.state === 'idle' &&
|
|
770
|
+
snapshot.subagents.every((agent) => agent.state === 'idle' &&
|
|
771
|
+
!agent.ownedProcesses?.some((process) => ['running', 'detached-active'].includes(process.state))));
|
|
772
|
+
},
|
|
773
|
+
schedule: options.autopilotSchedule ??
|
|
774
|
+
((callback, delay) => {
|
|
775
|
+
const timer = setTimeout(callback, delay);
|
|
776
|
+
return () => clearTimeout(timer);
|
|
777
|
+
}),
|
|
778
|
+
start: async (session, current) => {
|
|
779
|
+
if (!runtime || !current())
|
|
780
|
+
throw new Error('PROVIDER_RETRY_CANCELLED');
|
|
781
|
+
const started = await runtime.startTurn(session, providerContinuationPrompt, `provider-retry-${randomUUID()}`, new Date().toISOString(), current);
|
|
782
|
+
saveSession(started);
|
|
783
|
+
activity.observe({
|
|
784
|
+
sessionId: started.id,
|
|
785
|
+
occurredAt: started.updatedAt,
|
|
786
|
+
kind: 'turnStarted',
|
|
787
|
+
threadId: started.threadId,
|
|
788
|
+
turnId: started.activeTurnId,
|
|
789
|
+
});
|
|
790
|
+
},
|
|
791
|
+
publish: (id, type, payload) => {
|
|
792
|
+
events.publish(journal.append(id, type, payload, new Date().toISOString()));
|
|
793
|
+
},
|
|
794
|
+
});
|
|
729
795
|
let kimiRuntime = null;
|
|
730
796
|
const executorPolicyContext = (sessionId) => {
|
|
731
797
|
const session = sessions.find(sessionId);
|
|
@@ -873,14 +939,25 @@ export async function composeRelayApp(options) {
|
|
|
873
939
|
const normalized = normalizeCodexNotification(sessionId, 0, occurredAt, notification, currentSession?.workspacePath, currentSession?.activeTurnId, resolvedOrigin);
|
|
874
940
|
// Pause before activity/completion can schedule another automatic turn.
|
|
875
941
|
// Unknown threads must not stop an unrelated session on the shared server.
|
|
876
|
-
|
|
942
|
+
// Codex may emit the terminal error separately and omit it from the
|
|
943
|
+
// completion. Carry forward only evidence for this exact active root.
|
|
944
|
+
const settledFailure = resolvedOrigin.kind === 'root' &&
|
|
945
|
+
completionTurnId === currentSession?.activeTurnId &&
|
|
946
|
+
notification.params?.turn?.status ===
|
|
947
|
+
'failed'
|
|
948
|
+
? autopilotStore.find(sessionId)
|
|
949
|
+
: null;
|
|
950
|
+
const providerFailure = decodeCodexFailure(notification) ??
|
|
951
|
+
(settledFailure?.providerFailureTurnId === completionTurnId
|
|
952
|
+
? settledFailure?.providerFailure
|
|
953
|
+
: undefined);
|
|
877
954
|
if (resolvedOrigin.kind !== 'unknown' && providerFailure)
|
|
878
955
|
autopilot.providerFailed(sessionId, providerFailure, {
|
|
879
956
|
actor: resolvedOrigin.kind === 'root' ? 'root' : 'child',
|
|
880
957
|
turnId: completionTurnId ??
|
|
881
958
|
(typeof notification.params?.turnId === 'string'
|
|
882
959
|
? notification.params.turnId
|
|
883
|
-
:
|
|
960
|
+
: resolvedOrigin.physicalTurnId),
|
|
884
961
|
settled: notification.method === 'turn/completed',
|
|
885
962
|
});
|
|
886
963
|
const rootCommandId = resolvedOrigin.kind === 'root' ? completedCommandId(notification) : null;
|
|
@@ -920,8 +997,13 @@ export async function composeRelayApp(options) {
|
|
|
920
997
|
// these facts project the idle root; its first evaluation can therefore
|
|
921
998
|
// still see the pre-completion activity snapshot. This second evaluation
|
|
922
999
|
// is idempotently fenced by the durable control row.
|
|
923
|
-
if (completedSession)
|
|
1000
|
+
if (completedSession) {
|
|
1001
|
+
if (providerFailure && completionTurnId)
|
|
1002
|
+
providerRecovery.failed(completedSession, completionTurnId, providerFailure);
|
|
1003
|
+
else
|
|
1004
|
+
providerRecovery.cancel(sessionId);
|
|
924
1005
|
autopilot.evaluate(sessionId);
|
|
1006
|
+
}
|
|
925
1007
|
// Lifecycle notifications are fast transition evidence, while
|
|
926
1008
|
// thread/list is the bounded topology authority. Reconcile after the
|
|
927
1009
|
// mutation so canonical identity and every retained child reach both
|
|
@@ -948,6 +1030,15 @@ export async function composeRelayApp(options) {
|
|
|
948
1030
|
const session = withPendingInteractions(sessions.find(sessionId));
|
|
949
1031
|
if (!session)
|
|
950
1032
|
return false;
|
|
1033
|
+
if (isManagedPlaywrightCall(request)) {
|
|
1034
|
+
const result = await playwright.control(playwrightAuthority(session), request.params.arguments, origin.kind === 'root' &&
|
|
1035
|
+
origin.physicalThreadId === session.threadId &&
|
|
1036
|
+
origin.physicalTurnId === session.activeTurnId);
|
|
1037
|
+
return (runtime?.resolveServerRequest(sessionId, String(request.id), {
|
|
1038
|
+
success: true,
|
|
1039
|
+
contentItems: [{ type: 'inputText', text: JSON.stringify(result) }],
|
|
1040
|
+
}) === true);
|
|
1041
|
+
}
|
|
951
1042
|
const toolCall = request.params;
|
|
952
1043
|
if (request.method === 'item/tool/call' &&
|
|
953
1044
|
toolCall?.tool === gestaltTestRunnerDynamicTool.name) {
|
|
@@ -1240,7 +1331,7 @@ export async function composeRelayApp(options) {
|
|
|
1240
1331
|
explicit: session.effectiveSkillSelection?.skills ?? options.explicitSkillProfile?.skills,
|
|
1241
1332
|
project: project?.skills,
|
|
1242
1333
|
});
|
|
1243
|
-
|
|
1334
|
+
const state = await capabilities.prepare({
|
|
1244
1335
|
cwd: session.workspacePath,
|
|
1245
1336
|
approvalPolicy: session.executionPolicy?.approvalPolicy ?? 'on-request',
|
|
1246
1337
|
rpc,
|
|
@@ -1250,8 +1341,25 @@ export async function composeRelayApp(options) {
|
|
|
1250
1341
|
skillsConfig: selected.skillsConfig,
|
|
1251
1342
|
start: true,
|
|
1252
1343
|
});
|
|
1344
|
+
return playwright.prepare(state, playwrightAuthority(session), {
|
|
1345
|
+
rpc,
|
|
1346
|
+
skills: catalog.skills,
|
|
1347
|
+
deadline: Date.now() + 5_000,
|
|
1348
|
+
current: () => playwrightAuthority(sessions.find(session.id) ?? session),
|
|
1349
|
+
});
|
|
1350
|
+
},
|
|
1351
|
+
verify: async (rpc, threadId, state) => {
|
|
1352
|
+
const base = playwright.base(state);
|
|
1353
|
+
const [retrievalReady, browserReady] = await Promise.all([
|
|
1354
|
+
capabilities.verify(rpc, threadId, base),
|
|
1355
|
+
playwright.verify(rpc, threadId, state),
|
|
1356
|
+
]);
|
|
1357
|
+
return retrievalReady && browserReady;
|
|
1253
1358
|
},
|
|
1254
|
-
|
|
1359
|
+
needsResume: (session) => playwright.needsResume(playwrightAuthority(session)),
|
|
1360
|
+
release: (sessionId) => playwright.release(sessionId),
|
|
1361
|
+
observe: (sessionId, notification) => playwright.observe(sessionId, notification),
|
|
1362
|
+
bound: (state, threadId) => playwright.bound(state, threadId),
|
|
1255
1363
|
}, async (sessionId, threadId) => {
|
|
1256
1364
|
requireOrgExecutionAdmission(sessionId);
|
|
1257
1365
|
const plan = supervisedPlans.find(sessionId);
|
|
@@ -1465,6 +1573,7 @@ export async function composeRelayApp(options) {
|
|
|
1465
1573
|
// An exited child has released our writer. Do not repeatedly resume a
|
|
1466
1574
|
// durable thread: another Codex client may acquire it between callbacks.
|
|
1467
1575
|
recoverExitedSession = (sessionId) => {
|
|
1576
|
+
providerRecovery.cancel(sessionId);
|
|
1468
1577
|
supervisor.cancel(sessionId);
|
|
1469
1578
|
const session = sessions.find(sessionId);
|
|
1470
1579
|
if (session) {
|
|
@@ -1696,6 +1805,7 @@ export async function composeRelayApp(options) {
|
|
|
1696
1805
|
: undefined,
|
|
1697
1806
|
startTurn: runtime || kimiRuntime
|
|
1698
1807
|
? async (session, text, clientUserMessageId) => {
|
|
1808
|
+
providerRecovery.cancel(session.id);
|
|
1699
1809
|
autopilot.manualSend(session.id);
|
|
1700
1810
|
const owner = ownerRuntime(session);
|
|
1701
1811
|
if (!owner)
|
|
@@ -1714,6 +1824,7 @@ export async function composeRelayApp(options) {
|
|
|
1714
1824
|
: undefined,
|
|
1715
1825
|
releaseWriter: runtime || kimiRuntime
|
|
1716
1826
|
? (id) => {
|
|
1827
|
+
providerRecovery.cancel(id);
|
|
1717
1828
|
dismissPendingInteractions(id, new Date().toISOString());
|
|
1718
1829
|
const session = sessions.find(id);
|
|
1719
1830
|
const owner = session ? ownerRuntime(session) : null;
|
|
@@ -1751,12 +1862,14 @@ export async function composeRelayApp(options) {
|
|
|
1751
1862
|
activityHistory: (sessionId, throughSequence) => journal.activityHistory(sessionId, throughSequence),
|
|
1752
1863
|
interruptTurn: runtime || kimiRuntime
|
|
1753
1864
|
? (session, turnId) => {
|
|
1865
|
+
providerRecovery.cancel(session.id);
|
|
1754
1866
|
const owner = ownerRuntime(session);
|
|
1755
1867
|
return owner ? owner.interruptTurn(session, turnId) : Promise.resolve();
|
|
1756
1868
|
}
|
|
1757
1869
|
: undefined,
|
|
1758
1870
|
queueTurnInput: runtime || kimiRuntime
|
|
1759
1871
|
? (session, turnId, text, clientUserMessageId) => {
|
|
1872
|
+
providerRecovery.cancel(session.id);
|
|
1760
1873
|
autopilot.manualSend(session.id);
|
|
1761
1874
|
const owner = ownerRuntime(session);
|
|
1762
1875
|
if (!owner)
|
|
@@ -1804,10 +1917,12 @@ export async function composeRelayApp(options) {
|
|
|
1804
1917
|
})
|
|
1805
1918
|
: undefined,
|
|
1806
1919
|
release: (session) => {
|
|
1920
|
+
providerRecovery.cancel(session.id);
|
|
1807
1921
|
autopilot.cancel(session.id, 'sessionEnded');
|
|
1808
1922
|
return RelaySession.rehydrate(session).release(new Date().toISOString()).snapshot;
|
|
1809
1923
|
},
|
|
1810
1924
|
remove: (id) => {
|
|
1925
|
+
providerRecovery.cancel(id);
|
|
1811
1926
|
autopilot.cancel(id, 'sessionEnded');
|
|
1812
1927
|
activity.dispose(id);
|
|
1813
1928
|
sessions.remove(id);
|
|
@@ -1815,6 +1930,7 @@ export async function composeRelayApp(options) {
|
|
|
1815
1930
|
idempotency,
|
|
1816
1931
|
close: runtime || kimiRuntime
|
|
1817
1932
|
? async (id) => {
|
|
1933
|
+
providerRecovery.cancel(id);
|
|
1818
1934
|
autopilot.cancel(id, 'sessionEnded');
|
|
1819
1935
|
await hostTests?.cancelSession(id);
|
|
1820
1936
|
planMeasurementRefresh?.stop(id);
|
|
@@ -1827,6 +1943,7 @@ export async function composeRelayApp(options) {
|
|
|
1827
1943
|
: undefined,
|
|
1828
1944
|
replyInteraction: runtime || kimiRuntime
|
|
1829
1945
|
? async (sessionId, requestId, value) => {
|
|
1946
|
+
providerRecovery.cancel(sessionId);
|
|
1830
1947
|
const session = sessions.find(sessionId);
|
|
1831
1948
|
const owner = session ? ownerRuntime(session) : null;
|
|
1832
1949
|
if (await owner?.resolveServerRequest(sessionId, requestId, value))
|
|
@@ -2199,6 +2316,7 @@ export async function composeRelayApp(options) {
|
|
|
2199
2316
|
});
|
|
2200
2317
|
app.addHook('onClose', async () => {
|
|
2201
2318
|
closing = true;
|
|
2319
|
+
providerRecovery.dispose();
|
|
2202
2320
|
await hostTests?.close();
|
|
2203
2321
|
await xerjIndexer.close();
|
|
2204
2322
|
for (const [sessionId, timer] of capacityRecoveryTimers) {
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import { parseOrgPlanAgentIdentity } from '../../../../shared/org-plan-position.js';
|
|
7
7
|
import { assessModelPolicyAdmission } from '../../plans/domain/model-policy-admission.js';
|
|
8
|
+
import { isTransientProviderFailure, providerRetryDelayMs, providerRetryLimit, } from '../../../../shared/contracts/provider-failure.js';
|
|
8
9
|
import { requirePlanFingerprint } from '../domain/plan-fingerprint.js';
|
|
9
10
|
import { AutopilotStateError } from '../domain/persisted-state-error.js';
|
|
10
11
|
import { canTransitionExecutorCommand, retainExecutorCommands, } from '../domain/executor-commands.js';
|
|
@@ -912,7 +913,7 @@ export class AutopilotCoordinator {
|
|
|
912
913
|
if (retry &&
|
|
913
914
|
!retry.pending &&
|
|
914
915
|
retry.turnId === origin?.turnId &&
|
|
915
|
-
failure
|
|
916
|
+
isTransientProviderFailure(failure))
|
|
916
917
|
return false;
|
|
917
918
|
if (retry && retry.turnId === origin?.turnId && state.providerFailure?.code === failure.code) {
|
|
918
919
|
if (origin?.settled && !retry.settled)
|
|
@@ -928,11 +929,11 @@ export class AutopilotCoordinator {
|
|
|
928
929
|
const enabled = state.requestedEnabled || Boolean(retry?.pending);
|
|
929
930
|
const attempt = (retry?.attempt ?? 0) + 1;
|
|
930
931
|
const recoverable = enabled &&
|
|
931
|
-
failure
|
|
932
|
+
isTransientProviderFailure(failure) &&
|
|
932
933
|
origin?.actor === 'root' &&
|
|
933
934
|
Boolean(origin.turnId) &&
|
|
934
935
|
origin.turnId === this.deps.session(sessionId)?.activeTurnId &&
|
|
935
|
-
attempt <=
|
|
936
|
+
attempt <= providerRetryLimit;
|
|
936
937
|
const event = {
|
|
937
938
|
sessionId,
|
|
938
939
|
type: 'autopilot.provider-failed',
|
|
@@ -963,7 +964,7 @@ export class AutopilotCoordinator {
|
|
|
963
964
|
requestedEnabled: false,
|
|
964
965
|
generation: state.generation + 1,
|
|
965
966
|
nextEvaluationAt: recoverable
|
|
966
|
-
? new Date(Date.parse(now) +
|
|
967
|
+
? new Date(Date.parse(now) + providerRetryDelayMs).toISOString()
|
|
967
968
|
: null,
|
|
968
969
|
...(cancelled ? { lastControlId: null } : {}),
|
|
969
970
|
stopReason: failure.code === 'usageLimitExceeded' ? 'usageLimitExceeded' : 'providerError',
|
|
@@ -973,7 +974,7 @@ export class AutopilotCoordinator {
|
|
|
973
974
|
? {
|
|
974
975
|
turnId: origin.turnId,
|
|
975
976
|
attempt,
|
|
976
|
-
notBefore: new Date(Date.parse(now) +
|
|
977
|
+
notBefore: new Date(Date.parse(now) + providerRetryDelayMs).toISOString(),
|
|
977
978
|
settled: origin.settled,
|
|
978
979
|
pending: true,
|
|
979
980
|
resumeRoot: false,
|
|
@@ -989,7 +990,7 @@ export class AutopilotCoordinator {
|
|
|
989
990
|
this.providerTimers.set(sessionId, this.deps.schedule(() => {
|
|
990
991
|
this.providerTimers.delete(sessionId);
|
|
991
992
|
this.enqueue(sessionId, () => this.retryProvider(sessionId, next.generation));
|
|
992
|
-
},
|
|
993
|
+
}, providerRetryDelayMs));
|
|
993
994
|
return true;
|
|
994
995
|
}
|
|
995
996
|
async retryProvider(sessionId, generation) {
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
import { readTransportDiagnostics } from '../../platform/persistence/sqlite-transport-diagnostics.js';
|
|
7
7
|
import { DatabaseSync } from 'node:sqlite';
|
|
8
8
|
import { parseMcpStartupStatus } from '../../../shared/contracts/mcp-startup-failure.js';
|
|
9
|
-
const relevant = /^(?:org-plan\.|autopilot\.|agent\.activity\.|session\.status\.)/;
|
|
9
|
+
const relevant = /^(?:org-plan\.|autopilot\.|agent\.activity\.|session\.status\.|session\.provider-retry-)/;
|
|
10
10
|
const statusTypes = ['autopilot.updated', 'agent.activity.updated', 'session.status.updated'];
|
|
11
11
|
// Export structural telemetry only. Event types alone do not imply payload safety.
|
|
12
12
|
const diagnosticFields = new Set([
|
|
@@ -133,7 +133,7 @@ export function exportControlPlaneTrace(databasePath, sessionId, generatedAt = n
|
|
|
133
133
|
// journal. Keep a recent status tail and disclose every omitted row.
|
|
134
134
|
const statusEventLimit = 100;
|
|
135
135
|
const transitionEventLimit = 4900;
|
|
136
|
-
const relevantWhere = "(type LIKE 'org-plan.%' OR type LIKE 'autopilot.%' OR type LIKE 'agent.activity.%' OR type LIKE 'session.status.%')";
|
|
136
|
+
const relevantWhere = "(type LIKE 'org-plan.%' OR type LIKE 'autopilot.%' OR type LIKE 'agent.activity.%' OR type LIKE 'session.status.%' OR type LIKE 'session.provider-retry-%')";
|
|
137
137
|
const statusWhere = `type IN (${statusTypes.map(() => '?').join(',')})`;
|
|
138
138
|
const counts = database
|
|
139
139
|
.prepare(`SELECT SUM(CASE WHEN ${statusWhere} THEN 1 ELSE 0 END) AS statuses, COUNT(*) AS total FROM session_events WHERE session_id = ? AND ${relevantWhere}`)
|
|
@@ -191,6 +191,9 @@ function makeStep(heading) {
|
|
|
191
191
|
const measurement = measurementFor(heading);
|
|
192
192
|
if (!description || measurement === null)
|
|
193
193
|
return null;
|
|
194
|
+
const managed = heading.descriptions.get('Managed MCP');
|
|
195
|
+
if (managed !== undefined && (heading.level !== 1 || managed !== 'playwright'))
|
|
196
|
+
return null;
|
|
194
197
|
if (heading.level === 1) {
|
|
195
198
|
const reviewStatus = heading.properties.get('REVIEW_STATUS');
|
|
196
199
|
const skills = heading.properties.get('SKILLS');
|
|
@@ -204,6 +207,7 @@ function makeStep(heading) {
|
|
|
204
207
|
priority: heading.priority,
|
|
205
208
|
reviewStatus: reviewStatus,
|
|
206
209
|
skills: skills.split(/\s+/).filter(Boolean),
|
|
210
|
+
...(managed === 'playwright' ? { managedMcp: ['playwright'] } : {}),
|
|
207
211
|
description,
|
|
208
212
|
...(measurement ? { measurement } : {}),
|
|
209
213
|
children: [],
|
|
@@ -399,6 +403,7 @@ function freezePlan(plan) {
|
|
|
399
403
|
const freezeStep = (step) => Object.freeze({
|
|
400
404
|
...step,
|
|
401
405
|
...(step.skills ? { skills: Object.freeze([...step.skills]) } : {}),
|
|
406
|
+
...(step.managedMcp ? { managedMcp: Object.freeze(['playwright']) } : {}),
|
|
402
407
|
description: Object.freeze({ ...step.description }),
|
|
403
408
|
children: Object.freeze(step.children.map(freezeStep)),
|
|
404
409
|
});
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
/** Retains at most one validated plan projection for each relay session. */
|
|
7
7
|
export class SupervisedPlanRegistry {
|
|
8
8
|
policyUnavailable = new Set();
|
|
9
|
+
currentUnavailable = new Set();
|
|
9
10
|
plans = new Map();
|
|
10
11
|
accept(sessionId, update) {
|
|
11
12
|
if (update.kind === 'updated') {
|
|
@@ -15,9 +16,12 @@ export class SupervisedPlanRegistry {
|
|
|
15
16
|
publicationReason: update.reason,
|
|
16
17
|
});
|
|
17
18
|
this.policyUnavailable.delete(sessionId);
|
|
19
|
+
this.currentUnavailable.delete(sessionId);
|
|
18
20
|
}
|
|
19
|
-
else
|
|
20
|
-
this.
|
|
21
|
+
else {
|
|
22
|
+
this.currentUnavailable.add(sessionId);
|
|
23
|
+
if (update.modelPolicyRequired || this.find(sessionId)?.modelPolicyVersion === 1)
|
|
24
|
+
this.policyUnavailable.add(sessionId);
|
|
21
25
|
}
|
|
22
26
|
}
|
|
23
27
|
/** An invalid mandatory publication cannot silently reuse a legacy execution policy. */
|
|
@@ -31,6 +35,10 @@ export class SupervisedPlanRegistry {
|
|
|
31
35
|
find(sessionId) {
|
|
32
36
|
return this.plans.get(sessionId)?.plan ?? null;
|
|
33
37
|
}
|
|
38
|
+
/** Retained display state cannot authorize a capability after an invalid publication. */
|
|
39
|
+
findCurrent(sessionId) {
|
|
40
|
+
return this.currentUnavailable.has(sessionId) ? null : this.find(sessionId);
|
|
41
|
+
}
|
|
34
42
|
identity(sessionId) {
|
|
35
43
|
return this.plans.get(sessionId)?.identity ?? null;
|
|
36
44
|
}
|
|
@@ -40,5 +48,6 @@ export class SupervisedPlanRegistry {
|
|
|
40
48
|
clear(sessionId) {
|
|
41
49
|
this.plans.delete(sessionId);
|
|
42
50
|
this.policyUnavailable.delete(sessionId);
|
|
51
|
+
this.currentUnavailable.delete(sessionId);
|
|
43
52
|
}
|
|
44
53
|
}
|
|
@@ -0,0 +1,109 @@
|
|
|
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 { isTransientProviderFailure, providerRetryDelayMs, providerRetryLimit, } from '../../../../shared/contracts/provider-failure.js';
|
|
7
|
+
/** Live task recovery never enables Autopilot or recreates work after relay shutdown. */
|
|
8
|
+
export class SessionProviderRecovery {
|
|
9
|
+
deps;
|
|
10
|
+
episodes = new Map();
|
|
11
|
+
constructor(deps) {
|
|
12
|
+
this.deps = deps;
|
|
13
|
+
}
|
|
14
|
+
failed(session, turnId, failure) {
|
|
15
|
+
if (!isTransientProviderFailure(failure)) {
|
|
16
|
+
this.cancel(session.id);
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
const authority = this.deps.authority(session.id);
|
|
20
|
+
if (!session.threadId ||
|
|
21
|
+
session.state !== 'ready' ||
|
|
22
|
+
session.desiredState !== 'active' ||
|
|
23
|
+
session.activeTurnId ||
|
|
24
|
+
authority === null)
|
|
25
|
+
return;
|
|
26
|
+
const previous = this.episodes.get(session.id);
|
|
27
|
+
if (previous?.turnId === turnId)
|
|
28
|
+
return;
|
|
29
|
+
const attempt = (previous?.attempt ?? 0) + 1;
|
|
30
|
+
previous?.cancel();
|
|
31
|
+
if (attempt > providerRetryLimit) {
|
|
32
|
+
if (previous)
|
|
33
|
+
previous.turnId = turnId;
|
|
34
|
+
this.deps.publish(session.id, 'session.provider-retry-exhausted', {
|
|
35
|
+
turnId,
|
|
36
|
+
retryAttempt: providerRetryLimit,
|
|
37
|
+
});
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
const episode = {
|
|
41
|
+
threadId: session.threadId,
|
|
42
|
+
turnId,
|
|
43
|
+
updatedAt: session.updatedAt,
|
|
44
|
+
attempt,
|
|
45
|
+
authority,
|
|
46
|
+
pending: true,
|
|
47
|
+
cancel: () => { },
|
|
48
|
+
};
|
|
49
|
+
this.episodes.set(session.id, episode);
|
|
50
|
+
episode.cancel = this.deps.schedule(() => {
|
|
51
|
+
void this.retry(session.id, episode);
|
|
52
|
+
}, providerRetryDelayMs);
|
|
53
|
+
this.deps.publish(session.id, 'session.provider-retry-scheduled', {
|
|
54
|
+
turnId,
|
|
55
|
+
retryAttempt: attempt,
|
|
56
|
+
providerFailure: failure,
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
/** Manual sends, interruptions, successful turns and lifecycle changes end an episode. */
|
|
60
|
+
cancel(id) {
|
|
61
|
+
this.episodes.get(id)?.cancel();
|
|
62
|
+
this.episodes.delete(id);
|
|
63
|
+
}
|
|
64
|
+
dispose() {
|
|
65
|
+
for (const id of this.episodes.keys())
|
|
66
|
+
this.cancel(id);
|
|
67
|
+
}
|
|
68
|
+
current(id, episode) {
|
|
69
|
+
const session = this.deps.find(id);
|
|
70
|
+
return Boolean(this.episodes.get(id) === episode &&
|
|
71
|
+
session?.threadId === episode.threadId &&
|
|
72
|
+
session.updatedAt === episode.updatedAt &&
|
|
73
|
+
session.state === 'ready' &&
|
|
74
|
+
session.desiredState === 'active' &&
|
|
75
|
+
!session.activeTurnId &&
|
|
76
|
+
this.deps.authority(id) === episode.authority);
|
|
77
|
+
}
|
|
78
|
+
async retry(id, episode) {
|
|
79
|
+
if (this.episodes.get(id) !== episode || !episode.pending)
|
|
80
|
+
return;
|
|
81
|
+
episode.pending = false; // Duplicate timer delivery cannot dispatch a second start.
|
|
82
|
+
let started = false;
|
|
83
|
+
let reason = 'sessionChanged';
|
|
84
|
+
try {
|
|
85
|
+
if (this.current(id, episode)) {
|
|
86
|
+
reason = 'activityNotIdle';
|
|
87
|
+
if (await this.deps.reconcile(id)) {
|
|
88
|
+
reason = 'sessionChanged';
|
|
89
|
+
if (this.current(id, episode)) {
|
|
90
|
+
reason = 'startUnconfirmed';
|
|
91
|
+
await this.deps.start(this.deps.find(id), () => this.current(id, episode));
|
|
92
|
+
started = true;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
catch {
|
|
98
|
+
// An unconfirmed start is never replayed. A new terminal provider event
|
|
99
|
+
// may request the next bounded attempt; transport prose is not persisted.
|
|
100
|
+
}
|
|
101
|
+
if (this.episodes.get(id) !== episode)
|
|
102
|
+
return;
|
|
103
|
+
this.deps.publish(id, started ? 'session.provider-retry-started' : 'session.provider-retry-abandoned', {
|
|
104
|
+
turnId: episode.turnId,
|
|
105
|
+
retryAttempt: episode.attempt,
|
|
106
|
+
...(started ? {} : { reason }),
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
}
|