@vellumai/assistant 0.10.7-dev.202607100051.bd9658e → 0.10.7-dev.202607100313.fffdfea

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.
Files changed (201) hide show
  1. package/ARCHITECTURE.md +1 -2
  2. package/docs/architecture/memory.md +1 -3
  3. package/openapi.yaml +1 -222
  4. package/package.json +1 -1
  5. package/scripts/memory-inspect.ts +2 -8
  6. package/src/__tests__/approval-routes-http.test.ts +0 -8
  7. package/src/__tests__/background-workers-disk-pressure.test.ts +4 -2
  8. package/src/__tests__/compaction-events.test.ts +0 -4
  9. package/src/__tests__/context-search-memory-source.test.ts +0 -1
  10. package/src/__tests__/conversation-agent-loop-disk-pressure.test.ts +0 -1
  11. package/src/__tests__/conversation-agent-loop-inference-profile.test.ts +0 -2
  12. package/src/__tests__/conversation-agent-loop-overflow.test.ts +0 -2
  13. package/src/__tests__/conversation-agent-loop.test.ts +0 -4
  14. package/src/__tests__/conversation-app-control-lifecycle.test.ts +0 -4
  15. package/src/__tests__/conversation-fork-crud.test.ts +18 -5
  16. package/src/__tests__/conversation-fork-retrospective.test.ts +483 -0
  17. package/src/__tests__/conversation-routes-disk-view.test.ts +0 -4
  18. package/src/__tests__/conversation-store.test.ts +0 -10
  19. package/src/__tests__/conversation-summarize-up-to.test.ts +0 -4
  20. package/src/__tests__/graph-extraction-event-date.test.ts +0 -9
  21. package/src/__tests__/injection-block.test.ts +0 -1
  22. package/src/__tests__/job-handler-registration-guard.test.ts +0 -1
  23. package/src/__tests__/lexical-index-dual-write.test.ts +2 -2
  24. package/src/__tests__/llm-resolver.test.ts +0 -1
  25. package/src/__tests__/messages-after-tiebreaker.test.ts +0 -1
  26. package/src/__tests__/playbook-execution.test.ts +2 -26
  27. package/src/__tests__/plugin-import-boundary-guard.test.ts +0 -4
  28. package/src/__tests__/plugin-import-boundary-reverse-guard.test.ts +0 -2
  29. package/src/__tests__/proxy-approval-callback.test.ts +0 -1
  30. package/src/__tests__/rebuild-index-graph-nodes.test.ts +0 -4
  31. package/src/__tests__/send-endpoint-busy.test.ts +0 -12
  32. package/src/__tests__/subagent-fork-spawn.test.ts +0 -37
  33. package/src/__tests__/task-memory-cleanup.test.ts +0 -11
  34. package/src/__tests__/voice-scoped-grant-consumer.test.ts +0 -1
  35. package/src/__tests__/voice-session-bridge.test.ts +0 -56
  36. package/src/__tests__/workspace-migration-009-backfill-conversation-disk-view.test.ts +0 -1
  37. package/src/__tests__/workspace-migration-013-repair-conversation-disk-view.test.ts +0 -1
  38. package/src/__tests__/workspace-migration-028-recover-conversations-from-disk-view.test.ts +0 -1
  39. package/src/__tests__/workspace-migration-129-remove-analyze-conversation-config.test.ts +190 -0
  40. package/src/cli/commands/db/repair-step-conversation-backfill.ts +0 -1
  41. package/src/config/bundled-skills/messaging/tools/messaging-analyze-style.ts +0 -6
  42. package/src/config/bundled-skills/playbooks/tools/playbook-create.ts +0 -3
  43. package/src/config/bundled-skills/playbooks/tools/playbook-delete.ts +0 -3
  44. package/src/config/bundled-skills/playbooks/tools/playbook-list.ts +1 -3
  45. package/src/config/bundled-skills/playbooks/tools/playbook-update.ts +0 -4
  46. package/src/config/call-site-defaults.ts +0 -1
  47. package/src/config/feature-flag-registry.json +0 -16
  48. package/src/config/schema.ts +0 -3
  49. package/src/config/schemas/call-site-catalog.ts +0 -6
  50. package/src/config/schemas/llm.ts +0 -1
  51. package/src/conversations/job-handlers/summarization.ts +0 -2
  52. package/src/daemon/conversation-agent-loop-handlers.ts +0 -1
  53. package/src/daemon/conversation-agent-loop.ts +1 -6
  54. package/src/daemon/conversation-lifecycle.ts +0 -14
  55. package/src/daemon/conversation-turn-finalize.ts +0 -1
  56. package/src/daemon/handlers/shared.ts +1 -2
  57. package/src/export/transcript-formatter.ts +9 -39
  58. package/src/home/conversation-starter-checkpoints.ts +9 -5
  59. package/src/home/job-handlers/conversation-starters.ts +24 -54
  60. package/src/hooks/types.ts +2 -2
  61. package/src/ipc/routes/__tests__/memory-v2-backfill.test.ts +5 -7
  62. package/src/persistence/__tests__/bulk-write-gate.test.ts +165 -0
  63. package/src/persistence/__tests__/immediate-transaction-guard.test.ts +70 -0
  64. package/src/persistence/auto-analysis-constants.ts +4 -13
  65. package/src/persistence/bulk-write-gate.ts +82 -0
  66. package/src/persistence/conversation-bootstrap.ts +3 -3
  67. package/src/persistence/conversation-crud.ts +158 -80
  68. package/src/persistence/conversation-key-store.ts +0 -2
  69. package/src/persistence/conversation-row-batch-delete.ts +16 -1
  70. package/src/persistence/conversation-types.ts +12 -1
  71. package/src/persistence/db-async-query.ts +18 -9
  72. package/src/persistence/db-connection.ts +20 -4
  73. package/src/persistence/db-maintenance.ts +78 -6
  74. package/src/persistence/fork-message-copy.ts +18 -4
  75. package/src/persistence/jobs-store.ts +3 -86
  76. package/src/persistence/migrations/323-delete-non-default-memory-scopes.test.ts +148 -0
  77. package/src/persistence/migrations/323-delete-non-default-memory-scopes.ts +35 -0
  78. package/src/persistence/schema/conversations.ts +0 -1
  79. package/src/persistence/schema/memory-core.ts +17 -28
  80. package/src/persistence/schema/memory-graph.ts +0 -4
  81. package/src/persistence/schema/tasks.ts +0 -1
  82. package/src/persistence/steps.ts +2 -0
  83. package/src/playbooks/playbook-compiler.ts +2 -10
  84. package/src/plugins/defaults/memory/__tests__/db-maintenance.test.ts +105 -11
  85. package/src/plugins/defaults/memory/__tests__/jobs-store-enqueue-gate.test.ts +7 -62
  86. package/src/plugins/defaults/memory/__tests__/memory-retrospective-job.test.ts +47 -5
  87. package/src/plugins/defaults/memory/__tests__/memory-retrospective-skill-card.test.ts +29 -1
  88. package/src/plugins/defaults/memory/__tests__/memory-retrospective-startup-cleanup.test.ts +133 -70
  89. package/src/plugins/defaults/memory/activation-session-store.ts +1 -1
  90. package/src/plugins/defaults/memory/config.ts +1 -1
  91. package/src/plugins/defaults/memory/context-search/sources/conversations.ts +1 -1
  92. package/src/plugins/defaults/memory/context-search/sources/memory-v2.ts +1 -1
  93. package/src/plugins/defaults/memory/context-search/sources/memory.ts +1 -1
  94. package/src/plugins/defaults/memory/filing-jobs.ts +1 -1
  95. package/src/plugins/defaults/memory/fork-conversation-memory.ts +8 -4
  96. package/src/plugins/defaults/memory/frontmatter.ts +1 -1
  97. package/src/plugins/defaults/memory/graph/bootstrap.ts +12 -18
  98. package/src/plugins/defaults/memory/graph/capability-seed.ts +4 -18
  99. package/src/plugins/defaults/memory/graph/consolidation.ts +7 -14
  100. package/src/plugins/defaults/memory/graph/conversation-graph-memory.ts +1 -3
  101. package/src/plugins/defaults/memory/graph/decay.ts +5 -10
  102. package/src/plugins/defaults/memory/graph/extraction-job.ts +2 -3
  103. package/src/plugins/defaults/memory/graph/extraction.test.ts +1 -9
  104. package/src/plugins/defaults/memory/graph/extraction.ts +1 -8
  105. package/src/plugins/defaults/memory/graph/graph-search.ts +1 -1
  106. package/src/plugins/defaults/memory/graph/injection.test.ts +0 -1
  107. package/src/plugins/defaults/memory/graph/injection.ts +1 -1
  108. package/src/plugins/defaults/memory/graph/narrative.ts +1 -3
  109. package/src/plugins/defaults/memory/graph/pattern-scan.ts +1 -4
  110. package/src/plugins/defaults/memory/graph/retriever.test.ts +0 -19
  111. package/src/plugins/defaults/memory/graph/retriever.ts +6 -14
  112. package/src/plugins/defaults/memory/graph/scoring.test.ts +0 -1
  113. package/src/plugins/defaults/memory/graph/store.test.ts +6 -58
  114. package/src/plugins/defaults/memory/graph/store.ts +5 -43
  115. package/src/plugins/defaults/memory/graph/tool-handlers.ts +1 -5
  116. package/src/plugins/defaults/memory/graph/types.ts +0 -3
  117. package/src/plugins/defaults/memory/hooks/init.ts +1 -1
  118. package/src/plugins/defaults/memory/indexer.ts +2 -45
  119. package/src/plugins/defaults/memory/injectors.ts +1 -1
  120. package/src/plugins/defaults/memory/job-handler-registration.ts +0 -4
  121. package/src/plugins/defaults/memory/job-handlers/backfill.ts +0 -1
  122. package/src/plugins/defaults/memory/job-handlers/index-maintenance.ts +1 -1
  123. package/src/plugins/defaults/memory/job-handlers.ts +5 -9
  124. package/src/plugins/defaults/memory/jobs/embed-concept-page.ts +1 -1
  125. package/src/plugins/defaults/memory/jobs-worker.ts +21 -9
  126. package/src/plugins/defaults/memory/logging.ts +17 -0
  127. package/src/plugins/defaults/memory/memory-retrospective-constants.ts +10 -7
  128. package/src/plugins/defaults/memory/memory-retrospective-enqueue.ts +5 -6
  129. package/src/plugins/defaults/memory/memory-retrospective-fork-boundary.ts +57 -20
  130. package/src/plugins/defaults/memory/memory-retrospective-job.ts +13 -15
  131. package/src/plugins/defaults/memory/memory-retrospective-skill-card.ts +2 -2
  132. package/src/plugins/defaults/memory/memory-retrospective-startup-cleanup.ts +52 -39
  133. package/src/plugins/defaults/memory/memory-retrospective-trigger-check.ts +1 -1
  134. package/src/plugins/defaults/memory/pkb/pkb-reconcile.ts +1 -1
  135. package/src/plugins/defaults/memory/pkb/pkb-search.ts +1 -1
  136. package/src/plugins/defaults/memory/rerank-local.ts +1 -1
  137. package/src/plugins/defaults/memory/routes/memory-eval-routes.ts +1 -1
  138. package/src/plugins/defaults/memory/routes/memory-item-routes.test.ts +0 -1
  139. package/src/plugins/defaults/memory/routes/memory-item-routes.ts +3 -11
  140. package/src/plugins/defaults/memory/routes/memory-v2-routes.ts +1 -1
  141. package/src/plugins/defaults/memory/routes/memory-v3-routes.ts +1 -1
  142. package/src/plugins/defaults/memory/startup.ts +1 -1
  143. package/src/plugins/defaults/memory/task-memory-cleanup.ts +1 -1
  144. package/src/plugins/defaults/memory/v2/backfill-jobs.ts +1 -1
  145. package/src/plugins/defaults/memory/v2/cli-command-store.ts +1 -1
  146. package/src/plugins/defaults/memory/v2/consolidation-job.ts +1 -1
  147. package/src/plugins/defaults/memory/v2/frontmatter-sweep.ts +1 -1
  148. package/src/plugins/defaults/memory/v2/injection-events.ts +1 -1
  149. package/src/plugins/defaults/memory/v2/injection.ts +1 -1
  150. package/src/plugins/defaults/memory/v2/memory-v2-startup.ts +1 -1
  151. package/src/plugins/defaults/memory/v2/migration.ts +1 -1
  152. package/src/plugins/defaults/memory/v2/page-index.ts +1 -1
  153. package/src/plugins/defaults/memory/v2/prompts/consolidation.ts +1 -1
  154. package/src/plugins/defaults/memory/v2/prompts/router.ts +1 -1
  155. package/src/plugins/defaults/memory/v2/qdrant.ts +1 -1
  156. package/src/plugins/defaults/memory/v2/reranker.ts +1 -1
  157. package/src/plugins/defaults/memory/v2/router.ts +1 -1
  158. package/src/plugins/defaults/memory/v2/skill-store.ts +1 -1
  159. package/src/plugins/defaults/memory/v2/sweep-job.ts +1 -1
  160. package/src/plugins/defaults/memory/v3/candidate-match.ts +1 -1
  161. package/src/plugins/defaults/memory/v3/dense.ts +1 -1
  162. package/src/plugins/defaults/memory/v3/injector.ts +1 -1
  163. package/src/plugins/defaults/memory/v3/maintain-job.ts +1 -1
  164. package/src/plugins/defaults/memory/v3/orchestrate.ts +1 -1
  165. package/src/plugins/defaults/memory/v3/pool-select.ts +1 -1
  166. package/src/plugins/defaults/memory/v3/prune.ts +1 -1
  167. package/src/plugins/defaults/memory/v3/section-dense-store.ts +1 -1
  168. package/src/plugins/defaults/memory/v3/shadow-plugin.ts +1 -1
  169. package/src/plugins/defaults/memory/worker.ts +1 -1
  170. package/src/runtime/capabilities.ts +1 -1
  171. package/src/runtime/routes/__tests__/bookmark-routes.test.ts +0 -1
  172. package/src/runtime/routes/__tests__/conversation-management-routes.test.ts +0 -1
  173. package/src/runtime/routes/__tests__/conversation-query-routes.test.ts +0 -1
  174. package/src/runtime/routes/conversation-starter-routes.ts +12 -23
  175. package/src/runtime/routes/index.ts +0 -2
  176. package/src/runtime/services/__tests__/auto-analysis-guard.test.ts +1 -8
  177. package/src/runtime/services/__tests__/conversation-serializer.test.ts +0 -1
  178. package/src/runtime/services/auto-analysis-guard.ts +5 -5
  179. package/src/runtime/services/conversation-serializer.ts +2 -3
  180. package/src/tasks/SPEC.md +10 -17
  181. package/src/tools/tool-types.ts +0 -2
  182. package/src/workspace/migrations/028-recover-conversations-from-disk-view.ts +0 -1
  183. package/src/workspace/migrations/129-remove-analyze-conversation-config.ts +59 -0
  184. package/src/workspace/migrations/registry.ts +2 -0
  185. package/src/__tests__/auto-analysis-end-to-end.test.ts +0 -621
  186. package/src/__tests__/auto-analysis-prompt.test.ts +0 -50
  187. package/src/__tests__/config-analysis.test.ts +0 -83
  188. package/src/__tests__/conversation-analysis-routes.test.ts +0 -156
  189. package/src/config/schemas/analysis.ts +0 -32
  190. package/src/daemon/__tests__/conversation-lifecycle-auto-analyze.test.ts +0 -449
  191. package/src/plugins/defaults/memory/__tests__/find-analysis-conversation.test.ts +0 -197
  192. package/src/runtime/routes/conversation-analysis-routes.ts +0 -75
  193. package/src/runtime/services/__tests__/analyze-conversation.test.ts +0 -477
  194. package/src/runtime/services/__tests__/auto-analysis-enqueue.test.ts +0 -386
  195. package/src/runtime/services/__tests__/auto-analysis-prompt.test.ts +0 -53
  196. package/src/runtime/services/__tests__/conversation-analyze-job.test.ts +0 -213
  197. package/src/runtime/services/__tests__/manual-analysis-prompt.test.ts +0 -41
  198. package/src/runtime/services/analyze-conversation.ts +0 -334
  199. package/src/runtime/services/auto-analysis-enqueue.ts +0 -130
  200. package/src/runtime/services/auto-analysis-prompt.ts +0 -55
  201. package/src/runtime/services/conversation-analyze-job.ts +0 -53
@@ -19,11 +19,14 @@ mock.module("../config/loader.js", () => ({
19
19
  }),
20
20
  }));
21
21
 
22
+ import { eq } from "drizzle-orm";
23
+
22
24
  import {
23
25
  getAttachmentsForMessage,
24
26
  linkAttachmentToMessage,
25
27
  uploadAttachment,
26
28
  } from "../persistence/attachments-store.js";
29
+ import { appendCompactionEvent } from "../persistence/compaction-ledger-store.js";
27
30
  import {
28
31
  addMessage,
29
32
  createConversation,
@@ -43,17 +46,28 @@ import {
43
46
  activationState,
44
47
  channelInboundEvents,
45
48
  conversationAssistantAttentionState,
49
+ conversationCompactionEvents,
46
50
  conversationGraphMemoryState,
51
+ conversations,
47
52
  externalConversationBindings,
48
53
  llmRequestLogs,
49
54
  memoryJobs,
50
55
  memoryRetrospectiveState,
56
+ messages,
51
57
  toolInvocations,
52
58
  } from "../persistence/schema/index.js";
53
59
  import {
54
60
  loadGraphMemoryState,
55
61
  saveGraphMemoryState,
56
62
  } from "../plugins/defaults/memory/graph/graph-memory-state-store.js";
63
+ import {
64
+ MEMORY_RETROSPECTIVE_FORK_SOURCE,
65
+ MEMORY_RETROSPECTIVE_INSTRUCTION_KIND,
66
+ } from "../plugins/defaults/memory/memory-retrospective-constants.js";
67
+ import {
68
+ findForkBoundaryCreatedAt,
69
+ loadRetrospectiveRunMessages,
70
+ } from "../plugins/defaults/memory/memory-retrospective-fork-boundary.js";
57
71
 
58
72
  await initializeDb();
59
73
 
@@ -71,6 +85,7 @@ function resetTables(): void {
71
85
  db.run("DELETE FROM memory_v3_ever_injected");
72
86
  db.run("DELETE FROM message_attachments");
73
87
  db.run("DELETE FROM attachments");
88
+ db.run("DELETE FROM conversation_compaction_events");
74
89
  db.run("DELETE FROM messages");
75
90
  db.run("DELETE FROM conversations");
76
91
  }
@@ -248,3 +263,471 @@ describe("forkConversationForRetrospective", () => {
248
263
  expect(countConversations()).toBe(before);
249
264
  });
250
265
  });
266
+
267
+ describe("forkConversationForRetrospective — compacted source", () => {
268
+ beforeEach(() => {
269
+ resetTables();
270
+ });
271
+
272
+ interface CompactedSource {
273
+ id: string;
274
+ summary: string;
275
+ compactedAt: number;
276
+ compactedCount: number;
277
+ base: number;
278
+ }
279
+
280
+ /**
281
+ * Six-message source with a compaction covering the first four rows.
282
+ * Timestamps are pinned so the compaction event sits strictly between
283
+ * row 4 and row 5.
284
+ */
285
+ async function seedCompactedSource(): Promise<CompactedSource> {
286
+ const source = createConversation("Compacted retro thread");
287
+ const rows = [
288
+ await addMessage(source.id, "user", "old question", {
289
+ skipIndexing: true,
290
+ }),
291
+ await addMessage(source.id, "assistant", "old answer", {
292
+ skipIndexing: true,
293
+ }),
294
+ await addMessage(source.id, "user", "older question", {
295
+ skipIndexing: true,
296
+ }),
297
+ await addMessage(source.id, "assistant", "older answer", {
298
+ skipIndexing: true,
299
+ }),
300
+ await addMessage(source.id, "user", "fresh question", {
301
+ skipIndexing: true,
302
+ }),
303
+ await addMessage(source.id, "assistant", "fresh answer", {
304
+ skipIndexing: true,
305
+ }),
306
+ ];
307
+ const db = getDb();
308
+ const base = Date.now();
309
+ rows.forEach((row, index) => {
310
+ const createdAt = index < 4 ? base + index : base + index + 10;
311
+ db.update(messages)
312
+ .set({ createdAt })
313
+ .where(eq(messages.id, row.id))
314
+ .run();
315
+ });
316
+ const compactedAt = base + 5;
317
+ const summary = "Summary of the old exchange";
318
+ db.update(conversations)
319
+ .set({
320
+ contextSummary: summary,
321
+ contextCompactedMessageCount: 4,
322
+ contextCompactedAt: compactedAt,
323
+ })
324
+ .where(eq(conversations.id, source.id))
325
+ .run();
326
+ appendCompactionEvent(source.id, {
327
+ compactedAt,
328
+ summary,
329
+ compactedMessageCount: 4,
330
+ });
331
+ return { id: source.id, summary, compactedAt, compactedCount: 4, base };
332
+ }
333
+
334
+ function contentOf(m: { role: string; content: string; createdAt: number }) {
335
+ return { role: m.role, content: m.content, createdAt: m.createdAt };
336
+ }
337
+
338
+ test("copies only the visible tail and renders identically to the source", async () => {
339
+ const source = await seedCompactedSource();
340
+ const sourceRows = getMessages(source.id);
341
+ const tip = sourceRows.at(-1)!;
342
+
343
+ const fork = await forkConversationForRetrospective({
344
+ conversationId: source.id,
345
+ throughMessageId: tip.id,
346
+ conversationType: "background",
347
+ source: MEMORY_RETROSPECTIVE_FORK_SOURCE,
348
+ });
349
+
350
+ // Physical rows: the visible tail only, each stamped with its source id.
351
+ const forkRows = getMessages(fork.id);
352
+ expect(forkRows.map(contentOf)).toEqual(sourceRows.slice(4).map(contentOf));
353
+ expect(
354
+ forkRows.map(
355
+ (m) =>
356
+ (JSON.parse(m.metadata!) as { forkSourceMessageId: string })
357
+ .forkSourceMessageId,
358
+ ),
359
+ ).toEqual(sourceRows.slice(4).map((m) => m.id));
360
+
361
+ // Fork row: inherited summary + timestamp, fork-local count of 0.
362
+ expect(fork.contextSummary).toBe(source.summary);
363
+ expect(fork.contextCompactedMessageCount).toBe(0);
364
+ expect(fork.contextCompactedAt).toBe(source.compactedAt);
365
+ expect(fork.forkParentMessageId).toBe(tip.id);
366
+
367
+ // Rendered history — summary + post-slice rows, assembled the way
368
+ // `loadFromDb` does — is identical to the source's.
369
+ const render = (
370
+ summary: string | null,
371
+ rows: Array<{ role: string; content: string; createdAt: number }>,
372
+ count: number,
373
+ ) => [summary, ...rows.slice(Math.min(count, rows.length)).map(contentOf)];
374
+ expect(
375
+ render(fork.contextSummary, forkRows, fork.contextCompactedMessageCount),
376
+ ).toEqual(render(source.summary, sourceRows, source.compactedCount));
377
+
378
+ // The synchronous user fork keeps the full physical history.
379
+ const syncFork = forkConversation({
380
+ conversationId: source.id,
381
+ throughMessageId: tip.id,
382
+ });
383
+ expect(getMessages(syncFork.id)).toHaveLength(6);
384
+ expect(syncFork.contextCompactedMessageCount).toBe(4);
385
+ });
386
+
387
+ test("carries per-conversation memory state wholesale on a tip fork", async () => {
388
+ const source = await seedCompactedSource();
389
+ const snapshot = JSON.stringify({ inContext: ["node-a"], currentTurn: 7 });
390
+ saveGraphMemoryState(source.id, snapshot);
391
+ const everInjected = JSON.stringify([{ slug: "page-a", turn: 1 }]);
392
+ const db = getDb();
393
+ db.insert(activationState)
394
+ .values({
395
+ conversationId: source.id,
396
+ messageId: "source-turn-marker",
397
+ stateJson: "{}",
398
+ everInjectedJson: everInjected,
399
+ currentTurn: 7,
400
+ updatedAt: Date.now(),
401
+ })
402
+ .run();
403
+ getSqlite()
404
+ .query(
405
+ `INSERT INTO memory_v3_ever_injected (conversation_id, slug, injected_at, bytes, pruned_at)
406
+ VALUES (?, 'card-a', ?, 12, NULL)`,
407
+ )
408
+ .run(source.id, Date.now());
409
+
410
+ const tip = getMessages(source.id).at(-1)!;
411
+ const fork = await forkConversationForRetrospective({
412
+ conversationId: source.id,
413
+ throughMessageId: tip.id,
414
+ conversationType: "background",
415
+ source: MEMORY_RETROSPECTIVE_FORK_SOURCE,
416
+ });
417
+
418
+ // The fork's rendered window equals the source's, so activation,
419
+ // ever-injected, and graph state are carried as-is.
420
+ expect(loadGraphMemoryState(fork.id)).toBe(snapshot);
421
+ const forkActivation = db
422
+ .select()
423
+ .from(activationState)
424
+ .where(eq(activationState.conversationId, fork.id))
425
+ .get();
426
+ expect(forkActivation?.everInjectedJson).toBe(everInjected);
427
+ const v3Rows = getSqlite()
428
+ .query(
429
+ "SELECT slug FROM memory_v3_ever_injected WHERE conversation_id = ?",
430
+ )
431
+ .all(fork.id) as Array<{ slug: string }>;
432
+ expect(v3Rows.map((r) => r.slug)).toEqual(["card-a"]);
433
+ });
434
+
435
+ test("re-derives memory seeding from the copied tail on a truncated cutoff", async () => {
436
+ const source = await seedCompactedSource();
437
+ const db = getDb();
438
+ const sourceRows = getMessages(source.id);
439
+ // Injection blocks: one behind the summary, one on a visible tail row.
440
+ db.update(messages)
441
+ .set({
442
+ metadata: JSON.stringify({
443
+ memoryInjectedBlock: "# memory/concepts/prefix-slug.md",
444
+ }),
445
+ })
446
+ .where(eq(messages.id, sourceRows[0]!.id))
447
+ .run();
448
+ db.update(messages)
449
+ .set({
450
+ metadata: JSON.stringify({
451
+ memoryInjectedBlock: "# memory/concepts/tail-slug.md",
452
+ }),
453
+ })
454
+ .where(eq(messages.id, sourceRows[4]!.id))
455
+ .run();
456
+ const snapshot = JSON.stringify({ inContext: ["node-a"], currentTurn: 7 });
457
+ saveGraphMemoryState(source.id, snapshot);
458
+
459
+ // Cut off before the tip (a user row, so no display-turn extension): the
460
+ // fork is truncated and takes the derived-seeding branch.
461
+ const fork = await forkConversationForRetrospective({
462
+ conversationId: source.id,
463
+ throughMessageId: sourceRows[4]!.id,
464
+ conversationType: "background",
465
+ source: MEMORY_RETROSPECTIVE_FORK_SOURCE,
466
+ });
467
+
468
+ // The compaction slice composes with the cutoff: source row 5 only.
469
+ const forkRows = getMessages(fork.id);
470
+ expect(forkRows.map((m) => m.content)).toEqual([sourceRows[4]!.content]);
471
+ expect(fork.forkParentMessageId).toBe(sourceRows[4]!.id);
472
+
473
+ // Derived seeding sees only the copied tail's slug; the wholesale graph
474
+ // carry is skipped for truncated forks.
475
+ const forkActivation = db
476
+ .select()
477
+ .from(activationState)
478
+ .where(eq(activationState.conversationId, fork.id))
479
+ .get();
480
+ expect(forkActivation?.everInjectedJson).toBe(
481
+ JSON.stringify([{ slug: "tail-slug", turn: 0 }]),
482
+ );
483
+ expect(loadGraphMemoryState(fork.id)).toBeNull();
484
+ });
485
+
486
+ test("seeds a single count-adjusted ledger event instead of copying the source ledger", async () => {
487
+ const source = await seedCompactedSource();
488
+ // An older superseded event on the source; it must not be copied either.
489
+ appendCompactionEvent(source.id, {
490
+ compactedAt: source.base + 1,
491
+ summary: "Older summary",
492
+ compactedMessageCount: 2,
493
+ });
494
+
495
+ const tip = getMessages(source.id).at(-1)!;
496
+ const fork = await forkConversationForRetrospective({
497
+ conversationId: source.id,
498
+ throughMessageId: tip.id,
499
+ conversationType: "background",
500
+ source: MEMORY_RETROSPECTIVE_FORK_SOURCE,
501
+ });
502
+
503
+ const forkEvents = getDb()
504
+ .select()
505
+ .from(conversationCompactionEvents)
506
+ .where(eq(conversationCompactionEvents.conversationId, fork.id))
507
+ .all();
508
+ expect(forkEvents).toHaveLength(1);
509
+ expect(forkEvents[0]).toMatchObject({
510
+ compactedAt: source.compactedAt,
511
+ summary: source.summary,
512
+ compactedMessageCount: 0,
513
+ });
514
+
515
+ // A fork of the fork at its tip inherits the summary with the fork-local
516
+ // count — no rows are hidden behind it.
517
+ const forkTip = getMessages(fork.id).at(-1)!;
518
+ const grandchild = forkConversation({
519
+ conversationId: fork.id,
520
+ throughMessageId: forkTip.id,
521
+ });
522
+ expect(grandchild.contextSummary).toBe(source.summary);
523
+ expect(grandchild.contextCompactedMessageCount).toBe(0);
524
+ expect(getMessages(grandchild.id)).toHaveLength(
525
+ getMessages(fork.id).length,
526
+ );
527
+ });
528
+
529
+ test("post-fork tail extraction still detects the copied boundary", async () => {
530
+ const source = await seedCompactedSource();
531
+ const tip = getMessages(source.id).at(-1)!;
532
+ const fork = await forkConversationForRetrospective({
533
+ conversationId: source.id,
534
+ throughMessageId: tip.id,
535
+ conversationType: "background",
536
+ source: MEMORY_RETROSPECTIVE_FORK_SOURCE,
537
+ });
538
+
539
+ const boundary = findForkBoundaryCreatedAt(getMessages(fork.id));
540
+ expect(boundary).toBe(tip.createdAt);
541
+
542
+ // A run-authored message lands after the boundary and is the only row
543
+ // attributed to the run.
544
+ const runMessage = await addMessage(fork.id, "user", "retro instruction", {
545
+ skipIndexing: true,
546
+ });
547
+ getDb()
548
+ .update(messages)
549
+ .set({ createdAt: tip.createdAt + 100 })
550
+ .where(eq(messages.id, runMessage.id))
551
+ .run();
552
+ const runRows = await loadRetrospectiveRunMessages(
553
+ fork.id,
554
+ MEMORY_RETROSPECTIVE_FORK_SOURCE,
555
+ );
556
+ expect(runRows?.map((m) => m.id)).toEqual([runMessage.id]);
557
+ });
558
+
559
+ test("succeeds with an empty tail when the compaction covers the whole cutoff range", async () => {
560
+ const source = await seedCompactedSource();
561
+ const db = getDb();
562
+ const sourceRows = getMessages(source.id);
563
+ const tip = sourceRows.at(-1)!;
564
+ // A later compaction covering every row, timestamped exactly at the tip.
565
+ db.update(conversations)
566
+ .set({
567
+ contextSummary: "Everything summarized",
568
+ contextCompactedMessageCount: sourceRows.length,
569
+ contextCompactedAt: tip.createdAt,
570
+ })
571
+ .where(eq(conversations.id, source.id))
572
+ .run();
573
+ appendCompactionEvent(source.id, {
574
+ compactedAt: tip.createdAt,
575
+ summary: "Everything summarized",
576
+ compactedMessageCount: sourceRows.length,
577
+ });
578
+
579
+ const fork = await forkConversationForRetrospective({
580
+ conversationId: source.id,
581
+ throughMessageId: tip.id,
582
+ conversationType: "background",
583
+ source: MEMORY_RETROSPECTIVE_FORK_SOURCE,
584
+ });
585
+
586
+ expect(getMessages(fork.id)).toHaveLength(0);
587
+ expect(fork.contextSummary).toBe("Everything summarized");
588
+ expect(fork.contextCompactedMessageCount).toBe(0);
589
+ expect(fork.contextCompactedAt).toBe(tip.createdAt);
590
+ expect(fork.forkParentMessageId).toBe(tip.id);
591
+ // Ageable despite copying no rows, so the startup orphan sweep (which
592
+ // skips null `lastMessageAt` rows) can reclaim it after a crash.
593
+ expect(fork.lastMessageAt).toBe(tip.createdAt);
594
+
595
+ // With no stamped copied rows and the run's instruction opening the
596
+ // conversation, every message is the run's own output — it still feeds
597
+ // the success bookkeeping (dedup baseline, skill cards).
598
+ const runMessage = await addMessage(fork.id, "user", "retro instruction", {
599
+ metadata: {
600
+ kind: MEMORY_RETROSPECTIVE_INSTRUCTION_KIND,
601
+ hidden: true,
602
+ },
603
+ skipIndexing: true,
604
+ });
605
+ const runRows = await loadRetrospectiveRunMessages(
606
+ fork.id,
607
+ MEMORY_RETROSPECTIVE_FORK_SOURCE,
608
+ );
609
+ expect(runRows?.map((m) => m.id)).toEqual([runMessage.id]);
610
+ });
611
+
612
+ test("drops the render-hidden rows on createdAt ties, not the re-sort prefix", async () => {
613
+ const source = createConversation("Tie-boundary thread");
614
+ const first = await addMessage(source.id, "user", "hidden by compaction", {
615
+ skipIndexing: true,
616
+ });
617
+ const second = await addMessage(source.id, "assistant", "still visible", {
618
+ skipIndexing: true,
619
+ });
620
+ const tail = await addMessage(source.id, "user", "fresh tail", {
621
+ skipIndexing: true,
622
+ });
623
+
624
+ // The first two rows share a millisecond, with ids crafted so the cutoff
625
+ // re-sort's `(createdAt, id)` order REVERSES their insertion (= render)
626
+ // order. The compaction hides exactly one row: in render order that is
627
+ // `first`; a positional slice of the re-sorted array would drop `second`
628
+ // instead.
629
+ const db = getDb();
630
+ const base = Date.now();
631
+ db.update(messages)
632
+ .set({ id: "zz-tie-first", createdAt: base })
633
+ .where(eq(messages.id, first.id))
634
+ .run();
635
+ db.update(messages)
636
+ .set({ id: "aa-tie-second", createdAt: base })
637
+ .where(eq(messages.id, second.id))
638
+ .run();
639
+ db.update(messages)
640
+ .set({ createdAt: base + 10 })
641
+ .where(eq(messages.id, tail.id))
642
+ .run();
643
+ const compactedAt = base + 5;
644
+ db.update(conversations)
645
+ .set({
646
+ contextSummary: "Tie summary",
647
+ contextCompactedMessageCount: 1,
648
+ contextCompactedAt: compactedAt,
649
+ })
650
+ .where(eq(conversations.id, source.id))
651
+ .run();
652
+ appendCompactionEvent(source.id, {
653
+ compactedAt,
654
+ summary: "Tie summary",
655
+ compactedMessageCount: 1,
656
+ });
657
+
658
+ const fork = await forkConversationForRetrospective({
659
+ conversationId: source.id,
660
+ throughMessageId: tail.id,
661
+ conversationType: "background",
662
+ source: MEMORY_RETROSPECTIVE_FORK_SOURCE,
663
+ });
664
+
665
+ // The source renders ["still visible", "fresh tail"] after its slice;
666
+ // the fork must carry exactly those rows.
667
+ expect(getMessages(fork.id).map((m) => m.content)).toEqual([
668
+ "still visible",
669
+ "fresh tail",
670
+ ]);
671
+ });
672
+
673
+ test("seeds the fork-local ledger event even when the hidden prefix falls outside the cutoff", async () => {
674
+ const source = createConversation("Tie-cutoff thread");
675
+ const hidden = await addMessage(source.id, "user", "hidden by compaction", {
676
+ skipIndexing: true,
677
+ });
678
+ const requested = await addMessage(source.id, "assistant", "visible", {
679
+ skipIndexing: true,
680
+ });
681
+
682
+ // Same-millisecond rows with ids crafted so the `(createdAt, id)` cutoff
683
+ // order puts the requested message BEFORE the render-hidden sibling: the
684
+ // cutoff range then contains no hidden row, so nothing is dropped, but
685
+ // the fork still inherits the compaction and must not copy the source's
686
+ // count-1 ledger event (a fork of this fork would hide a visible row).
687
+ const db = getDb();
688
+ const base = Date.now();
689
+ db.update(messages)
690
+ .set({ id: "zz-tie-hidden", createdAt: base })
691
+ .where(eq(messages.id, hidden.id))
692
+ .run();
693
+ db.update(messages)
694
+ .set({ id: "aa-tie-requested", createdAt: base })
695
+ .where(eq(messages.id, requested.id))
696
+ .run();
697
+ db.update(conversations)
698
+ .set({
699
+ contextSummary: "Tie summary",
700
+ contextCompactedMessageCount: 1,
701
+ contextCompactedAt: base,
702
+ })
703
+ .where(eq(conversations.id, source.id))
704
+ .run();
705
+ appendCompactionEvent(source.id, {
706
+ compactedAt: base,
707
+ summary: "Tie summary",
708
+ compactedMessageCount: 1,
709
+ });
710
+
711
+ const fork = await forkConversationForRetrospective({
712
+ conversationId: source.id,
713
+ throughMessageId: "aa-tie-requested",
714
+ conversationType: "background",
715
+ source: MEMORY_RETROSPECTIVE_FORK_SOURCE,
716
+ });
717
+
718
+ expect(getMessages(fork.id).map((m) => m.content)).toEqual(["visible"]);
719
+ expect(fork.contextSummary).toBe("Tie summary");
720
+ expect(fork.contextCompactedMessageCount).toBe(0);
721
+ const forkEvents = getDb()
722
+ .select()
723
+ .from(conversationCompactionEvents)
724
+ .where(eq(conversationCompactionEvents.conversationId, fork.id))
725
+ .all();
726
+ expect(forkEvents).toHaveLength(1);
727
+ expect(forkEvents[0]).toMatchObject({
728
+ compactedAt: base,
729
+ summary: "Tie summary",
730
+ compactedMessageCount: 0,
731
+ });
732
+ });
733
+ });
@@ -146,10 +146,6 @@ function createFakeConversation(conversationId: string): Conversation {
146
146
  messages: [] as Array<unknown>,
147
147
  hostCuProxy: undefined as unknown,
148
148
  usageStats: { inputTokens: 0, outputTokens: 0, estimatedCost: 0 },
149
- memoryPolicy: {
150
- scopeId: "default",
151
- includeDefaultFallback: false,
152
- },
153
149
  isProcessing(this: { processing: boolean }) {
154
150
  return this.processing;
155
151
  },
@@ -467,17 +467,11 @@ describe("conversation metadata defaults", () => {
467
467
  expect(conv.conversationType).toBe("standard");
468
468
  });
469
469
 
470
- test("new conversation has memoryScopeId defaulting to default", () => {
471
- const conv = createConversation("test");
472
- expect(conv.memoryScopeId).toBe("default");
473
- });
474
-
475
470
  test("defaults are persisted and retrievable from DB", () => {
476
471
  const conv = createConversation("test");
477
472
  const loaded = getConversation(conv.id);
478
473
  expect(loaded).not.toBeNull();
479
474
  expect(loaded!.conversationType).toBe("standard");
480
- expect(loaded!.memoryScopeId).toBe("default");
481
475
  });
482
476
 
483
477
  test("existing conversations without explicit values get defaults via migration", () => {
@@ -493,7 +487,6 @@ describe("conversation metadata defaults", () => {
493
487
  const loaded = getConversation(id);
494
488
  expect(loaded).not.toBeNull();
495
489
  expect(loaded!.conversationType).toBe("standard");
496
- expect(loaded!.memoryScopeId).toBe("default");
497
490
  });
498
491
  });
499
492
 
@@ -508,7 +501,6 @@ describe("createConversation with conversation type option", () => {
508
501
  const conv = createConversation("hello");
509
502
  expect(conv.title).toBe("hello");
510
503
  expect(conv.conversationType).toBe("standard");
511
- expect(conv.memoryScopeId).toBe("default");
512
504
  });
513
505
 
514
506
  test("standard create with options object uses defaults", () => {
@@ -517,13 +509,11 @@ describe("createConversation with conversation type option", () => {
517
509
  conversationType: "standard",
518
510
  });
519
511
  expect(conv.conversationType).toBe("standard");
520
- expect(conv.memoryScopeId).toBe("default");
521
512
  });
522
513
 
523
514
  test("no-arg create uses defaults", () => {
524
515
  const conv = createConversation();
525
516
  expect(conv.conversationType).toBe("standard");
526
- expect(conv.memoryScopeId).toBe("default");
527
517
  });
528
518
  });
529
519
 
@@ -240,10 +240,6 @@ mock.module("../persistence/llm-usage-store.js", () => ({
240
240
  listUsageEvents: () => [],
241
241
  }));
242
242
 
243
- mock.module("../runtime/services/auto-analysis-enqueue.js", () => ({
244
- enqueueAutoAnalysisOnCompaction: () => {},
245
- }));
246
-
247
243
  mock.module("../agent/loop.js", () => ({
248
244
  AgentLoop: class {
249
245
  compactionCircuit = new CompactionCircuit("test-conv");
@@ -80,7 +80,6 @@ describe("event_date prompt grounding", () => {
80
80
  describe("parseExtractionResponse event_date coercion", () => {
81
81
  const candidateNodeIds = new Set<string>();
82
82
  const conversationId = "test-convo";
83
- const scopeId = "default";
84
83
  const now = Date.now();
85
84
 
86
85
  function makeInput(overrides: Record<string, unknown> = {}) {
@@ -110,7 +109,6 @@ describe("parseExtractionResponse event_date coercion", () => {
110
109
  const { diff } = parseExtractionResponse(
111
110
  input,
112
111
  conversationId,
113
- scopeId,
114
112
  candidateNodeIds,
115
113
  now,
116
114
  );
@@ -122,7 +120,6 @@ describe("parseExtractionResponse event_date coercion", () => {
122
120
  const { diff } = parseExtractionResponse(
123
121
  input,
124
122
  conversationId,
125
- scopeId,
126
123
  candidateNodeIds,
127
124
  now,
128
125
  );
@@ -134,7 +131,6 @@ describe("parseExtractionResponse event_date coercion", () => {
134
131
  const { diff } = parseExtractionResponse(
135
132
  input,
136
133
  conversationId,
137
- scopeId,
138
134
  candidateNodeIds,
139
135
  now,
140
136
  );
@@ -156,7 +152,6 @@ describe("parseExtractionResponse event_date coercion", () => {
156
152
  const { deferredTriggers } = parseExtractionResponse(
157
153
  input,
158
154
  conversationId,
159
- scopeId,
160
155
  candidateNodeIds,
161
156
  now,
162
157
  );
@@ -184,7 +179,6 @@ describe("parseExtractionResponse event_date coercion", () => {
184
179
  const { diff } = parseExtractionResponse(
185
180
  input,
186
181
  conversationId,
187
- scopeId,
188
182
  candidates,
189
183
  now,
190
184
  );
@@ -198,7 +192,6 @@ describe("parseExtractionResponse event_date coercion", () => {
198
192
  const { deferredTriggers } = parseExtractionResponse(
199
193
  input,
200
194
  conversationId,
201
- scopeId,
202
195
  candidateNodeIds,
203
196
  conversationTs,
204
197
  );
@@ -216,7 +209,6 @@ describe("parseExtractionResponse event_date coercion", () => {
216
209
  const { deferredTriggers } = parseExtractionResponse(
217
210
  input,
218
211
  conversationId,
219
- scopeId,
220
212
  candidateNodeIds,
221
213
  conversationTs,
222
214
  );
@@ -241,7 +233,6 @@ describe("parseExtractionResponse event_date coercion", () => {
241
233
  const { diff } = parseExtractionResponse(
242
234
  input,
243
235
  conversationId,
244
- scopeId,
245
236
  candidates,
246
237
  now,
247
238
  );
@@ -39,7 +39,6 @@ function makeScoredNode(
39
39
  narrativeRole: overrides.narrativeRole ?? null,
40
40
  partOfStory: overrides.partOfStory ?? null,
41
41
  imageRefs: overrides.imageRefs ?? null,
42
- scopeId: overrides.scopeId ?? "default",
43
42
  },
44
43
  score: 0.8,
45
44
  scoreBreakdown: {
@@ -53,7 +53,6 @@ const NON_PLUGIN_JOB_TYPES = [
53
53
  "backfill_lexical_index",
54
54
  "build_conversation_summary",
55
55
  "media_processing",
56
- "conversation_analyze",
57
56
  "generate_conversation_starters",
58
57
  ].sort();
59
58
 
@@ -251,7 +251,7 @@ describe("messages lexical-index dual-write", () => {
251
251
  // One memory-plugin job type, one host-owned job type — both keyed by the
252
252
  // conversation id.
253
253
  enqueueMemoryJob("graph_extract", { conversationId: conv.id });
254
- enqueueMemoryJob("conversation_analyze", { conversationId: conv.id });
254
+ enqueueMemoryJob("media_processing", { conversationId: conv.id });
255
255
 
256
256
  deleteConversation(conv.id);
257
257
 
@@ -281,7 +281,7 @@ describe("messages lexical-index dual-write", () => {
281
281
  // The sweep is scoped to the plugin's own job types: host-owned jobs —
282
282
  // including the purge the delete primitive itself enqueued — stay
283
283
  // runnable.
284
- expect(jobStatus("conversation_analyze")).toBe("pending");
284
+ expect(jobStatus("media_processing")).toBe("pending");
285
285
  expect(jobStatus("purge_conversation_lexical")).toBe("pending");
286
286
  });
287
287