From 95f1e28cfcb9ddf9d6cee5ca98db848ca234637e Mon Sep 17 00:00:00 2001 From: nullStack65 <112618179+nullStack65@users.noreply.github.com> Date: Mon, 23 Nov 2026 07:38:34 +0000 Subject: [PATCH] fix(chat): keep private notes out of title generation and search Close the remaining note-privacy gap (F1) on the chatter-fold PR. Title regeneration fed every user message, private notes included, to the title model; the formatter and the initial-title path now drop notes. The agent search filter bound a boolean that node:sqlite rejects, so every message search failed; it now binds 0 or 1. Model: claude-opus-5-5 Task: fix Agent: Magpie Lane: magpie Harness: t3/claude-code Co-Authored-By: Claude Opus 5.5 --- .../src/orchestration-v2/ThreadSearch.ts | 2 +- .../ThreadTitleRegenerationService.test.ts | 75 +++++++++++++++++++ .../ThreadTitleRegenerationService.ts | 3 +- .../src/server/threadTitleContext.test.ts | 9 +++ .../src/server/threadTitleContext.ts | 3 + 5 files changed, 90 insertions(+), 2 deletions(-) diff --git a/apps/server/src/orchestration-v2/ThreadSearch.ts b/apps/server/src/orchestration-v2/ThreadSearch.ts index 459ffc486a346..d03e8c2be192d 100644 --- a/apps/server/src/orchestration-v2/ThreadSearch.ts +++ b/apps/server/src/orchestration-v2/ThreadSearch.ts @@ -333,7 +333,7 @@ export const messageHitsQuery = ( -- neither find nor a jump can reach them. AND messages.message_id NOT LIKE 'async-answer:%' AND ${messageSenderCondition(sql, sender)} - AND (${includeHumanNotes} OR json_extract(messages.payload_json, '$.humanNote') IS NOT 1) + AND (${includeHumanNotes ? 1 : 0} OR json_extract(messages.payload_json, '$.humanNote') IS NOT 1) -- Nor can they reach a rolled-back turn, or a message of a stopped turn -- that no shown item carries, such as a queued prompt that never ran. AND NOT EXISTS ( diff --git a/apps/server/src/orchestration-v2/ThreadTitleRegenerationService.test.ts b/apps/server/src/orchestration-v2/ThreadTitleRegenerationService.test.ts index c73f72ea512fa..a82fb44481c41 100644 --- a/apps/server/src/orchestration-v2/ThreadTitleRegenerationService.test.ts +++ b/apps/server/src/orchestration-v2/ThreadTitleRegenerationService.test.ts @@ -550,6 +550,81 @@ describe("ThreadTitleRegenerationService", () => { }).pipe(Effect.provide(NodeServices.layer)), ); + it.effect("keeps a person's private note out of the title model until it is promoted", () => + Effect.gen(function* () { + const harness = makeHarness(); + yield* Effect.gen(function* () { + const threads = yield* ThreadManagement.ThreadManagementService; + const titleRegeneration = yield* ThreadTitleRegeneration.ThreadTitleRegenerationService; + const threadId = yield* createThread({ + command: "command:title:note:create", + thread: "thread:title:note", + }); + yield* dispatchUserMessage({ + command: "command:title:note:prompt", + threadId, + text: "Investigate the flaky login test", + }); + yield* threads.dispatch({ + type: "thread.metadata.update", + commandId: CommandId.make("command:title:note:share"), + threadId, + inboxRouting: { + owner: null, + assignee: null, + audience: "shared", + attentionKind: "FYI", + reason: "decision", + }, + }); + const noteId = MessageId.make("command:title:note:note:message"); + yield* threads.dispatch({ + type: "message.dispatch", + commandId: CommandId.make("command:title:note:note"), + threadId, + messageId: noteId, + text: "Private aside about the board", + attachments: [], + humanNote: true, + dispatchMode: { type: "start_immediately" }, + createdBy: "user", + creationSource: "web", + }); + const note = (yield* threads.getThreadRecords(threadId, ["messages"])).messages.find( + (message) => message.id === noteId, + ); + assert.equal(note?.humanNote, true); + + const regenerate = yield* armRegeneration({ + command: "command:title:note:regenerate", + threadId, + }); + yield* titleRegeneration.execute({ + threadId, + requestId: regenerate, + kind: { type: "regenerate" }, + }); + // Even if a note id reaches the initial path, its text stays private. + const initial = yield* armRegeneration({ + command: "command:title:note:initial", + threadId, + }); + yield* titleRegeneration.execute({ + threadId, + requestId: initial, + kind: { type: "initial", messageId: noteId }, + }); + + const [regenerated, initialCall] = harness.generateThreadTitle.mock.calls.map( + ([call]) => call, + ); + assert.include(regenerated?.message, "USER:\nInvestigate the flaky login test"); + assert.notInclude(regenerated?.message, "Private aside"); + assert.notInclude(initialCall?.message ?? "", "Private aside"); + }).pipe(Effect.provide(harness.layer)); + }).pipe(Effect.provide(NodeServices.layer)), + ); + it.effect.each([ { name: "its first message", followUp: true }, { name: "no message of its own yet", followUp: false }, diff --git a/apps/server/src/orchestration-v2/ThreadTitleRegenerationService.ts b/apps/server/src/orchestration-v2/ThreadTitleRegenerationService.ts index 725a15aa136e0..5bbc13edb620f 100644 --- a/apps/server/src/orchestration-v2/ThreadTitleRegenerationService.ts +++ b/apps/server/src/orchestration-v2/ThreadTitleRegenerationService.ts @@ -178,8 +178,9 @@ const make = Effect.gen(function* () { const message = projection.messages.find( (candidate) => candidate.id === messageId && !candidate.streaming, ); + // A private note never reaches the title model. context = - message === undefined + message === undefined || message.humanNote === true ? { message: "", attachments: [] } : { message: isAttachmentOnlyBootstrapPrompt(message.text) ? "" : message.text, diff --git a/packages/provider-core/src/server/threadTitleContext.test.ts b/packages/provider-core/src/server/threadTitleContext.test.ts index 4c19d6f573134..cbffc647451cc 100644 --- a/packages/provider-core/src/server/threadTitleContext.test.ts +++ b/packages/provider-core/src/server/threadTitleContext.test.ts @@ -55,6 +55,15 @@ describe("thread title context", () => { expect(result.message.match(/USER:/g)).toHaveLength(1); }); + it("leaves a person's private note out of the model context", () => { + const result = formatThreadTitleContext([ + { role: "user", text: "Private aside about the board", humanNote: true }, + { role: "user", text: "Fix Android pairing." }, + { role: "assistant", text: "Found the cause." }, + ]); + expect(result.message).toBe("USER:\nFix Android pairing.\n\nASSISTANT:\nFound the cause."); + }); + it("cuts both ends of a long message without splitting an emoji", () => { const result = limitTitleMessage(`${"a".repeat(9)}🚀${"b".repeat(20)}🚀${"c".repeat(9)}`, 41); expect(result).toBe(`${"a".repeat(9)}\n[Content truncated]\n${"c".repeat(9)}`); diff --git a/packages/provider-core/src/server/threadTitleContext.ts b/packages/provider-core/src/server/threadTitleContext.ts index 1bff106003958..f375b04c1bfea 100644 --- a/packages/provider-core/src/server/threadTitleContext.ts +++ b/packages/provider-core/src/server/threadTitleContext.ts @@ -6,6 +6,8 @@ export type ThreadTitleMessage = { readonly role: "user" | "assistant" | "system" | "reasoning"; readonly text: string; readonly attachments?: ReadonlyArray | undefined; + /** A person's private note. The model sees it only after it is promoted as its own message. */ + readonly humanNote?: true | undefined; }; const MAX_CONTEXT = 8_000; @@ -34,6 +36,7 @@ export function formatThreadTitleContext(messages: ReadonlyArray