Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/server/src/orchestration-v2/ThreadSearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 9 additions & 0 deletions packages/provider-core/src/server/threadTitleContext.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)}`);
Expand Down
3 changes: 3 additions & 0 deletions packages/provider-core/src/server/threadTitleContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ export type ThreadTitleMessage = {
readonly role: "user" | "assistant" | "system" | "reasoning";
readonly text: string;
readonly attachments?: ReadonlyArray<ChatAttachment> | 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;
Expand Down Expand Up @@ -34,6 +36,7 @@ export function formatThreadTitleContext(messages: ReadonlyArray<ThreadTitleMess
if (
message.role === "system" ||
message.role === "reasoning" ||
message.humanNote === true ||
(!message.text.trim() && !message.attachments?.length)
)
return [];
Expand Down
Loading