@vellumai/assistant 0.9.0-dev.202606191743.3f533cf → 0.9.0-dev.202606191847.4c0bfe4

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vellumai/assistant",
3
- "version": "0.9.0-dev.202606191743.3f533cf",
3
+ "version": "0.9.0-dev.202606191847.4c0bfe4",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "exports": {
@@ -626,6 +626,107 @@ describe("Subagent spawn success and failure", () => {
626
626
  }
627
627
  });
628
628
 
629
+ test("spawn inherits the invoker's resolved profile from attribution over the catalog default", async () => {
630
+ const manager = getSubagentManager();
631
+ const originalSpawn = manager.spawn.bind(manager);
632
+ let capturedConfig: Record<string, unknown> | undefined;
633
+
634
+ manager.spawn = async (config: Record<string, unknown>) => {
635
+ capturedConfig = config;
636
+ return "inherit-applied-id";
637
+ };
638
+
639
+ try {
640
+ const result = await executeSubagentSpawn(
641
+ { label: "Applied child", objective: "Do it" },
642
+ makeContext("sess-inherit-applied", {
643
+ sendToClient: () => {},
644
+ // The invoker ran under heartbeatAgent but resolved to
645
+ // quality-optimized via a configured llm.callSites.heartbeatAgent
646
+ // profile. attribution captures that resolved profile; the catalog
647
+ // default (cost-optimized) would not.
648
+ invokingCallSite: "heartbeatAgent",
649
+ attribution: {
650
+ appliedProfile: "quality-optimized",
651
+ resolvedMixArm: null,
652
+ },
653
+ }),
654
+ );
655
+
656
+ expect(result.isError).toBe(false);
657
+ expect(capturedConfig!.overrideProfile).toBe("quality-optimized");
658
+ } finally {
659
+ manager.spawn = originalSpawn;
660
+ }
661
+ });
662
+
663
+ test("spawn pins the invoker's resolved mix arm rather than the mix name", async () => {
664
+ const manager = getSubagentManager();
665
+ const originalSpawn = manager.spawn.bind(manager);
666
+ let capturedConfig: Record<string, unknown> | undefined;
667
+
668
+ manager.spawn = async (config: Record<string, unknown>) => {
669
+ capturedConfig = config;
670
+ return "inherit-mixarm-id";
671
+ };
672
+
673
+ try {
674
+ const result = await executeSubagentSpawn(
675
+ { label: "Mix child", objective: "Do it" },
676
+ makeContext("sess-inherit-mixarm", {
677
+ sendToClient: () => {},
678
+ invokingCallSite: "mainAgent",
679
+ // The parent turn expanded a mix profile to the "balanced" arm; the
680
+ // child should pin that arm, not re-expand the mix under its own seed.
681
+ attribution: {
682
+ appliedProfile: "balanced-mix",
683
+ resolvedMixArm: "balanced",
684
+ },
685
+ }),
686
+ );
687
+
688
+ expect(result.isError).toBe(false);
689
+ expect(capturedConfig!.overrideProfile).toBe("balanced");
690
+ } finally {
691
+ manager.spawn = originalSpawn;
692
+ }
693
+ });
694
+
695
+ test("spawn pins the resolved mix arm even when the mix was chosen via a per-turn override", async () => {
696
+ const manager = getSubagentManager();
697
+ const originalSpawn = manager.spawn.bind(manager);
698
+ let capturedConfig: Record<string, unknown> | undefined;
699
+
700
+ manager.spawn = async (config: Record<string, unknown>) => {
701
+ capturedConfig = config;
702
+ return "inherit-mixoverride-id";
703
+ };
704
+
705
+ try {
706
+ const result = await executeSubagentSpawn(
707
+ { label: "Mix override child", objective: "Do it" },
708
+ makeContext("sess-inherit-mixoverride", {
709
+ sendToClient: () => {},
710
+ invokingCallSite: "mainAgent",
711
+ // The per-turn override selected a mix, so overrideProfile holds the
712
+ // mix NAME; attribution carries the arm the PARENT expanded it to.
713
+ // The arm must win — forwarding the raw mix name would let the child
714
+ // re-expand to a different arm under its own seed.
715
+ overrideProfile: "experiment-mix",
716
+ attribution: {
717
+ appliedProfile: "experiment-mix",
718
+ resolvedMixArm: "quality-optimized",
719
+ },
720
+ }),
721
+ );
722
+
723
+ expect(result.isError).toBe(false);
724
+ expect(capturedConfig!.overrideProfile).toBe("quality-optimized");
725
+ } finally {
726
+ manager.spawn = originalSpawn;
727
+ }
728
+ });
729
+
629
730
  test("spawn returns error for unknown inference_profile", async () => {
630
731
  const manager = getSubagentManager();
631
732
  const originalSpawn = manager.spawn.bind(manager);
@@ -47,6 +47,20 @@ mock.module("../../runtime/assistant-event-hub.js", () => ({
47
47
  broadcastMessage: () => {},
48
48
  }));
49
49
 
50
+ // Control the advisor profile gate to verify the advisor tool is wired to it.
51
+ // The gate's own config semantics (default-on, active-profile fallback) are
52
+ // covered by advisor-gate.test.ts; here we only assert the wiring and the
53
+ // profile argument isToolActiveForContext passes through.
54
+ let advisorGateResult = true;
55
+ const advisorGateProfiles: (string | null)[] = [];
56
+
57
+ mock.module("../../plugins/defaults/advisor/advisor-gate.js", () => ({
58
+ advisorEnabledForProfile: (profile: string | null) => {
59
+ advisorGateProfiles.push(profile);
60
+ return advisorGateResult;
61
+ },
62
+ }));
63
+
50
64
  // Dynamic imports after mock.module calls so the stubs take effect
51
65
  // before the modules under test are loaded.
52
66
  const { HOST_TOOL_NAMES, HOST_TOOL_TO_CAPABILITY, isToolActiveForContext } =
@@ -597,6 +611,36 @@ describe("isToolActiveForContext — ask_question macOS gating", () => {
597
611
  });
598
612
  });
599
613
 
614
+ describe("isToolActiveForContext — advisor profile gate", () => {
615
+ beforeEach(() => {
616
+ advisorGateResult = true;
617
+ advisorGateProfiles.length = 0;
618
+ });
619
+
620
+ test("advisor is active when the profile enables it", () => {
621
+ advisorGateResult = true;
622
+ expect(isToolActiveForContext("advisor", makeCtx())).toBe(true);
623
+ });
624
+
625
+ test("advisor is NOT active when the profile disables it", () => {
626
+ advisorGateResult = false;
627
+ expect(isToolActiveForContext("advisor", makeCtx())).toBe(false);
628
+ });
629
+
630
+ test("consults the gate with the per-turn override profile", () => {
631
+ isToolActiveForContext(
632
+ "advisor",
633
+ makeCtx({ currentTurnOverrideProfile: "cost-optimized" }),
634
+ );
635
+ expect(advisorGateProfiles).toEqual(["cost-optimized"]);
636
+ });
637
+
638
+ test("consults the gate with null when no per-turn override is set", () => {
639
+ isToolActiveForContext("advisor", makeCtx());
640
+ expect(advisorGateProfiles).toEqual([null]);
641
+ });
642
+ });
643
+
600
644
  describe("HOST_TOOL_NAMES derivation", () => {
601
645
  test("HOST_TOOL_NAMES is derived from HOST_TOOL_TO_CAPABILITY", () => {
602
646
  // Sanity check: every tool in the names set has a capability mapping.
@@ -17,6 +17,7 @@ import type { LLMCallSite } from "../config/schemas/llm.js";
17
17
  import { getBindingByConversation } from "../memory/external-conversation-store.js";
18
18
  import type { PermissionPrompter } from "../permissions/prompter.js";
19
19
  import type { SecretPrompter } from "../permissions/secret-prompter.js";
20
+ import { advisorEnabledForProfile } from "../plugins/defaults/advisor/advisor-gate.js";
20
21
  import type { Message, ToolDefinition } from "../providers/types.js";
21
22
  import { assistantEventHub } from "../runtime/assistant-event-hub.js";
22
23
  import { registerConversationSender } from "../tools/browser/browser-screencast.js";
@@ -91,8 +92,10 @@ export type {
91
92
  * agent's). The conversation id is threaded as the mix selection seed so
92
93
  * mix-profile arms match what the dispatch path actually ran.
93
94
  *
94
- * Returns `null` on any failure: attribution is telemetry-only and must
95
- * never break tool execution (or skill loads, which reuse this helper).
95
+ * Returns `null` on any failure: attribution must never break tool execution
96
+ * (or skill loads, which reuse this helper). Consumers read it best-effort —
97
+ * usage telemetry, and `subagent_spawn`, which inherits the resolved
98
+ * `appliedProfile` so a child defaults to the invoking turn's profile.
96
99
  */
97
100
  export function resolveConversationAttribution(
98
101
  ctx: Pick<
@@ -589,6 +592,16 @@ export function isToolActiveForContext(
589
592
  return true;
590
593
  }
591
594
  }
595
+ if (name === "advisor") {
596
+ // Gated per chat-profile (`ProfileEntry.advisorEnabled`): when the resolved
597
+ // profile disables the advisor, omit the tool from the wire list so the
598
+ // model never sees a tool it can only no-op on. Resolves the profile the
599
+ // same way the advisor's execution-time guard does (the per-turn override,
600
+ // else the active profile). The wire list is fixed before PRE_MODEL_CALL
601
+ // hooks run, so a hook that re-routes the profile mid-turn (the model-router
602
+ // lever on `PreModelCallContext.modelProfile`) is not reflected here.
603
+ return advisorEnabledForProfile(ctx.currentTurnOverrideProfile ?? null);
604
+ }
592
605
  if (UI_SURFACE_TOOL_NAMES.has(name)) {
593
606
  if (
594
607
  channelCapabilities?.channel === "slack" &&
@@ -1138,6 +1138,52 @@ describe("wakeAgentForOpportunity", () => {
1138
1138
  expect(conversation.isProcessing()).toBe(false);
1139
1139
  });
1140
1140
 
1141
+ test("stamps the resolved call site and override profile during the run, then restores them", async () => {
1142
+ const conversation = makeWakeConversation({
1143
+ baseline: [{ role: "user", content: [{ type: "text", text: "hi" }] }],
1144
+ scriptedAssistant: {
1145
+ role: "assistant",
1146
+ content: [{ type: "text", text: "reply" }],
1147
+ },
1148
+ });
1149
+
1150
+ // The conversation is pinned to a profile via its row.
1151
+ mockGetConversationOverrideProfile = () => "quality-optimized";
1152
+
1153
+ // The tool executor reads these fields off the conversation at tool-call
1154
+ // time, so they must reflect the wake's resolved turn while the loop runs.
1155
+ const ctx = conversation as unknown as {
1156
+ currentCallSite?: unknown;
1157
+ currentTurnOverrideProfile?: unknown;
1158
+ };
1159
+ let observedCallSite: unknown;
1160
+ let observedOverrideProfile: unknown;
1161
+ const originalRun = conversation.agentLoop.run;
1162
+ conversation.agentLoop.run = async (options: AgentLoopRunOptions) => {
1163
+ observedCallSite = ctx.currentCallSite;
1164
+ observedOverrideProfile = ctx.currentTurnOverrideProfile;
1165
+ return originalRun(options);
1166
+ };
1167
+
1168
+ await wakeAgentForOpportunity(
1169
+ {
1170
+ conversationId: conversation.conversationId,
1171
+ hint: "x",
1172
+ source: "unit-test",
1173
+ callSite: "heartbeatAgent",
1174
+ },
1175
+ { resolveTarget: async () => conversation },
1176
+ );
1177
+
1178
+ // During the run: the wake's call site and the conversation's pinned profile.
1179
+ expect(observedCallSite).toBe("heartbeatAgent");
1180
+ expect(observedOverrideProfile).toBe("quality-optimized");
1181
+
1182
+ // Restored afterwards so a queued user turn / background read can't inherit them.
1183
+ expect(ctx.currentCallSite).toBeUndefined();
1184
+ expect(ctx.currentTurnOverrideProfile).toBeUndefined();
1185
+ });
1186
+
1141
1187
  test("marks processing false even when the agent loop throws", async () => {
1142
1188
  const conversation = makeWakeConversation({
1143
1189
  conversationId: "conv-err-guard",
@@ -1114,6 +1114,19 @@ export async function wakeAgentForOpportunity(
1114
1114
  };
1115
1115
  }
1116
1116
 
1117
+ // Wakes bypass `runAgentLoopImpl`, which is what stamps the live turn's
1118
+ // call site and override profile onto the conversation for the tool
1119
+ // executor to read. Without stamping them here, `subagent_spawn` (and
1120
+ // usage attribution) see an unstamped context and resolve children under
1121
+ // workspace defaults instead of the profile this wake actually runs
1122
+ // under — so a wake on a conversation pinned to another profile spawns
1123
+ // children under the wrong one. Restored in the `finally` so a queued
1124
+ // user turn or a later background read never inherits the wake's stamps.
1125
+ const priorCallSite = conversation.currentCallSite;
1126
+ const priorTurnOverrideProfile = conversation.currentTurnOverrideProfile;
1127
+ conversation.currentCallSite = callSite;
1128
+ conversation.currentTurnOverrideProfile = overrideProfile;
1129
+
1117
1130
  let updatedHistory: Message[];
1118
1131
  try {
1119
1132
  ({ history: updatedHistory } = await conversation.agentLoop.run({
@@ -1164,6 +1177,12 @@ export async function wakeAgentForOpportunity(
1164
1177
  // `processing` and drain the queue.
1165
1178
  runError = err instanceof Error ? err : new Error(String(err));
1166
1179
  return { invoked: true, producedToolCalls: false };
1180
+ } finally {
1181
+ // Restore the pre-wake values so a queued user turn or background read
1182
+ // never observes the wake's stamps. (`runAgentLoopImpl` re-stamps both
1183
+ // at the start of the next normal turn regardless.)
1184
+ conversation.currentCallSite = priorCallSite;
1185
+ conversation.currentTurnOverrideProfile = priorTurnOverrideProfile;
1167
1186
  }
1168
1187
 
1169
1188
  // The loop swallows provider rejections into a graceful no-output
@@ -119,5 +119,8 @@ describe("streamExportVBundle — descriptor lifecycle", () => {
119
119
  // incidental descriptors (temp output file already cleaned up, jitter).
120
120
  expect(delta).toBeLessThan(8);
121
121
  },
122
+ // Two full exports of a multi-megabyte workspace (hash pass + tar pass each)
123
+ // do real disk I/O; the default 5s budget is tight under loaded CI runners.
124
+ 30_000,
122
125
  );
123
126
  });
@@ -96,25 +96,24 @@ export async function executeSubagentSpawn(
96
96
 
97
97
  // The subagent runs as its own background conversation, so the agent
98
98
  // loop's background-skip rule would zero out any inherited profile.
99
- // Pass the parent's profile explicitly via `SubagentConfig` so
100
- // `SubagentManager.spawn` forwards it back into the subagent's
101
- // `runAgentLoop` call as `options.overrideProfile`.
99
+ // Forward the invoker's profile explicitly via `SubagentConfig` so
100
+ // `SubagentManager.spawn` passes it into the subagent's `runAgentLoop` as
101
+ // `options.overrideProfile`.
102
102
  //
103
- // Resolution order: an explicit spawn-time profile, then the per-turn
104
- // `context.overrideProfile` (populated by `runAgentLoopImpl` from its
105
- // resolved `turnOverrideProfile`, covering per-conversation overrides and
106
- // tool-routed switches), then a row read, and finally the resolved DEFAULT
107
- // profile of the call site that invoked us. That last fallback is what makes
108
- // a subagent match its invoker when the invoking turn ran purely on its
109
- // call-site default — the workspace `activeProfile` for `mainAgent`, or the
110
- // call site's own catalog default (e.g. `cost-optimized`) for a
111
- // heartbeat/background invoker. `resolveDefaultProfileKey` does not reflect a
112
- // static `llm.callSites.<callSite>` profile override (only the
113
- // activeProfile-for-mainAgent path plus the catalog default), a narrow gap
114
- // that only surfaces with no `activeProfile` set and a hand-tuned call-site
115
- // profile.
103
+ // After an explicit spawn-time profile, the authoritative source is
104
+ // `context.attribution` — the profile the invoking turn ACTUALLY resolved
105
+ // to. It already folds in the per-turn override (per-conversation or
106
+ // tool-routed), the workspace `activeProfile`, and any configured
107
+ // `llm.callSites.<callSite>.profile`, and `resolvedMixArm` is the exact arm a
108
+ // mix expanded to under the PARENT's selection seed. Prefer it so the child
109
+ // runs what the parent ran — in particular, leading with `resolvedMixArm`
110
+ // (ahead of the raw override below, which holds only the mix NAME) stops the
111
+ // child from re-expanding the mix under its own seed and drifting to a
112
+ // different arm. The `context.overrideProfile` / row-read /
113
+ // `resolveDefaultProfileKey` chain is the fallback for spawns with no
114
+ // attribution (e.g. tool calls outside an agent-loop turn).
116
115
  //
117
- // The fallback is forwarded NON-forced, so an explicit
116
+ // The inherited profile is forwarded NON-forced, so an explicit
118
117
  // `llm.callSites.subagentSpawn` profile still wins; an explicit
119
118
  // `inference_profile` argument keeps `forceOverrideProfile` and wins
120
119
  // outright. (The row read short-circuits to `undefined` for the background
@@ -122,6 +121,8 @@ export async function executeSubagentSpawn(
122
121
  let inheritedOverrideProfile = requestedOverrideProfile;
123
122
  if (inheritedOverrideProfile === undefined) {
124
123
  const inheritedCandidate =
124
+ context.attribution?.resolvedMixArm ??
125
+ context.attribution?.appliedProfile ??
125
126
  context.overrideProfile ??
126
127
  getConversationOverrideProfile(context.conversationId) ??
127
128
  resolveDefaultProfileKey(