gestalt-mobile 0.44.1 → 0.44.3
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 +22 -6
- package/dist/client/assets/index-DEVCzFB9.css +1 -0
- package/dist/client/assets/index-DYZT_mLU.js +108 -0
- package/dist/client/index.html +2 -2
- package/dist/server/server/composition.contracts.js +188 -3
- package/dist/server/server/composition.js +53 -12
- package/dist/server/server/features/agent-activity/registry.js +12 -2
- package/dist/server/server/features/autopilot/application/service.js +184 -61
- package/dist/server/server/features/autopilot/domain/executor-commands.js +28 -0
- package/dist/server/server/features/autopilot/domain/persisted-state-error.js +14 -0
- package/dist/server/server/features/autopilot/domain/plan-fingerprint.js +24 -0
- package/dist/server/server/features/autopilot/domain/supervised-lifecycle.js +33 -7
- package/dist/server/server/features/org-plan-checkpoint/application/validate.js +45 -16
- package/dist/server/server/features/sessions/application/resume-command.js +3 -1
- package/dist/server/server/platform/codex/session-runtime.js +49 -13
- package/dist/server/server/platform/persistence/migrate.js +1 -0
- package/dist/server/server/platform/persistence/sqlite-autopilot-store.js +73 -14
- package/dist/server/server/platform/persistence/sqlite-event-journal.js +16 -0
- package/dist/server/shared/contracts/attention-report.js +12 -0
- package/dist/server/shared/contracts/org-plan-health.js +21 -0
- package/dist/server/shared/contracts/plan-signal.js +2 -1
- package/package.json +1 -1
- package/dist/client/assets/index-6WgZCe9g.js +0 -107
- package/dist/client/assets/index-BKls66uM.css +0 -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-DYZT_mLU.js"></script>
|
|
20
|
+
<link rel="stylesheet" crossorigin href="/assets/index-DEVCzFB9.css">
|
|
21
21
|
</head>
|
|
22
22
|
<body>
|
|
23
23
|
<div id="app"></div>
|
|
@@ -61,7 +61,13 @@ function liveAppServer(handles) {
|
|
|
61
61
|
if (method === 'turn/start')
|
|
62
62
|
return { turn: { id: `turn-${handle.calls.length}` } };
|
|
63
63
|
if (method === 'thread/read')
|
|
64
|
-
return {
|
|
64
|
+
return {
|
|
65
|
+
thread: {
|
|
66
|
+
id: params.threadId,
|
|
67
|
+
status: { type: 'idle' },
|
|
68
|
+
turns: [],
|
|
69
|
+
},
|
|
70
|
+
};
|
|
65
71
|
if (method === 'model/list')
|
|
66
72
|
return { data: [{ id: 'gpt-5.6-terra' }] };
|
|
67
73
|
if (method === 'skills/list')
|
|
@@ -373,6 +379,68 @@ async function createUnauthorizedProductionApp(root, dataDir) {
|
|
|
373
379
|
}
|
|
374
380
|
describe('production composition', () => {
|
|
375
381
|
describeCompositionConcern('autopilot', () => {
|
|
382
|
+
it('health reads match UI authority, reject session selection, and expose recoverable corrupt state', async () => {
|
|
383
|
+
const fixture = await createProductionAutopilotFixture();
|
|
384
|
+
const { app, sessionId, handles, dataDir } = fixture;
|
|
385
|
+
const database = new DatabaseSync(join(dataDir, 'relay.sqlite'));
|
|
386
|
+
try {
|
|
387
|
+
const handle = handles.filter((value) => value.request).at(-1);
|
|
388
|
+
const read = () => handle.request({
|
|
389
|
+
id: 901,
|
|
390
|
+
method: 'item/tool/call',
|
|
391
|
+
params: {
|
|
392
|
+
tool: 'gestalt_org_plan_health',
|
|
393
|
+
arguments: {},
|
|
394
|
+
},
|
|
395
|
+
});
|
|
396
|
+
const before = (await app.inject(`/api/sessions/${sessionId}`)).json();
|
|
397
|
+
const response = await read();
|
|
398
|
+
expect(response.success).toBe(true);
|
|
399
|
+
const health = JSON.parse(response.contentItems[0].text);
|
|
400
|
+
expect(health).toMatchObject({
|
|
401
|
+
state: before.autopilot.state,
|
|
402
|
+
enabled: before.autopilot.enabled,
|
|
403
|
+
});
|
|
404
|
+
expect(health.health).toMatchObject({
|
|
405
|
+
phase: before.autopilot.health.phase,
|
|
406
|
+
healthy: before.autopilot.health.healthy,
|
|
407
|
+
});
|
|
408
|
+
await expect(handle.request({
|
|
409
|
+
id: 902,
|
|
410
|
+
method: 'item/tool/call',
|
|
411
|
+
params: {
|
|
412
|
+
tool: 'gestalt_org_plan_health',
|
|
413
|
+
arguments: { sessionId: 'another' },
|
|
414
|
+
},
|
|
415
|
+
})).rejects.toThrow();
|
|
416
|
+
await app.inject({
|
|
417
|
+
method: 'PUT',
|
|
418
|
+
url: `/api/sessions/${sessionId}/autopilot`,
|
|
419
|
+
payload: { enabled: false },
|
|
420
|
+
});
|
|
421
|
+
database
|
|
422
|
+
.prepare('UPDATE autopilot_sessions SET lifecycle_json = ? WHERE session_id = ?')
|
|
423
|
+
.run('{broken', sessionId);
|
|
424
|
+
expect(JSON.parse((await read()).contentItems[0].text)).toMatchObject({
|
|
425
|
+
health: { phase: 'degraded', degradationReason: 'controllerUnavailable' },
|
|
426
|
+
});
|
|
427
|
+
expect(database.prepare('SELECT * FROM autopilot_state_quarantine').all()).toHaveLength(0);
|
|
428
|
+
const recovered = await app.inject({
|
|
429
|
+
method: 'PUT',
|
|
430
|
+
url: `/api/sessions/${sessionId}/autopilot`,
|
|
431
|
+
payload: { enabled: false },
|
|
432
|
+
});
|
|
433
|
+
expect(recovered.statusCode).toBe(200);
|
|
434
|
+
expect(recovered.json()).toMatchObject({
|
|
435
|
+
autopilot: { enabled: false, health: { phase: 'off' } },
|
|
436
|
+
});
|
|
437
|
+
expect(database.prepare('SELECT * FROM autopilot_state_quarantine').all()).toHaveLength(1);
|
|
438
|
+
}
|
|
439
|
+
finally {
|
|
440
|
+
database.close();
|
|
441
|
+
await app.close();
|
|
442
|
+
}
|
|
443
|
+
});
|
|
376
444
|
it('autopilot production composition keeps disabled sessions free of timers, reads, polls, and leaks', async () => {
|
|
377
445
|
const root = await mkdtemp(join(tmpdir(), 'gestalt-mobile-root-'));
|
|
378
446
|
const dataDir = await mkdtemp(join(tmpdir(), 'gestalt-mobile-state-'));
|
|
@@ -982,6 +1050,61 @@ describe('production composition', () => {
|
|
|
982
1050
|
expect(checkpoint.count).toBe(1);
|
|
983
1051
|
await fixture.app.close();
|
|
984
1052
|
});
|
|
1053
|
+
it('refreshes the published L2 boundary before selecting among multiple DONE children', async () => {
|
|
1054
|
+
const timers = [];
|
|
1055
|
+
const fixture = await createProductionAutopilotFixture({
|
|
1056
|
+
autopilotSchedule: (callback) => {
|
|
1057
|
+
const timer = { callback, cancelled: false };
|
|
1058
|
+
timers.push(timer);
|
|
1059
|
+
return () => {
|
|
1060
|
+
timer.cancelled = true;
|
|
1061
|
+
};
|
|
1062
|
+
},
|
|
1063
|
+
});
|
|
1064
|
+
timers.find((timer) => !timer.cancelled).callback();
|
|
1065
|
+
await vi.waitFor(async () => expect((await fixture.app.inject(`/api/sessions/${fixture.sessionId}`)).json().activeTurnId).toEqual(expect.any(String)));
|
|
1066
|
+
const session = (await fixture.app.inject(`/api/sessions/${fixture.sessionId}`)).json();
|
|
1067
|
+
const handle = fixture.handles.find((candidate) => candidate.requests.some((request) => request.method === 'turn/start'));
|
|
1068
|
+
const planPath = join(fixture.workspacePath, 'autopilot.org');
|
|
1069
|
+
await writeFile(planPath, `${autopilotPlanText('DONE')}
|
|
1070
|
+
** DONE [#A] Newly completed child
|
|
1071
|
+
:PROPERTIES:
|
|
1072
|
+
:ID: second-child
|
|
1073
|
+
:END:
|
|
1074
|
+
- Why :: Verify a resumed plan with earlier completed work.
|
|
1075
|
+
- Change :: Preserve the publication target.
|
|
1076
|
+
- Tests :: Checkpoint immediately after writing the signal.
|
|
1077
|
+
- Done when :: L1.2 is recorded exactly once.
|
|
1078
|
+
`);
|
|
1079
|
+
await writeFile(planStatusFilePath(planStatusDirectoryPath(fixture.workspacePath, fixture.sessionId), planPath), JSON.stringify({
|
|
1080
|
+
schemaVersion: 1,
|
|
1081
|
+
planPath,
|
|
1082
|
+
reason: 'l2:second-child:DONE',
|
|
1083
|
+
updatedAt: new Date().toISOString(),
|
|
1084
|
+
}));
|
|
1085
|
+
// No watcher wait or GET /plan refresh: the checkpoint itself is the barrier.
|
|
1086
|
+
await expect(handle.request({
|
|
1087
|
+
id: 818,
|
|
1088
|
+
method: 'item/tool/call',
|
|
1089
|
+
params: {
|
|
1090
|
+
threadId: session.threadId,
|
|
1091
|
+
turnId: session.activeTurnId,
|
|
1092
|
+
tool: 'gestalt_org_plan_checkpoint',
|
|
1093
|
+
arguments: { kind: 'l2Completed' },
|
|
1094
|
+
},
|
|
1095
|
+
})).resolves.toEqual(toOrgPlanCheckpointToolResponse('recorded'));
|
|
1096
|
+
const db = new DatabaseSync(join(fixture.dataDir, 'relay.sqlite'));
|
|
1097
|
+
const rows = db
|
|
1098
|
+
.prepare("SELECT payload_json FROM session_events WHERE session_id = ? AND type = 'org-plan.step-checkpointed'")
|
|
1099
|
+
.all(fixture.sessionId);
|
|
1100
|
+
expect(rows).toHaveLength(1);
|
|
1101
|
+
expect(JSON.parse(rows[0].payload_json)).toMatchObject({
|
|
1102
|
+
l2Id: 'second-child',
|
|
1103
|
+
position: 'L1.2',
|
|
1104
|
+
});
|
|
1105
|
+
db.close();
|
|
1106
|
+
await fixture.app.close();
|
|
1107
|
+
});
|
|
985
1108
|
it('records and idempotently replays accepted L1 after REVIEWED advances to the next TODO L1', async () => {
|
|
986
1109
|
const timers = [];
|
|
987
1110
|
const fixture = await createProductionAutopilotFixture({
|
|
@@ -1020,6 +1143,13 @@ describe('production composition', () => {
|
|
|
1020
1143
|
const startsBefore = fixture.handles
|
|
1021
1144
|
.flatMap((candidate) => candidate.requests)
|
|
1022
1145
|
.filter((request) => request.method === 'turn/start').length;
|
|
1146
|
+
const unresolvedCall = handle.request({
|
|
1147
|
+
...checkpointCall(815),
|
|
1148
|
+
params: { ...checkpointCall(815).params, arguments: { kind: 'l2Completed' } },
|
|
1149
|
+
});
|
|
1150
|
+
await vi.waitFor(() => expect(handle.pendingResponses.has(815)).toBe(true));
|
|
1151
|
+
handle.responseSettled({ id: 815, outcome: 'resultWritten' });
|
|
1152
|
+
await expect(unresolvedCall).resolves.toEqual(toOrgPlanCheckpointToolResponse('failed', { reasonCode: 'checkpointBoundaryAmbiguous' }));
|
|
1023
1153
|
const first = handle.request(checkpointCall(813));
|
|
1024
1154
|
await vi.waitFor(() => expect(handle.pendingResponses.has(813)).toBe(true));
|
|
1025
1155
|
handle.responseSettled({ id: 813, outcome: 'resultWritten' });
|
|
@@ -2079,6 +2209,59 @@ describe('production composition', () => {
|
|
|
2079
2209
|
});
|
|
2080
2210
|
});
|
|
2081
2211
|
describeCompositionConcern('attention', () => {
|
|
2212
|
+
it('includes the same blocked root turn explanation in attention and session reloads', async () => {
|
|
2213
|
+
const timers = [];
|
|
2214
|
+
const fixture = await createProductionAutopilotFixture({
|
|
2215
|
+
autopilotSchedule: (callback) => {
|
|
2216
|
+
const timer = { callback, cancelled: false };
|
|
2217
|
+
timers.push(timer);
|
|
2218
|
+
return () => {
|
|
2219
|
+
timer.cancelled = true;
|
|
2220
|
+
};
|
|
2221
|
+
},
|
|
2222
|
+
});
|
|
2223
|
+
timers.find((timer) => !timer.cancelled).callback();
|
|
2224
|
+
await vi.waitFor(async () => expect((await fixture.app.inject(`/api/sessions/${fixture.sessionId}`)).json().activeTurnId).toEqual(expect.any(String)));
|
|
2225
|
+
const session = (await fixture.app.inject(`/api/sessions/${fixture.sessionId}`)).json();
|
|
2226
|
+
const handle = fixture.handles.find((candidate) => candidate.requests.some((request) => request.method === 'turn/start'));
|
|
2227
|
+
await expect(handle.request({
|
|
2228
|
+
id: 698,
|
|
2229
|
+
method: 'item/tool/call',
|
|
2230
|
+
params: {
|
|
2231
|
+
threadId: session.threadId,
|
|
2232
|
+
turnId: session.activeTurnId,
|
|
2233
|
+
tool: 'gestalt_org_plan_attention',
|
|
2234
|
+
arguments: { reason: 'hardBlock', resumeCondition: 'externalStateChanged' },
|
|
2235
|
+
},
|
|
2236
|
+
})).resolves.toEqual(toOrgPlanAttentionAcknowledgement());
|
|
2237
|
+
const report = 'The checkpoint cannot identify L1.2. Refresh plan state, then retry.';
|
|
2238
|
+
handle.notify({
|
|
2239
|
+
method: 'item/completed',
|
|
2240
|
+
params: {
|
|
2241
|
+
threadId: session.threadId,
|
|
2242
|
+
turnId: session.activeTurnId,
|
|
2243
|
+
item: { id: 'blocker-final', type: 'agentMessage', phase: 'final_answer', text: report },
|
|
2244
|
+
},
|
|
2245
|
+
});
|
|
2246
|
+
handle.notify({
|
|
2247
|
+
method: 'item/completed',
|
|
2248
|
+
params: {
|
|
2249
|
+
threadId: session.threadId,
|
|
2250
|
+
turnId: 'another-turn',
|
|
2251
|
+
item: {
|
|
2252
|
+
id: 'unrelated-final',
|
|
2253
|
+
type: 'agentMessage',
|
|
2254
|
+
phase: 'final_answer',
|
|
2255
|
+
text: 'Unrelated report',
|
|
2256
|
+
},
|
|
2257
|
+
},
|
|
2258
|
+
});
|
|
2259
|
+
expect((await fixture.app.inject(`/api/sessions/${fixture.sessionId}/attention`)).json()).toMatchObject({ supervisorReport: report });
|
|
2260
|
+
expect((await fixture.app.inject(`/api/sessions/${fixture.sessionId}`)).json().pendingInteractions).toEqual(expect.arrayContaining([
|
|
2261
|
+
expect.objectContaining({ requestId: '698', supervisorReport: report }),
|
|
2262
|
+
]));
|
|
2263
|
+
await fixture.app.close();
|
|
2264
|
+
});
|
|
2082
2265
|
it('bounds a wedged attention acknowledgement writer without losing durable attention', async () => {
|
|
2083
2266
|
const fixture = await createProductionAutopilotFixture({
|
|
2084
2267
|
attentionAcknowledgementDeadlineMs: 100,
|
|
@@ -3823,7 +4006,7 @@ describe('production composition', () => {
|
|
|
3823
4006
|
if (method === 'thread/read') {
|
|
3824
4007
|
if (handle.failReads)
|
|
3825
4008
|
throw new Error('READ_DOWN');
|
|
3826
|
-
return { thread: { turns: [] } };
|
|
4009
|
+
return { thread: { id: 'thread-1', status: { type: 'idle' }, turns: [] } };
|
|
3827
4010
|
}
|
|
3828
4011
|
if (method === 'model/list')
|
|
3829
4012
|
return { data: [{ id: 'gpt-5.6-terra' }] };
|
|
@@ -3902,7 +4085,9 @@ describe('production composition', () => {
|
|
|
3902
4085
|
await Promise.resolve();
|
|
3903
4086
|
}
|
|
3904
4087
|
await vi.waitFor(() => expect(activityDiagnostic).toHaveBeenCalledTimes(1));
|
|
3905
|
-
expect(activityDiagnostic).toHaveBeenCalledWith(sessionId, 'reconcileExhausted'
|
|
4088
|
+
expect(activityDiagnostic).toHaveBeenCalledWith(sessionId, 'reconcileExhausted', {
|
|
4089
|
+
attempt: 4,
|
|
4090
|
+
});
|
|
3906
4091
|
handle.failReads = false;
|
|
3907
4092
|
const initialActivityEvents = activityEvents.filter((message) => message.event.type === 'agent.activity.updated').length;
|
|
3908
4093
|
handle.notify({
|
|
@@ -72,6 +72,7 @@ import { createRelyingPartyConfig } from './config.js';
|
|
|
72
72
|
import { parseOrgPlanAttention, parseOrgPlanAttentionToolResponse, toOrgPlanAttentionAcknowledgement, } from '../shared/contracts/org-plan-attention.js';
|
|
73
73
|
import { autopilotWaitLeaseToolResponse, } from '../shared/contracts/autopilot-wait-lease.js';
|
|
74
74
|
import { agentCapacityRecoveryToolResponse } from '../shared/contracts/agent-capacity-recovery.js';
|
|
75
|
+
import { isOrgPlanHealthCall } from '../shared/contracts/org-plan-health.js';
|
|
75
76
|
import { pwaIconUrl } from './features/pwa/register-routes.js';
|
|
76
77
|
const generatedProtocolVersion = 'codex-cli 0.144.3';
|
|
77
78
|
const checkpointDiagnostic = debuglog('gestalt-mobile:checkpoint');
|
|
@@ -115,7 +116,17 @@ export async function composeRelayApp(options) {
|
|
|
115
116
|
const supervisedPlans = new SupervisedPlanRegistry();
|
|
116
117
|
const planStatusSource = new FilesystemPlanStatusSource(join(dirname(databasePath), 'plans'));
|
|
117
118
|
const planMeasurementHelperPath = options.planMeasurementHelperPath ?? process.env.GESTALT_MOBILE_ORG_PLAN_HELPER;
|
|
118
|
-
const
|
|
119
|
+
const pendingInteractionsWithReports = (sessionId) => interactions.list(sessionId).map((interaction) => ({
|
|
120
|
+
...interaction,
|
|
121
|
+
...(interaction.kind === 'orgPlanAttention' && interaction.turnId && interaction.requestedAt
|
|
122
|
+
? {
|
|
123
|
+
supervisorReport: journal.attentionReport(sessionId, interaction.turnId, interaction.requestedAt),
|
|
124
|
+
}
|
|
125
|
+
: {}),
|
|
126
|
+
}));
|
|
127
|
+
const withPendingInteractions = (session) => session
|
|
128
|
+
? { ...session, pendingInteractions: pendingInteractionsWithReports(session.id) }
|
|
129
|
+
: null;
|
|
119
130
|
const events = new SessionEventBus();
|
|
120
131
|
let notifyAutopilotActivity = () => undefined;
|
|
121
132
|
let publishSessionStatus = () => undefined;
|
|
@@ -159,7 +170,7 @@ export async function composeRelayApp(options) {
|
|
|
159
170
|
}),
|
|
160
171
|
now: () => new Date().toISOString(),
|
|
161
172
|
diagnostic: options.activityDiagnostic ??
|
|
162
|
-
((sessionId, code) => console.warn(`agent activity ${code} session=${sessionId}`)),
|
|
173
|
+
((sessionId, code, detail) => console.warn(`agent activity ${code} session=${sessionId} attempt=${detail?.attempt ?? 0} rpcCode=${detail?.rpcCode ?? 'none'}`)),
|
|
163
174
|
reconcile: async (sessionId) => {
|
|
164
175
|
const session = sessions.find(sessionId);
|
|
165
176
|
if (!session)
|
|
@@ -187,7 +198,7 @@ export async function composeRelayApp(options) {
|
|
|
187
198
|
}
|
|
188
199
|
if (!runtime)
|
|
189
200
|
return false;
|
|
190
|
-
const
|
|
201
|
+
const rootActivity = await runtime.readActivity(session);
|
|
191
202
|
const children = await runtime.listDirectChildren(session);
|
|
192
203
|
const childProcesses = new Map();
|
|
193
204
|
await mapWithConcurrency([...children], 4, async (child) => {
|
|
@@ -203,9 +214,8 @@ export async function composeRelayApp(options) {
|
|
|
203
214
|
activity.observe({
|
|
204
215
|
sessionId,
|
|
205
216
|
occurredAt,
|
|
206
|
-
kind:
|
|
217
|
+
kind: rootActivity.active ? 'turnStarted' : 'turnCompleted',
|
|
207
218
|
...(session.threadId ? { threadId: session.threadId } : {}),
|
|
208
|
-
...(history.activeTurnId ? { turnId: history.activeTurnId } : {}),
|
|
209
219
|
});
|
|
210
220
|
activity.childrenReconciled(sessionId, occurredAt, children.map((child) => ({
|
|
211
221
|
...child,
|
|
@@ -739,7 +749,7 @@ export async function composeRelayApp(options) {
|
|
|
739
749
|
if (session && turnId && session.activeTurnId === turnId) {
|
|
740
750
|
completedSession = RelaySession.rehydrate(session).completeTurn(turnId, occurredAt).snapshot;
|
|
741
751
|
sessions.save(completedSession);
|
|
742
|
-
autopilot.turnCompleted(sessionId);
|
|
752
|
+
autopilot.turnCompleted(sessionId, turnId);
|
|
743
753
|
}
|
|
744
754
|
planMeasurementRefresh?.refreshNow(sessionId);
|
|
745
755
|
}
|
|
@@ -764,17 +774,43 @@ export async function composeRelayApp(options) {
|
|
|
764
774
|
events.publish(journal.append(sessionId, normalized.type, normalized.payload, normalized.occurredAt));
|
|
765
775
|
if (completedSession)
|
|
766
776
|
events.publish(journal.append(sessionId, 'session.updated', completedSession, occurredAt));
|
|
767
|
-
}, (sessionId, request, origin) => {
|
|
777
|
+
}, async (sessionId, request, origin) => {
|
|
768
778
|
let rawInteraction = toPendingInteraction(request);
|
|
779
|
+
const compactCheckpointKind = compactOrgPlanCheckpointKind(request);
|
|
780
|
+
if (compactCheckpointKind || rawInteraction?.kind === 'orgPlanCheckpoint') {
|
|
781
|
+
// A checkpoint is a read barrier, not a race against the debounced watcher.
|
|
782
|
+
const refreshed = await planStatusSource.refresh(sessionId);
|
|
783
|
+
if (refreshed?.kind !== 'updated')
|
|
784
|
+
return (runtime?.resolveServerRequest(sessionId, String(request.id), checkpointFailureResponse('planProjectionUnavailable')) === true);
|
|
785
|
+
}
|
|
769
786
|
const session = withPendingInteractions(sessions.find(sessionId));
|
|
770
787
|
if (!session)
|
|
771
788
|
return false;
|
|
772
|
-
|
|
789
|
+
if (isOrgPlanHealthCall(request)) {
|
|
790
|
+
const snapshot = autopilot.snapshot(sessionId);
|
|
791
|
+
return (runtime?.resolveServerRequest(sessionId, String(request.id), {
|
|
792
|
+
success: true,
|
|
793
|
+
contentItems: [
|
|
794
|
+
{
|
|
795
|
+
type: 'inputText',
|
|
796
|
+
text: JSON.stringify({
|
|
797
|
+
state: snapshot.state,
|
|
798
|
+
enabled: snapshot.enabled,
|
|
799
|
+
health: snapshot.health,
|
|
800
|
+
reason: snapshot.reason,
|
|
801
|
+
}),
|
|
802
|
+
},
|
|
803
|
+
],
|
|
804
|
+
}) === true);
|
|
805
|
+
}
|
|
773
806
|
if (!rawInteraction && compactCheckpointKind) {
|
|
774
807
|
const retained = supervisedPlans.find(sessionId);
|
|
775
808
|
const identity = supervisedPlans.identity(sessionId);
|
|
776
809
|
const checkpoint = retained && identity
|
|
777
|
-
? resolveOrgPlanCheckpointSignal(compactCheckpointKind, retained, identity, supervisedPlans.publicationReason(sessionId)
|
|
810
|
+
? resolveOrgPlanCheckpointSignal(compactCheckpointKind, retained, identity, supervisedPlans.publicationReason(sessionId), autopilotStore
|
|
811
|
+
.find(sessionId)
|
|
812
|
+
?.checkpoints?.completionEpochs?.filter((epoch) => epoch.completed && !epoch.reopened)
|
|
813
|
+
.map((epoch) => epoch.target), autopilotStore.find(sessionId)?.checkpoints?.pendingTarget)
|
|
778
814
|
: null;
|
|
779
815
|
if (checkpoint)
|
|
780
816
|
rawInteraction = {
|
|
@@ -782,6 +818,10 @@ export async function composeRelayApp(options) {
|
|
|
782
818
|
kind: 'orgPlanCheckpoint',
|
|
783
819
|
payload: checkpoint,
|
|
784
820
|
};
|
|
821
|
+
else
|
|
822
|
+
return (runtime?.resolveServerRequest(sessionId, String(request.id), toOrgPlanCheckpointToolResponse('failed', {
|
|
823
|
+
reasonCode: 'checkpointBoundaryAmbiguous',
|
|
824
|
+
})) === true);
|
|
785
825
|
}
|
|
786
826
|
if (!rawInteraction && isAgentCapacityRecoveryCall(request)) {
|
|
787
827
|
const rootOwned = origin.kind === 'root' && origin.physicalTurnId === session.activeTurnId;
|
|
@@ -1446,9 +1486,7 @@ export async function composeRelayApp(options) {
|
|
|
1446
1486
|
exists: (id) => sessions.find(id) !== null,
|
|
1447
1487
|
reader: {
|
|
1448
1488
|
active: (sessionId) => {
|
|
1449
|
-
const interaction =
|
|
1450
|
-
.list(sessionId)
|
|
1451
|
-
.find((item) => item.kind === 'orgPlanAttention');
|
|
1489
|
+
const interaction = pendingInteractionsWithReports(sessionId).find((item) => item.kind === 'orgPlanAttention');
|
|
1452
1490
|
const attention = interaction ? parseOrgPlanAttention(interaction.payload) : null;
|
|
1453
1491
|
return interaction && attention
|
|
1454
1492
|
? {
|
|
@@ -1456,6 +1494,9 @@ export async function composeRelayApp(options) {
|
|
|
1456
1494
|
turnId: interaction.turnId ?? null,
|
|
1457
1495
|
requestedAt: interaction.requestedAt ?? null,
|
|
1458
1496
|
attention,
|
|
1497
|
+
...(interaction.supervisorReport
|
|
1498
|
+
? { supervisorReport: interaction.supervisorReport }
|
|
1499
|
+
: {}),
|
|
1459
1500
|
}
|
|
1460
1501
|
: null;
|
|
1461
1502
|
},
|
|
@@ -167,13 +167,23 @@ export class AgentActivityRegistry {
|
|
|
167
167
|
if (this.#generation.get(sessionId) === generation)
|
|
168
168
|
this.reconciled(sessionId, this.options.now?.() ?? now);
|
|
169
169
|
}
|
|
170
|
-
catch {
|
|
170
|
+
catch (error) {
|
|
171
171
|
if (this.#generation.get(sessionId) !== generation)
|
|
172
172
|
return;
|
|
173
173
|
const delays = this.options.retryDelaysMs ?? [1_000, 5_000, 15_000];
|
|
174
174
|
if (attempt >=
|
|
175
175
|
Math.min(this.options.maxReconcileAttempts ?? delays.length + 1, delays.length + 1)) {
|
|
176
|
-
|
|
176
|
+
const rpcCode = error &&
|
|
177
|
+
typeof error === 'object' &&
|
|
178
|
+
'code' in error &&
|
|
179
|
+
typeof error.code === 'number' &&
|
|
180
|
+
Number.isSafeInteger(error.code)
|
|
181
|
+
? error.code
|
|
182
|
+
: undefined;
|
|
183
|
+
this.options.diagnostic?.(sessionId, 'reconcileExhausted', {
|
|
184
|
+
attempt,
|
|
185
|
+
...(rpcCode !== undefined ? { rpcCode } : {}),
|
|
186
|
+
});
|
|
177
187
|
this.disconnected(sessionId, this.options.now?.() ?? now);
|
|
178
188
|
return;
|
|
179
189
|
}
|