Skip to content

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

Train H: a damaged skill switch file never stops a bot (#5454, #5450)

milind-soni3256001d2e9d
diff --git a/docs/custom-mcp-servers.md b/docs/custom-mcp-servers.md
index 1d2b03a5a0..77d267feb7 100644
--- a/docs/custom-mcp-servers.md
+++ b/docs/custom-mcp-servers.md
@@ -289,10 +289,9 @@ path for the bot's turns, so a same-named skill in the turn's own
keep applying. A skill brought in from this computer and switched off is kept
out the same way, from the folder it came from. If the bot's saved switches
(`<data>/skill-state/<bot id>/native-skills.json`) are there but can't be read,
-the page shows every such skill off, switches can't be changed, and the bot's
-Claude and Codex turns don't start, saying which file to fix or delete;
-deleting it resets those switches to on (skills from this computer switched
-off for the bot stay off).
+every such skill counts as on (skills from this computer switched off for the
+bot stay off), turns run as usual and the server logs it once; the next switch
+writes a good file.
Open a bot’s **Tools → Access → MCP servers** to narrow the enabled global
servers offered to it. Existing bots keep all enabled global servers until you
diff --git a/docs/feature-flags.md b/docs/feature-flags.md
index cb2b71e167..c0bdb67a05 100644
--- a/docs/feature-flags.md
+++ b/docs/feature-flags.md
@@ -62,10 +62,9 @@ text and extra work can increase token usage.
With `skillsLibrary` on, the every-bot skills a bot was taken off live in
`<data>/skill-state/<bot id>/library-opt-out.json`. If that file is there but
-can't be read or isn't a list of names, every library skill counts as off for
-that bot (skills assigned to it explicitly still apply) and the server logs it
-once. To recover, make the file readable and writable again (or delete it to
-give the bot every every-bot skill), then switch skills back on for the bot.
+can't be read or isn't a list of names, the bot keeps every every-bot skill and
+the server logs it once. Switching a skill off for the bot again writes a good
+file.
### Ordinary server lending has three states
diff --git a/server/drivers/codex-guest.ts b/server/drivers/codex-guest.ts
index 0cc51fe28d..db2ab4e9c2 100644
--- a/server/drivers/codex-guest.ts
+++ b/server/drivers/codex-guest.ts
@@ -31,8 +31,7 @@ const isFile = (path: string) => {
/** `-c skills.config=[…]` selecting each SKILL.md this bot switched off by absolute path: a `name` selector would also
* match the same-named skills linked into the turn's `.agents/skills`. codex-cli (0.163.0–0.167.0) keeps
- * `[[skills.config]]` from config.toml in effect alongside it and reads the list once per turn. Throws
- * NativeSkillChoicesUnreadable. */
+ * `[[skills.config]]` from config.toml in effect alongside it and reads the list once per turn. */
export function codexDisabledNativeSkillArgs(botId: string | undefined, env: Record<string, string | undefined>): string[] {
if (!botId) return [];
const denied = deniedNativeSkills(botId);
diff --git a/server/drivers/codex.test.ts b/server/drivers/codex.test.ts
index 3214545bf3..6a70692b23 100644
--- a/server/drivers/codex.test.ts
+++ b/server/drivers/codex.test.ts
@@ -255,7 +255,7 @@ describe("CodexDriver turns (fake app-server)", () => {
expect(existsSync(dump)).toBe(false);
});
- it("switches a bot's native skills off by path, and refuses its turn while its switches can't be read", async () => {
+ it("switches a bot's native skills off by path, and still runs its turn while its switches can't be read", async () => {
const dump = join(scratch, "skills-off.json"); process.env.FAKE_CODEX_DUMP = dump;
const skill = join(scratch, ".agents", "skills", "pdf", "SKILL.md");
mkdirSync(dirname(skill), { recursive: true }); writeFileSync(skill, "---\nname: pdf\ndescription: PDFs.\n---\nSteps.\n");
@@ -269,12 +269,14 @@ describe("CodexDriver turns (fake app-server)", () => {
expect(skillsConfig(dump)).not.toContain("name=");
writeFileSync(choices, "{\"off\": [");
- const refused = join(scratch, "skills-unreadable.json"); process.env.FAKE_CODEX_DUMP = refused;
- await expect(instance.adapter.sendTurn({ threadId: "skills-unreadable", botId: "codex-skills-off", text: "hi" })).rejects.toThrow(/can't be read/);
- expect(existsSync(refused)).toBe(false);
+ const damaged = join(scratch, "skills-unreadable.json"); process.env.FAKE_CODEX_DUMP = damaged;
+ recorder.events.length = 0;
+ await instance.adapter.sendTurn({ threadId: "skills-unreadable", botId: "codex-skills-off", text: "hi" });
+ await expect(recorder.until((e) => e.type === "turn.completed")).resolves.toMatchObject({ ok: true });
+ expect(skillsConfig(damaged)).toBe("");
});
- it("rebuilds a bot's native skill switches for each relaunch, and ends the turn if they turn unreadable", async () => {
+ it("rebuilds a bot's native skill switches for each relaunch, and keeps going if they turn unreadable", async () => {
const skill = join(scratch, ".agents", "skills", "pdf", "SKILL.md");
const choices = join(DATA_DIR, "skill-state", "codex-skills-retry", "native-skills.json");
mkdirSync(dirname(choices), { recursive: true }); writeFileSync(choices, JSON.stringify({ off: ["pdf"] }));
@@ -294,10 +296,10 @@ describe("CodexDriver turns (fake app-server)", () => {
process.env.FAKE_CODEX_STATE = join(scratch, "skills-retry-damaged");
const damage = instance.adapter.onEvent((event) => { if (event.type === "turn.retrying") writeFileSync(choices, "{"); });
await instance.adapter.sendTurn({ threadId: "skills-retry-damaged", botId: "codex-skills-retry", text: "hi" });
- await expect(recorder.until((e) => e.type === "turn.completed", 15_000)).resolves.toMatchObject({ ok: false });
+ await expect(recorder.until((e) => e.type === "turn.completed", 15_000)).resolves.toMatchObject({ ok: true });
damage();
- expect(recorder.events.some((e) => e.type === "runtime.error" && /can't be read/.test((e as { message: string }).message))).toBe(true);
- expect(readFileSync(join(scratch, "skills-retry-damaged"), "utf8")).toBe("1");
+ expect(recorder.events.some((e) => e.type === "runtime.error")).toBe(false);
+ expect(readFileSync(join(scratch, "skills-retry-damaged"), "utf8")).toBe("2");
}, 30_000);
it("gates raw custom identities before mount renaming and disables ambient MCP servers", async () => {
diff --git a/server/native-skill-choices.test.ts b/server/native-skill-choices.test.ts
index 8207dd3be0..a696c93d0e 100644
--- a/server/native-skill-choices.test.ts
+++ b/server/native-skill-choices.test.ts
@@ -8,7 +8,7 @@ import { DATA_DIR } from "./config.ts";
import { claudeDisabledNativeSkillRules } from "./drivers/claude-unusable-tools.ts";
import { codexDisabledNativeSkillArgs, codexTurnConfigArgs, GUEST_CONFINED_CODEX_ARGS } from "./drivers/codex-guest.ts";
import { setImportedSkillEnabled, storeImportedSkills } from "./imported-skills.ts";
-import { deniedNativeSkills, isNativeSkillEnabled, NativeSkillChoicesUnreadable, setNativeSkillEnabled } from "./native-skill-choices.ts";
+import { deniedNativeSkills, isNativeSkillEnabled, setNativeSkillEnabled } from "./native-skill-choices.ts";
// HOME and the data folder are this test file's own temporary ones (server/testing/setup.ts).
const HOME = join(DATA_DIR, "..");
@@ -53,16 +53,15 @@ describe("per-bot native skill switches", () => {
expect(isNativeSkillEnabled("bot-a", "pdf")).toBe(true);
});
- it("refuses to guess when the bot's saved switches can't be read, and never writes over them", () => {
+ it("keeps every native skill on while the bot's saved switches can't be read, and lets a switch write a good file", () => {
damage("bot-a");
- expect(isNativeSkillEnabled("bot-a", "pdf")).toBe(false);
- expect(() => deniedNativeSkills("bot-a")).toThrow(NativeSkillChoicesUnreadable);
- expect(setNativeSkillEnabled("bot-a", "pdf", true)).toEqual({ error: expect.stringContaining("Fix or delete that file") });
- expect(readFileSync(choicesFile("bot-a"), "utf8")).toBe("{\"off\": [");
- expect(() => claudeDisabledNativeSkillRules("bot-a")).toThrow(NativeSkillChoicesUnreadable);
- expect(() => codexTurnConfigArgs({ botId: "bot-a" }, env)).toThrow(NativeSkillChoicesUnreadable);
- rmSync(choicesFile("bot-a"));
expect(isNativeSkillEnabled("bot-a", "pdf")).toBe(true);
+ expect(deniedNativeSkills("bot-a")).toEqual({ names: [], origins: [] });
+ expect(claudeDisabledNativeSkillRules("bot-a")).toEqual([]);
+ expect(codexTurnConfigArgs({ botId: "bot-a" }, env)).toEqual([]);
+ expect(setNativeSkillEnabled("bot-a", "pdf", false)).toEqual({ off: ["pdf"] });
+ expect(JSON.parse(readFileSync(choicesFile("bot-a"), "utf8"))).toEqual({ off: ["pdf"] });
+ expect(isNativeSkillEnabled("bot-a", "pdf")).toBe(false);
});
});
diff --git a/server/native-skill-choices.ts b/server/native-skill-choices.ts
index 39984f0e71..78eebfd574 100644
--- a/server/native-skill-choices.ts
+++ b/server/native-skill-choices.ts
@@ -12,33 +12,29 @@ import { isSkillName } from "../shared/skill-md.ts";
const choicesPath = (botId: string) => join(DATA_DIR, "skill-state", botId, "native-skills.json");
const choicesSchema = z.object({ off: z.array(z.string()) });
-/** The bot's switches exist but cannot be read. Nothing can tell which skills were off, so a turn on an engine that
- * loads skills by itself does not start, and no switch is written over the file, until the person fixes or deletes it. */
-export class NativeSkillChoicesUnreadable extends Error {
- constructor(path: string) {
- super(`This bot's switches for the skills its AI loads by itself can't be read (${path}). Fix or delete that file, then try again.`);
- }
-}
+const unreadableWarned = new Set<string>();
+/** A file that is there but can't be read counts as nothing switched off, so the bot keeps working with every skill;
+ * the server logs it once, and the next switch writes a good file over it. */
function readChoices(botId: string): string[] {
const path = choicesPath(botId);
- let text: string;
+ let why = "not a list of skill names";
try {
- text = readFileSync(path, "utf8");
+ const parsed = choicesSchema.safeParse(JSON.parse(readFileSync(path, "utf8")));
+ if (parsed.success) return parsed.data.off.filter(isSkillName).sort();
} catch (error) {
if ((error as NodeJS.ErrnoException).code === "ENOENT") return [];
- throw new NativeSkillChoicesUnreadable(path);
+ why = (error as NodeJS.ErrnoException).code ?? why;
}
- try {
- const parsed = choicesSchema.safeParse(JSON.parse(text));
- if (parsed.success) return parsed.data.off.filter(isSkillName).sort();
- } catch {}
- throw new NativeSkillChoicesUnreadable(path);
+ if (!unreadableWarned.has(path)) {
+ unreadableWarned.add(path);
+ console.warn(`Native skill switches at ${path} can't be read (${why}); every native skill stays on for that bot until one is switched off again.`);
+ }
+ return [];
}
/** Native skills this bot has off: its own switches, plus each skill from this computer it switched off, with the
- * SKILL.md it was brought in from, which an engine loading that folder would still read. Throws
- * NativeSkillChoicesUnreadable. */
+ * SKILL.md it was brought in from, which an engine loading that folder would still read. */
export function deniedNativeSkills(botId: string): { names: string[]; origins: string[] } {
const own = readChoices(botId);
const imported = importedSkillsSwitchedOff(botId);
@@ -47,30 +43,19 @@ export function deniedNativeSkills(botId: string): { names: string[]; origins: s
return { names: [...new Set([...own, ...imported])].sort(), origins };
}
-/** Names of the native skills this bot has off. Throws NativeSkillChoicesUnreadable. */
+/** Names of the native skills this bot has off. */
export function disabledNativeSkillNames(botId: string): string[] {
return deniedNativeSkills(botId).names;
}
export function isNativeSkillEnabled(botId: string, name: string): boolean {
- try {
- return !deniedNativeSkills(botId).names.includes(name);
- } catch (error) {
- if (error instanceof NativeSkillChoicesUnreadable) return false;
- throw error;
- }
+ return !deniedNativeSkills(botId).names.includes(name);
}
/** Persist one bot's native-skill switch. Does not create or delete skill files. */
export function setNativeSkillEnabled(botId: string, name: string, enabled: boolean): { off: string[] } | { error: string } {
if (!isSkillName(name)) return { error: `invalid skill name "${name}"` };
- let off: string[];
- try {
- off = readChoices(botId).filter((other) => other !== name);
- } catch (error) {
- if (error instanceof NativeSkillChoicesUnreadable) return { error: error.message };
- throw error;
- }
+ const off = readChoices(botId).filter((other) => other !== name);
const next = enabled ? off : [...off, name].sort();
mkdirSync(dirname(choicesPath(botId)), { recursive: true, mode: 0o700 });
writeFileAtomic(choicesPath(botId), `${JSON.stringify({ off: next }, null, 2)}\n`, { mode: 0o600 });
diff --git a/server/native-skills.test.ts b/server/native-skills.test.ts
index f58ec57da8..f09f532ec6 100644
--- a/server/native-skills.test.ts
+++ b/server/native-skills.test.ts
@@ -181,7 +181,7 @@ describe("switching a native skill off for one bot", () => {
expect(listed(hostFor("claudeAgent").host.listBotSkills(bot))).not.toContain("release-notes:native");
});
- it("shows every native skill off and keeps /name from expanding one while the bot's saved switches can't be read", () => {
+ it("shows every native skill on while the bot's saved switches can't be read", () => {
const { host, bot } = hostFor("codex");
plant(CODEX_SKILLS, "pdf");
plant(AGENTS_SKILLS, "deploy");
@@ -189,8 +189,7 @@ describe("switching a native skill off for one bot", () => {
writeFileSync(join(DATA_DIR, "skill-state", bot.id, "native-skills.json"), "{\"off\": [\"pd");
const natives = host.listBotSkills(bot).filter((skill) => "origin" in skill && skill.origin === "native")
.map((skill) => [skill.name, skill.enabled] as const).sort();
- expect(natives).toEqual([["deploy", false], ["pdf", false]]);
- expect(host.expandSkillCommand(bot, "main", "/pdf now", undefined, [], true)).toBe("/pdf now");
+ expect(natives).toEqual([["deploy", true], ["pdf", true]]);
});
});
diff --git a/server/routes/bot-skills.test.ts b/server/routes/bot-skills.test.ts
index 5793faaac0..10610c8b58 100644
--- a/server/routes/bot-skills.test.ts
+++ b/server/routes/bot-skills.test.ts
@@ -211,7 +211,7 @@ describe("removing a skill from one bot", () => {
describe("a bot's opt-outs from every-bot skills", () => {
const optOutFile = (botId: string) => join(DATA_DIR, "skill-state", botId, "library-opt-out.json");
- it("keeps every-bot skills off for a bot whose opt-out list is damaged or can't be read", () => {
+ it("keeps every-bot skills on for a bot whose opt-out list is damaged or can't be read", () => {
const shared = "everyone-opt-out-check";
expect(installLibrarySkill({ name: shared, instructions: learned(shared), source: "lib", reviewState: "approved" })).toMatchObject({ name: shared });
expect(setLibrarySkillEveryBot(shared, true)).toMatchObject({ everyBot: true });
@@ -219,7 +219,7 @@ describe("a bot's opt-outs from every-bot skills", () => {
writeFileSync(optOutFile("opt-out-damaged"), "[\"half-written");
expect(resolveBotSkills("opt-out-none", []).map((skill) => skill.name)).toContain(shared);
- expect(resolveBotSkills("opt-out-damaged", []).map((skill) => skill.name)).not.toContain(shared);
+ expect(resolveBotSkills("opt-out-damaged", []).map((skill) => skill.name)).toContain(shared);
expect(resolveBotSkills("opt-out-damaged", [shared]).map((skill) => skill.name)).toContain(shared);
if (process.platform === "win32" || process.getuid?.() === 0) return;
@@ -227,7 +227,7 @@ describe("a bot's opt-outs from every-bot skills", () => {
writeFileSync(optOutFile("opt-out-unreadable"), "[]");
chmodSync(dirname(optOutFile("opt-out-unreadable")), 0o000);
try {
- expect(resolveBotSkills("opt-out-unreadable", []).map((skill) => skill.name)).not.toContain(shared);
+ expect(resolveBotSkills("opt-out-unreadable", []).map((skill) => skill.name)).toContain(shared);
} finally {
chmodSync(dirname(optOutFile("opt-out-unreadable")), 0o700);
}
diff --git a/server/skill-library.ts b/server/skill-library.ts
index 4c47f56d31..57adc5c824 100644
--- a/server/skill-library.ts
+++ b/server/skill-library.ts
@@ -312,17 +312,16 @@ function libraryOptOutPath(botId: string): string | null {
const unreadableOptOutsWarned = new Set<string>();
-function everyLibrarySkillOff(path: string, why: string): ReadonlySet<string> {
+function noLibraryOptOuts(path: string, why: string): ReadonlySet<string> {
if (!unreadableOptOutsWarned.has(path)) {
unreadableOptOutsWarned.add(path);
- console.warn(`Library opt-outs at ${path} can't be read (${why}); every library skill stays off for that bot until the file is readable again and one is switched back on.`);
+ console.warn(`Library opt-outs at ${path} can't be read (${why}); every every-bot skill stays on for that bot until one is switched off again.`);
}
- return new Set(listLibrarySkills().map((skill) => skill.name));
+ return new Set();
}
/** Names this bot has taken off its own list. An explicit assignment still wins; the shared copy stays. A list that is
- * there but cannot be read counts as every library skill, so a damaged or unreadable file never puts an every-bot skill
- * back. */
+ * there but cannot be read counts as none, so the bot keeps working with every every-bot skill; the server logs it once. */
export function librarySkillOptOuts(botId: string): ReadonlySet<string> {
const path = libraryOptOutPath(botId);
if (!path) return new Set();
@@ -332,13 +331,13 @@ export function librarySkillOptOuts(botId: string): ReadonlySet<string> {
} catch (error) {
const code = (error as NodeJS.ErrnoException).code;
if (code === "ENOENT") return new Set();
- return everyLibrarySkillOff(path, code ?? "read failed");
+ return noLibraryOptOuts(path, code ?? "read failed");
}
try {
const parsed = libraryOptOutSchema.safeParse(JSON.parse(text));
if (parsed.success) return new Set(parsed.data.filter(isSkillName));
} catch {}
- return everyLibrarySkillOff(path, "not a list of skill names");
+ return noLibraryOptOuts(path, "not a list of skill names");
}
export function setLibrarySkillOptOut(botId: string, name: string, optedOut: boolean): void {