@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
@@ -1,7 +1,7 @@
1
1
  import { refreshBackgroundWakeIntent } from "../background-wake/publisher.js";
2
2
  import { resolveSingleRouteProfileKey } from "../config/llm-resolver.js";
3
3
  import { getConfig } from "../config/loader.js";
4
- import { findConversation } from "../daemon/conversation-registry.js";
4
+ import { findConversationOrSubagent } from "../daemon/conversation-registry.js";
5
5
  import {
6
6
  checkDiskPressureBackgroundGate,
7
7
  diskPressureBackgroundSkipLogFields,
@@ -16,7 +16,10 @@ import { getConversation } from "../persistence/conversation-crud.js";
16
16
  import { isLifecycleQuiesced } from "../persistence/lifecycle-quiesce.js";
17
17
  import { invalidateAssistantInferredItemsForConversation } from "../plugins/defaults/memory/task-memory-cleanup.js";
18
18
  import { dispatchProviderResolvable } from "../providers/provider-resolvability.js";
19
- import { wakeAgentForOpportunity } from "../runtime/agent-wake.js";
19
+ import {
20
+ hasPendingAgentWake,
21
+ wakeAgentForOpportunity,
22
+ } from "../runtime/agent-wake.js";
20
23
  import { broadcastMessage } from "../runtime/assistant-event-hub.js";
21
24
  import {
22
25
  type BackgroundJobErrorKind,
@@ -27,6 +30,10 @@ import { runSequencesOnce } from "../sequence/engine.js";
27
30
  import { getSubagentManager } from "../subagent/index.js";
28
31
  import type { TurnFailure } from "../telemetry/turn-outcome.js";
29
32
  import { recordWatchdogEvent } from "../telemetry/watchdog-events-store.js";
33
+ import {
34
+ cancelBackgroundTools,
35
+ hasBackgroundToolWork,
36
+ } from "../tools/background-tool-registry.js";
30
37
  import { getLogger } from "../util/logger.js";
31
38
  import { describeScheduleSource } from "../util/schedule-source-key.js";
32
39
  import {
@@ -89,6 +96,28 @@ const DELEGATED_WORK_POLL_MS = 100;
89
96
  */
90
97
  const DELEGATED_WORK_QUIET_POLLS = 2;
91
98
 
99
+ function hasPendingScheduledWork(
100
+ conversationId: string,
101
+ runId: string,
102
+ ): boolean {
103
+ const conversation = findConversationOrSubagent(conversationId);
104
+ const manager = getSubagentManager();
105
+ return (
106
+ (conversation?.pendingQueuedDispatches?.get(runId)?.size ?? 0) > 0 ||
107
+ (conversation?.isProcessing() === true &&
108
+ conversation.currentTurnCronRunId === runId) ||
109
+ conversation
110
+ ?.snapshotQueuedMessages()
111
+ .some((message) => message.cronRunId === runId) === true ||
112
+ hasBackgroundToolWork(conversationId, { cronRunId: runId }) ||
113
+ hasPendingAgentWake(conversationId, runId) ||
114
+ manager.hasActiveChildren(conversationId, runId) ||
115
+ manager
116
+ .getChildrenOf(conversationId)
117
+ .some((child) => hasPendingScheduledWork(child.conversationId, runId))
118
+ );
119
+ }
120
+
92
121
  /**
93
122
  * Wait for work a scheduled turn delegated before the run is called done.
94
123
  *
@@ -99,54 +128,76 @@ const DELEGATED_WORK_QUIET_POLLS = 2;
99
128
  * latest assistant row, so completing at the first resolve ships the
100
129
  * pre-consult reply and drops the informed one for good.
101
130
  *
102
- * Returns immediately for a conversation that never delegated anything, which
103
- * is the ordinary case, so no scheduled run pays for this unless it spawned.
131
+ * Background commands and their queued wakes are included, even while a wake
132
+ * is resolving its conversation before acquiring the processing lock.
104
133
  *
105
134
  * Bounded by what is left of the schedule turn timeout, so the whole run (its
106
135
  * turn plus the work it delegated) stays inside the one ceiling that stops a
107
- * wedged schedule from blocking the next tick. Exhausting the ceiling is not a
108
- * failure: the run still completes and still produces a result, just from
109
- * whatever had been written by then.
136
+ * wedged schedule from blocking the next tick. Unsettled work at the ceiling
137
+ * fails the attempt, so partial output cannot consume its completion alert.
110
138
  */
111
139
  async function awaitDelegatedWork(
112
140
  conversationId: string,
113
141
  runStartedAt: number,
142
+ runId: string,
114
143
  rlog: typeof log,
115
- ): Promise<void> {
144
+ ): Promise<boolean> {
116
145
  if (!conversationId || conversationId.startsWith("bootstrap-error:")) {
117
- return;
118
- }
119
- const conversation = findConversation(conversationId);
120
- if (!conversation) {
121
- return;
146
+ return true;
122
147
  }
123
- // Terminal children stay readable for their retention window, so this asks
124
- // "did this conversation ever delegate?" and skips the polling entirely for
125
- // the schedules that never do.
126
- if (getSubagentManager().getChildrenOf(conversationId).length === 0) {
127
- return;
148
+ if (
149
+ !getSubagentManager()
150
+ .getChildrenOf(conversationId)
151
+ .some((child) => child.config.cronRunId === runId) &&
152
+ !hasPendingScheduledWork(conversationId, runId)
153
+ ) {
154
+ return true;
128
155
  }
129
156
 
130
157
  const deadline =
131
158
  runStartedAt + getConfig().timeouts.scheduleTurnTimeoutSec * 1000;
132
159
  let quiet = 0;
133
160
  while (Date.now() < deadline) {
134
- if (conversation.hasInFlightWork()) {
161
+ if (hasPendingScheduledWork(conversationId, runId)) {
135
162
  quiet = 0;
136
163
  } else {
137
164
  quiet += 1;
138
165
  if (quiet >= DELEGATED_WORK_QUIET_POLLS) {
139
- return;
166
+ return true;
140
167
  }
141
168
  }
142
169
  await new Promise((resolve) => setTimeout(resolve, DELEGATED_WORK_POLL_MS));
143
170
  }
144
171
  rlog.warn(
145
172
  { conversationId },
146
- "Delegated work still in flight at the schedule turn ceiling; producing the result from what is written",
173
+ "Delegated work did not settle before the schedule turn ceiling",
174
+ );
175
+ return false;
176
+ }
177
+
178
+ function cancelTimedOutScheduleWork(
179
+ conversationId: string,
180
+ runId: string,
181
+ ): void {
182
+ const manager = getSubagentManager();
183
+ for (const child of manager.getChildrenOf(conversationId)) {
184
+ cancelTimedOutScheduleWork(child.conversationId, runId);
185
+ if (child.config.cronRunId !== runId) {
186
+ continue;
187
+ }
188
+ manager.abort(child.config.id, undefined, conversationId, {
189
+ cronRunId: runId,
190
+ });
191
+ }
192
+ findConversationOrSubagent(conversationId)?.abortScheduledRun(runId);
193
+ cancelBackgroundTools(
194
+ (tool) =>
195
+ tool.conversationId === conversationId && tool.cronRunId === runId,
196
+ "schedule_timeout",
147
197
  );
148
198
  }
149
199
 
200
+ import { trackDaemonActivity } from "../daemon/activity-trail.js";
150
201
  import type { ScheduleMessageOptions } from "./scheduler-types.js";
151
202
 
152
203
  /**
@@ -557,6 +608,14 @@ export async function runScheduleOnce(): Promise<number> {
557
608
  */
558
609
  export async function runScheduleDueWorkOnce(
559
610
  options: SchedulerRunDueWorkOptions = {},
611
+ ): Promise<SchedulerDueWorkResult> {
612
+ return trackDaemonActivity({ kind: "schedule_tick" }, () =>
613
+ runScheduleDueWork(options),
614
+ );
615
+ }
616
+
617
+ async function runScheduleDueWork(
618
+ options: SchedulerRunDueWorkOptions,
560
619
  ): Promise<SchedulerDueWorkResult> {
561
620
  const minStartBudgetMs = options.minStartBudgetMs ?? 0;
562
621
  const result: SchedulerDueWorkResult = {
@@ -1177,10 +1236,16 @@ export async function runDueSchedulesOnce(
1177
1236
  failedTurn = result.turnFailure;
1178
1237
  }
1179
1238
 
1239
+ if (
1240
+ ok &&
1241
+ !(await awaitDelegatedWork(conversationId, runStartedAt, runId, log))
1242
+ ) {
1243
+ ok = false;
1244
+ errorKind = "timeout";
1245
+ errorMsg = "Scheduled work did not finish before its time limit";
1246
+ }
1247
+
1180
1248
  if (ok) {
1181
- // The turn resolved, but work it delegated may still be running. Settle
1182
- // that before the run is called done and its one result is produced.
1183
- await awaitDelegatedWork(conversationId, runStartedAt, log);
1184
1249
  await completeScheduleRun(runId, { status: "ok" });
1185
1250
  // Automatic completion notification for successful execute-mode runs.
1186
1251
  // Quiet schedules skip this fallback so a clean tick stays silent.
@@ -1218,6 +1283,9 @@ export async function runDueSchedulesOnce(
1218
1283
  : "Schedule execution failed",
1219
1284
  );
1220
1285
  await completeScheduleRun(runId, { status: "error", error: errorMsg });
1286
+ if (errorKind === "timeout") {
1287
+ cancelTimedOutScheduleWork(conversationId, runId);
1288
+ }
1221
1289
  await handleExecutionFailure({
1222
1290
  job,
1223
1291
  errorMsg: errorMsg ?? "Schedule run failed",
@@ -1331,6 +1331,8 @@ export class SubagentManager {
1331
1331
  callerConversationId?: string,
1332
1332
  options?: {
1333
1333
  suppressNotification?: boolean;
1334
+ /** Restricts cancellation to one schedule firing while preserving user turns. */
1335
+ cronRunId?: string;
1334
1336
  /**
1335
1337
  * Replaces the default "explicitly aborted, do not retry" injection for
1336
1338
  * an abort the parent did not ask for, whose right follow-up differs.
@@ -1342,6 +1344,12 @@ export class SubagentManager {
1342
1344
  if (!managed) {
1343
1345
  return false;
1344
1346
  }
1347
+ if (
1348
+ options?.cronRunId &&
1349
+ managed.state.config.cronRunId !== options.cronRunId
1350
+ ) {
1351
+ return false;
1352
+ }
1345
1353
  if (TERMINAL_STATUSES.has(managed.state.status)) {
1346
1354
  return false;
1347
1355
  }
@@ -1361,13 +1369,17 @@ export class SubagentManager {
1361
1369
  return false;
1362
1370
  }
1363
1371
 
1364
- managed.conversation?.abort(
1365
- createAbortReason(
1366
- "subagent_aborted",
1367
- "SubagentManager.abort",
1368
- managed.conversation.conversationId,
1369
- ),
1370
- );
1372
+ if (options?.cronRunId) {
1373
+ managed.conversation?.abortScheduledRun(options.cronRunId);
1374
+ } else {
1375
+ managed.conversation?.abort(
1376
+ createAbortReason(
1377
+ "subagent_aborted",
1378
+ "SubagentManager.abort",
1379
+ managed.conversation.conversationId,
1380
+ ),
1381
+ );
1382
+ }
1371
1383
  managed.state.completedAt = Date.now();
1372
1384
  // Capture the conversation's latest usage before emitting the terminal
1373
1385
  // status. `subagent_status_changed` ships `state.usage`, and the abort path
@@ -1553,9 +1565,8 @@ export class SubagentManager {
1553
1565
  *
1554
1566
  * `opts.cronRunId` is the firing that produced THIS message, not the one the
1555
1567
  * subagent was spawned under: a continuation turn's spend belongs to the
1556
- * firing that asked for it. Only the immediately-processed turn carries it,
1557
- * since a queued message drains through the conversation's own queue, which
1558
- * holds no per-message run options.
1568
+ * firing that asked for it. Both immediate turns and queued messages carry
1569
+ * that ownership through the conversation loop.
1559
1570
  *
1560
1571
  * An advisor takes no follow-up (`one_shot`). A consult answers one question
1561
1572
  * once, and a follow-up would escape the budget its spawn set: the drained
@@ -1586,7 +1597,10 @@ export class SubagentManager {
1586
1597
  }
1587
1598
 
1588
1599
  // If the conversation is busy, queue the message; otherwise process immediately.
1589
- const result = managed.conversation.enqueueMessage({ content: trimmed });
1600
+ const result = managed.conversation.enqueueMessage({
1601
+ content: trimmed,
1602
+ cronRunId: opts?.cronRunId,
1603
+ });
1590
1604
  if (result.rejected) {
1591
1605
  return "sent"; // error event already delivered via sendToClient
1592
1606
  }
@@ -1764,7 +1778,7 @@ export class SubagentManager {
1764
1778
  * injects into the parent and releases the child's conversation. Evicting the
1765
1779
  * parent in that window would race its own teardown.
1766
1780
  */
1767
- hasActiveChildren(parentConversationId: string): boolean {
1781
+ hasActiveChildren(parentConversationId: string, cronRunId?: string): boolean {
1768
1782
  const children = this.parentToChildren.get(parentConversationId);
1769
1783
  if (!children) {
1770
1784
  return false;
@@ -1774,6 +1788,12 @@ export class SubagentManager {
1774
1788
  if (!managed) {
1775
1789
  continue;
1776
1790
  }
1791
+ if (
1792
+ cronRunId !== undefined &&
1793
+ managed.state.config.cronRunId !== cronRunId
1794
+ ) {
1795
+ continue;
1796
+ }
1777
1797
  if (managed.runInFlight || !TERMINAL_STATUSES.has(managed.state.status)) {
1778
1798
  return true;
1779
1799
  }
@@ -29,8 +29,16 @@ let emitFails = false;
29
29
 
30
30
  // ── Module mocks ──────────────────────────────────────────────────────
31
31
 
32
+ // Spread the real module: mocks are shared across files in a combined run,
33
+ // and a wholesale replacement drops the exports peer modules import.
34
+ const actualSecureKeys = await import("../../security/secure-keys.js");
32
35
  mock.module("../../security/secure-keys.js", () => ({
36
+ ...actualSecureKeys,
33
37
  getSecureKeyAsync: async (account: string) => secureKeyValues.get(account),
38
+ getSecureKeyResultAsync: async (account: string) => ({
39
+ value: secureKeyValues.get(account),
40
+ unreachable: false,
41
+ }),
34
42
  }));
35
43
 
36
44
  mock.module("../../security/credential-key.js", () => ({
@@ -1,4 +1,4 @@
1
1
  {
2
2
  "sourceRepo": "vellum-ai/vellum-assistant-platform",
3
- "sourceSha": "65df18670801af2d86fff3ba9b9bc12007c07d73"
3
+ "sourceSha": "55599f8f2bc422177cc423020043577d7ee36264"
4
4
  }
@@ -446,6 +446,7 @@ export type TelemetryEvent = z.infer<typeof telemetryEventSchema>;
446
446
  // event of one of these types is rejected (dropped) by ingest.
447
447
  export const PLATFORM_MANAGED_EVENT_TYPES = [
448
448
  "credit_balance_depleted",
449
+ "free_tier_daily_limit_reached",
449
450
  "plugin_installed",
450
451
  ] as const;
451
452
 
@@ -16,6 +16,8 @@ export interface BackgroundTool {
16
16
  /** Tool type identifier (e.g. "bash", "host_bash"). */
17
17
  toolName: string;
18
18
  conversationId: string;
19
+ /** Scheduled firing that owns this command, absent for user-owned work. */
20
+ cronRunId?: string;
19
21
  command: string;
20
22
  startedAt: number;
21
23
  /** Kills the process (bash) or aborts the proxy (host_bash). */
@@ -48,6 +50,7 @@ export const MAX_BACKGROUND_TOOLS = 20;
48
50
  export const MAX_COMPLETED_BACKGROUND_TOOLS = 50;
49
51
 
50
52
  const registry = new Map<string, BackgroundTool>();
53
+ const pendingCancellations = new Map<string, BackgroundTool>();
51
54
 
52
55
  // FIFO ring of recently-completed tools, oldest first. Bounded by
53
56
  // MAX_COMPLETED_BACKGROUND_TOOLS so a long-lived daemon can't accumulate
@@ -70,6 +73,24 @@ export function registerBackgroundTool(tool: BackgroundTool): void {
70
73
  /** Removes a background tool entry by ID. */
71
74
  export function removeBackgroundTool(id: string): void {
72
75
  registry.delete(id);
76
+ pendingCancellations.delete(id);
77
+ }
78
+
79
+ /** Includes cancelled processes until their terminal callback has run. */
80
+ export function hasBackgroundToolWork(
81
+ conversationId: string,
82
+ options?: { startedAfter?: number; cronRunId?: string },
83
+ ): boolean {
84
+ return [registry, pendingCancellations].some((tools) =>
85
+ Array.from(tools.values()).some(
86
+ (tool) =>
87
+ tool.conversationId === conversationId &&
88
+ (options?.cronRunId === undefined ||
89
+ tool.cronRunId === options.cronRunId) &&
90
+ (options?.startedAfter === undefined ||
91
+ tool.startedAt >= options.startedAfter),
92
+ ),
93
+ );
73
94
  }
74
95
 
75
96
  /**
@@ -128,7 +149,13 @@ export function cancelBackgroundTool(id: string, reason?: string): boolean {
128
149
  if (!tool) {
129
150
  return false;
130
151
  }
131
- tool.cancel(reason);
152
+ pendingCancellations.set(id, tool);
153
+ try {
154
+ tool.cancel(reason);
155
+ } catch (error) {
156
+ pendingCancellations.delete(id);
157
+ throw error;
158
+ }
132
159
  registry.delete(id);
133
160
  return true;
134
161
  }
@@ -142,8 +169,7 @@ export function cancelBackgroundTools(
142
169
  if (!shouldCancel(tool)) {
143
170
  continue;
144
171
  }
145
- tool.cancel(reason);
146
- registry.delete(tool.id);
172
+ cancelBackgroundTool(tool.id, reason);
147
173
  cancelled.push(tool);
148
174
  }
149
175
  return cancelled;
@@ -173,5 +199,6 @@ export function isBackgroundToolLimitReached(): boolean {
173
199
  */
174
200
  export function _clearRegistryForTesting(): void {
175
201
  registry.clear();
202
+ pendingCancellations.clear();
176
203
  completedRing.length = 0;
177
204
  }
@@ -136,8 +136,7 @@ export class LocalCdpClient implements ScopedCdpClient {
136
136
  });
137
137
  }
138
138
  try {
139
- const result = (await session.send(method, params)) as T;
140
- return result;
139
+ return (await session.send(method, params)) as T;
141
140
  } catch (err) {
142
141
  if (signal?.aborted) {
143
142
  throw new CdpError("aborted", "Aborted during send", {
@@ -165,6 +165,7 @@ export const hostShellTool = {
165
165
  input: Record<string, unknown>,
166
166
  context: ToolContext,
167
167
  ): Promise<ToolExecutionResult> {
168
+ const cronRunId = context.cronRunId ?? undefined;
168
169
  const parsed = hostShellInputSchema.safeParse(input);
169
170
  if (!parsed.success) {
170
171
  return invalidToolInputResult("host_bash", parsed.error);
@@ -317,6 +318,7 @@ export const hostShellTool = {
317
318
  : `Background host command completed (id=${bgId}):`;
318
319
  void wakeAgentForOpportunity({
319
320
  conversationId: context.conversationId,
321
+ cronRunId,
320
322
  hint: framing,
321
323
  source: "background-tool",
322
324
  persistTriggerAsEvent: true,
@@ -365,6 +367,7 @@ export const hostShellTool = {
365
367
  );
366
368
  void wakeAgentForOpportunity({
367
369
  conversationId: context.conversationId,
370
+ cronRunId,
368
371
  hint:
369
372
  status === "cancelled"
370
373
  ? `Background host command cancelled (id=${bgId}):`
@@ -378,6 +381,7 @@ export const hostShellTool = {
378
381
 
379
382
  registerBackgroundTool({
380
383
  id: bgId,
384
+ cronRunId,
381
385
  toolName: "host_bash",
382
386
  conversationId: context.conversationId,
383
387
  command,
@@ -536,6 +540,7 @@ export const hostShellTool = {
536
540
  : `Background host command completed (id=${bgId}):`;
537
541
  void wakeAgentForOpportunity({
538
542
  conversationId: context.conversationId,
543
+ cronRunId,
539
544
  hint: framing,
540
545
  source: "background-tool",
541
546
  persistTriggerAsEvent: true,
@@ -587,6 +592,7 @@ export const hostShellTool = {
587
592
  );
588
593
  void wakeAgentForOpportunity({
589
594
  conversationId: context.conversationId,
595
+ cronRunId,
590
596
  hint:
591
597
  status === "cancelled"
592
598
  ? `Background host command cancelled (id=${bgId}):`
@@ -600,6 +606,7 @@ export const hostShellTool = {
600
606
 
601
607
  registerBackgroundTool({
602
608
  id: bgId,
609
+ cronRunId,
603
610
  toolName: "host_bash",
604
611
  conversationId: context.conversationId,
605
612
  command,
@@ -1,4 +1,12 @@
1
- import { afterEach, beforeEach, describe, expect, mock, test } from "bun:test";
1
+ import {
2
+ afterEach,
3
+ beforeEach,
4
+ describe,
5
+ expect,
6
+ mock,
7
+ spyOn,
8
+ test,
9
+ } from "bun:test";
2
10
 
3
11
  import { setConfig } from "../../../__tests__/helpers/set-config.js";
4
12
 
@@ -133,6 +141,25 @@ describe("executeFirecrawlScrape", () => {
133
141
  expect(result.status).toContain("truncated");
134
142
  });
135
143
 
144
+ test("carries the provider's warning and a start past the end in metadata", async () => {
145
+ spyOn(globalThis, "fetch").mockResolvedValue(
146
+ scrapeResponse({
147
+ success: true,
148
+ warning: "The page was served from cache.",
149
+ data: { markdown: "abcdefghij", metadata: { statusCode: 200 } },
150
+ }),
151
+ );
152
+
153
+ const result = await executeFirecrawlScrape(
154
+ { url: "https://example.com", start_index: 50 },
155
+ { apiKey: "fc-key" },
156
+ );
157
+ expect(result.isError).toBe(false);
158
+ const meta = result.activityMetadata?.webFetch;
159
+ expect(meta?.providerWarning).toBe("The page was served from cache.");
160
+ expect(meta?.startIndexPastEnd).toBe(true);
161
+ });
162
+
136
163
  test("empty markdown yields a no-content marker, not an error", async () => {
137
164
  globalThis.fetch = (async () =>
138
165
  scrapeResponse({ success: true, data: { markdown: "" } })) as any;
@@ -130,6 +130,40 @@ describe("web_fetch activityMetadata", () => {
130
130
  expect(meta?.charCount).toBe(maxChars);
131
131
  });
132
132
 
133
+ test("flags a start_index past the end of a page it downloaded whole", async () => {
134
+ const result = await executeWithMockFetch(
135
+ { url: "https://example.com/short", start_index: 500 },
136
+ {
137
+ requestExecutor: async () =>
138
+ new Response("x".repeat(100), {
139
+ status: 200,
140
+ headers: { "content-type": "text/plain; charset=utf-8" },
141
+ }),
142
+ },
143
+ );
144
+ expect(result.isError).toBe(false);
145
+ expect(result.activityMetadata?.webFetch?.startIndexPastEnd).toBe(true);
146
+ });
147
+
148
+ test("does not call a start_index past a capped download the end of the page", async () => {
149
+ // Over the 2 MB download cap: only a prefix is read, so an offset past it
150
+ // may still be inside the page.
151
+ const result = await executeWithMockFetch(
152
+ { url: "https://example.com/huge", start_index: 2_500_000 },
153
+ {
154
+ requestExecutor: async () =>
155
+ new Response("x".repeat(3_000_000), {
156
+ status: 200,
157
+ headers: { "content-type": "text/plain; charset=utf-8" },
158
+ }),
159
+ },
160
+ );
161
+ expect(result.isError).toBe(false);
162
+ const meta = result.activityMetadata?.webFetch;
163
+ expect(meta?.truncated).toBe(true);
164
+ expect(meta?.startIndexPastEnd).toBe(false);
165
+ });
166
+
133
167
  test("populates errorMessage and status on a 404 response", async () => {
134
168
  globalThis.fetch = (async () =>
135
169
  new Response("<title>Not Found</title>not here", {
@@ -1,4 +1,12 @@
1
- import { afterEach, beforeEach, describe, expect, mock, test } from "bun:test";
1
+ import {
2
+ afterEach,
3
+ beforeEach,
4
+ describe,
5
+ expect,
6
+ mock,
7
+ spyOn,
8
+ test,
9
+ } from "bun:test";
2
10
 
3
11
  import { setConfig } from "../../../__tests__/helpers/set-config.js";
4
12
 
@@ -101,6 +109,32 @@ describe("executeTinyfishFetch", () => {
101
109
  );
102
110
  });
103
111
 
112
+ test("an empty upstream title is no title", async () => {
113
+ spyOn(globalThis, "fetch").mockResolvedValue(
114
+ fetchResponse({
115
+ results: [
116
+ {
117
+ url: "https://example.com/",
118
+ final_url: "https://example.com/",
119
+ title: " ",
120
+ text: "# Example",
121
+ format: "markdown",
122
+ },
123
+ ],
124
+ errors: [],
125
+ }),
126
+ );
127
+
128
+ const result = await executeTinyfishFetch(
129
+ { url: "https://example.com" },
130
+ { apiKey: "tf_test" },
131
+ );
132
+
133
+ expect(result.isError).toBe(false);
134
+ expect(result.activityMetadata?.webFetch?.title).toBeUndefined();
135
+ expect(result.content).not.toContain("Title:");
136
+ });
137
+
104
138
  test("uses a custom API base and applies character windows", async () => {
105
139
  seedWebFetch("tinyfish", "https://fetch.example.com/api/");
106
140
  let capturedUrl = "";