The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 25, 10:00 UTC
Persist thread runtime mode and handle mode-switch session restarts
- Add `thread.runtime-mode.set` -> `thread.runtime-mode-set` flow in decider/reactors/projectors - Persist runtime mode on thread/session projections with new DB migrations - Update provider and Codex integration tests to verify thread continuity across mode changes Co-authored-by: codex <codex@users.noreply.github.com>
Julius Marminge committed
Mar 4, 2026 at 13:13 UTC
689dda59e997337103c76ed93af0574dcc554d26
51 files changed
+743
-173
apps/server/integration/OrchestrationEngineHarness.integration.ts
+46
-17
@@ -37,6 +37,8 @@ import { ProviderUnsupportedError } from "../src/provider/Errors.ts";
37
import { ProviderAdapterRegistry } from "../src/provider/Services/ProviderAdapterRegistry.ts";
38
import { ProviderSessionDirectoryLive } from "../src/provider/Layers/ProviderSessionDirectory.ts";
39
import { makeProviderServiceLive } from "../src/provider/Layers/ProviderService.ts";
40
+import { makeCodexAdapterLive } from "../src/provider/Layers/CodexAdapter.ts";
41
+import { CodexAdapter } from "../src/provider/Services/CodexAdapter.ts";
42
import { ProviderService } from "../src/provider/Services/ProviderService.ts";
43
import { CheckpointReactorLive } from "../src/orchestration/Layers/CheckpointReactor.ts";
44
import { OrchestrationEngineLive } from "../src/orchestration/Layers/OrchestrationEngine.ts";
@@ -187,6 +189,7 @@ export interface OrchestrationIntegrationHarness {
189
190
interface MakeOrchestrationIntegrationHarnessOptions {
191
readonly provider?: "codex" | "claudeCode";
192
+ readonly realCodex?: boolean;
193
}
194
195
export const makeOrchestrationIntegrationHarness = (
@@ -195,10 +198,21 @@ export const makeOrchestrationIntegrationHarness = (
198
Effect.gen(function* () {
199
const sleep = (ms: number) => Effect.sleep(ms);
200
const provider = options?.provider ?? "codex";
198
- const adapterHarness = yield* makeTestProviderAdapterHarness({
199
- provider,
200
- });
201
-
201
+ const useRealCodex = options?.realCodex === true;
202
+ const adapterHarness = useRealCodex
203
+ ? null
204
+ : yield* makeTestProviderAdapterHarness({
205
+ provider,
206
+ });
207
+ const fakeRegistry = adapterHarness
208
+ ? Layer.succeed(ProviderAdapterRegistry, {
209
+ getByProvider: (resolvedProvider) =>
210
+ resolvedProvider === adapterHarness.provider
211
+ ? Effect.succeed(adapterHarness.adapter)
212
+ : Effect.fail(new ProviderUnsupportedError({ provider: resolvedProvider })),
213
+ listProviders: () => Effect.succeed([adapterHarness.provider]),
214
+ } as typeof ProviderAdapterRegistry.Service)
215
+ : null;
216
const rootDir = fs.mkdtempSync(path.join(os.tmpdir(), "t3-orchestration-integration-"));
217
const workspaceDir = path.join(rootDir, "workspace");
218
const stateDir = path.join(rootDir, "state");
@@ -207,14 +221,6 @@ export const makeOrchestrationIntegrationHarness = (
221
fs.mkdirSync(stateDir, { recursive: true });
222
initializeGitWorkspace(workspaceDir);
223
210
- const registry: typeof ProviderAdapterRegistry.Service = {
211
- getByProvider: (provider) =>
212
- provider === adapterHarness.provider
213
- ? Effect.succeed(adapterHarness.adapter)
214
- : Effect.fail(new ProviderUnsupportedError({ provider })),
215
- listProviders: () => Effect.succeed([adapterHarness.provider]),
216
- };
217
-
224
const persistenceLayer = makeSqlitePersistenceLive(dbPath);
225
const orchestrationLayer = OrchestrationEngineLive.pipe(
226
Layer.provide(OrchestrationProjectionPipelineLive),
@@ -224,10 +230,33 @@ export const makeOrchestrationIntegrationHarness = (
230
const providerSessionDirectoryLayer = ProviderSessionDirectoryLive.pipe(
231
Layer.provide(ProviderSessionRuntimeRepositoryLive),
232
);
227
- const providerLayer = makeProviderServiceLive().pipe(
228
- Layer.provide(providerSessionDirectoryLayer),
229
- Layer.provide(Layer.succeed(ProviderAdapterRegistry, registry)),
233
+ const realCodexRegistry = Layer.effect(
234
+ ProviderAdapterRegistry,
235
+ Effect.gen(function* () {
236
+ const codexAdapter = yield* CodexAdapter;
237
+ return {
238
+ getByProvider: (resolvedProvider) =>
239
+ resolvedProvider === "codex"
240
+ ? Effect.succeed(codexAdapter)
241
+ : Effect.fail(new ProviderUnsupportedError({ provider: resolvedProvider })),
242
+ listProviders: () => Effect.succeed(["codex"] as const),
243
+ } as typeof ProviderAdapterRegistry.Service;
244
+ }),
245
+ ).pipe(
246
+ Layer.provide(makeCodexAdapterLive()),
247
+ Layer.provideMerge(ServerConfig.layerTest(workspaceDir, stateDir)),
248
+ Layer.provideMerge(NodeServices.layer),
249
+ Layer.provideMerge(providerSessionDirectoryLayer),
250
);
251
+ const providerLayer = useRealCodex
252
+ ? makeProviderServiceLive().pipe(
253
+ Layer.provide(providerSessionDirectoryLayer),
254
+ Layer.provide(realCodexRegistry),
255
+ )
256
+ : makeProviderServiceLive().pipe(
257
+ Layer.provide(providerSessionDirectoryLayer),
258
+ Layer.provide(fakeRegistry!),
259
+ );
260
261
const runtimeServicesLayer = Layer.mergeAll(
262
orchestrationLayer,
@@ -407,8 +436,8 @@ export const makeOrchestrationIntegrationHarness = (
436
return {
437
rootDir,
438
workspaceDir,
410
- dbPath,
411
- adapterHarness,
439
+ dbPath,
440
+ adapterHarness: adapterHarness as TestProviderAdapterHarness,
441
engine,
442
snapshotQuery,
443
providerService,
apps/server/integration/TestProviderAdapter.integration.ts
+1
@@ -264,6 +264,7 @@ export const makeTestProviderAdapterHarness = (options?: MakeTestProviderAdapter
264
sessionId,
265
provider,
266
status: "ready",
267
+ runtimeMode: input.runtimeMode,
268
threadId,
269
cwd: input.cwd,
270
resumeCursor: input.resumeCursor ?? { sessionId },
apps/server/integration/orchestrationEngine.integration.test.ts
+102
@@ -97,6 +97,16 @@ function withHarness<A, E>(
97
);
98
}
99
100
+function withRealCodexHarness<A, E>(
101
+ use: (harness: OrchestrationIntegrationHarness) => Effect.Effect<A, E>,
102
+) {
103
+ return Effect.acquireUseRelease(
104
+ makeOrchestrationIntegrationHarness({ provider: "codex", realCodex: true }),
105
+ use,
106
+ (harness) => harness.dispose,
107
+ );
108
+}
109
+
110
const seedProjectAndThread = (harness: OrchestrationIntegrationHarness) =>
111
Effect.gen(function* () {
112
const createdAt = nowIso();
@@ -118,6 +128,7 @@ const seedProjectAndThread = (harness: OrchestrationIntegrationHarness) =>
128
projectId: PROJECT_ID,
129
title: "Integration Thread",
130
model: "gpt-5-codex",
131
+ runtimeMode: "approval-required",
132
branch: null,
133
worktreePath: harness.workspaceDir,
134
createdAt,
@@ -216,6 +227,97 @@ it.live("runs a single turn end-to-end and persists checkpoint state in sqlite +
227
),
228
);
229
230
+it.live.skipIf(!process.env.CODEX_BINARY_PATH)(
231
+ "keeps the same Codex provider thread across runtime mode switches",
232
+ () =>
233
+ withRealCodexHarness((harness) =>
234
+ Effect.gen(function* () {
235
+ const createdAt = nowIso();
236
+
237
+ yield* harness.engine.dispatch({
238
+ type: "project.create",
239
+ commandId: CommandId.makeUnsafe("cmd-project-create-real-codex"),
240
+ projectId: PROJECT_ID,
241
+ title: "Integration Project",
242
+ workspaceRoot: harness.workspaceDir,
243
+ defaultModel: "gpt-5.3-codex",
244
+ createdAt,
245
+ });
246
+
247
+ yield* harness.engine.dispatch({
248
+ type: "thread.create",
249
+ commandId: CommandId.makeUnsafe("cmd-thread-create-real-codex"),
250
+ threadId: THREAD_ID,
251
+ projectId: PROJECT_ID,
252
+ title: "Integration Thread",
253
+ model: "gpt-5.3-codex",
254
+ runtimeMode: "full-access",
255
+ branch: null,
256
+ worktreePath: harness.workspaceDir,
257
+ createdAt,
258
+ });
259
+
260
+ yield* harness.engine.dispatch({
261
+ type: "thread.turn.start",
262
+ commandId: CommandId.makeUnsafe("cmd-turn-start-real-codex-1"),
263
+ threadId: THREAD_ID,
264
+ message: {
265
+ messageId: asMessageId("msg-real-codex-1"),
266
+ role: "user",
267
+ text: "Reply with exactly ALPHA.",
268
+ attachments: [],
269
+ },
270
+ runtimeMode: "full-access",
271
+ createdAt: nowIso(),
272
+ });
273
+
274
+ const firstThread = yield* harness.waitForThread(
275
+ THREAD_ID,
276
+ (entry) =>
277
+ entry.session?.status === "ready" &&
278
+ entry.session.providerName === "codex" &&
279
+ entry.session.providerThreadId !== null &&
280
+ entry.messages.some(
281
+ (message) => message.role === "assistant" && message.streaming === false,
282
+ ),
283
+ 180_000,
284
+ );
285
+
286
+ const originalProviderThreadId = firstThread.session?.providerThreadId;
287
+ assert.isNotNull(originalProviderThreadId);
288
+
289
+ yield* harness.engine.dispatch({
290
+ type: "thread.turn.start",
291
+ commandId: CommandId.makeUnsafe("cmd-turn-start-real-codex-2"),
292
+ threadId: THREAD_ID,
293
+ message: {
294
+ messageId: asMessageId("msg-real-codex-2"),
295
+ role: "user",
296
+ text: "Reply with exactly BETA.",
297
+ attachments: [],
298
+ },
299
+ runtimeMode: "approval-required",
300
+ createdAt: nowIso(),
301
+ });
302
+
303
+ const secondThread = yield* harness.waitForThread(
304
+ THREAD_ID,
305
+ (entry) =>
306
+ entry.session?.status === "ready" &&
307
+ entry.session.providerName === "codex" &&
308
+ entry.session.providerThreadId !== null &&
309
+ entry.session.runtimeMode === "approval-required" &&
310
+ entry.messages.some(
311
+ (message) => message.role === "assistant" && message.text.includes("BETA"),
312
+ ),
313
+ 180_000,
314
+ );
315
+
316
+ assert.equal(secondThread.session?.providerThreadId, originalProviderThreadId);
317
+ }),
318
+ ),
319
+);
320
+
321
it.live("runs multi-turn file edits and persists checkpoint diffs", () =>
322
withHarness((harness) =>
323
Effect.gen(function* () {
apps/server/integration/providerService.integration.test.ts
+4
@@ -122,6 +122,7 @@ it.effect("replays typed runtime fixture events", () =>
122
{
123
provider: "codex",
124
cwd: fixture.cwd,
125
+ runtimeMode: "full-access",
126
},
127
);
128
assert.equal((session.threadId ?? "").length > 0, true);
@@ -155,6 +156,7 @@ it.effect("replays file-changing fixture turn events", () =>
156
{
157
provider: "codex",
158
cwd: fixture.cwd,
159
+ runtimeMode: "full-access",
160
},
161
);
162
assert.equal((session.threadId ?? "").length > 0, true);
@@ -192,6 +194,7 @@ it.effect("runs multi-turn tool/approval flow", () =>
194
{
195
provider: "codex",
196
cwd: fixture.cwd,
197
+ runtimeMode: "full-access",
198
},
199
);
200
assert.equal((session.threadId ?? "").length > 0, true);
@@ -244,6 +247,7 @@ it.effect("rolls back provider conversation state only", () =>
247
{
248
provider: "codex",
249
cwd: fixture.cwd,
250
+ runtimeMode: "full-access",
251
},
252
);
253
assert.equal((session.threadId ?? "").length > 0, true);
apps/server/src/checkpointing/Layers/CheckpointDiffQuery.test.ts
+1
@@ -43,6 +43,7 @@ function makeSnapshot(input: {
43
projectId: input.projectId,
44
title: "Thread",
45
model: "gpt-5-codex",
46
+ runtimeMode: "full-access",
47
branch: null,
48
worktreePath: input.worktreePath,
49
latestTurn: {
apps/server/src/codexAppServerManager.test.ts
+86
@@ -1,4 +1,8 @@
1
import { describe, expect, it, vi } from "vitest";
2
+import { randomUUID } from "node:crypto";
3
+import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
4
+import os from "node:os";
5
+import path from "node:path";
6
import { ProviderSessionId } from "@t3tools/contracts";
7
8
import {
@@ -165,6 +169,7 @@ describe("startSession", () => {
169
await expect(
170
manager.startSession({
171
provider: "codex",
172
+ runtimeMode: "full-access",
173
}),
174
).rejects.toThrow("cwd missing");
175
expect(events).toHaveLength(1);
@@ -347,3 +352,84 @@ describe("thread checkpoint control", () => {
352
});
353
});
354
});
355
+
356
+describe.skipIf(!process.env.CODEX_BINARY_PATH)("startSession live Codex resume", () => {
357
+ it(
358
+ "keeps prior thread history when resuming with a changed runtime mode",
359
+ async () => {
360
+ const workspaceDir = mkdtempSync(path.join(os.tmpdir(), "codex-live-resume-"));
361
+ writeFileSync(path.join(workspaceDir, "README.md"), "hello\n", "utf8");
362
+
363
+ const manager = new CodexAppServerManager();
364
+
365
+ try {
366
+ const firstSession = await manager.startSession({
367
+ provider: "codex",
368
+ cwd: workspaceDir,
369
+ runtimeMode: "full-access",
370
+ providerOptions: {
371
+ codex: {
372
+ binaryPath: process.env.CODEX_BINARY_PATH,
373
+ ...(process.env.CODEX_HOME_PATH
374
+ ? { homePath: process.env.CODEX_HOME_PATH }
375
+ : {}),
376
+ },
377
+ },
378
+ });
379
+
380
+ const firstTurn = await manager.sendTurn({
381
+ sessionId: firstSession.sessionId,
382
+ input: `Reply with exactly the word ALPHA ${randomUUID()}`,
383
+ });
384
+
385
+ expect(firstTurn.threadId).toBe(firstSession.threadId);
386
+
387
+ await vi.waitFor(async () => {
388
+ const snapshot = await manager.readThread(firstSession.sessionId);
389
+ expect(snapshot.turns.length).toBeGreaterThan(0);
390
+ }, { timeout: 120_000, interval: 1_000 });
391
+
392
+ const firstSnapshot = await manager.readThread(firstSession.sessionId);
393
+ const originalThreadId = firstSnapshot.threadId;
394
+ const originalTurnCount = firstSnapshot.turns.length;
395
+
396
+ manager.stopSession(firstSession.sessionId);
397
+
398
+ const resumedSession = await manager.startSession({
399
+ provider: "codex",
400
+ cwd: workspaceDir,
401
+ runtimeMode: "approval-required",
402
+ resumeCursor: firstSession.resumeCursor,
403
+ providerOptions: {
404
+ codex: {
405
+ binaryPath: process.env.CODEX_BINARY_PATH,
406
+ ...(process.env.CODEX_HOME_PATH
407
+ ? { homePath: process.env.CODEX_HOME_PATH }
408
+ : {}),
409
+ },
410
+ },
411
+ });
412
+
413
+ expect(resumedSession.threadId).toBe(originalThreadId);
414
+
415
+ const resumedSnapshotBeforeTurn = await manager.readThread(resumedSession.sessionId);
416
+ expect(resumedSnapshotBeforeTurn.threadId).toBe(originalThreadId);
417
+ expect(resumedSnapshotBeforeTurn.turns.length).toBeGreaterThanOrEqual(originalTurnCount);
418
+
419
+ await manager.sendTurn({
420
+ sessionId: resumedSession.sessionId,
421
+ input: `Reply with exactly the word BETA ${randomUUID()}`,
422
+ });
423
+
424
+ await vi.waitFor(async () => {
425
+ const snapshot = await manager.readThread(resumedSession.sessionId);
426
+ expect(snapshot.turns.length).toBeGreaterThan(originalTurnCount);
427
+ }, { timeout: 120_000, interval: 1_000 });
428
+ } finally {
429
+ manager.stopAll();
430
+ rmSync(workspaceDir, { recursive: true, force: true });
431
+ }
432
+ },
433
+ 180_000,
434
+ );
435
+});
apps/server/src/codexAppServerManager.ts
+1
@@ -204,6 +204,7 @@ export class CodexAppServerManager extends EventEmitter<CodexAppServerManagerEve
204
sessionId,
205
provider: "codex",
206
status: "connecting",
207
+ runtimeMode: input.runtimeMode,
208
model: normalizeCodexModelSlug(input.model),
209
cwd: resolvedCwd,
210
createdAt: now,
apps/server/src/orchestration/Layers/CheckpointReactor.test.ts
+2
@@ -80,6 +80,7 @@ function createProviderServiceHarness(
80
sessionId: asSessionId("sess-1"),
81
provider: providerName,
82
status: "ready",
83
+ runtimeMode: "full-access",
84
threadId: asProviderThreadId("provider-thread-1"),
85
cwd: sessionCwd,
86
createdAt: now,
@@ -293,6 +294,7 @@ describe("CheckpointReactor", () => {
294
projectId: asProjectId("project-1"),
295
title: "Thread",
296
model: "gpt-5-codex",
297
+ runtimeMode: "approval-required",
298
branch: null,
299
worktreePath: options?.threadWorktreePath ?? cwd,
300
createdAt,
apps/server/src/orchestration/Layers/OrchestrationEngine.test.ts
+10
@@ -80,6 +80,7 @@ describe("OrchestrationEngine", () => {
80
projectId: asProjectId("project-1"),
81
title: "Thread",
82
model: "gpt-5-codex",
83
+ runtimeMode: "approval-required",
84
branch: null,
85
worktreePath: null,
86
createdAt,
@@ -131,6 +132,7 @@ describe("OrchestrationEngine", () => {
132
projectId: asProjectId("project-replay"),
133
title: "replay",
134
model: "gpt-5-codex",
135
+ runtimeMode: "approval-required",
136
branch: null,
137
worktreePath: null,
138
createdAt,
@@ -191,6 +193,7 @@ describe("OrchestrationEngine", () => {
193
projectId: asProjectId("project-stream"),
194
title: "domain-stream",
195
model: "gpt-5-codex",
196
+ runtimeMode: "approval-required",
197
branch: null,
198
worktreePath: null,
199
createdAt,
@@ -234,6 +237,7 @@ describe("OrchestrationEngine", () => {
237
projectId: asProjectId("project-turn-diff"),
238
title: "Turn diff thread",
239
model: "gpt-5-codex",
240
+ runtimeMode: "approval-required",
241
branch: null,
242
worktreePath: null,
243
createdAt,
@@ -341,6 +345,7 @@ describe("OrchestrationEngine", () => {
345
projectId: asProjectId("project-flaky"),
346
title: "flaky-fail",
347
model: "gpt-5-codex",
348
+ runtimeMode: "approval-required",
349
branch: null,
350
worktreePath: null,
351
createdAt,
@@ -356,6 +361,7 @@ describe("OrchestrationEngine", () => {
361
projectId: asProjectId("project-flaky"),
362
title: "flaky-ok",
363
model: "gpt-5-codex",
364
+ runtimeMode: "approval-required",
365
branch: null,
366
worktreePath: null,
367
createdAt,
@@ -419,6 +425,7 @@ describe("OrchestrationEngine", () => {
425
projectId: asProjectId("project-atomic"),
426
title: "atomic",
427
model: "gpt-5-codex",
428
+ runtimeMode: "approval-required",
429
branch: null,
430
worktreePath: null,
431
createdAt,
@@ -551,6 +558,7 @@ describe("OrchestrationEngine", () => {
558
projectId: asProjectId("project-sync"),
559
title: "sync-before",
560
model: "gpt-5-codex",
561
+ runtimeMode: "approval-required",
562
branch: null,
563
worktreePath: null,
564
createdAt,
@@ -628,6 +636,7 @@ describe("OrchestrationEngine", () => {
636
projectId: asProjectId("project-duplicate"),
637
title: "duplicate",
638
model: "gpt-5-codex",
639
+ runtimeMode: "approval-required",
640
branch: null,
641
worktreePath: null,
642
createdAt,
@@ -643,6 +652,7 @@ describe("OrchestrationEngine", () => {
652
projectId: asProjectId("project-duplicate"),
653
title: "duplicate",
654
model: "gpt-5-codex",
655
+ runtimeMode: "approval-required",
656
branch: null,
657
worktreePath: null,
658
createdAt,
apps/server/src/orchestration/Layers/ProjectionPipeline.ts
+16
@@ -396,6 +396,7 @@ const makeOrchestrationProjectionPipeline = Effect.gen(function* () {
396
projectId: event.payload.projectId,
397
title: event.payload.title,
398
model: event.payload.model,
399
+ runtimeMode: event.payload.runtimeMode,
400
branch: event.payload.branch,
401
worktreePath: event.payload.worktreePath,
402
latestTurnId: null,
@@ -425,6 +426,21 @@ const makeOrchestrationProjectionPipeline = Effect.gen(function* () {
426
return;
427
}
428
429
+ case "thread.runtime-mode-set": {
430
+ const existingRow = yield* projectionThreadRepository.getById({
431
+ threadId: event.payload.threadId,
432
+ });
433
+ if (Option.isNone(existingRow)) {
434
+ return;
435
+ }
436
+ yield* projectionThreadRepository.upsert({
437
+ ...existingRow.value,
438
+ runtimeMode: event.payload.runtimeMode,
439
+ updatedAt: event.payload.updatedAt,
440
+ });
441
+ return;
442
+ }
443
+
444
case "thread.deleted": {
445
attachmentSideEffects.deletedThreadIds.add(event.payload.threadId);
446
const existingRow = yield* projectionThreadRepository.getById({
apps/server/src/orchestration/Layers/ProjectionSnapshotQuery.test.ts
+1
@@ -239,6 +239,7 @@ projectionSnapshotLayer("ProjectionSnapshotQuery", (it) => {
239
projectId: asProjectId("project-1"),
240
title: "Thread 1",
241
model: "gpt-5-codex",
242
+ runtimeMode: "full-access",
243
branch: null,
244
worktreePath: null,
245
latestTurn: {
apps/server/src/orchestration/Layers/ProjectionSnapshotQuery.ts
+2
@@ -153,6 +153,7 @@ const makeProjectionSnapshotQuery = Effect.gen(function* () {
153
project_id AS "projectId",
154
title,
155
model,
156
+ runtime_mode AS "runtimeMode",
157
branch,
158
worktree_path AS "worktreePath",
159
latest_turn_id AS "latestTurnId",
@@ -485,6 +486,7 @@ const makeProjectionSnapshotQuery = Effect.gen(function* () {
486
projectId: row.projectId,
487
title: row.title,
488
model: row.model,
489
+ runtimeMode: row.runtimeMode,
490
branch: row.branch,
491
worktreePath: row.worktreePath,
492
latestTurn: latestTurnByThread.get(row.threadId) ?? null,
apps/server/src/orchestration/Layers/ProviderCommandReactor.test.ts
+25
-12
@@ -114,6 +114,13 @@ describe("ProviderCommandReactor", () => {
114
sessionId: asSessionId(`sess-${sessionIndex}`),
115
provider,
116
status: "ready" as const,
117
+ runtimeMode:
118
+ typeof input === "object" &&
119
+ input !== null &&
120
+ "runtimeMode" in input &&
121
+ (input.runtimeMode === "approval-required" || input.runtimeMode === "full-access")
122
+ ? input.runtimeMode
123
+ : "full-access",
124
...(model !== undefined ? { model } : {}),
125
threadId: ProviderThreadId.makeUnsafe(`provider-thread-${sessionIndex}`),
126
resumeCursor: resumeCursor ?? { opaque: `cursor-${sessionIndex}` },
@@ -226,6 +233,7 @@ describe("ProviderCommandReactor", () => {
233
projectId: asProjectId("project-1"),
234
title: "Thread",
235
model: "gpt-5-codex",
236
+ runtimeMode: "approval-required",
237
branch: null,
238
worktreePath: null,
239
createdAt: now,
@@ -497,7 +505,7 @@ describe("ProviderCommandReactor", () => {
505
});
506
});
507
500
- it("restarts the provider session when runtime mode changes", async () => {
508
+ it("restarts the provider session when runtime mode is updated on the thread", async () => {
509
const harness = await createHarness();
510
const now = new Date().toISOString();
511
@@ -520,6 +528,19 @@ describe("ProviderCommandReactor", () => {
528
await waitFor(() => harness.startSession.mock.calls.length === 1);
529
await waitFor(() => harness.sendTurn.mock.calls.length === 1);
530
531
+ await Effect.runPromise(
532
+ harness.engine.dispatch({
533
+ type: "thread.runtime-mode.set",
534
+ commandId: CommandId.makeUnsafe("cmd-runtime-mode-set-1"),
535
+ threadId: ThreadId.makeUnsafe("thread-1"),
536
+ runtimeMode: "approval-required",
537
+ createdAt: now,
538
+ }),
539
+ );
540
+
541
+ await waitFor(() => harness.startSession.mock.calls.length === 2);
542
+ await waitFor(() => harness.stopSession.mock.calls.length === 1);
543
+
544
await Effect.runPromise(
545
harness.engine.dispatch({
546
type: "thread.turn.start",
@@ -531,13 +552,11 @@ describe("ProviderCommandReactor", () => {
552
text: "second",
553
attachments: [],
554
},
534
- runtimeMode: "approval-required",
555
+ runtimeMode: "full-access",
556
createdAt: now,
557
}),
558
);
559
539
- await waitFor(() => harness.stopSession.mock.calls.length === 1);
540
- await waitFor(() => harness.startSession.mock.calls.length === 2);
560
await waitFor(() => harness.sendTurn.mock.calls.length === 2);
561
562
expect(harness.stopSession.mock.calls[0]?.[0]).toEqual({ sessionId: asSessionId("sess-1") });
@@ -642,15 +661,9 @@ describe("ProviderCommandReactor", () => {
661
662
await Effect.runPromise(
663
harness.engine.dispatch({
645
- type: "thread.turn.start",
646
- commandId: CommandId.makeUnsafe("cmd-turn-start-restart-failure-2"),
664
+ type: "thread.runtime-mode.set",
665
+ commandId: CommandId.makeUnsafe("cmd-runtime-mode-set-restart-failure"),
666
threadId: ThreadId.makeUnsafe("thread-1"),
648
- message: {
649
- messageId: asMessageId("user-message-restart-failure-2"),
650
- role: "user",
651
- text: "second",
652
- attachments: [],
653
- },
667
runtimeMode: "approval-required",
668
createdAt: now,
669
}),
apps/server/src/orchestration/Layers/ProviderCommandReactor.ts
+12
-8
@@ -28,6 +28,7 @@ type ProviderIntentEvent = Extract<
28
OrchestrationEvent,
29
{
30
type:
31
+ | "thread.runtime-mode-set"
32
| "thread.turn-start-requested"
33
| "thread.turn-interrupt-requested"
34
| "thread.approval-response-requested"
@@ -197,7 +198,6 @@ const make = Effect.gen(function* () {
198
options?: {
199
readonly provider?: ProviderKind;
200
readonly model?: string;
200
- readonly runtimeMode?: RuntimeMode;
201
},
202
) {
203
const readModel = yield* orchestrationEngine.getReadModel();
@@ -206,8 +206,7 @@ const make = Effect.gen(function* () {
206
return yield* Effect.die(new Error(`Thread '${threadId}' was not found in read model.`));
207
}
208
209
- const desiredRuntimeMode =
210
- options?.runtimeMode ?? thread.session?.runtimeMode ?? DEFAULT_RUNTIME_MODE;
209
+ const desiredRuntimeMode = thread.runtimeMode;
210
const currentProvider: ProviderKind | undefined =
211
thread.session?.providerName === "codex" ||
212
thread.session?.providerName === "claudeCode" ||
@@ -260,8 +259,7 @@ const make = Effect.gen(function* () {
259
260
const existingSessionId = thread.session?.providerSessionId;
261
if (existingSessionId) {
263
- const runtimeModeChanged =
264
- options?.runtimeMode !== undefined && options.runtimeMode !== thread.session?.runtimeMode;
262
+ const runtimeModeChanged = thread.runtimeMode !== thread.session?.runtimeMode;
263
const providerChanged = options?.provider !== undefined && options.provider !== currentProvider;
264
const activeSession = yield* resolveActiveSession(existingSessionId);
265
const sessionModelSwitch =
@@ -316,7 +314,6 @@ const make = Effect.gen(function* () {
314
readonly provider?: ProviderKind;
315
readonly model?: string;
316
readonly effort?: string;
319
- readonly runtimeMode: RuntimeMode;
317
readonly createdAt: string;
318
}) {
319
const thread = yield* resolveThread(input.threadId);
@@ -326,7 +323,6 @@ const make = Effect.gen(function* () {
323
const sessionId = yield* ensureSessionForThread(input.threadId, input.createdAt, {
324
...(input.provider !== undefined ? { provider: input.provider } : {}),
325
...(input.model !== undefined ? { model: input.model } : {}),
329
- runtimeMode: input.runtimeMode,
326
});
327
const normalizedInput = toNonEmptyProviderInput(input.messageText);
328
const normalizedAttachments = input.attachments ?? [];
@@ -459,7 +455,6 @@ const make = Effect.gen(function* () {
455
...(event.payload.provider !== undefined ? { provider: event.payload.provider } : {}),
456
...(event.payload.model !== undefined ? { model: event.payload.model } : {}),
457
...(event.payload.effort !== undefined ? { effort: event.payload.effort } : {}),
462
- runtimeMode: event.payload.runtimeMode,
458
createdAt: event.payload.createdAt,
459
});
460
});
@@ -569,6 +564,14 @@ const make = Effect.gen(function* () {
564
const processDomainEvent = (event: ProviderIntentEvent) =>
565
Effect.gen(function* () {
566
switch (event.type) {
567
+ case "thread.runtime-mode-set": {
568
+ const thread = yield* resolveThread(event.payload.threadId);
569
+ if (!thread?.session || thread.session.status === "stopped") {
570
+ return;
571
+ }
572
+ yield* ensureSessionForThread(event.payload.threadId, event.occurredAt);
573
+ return;
574
+ }
575
case "thread.turn-start-requested":
576
yield* processTurnStartRequested(event);
577
return;
@@ -608,6 +611,7 @@ const make = Effect.gen(function* () {
611
yield* Effect.forkScoped(
612
Stream.runForEach(orchestrationEngine.streamDomainEvents, (event) => {
613
if (
614
+ event.type !== "thread.runtime-mode-set" &&
615
event.type !== "thread.turn-start-requested" &&
616
event.type !== "thread.turn-interrupt-requested" &&
617
event.type !== "thread.approval-response-requested" &&
apps/server/src/orchestration/Layers/ProviderRuntimeIngestion.test.ts
+1
@@ -167,6 +167,7 @@ describe("ProviderRuntimeIngestion", () => {
167
projectId: asProjectId("project-1"),
168
title: "Thread",
169
model: "gpt-5-codex",
170
+ runtimeMode: "approval-required",
171
branch: null,
172
worktreePath: null,
173
createdAt,
apps/server/src/orchestration/Schemas.ts
+2
@@ -4,6 +4,7 @@ import {
4
ProjectDeletedPayload as ContractsProjectDeletedPayloadSchema,
5
ThreadCreatedPayload as ContractsThreadCreatedPayloadSchema,
6
ThreadMetaUpdatedPayload as ContractsThreadMetaUpdatedPayloadSchema,
7
+ ThreadRuntimeModeSetPayload as ContractsThreadRuntimeModeSetPayloadSchema,
8
ThreadDeletedPayload as ContractsThreadDeletedPayloadSchema,
9
ThreadMessageSentPayload as ContractsThreadMessageSentPayloadSchema,
10
ThreadSessionSetPayload as ContractsThreadSessionSetPayloadSchema,
@@ -24,6 +25,7 @@ export const ProjectDeletedPayload = ContractsProjectDeletedPayloadSchema;
25
26
export const ThreadCreatedPayload = ContractsThreadCreatedPayloadSchema;
27
export const ThreadMetaUpdatedPayload = ContractsThreadMetaUpdatedPayloadSchema;
28
+export const ThreadRuntimeModeSetPayload = ContractsThreadRuntimeModeSetPayloadSchema;
29
export const ThreadDeletedPayload = ContractsThreadDeletedPayloadSchema;
30
31
export const MessageSentPayloadSchema = ContractsThreadMessageSentPayloadSchema;
apps/server/src/orchestration/commandInvariants.test.ts
+4
@@ -50,6 +50,7 @@ const readModel: OrchestrationReadModel = {
50
projectId: ProjectId.makeUnsafe("project-a"),
51
title: "Thread A",
52
model: "gpt-5-codex",
53
+ runtimeMode: "full-access",
54
branch: null,
55
worktreePath: null,
56
createdAt: now,
@@ -66,6 +67,7 @@ const readModel: OrchestrationReadModel = {
67
projectId: ProjectId.makeUnsafe("project-b"),
68
title: "Thread B",
69
model: "gpt-5-codex",
70
+ runtimeMode: "full-access",
71
branch: null,
72
worktreePath: null,
73
createdAt: now,
@@ -137,6 +139,7 @@ describe("commandInvariants", () => {
139
projectId: ProjectId.makeUnsafe("project-a"),
140
title: "new",
141
model: "gpt-5-codex",
142
+ runtimeMode: "full-access",
143
branch: null,
144
worktreePath: null,
145
createdAt: now,
@@ -156,6 +159,7 @@ describe("commandInvariants", () => {
159
projectId: ProjectId.makeUnsafe("project-a"),
160
title: "dup",
161
model: "gpt-5-codex",
162
+ runtimeMode: "full-access",
163
branch: null,
164
worktreePath: null,
165
createdAt: now,
apps/server/src/orchestration/decider.projectScripts.test.ts
+77
@@ -130,6 +130,7 @@ describe("decider project scripts", () => {
130
projectId: asProjectId("project-1"),
131
title: "Thread",
132
model: "gpt-5-codex",
133
+ runtimeMode: "approval-required",
134
branch: null,
135
worktreePath: null,
136
createdAt: now,
@@ -180,4 +181,80 @@ describe("decider project scripts", () => {
181
runtimeMode: "approval-required",
182
});
183
});
184
+
185
+ it("emits thread.runtime-mode-set from thread.runtime-mode.set", async () => {
186
+ const now = new Date().toISOString();
187
+ const initial = createEmptyReadModel(now);
188
+ const withProject = await Effect.runPromise(
189
+ projectEvent(initial, {
190
+ sequence: 1,
191
+ eventId: asEventId("evt-project-create"),
192
+ aggregateKind: "project",
193
+ aggregateId: asProjectId("project-1"),
194
+ type: "project.created",
195
+ occurredAt: now,
196
+ commandId: CommandId.makeUnsafe("cmd-project-create"),
197
+ causationEventId: null,
198
+ correlationId: CommandId.makeUnsafe("cmd-project-create"),
199
+ metadata: {},
200
+ payload: {
201
+ projectId: asProjectId("project-1"),
202
+ title: "Project",
203
+ workspaceRoot: "/tmp/project",
204
+ defaultModel: null,
205
+ scripts: [],
206
+ createdAt: now,
207
+ updatedAt: now,
208
+ },
209
+ }),
210
+ );
211
+ const readModel = await Effect.runPromise(
212
+ projectEvent(withProject, {
213
+ sequence: 2,
214
+ eventId: asEventId("evt-thread-create"),
215
+ aggregateKind: "thread",
216
+ aggregateId: ThreadId.makeUnsafe("thread-1"),
217
+ type: "thread.created",
218
+ occurredAt: now,
219
+ commandId: CommandId.makeUnsafe("cmd-thread-create"),
220
+ causationEventId: null,
221
+ correlationId: CommandId.makeUnsafe("cmd-thread-create"),
222
+ metadata: {},
223
+ payload: {
224
+ threadId: ThreadId.makeUnsafe("thread-1"),
225
+ projectId: asProjectId("project-1"),
226
+ title: "Thread",
227
+ model: "gpt-5-codex",
228
+ runtimeMode: "full-access",
229
+ branch: null,
230
+ worktreePath: null,
231
+ createdAt: now,
232
+ updatedAt: now,
233
+ },
234
+ }),
235
+ );
236
+
237
+ const result = await Effect.runPromise(
238
+ decideOrchestrationCommand({
239
+ command: {
240
+ type: "thread.runtime-mode.set",
241
+ commandId: CommandId.makeUnsafe("cmd-runtime-mode-set"),
242
+ threadId: ThreadId.makeUnsafe("thread-1"),
243
+ runtimeMode: "approval-required",
244
+ createdAt: now,
245
+ },
246
+ readModel,
247
+ }),
248
+ );
249
+
250
+ const singleResult = Array.isArray(result) ? null : result;
251
+ if (singleResult === null) {
252
+ throw new Error("Expected a single runtime-mode-set event.");
253
+ }
254
+ expect(singleResult.type).toBe("thread.runtime-mode-set");
255
+ expect(singleResult.payload).toMatchObject({
256
+ threadId: ThreadId.makeUnsafe("thread-1"),
257
+ runtimeMode: "approval-required",
258
+ });
259
+ });
260
});
apps/server/src/orchestration/decider.ts
+27
-1
@@ -157,6 +157,7 @@ export const decideOrchestrationCommand = Effect.fn("decideOrchestrationCommand"
157
projectId: command.projectId,
158
title: command.title,
159
model: command.model,
160
+ runtimeMode: command.runtimeMode,
161
branch: command.branch,
162
worktreePath: command.worktreePath,
163
createdAt: command.createdAt,
@@ -213,6 +214,29 @@ export const decideOrchestrationCommand = Effect.fn("decideOrchestrationCommand"
214
};
215
}
216
217
+ case "thread.runtime-mode.set": {
218
+ yield* requireThread({
219
+ readModel,
220
+ command,
221
+ threadId: command.threadId,
222
+ });
223
+ const occurredAt = nowIso();
224
+ return {
225
+ ...withEventBase({
226
+ aggregateKind: "thread",
227
+ aggregateId: command.threadId,
228
+ occurredAt,
229
+ commandId: command.commandId,
230
+ }),
231
+ type: "thread.runtime-mode-set",
232
+ payload: {
233
+ threadId: command.threadId,
234
+ runtimeMode: command.runtimeMode,
235
+ updatedAt: occurredAt,
236
+ },
237
+ };
238
+ }
239
+
240
case "thread.turn.start": {
241
yield* requireThread({
242
readModel,
@@ -255,7 +279,9 @@ export const decideOrchestrationCommand = Effect.fn("decideOrchestrationCommand"
279
...(command.model !== undefined ? { model: command.model } : {}),
280
...(command.effort !== undefined ? { effort: command.effort } : {}),
281
assistantDeliveryMode: command.assistantDeliveryMode ?? DEFAULT_ASSISTANT_DELIVERY_MODE,
258
- runtimeMode: command.runtimeMode,
282
+ runtimeMode:
283
+ readModel.threads.find((entry) => entry.id === command.threadId)?.runtimeMode ??
284
+ command.runtimeMode,
285
createdAt: command.createdAt,
286
},
287
};
apps/server/src/orchestration/projector.test.ts
+60
@@ -57,6 +57,7 @@ describe("orchestration projector", () => {
57
projectId: "project-1",
58
title: "demo",
59
model: "gpt-5-codex",
60
+ runtimeMode: "full-access",
61
branch: null,
62
worktreePath: null,
63
createdAt: now,
@@ -73,6 +74,7 @@ describe("orchestration projector", () => {
74
projectId: "project-1",
75
title: "demo",
76
model: "gpt-5-codex",
77
+ runtimeMode: "full-access",
78
branch: null,
79
worktreePath: null,
80
latestTurn: null,
@@ -167,6 +169,7 @@ describe("orchestration projector", () => {
169
projectId: "project-1",
170
title: "demo",
171
model: "gpt-5.3-codex",
172
+ runtimeMode: "full-access",
173
branch: null,
174
worktreePath: null,
175
createdAt,
@@ -209,6 +212,59 @@ describe("orchestration projector", () => {
212
expect(thread?.session?.status).toBe("running");
213
});
214
215
+ it("updates canonical thread runtime mode from thread.runtime-mode-set", async () => {
216
+ const createdAt = "2026-02-23T08:00:00.000Z";
217
+ const updatedAt = "2026-02-23T08:00:05.000Z";
218
+ const model = createEmptyReadModel(createdAt);
219
+
220
+ const afterCreate = await Effect.runPromise(
221
+ projectEvent(
222
+ model,
223
+ makeEvent({
224
+ sequence: 1,
225
+ type: "thread.created",
226
+ aggregateKind: "thread",
227
+ aggregateId: "thread-1",
228
+ occurredAt: createdAt,
229
+ commandId: "cmd-create",
230
+ payload: {
231
+ threadId: "thread-1",
232
+ projectId: "project-1",
233
+ title: "demo",
234
+ model: "gpt-5.3-codex",
235
+ runtimeMode: "full-access",
236
+ branch: null,
237
+ worktreePath: null,
238
+ createdAt,
239
+ updatedAt: createdAt,
240
+ },
241
+ }),
242
+ ),
243
+ );
244
+
245
+ const afterUpdate = await Effect.runPromise(
246
+ projectEvent(
247
+ afterCreate,
248
+ makeEvent({
249
+ sequence: 2,
250
+ type: "thread.runtime-mode-set",
251
+ aggregateKind: "thread",
252
+ aggregateId: "thread-1",
253
+ occurredAt: updatedAt,
254
+ commandId: "cmd-runtime-mode-set",
255
+ payload: {
256
+ threadId: "thread-1",
257
+ runtimeMode: "approval-required",
258
+ updatedAt,
259
+ },
260
+ }),
261
+ ),
262
+ );
263
+
264
+ expect(afterUpdate.threads[0]?.runtimeMode).toBe("approval-required");
265
+ expect(afterUpdate.threads[0]?.updatedAt).toBe(updatedAt);
266
+ });
267
+
268
it("marks assistant messages completed with non-streaming updates", async () => {
269
const createdAt = "2026-02-23T09:00:00.000Z";
270
const deltaAt = "2026-02-23T09:00:01.000Z";
@@ -230,6 +286,7 @@ describe("orchestration projector", () => {
286
projectId: "project-1",
287
title: "demo",
288
model: "gpt-5.3-codex",
289
+ runtimeMode: "full-access",
290
branch: null,
291
worktreePath: null,
292
createdAt,
@@ -313,6 +370,7 @@ describe("orchestration projector", () => {
370
projectId: "project-1",
371
title: "demo",
372
model: "gpt-5.3-codex",
373
+ runtimeMode: "full-access",
374
branch: null,
375
worktreePath: null,
376
createdAt,
@@ -524,6 +582,7 @@ describe("orchestration projector", () => {
582
projectId: "project-1",
583
title: "demo",
584
model: "gpt-5.3-codex",
585
+ runtimeMode: "full-access",
586
branch: null,
587
worktreePath: null,
588
createdAt,
@@ -673,6 +732,7 @@ describe("orchestration projector", () => {
732
projectId: "project-1",
733
title: "capped",
734
model: "gpt-5-codex",
735
+ runtimeMode: "full-access",
736
branch: null,
737
worktreePath: null,
738
createdAt,
apps/server/src/orchestration/projector.ts
+18
@@ -17,6 +17,7 @@ import {
17
ThreadCreatedPayload,
18
ThreadDeletedPayload,
19
ThreadMetaUpdatedPayload,
20
+ ThreadRuntimeModeSetPayload,
21
ThreadRevertedPayload,
22
ThreadSessionSetPayload,
23
ThreadTurnDiffCompletedPayload,
@@ -241,6 +242,7 @@ export function projectEvent(
242
projectId: payload.projectId,
243
title: payload.title,
244
model: payload.model,
245
+ runtimeMode: payload.runtimeMode,
246
branch: payload.branch,
247
worktreePath: payload.worktreePath,
248
latestTurn: null,
@@ -289,6 +291,22 @@ export function projectEvent(
291
})),
292
);
293
294
+ case "thread.runtime-mode-set":
295
+ return decodeForEvent(
296
+ ThreadRuntimeModeSetPayload,
297
+ event.payload,
298
+ event.type,
299
+ "payload",
300
+ ).pipe(
301
+ Effect.map((payload) => ({
302
+ ...nextBase,
303
+ threads: updateThread(nextBase.threads, payload.threadId, {
304
+ runtimeMode: payload.runtimeMode,
305
+ updatedAt: payload.updatedAt,
306
+ }),
307
+ })),
308
+ );
309
+
310
case "thread.message-sent":
311
return Effect.gen(function* () {
312
const payload = yield* decodeForEvent(
apps/server/src/persistence/Layers/ProjectionThreads.ts
+5
@@ -24,6 +24,7 @@ const makeProjectionThreadRepository = Effect.gen(function* () {
24
project_id,
25
title,
26
model,
27
+ runtime_mode,
28
branch,
29
worktree_path,
30
latest_turn_id,
@@ -36,6 +37,7 @@ const makeProjectionThreadRepository = Effect.gen(function* () {
37
${row.projectId},
38
${row.title},
39
${row.model},
40
+ ${row.runtimeMode},
41
${row.branch},
42
${row.worktreePath},
43
${row.latestTurnId},
@@ -48,6 +50,7 @@ const makeProjectionThreadRepository = Effect.gen(function* () {
50
project_id = excluded.project_id,
51
title = excluded.title,
52
model = excluded.model,
53
+ runtime_mode = excluded.runtime_mode,
54
branch = excluded.branch,
55
worktree_path = excluded.worktree_path,
56
latest_turn_id = excluded.latest_turn_id,
@@ -67,6 +70,7 @@ const makeProjectionThreadRepository = Effect.gen(function* () {
70
project_id AS "projectId",
71
title,
72
model,
73
+ runtime_mode AS "runtimeMode",
74
branch,
75
worktree_path AS "worktreePath",
76
latest_turn_id AS "latestTurnId",
@@ -88,6 +92,7 @@ const makeProjectionThreadRepository = Effect.gen(function* () {
92
project_id AS "projectId",
93
title,
94
model,
95
+ runtime_mode AS "runtimeMode",
96
branch,
97
worktree_path AS "worktreePath",
98
latest_turn_id AS "latestTurnId",
apps/server/src/persistence/Layers/ProviderSessionRuntime.ts
+5
@@ -49,6 +49,7 @@ const makeProviderSessionRuntimeRepository = Effect.gen(function* () {
49
provider_name,
50
adapter_key,
51
provider_thread_id,
52
+ runtime_mode,
53
status,
54
last_seen_at,
55
resume_cursor_json,
@@ -60,6 +61,7 @@ const makeProviderSessionRuntimeRepository = Effect.gen(function* () {
61
${runtime.providerName},
62
${runtime.adapterKey},
63
${runtime.providerThreadId},
64
+ ${runtime.runtimeMode},
65
${runtime.status},
66
${runtime.lastSeenAt},
67
${runtime.resumeCursor},
@@ -71,6 +73,7 @@ const makeProviderSessionRuntimeRepository = Effect.gen(function* () {
73
provider_name = excluded.provider_name,
74
adapter_key = excluded.adapter_key,
75
provider_thread_id = excluded.provider_thread_id,
76
+ runtime_mode = excluded.runtime_mode,
77
status = excluded.status,
78
last_seen_at = excluded.last_seen_at,
79
resume_cursor_json = excluded.resume_cursor_json,
@@ -89,6 +92,7 @@ const makeProviderSessionRuntimeRepository = Effect.gen(function* () {
92
provider_name AS "providerName",
93
adapter_key AS "adapterKey",
94
provider_thread_id AS "providerThreadId",
95
+ runtime_mode AS "runtimeMode",
96
status,
97
last_seen_at AS "lastSeenAt",
98
resume_cursor_json AS "resumeCursor",
@@ -109,6 +113,7 @@ const makeProviderSessionRuntimeRepository = Effect.gen(function* () {
113
provider_name AS "providerName",
114
adapter_key AS "adapterKey",
115
provider_thread_id AS "providerThreadId",
116
+ runtime_mode AS "runtimeMode",
117
status,
118
last_seen_at AS "lastSeenAt",
119
resume_cursor_json AS "resumeCursor",
apps/server/src/persistence/Migrations.ts
+12
-1
@@ -20,6 +20,10 @@ import Migration0005 from "./Migrations/005_Projections.ts";
20
import Migration0006 from "./Migrations/006_ProjectionThreadSessionRuntimeModeColumns.ts";
21
import Migration0007 from "./Migrations/007_ProjectionThreadMessageAttachments.ts";
22
import Migration0008 from "./Migrations/008_ProjectionThreadActivitySequence.ts";
23
+import Migration0009 from "./Migrations/009_ProviderSessionRuntimeMode.ts";
24
+import Migration0010 from "./Migrations/010_ProjectionThreadsRuntimeMode.ts";
25
+import Migration0011 from "./Migrations/011_OrchestrationThreadCreatedRuntimeMode.ts";
26
+import { Effect } from "effect";
27
28
/**
29
* Migration loader with all migrations defined inline.
@@ -40,6 +44,9 @@ const loader = Migrator.fromRecord({
44
"6_ProjectionThreadSessionRuntimeModeColumns": Migration0006,
45
"7_ProjectionThreadMessageAttachments": Migration0007,
46
"8_ProjectionThreadActivitySequence": Migration0008,
47
+ "9_ProviderSessionRuntimeMode": Migration0009,
48
+ "10_ProjectionThreadsRuntimeMode": Migration0010,
49
+ "11_OrchestrationThreadCreatedRuntimeMode": Migration0011,
50
});
51
52
/**
@@ -58,7 +65,11 @@ const run = Migrator.make({});
65
*
66
* @returns Effect containing array of executed migrations
67
*/
61
-export const runMigrations = run({ loader });
68
+export const runMigrations = Effect.gen(function* () {
69
+ yield* Effect.log("Running migrations...");
70
+ yield* run({ loader });
71
+ yield* Effect.log("Migrations ran successfully");
72
+});
73
74
/**
75
* Layer that runs migrations when the layer is built.
apps/server/src/persistence/Migrations/009_ProviderSessionRuntimeMode.ts
new
+17
@@ -0,0 +1,17 @@
1
+import * as SqlClient from "effect/unstable/sql/SqlClient";
2
+import * as Effect from "effect/Effect";
3
+
4
+export default Effect.gen(function* () {
5
+ const sql = yield* SqlClient.SqlClient;
6
+
7
+ yield* sql`
8
+ ALTER TABLE provider_session_runtime
9
+ ADD COLUMN runtime_mode TEXT NOT NULL DEFAULT 'full-access'
10
+ `;
11
+
12
+ yield* sql`
13
+ UPDATE provider_session_runtime
14
+ SET runtime_mode = 'full-access'
15
+ WHERE runtime_mode IS NULL
16
+ `;
17
+});
apps/server/src/persistence/Migrations/010_ProjectionThreadsRuntimeMode.ts
new
+17
@@ -0,0 +1,17 @@
1
+import * as Effect from "effect/Effect";
2
+import * as SqlClient from "effect/unstable/sql/SqlClient";
3
+
4
+export default Effect.gen(function* () {
5
+ const sql = yield* SqlClient.SqlClient;
6
+
7
+ yield* sql`
8
+ ALTER TABLE projection_threads
9
+ ADD COLUMN runtime_mode TEXT NOT NULL DEFAULT 'full-access'
10
+ `;
11
+
12
+ yield* sql`
13
+ UPDATE projection_threads
14
+ SET runtime_mode = 'full-access'
15
+ WHERE runtime_mode IS NULL
16
+ `;
17
+});
apps/server/src/persistence/Migrations/011_OrchestrationThreadCreatedRuntimeMode.ts
new
+13
@@ -0,0 +1,13 @@
1
+import * as Effect from "effect/Effect";
2
+import * as SqlClient from "effect/unstable/sql/SqlClient";
3
+
4
+export default Effect.gen(function* () {
5
+ const sql = yield* SqlClient.SqlClient;
6
+
7
+ yield* sql`
8
+ UPDATE orchestration_events
9
+ SET payload_json = json_set(payload_json, '$.runtimeMode', 'full-access')
10
+ WHERE event_type = 'thread.created'
11
+ AND json_type(payload_json, '$.runtimeMode') IS NULL
12
+ `;
13
+});
apps/server/src/persistence/Services/ProjectionThreads.ts
+2
-1
@@ -6,7 +6,7 @@
6
*
7
* @module ProjectionThreadRepository
8
*/
9
-import { IsoDateTime, ProjectId, ThreadId, TurnId } from "@t3tools/contracts";
9
+import { IsoDateTime, ProjectId, RuntimeMode, ThreadId, TurnId } from "@t3tools/contracts";
10
import { Option, Schema, ServiceMap } from "effect";
11
import type { Effect } from "effect";
12
@@ -17,6 +17,7 @@ export const ProjectionThread = Schema.Struct({
17
projectId: ProjectId,
18
title: Schema.String,
19
model: Schema.String,
20
+ runtimeMode: RuntimeMode,
21
branch: Schema.NullOr(Schema.String),
22
worktreePath: Schema.NullOr(Schema.String),
23
latestTurnId: Schema.NullOr(TurnId),
apps/server/src/persistence/Services/ProviderSessionRuntime.ts
+2
@@ -10,6 +10,7 @@ import {
10
ProviderSessionId,
11
ProviderSessionRuntimeStatus,
12
ProviderThreadId,
13
+ RuntimeMode,
14
ThreadId,
15
} from "@t3tools/contracts";
16
import { Option, Schema, ServiceMap } from "effect";
@@ -23,6 +24,7 @@ export const ProviderSessionRuntime = Schema.Struct({
24
providerName: Schema.String,
25
adapterKey: Schema.String,
26
providerThreadId: Schema.NullOr(ProviderThreadId),
27
+ runtimeMode: RuntimeMode,
28
status: ProviderSessionRuntimeStatus,
29
lastSeenAt: IsoDateTime,
30
resumeCursor: Schema.NullOr(Schema.Unknown),
apps/server/src/provider/Layers/ClaudeCodeAdapter.test.ts
+15
-2
@@ -166,7 +166,9 @@ describe("ClaudeCodeAdapterLive", () => {
166
const harness = makeHarness();
167
return Effect.gen(function* () {
168
const adapter = yield* ClaudeCodeAdapter;
169
- const result = yield* adapter.startSession({ provider: "codex" }).pipe(Effect.result);
169
+ const result = yield* adapter
170
+ .startSession({ provider: "codex", runtimeMode: "full-access" })
171
+ .pipe(Effect.result);
172
173
assert.equal(result._tag, "Failure");
174
if (result._tag !== "Failure") {
@@ -240,6 +242,7 @@ describe("ClaudeCodeAdapterLive", () => {
242
const session = yield* adapter.startSession({
243
provider: "claudeCode",
244
model: "claude-sonnet-4-5",
245
+ runtimeMode: "full-access",
246
});
247
248
const turn = yield* adapter.sendTurn({
@@ -374,6 +377,7 @@ describe("ClaudeCodeAdapterLive", () => {
377
378
const session = yield* adapter.startSession({
379
provider: "claudeCode",
380
+ runtimeMode: "full-access",
381
});
382
383
const turn = yield* adapter.sendTurn({
@@ -461,6 +465,7 @@ describe("ClaudeCodeAdapterLive", () => {
465
466
const session = yield* adapter.startSession({
467
provider: "claudeCode",
468
+ runtimeMode: "full-access",
469
});
470
471
const turn = yield* adapter.sendTurn({
@@ -529,6 +534,7 @@ describe("ClaudeCodeAdapterLive", () => {
534
535
const session = yield* adapter.startSession({
536
provider: "claudeCode",
537
+ runtimeMode: "full-access",
538
});
539
assert.equal(session.threadId, undefined);
540
@@ -679,6 +685,7 @@ describe("ClaudeCodeAdapterLive", () => {
685
resumeSessionAt: "assistant-99",
686
turnCount: 3,
687
},
688
+ runtimeMode: "full-access",
689
});
690
691
assert.equal(session.threadId, "resume-thread-1");
@@ -705,6 +712,7 @@ describe("ClaudeCodeAdapterLive", () => {
712
713
const session = yield* adapter.startSession({
714
provider: "claudeCode",
715
+ runtimeMode: "full-access",
716
});
717
718
assert.equal(
@@ -727,6 +735,7 @@ describe("ClaudeCodeAdapterLive", () => {
735
736
const session = yield* adapter.startSession({
737
provider: "claudeCode",
738
+ runtimeMode: "full-access",
739
});
740
741
const firstTurn = yield* adapter.sendTurn({
@@ -802,7 +811,10 @@ describe("ClaudeCodeAdapterLive", () => {
811
return Effect.gen(function* () {
812
const adapter = yield* ClaudeCodeAdapter;
813
805
- const session = yield* adapter.startSession({ provider: "claudeCode" });
814
+ const session = yield* adapter.startSession({
815
+ provider: "claudeCode",
816
+ runtimeMode: "full-access",
817
+ });
818
yield* adapter.sendTurn({
819
sessionId: session.sessionId,
820
input: "hello",
@@ -841,6 +853,7 @@ describe("ClaudeCodeAdapterLive", () => {
853
854
const session = yield* adapter.startSession({
855
provider: "claudeCode",
856
+ runtimeMode: "full-access",
857
});
858
const turn = yield* adapter.sendTurn({
859
sessionId: session.sessionId,
apps/server/src/provider/Layers/ClaudeCodeAdapter.ts
+1
@@ -1632,6 +1632,7 @@ function makeClaudeCodeAdapter(options?: ClaudeCodeAdapterLiveOptions) {
1632
sessionId,
1633
provider: PROVIDER,
1634
status: "ready",
1635
+ runtimeMode: input.runtimeMode,
1636
...(input.cwd ? { cwd: input.cwd } : {}),
1637
...(input.model ? { model: input.model } : {}),
1638
...(threadId ? { threadId } : {}),
apps/server/src/provider/Layers/CodexAdapter.test.ts
+2
@@ -40,6 +40,7 @@ class FakeCodexManager extends CodexAppServerManager {
40
sessionId: asSessionId("sess-1"),
41
provider: "codex",
42
status: "ready",
43
+ runtimeMode: input.runtimeMode,
44
threadId: ProviderThreadId.makeUnsafe("thread-1"),
45
cwd: input.cwd,
46
createdAt: now,
@@ -148,6 +149,7 @@ validationLayer("CodexAdapterLive validation", (it) => {
149
const result = yield* adapter
150
.startSession({
151
provider: "claudeCode",
152
+ runtimeMode: "full-access",
153
})
154
.pipe(Effect.result);
155
apps/server/src/provider/Layers/CursorAdapter.test.ts
+10
-1
@@ -255,7 +255,9 @@ describe("CursorAdapterLive", () => {
255
256
return Effect.gen(function* () {
257
const adapter = yield* CursorAdapter;
258
- const result = yield* adapter.startSession({ provider: "codex" }).pipe(Effect.result);
258
+ const result = yield* adapter
259
+ .startSession({ provider: "codex", runtimeMode: "full-access" })
260
+ .pipe(Effect.result);
261
262
assert.equal(result._tag, "Failure");
263
if (result._tag !== "Failure") {
@@ -289,6 +291,7 @@ describe("CursorAdapterLive", () => {
291
const session = yield* adapter.startSession({
292
provider: "cursor",
293
cwd: "/tmp/project",
294
+ runtimeMode: "full-access",
295
});
296
297
const turn = yield* adapter.sendTurn({
@@ -353,6 +356,7 @@ describe("CursorAdapterLive", () => {
356
yield* adapter.startSession({
357
provider: "cursor",
358
model: "composer-1.5",
359
+ runtimeMode: "full-access",
360
});
361
362
assert.deepEqual(createProcessInput?.model, "composer-1.5");
@@ -385,6 +389,7 @@ describe("CursorAdapterLive", () => {
389
const session = yield* adapter.startSession({
390
provider: "cursor",
391
cwd: "/tmp/project",
392
+ runtimeMode: "full-access",
393
});
394
395
assert.equal(nativeEvents.length > 0, true);
@@ -408,6 +413,7 @@ describe("CursorAdapterLive", () => {
413
resumeCursor: {
414
acpSessionId: "acp-session-resume",
415
},
416
+ runtimeMode: "full-access",
417
});
418
419
const methods = new Set(fake.requests.map((request) => request.method));
@@ -441,6 +447,7 @@ describe("CursorAdapterLive", () => {
447
resumeCursor: {
448
sessionId: "acp-session-legacy",
449
},
450
+ runtimeMode: "full-access",
451
});
452
453
const loadRequest = fake.requests.find((request) => request.method === "session/load");
@@ -555,6 +562,7 @@ describe("CursorAdapterLive", () => {
562
const adapter = yield* CursorAdapter;
563
const session = yield* adapter.startSession({
564
provider: "cursor",
565
+ runtimeMode: "full-access",
566
});
567
568
yield* Stream.take(adapter.streamEvents, 6).pipe(Stream.runDrain);
@@ -600,6 +608,7 @@ describe("CursorAdapterLive", () => {
608
609
const session = yield* adapter.startSession({
610
provider: "cursor",
611
+ runtimeMode: "full-access",
612
});
613
614
yield* adapter.sendTurn({
apps/server/src/provider/Layers/CursorAdapter.ts
+2
-1
@@ -1040,6 +1040,7 @@ function makeCursorAdapter(options?: CursorAdapterLiveOptions) {
1040
sessionId,
1041
provider: PROVIDER,
1042
status: "connecting",
1043
+ runtimeMode: input.runtimeMode,
1044
...(input.cwd ? { cwd: input.cwd } : {}),
1045
...(input.model ? { model: input.model } : {}),
1046
createdAt: startedAt,
@@ -1048,7 +1049,7 @@ function makeCursorAdapter(options?: CursorAdapterLiveOptions) {
1049
1050
const context: CursorSessionContext = {
1051
session,
1051
- runtimeMode: input.runtimeMode ?? "full-access",
1052
+ runtimeMode: input.runtimeMode,
1053
child,
1054
output,
1055
pending: new Map(),
apps/server/src/provider/Layers/ProviderService.test.ts
+14
@@ -80,6 +80,7 @@ function makeFakeCodexAdapter(provider: ProviderKind = "codex") {
80
sessionId: ProviderSessionId.makeUnsafe(`sess-${next}`),
81
provider,
82
status: "ready",
83
+ runtimeMode: input.runtimeMode,
84
threadId,
85
resumeCursor: input.resumeCursor ?? { opaque: `cursor-${next}` },
86
cwd: input.cwd ?? process.cwd(),
@@ -350,6 +351,7 @@ it.effect(
351
return yield* provider.startSession(asThreadId("thread-1"), {
352
provider: "codex",
353
cwd: "/tmp/project",
354
+ runtimeMode: "full-access",
355
});
356
}).pipe(Effect.provide(firstProviderLayer));
357
@@ -429,6 +431,7 @@ routing.layer("ProviderServiceLive routing", (it) => {
431
const session = yield* provider.startSession(asThreadId("thread-1"), {
432
provider: "codex",
433
cwd: "/tmp/project",
434
+ runtimeMode: "full-access",
435
});
436
assert.equal(session.provider, "codex");
437
@@ -481,6 +484,7 @@ routing.layer("ProviderServiceLive routing", (it) => {
484
const session = yield* provider.startSession(asThreadId("thread-claude"), {
485
provider: "claudeCode",
486
cwd: "/tmp/project-claude",
487
+ runtimeMode: "full-access",
488
});
489
490
assert.equal(session.provider, "claudeCode");
@@ -502,6 +506,7 @@ routing.layer("ProviderServiceLive routing", (it) => {
506
const initial = yield* provider.startSession(asThreadId("thread-1"), {
507
provider: "codex",
508
cwd: "/tmp/project",
509
+ runtimeMode: "full-access",
510
});
511
yield* routing.codex.stopSession(initial.sessionId);
512
routing.codex.startSession.mockClear();
@@ -540,6 +545,7 @@ routing.layer("ProviderServiceLive routing", (it) => {
545
const initial = yield* provider.startSession(asThreadId("thread-1"), {
546
provider: "codex",
547
cwd: "/tmp/project-send-turn",
548
+ runtimeMode: "full-access",
549
});
550
551
yield* provider.stopAll();
@@ -577,9 +583,11 @@ routing.layer("ProviderServiceLive routing", (it) => {
583
584
yield* provider.startSession(asThreadId("thread-1"), {
585
provider: "codex",
586
+ runtimeMode: "full-access",
587
});
588
yield* provider.startSession(asThreadId("thread-2"), {
589
provider: "codex",
590
+ runtimeMode: "full-access",
591
});
592
593
yield* provider.stopAll();
@@ -596,6 +604,7 @@ routing.layer("ProviderServiceLive routing", (it) => {
604
605
const session = yield* provider.startSession(asThreadId("thread-1"), {
606
provider: "codex",
607
+ runtimeMode: "full-access",
608
});
609
yield* provider.sendTurn({
610
sessionId: session.sessionId,
@@ -647,6 +656,7 @@ fanout.layer("ProviderServiceLive fanout", (it) => {
656
const provider = yield* ProviderService;
657
const session = yield* provider.startSession(asThreadId("thread-1"), {
658
provider: "codex",
659
+ runtimeMode: "full-access",
660
});
661
662
const eventsRef = yield* Ref.make<Array<ProviderRuntimeEvent>>([]);
@@ -684,6 +694,7 @@ fanout.layer("ProviderServiceLive fanout", (it) => {
694
const provider = yield* ProviderService;
695
const session = yield* provider.startSession(asThreadId("thread-seq"), {
696
provider: "codex",
697
+ runtimeMode: "full-access",
698
});
699
700
const receivedRef = yield* Ref.make<Array<ProviderRuntimeEvent>>([]);
@@ -740,6 +751,7 @@ fanout.layer("ProviderServiceLive fanout", (it) => {
751
const provider = yield* ProviderService;
752
const session = yield* provider.startSession(asThreadId("thread-1"), {
753
provider: "codex",
754
+ runtimeMode: "full-access",
755
});
756
757
const receivedByHealthy: string[] = [];
@@ -845,6 +857,7 @@ validation.layer("ProviderServiceLive validation", (it) => {
857
sessionId: asSessionId("sess-missing-thread"),
858
provider: "codex",
859
status: "ready",
860
+ runtimeMode: input.runtimeMode,
861
cwd: input.cwd ?? process.cwd(),
862
createdAt: now,
863
updatedAt: now,
@@ -855,6 +868,7 @@ validation.layer("ProviderServiceLive validation", (it) => {
868
const session = yield* provider.startSession(asThreadId("thread-missing"), {
869
provider: "codex",
870
cwd: "/tmp/project",
871
+ runtimeMode: "full-access",
872
});
873
874
assert.equal(session.sessionId, asSessionId("sess-missing-thread"));
apps/server/src/provider/Layers/ProviderService.ts
+2
-1
@@ -180,6 +180,7 @@ const makeProviderService = (options?: ProviderServiceLiveOptions) =>
180
provider: session.provider,
181
threadId,
182
...(providerThreadId !== undefined ? { providerThreadId } : {}),
183
+ runtimeMode: session.runtimeMode,
184
status: toRuntimeStatus(session),
185
...(session.resumeCursor !== undefined ? { resumeCursor: session.resumeCursor } : {}),
186
runtimePayload: toRuntimePayloadFromSession(session),
@@ -296,6 +297,7 @@ const makeProviderService = (options?: ProviderServiceLiveOptions) =>
297
...(persistedCwd ? { cwd: persistedCwd } : {}),
298
...(resumeThreadId ? { resumeThreadId } : {}),
299
...(hasResumeCursor ? { resumeCursor: input.binding.resumeCursor } : {}),
300
+ runtimeMode: input.binding.runtimeMode ?? "full-access",
301
});
302
if (resumed.provider !== adapter.provider) {
303
return yield* toValidationError(
@@ -415,7 +417,6 @@ const makeProviderService = (options?: ProviderServiceLiveOptions) =>
417
const input = {
418
...parsed,
419
provider: parsed.provider ?? "codex",
418
- runtimeMode: parsed.runtimeMode ?? "full-access",
420
};
421
const adapter = yield* registry.getByProvider(input.provider);
422
const session = yield* adapter.startSession(input);
apps/server/src/provider/Layers/ProviderSessionDirectory.ts
+2
@@ -75,6 +75,7 @@ const makeProviderSessionDirectory = Effect.gen(function* () {
75
threadId: value.threadId,
76
adapterKey: value.adapterKey,
77
providerThreadId: value.providerThreadId,
78
+ runtimeMode: value.runtimeMode,
79
status: value.status,
80
resumeCursor: value.resumeCursor,
81
runtimePayload: value.runtimePayload,
@@ -112,6 +113,7 @@ const makeProviderSessionDirectory = Effect.gen(function* () {
113
binding.providerThreadId !== undefined
114
? binding.providerThreadId
115
: (existingRuntime?.providerThreadId ?? null),
116
+ runtimeMode: binding.runtimeMode ?? existingRuntime?.runtimeMode ?? "full-access",
117
status: binding.status ?? existingRuntime?.status ?? "running",
118
lastSeenAt: now,
119
resumeCursor:
apps/server/src/provider/Services/ProviderSessionDirectory.ts
+2
@@ -12,6 +12,7 @@ import type {
12
ProviderSessionId,
13
ProviderSessionRuntimeStatus,
14
ProviderThreadId,
15
+ RuntimeMode,
16
ThreadId,
17
} from "@t3tools/contracts";
18
import { Option, ServiceMap } from "effect";
@@ -32,6 +33,7 @@ export interface ProviderSessionBinding {
33
readonly status?: ProviderSessionRuntimeStatus;
34
readonly resumeCursor?: unknown | null;
35
readonly runtimePayload?: unknown | null;
36
+ readonly runtimeMode?: RuntimeMode;
37
}
38
39
export type ProviderSessionDirectoryReadError =
apps/server/src/wsServer.test.ts
+1
@@ -1157,6 +1157,7 @@ describe("WebSocket Server", () => {
1157
sessionId,
1158
provider: "codex",
1159
status: "ready",
1160
+ runtimeMode: "full-access",
1161
threadId: asProviderThreadId("provider-thread-1"),
1162
createdAt: new Date().toISOString(),
1163
updatedAt: new Date().toISOString(),
apps/server/src/wsServer.ts
+1
@@ -595,6 +595,7 @@ export const createServer = Effect.fn(function* (): Effect.fn.Return<
595
projectId: bootstrapProjectId,
596
title: "New thread",
597
model: bootstrapProjectDefaultModel,
598
+ runtimeMode: "full-access",
599
branch: null,
600
worktreePath: null,
601
createdAt,
apps/web/src/components/ChatView.tsx
+43
-33
@@ -31,7 +31,17 @@ import {
31
resolveModelSlugForProvider,
32
OrchestrationThreadActivity,
33
} from "@t3tools/contracts";
34
-import { memo, useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
34
+import {
35
+ memo,
36
+ useCallback,
37
+ useEffect,
38
+ useLayoutEffect,
39
+ useMemo,
40
+ useOptimistic,
41
+ useRef,
42
+ useState,
43
+ useTransition,
44
+} from "react";
45
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
46
import { useDebouncedValue } from "@tanstack/react-pacer";
47
import { useNavigate, useSearch } from "@tanstack/react-router";
@@ -69,6 +79,7 @@ import { AUTO_SCROLL_BOTTOM_THRESHOLD_PX, isScrollContainerNearBottom } from "..
79
import { useStore } from "../store";
80
import { truncateTitle } from "../truncateTitle";
81
import {
82
+ DEFAULT_RUNTIME_MODE,
83
DEFAULT_THREAD_TERMINAL_ID,
84
MAX_THREAD_TERMINAL_COUNT,
85
type ChatMessage,
@@ -267,6 +278,7 @@ function buildLocalDraftThread(
278
projectId: draftThread.projectId,
279
title: "New thread",
280
model: fallbackModel,
281
+ runtimeMode: draftThread.runtimeMode,
282
session: null,
283
messages: [],
284
error,
@@ -500,10 +512,8 @@ interface ChatViewProps {
512
export default function ChatView({ threadId }: ChatViewProps) {
513
const threads = useStore((store) => store.threads);
514
const projects = useStore((store) => store.projects);
503
- const runtimeMode = useStore((store) => store.runtimeMode);
515
const markThreadVisited = useStore((store) => store.markThreadVisited);
516
const setStoreThreadError = useStore((store) => store.setError);
506
- const setStoreRuntimeMode = useStore((store) => store.setRuntimeMode);
517
const setStoreThreadBranch = useStore((store) => store.setThreadBranch);
518
const { settings } = useAppSettings();
519
const navigate = useNavigate();
@@ -549,7 +559,6 @@ export default function ChatView({ threadId }: ChatViewProps) {
559
const [sendPhase, setSendPhase] = useState<SendPhase>("idle");
560
const [isConnecting, _setIsConnecting] = useState(false);
561
const [isRevertingCheckpoint, setIsRevertingCheckpoint] = useState(false);
552
- const [isSwitchingRuntimeMode, setIsSwitchingRuntimeMode] = useState(false);
562
const [respondingRequestIds, setRespondingRequestIds] = useState<ApprovalRequestId[]>([]);
563
const [expandedWorkGroups, setExpandedWorkGroups] = useState<Record<string, boolean>>({});
564
const [nowTick, setNowTick] = useState(() => Date.now());
@@ -642,6 +651,9 @@ export default function ChatView({ threadId }: ChatViewProps) {
651
[draftThread, fallbackDraftProject?.model, localDraftError, threadId],
652
);
653
const activeThread = serverThread ?? localDraftThread;
654
+ const runtimeMode = activeThread?.runtimeMode ?? DEFAULT_RUNTIME_MODE;
655
+ const [optimisticRuntimeMode, setOptimisticRuntimeMode] = useOptimistic(runtimeMode);
656
+ const [isRuntimeModePending, startRuntimeModeTransition] = useTransition();
657
const isServerThread = serverThread !== undefined;
658
const isLocalDraftThread = !isServerThread && localDraftThread !== undefined;
659
const diffSearch = useMemo(
@@ -1410,31 +1422,26 @@ export default function ChatView({ threadId }: ChatViewProps) {
1422
1423
const handleRuntimeModeChange = async (mode: "approval-required" | "full-access") => {
1424
if (mode === runtimeMode) return;
1413
- setStoreRuntimeMode(mode);
1414
- scheduleComposerFocus();
1425
+ if (isLocalDraftThread) {
1426
+ setDraftThreadContext(threadId, { runtimeMode: mode });
1427
+ scheduleComposerFocus();
1428
+ return;
1429
+ }
1430
const api = readNativeApi();
1416
- if (!api) return;
1417
-
1418
- const runningThreadIds = threads
1419
- .filter((thread) => thread.session !== null && thread.session.status !== "closed")
1420
- .map((thread) => thread.id);
1421
-
1422
- if (runningThreadIds.length === 0) return;
1423
-
1424
- setIsSwitchingRuntimeMode(true);
1425
- await Promise.all(
1426
- runningThreadIds.map((threadId) =>
1427
- api.orchestration
1428
- .dispatchCommand({
1429
- type: "thread.session.stop",
1430
- commandId: newCommandId(),
1431
- threadId,
1432
- createdAt: new Date().toISOString(),
1433
- })
1434
- .catch(() => undefined),
1435
- ),
1436
- );
1437
- setIsSwitchingRuntimeMode(false);
1431
+ if (!api || !isServerThread) return;
1432
+ scheduleComposerFocus();
1433
+ startRuntimeModeTransition(() => {
1434
+ setOptimisticRuntimeMode(mode);
1435
+ void api.orchestration
1436
+ .dispatchCommand({
1437
+ type: "thread.runtime-mode.set",
1438
+ commandId: newCommandId(),
1439
+ threadId,
1440
+ runtimeMode: mode,
1441
+ createdAt: new Date().toISOString(),
1442
+ })
1443
+ .catch(() => undefined);
1444
+ });
1445
};
1446
1447
useEffect(() => {
@@ -2186,6 +2193,7 @@ export default function ChatView({ threadId }: ChatViewProps) {
2193
projectId: activeProject.id,
2194
title,
2195
model: threadCreateModel,
2196
+ runtimeMode,
2197
branch: nextThreadBranch,
2198
worktreePath: nextThreadWorktreePath,
2199
createdAt: activeThread.createdAt,
@@ -2941,21 +2949,23 @@ export default function ChatView({ threadId }: ChatViewProps) {
2949
className="shrink-0 whitespace-nowrap px-2 text-muted-foreground/70 hover:text-foreground/80 sm:px-3"
2950
size="sm"
2951
type="button"
2944
- disabled={isSwitchingRuntimeMode}
2952
+ disabled={isRuntimeModePending}
2953
onClick={() =>
2954
void handleRuntimeModeChange(
2947
- runtimeMode === "full-access" ? "approval-required" : "full-access",
2955
+ optimisticRuntimeMode === "full-access"
2956
+ ? "approval-required"
2957
+ : "full-access",
2958
)
2959
}
2960
title={
2951
- runtimeMode === "full-access"
2961
+ optimisticRuntimeMode === "full-access"
2962
? "Full access — click to require approvals"
2963
: "Approval required — click for full access"
2964
}
2965
>
2956
- {runtimeMode === "full-access" ? <LockOpenIcon /> : <LockIcon />}
2966
+ {optimisticRuntimeMode === "full-access" ? <LockOpenIcon /> : <LockIcon />}
2967
<span className="sr-only sm:not-sr-only">
2958
- {runtimeMode === "full-access" ? "Full access" : "Supervised"}
2968
+ {optimisticRuntimeMode === "full-access" ? "Full access" : "Supervised"}
2969
</span>
2970
</Button>
2971
</div>
apps/web/src/components/Sidebar.tsx
+2
@@ -8,6 +8,7 @@ import {
8
} from "lucide-react";
9
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
10
import {
11
+ DEFAULT_RUNTIME_MODE,
12
DEFAULT_MODEL,
13
type DesktopUpdateState,
14
ProjectId,
@@ -435,6 +436,7 @@ export default function Sidebar() {
436
branch: options?.branch ?? null,
437
worktreePath: options?.worktreePath ?? null,
438
envMode: options?.envMode ?? "local",
439
+ runtimeMode: DEFAULT_RUNTIME_MODE,
440
});
441
442
await navigate({
apps/web/src/composerDraftStore.ts
+16
-1
@@ -6,8 +6,9 @@ import {
6
normalizeModelSlug,
7
type CodexReasoningEffort,
8
type ProviderKind,
9
+ type RuntimeMode,
10
} from "@t3tools/contracts";
10
-import type { ChatImageAttachment } from "./types";
11
+import { DEFAULT_RUNTIME_MODE, type ChatImageAttachment } from "./types";
12
import { create } from "zustand";
13
import { createJSONStorage, persist } from "zustand/middleware";
14
@@ -38,6 +39,7 @@ interface PersistedComposerThreadDraftState {
39
interface PersistedDraftThreadState {
40
projectId: ProjectId;
41
createdAt: string;
42
+ runtimeMode: RuntimeMode;
43
branch: string | null;
44
worktreePath: string | null;
45
envMode: DraftThreadEnvMode;
@@ -62,6 +64,7 @@ interface ComposerThreadDraftState {
64
export interface DraftThreadState {
65
projectId: ProjectId;
66
createdAt: string;
67
+ runtimeMode: RuntimeMode;
68
branch: string | null;
69
worktreePath: string | null;
70
envMode: DraftThreadEnvMode;
@@ -85,6 +88,7 @@ interface ComposerDraftStoreState {
88
worktreePath?: string | null;
89
createdAt?: string;
90
envMode?: DraftThreadEnvMode;
91
+ runtimeMode?: RuntimeMode;
92
},
93
) => void;
94
setDraftThreadContext: (
@@ -95,6 +99,7 @@ interface ComposerDraftStoreState {
99
projectId?: ProjectId;
100
createdAt?: string;
101
envMode?: DraftThreadEnvMode;
102
+ runtimeMode?: RuntimeMode;
103
},
104
) => void;
105
clearProjectDraftThreadId: (projectId: ProjectId) => void;
@@ -260,6 +265,11 @@ function normalizePersistedComposerDraftState(value: unknown): PersistedComposer
265
typeof createdAt === "string" && createdAt.length > 0
266
? createdAt
267
: new Date().toISOString(),
268
+ runtimeMode:
269
+ candidateDraftThread.runtimeMode === "approval-required" ||
270
+ candidateDraftThread.runtimeMode === "full-access"
271
+ ? candidateDraftThread.runtimeMode
272
+ : DEFAULT_RUNTIME_MODE,
273
branch: typeof branch === "string" ? branch : null,
274
worktreePath: normalizedWorktreePath,
275
envMode: normalizeDraftThreadEnvMode(candidateDraftThread.envMode, normalizedWorktreePath),
@@ -286,6 +296,7 @@ function normalizePersistedComposerDraftState(value: unknown): PersistedComposer
296
draftThreadsByThreadId[threadId as ThreadId] = {
297
projectId: projectId as ProjectId,
298
createdAt: new Date().toISOString(),
299
+ runtimeMode: DEFAULT_RUNTIME_MODE,
300
branch: null,
301
worktreePath: null,
302
envMode: "local",
@@ -488,6 +499,7 @@ export const useComposerDraftStore = create<ComposerDraftStoreState>()(
499
const nextDraftThread: DraftThreadState = {
500
projectId,
501
createdAt: options?.createdAt ?? existingThread?.createdAt ?? new Date().toISOString(),
502
+ runtimeMode: options?.runtimeMode ?? existingThread?.runtimeMode ?? DEFAULT_RUNTIME_MODE,
503
branch:
504
options?.branch === undefined
505
? (existingThread?.branch ?? null)
@@ -502,6 +514,7 @@ export const useComposerDraftStore = create<ComposerDraftStoreState>()(
514
existingThread &&
515
existingThread.projectId === nextDraftThread.projectId &&
516
existingThread.createdAt === nextDraftThread.createdAt &&
517
+ existingThread.runtimeMode === nextDraftThread.runtimeMode &&
518
existingThread.branch === nextDraftThread.branch &&
519
existingThread.worktreePath === nextDraftThread.worktreePath &&
520
existingThread.envMode === nextDraftThread.envMode;
@@ -556,6 +569,7 @@ export const useComposerDraftStore = create<ComposerDraftStoreState>()(
569
options.createdAt === undefined
570
? existing.createdAt
571
: options.createdAt || existing.createdAt,
572
+ runtimeMode: options.runtimeMode ?? existing.runtimeMode,
573
branch: options.branch === undefined ? existing.branch : (options.branch ?? null),
574
worktreePath: nextWorktreePath,
575
envMode:
@@ -565,6 +579,7 @@ export const useComposerDraftStore = create<ComposerDraftStoreState>()(
579
const isUnchanged =
580
nextDraftThread.projectId === existing.projectId &&
581
nextDraftThread.createdAt === existing.createdAt &&
582
+ nextDraftThread.runtimeMode === existing.runtimeMode &&
583
nextDraftThread.branch === existing.branch &&
584
nextDraftThread.worktreePath === existing.worktreePath &&
585
nextDraftThread.envMode === existing.envMode;
apps/web/src/routes/_chat.settings.tsx
-57
@@ -8,7 +8,6 @@ import { isElectron } from "../env";
8
import { useTheme } from "../hooks/useTheme";
9
import { serverConfigQueryOptions } from "../lib/serverReactQuery";
10
import { ensureNativeApi } from "../nativeApi";
11
-import { useStore } from "../store";
11
import { preferredTerminalEditor } from "../terminal-links";
12
import { Button } from "../components/ui/button";
13
import { Input } from "../components/ui/input";
@@ -33,19 +32,6 @@ const THEME_OPTIONS = [
32
},
33
] as const;
34
36
-const RUNTIME_MODE_OPTIONS = [
37
- {
38
- value: "full-access",
39
- label: "Full access",
40
- description: "Allow commands to run without confirmation prompts.",
41
- },
42
- {
43
- value: "approval-required",
44
- label: "Supervised",
45
- description: "Require approval prompts before command execution.",
46
- },
47
-] as const;
48
-
35
const MODEL_PROVIDER_SETTINGS: Array<{
36
provider: ProviderKind;
37
title: string;
@@ -120,8 +106,6 @@ function patchCustomModels(provider: ProviderKind, models: string[]) {
106
107
function SettingsRouteView() {
108
const { theme, setTheme, resolvedTheme } = useTheme();
123
- const runtimeMode = useStore((store) => store.runtimeMode);
124
- const setRuntimeMode = useStore((store) => store.setRuntimeMode);
109
const { settings, defaults, updateSettings } = useAppSettings();
110
const serverConfigQuery = useQuery(serverConfigQueryOptions());
111
const [isOpeningKeybindings, setIsOpeningKeybindings] = useState(false);
@@ -469,47 +453,6 @@ function SettingsRouteView() {
453
</div>
454
</section>
455
472
- <section className="rounded-2xl border border-border bg-card p-5">
473
- <div className="mb-4">
474
- <h2 className="text-sm font-medium text-foreground">Runtime Mode</h2>
475
- <p className="mt-1 text-xs text-muted-foreground">
476
- Select the default execution policy for this client.
477
- </p>
478
- </div>
479
-
480
- <div className="space-y-2" role="radiogroup" aria-label="Runtime mode preference">
481
- {RUNTIME_MODE_OPTIONS.map((option) => {
482
- const selected = runtimeMode === option.value;
483
- return (
484
- <button
485
- key={option.value}
486
- type="button"
487
- role="radio"
488
- aria-checked={selected}
489
- className={`flex w-full items-start justify-between rounded-lg border px-3 py-2 text-left transition-colors ${
490
- selected
491
- ? "border-primary/60 bg-primary/8 text-foreground"
492
- : "border-border bg-background text-muted-foreground hover:bg-accent"
493
- }`}
494
- onClick={() => {
495
- setRuntimeMode(option.value);
496
- }}
497
- >
498
- <span className="flex flex-col">
499
- <span className="text-sm font-medium">{option.label}</span>
500
- <span className="text-xs">{option.description}</span>
501
- </span>
502
- {selected ? (
503
- <span className="rounded bg-primary/14 px-1.5 py-0.5 text-[10px] font-medium uppercase tracking-wide text-primary">
504
- Selected
505
- </span>
506
- ) : null}
507
- </button>
508
- );
509
- })}
510
- </div>
511
- </section>
512
-
456
<section className="rounded-2xl border border-border bg-card p-5">
457
<div className="mb-4">
458
<h2 className="text-sm font-medium text-foreground">Responses</h2>
apps/web/src/store.test.ts
+3
-2
@@ -2,7 +2,7 @@ import { ProjectId, ThreadId, TurnId, type OrchestrationReadModel } from "@t3too
2
import { describe, expect, it } from "vitest";
3
4
import { markThreadUnread, syncServerReadModel, type AppState } from "./store";
5
-import type { Thread } from "./types";
5
+import { DEFAULT_RUNTIME_MODE, type Thread } from "./types";
6
7
function makeThread(overrides: Partial<Thread> = {}): Thread {
8
return {
@@ -11,6 +11,7 @@ function makeThread(overrides: Partial<Thread> = {}): Thread {
11
projectId: ProjectId.makeUnsafe("project-1"),
12
title: "Thread",
13
model: "gpt-5-codex",
14
+ runtimeMode: DEFAULT_RUNTIME_MODE,
15
session: null,
16
messages: [],
17
turnDiffSummaries: [],
@@ -38,7 +39,6 @@ function makeState(thread: Thread): AppState {
39
],
40
threads: [thread],
41
threadsHydrated: true,
41
- runtimeMode: "full-access",
42
};
43
}
44
@@ -48,6 +48,7 @@ function makeReadModelThread(overrides: Partial<OrchestrationReadModel["threads"
48
projectId: ProjectId.makeUnsafe("project-1"),
49
title: "Thread",
50
model: "gpt-5.3-codex",
51
+ runtimeMode: DEFAULT_RUNTIME_MODE,
52
branch: null,
53
worktreePath: null,
54
latestTurn: null,
apps/web/src/store.ts
+11
-32
@@ -13,10 +13,8 @@ import {
13
} from "@t3tools/contracts";
14
import { create } from "zustand";
15
import {
16
- DEFAULT_RUNTIME_MODE,
16
type ChatMessage,
17
type Project,
19
- type RuntimeMode,
18
type Thread,
19
} from "./types";
20
@@ -26,10 +24,9 @@ export interface AppState {
24
projects: Project[];
25
threads: Thread[];
26
threadsHydrated: boolean;
29
- runtimeMode: RuntimeMode;
27
}
28
32
-const PERSISTED_STATE_KEY = "t3code:renderer-state:v7";
29
+const PERSISTED_STATE_KEY = "t3code:renderer-state:v8";
30
const LEGACY_PERSISTED_STATE_KEYS = [
31
"t3code:renderer-state:v6",
32
"t3code:renderer-state:v5",
@@ -45,7 +42,6 @@ const initialState: AppState = {
42
projects: [],
43
threads: [],
44
threadsHydrated: false,
48
- runtimeMode: DEFAULT_RUNTIME_MODE,
45
};
46
const persistedExpandedProjectCwds = new Set<string>();
47
@@ -56,23 +52,14 @@ function readPersistedState(): AppState {
52
try {
53
const raw = window.localStorage.getItem(PERSISTED_STATE_KEY);
54
if (!raw) return initialState;
59
- const parsed = JSON.parse(raw) as {
60
- runtimeMode?: RuntimeMode;
61
- expandedProjectCwds?: string[];
62
- };
55
+ const parsed = JSON.parse(raw) as { expandedProjectCwds?: string[] };
56
persistedExpandedProjectCwds.clear();
57
for (const cwd of parsed.expandedProjectCwds ?? []) {
58
if (typeof cwd === "string" && cwd.length > 0) {
59
persistedExpandedProjectCwds.add(cwd);
60
}
61
}
69
- return {
70
- ...initialState,
71
- runtimeMode:
72
- parsed.runtimeMode === "approval-required" || parsed.runtimeMode === "full-access"
73
- ? parsed.runtimeMode
74
- : DEFAULT_RUNTIME_MODE,
75
- };
62
+ return { ...initialState };
63
} catch {
64
return initialState;
65
}
@@ -84,7 +71,6 @@ function persistState(state: AppState): void {
71
window.localStorage.setItem(
72
PERSISTED_STATE_KEY,
73
JSON.stringify({
87
- runtimeMode: state.runtimeMode,
74
expandedProjectCwds: state.projects
75
.filter((project) => project.expanded)
76
.map((project) => project.cwd),
@@ -265,12 +251,13 @@ export function syncServerReadModel(
251
projectId: thread.projectId,
252
title: thread.title,
253
model: resolveModelSlugForProvider(
268
- inferProviderForThreadModel({
269
- model: thread.model,
270
- sessionProviderName: thread.session?.providerName ?? null,
271
- }),
272
- thread.model,
273
- ),
254
+ inferProviderForThreadModel({
255
+ model: thread.model,
256
+ sessionProviderName: thread.session?.providerName ?? null,
257
+ }),
258
+ thread.model,
259
+ ),
260
+ runtimeMode: thread.runtimeMode,
261
session: thread.session
262
? {
263
sessionId:
@@ -415,11 +402,6 @@ export function setThreadBranch(
402
return threads === state.threads ? state : { ...state, threads };
403
}
404
418
-export function setRuntimeMode(state: AppState, mode: RuntimeMode): AppState {
419
- if (state.runtimeMode === mode) return state;
420
- return { ...state, runtimeMode: mode };
421
-}
422
-
405
// ── Zustand store ────────────────────────────────────────────────────
406
407
interface AppStore extends AppState {
@@ -434,7 +416,6 @@ interface AppStore extends AppState {
416
branch: string | null,
417
worktreePath: string | null,
418
) => void;
437
- setRuntimeMode: (mode: RuntimeMode) => void;
419
}
420
421
export const useStore = create<AppStore>((set) => ({
@@ -453,11 +434,9 @@ export const useStore = create<AppStore>((set) => ({
434
set((state) => setError(state, threadId, error)),
435
setThreadBranch: (threadId, branch, worktreePath) =>
436
set((state) => setThreadBranch(state, threadId, branch, worktreePath)),
456
- setRuntimeMode: (mode) =>
457
- set((state) => setRuntimeMode(state, mode)),
437
}));
438
460
-// Persist on every state change (only runtimeMode + expandedProjectCwds)
439
+// Persist on every state change
440
useStore.subscribe((state) => persistState(state));
441
442
export function StoreProvider({ children }: { children: ReactNode }) {
apps/web/src/types.ts
+1
@@ -79,6 +79,7 @@ export interface Thread {
79
projectId: ProjectId;
80
title: string;
81
model: string;
82
+ runtimeMode: RuntimeMode;
83
session: ThreadSession | null;
84
messages: ChatMessage[];
85
error: string | null;
apps/web/src/worktreeCleanup.test.ts
+2
-1
@@ -1,7 +1,7 @@
1
import { ProjectId, ThreadId } from "@t3tools/contracts";
2
import { describe, expect, it } from "vitest";
3
4
-import type { Thread } from "./types";
4
+import { DEFAULT_RUNTIME_MODE, type Thread } from "./types";
5
import { formatWorktreePathForDisplay, getOrphanedWorktreePathForThread } from "./worktreeCleanup";
6
7
function makeThread(overrides: Partial<Thread> = {}): Thread {
@@ -11,6 +11,7 @@ function makeThread(overrides: Partial<Thread> = {}): Thread {
11
projectId: ProjectId.makeUnsafe("project-1"),
12
title: "Thread",
13
model: "gpt-5.3-codex",
14
+ runtimeMode: DEFAULT_RUNTIME_MODE,
15
session: null,
16
messages: [],
17
turnDiffSummaries: [],
packages/contracts/src/orchestration.ts
+30
@@ -223,6 +223,7 @@ export const OrchestrationThread = Schema.Struct({
223
projectId: ProjectId,
224
title: TrimmedNonEmptyString,
225
model: TrimmedNonEmptyString,
226
+ runtimeMode: RuntimeMode,
227
branch: Schema.NullOr(TrimmedNonEmptyString),
228
worktreePath: Schema.NullOr(TrimmedNonEmptyString),
229
latestTurn: Schema.NullOr(OrchestrationLatestTurn),
@@ -277,6 +278,7 @@ export const ThreadCreateCommand = Schema.Struct({
278
projectId: ProjectId,
279
title: TrimmedNonEmptyString,
280
model: TrimmedNonEmptyString,
281
+ runtimeMode: RuntimeMode,
282
branch: Schema.NullOr(TrimmedNonEmptyString),
283
worktreePath: Schema.NullOr(TrimmedNonEmptyString),
284
createdAt: IsoDateTime,
@@ -298,6 +300,14 @@ export const ThreadMetaUpdateCommand = Schema.Struct({
300
worktreePath: Schema.optional(Schema.NullOr(TrimmedNonEmptyString)),
301
});
302
303
+export const ThreadRuntimeModeSetCommand = Schema.Struct({
304
+ type: Schema.Literal("thread.runtime-mode.set"),
305
+ commandId: CommandId,
306
+ threadId: ThreadId,
307
+ runtimeMode: RuntimeMode,
308
+ createdAt: IsoDateTime,
309
+});
310
+
311
export const ThreadTurnStartCommand = Schema.Struct({
312
type: Schema.Literal("thread.turn.start"),
313
commandId: CommandId,
@@ -373,6 +383,7 @@ export const DispatchableClientOrchestrationCommand = Schema.Union([
383
ThreadCreateCommand,
384
ThreadDeleteCommand,
385
ThreadMetaUpdateCommand,
386
+ ThreadRuntimeModeSetCommand,
387
ThreadTurnStartCommand,
388
ThreadTurnInterruptCommand,
389
ThreadApprovalRespondCommand,
@@ -389,6 +400,7 @@ export const ClientOrchestrationCommand = Schema.Union([
400
ThreadCreateCommand,
401
ThreadDeleteCommand,
402
ThreadMetaUpdateCommand,
403
+ ThreadRuntimeModeSetCommand,
404
ClientThreadTurnStartCommand,
405
ThreadTurnInterruptCommand,
406
ThreadApprovalRespondCommand,
@@ -477,6 +489,7 @@ export const OrchestrationEventType = Schema.Literals([
489
"thread.created",
490
"thread.deleted",
491
"thread.meta-updated",
492
+ "thread.runtime-mode-set",
493
"thread.message-sent",
494
"thread.turn-start-requested",
495
"thread.turn-interrupt-requested",
@@ -523,6 +536,7 @@ export const ThreadCreatedPayload = Schema.Struct({
536
projectId: ProjectId,
537
title: TrimmedNonEmptyString,
538
model: TrimmedNonEmptyString,
539
+ runtimeMode: RuntimeMode,
540
branch: Schema.NullOr(TrimmedNonEmptyString),
541
worktreePath: Schema.NullOr(TrimmedNonEmptyString),
542
createdAt: IsoDateTime,
@@ -543,6 +557,12 @@ export const ThreadMetaUpdatedPayload = Schema.Struct({
557
updatedAt: IsoDateTime,
558
});
559
560
+export const ThreadRuntimeModeSetPayload = Schema.Struct({
561
+ threadId: ThreadId,
562
+ runtimeMode: RuntimeMode,
563
+ updatedAt: IsoDateTime,
564
+});
565
+
566
export const ThreadMessageSentPayload = Schema.Struct({
567
threadId: ThreadId,
568
messageId: MessageId,
@@ -684,6 +704,11 @@ export const OrchestrationEvent = Schema.Union([
704
type: Schema.Literal("thread.meta-updated"),
705
payload: ThreadMetaUpdatedPayload,
706
}),
707
+ Schema.Struct({
708
+ ...EventBaseFields,
709
+ type: Schema.Literal("thread.runtime-mode-set"),
710
+ payload: ThreadRuntimeModeSetPayload,
711
+ }),
712
Schema.Struct({
713
...EventBaseFields,
714
type: Schema.Literal("thread.message-sent"),
@@ -768,6 +793,11 @@ export const OrchestrationPersistedEvent = Schema.Union([
793
eventType: Schema.Literal("thread.meta-updated"),
794
payload: ThreadMetaUpdatedPayload,
795
}),
796
+ Schema.Struct({
797
+ ...PersistedEventBaseFields,
798
+ eventType: Schema.Literal("thread.runtime-mode-set"),
799
+ payload: ThreadRuntimeModeSetPayload,
800
+ }),
801
Schema.Struct({
802
...PersistedEventBaseFields,
803
eventType: Schema.Literal("thread.message-sent"),
packages/contracts/src/provider.test.ts
+10
-1
@@ -11,6 +11,7 @@ describe("ProviderSessionStartInput", () => {
11
provider: "codex",
12
cwd: "/tmp/workspace",
13
model: "gpt-5.3-codex",
14
+ runtimeMode: "full-access",
15
providerOptions: {
16
codex: {
17
binaryPath: "/usr/local/bin/codex",
@@ -18,11 +19,19 @@ describe("ProviderSessionStartInput", () => {
19
},
20
},
21
});
21
- expect(parsed.runtimeMode).toBeUndefined();
22
+ expect(parsed.runtimeMode).toBe("full-access");
23
expect(parsed.providerOptions?.codex?.binaryPath).toBe("/usr/local/bin/codex");
24
expect(parsed.providerOptions?.codex?.homePath).toBe("/tmp/.codex");
25
});
26
27
+ it("rejects payloads without runtime mode", () => {
28
+ expect(() =>
29
+ decodeProviderSessionStartInput({
30
+ provider: "codex",
31
+ }),
32
+ ).toThrow();
33
+ });
34
+
35
it("accepts claude runtime knobs", () => {
36
const parsed = decodeProviderSessionStartInput({
37
provider: "claudeCode",
packages/contracts/src/provider.ts
+2
-1
@@ -37,6 +37,7 @@ export const ProviderSession = Schema.Struct({
37
sessionId: ProviderSessionId,
38
provider: ProviderKind,
39
status: ProviderSessionStatus,
40
+ runtimeMode: RuntimeMode,
41
cwd: Schema.optional(TrimmedNonEmptyStringSchema),
42
model: Schema.optional(TrimmedNonEmptyStringSchema),
43
threadId: Schema.optional(ProviderThreadId),
@@ -79,7 +80,7 @@ export const ProviderSessionStartInput = Schema.Struct({
80
model: Schema.optional(TrimmedNonEmptyStringSchema),
81
resumeCursor: Schema.optional(Schema.Unknown),
82
providerOptions: Schema.optional(ProviderStartOptions),
82
- runtimeMode: Schema.optional(RuntimeMode),
83
+ runtimeMode: RuntimeMode,
84
});
85
export type ProviderSessionStartInput = typeof ProviderSessionStartInput.Type;
86