Skip to content

Open-source Grok Bot alternative for named AI teammates. Local-first desktop, web, and mobile clients with per-bot tools, instructions, and memory. Independent fork of T3 Code.

fix(clients): reconnect after credentials fail during remote server updates (#7953)

Theo Browneafa83098064e
diff --git a/packages/client-runtime/src/state/server.test.ts b/packages/client-runtime/src/state/server.test.ts
index 8edecae56..8ee312f61 100644
--- a/packages/client-runtime/src/state/server.test.ts
+++ b/packages/client-runtime/src/state/server.test.ts
@@ -124,6 +124,30 @@ describe("update restart reconnect nudges", () => {
yield* Fiber.join(fiber);
}).pipe(Effect.provide(TestClock.layer())),
);
+
+ it.effect("retries rejected credentials only while the update restart is in progress", () =>
+ Effect.gen(function* () {
+ const retries = yield* Ref.make(0);
+
+ yield* nudgeReconnectDuringUpdateRestart({
+ stateChanges: Stream.fromIterable([
+ { phase: "blocked", lastFailure: { reason: "permission" } },
+ {
+ phase: "blocked",
+ lastFailure: {
+ reason: "authentication",
+ detail: "The environment credential is invalid.",
+ },
+ },
+ { phase: "blocked", lastFailure: { reason: "configuration" } },
+ ]),
+ retryNow: Ref.update(retries, (count) => count + 1),
+ interval: Duration.zero,
+ });
+
+ expect(yield* Ref.get(retries)).toBe(1);
+ }),
+ );
});
describe("server state projection", () => {
diff --git a/packages/client-runtime/src/state/server.ts b/packages/client-runtime/src/state/server.ts
index f579453c2..2fef689a9 100644
--- a/packages/client-runtime/src/state/server.ts
+++ b/packages/client-runtime/src/state/server.ts
@@ -160,16 +160,30 @@ export function validateServerUpdateReadyEvent(
* each nudge is the pacer: a connection that fails instantly re-enters backoff
* immediately and would otherwise spin a tight retry loop.
*
+ * A newly restarted server can also reject the first environment credential.
+ * Authentication blocks need the same paced retry during this known restart;
+ * permission and configuration failures remain blocked.
+ *
* Callers fork this as a child of the update command so it is interrupted as
* soon as the update settles, whether it succeeds, fails, or times out.
*/
export function nudgeReconnectDuringUpdateRestart(input: {
- readonly stateChanges: Stream.Stream<{ readonly phase: string }, unknown>;
+ readonly stateChanges: Stream.Stream<
+ {
+ readonly phase: string;
+ readonly lastFailure?: { readonly reason: string } | null;
+ },
+ unknown
+ >;
readonly retryNow: Effect.Effect<void>;
readonly interval?: Duration.Duration;
}): Effect.Effect<void> {
return input.stateChanges.pipe(
- Stream.filter((state) => state.phase === "backoff"),
+ Stream.filter(
+ (state) =>
+ state.phase === "backoff" ||
+ (state.phase === "blocked" && state.lastFailure?.reason === "authentication"),
+ ),
Stream.runForEach(() =>
Effect.sleep(input.interval ?? Duration.seconds(1)).pipe(Effect.andThen(input.retryNow)),
),