@vellumai/assistant 0.10.3-dev.202606292327.80883ab → 0.10.3-dev.202606300531.247eff8

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 (93) hide show
  1. package/docs/architecture/memory.md +26 -0
  2. package/openapi.yaml +173 -1
  3. package/package.json +1 -1
  4. package/src/__tests__/agent-loop-compaction-events.test.ts +1 -0
  5. package/src/__tests__/agent-loop-compaction-strip.test.ts +2 -0
  6. package/src/__tests__/agent-loop-exit-reason.test.ts +2 -0
  7. package/src/__tests__/agent-loop-regrowth-guard.test.ts +8 -0
  8. package/src/__tests__/agent-loop.test.ts +1 -0
  9. package/src/__tests__/context-search-memory-v2-source.test.ts +1 -0
  10. package/src/__tests__/conversation-agent-loop.test.ts +39 -1
  11. package/src/__tests__/conversation-runtime-assembly.test.ts +6 -6
  12. package/src/__tests__/device-id.test.ts +38 -1
  13. package/src/__tests__/history-repair-hook.test.ts +1 -1
  14. package/src/__tests__/lifecycle-memory-v2-seed.test.ts +1 -0
  15. package/src/__tests__/llm-request-log-source-clickhouse.test.ts +1 -0
  16. package/src/__tests__/mcp-config-secret-boundary.test.ts +1 -0
  17. package/src/__tests__/memory-retrieval-hook.test.ts +1 -1
  18. package/src/__tests__/qdrant-collection-migration.test.ts +4 -1
  19. package/src/__tests__/title-generate-hook.test.ts +1 -1
  20. package/src/agent/loop.ts +190 -135
  21. package/src/api/index.ts +4 -0
  22. package/src/api/responses/llm-request-log-entry.ts +41 -0
  23. package/src/cli/commands/__tests__/conversations-wake.test.ts +147 -0
  24. package/src/cli/commands/conversations.ts +32 -2
  25. package/src/{__tests__/config-managed-gemini-defaults.test.ts → config/__tests__/deployment-context-defaults.test.ts} +64 -113
  26. package/src/config/bundled-skills/app-builder/SKILL.md +2 -0
  27. package/src/config/llm-resolver.ts +17 -0
  28. package/src/config/loader.ts +38 -58
  29. package/src/config/schemas/__tests__/memory-v3.test.ts +11 -11
  30. package/src/config/schemas/memory-v3.ts +10 -10
  31. package/src/daemon/__tests__/embedding-reconcile.test.ts +456 -0
  32. package/src/daemon/__tests__/lifecycle-embedding-reconcile.test.ts +119 -0
  33. package/src/daemon/__tests__/memory-v2-startup.test.ts +86 -0
  34. package/src/daemon/conversation-agent-loop-handlers.ts +58 -8
  35. package/src/daemon/conversation-agent-loop.ts +31 -13
  36. package/src/daemon/conversation-runtime-assembly.ts +10 -8
  37. package/src/daemon/conversation.ts +1 -0
  38. package/src/daemon/embedding-reconcile.ts +340 -0
  39. package/src/daemon/lifecycle.ts +15 -0
  40. package/src/daemon/memory-v2-startup.ts +35 -1
  41. package/src/daemon/turn-latency-tracker.test.ts +137 -0
  42. package/src/daemon/turn-latency-tracker.ts +134 -0
  43. package/src/memory/graph/__tests__/conversation-graph-memory-v2-routing.test.ts +1 -0
  44. package/src/memory/v2/__tests__/activation.test.ts +41 -0
  45. package/src/memory/v2/__tests__/backfill-jobs.test.ts +1 -0
  46. package/src/memory/v2/__tests__/injection.test.ts +1 -0
  47. package/src/memory/v2/__tests__/qdrant.test.ts +31 -7
  48. package/src/memory/v2/__tests__/sim.test.ts +29 -0
  49. package/src/memory/v2/activation.ts +22 -10
  50. package/src/memory/v2/qdrant.ts +48 -1
  51. package/src/memory/v2/sim.ts +24 -10
  52. package/src/messaging/providers/slack/render.test.ts +166 -4
  53. package/src/messaging/providers/slack/render.ts +289 -36
  54. package/src/persistence/embeddings/__tests__/embedding-identity.test.ts +156 -0
  55. package/src/persistence/embeddings/__tests__/reconcile-decision.test.ts +95 -0
  56. package/src/persistence/embeddings/embedding-backend.test.ts +151 -0
  57. package/src/persistence/embeddings/embedding-backend.ts +132 -26
  58. package/src/persistence/embeddings/embedding-identity.ts +88 -0
  59. package/src/persistence/embeddings/embedding-types.ts +7 -0
  60. package/src/persistence/embeddings/qdrant-client.ts +9 -1
  61. package/src/persistence/embeddings/reconcile-decision.ts +53 -0
  62. package/src/persistence/llm-request-log-source-clickhouse.ts +4 -0
  63. package/src/persistence/llm-request-log-store.ts +25 -2
  64. package/src/persistence/migrations/310-llm-request-log-latency-breakdown.ts +37 -0
  65. package/src/persistence/schema/infrastructure.ts +8 -0
  66. package/src/persistence/steps.ts +2 -0
  67. package/src/plugin-api/types.ts +9 -13
  68. package/src/plugins/defaults/image-fallback/__tests__/image-fallback.test.ts +23 -9
  69. package/src/plugins/defaults/image-fallback/hooks/user-prompt-submit.ts +2 -3
  70. package/src/plugins/defaults/image-fallback/src/caption-blocks.ts +7 -14
  71. package/src/plugins/defaults/memory/hooks/post-compact.ts +3 -4
  72. package/src/plugins/defaults/memory/hooks/user-prompt-submit.ts +5 -4
  73. package/src/plugins/defaults/memory/v3/__tests__/dense.test.ts +15 -0
  74. package/src/plugins/defaults/memory/v3/__tests__/maintain-job.test.ts +24 -0
  75. package/src/plugins/defaults/memory/v3/__tests__/orchestrate.test.ts +20 -9
  76. package/src/plugins/defaults/memory/v3/__tests__/section-dense-store.test.ts +52 -9
  77. package/src/plugins/defaults/memory/v3/__tests__/shadow-integration.test.ts +16 -6
  78. package/src/plugins/defaults/memory/v3/__tests__/shadow-plugin.test.ts +56 -9
  79. package/src/plugins/defaults/memory/v3/dense.ts +13 -2
  80. package/src/plugins/defaults/memory/v3/hot-set.test.ts +1 -1
  81. package/src/plugins/defaults/memory/v3/maintain-job.ts +17 -20
  82. package/src/plugins/defaults/memory/v3/orchestrate.ts +2 -2
  83. package/src/plugins/defaults/memory/v3/section-dense-store.ts +56 -7
  84. package/src/plugins/defaults/memory/v3/shadow-plugin.ts +17 -14
  85. package/src/runtime/__tests__/agent-wake.test.ts +7 -3
  86. package/src/runtime/agent-wake.ts +17 -0
  87. package/src/runtime/routes/__tests__/memory-worker-routes.test.ts +107 -1
  88. package/src/runtime/routes/__tests__/wake-conversation-routes.test.ts +36 -0
  89. package/src/runtime/routes/conversation-query-routes.ts +24 -1
  90. package/src/runtime/routes/memory-worker-routes.ts +19 -2
  91. package/src/runtime/routes/platform-routes.ts +3 -0
  92. package/src/runtime/routes/wake-conversation-routes.ts +18 -2
  93. package/src/util/device-id.ts +52 -12
@@ -405,6 +405,32 @@ When the embedding backend or Qdrant is unavailable:
405
405
  - If embeddings are optional (default), the pipeline returns empty results (no fallback search path exists without Qdrant).
406
406
  - Degradation status is reported to clients via `memory_status` events.
407
407
 
408
+ ### Embedding Dimension Reconciliation
409
+
410
+ The embedding dimension is a **committed property of the Qdrant collection**, derived from the dimension of whichever embedding backend built it. It is not a free-standing config value the user picks: `memory.qdrant.vectorSize` records the dimension the collections were created at, and reconciliation keeps that record consistent with the reachable backend.
411
+
412
+ `reconcileEmbeddingIdentity` (`assistant/src/daemon/embedding-reconcile.ts`) runs once at daemon startup. It reads the committed collection dimension and probes the configured backend in parallel, then routes both observations through the pure `decideEmbeddingReconcile` (`assistant/src/persistence/embeddings/reconcile-decision.ts`) and executes the resulting action. A transient backend outage **degrades** (recall returns empty results, surfaced via `memory_worker_status`'s `embedding.degraded` flag) — it never destroys the collection.
413
+
414
+ #### Decision table
415
+
416
+ | Probe | Committed dim | Provider | Action | Effect |
417
+ | --------------------------- | ------------- | ----------------------------------------- | ---------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
418
+ | down (no reachable backend) | — | — | `defer-degraded` | No write, no destructive call. Warn and leave the collection untouched. |
419
+ | up | none | — | `commit-fresh` | Adopt the probed dimension: commit it, ensure the collections exist at it (create-if-absent), enqueue a reembed. |
420
+ | up | matches probe | — | `noop` | No writes. |
421
+ | up | mismatch | explicit (`openai` / `gemini` / `ollama`) | `migrate` | Deliberate intent, confirmed by a successful probe: commit the new dim, destroy + recreate the collections, enqueue a reembed. The only destructive path. |
422
+ | up | mismatch | `auto` | `noop` | No thrash. Under `auto` the reachable backend can flip between a small local model (384) and a large managed model (3072) on transient availability, so a per-boot mismatch is not allowed to recreate the collection. |
423
+
424
+ Confirm-before-destroy: a destructive recreate runs only on a `migrate` action, and only after a non-null backend probe. This makes the dimension change depend on the backend being reachable rather than on a config flag written before the backend is known to answer.
425
+
426
+ #### Platform intent is a fill-only deployment default
427
+
428
+ Platform deployments express an embedding-provider preference through `getDeploymentContextDefaults` in `assistant/src/config/loader.ts`: when `IS_PLATFORM` is set, the loader **fills** `memory.embeddings.provider: "gemini"` as an in-memory default. This default is layered at config-load time and is **not persisted** to `config.json`, and it does **not** set `memory.qdrant.vectorSize` or `geminiModel`. The dimension stays derived from the live probe; the explicit provider only lifts a genuine upgrade from `noop` (auto) to `migrate` (explicit) in the decision table above. There is no config migration that writes a provider or dimension to disk.
429
+
430
+ #### Lazy ensure vs. startup reconcile
431
+
432
+ The lazy `ensureCollection` paths (`ensureConceptPageCollection` in `assistant/src/memory/v2/qdrant.ts`, `ensureSectionCollection` for v3) **create-if-absent only** for the committed dimension. They never perform a dimension migration — destructive dimension change is owned solely by the startup reconcile's `migrate` action. The lazy paths still recreate on **schema drift**: a collection missing a required named vector (e.g. an unnamed-vector layout, or one lacking `summary_dense` / `summary_sparse`) is rebuilt and signalled via `{ migrated: true }` so callers enqueue a backfill.
433
+
408
434
  ---
409
435
 
410
436
  ## Workspace Context Injection — Directory Awareness
package/openapi.yaml CHANGED
@@ -8527,6 +8527,49 @@ paths:
8527
8527
  - type: "null"
8528
8528
  additionalProperties: false
8529
8529
  - type: "null"
8530
+ latency:
8531
+ anyOf:
8532
+ - type: object
8533
+ properties:
8534
+ phases:
8535
+ type: array
8536
+ items:
8537
+ type: object
8538
+ properties:
8539
+ key:
8540
+ type: string
8541
+ label:
8542
+ type: string
8543
+ ms:
8544
+ type: number
8545
+ required:
8546
+ - key
8547
+ - label
8548
+ - ms
8549
+ additionalProperties: false
8550
+ ttftMs:
8551
+ anyOf:
8552
+ - type: number
8553
+ - type: "null"
8554
+ totalToFirstTokenMs:
8555
+ anyOf:
8556
+ - type: number
8557
+ - type: "null"
8558
+ providerDurationMs:
8559
+ anyOf:
8560
+ - type: number
8561
+ - type: "null"
8562
+ firstTokenKind:
8563
+ anyOf:
8564
+ - type: string
8565
+ enum:
8566
+ - thinking
8567
+ - text
8568
+ - type: "null"
8569
+ required:
8570
+ - phases
8571
+ additionalProperties: false
8572
+ - type: "null"
8530
8573
  required:
8531
8574
  - id
8532
8575
  - createdAt
@@ -9097,6 +9140,10 @@ paths:
9097
9140
  cronRunId:
9098
9141
  type: string
9099
9142
  minLength: 1
9143
+ persist:
9144
+ type: boolean
9145
+ externalContent:
9146
+ type: string
9100
9147
  required:
9101
9148
  - conversationId
9102
9149
  - hint
@@ -15521,6 +15568,49 @@ paths:
15521
15568
  - type: "null"
15522
15569
  additionalProperties: false
15523
15570
  - type: "null"
15571
+ latency:
15572
+ anyOf:
15573
+ - type: object
15574
+ properties:
15575
+ phases:
15576
+ type: array
15577
+ items:
15578
+ type: object
15579
+ properties:
15580
+ key:
15581
+ type: string
15582
+ label:
15583
+ type: string
15584
+ ms:
15585
+ type: number
15586
+ required:
15587
+ - key
15588
+ - label
15589
+ - ms
15590
+ additionalProperties: false
15591
+ ttftMs:
15592
+ anyOf:
15593
+ - type: number
15594
+ - type: "null"
15595
+ totalToFirstTokenMs:
15596
+ anyOf:
15597
+ - type: number
15598
+ - type: "null"
15599
+ providerDurationMs:
15600
+ anyOf:
15601
+ - type: number
15602
+ - type: "null"
15603
+ firstTokenKind:
15604
+ anyOf:
15605
+ - type: string
15606
+ enum:
15607
+ - thinking
15608
+ - text
15609
+ - type: "null"
15610
+ required:
15611
+ - phases
15612
+ additionalProperties: false
15613
+ - type: "null"
15524
15614
  required:
15525
15615
  - id
15526
15616
  - createdAt
@@ -16563,7 +16653,9 @@ paths:
16563
16653
  get:
16564
16654
  operationId: memory_worker_status_get
16565
16655
  summary: Memory worker status
16566
- description: Reports the memory worker process state, memory.worker.enabled, and the synchronous in-process runner.
16656
+ description:
16657
+ Reports the memory worker process state, memory.worker.enabled, the synchronous in-process runner, and the
16658
+ embedding-backend status (including a degraded flag and reason when no backend resolves).
16567
16659
  tags:
16568
16660
  - system
16569
16661
  responses:
@@ -16596,10 +16688,42 @@ paths:
16596
16688
  required:
16597
16689
  - status
16598
16690
  additionalProperties: false
16691
+ embedding:
16692
+ type: object
16693
+ properties:
16694
+ enabled:
16695
+ type: boolean
16696
+ degraded:
16697
+ type: boolean
16698
+ provider:
16699
+ anyOf:
16700
+ - type: string
16701
+ enum:
16702
+ - local
16703
+ - openai
16704
+ - gemini
16705
+ - ollama
16706
+ - type: "null"
16707
+ model:
16708
+ anyOf:
16709
+ - type: string
16710
+ - type: "null"
16711
+ reason:
16712
+ anyOf:
16713
+ - type: string
16714
+ - type: "null"
16715
+ required:
16716
+ - enabled
16717
+ - degraded
16718
+ - provider
16719
+ - model
16720
+ - reason
16721
+ additionalProperties: false
16599
16722
  required:
16600
16723
  - status
16601
16724
  - workerEnabled
16602
16725
  - syncRunner
16726
+ - embedding
16603
16727
  additionalProperties: false
16604
16728
  /v1/memory/worker/stop:
16605
16729
  post:
@@ -18145,6 +18269,49 @@ paths:
18145
18269
  - type: "null"
18146
18270
  additionalProperties: false
18147
18271
  - type: "null"
18272
+ latency:
18273
+ anyOf:
18274
+ - type: object
18275
+ properties:
18276
+ phases:
18277
+ type: array
18278
+ items:
18279
+ type: object
18280
+ properties:
18281
+ key:
18282
+ type: string
18283
+ label:
18284
+ type: string
18285
+ ms:
18286
+ type: number
18287
+ required:
18288
+ - key
18289
+ - label
18290
+ - ms
18291
+ additionalProperties: false
18292
+ ttftMs:
18293
+ anyOf:
18294
+ - type: number
18295
+ - type: "null"
18296
+ totalToFirstTokenMs:
18297
+ anyOf:
18298
+ - type: number
18299
+ - type: "null"
18300
+ providerDurationMs:
18301
+ anyOf:
18302
+ - type: number
18303
+ - type: "null"
18304
+ firstTokenKind:
18305
+ anyOf:
18306
+ - type: string
18307
+ enum:
18308
+ - thinking
18309
+ - text
18310
+ - type: "null"
18311
+ required:
18312
+ - phases
18313
+ additionalProperties: false
18314
+ - type: "null"
18148
18315
  required:
18149
18316
  - id
18150
18317
  - createdAt
@@ -20315,6 +20482,10 @@ paths:
20315
20482
  type: boolean
20316
20483
  hasWebhookSecret:
20317
20484
  type: boolean
20485
+ clientInstallationId:
20486
+ anyOf:
20487
+ - type: string
20488
+ - type: "null"
20318
20489
  available:
20319
20490
  type: boolean
20320
20491
  organizationId:
@@ -20346,6 +20517,7 @@ paths:
20346
20517
  - assistantId
20347
20518
  - hasAssistantApiKey
20348
20519
  - hasWebhookSecret
20520
+ - clientInstallationId
20349
20521
  - available
20350
20522
  - organizationId
20351
20523
  - userId
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vellumai/assistant",
3
- "version": "0.10.3-dev.202606292327.80883ab",
3
+ "version": "0.10.3-dev.202606300531.247eff8",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "exports": {
@@ -150,6 +150,7 @@ describe("AgentLoop compaction start/end event pair", () => {
150
150
  onEvent: (event) => {
151
151
  events.push(event);
152
152
  },
153
+ modelProfileKey: "balanced",
153
154
  resolveContextWindow: () => ({
154
155
  maxInputTokens: 10,
155
156
  overflowRecovery: { enabled: true, safetyMarginRatio: 0 },
@@ -167,6 +167,7 @@ describe("AgentLoop compaction summarizer input", () => {
167
167
  onEvent: (event) => {
168
168
  events.push(event);
169
169
  },
170
+ modelProfileKey: "balanced",
170
171
  resolveContextWindow: () => ({
171
172
  maxInputTokens: 10,
172
173
  overflowRecovery: { enabled: true, safetyMarginRatio: 0 },
@@ -221,6 +222,7 @@ describe("AgentLoop compaction summarizer input", () => {
221
222
  onEvent: (event) => {
222
223
  events.push(event);
223
224
  },
225
+ modelProfileKey: "balanced",
224
226
  resolveContextWindow: () => ({
225
227
  maxInputTokens: 10,
226
228
  overflowRecovery: { enabled: true, safetyMarginRatio: 0 },
@@ -460,6 +460,7 @@ describe("AgentLoop exit-reason instrumentation", () => {
460
460
  messages: [userMessage],
461
461
  onEvent: () => {},
462
462
  trust: { sourceChannel: "vellum", trustClass: "unknown" },
463
+ modelProfileKey: "balanced",
463
464
  resolveContextWindow: () => ({
464
465
  maxInputTokens: 10,
465
466
  overflowRecovery: { enabled: false, safetyMarginRatio: 0 },
@@ -500,6 +501,7 @@ describe("AgentLoop exit-reason instrumentation", () => {
500
501
  onEvent: (event) => {
501
502
  events.push(event);
502
503
  },
504
+ modelProfileKey: "balanced",
503
505
  resolveContextWindow: () => ({
504
506
  maxInputTokens: 10,
505
507
  overflowRecovery: { enabled: true, safetyMarginRatio: 0 },
@@ -148,6 +148,7 @@ async function runOnce(args: {
148
148
  onEvent: (event) => {
149
149
  events.push(event);
150
150
  },
151
+ modelProfileKey: "balanced",
151
152
  resolveContextWindow: () => ({
152
153
  maxInputTokens: 10,
153
154
  overflowRecovery: { enabled: true, safetyMarginRatio: 0 },
@@ -215,6 +216,7 @@ describe("AgentLoop budget-gate regrowth guard", () => {
215
216
  onEvent: (event) => {
216
217
  events.push(event);
217
218
  },
219
+ modelProfileKey: "balanced",
218
220
  resolveContextWindow: () => ({
219
221
  maxInputTokens: 10,
220
222
  overflowRecovery: { enabled: true, safetyMarginRatio: 0 },
@@ -249,6 +251,7 @@ describe("AgentLoop budget-gate regrowth guard", () => {
249
251
  requestId: "req",
250
252
  messages: [userMessage],
251
253
  onEvent: () => {},
254
+ modelProfileKey: "balanced",
252
255
  resolveContextWindow: () => ({
253
256
  maxInputTokens: 10,
254
257
  overflowRecovery: { enabled: true, safetyMarginRatio: 0 },
@@ -310,6 +313,7 @@ describe("AgentLoop budget-gate per-turn proactive-futility suppression", () =>
310
313
  onEvent: (event) => {
311
314
  events.push(event);
312
315
  },
316
+ modelProfileKey: "balanced",
313
317
  resolveContextWindow: () => ({
314
318
  maxInputTokens: 10,
315
319
  overflowRecovery: { enabled: true, safetyMarginRatio: 0 },
@@ -369,6 +373,7 @@ describe("AgentLoop budget-gate per-turn proactive-futility suppression", () =>
369
373
  onEvent: (e) => {
370
374
  events.push(e);
371
375
  },
376
+ modelProfileKey: "balanced",
372
377
  resolveContextWindow: () => ({
373
378
  maxInputTokens: 10,
374
379
  overflowRecovery: { enabled: true, safetyMarginRatio: 0 },
@@ -411,6 +416,7 @@ describe("AgentLoop budget-gate per-turn proactive-futility suppression", () =>
411
416
  onEvent: (e) => {
412
417
  turn1.push(e);
413
418
  },
419
+ modelProfileKey: "balanced",
414
420
  resolveContextWindow: () => ({
415
421
  maxInputTokens: 10,
416
422
  overflowRecovery: { enabled: true, safetyMarginRatio: 0 },
@@ -428,6 +434,7 @@ describe("AgentLoop budget-gate per-turn proactive-futility suppression", () =>
428
434
  onEvent: (e) => {
429
435
  turn2.push(e);
430
436
  },
437
+ modelProfileKey: "balanced",
431
438
  resolveContextWindow: () => ({
432
439
  maxInputTokens: 10,
433
440
  overflowRecovery: { enabled: true, safetyMarginRatio: 0 },
@@ -483,6 +490,7 @@ describe("AgentLoop budget-gate per-turn proactive-futility suppression", () =>
483
490
  onEvent: (e) => {
484
491
  events.push(e);
485
492
  },
493
+ modelProfileKey: "balanced",
486
494
  resolveContextWindow: () => ({
487
495
  maxInputTokens: 10,
488
496
  overflowRecovery: { enabled: true, safetyMarginRatio: 0 },
@@ -204,6 +204,7 @@ describe("AgentLoop", () => {
204
204
  trust: { sourceChannel: "vellum", trustClass: "unknown" },
205
205
  requestId: "req-1",
206
206
  callSite: "mainAgent",
207
+ modelProfileKey: "balanced",
207
208
  resolveContextWindow: () => ({
208
209
  maxInputTokens,
209
210
  overflowRecovery: { enabled: false, safetyMarginRatio: 0 },
@@ -36,6 +36,7 @@ mock.module("../util/logger.js", () => ({
36
36
 
37
37
  let denseEmbedReturn: number[] = [0.1, 0.2, 0.3];
38
38
  mock.module("../persistence/embeddings/embedding-backend.js", () => ({
39
+ isEmbeddingDimensionAvailable: async () => true,
39
40
  embedWithBackend: async () => ({
40
41
  provider: "test",
41
42
  model: "test-model",
@@ -32,6 +32,8 @@ const conversationDiskViewRealSnapshot = {
32
32
  ) as Record<string, unknown>),
33
33
  };
34
34
  let mockUiConfig: { userTimezone?: string; detectedTimezone?: string } = {};
35
+ let mockLlmProfiles: Record<string, unknown> = {};
36
+ let mockLlmActiveProfile: string | undefined;
35
37
 
36
38
  // ── Module mocks (must precede imports of the module under test) ─────
37
39
 
@@ -80,8 +82,9 @@ mock.module("../config/loader.js", () => ({
80
82
  },
81
83
  },
82
84
  },
83
- profiles: {},
85
+ profiles: mockLlmProfiles,
84
86
  callSites: {},
87
+ activeProfile: mockLlmActiveProfile,
85
88
  pricingOverrides: [],
86
89
  },
87
90
  rateLimit: { maxRequestsPerMinute: 0 },
@@ -835,6 +838,8 @@ function makeCompactionResult(
835
838
 
836
839
  beforeEach(() => {
837
840
  mockUiConfig = {};
841
+ mockLlmProfiles = {};
842
+ mockLlmActiveProfile = undefined;
838
843
  mockEstimateTokens = 1000;
839
844
  mockReducerStepFn = null;
840
845
  mockOverflowAction = "fail_gracefully";
@@ -903,6 +908,39 @@ beforeEach(() => {
903
908
 
904
909
  describe("session-agent-loop", () => {
905
910
  describe("user-prompt-submit hook failures", () => {
911
+ test("passes the effective profile to hooks even when it was already announced", async () => {
912
+ mockLlmProfiles = {
913
+ balanced: {
914
+ label: "Balanced",
915
+ model: "accounts/fireworks/models/glm-5p2",
916
+ },
917
+ quality: { label: "Quality", model: "claude-opus-4-8" },
918
+ };
919
+ mockLlmActiveProfile = "quality";
920
+ const observedProfileKeys: string[] = [];
921
+ registerPlugin({
922
+ manifest: {
923
+ name: "test-observe-model-profile",
924
+ version: "1.0.0",
925
+ },
926
+ hooks: {
927
+ "user-prompt-submit": async (ctx: UserPromptSubmitContext) => {
928
+ observedProfileKeys.push(ctx.modelProfileKey);
929
+ },
930
+ },
931
+ });
932
+
933
+ const ctx = makeCtx({
934
+ inferenceProfile: "balanced",
935
+ lastNotifiedInferenceProfile: "balanced",
936
+ providerResponses: [textResponse("ok")],
937
+ });
938
+
939
+ await runAgentLoopImpl(ctx, "hello", "msg-1", () => {});
940
+
941
+ expect(observedProfileKeys).toEqual(["balanced"]);
942
+ });
943
+
906
944
  test("logs and continues with prior hook mutations", async () => {
907
945
  registerPlugin({
908
946
  manifest: {
@@ -1104,7 +1104,7 @@ describe("applyRuntimeInjections — injection mode", () => {
1104
1104
  requestId: "reinject-req",
1105
1105
  conversationId: "injection-mode-conv",
1106
1106
  isNonInteractive: false,
1107
- modelProfileKey: null,
1107
+ modelProfileKey: "balanced",
1108
1108
  };
1109
1109
  await postCompact(postCompactCtx);
1110
1110
  const result = postCompactCtx.history;
@@ -1628,16 +1628,16 @@ describe("resolveTurnInboundActorContext", () => {
1628
1628
 
1629
1629
  describe("resolveTurnModelProfileLabel", () => {
1630
1630
  /**
1631
- * A null key means the active profile is unchanged since the last notified
1632
- * one, so there is no `model_profile` line to render this turn.
1631
+ * A null notice key means there is no `model_profile` line to render this
1632
+ * turn.
1633
1633
  */
1634
- test("returns null when the profile key is null", () => {
1635
- // GIVEN a turn whose profile is unchanged since the last notification
1634
+ test("returns null when the profile notice key is null", () => {
1635
+ // GIVEN a turn without a profile notice to render
1636
1636
  const llm = LLMSchema.parse({
1637
1637
  default: { provider: "anthropic", model: "claude-sonnet-4-7" },
1638
1638
  });
1639
1639
 
1640
- // WHEN the label is resolved for a null key
1640
+ // WHEN the label is resolved for a null notice key
1641
1641
  const label = resolveTurnModelProfileLabel(null, "mainAgent", llm);
1642
1642
 
1643
1643
  // THEN there is no profile line to inject
@@ -19,7 +19,11 @@ mock.module("../util/logger.js", () => ({
19
19
  }),
20
20
  }));
21
21
 
22
- import { getDeviceId, resetDeviceIdCache } from "../util/device-id.js";
22
+ import {
23
+ getDeviceId,
24
+ getExistingDeviceId,
25
+ resetDeviceIdCache,
26
+ } from "../util/device-id.js";
23
27
 
24
28
  const originalVellumEnvironment = process.env.VELLUM_ENVIRONMENT;
25
29
  const originalXdgConfigHome = process.env.XDG_CONFIG_HOME;
@@ -179,3 +183,36 @@ describe("getDeviceId VELLUM_DEVICE_ID precedence", () => {
179
183
  expect(getDeviceId()).not.toBe("env-id");
180
184
  });
181
185
  });
186
+
187
+ describe("getExistingDeviceId", () => {
188
+ beforeEach(() => {
189
+ delete process.env.IS_CONTAINERIZED;
190
+ process.env.VELLUM_ENVIRONMENT = "dev";
191
+ process.env.XDG_CONFIG_HOME = tempDir;
192
+ });
193
+
194
+ test("returns null without creating device.json when no id exists", () => {
195
+ const expectedPath = join(tempDir, "vellum-dev", "device.json");
196
+
197
+ expect(getExistingDeviceId()).toBeNull();
198
+ expect(existsSync(expectedPath)).toBe(false);
199
+ });
200
+
201
+ test("reads an existing device.json id", () => {
202
+ const dir = join(tempDir, "vellum-dev");
203
+ mkdirSync(dir, { recursive: true });
204
+ writeFileSync(
205
+ join(dir, "device.json"),
206
+ JSON.stringify({ deviceId: "file-id" }),
207
+ );
208
+
209
+ expect(getExistingDeviceId()).toBe("file-id");
210
+ });
211
+
212
+ test("returns the env override without writing device.json", () => {
213
+ process.env.VELLUM_DEVICE_ID = "env-id";
214
+
215
+ expect(getExistingDeviceId()).toBe("env-id");
216
+ expect(readdirSync(tempDir)).toEqual([]);
217
+ });
218
+ });
@@ -72,7 +72,7 @@ function makeCtx(messages: Message[]): UserPromptSubmitContext {
72
72
  conversationId: "conv-test",
73
73
  userMessageId: "msg-test",
74
74
  requestId: "req-test",
75
- modelProfileKey: null,
75
+ modelProfileKey: "balanced",
76
76
  isNonInteractive: false,
77
77
  prompt: "",
78
78
  originalMessages: messages,
@@ -113,6 +113,7 @@ mock.module("../persistence/jobs-store.js", () => ({
113
113
  state.enqueueCalls.push({ type, payload });
114
114
  return "test-job-id";
115
115
  },
116
+ hasActiveJobOfType: (): boolean => false,
116
117
  }));
117
118
 
118
119
  mock.module("../util/platform.js", () => ({
@@ -106,6 +106,7 @@ describe("ClickHouseLlmRequestLogSource", () => {
106
106
  createdAt: 1778465138786,
107
107
  agentLoopExitReason: "no_tool_calls",
108
108
  callSite: "mainAgent",
109
+ latencyBreakdown: null,
109
110
  });
110
111
  });
111
112
 
@@ -115,6 +115,7 @@ mock.module("../providers/registry.js", () => ({
115
115
  }));
116
116
 
117
117
  mock.module("../persistence/embeddings/embedding-backend.js", () => ({
118
+ isEmbeddingDimensionAvailable: async () => true,
118
119
  EmbeddingBackendUnavailableError: class EmbeddingBackendUnavailableError extends Error {},
119
120
  SPARSE_EMBEDDING_VERSION: 4,
120
121
  clearEmbeddingBackendCache: () => {},
@@ -158,7 +158,7 @@ function makeHookCtx(
158
158
  latestMessages: [],
159
159
  requestId: "req-test",
160
160
  isNonInteractive: false,
161
- modelProfileKey: null,
161
+ modelProfileKey: "balanced",
162
162
  prompt: "",
163
163
  originalMessages: [],
164
164
  ...overrides,
@@ -104,7 +104,7 @@ beforeEach(() => {
104
104
  });
105
105
 
106
106
  describe("Qdrant collection migration", () => {
107
- test("deletes and recreates collection on dimension mismatch", async () => {
107
+ test("deletes and recreates collection on pure dimension mismatch", async () => {
108
108
  mockCollectionExists = true;
109
109
  mockUseNamedVectors = true;
110
110
  mockCollectionSize = 384; // Current collection has 384-dim vectors
@@ -120,6 +120,9 @@ describe("Qdrant collection migration", () => {
120
120
 
121
121
  const result = await client.ensureCollection();
122
122
 
123
+ // The v1 collection is not managed by the startup embedding reconcile, so
124
+ // dimension drift is repaired here: delete + recreate, then rebuild_index
125
+ // re-embeds from the SQLite cache via the lifecycle hook.
123
126
  expect(callLog.deleteCollection).toBe(1);
124
127
  expect(callLog.createCollection).toBe(1);
125
128
  expect(result.migrated).toBe(true);
@@ -109,7 +109,7 @@ function makeCtx(
109
109
  conversationId: "conv-1",
110
110
  userMessageId: "msg-1",
111
111
  requestId: "req-1",
112
- modelProfileKey: null,
112
+ modelProfileKey: "balanced",
113
113
  isNonInteractive: false,
114
114
  prompt: "first message",
115
115
  originalMessages: messages,