@vellumai/assistant 0.11.2-dev.202608071719.8f7a9f1 → 0.11.2-dev.202608071820.0d9e564

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.11.2-dev.202608071719.8f7a9f1",
3
+ "version": "0.11.2-dev.202608071820.0d9e564",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "exports": {
@@ -648,6 +648,82 @@ describe("Conversation message queue", () => {
648
648
  await new Promise((r) => setTimeout(r, 10));
649
649
  });
650
650
 
651
+ test("a processMessage turn keeps its turn-start trust when the slot moves before the loop opens", async () => {
652
+ // processMessage is the third turn entry point, and the one a web turn
653
+ // takes on an idle conversation (the route only enqueues while
654
+ // isProcessing). It captures trust at turn start, then awaits several
655
+ // times before the agent loop opens. The conversation slot is writable
656
+ // throughout that window by paths that do not own this turn: live-voice
657
+ // hydration stamp-and-restore, pointer elevation, the voice bridge.
658
+ //
659
+ // Driving a real Conversation with only AgentLoop.run mocked is what makes
660
+ // this observable. A double that stubs runAgentLoop itself would skip the
661
+ // re-read entirely and pass either way.
662
+ const conversation = makeConversation();
663
+ await conversation.loadFromDb();
664
+
665
+ conversation.setTrustContext({
666
+ trustClass: "trusted_contact",
667
+ sourceChannel: "slack",
668
+ requesterExternalUserId: "U-contact",
669
+ });
670
+
671
+ // Land another actor's slot write inside the window, after the turn-start
672
+ // capture and before the loop opens. persistUserMessage is awaited there.
673
+ const originalPersist = conversation.persistUserMessage.bind(conversation);
674
+ let slotMoved = false;
675
+ (
676
+ conversation as unknown as {
677
+ persistUserMessage: typeof conversation.persistUserMessage;
678
+ }
679
+ ).persistUserMessage = async (opts) => {
680
+ const result = await originalPersist(opts);
681
+ conversation.setTrustContext({
682
+ trustClass: "guardian",
683
+ sourceChannel: "vellum",
684
+ requesterExternalUserId: "guardian-principal",
685
+ });
686
+ // Also move the per-turn field, which is writable out-of-band: a wake
687
+ // that settles inside this window restores its prior value there
688
+ // (agent-wake stamps at :1470 and restores in a `finally` at :1554).
689
+ // Covers both writers, so a fix that reads either one back at the agent
690
+ // loop call still fails this test.
691
+ conversation.currentTurnTrustContext = {
692
+ trustClass: "guardian",
693
+ sourceChannel: "vellum",
694
+ requesterExternalUserId: "guardian-principal",
695
+ };
696
+ slotMoved = true;
697
+ return result;
698
+ };
699
+
700
+ const p1 = conversation.processMessage({
701
+ content: "msg-1",
702
+ attachments: [],
703
+ onEvent: () => {},
704
+ requestId: "req-1",
705
+ });
706
+ await waitForPendingRun(1);
707
+
708
+ // Guard the test itself: if the injection stopped running, the assertions
709
+ // below would pass for the wrong reason.
710
+ expect(slotMoved).toBe(true);
711
+ expect(conversation.trustContext?.trustClass).toBe("guardian");
712
+
713
+ // Read mid-run: this is what tool setup and the guardian-request producers
714
+ // resolve against while the turn executes.
715
+ expect(conversation.currentTurnTrustContext?.trustClass).toBe(
716
+ "trusted_contact",
717
+ );
718
+ expect(conversation.currentTurnTrustContext?.requesterExternalUserId).toBe(
719
+ "U-contact",
720
+ );
721
+
722
+ await resolveRun(0);
723
+ await p1;
724
+ await new Promise((r) => setTimeout(r, 10));
725
+ });
726
+
651
727
  test("[experimental] queued passthrough siblings drain as a single batched run", async () => {
652
728
  const conversation = makeConversation();
653
729
  await conversation.loadFromDb();
@@ -164,7 +164,11 @@ function makeConversationWithPendingConfirmation(
164
164
  promoteToHead: (requestId: string) => ({ requestId }),
165
165
  },
166
166
  pendingSteerRepair: false,
167
- setTrustContext: () => {},
167
+ // Stores rather than discarding, so a test can observe which trust the
168
+ // route resolved and move the slot afterwards.
169
+ setTrustContext(this: { trustContext: unknown }, ctx: unknown) {
170
+ this.trustContext = ctx;
171
+ },
168
172
  updateClient: () => {},
169
173
  emitConfirmationStateChanged: () => {},
170
174
  emitActivityState: () => {},
@@ -354,3 +358,62 @@ describe("hidden sends to an idle conversation with a pending confirmation", ()
354
358
  expect(spies.agentLoopOptions()?.isHiddenPrompt).toBeUndefined();
355
359
  });
356
360
  });
361
+
362
+ describe("POST /messages turn trust", () => {
363
+ test("the idle send path runs its turn under the trust resolved for the request", async () => {
364
+ // The idle web path does not go through `processMessage`; it persists and
365
+ // calls `runAgentLoop` directly. Without the captured trust travelling
366
+ // with that call, the loop re-reads the conversation slot when it opens,
367
+ // and the slot is writable in between by paths that do not own this turn
368
+ // (channel ingress for another actor, live-voice hydration, pointer
369
+ // elevation, the voice bridge).
370
+ //
371
+ // The defect here is at the call site, not inside the loop, so observing
372
+ // the options the route passes is sufficient. The re-read *inside* the
373
+ // loop is covered separately against a real Conversation, since a stub
374
+ // like this one cannot see it.
375
+ const spies = makeConversationWithPendingConfirmation(false);
376
+ setConversation(CONV_ID, spies.conversation);
377
+
378
+ const conversation = spies.conversation as unknown as {
379
+ trustContext: unknown;
380
+ persistUserMessage: () => Promise<{ id: string; deduplicated: boolean }>;
381
+ };
382
+
383
+ // Another actor writes the slot inside the window, after the route
384
+ // resolves this request's trust and before the loop call.
385
+ let slotMoved = false;
386
+ conversation.persistUserMessage = async () => {
387
+ conversation.trustContext = {
388
+ trustClass: "trusted_contact",
389
+ sourceChannel: "slack",
390
+ requesterExternalUserId: "U-other-actor",
391
+ };
392
+ slotMoved = true;
393
+ return { id: "persisted-user-id", deduplicated: false };
394
+ };
395
+
396
+ const res = await callHandler(
397
+ (args) => handleSendMessage(args, makeDeps(spies.conversation)),
398
+ makeRequest({ content: "run a command" }),
399
+ undefined,
400
+ 202,
401
+ );
402
+
403
+ expect(res.status).toBe(202);
404
+ // Guard the test itself: if the injection stopped running the assertion
405
+ // below would pass for the wrong reason.
406
+ expect(slotMoved).toBe(true);
407
+ expect(
408
+ (conversation.trustContext as { trustClass?: string } | undefined)
409
+ ?.trustClass,
410
+ ).toBe("trusted_contact");
411
+
412
+ // The turn carries the trust this request resolved, not the moved slot.
413
+ const turnTrust = spies.agentLoopOptions()?.turnTrustContext as
414
+ | { trustClass?: string }
415
+ | undefined;
416
+ expect(turnTrust).toBeDefined();
417
+ expect(turnTrust?.trustClass).toBe("guardian");
418
+ });
419
+ });
@@ -384,10 +384,19 @@ export async function runAgentLoopImpl(
384
384
  // without going through processMessage/drainQueue. This ensures the system
385
385
  // prompt callback always reads a valid snapshot rather than undefined.
386
386
  //
387
- // A queue drain runs a message whose sender may not be the conversation's
388
- // most recent one, so it passes that sender's trust explicitly. Falling back
389
- // to the slot here would undo the drain's stamp and hand the turn back to
390
- // whoever sent last.
387
+ // The invariant: a turn runs under the trust captured when that turn
388
+ // started, never under whatever the slot holds when the loop happens to
389
+ // open. Awaits sit between capture and this line, and the slot is writable
390
+ // throughout by paths that do not own the turn (channel ingress for another
391
+ // actor, live-voice hydration, pointer elevation, the voice bridge).
392
+ //
393
+ // Callers that own a turn are expected to capture at turn start and pass
394
+ // `turnTrustContext`. This has not been swept across all 13 call sites, so
395
+ // the fallback below is load-bearing for two different populations: callers
396
+ // that legitimately have no turn to capture (subagent manager, voice
397
+ // bridge, regenerate), and callers that should pass it and do not yet.
398
+ // Treat a caller reaching the fallback as unverified, not as correct.
399
+ // LUM-3148 removes the ambiguity by making trust ride the turn.
391
400
  ctx.currentTurnTrustContext = options?.turnTrustContext ?? ctx.trustContext;
392
401
  ctx.currentTurnChannelCapabilities = ctx.channelCapabilities;
393
402
 
@@ -1876,7 +1876,14 @@ export async function processMessage(
1876
1876
  await conversation.ensureActorScopedHistory();
1877
1877
  // Snapshot persona context at turn start so later tool turns can't pick up
1878
1878
  // a different actor's context if a concurrent request mutates the live fields.
1879
- conversation.currentTurnTrustContext = conversation.trustContext;
1879
+ //
1880
+ // Held in a local as well as on the conversation: the field is writable
1881
+ // out-of-band while this turn is in flight (`agent-wake` stamps it and
1882
+ // restores the prior value in a `finally`), so reading it back at the agent
1883
+ // loop call below would reintroduce the late read this capture exists to
1884
+ // avoid. The local is what the loop runs under.
1885
+ const turnTrustContext = conversation.trustContext;
1886
+ conversation.currentTurnTrustContext = turnTrustContext;
1880
1887
  conversation.currentTurnAuthContext = conversation.authContext;
1881
1888
  conversation.currentTurnSourceActorPrincipalId =
1882
1889
  sourceActorPrincipalId ?? conversation.authContext?.actorPrincipalId;
@@ -2345,7 +2352,16 @@ export async function processMessage(
2345
2352
  titleText?: string;
2346
2353
  callSite?: LLMCallSite;
2347
2354
  overrideProfile?: string;
2348
- } = { isUserMessage: true };
2355
+ turnTrustContext?: TrustContext;
2356
+ } = {
2357
+ isUserMessage: true,
2358
+ // Carry the trust captured at turn start into the run. Several awaits sit
2359
+ // between that capture and the loop opening, and both the conversation
2360
+ // slot and the per-turn field are writable throughout that window, so
2361
+ // reading either here would run this turn as whoever wrote last. The
2362
+ // local captured at turn start is the only value no other writer can move.
2363
+ turnTrustContext,
2364
+ };
2349
2365
  if (isInteractive !== undefined) {
2350
2366
  loopOptions.isInteractive = isInteractive;
2351
2367
  }
@@ -1915,6 +1915,15 @@ export async function handleSendMessage(
1915
1915
  conversation.setTrustContext({ trustClass: "guardian", sourceChannel });
1916
1916
  }
1917
1917
 
1918
+ // The trust this request's turn runs under, captured here rather than read
1919
+ // back at the agent loop below. Every branch above has just written it and
1920
+ // nothing awaits in between, so this is the resolved sender. Between here
1921
+ // and the loop the conversation slot is writable by paths that do not own
1922
+ // this turn (channel ingress for another actor, live-voice hydration,
1923
+ // pointer elevation, the voice bridge), and the loop would otherwise
1924
+ // re-read it and run this turn as whoever wrote last.
1925
+ const turnTrustContext = conversation.trustContext;
1926
+
1918
1927
  const isInteractive = isInteractiveInterface(sourceInterface);
1919
1928
  // Translate the dev-bypass actor principal to the real guardian principal
1920
1929
  // before the same-actor host-proxy gate so web/iOS turns match the macOS
@@ -2691,6 +2700,7 @@ export async function handleSendMessage(
2691
2700
  onEvent: broadcastMessage,
2692
2701
  isInteractive,
2693
2702
  isUserMessage: true,
2703
+ turnTrustContext,
2694
2704
  ...(body.hidden === true ? { isHiddenPrompt: true } : {}),
2695
2705
  })
2696
2706
  .catch((err) => {