From 49aa48ce5850eb97e4a145a1ee93794283a95790 Mon Sep 17 00:00:00 2001 From: Timo Clasen Date: Wed, 6 Aug 2025 00:15:50 +0200 Subject: [PATCH] fix: prevent title regeneration on auto compact (#1628) --- packages/opencode/src/session/index.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/packages/opencode/src/session/index.ts b/packages/opencode/src/session/index.ts index 8e75e749..89ae5a57 100644 --- a/packages/opencode/src/session/index.ts +++ b/packages/opencode/src/session/index.ts @@ -48,6 +48,17 @@ export namespace Session { const OUTPUT_TOKEN_MAX = 32_000 + const parentSessionTitlePrefix = "New session - " + const childSessionTitlePrefix = "Child session - " + + function createDefaultTitle(isChild = false) { + return (isChild ? childSessionTitlePrefix : parentSessionTitlePrefix) + new Date().toISOString() + } + + function isDefaultTitle(title: string) { + return title.startsWith(parentSessionTitlePrefix) + } + export const Info = z .object({ id: Identifier.schema("session"), @@ -153,7 +164,7 @@ export namespace Session { id: Identifier.descending("session"), version: Installation.VERSION, parentID, - title: (parentID ? "Child session - " : "New Session - ") + new Date().toISOString(), + title: createDefaultTitle(!!parentID), time: { created: Date.now(), updated: Date.now(), @@ -631,7 +642,7 @@ export namespace Session { const lastSummary = msgs.findLast((msg) => msg.info.role === "assistant" && msg.info.summary === true) if (lastSummary) msgs = msgs.filter((msg) => msg.info.id >= lastSummary.info.id) - if (msgs.length === 1 && !session.parentID) { + if (msgs.length === 1 && !session.parentID && isDefaultTitle(session.title)) { const small = (await Provider.getSmallModel(input.providerID)) ?? model generateText({ maxOutputTokens: small.info.reasoning ? 1024 : 20,