gestalt-mobile 0.46.0 → 0.46.2
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 +239 -24
- package/dist/server/server/features/autopilot/application/policy.js +4 -0
- package/dist/server/server/features/autopilot/application/service.js +53 -5
- package/dist/server/server/features/autopilot/domain/supervised-lifecycle.js +6 -0
- package/dist/server/server/platform/codex/session-runtime.js +19 -2
- package/package.json +1 -1
|
@@ -830,7 +830,124 @@ describe('production composition', () => {
|
|
|
830
830
|
expect(accepted.handles.flatMap((handle) => handle.calls)).not.toContain('turn/start');
|
|
831
831
|
await accepted.app.close();
|
|
832
832
|
});
|
|
833
|
-
it('
|
|
833
|
+
it('continues the root after a checkpoint with a completed assigned executor', async () => {
|
|
834
|
+
const timers = [];
|
|
835
|
+
let coordinator;
|
|
836
|
+
const fixture = await createProductionAutopilotFixture({
|
|
837
|
+
activitySchedule: () => () => { },
|
|
838
|
+
autopilotSchedule: (callback) => {
|
|
839
|
+
const timer = { callback, cancelled: false, fired: false };
|
|
840
|
+
timers.push(timer);
|
|
841
|
+
return () => {
|
|
842
|
+
timer.cancelled = true;
|
|
843
|
+
};
|
|
844
|
+
},
|
|
845
|
+
onAutopilotCoordinator: (value) => {
|
|
846
|
+
coordinator = value;
|
|
847
|
+
},
|
|
848
|
+
});
|
|
849
|
+
onTestFinished(() => fixture.app.close());
|
|
850
|
+
const checkpoint = await holdCheckpointRequest(fixture, timers, 8900);
|
|
851
|
+
checkpoint.handle.responseSettled({ id: 8900, outcome: 'resultWritten' });
|
|
852
|
+
await expect(checkpoint.response).resolves.toEqual(toOrgPlanCheckpointToolResponse('recorded'));
|
|
853
|
+
let rootActive = true;
|
|
854
|
+
for (const handle of fixture.handles)
|
|
855
|
+
handle.respond = (method, params) => {
|
|
856
|
+
if (method === 'thread/read')
|
|
857
|
+
return {
|
|
858
|
+
thread: {
|
|
859
|
+
id: params.threadId,
|
|
860
|
+
status: { type: rootActive ? 'active' : 'idle' },
|
|
861
|
+
turns: [],
|
|
862
|
+
},
|
|
863
|
+
};
|
|
864
|
+
if (method === 'thread/list')
|
|
865
|
+
return {
|
|
866
|
+
data: [
|
|
867
|
+
{
|
|
868
|
+
id: 'checkpoint-executor',
|
|
869
|
+
status: { type: 'idle' },
|
|
870
|
+
source: { subAgent: { thread_spawn: { agent_path: '/root/l1' } } },
|
|
871
|
+
},
|
|
872
|
+
],
|
|
873
|
+
};
|
|
874
|
+
return undefined;
|
|
875
|
+
};
|
|
876
|
+
await fixture.app.inject({
|
|
877
|
+
method: 'POST',
|
|
878
|
+
url: `/api/sessions/${fixture.sessionId}/activity/refresh`,
|
|
879
|
+
});
|
|
880
|
+
// The final callback may run before the activity projection drops the
|
|
881
|
+
// original turn. Its stale working observation cannot release this fence.
|
|
882
|
+
expect(coordinator.turnCompleted(fixture.sessionId, checkpoint.turnId)).toBe(true);
|
|
883
|
+
coordinator.activityChanged(fixture.sessionId);
|
|
884
|
+
const beforeFinal = new DatabaseSync(join(fixture.dataDir, 'relay.sqlite'));
|
|
885
|
+
try {
|
|
886
|
+
const row = beforeFinal
|
|
887
|
+
.prepare('SELECT lifecycle_json FROM autopilot_sessions WHERE session_id = ?')
|
|
888
|
+
.get(fixture.sessionId);
|
|
889
|
+
expect(JSON.parse(row.lifecycle_json).checkpoints.rootContinuationFromTurnId).toBe(checkpoint.turnId);
|
|
890
|
+
}
|
|
891
|
+
finally {
|
|
892
|
+
beforeFinal.close();
|
|
893
|
+
}
|
|
894
|
+
rootActive = false;
|
|
895
|
+
checkpoint.handle.notify({
|
|
896
|
+
method: 'turn/completed',
|
|
897
|
+
params: {
|
|
898
|
+
threadId: checkpoint.threadId,
|
|
899
|
+
turn: { id: checkpoint.turnId, status: 'completed' },
|
|
900
|
+
},
|
|
901
|
+
});
|
|
902
|
+
await vi.waitFor(async () => expect((await fixture.app.inject(`/api/sessions/${fixture.sessionId}`)).json().agentActivity.root
|
|
903
|
+
.state).toBe('idle'));
|
|
904
|
+
const starts = () => fixture.handles
|
|
905
|
+
.flatMap((handle) => handle.requests)
|
|
906
|
+
.filter((request) => request.method === 'turn/start');
|
|
907
|
+
for (let attempt = 0; attempt < 8 && starts().length < 2; attempt++) {
|
|
908
|
+
const ready = timers.filter((timer) => !timer.cancelled && !timer.fired);
|
|
909
|
+
expect(ready.length).toBeGreaterThan(0);
|
|
910
|
+
for (const timer of ready) {
|
|
911
|
+
timer.fired = true;
|
|
912
|
+
timer.callback();
|
|
913
|
+
}
|
|
914
|
+
await new Promise((resolve) => setImmediate(resolve));
|
|
915
|
+
}
|
|
916
|
+
await vi.waitFor(() => expect(starts()).toHaveLength(2));
|
|
917
|
+
expect(starts().map((request) => request.params.threadId)).toEqual([
|
|
918
|
+
checkpoint.threadId,
|
|
919
|
+
checkpoint.threadId,
|
|
920
|
+
]);
|
|
921
|
+
coordinator.evaluate(fixture.sessionId);
|
|
922
|
+
coordinator.turnCompleted(fixture.sessionId, checkpoint.turnId);
|
|
923
|
+
for (const timer of timers.filter((timer) => !timer.cancelled && !timer.fired)) {
|
|
924
|
+
timer.fired = true;
|
|
925
|
+
timer.callback();
|
|
926
|
+
timer.callback();
|
|
927
|
+
}
|
|
928
|
+
await new Promise((resolve) => setImmediate(resolve));
|
|
929
|
+
expect(starts()).toHaveLength(2);
|
|
930
|
+
const database = new DatabaseSync(join(fixture.dataDir, 'relay.sqlite'));
|
|
931
|
+
try {
|
|
932
|
+
const row = database
|
|
933
|
+
.prepare('SELECT lifecycle_json FROM autopilot_sessions WHERE session_id = ?')
|
|
934
|
+
.get(fixture.sessionId);
|
|
935
|
+
expect(JSON.parse(row.lifecycle_json).checkpoints.rootContinuationFromTurnId).toBeUndefined();
|
|
936
|
+
const counts = database
|
|
937
|
+
.prepare("SELECT type, count(*) AS count FROM session_events WHERE session_id = ? AND type IN ('org-plan.step-checkpointed', 'org-plan.step-reported', 'autopilot.executor-resumed', 'autopilot.operation-failed', 'autopilot.turn-started') GROUP BY type")
|
|
938
|
+
.all(fixture.sessionId);
|
|
939
|
+
expect(counts).toEqual(expect.arrayContaining([
|
|
940
|
+
{ type: 'org-plan.step-checkpointed', count: 1 },
|
|
941
|
+
{ type: 'org-plan.step-reported', count: 1 },
|
|
942
|
+
{ type: 'autopilot.turn-started', count: 2 },
|
|
943
|
+
]));
|
|
944
|
+
expect(counts).toHaveLength(3);
|
|
945
|
+
}
|
|
946
|
+
finally {
|
|
947
|
+
database.close();
|
|
948
|
+
}
|
|
949
|
+
});
|
|
950
|
+
it('continues the root after a checkpoint while activity is refreshed', async () => {
|
|
834
951
|
const timers = [];
|
|
835
952
|
const fixture = await createProductionAutopilotFixture({
|
|
836
953
|
activitySchedule: () => () => { },
|
|
@@ -909,24 +1026,28 @@ describe('production composition', () => {
|
|
|
909
1026
|
url: `/api/sessions/${fixture.sessionId}/activity/refresh`,
|
|
910
1027
|
});
|
|
911
1028
|
void refreshing.then(() => { });
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
timer.fired
|
|
915
|
-
|
|
1029
|
+
try {
|
|
1030
|
+
await vi.waitFor(() => expect(releaseRoster.length).toBeGreaterThan(0));
|
|
1031
|
+
for (const timer of timers.filter((candidate) => !candidate.cancelled && !candidate.fired)) {
|
|
1032
|
+
timer.fired = true;
|
|
1033
|
+
timer.callback();
|
|
1034
|
+
}
|
|
1035
|
+
await new Promise((resolve) => setImmediate(resolve));
|
|
1036
|
+
expect(releaseRoster).toHaveLength(1);
|
|
1037
|
+
}
|
|
1038
|
+
finally {
|
|
1039
|
+
holdRoster = false;
|
|
1040
|
+
for (const release of releaseRoster)
|
|
1041
|
+
release();
|
|
1042
|
+
await refreshing;
|
|
916
1043
|
}
|
|
917
|
-
await new Promise((resolve) => setImmediate(resolve));
|
|
918
|
-
holdRoster = false;
|
|
919
|
-
expect(releaseRoster).toHaveLength(1);
|
|
920
|
-
for (const release of releaseRoster)
|
|
921
|
-
release();
|
|
922
|
-
await refreshing;
|
|
923
1044
|
const starts = () => fixture.handles
|
|
924
1045
|
.flatMap((handle) => handle.requests)
|
|
925
1046
|
.filter((request) => request.method === 'turn/start' &&
|
|
926
|
-
request.params.threadId ===
|
|
927
|
-
for (let attempt = 0; attempt < 8 && starts().length
|
|
928
|
-
await vi.waitFor(() => expect(starts().length >
|
|
929
|
-
if (starts().length >
|
|
1047
|
+
request.params.threadId === checkpoint.threadId);
|
|
1048
|
+
for (let attempt = 0; attempt < 8 && starts().length < 2; attempt += 1) {
|
|
1049
|
+
await vi.waitFor(() => expect(starts().length > 1 || timers.some((timer) => !timer.cancelled && !timer.fired)).toBe(true));
|
|
1050
|
+
if (starts().length > 1)
|
|
930
1051
|
break;
|
|
931
1052
|
const timer = timers.find((candidate) => !candidate.cancelled && !candidate.fired);
|
|
932
1053
|
timer.fired = true;
|
|
@@ -937,16 +1058,13 @@ describe('production composition', () => {
|
|
|
937
1058
|
});
|
|
938
1059
|
await new Promise((resolve) => setImmediate(resolve));
|
|
939
1060
|
}
|
|
940
|
-
await vi.waitFor(() => expect(starts()).toHaveLength(
|
|
1061
|
+
await vi.waitFor(() => expect(starts()).toHaveLength(2));
|
|
941
1062
|
const database = new DatabaseSync(join(fixture.dataDir, 'relay.sqlite'));
|
|
942
1063
|
const events = database
|
|
943
1064
|
.prepare("SELECT type FROM session_events WHERE session_id = ? AND type IN ('org-plan.step-reported', 'autopilot.executor-resumed') ORDER BY sequence")
|
|
944
1065
|
.all(fixture.sessionId);
|
|
945
1066
|
database.close();
|
|
946
|
-
expect(events).toEqual([
|
|
947
|
-
{ type: 'org-plan.step-reported' },
|
|
948
|
-
{ type: 'autopilot.executor-resumed' },
|
|
949
|
-
]);
|
|
1067
|
+
expect(events).toEqual([{ type: 'org-plan.step-reported' }]);
|
|
950
1068
|
});
|
|
951
1069
|
it('acknowledges a checkpoint before scheduling and drops an obsolete executor wait lease', async () => {
|
|
952
1070
|
const timers = [];
|
|
@@ -1952,7 +2070,97 @@ describe('production composition', () => {
|
|
|
1952
2070
|
expect(fixture.handles.flatMap((candidate) => candidate.requests.filter((call) => call.method === 'turn/start'))[0]?.params).toMatchObject({ threadId: 'child-1' });
|
|
1953
2071
|
await fixture.app.close();
|
|
1954
2072
|
});
|
|
1955
|
-
it('production
|
|
2073
|
+
it('production resumes an unloaded executor without leaving its command issued or replacing it', async () => {
|
|
2074
|
+
const timers = [];
|
|
2075
|
+
const fixture = await createProductionAutopilotFixture({
|
|
2076
|
+
autopilotActivity: (sessionId) => {
|
|
2077
|
+
const observedAt = new Date().toISOString();
|
|
2078
|
+
return {
|
|
2079
|
+
sessionId,
|
|
2080
|
+
rootThreadId: 'thread-1',
|
|
2081
|
+
root: {
|
|
2082
|
+
state: 'idle',
|
|
2083
|
+
reason: 'turnCompleted',
|
|
2084
|
+
observedAt,
|
|
2085
|
+
lastActivityAt: observedAt,
|
|
2086
|
+
},
|
|
2087
|
+
subagents: [
|
|
2088
|
+
{
|
|
2089
|
+
id: 'child-1',
|
|
2090
|
+
threadId: 'child-1',
|
|
2091
|
+
taskPath: '/root/l1',
|
|
2092
|
+
canonicalTaskName: 'l1',
|
|
2093
|
+
canonicalPosition: 'L1',
|
|
2094
|
+
continuationGeneration: 1,
|
|
2095
|
+
outcome: 'partial',
|
|
2096
|
+
ownedProcesses: [],
|
|
2097
|
+
state: 'idle',
|
|
2098
|
+
reason: 'turnCompleted',
|
|
2099
|
+
observedAt,
|
|
2100
|
+
lastActivityAt: observedAt,
|
|
2101
|
+
},
|
|
2102
|
+
],
|
|
2103
|
+
aggregateSubagents: 'idle',
|
|
2104
|
+
confidence: 'fresh',
|
|
2105
|
+
};
|
|
2106
|
+
},
|
|
2107
|
+
autopilotSchedule: (callback) => {
|
|
2108
|
+
const timer = { callback, cancelled: false };
|
|
2109
|
+
timers.push(timer);
|
|
2110
|
+
return () => {
|
|
2111
|
+
timer.cancelled = true;
|
|
2112
|
+
};
|
|
2113
|
+
},
|
|
2114
|
+
});
|
|
2115
|
+
onTestFinished(() => fixture.app.close());
|
|
2116
|
+
for (const handle of fixture.handles) {
|
|
2117
|
+
let loaded = false;
|
|
2118
|
+
handle.respond = (method, params) => {
|
|
2119
|
+
if (params.threadId !== 'child-1')
|
|
2120
|
+
return undefined;
|
|
2121
|
+
if (method === 'thread/resume') {
|
|
2122
|
+
loaded = true;
|
|
2123
|
+
return { thread: { id: 'child-1' } };
|
|
2124
|
+
}
|
|
2125
|
+
if (method === 'turn/start') {
|
|
2126
|
+
if (!loaded)
|
|
2127
|
+
throw new CodexJsonRpcError(-32600, 'thread not found: child-1');
|
|
2128
|
+
return { turn: { id: 'child-turn' } };
|
|
2129
|
+
}
|
|
2130
|
+
return undefined;
|
|
2131
|
+
};
|
|
2132
|
+
}
|
|
2133
|
+
expect((await fixture.app.inject({
|
|
2134
|
+
method: 'PUT',
|
|
2135
|
+
url: `/api/sessions/${fixture.sessionId}/autopilot`,
|
|
2136
|
+
payload: { enabled: true },
|
|
2137
|
+
})).statusCode).toBe(200);
|
|
2138
|
+
await vi.waitFor(() => expect(timers.some((timer) => !timer.cancelled)).toBe(true));
|
|
2139
|
+
timers.find((timer) => !timer.cancelled).callback();
|
|
2140
|
+
const database = new DatabaseSync(join(fixture.dataDir, 'relay.sqlite'));
|
|
2141
|
+
onTestFinished(() => database.close());
|
|
2142
|
+
await vi.waitFor(() => {
|
|
2143
|
+
const row = database
|
|
2144
|
+
.prepare('SELECT lifecycle_json FROM autopilot_sessions WHERE session_id = ?')
|
|
2145
|
+
.get(fixture.sessionId);
|
|
2146
|
+
expect(JSON.parse(row.lifecycle_json)).toMatchObject({
|
|
2147
|
+
executor: {
|
|
2148
|
+
continuationCount: 1,
|
|
2149
|
+
commands: [expect.objectContaining({ status: 'accepted', threadId: 'child-1' })],
|
|
2150
|
+
},
|
|
2151
|
+
});
|
|
2152
|
+
});
|
|
2153
|
+
const calls = fixture.handles
|
|
2154
|
+
.flatMap((handle) => handle.requests)
|
|
2155
|
+
.filter((call) => call.params.threadId === 'child-1');
|
|
2156
|
+
expect(calls.filter((call) => call.method === 'turn/start')).toHaveLength(2);
|
|
2157
|
+
expect(calls.filter((call) => call.method === 'thread/resume')).toHaveLength(1);
|
|
2158
|
+
const failures = database
|
|
2159
|
+
.prepare("SELECT count(*) AS count FROM session_events WHERE session_id = ? AND type IN ('autopilot.operation-failed', 'autopilot.executor-replacement-scheduled')")
|
|
2160
|
+
.get(fixture.sessionId);
|
|
2161
|
+
expect(failures.count).toBe(0);
|
|
2162
|
+
});
|
|
2163
|
+
it.each(['missing rollout', 'unloaded child without rollout'])('production treats %s as an executor rejection and starts one fenced replacement', async (scenario) => {
|
|
1956
2164
|
const timers = [];
|
|
1957
2165
|
const fixture = await createProductionAutopilotFixture({
|
|
1958
2166
|
autopilotActivity: (sessionId) => {
|
|
@@ -1998,7 +2206,11 @@ describe('production composition', () => {
|
|
|
1998
2206
|
// every live writer that can own the executor continuation.
|
|
1999
2207
|
for (const handle of fixture.handles)
|
|
2000
2208
|
handle.respond = (method, params) => {
|
|
2001
|
-
if (
|
|
2209
|
+
if (params.threadId !== 'child-1')
|
|
2210
|
+
return undefined;
|
|
2211
|
+
if (method === 'turn/start' && scenario === 'unloaded child without rollout')
|
|
2212
|
+
throw new CodexJsonRpcError(-32600, 'thread not found: child-1');
|
|
2213
|
+
if (method === 'turn/start' || method === 'thread/resume')
|
|
2002
2214
|
throw new CodexJsonRpcError(-32600, 'no rollout found for thread id child-1');
|
|
2003
2215
|
return undefined;
|
|
2004
2216
|
};
|
|
@@ -2073,7 +2285,10 @@ describe('production composition', () => {
|
|
|
2073
2285
|
expect(replacements.count).toBe(1);
|
|
2074
2286
|
await fixture.app.close();
|
|
2075
2287
|
});
|
|
2076
|
-
it(
|
|
2288
|
+
it.each([
|
|
2289
|
+
['transport-lost', new Error('CODEX_CONNECTION_LOST')],
|
|
2290
|
+
['ambiguous RPC failure', new CodexJsonRpcError(-32603, 'internal error')],
|
|
2291
|
+
])('production leaves a %s executor command issued and never replays it as a replacement', async (_scenario, failure) => {
|
|
2077
2292
|
const timers = [];
|
|
2078
2293
|
const fixture = await createProductionAutopilotFixture({
|
|
2079
2294
|
autopilotActivity: (sessionId) => {
|
|
@@ -2118,7 +2333,7 @@ describe('production composition', () => {
|
|
|
2118
2333
|
for (const handle of fixture.handles)
|
|
2119
2334
|
handle.respond = (method, params) => {
|
|
2120
2335
|
if (method === 'turn/start' && params.threadId === 'child-1')
|
|
2121
|
-
throw
|
|
2336
|
+
throw failure;
|
|
2122
2337
|
return undefined;
|
|
2123
2338
|
};
|
|
2124
2339
|
expect((await fixture.app.inject({
|
|
@@ -99,6 +99,10 @@ function classifySupervisedActivity(activity, plan) {
|
|
|
99
99
|
/** A deliberately pure, exhaustive safety gate. Adapters may only enact this result. */
|
|
100
100
|
export function decideAutopilot(input) {
|
|
101
101
|
const { state, plan, activity, hasPendingInteraction, now, policy } = input;
|
|
102
|
+
// A late checkpoint final must not relabel a terminal safety pause as Off.
|
|
103
|
+
// Only an explicit enable/recovery transition can grant new authority.
|
|
104
|
+
if (state.state === 'safetyPaused')
|
|
105
|
+
return { kind: 'observe' };
|
|
102
106
|
if (input.hasActiveAttention)
|
|
103
107
|
return {
|
|
104
108
|
kind: 'requestAttention',
|
|
@@ -672,6 +672,9 @@ export class AutopilotCoordinator {
|
|
|
672
672
|
pendingTarget: undefined,
|
|
673
673
|
pendingKind: null,
|
|
674
674
|
checkpointHandoffFailed: false,
|
|
675
|
+
rootContinuationFromTurnId: pendingKind !== 'terminalReviewAccepted'
|
|
676
|
+
? state.checkpoints.pendingTurnId
|
|
677
|
+
: undefined,
|
|
675
678
|
},
|
|
676
679
|
updatedAt: occurredAt,
|
|
677
680
|
}, undefined, [
|
|
@@ -987,7 +990,7 @@ export class AutopilotCoordinator {
|
|
|
987
990
|
}
|
|
988
991
|
/** Reacts only to fresh actor status; plan mutations are not scheduling signals. */
|
|
989
992
|
activityChanged(sessionId) {
|
|
990
|
-
|
|
993
|
+
let prior = this.deps.store.find(sessionId);
|
|
991
994
|
if (!prior?.requestedEnabled)
|
|
992
995
|
return;
|
|
993
996
|
const activity = this.deps.activity(sessionId);
|
|
@@ -997,6 +1000,18 @@ export class AutopilotCoordinator {
|
|
|
997
1000
|
this.evaluate(sessionId);
|
|
998
1001
|
return;
|
|
999
1002
|
}
|
|
1003
|
+
if (prior.checkpoints?.rootContinuationFromTurnId &&
|
|
1004
|
+
this.deps.session(sessionId)?.activeTurnId &&
|
|
1005
|
+
this.deps.session(sessionId)?.activeTurnId !== prior.checkpoints.rootContinuationFromTurnId &&
|
|
1006
|
+
activity.root.state === 'working') {
|
|
1007
|
+
this.persist({
|
|
1008
|
+
...prior,
|
|
1009
|
+
checkpoints: { ...prior.checkpoints, rootContinuationFromTurnId: undefined },
|
|
1010
|
+
stopReason: null,
|
|
1011
|
+
updatedAt: this.deps.now(),
|
|
1012
|
+
});
|
|
1013
|
+
prior = this.deps.store.find(sessionId) ?? prior;
|
|
1014
|
+
}
|
|
1000
1015
|
// Reuse the canonical semantic projection: child order, timestamps, and
|
|
1001
1016
|
// activity prose cannot manufacture an extra wake, while a child-only
|
|
1002
1017
|
// lifecycle transition remains visible with an unchanged root.
|
|
@@ -1460,6 +1475,8 @@ export class AutopilotCoordinator {
|
|
|
1460
1475
|
}
|
|
1461
1476
|
}
|
|
1462
1477
|
requiresRootBoundary(state, plan) {
|
|
1478
|
+
if (state.checkpoints?.rootContinuationFromTurnId)
|
|
1479
|
+
return true;
|
|
1463
1480
|
const reportedL2 = new Set(state.checkpoints?.reportedL2Ids ?? []);
|
|
1464
1481
|
const reportedL1 = new Set(state.checkpoints?.reportedL1Ids ?? []);
|
|
1465
1482
|
const epochs = new Map(state.checkpoints?.completionEpochs?.map((entry) => [entry.target, entry]) ?? []);
|
|
@@ -1764,7 +1781,11 @@ export class AutopilotCoordinator {
|
|
|
1764
1781
|
}
|
|
1765
1782
|
catch (error) {
|
|
1766
1783
|
// The command remains issued: the same idempotency key is the only retry.
|
|
1767
|
-
this.containOperationFailure(sessionId, error
|
|
1784
|
+
this.containOperationFailure(sessionId, error, kind === 'consume'
|
|
1785
|
+
? 'processConsume'
|
|
1786
|
+
: kind === 'transfer'
|
|
1787
|
+
? 'processTransfer'
|
|
1788
|
+
: 'processTerminate');
|
|
1768
1789
|
return false;
|
|
1769
1790
|
}
|
|
1770
1791
|
const latest = this.processActionCurrent(sessionId, issued);
|
|
@@ -2189,7 +2210,7 @@ export class AutopilotCoordinator {
|
|
|
2189
2210
|
// Only an explicit app-server rejection is safe to retry. A lost
|
|
2190
2211
|
// response may conceal accepted work, so retain its issued fence.
|
|
2191
2212
|
if (!explicitExecutorRejection(error)) {
|
|
2192
|
-
this.containOperationFailure(sessionId, error);
|
|
2213
|
+
this.containOperationFailure(sessionId, error, 'executorResume');
|
|
2193
2214
|
this.armExecutorRefresh(sessionId, this.deps.policy.executorContinuationMaxMs);
|
|
2194
2215
|
return;
|
|
2195
2216
|
}
|
|
@@ -2278,7 +2299,21 @@ export class AutopilotCoordinator {
|
|
|
2278
2299
|
updatedAt: this.deps.now(),
|
|
2279
2300
|
};
|
|
2280
2301
|
const occurredAt = this.deps.now();
|
|
2302
|
+
const state = this.deps.store.find(sessionId);
|
|
2281
2303
|
this.commit({
|
|
2304
|
+
...(status === 'started' &&
|
|
2305
|
+
turnId &&
|
|
2306
|
+
state?.checkpoints?.rootContinuationFromTurnId &&
|
|
2307
|
+
turnId !== state.checkpoints.rootContinuationFromTurnId
|
|
2308
|
+
? {
|
|
2309
|
+
state: {
|
|
2310
|
+
...state,
|
|
2311
|
+
checkpoints: { ...state.checkpoints, rootContinuationFromTurnId: undefined },
|
|
2312
|
+
stopReason: null,
|
|
2313
|
+
updatedAt: occurredAt,
|
|
2314
|
+
},
|
|
2315
|
+
}
|
|
2316
|
+
: {}),
|
|
2282
2317
|
control: updated,
|
|
2283
2318
|
events: eventType
|
|
2284
2319
|
? [
|
|
@@ -2590,7 +2625,7 @@ export class AutopilotCoordinator {
|
|
|
2590
2625
|
* outbox publication failure must not recursively manufacture another
|
|
2591
2626
|
* rejected promise before a later journal flush can replay the event.
|
|
2592
2627
|
*/
|
|
2593
|
-
containOperationFailure(sessionId, error) {
|
|
2628
|
+
containOperationFailure(sessionId, error, operation = 'queuedOperation') {
|
|
2594
2629
|
const code = operationFailureCode(error);
|
|
2595
2630
|
try {
|
|
2596
2631
|
this.deps.diagnostic?.(sessionId, `operationFailed:${code}`);
|
|
@@ -2639,7 +2674,7 @@ export class AutopilotCoordinator {
|
|
|
2639
2674
|
{
|
|
2640
2675
|
sessionId,
|
|
2641
2676
|
type: 'autopilot.operation-failed',
|
|
2642
|
-
payload: { code },
|
|
2677
|
+
payload: { code, kind: operation, reason: operationErrorKind(error) },
|
|
2643
2678
|
occurredAt: now,
|
|
2644
2679
|
},
|
|
2645
2680
|
],
|
|
@@ -2724,6 +2759,19 @@ function operationFailureCode(error) {
|
|
|
2724
2759
|
return 'PUBLICATION';
|
|
2725
2760
|
return 'OPERATION';
|
|
2726
2761
|
}
|
|
2762
|
+
/** Fixed protocol categories only; exception prose and arbitrary codes stay private. */
|
|
2763
|
+
function operationErrorKind(error) {
|
|
2764
|
+
if (error &&
|
|
2765
|
+
typeof error === 'object' &&
|
|
2766
|
+
'kind' in error &&
|
|
2767
|
+
['CODEX_THREAD_NOT_FOUND', 'CODEX_THREAD_WRITER_BUSY', 'CODEX_JSON_RPC_ERROR'].includes(String(error.kind)))
|
|
2768
|
+
return String(error.kind);
|
|
2769
|
+
if (error instanceof TypeError)
|
|
2770
|
+
return 'TYPE_ERROR';
|
|
2771
|
+
if (error instanceof RangeError)
|
|
2772
|
+
return 'RANGE_ERROR';
|
|
2773
|
+
return 'UNKNOWN';
|
|
2774
|
+
}
|
|
2727
2775
|
function fingerprint(plan) {
|
|
2728
2776
|
return requirePlanFingerprint(JSON.stringify(plan.steps.map((step) => [
|
|
2729
2777
|
step.id,
|
|
@@ -417,6 +417,9 @@ function parseCheckpoints(value) {
|
|
|
417
417
|
return undefined;
|
|
418
418
|
if (typeof value.terminalReviewAccepted !== 'boolean')
|
|
419
419
|
return undefined;
|
|
420
|
+
if (value.rootContinuationFromTurnId !== undefined &&
|
|
421
|
+
!boundedText(value.rootContinuationFromTurnId))
|
|
422
|
+
return undefined;
|
|
420
423
|
const terminalReviewFingerprint = value.terminalReviewFingerprint === undefined
|
|
421
424
|
? undefined
|
|
422
425
|
: parsePlanFingerprint(value.terminalReviewFingerprint);
|
|
@@ -473,6 +476,9 @@ function parseCheckpoints(value) {
|
|
|
473
476
|
? {}
|
|
474
477
|
: { checkpointHandoffFailed: value.checkpointHandoffFailed }),
|
|
475
478
|
terminalReviewAccepted: value.terminalReviewAccepted,
|
|
479
|
+
...(value.rootContinuationFromTurnId === undefined
|
|
480
|
+
? {}
|
|
481
|
+
: { rootContinuationFromTurnId: value.rootContinuationFromTurnId }),
|
|
476
482
|
...(terminalReviewFingerprint ? { terminalReviewFingerprint } : {}),
|
|
477
483
|
};
|
|
478
484
|
}
|
|
@@ -246,7 +246,7 @@ export class CodexSessionRuntime {
|
|
|
246
246
|
const resource = this.sessions.get(session.id);
|
|
247
247
|
if (!resource)
|
|
248
248
|
throw new Error('CODEX_SESSION_NOT_RUNNING');
|
|
249
|
-
const
|
|
249
|
+
const params = {
|
|
250
250
|
threadId: childThreadId,
|
|
251
251
|
input: [{ type: 'text', text, text_elements: [] }],
|
|
252
252
|
clientUserMessageId,
|
|
@@ -256,7 +256,24 @@ export class CodexSessionRuntime {
|
|
|
256
256
|
...(session.modelSettings?.executorReasoningEffort
|
|
257
257
|
? { effort: session.modelSettings.executorReasoningEffort }
|
|
258
258
|
: {}),
|
|
259
|
-
}
|
|
259
|
+
};
|
|
260
|
+
let response;
|
|
261
|
+
try {
|
|
262
|
+
response = await resource.process.rpc.request('turn/start', params);
|
|
263
|
+
}
|
|
264
|
+
catch (error) {
|
|
265
|
+
// Codex 0.160 rejects a durable child absent from this writer's live
|
|
266
|
+
// registry. Load that same thread without overriding its role/config.
|
|
267
|
+
// Only this exact rejection permits one retry; transport loss may hide
|
|
268
|
+
// accepted work and must retain the durable issued fence.
|
|
269
|
+
if (!(error instanceof CodexJsonRpcError) ||
|
|
270
|
+
error.code !== -32600 ||
|
|
271
|
+
error.message !== `thread not found: ${childThreadId}`)
|
|
272
|
+
throw error;
|
|
273
|
+
await resource.process.rpc.request('thread/resume', { threadId: childThreadId });
|
|
274
|
+
response = await resource.process.rpc.request('turn/start', params);
|
|
275
|
+
}
|
|
276
|
+
const result = decodeTurnStart(response);
|
|
260
277
|
if (resource.turnThreads.has(result) || resource.turnThreads.size < 256)
|
|
261
278
|
resource.turnThreads.set(result, childThreadId);
|
|
262
279
|
return result;
|