@vellumai/assistant 0.11.1-dev.202608032034.aebd2da → 0.11.1-dev.202608032226.351a4e2

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 (47) hide show
  1. package/openapi.yaml +1 -0
  2. package/package.json +1 -1
  3. package/src/__tests__/agent-loop-resume-interrupted.test.ts +223 -0
  4. package/src/__tests__/conversation-agent-loop.test.ts +16 -7
  5. package/src/__tests__/conversation-error.test.ts +106 -0
  6. package/src/__tests__/llm-resolver.test.ts +16 -0
  7. package/src/__tests__/provider-send-message-override-profile.test.ts +95 -0
  8. package/src/__tests__/workspace-migration-137-repair-retired-fireworks-minimax-model-id.test.ts +6 -6
  9. package/src/__tests__/workspace-migration-138-backfill-home-feed-titles.test.ts +373 -0
  10. package/src/agent/loop.ts +36 -7
  11. package/src/cli/commands/notifications.help.ts +3 -2
  12. package/src/config/llm-resolver.ts +19 -3
  13. package/src/daemon/conversation-agent-loop-handlers.ts +15 -6
  14. package/src/daemon/conversation-agent-loop.ts +31 -18
  15. package/src/daemon/conversation-error.ts +40 -24
  16. package/src/home/__tests__/feed-types.test.ts +43 -8
  17. package/src/home/__tests__/feed-writer.test.ts +59 -0
  18. package/src/home/feed-types.ts +34 -7
  19. package/src/home/feed-writer.ts +15 -6
  20. package/src/live-voice/__tests__/activity-label.test.ts +68 -0
  21. package/src/live-voice/__tests__/live-activity-reporter.test.ts +86 -5
  22. package/src/live-voice/__tests__/live-voice-agent-turn.test.ts +14 -5
  23. package/src/live-voice/activity-label.ts +106 -0
  24. package/src/live-voice/live-activity-reporter.ts +35 -6
  25. package/src/live-voice/live-voice-session.ts +58 -0
  26. package/src/live-voice/protocol.ts +23 -0
  27. package/src/notifications/__tests__/copy-composer.test.ts +53 -3
  28. package/src/notifications/__tests__/decision-engine.test.ts +150 -20
  29. package/src/notifications/__tests__/edit-notification.test.ts +330 -0
  30. package/src/notifications/__tests__/home-feed-side-effect.test.ts +170 -12
  31. package/src/notifications/copy-composer.ts +23 -3
  32. package/src/notifications/decision-engine.ts +29 -7
  33. package/src/notifications/edit-notification.ts +8 -4
  34. package/src/notifications/home-feed-side-effect.ts +43 -6
  35. package/src/notifications/notification-utils.ts +8 -2
  36. package/src/persistence/conversation-title-service.ts +5 -170
  37. package/src/providers/__tests__/dispatch-connection-routing.test.ts +43 -2
  38. package/src/providers/__tests__/vellum-mismatch-routing.test.ts +8 -0
  39. package/src/providers/call-site-routing.ts +77 -14
  40. package/src/providers/connection-resolution.ts +42 -2
  41. package/src/providers/types.ts +7 -1
  42. package/src/runtime/routes/notification-routes.ts +4 -1
  43. package/src/util/__tests__/short-title.test.ts +229 -0
  44. package/src/util/errors.ts +15 -0
  45. package/src/util/short-title.ts +189 -0
  46. package/src/workspace/migrations/138-backfill-home-feed-titles.ts +179 -0
  47. package/src/workspace/migrations/registry.ts +2 -0
@@ -0,0 +1,330 @@
1
+ import { mkdtempSync, rmSync } from "node:fs";
2
+ import { tmpdir } from "node:os";
3
+ import { join } from "node:path";
4
+ import { afterEach, beforeEach, describe, expect, mock, test } from "bun:test";
5
+
6
+ import type { FeedItem } from "../../home/feed-types.js";
7
+ import type { NotificationDeliveryRow } from "../deliveries-store.js";
8
+
9
+ // ── Module mocks ───────────────────────────────────────────────────────
10
+ //
11
+ // The home-feed writer is deliberately NOT mocked: these tests exercise
12
+ // the real on-disk patch semantics through a temp workspace so the
13
+ // "an empty title never clears the field" guarantee is covered end to
14
+ // end. Only the sqlite-backed stores, the broadcaster, and the SSE hub
15
+ // are intercepted.
16
+
17
+ mock.module("../../runtime/assistant-event-hub.js", () => ({
18
+ assistantEventHub: {
19
+ publish: async () => {},
20
+ subscribe: () => () => {},
21
+ },
22
+ broadcastMessage: () => {},
23
+ }));
24
+
25
+ let decisionRow: { id: string } | null = null;
26
+ let deliveryRows: NotificationDeliveryRow[] = [];
27
+ const renderedCopyPatches: Array<{
28
+ id: string;
29
+ patch: { renderedTitle?: string; renderedBody?: string };
30
+ }> = [];
31
+
32
+ mock.module("../decisions-store.js", () => ({
33
+ findLatestDecisionByEventId: () => decisionRow,
34
+ }));
35
+
36
+ mock.module("../deliveries-store.js", () => ({
37
+ findDeliveriesByDecisionId: () => deliveryRows,
38
+ updateDeliveryRenderedCopy: (
39
+ id: string,
40
+ patch: { renderedTitle?: string; renderedBody?: string },
41
+ ) => {
42
+ renderedCopyPatches.push({ id, patch });
43
+ return true;
44
+ },
45
+ }));
46
+
47
+ const adapterUpdates: Array<{ title?: string; body?: string }> = [];
48
+ let adapterSupportsUpdate = true;
49
+
50
+ mock.module("../emit-signal.js", () => ({
51
+ getBroadcaster: () => ({
52
+ getAdapter: () =>
53
+ adapterSupportsUpdate
54
+ ? {
55
+ update: async (
56
+ _target: unknown,
57
+ patch: { title?: string; body?: string },
58
+ ) => {
59
+ adapterUpdates.push(patch);
60
+ return { success: true };
61
+ },
62
+ }
63
+ : {},
64
+ }),
65
+ }));
66
+
67
+ const { appendFeedItem, readHomeFeed } =
68
+ await import("../../home/feed-writer.js");
69
+ const { editNotification, normalizeFeedItemId, feedItemIdToSignalId } =
70
+ await import("../edit-notification.js");
71
+
72
+ // ── Fixtures ───────────────────────────────────────────────────────────
73
+
74
+ const SIGNAL_ID = "sig-1";
75
+ const FEED_ITEM_ID = `notif:${SIGNAL_ID}`;
76
+
77
+ function makeItem(overrides: Partial<FeedItem> = {}): FeedItem {
78
+ return {
79
+ id: FEED_ITEM_ID,
80
+ type: "notification",
81
+ priority: 50,
82
+ title: "Backup complete",
83
+ summary: "Nightly backup finished",
84
+ timestamp: "2026-04-14T12:00:00.000Z",
85
+ status: "new",
86
+ createdAt: "2026-04-14T12:00:00.000Z",
87
+ ...overrides,
88
+ } as FeedItem;
89
+ }
90
+
91
+ function makeDelivery(
92
+ overrides: Partial<NotificationDeliveryRow> = {},
93
+ ): NotificationDeliveryRow {
94
+ return {
95
+ id: "del-1",
96
+ notificationDecisionId: "dec-1",
97
+ channel: "slack",
98
+ destination: "C123",
99
+ status: "sent",
100
+ attempt: 1,
101
+ renderedTitle: "Backup complete",
102
+ renderedBody: "Nightly backup finished",
103
+ errorCode: null,
104
+ errorMessage: null,
105
+ sentAt: 1700000000000,
106
+ conversationId: null,
107
+ messageId: "1700000000.0001",
108
+ conversationStrategy: null,
109
+ conversationAction: null,
110
+ conversationTargetId: null,
111
+ conversationFallbackUsed: null,
112
+ clientDeliveryStatus: null,
113
+ clientDeliveryError: null,
114
+ clientDeliveryAt: null,
115
+ createdAt: 1700000000000,
116
+ updatedAt: 1700000000000,
117
+ ...overrides,
118
+ };
119
+ }
120
+
121
+ function readItem(id = FEED_ITEM_ID): FeedItem | undefined {
122
+ return readHomeFeed().items.find((item) => item.id === id);
123
+ }
124
+
125
+ let workspaceDir: string;
126
+ let origWorkspaceDir: string | undefined;
127
+
128
+ beforeEach(() => {
129
+ workspaceDir = mkdtempSync(join(tmpdir(), "vellum-edit-notif-"));
130
+ origWorkspaceDir = process.env.VELLUM_WORKSPACE_DIR;
131
+ process.env.VELLUM_WORKSPACE_DIR = workspaceDir;
132
+ decisionRow = null;
133
+ deliveryRows = [];
134
+ renderedCopyPatches.length = 0;
135
+ adapterUpdates.length = 0;
136
+ adapterSupportsUpdate = true;
137
+ });
138
+
139
+ afterEach(() => {
140
+ if (origWorkspaceDir === undefined) {
141
+ delete process.env.VELLUM_WORKSPACE_DIR;
142
+ } else {
143
+ process.env.VELLUM_WORKSPACE_DIR = origWorkspaceDir;
144
+ }
145
+ try {
146
+ rmSync(workspaceDir, { recursive: true, force: true });
147
+ } catch {
148
+ // best-effort
149
+ }
150
+ });
151
+
152
+ // ── Tests ──────────────────────────────────────────────────────────────
153
+
154
+ describe("normalizeFeedItemId", () => {
155
+ test("adds the notif: prefix to a bare uuid and leaves prefixed ids alone", () => {
156
+ expect(normalizeFeedItemId(SIGNAL_ID)).toBe(FEED_ITEM_ID);
157
+ expect(normalizeFeedItemId(` ${FEED_ITEM_ID} `)).toBe(FEED_ITEM_ID);
158
+ expect(feedItemIdToSignalId(FEED_ITEM_ID)).toBe(SIGNAL_ID);
159
+ });
160
+ });
161
+
162
+ describe("editNotification", () => {
163
+ test("applies a title edit to the feed item", async () => {
164
+ await appendFeedItem(makeItem());
165
+
166
+ const result = await editNotification({
167
+ id: FEED_ITEM_ID,
168
+ title: "Backup finished early",
169
+ });
170
+
171
+ expect(result).not.toBeNull();
172
+ expect(result!.feedItem.title).toBe("Backup finished early");
173
+ expect(readItem()!.title).toBe("Backup finished early");
174
+ expect(readItem()!.summary).toBe("Nightly backup finished");
175
+ });
176
+
177
+ test("accepts a bare signal uuid as the id", async () => {
178
+ await appendFeedItem(makeItem());
179
+
180
+ const result = await editNotification({
181
+ id: SIGNAL_ID,
182
+ title: "Renamed via bare id",
183
+ });
184
+
185
+ expect(result!.feedItem.id).toBe(FEED_ITEM_ID);
186
+ expect(readItem()!.title).toBe("Renamed via bare id");
187
+ });
188
+
189
+ test("an empty title edit leaves the previous title intact", async () => {
190
+ await appendFeedItem(makeItem());
191
+
192
+ const result = await editNotification({ id: FEED_ITEM_ID, title: "" });
193
+
194
+ expect(result).not.toBeNull();
195
+ expect(result!.feedItem.title).toBe("Backup complete");
196
+ expect(readItem()!.title).toBe("Backup complete");
197
+ });
198
+
199
+ test("a whitespace-only title edit leaves the previous title intact", async () => {
200
+ await appendFeedItem(makeItem());
201
+
202
+ const result = await editNotification({ id: FEED_ITEM_ID, title: " \t" });
203
+
204
+ expect(result!.feedItem.title).toBe("Backup complete");
205
+ expect(readItem()!.title).toBe("Backup complete");
206
+ });
207
+
208
+ test("an empty title edit does not push a channel update", async () => {
209
+ await appendFeedItem(makeItem());
210
+ decisionRow = { id: "dec-1" };
211
+ deliveryRows = [makeDelivery()];
212
+
213
+ const result = await editNotification({ id: FEED_ITEM_ID, title: "" });
214
+
215
+ expect(result!.channels).toEqual([]);
216
+ expect(adapterUpdates).toHaveLength(0);
217
+ expect(renderedCopyPatches).toHaveLength(0);
218
+ });
219
+
220
+ test("a body-only edit does not disturb the title", async () => {
221
+ await appendFeedItem(makeItem());
222
+
223
+ const result = await editNotification({
224
+ id: FEED_ITEM_ID,
225
+ body: "Nightly backup finished in 4 minutes",
226
+ });
227
+
228
+ expect(result!.feedItem.title).toBe("Backup complete");
229
+ expect(result!.feedItem.summary).toBe(
230
+ "Nightly backup finished in 4 minutes",
231
+ );
232
+ expect(readItem()!.title).toBe("Backup complete");
233
+ });
234
+
235
+ test("a feed-only edit skips channel updates entirely", async () => {
236
+ await appendFeedItem(makeItem());
237
+ decisionRow = { id: "dec-1" };
238
+ deliveryRows = [makeDelivery()];
239
+
240
+ const result = await editNotification({
241
+ id: FEED_ITEM_ID,
242
+ status: "dismissed",
243
+ });
244
+
245
+ expect(result!.feedItem.status).toBe("dismissed");
246
+ expect(result!.channels).toEqual([]);
247
+ expect(adapterUpdates).toHaveLength(0);
248
+ });
249
+
250
+ test("returns null for an unknown id", async () => {
251
+ await appendFeedItem(makeItem());
252
+
253
+ const result = await editNotification({
254
+ id: "notif:does-not-exist",
255
+ title: "Nope",
256
+ });
257
+
258
+ expect(result).toBeNull();
259
+ });
260
+
261
+ test("pushes the new copy to update-capable channel deliveries", async () => {
262
+ await appendFeedItem(makeItem());
263
+ decisionRow = { id: "dec-1" };
264
+ deliveryRows = [makeDelivery()];
265
+
266
+ const result = await editNotification({
267
+ id: FEED_ITEM_ID,
268
+ title: "Backup finished early",
269
+ body: "Done in 4 minutes",
270
+ });
271
+
272
+ expect(adapterUpdates).toEqual([
273
+ { title: "Backup finished early", body: "Done in 4 minutes" },
274
+ ]);
275
+ expect(renderedCopyPatches).toEqual([
276
+ {
277
+ id: "del-1",
278
+ patch: {
279
+ renderedTitle: "Backup finished early",
280
+ renderedBody: "Done in 4 minutes",
281
+ },
282
+ },
283
+ ]);
284
+ expect(result!.channels).toEqual([
285
+ { channel: "slack", deliveryId: "del-1", outcome: "updated" },
286
+ ]);
287
+ });
288
+
289
+ test("reports channels whose adapter cannot edit in place as unsupported", async () => {
290
+ await appendFeedItem(makeItem());
291
+ decisionRow = { id: "dec-1" };
292
+ deliveryRows = [makeDelivery()];
293
+ adapterSupportsUpdate = false;
294
+
295
+ const result = await editNotification({
296
+ id: FEED_ITEM_ID,
297
+ title: "Backup finished early",
298
+ });
299
+
300
+ expect(result!.channels[0]!.outcome).toBe("unsupported");
301
+ expect(renderedCopyPatches).toHaveLength(0);
302
+ });
303
+
304
+ test("skips deliveries that never reached sent", async () => {
305
+ await appendFeedItem(makeItem());
306
+ decisionRow = { id: "dec-1" };
307
+ deliveryRows = [makeDelivery({ status: "failed" })];
308
+
309
+ const result = await editNotification({
310
+ id: FEED_ITEM_ID,
311
+ title: "Backup finished early",
312
+ });
313
+
314
+ expect(result!.channels[0]!.outcome).toBe("skipped");
315
+ expect(adapterUpdates).toHaveLength(0);
316
+ });
317
+
318
+ test("skips channel updates when the feed item has no persisted decision", async () => {
319
+ await appendFeedItem(makeItem());
320
+ decisionRow = null;
321
+
322
+ const result = await editNotification({
323
+ id: FEED_ITEM_ID,
324
+ title: "Backup finished early",
325
+ });
326
+
327
+ expect(result!.channels).toEqual([]);
328
+ expect(adapterUpdates).toHaveLength(0);
329
+ });
330
+ });
@@ -320,11 +320,9 @@ describe("writeHomeFeedItemForSignal", () => {
320
320
  expect(appendCalls).toHaveLength(0);
321
321
  });
322
322
 
323
- test("writes a feed item with undefined title when only the body is available", async () => {
324
- // Regression: when `notifications send` is called without `--title`, the
325
- // notification pipeline must not manufacture a title (the LLM's rendered
326
- // copy echoes the body into `renderedCopy.title`). Leave `title`
327
- // undefined so renderers fall back to `summary` instead of stuttering.
323
+ test("derives a title from the summary when only the body is available", async () => {
324
+ // With no authored candidate at all, the title is derived from the
325
+ // summary rather than left off: every row carries a headline.
328
326
  conversationRow = { conversationType: "background" };
329
327
  const signal = makeSignal({
330
328
  sourceEventName: "example.event",
@@ -335,14 +333,14 @@ describe("writeHomeFeedItemForSignal", () => {
335
333
 
336
334
  expect(item).not.toBeNull();
337
335
  expect(appendCalls).toHaveLength(1);
338
- expect(appendCalls[0]!.title).toBeUndefined();
336
+ expect(appendCalls[0]!.title).toBe("Real body");
339
337
  expect(appendCalls[0]!.summary).toBe("Real body");
340
338
  });
341
339
 
342
- test("ignores LLM-rendered title when no payload title was supplied", async () => {
343
- // The LLM often echoes the body verbatim into `renderedCopy.title` when
344
- // the source didn't pass one. The home-feed writer must NOT promote that
345
- // echo into the feed item — only an explicit source title is honored.
340
+ test("uses the LLM-rendered title when no payload title was supplied", async () => {
341
+ // The model authors `renderedCopy.title` as a topic headline, and the
342
+ // decision engine validates it before it gets here, so it is the second
343
+ // candidate after the payload title.
346
344
  conversationRow = { conversationType: "background" };
347
345
  const signal = makeSignal({
348
346
  sourceEventName: "example.event",
@@ -351,7 +349,7 @@ describe("writeHomeFeedItemForSignal", () => {
351
349
  const decision = makeDecision({
352
350
  renderedCopy: {
353
351
  vellum: {
354
- title: "Real body",
352
+ title: "Nightly sync finished",
355
353
  body: "Real body",
356
354
  },
357
355
  },
@@ -361,10 +359,170 @@ describe("writeHomeFeedItemForSignal", () => {
361
359
 
362
360
  expect(item).not.toBeNull();
363
361
  expect(appendCalls).toHaveLength(1);
364
- expect(appendCalls[0]!.title).toBeUndefined();
362
+ expect(appendCalls[0]!.title).toBe("Nightly sync finished");
365
363
  expect(appendCalls[0]!.summary).toBe("Real body");
366
364
  });
367
365
 
366
+ test("payload title wins over the rendered title when it is clean", async () => {
367
+ conversationRow = { conversationType: "background" };
368
+ const signal = makeSignal({
369
+ sourceEventName: "example.event",
370
+ contextPayload: { title: "Payload headline" },
371
+ });
372
+ const decision = makeDecision({
373
+ renderedCopy: {
374
+ vellum: {
375
+ title: "Model headline",
376
+ body: "A description of what the run did.",
377
+ },
378
+ },
379
+ });
380
+
381
+ const item = await writeHomeFeedItemForSignal(signal, decision);
382
+
383
+ expect(item?.title).toBe("Payload headline");
384
+ expect(appendCalls[0]!.title).toBe("Payload headline");
385
+ });
386
+
387
+ test("keeps a payload title that opens the summary", async () => {
388
+ // A correct topic headline is usually the opening noun phrase of the body,
389
+ // so an authored title that overlaps the summary still wins.
390
+ conversationRow = { conversationType: "background" };
391
+ const signal = makeSignal({
392
+ sourceEventName: "example.event",
393
+ contextPayload: { title: "Nightly Backup Failure" },
394
+ });
395
+ const decision = makeDecision({
396
+ renderedCopy: {
397
+ vellum: {
398
+ title: "Reminder plumbing check",
399
+ body: "Nightly backup failure on db-primary at 02:14. Retry scheduled.",
400
+ },
401
+ },
402
+ });
403
+
404
+ const item = await writeHomeFeedItemForSignal(signal, decision);
405
+
406
+ expect(item?.title).toBe("Nightly Backup Failure");
407
+ expect(appendCalls[0]!.summary).toBe(
408
+ "Nightly backup failure on db-primary at 02:14. Retry scheduled.",
409
+ );
410
+ });
411
+
412
+ test("keeps a payload title that matches the summary's first sentence", async () => {
413
+ conversationRow = { conversationType: "background" };
414
+ const signal = makeSignal({
415
+ sourceEventName: "example.event",
416
+ contextPayload: { title: "Test notifications reminder." },
417
+ });
418
+ const decision = makeDecision({
419
+ renderedCopy: {
420
+ vellum: {
421
+ title: "Model headline",
422
+ body: "Test notifications reminder. It fired on schedule.",
423
+ },
424
+ },
425
+ });
426
+
427
+ const item = await writeHomeFeedItemForSignal(signal, decision);
428
+
429
+ expect(item?.title).toBe("Test notifications reminder.");
430
+ expect(appendCalls[0]!.summary).toBe(
431
+ "Test notifications reminder. It fired on schedule.",
432
+ );
433
+ });
434
+
435
+ test("always writes a non-empty title even when the copy is unusable", async () => {
436
+ // `normalizeTitle` rejects prose-shaped candidates, so both authored
437
+ // titles drop out and the derivation carries the row.
438
+ conversationRow = { conversationType: "background" };
439
+ const signal = makeSignal({
440
+ sourceEventName: "example.event",
441
+ contextPayload: { title: "I need to name this notification somehow" },
442
+ });
443
+ const decision = makeDecision({
444
+ renderedCopy: {
445
+ vellum: {
446
+ title: "Let me summarize what happened",
447
+ body: "Disk usage crossed 90 percent. Cleanup ran.",
448
+ },
449
+ },
450
+ });
451
+
452
+ const item = await writeHomeFeedItemForSignal(signal, decision);
453
+
454
+ expect(item?.title).toBe("Disk usage crossed 90 percent.");
455
+ expect(appendCalls[0]!.title).toBeTruthy();
456
+ });
457
+
458
+ test("derives a single-line plain title from a markdown-headed conversation seed", async () => {
459
+ // The summary prefers `conversationSeedMessage`, which carries structured
460
+ // markdown and hard line breaks. The derived title must not.
461
+ conversationRow = { conversationType: "background" };
462
+ const seed =
463
+ "## Nightly Backup Report\n\nThe backup job on db-primary failed at 02:14.";
464
+ const signal = makeSignal({ sourceEventName: "example.event" });
465
+ const decision = makeDecision({
466
+ renderedCopy: {
467
+ vellum: {
468
+ title: "",
469
+ body: "The backup job failed.",
470
+ conversationSeedMessage: seed,
471
+ },
472
+ },
473
+ });
474
+
475
+ const item = await writeHomeFeedItemForSignal(signal, decision);
476
+
477
+ expect(item?.title).toBe(
478
+ "Nightly Backup Report The backup job on db-primary failed at…",
479
+ );
480
+ expect(item?.summary).toBe(seed);
481
+ });
482
+
483
+ test("strips tilde fences and indented headings, matching migration 138", async () => {
484
+ // Workspace migration 138 backfills titles with its own self-contained copy
485
+ // of these rules. A backfilled title and a freshly written one must match
486
+ // for the same summary, so both accept CommonMark's 3-space indent and both
487
+ // fence styles.
488
+ conversationRow = { conversationType: "background" };
489
+ const seed = " ## Indented heading\n\n~~~\ntilde fence\n~~~\nBody text.";
490
+ const signal = makeSignal({ sourceEventName: "example.event" });
491
+ const decision = makeDecision({
492
+ renderedCopy: {
493
+ vellum: {
494
+ title: "",
495
+ body: "Body text.",
496
+ conversationSeedMessage: seed,
497
+ },
498
+ },
499
+ });
500
+
501
+ const item = await writeHomeFeedItemForSignal(signal, decision);
502
+
503
+ expect(item?.title).toBe("Indented heading tilde fence Body text.");
504
+ });
505
+
506
+ test("derives a single-line plain title from a markdown-list conversation seed", async () => {
507
+ conversationRow = { conversationType: "background" };
508
+ const seed = "- Ran 12 checks\n- 3 failed\n\nSee the log for details.";
509
+ const signal = makeSignal({ sourceEventName: "example.event" });
510
+ const decision = makeDecision({
511
+ renderedCopy: {
512
+ vellum: {
513
+ title: "",
514
+ body: "Check run finished.",
515
+ conversationSeedMessage: seed,
516
+ },
517
+ },
518
+ });
519
+
520
+ const item = await writeHomeFeedItemForSignal(signal, decision);
521
+
522
+ expect(item?.title).toBe("Ran 12 checks 3 failed See the log for details.");
523
+ expect(item?.summary).toBe(seed);
524
+ });
525
+
368
526
  test("treats whitespace-only rendered copy and payload values as missing and returns null", async () => {
369
527
  conversationRow = { conversationType: "background" };
370
528
  const signal = makeSignal({
@@ -9,6 +9,7 @@
9
9
  * values from the context payload.
10
10
  */
11
11
 
12
+ import { normalizeTitle } from "../util/short-title.js";
12
13
  import {
13
14
  accessRequestCardTitle,
14
15
  buildAccessRequestContractText,
@@ -60,6 +61,24 @@ export function deriveTitle(body: string): string {
60
61
  : candidate.trim();
61
62
  }
62
63
 
64
+ /**
65
+ * Clean a producer-authored title, falling back to one derived from the body
66
+ * when `normalizeTitle` returns its empty-string rejection signal.
67
+ *
68
+ * The decision engine's pass-through path applies the same clamp, so a signal
69
+ * carrying `requestedTitle` renders the same headline whether or not the LLM
70
+ * classifier was reachable.
71
+ *
72
+ * The two branches carry different budgets. An accepted authored title is
73
+ * bounded by `normalizeTitle` at 40 characters. A rejected one falls through to
74
+ * `deriveTitle`, which never sees the normalizer and applies
75
+ * `NOTIFICATION_TITLE_MAX_LENGTH` (60) plus a trailing ellipsis, so a derived
76
+ * title can reach 61 characters.
77
+ */
78
+ export function resolveTitle(raw: string | undefined, body: string): string {
79
+ return normalizeTitle(raw ?? "") || deriveTitle(body);
80
+ }
81
+
63
82
  /**
64
83
  * Build a display label for a trusted-contact actor (requester or decider),
65
84
  * preferring the display name, then a Slack `<@id>` mention for raw Slack user
@@ -291,9 +310,10 @@ export function composeFallbackCopy(
291
310
  readPayloadString(signal.contextPayload, "requestedMessage"),
292
311
  );
293
312
  if (msg) {
294
- const title =
295
- nonEmpty(readPayloadString(signal.contextPayload, "requestedTitle")) ??
296
- deriveTitle(msg);
313
+ const title = resolveTitle(
314
+ readPayloadString(signal.contextPayload, "requestedTitle"),
315
+ msg,
316
+ );
297
317
  const baseCopy: RenderedChannelCopy = {
298
318
  title,
299
319
  body: msg,
@@ -44,7 +44,7 @@ import {
44
44
  type ConversationCandidateSet,
45
45
  serializeCandidatesForPrompt,
46
46
  } from "./conversation-candidates.js";
47
- import { composeFallbackCopy, deriveTitle } from "./copy-composer.js";
47
+ import { composeFallbackCopy, resolveTitle } from "./copy-composer.js";
48
48
  import { createDecision } from "./decisions-store.js";
49
49
  import {
50
50
  buildGuardianRequestCodeInstruction,
@@ -229,6 +229,26 @@ function buildUserPrompt(signal: NotificationSignal): string {
229
229
 
230
230
  // ── Tool definition ────────────────────────────────────────────────────
231
231
 
232
+ /**
233
+ * Spec for the per-channel notification title. Mirrors the conversation title
234
+ * prompt (`persistence/conversation-title-service.ts`), which gets clean
235
+ * noun-phrase headlines out of this same model profile.
236
+ */
237
+ const TITLE_FIELD_DESCRIPTION = [
238
+ "Scannable headline naming the TOPIC of this notification, not a summary of it.",
239
+ "Rules:",
240
+ "- 2 to 5 words. Longer titles are unacceptable, ruthlessly compress",
241
+ "- 40 characters absolute maximum, longer titles get truncated and look broken",
242
+ "- A noun phrase naming the topic, never a sentence, question, or greeting (e.g. 'Platform Standup', 'Nightly Backup Failure')",
243
+ "- Do NOT restate, summarize, or echo the body. The title and the body must carry different information",
244
+ "- No quotes, no markdown, no trailing punctuation",
245
+ "- Never describe missing or thin context. Titles like 'Notification', 'Update', 'Missing Context' are forbidden. Extract a topic from the words that ARE present",
246
+ "Examples:",
247
+ "- Body 'Your 9am standup with the platform team starts in 5 minutes' -> 'Platform Standup', NOT 'Standup Starts In 5 Minutes'",
248
+ "- Body 'The nightly backup job failed on db-primary at 02:14' -> 'Nightly Backup Failure', NOT 'Nightly Backup Job Failed On db-primary'",
249
+ "- Body 'Alice replied about the Q3 pricing deck and wants your notes' -> 'Q3 Pricing Deck', NOT 'Alice Replied About The Pricing Deck'",
250
+ ].join("\n");
251
+
232
252
  function buildDecisionTool(availableChannels: NotificationChannel[]) {
233
253
  return {
234
254
  name: "record_notification_decision",
@@ -264,7 +284,7 @@ function buildDecisionTool(availableChannels: NotificationChannel[]) {
264
284
  properties: {
265
285
  title: {
266
286
  type: "string",
267
- description: "Short notification popup title (≤ 8 words)",
287
+ description: TITLE_FIELD_DESCRIPTION,
268
288
  },
269
289
  body: {
270
290
  type: "string",
@@ -445,7 +465,7 @@ function validateDecisionOutput(
445
465
  );
446
466
  }
447
467
  renderedCopy[ch] = {
448
- title: c.title,
468
+ title: resolveTitle(c.title, c.body),
449
469
  body: c.body,
450
470
  deliveryText:
451
471
  typeof c.deliveryText === "string" ? c.deliveryText : undefined,
@@ -874,7 +894,8 @@ function ensureInviteFlowDirectiveInCopy(
874
894
  /**
875
895
  * Build, guard, and persist a decision whose copy came verbatim from the
876
896
  * producer, bypassing the LLM classifier. The title falls back to one derived
877
- * from the body when the producer supplies none.
897
+ * from the body when the producer supplies none or supplies one that fails
898
+ * normalization.
878
899
  *
879
900
  * `renderedCopy` and `conversationActions` are populated for every available
880
901
  * channel, not just `selectedChannels`: downstream guards (routing-intent
@@ -891,9 +912,10 @@ function buildPassThroughDecision(params: {
891
912
  reasoningSummary: string;
892
913
  }): NotificationDecision {
893
914
  const { availableChannels, body, signal } = params;
894
- const title =
895
- nonEmpty(readPayloadString(signal.contextPayload, "requestedTitle")) ??
896
- deriveTitle(body);
915
+ const title = resolveTitle(
916
+ readPayloadString(signal.contextPayload, "requestedTitle"),
917
+ body,
918
+ );
897
919
  const deepLinkTarget = readPayloadObject(
898
920
  signal.contextPayload,
899
921
  "deepLinkMetadata",