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, 21:00 UTC
fix(provider-core): recheck a failed sign-in when settings are applied (#34485)
Julius Marminge committed
Nov 11, 2026 at 15:52 UTC
d27d03b6d3ee29fd7f4da49a95179803396450fa
2 files changed
+68
-2
packages/provider-core/src/server/managedProvider.test.ts
+60
@@ -472,6 +472,66 @@ describe("makeManagedServerProvider", () => {
472
).pipe(Effect.provide(layerAlwaysRunTest)),
473
);
474
475
+ it.effect(
476
+ "rechecks an auth failure when settings are applied, even if this provider's did not change",
477
+ () =>
478
+ Effect.scoped(
479
+ Effect.gen(function* () {
480
+ const settingsChanges = yield* PubSub.unbounded<
481
+ TestSettings & { readonly revision: number }
482
+ >();
483
+ const checkCalls = yield* Ref.make(0);
484
+ const seenRevisions: Array<number> = [];
485
+ const releaseInitialCheck = yield* Deferred.make<void>();
486
+ const markerApplied = yield* Deferred.make<void>();
487
+ const unauthenticatedSnapshot: ServerProvider = {
488
+ ...refreshedSnapshot,
489
+ status: "error",
490
+ auth: { status: "unauthenticated" },
491
+ message: "Codex CLI is not authenticated. Run `codex login` and try again.",
492
+ };
493
+ const provider = yield* makeManagedServerProvider<
494
+ TestSettings & { readonly revision: number }
495
+ >({
496
+ resolveMaintenance: () => Effect.succeed(maintenanceCapabilities),
497
+ getSettings: Effect.succeed({ enabled: true, revision: 0 }),
498
+ streamSettings: Stream.fromPubSub(settingsChanges),
499
+ haveSettingsChanged: (previous, next) => {
500
+ seenRevisions.push(next.revision);
501
+ if (next.revision === 2) Deferred.doneUnsafe(markerApplied, Effect.void);
502
+ return previous.enabled !== next.enabled;
503
+ },
504
+ initialSnapshot: () => Effect.succeed(initialSnapshot),
505
+ // The credential is fixed (e.g. `codex login`) after the first, failed probe.
506
+ checkProvider: Deferred.await(releaseInitialCheck).pipe(
507
+ Effect.andThen(Ref.updateAndGet(checkCalls, (count) => count + 1)),
508
+ Effect.map((count) => (count === 1 ? unauthenticatedSnapshot : refreshedSnapshot)),
509
+ ),
510
+ refreshInterval: "1 hour",
511
+ });
512
+ const initialProbe = yield* provider.streamChanges.pipe(
513
+ Stream.take(1),
514
+ Stream.runDrain,
515
+ Effect.forkChild,
516
+ );
517
+ yield* Effect.yieldNow;
518
+ yield* Deferred.succeed(releaseInitialCheck, undefined);
519
+ yield* Fiber.join(initialProbe);
520
+ assert.deepStrictEqual(yield* provider.getSnapshot, unauthenticatedSnapshot);
521
+
522
+ // A settings apply that does not touch this provider's settings, then a marker:
523
+ // the consumer is sequential, so the first apply has finished once the marker is seen.
524
+ yield* PubSub.publish(settingsChanges, { enabled: true, revision: 1 });
525
+ yield* PubSub.publish(settingsChanges, { enabled: true, revision: 2 });
526
+ yield* Deferred.await(markerApplied);
527
+
528
+ assert.deepStrictEqual(seenRevisions, [1, 2]);
529
+ assert.isAtLeast(yield* Ref.get(checkCalls), 2);
530
+ assert.deepStrictEqual((yield* provider.getSnapshot).auth, refreshedSnapshot.auth);
531
+ }),
532
+ ).pipe(Effect.provide(layerAlwaysRunTest)),
533
+ );
534
+
535
it.effect("streams supplemental snapshot updates after the base provider check completes", () =>
536
Effect.scoped(
537
Effect.gen(function* () {
packages/provider-core/src/server/managedProvider.ts
+8
-2
@@ -143,9 +143,15 @@ export const makeManagedServerProvider = Effect.fn("makeManagedServerProvider")(
143
nextSettings: Settings,
144
options?: { readonly forceRefresh?: boolean },
145
) {
146
- const forceRefresh = options?.forceRefresh === true;
146
const previousSettings = yield* Ref.get(settingsRef);
148
- if (!forceRefresh && !input.haveSettingsChanged(previousSettings, nextSettings)) {
147
+ const settingsChanged =
148
+ options?.forceRefresh === true || input.haveSettingsChanged(previousSettings, nextSettings);
149
+ // Nothing watches credential files, so any settings apply rechecks a failed sign-in.
150
+ const { snapshot: currentSnapshot } = yield* Ref.get(snapshotStateRef);
151
+ const forceRefresh =
152
+ options?.forceRefresh === true ||
153
+ (currentSnapshot.enabled && currentSnapshot.auth.status === "unauthenticated");
154
+ if (!forceRefresh && !settingsChanged) {
155
yield* Ref.set(settingsRef, nextSettings);
156
return yield* Ref.get(snapshotStateRef).pipe(Effect.map((state) => state.snapshot));
157
}