Skip to content

Commit 7d17488

Browse files
committed
fix(server): disable Grok startup updates during health checks
1 parent 611132c commit 7d17488

2 files changed

Lines changed: 29 additions & 6 deletions

File tree

‎apps/server/src/provider/GrokProvider.test.ts‎

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,11 @@ it.layer(NodeServices.layer)("checkGrokProviderStatus", (it) => {
402402

403403
// A stand-in for the Grok CLI: `--version` and `models` print canned text,
404404
// and `agent stdio` execs the mock ACP agent so `initialize` returns model metadata.
405-
const writeFakeGrokCli = (input: { readonly modelsOutput: string; readonly acp: boolean }) =>
405+
const writeFakeGrokCli = (input: {
406+
readonly modelsOutput: string;
407+
readonly acp: boolean;
408+
readonly updateLogPath?: string;
409+
}) =>
406410
Effect.gen(function* () {
407411
const fs = yield* FileSystem.FileSystem;
408412
const dir = yield* fs.makeTempDirectoryScoped({ prefix: "t3code-grok-probe-" });
@@ -411,6 +415,14 @@ it.layer(NodeServices.layer)("checkGrokProviderStatus", (it) => {
411415
directory: dir,
412416
name: "grok",
413417
source: [
418+
...(input.updateLogPath
419+
? [
420+
'import { appendFileSync as appendUpdateAttempt } from "node:fs";',
421+
'if (process.env.GROK_DISABLE_AUTOUPDATER !== "1") {',
422+
` appendUpdateAttempt(${JSON.stringify(input.updateLogPath)}, "update\\n");`,
423+
"}",
424+
]
425+
: []),
414426
'if (process.argv[2] === "--version") {',
415427
' process.stdout.write("grok 1.0.13\\n");',
416428
" process.exit(0);",
@@ -426,21 +438,29 @@ it.layer(NodeServices.layer)("checkGrokProviderStatus", (it) => {
426438
});
427439
});
428440

429-
it.effect("reports ready with ACP-discovered models when logged in", () =>
441+
it.effect("reports ready with ACP-discovered models without running startup updates", () =>
430442
Effect.gen(function* () {
431-
const snapshot = yield* Effect.scoped(
443+
const environment = { ...process.env, XAI_API_KEY: "", GROK_DISABLE_AUTOUPDATER: "0" };
444+
const { snapshot, updateRan } = yield* Effect.scoped(
432445
Effect.gen(function* () {
446+
const fs = yield* FileSystem.FileSystem;
447+
const dir = yield* fs.makeTempDirectoryScoped({ prefix: "t3code-grok-updater-" });
448+
const updateLogPath = NodePath.join(dir, "updates.log");
433449
const grokPath = yield* writeFakeGrokCli({
434450
modelsOutput: LOGGED_IN_MODELS_OUTPUT,
435451
acp: true,
452+
updateLogPath,
436453
});
437-
return yield* checkGrokProviderStatus(
454+
const snapshot = yield* checkGrokProviderStatus(
438455
decodeGrokSettings({ enabled: true, binaryPath: grokPath }),
439-
{ ...process.env, XAI_API_KEY: "" },
456+
environment,
440457
);
458+
return { snapshot, updateRan: yield* fs.exists(updateLogPath) };
441459
}),
442460
);
443461

462+
expect(updateRan).toBe(false);
463+
expect(environment.GROK_DISABLE_AUTOUPDATER).toBe("0");
444464
expect(snapshot.status).toBe("ready");
445465
expect(snapshot.version).toBe("1.0.13");
446466
expect(snapshot.auth).toEqual({

‎apps/server/src/provider/GrokProvider.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ const discoverGrokMetadataViaAcpInitialize = (
372372

373373
export const checkGrokProviderStatus = Effect.fn("checkGrokProviderStatus")(function* (
374374
grokSettings: GrokSettings,
375-
environment: NodeJS.ProcessEnv = process.env,
375+
parentEnvironment: NodeJS.ProcessEnv = process.env,
376376
cwd?: string,
377377
): Effect.fn.Return<
378378
ServerProviderDraft,
@@ -398,6 +398,9 @@ export const checkGrokProviderStatus = Effect.fn("checkGrokProviderStatus")(func
398398
});
399399
}
400400

401+
// Periodic probes must not run Grok's launch-time updater.
402+
const environment: NodeJS.ProcessEnv = { ...parentEnvironment, GROK_DISABLE_AUTOUPDATER: "1" };
403+
401404
const versionResult = yield* runGrokCliCommand(grokSettings, ["--version"], environment).pipe(
402405
Effect.timeoutOption(VERSION_PROBE_TIMEOUT_MS),
403406
Effect.result,

0 commit comments

Comments
 (0)