gestalt-mobile 0.44.2 → 0.44.4
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/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 +219 -2
- package/dist/server/server/composition.js +23 -6
- package/dist/server/server/features/autopilot/application/policy.js +9 -3
- package/dist/server/server/features/sessions/application/resume-command.js +3 -1
- package/dist/server/server/platform/codex/session-runtime.js +29 -7
- 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/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>
|
|
@@ -1050,6 +1050,61 @@ describe('production composition', () => {
|
|
|
1050
1050
|
expect(checkpoint.count).toBe(1);
|
|
1051
1051
|
await fixture.app.close();
|
|
1052
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
|
+
});
|
|
1053
1108
|
it('records and idempotently replays accepted L1 after REVIEWED advances to the next TODO L1', async () => {
|
|
1054
1109
|
const timers = [];
|
|
1055
1110
|
const fixture = await createProductionAutopilotFixture({
|
|
@@ -2049,6 +2104,84 @@ describe('production composition', () => {
|
|
|
2049
2104
|
.filter((call) => call === 'turn/start')).toHaveLength(1));
|
|
2050
2105
|
await fixture.app.close();
|
|
2051
2106
|
});
|
|
2107
|
+
it('continues the same unloaded executor once after authoritative roster recovery', async () => {
|
|
2108
|
+
const handles = [];
|
|
2109
|
+
const launch = liveAppServer(handles);
|
|
2110
|
+
let unavailable = true;
|
|
2111
|
+
const timers = [];
|
|
2112
|
+
const fixture = await createProductionAutopilotFixture({
|
|
2113
|
+
activitySchedule: () => () => { },
|
|
2114
|
+
autopilotSchedule: (callback) => {
|
|
2115
|
+
const timer = { callback, cancelled: false, fired: false };
|
|
2116
|
+
timers.push(timer);
|
|
2117
|
+
return () => {
|
|
2118
|
+
timer.cancelled = true;
|
|
2119
|
+
};
|
|
2120
|
+
},
|
|
2121
|
+
launchAppServer: () => {
|
|
2122
|
+
const server = launch();
|
|
2123
|
+
handles.at(-1).respond = (method) => {
|
|
2124
|
+
if (method === 'thread/list' && unavailable)
|
|
2125
|
+
throw new Error('RPC_DOWN');
|
|
2126
|
+
if (method === 'thread/list')
|
|
2127
|
+
return {
|
|
2128
|
+
data: [
|
|
2129
|
+
{
|
|
2130
|
+
id: 'preserved-executor',
|
|
2131
|
+
status: { type: 'notLoaded' },
|
|
2132
|
+
source: { subAgent: { thread_spawn: { agent_path: '/root/l1' } } },
|
|
2133
|
+
},
|
|
2134
|
+
],
|
|
2135
|
+
};
|
|
2136
|
+
if (method === 'thread/backgroundTerminals/list')
|
|
2137
|
+
throw new CodexJsonRpcError(-32600, 'thread not found: preserved-executor');
|
|
2138
|
+
return undefined;
|
|
2139
|
+
};
|
|
2140
|
+
return server;
|
|
2141
|
+
},
|
|
2142
|
+
});
|
|
2143
|
+
onTestFinished(() => fixture.app.close());
|
|
2144
|
+
await vi.waitFor(async () => {
|
|
2145
|
+
expect((await fixture.app.inject(`/api/sessions/${fixture.sessionId}`)).json()).toMatchObject({ autopilot: { enabled: true, reason: 'reconcileFailed' } });
|
|
2146
|
+
});
|
|
2147
|
+
unavailable = false;
|
|
2148
|
+
await fixture.app.inject({
|
|
2149
|
+
method: 'POST',
|
|
2150
|
+
url: `/api/sessions/${fixture.sessionId}/activity/refresh`,
|
|
2151
|
+
});
|
|
2152
|
+
const starts = () => handles
|
|
2153
|
+
.flatMap((handle) => handle.requests)
|
|
2154
|
+
.filter((request) => request.method === 'turn/start');
|
|
2155
|
+
await vi.waitFor(async () => {
|
|
2156
|
+
expect((await fixture.app.inject(`/api/sessions/${fixture.sessionId}`)).json()).toMatchObject({
|
|
2157
|
+
agentActivity: {
|
|
2158
|
+
confidence: 'fresh',
|
|
2159
|
+
subagents: [
|
|
2160
|
+
{
|
|
2161
|
+
id: 'preserved-executor',
|
|
2162
|
+
canonicalPosition: 'L1',
|
|
2163
|
+
},
|
|
2164
|
+
],
|
|
2165
|
+
},
|
|
2166
|
+
autopilot: { enabled: true },
|
|
2167
|
+
});
|
|
2168
|
+
expect(timers.some((timer) => !timer.cancelled && !timer.fired)).toBe(true);
|
|
2169
|
+
});
|
|
2170
|
+
for (let attempt = 0; attempt < 8 && starts().length === 0; attempt += 1) {
|
|
2171
|
+
const timer = timers.find((candidate) => !candidate.cancelled && !candidate.fired);
|
|
2172
|
+
expect(timer).toBeDefined();
|
|
2173
|
+
timer.fired = true;
|
|
2174
|
+
timer.callback();
|
|
2175
|
+
await vi.waitFor(() => expect(starts().length > 0 ||
|
|
2176
|
+
timers.some((candidate) => !candidate.cancelled && !candidate.fired)).toBe(true));
|
|
2177
|
+
}
|
|
2178
|
+
expect(starts()).toHaveLength(1);
|
|
2179
|
+
expect(starts()[0].params).toMatchObject({ threadId: 'preserved-executor' });
|
|
2180
|
+
for (const timer of timers.filter((candidate) => candidate.fired))
|
|
2181
|
+
timer.callback();
|
|
2182
|
+
await Promise.resolve();
|
|
2183
|
+
expect(starts()).toHaveLength(1);
|
|
2184
|
+
});
|
|
2052
2185
|
it('production incompatible reconcile remains supervised and schedules reinspection', async () => {
|
|
2053
2186
|
let reconciliations = 0;
|
|
2054
2187
|
const timers = [];
|
|
@@ -2154,6 +2287,59 @@ describe('production composition', () => {
|
|
|
2154
2287
|
});
|
|
2155
2288
|
});
|
|
2156
2289
|
describeCompositionConcern('attention', () => {
|
|
2290
|
+
it('includes the same blocked root turn explanation in attention and session reloads', async () => {
|
|
2291
|
+
const timers = [];
|
|
2292
|
+
const fixture = await createProductionAutopilotFixture({
|
|
2293
|
+
autopilotSchedule: (callback) => {
|
|
2294
|
+
const timer = { callback, cancelled: false };
|
|
2295
|
+
timers.push(timer);
|
|
2296
|
+
return () => {
|
|
2297
|
+
timer.cancelled = true;
|
|
2298
|
+
};
|
|
2299
|
+
},
|
|
2300
|
+
});
|
|
2301
|
+
timers.find((timer) => !timer.cancelled).callback();
|
|
2302
|
+
await vi.waitFor(async () => expect((await fixture.app.inject(`/api/sessions/${fixture.sessionId}`)).json().activeTurnId).toEqual(expect.any(String)));
|
|
2303
|
+
const session = (await fixture.app.inject(`/api/sessions/${fixture.sessionId}`)).json();
|
|
2304
|
+
const handle = fixture.handles.find((candidate) => candidate.requests.some((request) => request.method === 'turn/start'));
|
|
2305
|
+
await expect(handle.request({
|
|
2306
|
+
id: 698,
|
|
2307
|
+
method: 'item/tool/call',
|
|
2308
|
+
params: {
|
|
2309
|
+
threadId: session.threadId,
|
|
2310
|
+
turnId: session.activeTurnId,
|
|
2311
|
+
tool: 'gestalt_org_plan_attention',
|
|
2312
|
+
arguments: { reason: 'hardBlock', resumeCondition: 'externalStateChanged' },
|
|
2313
|
+
},
|
|
2314
|
+
})).resolves.toEqual(toOrgPlanAttentionAcknowledgement());
|
|
2315
|
+
const report = 'The checkpoint cannot identify L1.2. Refresh plan state, then retry.';
|
|
2316
|
+
handle.notify({
|
|
2317
|
+
method: 'item/completed',
|
|
2318
|
+
params: {
|
|
2319
|
+
threadId: session.threadId,
|
|
2320
|
+
turnId: session.activeTurnId,
|
|
2321
|
+
item: { id: 'blocker-final', type: 'agentMessage', phase: 'final_answer', text: report },
|
|
2322
|
+
},
|
|
2323
|
+
});
|
|
2324
|
+
handle.notify({
|
|
2325
|
+
method: 'item/completed',
|
|
2326
|
+
params: {
|
|
2327
|
+
threadId: session.threadId,
|
|
2328
|
+
turnId: 'another-turn',
|
|
2329
|
+
item: {
|
|
2330
|
+
id: 'unrelated-final',
|
|
2331
|
+
type: 'agentMessage',
|
|
2332
|
+
phase: 'final_answer',
|
|
2333
|
+
text: 'Unrelated report',
|
|
2334
|
+
},
|
|
2335
|
+
},
|
|
2336
|
+
});
|
|
2337
|
+
expect((await fixture.app.inject(`/api/sessions/${fixture.sessionId}/attention`)).json()).toMatchObject({ supervisorReport: report });
|
|
2338
|
+
expect((await fixture.app.inject(`/api/sessions/${fixture.sessionId}`)).json().pendingInteractions).toEqual(expect.arrayContaining([
|
|
2339
|
+
expect.objectContaining({ requestId: '698', supervisorReport: report }),
|
|
2340
|
+
]));
|
|
2341
|
+
await fixture.app.close();
|
|
2342
|
+
});
|
|
2157
2343
|
it('bounds a wedged attention acknowledgement writer without losing durable attention', async () => {
|
|
2158
2344
|
const fixture = await createProductionAutopilotFixture({
|
|
2159
2345
|
attentionAcknowledgementDeadlineMs: 100,
|
|
@@ -3863,7 +4049,7 @@ describe('production composition', () => {
|
|
|
3863
4049
|
// Model and skill catalogs run for bootstrap and session start; the active child closes with the relay.
|
|
3864
4050
|
await vi.waitFor(() => expect(closed).toBe(5));
|
|
3865
4051
|
});
|
|
3866
|
-
it('reconciles
|
|
4052
|
+
it('reconciles cleared interactions and unloaded child rosters through later activity', async () => {
|
|
3867
4053
|
const root = await mkdtemp(join(tmpdir(), 'gestalt-mobile-root-'));
|
|
3868
4054
|
const dataDir = await mkdtemp(join(tmpdir(), 'gestalt-mobile-state-'));
|
|
3869
4055
|
ownTemporaryPaths(root, dataDir);
|
|
@@ -3871,6 +4057,7 @@ describe('production composition', () => {
|
|
|
3871
4057
|
const handles = [];
|
|
3872
4058
|
const activityCallbacks = [];
|
|
3873
4059
|
const activityDiagnostic = vi.fn();
|
|
4060
|
+
let includeUnloadedChild = false;
|
|
3874
4061
|
const app = await composeAuthorizedApp({
|
|
3875
4062
|
root,
|
|
3876
4063
|
dataDir,
|
|
@@ -3900,6 +4087,20 @@ describe('production composition', () => {
|
|
|
3900
4087
|
throw new Error('READ_DOWN');
|
|
3901
4088
|
return { thread: { id: 'thread-1', status: { type: 'idle' }, turns: [] } };
|
|
3902
4089
|
}
|
|
4090
|
+
if (method === 'thread/list')
|
|
4091
|
+
return {
|
|
4092
|
+
data: includeUnloadedChild
|
|
4093
|
+
? [
|
|
4094
|
+
{
|
|
4095
|
+
id: 'l4',
|
|
4096
|
+
status: { type: 'notLoaded' },
|
|
4097
|
+
source: { subAgent: { thread_spawn: { agent_path: '/root/l4' } } },
|
|
4098
|
+
},
|
|
4099
|
+
]
|
|
4100
|
+
: [],
|
|
4101
|
+
};
|
|
4102
|
+
if (method === 'thread/backgroundTerminals/list')
|
|
4103
|
+
throw new CodexJsonRpcError(-32600, 'thread not found: l4');
|
|
3903
4104
|
if (method === 'model/list')
|
|
3904
4105
|
return { data: [{ id: 'gpt-5.6-terra' }] };
|
|
3905
4106
|
if (method === 'skills/list')
|
|
@@ -3941,6 +4142,19 @@ describe('production composition', () => {
|
|
|
3941
4142
|
state: 'ready',
|
|
3942
4143
|
agentActivity: { confidence: 'fresh' },
|
|
3943
4144
|
});
|
|
4145
|
+
// A durable child may be absent from the writer's process registry.
|
|
4146
|
+
// Its process RPC must not prevent roster publication or future refreshes.
|
|
4147
|
+
includeUnloadedChild = true;
|
|
4148
|
+
await app.inject({ method: 'POST', url: `/api/sessions/${sessionId}/activity/refresh` });
|
|
4149
|
+
await vi.waitFor(async () => {
|
|
4150
|
+
expect((await app.inject(`/api/sessions/${sessionId}`)).json()).toMatchObject({
|
|
4151
|
+
agentActivity: {
|
|
4152
|
+
confidence: 'fresh',
|
|
4153
|
+
subagents: [{ id: 'l4', canonicalPosition: 'L4', state: 'disconnected' }],
|
|
4154
|
+
},
|
|
4155
|
+
});
|
|
4156
|
+
});
|
|
4157
|
+
expect(activityDiagnostic).not.toHaveBeenCalled();
|
|
3944
4158
|
const reconciliationCalls = handle.calls.filter((method) => method === 'thread/read' || method === 'thread/list');
|
|
3945
4159
|
const ordinarySave = await app.inject({
|
|
3946
4160
|
method: 'POST',
|
|
@@ -4013,7 +4227,10 @@ describe('production composition', () => {
|
|
|
4013
4227
|
params: { thread: { id: 'thread-1', status: { type: 'active' } } },
|
|
4014
4228
|
});
|
|
4015
4229
|
expect((await app.inject(`/api/sessions/${sessionId}`)).json()).toMatchObject({
|
|
4016
|
-
agentActivity: {
|
|
4230
|
+
agentActivity: {
|
|
4231
|
+
root: { state: 'working' },
|
|
4232
|
+
subagents: [{ id: 'l4', canonicalPosition: 'L4', state: 'disconnected' }],
|
|
4233
|
+
},
|
|
4017
4234
|
});
|
|
4018
4235
|
const pending = handle.request({
|
|
4019
4236
|
id: 7,
|
|
@@ -116,7 +116,17 @@ export async function composeRelayApp(options) {
|
|
|
116
116
|
const supervisedPlans = new SupervisedPlanRegistry();
|
|
117
117
|
const planStatusSource = new FilesystemPlanStatusSource(join(dirname(databasePath), 'plans'));
|
|
118
118
|
const planMeasurementHelperPath = options.planMeasurementHelperPath ?? process.env.GESTALT_MOBILE_ORG_PLAN_HELPER;
|
|
119
|
-
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;
|
|
120
130
|
const events = new SessionEventBus();
|
|
121
131
|
let notifyAutopilotActivity = () => undefined;
|
|
122
132
|
let publishSessionStatus = () => undefined;
|
|
@@ -764,8 +774,15 @@ 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;
|
|
@@ -786,7 +803,6 @@ export async function composeRelayApp(options) {
|
|
|
786
803
|
],
|
|
787
804
|
}) === true);
|
|
788
805
|
}
|
|
789
|
-
const compactCheckpointKind = compactOrgPlanCheckpointKind(request);
|
|
790
806
|
if (!rawInteraction && compactCheckpointKind) {
|
|
791
807
|
const retained = supervisedPlans.find(sessionId);
|
|
792
808
|
const identity = supervisedPlans.identity(sessionId);
|
|
@@ -1470,9 +1486,7 @@ export async function composeRelayApp(options) {
|
|
|
1470
1486
|
exists: (id) => sessions.find(id) !== null,
|
|
1471
1487
|
reader: {
|
|
1472
1488
|
active: (sessionId) => {
|
|
1473
|
-
const interaction =
|
|
1474
|
-
.list(sessionId)
|
|
1475
|
-
.find((item) => item.kind === 'orgPlanAttention');
|
|
1489
|
+
const interaction = pendingInteractionsWithReports(sessionId).find((item) => item.kind === 'orgPlanAttention');
|
|
1476
1490
|
const attention = interaction ? parseOrgPlanAttention(interaction.payload) : null;
|
|
1477
1491
|
return interaction && attention
|
|
1478
1492
|
? {
|
|
@@ -1480,6 +1494,9 @@ export async function composeRelayApp(options) {
|
|
|
1480
1494
|
turnId: interaction.turnId ?? null,
|
|
1481
1495
|
requestedAt: interaction.requestedAt ?? null,
|
|
1482
1496
|
attention,
|
|
1497
|
+
...(interaction.supervisorReport
|
|
1498
|
+
? { supervisorReport: interaction.supervisorReport }
|
|
1499
|
+
: {}),
|
|
1483
1500
|
}
|
|
1484
1501
|
: null;
|
|
1485
1502
|
},
|
|
@@ -69,8 +69,14 @@ function classifySupervisedActivity(activity, plan) {
|
|
|
69
69
|
(process.state === 'running' || process.state === 'detached-active'));
|
|
70
70
|
return !historical || supervisedProcess;
|
|
71
71
|
});
|
|
72
|
+
// A fresh authoritative roster can retain the current executor while its
|
|
73
|
+
// runtime is unloaded. Re-reading that same status cannot load it: allow the
|
|
74
|
+
// coordinator's fenced continuation to resume the existing physical thread.
|
|
75
|
+
const resumable = (child) => child.canonicalPosition === `L${position}` &&
|
|
76
|
+
Boolean(child.taskPath && child.canonicalTaskName) &&
|
|
77
|
+
child.state === 'disconnected';
|
|
72
78
|
// An aggregate-only observation cannot prove which child is historical.
|
|
73
|
-
if (retained.length === activity.subagents.length)
|
|
79
|
+
if (retained.length === activity.subagents.length && !retained.some(resumable))
|
|
74
80
|
return classifyAgentActivity(activity);
|
|
75
81
|
if (activity.root.state === 'awaitingHuman' ||
|
|
76
82
|
retained.some((child) => child.state === 'awaitingHuman'))
|
|
@@ -82,12 +88,12 @@ function classifySupervisedActivity(activity, plan) {
|
|
|
82
88
|
(process.state === 'running' || process.state === 'detached-active'))))
|
|
83
89
|
return 'active';
|
|
84
90
|
if (activity.root.state === 'disconnected' ||
|
|
85
|
-
retained.some((child) => child.state === 'disconnected'))
|
|
91
|
+
retained.some((child) => child.state === 'disconnected' && !resumable(child)))
|
|
86
92
|
return 'reconcile';
|
|
87
93
|
const rootSettled = activity.root.state === 'idle' ||
|
|
88
94
|
activity.root.state === 'blocked' ||
|
|
89
95
|
activity.root.state === 'awaitingAgent';
|
|
90
|
-
const childrenSettled = retained.every((child) => child.state === 'idle' || child.state === 'blocked');
|
|
96
|
+
const childrenSettled = retained.every((child) => child.state === 'idle' || child.state === 'blocked' || resumable(child));
|
|
91
97
|
return rootSettled && childrenSettled ? 'settled' : 'observe';
|
|
92
98
|
}
|
|
93
99
|
/** A deliberately pure, exhaustive safety gate. Adapters may only enact this result. */
|
|
@@ -16,7 +16,7 @@ import { gestaltAgentCapacityRecoveryDynamicTool } from '../../../shared/contrac
|
|
|
16
16
|
import { countDiffLines } from '../../../shared/contracts/file-change.js';
|
|
17
17
|
import { threadPlanName } from './thread-plan-name.js';
|
|
18
18
|
import { WriterAcquisitionError, } from '../../features/sessions/application/writer-acquisition.js';
|
|
19
|
-
import { isCodexThreadWriterBusy, isMissingCodexThreadRollout } from './json-rpc-client.js';
|
|
19
|
+
import { CodexJsonRpcError, isCodexThreadWriterBusy, isMissingCodexThreadRollout, } from './json-rpc-client.js';
|
|
20
20
|
import { resolvedServerRequestId } from './server-request.js';
|
|
21
21
|
/** Sticky thread config keeps skill paths out of the app-server process argv. */
|
|
22
22
|
export function threadSkillConfig(skillsConfig, modelConfig = {}) {
|
|
@@ -525,7 +525,24 @@ export class CodexSessionRuntime {
|
|
|
525
525
|
const owned = this.sessions.get(session.id);
|
|
526
526
|
if (!owned)
|
|
527
527
|
return [];
|
|
528
|
-
|
|
528
|
+
let active;
|
|
529
|
+
try {
|
|
530
|
+
active = await this.listChildBackgroundTerminals(owned, child);
|
|
531
|
+
}
|
|
532
|
+
catch (error) {
|
|
533
|
+
// Durable topology includes children absent from this app-server's live
|
|
534
|
+
// registry. Its process RPC then reports "thread not found"; that does
|
|
535
|
+
// not invalidate the roster or prove that previously observed work exited.
|
|
536
|
+
if (child.status !== 'notLoaded' ||
|
|
537
|
+
child.qualified === false ||
|
|
538
|
+
!(error instanceof CodexJsonRpcError) ||
|
|
539
|
+
error.code !== -32600 ||
|
|
540
|
+
error.message !== `thread not found: ${child.id}`)
|
|
541
|
+
throw error;
|
|
542
|
+
return [...owned.ownedChildProcesses.values()].filter((process) => process.ownerThreadId === child.id &&
|
|
543
|
+
process.state !== 'result-consumed' &&
|
|
544
|
+
process.state !== 'terminated-for-budget');
|
|
545
|
+
}
|
|
529
546
|
const activeIds = new Set(active.map((process) => process.processId));
|
|
530
547
|
for (const process of active)
|
|
531
548
|
owned.ownedChildProcesses.set(childProcessKey(child.id, process.processId), process);
|
|
@@ -803,17 +820,22 @@ export class CodexSessionRuntime {
|
|
|
803
820
|
return Promise.reject(new Error('CODEX_SERVER_REQUEST_DUPLICATE'));
|
|
804
821
|
return new Promise((resolve, reject) => {
|
|
805
822
|
resource.pendingRequests.set(requestId, { resolve, reject });
|
|
806
|
-
|
|
823
|
+
const unsupported = () => {
|
|
824
|
+
if (resource.pendingRequests.delete(requestId))
|
|
825
|
+
reject(new Error('CODEX_SERVER_REQUEST_UNSUPPORTED'));
|
|
826
|
+
};
|
|
807
827
|
try {
|
|
808
|
-
accepted =
|
|
809
|
-
|
|
828
|
+
const accepted = this.onServerRequest?.(resource.sessionId, request, this.resolveNotificationOrigin(resource, request));
|
|
829
|
+
void Promise.resolve(accepted).then((value) => {
|
|
830
|
+
if (value !== true)
|
|
831
|
+
unsupported();
|
|
832
|
+
}, unsupported);
|
|
810
833
|
}
|
|
811
834
|
catch {
|
|
812
835
|
// Publication failures are protocol failures, not permission to retain
|
|
813
836
|
// an unreachable app-server request.
|
|
837
|
+
unsupported();
|
|
814
838
|
}
|
|
815
|
-
if (!accepted && resource.pendingRequests.delete(requestId))
|
|
816
|
-
reject(new Error('CODEX_SERVER_REQUEST_UNSUPPORTED'));
|
|
817
839
|
});
|
|
818
840
|
}
|
|
819
841
|
async startThread(process, session, skillsConfig, modelConfig = {}) {
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* Designed by Denis Roio <jaromil@dyne.org>
|
|
4
4
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
|
5
5
|
*/
|
|
6
|
+
import { boundedAttentionReport } from '../../../shared/contracts/attention-report.js';
|
|
6
7
|
export const autopilotAuditEventTypes = [
|
|
7
8
|
'autopilot.turn-started',
|
|
8
9
|
'autopilot.turn-failed',
|
|
@@ -89,6 +90,21 @@ export class SqliteEventJournal {
|
|
|
89
90
|
payload: JSON.parse(row.payload_json),
|
|
90
91
|
}));
|
|
91
92
|
}
|
|
93
|
+
/** Same-turn root final only: never borrow another session, child, or commentary. */
|
|
94
|
+
attentionReport(sessionId, turnId, requestedAt) {
|
|
95
|
+
const row = this.db
|
|
96
|
+
.prepare(`
|
|
97
|
+
SELECT substr(json_extract(payload_json, '$.text'), 1, 4001) AS text
|
|
98
|
+
FROM session_events
|
|
99
|
+
WHERE session_id = ? AND type = 'agentMessageCompleted' AND occurred_at >= ?
|
|
100
|
+
AND json_extract(payload_json, '$.turnId') = ?
|
|
101
|
+
AND json_extract(payload_json, '$.phase') = 'final_answer'
|
|
102
|
+
AND json_type(payload_json, '$.text') = 'text'
|
|
103
|
+
ORDER BY sequence DESC LIMIT 1
|
|
104
|
+
`)
|
|
105
|
+
.get(sessionId, requestedAt, turnId);
|
|
106
|
+
return boundedAttentionReport(row?.text);
|
|
107
|
+
}
|
|
92
108
|
/** Bounded chronological tail for redacted timeline projections. */
|
|
93
109
|
tail(sessionId, limit) {
|
|
94
110
|
const safeLimit = Math.max(1, Math.min(limit, 200));
|
|
@@ -0,0 +1,12 @@
|
|
|
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
|
+
/** Presentation context only; supervisor prose never changes control authority. */
|
|
7
|
+
export function boundedAttentionReport(value) {
|
|
8
|
+
if (typeof value !== 'string' || !value.trim())
|
|
9
|
+
return undefined;
|
|
10
|
+
const text = value.trim();
|
|
11
|
+
return text.length <= 4_000 ? text : `${text.slice(0, 3_999)}…`;
|
|
12
|
+
}
|
|
@@ -15,5 +15,6 @@ export const planSignalReasons = [
|
|
|
15
15
|
export function isPlanSignalReason(value) {
|
|
16
16
|
return (typeof value === 'string' &&
|
|
17
17
|
(planSignalReasons.includes(value) ||
|
|
18
|
-
/^review:[A-Za-z0-9._-]{1,128}:REVIEWED$/.test(value)
|
|
18
|
+
/^review:[A-Za-z0-9._-]{1,128}:REVIEWED$/.test(value) ||
|
|
19
|
+
/^l2:[A-Za-z0-9._-]{1,128}:(WIP|DONE)$/.test(value)));
|
|
19
20
|
}
|