-
Notifications
You must be signed in to change notification settings - Fork 0
fix codex chat #80
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
Merged
fix codex chat #80
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
fef1606
Implement chat text batching across service and renderer
arul28 a930eba
Fix CI checks and address review feedback for chat text batching
arul28 ac91850
Fix transcript rendering tests and address new review feedback
arul28 7f22cdb
Add aria-expanded to InlineDisclosureRow for screen reader support
arul28 4b47ebc
Fix empty-state masking, text back-merge safety, and turn model fallback
arul28 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
Some comments aren't visible on the classic Files Changed page.
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
145 changes: 145 additions & 0 deletions
145
apps/desktop/src/main/services/chat/chatTextBatching.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,145 @@ | ||
| import { describe, expect, it } from "vitest"; | ||
| import { | ||
| appendBufferedAssistantText, | ||
| canAppendBufferedAssistantText, | ||
| shouldFlushBufferedAssistantTextForEvent, | ||
| } from "./chatTextBatching"; | ||
|
|
||
| describe("chatTextBatching", () => { | ||
| it("appends adjacent text deltas for the same turn and item", () => { | ||
| const buffered = appendBufferedAssistantText(null, { | ||
| type: "text", | ||
| text: "Hello", | ||
| turnId: "turn-1", | ||
| itemId: "item-1", | ||
| }); | ||
|
|
||
| expect(canAppendBufferedAssistantText(buffered, { | ||
| type: "text", | ||
| text: " world", | ||
| turnId: "turn-1", | ||
| itemId: "item-1", | ||
| })).toBe(true); | ||
|
|
||
| expect(appendBufferedAssistantText(buffered, { | ||
| type: "text", | ||
| text: " world", | ||
| turnId: "turn-1", | ||
| itemId: "item-1", | ||
| })).toMatchObject({ | ||
| text: "Hello world", | ||
| turnId: "turn-1", | ||
| itemId: "item-1", | ||
| }); | ||
| }); | ||
|
|
||
| it("stops batching when the text identity changes", () => { | ||
| const buffered = appendBufferedAssistantText(null, { | ||
| type: "text", | ||
| text: "Hello", | ||
| turnId: "turn-1", | ||
| itemId: "item-1", | ||
| }); | ||
|
|
||
| expect(canAppendBufferedAssistantText(buffered, { | ||
| type: "text", | ||
| text: "Other", | ||
| turnId: "turn-2", | ||
| itemId: "item-1", | ||
| })).toBe(false); | ||
|
|
||
| expect(canAppendBufferedAssistantText(buffered, { | ||
| type: "text", | ||
| text: "Other", | ||
| turnId: "turn-1", | ||
| itemId: "item-2", | ||
| })).toBe(false); | ||
| }); | ||
|
|
||
| it("flushes buffered text on structural chat events", () => { | ||
| expect(shouldFlushBufferedAssistantTextForEvent({ | ||
| type: "tool_call", | ||
| tool: "functions.exec_command", | ||
| args: { cmd: "pwd" }, | ||
| itemId: "tool-1", | ||
| turnId: "turn-1", | ||
| })).toBe(true); | ||
|
|
||
| expect(shouldFlushBufferedAssistantTextForEvent({ | ||
| type: "command", | ||
| command: "pwd", | ||
| cwd: "/tmp", | ||
| output: "", | ||
| itemId: "cmd-1", | ||
| turnId: "turn-1", | ||
| status: "running", | ||
| })).toBe(true); | ||
|
|
||
| expect(shouldFlushBufferedAssistantTextForEvent({ | ||
| type: "approval_request", | ||
| itemId: "approval-1", | ||
| kind: "command", | ||
| description: "Run shell command", | ||
| turnId: "turn-1", | ||
| })).toBe(true); | ||
|
|
||
| expect(shouldFlushBufferedAssistantTextForEvent({ | ||
| type: "done", | ||
| turnId: "turn-1", | ||
| status: "completed", | ||
| })).toBe(true); | ||
| }); | ||
|
|
||
| it("does not collapse anonymous text chunks that lack identity", () => { | ||
| const buffered = appendBufferedAssistantText(null, { | ||
| type: "text", | ||
| text: "Hello", | ||
| }); | ||
|
|
||
| expect(canAppendBufferedAssistantText(buffered, { | ||
| type: "text", | ||
| text: " world", | ||
| })).toBe(false); | ||
| }); | ||
|
|
||
| it("flushes buffered text on discrete UI card events", () => { | ||
| expect(shouldFlushBufferedAssistantTextForEvent({ | ||
| type: "todo_update", | ||
| todos: [], | ||
| turnId: "turn-1", | ||
| } as any)).toBe(true); | ||
|
|
||
| expect(shouldFlushBufferedAssistantTextForEvent({ | ||
| type: "subagent_started", | ||
| taskId: "task-1", | ||
| turnId: "turn-1", | ||
| } as any)).toBe(true); | ||
|
|
||
| expect(shouldFlushBufferedAssistantTextForEvent({ | ||
| type: "web_search", | ||
| query: "test", | ||
| turnId: "turn-1", | ||
| } as any)).toBe(true); | ||
| }); | ||
|
|
||
| it("keeps buffered text live across lightweight progress events", () => { | ||
| expect(shouldFlushBufferedAssistantTextForEvent({ | ||
| type: "activity", | ||
| activity: "thinking", | ||
| detail: "Reasoning", | ||
| turnId: "turn-1", | ||
| })).toBe(false); | ||
|
|
||
| expect(shouldFlushBufferedAssistantTextForEvent({ | ||
| type: "reasoning", | ||
| text: "Thinking through it", | ||
| turnId: "turn-1", | ||
| })).toBe(false); | ||
|
|
||
| expect(shouldFlushBufferedAssistantTextForEvent({ | ||
| type: "plan_text", | ||
| text: "- step one", | ||
| turnId: "turn-1", | ||
| })).toBe(false); | ||
| }); | ||
| }); |
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,48 @@ | ||
| import type { AgentChatEvent } from "../../../shared/types"; | ||
|
|
||
| export type BufferedAssistantText = { | ||
| text: string; | ||
| turnId?: string; | ||
| itemId?: string; | ||
| }; | ||
|
|
||
| export function canAppendBufferedAssistantText( | ||
| buffered: BufferedAssistantText | null, | ||
| event: Extract<AgentChatEvent, { type: "text" }>, | ||
| ): boolean { | ||
| if (!buffered) return false; | ||
| // Don't collapse anonymous chunks that lack any identity | ||
| if (!buffered.turnId && !buffered.itemId && !event.turnId && !event.itemId) return false; | ||
| return (buffered.turnId ?? null) === (event.turnId ?? null) | ||
| && (buffered.itemId ?? null) === (event.itemId ?? null); | ||
| } | ||
|
|
||
| export function appendBufferedAssistantText( | ||
| buffered: BufferedAssistantText | null, | ||
| event: Extract<AgentChatEvent, { type: "text" }>, | ||
| ): BufferedAssistantText { | ||
| if (canAppendBufferedAssistantText(buffered, event)) { | ||
| return { | ||
| ...buffered!, | ||
| text: `${buffered!.text}${event.text}`, | ||
| }; | ||
| } | ||
|
|
||
| return { | ||
| text: event.text, | ||
| ...(event.turnId ? { turnId: event.turnId } : {}), | ||
| ...(event.itemId ? { itemId: event.itemId } : {}), | ||
| }; | ||
| } | ||
|
|
||
| export function shouldFlushBufferedAssistantTextForEvent(event: AgentChatEvent): boolean { | ||
| switch (event.type) { | ||
| case "text": | ||
| case "reasoning": | ||
| case "activity": | ||
| case "plan_text": | ||
| return false; | ||
| default: | ||
| return true; | ||
| } | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.