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 21, 22:15 UTC
fix(server): re-probe Codex when its auth.json changes (#34320)
Co-authored-by: Julius Marminge <julius0216@outlook.com>
Invix committed
Nov 12, 2026 at 00:21 UTC
2597756eecd5c672007625ffe7245015c4cbf740
2 files changed
+65
apps/server/src/provider/Drivers/CodexDriver.test.ts
+52
@@ -17,9 +17,11 @@ import * as FileSystem from "effect/FileSystem";
17
import * as Layer from "effect/Layer";
18
import * as Option from "effect/Option";
19
import * as PlatformError from "effect/PlatformError";
20
+import * as Queue from "effect/Queue";
21
import * as Schema from "effect/Schema";
22
import * as Sink from "effect/Sink";
23
import * as Stream from "effect/Stream";
24
+import * as TestClock from "effect/testing/TestClock";
25
import { HttpClient, HttpClientResponse } from "effect/http";
26
import * as ChildProcess from "effect/process/ChildProcess";
27
import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner";
@@ -725,4 +727,54 @@ it.layer(layerTest)("CodexDriver", (it) => {
727
}).pipe(Effect.scoped),
728
{ skip: windowsHost },
729
);
730
+
731
+ it.effect("probes again when auth.json in the Codex home changes", () =>
732
+ Effect.gen(function* () {
733
+ const fs = yield* FileSystem.FileSystem;
734
+ const codexHome = yield* fs.makeTempDirectoryScoped({ prefix: "t3-codex-auth-watch-" });
735
+ const watchedPath = yield* Deferred.make<string>();
736
+ const homeEvents = yield* Queue.unbounded<FileSystem.WatchEvent>();
737
+ const probes = yield* Queue.unbounded<void>();
738
+ yield* CodexDriver.create({
739
+ instanceId: ProviderInstanceId.make("codex-auth-watch"),
740
+ displayName: "Codex auth watch",
741
+ enabled: true,
742
+ environment: [],
743
+ config: { ...CodexDriver.defaultConfig(), homePath: codexHome },
744
+ }).pipe(
745
+ // OS watchers can miss events written right after they start, so the test supplies them.
746
+ Effect.provideService(FileSystem.FileSystem, {
747
+ ...fs,
748
+ watch: (path) =>
749
+ Stream.unwrap(
750
+ Deferred.succeed(watchedPath, path).pipe(Effect.as(Stream.fromQueue(homeEvents))),
751
+ ),
752
+ }),
753
+ Effect.provideService(
754
+ ChildProcessSpawner.ChildProcessSpawner,
755
+ ChildProcessSpawner.make((command) =>
756
+ (ChildProcess.isStandardCommand(command) && command.args.includes("app-server")
757
+ ? Queue.offer(probes, undefined)
758
+ : Effect.void
759
+ ).pipe(
760
+ Effect.andThen(
761
+ PlatformError.badArgument({
762
+ module: "ChildProcessSpawner",
763
+ method: "spawn",
764
+ description: "The fixture has no Codex executable",
765
+ }),
766
+ ),
767
+ ),
768
+ ),
769
+ ),
770
+ );
771
+ expect(yield* Deferred.await(watchedPath)).toBe(codexHome);
772
+ yield* Queue.take(probes);
773
+
774
+ yield* Queue.offer(homeEvents, { _tag: "Update", path: "auth.json" });
775
+ yield* TestClock.adjust("250 millis");
776
+
777
+ yield* Queue.take(probes);
778
+ }).pipe(Effect.scoped),
779
+ );
780
});
apps/server/src/provider/Drivers/CodexDriver.ts
+13
@@ -2,10 +2,12 @@ import { CodexSettings, ProviderDriverKind } from "@t3tools/contracts";
2
import * as Digest from "effect/crypto/Digest";
3
import * as SecureRandom from "effect/crypto/SecureRandom";
4
import type * as Signature from "effect/crypto/Signature";
5
+import * as Duration from "effect/Duration";
6
import * as Effect from "effect/Effect";
7
import * as FileSystem from "effect/FileSystem";
8
import * as Path from "effect/Path";
9
import * as Schema from "effect/Schema";
10
+import * as Stream from "effect/Stream";
11
import { HttpClient } from "effect/http";
12
import { ChildProcessSpawner } from "effect/process";
13
@@ -371,6 +373,17 @@ export const CodexDriver: ProviderDriver<
373
),
374
);
375
376
+ // `codex login` and `codex logout` rewrite auth.json outside T3.
377
+ if (effectiveConfig.enabled) {
378
+ yield* fileSystem.watch(accountKey).pipe(
379
+ Stream.filter((event) => pathService.basename(event.path) === "auth.json"),
380
+ Stream.debounce(Duration.millis(250)),
381
+ Stream.runForEach(() => snapshot.refresh.pipe(Effect.ignoreCause({ log: true }))),
382
+ Effect.catchReason("PlatformError", "NotFound", () => Effect.void),
383
+ Effect.ignoreCause({ log: true }),
384
+ Effect.forkScoped,
385
+ );
386
+ }
387
return {
388
instanceId,
389
driverKind: DRIVER_KIND,