Skip to content

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

Continue folded check-back work in a fresh engine

vincent1eeba78a51ed
diff --git a/docs/verification/context-compaction.md b/docs/verification/context-compaction.md
index 6f75be563b..5317c1f168 100644
--- a/docs/verification/context-compaction.md
+++ b/docs/verification/context-compaction.md
@@ -46,7 +46,10 @@ pnpm exec vitest run server/host/conversation-compaction.test.ts server/context-
Long direct conversations can summarize older exchanges before the next turn.
The full transcript, its branches and attachments are retained. The new session
-gets a bounded summary plus recent exchanges; later turns resume that session.
+gets a bounded summary plus recent exchanges. If a check-back or another
+continuation opens the new session without a new user message, its prompt tells
+the engine to resume the pending work in the user's language. Later turns resume
+that session.
A visible, expandable note explains what was summarized, even with tool chips off;
when no model wrote the summary, it says the agent continues from recent excerpts only.
diff --git a/server/check-backs.e2e.test.ts b/server/check-backs.e2e.test.ts
index 38766d0e95..081f1fea87 100644
--- a/server/check-backs.e2e.test.ts
+++ b/server/check-backs.e2e.test.ts
@@ -13,7 +13,7 @@ import { removeTempDir } from "./testing/cleanup.ts";
it("wakes the same bot in the same conversation at its time with no human action, and Cancel stops another", async () => {
const folder = mkdtempSync(join(tmpdir(), "omb-check-backs-"));
const gate = join(folder, "finish");
- const fixture = await launchVerificationServer({ FAKE_CLAUDE_MODE: "slow", FAKE_CLAUDE_SLOW_FINISH_GATE: gate });
+ const fixture = await launchVerificationServer({ FAKE_CLAUDE_MODE: "slow", FAKE_CLAUDE_SLOW_FINISH_GATE: gate, FAKE_CLAUDE_VERSION: "2.0.76" });
const evidence: unknown[] = [];
const api = async (method: string, path: string, body?: unknown, expected = 200, token?: string) => {
const response = await fetch(fixture.info.url + path, {
@@ -59,10 +59,18 @@ it("wakes the same bot in the same conversation at its time with no human action
writeFileSync(gate, "finish");
await expect.poll(busy, { timeout: 15_000 }).toBe(false);
+ await api("POST", `/api/bots/${bot.id}/compact`, { threadId: bot.threadId }, 202);
+ await expect.poll(busy, { timeout: 15_000 }).toBe(false);
+ expect((await transcript()).at(-1)).toMatchObject({ kind: "compaction", compaction: { by: "person" } });
unlinkSync(gate);
await expect.poll(turnPrompt, { timeout: 90_000, interval: 500 }).toContain("What to check: see if CI passed");
- expect(turnPrompt()).toContain("[Check back:");
+ const prompt = turnPrompt();
+ expect(prompt).toContain("[Earlier conversation summary");
+ expect(prompt).toContain("Merge it, then check CI in a minute");
+ expect(prompt).toContain("[Check back:");
+ expect(prompt).not.toContain("Now reply to the user's latest message");
+ expect(prompt).toContain("[Continue the pending work in this conversation");
const woken = await turnToken();
expect(await lines()).toMatchObject([{ status: "started" }, { status: "cancelled" }]);
const rows = await transcript();
diff --git a/server/index.ts b/server/index.ts
index 2d5930c9d1..19cf04a367 100644
--- a/server/index.ts
+++ b/server/index.ts
@@ -7735,11 +7735,11 @@ async function beginTurn(
const decideContext = (config: string) => {
const handedStale = resuming.stale(config);
const { block: unseenBlock, placed } = unseen && !handedStale ? renderUnseen(unseen) : { block: "", placed: [] };
- const { turnText: contextTurnText, resume } = buildTurnContext({
+ const { turnText: contextTurnText, resume, replayed } = buildTurnContext({
text: userTurnText,
transcript: replay.transcript,
- rewound,
- fresh: fresh || contextReset,
+ rewound, fresh: fresh || contextReset,
+ continuingAfterFold: contextReset && (opts?.cardContinuation === true || !text.trim()),
externallyUpdated: Boolean(externalContextMarker) || handedStale,
replaysNatively: replaysNatively(instance.driverKind),
});
@@ -7754,12 +7754,12 @@ async function beginTurn(
const windowIds = selection.representedIds;
return {
turnText: withUnseenMessages(unseenBlock, contextTurnText),
- images: contextTurnText !== userTurnText ? [...replay.images, ...turnImages] : turnImages, videos: turnVideos,
+ images: replayed ? [...replay.images, ...turnImages] : turnImages, videos: turnVideos,
resumeCursor, sessionReset: !resume, recoveryText,
handoff: strictResume ? {
botId: bot.id, instanceId, config, resumeCursor: typeof resumeCursor === "string" ? resumeCursor : undefined,
...(instance.driverKind === "codex" ? { effort: effort ?? null } : {}),
- started: sessionStart(contextOrder, contextTurnText !== userTurnText ? windowIds : [], carried),
+ started: sessionStart(contextOrder, replayed ? windowIds : [], carried),
recovery: sessionStart(contextOrder, recoveryText !== undefined ? windowIds : [], carried),
resumed: sessionStart(contextOrder, [], [...placed, ...carried]),
placed, carried, own: [userMessage.id, ...(opts?.excludeMessageIds ?? [])],
diff --git a/server/turn-context.test.ts b/server/turn-context.test.ts
index d6bee529b2..a9928d25b6 100644
--- a/server/turn-context.test.ts
+++ b/server/turn-context.test.ts
@@ -14,7 +14,7 @@ const transcript = [
describe("buildTurnContext", () => {
it("passes text through untouched on a plain resumed turn", () => {
const out = buildTurnContext({ text: "hi", transcript, rewound: false, fresh: false, externallyUpdated: false, replaysNatively: false });
- expect(out).toEqual({ turnText: "hi", resume: true });
+ expect(out).toEqual({ turnText: "hi", resume: true, replayed: false });
});
it("replays inline on rewind, exactly like the existing behaviour", () => {
@@ -34,6 +34,18 @@ describe("buildTurnContext", () => {
expect(out.turnText.endsWith("hi")).toBe(true);
});
+ it.each([false, true])("instructs an automated post-fold turn to continue (native replay: %s)", (replaysNatively) => {
+ const out = buildTurnContext({
+ text: "Teammate result: the checks passed.", transcript,
+ rewound: false, fresh: true, externallyUpdated: false, replaysNatively, continuingAfterFold: true,
+ });
+ expect(out.resume).toBe(false);
+ expect(out.replayed).toBe(!replaysNatively);
+ expect(out.turnText.includes("Assistant: Noted — Biscuit.")).toBe(!replaysNatively);
+ expect(out.turnText).not.toContain("Now reply to the user's latest message");
+ expect(out.turnText.indexOf("Teammate result:")).toBeLessThan(out.turnText.indexOf("[Continue the pending work"));
+ });
+
it("never wraps for native-replay drivers — they get history via SendTurnInput.transcript", () => {
for (const flags of [
{ rewound: true, fresh: false, externallyUpdated: false },
@@ -48,7 +60,7 @@ describe("buildTurnContext", () => {
it("does not wrap a fresh engine on an empty thread — nothing to replay", () => {
const out = buildTurnContext({ text: "hi", transcript: [], rewound: false, fresh: true, externallyUpdated: false, replaysNatively: false });
- expect(out).toEqual({ turnText: "hi", resume: false });
+ expect(out).toEqual({ turnText: "hi", resume: false, replayed: false });
});
it("replays an out-of-band teammate result before the next user turn", () => {
@@ -197,13 +209,13 @@ describe("tool history in an inline replay", () => {
});
it("leaves a turn that resumes its session untouched", () => {
- expect(buildTurnContext({ text: "and now?", transcript: replay(ON).inline, ...flags })).toEqual({ turnText: "and now?", resume: true });
+ expect(buildTurnContext({ text: "and now?", transcript: replay(ON).inline, ...flags })).toEqual({ turnText: "and now?", resume: true, replayed: false });
});
it("leaves natively replaying drivers untouched: no wrapper, and a text-only transcript", () => {
for (const rebuild of rebuilds) {
const out = buildTurnContext({ text: "and now?", transcript: replay(ON).inline, ...flags, ...rebuild, replaysNatively: true });
- expect(out).toEqual({ turnText: "and now?", resume: false });
+ expect(out).toEqual({ turnText: "and now?", resume: false, replayed: false });
}
// what SendTurnInput.transcript carries is the selection's own transcript
expect(replay(ON).transcript).toEqual(history);
diff --git a/server/turn-context.ts b/server/turn-context.ts
index cb37a3d713..258297d560 100644
--- a/server/turn-context.ts
+++ b/server/turn-context.ts
@@ -13,6 +13,7 @@ export interface TurnContextInput {
fresh: boolean;
externallyUpdated: boolean;
replaysNatively: boolean;
+ continuingAfterFold?: boolean;
}
export function engineIsFresh(input: {
@@ -35,6 +36,11 @@ const FRESH_PREAMBLE =
const EXTERNAL_UPDATE_PREAMBLE =
"[This conversation received an update outside your provider session. The complete current history follows so you can use that update in your next response:]";
+const FOLD_PREAMBLE =
+ "[This conversation was compacted and is continuing in a fresh engine session. The conversation so far:]";
+const FOLD_CONTINUATION =
+ "[Continue the pending work in this conversation using the earlier context and any new results. Follow the user's standing instructions and respond in their language.]";
+
const RECOVERED_PREAMBLE =
"[Your previous session for this conversation could not be resumed, so this is a new session. The conversation so far:]";
@@ -61,21 +67,25 @@ export const canResume = (input: Pick<TurnContextInput, "rewound" | "fresh" | "e
export function buildTurnContext(input: TurnContextInput): {
turnText: string;
resume: boolean;
+ replayed: boolean;
} {
const { text, transcript, rewound, externallyUpdated, replaysNatively } = input;
const resume = canResume(input);
- const replay = !resume && !replaysNatively && transcript.length > 0;
- if (!replay) return { turnText: text, resume };
+ const continuing = !resume && input.continuingAfterFold;
+ const current = continuing ? (text ? `${text}\n\n${FOLD_CONTINUATION}` : FOLD_CONTINUATION) : text;
+ const replayed = !resume && !replaysNatively && transcript.length > 0;
+ if (!replayed) return { turnText: current, resume, replayed };
return {
turnText: [
- rewound ? REWOUND_PREAMBLE : externallyUpdated ? EXTERNAL_UPDATE_PREAMBLE : FRESH_PREAMBLE,
+ continuing ? FOLD_PREAMBLE : rewound ? REWOUND_PREAMBLE : externallyUpdated ? EXTERNAL_UPDATE_PREAMBLE : FRESH_PREAMBLE,
"",
...transcript.map((m) => `${m.role === "user" ? "User" : "Assistant"}: ${m.text}`),
"",
- "[Now reply to the user's latest message:]",
+ continuing ? "[Current continuation:]" : "[Now reply to the user's latest message:]",
"",
- text,
+ current,
].join("\n"),
resume,
+ replayed,
};
}