Skip to content

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

Skip empty prior summaries and tighten escaping comments

hh123456tw738453918d04
diff --git a/server/compaction-summary.ts b/server/compaction-summary.ts
index a18daacdc7..4598556fcc 100644
--- a/server/compaction-summary.ts
+++ b/server/compaction-summary.ts
@@ -20,10 +20,10 @@ export function deterministicSummary(history: readonly ReplayEntry[], maxBytes =
for (let i = history.length - 1; i >= 0; i--) {
const entry = history[i]!;
if (!entry.text.trim()) continue;
- // An earlier summary is already quoted once; quoting it again doubles its escapes every round.
- const prior = entry.priorSummary?.startsWith(EXCERPT_SUMMARY_HEADER) ? entry.priorSummary.slice(EXCERPT_SUMMARY_HEADER.length).trim() : entry.priorSummary?.trim();
+ // Already escaped once: stringifying it again would double the escapes every round.
+ const prior = entry.priorSummary?.replace(EXCERPT_SUMMARY_HEADER, (m, at) => at === 0 ? "" : m).trim() || undefined;
const text = prior ?? `${entry.role === "user" ? "User message" : "Assistant/record"}: ${JSON.stringify(entry.text)}`;
- const line = boundedContextText(text, Math.min(prior === undefined ? 1_600 : MAX_SUMMARY_BYTES, available));
+ const line = boundedContextText(text, Math.min(prior ? MAX_SUMMARY_BYTES : 1_600, available));
if (available < 128) { omitted++; continue; }
lines.unshift(line);
available -= Buffer.byteLength(line) + 1;
diff --git a/server/context-rebuild.ts b/server/context-rebuild.ts
index f3ec3b3b34..64107e5896 100644
--- a/server/context-rebuild.ts
+++ b/server/context-rebuild.ts
@@ -11,7 +11,7 @@ export interface ReplayEntry {
id: string;
role: "user" | "assistant";
text: string;
- /** Set only on the entry that stands for an earlier compaction summary: that summary's own text, before it is wrapped into `text`. */
+ /** On the entry standing for an earlier compaction summary: the summary's raw text, before it is JSON-quoted into `text`. */
priorSummary?: string;
}