Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

Train T1 (#7391 x #7409): no kept probe answer while any engine status check is open

milind-sonif390c09b985d
diff --git a/server/cli-probe-cache.test.ts b/server/cli-probe-cache.test.ts
index 52ea746c1d..a3bc98845c 100644
--- a/server/cli-probe-cache.test.ts
+++ b/server/cli-probe-cache.test.ts
@@ -6,6 +6,7 @@ import { afterEach, describe, expect, it } from "vitest";
const windows = process.platform === "win32";
import { createCliProbeCache, probeCacheFile, probedProgram } from "./cli-probe-cache.ts";
+import { noteProbeUnsettled } from "./cli-program.ts";
const roots: string[] = [];
afterEach(() => { for (const root of roots.splice(0)) rmSync(root, { recursive: true, force: true }); });
@@ -184,4 +185,23 @@ describe("engine probe answers kept between desktop starts", () => {
await ask(cache.exec, cliFor(bin, "engine"), ["--version"], bin);
expect(counted.calls).toHaveLength(2);
});
+
+ it("runs the program again while the status check could not finish, also when the probe names the CLI by another path", async () => {
+ const { bin, file } = place();
+ program(bin, "engine");
+ const counted = runner();
+ const cache = createCliProbeCache({ file, appVersion: "1", run: counted.run });
+ // The probe names the copy by its full path (as on Windows); the engine status check knows the CLI by its set name.
+ const byPath = join(bin, windows ? "engine.exe" : "engine");
+ await ask(cache.exec, byPath, ["--version"], bin);
+ try {
+ noteProbeUnsettled("engine", true);
+ await ask(cache.exec, byPath, ["--version"], bin);
+ expect(counted.calls).toHaveLength(2);
+ } finally {
+ noteProbeUnsettled("engine", false);
+ }
+ await ask(cache.exec, byPath, ["--version"], bin);
+ expect(counted.calls).toHaveLength(2);
+ });
});
diff --git a/server/cli-probe-cache.ts b/server/cli-probe-cache.ts
index 71fad20d73..bb6e5100d4 100644
--- a/server/cli-probe-cache.ts
+++ b/server/cli-probe-cache.ts
@@ -15,7 +15,7 @@ import { basename, dirname, isAbsolute, join } from "node:path";
import type { ExecFileOptions } from "node:child_process";
import { writeFileAtomic } from "./atomic.ts";
-import { cliProgramFile, probeUnsettled } from "./cli-program.ts";
+import { anyProbeUnsettled, cliProgramFile, probeUnsettled } from "./cli-program.ts";
import { splitCliString } from "./env-path.ts";
import { execCli, outsideBoxOptions, resolveCli } from "./procs.ts";
@@ -147,7 +147,7 @@ export function createCliProbeCache(options: { file: string | null; appVersion:
const program = options.file && args.length === 1 && CACHED_ARGS.has(args[0]!) ? probedProgram(cli, opts) : null;
const key = program ? probeKey(program, args, options.appVersion, platform) : null;
// A check again after one that could not finish runs the program: an earlier answer never stands in for it.
- const kept = key && !(options.unsettled ?? probeUnsettled)(cli) ? loaded().get(key) : undefined;
+ const kept = key && !(options.unsettled ?? unsettledNow)(cli) ? loaded().get(key) : undefined;
if (kept) {
queueMicrotask(() => cb(null, kept.stdout, kept.stderr));
return;
@@ -166,6 +166,10 @@ export function createCliProbeCache(options: { file: string | null; appVersion:
return { exec, forget() { entries = new Map(); save(); } };
}
+/** A status check of this CLI, or of any, could not finish: on Windows a probe names the copy it found by its path while
+ * the check names the CLI as it is set, so no kept answer is given while any check is open. */
+const unsettledNow = (cli: string): boolean => probeUnsettled(cli) || anyProbeUnsettled();
+
let shared: ReturnType<typeof createCliProbeCache> | null = null;
/** execCli for `--version` and `--help` probes: the desktop app's kept answer when the program is unchanged. */
diff --git a/server/cli-program.ts b/server/cli-program.ts
index 3682aee832..24e2109511 100644
--- a/server/cli-program.ts
+++ b/server/cli-program.ts
@@ -28,3 +28,7 @@ export function noteProbeUnsettled(cli: string, open: boolean): void {
/** Whether this CLI's last status check could not finish: a check again must run the program, never answer from a kept
* copy of an earlier answer. */
export const probeUnsettled = (cli: string): boolean => unsettled.has(cli);
+
+/** Whether any CLI's last status check could not finish. A probe may name its program otherwise than the check does (on
+ * Windows, by the path of the copy it found), so a kept answer waits until every open check has answered. */
+export const anyProbeUnsettled = (): boolean => unsettled.size > 0;