@shumkov/orchestra 0.12.2 → 0.12.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.
|
@@ -205,6 +205,7 @@ const CONSTRUCTOR_KEYS = new Set([
|
|
|
205
205
|
// Keyed by the pending record itself, so a forged record inserted into the
|
|
206
206
|
// pending map carries no projector and can never yield a raw response.
|
|
207
207
|
const RESULT_PROJECTORS = new WeakMap();
|
|
208
|
+
const THREAD_READ_IDS = new WeakMap();
|
|
208
209
|
const CLIENT_REQUESTS = new Map(Object.entries(protocolSchema.clientRequests));
|
|
209
210
|
const CLIENT_NOTIFICATIONS = new Set(protocolSchema.clientNotifications);
|
|
210
211
|
const DENIED_CLIENT_REQUESTS = new Set(protocolSchema.deniedClientRequests);
|
|
@@ -1491,8 +1492,29 @@ function projectRuntimeWorkspaceRoots(value, ownedCwd) {
|
|
|
1491
1492
|
};
|
|
1492
1493
|
}
|
|
1493
1494
|
|
|
1494
|
-
function projectRpcResult(method, value, ownedCwd) {
|
|
1495
|
+
function projectRpcResult(method, value, ownedCwd, readThreadId) {
|
|
1495
1496
|
const result = protocolObject(value, `${method} result`);
|
|
1497
|
+
if (method === 'thread/read') {
|
|
1498
|
+
const thread = protocolObject(result.thread, 'saved thread');
|
|
1499
|
+
if (
|
|
1500
|
+
thread.id !== readThreadId
|
|
1501
|
+
|| !Array.isArray(thread.turns)
|
|
1502
|
+
|| thread.turns.length !== 0
|
|
1503
|
+
) {
|
|
1504
|
+
throw new CodexAppServerError(
|
|
1505
|
+
'app-server saved thread identity is inconsistent',
|
|
1506
|
+
'CODEX_PROTOCOL_ERROR',
|
|
1507
|
+
);
|
|
1508
|
+
}
|
|
1509
|
+
return {
|
|
1510
|
+
thread: projectThread(
|
|
1511
|
+
thread,
|
|
1512
|
+
'saved thread',
|
|
1513
|
+
ownedCwd,
|
|
1514
|
+
protocolRequiredString(thread.modelProvider, 'saved thread provider'),
|
|
1515
|
+
),
|
|
1516
|
+
};
|
|
1517
|
+
}
|
|
1496
1518
|
if (method === 'initialize') {
|
|
1497
1519
|
return {
|
|
1498
1520
|
codexHome: protocolRequiredString(
|
|
@@ -2170,6 +2192,15 @@ function projectRequestParams(method, params, spec, ownedCwd) {
|
|
|
2170
2192
|
}
|
|
2171
2193
|
return { cwds: [ownedCwd] };
|
|
2172
2194
|
}
|
|
2195
|
+
if (method === 'thread/read') {
|
|
2196
|
+
if (params.includeTurns !== false) {
|
|
2197
|
+
throw new CodexAppServerError(
|
|
2198
|
+
'app-server saved thread read cannot request history',
|
|
2199
|
+
'CODEX_RPC_REJECTED',
|
|
2200
|
+
);
|
|
2201
|
+
}
|
|
2202
|
+
return { threadId: threadId(), includeTurns: false };
|
|
2203
|
+
}
|
|
2173
2204
|
if (method === 'thread/resume') return { threadId: threadId() };
|
|
2174
2205
|
if (method === 'turn/start') {
|
|
2175
2206
|
const projected = {
|
|
@@ -2373,6 +2404,7 @@ function dispatchRequest(client, method, params, {
|
|
|
2373
2404
|
timer: null,
|
|
2374
2405
|
sinkController: null,
|
|
2375
2406
|
};
|
|
2407
|
+
if (method === 'thread/read') THREAD_READ_IDS.set(pending, projectedParams.threadId);
|
|
2376
2408
|
pending.timer = client.setTimer(() => {
|
|
2377
2409
|
if (client.pending.get(id) !== pending) return;
|
|
2378
2410
|
const timeoutError = new CodexAppServerError(
|
|
@@ -3306,7 +3338,7 @@ class CodexAppServerClient extends EventEmitter {
|
|
|
3306
3338
|
const projectResult = RESULT_PROJECTORS.get(pending);
|
|
3307
3339
|
projectedResult = typeof projectResult === 'function'
|
|
3308
3340
|
? projectResult(message.result)
|
|
3309
|
-
: projectRpcResult(pending.method, message.result, this.cwd);
|
|
3341
|
+
: projectRpcResult(pending.method, message.result, this.cwd, THREAD_READ_IDS.get(pending));
|
|
3310
3342
|
} else {
|
|
3311
3343
|
projectedError = projectRpcError(message.error);
|
|
3312
3344
|
}
|
|
@@ -3352,9 +3384,12 @@ class CodexAppServerClient extends EventEmitter {
|
|
|
3352
3384
|
if (this.pending.get(message.id) !== pending) return;
|
|
3353
3385
|
this.pending.delete(message.id);
|
|
3354
3386
|
if (hasError) {
|
|
3387
|
+
const missingThread = pending.method === 'thread/read'
|
|
3388
|
+
&& projectedError.code === -32600
|
|
3389
|
+
&& projectedError.message === `thread not loaded: ${THREAD_READ_IDS.get(pending)}`;
|
|
3355
3390
|
const error = new CodexAppServerError(
|
|
3356
3391
|
`app-server ${pending.method} failed`,
|
|
3357
|
-
'CODEX_RPC_ERROR',
|
|
3392
|
+
missingThread ? 'CODEX_THREAD_UNAVAILABLE' : 'CODEX_RPC_ERROR',
|
|
3358
3393
|
);
|
|
3359
3394
|
error.rpcCode = projectedError.code;
|
|
3360
3395
|
if (
|
|
@@ -633,6 +633,16 @@ class CodexProcess extends Process {
|
|
|
633
633
|
// is proven before either kind of attachment.
|
|
634
634
|
await this._verifyHookTrust();
|
|
635
635
|
this._assertLifecycle(lifecycle);
|
|
636
|
+
if (existingSessionId) {
|
|
637
|
+
const metadata = await this.client.request('thread/read', {
|
|
638
|
+
threadId: existingSessionId,
|
|
639
|
+
includeTurns: false,
|
|
640
|
+
});
|
|
641
|
+
this._assertLifecycle(lifecycle);
|
|
642
|
+
if (metadata?.thread?.id !== existingSessionId || metadata.thread.ephemeral !== false) {
|
|
643
|
+
throw processError('Codex saved thread metadata is inconsistent', 'CODEX_PROTOCOL_ERROR');
|
|
644
|
+
}
|
|
645
|
+
}
|
|
636
646
|
this.state = 'AttachingThread';
|
|
637
647
|
this.attachingThreadId = existingSessionId;
|
|
638
648
|
const result = await this._withSettingsGate(async () => (
|
|
@@ -3008,9 +3018,11 @@ class CodexProcess extends Process {
|
|
|
3008
3018
|
readClientFaultProvenance(outcome),
|
|
3009
3019
|
);
|
|
3010
3020
|
await this._enterContainment(
|
|
3011
|
-
|
|
3012
|
-
? '
|
|
3013
|
-
: '
|
|
3021
|
+
this.state === 'AttachingThread' && this.providerSessionId == null
|
|
3022
|
+
? 'thread-attach-outcome-unknown'
|
|
3023
|
+
: outcome?.errorCode === 'CODEX_RPC_OUTCOME_UNKNOWN'
|
|
3024
|
+
? 'rpc-outcome-unknown'
|
|
3025
|
+
: 'app-server-fault',
|
|
3014
3026
|
error,
|
|
3015
3027
|
);
|
|
3016
3028
|
}
|
|
@@ -3241,6 +3253,7 @@ class CodexProcess extends Process {
|
|
|
3241
3253
|
try {
|
|
3242
3254
|
await this._checkpoint('containment-entered', {
|
|
3243
3255
|
reason,
|
|
3256
|
+
threadId: this.providerSessionId ?? this.attachingThreadId ?? null,
|
|
3244
3257
|
errorCode: error?.code ?? null,
|
|
3245
3258
|
turnId: ownedTurnId ?? null,
|
|
3246
3259
|
...this.containmentProvenance,
|
|
@@ -3300,6 +3313,7 @@ class CodexProcess extends Process {
|
|
|
3300
3313
|
if (this.state !== 'ContainmentFailed') return null;
|
|
3301
3314
|
await this._checkpoint('containment-cleanup-completed', {
|
|
3302
3315
|
reason: this.containmentReason,
|
|
3316
|
+
threadId: this.providerSessionId ?? this.attachingThreadId ?? null,
|
|
3303
3317
|
errorCode: this.containmentErrorCode,
|
|
3304
3318
|
turnId: this.containmentTurnId,
|
|
3305
3319
|
...this.containmentProvenance,
|
|
@@ -916,6 +916,17 @@ class ProcessManager {
|
|
|
916
916
|
}
|
|
917
917
|
if (this._isCodex(existing)) {
|
|
918
918
|
this._assertStrictResumeReuse(existing, spawnContext);
|
|
919
|
+
const failedStateCodes = {
|
|
920
|
+
ContainmentFailed: 'CODEX_CONTAINMENT_FAILED',
|
|
921
|
+
FailedAmbiguous: 'CODEX_RPC_OUTCOME_UNKNOWN',
|
|
922
|
+
DurabilityBlocked: 'CODEX_DURABILITY_FAILED',
|
|
923
|
+
};
|
|
924
|
+
if (failedStateCodes[existing.state]) {
|
|
925
|
+
throw managerError(
|
|
926
|
+
'Codex generation remains fenced pending verified cleanup',
|
|
927
|
+
failedStateCodes[existing.state],
|
|
928
|
+
);
|
|
929
|
+
}
|
|
919
930
|
}
|
|
920
931
|
// Reload-on-drift (cli): a warm cli proc can't hot-swap model/effort or
|
|
921
932
|
// its display hint (all spawn-time). If the resolved config has drifted
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shumkov/orchestra",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.3",
|
|
4
4
|
"description": "Transport-agnostic session engine for Claude Code and the native Codex app-server: spawn, steer, supervise, observe turns, and recover.",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "index.js",
|