@vellumai/assistant 0.11.2-dev.202608051451.3b2a3a6 → 0.11.2-dev.202608051637.aae860e

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 (33) hide show
  1. package/package.json +1 -1
  2. package/src/__tests__/workspace-migration-139-clear-renamed-cost-profile-label.test.ts +6 -6
  3. package/src/__tests__/workspace-migration-140-repair-seed-pinned-memory-v3-live.test.ts +324 -0
  4. package/src/calls/__tests__/voice-session-bridge.test.ts +50 -0
  5. package/src/calls/voice-session-bridge.ts +38 -0
  6. package/src/cli/commands/memory/memory-retrospective.ts +18 -0
  7. package/src/config/__tests__/deployment-context-defaults.test.ts +73 -0
  8. package/src/config/loader.ts +70 -1
  9. package/src/live-voice/__tests__/live-voice-session-telemetry.test.ts +265 -0
  10. package/src/live-voice/__tests__/protocol.test.ts +52 -0
  11. package/src/live-voice/live-voice-session.ts +54 -1
  12. package/src/live-voice/protocol.ts +23 -0
  13. package/src/onboarding/onboarding-events-store.ts +91 -1
  14. package/src/persistence/conversation-crud.ts +15 -0
  15. package/src/persistence/conversation-plugin-facade.ts +14 -0
  16. package/src/persistence/jobs-store.ts +32 -8
  17. package/src/plugin-api/index.ts +1 -0
  18. package/src/plugins/defaults/memory/__tests__/jobs-worker-outcome-contract.test.ts +242 -0
  19. package/src/plugins/defaults/memory/__tests__/memory-retrospective-job.test.ts +493 -18
  20. package/src/plugins/defaults/memory/__tests__/memory-retrospective-prompt.test.ts +39 -3
  21. package/src/plugins/defaults/memory/__tests__/memory-retrospective-provider-path.test.ts +492 -0
  22. package/src/plugins/defaults/memory/__tests__/memory-retrospective-wake-chain.test.ts +5 -4
  23. package/src/plugins/defaults/memory/__tests__/memory-tier-boundary-guard.test.ts +5 -1
  24. package/src/plugins/defaults/memory/job-handlers.ts +87 -5
  25. package/src/plugins/defaults/memory/jobs-worker.ts +50 -6
  26. package/src/plugins/defaults/memory/memory-retrospective-constants.ts +11 -0
  27. package/src/plugins/defaults/memory/memory-retrospective-job.ts +322 -55
  28. package/src/plugins/defaults/memory/memory-retrospective-prompt.ts +23 -3
  29. package/src/plugins/types.ts +60 -2
  30. package/src/telemetry/activation-funnel.ts +6 -1
  31. package/src/telemetry/live-voice-funnel.ts +75 -0
  32. package/src/workspace/migrations/140-repair-seed-pinned-memory-v3-live.ts +260 -0
  33. package/src/workspace/migrations/registry.ts +2 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vellumai/assistant",
3
- "version": "0.11.2-dev.202608051451.3b2a3a6",
3
+ "version": "0.11.2-dev.202608051637.aae860e",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "exports": {
@@ -51,15 +51,15 @@ afterEach(() => {
51
51
  });
52
52
 
53
53
  describe("139-clear-renamed-cost-profile-label migration", () => {
54
- test("has correct migration id and is registered last", () => {
54
+ test("has correct migration id and is registered", () => {
55
55
  expect(clearRenamedCostProfileLabelMigration.id).toBe(
56
56
  "139-clear-renamed-cost-profile-label",
57
57
  );
58
- // getLastWorkspaceMigrationId() reports the final entry as the registry
59
- // ceiling, so the highest id must stay last.
60
- expect(WORKSPACE_MIGRATIONS[WORKSPACE_MIGRATIONS.length - 1]?.id).toBe(
61
- "139-clear-renamed-cost-profile-label",
62
- );
58
+ expect(
59
+ WORKSPACE_MIGRATIONS.some(
60
+ (migration) => migration.id === "139-clear-renamed-cost-profile-label",
61
+ ),
62
+ ).toBe(true);
63
63
  });
64
64
 
65
65
  test("clears the seeded label so the code catalog label applies", () => {
@@ -0,0 +1,324 @@
1
+ /**
2
+ * Tests for workspace migration `140-repair-seed-pinned-memory-v3-live`.
3
+ *
4
+ * The pre-#39847 first-launch seed persisted `memory.v3.live = false` before
5
+ * migration 105 could record the real decision, stranding brand-new
6
+ * assistants on v2 and demoting existing v3 assistants whose config.json was
7
+ * quarantined and reseeded. The repair flips `live` back to true only for
8
+ * those two victim classes and never over a deliberate opt-out.
9
+ */
10
+
11
+ import {
12
+ existsSync,
13
+ mkdirSync,
14
+ mkdtempSync,
15
+ readFileSync,
16
+ rmSync,
17
+ writeFileSync,
18
+ } from "node:fs";
19
+ import { tmpdir } from "node:os";
20
+ import { join } from "node:path";
21
+ import { Database } from "bun:sqlite";
22
+ import { afterEach, beforeEach, describe, expect, test } from "bun:test";
23
+
24
+ import { repairSeedPinnedMemoryV3LiveMigration } from "../workspace/migrations/140-repair-seed-pinned-memory-v3-live.js";
25
+ import { WORKSPACE_MIGRATIONS } from "../workspace/migrations/registry.js";
26
+ import type { MigrationRunContext } from "../workspace/migrations/types.js";
27
+
28
+ const NEW_WORKSPACE_CTX: MigrationRunContext = { isNewWorkspace: true };
29
+ const UPGRADE_CTX: MigrationRunContext = { isNewWorkspace: false };
30
+
31
+ let workspaceDir: string;
32
+ let configPath: string;
33
+
34
+ beforeEach(() => {
35
+ workspaceDir = mkdtempSync(join(tmpdir(), "vellum-migration-140-test-"));
36
+ configPath = join(workspaceDir, "config.json");
37
+ mkdirSync(join(workspaceDir, "data", "db"), { recursive: true });
38
+ });
39
+
40
+ afterEach(() => {
41
+ if (existsSync(workspaceDir)) {
42
+ rmSync(workspaceDir, { recursive: true, force: true });
43
+ }
44
+ });
45
+
46
+ function readConfig(): Record<string, unknown> {
47
+ return JSON.parse(readFileSync(configPath, "utf-8"));
48
+ }
49
+
50
+ function readLive(): unknown {
51
+ const memory = (readConfig().memory ?? {}) as Record<string, unknown>;
52
+ const v3 = (memory.v3 ?? {}) as Record<string, unknown>;
53
+ return v3.live;
54
+ }
55
+
56
+ function writeConfig(config: Record<string, unknown>): void {
57
+ writeFileSync(configPath, JSON.stringify(config, null, 2) + "\n");
58
+ }
59
+
60
+ /** A checkpoint file whose 105 entry ran `gapMs` after the earliest entry. */
61
+ function writeCheckpoints(gapMs: number): void {
62
+ const base = Date.parse("2026-06-20T12:00:00.000Z");
63
+ writeFileSync(
64
+ join(workspaceDir, "data", ".workspace-migrations.json"),
65
+ JSON.stringify(
66
+ {
67
+ applied: {
68
+ "001-avatar-rename": {
69
+ appliedAt: new Date(base).toISOString(),
70
+ status: "completed",
71
+ },
72
+ "105-enable-memory-v3-live-for-new-workspaces": {
73
+ appliedAt: new Date(base + gapMs).toISOString(),
74
+ status: "completed",
75
+ },
76
+ },
77
+ },
78
+ null,
79
+ 2,
80
+ ) + "\n",
81
+ );
82
+ }
83
+
84
+ const FIRST_BOOT_GAP_MS = 5_000;
85
+ const UPGRADE_SWEEP_GAP_MS = 30 * 24 * 60 * 60 * 1000;
86
+
87
+ function writeSelectionRows(file: string): void {
88
+ const db = new Database(join(workspaceDir, "data", "db", file));
89
+ db.exec(`
90
+ CREATE TABLE memory_v3_selections (
91
+ conversation_id TEXT NOT NULL,
92
+ turn INTEGER NOT NULL,
93
+ slug TEXT NOT NULL,
94
+ source TEXT NOT NULL,
95
+ pinned INTEGER NOT NULL DEFAULT 0
96
+ );
97
+ INSERT INTO memory_v3_selections (conversation_id, turn, slug, source)
98
+ VALUES ('conv-1', 1, 'some-page', 'needle');
99
+ `);
100
+ db.close();
101
+ }
102
+
103
+ describe("140-repair-seed-pinned-memory-v3-live migration", () => {
104
+ test("has correct id and is registered last", () => {
105
+ expect(repairSeedPinnedMemoryV3LiveMigration.id).toBe(
106
+ "140-repair-seed-pinned-memory-v3-live",
107
+ );
108
+ expect(repairSeedPinnedMemoryV3LiveMigration.description).toContain(
109
+ "memory.v3.live",
110
+ );
111
+ // getLastWorkspaceMigrationId() reports the final entry as the registry
112
+ // ceiling, so the highest id must stay last.
113
+ expect(WORKSPACE_MIGRATIONS[WORKSPACE_MIGRATIONS.length - 1]?.id).toBe(
114
+ "140-repair-seed-pinned-memory-v3-live",
115
+ );
116
+ });
117
+
118
+ test("flips a seed-race victim: born in the 105 era, live=false, v3 never ran", () => {
119
+ writeConfig({
120
+ memory: { v2: { enabled: true }, v3: { live: false } },
121
+ llm: { activeProfile: "balanced" },
122
+ });
123
+ writeCheckpoints(FIRST_BOOT_GAP_MS);
124
+
125
+ repairSeedPinnedMemoryV3LiveMigration.run(workspaceDir, UPGRADE_CTX);
126
+
127
+ expect(readLive()).toBe(true);
128
+ // The rest of the config is untouched.
129
+ const config = readConfig();
130
+ expect((config.llm as Record<string, unknown>).activeProfile).toBe(
131
+ "balanced",
132
+ );
133
+ expect(
134
+ ((config.memory as Record<string, unknown>).v2 as Record<string, unknown>)
135
+ .enabled,
136
+ ).toBe(true);
137
+ });
138
+
139
+ test("skips new workspaces so a hatch-time opt-out override wins", () => {
140
+ writeConfig({ memory: { v3: { live: false } } });
141
+ writeCheckpoints(FIRST_BOOT_GAP_MS);
142
+
143
+ repairSeedPinnedMemoryV3LiveMigration.run(workspaceDir, NEW_WORKSPACE_CTX);
144
+
145
+ expect(readLive()).toBe(false);
146
+ });
147
+
148
+ test("leaves an absent leaf alone: pre-105 assistants stay on the manual-upgrade path", () => {
149
+ writeConfig({ memory: { v2: { enabled: true } } });
150
+ writeCheckpoints(UPGRADE_SWEEP_GAP_MS);
151
+
152
+ repairSeedPinnedMemoryV3LiveMigration.run(workspaceDir, UPGRADE_CTX);
153
+
154
+ expect(readLive()).toBeUndefined();
155
+ });
156
+
157
+ test("leaves live=true alone (idempotent after its own repair)", () => {
158
+ writeConfig({ memory: { v3: { live: false } } });
159
+ writeCheckpoints(FIRST_BOOT_GAP_MS);
160
+
161
+ repairSeedPinnedMemoryV3LiveMigration.run(workspaceDir, UPGRADE_CTX);
162
+ expect(readLive()).toBe(true);
163
+ const afterFirstRun = readFileSync(configPath, "utf-8");
164
+
165
+ repairSeedPinnedMemoryV3LiveMigration.run(workspaceDir, UPGRADE_CTX);
166
+ expect(readFileSync(configPath, "utf-8")).toBe(afterFirstRun);
167
+ });
168
+
169
+ test("skips a live=false workspace that was NOT born in the 105 era", () => {
170
+ writeConfig({ memory: { v3: { live: false } } });
171
+ writeCheckpoints(UPGRADE_SWEEP_GAP_MS);
172
+
173
+ repairSeedPinnedMemoryV3LiveMigration.run(workspaceDir, UPGRADE_CTX);
174
+
175
+ expect(readLive()).toBe(false);
176
+ });
177
+
178
+ test("skips when the checkpoint file is missing (no era evidence)", () => {
179
+ writeConfig({ memory: { v3: { live: false } } });
180
+
181
+ repairSeedPinnedMemoryV3LiveMigration.run(workspaceDir, UPGRADE_CTX);
182
+
183
+ expect(readLive()).toBe(false);
184
+ });
185
+
186
+ test("respects a hatch-time opt-out recorded in the archived default overlay", () => {
187
+ writeConfig({ memory: { v3: { live: false } } });
188
+ writeCheckpoints(FIRST_BOOT_GAP_MS);
189
+ writeFileSync(
190
+ join(workspaceDir, "default-config.json"),
191
+ JSON.stringify({ memory: { v3: { live: false } } }, null, 2),
192
+ );
193
+
194
+ repairSeedPinnedMemoryV3LiveMigration.run(workspaceDir, UPGRADE_CTX);
195
+
196
+ expect(readLive()).toBe(false);
197
+ });
198
+
199
+ test("an archived overlay without a memory.v3.live opt-out does not block repair", () => {
200
+ writeConfig({ memory: { v3: { live: false } } });
201
+ writeCheckpoints(FIRST_BOOT_GAP_MS);
202
+ writeFileSync(
203
+ join(workspaceDir, "default-config.json"),
204
+ JSON.stringify({ llm: { activeProfile: "balanced" } }, null, 2),
205
+ );
206
+
207
+ repairSeedPinnedMemoryV3LiveMigration.run(workspaceDir, UPGRADE_CTX);
208
+
209
+ expect(readLive()).toBe(true);
210
+ });
211
+
212
+ test("respects a deliberate opt-out: v3 selection rows exist", () => {
213
+ writeConfig({ memory: { v3: { live: false } } });
214
+ writeCheckpoints(FIRST_BOOT_GAP_MS);
215
+ writeSelectionRows("assistant-memory.db");
216
+
217
+ repairSeedPinnedMemoryV3LiveMigration.run(workspaceDir, UPGRADE_CTX);
218
+
219
+ expect(readLive()).toBe(false);
220
+ });
221
+
222
+ test("finds selection rows staged under the __relocating name mid-drain", () => {
223
+ writeConfig({ memory: { v3: { live: false } } });
224
+ writeCheckpoints(FIRST_BOOT_GAP_MS);
225
+ const db = new Database(join(workspaceDir, "data", "db", "assistant.db"));
226
+ db.exec(`
227
+ CREATE TABLE memory_v3_selections__relocating (
228
+ conversation_id TEXT NOT NULL,
229
+ turn INTEGER NOT NULL,
230
+ slug TEXT NOT NULL,
231
+ source TEXT NOT NULL
232
+ );
233
+ INSERT INTO memory_v3_selections__relocating
234
+ (conversation_id, turn, slug, source)
235
+ VALUES ('conv-1', 1, 'some-page', 'needle');
236
+ `);
237
+ db.close();
238
+
239
+ repairSeedPinnedMemoryV3LiveMigration.run(workspaceDir, UPGRADE_CTX);
240
+
241
+ expect(readLive()).toBe(false);
242
+ });
243
+
244
+ test("finds selection rows in the pre-relocation assistant.db too", () => {
245
+ writeConfig({ memory: { v3: { live: false } } });
246
+ writeCheckpoints(FIRST_BOOT_GAP_MS);
247
+ writeSelectionRows("assistant.db");
248
+
249
+ repairSeedPinnedMemoryV3LiveMigration.run(workspaceDir, UPGRADE_CTX);
250
+
251
+ expect(readLive()).toBe(false);
252
+ });
253
+
254
+ test("an empty selections table is not usage evidence", () => {
255
+ writeConfig({ memory: { v3: { live: false } } });
256
+ writeCheckpoints(FIRST_BOOT_GAP_MS);
257
+ const db = new Database(
258
+ join(workspaceDir, "data", "db", "assistant-memory.db"),
259
+ );
260
+ db.exec(
261
+ `CREATE TABLE memory_v3_selections (conversation_id TEXT, turn INTEGER)`,
262
+ );
263
+ db.close();
264
+
265
+ repairSeedPinnedMemoryV3LiveMigration.run(workspaceDir, UPGRADE_CTX);
266
+
267
+ expect(readLive()).toBe(true);
268
+ });
269
+
270
+ test("quarantine carry-forward flips a demoted v3 assistant even with usage rows and an old workspace", () => {
271
+ writeConfig({ memory: { v3: { live: false } } });
272
+ writeCheckpoints(UPGRADE_SWEEP_GAP_MS);
273
+ writeSelectionRows("assistant-memory.db");
274
+ writeFileSync(
275
+ join(workspaceDir, "config.json.corrupt-2026-08-01T10-00-00.000Z.json"),
276
+ JSON.stringify({ memory: { v3: { live: true } } }, null, 2),
277
+ );
278
+
279
+ repairSeedPinnedMemoryV3LiveMigration.run(workspaceDir, UPGRADE_CTX);
280
+
281
+ expect(readLive()).toBe(true);
282
+ });
283
+
284
+ test("salvages live=true from a truncated (unparseable) quarantined config", () => {
285
+ writeConfig({ memory: { v3: { live: false } } });
286
+ writeCheckpoints(UPGRADE_SWEEP_GAP_MS);
287
+ writeFileSync(
288
+ join(workspaceDir, "config.json.corrupt-2026-08-01T10-00-00.000Z.json"),
289
+ `{\n "memory": {\n "v3": {\n "live": true\n }\n },\n "llm": {\n "activeProf`,
290
+ );
291
+
292
+ repairSeedPinnedMemoryV3LiveMigration.run(workspaceDir, UPGRADE_CTX);
293
+
294
+ expect(readLive()).toBe(true);
295
+ });
296
+
297
+ test("the NEWEST quarantined config wins", () => {
298
+ writeConfig({ memory: { v3: { live: false } } });
299
+ writeCheckpoints(UPGRADE_SWEEP_GAP_MS);
300
+ writeFileSync(
301
+ join(workspaceDir, "config.json.corrupt-2026-07-01T10-00-00.000Z.json"),
302
+ JSON.stringify({ memory: { v3: { live: true } } }),
303
+ );
304
+ writeFileSync(
305
+ join(workspaceDir, "config.json.corrupt-2026-08-01T10-00-00.000Z.json"),
306
+ JSON.stringify({ memory: { v3: { live: false } } }),
307
+ );
308
+
309
+ repairSeedPinnedMemoryV3LiveMigration.run(workspaceDir, UPGRADE_CTX);
310
+
311
+ expect(readLive()).toBe(false);
312
+ });
313
+
314
+ test("no-ops when config.json is missing or corrupt", () => {
315
+ // Missing.
316
+ repairSeedPinnedMemoryV3LiveMigration.run(workspaceDir, UPGRADE_CTX);
317
+ expect(existsSync(configPath)).toBe(false);
318
+
319
+ // Corrupt.
320
+ writeFileSync(configPath, "{ not json");
321
+ repairSeedPinnedMemoryV3LiveMigration.run(workspaceDir, UPGRADE_CTX);
322
+ expect(readFileSync(configPath, "utf-8")).toBe("{ not json");
323
+ });
324
+ });
@@ -380,6 +380,56 @@ describe("startVoiceTurn escalation-continuation persistence", () => {
380
380
  voiceSessionTurn: true,
381
381
  });
382
382
  });
383
+
384
+ test("a live-voice turn persists its session attribution under metadata.client", async () => {
385
+ const fake = makeFakeConversation({ processing: false });
386
+ fakeConversation = fake.conversation;
387
+
388
+ await startVoiceTurn({
389
+ ...makeTurnOptions(),
390
+ voiceTelemetry: { sessionId: "session-123", client: "ios" },
391
+ });
392
+
393
+ // `turn-events-store` projects `$.client` onto `TurnTelemetryEvent.client`,
394
+ // so this bag is what makes a voice turn countable per client and joinable
395
+ // to its session's funnel rows. The platform goes in `os`, the same key
396
+ // the HTTP send path fills, so voice turns sit in the column existing turn
397
+ // analytics already read.
398
+ expect(fake.lastPersistOpts()?.metadata).toEqual({
399
+ voiceSessionTurn: true,
400
+ client: {
401
+ voice: true,
402
+ voice_session_id: "session-123",
403
+ os: "ios",
404
+ },
405
+ });
406
+ });
407
+
408
+ test("omits the client key when the session reported no originating client", async () => {
409
+ const fake = makeFakeConversation({ processing: false });
410
+ fakeConversation = fake.conversation;
411
+
412
+ await startVoiceTurn({
413
+ ...makeTurnOptions(),
414
+ voiceTelemetry: { sessionId: "session-123" },
415
+ });
416
+
417
+ expect(fake.lastPersistOpts()?.metadata).toEqual({
418
+ voiceSessionTurn: true,
419
+ client: { voice: true, voice_session_id: "session-123" },
420
+ });
421
+ });
422
+
423
+ test("a phone turn carries no client bag", async () => {
424
+ const fake = makeFakeConversation({ processing: false });
425
+ fakeConversation = fake.conversation;
426
+
427
+ await startVoiceTurn(makeTurnOptions());
428
+
429
+ // Only live-voice sessions pass `voiceTelemetry`; a phone call has no
430
+ // live-voice session id to attribute a turn to.
431
+ expect(fake.lastPersistOpts()?.metadata).not.toHaveProperty("client");
432
+ });
383
433
  });
384
434
 
385
435
  describe("startVoiceTurn hiddenSyntheticPrompt", () => {
@@ -17,6 +17,7 @@ import type {
17
17
  import { consumeGrantForInvocation } from "../approvals/approval-primitive.js";
18
18
  import type {
19
19
  ChannelId,
20
+ ClientOs,
20
21
  InterfaceId,
21
22
  TurnChannelContext,
22
23
  TurnInterfaceContext,
@@ -265,6 +266,22 @@ export interface VoiceTurnOptions {
265
266
  userMessageInterface?: InterfaceId;
266
267
  /** Source interface for persisted assistant messages. Defaults to userMessageInterface. */
267
268
  assistantMessageInterface?: InterfaceId;
269
+ /**
270
+ * Analytics attribution for a live-voice turn: which client opened the
271
+ * session, and that session's id. Persisted into the user message's
272
+ * `metadata.client` bag, which `turn-events-store` projects onto
273
+ * `TurnTelemetryEvent.client`, so a live-voice turn is countable per client
274
+ * and joinable to its session's start/end funnel rows.
275
+ *
276
+ * Deliberately separate from {@link userMessageInterface}: that field feeds
277
+ * `resolveChannelCapabilities` and decides what the turn may do, so it is not
278
+ * free to carry attribution. Absent for phone calls and for clients that send
279
+ * no identity on the start frame.
280
+ */
281
+ voiceTelemetry?: {
282
+ sessionId: string;
283
+ client?: ClientOs;
284
+ };
268
285
  /** Per-turn control prompt. Undefined uses the phone prompt; null disables it. */
269
286
  voiceControlPrompt?: string | null;
270
287
  /** The transcribed caller utterance or synthetic marker. */
@@ -945,6 +962,27 @@ export async function startVoiceTurn(
945
962
  // `isVoiceSessionUserMessage` for why the channel fields cannot carry it.
946
963
  voiceSessionTurn: true,
947
964
  ...(isHiddenSyntheticPrompt ? { hidden: true } : {}),
965
+ ...(opts.voiceTelemetry
966
+ ? {
967
+ // Projected onto `TurnTelemetryEvent.client` by
968
+ // `turn-events-store`. `voice_session_id` is what joins these
969
+ // turn rows to the session's funnel rows, so a session's turn
970
+ // count is a count of rows carrying its id, never a field
971
+ // anyone has to keep correct.
972
+ //
973
+ // `os` is the standard per-platform dimension the HTTP send
974
+ // path already fills from the same `detectClientOs()` value, so
975
+ // a voice turn reports its platform in the column existing turn
976
+ // analytics read rather than one only voice knows about.
977
+ client: {
978
+ voice: true,
979
+ voice_session_id: opts.voiceTelemetry.sessionId,
980
+ ...(opts.voiceTelemetry.client
981
+ ? { os: opts.voiceTelemetry.client }
982
+ : {}),
983
+ },
984
+ }
985
+ : {}),
948
986
  },
949
987
  });
950
988
  return persistResult.id;
@@ -135,6 +135,11 @@ function renderOutcome(outcome: MemoryRetrospectiveOutcome): void {
135
135
  case "no_new_messages":
136
136
  log.info("No new messages to review since the last retrospective.");
137
137
  break;
138
+ case "no_user_activity":
139
+ log.info(
140
+ "No user activity in the window since the last retrospective; skipping.",
141
+ );
142
+ break;
138
143
  case "source_dormant":
139
144
  log.info(
140
145
  "Source conversation is dormant beyond the sweep lookback; skipping.",
@@ -152,6 +157,15 @@ function renderOutcome(outcome: MemoryRetrospectiveOutcome): void {
152
157
  );
153
158
  process.exitCode = 1;
154
159
  break;
160
+ case "no_usable_output":
161
+ log.error(
162
+ `Run produced no usable output` +
163
+ `${outcome.reason ? `: ${outcome.reason}` : ""}` +
164
+ (outcome.conversationId ? ` (fork: ${outcome.conversationId})` : "") +
165
+ `. The window stays retryable.`,
166
+ );
167
+ process.exitCode = 1;
168
+ break;
155
169
  case "invoked":
156
170
  log.info(
157
171
  `Retrospective invoked.\n` +
@@ -163,5 +177,9 @@ function renderOutcome(outcome: MemoryRetrospectiveOutcome): void {
163
177
  : ""),
164
178
  );
165
179
  break;
180
+ default: {
181
+ const _exhaustive: never = outcome;
182
+ break;
183
+ }
166
184
  }
167
185
  }
@@ -1,6 +1,7 @@
1
1
  import {
2
2
  existsSync,
3
3
  mkdirSync,
4
+ readdirSync,
4
5
  readFileSync,
5
6
  rmSync,
6
7
  writeFileSync,
@@ -267,4 +268,76 @@ describe("deployment-context embedding-provider default (via loadConfig)", () =>
267
268
  >;
268
269
  expect(v3Raw.live).toBe(true);
269
270
  });
271
+
272
+ describe("quarantine-reseed carries memory.v3.live forward", () => {
273
+ function removeQuarantineFiles(): void {
274
+ for (const name of readdirSync(WORKSPACE_DIR)) {
275
+ if (name.startsWith("config.json.corrupt-")) {
276
+ rmSync(join(WORKSPACE_DIR, name), { force: true });
277
+ }
278
+ }
279
+ }
280
+
281
+ function readV3Raw(): Record<string, unknown> {
282
+ const raw = readConfig();
283
+ return ((raw.memory as Record<string, unknown>).v3 ?? {}) as Record<
284
+ string,
285
+ unknown
286
+ >;
287
+ }
288
+
289
+ afterEach(() => {
290
+ removeQuarantineFiles();
291
+ });
292
+
293
+ test("a corrupt live-v3 config is quarantined and the reseed keeps live=true", () => {
294
+ // Truncated mid-write JSON from a memory-v3 assistant: unparseable,
295
+ // but the live flag survives in the raw text.
296
+ writeFileSync(
297
+ CONFIG_PATH,
298
+ `{\n "memory": {\n "v3": {\n "live": true\n }\n },\n "llm": {\n "activeProf`,
299
+ );
300
+
301
+ const config = loadConfig();
302
+
303
+ // The corrupt file was quarantined and the reseeded config carries the
304
+ // tier forward, both in-memory (this boot runs v3) and on disk
305
+ // (migration 105 is checkpointed on existing workspaces and never
306
+ // re-runs, so the persisted value is the only durable record).
307
+ expect(config.memory.v3.live).toBe(true);
308
+ expect(readV3Raw()).toEqual({ live: true });
309
+ });
310
+
311
+ test("a corrupt config without live=true reseeds with the leaf absent", () => {
312
+ writeFileSync(
313
+ CONFIG_PATH,
314
+ `{\n "memory": {\n "v3": {\n "live": false\n }\n },\n "llm": {\n "activeProf`,
315
+ );
316
+
317
+ const config = loadConfig();
318
+
319
+ // Never carry `false` forward: an absent leaf is the only way to keep
320
+ // "no decision recorded" representable for migration 105.
321
+ expect(config.memory.v3.live).toBe(false);
322
+ expect(readV3Raw()).toEqual({});
323
+ });
324
+
325
+ test("a deleted config with an earlier live-v3 quarantine still carries live=true", () => {
326
+ if (existsSync(CONFIG_PATH)) {
327
+ rmSync(CONFIG_PATH, { force: true });
328
+ }
329
+ writeFileSync(
330
+ join(
331
+ WORKSPACE_DIR,
332
+ "config.json.corrupt-2026-08-01T10-00-00.000Z.json",
333
+ ),
334
+ JSON.stringify({ memory: { v3: { live: true } } }, null, 2),
335
+ );
336
+
337
+ const config = loadConfig();
338
+
339
+ expect(config.memory.v3.live).toBe(true);
340
+ expect(readV3Raw()).toEqual({ live: true });
341
+ });
342
+ });
270
343
  });
@@ -1,12 +1,13 @@
1
1
  import {
2
2
  existsSync,
3
3
  mkdirSync,
4
+ readdirSync,
4
5
  readFileSync,
5
6
  renameSync,
6
7
  rmSync,
7
8
  writeFileSync,
8
9
  } from "node:fs";
9
- import { dirname, join } from "node:path";
10
+ import { basename, dirname, join } from "node:path";
10
11
 
11
12
  import { safeStatSync } from "../util/fs.js";
12
13
  import { getLogger } from "../util/logger.js";
@@ -319,6 +320,53 @@ function writeQuarantineNotice(
319
320
  }
320
321
  }
321
322
 
323
+ /**
324
+ * Whether the newest quarantined config next to `configPath`
325
+ * (`config.json.corrupt-*.json`, written by {@link quarantineCorruptConfig})
326
+ * carried `memory.v3.live: true`. Quarantine filenames embed a
327
+ * filesystem-safe ISO timestamp, so a lexicographic sort is chronological.
328
+ *
329
+ * The first-launch seed asks this so a quarantine-reseed carries the memory
330
+ * tier forward: without it, reseeding an existing memory-v3 assistant
331
+ * silently demotes it to v2: the reseeded file records no `live` decision,
332
+ * migration 105 is already checkpointed on an existing workspace and never
333
+ * re-runs, and the schema default is `false`. Only `true` is ever salvaged:
334
+ * carrying `false` forward would re-pin a workspace to the schema default,
335
+ * the exact bug the seed's absent-leaf contract exists to prevent.
336
+ *
337
+ * A quarantined file usually fails `JSON.parse` (that is why it was
338
+ * quarantined); every config writer serializes via
339
+ * `JSON.stringify(config, null, 2)` and `memory.v3.live` is the only config
340
+ * key named `"live"`, so a literal `"live": true` match on the raw text is
341
+ * an unambiguous fallback for truncated files.
342
+ */
343
+ function quarantinedConfigSaidMemoryV3Live(configPath: string): boolean {
344
+ try {
345
+ const dir = dirname(configPath);
346
+ const prefix = `${basename(configPath)}.corrupt-`;
347
+ const quarantines = readdirSync(dir)
348
+ .filter((name) => name.startsWith(prefix) && name.endsWith(".json"))
349
+ .sort();
350
+ const newest = quarantines[quarantines.length - 1];
351
+ if (!newest) {
352
+ return false;
353
+ }
354
+ const raw = readFileSync(join(dir, newest), "utf-8");
355
+ try {
356
+ const parsed: unknown = JSON.parse(raw);
357
+ if (!isPlainObject(parsed) || !isPlainObject(parsed.memory)) {
358
+ return false;
359
+ }
360
+ const v3 = parsed.memory.v3;
361
+ return isPlainObject(v3) && v3.live === true;
362
+ } catch {
363
+ return /"live"\s*:\s*true/.test(raw);
364
+ }
365
+ } catch {
366
+ return false;
367
+ }
368
+ }
369
+
322
370
  /** Minimal structural view of the Zod issues the recovery ladder consumes. */
323
371
  type ValidationIssue = { path: PropertyKey[]; message: string };
324
372
 
@@ -1137,6 +1185,27 @@ export function loadConfig(): AssistantConfig {
1137
1185
  // `memory.v3.live=false` override still wins by merging after
1138
1186
  // migrations.
1139
1187
  seed.memory.v3 = {} as (typeof seed.memory)["v3"];
1188
+ // Exception: a quarantine-reseed carries the memory tier forward.
1189
+ // When the missing config.json is explained by a quarantined
1190
+ // predecessor that had `live: true`, this is an EXISTING memory-v3
1191
+ // assistant being reseeded, not a first launch: migration 105 is
1192
+ // already checkpointed here and never re-runs, so leaving the leaf
1193
+ // absent would silently demote the assistant to v2. Persist the
1194
+ // carried value and apply it to this load's effective config so the
1195
+ // current boot already runs v3.
1196
+ if (quarantinedConfigSaidMemoryV3Live(configPath)) {
1197
+ seed.memory.v3 = { live: true } as (typeof seed.memory)["v3"];
1198
+ config.memory.v3.live = true;
1199
+ // Refresh the last-known-good safety net (mirrors the
1200
+ // deployment-context refresh above): its snapshot was taken before
1201
+ // the carry, so a later in-process validation recovery would
1202
+ // otherwise restore live=false and demote the assistant in memory
1203
+ // despite the reseeded file on disk carrying true.
1204
+ lastKnownGoodConfig = structuredClone(config);
1205
+ log.info(
1206
+ "Carried memory.v3.live=true forward from the quarantined config",
1207
+ );
1208
+ }
1140
1209
  // Strip dataDir (runtime-derived) from the persisted config
1141
1210
  const { dataDir: _, ...persistable } = seed;
1142
1211
  writeFileSync(configPath, JSON.stringify(persistable, null, 2) + "\n");