Skip to content

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

fix(claude): a turn whose copy never owns the version check treats the version as unknown

AdityaUmale38119978b480
diff --git a/server/drivers/claude.test.ts b/server/drivers/claude.test.ts
index 32eed0e848..eb58556691 100644
--- a/server/drivers/claude.test.ts
+++ b/server/drivers/claude.test.ts
@@ -2081,6 +2081,34 @@ describe("ClaudeDriver turns (fake CLI)", () => {
resetPathCacheForTests();
}
});
+ it.skipIf(process.platform === "win32")("treats the version as unknown when another copy's check still owns the state after both re-checks", async () => {
+ // Each time the turn's own copy (2.1.197) reads its --help, a version check of 2.1.321 lands; after both re-checks the shared
+ // version is still 2.1.321's, so it must not confirm a restricted MCP configuration for the copy this turn launches.
+ const gates = join(scratch, "exhaust-gates"), newer = join(scratch, "exhaust-newer"), older = join(scratch, "exhaust-older");
+ mkdirSync(gates); mkdirSync(newer); mkdirSync(older);
+ writeFileSync(join(newer, "claude"), `#!/bin/sh\nFAKE_CLAUDE_VERSION=2.1.321 exec "${FAKE_CLI}" "$@"\n`, { mode: 0o755 });
+ writeFileSync(join(older, "claude"), `#!/bin/sh\nif [ "$1" = --help ]; then i=1; while ! mkdir "${gates}/help-$i" 2>/dev/null; do i=$((i+1)); done; : > "${gates}/asked-$i"; while [ ! -e "${gates}/go-$i" ]; do sleep 0.05; done; fi\nFAKE_CLAUDE_VERSION=2.1.197 exec "${FAKE_CLI}" "$@"\n`, { mode: 0o755 });
+ try {
+ resetPathCacheForTests();
+ registerPathDir(newer);
+ await create(undefined, {}, { cli: "claude" });
+ await instance.snapshot();
+ registerPathDir(older);
+ const sent = instance.adapter.sendTurn({ threadId: "t-exhausted-recheck", text: "Must not run", toolScope: { allow: ["native:*"] } });
+ sent.catch(() => {});
+ for (const i of [1, 2, 3]) { // the first check and both re-checks
+ await vi.waitFor(() => expect(existsSync(join(gates, `asked-${i}`))).toBe(true), { timeout: 5000 });
+ resetPathCacheForTests();
+ registerPathDir(newer);
+ await instance.snapshot(); // 2.1.321's check lands while the turn waits for 2.1.197's --help
+ writeFileSync(join(gates, `go-${i}`), "");
+ }
+ await expect(sent).rejects.toThrow(/restricted MCP configuration/);
+ expect(existsSync(join(gates, "asked-4"))).toBe(false);
+ } finally {
+ resetPathCacheForTests();
+ }
+ });
it.skipIf(process.platform === "win32")("keeps the new copy's flags when the old copy's slower --help read finishes last", async () => {
// snapshot() is still reading 2.1.321's help when PATH finds 2.1.197 (no --autocompact); that old read must not restore 2.1.321's flags.
const refused = join(scratch, "stale-help-autocompact.jsonl"), helpStarted = join(scratch, "newer-help-started");
diff --git a/server/drivers/claude.ts b/server/drivers/claude.ts
index ece745d704..2eb648873b 100644
--- a/server/drivers/claude.ts
+++ b/server/drivers/claude.ts
@@ -1019,22 +1019,22 @@ export const ClaudeDriver: ProviderDriver<ClaudeConfig> = {
const turnEnvironment = environment();
const launchCli = findCliCandidates(config.cli, turnEnvironment.PATH ?? "")[0]; await ensureCliVersion(turnEnvironment);
for (let tries = 0; tries < 2 && cliVersionChecked && cliProbedAt !== launchCli; tries++) await ensureCliVersion(turnEnvironment); // another copy's late check landed while this turn waited
- const ownCli = cliProbedAt === launchCli; // still another copy's state: none of its version-picked flags
- if (turn.guestConfined && !claudeCliSupports(cliVersion, "--restricted")) {
+ const ownCli = cliProbedAt === launchCli, turnCliVersion = ownCli ? cliVersion : null; // still another copy's state: none of its flags, its version counts as unknown
+ if (turn.guestConfined && !claudeCliSupports(turnCliVersion, "--restricted")) {
throw new Error(withWhy("This Claude Code is too old to run this turn without a shell. Update Claude Code.", turn.confinedWhy));
}
- const replaysUserMessages = cliVersion === null || versionAtLeast(cliVersion, CLAUDE_REPLAY_FLOOR);
+ const replaysUserMessages = turnCliVersion === null || versionAtLeast(turnCliVersion, CLAUDE_REPLAY_FLOOR);
if (replaysUserMessages) args.push("--replay-user-messages");
const isolated = !inheritsUserConfig(turnEnvironment);
const disallowed = [...(config.disallowedTools ?? []), ...unusableBuiltIns({ isolated, listsTools: config.tools !== undefined, guest: Boolean(turn.guestConfined) }), ...claudeDisabledNativeSkillRules(botId)];
if (disallowed.length) args.push("--disallowedTools", disallowed.join(","));
- if (turn.toolScope !== undefined && (!isolated || turn.mcpFromUserConfig || cliVersion === null || !claudeCliSupports(cliVersion, "--strict-mcp-config"))) {
+ if (turn.toolScope !== undefined && (!isolated || turn.mcpFromUserConfig || turnCliVersion === null || !claudeCliSupports(turnCliVersion, "--strict-mcp-config"))) {
throw new Error("Claude cannot confirm a restricted MCP configuration for this account. Disable inherited Claude MCP servers and use a current, identifiable Claude CLI before using tool selection.");
}
if (isolated) {
// Without these every turn gets this machine's MCP servers, connectors, skills, hooks and CLAUDE.md (one desktop: 407 tools, ~10k tokens).
- if (!turn.mcpFromUserConfig && claudeCliSupports(cliVersion, "--strict-mcp-config")) args.push("--strict-mcp-config");
- if (claudeCliSupports(cliVersion, "--setting-sources")) args.push("--setting-sources", "project");
+ if (!turn.mcpFromUserConfig && claudeCliSupports(turnCliVersion, "--strict-mcp-config")) args.push("--strict-mcp-config");
+ if (claudeCliSupports(turnCliVersion, "--setting-sources")) args.push("--setting-sources", "project");
if (turn.userSkillsDir) args.push("--add-dir", turn.userSkillsDir);
}
const compactWindow = autoCompactWindow(turnEnvironment);