Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Train U4: #6171 without the new context.maxMessages setting
milind-sonicde9a47c5db5
diff --git a/docs/verification/context-compaction.md b/docs/verification/context-compaction.mdindex 86bf3b8e74..f93f2c3ad5 100644--- a/docs/verification/context-compaction.md+++ b/docs/verification/context-compaction.md@@ -346,9 +346,7 @@ those at the top level. A URL inside a command is left as the command ran.`context` settings in config.json are optional. `autoCompact: false` disablesautomatic folding, `compactAt` is a fraction below 1 or a token count, and-`rebuildBytes` controls replay size in bytes (default 24,000) and `maxMessages`-caps retained history entries by count (default 40); a compaction summary or-omitted-prefix notice is added on top of that count, not counted in it. Context-only settings+`rebuildBytes` controls replay size (default 24,000 bytes). Context-only settingsdo not reload provider processes. The default threshold is 80% of the knownmodel window; a real latest-prompt measurement wins over a transcript estimate,except an ACP agent's own reading, which is shown and does not time compaction.diff --git a/server/comms.test.ts b/server/comms.test.tsindex b4c4df47ca..1d22654c16 100644--- a/server/comms.test.ts+++ b/server/comms.test.ts@@ -707,49 +707,6 @@ describe("routine comms e2e on the job runtime (fake ACP fleet)", () => {45_000,);- it(- "bounds the rebuilt conversation by context.maxMessages, not only the byte budget",- async () => {- await hideAll();- rmSync(gateFile, { force: true });- const helper = await named("Helper", { modelSelection: { instanceId: "helperGate", model: "fake-model" } });- const asker = await named("Asker", { modelSelection: { instanceId: "askerNoLoad", model: "fake-model" } });-- expect((await api("PATCH", "/api/config", { context: { maxMessages: 1 } })).status).toBe(200);- try {- await startRoutine(asker.id, "hey @Helper please pick this up; keep the codename ORCHID_EARLIER_CONTEXT");- await waitUntil(async () => (await bot(helper.id)).busy, 30_000, "the helper never took the assignment");- // A shared-rules change while the helper holds makes the handed session state stale, so the wake- // rebuilds the conversation from the bounded replay instead of resuming the warm session.- expect((await api("PATCH", "/api/config", { everyBotRules: "keep answers short" })).status).toBe(200);- writeFileSync(gateFile, "go");- await waitUntil(async () => {- const current = await bot(asker.id);- return !current.busy && lastText(current.messages)?.text === WOKE_WITH_RESULT;- }, 30_000, "the source never woke after its hand-off");-- const woke = JSON.parse(readFileSync(join(home, "asker-no-load.json.prompt.json"), "utf8")).map((block: any) => String(block.text ?? "")).join("\n");- expect(woke).toContain("update outside your provider session");- expect(woke).toContain("earlier messages omitted");- expect(woke).toContain("Assistant: [What Asker did in an earlier turn");- expect(woke).toContain('What @Helper said: "echo:');- // Only the newest entry survives a one-message window: the routine request and the asker's- // delegation reply (earlier transcript lines) drop out of the replay.- expect(woke).not.toContain("User: (Routine");- expect(woke).not.toContain("Assistant: delegated:");- } finally {- writeFileSync(gateFile, "go");- await waitUntil(async () => {- const current = (await api("GET", "/api/bots?messages=0")).body.bots.find((bot: any) => bot.id === helper.id);- return !current?.busy;- }, 10_000, "gated helper did not settle during cleanup").catch(() => {});- rmSync(gateFile, { force: true });- await api("PATCH", "/api/config", { context: { maxMessages: 10_000 }, everyBotRules: "" });- }- },- 45_000,- );-it("keeps a Chief available while its delegated teammate is still working",async () => {diff --git a/server/config.ts b/server/config.tsindex c907e23335..d736d7aec6 100644--- a/server/config.ts+++ b/server/config.ts@@ -481,7 +481,7 @@ export interface AppConfig extends HelperConfig {rooms?: { turnTimeoutMinutes: number };mcp?: { callTimeoutMinutes?: number };threads?: { maxConcurrentPerBot: number; eventLogMaxBytes?: number; eventLogRetentionDays?: number }; burst?: { maxParallel?: number };- context?: { rebuildBytes?: number; compactAt?: number; autoCompact?: boolean; roomCompactAt?: number; roomSessions?: boolean; replayToolHistory?: boolean; maxMessages?: number };+ context?: { rebuildBytes?: number; compactAt?: number; autoCompact?: boolean; roomCompactAt?: number; roomSessions?: boolean; replayToolHistory?: boolean };memory?: { captureQuietMs?: number; tidyHour?: number };localVm?: { mode?: "shared" | "per-bot" | "pool"; maxInstances?: number; idleTimeoutMinutes?: number; preserveInstalledApps?: boolean; memoryGb?: number; cpus?: number };features?: { skillAuthoring?: boolean; skillReview?: boolean; skillReviewSteps?: number; showToolCalls?: boolean; browser?: boolean; sharedComputers?: boolean; claudeUserMcp?: boolean; claudeUserSkills?: boolean; llmThreadTitles?: boolean; smartSetupChoices?: boolean; autoRecall?: boolean; skillsLibrary?: boolean; shareLearnedSkills?: "off" | "ask" | "auto"; roomMemoryCapture?: boolean; parallelRoomJobs?: boolean; acpPlanLines?: boolean; agentsToolBridge?: boolean; savedSteps?: boolean; usbPhoneTakeover?: boolean; cloudComputerAutoReplace?: boolean; phonePush?: boolean };diff --git a/server/index.ts b/server/index.tsindex bd0796adbc..45130ec9a3 100644--- a/server/index.ts+++ b/server/index.ts@@ -7819,7 +7819,7 @@ async function beginTurn(const contextOrder = context.map(m => m.id);const replayable = context.filter(m => !skipTranscript.has(m.id));const record = latestCompaction(activeMessages);- const selection = selectReplay(context, { budgetBytes: cfg.context?.rebuildBytes ?? DEFAULT_REBUILD_BYTES, maxMessages: cfg.context?.maxMessages, excludedIds: skipTranscript, compaction: record, tools: replayToolCalls(activeMessages, cfg.context) });+ const selection = selectReplay(context, { budgetBytes: cfg.context?.rebuildBytes ?? DEFAULT_REBUILD_BYTES, excludedIds: skipTranscript, compaction: record, tools: replayToolCalls(activeMessages, cfg.context) });const transcript = selection.transcript.map(({ role, text }) => ({ role, text }));const contextReset = selection.compacted > 0 && record?.id !== task.appliedCompactionId;if (contextReset) store.patchTask(bot.id, threadId, { resumeCursors: {} });diff --git a/server/replay-settings.test.ts b/server/replay-settings.test.tsindex dee36d9ad5..578abca797 100644--- a/server/replay-settings.test.ts+++ b/server/replay-settings.test.ts@@ -8,11 +8,11 @@ describe("replaySettings", () => {// as server/config.ts takes them: added to the `context` groupconst context = z.object({ compactAt: z.number().optional() }).extend(replaySettings);- it("is the replay's three settings, each optional, beside whatever else the group holds", () => {- expect(Object.keys(replaySettings).sort()).toEqual(["maxMessages", "rebuildBytes", "replayToolHistory"]);+ it("is the replay's two settings, each optional, beside whatever else the group holds", () => {+ expect(Object.keys(replaySettings).sort()).toEqual(["rebuildBytes", "replayToolHistory"]);expect(context.parse({})).toEqual({});- expect(context.parse({ compactAt: 0.7, rebuildBytes: 32_000, maxMessages: 200, replayToolHistory: true }))- .toEqual({ compactAt: 0.7, rebuildBytes: 32_000, maxMessages: 200, replayToolHistory: true });+ expect(context.parse({ compactAt: 0.7, rebuildBytes: 32_000, replayToolHistory: true }))+ .toEqual({ compactAt: 0.7, rebuildBytes: 32_000, replayToolHistory: true });});it("bounds rebuildBytes, with the floor selectReplay itself refuses to go under", () => {@@ -23,14 +23,6 @@ describe("replaySettings", () => {expect(() => selectReplay([], { budgetBytes: 1_023 })).toThrow("invalid context");});- it("bounds maxMessages, with the floor selectReplay itself refuses to go under", () => {- for (const value of [1, 40, 10_000]) expect(context.parse({ maxMessages: value })).toEqual({ maxMessages: value });- for (const value of [0, -1, 1.5, 10_001, "40", null]) expect(() => context.parse({ maxMessages: value })).toThrow();- // a count this lets through never makes the replay throw, and the first one it refuses would- expect(() => selectReplay([], { maxMessages: 1 })).not.toThrow();- expect(() => selectReplay([], { maxMessages: 0 })).toThrow("invalid context");- });-it("takes replayToolHistory as a boolean only", () => {for (const value of [true, false]) expect(context.parse({ replayToolHistory: value })).toEqual({ replayToolHistory: value });for (const value of ["1", 1, "true", null]) expect(() => context.parse({ replayToolHistory: value })).toThrow();diff --git a/server/replay-settings.ts b/server/replay-settings.tsindex 44b66d3ca2..67f61e8422 100644--- a/server/replay-settings.ts+++ b/server/replay-settings.ts@@ -3,8 +3,6 @@ import { z } from "zod";export const replaySettings = {/** Bytes of history a rebuilt session is replayed. */rebuildBytes: z.number().int().min(1_024).max(1_000_000).optional(),- /** Messages of history a rebuilt session is replayed. */- maxMessages: z.number().int().min(1).max(10_000).optional(),/** Also tell a session rebuilt from an inline replay which tools already ran, one line per call. Off unless true; OMB_REPLAY_TOOL_HISTORY=1 or 0 overrides. */replayToolHistory: z.boolean().optional(),};