Share Codex sessions across orchestration threads

- Track explicit thread-to-session bindings and detach without stopping siblings
- Apply runtime settings per Codex thread and filter multiplexed events by turn
- Add migration, projection, lifecycle, and concurrency coverage
This commit is contained in:
Julius Marminge authored and Julius Marminge committed 2026-08-14 11:22:52 +02:00
1 parent 12173fe8e9
commit 27da49519f
30 files changed
+1798 -358

No files matched your search

+29 -3
View File
@@ -470,6 +470,14 @@ export const OrchestrationV2ProviderSession = Schema.Struct({
});
export type OrchestrationV2ProviderSession = typeof OrchestrationV2ProviderSession.Type;
export const OrchestrationV2ProviderSessionDetached = Schema.Struct({
providerSessionId: ProviderSessionId,
detachedAt: Schema.DateTimeUtc,
reason: Schema.optional(Schema.String),
});
export type OrchestrationV2ProviderSessionDetached =
typeof OrchestrationV2ProviderSessionDetached.Type;
export const OrchestrationV2ProviderThread = Schema.Struct({
id: ProviderThreadId,
driver: ProviderDriverKind,
@@ -947,9 +955,14 @@ export const OrchestrationV2DomainEvent = Schema.Union([
}),
Schema.Struct({
...OrchestrationV2EventBase.fields,
type: Schema.Literal("provider-session.updated"),
type: Schema.Literals(["provider-session.attached", "provider-session.updated"]),
payload: OrchestrationV2ProviderSession,
}),
Schema.Struct({
...OrchestrationV2EventBase.fields,
type: Schema.Literal("provider-session.detached"),
payload: OrchestrationV2ProviderSessionDetached,
}),
Schema.Struct({
...OrchestrationV2EventBase.fields,
type: Schema.Literal("provider-thread.updated"),
@@ -1179,6 +1192,14 @@ export const OrchestrationV2ProviderSessionJson = OrchestrationV2ProviderSession
);
export type OrchestrationV2ProviderSessionJson = typeof OrchestrationV2ProviderSessionJson.Type;
export const OrchestrationV2ProviderSessionDetachedJson =
OrchestrationV2ProviderSessionDetached.mapFields((fields) => ({
...fields,
detachedAt: Schema.DateTimeUtcFromString,
}));
export type OrchestrationV2ProviderSessionDetachedJson =
typeof OrchestrationV2ProviderSessionDetachedJson.Type;
export const OrchestrationV2ProviderThreadJson = OrchestrationV2ProviderThread.mapFields(
(fields) => ({
...fields,
@@ -1474,9 +1495,14 @@ export const OrchestrationV2DomainEventJson = Schema.Union([
}),
Schema.Struct({
...OrchestrationV2JsonEventBaseFields,
type: Schema.Literal("provider-session.updated"),
type: Schema.Literals(["provider-session.attached", "provider-session.updated"]),
payload: OrchestrationV2ProviderSessionJson,
}),
Schema.Struct({
...OrchestrationV2JsonEventBaseFields,
type: Schema.Literal("provider-session.detached"),
payload: OrchestrationV2ProviderSessionDetachedJson,
}),
Schema.Struct({
...OrchestrationV2JsonEventBaseFields,
type: Schema.Literal("provider-thread.updated"),
@@ -1603,7 +1629,7 @@ export const OrchestrationV2Command = Schema.Union([
modelSelection: ModelSelection,
}),
Schema.Struct({
type: Schema.Literal("provider-session.release"),
type: Schema.Literal("provider-session.detach"),
commandId: CommandId,
threadId: ThreadId,
providerSessionId: ProviderSessionId,
@@ -240,6 +240,23 @@ function normalizeReplayFrame(value: unknown): unknown {
normalized.params = params;
}
if (
(normalized.method === "thread/start" ||
normalized.method === "thread/resume" ||
normalized.method === "thread/fork") &&
typeof normalized.params === "object" &&
normalized.params !== null
) {
// Runtime-scoped thread settings are supplied by the host and commonly
// contain machine-local cwd and short-lived MCP authorization headers.
// They are orthogonal to the recorded provider protocol behavior.
const params = { ...(normalized.params as Record<string, unknown>) };
delete params.cwd;
delete params.model;
delete params.config;
normalized.params = params;
}
return normalized;
}