-
Notifications
You must be signed in to change notification settings - Fork 3k
fix(daemon): preserve user message source metadata #6385
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -53,6 +53,21 @@ describe('MessageEmitter', () => { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| content: { type: 'text', text: multilineText }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| it('should include source metadata when provided', async () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Collaborator
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. [Suggestion] This test covers A future caller passing
Suggested change
— qwen3.7-max via Qwen Code /review |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await emitter.emitUserMessage('scheduled prompt', 1_700_000_000_000, { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| source: 'cron', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| expect(sendUpdateSpy).toHaveBeenCalledWith({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| sessionUpdate: 'user_message_chunk', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| content: { type: 'text', text: 'scheduled prompt' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| _meta: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| timestamp: 1_700_000_000_000, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| source: 'cron', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| describe('emitAgentMessage', () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -531,6 +531,7 @@ function normalizeSessionUpdate( | |
| ) { | ||
| return []; | ||
| } | ||
| const meta = extractUpdateMeta(update); | ||
|
Collaborator
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. [Suggestion] No live bug today (cron/loop prompts are text-only), but future image-bearing scheduled messages would lose provenance without warning. Consider propagating — qwen3.7-max via Qwen Code /review |
||
| const content = update['content']; | ||
| const part = extractContentPart(content); | ||
| if (part) { | ||
|
|
@@ -555,13 +556,29 @@ function normalizeSessionUpdate( | |
| } | ||
| if (part.kind === 'text') { | ||
| return part.text | ||
| ? [{ ...base, type: 'user.text.delta', text: part.text }] | ||
| ? [ | ||
| { | ||
| ...base, | ||
| type: 'user.text.delta', | ||
| text: part.text, | ||
| ...(meta ? { meta } : {}), | ||
| }, | ||
| ] | ||
| : []; | ||
| } | ||
| return []; | ||
| } | ||
| const text = getTextContent(content); | ||
| return text ? [{ ...base, type: 'user.text.delta', text }] : []; | ||
| return text | ||
| ? [ | ||
| { | ||
| ...base, | ||
| type: 'user.text.delta', | ||
| text, | ||
| ...(meta ? { meta } : {}), | ||
| }, | ||
| ] | ||
| : []; | ||
| } | ||
| case 'agent_message_chunk': { | ||
| const text = getTextContent(update['content']); | ||
|
|
||
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.
[Suggestion] Two concerns on this line:
1. Hardcoded
'cron'loses'loop'on replay. The live path (Session.ts:2812) sendssource: 'loop'for loop prompts (wherecronExpr === '@wakeup'), but both cron and loop prompts are recorded withsubtype: 'cron'bychatRecordingService.ts. On replay, loop-originated messages will incorrectly carrysource: 'cron'instead ofsource: 'loop'. No current UI consumer distinguishes the two, but this contradicts the PR's goal of preserving source metadata end-to-end.Consider persisting the original
sourcevalue on the chat record (e.g., insystemPayload) and reading it back during replay:2. No test coverage. The conditional that tags cron-subtype user messages with
sourcemetadata during replay is not tested inHistoryReplayer.test.ts. The downstream layers are individually tested, but this integration point is not — a future refactor that drops or inverts the ternary would go undetected. Consider adding test cases for (a) cron-subtype records emitting_meta.source: 'cron'and (b) notification-subtype records emitting nosource.— qwen3.7-max via Qwen Code /review