-
Notifications
You must be signed in to change notification settings - Fork 3k
fix(daemon): Avoid replaying truncated session diffs #5108
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 |
|---|---|---|
|
|
@@ -171,7 +171,10 @@ export class ToolCallEmitter extends BaseEmitter { | |
| }; | ||
|
|
||
| // Add rawOutput from resultDisplay | ||
| if (params.resultDisplay !== undefined) { | ||
| if ( | ||
| params.resultDisplay !== undefined && | ||
| !this.isTruncatedSessionDiffDisplay(params.resultDisplay) | ||
| ) { | ||
| (update as Record<string, unknown>)['rawOutput'] = params.resultDisplay; | ||
| } | ||
|
|
||
|
|
@@ -353,7 +356,7 @@ export class ToolCallEmitter extends BaseEmitter { | |
|
|
||
| // Check if this is a diff display (edit tool result) | ||
| if ('fileName' in obj && 'newContent' in obj) { | ||
| if (obj['truncatedForSession'] === true) { | ||
| if (this.isTruncatedSessionDiffDisplay(resultDisplay)) { | ||
| return { | ||
| type: 'content', | ||
| content: { | ||
|
|
@@ -374,6 +377,17 @@ export class ToolCallEmitter extends BaseEmitter { | |
| return null; | ||
| } | ||
|
|
||
| private isTruncatedSessionDiffDisplay(resultDisplay: unknown): boolean { | ||
|
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] The same three-condition check ( If the Consider extracting a shared predicate into — qwen3.7-max via Qwen Code /review |
||
| if (!resultDisplay || typeof resultDisplay !== 'object') return false; | ||
|
|
||
| const obj = resultDisplay as Record<string, unknown>; | ||
| return ( | ||
| obj['truncatedForSession'] === true && | ||
| 'fileName' in obj && | ||
| 'newContent' in obj | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Transforms Part[] to ToolCallContent[]. | ||
| * Extracts text from functionResponse parts and text parts. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,6 +15,7 @@ import type { | |
| import type { | ||
| DaemonMessage, | ||
| DaemonMessageToolCall, | ||
| DaemonMessageToolCallContent, | ||
| DaemonMessageToolCallStatus, | ||
| DaemonMessageToolKind, | ||
| DaemonMessageTodoItem, | ||
|
|
@@ -645,6 +646,7 @@ function daemonToolBlockToToolCall( | |
| ): DaemonMessageToolCall { | ||
| const rawOutput = getToolRawOutput(block); | ||
| const isBackgroundAgent = isBackgroundAgentBlock(block, rawOutput); | ||
| const content = normalizeToolContent(block.content); | ||
| const statusMap: Record<string, DaemonMessageToolCallStatus> = { | ||
| running: 'in_progress', | ||
| pending: 'pending', | ||
|
|
@@ -676,6 +678,7 @@ function daemonToolBlockToToolCall( | |
| parentToolCallId: block.parentToolCallId, | ||
| startTime: block.createdAt, | ||
| endTime: isComplete && !isBackgroundAgent ? block.updatedAt : undefined, | ||
| ...(content ? { content } : {}), | ||
| }; | ||
| } | ||
|
|
||
|
|
@@ -813,6 +816,59 @@ function getToolRawOutput(block: DaemonToolTranscriptBlock): unknown { | |
| }; | ||
| } | ||
|
|
||
| function normalizeToolContent( | ||
| value: unknown, | ||
| ): DaemonMessageToolCallContent[] | undefined { | ||
| if (!Array.isArray(value)) return undefined; | ||
|
|
||
| const content = value.flatMap((entry): DaemonMessageToolCallContent[] => { | ||
| const item = getRecord(entry); | ||
| if (!item) return []; | ||
|
|
||
| const type = item['type']; | ||
| if (type === 'content') { | ||
| const body = getRecord(item['content']); | ||
| if (!body || typeof body['type'] !== 'string') return []; | ||
| return [ | ||
| { | ||
| type: 'content', | ||
| content: { ...body, type: body['type'] }, | ||
| }, | ||
| ]; | ||
| } | ||
|
|
||
| if (type === 'diff') { | ||
| const newText = item['newText']; | ||
| if (typeof newText !== 'string') return []; | ||
|
|
||
| const path = item['path']; | ||
| const oldText = item['oldText']; | ||
| return [ | ||
| { | ||
| type: 'diff', | ||
| ...(typeof path === 'string' ? { path } : {}), | ||
| ...(typeof oldText === 'string' ? { oldText } : {}), | ||
| newText, | ||
| }, | ||
| ]; | ||
| } | ||
|
|
||
| if (type === 'terminal') { | ||
| const terminalId = item['terminalId']; | ||
| return [ | ||
| { | ||
| type: 'terminal', | ||
| ...(typeof terminalId === 'string' ? { terminalId } : {}), | ||
| }, | ||
| ]; | ||
| } | ||
|
|
||
| return []; | ||
| }); | ||
|
|
||
| return content.length > 0 ? content : undefined; | ||
|
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] Since Consider adding a if (typeof type === 'string') {
console.warn(`normalizeToolContent: unknown content type '${type}' dropped`);
}
return [];— qwen3.7-max via Qwen Code /review |
||
| } | ||
|
|
||
| function isAskUserQuestionBlock(block: DaemonToolTranscriptBlock): boolean { | ||
| if (!block.toolName) return false; | ||
| const normalized = block.toolName.toLowerCase(); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.