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, 16:00 UTC
Reuse persisted cwd when recovering stale provider sessions
- Read and validate `cwd` from persisted runtime payload when restarting sessions - Apply persisted `cwd` during stale-session recovery paths, including `sendTurn` - Add tests to verify resumed sessions preserve the original working directory
Julius Marminge committed
Feb 27, 2026 at 20:58 UTC
2aad749e2474f79a532764c9f6f7ce4abc3a68f0
2 files changed
+49
apps/server/src/provider/Layers/ProviderService.test.ts
+34
@@ -378,6 +378,7 @@ it.effect(
378
[
379
{
380
provider: "codex",
381
+ cwd: "/tmp/project",
382
resumeThreadId: startedSession.threadId,
383
},
384
],
@@ -465,6 +466,7 @@ routing.layer("ProviderServiceLive routing", (it) => {
466
[
467
{
468
provider: "codex",
469
+ cwd: "/tmp/project",
470
resumeThreadId: initial.threadId,
471
},
472
],
@@ -475,6 +477,38 @@ routing.layer("ProviderServiceLive routing", (it) => {
477
}),
478
);
479
480
+ it.effect("recovers stale sessions for sendTurn using persisted cwd", () =>
481
+ Effect.gen(function* () {
482
+ const provider = yield* ProviderService;
483
+
484
+ const initial = yield* provider.startSession(asThreadId("thread-1"), {
485
+ provider: "codex",
486
+ cwd: "/tmp/project-send-turn",
487
+ });
488
+
489
+ yield* provider.stopAll();
490
+ routing.codex.startSession.mockClear();
491
+ routing.codex.sendTurn.mockClear();
492
+
493
+ yield* provider.sendTurn({
494
+ sessionId: initial.sessionId,
495
+ input: "resume",
496
+ attachments: [],
497
+ });
498
+
499
+ assert.deepEqual(routing.codex.startSession.mock.calls, [
500
+ [
501
+ {
502
+ provider: "codex",
503
+ cwd: "/tmp/project-send-turn",
504
+ resumeThreadId: initial.threadId,
505
+ },
506
+ ],
507
+ ]);
508
+ assert.equal(routing.codex.sendTurn.mock.calls.length, 1);
509
+ }),
510
+ );
511
+
512
it.effect("stops all sessions and clears adapter runtime", () =>
513
Effect.gen(function* () {
514
const provider = yield* ProviderService;
apps/server/src/provider/Layers/ProviderService.ts
+15
@@ -93,6 +93,18 @@ function toRuntimePayloadFromSession(session: ProviderSession): Record<string, u
93
};
94
}
95
96
+function readPersistedCwd(runtimePayload: ProviderSessionBinding["runtimePayload"]): string | undefined {
97
+ if (!runtimePayload || typeof runtimePayload !== "object" || Array.isArray(runtimePayload)) {
98
+ return undefined;
99
+ }
100
+ const rawCwd = runtimePayload.cwd;
101
+ if (typeof rawCwd !== "string") {
102
+ return undefined;
103
+ }
104
+ const trimmed = rawCwd.trim();
105
+ return trimmed.length > 0 ? trimmed : undefined;
106
+}
107
+
108
const makeProviderService = (options?: ProviderServiceLiveOptions) =>
109
Effect.gen(function* () {
110
const canonicalEventLogger =
@@ -266,8 +278,11 @@ const makeProviderService = (options?: ProviderServiceLiveOptions) =>
278
);
279
}
280
281
+ const persistedCwd = readPersistedCwd(input.binding.runtimePayload);
282
+
283
const resumed = yield* adapter.startSession({
284
provider: input.binding.provider,
285
+ ...(persistedCwd ? { cwd: persistedCwd } : {}),
286
...(resumeThreadId ? { resumeThreadId } : {}),
287
...(hasResumeCursor ? { resumeCursor: input.binding.resumeCursor } : {}),
288
});