-
Notifications
You must be signed in to change notification settings - Fork 77
refactor(assistant): daemon goes bilingual on conversationKey/conversationId wire fields (LUM-1890 Phase 1) #31922
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
dvargasfuertes
merged 3 commits into
main
from
apollo/lum-1890-phase-1-daemon-bilingual
May 24, 2026
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
154 changes: 154 additions & 0 deletions
154
assistant/src/__tests__/runtime-events-sse-bilingual.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,154 @@ | ||
| /** | ||
| * `GET /v1/events` (`handleSubscribeAssistantEvents`) — bilingual scope | ||
| * resolution. Two query params are accepted, with distinct semantics: | ||
| * | ||
| * - `?conversationId=<internal-id>` — looks up the conversation row | ||
| * directly by its assistant-minted id. 404 if not found. Does NOT | ||
| * materialise a new row. | ||
| * - `?conversationKey=<external-key>` — resolves via the | ||
| * `conversation_keys` table; materialises on first use. Ignored when | ||
| * `conversationId` is also supplied. | ||
| * | ||
| * Companion to `runtime-events-sse.test.ts`, which exercises the broader | ||
| * `?conversationKey=` happy/error path. | ||
| */ | ||
|
|
||
| import { beforeEach, describe, expect, mock, test } from "bun:test"; | ||
|
|
||
| mock.module("../util/logger.js", () => ({ | ||
| getLogger: () => | ||
| new Proxy({} as Record<string, unknown>, { | ||
| get: () => () => {}, | ||
| }), | ||
| })); | ||
|
|
||
| mock.module("../config/loader.js", () => ({ | ||
| getConfig: () => ({ | ||
| ui: {}, | ||
| model: "test", | ||
| provider: "test", | ||
| memory: { enabled: false }, | ||
| rateLimit: { maxRequestsPerMinute: 0 }, | ||
| secretDetection: { enabled: false }, | ||
| }), | ||
| })); | ||
|
|
||
| import { getOrCreateConversation } from "../memory/conversation-key-store.js"; | ||
| import { getDb } from "../memory/db-connection.js"; | ||
| import { initializeDb } from "../memory/db-init.js"; | ||
| import { buildAssistantEvent } from "../runtime/assistant-event.js"; | ||
| import { AssistantEventHub } from "../runtime/assistant-event-hub.js"; | ||
| import { | ||
| BadRequestError, | ||
| NotFoundError, | ||
| } from "../runtime/routes/errors.js"; | ||
| import { handleSubscribeAssistantEvents } from "../runtime/routes/events-routes.js"; | ||
|
|
||
| initializeDb(); | ||
|
|
||
| describe("GET /v1/events — bilingual scope query params", () => { | ||
| beforeEach(() => { | ||
| const db = getDb(); | ||
| db.run("DELETE FROM conversation_keys"); | ||
| db.run("DELETE FROM conversations"); | ||
| }); | ||
|
|
||
| test("?conversationId=<existing-id> scopes the stream to that conversation", async () => { | ||
| // Materialise a conversation via the key path, then subscribe to it | ||
| // directly by its internal id. | ||
| const { conversationId } = getOrCreateConversation("sse-id-scope-source"); | ||
|
|
||
| const ac = new AbortController(); | ||
| const testHub = new AssistantEventHub(); | ||
|
|
||
| const stream = handleSubscribeAssistantEvents( | ||
| { | ||
| queryParams: { conversationId }, | ||
| abortSignal: ac.signal, | ||
| }, | ||
| { hub: testHub }, | ||
| ); | ||
|
|
||
| const reader = stream.getReader(); | ||
| // Consume the initial heartbeat. | ||
| const heartbeat = await reader.read(); | ||
| expect(new TextDecoder().decode(heartbeat.value)).toBe(": heartbeat\n\n"); | ||
|
|
||
| // Publish an event scoped to that conversation — should be delivered. | ||
| await testHub.publish(buildAssistantEvent({ type: "pong" }, conversationId)); | ||
|
|
||
| const { value, done } = await reader.read(); | ||
| ac.abort(); | ||
|
|
||
| expect(done).toBe(false); | ||
| const frame = new TextDecoder().decode(value); | ||
| expect(frame).toContain("event: assistant_event"); | ||
| expect(frame).toContain(`"conversationId":"${conversationId}"`); | ||
| }); | ||
|
|
||
| test("?conversationId=<non-existent-id> throws NotFoundError", () => { | ||
| expect(() => | ||
| handleSubscribeAssistantEvents({ | ||
| queryParams: { conversationId: "does-not-exist" }, | ||
| abortSignal: new AbortController().signal, | ||
| }), | ||
| ).toThrow(NotFoundError); | ||
| }); | ||
|
|
||
| test("?conversationId is honored and ?conversationKey is ignored when both are present", async () => { | ||
| // Materialise two distinct conversations: one we'll subscribe to by id, | ||
| // one we'll publish to via the ignored key. | ||
| const { conversationId: idConv } = getOrCreateConversation("sse-id-wins"); | ||
| const { conversationId: keyConv } = getOrCreateConversation( | ||
| "sse-key-ignored", | ||
| ); | ||
| expect(idConv).not.toBe(keyConv); | ||
|
|
||
| const ac = new AbortController(); | ||
| const testHub = new AssistantEventHub(); | ||
|
|
||
| const stream = handleSubscribeAssistantEvents( | ||
| { | ||
| queryParams: { | ||
| conversationId: idConv, | ||
| conversationKey: "sse-key-ignored", | ||
| }, | ||
| abortSignal: ac.signal, | ||
| }, | ||
| { hub: testHub }, | ||
| ); | ||
| const reader = stream.getReader(); | ||
| await reader.read(); // heartbeat | ||
|
|
||
| // Publish on the "key" conversation — should NOT be delivered (filter | ||
| // is locked to idConv because conversationId wins). | ||
| await testHub.publish(buildAssistantEvent({ type: "pong" }, keyConv)); | ||
| // Publish on the "id" conversation — should be delivered. | ||
| await testHub.publish(buildAssistantEvent({ type: "pong" }, idConv)); | ||
|
|
||
| const { value } = await reader.read(); | ||
| ac.abort(); | ||
| const frame = new TextDecoder().decode(value); | ||
|
|
||
| expect(frame).toContain(`"conversationId":"${idConv}"`); | ||
| expect(frame).not.toContain(`"conversationId":"${keyConv}"`); | ||
| }); | ||
|
|
||
| test("empty conversationId is rejected with BadRequestError", () => { | ||
| expect(() => | ||
| handleSubscribeAssistantEvents({ | ||
| queryParams: { conversationId: "" }, | ||
| abortSignal: new AbortController().signal, | ||
| }), | ||
| ).toThrow(BadRequestError); | ||
| }); | ||
|
|
||
| test("empty conversationKey is still rejected (legacy parity)", () => { | ||
| expect(() => | ||
| handleSubscribeAssistantEvents({ | ||
| queryParams: { conversationKey: "" }, | ||
| abortSignal: new AbortController().signal, | ||
| }), | ||
| ).toThrow(BadRequestError); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -106,6 +106,13 @@ function handleCreateConversation({ body = {}, headers }: RouteHandlerArgs) { | |
| }, | ||
| "Created conversation via POST", | ||
| ); | ||
| // `id` is the assistant-minted internal `conversations.id` — the | ||
| // authoritative identifier for this conversation. `conversationKey` | ||
| // echoes the optional external key supplied by the client (or the | ||
| // UUID we minted) and is the identifier non-vellum channel adapters | ||
| // (Telegram, WhatsApp, etc.) use to scope to a logical channel | ||
| // thread. Vellum-web clients can ignore `conversationKey` and use | ||
| // `id` directly. | ||
| return { | ||
| id: result.conversationId, | ||
| conversationKey, | ||
|
|
@@ -428,15 +435,26 @@ export const ROUTES: RouteDefinition[] = [ | |
| requestBody: z.object({ | ||
| conversationKey: z | ||
| .string() | ||
| .describe("Idempotency key for the conversation"), | ||
| .optional() | ||
| .describe( | ||
| "Optional external key. Echoed back in the response. Non-vellum channels (Telegram, WhatsApp) use this to scope to a logical channel thread; vellum-web clients can omit it and rely on the assistant-minted `id`.", | ||
| ), | ||
| conversationType: z | ||
| .literal("standard") | ||
| .optional() | ||
| .describe("Only standard conversations are created by this endpoint"), | ||
| }), | ||
| responseBody: z.object({ | ||
| id: z.string(), | ||
| conversationKey: z.string(), | ||
| id: z | ||
| .string() | ||
| .describe( | ||
| "Assistant-minted internal conversation id. The authoritative identifier for the conversation.", | ||
| ), | ||
| conversationKey: z | ||
| .string() | ||
| .describe( | ||
| "Echo of the optional external key supplied by the client (or the value the daemon minted when omitted).", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove the parenthesis
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Queued for the next assistant-touching PR — tracked at |
||
| ), | ||
| conversationType: z.string(), | ||
| created: z.boolean(), | ||
| }), | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Delete this comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Queued for the next assistant-touching PR — tracked at
notes/pending-followups.mdwith the exact patch ready to apply.