Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix(runtime): drop a secret cut in half by the 12k answer clip
AdityaUmale3ff54172ef73
diff --git a/server/runtime/envelope.test.ts b/server/runtime/envelope.test.tsindex 8213450e3b..822a1830ce 100644--- a/server/runtime/envelope.test.ts+++ b/server/runtime/envelope.test.ts@@ -500,12 +500,12 @@ describe("composeEnvelope at Full access: nothing a bot can settle waits on theexpect(envelope).toContain(`END".`);});- it("keeps the end of a 12 000-character answer that redaction made longer", () => {+ it("keeps the end of an answer just under the 12 000-character storage limit that redaction made longer", () => {const removeScrubber = addHeldSecretScrubber((text) => text.replaceAll("code 42", `code ${HELD_SECRET_MASK}`));try {const body = "Sent code 42. ".repeat(100);- const answer = `${body}${"x".repeat(12_000 - body.length - 4)}End.`;- expect(answer.length).toBe(12_000);+ const answer = `${body}${"x".repeat(11_999 - body.length - 5)} End.`;+ expect(answer.length).toBe(11_999);const envelope = composeEnvelope(assignment({ question: "Done?", answer, answeredBy: { kind: "bot", botId: "chief" } }), { ...names, answerer: "Chief" });expect(envelope).toContain(`End.".`);expect(envelope).toContain(`code ${HELD_SECRET_MASK}`);@@ -514,6 +514,21 @@ describe("composeEnvelope at Full access: nothing a bot can settle waits on theremoveScrubber();}});+ it("drops a held secret cut in half where the stored answer was clipped", () => {+ const secret = "Zq8-held-PASSWORD-value";+ const removeScrubber = addHeldSecretScrubber((text) => text.replaceAll(secret, HELD_SECRET_MASK));+ try {+ const lead = `Done. ${"word ".repeat(2_398)}`;+ const answer = `${lead}${secret}`.slice(0, 12_000);+ expect(answer.length).toBe(12_000);+ expect(answer.endsWith(secret)).toBe(false);+ const envelope = composeEnvelope(assignment({ question: "Done?", answer, answeredBy: { kind: "bot", botId: "chief" } }), { ...names, answerer: "Chief" });+ expect(envelope).not.toContain("Zq8");+ expect(envelope).toContain(`word …".`);+ } finally {+ removeScrubber();+ }+ });});describe("composeResume", () => {diff --git a/server/runtime/envelope.ts b/server/runtime/envelope.tsindex 78e892b15d..10ffd9ce27 100644--- a/server/runtime/envelope.ts+++ b/server/runtime/envelope.ts@@ -107,13 +107,23 @@ function replyLine(a: Assignment, requester: string, parent?: Assignment): strinreturn `Ownership is yours: results, failures and questions stay in this thread; ${requester} is not waiting and will not be resumed.${answerBack}`;}+/** runtime.ts stores an answer clipped at 12 000 characters (BRIEF_MAX). */+const STORED_ANSWER_MAX = 12_000;++/** A stored answer cut at the limit may end mid-secret, which redaction can no longer match: drop that last partial word. */+function dropClippedTail(text: string | undefined): string | undefined {+ if (!text || text.length < STORED_ANSWER_MAX) return text;+ return `${text.replace(/\S+$/, "").trimEnd()} …`;+}+/** Harness-quoted, so the person's "yes" never travels as pasted text, and a bot's answer never passes for theirs. */function answerLine(a: Assignment, names: EnvelopeNames): string {const question = quote(a.question, QUOTE_MAX);const asked = question ? `Your question was: "${question}". ` : "";// Only a bot's or the person's answer travels whole; a default pick keeps the short quote it always had.- const answer = quote(a.answer, a.answeredBy?.kind === "default" ? QUOTE_MAX : Number.POSITIVE_INFINITY);- if (a.answeredBy?.kind === "default") {+ const isDefault = a.answeredBy?.kind === "default";+ const answer = isDefault ? quote(a.answer, QUOTE_MAX) : quote(dropClippedTail(a.answer), Number.POSITIVE_INFINITY);+ if (isDefault) {return `${asked}Nobody was asked, at this level: ${answer ? `go on with your default, "${answer}"` : "pick the sensible default yourself"}, and say in one plain line what you chose.`;}if (a.answeredBy?.kind === "bot") return `${asked}@${label(names.answerer, a.answeredBy.botId)} answered: "${answer}".`;