@vellumai/assistant 0.10.4-dev.202607012335.d6d6958 → 0.10.4-dev.202607020106.aa66e63
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/__tests__/config-loader-backfill.test.ts +5 -5
- package/src/__tests__/context-search-conversations-source.test.ts +181 -298
- package/src/__tests__/db-drop-messages-fts.test.ts +115 -0
- package/src/__tests__/model-intents.test.ts +1 -1
- package/src/__tests__/non-member-access-request.test.ts +125 -2
- package/src/__tests__/workspace-migration-122-relocate-default-user-boundary.test.ts +119 -0
- package/src/__tests__/workspace-migration-123-swap-quality-profile-to-fable.test.ts +191 -0
- package/src/config/seed-inference-profiles.ts +2 -2
- package/src/persistence/__tests__/conversation-queries-search.test.ts +65 -71
- package/src/persistence/conversation-crud.ts +0 -41
- package/src/persistence/conversation-queries.ts +45 -118
- package/src/persistence/conversation-row-batch-delete.ts +8 -11
- package/src/persistence/conversation-search-lexical.ts +5 -4
- package/src/persistence/migrations/116-messages-fts.ts +8 -1
- package/src/persistence/migrations/313-drop-messages-fts.ts +17 -0
- package/src/persistence/raw-query.ts +0 -3
- package/src/persistence/steps.ts +2 -0
- package/src/plugins/defaults/memory/__tests__/conversation-queries.test.ts +6 -38
- package/src/plugins/defaults/memory/context-search/sources/conversations.ts +49 -186
- package/src/prompts/__tests__/system-prompt.test.ts +38 -0
- package/src/prompts/templates/system-sections.ts +32 -0
- package/src/prompts/templates/users/default.md +6 -22
- package/src/providers/model-intents.ts +2 -2
- package/src/runtime/access-request-helper.ts +70 -2
- package/src/runtime/channel-verification-service.ts +6 -2
- package/src/runtime/routes/inbound-message-handler.ts +71 -38
- package/src/runtime/routes/inbound-stages/acl-enforcement.test.ts +138 -0
- package/src/runtime/routes/inbound-stages/acl-enforcement.ts +126 -50
- package/src/workspace/migrations/122-relocate-default-user-boundary.ts +111 -0
- package/src/workspace/migrations/123-swap-quality-profile-to-fable.ts +85 -0
- package/src/workspace/migrations/registry.ts +4 -0
package/package.json
CHANGED
|
@@ -856,9 +856,9 @@ describe("loadConfig startup behavior", () => {
|
|
|
856
856
|
);
|
|
857
857
|
expect(raw.llm.profiles.balanced.effort).toBe("high");
|
|
858
858
|
expect(raw.llm.profiles.balanced.source).toBe("managed");
|
|
859
|
-
// Quality serves Anthropic
|
|
859
|
+
// Quality serves Anthropic Fable, the most capable managed profile.
|
|
860
860
|
expect(raw.llm.profiles["quality-optimized"].provider).toBe("anthropic");
|
|
861
|
-
expect(raw.llm.profiles["quality-optimized"].model).toBe("claude-
|
|
861
|
+
expect(raw.llm.profiles["quality-optimized"].model).toBe("claude-fable-5");
|
|
862
862
|
// Speed is served by DeepSeek V4 Flash on Fireworks.
|
|
863
863
|
expect(raw.llm.profiles["cost-optimized"].provider).toBe("fireworks");
|
|
864
864
|
expect(raw.llm.profiles["cost-optimized"].model).toBe(
|
|
@@ -899,7 +899,7 @@ describe("loadConfig startup behavior", () => {
|
|
|
899
899
|
test("reseed updates a source-less legacy canonical managed profile", () => {
|
|
900
900
|
// Migration 052 seeded canonical profiles without a `source`. Such a
|
|
901
901
|
// source-less `quality-optimized` is legacy managed, not user-owned, so it
|
|
902
|
-
// must still reseed to the latest template (
|
|
902
|
+
// must still reseed to the latest template (Fable) and be tagged managed.
|
|
903
903
|
writeConfig({
|
|
904
904
|
llm: {
|
|
905
905
|
profiles: {
|
|
@@ -915,7 +915,7 @@ describe("loadConfig startup behavior", () => {
|
|
|
915
915
|
mergeDefaultConfigAndSeedInferenceProfiles();
|
|
916
916
|
const raw = JSON.parse(readFileSync(CONFIG_PATH, "utf-8"));
|
|
917
917
|
|
|
918
|
-
expect(raw.llm.profiles["quality-optimized"].model).toBe("claude-
|
|
918
|
+
expect(raw.llm.profiles["quality-optimized"].model).toBe("claude-fable-5");
|
|
919
919
|
expect(raw.llm.profiles["quality-optimized"].source).toBe("managed");
|
|
920
920
|
});
|
|
921
921
|
|
|
@@ -1574,7 +1574,7 @@ describe("seedInferenceProfiles BYOK-mode managed profile labels", () => {
|
|
|
1574
1574
|
const raw = JSON.parse(readFileSync(CONFIG_PATH, "utf-8"));
|
|
1575
1575
|
|
|
1576
1576
|
expect(raw.llm.activeProfile).toBe("balanced");
|
|
1577
|
-
// Balanced lives on `fireworks-managed`; `quality-optimized` (
|
|
1577
|
+
// Balanced lives on `fireworks-managed`; `quality-optimized` (Fable on
|
|
1578
1578
|
// `anthropic-managed`) is on a different connection, so selecting balanced at
|
|
1579
1579
|
// hatch disables it. The default advisor falls to the only active managed
|
|
1580
1580
|
// profile, `balanced`.
|
|
@@ -3,11 +3,11 @@ import { afterEach, beforeEach, describe, expect, mock, test } from "bun:test";
|
|
|
3
3
|
import { writeSlackMetadata } from "../messaging/providers/slack/message-metadata.js";
|
|
4
4
|
import type { MessageLexicalSearchResult } from "../persistence/embeddings/messages-lexical-index.js";
|
|
5
5
|
|
|
6
|
-
// Mutable stand-in for the Qdrant lexical candidate helper. The
|
|
7
|
-
//
|
|
8
|
-
//
|
|
9
|
-
//
|
|
10
|
-
//
|
|
6
|
+
// Mutable stand-in for the Qdrant lexical candidate helper. The source treats
|
|
7
|
+
// a thrown lookup as "no candidates" (logged, empty evidence), so the throwing
|
|
8
|
+
// default cannot fail a forgetful test loudly — tests that assert evidence
|
|
9
|
+
// must configure an implementation, and tests that assert the helper is never
|
|
10
|
+
// consulted check `lexicalCalls` instead.
|
|
11
11
|
let lexicalMockImpl: (
|
|
12
12
|
query: string,
|
|
13
13
|
limit: number,
|
|
@@ -17,7 +17,7 @@ let lexicalMockImpl: (
|
|
|
17
17
|
};
|
|
18
18
|
|
|
19
19
|
// Records the arguments of every mock invocation so tests can assert the
|
|
20
|
-
// candidate over-fetch count
|
|
20
|
+
// candidate over-fetch count and that gated paths never consult the index.
|
|
21
21
|
let lexicalCalls: Array<{
|
|
22
22
|
query: string;
|
|
23
23
|
limit: number;
|
|
@@ -35,11 +35,11 @@ mock.module("../persistence/conversation-search-lexical.js", () => ({
|
|
|
35
35
|
},
|
|
36
36
|
}));
|
|
37
37
|
|
|
38
|
-
// Drives the real recall
|
|
39
|
-
//
|
|
40
|
-
//
|
|
41
|
-
//
|
|
42
|
-
//
|
|
38
|
+
// Drives the real recall availability gate: when true the source yields no
|
|
39
|
+
// evidence, because the lexical index write path is suppressed and the
|
|
40
|
+
// collection is never populated. Defaults false so every other test exercises
|
|
41
|
+
// the live path. Spread the real module so its other exports (job handlers,
|
|
42
|
+
// enqueue helpers) stay intact for transitive importers.
|
|
43
43
|
let suppressIndexing = false;
|
|
44
44
|
const realLexicalModule =
|
|
45
45
|
await import("../plugins/defaults/memory/job-handlers/index-message-lexical.js");
|
|
@@ -65,18 +65,36 @@ await initializeDb();
|
|
|
65
65
|
|
|
66
66
|
let seedId = 0;
|
|
67
67
|
|
|
68
|
-
describe("searchConversationSource", () => {
|
|
68
|
+
describe("searchConversationSource (qdrant lexical index)", () => {
|
|
69
69
|
beforeEach(() => {
|
|
70
70
|
getDb().run("DELETE FROM messages");
|
|
71
71
|
getDb().run("DELETE FROM conversations");
|
|
72
|
+
lexicalCalls = [];
|
|
73
|
+
suppressIndexing = false;
|
|
74
|
+
// Content evidence is available once the index is populated: not
|
|
75
|
+
// suppressed + backfill complete. Most tests exercise that path, so mark
|
|
76
|
+
// the backfill complete; the gates are covered by their own tests.
|
|
77
|
+
setMemoryCheckpoint(LEXICAL_BACKFILL_COMPLETE_KEY, "1");
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
afterEach(() => {
|
|
81
|
+
suppressIndexing = false;
|
|
82
|
+
deleteMemoryCheckpoint(LEXICAL_BACKFILL_COMPLETE_KEY);
|
|
83
|
+
lexicalMockImpl = () => {
|
|
84
|
+
throw new Error(
|
|
85
|
+
"searchMessageIdsLexical mock not configured for this test",
|
|
86
|
+
);
|
|
87
|
+
};
|
|
72
88
|
});
|
|
73
89
|
|
|
74
|
-
test("returns matching message evidence
|
|
90
|
+
test("returns matching message evidence for lexical candidates", async () => {
|
|
75
91
|
const { conversation, message } = await seedConversation({
|
|
76
92
|
title: "Launch notes",
|
|
77
93
|
content: "The alpha launch checklist includes database backups.",
|
|
78
94
|
});
|
|
79
95
|
|
|
96
|
+
lexicalMockImpl = async () => [{ messageId: message.id, score: 0.9 }];
|
|
97
|
+
|
|
80
98
|
const result = await searchConversationSource(
|
|
81
99
|
"alpha launch",
|
|
82
100
|
makeContext(),
|
|
@@ -99,9 +117,10 @@ describe("searchConversationSource", () => {
|
|
|
99
117
|
});
|
|
100
118
|
|
|
101
119
|
test("returns no evidence for short and non-ASCII queries (content matching is index-only)", async () => {
|
|
102
|
-
// Short/punctuation-only and CJK queries produce no usable ≥2-char
|
|
103
|
-
//
|
|
104
|
-
//
|
|
120
|
+
// Short/punctuation-only and CJK queries produce no usable ≥2-char token.
|
|
121
|
+
// There is no content-scan fallback, so such queries yield no conversation
|
|
122
|
+
// evidence even when an exact substring exists — and the index is never
|
|
123
|
+
// consulted (the sparse encoder would emit noisy 1-char tokens).
|
|
105
124
|
await seedConversation({
|
|
106
125
|
title: "C++ notes",
|
|
107
126
|
role: "user",
|
|
@@ -119,80 +138,173 @@ describe("searchConversationSource", () => {
|
|
|
119
138
|
5,
|
|
120
139
|
);
|
|
121
140
|
|
|
141
|
+
expect(lexicalCalls).toHaveLength(0);
|
|
122
142
|
expect(shortResult.evidence).toEqual([]);
|
|
123
143
|
expect(unicodeResult.evidence).toEqual([]);
|
|
124
144
|
});
|
|
125
145
|
|
|
126
|
-
test("
|
|
127
|
-
const visible = await seedConversation({
|
|
128
|
-
title: "User conversation",
|
|
129
|
-
content: "derivedtoken belongs to a user-authored conversation.",
|
|
130
|
-
});
|
|
146
|
+
test("returns no evidence when memory indexing is suppressed", async () => {
|
|
131
147
|
await seedConversation({
|
|
132
|
-
title: "
|
|
133
|
-
|
|
134
|
-
content: "derivedtoken should not include subagent output.",
|
|
148
|
+
title: "Suppressed indexing notes",
|
|
149
|
+
content: "The suppressedtoken decision is recorded here.",
|
|
135
150
|
});
|
|
151
|
+
|
|
152
|
+
// The lexical index is never populated while indexing is suppressed, so
|
|
153
|
+
// the source must yield no evidence without consulting Qdrant.
|
|
154
|
+
suppressIndexing = true;
|
|
155
|
+
lexicalMockImpl = async () => {
|
|
156
|
+
throw new Error("searchMessageIdsLexical must not run while suppressed");
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
const result = await searchConversationSource(
|
|
160
|
+
"suppressedtoken",
|
|
161
|
+
makeContext(),
|
|
162
|
+
5,
|
|
163
|
+
);
|
|
164
|
+
|
|
165
|
+
expect(lexicalCalls).toHaveLength(0);
|
|
166
|
+
expect(result.evidence).toEqual([]);
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
test("returns no evidence until the backfill completion checkpoint is set", async () => {
|
|
136
170
|
await seedConversation({
|
|
137
|
-
title: "
|
|
138
|
-
|
|
139
|
-
content: "derivedtoken should not include auto-analysis output.",
|
|
171
|
+
title: "Pre-backfill notes",
|
|
172
|
+
content: "The prebackfilltoken decision is recorded here.",
|
|
140
173
|
});
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
174
|
+
|
|
175
|
+
// On an upgraded instance the historical messages are still being indexed
|
|
176
|
+
// by the background backfill, so the lexical collection is only partially
|
|
177
|
+
// populated. Until the completion checkpoint is set, the source must
|
|
178
|
+
// yield no evidence without consulting Qdrant.
|
|
179
|
+
deleteMemoryCheckpoint(LEXICAL_BACKFILL_COMPLETE_KEY);
|
|
180
|
+
lexicalMockImpl = async () => {
|
|
181
|
+
throw new Error(
|
|
182
|
+
"searchMessageIdsLexical must not run before the backfill completes",
|
|
183
|
+
);
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
const result = await searchConversationSource(
|
|
187
|
+
"prebackfilltoken",
|
|
188
|
+
makeContext(),
|
|
189
|
+
5,
|
|
190
|
+
);
|
|
191
|
+
|
|
192
|
+
expect(lexicalCalls).toHaveLength(0);
|
|
193
|
+
expect(result.evidence).toEqual([]);
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
test("over-fetches a wide candidate pool from Qdrant", async () => {
|
|
197
|
+
const match = await seedConversation({
|
|
198
|
+
title: "Launch notes",
|
|
199
|
+
content: "The widecandidatetoken launch checklist is recorded here.",
|
|
145
200
|
});
|
|
146
201
|
|
|
202
|
+
lexicalMockImpl = async () => [{ messageId: match.message.id, score: 0.9 }];
|
|
203
|
+
|
|
204
|
+
// limit = 5 → the source over-fetches max(5 × 20, 200) = 200 candidates so
|
|
205
|
+
// post-filter yield stays healthy when top lexical hits are excluded by
|
|
206
|
+
// the SQL predicates.
|
|
147
207
|
const result = await searchConversationSource(
|
|
148
|
-
"
|
|
208
|
+
"widecandidatetoken",
|
|
149
209
|
makeContext(),
|
|
150
|
-
|
|
210
|
+
5,
|
|
151
211
|
);
|
|
152
212
|
|
|
213
|
+
expect(lexicalCalls).toHaveLength(1);
|
|
214
|
+
expect(lexicalCalls[0]?.limit).toBe(200);
|
|
215
|
+
// Filtering still yields the correctly-scored surviving row.
|
|
153
216
|
expect(result.evidence.map((item) => item.locator)).toEqual([
|
|
154
|
-
`${
|
|
217
|
+
`${match.conversation.id}#${match.message.id}`,
|
|
155
218
|
]);
|
|
219
|
+
expect(result.evidence[0]?.score).toBeGreaterThan(0);
|
|
156
220
|
});
|
|
157
221
|
|
|
158
|
-
test("
|
|
159
|
-
const
|
|
160
|
-
title: "
|
|
161
|
-
content: "
|
|
222
|
+
test("returns app-scored evidence for Qdrant-supplied candidates", async () => {
|
|
223
|
+
const match = await seedConversation({
|
|
224
|
+
title: "Launch notes",
|
|
225
|
+
content: "The alpha launch checklist includes database backups.",
|
|
162
226
|
});
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
227
|
+
// A candidate the lexical index also surfaces but that the query does not
|
|
228
|
+
// actually match — proves the app-side scorer, not Qdrant order, ranks.
|
|
229
|
+
const weak = await seedConversation({
|
|
230
|
+
title: "Unrelated",
|
|
231
|
+
content: "Nothing salient in this conversation at all.",
|
|
166
232
|
});
|
|
167
233
|
|
|
234
|
+
lexicalMockImpl = async () => [
|
|
235
|
+
{ messageId: weak.message.id, score: 0.9 },
|
|
236
|
+
{ messageId: match.message.id, score: 0.1 },
|
|
237
|
+
];
|
|
238
|
+
|
|
168
239
|
const result = await searchConversationSource(
|
|
169
|
-
"
|
|
170
|
-
makeContext(
|
|
171
|
-
|
|
240
|
+
"alpha launch",
|
|
241
|
+
makeContext(),
|
|
242
|
+
5,
|
|
172
243
|
);
|
|
173
244
|
|
|
174
|
-
expect(result.evidence
|
|
175
|
-
|
|
176
|
-
|
|
245
|
+
expect(result.evidence[0]).toMatchObject({
|
|
246
|
+
id: `conversations:${match.conversation.id}:${match.message.id}`,
|
|
247
|
+
source: "conversations",
|
|
248
|
+
title: "Launch notes",
|
|
249
|
+
locator: `${match.conversation.id}#${match.message.id}`,
|
|
250
|
+
excerpt: "The alpha launch checklist includes database backups.",
|
|
251
|
+
metadata: {
|
|
252
|
+
role: "assistant",
|
|
253
|
+
conversationId: match.conversation.id,
|
|
254
|
+
},
|
|
255
|
+
});
|
|
256
|
+
expect(result.evidence[0]?.score).toBeGreaterThan(
|
|
257
|
+
result.evidence[1]?.score ?? -1,
|
|
258
|
+
);
|
|
177
259
|
});
|
|
178
260
|
|
|
179
|
-
test("
|
|
261
|
+
test("applies source, type, and excluded-conversation filters to Qdrant candidates", async () => {
|
|
180
262
|
const visible = await seedConversation({
|
|
181
|
-
title: "
|
|
182
|
-
content: "
|
|
263
|
+
title: "User conversation",
|
|
264
|
+
content: "derivedtoken belongs to a user-authored conversation.",
|
|
265
|
+
});
|
|
266
|
+
const subagent = await seedConversation({
|
|
267
|
+
title: "Subagent conversation",
|
|
268
|
+
source: "subagent",
|
|
269
|
+
content: "derivedtoken should not include subagent output.",
|
|
270
|
+
});
|
|
271
|
+
const autoAnalysis = await seedConversation({
|
|
272
|
+
title: "Auto-analysis conversation",
|
|
273
|
+
source: "auto-analysis",
|
|
274
|
+
content: "derivedtoken should not include auto-analysis output.",
|
|
275
|
+
});
|
|
276
|
+
const notification = await seedConversation({
|
|
277
|
+
title: "Notification conversation",
|
|
278
|
+
source: "notification",
|
|
279
|
+
content: "derivedtoken should not include notification output.",
|
|
280
|
+
});
|
|
281
|
+
const current = await seedConversation({
|
|
282
|
+
title: "Current conversation",
|
|
283
|
+
content: "derivedtoken appears in the active conversation.",
|
|
183
284
|
});
|
|
184
285
|
const legacyPrivate = await seedConversation({
|
|
185
286
|
title: "Legacy private conversation",
|
|
186
|
-
content: "
|
|
287
|
+
content: "derivedtoken belongs to legacy private history.",
|
|
187
288
|
});
|
|
188
289
|
rawRun(
|
|
189
290
|
"UPDATE conversations SET conversation_type = 'private' WHERE id = ?",
|
|
190
291
|
legacyPrivate.conversation.id,
|
|
191
292
|
);
|
|
192
293
|
|
|
294
|
+
// The lexical index does not filter — it hands back every candidate,
|
|
295
|
+
// including the ones SQL must exclude.
|
|
296
|
+
lexicalMockImpl = async () => [
|
|
297
|
+
{ messageId: visible.message.id, score: 0.9 },
|
|
298
|
+
{ messageId: subagent.message.id, score: 0.85 },
|
|
299
|
+
{ messageId: autoAnalysis.message.id, score: 0.8 },
|
|
300
|
+
{ messageId: notification.message.id, score: 0.75 },
|
|
301
|
+
{ messageId: current.message.id, score: 0.7 },
|
|
302
|
+
{ messageId: legacyPrivate.message.id, score: 0.65 },
|
|
303
|
+
];
|
|
304
|
+
|
|
193
305
|
const result = await searchConversationSource(
|
|
194
|
-
"
|
|
195
|
-
makeContext(),
|
|
306
|
+
"derivedtoken",
|
|
307
|
+
makeContext({ conversationId: current.conversation.id }),
|
|
196
308
|
10,
|
|
197
309
|
);
|
|
198
310
|
|
|
@@ -222,6 +334,12 @@ describe("searchConversationSource", () => {
|
|
|
222
334
|
content: "includetoken appears in background history.",
|
|
223
335
|
});
|
|
224
336
|
|
|
337
|
+
lexicalMockImpl = async () => [
|
|
338
|
+
{ messageId: archived.message.id, score: 0.9 },
|
|
339
|
+
{ messageId: scheduled.message.id, score: 0.85 },
|
|
340
|
+
{ messageId: background.message.id, score: 0.8 },
|
|
341
|
+
];
|
|
342
|
+
|
|
225
343
|
const result = await searchConversationSource(
|
|
226
344
|
"includetoken",
|
|
227
345
|
makeContext(),
|
|
@@ -249,6 +367,8 @@ describe("searchConversationSource", () => {
|
|
|
249
367
|
content,
|
|
250
368
|
});
|
|
251
369
|
|
|
370
|
+
lexicalMockImpl = async () => [{ messageId: message.id, score: 0.9 }];
|
|
371
|
+
|
|
252
372
|
const result = await searchConversationSource("needle", makeContext(), 1);
|
|
253
373
|
|
|
254
374
|
expect(result.evidence).toHaveLength(1);
|
|
@@ -266,6 +386,8 @@ describe("searchConversationSource", () => {
|
|
|
266
386
|
'<external_content source="slack" origin="@alice">\nThe recalltoken decision came from Slack.\n</external_content>',
|
|
267
387
|
});
|
|
268
388
|
|
|
389
|
+
lexicalMockImpl = async () => [{ messageId: message.id, score: 0.9 }];
|
|
390
|
+
|
|
269
391
|
const result = await searchConversationSource(
|
|
270
392
|
"recalltoken",
|
|
271
393
|
makeContext(),
|
|
@@ -290,6 +412,8 @@ describe("searchConversationSource", () => {
|
|
|
290
412
|
}),
|
|
291
413
|
});
|
|
292
414
|
|
|
415
|
+
lexicalMockImpl = async () => [{ messageId: message.id, score: 0.9 }];
|
|
416
|
+
|
|
293
417
|
const result = await searchConversationSource(
|
|
294
418
|
"rawrecalltoken",
|
|
295
419
|
makeContext(),
|
|
@@ -315,6 +439,8 @@ describe("searchConversationSource", () => {
|
|
|
315
439
|
}),
|
|
316
440
|
});
|
|
317
441
|
|
|
442
|
+
lexicalMockImpl = async () => [{ messageId: message.id, score: 0.9 }];
|
|
443
|
+
|
|
318
444
|
const result = await searchConversationSource(
|
|
319
445
|
"tagmentionrecalltoken",
|
|
320
446
|
makeContext(),
|
|
@@ -339,6 +465,8 @@ describe("searchConversationSource", () => {
|
|
|
339
465
|
}),
|
|
340
466
|
});
|
|
341
467
|
|
|
468
|
+
lexicalMockImpl = async () => [{ messageId: message.id, score: 0.9 }];
|
|
469
|
+
|
|
342
470
|
const result = await searchConversationSource(
|
|
343
471
|
"guardianrecalltoken",
|
|
344
472
|
makeContext(),
|
|
@@ -352,251 +480,6 @@ describe("searchConversationSource", () => {
|
|
|
352
480
|
});
|
|
353
481
|
});
|
|
354
482
|
|
|
355
|
-
test("broadens overconstrained recall queries to salient terms", async () => {
|
|
356
|
-
const specific = await seedConversation({
|
|
357
|
-
title: "Birthday cake plan",
|
|
358
|
-
content:
|
|
359
|
-
"The birthday cake was vanilla with raspberry filling and had the message Happy birthday Alice Love Example Assistant.",
|
|
360
|
-
});
|
|
361
|
-
await seedConversation({
|
|
362
|
-
title: "Decoration notes",
|
|
363
|
-
content: "The decoration and flavor notes for the launch party are open.",
|
|
364
|
-
});
|
|
365
|
-
|
|
366
|
-
const result = await searchConversationSource(
|
|
367
|
-
"birthday cake flavor decoration message recipient",
|
|
368
|
-
makeContext(),
|
|
369
|
-
5,
|
|
370
|
-
);
|
|
371
|
-
|
|
372
|
-
expect(result.evidence[0]).toMatchObject({
|
|
373
|
-
locator: `${specific.conversation.id}#${specific.message.id}`,
|
|
374
|
-
title: "Birthday cake plan",
|
|
375
|
-
});
|
|
376
|
-
expect(result.evidence[0]?.excerpt).toContain("vanilla with raspberry");
|
|
377
|
-
expect(result.evidence[0]?.score).toBeGreaterThan(0);
|
|
378
|
-
});
|
|
379
|
-
});
|
|
380
|
-
|
|
381
|
-
describe("searchConversationSource with the qdrant backend", () => {
|
|
382
|
-
beforeEach(() => {
|
|
383
|
-
getDb().run("DELETE FROM messages");
|
|
384
|
-
getDb().run("DELETE FROM conversations");
|
|
385
|
-
lexicalCalls = [];
|
|
386
|
-
suppressIndexing = false;
|
|
387
|
-
// The qdrant backend is selected once the index is populated: not suppressed
|
|
388
|
-
// + backfill complete. These tests exercise that post-backfill path, so mark
|
|
389
|
-
// the backfill complete. The completion gate is covered by its own test.
|
|
390
|
-
setMemoryCheckpoint(LEXICAL_BACKFILL_COMPLETE_KEY, "1");
|
|
391
|
-
});
|
|
392
|
-
|
|
393
|
-
afterEach(() => {
|
|
394
|
-
suppressIndexing = false;
|
|
395
|
-
deleteMemoryCheckpoint(LEXICAL_BACKFILL_COMPLETE_KEY);
|
|
396
|
-
lexicalMockImpl = () => {
|
|
397
|
-
throw new Error(
|
|
398
|
-
"searchMessageIdsLexical mock not configured for this test",
|
|
399
|
-
);
|
|
400
|
-
};
|
|
401
|
-
});
|
|
402
|
-
|
|
403
|
-
test("falls back to FTS when memory indexing is suppressed", async () => {
|
|
404
|
-
const match = await seedConversation({
|
|
405
|
-
title: "Suppressed indexing notes",
|
|
406
|
-
content: "The suppressedtoken decision is recorded here.",
|
|
407
|
-
});
|
|
408
|
-
|
|
409
|
-
// The lexical index is not populated while indexing is suppressed, so the
|
|
410
|
-
// source must NOT query Qdrant — it must use the FTS path.
|
|
411
|
-
suppressIndexing = true;
|
|
412
|
-
lexicalMockImpl = async () => {
|
|
413
|
-
throw new Error("searchMessageIdsLexical must not run while suppressed");
|
|
414
|
-
};
|
|
415
|
-
|
|
416
|
-
const result = await searchConversationSource(
|
|
417
|
-
"suppressedtoken",
|
|
418
|
-
makeContext(),
|
|
419
|
-
5,
|
|
420
|
-
);
|
|
421
|
-
|
|
422
|
-
// FTS path found the row (proves the backend fell back), and the Qdrant
|
|
423
|
-
// candidate helper was never called.
|
|
424
|
-
expect(lexicalCalls).toHaveLength(0);
|
|
425
|
-
expect(result.evidence.map((item) => item.locator)).toEqual([
|
|
426
|
-
`${match.conversation.id}#${match.message.id}`,
|
|
427
|
-
]);
|
|
428
|
-
});
|
|
429
|
-
|
|
430
|
-
test("falls back to FTS until the backfill completion checkpoint is set", async () => {
|
|
431
|
-
const match = await seedConversation({
|
|
432
|
-
title: "Pre-backfill notes",
|
|
433
|
-
content: "The prebackfilltoken decision is recorded here.",
|
|
434
|
-
});
|
|
435
|
-
|
|
436
|
-
// On an upgraded instance the historical messages are still being indexed
|
|
437
|
-
// by the background backfill, so the lexical collection is only partially
|
|
438
|
-
// populated. Until the completion checkpoint is set, the source must use
|
|
439
|
-
// the FTS path and never query Qdrant.
|
|
440
|
-
deleteMemoryCheckpoint(LEXICAL_BACKFILL_COMPLETE_KEY);
|
|
441
|
-
lexicalMockImpl = async () => {
|
|
442
|
-
throw new Error(
|
|
443
|
-
"searchMessageIdsLexical must not run before the backfill completes",
|
|
444
|
-
);
|
|
445
|
-
};
|
|
446
|
-
|
|
447
|
-
const result = await searchConversationSource(
|
|
448
|
-
"prebackfilltoken",
|
|
449
|
-
makeContext(),
|
|
450
|
-
5,
|
|
451
|
-
);
|
|
452
|
-
|
|
453
|
-
expect(lexicalCalls).toHaveLength(0);
|
|
454
|
-
expect(result.evidence.map((item) => item.locator)).toEqual([
|
|
455
|
-
`${match.conversation.id}#${match.message.id}`,
|
|
456
|
-
]);
|
|
457
|
-
});
|
|
458
|
-
|
|
459
|
-
test("short/punctuation-only queries return no evidence and never hit Qdrant", async () => {
|
|
460
|
-
await seedConversation({
|
|
461
|
-
title: "C++ notes",
|
|
462
|
-
role: "user",
|
|
463
|
-
content: "Use C++ when the example needs deterministic lifetime notes.",
|
|
464
|
-
});
|
|
465
|
-
|
|
466
|
-
// `C++` produces no usable ≥2-char FTS match shape. The sparse encoder
|
|
467
|
-
// would still emit a noisy 1-char `c` token, so the source must return no
|
|
468
|
-
// evidence WITHOUT querying the index. The mock throws to prove it never
|
|
469
|
-
// runs.
|
|
470
|
-
lexicalMockImpl = async () => {
|
|
471
|
-
throw new Error("searchMessageIdsLexical must not run for a short query");
|
|
472
|
-
};
|
|
473
|
-
|
|
474
|
-
const result = await searchConversationSource("C++", makeContext(), 5);
|
|
475
|
-
|
|
476
|
-
expect(lexicalCalls).toHaveLength(0);
|
|
477
|
-
expect(result.evidence).toEqual([]);
|
|
478
|
-
});
|
|
479
|
-
|
|
480
|
-
test("over-fetches a wide candidate pool from Qdrant, not the FTS prefetch window", async () => {
|
|
481
|
-
const match = await seedConversation({
|
|
482
|
-
title: "Launch notes",
|
|
483
|
-
content: "The widecandidatetoken launch checklist is recorded here.",
|
|
484
|
-
});
|
|
485
|
-
|
|
486
|
-
lexicalMockImpl = async () => [{ messageId: match.message.id, score: 0.9 }];
|
|
487
|
-
|
|
488
|
-
// limit = 5 → FTS would prefetch 5 × 5 = 25. The qdrant branch instead
|
|
489
|
-
// over-fetches max(5 × 20, 200) = 200 candidates so post-filter yield stays
|
|
490
|
-
// healthy when top lexical hits are excluded by the SQL predicates.
|
|
491
|
-
const result = await searchConversationSource(
|
|
492
|
-
"widecandidatetoken",
|
|
493
|
-
makeContext(),
|
|
494
|
-
5,
|
|
495
|
-
);
|
|
496
|
-
|
|
497
|
-
expect(lexicalCalls).toHaveLength(1);
|
|
498
|
-
expect(lexicalCalls[0]?.limit).toBe(200);
|
|
499
|
-
// Filtering still yields the correctly-scored surviving row.
|
|
500
|
-
expect(result.evidence.map((item) => item.locator)).toEqual([
|
|
501
|
-
`${match.conversation.id}#${match.message.id}`,
|
|
502
|
-
]);
|
|
503
|
-
expect(result.evidence[0]?.score).toBeGreaterThan(0);
|
|
504
|
-
});
|
|
505
|
-
|
|
506
|
-
test("returns app-scored evidence for Qdrant-supplied candidates", async () => {
|
|
507
|
-
const match = await seedConversation({
|
|
508
|
-
title: "Launch notes",
|
|
509
|
-
content: "The alpha launch checklist includes database backups.",
|
|
510
|
-
});
|
|
511
|
-
// A candidate the lexical index also surfaces but that the query does not
|
|
512
|
-
// actually match — proves the app-side scorer, not Qdrant order, ranks.
|
|
513
|
-
const weak = await seedConversation({
|
|
514
|
-
title: "Unrelated",
|
|
515
|
-
content: "Nothing salient in this conversation at all.",
|
|
516
|
-
});
|
|
517
|
-
|
|
518
|
-
lexicalMockImpl = async () => [
|
|
519
|
-
{ messageId: weak.message.id, score: 0.9 },
|
|
520
|
-
{ messageId: match.message.id, score: 0.1 },
|
|
521
|
-
];
|
|
522
|
-
|
|
523
|
-
const result = await searchConversationSource(
|
|
524
|
-
"alpha launch",
|
|
525
|
-
makeContext(),
|
|
526
|
-
5,
|
|
527
|
-
);
|
|
528
|
-
|
|
529
|
-
expect(result.evidence[0]).toMatchObject({
|
|
530
|
-
id: `conversations:${match.conversation.id}:${match.message.id}`,
|
|
531
|
-
source: "conversations",
|
|
532
|
-
title: "Launch notes",
|
|
533
|
-
locator: `${match.conversation.id}#${match.message.id}`,
|
|
534
|
-
excerpt: "The alpha launch checklist includes database backups.",
|
|
535
|
-
metadata: {
|
|
536
|
-
role: "assistant",
|
|
537
|
-
conversationId: match.conversation.id,
|
|
538
|
-
},
|
|
539
|
-
});
|
|
540
|
-
expect(result.evidence[0]?.score).toBeGreaterThan(
|
|
541
|
-
result.evidence[1]?.score ?? -1,
|
|
542
|
-
);
|
|
543
|
-
});
|
|
544
|
-
|
|
545
|
-
test("applies source, type, and excluded-conversation filters to Qdrant candidates", async () => {
|
|
546
|
-
const visible = await seedConversation({
|
|
547
|
-
title: "User conversation",
|
|
548
|
-
content: "derivedtoken belongs to a user-authored conversation.",
|
|
549
|
-
});
|
|
550
|
-
const subagent = await seedConversation({
|
|
551
|
-
title: "Subagent conversation",
|
|
552
|
-
source: "subagent",
|
|
553
|
-
content: "derivedtoken should not include subagent output.",
|
|
554
|
-
});
|
|
555
|
-
const autoAnalysis = await seedConversation({
|
|
556
|
-
title: "Auto-analysis conversation",
|
|
557
|
-
source: "auto-analysis",
|
|
558
|
-
content: "derivedtoken should not include auto-analysis output.",
|
|
559
|
-
});
|
|
560
|
-
const notification = await seedConversation({
|
|
561
|
-
title: "Notification conversation",
|
|
562
|
-
source: "notification",
|
|
563
|
-
content: "derivedtoken should not include notification output.",
|
|
564
|
-
});
|
|
565
|
-
const current = await seedConversation({
|
|
566
|
-
title: "Current conversation",
|
|
567
|
-
content: "derivedtoken appears in the active conversation.",
|
|
568
|
-
});
|
|
569
|
-
const legacyPrivate = await seedConversation({
|
|
570
|
-
title: "Legacy private conversation",
|
|
571
|
-
content: "derivedtoken belongs to legacy private history.",
|
|
572
|
-
});
|
|
573
|
-
rawRun(
|
|
574
|
-
"UPDATE conversations SET conversation_type = 'private' WHERE id = ?",
|
|
575
|
-
legacyPrivate.conversation.id,
|
|
576
|
-
);
|
|
577
|
-
|
|
578
|
-
// The lexical index does not filter — it hands back every candidate,
|
|
579
|
-
// including the ones SQL must exclude.
|
|
580
|
-
lexicalMockImpl = async () => [
|
|
581
|
-
{ messageId: visible.message.id, score: 0.9 },
|
|
582
|
-
{ messageId: subagent.message.id, score: 0.85 },
|
|
583
|
-
{ messageId: autoAnalysis.message.id, score: 0.8 },
|
|
584
|
-
{ messageId: notification.message.id, score: 0.75 },
|
|
585
|
-
{ messageId: current.message.id, score: 0.7 },
|
|
586
|
-
{ messageId: legacyPrivate.message.id, score: 0.65 },
|
|
587
|
-
];
|
|
588
|
-
|
|
589
|
-
const result = await searchConversationSource(
|
|
590
|
-
"derivedtoken",
|
|
591
|
-
makeContext({ conversationId: current.conversation.id }),
|
|
592
|
-
10,
|
|
593
|
-
);
|
|
594
|
-
|
|
595
|
-
expect(result.evidence.map((item) => item.locator)).toEqual([
|
|
596
|
-
`${visible.conversation.id}#${visible.message.id}`,
|
|
597
|
-
]);
|
|
598
|
-
});
|
|
599
|
-
|
|
600
483
|
test("returns no evidence when the Qdrant lookup throws", async () => {
|
|
601
484
|
await seedConversation({
|
|
602
485
|
title: "Failure notes",
|