@vellumai/assistant 0.10.6-dev.202607062330.7613445 → 0.10.6-dev.202607070055.e6ecf41

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/package.json +1 -1
  2. package/src/__tests__/agent-loop-override-profile.test.ts +1 -1
  3. package/src/__tests__/conversation-lifecycle.test.ts +25 -3
  4. package/src/__tests__/persistence-layering-guard.test.ts +5 -5
  5. package/src/__tests__/schedule-retry.test.ts +8 -0
  6. package/src/__tests__/scheduler-recurrence.test.ts +8 -0
  7. package/src/__tests__/scheduler-reuse-conversation.test.ts +8 -0
  8. package/src/__tests__/scheduler-wake.test.ts +8 -0
  9. package/src/__tests__/subagent-call-site-routing.test.ts +1 -1
  10. package/src/__tests__/subagent-fork-prompt-role.test.ts +1 -1
  11. package/src/__tests__/subagent-notify-parent.test.ts +124 -137
  12. package/src/__tests__/subagent-spawn-and-await.test.ts +1 -1
  13. package/src/__tests__/task-scheduler.test.ts +8 -0
  14. package/src/__tests__/telephony-tts-guard.test.ts +142 -2
  15. package/src/calls/call-controller.ts +34 -66
  16. package/src/calls/call-speech-output.ts +58 -45
  17. package/src/calls/media-stream-stt-session.ts +2 -3
  18. package/src/config/feature-flag-registry.json +8 -0
  19. package/src/config/schemas/memory-lifecycle.ts +2 -2
  20. package/src/config/schemas/schedules.ts +2 -2
  21. package/src/daemon/conversation.ts +21 -3
  22. package/src/live-voice/__tests__/live-voice-agent-turn.test.ts +26 -0
  23. package/src/live-voice/__tests__/live-voice-events.test.ts +16 -25
  24. package/src/live-voice/__tests__/live-voice-integration.test.ts +194 -3
  25. package/src/live-voice/__tests__/live-voice-metrics.test.ts +74 -0
  26. package/src/live-voice/__tests__/live-voice-stt.test.ts +274 -0
  27. package/src/live-voice/__tests__/live-voice-tts-session.test.ts +60 -0
  28. package/src/live-voice/__tests__/live-voice-tts.test.ts +44 -0
  29. package/src/live-voice/__tests__/live-voice-vad.test.ts +1039 -0
  30. package/src/live-voice/__tests__/protocol.test.ts +227 -0
  31. package/src/live-voice/live-voice-metrics.ts +91 -2
  32. package/src/live-voice/live-voice-session.ts +751 -158
  33. package/src/live-voice/live-voice-tts.ts +26 -16
  34. package/src/live-voice/protocol.ts +95 -0
  35. package/src/persistence/conversation-crud.ts +2 -2
  36. package/src/persistence/subagent-store.ts +19 -1
  37. package/src/plugins/defaults/memory/fork-conversation-memory.ts +128 -0
  38. package/src/plugins/defaults/memory/jobs-worker.ts +3 -2
  39. package/src/plugins/defaults/memory/pkb-schedule.ts +2 -3
  40. package/src/stt/__tests__/speech-energy.test.ts +68 -0
  41. package/src/stt/speech-energy.ts +49 -0
  42. package/src/subagent/manager.ts +79 -128
  43. package/src/subagent/notify.ts +114 -0
  44. package/src/tools/subagent/notify-parent.ts +2 -3
  45. package/src/tts/__tests__/synthesis-stream.test.ts +805 -0
  46. package/src/tts/synthesis-stream.ts +259 -0
  47. package/src/plugins/defaults/memory/persistence-hooks.ts +0 -127
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vellumai/assistant",
3
- "version": "0.10.6-dev.202607062330.7613445",
3
+ "version": "0.10.6-dev.202607070055.e6ecf41",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "exports": {
@@ -203,7 +203,7 @@ const capturedRunAgentLoopOptions: CapturedRunAgentLoopOptions[] = [];
203
203
  class FakeConversation {
204
204
  constructor() {}
205
205
  updateClient() {}
206
- setIsSubagent() {}
206
+
207
207
  setTrustContext() {}
208
208
  setAuthContext() {}
209
209
  getAuthContext() {
@@ -128,7 +128,10 @@ mock.module("../plugins/defaults/memory/v3/ever-injected-store.js", () => ({
128
128
  : realEverInjectedStore.getPrunedSlugs(conversationId),
129
129
  }));
130
130
 
131
- import { Conversation } from "../daemon/conversation.js";
131
+ import {
132
+ Conversation,
133
+ type ConversationConstructorOptions,
134
+ } from "../daemon/conversation.js";
132
135
 
133
136
  beforeEach(() => {
134
137
  lifecycleStoreMockActive = true;
@@ -139,7 +142,9 @@ afterAll(() => {
139
142
  lifecycleStoreMockActive = false;
140
143
  });
141
144
 
142
- function makeConversation(): Conversation {
145
+ function makeConversation(
146
+ options: ConversationConstructorOptions = { maxTokens: 4096 },
147
+ ): Conversation {
143
148
  const provider = {
144
149
  name: "mock",
145
150
  sendMessage: async () => ({
@@ -155,7 +160,7 @@ function makeConversation(): Conversation {
155
160
  "system prompt",
156
161
  () => {},
157
162
  "/tmp",
158
- { maxTokens: 4096 },
163
+ options,
159
164
  );
160
165
  // Default to guardian trust so tests load all messages.
161
166
  conv.setTrustContext({ trustClass: "guardian", sourceChannel: "vellum" });
@@ -173,6 +178,23 @@ function defaultConv() {
173
178
  };
174
179
  }
175
180
 
181
+ describe("Conversation — subagent identity", () => {
182
+ test("is not a subagent by default", () => {
183
+ const conv = makeConversation();
184
+ expect(conv.parentConversationId).toBeUndefined();
185
+ expect(conv.isSubagent).toBe(false);
186
+ });
187
+
188
+ test("derives isSubagent from the constructor parentConversationId", () => {
189
+ const conv = makeConversation({
190
+ maxTokens: 4096,
191
+ parentConversationId: "parent-1",
192
+ });
193
+ expect(conv.parentConversationId).toBe("parent-1");
194
+ expect(conv.isSubagent).toBe(true);
195
+ });
196
+ });
197
+
176
198
  describe("loadFromDb metadata injection rehydration", () => {
177
199
  beforeEach(() => {
178
200
  nextMockMessageId = 1;
@@ -42,10 +42,10 @@ const MEMORY_DIR = join(ASSISTANT_SRC, "plugins", "defaults", "memory");
42
42
  * plan.
43
43
  *
44
44
  * Current entries, both on the conversation write paths:
45
- * - `persistence-hooks` — the memory plugin's fork-time state carry, invoked
46
- * synchronously inside the fork transaction (see the module docstring for
47
- * why it resists the `hooks`-system migration the other lifecycle events
48
- * took).
45
+ * - `fork-conversation-memory` — the memory plugin's fork-time state carry,
46
+ * invoked synchronously inside the fork transaction (see the module
47
+ * docstring for why it is a direct call rather than a first-class `hooks`
48
+ * dispatch like the other lifecycle events).
49
49
  * - `indexer` — the plain `addMessage` path invokes `indexMessageNow` to feed
50
50
  * the persisted message into memory segment indexing, matching the other
51
51
  * (non-persistence) write seams that already call it directly.
@@ -55,7 +55,7 @@ const MEMORY_DIR = join(ASSISTANT_SRC, "plugins", "defaults", "memory");
55
55
  */
56
56
  const PERSISTENCE_TO_MEMORY_ALLOWLIST: Record<string, ReadonlySet<string>> = {
57
57
  "assistant/src/persistence/conversation-crud.ts": new Set([
58
- "persistence-hooks",
58
+ "fork-conversation-memory",
59
59
  "indexer",
60
60
  ]),
61
61
  };
@@ -64,6 +64,7 @@ mock.module("../notifications/emit-signal.js", () => ({
64
64
  emitNotificationSignalImpl(payload),
65
65
  }));
66
66
 
67
+ import { loadRawConfig, saveRawConfig } from "../config/loader.js";
67
68
  import { getDb } from "../persistence/db-connection.js";
68
69
  import { initializeDb } from "../persistence/db-init.js";
69
70
  import { applyRetryDecision, decideRetry } from "../schedule/retry-policy.js";
@@ -104,6 +105,13 @@ function startScheduler(
104
105
 
105
106
  await initializeDb();
106
107
 
108
+ // The schedule worker is on by default, which stands the daemon's in-process
109
+ // scheduler down. These tests exercise that in-process execution path directly,
110
+ // so pin the worker flag off for this test process.
111
+ const rawConfig = loadRawConfig();
112
+ rawConfig.schedules = { worker: { enabled: false } };
113
+ saveRawConfig(rawConfig);
114
+
107
115
  /** Access the underlying bun:sqlite Database for raw parameterized queries. */
108
116
  function getRawDb(): import("bun:sqlite").Database {
109
117
  return (getDb() as unknown as { $client: import("bun:sqlite").Database })
@@ -69,6 +69,7 @@ mock.module("../notifications/emit-signal.js", () => ({
69
69
  },
70
70
  }));
71
71
 
72
+ import { loadRawConfig, saveRawConfig } from "../config/loader.js";
72
73
  import { getDb } from "../persistence/db-connection.js";
73
74
  import { initializeDb } from "../persistence/db-init.js";
74
75
  import {
@@ -81,6 +82,13 @@ import { createTask } from "../tasks/task-store.js";
81
82
 
82
83
  await initializeDb();
83
84
 
85
+ // The schedule worker is on by default, which stands the daemon's in-process
86
+ // scheduler down. These tests exercise that in-process execution path directly,
87
+ // so pin the worker flag off for this test process.
88
+ const rawConfig = loadRawConfig();
89
+ rawConfig.schedules = { worker: { enabled: false } };
90
+ saveRawConfig(rawConfig);
91
+
84
92
  /** Access the underlying bun:sqlite Database for raw parameterized queries. */
85
93
  function getRawDb(): import("bun:sqlite").Database {
86
94
  return (getDb() as unknown as { $client: import("bun:sqlite").Database })
@@ -104,6 +104,7 @@ mock.module("../daemon/process-message.js", () => ({
104
104
  processMessageImpl(conversationId, message),
105
105
  }));
106
106
 
107
+ import { loadRawConfig, saveRawConfig } from "../config/loader.js";
107
108
  import { deleteConversation } from "../persistence/conversation-crud.js";
108
109
  import { getDb } from "../persistence/db-connection.js";
109
110
  import { initializeDb } from "../persistence/db-init.js";
@@ -113,6 +114,13 @@ import { startScheduler } from "../schedule/scheduler.js";
113
114
 
114
115
  await initializeDb();
115
116
 
117
+ // The schedule worker is on by default, which stands the daemon's in-process
118
+ // scheduler down. These tests exercise that in-process execution path directly,
119
+ // so pin the worker flag off for this test process.
120
+ const rawConfig = loadRawConfig();
121
+ rawConfig.schedules = { worker: { enabled: false } };
122
+ saveRawConfig(rawConfig);
123
+
116
124
  /** Access the underlying bun:sqlite Database for raw parameterized queries. */
117
125
  function getRawDb(): import("bun:sqlite").Database {
118
126
  return (getDb() as unknown as { $client: import("bun:sqlite").Database })
@@ -32,6 +32,7 @@ mock.module("../daemon/process-message.js", () => ({
32
32
  processMessage: mockProcessMessage,
33
33
  }));
34
34
 
35
+ import { loadRawConfig, saveRawConfig } from "../config/loader.js";
35
36
  import { getDb } from "../persistence/db-connection.js";
36
37
  import { initializeDb } from "../persistence/db-init.js";
37
38
  import { createSchedule } from "../schedule/schedule-store.js";
@@ -39,6 +40,13 @@ import { startScheduler } from "../schedule/scheduler.js";
39
40
 
40
41
  await initializeDb();
41
42
 
43
+ // The schedule worker is on by default, which stands the daemon's in-process
44
+ // scheduler down. These tests exercise that in-process execution path directly,
45
+ // so pin the worker flag off for this test process.
46
+ const rawConfig = loadRawConfig();
47
+ rawConfig.schedules = { worker: { enabled: false } };
48
+ saveRawConfig(rawConfig);
49
+
42
50
  /** Access the underlying bun:sqlite Database for raw parameterized queries. */
43
51
  function getRawDb(): import("bun:sqlite").Database {
44
52
  return (getDb() as unknown as { $client: import("bun:sqlite").Database })
@@ -52,7 +52,7 @@ class FakeConversation {
52
52
  capturedConversations.push(this.capturedState);
53
53
  }
54
54
  updateClient() {}
55
- setIsSubagent() {}
55
+
56
56
  setTrustContext(ctx: unknown) {
57
57
  this.capturedState.trustContext = ctx ?? undefined;
58
58
  }
@@ -55,7 +55,7 @@ class FakeConversation {
55
55
  }
56
56
  conversationType = "background";
57
57
  updateClient() {}
58
- setIsSubagent() {}
58
+
59
59
  setTrustContext() {}
60
60
  setAuthContext() {}
61
61
  getAuthContext() {
@@ -38,15 +38,41 @@ mock.module("../persistence/conversation-crud.js", () => ({
38
38
  */
39
39
  const capturedMessages: string[] = [];
40
40
 
41
+ /** Parent conversation ids that a notification was routed to (findConversation). */
42
+ const capturedParentIds: string[] = [];
43
+
44
+ // Live subagent conversations, keyed by conversationId. notifyParentFromChild
45
+ // routes to the parent recorded here (the non-writable in-process source), so
46
+ // tests register a child before expecting a notification to route.
47
+ const liveSubagents = new Map<string, { parentConversationId: string }>();
48
+
41
49
  mock.module("../daemon/conversation-registry.js", () => ({
42
- findConversation: (_id: string) => ({
43
- enqueueMessage: (options: { content: string }) => {
44
- capturedMessages.push(options.content);
45
- return { queued: true };
46
- },
47
- persistUserMessage: async () => ({ id: "mock-msg", deduplicated: false }),
48
- runAgentLoop: async () => {},
49
- }),
50
+ findConversation: (id: string) => {
51
+ capturedParentIds.push(id);
52
+ return {
53
+ enqueueMessage: (options: { content: string }) => {
54
+ capturedMessages.push(options.content);
55
+ return { queued: true };
56
+ },
57
+ persistUserMessage: async () => ({ id: "mock-msg", deduplicated: false }),
58
+ runAgentLoop: async () => {},
59
+ };
60
+ },
61
+ findConversationOrSubagent: (id: string) => {
62
+ const live = liveSubagents.get(id);
63
+ return live
64
+ ? { parentConversationId: live.parentConversationId }
65
+ : undefined;
66
+ },
67
+ }));
68
+
69
+ // notifyParentFromChild reads cosmetic label/fork/objective from the durable
70
+ // record. Routing does NOT come from here (see liveSubagents above), so a
71
+ // tampered record can only mislabel, never redirect.
72
+ const records = new Map<string, SubagentRecord>();
73
+ mock.module("../persistence/subagent-store.js", () => ({
74
+ getSubagentRecordByConversationId: (conversationId: string) =>
75
+ records.get(conversationId),
50
76
  }));
51
77
 
52
78
  mock.module("../runtime/assistant-event-hub.js", () => ({
@@ -54,9 +80,8 @@ mock.module("../runtime/assistant-event-hub.js", () => ({
54
80
  }));
55
81
 
56
82
  import { isToolActiveForContext } from "../daemon/conversation-tool-setup.js";
57
- import { getSubagentManager } from "../subagent/index.js";
58
- import { SubagentManager } from "../subagent/manager.js";
59
- import type { SubagentState } from "../subagent/types.js";
83
+ import type { SubagentRecord } from "../persistence/subagent-store.js";
84
+ import { notifyParentFromChild } from "../subagent/notify.js";
60
85
  import {
61
86
  executeSubagentNotifyParent,
62
87
  notifyParentTool,
@@ -65,61 +90,42 @@ import {
65
90
  // ── Shared helpers ──────────────────────────────────────────────────
66
91
 
67
92
  /**
68
- * Inject a fake subagent into the singleton manager so tool executors
69
- * can find it. Uses the same private-internals trick as the other tests.
93
+ * Register a subagent so `notifyParentFromChild` (and the `notify_parent` tool)
94
+ * treat `conversationId` as a live subagent: a live child conversation (the
95
+ * routing source) plus a durable record (cosmetic label/fork/objective).
96
+ * Defaults to a running general subagent; pass overrides for status, label,
97
+ * fork, etc. By default the live parent matches the record's parent; pass
98
+ * `liveParentConversationId` to diverge them (models a tampered record).
70
99
  */
71
- function injectSubagent(
72
- manager: SubagentManager,
73
- subagentId: string,
74
- parentConversationId: string,
75
- status: SubagentState["status"] = "running",
76
- overrides: Partial<SubagentState> = {},
77
- ): SubagentState {
78
- const internals = manager as unknown as {
79
- subagents: Map<
80
- string,
81
- {
82
- conversation: unknown;
83
- state: SubagentState;
84
- parentSendToClient: () => void;
85
- }
86
- >;
87
- parentToChildren: Map<string, Set<string>>;
88
- };
89
- const state: SubagentState = {
90
- config: {
91
- id: subagentId,
92
- parentConversationId,
93
- label: "Test",
94
- objective: "test",
95
- },
96
- status,
97
- conversationId: `conv-${subagentId}`,
100
+ function seedSubagent(
101
+ conversationId: string,
102
+ overrides: Partial<SubagentRecord> = {},
103
+ liveParentConversationId?: string,
104
+ ): void {
105
+ const record: SubagentRecord = {
106
+ id: `sub-${conversationId}`,
107
+ parentConversationId: `parent-${conversationId}`,
108
+ conversationId,
109
+ label: "Test",
110
+ objective: "test",
111
+ role: "general",
98
112
  isFork: false,
99
- createdAt: Date.now(),
100
- usage: { inputTokens: 0, outputTokens: 0, estimatedCost: 0 },
113
+ sendResultToUser: null,
114
+ status: "running",
115
+ error: null,
116
+ createdAt: 0,
117
+ startedAt: null,
118
+ completedAt: null,
119
+ inputTokens: 0,
120
+ outputTokens: 0,
121
+ estimatedCost: 0,
101
122
  ...overrides,
102
123
  };
103
- const fakeConversation = {
104
- abort: () => {},
105
- dispose: () => {},
106
- messages: [],
107
- sendToClient: () => {},
108
- usageStats: { inputTokens: 0, outputTokens: 0, estimatedCost: 0 },
109
- enqueueMessage: () => ({ queued: false }),
110
- persistUserMessage: async () => ({ id: "msg-1", deduplicated: false }),
111
- runAgentLoop: async () => {},
112
- };
113
- internals.subagents.set(subagentId, {
114
- conversation: fakeConversation,
115
- state,
116
- parentSendToClient: () => {},
124
+ records.set(conversationId, record);
125
+ liveSubagents.set(conversationId, {
126
+ parentConversationId:
127
+ liveParentConversationId ?? record.parentConversationId,
117
128
  });
118
- if (!internals.parentToChildren.has(parentConversationId)) {
119
- internals.parentToChildren.set(parentConversationId, new Set());
120
- }
121
- internals.parentToChildren.get(parentConversationId)!.add(subagentId);
122
- return state;
123
129
  }
124
130
 
125
131
  function makeContext(
@@ -209,14 +215,12 @@ describe("executeSubagentNotifyParent", () => {
209
215
 
210
216
  test("succeeds when called from a subagent conversation", async () => {
211
217
  clearCaptured();
212
- const manager = getSubagentManager();
213
- const subagentId = "notify-sub-1";
214
- const parentConversationId = "notify-parent-1";
215
- injectSubagent(manager, subagentId, parentConversationId, "running");
218
+ const conversationId = "conv-notify-sub-1";
219
+ seedSubagent(conversationId);
216
220
 
217
221
  const result = await executeSubagentNotifyParent(
218
222
  { message: "Found key results", urgency: "important" },
219
- makeContext(`conv-${subagentId}`),
223
+ makeContext(conversationId),
220
224
  );
221
225
  expect(result.isError).toBe(false);
222
226
  const parsed = JSON.parse(result.content);
@@ -227,21 +231,15 @@ describe("executeSubagentNotifyParent", () => {
227
231
 
228
232
  test("formats message with label and urgency", async () => {
229
233
  clearCaptured();
230
- const manager = getSubagentManager();
231
- const subagentId = "notify-format-1";
232
- const parentConversationId = "notify-format-parent";
233
- injectSubagent(manager, subagentId, parentConversationId, "running", {
234
- config: {
235
- id: subagentId,
236
- parentConversationId,
237
- label: "Research Task",
238
- objective: "research",
239
- },
234
+ const conversationId = "conv-notify-format-1";
235
+ seedSubagent(conversationId, {
236
+ label: "Research Task",
237
+ objective: "research",
240
238
  });
241
239
 
242
240
  await executeSubagentNotifyParent(
243
241
  { message: "Preliminary findings ready", urgency: "info" },
244
- makeContext(`conv-${subagentId}`),
242
+ makeContext(conversationId),
245
243
  );
246
244
  expect(lastCapturedMessage()).toBe(
247
245
  '[Subagent "Research Task" — info] Preliminary findings ready',
@@ -267,14 +265,12 @@ describe("executeSubagentNotifyParent", () => {
267
265
  });
268
266
 
269
267
  test("defaults urgency to info when not provided", async () => {
270
- const manager = getSubagentManager();
271
- const subagentId = "notify-default-urg-1";
272
- const parentConversationId = "notify-default-urg-parent";
273
- injectSubagent(manager, subagentId, parentConversationId, "running");
268
+ const conversationId = "conv-notify-default-urg-1";
269
+ seedSubagent(conversationId);
274
270
 
275
271
  const result = await executeSubagentNotifyParent(
276
272
  { message: "Progress update" },
277
- makeContext(`conv-${subagentId}`),
273
+ makeContext(conversationId),
278
274
  );
279
275
  expect(result.isError).toBe(false);
280
276
  const parsed = JSON.parse(result.content);
@@ -283,14 +279,12 @@ describe("executeSubagentNotifyParent", () => {
283
279
 
284
280
  test("appends guidance hint for blocked urgency", async () => {
285
281
  clearCaptured();
286
- const manager = getSubagentManager();
287
- const subagentId = "notify-blocked-1";
288
- const parentConversationId = "notify-blocked-parent";
289
- injectSubagent(manager, subagentId, parentConversationId, "running");
282
+ const conversationId = "conv-notify-blocked-1";
283
+ seedSubagent(conversationId);
290
284
 
291
285
  await executeSubagentNotifyParent(
292
286
  { message: "Need API key to proceed", urgency: "blocked" },
293
- makeContext(`conv-${subagentId}`),
287
+ makeContext(conversationId),
294
288
  );
295
289
  expect(lastCapturedMessage()).toContain("Need API key to proceed");
296
290
  expect(lastCapturedMessage()).toContain(
@@ -299,68 +293,61 @@ describe("executeSubagentNotifyParent", () => {
299
293
  });
300
294
  });
301
295
 
302
- // ── Manager-level tests ────────────────────────────────────────────
296
+ // ── notifyParentFromChild ──────────────────────────────────────────
297
+
298
+ describe("notifyParentFromChild", () => {
299
+ test("returns false when the conversation is not a subagent", () => {
300
+ expect(notifyParentFromChild("unknown-conversation", "hi", "info")).toBe(
301
+ false,
302
+ );
303
+ });
303
304
 
304
- describe("SubagentManager.notifyParent", () => {
305
305
  test("returns false for terminal subagents", () => {
306
- const manager = getSubagentManager();
307
-
308
- for (const terminalStatus of ["completed", "failed", "aborted"] as const) {
309
- const subagentId = `notify-terminal-${terminalStatus}`;
310
- const parentConversationId = `notify-terminal-parent-${terminalStatus}`;
311
- injectSubagent(manager, subagentId, parentConversationId, terminalStatus);
312
-
313
- const result = manager.notifyParent(
314
- `conv-${subagentId}`,
315
- "Should not arrive",
316
- "info",
317
- );
318
- expect(result).toBe(false);
306
+ for (const status of ["completed", "failed", "aborted"] as const) {
307
+ const conversationId = `conv-terminal-${status}`;
308
+ seedSubagent(conversationId, { status });
309
+ expect(
310
+ notifyParentFromChild(conversationId, "Should not arrive", "info"),
311
+ ).toBe(false);
319
312
  }
320
313
  });
321
314
 
322
- test("returns true for running subagent (injects into parent via findConversation)", () => {
315
+ test("returns true for a running subagent and injects into the parent", () => {
323
316
  clearCaptured();
324
- const manager = getSubagentManager();
325
- const subagentId = "notify-running-1";
326
- const parentConversationId = "notify-running-parent";
327
- injectSubagent(manager, subagentId, parentConversationId, "running");
328
-
329
- const result = manager.notifyParent(
330
- `conv-${subagentId}`,
331
- "Test message",
332
- "info",
317
+ const conversationId = "conv-running-1";
318
+ seedSubagent(conversationId);
319
+
320
+ expect(notifyParentFromChild(conversationId, "Test message", "info")).toBe(
321
+ true,
333
322
  );
334
- expect(result).toBe(true);
335
323
  expect(lastCapturedMessage()).toContain("Test message");
336
324
  });
337
- });
338
325
 
339
- describe("SubagentManager.getParentInfo", () => {
340
- test("returns undefined for unknown conversationIds", () => {
341
- const manager = getSubagentManager();
342
- const result = manager.getParentInfo("nonexistent-conversation-id");
343
- expect(result).toBeUndefined();
326
+ test("labels forks as Fork", () => {
327
+ clearCaptured();
328
+ const conversationId = "conv-fork-1";
329
+ seedSubagent(conversationId, { isFork: true, label: "Explore" });
330
+
331
+ notifyParentFromChild(conversationId, "branch result", "info");
332
+ expect(lastCapturedMessage()).toBe('[Fork "Explore" — info] branch result');
344
333
  });
345
334
 
346
- test("returns parent info for known subagent conversationId", () => {
347
- const manager = getSubagentManager();
348
- const subagentId = "parent-info-sub-1";
349
- const parentConversationId = "parent-info-parent-1";
350
- injectSubagent(manager, subagentId, parentConversationId, "running", {
351
- config: {
352
- id: subagentId,
353
- parentConversationId,
354
- label: "Info Lookup",
355
- objective: "look things up",
356
- },
357
- });
335
+ test("routes to the live parent, ignoring a tampered record parent", () => {
336
+ clearCaptured();
337
+ capturedParentIds.length = 0;
338
+ const conversationId = "conv-tamper-1";
339
+ // The durable record claims a victim conversation as parent; the live
340
+ // child's real parent differs. Routing must follow the live child.
341
+ seedSubagent(
342
+ conversationId,
343
+ { parentConversationId: "victim-conversation" },
344
+ "real-parent-conversation",
345
+ );
358
346
 
359
- const info = manager.getParentInfo(`conv-${subagentId}`);
360
- expect(info).toBeDefined();
361
- expect(info!.parentConversationId).toBe(parentConversationId);
362
- expect(info!.subagentId).toBe(subagentId);
363
- expect(info!.label).toBe("Info Lookup");
364
- expect(typeof info!.parentSendToClient).toBe("function");
347
+ expect(notifyParentFromChild(conversationId, "injected", "info")).toBe(
348
+ true,
349
+ );
350
+ expect(capturedParentIds).toContain("real-parent-conversation");
351
+ expect(capturedParentIds).not.toContain("victim-conversation");
365
352
  });
366
353
  });
@@ -82,7 +82,7 @@ class FakeConversation {
82
82
  // wrappedSendToClient tap is the one the deltas flow through.
83
83
  this.sendToClient = sendToClient;
84
84
  }
85
- setIsSubagent() {}
85
+
86
86
  setTrustContext() {}
87
87
  setAuthContext() {}
88
88
  getAuthContext() {
@@ -102,6 +102,7 @@ mock.module("../daemon/process-message.js", () => ({
102
102
  ) => processMessageImpl(conversationId, message, options),
103
103
  }));
104
104
 
105
+ import { loadRawConfig, saveRawConfig } from "../config/loader.js";
105
106
  import { getDb } from "../persistence/db-connection.js";
106
107
  import { initializeDb } from "../persistence/db-init.js";
107
108
  import { recordUsageEvent } from "../persistence/llm-usage-store.js";
@@ -121,6 +122,13 @@ import { createTask } from "../tasks/task-store.js";
121
122
 
122
123
  await initializeDb();
123
124
 
125
+ // The schedule worker is on by default, which stands the daemon's in-process
126
+ // scheduler down. These tests exercise that in-process execution path directly
127
+ // (runScheduleDueWorkOnce), so pin the worker flag off for this test process.
128
+ const rawConfig = loadRawConfig();
129
+ rawConfig.schedules = { worker: { enabled: false } };
130
+ saveRawConfig(rawConfig);
131
+
124
132
  /** Access the underlying bun:sqlite Database for raw parameterized queries. */
125
133
  function getRawDb(): import("bun:sqlite").Database {
126
134
  return (getDb() as unknown as { $client: import("bun:sqlite").Database })