-
Notifications
You must be signed in to change notification settings - Fork 120
🤖 feat: continue interrupted stream by clicking the interrupted splitter #3634
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
+554
−9
Merged
Changes from 2 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
d7e6eaa
feat: continue interrupted stream by clicking the interrupted splitter
ethanndickson d89eba2
fix: address Codex review on interrupted-splitter resume
ethanndickson 9364f85
fix: surface interrupted-resume failures on the divider
ethanndickson c4d3d05
fix: don't make interrupted divider resumable in transcript-only chats
ethanndickson 928bc36
feat: add keyboard shortcut to continue interrupted streams
ethanndickson 9299d1d
fix: scope resume state per-workspace + list resume shortcut
ethanndickson 1fcb5b4
fix: restrict divider resume to suppressed-Retry turns + scope error …
ethanndickson 2c9e9fd
refactor: slim interrupted-divider resume to a one-shot hook
ethanndickson 483bd8f
fix: make pre-token interrupted turns resumable
ethanndickson e53d546
fix: use Shift+R for resume keybind instead of Ctrl/Cmd+Shift+Enter
ethanndickson 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
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
123 changes: 123 additions & 0 deletions
123
src/browser/features/Messages/ChatBarrier/InterruptedBarrier.test.tsx
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,123 @@ | ||
| import { afterEach, beforeEach, describe, expect, mock, test } from "bun:test"; | ||
| import { cleanup, fireEvent, render, waitFor } from "@testing-library/react"; | ||
| import { GlobalWindow } from "happy-dom"; | ||
|
|
||
| import type * as WorkspaceStoreModule from "@/browser/stores/WorkspaceStore"; | ||
|
|
||
| interface MockWorkspaceState { | ||
| autoRetryStatus: null; | ||
| isStreamStarting: boolean; | ||
| canInterrupt: boolean; | ||
| messages: Array<Record<string, unknown>>; | ||
| } | ||
|
|
||
| function createWorkspaceState(overrides: Partial<MockWorkspaceState> = {}): MockWorkspaceState { | ||
| return { | ||
| autoRetryStatus: null, | ||
| isStreamStarting: false, | ||
| canInterrupt: false, | ||
| messages: [ | ||
| { | ||
| type: "user", | ||
| id: "user-1", | ||
| historyId: "user-1", | ||
| content: "Hello", | ||
| historySequence: 1, | ||
| }, | ||
| ], | ||
| ...overrides, | ||
| }; | ||
| } | ||
|
|
||
| let currentWorkspaceState = createWorkspaceState(); | ||
|
|
||
| let resumeStreamResult: { success: true; data: { started: boolean } } = { | ||
| success: true, | ||
| data: { started: true }, | ||
| }; | ||
| const resumeStream = mock((_input: unknown) => Promise.resolve(resumeStreamResult)); | ||
| const setAutoRetryEnabled = mock((input: unknown) => | ||
| Promise.resolve({ | ||
| success: true as const, | ||
| data: { | ||
| previousEnabled: true, | ||
| enabled: | ||
| typeof input === "object" && input !== null && "enabled" in input | ||
| ? ((input as { enabled?: boolean }).enabled ?? true) | ||
| : true, | ||
| }, | ||
| }) | ||
| ); | ||
|
|
||
| void mock.module("@/browser/contexts/API", () => ({ | ||
| useAPI: () => ({ | ||
| api: { | ||
| workspace: { | ||
| resumeStream, | ||
| setAutoRetryEnabled, | ||
| }, | ||
| }, | ||
| status: "connected" as const, | ||
| error: null, | ||
| authenticate: () => undefined, | ||
| retry: () => undefined, | ||
| }), | ||
| })); | ||
|
|
||
| /* eslint-disable @typescript-eslint/no-require-imports */ | ||
| const actualWorkspaceStore = | ||
| require("@/browser/stores/WorkspaceStore?real=1") as typeof WorkspaceStoreModule; | ||
| /* eslint-enable @typescript-eslint/no-require-imports */ | ||
|
|
||
| void mock.module("@/browser/stores/WorkspaceStore", () => ({ | ||
| ...actualWorkspaceStore, | ||
| useWorkspaceState: () => currentWorkspaceState, | ||
| useWorkspaceStoreRaw: () => ({ | ||
| getWorkspaceState: (_workspaceId: string) => currentWorkspaceState, | ||
| }), | ||
| })); | ||
|
|
||
| import { InterruptedBarrier } from "./InterruptedBarrier"; | ||
|
|
||
| describe("InterruptedBarrier", () => { | ||
| beforeEach(() => { | ||
| globalThis.window = new GlobalWindow() as unknown as Window & typeof globalThis; | ||
| globalThis.document = globalThis.window.document; | ||
|
|
||
| currentWorkspaceState = createWorkspaceState(); | ||
| resumeStreamResult = { success: true, data: { started: true } }; | ||
| resumeStream.mockClear(); | ||
| setAutoRetryEnabled.mockClear(); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| cleanup(); | ||
| mock.restore(); | ||
| globalThis.window = undefined as unknown as Window & typeof globalThis; | ||
| globalThis.document = undefined as unknown as Document; | ||
| }); | ||
|
|
||
| test("clicking the resumable interrupted label resumes the tail without touching auto-retry", async () => { | ||
| const view = render(<InterruptedBarrier workspaceId="ws-1" resumable />); | ||
|
|
||
| const label = view.getByRole("button", { name: "Continue interrupted response" }); | ||
| fireEvent.click(label); | ||
|
|
||
| await waitFor(() => { | ||
| expect(resumeStream).toHaveBeenCalledTimes(1); | ||
| }); | ||
|
|
||
| // A user-initiated (Esc) interrupt means "continue once" — it must NOT flip | ||
| // the auto-retry preference, so the unmount-on-auto-retry path can't cancel | ||
| // an in-flight scheduled retry. | ||
| expect(setAutoRetryEnabled).not.toHaveBeenCalled(); | ||
| expect(resumeStream.mock.calls[0]?.[0]).toMatchObject({ workspaceId: "ws-1" }); | ||
| }); | ||
|
|
||
| test("a non-resumable divider renders no clickable control", () => { | ||
| const view = render(<InterruptedBarrier workspaceId="ws-1" resumable={false} />); | ||
|
|
||
| expect(view.queryByRole("button")).toBeNull(); | ||
| expect(view.getByText("interrupted")).toBeTruthy(); | ||
| }); | ||
| }); |
32 changes: 30 additions & 2 deletions
32
src/browser/features/Messages/ChatBarrier/InterruptedBarrier.tsx
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 |
|---|---|---|
| @@ -1,10 +1,38 @@ | ||
| import React from "react"; | ||
| import { BaseBarrier } from "./BaseBarrier"; | ||
| import { useResumeStream } from "@/browser/hooks/useResumeStream"; | ||
|
|
||
| interface InterruptedBarrierProps { | ||
| workspaceId: string; | ||
| /** | ||
| * Whether this divider sits on the current resume target (the history tail). | ||
| * resumeStream always continues the tail, so only the tail divider is made | ||
| * clickable — older partial dividers stay decorative to avoid resuming the | ||
| * wrong turn. | ||
| */ | ||
| resumable?: boolean; | ||
| className?: string; | ||
| } | ||
|
|
||
| export const InterruptedBarrier: React.FC<InterruptedBarrierProps> = ({ className }) => { | ||
| return <BaseBarrier text="interrupted" color="var(--color-interrupted)" className={className} />; | ||
| /** | ||
| * "interrupted" divider shown on a partial assistant turn. When it sits on the | ||
| * resumable tail, clicking the label continues the stream from where it stopped | ||
| * (same backend path as RetryBarrier / auto-retry). It is the only continue | ||
| * affordance for user-initiated (Esc) interrupts, where RetryBarrier is | ||
| * suppressed. autoRetryOnFailure is disabled because ChatPane unmounts this | ||
| * divider once auto-retry becomes active; see useResumeStream for why that | ||
| * matters. | ||
| */ | ||
| export const InterruptedBarrier: React.FC<InterruptedBarrierProps> = (props) => { | ||
| // resume() internally guards against re-entrancy while a resume is in flight. | ||
| const { resume } = useResumeStream(props.workspaceId, { autoRetryOnFailure: false }); | ||
|
ethanndickson marked this conversation as resolved.
Outdated
|
||
| return ( | ||
| <BaseBarrier | ||
| text="interrupted" | ||
| color="var(--color-interrupted)" | ||
| className={props.className} | ||
| onClick={props.resumable ? () => void resume() : undefined} | ||
| ariaLabel={props.resumable ? "Continue interrupted response" : undefined} | ||
| /> | ||
| ); | ||
| }; | ||
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.