Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix: normalize cap handoff paths while retaining legacy events
Afloata331e14a1880
diff --git a/server/thread-events.test.ts b/server/thread-events.test.tsindex 2f94bdd99e..2e270d1b3c 100644--- a/server/thread-events.test.ts+++ b/server/thread-events.test.ts@@ -1,6 +1,6 @@import { appendFileSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";import { tmpdir } from "node:os";-import { join } from "node:path";+import { join, resolve } from "node:path";import { afterEach, describe, expect, it } from "vitest";import { readThreadEvents } from "./thread-events.ts";@@ -71,6 +71,8 @@ describe("readThreadEvents", () => {cap,{ ...cap, eventId: "missing-path", handoffPath: undefined },{ ...cap, eventId: "bad-path", handoffPath: 42 },+ { ...cap, eventId: "empty-path", handoffPath: "" },+ { ...cap, eventId: "blank-path", handoffPath: " " },{ ...cap, eventId: "missing-reason", reason: undefined },{ ...cap, eventId: "bad-reason", reason: "timeout" },].map(line).join(""));@@ -81,6 +83,17 @@ describe("readThreadEvents", () => {expect(page.entries[0]).toMatchObject({ kind: "runtime", data: cap });});+ it("replays legacy relative handoff paths as absolute paths without dropping the event", () => {+ const eventsDir = tmp();+ const nativeDir = tmp();+ const handoffPath = "legacy-data/handoffs/cap-old.md";+ const cap = runtime({ eventId: "legacy-cap", type: "cap.exhausted", createdAt: "1", handoffPath, reason: "cap" });+ writeFileSync(join(eventsDir, "t1.ndjson"), line(cap));+ const page = readThreadEvents({ eventsDir, nativeDir, threadId: "t1" });+ expect(page.entries).toHaveLength(1);+ expect(page.entries[0]).toMatchObject({ kind: "runtime", data: { ...cap, handoffPath: resolve(handoffPath) } });+ });+it("caps each log to its most recent `limit` lines and reports what it skipped", () => {const eventsDir = tmp();const nativeDir = tmp();diff --git a/server/thread-events.ts b/server/thread-events.tsindex b84cc200a2..db2cfa8498 100644--- a/server/thread-events.ts+++ b/server/thread-events.ts@@ -1,5 +1,5 @@import { closeSync, fstatSync, openSync, readSync, type Stats } from "node:fs";-import { join } from "node:path";+import { join, resolve } from "node:path";import type { RuntimeEvent } from "./contracts.ts";import type { InspectorEntry, InspectorPage, NativeRecord } from "../shared/inspector.ts";@@ -136,6 +136,7 @@ const askQuestionsOrMissing = (value: unknown) =>question.options.every((option) => isRecord(option) && typeof option.label === "string"),));+/** Validate persisted records, including legacy relative handoff paths normalized during replay. */export function isRuntimeEvent(value: unknown): value is RuntimeEvent {if (!isRecord(value) ||@@ -178,7 +179,7 @@ export function isRuntimeEvent(value: unknown): value is RuntimeEvent {case "turn.wait_started":return typeof value.resource === "string" && computerHolderOrMissing(value.holder);case "cap.exhausted":- return typeof value.handoffPath === "string" && value.reason === "cap";+ return typeof value.handoffPath === "string" && value.handoffPath.trim().length > 0 && value.reason === "cap";case "turn.wait_ended":return (typeof value.resource === "string" &&@@ -253,7 +254,11 @@ export function readThreadEvents(input: {const native = readRecentLines(join(nativeDir, `${threadId}.ndjson`), limit, isNativeRecord);const merged: InspectorEntry[] = [- ...runtime.lines.map((data): InspectorEntry => ({ kind: "runtime", at: data.createdAt, data })),+ ...runtime.lines.map((data): InspectorEntry => ({+ kind: "runtime",+ at: data.createdAt,+ data: data.type === "cap.exhausted" ? { ...data, handoffPath: resolve(data.handoffPath) } : data,+ })),...native.lines.map((data): InspectorEntry => ({ kind: "native", at: data.at, data })),];merged.sort((a, b) => (a.at < b.at ? -1 : a.at > b.at ? 1 : 0));diff --git a/server/turn-continuation.test.ts b/server/turn-continuation.test.tsindex 8cf117f0f9..682d2897a8 100644--- a/server/turn-continuation.test.ts+++ b/server/turn-continuation.test.ts@@ -1,6 +1,6 @@import { mkdtempSync, readFileSync, rmSync } from "node:fs";import { tmpdir } from "node:os";-import { join } from "node:path";+import { dirname, isAbsolute, join, relative } from "node:path";import { afterEach, describe, expect, it, vi } from "vitest";import { classifyContinuable, writeTurnHandoff } from "./turn-continuation.ts";@@ -47,6 +47,16 @@ describe("writeTurnHandoff", () => {expect(text).toContain("Tokens this turn: 10 in / 20 out");});+ it("returns an absolute handoff when OMB_DATA_DIR is relative", () => {+ const dir = withTempDataDir();+ process.env.OMB_DATA_DIR = relative(process.cwd(), dir);+ const path = writeTurnHandoff({ threadId: "relative", turnId: "turn", toolCalls: 0, messages: [] });+ expect(path).not.toBeNull();+ expect(isAbsolute(path!)).toBe(true);+ expect(dirname(path!)).toBe(join(dir, "handoffs"));+ expect(readFileSync(path!, "utf8")).toContain("# Handoff");+ });+it("returns null when the handoff cannot be written", () => {process.env.OMB_DATA_DIR = join(tmpdir(), "omb-handoff-", "does-not-exist", "nested");expect(writeTurnHandoff({ threadId: "t", turnId: "u", toolCalls: 0, messages: [] })).not.toBeNull();diff --git a/server/turn-continuation.ts b/server/turn-continuation.tsindex e505cd94de..bc4fdfd13d 100644--- a/server/turn-continuation.ts+++ b/server/turn-continuation.ts@@ -1,9 +1,9 @@import { mkdirSync, writeFileSync } from "node:fs";import { homedir } from "node:os";-import { join } from "node:path";+import { join, resolve } from "node:path";export function handoffDir(): string {- return join(process.env.OMB_DATA_DIR || join(homedir(), ".openmausbot"), "handoffs");+ return resolve(process.env.OMB_DATA_DIR || join(homedir(), ".openmausbot"), "handoffs");}export interface HandoffInput {