@vellumai/assistant 0.12.5 → 0.12.6-dev.202609292019.a6f6d85

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 (264) hide show
  1. package/.env.example +2 -0
  2. package/ARCHITECTURE.md +23 -0
  3. package/docs/automatic-done.md +32 -0
  4. package/docs/desktop-browser-cli.md +3 -2
  5. package/node_modules/@vellumai/ces-client/node_modules/@vellumai/service-contracts/package.json +2 -1
  6. package/node_modules/@vellumai/ces-client/node_modules/@vellumai/service-contracts/src/__tests__/mcp-oauth.test.ts +53 -0
  7. package/node_modules/@vellumai/ces-client/node_modules/@vellumai/service-contracts/src/index.ts +1 -0
  8. package/node_modules/@vellumai/ces-client/node_modules/@vellumai/service-contracts/src/mcp-oauth.ts +60 -0
  9. package/node_modules/@vellumai/environments/src/shell.test.ts +13 -1
  10. package/node_modules/@vellumai/environments/src/shell.ts +22 -1
  11. package/node_modules/@vellumai/gateway-client/node_modules/@vellumai/service-contracts/package.json +2 -1
  12. package/node_modules/@vellumai/gateway-client/node_modules/@vellumai/service-contracts/src/__tests__/mcp-oauth.test.ts +53 -0
  13. package/node_modules/@vellumai/gateway-client/node_modules/@vellumai/service-contracts/src/index.ts +1 -0
  14. package/node_modules/@vellumai/gateway-client/node_modules/@vellumai/service-contracts/src/mcp-oauth.ts +60 -0
  15. package/node_modules/@vellumai/gateway-client/src/__tests__/status-contracts.test.ts +39 -0
  16. package/node_modules/@vellumai/gateway-client/src/gateway-ipc-contracts.ts +25 -0
  17. package/node_modules/@vellumai/service-contracts/package.json +2 -1
  18. package/node_modules/@vellumai/service-contracts/src/__tests__/mcp-oauth.test.ts +53 -0
  19. package/node_modules/@vellumai/service-contracts/src/index.ts +1 -0
  20. package/node_modules/@vellumai/service-contracts/src/mcp-oauth.ts +60 -0
  21. package/openapi.yaml +270 -10
  22. package/package.json +1 -1
  23. package/src/__tests__/agent-loop.test.ts +76 -0
  24. package/src/__tests__/anthropic-provider.test.ts +2 -0
  25. package/src/__tests__/byok-default-profile-ensure.test.ts +7 -0
  26. package/src/__tests__/config-get-vision-flag.test.ts +1 -1
  27. package/src/__tests__/config-loader-validation-reset-notice.test.ts +2 -2
  28. package/src/__tests__/conversation-agent-loop-overflow.test.ts +160 -154
  29. package/src/__tests__/conversation-evictor.test.ts +54 -0
  30. package/src/__tests__/conversation-pairing.test.ts +112 -0
  31. package/src/__tests__/document-append-idempotency.test.ts +13 -0
  32. package/src/__tests__/document-create-dedupe.test.ts +13 -0
  33. package/src/__tests__/document-find-replace.test.ts +13 -0
  34. package/src/__tests__/document-revision-history.test.ts +390 -0
  35. package/src/__tests__/document-revision.test.ts +425 -0
  36. package/src/__tests__/document-tool-security.test.ts +13 -0
  37. package/src/__tests__/document-update-default-surface.test.ts +13 -0
  38. package/src/__tests__/emit-signal-routing-intent.test.ts +270 -0
  39. package/src/__tests__/gateway-flag-listener.test.ts +59 -6
  40. package/src/__tests__/headless-browser-navigate.test.ts +20 -30
  41. package/src/__tests__/host-cu-proxy.test.ts +79 -0
  42. package/src/__tests__/host-cu-routes-targeted.test.ts +14 -5
  43. package/src/__tests__/host-shell-tool.test.ts +6 -2
  44. package/src/__tests__/identity-routes.test.ts +4 -3
  45. package/src/__tests__/llm-catalog-parity.test.ts +4 -4
  46. package/src/__tests__/llm-schema.test.ts +1 -1
  47. package/src/__tests__/notification-platform-adapter.test.ts +83 -1
  48. package/src/__tests__/oauth2-gateway-transport.test.ts +2 -0
  49. package/src/__tests__/openai-provider.test.ts +11 -11
  50. package/src/__tests__/pricing.test.ts +11 -0
  51. package/src/__tests__/public-ingress-urls.test.ts +26 -0
  52. package/src/__tests__/retry-thinking-tool-choice.test.ts +47 -0
  53. package/src/__tests__/usage-attribution.test.ts +31 -0
  54. package/src/__tests__/workspace-migration-133-collapse-provider-connections.test.ts +3 -3
  55. package/src/__tests__/workspace-migration-160-repair-retired-fireworks-model-ids.test.ts +262 -0
  56. package/src/__tests__/workspace-migration-161-repair-retired-fireworks-glm-5p2-model-id.test.ts +233 -0
  57. package/src/acp/agent-process.ts +6 -1
  58. package/src/acp/client-handler.ts +6 -1
  59. package/src/agent/loop.ts +29 -6
  60. package/src/api/events/document-editor-show.ts +5 -0
  61. package/src/api/events/document-editor-update.ts +10 -0
  62. package/src/api/events/tool-result.ts +1 -0
  63. package/src/calls/__tests__/voice-session-bridge.test.ts +54 -0
  64. package/src/calls/channel-admission-reader.ts +15 -9
  65. package/src/calls/twilio-provider.ts +14 -31
  66. package/src/calls/voice-session-bridge.ts +18 -1
  67. package/src/cli/commands/browser.ts +1 -2
  68. package/src/cli/lib/__tests__/plugin-artifact.test.ts +23 -0
  69. package/src/cli/lib/__tests__/plugin-catalog-visibility.test.ts +2 -0
  70. package/src/cli/lib/__tests__/plugin-details.test.ts +16 -0
  71. package/src/cli/lib/bundled-marketplace.json +41 -2
  72. package/src/cli/lib/inspect-plugin.ts +15 -15
  73. package/src/cli/lib/list-installed-plugins.ts +29 -28
  74. package/src/cli/lib/plugin-artifact.ts +74 -63
  75. package/src/cli/lib/plugin-catalog-visibility.ts +1 -0
  76. package/src/cli/lib/plugin-details.ts +27 -42
  77. package/src/cli/lib/plugin-marketplace.ts +6 -8
  78. package/src/cli/lib/plugin-surfaces.ts +8 -7
  79. package/src/cli.ts +1 -3
  80. package/src/config/__tests__/chat-settings.test.ts +121 -0
  81. package/src/config/assistant-feature-flags.ts +28 -23
  82. package/src/config/bundled-skills/computer-use/SKILL.md +20 -0
  83. package/src/config/bundled-skills/computer-use/TOOLS.json +11 -11
  84. package/src/config/chat-settings.ts +100 -0
  85. package/src/config/default-profile-catalog.ts +1 -1
  86. package/src/config/feature-flag-cache.ts +7 -25
  87. package/src/config/feature-flag-registry.json +1 -9
  88. package/src/config/loader.ts +5 -1
  89. package/src/config/profile-text-generation.ts +25 -21
  90. package/src/config/schemas/conversations.ts +14 -0
  91. package/src/config/schemas/llm.ts +1 -0
  92. package/src/config/schemas/notifications.ts +8 -1
  93. package/src/contacts/gateway-channel-read.ts +1 -1
  94. package/src/conversations/__tests__/auto-archive-activity.test.ts +136 -0
  95. package/src/conversations/__tests__/auto-archive.test.ts +304 -0
  96. package/src/conversations/auto-archive-activity.ts +61 -0
  97. package/src/conversations/auto-archive.ts +201 -0
  98. package/src/daemon/computer-use-observation.test.ts +81 -0
  99. package/src/daemon/computer-use-observation.ts +23 -0
  100. package/src/daemon/conversation-agent-loop.ts +11 -6
  101. package/src/daemon/conversation-evictor.ts +50 -16
  102. package/src/daemon/doordash-steps.ts +1 -3
  103. package/src/daemon/handlers/__tests__/config-a2a-accept.test.ts +43 -1
  104. package/src/daemon/handlers/__tests__/config-channels.test.ts +1 -1
  105. package/src/daemon/handlers/config-a2a.ts +75 -2
  106. package/src/daemon/host-cu-proxy.ts +34 -3
  107. package/src/daemon/lifecycle.ts +15 -2
  108. package/src/daemon/shutdown-handlers.ts +3 -0
  109. package/src/daemon/turn-finalization.ts +4 -0
  110. package/src/desktop/desktop-browser-endpoint.ts +11 -2
  111. package/src/desktop/desktop-chrome-policy.test.ts +1 -0
  112. package/src/desktop/desktop-chrome-policy.ts +7 -1
  113. package/src/desktop/desktop-computer-use.test.ts +14 -4
  114. package/src/desktop/desktop-session-manager.ts +5 -3
  115. package/src/documents/document-revisions-store.ts +153 -0
  116. package/src/documents/document-store.ts +471 -133
  117. package/src/followups/followup-store.ts +0 -4
  118. package/src/inbound/__tests__/oauth-callback-url.test.ts +25 -2
  119. package/src/inbound/oauth-callback-url.ts +30 -1
  120. package/src/inbound/public-ingress-urls.ts +12 -2
  121. package/src/ipc/gateway-client.test.ts +40 -0
  122. package/src/ipc/gateway-client.ts +12 -29
  123. package/src/ipc/gateway-flag-listener.ts +7 -10
  124. package/src/live-voice/__tests__/live-voice-agent-turn.test.ts +71 -0
  125. package/src/live-voice/__tests__/live-voice-flux-turn-end.test.ts +83 -0
  126. package/src/live-voice/__tests__/protocol.test.ts +77 -0
  127. package/src/live-voice/__tests__/share-targets.test.ts +163 -0
  128. package/src/live-voice/live-voice-session.ts +23 -6
  129. package/src/live-voice/protocol.ts +22 -0
  130. package/src/live-voice/share-targets.ts +225 -0
  131. package/src/mcp/__tests__/mcp-oauth-client-registration.test.ts +144 -3
  132. package/src/mcp/__tests__/mcp-oauth-provider.test.ts +2 -0
  133. package/src/mcp/client.ts +1 -19
  134. package/src/mcp/mcp-oauth-provider.ts +66 -49
  135. package/src/media/openrouter-image-service.ts +39 -22
  136. package/src/monitoring/__tests__/oom-inheritance-sweep.test.ts +86 -0
  137. package/src/monitoring/__tests__/oom-kill-reporter.test.ts +374 -0
  138. package/src/monitoring/control.ts +2 -1
  139. package/src/monitoring/oom-inheritance-sweep.ts +96 -0
  140. package/src/monitoring/oom-kill-reporter.ts +469 -0
  141. package/src/monitoring/resource-sampler.ts +30 -0
  142. package/src/notifications/README.md +53 -4
  143. package/src/notifications/__tests__/assistant-initiated-thread.test.ts +254 -0
  144. package/src/notifications/__tests__/broadcaster.test.ts +558 -6
  145. package/src/notifications/__tests__/completion-policy.test.ts +37 -0
  146. package/src/notifications/__tests__/from-me-alert-integration.test.ts +192 -0
  147. package/src/notifications/adapters/platform.ts +14 -0
  148. package/src/notifications/assistant-initiated-thread.ts +101 -0
  149. package/src/notifications/broadcaster.ts +94 -16
  150. package/src/notifications/chat-reply-policy.ts +11 -0
  151. package/src/notifications/completion-policy.ts +12 -2
  152. package/src/notifications/conversation-pairing.ts +15 -70
  153. package/src/notifications/emit-signal.ts +34 -3
  154. package/src/notifications/types.ts +2 -0
  155. package/src/oauth/connect-orchestrator.ts +1 -2
  156. package/src/persistence/__tests__/conversation-auto-archive.test.ts +330 -0
  157. package/src/persistence/conversation-auto-archive.ts +170 -0
  158. package/src/persistence/conversation-crud.ts +2 -1
  159. package/src/persistence/conversation-queries.ts +15 -8
  160. package/src/persistence/embeddings/embed.test.ts +96 -0
  161. package/src/persistence/embeddings/embed.ts +20 -2
  162. package/src/persistence/embeddings/embedding-gemini.test.ts +39 -3
  163. package/src/persistence/embeddings/embedding-gemini.ts +39 -1
  164. package/src/persistence/embeddings/embedding-local.ts +6 -0
  165. package/src/persistence/embeddings/qdrant-manager.ts +5 -0
  166. package/src/persistence/job-utils.ts +10 -0
  167. package/src/persistence/migrations/384-add-document-revision.test.ts +83 -0
  168. package/src/persistence/migrations/384-add-document-revision.ts +21 -0
  169. package/src/persistence/migrations/385-create-document-revisions.test.ts +67 -0
  170. package/src/persistence/migrations/385-create-document-revisions.ts +28 -0
  171. package/src/persistence/migrations/386-conversations-last-reopened-at.ts +10 -0
  172. package/src/persistence/migrations/__tests__/386-conversations-last-reopened-at.test.ts +32 -0
  173. package/src/persistence/schema/conversations.ts +1 -0
  174. package/src/persistence/schema/documents.ts +20 -0
  175. package/src/persistence/steps.ts +6 -0
  176. package/src/platform/managed-speech.ts +42 -46
  177. package/src/plugin-api/vision-support.test.ts +21 -21
  178. package/src/plugins/defaults/empty-response/hooks/post-model-call.ts +11 -6
  179. package/src/providers/__tests__/dispatch-connection-routing.test.ts +1 -1
  180. package/src/providers/__tests__/search-provider-catalog.test.ts +8 -0
  181. package/src/providers/anthropic/client.ts +1 -1
  182. package/src/providers/fireworks/client.test.ts +168 -0
  183. package/src/providers/fireworks/client.ts +24 -0
  184. package/src/providers/inference/adapter-factory.ts +6 -0
  185. package/src/providers/ionet/client.test.ts +143 -0
  186. package/src/providers/ionet/client.ts +37 -0
  187. package/src/providers/model-catalog.ts +141 -84
  188. package/src/providers/model-intents.ts +4 -4
  189. package/src/providers/openai/chat-completions-provider.ts +23 -1
  190. package/src/providers/retry.ts +56 -4
  191. package/src/providers/search-provider-catalog.ts +10 -0
  192. package/src/providers/types.ts +10 -2
  193. package/src/providers/usage-tracking.ts +5 -3
  194. package/src/runtime/assistant-event-hub.ts +23 -0
  195. package/src/runtime/auth/__tests__/guard-tests.test.ts +0 -7
  196. package/src/runtime/auth/__tests__/route-policy.test.ts +1 -1
  197. package/src/runtime/channel-retry-sweep.ts +1 -2
  198. package/src/runtime/migrations/__tests__/vbundle-streaming-validator.test.ts +35 -10
  199. package/src/runtime/migrations/__tests__/vbundle-validator-v1-schema.test.ts +48 -0
  200. package/src/runtime/migrations/vbundle-builder.ts +19 -3
  201. package/src/runtime/migrations/vbundle-streaming-importer.ts +14 -19
  202. package/src/runtime/migrations/vbundle-streaming-validator.ts +14 -7
  203. package/src/runtime/migrations/vbundle-validator.ts +54 -1
  204. package/src/runtime/pending-interactions.ts +20 -2
  205. package/src/runtime/routes/__tests__/contact-routes.test.ts +5 -3
  206. package/src/runtime/routes/__tests__/conversation-list-routes.test.ts +36 -0
  207. package/src/runtime/routes/__tests__/conversation-query-routes.test.ts +375 -2
  208. package/src/runtime/routes/__tests__/inference-send-routes.test.ts +1 -1
  209. package/src/runtime/routes/__tests__/user-route-dispatcher.test.ts +12 -0
  210. package/src/runtime/routes/contact-routes.ts +2 -2
  211. package/src/runtime/routes/conversation-list-routes.ts +10 -2
  212. package/src/runtime/routes/conversation-query-routes.ts +48 -10
  213. package/src/runtime/routes/documents-routes.ts +185 -47
  214. package/src/runtime/routes/events-routes.ts +1 -3
  215. package/src/runtime/routes/host-app-control-routes.ts +1 -0
  216. package/src/runtime/routes/host-bash-routes.ts +1 -0
  217. package/src/runtime/routes/host-browser-routes.ts +15 -0
  218. package/src/runtime/routes/host-cu-routes.ts +4 -1
  219. package/src/runtime/routes/host-file-routes.ts +1 -0
  220. package/src/runtime/routes/host-proxy-result-binding.test.ts +83 -0
  221. package/src/runtime/routes/host-proxy-result-binding.ts +25 -0
  222. package/src/runtime/routes/host-transfer-routes.ts +1 -0
  223. package/src/runtime/routes/identity-routes.ts +3 -3
  224. package/src/runtime/routes/integrations/a2a.ts +4 -1
  225. package/src/runtime/routes/migration-routes.ts +3 -1
  226. package/src/runtime/routes/notification-routes.ts +1 -2
  227. package/src/runtime/routes/ui-snapshot-routes.test.ts +1 -0
  228. package/src/runtime/routes/user-route-dispatcher.ts +5 -1
  229. package/src/runtime/verification-templates.ts +1 -2
  230. package/src/sequence/analytics.ts +0 -4
  231. package/src/sequence/engine.ts +1 -11
  232. package/src/sequence/guardrails.ts +1 -6
  233. package/src/sequence/importer.ts +0 -8
  234. package/src/sequence/store.ts +0 -10
  235. package/src/signals/user-message.ts +0 -6
  236. package/src/skills/catalog-install.ts +52 -23
  237. package/src/tools/browser/browser-execution.ts +20 -23
  238. package/src/tools/browser/cdp-client/cdp-inspect/ws-transport.ts +1 -3
  239. package/src/tools/document/document-tool.ts +13 -11
  240. package/src/tools/executor.ts +1 -2
  241. package/src/tools/host-terminal/host-shell.ts +4 -2
  242. package/src/tools/network/__tests__/web-search.test.ts +105 -0
  243. package/src/tools/network/web-fetch.ts +2 -4
  244. package/src/tools/network/web-search.ts +239 -12
  245. package/src/tools/shared/filesystem/format-diff.ts +1 -2
  246. package/src/tools/shared/shell-output.test.ts +42 -0
  247. package/src/tools/shared/shell-output.ts +27 -4
  248. package/src/tools/terminal/shell.ts +3 -3
  249. package/src/tools/ui-surface/visual-validation.ts +1 -2
  250. package/src/usage/attribution.ts +18 -1
  251. package/src/util/__tests__/oom-priority.test.ts +55 -0
  252. package/src/util/__tests__/worker-memory.test.ts +16 -0
  253. package/src/util/debounce.ts +0 -4
  254. package/src/util/oom-priority.ts +79 -0
  255. package/src/util/platform.ts +0 -2
  256. package/src/util/plugin-manifest.ts +5 -7
  257. package/src/util/pricing.ts +25 -0
  258. package/src/util/worker-memory.ts +9 -3
  259. package/src/util/worker-process.ts +8 -0
  260. package/src/workspace/byok-default-profile-ensure.ts +11 -0
  261. package/src/workspace/hatched-date.ts +11 -4
  262. package/src/workspace/migrations/160-repair-retired-fireworks-model-ids.ts +209 -0
  263. package/src/workspace/migrations/161-repair-retired-fireworks-glm-5p2-model-id.ts +197 -0
  264. package/src/workspace/migrations/registry.ts +4 -0
@@ -1723,6 +1723,7 @@ export async function runAgentLoopImpl(
1723
1723
  supportsDynamicUi: conversationSupportsDynamicUi(ctx),
1724
1724
  trust: loopTrust,
1725
1725
  overrideProfile: turnOverrideProfile,
1726
+ ...(autoRoute ? { overrideProfileOrigin: "auto" as const } : {}),
1726
1727
  ...(forceOverrideProfile ? { forceOverrideProfile: true } : {}),
1727
1728
  resolveOverrideProfile: refreshCurrentProfileState,
1728
1729
  ...(onModelCallPrepared !== undefined ? { onModelCallPrepared } : {}),
@@ -2147,6 +2148,9 @@ export async function runAgentLoopImpl(
2147
2148
  // path to the terminal SSE that re-enables the composer.
2148
2149
  ctx.messages = restoredHistory;
2149
2150
 
2151
+ // The row's override is whichever profile served the last call.
2152
+ const mainRowOverrideProfile =
2153
+ state.exchangeInferenceProfile ?? refreshCurrentProfileState() ?? null;
2150
2154
  emitUsage(
2151
2155
  ctx,
2152
2156
  state.exchangeInputTokens,
@@ -2171,16 +2175,17 @@ export async function runAgentLoopImpl(
2171
2175
  // backup (via `state.exchangeProviderName` / `state.model`), so
2172
2176
  // attributing the profile from the primary would write a row that
2173
2177
  // contradicts itself. `forceOverrideProfile` floats it above the
2174
- // call-site profile exactly as the fallback dispatch did.
2178
+ // call-site profile exactly as the fallback dispatch did. The Auto
2179
+ // origin applies only while the row's override is still the router's
2180
+ // pick: a profile switched in mid-turn is the user's.
2175
2181
  {
2176
2182
  callSite: inferenceCallSite,
2177
- overrideProfile:
2178
- state.exchangeInferenceProfile ??
2179
- refreshCurrentProfileState() ??
2180
- null,
2183
+ overrideProfile: mainRowOverrideProfile,
2181
2184
  ...(state.exchangeInferenceProfile !== undefined
2182
2185
  ? { forceOverrideProfile: true }
2183
- : {}),
2186
+ : autoRoute && mainRowOverrideProfile === autoRoute.profile
2187
+ ? { overrideProfileOrigin: "auto" as const }
2188
+ : {}),
2184
2189
  },
2185
2190
  turnCronRunId,
2186
2191
  );
@@ -1,4 +1,5 @@
1
1
  import { getSubagentManager } from "../subagent/index.js";
2
+ import { getContainerMemoryLimitBytes } from "../util/cgroup-memory.js";
2
3
  import { getLogger } from "../util/logger.js";
3
4
  import { getConversationMap } from "./conversation-registry.js";
4
5
 
@@ -15,7 +16,7 @@ export interface EvictorOptions {
15
16
  ttlMs?: number;
16
17
  /** Max number of in-memory conversations before LRU eviction kicks in. Default: 100. */
17
18
  maxConversations?: number;
18
- /** RSS threshold (bytes) above which idle conversations are aggressively evicted. Default: 3 GB. */
19
+ /** RSS threshold (bytes) above which idle conversations are aggressively evicted. Default: {@link defaultMemoryThresholdBytes}. */
19
20
  memoryThresholdBytes?: number;
20
21
  /** Interval between periodic sweeps (ms). Default: 60 s. */
21
22
  sweepIntervalMs?: number;
@@ -34,13 +35,34 @@ export interface EvictionResult {
34
35
 
35
36
  const DEFAULT_TTL_MS = 30 * 60 * 1000; // 30 minutes
36
37
  const DEFAULT_MAX_CONVERSATIONS = 100;
37
- const DEFAULT_MEMORY_THRESHOLD_BYTES = 3072 * 1024 * 1024; // 3 GB
38
+ /** Threshold when no container limit is known (local hosts). */
39
+ const FALLBACK_MEMORY_THRESHOLD_BYTES = 3072 * 1024 * 1024; // 3 GiB
40
+ /**
41
+ * Share of the container memory limit the daemon's own RSS may reach before
42
+ * idle conversations are evicted. The rest of the limit is Qdrant, the
43
+ * workers, and tool children, so the daemon cannot have it all.
44
+ */
45
+ const MEMORY_THRESHOLD_LIMIT_FRACTION = 0.5;
38
46
  const DEFAULT_SWEEP_INTERVAL_MS = 60 * 1000; // 60 seconds
47
+ /**
48
+ * Idle conversations evicted per sweep under memory pressure. RSS cannot fall
49
+ * until the disposed heap is collected after the sweep returns, so the sweep
50
+ * evicts a bounded batch and the next sweep re-measures.
51
+ */
52
+ const MEMORY_EVICTION_BATCH = 10;
53
+
54
+ /** Default memory-pressure threshold: half the container limit, or 3 GiB when there is none. */
55
+ export function defaultMemoryThresholdBytes(limitBytes: number | null): number {
56
+ return limitBytes != null
57
+ ? Math.floor(limitBytes * MEMORY_THRESHOLD_LIMIT_FRACTION)
58
+ : FALLBACK_MEMORY_THRESHOLD_BYTES;
59
+ }
39
60
 
40
61
  export class ConversationEvictor {
41
62
  private readonly ttlMs: number;
42
63
  private readonly maxConversations: number;
43
- private readonly memoryThresholdBytes: number;
64
+ /** Explicit threshold, or null to derive it from the container limit on first use. */
65
+ private memoryThresholdBytes: number | null;
44
66
  private readonly sweepIntervalMs: number;
45
67
 
46
68
  /** Tracks last access time per conversation ID. */
@@ -57,8 +79,7 @@ export class ConversationEvictor {
57
79
  this.ttlMs = options?.ttlMs ?? DEFAULT_TTL_MS;
58
80
  this.maxConversations =
59
81
  options?.maxConversations ?? DEFAULT_MAX_CONVERSATIONS;
60
- this.memoryThresholdBytes =
61
- options?.memoryThresholdBytes ?? DEFAULT_MEMORY_THRESHOLD_BYTES;
82
+ this.memoryThresholdBytes = options?.memoryThresholdBytes ?? null;
62
83
  this.sweepIntervalMs =
63
84
  options?.sweepIntervalMs ?? DEFAULT_SWEEP_INTERVAL_MS;
64
85
  }
@@ -155,25 +176,26 @@ export class ConversationEvictor {
155
176
  }
156
177
  }
157
178
 
158
- // Phase 3: Memory pressure — if RSS exceeds threshold, evict idle conversations
159
- // starting from least-recently-used until we're under the threshold or
160
- // no more idle conversations remain.
179
+ // Phase 3: Memory pressure — if RSS exceeds threshold, evict a batch of
180
+ // idle conversations starting from least-recently-used.
161
181
  const rss = process.memoryUsage.rss();
162
- if (rss > this.memoryThresholdBytes) {
163
- const sorted = this.idleConversationsByLru();
164
- if (sorted.length > 0) {
182
+ const thresholdBytes = this.resolveMemoryThresholdBytes();
183
+ if (rss > thresholdBytes) {
184
+ const batch = this.idleConversationsByLru().slice(
185
+ 0,
186
+ MEMORY_EVICTION_BATCH,
187
+ );
188
+ if (batch.length > 0) {
165
189
  log.warn(
166
190
  {
167
191
  rssBytes: rss,
168
- thresholdBytes: this.memoryThresholdBytes,
192
+ thresholdBytes,
169
193
  conversationCount: this.conversations.size,
194
+ evicting: batch.length,
170
195
  },
171
196
  "Memory pressure detected, evicting idle conversations",
172
197
  );
173
- for (const [id, conversation] of sorted) {
174
- if (process.memoryUsage.rss() <= this.memoryThresholdBytes) {
175
- break;
176
- }
198
+ for (const [id, conversation] of batch) {
177
199
  this.evict(id, conversation);
178
200
  result.memoryEvicted++;
179
201
  }
@@ -198,6 +220,18 @@ export class ConversationEvictor {
198
220
 
199
221
  // ── Internals ──────────────────────────────────────────────────────
200
222
 
223
+ /**
224
+ * Resolved on first sweep rather than at construction: the module-level
225
+ * singleton is built at import, before the daemon has loaded its dotenv
226
+ * file, and VELLUM_MEMORY_LIMIT may come from there.
227
+ */
228
+ private resolveMemoryThresholdBytes(): number {
229
+ this.memoryThresholdBytes ??= defaultMemoryThresholdBytes(
230
+ getContainerMemoryLimitBytes(),
231
+ );
232
+ return this.memoryThresholdBytes;
233
+ }
234
+
201
235
  private evict(id: string, conversation: EvictableConversation): void {
202
236
  conversation.dispose();
203
237
  this.conversations.delete(id);
@@ -78,7 +78,7 @@ function updateDoordashSteps(
78
78
  return undefined;
79
79
  }
80
80
 
81
- const updated = steps.map((s, i) => {
81
+ return steps.map((s, i) => {
82
82
  if (i < stepIndex) {
83
83
  // Steps before current should be completed
84
84
  return s.status === "completed" ? s : { ...s, status: "completed" };
@@ -96,8 +96,6 @@ function updateDoordashSteps(
96
96
  }
97
97
  return s;
98
98
  });
99
-
100
- return updated;
101
99
  }
102
100
 
103
101
  // ── Helpers for reading/writing the task_progress surface ─────────────
@@ -21,7 +21,11 @@ import {
21
21
  } from "../../../contacts/contact-store.js";
22
22
  import { getSqlite } from "../../../persistence/db-connection.js";
23
23
  import { initializeDb } from "../../../persistence/db-init.js";
24
- import { acceptA2AInvite, createA2AInvite } from "../config-a2a.js";
24
+ import {
25
+ acceptA2AInvite,
26
+ assertSafeSenderGatewayUrl,
27
+ createA2AInvite,
28
+ } from "../config-a2a.js";
25
29
 
26
30
  await initializeDb();
27
31
 
@@ -487,4 +491,42 @@ describe("acceptA2AInvite", () => {
487
491
  const contacts = searchContacts({ channelType: "a2a" });
488
492
  expect(contacts).toHaveLength(0);
489
493
  });
494
+
495
+ test("rejects http, credentials, and loopback or metadata hosts", async () => {
496
+ const originalFetch = globalThis.fetch;
497
+ let fetchCalls = 0;
498
+ globalThis.fetch = (async () => {
499
+ fetchCalls += 1;
500
+ throw new Error("fetch should not run");
501
+ }) as unknown as typeof fetch;
502
+
503
+ try {
504
+ for (const url of [
505
+ "http://sender.example.com",
506
+ "https://user:pass@sender.example.com",
507
+ "https://127.0.0.1",
508
+ "https://localhost",
509
+ "https://169.254.169.254",
510
+ "https://metadata.google.internal",
511
+ ]) {
512
+ const result = await acceptA2AInvite({
513
+ senderGatewayUrl: url,
514
+ senderAssistantId: SENDER_ASSISTANT_ID,
515
+ token: "any-token",
516
+ });
517
+ expect(result.success).toBe(false);
518
+ expect(result.errorCode).toBe("invalid_sender_url");
519
+ }
520
+ expect(fetchCalls).toBe(0);
521
+ } finally {
522
+ globalThis.fetch = originalFetch;
523
+ }
524
+ });
525
+
526
+ test("allows https LAN peers used by self-hosted accept", () => {
527
+ expect(assertSafeSenderGatewayUrl("https://192.168.1.20:8787").ok).toBe(
528
+ true,
529
+ );
530
+ expect(assertSafeSenderGatewayUrl("https://peer.ts.net").ok).toBe(true);
531
+ });
490
532
  });
@@ -68,7 +68,7 @@ mock.module("../../../ipc/gateway-client.js", () => ({
68
68
  }
69
69
  if (method === "contacts_get_rich") {
70
70
  if (mockGwContactChannels == null) {
71
- return { ok: true, contact: null };
71
+ return null;
72
72
  }
73
73
  return {
74
74
  ok: true,
@@ -303,6 +303,54 @@ export function redeemA2AInvite(params: {
303
303
  // ── Self-hosted broker ──────────────────────────────────────────────
304
304
 
305
305
  const ACCEPT_TIMEOUT_MS = 15_000;
306
+ const ACCEPT_MAX_BODY_BYTES = 64_000;
307
+
308
+ const BLOCKED_SENDER_HOSTS = new Set([
309
+ "localhost",
310
+ "localhost.localdomain",
311
+ "metadata.google.internal",
312
+ ]);
313
+
314
+ /**
315
+ * Self-hosted accept brokers an outbound POST to the peer's invite/complete
316
+ * URL. Require https, reject credentials, and refuse loopback/metadata
317
+ * literals so a settings.write caller cannot steer the daemon at link-local
318
+ * or cloud-metadata endpoints. RFC1918 and Tailscale hostnames stay allowed
319
+ * because that is how self-hosted peers reach each other on a LAN.
320
+ */
321
+ export function assertSafeSenderGatewayUrl(
322
+ raw: string,
323
+ ): { ok: true; origin: string } | { ok: false; error: string } {
324
+ let parsed: URL;
325
+ try {
326
+ parsed = new URL(raw);
327
+ } catch {
328
+ return { ok: false, error: "senderGatewayUrl must be a valid URL" };
329
+ }
330
+ if (parsed.protocol !== "https:") {
331
+ return { ok: false, error: "senderGatewayUrl must use https" };
332
+ }
333
+ if (parsed.username || parsed.password) {
334
+ return {
335
+ ok: false,
336
+ error: "senderGatewayUrl must not include credentials",
337
+ };
338
+ }
339
+ const host = parsed.hostname.replace(/^\[|\]$/g, "").toLowerCase();
340
+ if (!host) {
341
+ return { ok: false, error: "senderGatewayUrl must include a host" };
342
+ }
343
+ if (BLOCKED_SENDER_HOSTS.has(host) || host.endsWith(".localhost")) {
344
+ return { ok: false, error: "senderGatewayUrl host is not allowed" };
345
+ }
346
+ if (host === "127.0.0.1" || host === "::1" || host === "0.0.0.0") {
347
+ return { ok: false, error: "senderGatewayUrl host is not allowed" };
348
+ }
349
+ if (host.startsWith("169.254.") || host === "169.254.169.254") {
350
+ return { ok: false, error: "senderGatewayUrl host is not allowed" };
351
+ }
352
+ return { ok: true, origin: parsed.origin };
353
+ }
306
354
 
307
355
  /**
308
356
  * Extract a human-readable error message from a daemon HTTP error
@@ -339,7 +387,15 @@ export async function acceptA2AInvite(params: {
339
387
  senderAssistantId: string;
340
388
  token: string;
341
389
  }): Promise<AcceptA2AInviteResult> {
342
- const senderGatewayUrl = params.senderGatewayUrl.replace(/\/+$/, "");
390
+ const safety = assertSafeSenderGatewayUrl(params.senderGatewayUrl);
391
+ if (!safety.ok) {
392
+ return {
393
+ success: false,
394
+ error: safety.error,
395
+ errorCode: "invalid_sender_url",
396
+ };
397
+ }
398
+ const senderGatewayUrl = safety.origin;
343
399
 
344
400
  // 1. Validate local config
345
401
  const displayName = getAssistantName() ?? "Vellum Assistant";
@@ -380,10 +436,27 @@ export async function acceptA2AInvite(params: {
380
436
  method: "POST",
381
437
  headers: { "Content-Type": "application/json" },
382
438
  body: JSON.stringify(completeBody),
439
+ redirect: "error",
383
440
  signal: AbortSignal.timeout(ACCEPT_TIMEOUT_MS),
384
441
  });
385
442
 
386
- completeData = (await response.json()) as Record<string, unknown>;
443
+ const rawBody = await response.text();
444
+ if (new TextEncoder().encode(rawBody).byteLength > ACCEPT_MAX_BODY_BYTES) {
445
+ return {
446
+ success: false,
447
+ error: "Sender invite/complete response exceeded size limit",
448
+ errorCode: "complete_failed",
449
+ };
450
+ }
451
+ try {
452
+ completeData = JSON.parse(rawBody) as Record<string, unknown>;
453
+ } catch {
454
+ return {
455
+ success: false,
456
+ error: "Sender invite/complete returned invalid JSON",
457
+ errorCode: "complete_failed",
458
+ };
459
+ }
387
460
 
388
461
  if (!response.ok) {
389
462
  const error =
@@ -28,6 +28,7 @@ import { POINT_AT_PROXY_TOOL } from "../tools/computer-use/skill-proxy-bridge.js
28
28
  import type { ToolExecutionResult } from "../tools/types.js";
29
29
  import { AssistantError, ErrorCode } from "../util/errors.js";
30
30
  import { getLogger } from "../util/logger.js";
31
+ import { prepareComputerUseObservation } from "./computer-use-observation.js";
31
32
  import { resolveHostCuTarget } from "./host-cu-target.js";
32
33
  import { bestEffortModeSessionTracking } from "./mode-session-tracking.js";
33
34
 
@@ -615,7 +616,7 @@ export class HostCuProxy {
615
616
  this.recordAction(toolName, input, reasoning);
616
617
  this._previousAXTree = undefined;
617
618
  this._consecutiveUnchangedSteps = 0;
618
- const observation = await execute();
619
+ const observation = await prepareComputerUseObservation(await execute());
619
620
  return this.formatObservation(observation, undefined, false, {
620
621
  toolName,
621
622
  input,
@@ -791,7 +792,7 @@ export class HostCuProxy {
791
792
  );
792
793
  }
793
794
 
794
- const screenshotMeta = this.formatScreenshotMetadata(obs);
795
+ const screenshotMeta = this.formatScreenshotMetadata(obs, action);
795
796
  if (screenshotMeta.length > 0) {
796
797
  parts.push("");
797
798
  parts.push(...screenshotMeta);
@@ -898,7 +899,10 @@ export class HostCuProxy {
898
899
  }
899
900
  }
900
901
 
901
- private formatScreenshotMetadata(obs: CuObservationResult): string[] {
902
+ private formatScreenshotMetadata(
903
+ obs: CuObservationResult,
904
+ action: ActionIdentity | undefined,
905
+ ): string[] {
902
906
  if (!obs.screenshot) {
903
907
  return [];
904
908
  }
@@ -914,6 +918,33 @@ export class HostCuProxy {
914
918
  `Screen metadata: ${obs.screenWidthPt}x${obs.screenHeightPt} pt`,
915
919
  );
916
920
  }
921
+ if (action && hasCaptureTarget(action.input)) {
922
+ lines.push(
923
+ "This screenshot is capture-relative. Full-screen dimensions do not map its pixels to action coordinates. Use accessibility element IDs, or request an unscoped desktop observation before using coordinates.",
924
+ );
925
+ } else if (
926
+ [
927
+ obs.screenshotWidthPx,
928
+ obs.screenshotHeightPx,
929
+ obs.screenWidthPt,
930
+ obs.screenHeightPt,
931
+ ].every(
932
+ (dimension) =>
933
+ typeof dimension === "number" &&
934
+ Number.isFinite(dimension) &&
935
+ dimension > 0,
936
+ )
937
+ ) {
938
+ const scaleX = obs.screenWidthPt! / obs.screenshotWidthPx!;
939
+ const scaleY = obs.screenHeightPt! / obs.screenshotHeightPx!;
940
+ lines.push(
941
+ `Action coordinates are screen points, not screenshot pixels. Convert this image's pixels: x = round(image_x * ${scaleX.toFixed(6)}), y = round(image_y * ${scaleY.toFixed(6)}). Prefer accessibility element IDs when available.`,
942
+ );
943
+ } else {
944
+ lines.push(
945
+ "Screenshot-to-screen coordinate mapping is unavailable. Use accessibility element IDs or obtain an observation with both screenshot and screen dimensions before using coordinates.",
946
+ );
947
+ }
917
948
  return lines;
918
949
  }
919
950
  }
@@ -13,6 +13,7 @@ import {
13
13
  } from "../config/loader.js";
14
14
  import { seedInferenceProfiles } from "../config/seed-inference-profiles.js";
15
15
  import { reconcileFlagGatedProfiles } from "../config/sync-gated-profiles.js";
16
+ import { startConversationAutoArchive } from "../conversations/auto-archive.js";
16
17
  import { startCes } from "../credential-execution/ces-runtime.js";
17
18
  import { refreshManagedConnectionCache } from "../credential-execution/managed-catalog.js";
18
19
  import { startHeartbeatService } from "../heartbeat/heartbeat-service.js";
@@ -57,6 +58,7 @@ import { startScheduler } from "../schedule/scheduler.js";
57
58
  import { getSubagentManager } from "../subagent/index.js";
58
59
  import { startUsageTelemetryReporter } from "../telemetry/usage-telemetry-reporter.js";
59
60
  import { getLogger, initLogger } from "../util/logger.js";
61
+ import { DAEMON_OOM_SCORE_ADJ, setOomScoreAdj } from "../util/oom-priority.js";
60
62
  import {
61
63
  ensureDataDir,
62
64
  getDotEnvPath,
@@ -114,6 +116,9 @@ export async function runDaemon(): Promise<void> {
114
116
  // the event hub real clients subscribe to, so plugin-facing publishes made
115
117
  // here fan out locally rather than routing to a daemon over IPC.
116
118
  markCurrentProcessAsMainDaemon();
119
+ // Before the first spawn: every child inherits this value and resets its
120
+ // own, so the kernel OOM killer takes a tool or worker before the daemon.
121
+ const oomProtected = setOomScoreAdj(DAEMON_OOM_SCORE_ADJ);
117
122
 
118
123
  const startupStartedAt = Date.now();
119
124
  // dotenv loads before the first log call so the lazy root logger
@@ -121,7 +126,13 @@ export async function runDaemon(): Promise<void> {
121
126
  // whatever was in the live environment at process spawn.
122
127
  loadDotEnv();
123
128
  validateEnv();
124
- log.info({ version: APP_VERSION }, "Daemon starting");
129
+ log.info(
130
+ {
131
+ version: APP_VERSION,
132
+ oomScoreAdj: oomProtected ? DAEMON_OOM_SCORE_ADJ : undefined,
133
+ },
134
+ "Daemon starting",
135
+ );
125
136
 
126
137
  // Signal handlers install before any blocking startup work — a boot that
127
138
  // inherits a large WAL can spend minutes inside `initializeDb()`, and
@@ -860,13 +871,15 @@ export async function runDaemon(): Promise<void> {
860
871
  // CES, which the startup sequence above just brought up. Fire-and-forget:
861
872
  // the resumes run sequentially in the background while the daemon serves
862
873
  // requests; per-conversation failures are logged inside.
874
+ let startupRecovery = Promise.resolve();
863
875
  if (conversationsToResume.length > 0) {
864
876
  log.info(
865
877
  { count: conversationsToResume.length },
866
878
  "Resuming conversations interrupted by the previous process",
867
879
  );
868
- void resumeInterruptedConversations(conversationsToResume);
880
+ startupRecovery = resumeInterruptedConversations(conversationsToResume);
869
881
  }
882
+ startConversationAutoArchive(startupRecovery);
870
883
 
871
884
  log.info(
872
885
  {
@@ -1,4 +1,5 @@
1
1
  import { disposeAcpSessionManager } from "../acp/index.js";
2
+ import { stopConversationAutoArchive } from "../conversations/auto-archive.js";
2
3
  import { stopCes } from "../credential-execution/ces-runtime.js";
3
4
  import { stopHeartbeatService } from "../heartbeat/heartbeat-service.js";
4
5
  import { stopCliIpcServer } from "../ipc/assistant-server.js";
@@ -43,6 +44,7 @@ const log = getLogger("lifecycle");
43
44
  * leaves a stale PID file or orphaned timers behind.
44
45
  */
45
46
  function stopBackgroundServicesAndCleanupPidFile(): void {
47
+ stopConversationAutoArchive();
46
48
  stopGatewayFlagListener();
47
49
  stopDiskPressureGuardForLifecycle();
48
50
  stopResourcePressureGuardForLifecycle();
@@ -63,6 +65,7 @@ async function shutdown(): Promise<void> {
63
65
  return;
64
66
  }
65
67
  shuttingDown = true;
68
+ stopConversationAutoArchive();
66
69
 
67
70
  // Force exit if graceful shutdown takes too long.
68
71
  // Set this BEFORE awaiting heartbeat stop so it covers all
@@ -23,6 +23,10 @@ const pendingFinalizations = new Map<
23
23
  { promise: Promise<void>; settle: () => void }
24
24
  >();
25
25
 
26
+ export function hasPendingTurnFinalization(conversationId: string): boolean {
27
+ return pendingFinalizations.has(conversationId);
28
+ }
29
+
26
30
  /**
27
31
  * Open the barrier for a turn that is starting. Returns the closer, which the
28
32
  * turn calls once everything the next turn must not overlap with is done.
@@ -2,9 +2,14 @@ import { readdir, readFile, readlink, realpath } from "node:fs/promises";
2
2
  import { createServer } from "node:net";
3
3
  import { join } from "node:path";
4
4
 
5
+ import { z } from "zod";
6
+
5
7
  import { shouldRestoreDesktopChromeSession } from "./desktop-chrome-session.js";
6
8
 
7
9
  export const DESKTOP_CHROME_WINDOW_CLASS = "vellum-desktop-chrome";
10
+ const DesktopVersionResponseSchema = z.object({
11
+ webSocketDebuggerUrl: z.unknown().optional(),
12
+ });
8
13
 
9
14
  export async function allocateDesktopDebugPort(): Promise<number> {
10
15
  const server = createServer();
@@ -119,9 +124,12 @@ export async function discoverDesktopBrowser(
119
124
  if (body.length > 16_384) {
120
125
  throw new Error("Desktop browser discovery exceeded its size limit");
121
126
  }
122
- const data = JSON.parse(body) as { webSocketDebuggerUrl?: unknown };
127
+ const parsed = DesktopVersionResponseSchema.safeParse(JSON.parse(body));
123
128
  await assertDesktopListener(pid, port);
124
- return validateDesktopWebSocket(data.webSocketDebuggerUrl, port);
129
+ return validateDesktopWebSocket(
130
+ parsed.success ? parsed.data.webSocketDebuggerUrl : undefined,
131
+ port,
132
+ );
125
133
  }
126
134
 
127
135
  export function desktopChromeArguments(
@@ -134,6 +142,7 @@ export function desktopChromeArguments(
134
142
  `--class=${DESKTOP_CHROME_WINDOW_CLASS}`,
135
143
  "--force-renderer-accessibility",
136
144
  "--disable-dev-shm-usage",
145
+ `--disk-cache-size=${250 * 1024 * 1024}`,
137
146
  "--disable-features=Prerender2",
138
147
  ...(shouldRestoreDesktopChromeSession(profileDir)
139
148
  ? ["--restore-last-session", "--hide-crash-restore-bubble"]
@@ -35,6 +35,7 @@ test("preserves unrelated policies and does not rewrite on repeated startup", ()
35
35
  path,
36
36
  JSON.stringify({
37
37
  CommandLineFlagSecurityWarningsEnabled: false,
38
+ PasswordManagerEnabled: false,
38
39
  DownloadRestrictions: 1,
39
40
  }),
40
41
  );
@@ -23,16 +23,22 @@ export function writeDesktopChromePolicy(policyDir: string): void {
23
23
  }
24
24
  }
25
25
  if (
26
+ policy.NetworkPredictionOptions === 2 &&
26
27
  policy.CommandLineFlagSecurityWarningsEnabled === false &&
27
- policy.PasswordManagerEnabled === false
28
+ policy.PasswordManagerEnabled === false &&
29
+ policy.HighEfficiencyModeEnabled === true &&
30
+ policy.MemorySaverModeSavings === 1
28
31
  ) {
29
32
  return;
30
33
  }
31
34
 
35
+ policy.NetworkPredictionOptions = 2;
32
36
  // This suppresses command-line warnings; Chrome's sandbox stays unchanged.
33
37
  policy.CommandLineFlagSecurityWarningsEnabled = false;
34
38
  // Suppress save prompts while keeping previously saved passwords usable.
35
39
  policy.PasswordManagerEnabled = false;
40
+ policy.HighEfficiencyModeEnabled = true;
41
+ policy.MemorySaverModeSavings = 1;
36
42
  mkdirSync(policyDir, { recursive: true });
37
43
  const staging = mkdtempSync(join(policyDir, ".vellum-desktop-"));
38
44
  try {
@@ -1,5 +1,7 @@
1
1
  import { describe, expect, mock, spyOn, test } from "bun:test";
2
2
 
3
+ import sharp from "sharp";
4
+
3
5
  import { run as click } from "../config/bundled-skills/computer-use/tools/computer-use-click.js";
4
6
  import * as configLoader from "../config/loader.js";
5
7
  import { HostCuProxy } from "../daemon/host-cu-proxy.js";
@@ -14,12 +16,20 @@ import {
14
16
  } from "./desktop-computer-use.js";
15
17
  import * as sessionManager from "./desktop-session-manager.js";
16
18
 
19
+ const SCREENSHOT = (
20
+ await sharp({
21
+ create: { width: 1440, height: 810, channels: 3, background: "white" },
22
+ })
23
+ .jpeg()
24
+ .toBuffer()
25
+ ).toString("base64");
26
+
17
27
  function driver(userGuidance?: string) {
18
28
  return {
19
29
  input: mock(async (_args: string[], _signal?: AbortSignal) => {}),
20
30
  capture: mock(async (_signal: AbortSignal) => ({
21
31
  userGuidance,
22
- screenshot: "anBlZw==",
32
+ screenshot: SCREENSHOT,
23
33
  screenshotWidthPx: 1440,
24
34
  screenshotHeightPx: 810,
25
35
  screenWidthPt: 1440,
@@ -52,7 +62,7 @@ describe("virtual desktop computer use", () => {
52
62
  signal(),
53
63
  backend,
54
64
  );
55
- expect(result.screenshot).toBe("anBlZw==");
65
+ expect(result.screenshot).toBe(SCREENSHOT);
56
66
  }
57
67
  expect(backend.input).not.toHaveBeenCalled();
58
68
  expect(backend.capture).toHaveBeenCalledTimes(2);
@@ -161,7 +171,7 @@ describe("virtual desktop computer use", () => {
161
171
  );
162
172
  expect(backend.input).toHaveBeenCalledTimes(1);
163
173
  expect(result.executionError).toBe("Input failed");
164
- expect(result.screenshot).toBe("anBlZw==");
174
+ expect(result.screenshot).toBe(SCREENSHOT);
165
175
  });
166
176
 
167
177
  test("done releases only its conversation without starting the desktop", async () => {
@@ -316,7 +326,7 @@ describe("virtual desktop computer use", () => {
316
326
  source: {
317
327
  type: "base64",
318
328
  media_type: "image/jpeg",
319
- data: "anBlZw==",
329
+ data: SCREENSHOT,
320
330
  },
321
331
  },
322
332
  ]);
@@ -15,6 +15,7 @@ import { getIsContainerized } from "../config/env-registry.js";
15
15
  import { connectCdpWsTransport } from "../tools/browser/cdp-client/cdp-inspect/ws-transport.js";
16
16
  import { terminateProcessTree } from "../util/host-process.js";
17
17
  import { getLogger } from "../util/logger.js";
18
+ import { CHILD_OOM_SCORE_ADJ, withOomScoreAdj } from "../util/oom-priority.js";
18
19
  import { getDataDir, getWorkspaceDir } from "../util/platform.js";
19
20
  import { sleep } from "../util/retry.js";
20
21
  import { DesktopBrowserClient } from "./desktop-browser-client.js";
@@ -46,7 +47,7 @@ const log = getLogger("desktop-session");
46
47
 
47
48
  export const DESKTOP_VNC_PORT = 5999;
48
49
  const DESKTOP_GEOMETRY = `${DESKTOP_WIDTH}x${DESKTOP_HEIGHT}`;
49
- const DESKTOP_LINGER_MS = 24 * 60 * 60_000;
50
+ const DESKTOP_LINGER_MS = 8 * 60 * 60_000;
50
51
  const VNC_READY_DEADLINE_MS = 10_000;
51
52
  const VNC_PROBE_INTERVAL_MS = 100;
52
53
  const KILL_GRACE_MS = 2_000;
@@ -928,8 +929,9 @@ function spawnDetached(
928
929
  request: DesktopSpawnRequest,
929
930
  ): DesktopChild {
930
931
  // Each child leads its own process group so teardown can kill everything
931
- // it forked (Chrome's renderers, openbox's autostart) in one signal.
932
- return Bun.spawn([...request.cmd], {
932
+ // it forked (Chrome's renderers, openbox's autostart) in one signal. The
933
+ // OOM wrapper execs in place, so pid and process group are unchanged.
934
+ return Bun.spawn(withOomScoreAdj(request.cmd, CHILD_OOM_SCORE_ADJ), {
933
935
  env: request.env,
934
936
  detached: true,
935
937
  stdio: ["ignore", "ignore", "ignore"],