@vellumai/assistant 0.12.4 → 0.12.5-dev.202609251017.e467a6c

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 (281) hide show
  1. package/docs/architecture/memory.md +9 -1
  2. package/docs/architecture/scheduling.md +13 -5
  3. package/docs/desktop-browser-cli.md +3 -2
  4. package/docs/guardian-request-flow.md +1 -1
  5. package/node_modules/@vellumai/avatar-manifest/src/__tests__/notification-avatar.test.ts +48 -4
  6. package/node_modules/@vellumai/avatar-manifest/src/notification-avatar.ts +12 -8
  7. package/node_modules/@vellumai/ces-client/node_modules/@vellumai/service-contracts/src/__tests__/guardian-requests.test.ts +26 -0
  8. package/node_modules/@vellumai/ces-client/node_modules/@vellumai/service-contracts/src/guardian-requests.ts +77 -3
  9. package/node_modules/@vellumai/gateway-client/node_modules/@vellumai/service-contracts/src/__tests__/guardian-requests.test.ts +26 -0
  10. package/node_modules/@vellumai/gateway-client/node_modules/@vellumai/service-contracts/src/guardian-requests.ts +77 -3
  11. package/node_modules/@vellumai/gateway-client/src/outbound-contract.ts +2 -4
  12. package/node_modules/@vellumai/service-contracts/src/__tests__/guardian-requests.test.ts +26 -0
  13. package/node_modules/@vellumai/service-contracts/src/guardian-requests.ts +77 -3
  14. package/openapi.yaml +152 -3
  15. package/package.json +1 -1
  16. package/src/__tests__/agent-loop.test.ts +76 -0
  17. package/src/__tests__/anthropic-error-formatting.test.ts +9 -0
  18. package/src/__tests__/background-shell-bash.test.ts +34 -0
  19. package/src/__tests__/background-shell-host-bash.test.ts +98 -1
  20. package/src/__tests__/background-tool-registry.test.ts +39 -0
  21. package/src/__tests__/channel-readiness-discord.test.ts +8 -0
  22. package/src/__tests__/channel-readiness-slack-remote.test.ts +8 -0
  23. package/src/__tests__/client-os-metadata-persistence.test.ts +4 -20
  24. package/src/__tests__/conversation-agent-loop.test.ts +529 -1
  25. package/src/__tests__/conversation-error.test.ts +18 -0
  26. package/src/__tests__/conversation-pairing.test.ts +69 -0
  27. package/src/__tests__/conversation-queue.test.ts +257 -4
  28. package/src/__tests__/conversation-runtime-assembly.test.ts +27 -0
  29. package/src/__tests__/emit-signal-routing-intent.test.ts +62 -0
  30. package/src/__tests__/evict-conversations-for-reload.test.ts +21 -0
  31. package/src/__tests__/gemini-provider.test.ts +9 -0
  32. package/src/__tests__/host-cu-proxy.test.ts +79 -0
  33. package/src/__tests__/host-cu-routes-targeted.test.ts +14 -5
  34. package/src/__tests__/introduction-card-resolver.test.ts +53 -8
  35. package/src/__tests__/job-handler-registration-guard.test.ts +1 -0
  36. package/src/__tests__/non-member-access-request.test.ts +48 -0
  37. package/src/__tests__/notification-events-source-context-probe.test.ts +48 -1
  38. package/src/__tests__/notification-platform-adapter.test.ts +97 -0
  39. package/src/__tests__/notification-vellum-adapter.test.ts +103 -3
  40. package/src/__tests__/platform-callback-registration.test.ts +46 -1
  41. package/src/__tests__/plugin-import-boundary-guard.test.ts +3 -0
  42. package/src/__tests__/scaffold-managed-skill-tool.test.ts +116 -66
  43. package/src/__tests__/scheduler-disk-pressure.test.ts +1 -0
  44. package/src/__tests__/scheduler-result-notification.test.ts +521 -7
  45. package/src/__tests__/scheduler-wake.test.ts +1 -0
  46. package/src/__tests__/skill-load-inline-command.test.ts +35 -0
  47. package/src/__tests__/subagent-cron-run-attribution.test.ts +41 -2
  48. package/src/__tests__/subagent-manager-notify.test.ts +48 -0
  49. package/src/__tests__/trusted-contact-inline-approval-integration.test.ts +6 -6
  50. package/src/__tests__/usage-attribution.test.ts +31 -0
  51. package/src/__tests__/wake-schedule-escalation.test.ts +1 -0
  52. package/src/agent/loop.ts +23 -0
  53. package/src/api/ask-question-tool.ts +50 -0
  54. package/src/api/events/generation-handoff.ts +4 -0
  55. package/src/api/events/message-complete.ts +4 -0
  56. package/src/api/events/tool-result.ts +11 -0
  57. package/src/api/index.ts +11 -0
  58. package/src/api/requests/guardian-actions.test.ts +45 -0
  59. package/src/api/requests/guardian-actions.ts +20 -0
  60. package/src/api/responses/conversation-message.ts +4 -0
  61. package/src/api/responses/home.ts +27 -0
  62. package/src/approvals/guardian-decision-primitive.ts +6 -4
  63. package/src/approvals/guardian-request-resolvers.ts +35 -30
  64. package/src/avatar/notification-avatar.test.ts +42 -34
  65. package/src/avatar/notification-avatar.ts +1 -0
  66. package/src/calls/__tests__/call-controller.test.ts +18 -0
  67. package/src/calls/__tests__/voice-control-protocol.test.ts +6 -1
  68. package/src/calls/__tests__/voice-leg-coordinator.test.ts +70 -0
  69. package/src/calls/__tests__/voice-session-bridge.test.ts +116 -4
  70. package/src/calls/__tests__/voice-triage-escalate.test.ts +77 -11
  71. package/src/calls/call-controller.ts +3 -1
  72. package/src/calls/voice-control-protocol.ts +12 -4
  73. package/src/calls/voice-escalation-judge.ts +2 -2
  74. package/src/calls/voice-leg-coordinator.ts +23 -5
  75. package/src/calls/voice-screen-annotation.ts +44 -0
  76. package/src/calls/voice-session-bridge.ts +63 -20
  77. package/src/calls/voice-triage-escalate.ts +82 -27
  78. package/src/cli/commands/__tests__/conversations-clear.test.ts +156 -0
  79. package/src/cli/commands/conversations.help.ts +7 -2
  80. package/src/cli/commands/conversations.ts +36 -30
  81. package/src/cli/commands/oauth/index.help.ts +8 -2
  82. package/src/cli/commands/oauth/request.test.ts +32 -0
  83. package/src/cli/commands/platform/index.help.ts +2 -1
  84. package/src/cli/commands/platform/index.ts +8 -2
  85. package/src/cli/lib/__tests__/plugin-catalog-cache.test.ts +60 -0
  86. package/src/cli/lib/__tests__/plugin-catalog-platform.test.ts +66 -2
  87. package/src/cli/lib/bundled-marketplace.json +35 -0
  88. package/src/cli/lib/bundled-plugin-packages.json +21 -0
  89. package/src/cli/lib/plugin-catalog-cache.ts +17 -2
  90. package/src/cli/lib/plugin-catalog-platform.ts +48 -9
  91. package/src/config/__tests__/default-profile-catalog.test.ts +28 -0
  92. package/src/config/__tests__/platform-identity.test.ts +59 -0
  93. package/src/config/__tests__/profile-order.test.ts +19 -0
  94. package/src/config/__tests__/sync-gated-profiles.test.ts +71 -0
  95. package/src/config/bundled-skills/computer-use/SKILL.md +20 -0
  96. package/src/config/bundled-skills/computer-use/TOOLS.json +11 -11
  97. package/src/config/bundled-skills/screen-annotation/SKILL.md +41 -29
  98. package/src/config/bundled-skills/screen-annotation/TOOLS.json +5 -5
  99. package/src/config/call-site-defaults.ts +6 -0
  100. package/src/config/default-profile-catalog.ts +30 -1
  101. package/src/config/default-profile-names.ts +36 -2
  102. package/src/config/feature-flag-registry.json +9 -1
  103. package/src/config/platform-identity.ts +22 -5
  104. package/src/config/profile-order.ts +7 -1
  105. package/src/config/schemas/call-site-catalog.ts +7 -0
  106. package/src/config/schemas/llm.ts +21 -5
  107. package/src/config/sync-gated-profiles.ts +96 -44
  108. package/src/daemon/__tests__/abort-null-controller.test.ts +135 -1
  109. package/src/daemon/__tests__/auto-profile-router.test.ts +380 -0
  110. package/src/daemon/__tests__/turn-tail-assistant-reply-notify.test.ts +16 -0
  111. package/src/daemon/activity-trail.test.ts +206 -0
  112. package/src/daemon/activity-trail.ts +190 -0
  113. package/src/daemon/auto-profile-router.ts +431 -0
  114. package/src/daemon/computer-use-observation.test.ts +81 -0
  115. package/src/daemon/computer-use-observation.ts +23 -0
  116. package/src/daemon/conversation-agent-loop-handlers.ts +11 -0
  117. package/src/daemon/conversation-agent-loop.ts +157 -32
  118. package/src/daemon/conversation-error.ts +19 -0
  119. package/src/daemon/conversation-lifecycle.ts +70 -7
  120. package/src/daemon/conversation-media-retry.ts +1 -2
  121. package/src/daemon/conversation-messaging.ts +31 -2
  122. package/src/daemon/conversation-process.ts +107 -16
  123. package/src/daemon/conversation-queue-manager.ts +7 -0
  124. package/src/daemon/conversation-runtime-assembly.ts +1 -0
  125. package/src/daemon/conversation-turn-finalize.ts +14 -0
  126. package/src/daemon/conversation.ts +25 -6
  127. package/src/daemon/event-loop-watchdog.test.ts +201 -2
  128. package/src/daemon/event-loop-watchdog.ts +182 -6
  129. package/src/daemon/host-cu-proxy.ts +34 -3
  130. package/src/daemon/pkb-reminder-builder.test.ts +10 -3
  131. package/src/daemon/pkb-reminder-builder.ts +1 -1
  132. package/src/daemon/wake-conversation-ops.ts +4 -2
  133. package/src/desktop/desktop-computer-use.test.ts +14 -4
  134. package/src/home/feed-types.ts +2 -0
  135. package/src/inbound/platform-callback-registration.ts +19 -6
  136. package/src/live-voice/__tests__/live-voice-agent-turn.test.ts +27 -0
  137. package/src/live-voice/__tests__/live-voice-flux-turn-end.test.ts +83 -0
  138. package/src/live-voice/__tests__/live-voice-triage-escalate.test.ts +48 -1
  139. package/src/live-voice/__tests__/live-voice-vad.test.ts +34 -2
  140. package/src/live-voice/__tests__/protocol.test.ts +22 -0
  141. package/src/live-voice/continuation-judge.ts +1 -1
  142. package/src/live-voice/live-voice-session.ts +25 -19
  143. package/src/live-voice/protocol.ts +16 -5
  144. package/src/messaging/providers/discord/withdraw.ts +4 -5
  145. package/src/messaging/providers/gmail/client.ts +4 -0
  146. package/src/messaging/providers/slack/withdraw.ts +5 -5
  147. package/src/messaging/providers/telegram-bot/withdraw.ts +4 -5
  148. package/src/monitoring/__tests__/proc-fixtures.ts +28 -0
  149. package/src/monitoring/__tests__/proc-wait-state.test.ts +232 -0
  150. package/src/monitoring/__tests__/process-usage.test.ts +243 -0
  151. package/src/monitoring/proc-wait-state.ts +366 -0
  152. package/src/monitoring/process-memory.ts +4 -3
  153. package/src/monitoring/process-usage.ts +215 -0
  154. package/src/monitoring/resource-sample-types.ts +8 -0
  155. package/src/monitoring/resource-sampler.ts +17 -2
  156. package/src/monitoring/stall-capture.ts +12 -0
  157. package/src/notifications/README.md +88 -9
  158. package/src/notifications/__tests__/assistant-reply-producer.test.ts +390 -119
  159. package/src/notifications/__tests__/background-result-producer.test.ts +1272 -0
  160. package/src/notifications/__tests__/broadcaster.test.ts +292 -1
  161. package/src/notifications/__tests__/completion-policy.test.ts +243 -0
  162. package/src/notifications/__tests__/decision-engine.test.ts +51 -4
  163. package/src/notifications/__tests__/has-pending-background-work.test.ts +281 -0
  164. package/src/notifications/__tests__/home-feed-side-effect.test.ts +161 -3
  165. package/src/notifications/__tests__/resolve-visible-in-source.test.ts +110 -1
  166. package/src/notifications/__tests__/schedule-result-producer.test.ts +11 -4
  167. package/src/notifications/adapters/macos.ts +24 -12
  168. package/src/notifications/adapters/platform.ts +16 -5
  169. package/src/notifications/assistant-reply-producer.ts +96 -71
  170. package/src/notifications/background-result-producer.ts +369 -0
  171. package/src/notifications/broadcaster.ts +28 -8
  172. package/src/notifications/completion-policy.ts +115 -0
  173. package/src/notifications/completion-work.ts +46 -0
  174. package/src/notifications/conversation-pairing.ts +32 -13
  175. package/src/notifications/decision-engine.ts +18 -24
  176. package/src/notifications/emit-signal.ts +16 -1
  177. package/src/notifications/events-store.ts +4 -0
  178. package/src/notifications/has-pending-background-work.ts +91 -0
  179. package/src/notifications/home-feed-mirror.ts +44 -0
  180. package/src/notifications/home-feed-side-effect.ts +54 -28
  181. package/src/notifications/resolve-visible-in-source.ts +56 -2
  182. package/src/notifications/result-output.ts +154 -0
  183. package/src/notifications/schedule-result-producer.ts +6 -187
  184. package/src/notifications/types.ts +2 -0
  185. package/src/oauth/AGENTS.md +9 -1
  186. package/src/oauth/byo-connection.test.ts +28 -0
  187. package/src/persistence/__tests__/recent-conversation-messages.test.ts +41 -0
  188. package/src/persistence/conversation-crud.ts +26 -0
  189. package/src/persistence/conversation-types.ts +15 -37
  190. package/src/persistence/embeddings/__tests__/embedding-local-lifecycle.test.ts +85 -14
  191. package/src/persistence/jobs-store.ts +229 -0
  192. package/src/persistence/migrations/383-normalize-opencode-host-connections.ts +44 -0
  193. package/src/persistence/migrations/__tests__/383-normalize-opencode-host-connections.test.ts +102 -0
  194. package/src/persistence/steps.ts +12 -0
  195. package/src/platform/sync-avatar.test.ts +29 -0
  196. package/src/plugins/defaults/memory/AGENTS.md +5 -3
  197. package/src/plugins/defaults/memory/__tests__/skill-update-receipt-boundary-guard.test.ts +45 -0
  198. package/src/plugins/defaults/memory/__tests__/skill-update-receipt-job.test.ts +580 -0
  199. package/src/plugins/defaults/memory/__tests__/turn-retrieval.test.ts +21 -0
  200. package/src/plugins/defaults/memory/graph/tools.ts +9 -5
  201. package/src/plugins/defaults/memory/hooks/conversation-deleted.ts +4 -0
  202. package/src/plugins/defaults/memory/hooks/user-prompt-submit.ts +7 -3
  203. package/src/plugins/defaults/memory/job-handlers.ts +8 -2
  204. package/src/plugins/defaults/memory/skill-update-receipt-job.ts +334 -0
  205. package/src/plugins/defaults/memory/tools.test.ts +17 -0
  206. package/src/plugins/defaults/memory/turn-retrieval.ts +8 -0
  207. package/src/plugins/defaults/memory/v3/__tests__/injection.test.ts +24 -0
  208. package/src/plugins/defaults/memory/v3/injector.ts +4 -4
  209. package/src/plugins/types.ts +2 -0
  210. package/src/providers/__tests__/search-provider-catalog.test.ts +8 -0
  211. package/src/providers/anthropic/client.ts +4 -0
  212. package/src/providers/gemini/client.ts +7 -1
  213. package/src/providers/inference/auth.ts +25 -0
  214. package/src/providers/inference/profile-probe.ts +1 -0
  215. package/src/{calls/__tests__/typesafe-noul.test.ts → providers/jev/ask.test.ts} +4 -4
  216. package/src/{calls/typesafe-noul.ts → providers/jev/ask.ts} +67 -34
  217. package/src/providers/openai/__tests__/api-error-normalization.test.ts +12 -0
  218. package/src/providers/openai/api-error-normalization.ts +4 -0
  219. package/src/providers/retry.ts +2 -0
  220. package/src/providers/search-provider-catalog.ts +10 -0
  221. package/src/providers/types.ts +7 -0
  222. package/src/providers/usage-tracking.ts +5 -3
  223. package/src/runtime/__tests__/agent-wake.test.ts +308 -0
  224. package/src/runtime/access-request-helper.ts +16 -9
  225. package/src/runtime/agent-wake-queue.ts +52 -0
  226. package/src/runtime/agent-wake.ts +111 -18
  227. package/src/runtime/channel-approval-types.ts +6 -38
  228. package/src/runtime/channel-approvals.ts +4 -5
  229. package/src/runtime/http-server.ts +4 -1
  230. package/src/runtime/introduction-policy.test.ts +17 -1
  231. package/src/runtime/introduction-policy.ts +25 -7
  232. package/src/runtime/migrations/vbundle-builder.ts +9 -0
  233. package/src/runtime/routes/__tests__/inference-profiles-routes.test.ts +21 -1
  234. package/src/runtime/routes/__tests__/inference-provider-connection-routes.test.ts +60 -0
  235. package/src/runtime/routes/__tests__/oauth-proxy-routes.test.ts +61 -3
  236. package/src/runtime/routes/auto-profile-routes.ts +83 -0
  237. package/src/runtime/routes/conversation-management-routes.ts +1 -3
  238. package/src/runtime/routes/conversation-routes.ts +9 -0
  239. package/src/runtime/routes/guardian-action-routes.ts +8 -23
  240. package/src/runtime/routes/host-cu-routes.ts +3 -1
  241. package/src/runtime/routes/index.ts +2 -0
  242. package/src/runtime/routes/inference-profiles-routes.ts +5 -2
  243. package/src/runtime/routes/inference-provider-connection-routes.ts +25 -8
  244. package/src/runtime/routes/migration-routes.ts +8 -2
  245. package/src/runtime/routes/oauth-proxy-passthrough.test.ts +32 -0
  246. package/src/runtime/routes/platform-routes.ts +6 -1
  247. package/src/runtime/routes/user-route-dispatcher.ts +1 -2
  248. package/src/runtime/web-presence.ts +3 -4
  249. package/src/schedule/schedule-store.ts +10 -0
  250. package/src/schedule/scheduler.ts +92 -24
  251. package/src/subagent/manager.ts +32 -12
  252. package/src/telegram/__tests__/webhook-health.test.ts +8 -0
  253. package/src/telemetry/telemetry-wire-source.json +1 -1
  254. package/src/telemetry/telemetry-wire.generated.ts +1 -0
  255. package/src/tools/background-tool-registry.ts +30 -3
  256. package/src/tools/browser/cdp-client/local-cdp-client.ts +1 -2
  257. package/src/tools/host-terminal/host-shell.ts +7 -0
  258. package/src/tools/network/__tests__/web-fetch-firecrawl.test.ts +28 -1
  259. package/src/tools/network/__tests__/web-fetch-metadata.test.ts +34 -0
  260. package/src/tools/network/__tests__/web-fetch-tinyfish.test.ts +35 -1
  261. package/src/tools/network/__tests__/web-search.test.ts +96 -0
  262. package/src/tools/network/web-fetch.ts +30 -9
  263. package/src/tools/network/web-search.ts +235 -4
  264. package/src/tools/skills/load.ts +13 -17
  265. package/src/tools/skills/scaffold-managed.ts +86 -71
  266. package/src/tools/terminal/shell-launch.test.ts +27 -1
  267. package/src/tools/terminal/shell.ts +4 -0
  268. package/src/tools/workspace-tools/loader.ts +1 -2
  269. package/src/usage/attribution.ts +18 -1
  270. package/src/util/abort-reasons.ts +2 -0
  271. package/src/util/errors.ts +1 -0
  272. package/src/util/oauth-request-body.test.ts +5 -1
  273. package/src/util/provider-error-patterns.ts +11 -0
  274. package/src/util/single-flight.test.ts +6 -0
  275. package/src/util/single-flight.ts +2 -0
  276. package/src/util/worker-pipe.test.ts +56 -10
  277. package/src/util/worker-pipe.ts +9 -4
  278. package/src/workspace/git-service.ts +6 -1
  279. package/src/workspace/migrations/158-repoint-opencode-host-provider-fragments.ts +163 -0
  280. package/src/workspace/migrations/__tests__/158-repoint-opencode-host-provider-fragments.test.ts +188 -0
  281. package/src/workspace/migrations/registry.ts +2 -0
@@ -198,6 +198,17 @@ function spokenText(frames: LiveVoiceServerFrame[]): string {
198
198
  }
199
199
 
200
200
  describe("live-voice triage-and-escalate routing", () => {
201
+ test("screen-action escalation carries its retrieval policy without speaking the marker", async () => {
202
+ const { starter } = scriptedStartVoiceTurn({
203
+ frontDoor: ["[ESCALATE_", "SCREEN] Let me circle that."],
204
+ escalated: ["There it is."],
205
+ });
206
+ const { frames, session } = createHarness(starter);
207
+ await driveTurn(session);
208
+ await waitFor(() => frames.some((frame) => frame.type === "tts_done"));
209
+ expect(starter.mock.calls[1]?.[0]?.screenAction).toBe(true);
210
+ expect(spokenText(frames)).not.toContain("ESCALATE");
211
+ });
201
212
  test("simple turn: only the fast front-door leg runs", async () => {
202
213
  const { starter } = scriptedStartVoiceTurn({
203
214
  frontDoor: ["Sure, it's Tuesday."],
@@ -217,7 +228,7 @@ describe("live-voice triage-and-escalate routing", () => {
217
228
 
218
229
  test("tricky turn: the escalate verdict hands off to a second quality leg", async () => {
219
230
  const { starter } = scriptedStartVoiceTurn({
220
- frontDoor: ["[1] ", "Let me think about that."],
231
+ frontDoor: ["[ESCALATE] ", "Let me think about that."],
221
232
  escalated: ["The detailed answer is 42."],
222
233
  });
223
234
  const { frames, session } = createHarness(starter);
@@ -493,6 +504,42 @@ describe("live-voice triage-and-escalate routing", () => {
493
504
  expect(spokenText(frames)).toContain("Give me a moment");
494
505
  });
495
506
 
507
+ test.each([
508
+ "I will highlight the Rotate control on your screen.",
509
+ "Let me highlight that control",
510
+ ])(
511
+ "a terminal verdict hands off without repeating speech: %s",
512
+ async (bridge) => {
513
+ const { starter } = scriptedStartVoiceTurn({
514
+ frontDoor: [bridge, " [", "ESCALATE", "]"],
515
+ escalated: ["The control is highlighted."],
516
+ });
517
+ const speech: string[] = [];
518
+ const { frames, session } = createHarness(starter, {
519
+ streamTtsAudio: async (options) => {
520
+ speech.push(options.text);
521
+ return {
522
+ provider: "fish-audio",
523
+ contentType: "audio/pcm",
524
+ sampleRate: 24_000,
525
+ chunks: 0,
526
+ bytes: 0,
527
+ };
528
+ },
529
+ });
530
+
531
+ await driveTurn(session);
532
+ await waitFor(() => frames.some((frame) => frame.type === "tts_done"));
533
+
534
+ expect(starter).toHaveBeenCalledTimes(2);
535
+ expect(starter.mock.calls[1]?.[0]?.routingLeg).toBe("escalated");
536
+ expect(starter.mock.calls[1]?.[0]?.spokenEscalationBridge).toBe(bridge);
537
+ expect(spokenText(frames)).toBe(`${bridge} The control is highlighted.`);
538
+ expect(speech).toEqual([bridge, "The control is highlighted."]);
539
+ await session.close("client_end");
540
+ },
541
+ );
542
+
496
543
  test("the escalated leg receives the front-door leg's actual spoken bridge", async () => {
497
544
  const { starter } = scriptedStartVoiceTurn({
498
545
  frontDoor: ["[1] Let me check your calendar.", " ignored tail"],
@@ -3702,12 +3702,13 @@ describe("LiveVoiceSession server VAD", () => {
3702
3702
  // thread instead of being dropped.
3703
3703
  await session.close("client_end");
3704
3704
  expect(injectMessageIntoParentMock).toHaveBeenCalledTimes(1);
3705
- const [conversationId, message] =
3705
+ const [conversationId, message, metadata] =
3706
3706
  injectMessageIntoParentMock.mock.calls[0] ?? [];
3707
3707
  expect(conversationId).toBe("conversation-123");
3708
3708
  expect(message).toContain("THE_RESULT");
3709
3709
  expect(message).toContain("[Background work finished]");
3710
3710
  expect(message).toContain("first question");
3711
+ expect(metadata).toEqual({ hidden: true, voiceContinuationResult: true });
3711
3712
  });
3712
3713
 
3713
3714
  test("closing during an active announcement delivers the result into the conversation", async () => {
@@ -3739,12 +3740,43 @@ describe("LiveVoiceSession server VAD", () => {
3739
3740
 
3740
3741
  await session.close("client_end");
3741
3742
  expect(injectMessageIntoParentMock).toHaveBeenCalledTimes(1);
3742
- const [conversationId, message] =
3743
+ const [conversationId, message, metadata] =
3743
3744
  injectMessageIntoParentMock.mock.calls[0] ?? [];
3744
3745
  expect(conversationId).toBe("conversation-123");
3745
3746
  expect(message).toContain("THE_RESULT");
3746
3747
  expect(message).toContain("[Background work finished]");
3747
3748
  expect(message).toContain("first question");
3749
+ expect(metadata).toEqual({ hidden: true, voiceContinuationResult: true });
3750
+ });
3751
+
3752
+ test("a continuation finishing after the room closes stays hidden in the conversation", async () => {
3753
+ injectMessageIntoParentMock.mockClear();
3754
+ const continuation = makeControlledContinuation();
3755
+ const { startVoiceTurn } = makeResurfaceTurnStarter();
3756
+ const { frames, session } = createHarness({
3757
+ finals: ["first question", ""],
3758
+ startVoiceTurn,
3759
+ streamTtsAudio: makeImmediateTts(),
3760
+ spawnBackgroundContinuation: continuation.spawnBackgroundContinuation,
3761
+ });
3762
+
3763
+ await session.start();
3764
+ await session.handleBinaryAudio(LOUD_CHUNK);
3765
+ await waitFor(() => frames.some((frame) => frame.type === "thinking"));
3766
+ await session.handleBinaryAudio(SUSTAINED_LOUD_CHUNK);
3767
+ await waitFor(
3768
+ () => continuation.spawnBackgroundContinuation.mock.calls.length === 1,
3769
+ );
3770
+ await session.close("client_end");
3771
+ expect(injectMessageIntoParentMock).not.toHaveBeenCalled();
3772
+
3773
+ continuation.finish("THE_RESULT");
3774
+ await waitFor(() => injectMessageIntoParentMock.mock.calls.length === 1);
3775
+ const [conversationId, message, metadata] =
3776
+ injectMessageIntoParentMock.mock.calls[0] ?? [];
3777
+ expect(conversationId).toBe("conversation-123");
3778
+ expect(message).toContain("THE_RESULT");
3779
+ expect(metadata).toEqual({ hidden: true, voiceContinuationResult: true });
3748
3780
  });
3749
3781
 
3750
3782
  test("a speculative user reply preserves the pending announcement", async () => {
@@ -77,6 +77,28 @@ describe("parseLiveVoiceClientTextFrame", () => {
77
77
  expect(result).toEqual({ ok: true, frame });
78
78
  });
79
79
 
80
+ test.each([true, false])(
81
+ "parses screen sharing state %p",
82
+ (screenSharing) => {
83
+ const frame = { type: "update_config", screenSharing } as const;
84
+ expect(parseLiveVoiceClientTextFrame(JSON.stringify(frame))).toEqual({
85
+ ok: true,
86
+ frame,
87
+ });
88
+ },
89
+ );
90
+
91
+ test("rejects malformed screen sharing state", () => {
92
+ expect(
93
+ parseLiveVoiceClientTextFrame(
94
+ JSON.stringify({
95
+ type: "update_config",
96
+ screenSharing: "true",
97
+ }),
98
+ ).ok,
99
+ ).toBe(false);
100
+ });
101
+
80
102
  test("parses an update_config frame with a single field, omitting the other", () => {
81
103
  const result = parseLiveVoiceClientTextFrame(
82
104
  JSON.stringify({ type: "update_config", silenceThresholdMs: 900 }),
@@ -17,7 +17,7 @@
17
17
  import {
18
18
  askTypesafeNoul,
19
19
  resolveTypesafeProvider,
20
- } from "../calls/typesafe-noul.js";
20
+ } from "../providers/jev/ask.js";
21
21
  import type { Provider } from "../providers/types.js";
22
22
 
23
23
  export const VOICE_CONTINUATION_JUDGE_CALL_SITE = "voiceContinuationJudge";
@@ -1217,6 +1217,7 @@ export class LiveVoiceSession implements LiveVoiceSessionContract {
1217
1217
  private releaseModeSessionResidency?: () => void;
1218
1218
  private cameraModeSessions?: CameraModeSessionProducer;
1219
1219
  private sightFrameSequence: Promise<void> = Promise.resolve();
1220
+ private screenSharing = false;
1220
1221
  /**
1221
1222
  * Mirrors phase changes to the iOS Live Activity through the platform, for
1222
1223
  * the case the client cannot cover: an app backgrounded long enough for iOS
@@ -2084,13 +2085,13 @@ export class LiveVoiceSession implements LiveVoiceSessionContract {
2084
2085
  }
2085
2086
 
2086
2087
  /**
2087
- * Apply a mid-session `update_config` frame: retune the live turn detector's
2088
- * pause ("pause before reply") and/or the barge-in guard ("interrupt
2089
- * sensitivity") without reconnecting. Each field is optional and independent;
2090
- * changes take effect from the next utterance. A no-op on manual (non-
2091
- * server_vad) sessions, which have no turn detector.
2088
+ * Apply screen-sharing state and turn-detection tuning independently.
2089
+ * Changes take effect from the next utterance.
2092
2090
  */
2093
2091
  private applyConfigUpdate(frame: LiveVoiceClientUpdateConfigFrame): void {
2092
+ if (frame.screenSharing !== undefined) {
2093
+ this.screenSharing = frame.screenSharing;
2094
+ }
2094
2095
  if (frame.silenceThresholdMs !== undefined) {
2095
2096
  this.turnDetector?.setSilenceThresholdMs(frame.silenceThresholdMs);
2096
2097
  this.silenceThresholdMs = frame.silenceThresholdMs;
@@ -3607,7 +3608,7 @@ export class LiveVoiceSession implements LiveVoiceSessionContract {
3607
3608
  const outcome: VoiceTaskOutcome = {
3608
3609
  taskId: `voice-continuation:${turn.turnId}`,
3609
3610
  message: buildContinuationResult(interruptedRequest, answer),
3610
- metadata: {},
3611
+ metadata: { hidden: true, voiceContinuationResult: true },
3611
3612
  source: "continuation",
3612
3613
  };
3613
3614
  accepted = this.receiveTaskOutcome(outcome);
@@ -5944,11 +5945,6 @@ export class LiveVoiceSession implements LiveVoiceSessionContract {
5944
5945
  ) {
5945
5946
  return;
5946
5947
  }
5947
- // One assistant turn at a time: a server_vad utterance that closes while
5948
- // the previous turn is still speaking waits; rearmAfterTurn retries it.
5949
- if (this.activeAssistantTurn) {
5950
- return;
5951
- }
5952
5948
  if (utterance.phase !== "transcriber_closed") {
5953
5949
  return;
5954
5950
  }
@@ -5971,6 +5967,12 @@ export class LiveVoiceSession implements LiveVoiceSessionContract {
5971
5967
  return;
5972
5968
  }
5973
5969
 
5970
+ // Empty cycles must rearm input even during a reply so provider speech
5971
+ // starts can still interrupt it. Only a real transcript waits its turn.
5972
+ if (this.activeAssistantTurn) {
5973
+ return;
5974
+ }
5975
+
5974
5976
  await this.launchAssistantTurn(utterance, content);
5975
5977
  }
5976
5978
 
@@ -6353,6 +6355,7 @@ export class LiveVoiceSession implements LiveVoiceSessionContract {
6353
6355
  frontDoor?: boolean;
6354
6356
  directEscalated?: boolean;
6355
6357
  spokenEscalationBridge?: string;
6358
+ screenAction?: boolean;
6356
6359
  attachments?: readonly string[];
6357
6360
  },
6358
6361
  ): Promise<boolean> {
@@ -6602,7 +6605,7 @@ export class LiveVoiceSession implements LiveVoiceSessionContract {
6602
6605
  userMessageInterface: "macos",
6603
6606
  assistantMessageInterface: "macos",
6604
6607
  ...(this.context.startFrame.client === "macos"
6605
- ? { macosDesktopSession: true }
6608
+ ? { macosDesktopSession: true, screenSharing: this.screenSharing }
6606
6609
  : {}),
6607
6610
  voiceTelemetry: {
6608
6611
  sessionId: this.context.sessionId,
@@ -6653,6 +6656,7 @@ export class LiveVoiceSession implements LiveVoiceSessionContract {
6653
6656
  ? { overrideProfile: leg.overrideProfile }
6654
6657
  : {}),
6655
6658
  ...(leg.routingLeg != null ? { routingLeg: leg.routingLeg } : {}),
6659
+ ...(leg.screenAction === true ? { screenAction: true } : {}),
6656
6660
  ...(leg.spokenEscalationBridge != null
6657
6661
  ? { spokenEscalationBridge: leg.spokenEscalationBridge }
6658
6662
  : {}),
@@ -6922,13 +6926,15 @@ export class LiveVoiceSession implements LiveVoiceSessionContract {
6922
6926
  ): void {
6923
6927
  const { spokenBridge, usesFallback, language } = bridge;
6924
6928
  if (!usesFallback) {
6925
- this.markFirstAssistantDelta(activeTurn.utterance, activeTurn.turnId);
6926
- this.markAssistantDelta(activeTurn);
6927
- void this.sendFrame(
6928
- { type: "assistant_text_delta", text: spokenBridge },
6929
- () => !activeTurn.abortController.signal.aborted && !this.isClosed,
6930
- );
6931
- this.bufferAssistantTextForTts(activeTurn.token, `${spokenBridge} `);
6929
+ if (!bridge.alreadyReleased) {
6930
+ this.markFirstAssistantDelta(activeTurn.utterance, activeTurn.turnId);
6931
+ this.markAssistantDelta(activeTurn);
6932
+ void this.sendFrame(
6933
+ { type: "assistant_text_delta", text: spokenBridge },
6934
+ () => !activeTurn.abortController.signal.aborted && !this.isClosed,
6935
+ );
6936
+ this.bufferAssistantTextForTts(activeTurn.token, `${spokenBridge} `);
6937
+ }
6932
6938
  // Force-flush now: on the TTS path an unpunctuated bridge would
6933
6939
  // otherwise sit buffered until a sentence boundary and leave the
6934
6940
  // caller in silence during the escalated model's call.
@@ -276,16 +276,16 @@ export interface LiveVoiceClientEndFrame {
276
276
  }
277
277
 
278
278
  /**
279
- * Mid-session tuning update: applies the same turn-detection knobs the start
280
- * frame carries to the *running* session, so the client can retune "pause
281
- * before reply" / "interrupt sensitivity" without reconnecting. Each field is
282
- * optional and independently applied; the same bounds as the start frame apply.
283
- * Only meaningful for `server_vad` sessions.
279
+ * Mid-session screen-sharing state and turn-detection tuning. Each field is
280
+ * optional and independently applied. Tuning uses the start frame's bounds
281
+ * and affects `server_vad` sessions.
284
282
  */
285
283
  export interface LiveVoiceClientUpdateConfigFrame {
286
284
  readonly type: "update_config";
287
285
  readonly silenceThresholdMs?: number;
288
286
  readonly bargeInMinSpeechMs?: number;
287
+ /** A shared desktop surface is available for annotation. */
288
+ readonly screenSharing?: boolean;
289
289
  }
290
290
 
291
291
  /**
@@ -1279,6 +1279,14 @@ function validateSightFrameTiming(
1279
1279
  function validateUpdateConfigFrame(
1280
1280
  value: Record<string, unknown>,
1281
1281
  ): LiveVoiceParseResult<LiveVoiceClientUpdateConfigFrame> {
1282
+ if ("screenSharing" in value && typeof value.screenSharing !== "boolean") {
1283
+ return protocolError(
1284
+ "invalid_field",
1285
+ "update_config field screenSharing must be a boolean",
1286
+ "screenSharing",
1287
+ "update_config",
1288
+ );
1289
+ }
1282
1290
  if (
1283
1291
  "silenceThresholdMs" in value &&
1284
1292
  !isIntInRange(
@@ -1315,6 +1323,9 @@ function validateUpdateConfigFrame(
1315
1323
  ok: true,
1316
1324
  frame: {
1317
1325
  type: "update_config",
1326
+ ...(typeof value.screenSharing === "boolean"
1327
+ ? { screenSharing: value.screenSharing }
1328
+ : {}),
1318
1329
  ...(typeof value.silenceThresholdMs === "number"
1319
1330
  ? { silenceThresholdMs: value.silenceThresholdMs }
1320
1331
  : {}),
@@ -11,10 +11,9 @@
11
11
  * withdrawal time, the same way the adapter resolved it to deliver.
12
12
  */
13
13
 
14
- import {
15
- isParkAction,
16
- resolveDecisionStatusWord,
17
- } from "../../../runtime/channel-approval-types.js";
14
+ import { isParkGuardianAction } from "@vellumai/service-contracts/guardian-requests";
15
+
16
+ import { resolveDecisionStatusWord } from "../../../runtime/channel-approval-types.js";
18
17
  import { getLogger } from "../../../util/logger.js";
19
18
  import { openDiscordDmChannel } from "./api.js";
20
19
  import { editDiscordMessage } from "./send.js";
@@ -30,7 +29,7 @@ const STATUS_GLYPH: Record<string, string> = {
30
29
  const PARK_STATUS_GLYPH = "⏸️";
31
30
 
32
31
  function buildStatusText(status: string, decidedAction?: string): string {
33
- const park = status === "denied" && isParkAction(decidedAction);
32
+ const park = status === "denied" && isParkGuardianAction(decidedAction);
34
33
  const glyph = park ? PARK_STATUS_GLYPH : (STATUS_GLYPH[status] ?? "");
35
34
  const word = resolveDecisionStatusWord(status, decidedAction);
36
35
  return glyph ? `${glyph} ${word}` : word;
@@ -33,6 +33,10 @@ export const GMAIL_API_BASE_URL =
33
33
  * requests Calendar-only). Resolving against Gmail read access turns a
34
34
  * downstream 403 into an actionable "reconnect Google and grant Gmail" error
35
35
  * at resolution time when the selected connection cannot read Gmail.
36
+ *
37
+ * Managed connections never carry this scope: Vellum's app grants Gmail as
38
+ * `https://mail.google.com/`, which `scopeDifference` in `oauth/scope-utils.ts`
39
+ * accepts as covering it.
36
40
  */
37
41
  export const GMAIL_REQUIRED_SCOPES = [
38
42
  "https://www.googleapis.com/auth/gmail.readonly",
@@ -15,10 +15,9 @@
15
15
  * back to editing the message down to a status-only block — still an edit.
16
16
  */
17
17
 
18
- import {
19
- isParkAction,
20
- resolveDecisionStatusWord,
21
- } from "../../../runtime/channel-approval-types.js";
18
+ import { isParkGuardianAction } from "@vellumai/service-contracts/guardian-requests";
19
+
20
+ import { resolveDecisionStatusWord } from "../../../runtime/channel-approval-types.js";
22
21
  import { getLogger } from "../../../util/logger.js";
23
22
  import { callSlackApi, getSlackMessageBlocks } from "./api.js";
24
23
 
@@ -79,7 +78,8 @@ export interface WithdrawSlackApprovalCardParams {
79
78
  * Uses Slack's `<!date>` token so the time renders in each viewer's timezone.
80
79
  */
81
80
  function buildStatusText(params: WithdrawSlackApprovalCardParams): string {
82
- const park = params.status === "denied" && isParkAction(params.decidedAction);
81
+ const park =
82
+ params.status === "denied" && isParkGuardianAction(params.decidedAction);
83
83
  const glyph = park ? PARK_STATUS_GLYPH : (STATUS_GLYPH[params.status] ?? "");
84
84
  const word = resolveDecisionStatusWord(params.status, params.decidedAction);
85
85
  let line = glyph ? `${glyph} *${word}*` : `*${word}*`;
@@ -25,10 +25,9 @@
25
25
  * handling.
26
26
  */
27
27
 
28
- import {
29
- isParkAction,
30
- resolveDecisionStatusWord,
31
- } from "../../../runtime/channel-approval-types.js";
28
+ import { isParkGuardianAction } from "@vellumai/service-contracts/guardian-requests";
29
+
30
+ import { resolveDecisionStatusWord } from "../../../runtime/channel-approval-types.js";
32
31
  import { getLogger } from "../../../util/logger.js";
33
32
  import { callTelegramBotApi } from "./api.js";
34
33
 
@@ -73,7 +72,7 @@ export interface WithdrawTelegramApprovalCardParams {
73
72
 
74
73
  /** Build the plain-text outcome line for the quoted status reply. */
75
74
  function buildStatusText(status: string, decidedAction?: string): string {
76
- const park = status === "denied" && isParkAction(decidedAction);
75
+ const park = status === "denied" && isParkGuardianAction(decidedAction);
77
76
  const glyph = park ? PARK_STATUS_GLYPH : (STATUS_GLYPH[status] ?? "");
78
77
  const word = resolveDecisionStatusWord(status, decidedAction);
79
78
  return glyph ? `${glyph} ${word}` : word;
@@ -0,0 +1,28 @@
1
+ /** Fixture builders for tests that read a fake `/proc` tree. */
2
+
3
+ /** A `/proc/<pid>/stat` line; times in clock ticks, rss in pages. */
4
+ export function stat(
5
+ pid: number,
6
+ comm: string,
7
+ state: string,
8
+ ppid: number,
9
+ startTicks: number,
10
+ usage: { utime?: number; stime?: number; rssPages?: number } = {},
11
+ ): string {
12
+ // Fields 3..24: state ppid pgrp session tty tpgid flags minflt cminflt
13
+ // majflt cmajflt utime stime cutime cstime priority nice threads
14
+ // itrealvalue starttime vsize rss, then rsslim.
15
+ const fields = [
16
+ state,
17
+ ppid,
18
+ ...Array(9).fill(0),
19
+ usage.utime ?? 0,
20
+ usage.stime ?? 0,
21
+ ...Array(6).fill(0),
22
+ startTicks,
23
+ 0,
24
+ usage.rssPages ?? 0,
25
+ 0,
26
+ ];
27
+ return `${pid} (${comm}) ${fields.join(" ")}\n`;
28
+ }
@@ -0,0 +1,232 @@
1
+ /**
2
+ * Tests for the mid-stall `/proc` wait-state reader, against a fixture proc
3
+ * tree so they run on any platform. The key behavior: an epoll wait on the
4
+ * daemon's own loop (its set holds the HTTP listening socket) must read
5
+ * differently from a nested synchronous wait (a private set without it).
6
+ */
7
+
8
+ import {
9
+ mkdirSync,
10
+ mkdtempSync,
11
+ rmSync,
12
+ symlinkSync,
13
+ writeFileSync,
14
+ } from "node:fs";
15
+ import { tmpdir } from "node:os";
16
+ import { join } from "node:path";
17
+ import { afterEach, beforeEach, describe, expect, test } from "bun:test";
18
+
19
+ import {
20
+ parseEpollTargetFds,
21
+ parseListeningSocketInodes,
22
+ parseProcStat,
23
+ parseProcSyscall,
24
+ readStallWaitState,
25
+ } from "../proc-wait-state.js";
26
+ import { stat } from "./proc-fixtures.js";
27
+
28
+ const DAEMON = 100;
29
+ const EPFD = 7;
30
+
31
+ let procRoot: string;
32
+
33
+ function write(path: string, content: string): void {
34
+ const full = join(procRoot, path);
35
+ mkdirSync(join(full, ".."), { recursive: true });
36
+ writeFileSync(full, content);
37
+ }
38
+
39
+ function fdLink(pid: number, fd: number, target: string): void {
40
+ const dir = join(procRoot, String(pid), "fd");
41
+ mkdirSync(dir, { recursive: true });
42
+ symlinkSync(target, join(dir, String(fd)));
43
+ }
44
+
45
+ /**
46
+ * A daemon whose main thread waits in epoll_wait (x64 syscall 232) on
47
+ * `EPFD`, which watches the given fds.
48
+ */
49
+ function daemonWaitingOn(fds: Record<number, string>): void {
50
+ write(
51
+ `${DAEMON}/task/${DAEMON}/syscall`,
52
+ `232 0x${EPFD.toString(16)} 0x7ffd 0x400 0x5 0x0 0x0 0x7ffd 0x7f00\n`,
53
+ );
54
+ write(`${DAEMON}/task/${DAEMON}/stat`, stat(DAEMON, "bun", "S", 1, 500));
55
+ write(`${DAEMON}/task/${DAEMON}/wchan`, "do_epoll_wait");
56
+ write(`${DAEMON}/stat`, stat(DAEMON, "bun", "S", 1, 500));
57
+ write(
58
+ `${DAEMON}/fdinfo/${EPFD}`,
59
+ "pos:\t0\nflags:\t02000002\nmnt_id:\t15\n" +
60
+ Object.keys(fds)
61
+ .map(
62
+ (fd) =>
63
+ `tfd: ${fd} events: 19 data: 0 pos:0 ino:1 sdev:8\n`,
64
+ )
65
+ .join(""),
66
+ );
67
+ fdLink(DAEMON, EPFD, "anon_inode:[eventpoll]");
68
+ for (const [fd, target] of Object.entries(fds)) {
69
+ fdLink(DAEMON, Number(fd), target);
70
+ }
71
+ // Socket inode 111 listens (state 0A); 222 is an established connection.
72
+ write(
73
+ `${DAEMON}/net/tcp`,
74
+ " sl local_address rem_address st tx_queue rx_queue tr tm->when retrnsmt uid timeout inode\n" +
75
+ " 0: 00000000:1F40 00000000:0000 0A 00000000:00000000 00:00000000 00000000 0 0 111 1 0 100 0 0 10 0\n" +
76
+ " 1: 0100007F:1F40 0100007F:9C40 01 00000000:00000000 00:00000000 00000000 0 0 222 1 0 20 4 30 10 -1\n",
77
+ );
78
+ write("uptime", "1000.00 900.00\n");
79
+ }
80
+
81
+ beforeEach(() => {
82
+ procRoot = mkdtempSync(join(tmpdir(), "proc-wait-state-"));
83
+ });
84
+
85
+ afterEach(() => {
86
+ rmSync(procRoot, { recursive: true, force: true });
87
+ });
88
+
89
+ describe("readStallWaitState", () => {
90
+ test("an epoll wait on the daemon's own loop counts the listening socket", () => {
91
+ // GIVEN the waited epoll set holds the HTTP listener plus loop plumbing
92
+ daemonWaitingOn({
93
+ 3: "socket:[111]",
94
+ 4: "socket:[222]",
95
+ 5: "anon_inode:[eventfd]",
96
+ 6: "anon_inode:[timerfd]",
97
+ });
98
+
99
+ // WHEN the wait state is read
100
+ const state = readStallWaitState(DAEMON, procRoot);
101
+
102
+ // THEN the set is attributed to the main loop
103
+ expect(state.syscall).toBe(232);
104
+ expect(state.epoll).toEqual({
105
+ fd: EPFD,
106
+ watched: 4,
107
+ listeningSockets: 1,
108
+ sockets: 2,
109
+ pipes: 0,
110
+ eventfds: 1,
111
+ timerfds: 1,
112
+ other: 0,
113
+ });
114
+ });
115
+
116
+ test("a nested synchronous wait has no listening socket and a live child", () => {
117
+ // GIVEN a private epoll set watching only a child's stdout pipe
118
+ daemonWaitingOn({ 9: "pipe:[555]" });
119
+ write("200/stat", stat(200, "git", "R", DAEMON, 97_000)); // started 30s ago
120
+ write("300/stat", stat(300, "unrelated", "S", 1, 1_000));
121
+
122
+ // WHEN the wait state is read
123
+ const state = readStallWaitState(DAEMON, procRoot);
124
+
125
+ // THEN the wait is visibly not the main loop, and names the child
126
+ expect(state.epoll?.listeningSockets).toBe(0);
127
+ expect(state.epoll?.pipes).toBe(1);
128
+ expect(state.children).toEqual([
129
+ { pid: 200, comm: "git", state: "R", ageMs: 30_000 },
130
+ ]);
131
+ });
132
+
133
+ test("groups threads by comm, state and wait channel", () => {
134
+ // GIVEN the main thread plus two idle worker threads in the same futex wait
135
+ daemonWaitingOn({ 3: "socket:[111]" });
136
+ for (const tid of [101, 102]) {
137
+ write(`${DAEMON}/task/${tid}/stat`, stat(tid, "Bun Pool 0", "S", 1, 500));
138
+ write(`${DAEMON}/task/${tid}/wchan`, "futex_wait_queue");
139
+ }
140
+
141
+ // WHEN the wait state is read
142
+ const state = readStallWaitState(DAEMON, procRoot);
143
+
144
+ // THEN identical threads collapse into one counted group
145
+ expect(state.threads).toContainEqual({
146
+ comm: "Bun Pool 0",
147
+ state: "S",
148
+ wchan: "futex_wait_queue",
149
+ count: 2,
150
+ });
151
+ expect(state.threads).toContainEqual({
152
+ comm: "bun",
153
+ state: "S",
154
+ wchan: "do_epoll_wait",
155
+ count: 1,
156
+ });
157
+ });
158
+
159
+ test("a non-epoll wait skips the epoll set", () => {
160
+ // GIVEN the main thread blocked in wait4 on a child (arm64 syscall 260),
161
+ // whose first argument is a pid, not an epoll fd
162
+ write(
163
+ `${DAEMON}/task/${DAEMON}/syscall`,
164
+ "260 0x1b 0x0 0x0 0x0 0x0 0x0 0xffff 0xffff\n",
165
+ );
166
+ fdLink(DAEMON, 0x1b, "pipe:[1]");
167
+
168
+ // WHEN the wait state is read
169
+ const state = readStallWaitState(DAEMON, procRoot);
170
+
171
+ // THEN only the syscall is reported
172
+ expect(state.syscall).toBe(260);
173
+ expect(state.epoll).toBeNull();
174
+ });
175
+
176
+ test("an unreadable /proc yields an empty state, never a throw", () => {
177
+ // GIVEN no proc tree at all (non-Linux, or a permission boundary)
178
+ // WHEN the wait state is read
179
+ const state = readStallWaitState(DAEMON, join(procRoot, "missing"));
180
+
181
+ // THEN every field degrades to empty
182
+ expect(state).toEqual({
183
+ syscall: null,
184
+ epoll: null,
185
+ children: [],
186
+ threads: [],
187
+ });
188
+ });
189
+ });
190
+
191
+ describe("parsers", () => {
192
+ test("parseProcStat handles a comm containing spaces and parentheses", () => {
193
+ expect(
194
+ parseProcStat(
195
+ stat(5, "Bun (Pool) 1", "D", 4, 42, {
196
+ utime: 7,
197
+ stime: 3,
198
+ rssPages: 9,
199
+ }),
200
+ ),
201
+ ).toEqual({
202
+ comm: "Bun (Pool) 1",
203
+ state: "D",
204
+ ppid: 4,
205
+ cpuTicks: 10,
206
+ startTicks: 42,
207
+ rssPages: 9,
208
+ });
209
+ expect(parseProcStat("garbage")).toBeNull();
210
+ });
211
+
212
+ test("parseProcSyscall reads running and numbered forms", () => {
213
+ expect(parseProcSyscall("running\n")).toEqual({ nr: "running", args: [] });
214
+ expect(parseProcSyscall("281 0x1a 0x0\n")).toEqual({
215
+ nr: 281,
216
+ args: [26, 0],
217
+ });
218
+ expect(parseProcSyscall("")).toBeNull();
219
+ });
220
+
221
+ test("parseEpollTargetFds and parseListeningSocketInodes", () => {
222
+ expect(
223
+ parseEpollTargetFds("pos:\t0\ntfd: 3 events: 19\ntfd: 12 events: 1\n"),
224
+ ).toEqual([3, 12]);
225
+ const header = "sl local rem st tx rx tr retr uid timeout inode\n";
226
+ expect([
227
+ ...parseListeningSocketInodes(
228
+ `${header}0: a b 0A q:q t:t r 0 0 77 1\n1: a b 01 q:q t:t r 0 0 88 1\n`,
229
+ ),
230
+ ]).toEqual(["77"]);
231
+ });
232
+ });