Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
534788d
Park hidden structured chat views and preserve return state
brennanb2025 Oct 23, 2026
4e73368
Consolidate chat parking imports for CI
brennanb2025 Oct 23, 2026
b120b03
Correct parked chat hook lifetimes and initialization
brennanb2025 Oct 23, 2026
b853248
Align parking contract fixtures with checked types
brennanb2025 Oct 23, 2026
dc31056
Preserve transcript pin timing while recording reading position
brennanb2025 Oct 23, 2026
5f8e75b
test: align chat fixtures with retained input lifetime
brennanb2025 Oct 23, 2026
cc82361
Keep chat input ownership independent of parked views
brennanb2025 Oct 23, 2026
911a2a5
test: observe parking candidate updates after commit
brennanb2025 Oct 23, 2026
2a43589
fix: preserve causal chat state across parked views
brennanb2025 Oct 23, 2026
18f6bbd
Fix chat parking validation fixtures and retirement triggers
brennanb2025 Oct 23, 2026
9a9a349
test(chat): observe retirement and rail landing outcomes
brennanb2025 Oct 23, 2026
521d808
test(chat): type rail scroll recorder explicitly
brennanb2025 Oct 23, 2026
590ddeb
Merge origin/main before final chat lifecycle QA
brennanb2025 Oct 23, 2026
18f2ce7
Test recorded Codex async acceptance across chat parking
brennanb2025 Oct 23, 2026
874a64d
Separate recorded Codex decoder and renderer test boundaries
brennanb2025 Oct 24, 2026
30de3aa
Update rendered chat controls fixture to current Find wiring
brennanb2025 Oct 24, 2026
729ab1a
Merge origin/main to resolve PR check conflicts
brennanb2025 Oct 24, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/renderer/src/components/dictation/DictationController.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { holdNativeChatInput } from '../native-chat/native-chat-view-parking-owner'
import { useEffect, useRef, useCallback } from 'react'
import { useAppStore } from '@/store'
import { useAudioCapture } from '@/hooks/use-audio-capture'
import { toast } from 'sonner'
import { DictationIndicator } from './DictationIndicator'
import {
captureInsertionTarget,
useDictationChatInputLease,
captureReadyInsertionTarget,
insertText,
type DictationInsertionTarget
} from './dictation-insertion-target'
Expand Down Expand Up @@ -35,6 +37,7 @@ export function DictationController() {
dictationStateRef.current = dictationState
const dictationRunRef = useRef(0)
const holdGestureActiveRef = useRef(false)
const releaseChatInput = useDictationChatInputLease(dictationState)
const insertionTargetRef = useRef<DictationInsertionTarget | null>(null)
const activeSessionIdRef = useRef<string | null>(null)
const stoppedSessionIdsRef = useRef(new Set<string>())
Expand Down Expand Up @@ -122,7 +125,14 @@ export function DictationController() {
const sessionId = String(runId)
dictationRunRef.current = runId
activeSessionIdRef.current = sessionId
insertionTargetRef.current = captureInsertionTarget()
insertionTargetRef.current = await captureReadyInsertionTarget()
if (dictationRunRef.current !== runId) {
return
}
const target = insertionTargetRef.current
releaseChatInput.current?.()
releaseChatInput.current =
target && target.kind !== 'terminal' ? holdNativeChatInput(target.element) : null
stopRequestedDuringStartRef.current = false
finalTranscriptReceivedRef.current = false
erroredSessionIdsRef.current.clear()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
import { useEffect, useRef } from 'react'

export function useDictationChatInputLease(dictationState: string) {
const releaseChatInput = useRef<(() => void) | null>(null)
useEffect(() => {
if (dictationState === 'idle' || dictationState === 'error') {
releaseChatInput.current?.()
releaseChatInput.current = null
}
}, [dictationState])
useEffect(() => () => releaseChatInput.current?.(), [])
return releaseChatInput
}

import { awaitSelectedNativeChatInput } from '../native-chat/native-chat-input-readiness'
import { yieldToEventLoop } from '../../../../shared/event-loop-yield'
import { getUtf8ChunkEndIndex } from '../../../../shared/utf8-byte-limits'
import {
Expand All @@ -24,6 +39,19 @@ export function captureInsertionTarget(): DictationInsertionTarget | null {
return readFocusedInsertionTarget()
}

export async function captureReadyInsertionTarget(): Promise<DictationInsertionTarget | null> {
const current = captureInsertionTarget()
if (current) {
return current
}
const input = await awaitSelectedNativeChatInput()
if (input === false) {
return null
}
input?.focus({ preventScroll: true })
return readFocusedInsertionTarget()
}

function readFocusedInsertionTarget(): DictationInsertionTarget | null {
const activeElement = document.activeElement

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// @vitest-environment happy-dom

import { act, cleanup, render } from '@testing-library/react'
import type * as DraftHooks from './use-native-chat-draft'
import type { RefObject } from 'react'
import { NativeChatViewIdentity } from './native-chat-view-state-memory'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import type { NativeChatPickerItem } from '../../../../shared/native-chat-picker-items'
import type { NativeChatStructuredComposerTransport } from './native-chat-composer-types'
Expand Down Expand Up @@ -54,7 +56,8 @@ vi.mock('./native-chat-runtime-send', () => ({
sendNativeChatMessage: vi.fn(),
sendNativeChatTypedCommand: mocks.sendNativeChatTypedCommand
}))
vi.mock('./use-native-chat-draft', () => ({
vi.mock('./use-native-chat-draft', async (original) => ({
...(await original<typeof DraftHooks>()),
useNativeChatDraft: () => ({ draft: mocks.draft, setDraft: mocks.setDraft })
}))
vi.mock('./NativeChatComposerField', () => ({
Expand Down Expand Up @@ -92,7 +95,7 @@ const RESUME: CommandItem = {
orcaOwned: true
}

function renderStructuredChat() {
function renderStructuredChat(identity: string | null = null) {
const transport: NativeChatStructuredComposerTransport = {
send: vi.fn(() => true),
dispatchCommand: vi.fn(async () => ({ handled: false, accepted: false, error: null })),
Expand All @@ -110,16 +113,25 @@ function renderStructuredChat() {
runtimeEnvironmentId: null
}
const chat = () => (
<NativeChatComposer
terminalTabId="tab-1"
paneKey="tab-1:structured"
targetPtyId={null}
agent="claude"
structuredTransport={transport}
/>
<NativeChatViewIdentity.Provider value={identity}>
<NativeChatComposer
terminalTabId="tab-1"
paneKey="tab-1:structured"
targetPtyId={null}
agent="claude"
structuredTransport={transport}
/>
</NativeChatViewIdentity.Provider>
)
const view = render(chat())
return { transport, rerender: () => view.rerender(chat()) }
let view = render(chat())
return {
transport,
rerender: () => view.rerender(chat()),
park: () => view.unmount(),
reveal: () => {
view = render(chat())
}
}
}

describe('/resume in the native chat composer', () => {
Expand All @@ -139,7 +151,9 @@ describe('/resume in the native chat composer', () => {
it("opens a structured chat's history, typed in any case, and sends nothing", () => {
mocks.draft = '/Resume auth retry'
mocks.imageAttachments = [{ id: 'img-1', path: '/tmp/a.png' }]
const { transport } = renderStructuredChat()
const { transport, park, reveal } = renderStructuredChat('typed-resume-return')
park()
reveal()
let focusedAtOpen: Element | null = null
mocks.openHistory.mockImplementation(() => (focusedAtOpen = document.activeElement))

Expand Down Expand Up @@ -168,7 +182,7 @@ describe('/resume in the native chat composer', () => {

it('sends a picked skill named resume to the agent, as the skill it is', () => {
mocks.draft = '/res'
const { transport, rerender } = renderStructuredChat()
const { transport, rerender, park, reveal } = renderStructuredChat('picked-resume-return')
act(() =>
mocks.fieldProps?.onChoosePickerItem?.({
kind: 'skill',
Expand All @@ -181,6 +195,8 @@ describe('/resume in the native chat composer', () => {
)
mocks.draft = '/resume make it one page'
rerender()
park()
reveal()

act(() => mocks.fieldProps?.onSend?.())

Expand Down
24 changes: 12 additions & 12 deletions src/renderer/src/components/native-chat/NativeChatComposer.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import { useNativeChatReturnState } from './native-chat-view-state-memory'
import { useNativeChatComposerNotice } from './use-native-chat-composer-notice'
import { useNativeChatMobileHoldNotice } from './use-native-chat-mobile-hold-notice'
import type { NativeChatComposerInput } from './native-chat-composer-input'
import { forwardRef, useCallback, useState } from 'react'
import { useNativeChatComposerInterrupt } from './use-native-chat-composer-interrupt'
import { useNativeChatContextUsageSummary } from './use-native-chat-context-usage-summary'
import { useNativeChatMentionFiles } from './use-native-chat-mention-files'
import { useNativeChatDraft } from './use-native-chat-draft'
import {
useNativeChatDraft,
useNativeChatDraftChange,
composerCaret
} from './use-native-chat-draft'
import { useNativeChatComposerRecall } from './use-native-chat-composer-recall'
import { useNativeChatLaunchDraftAdoption } from './use-native-chat-launch-draft-adoption'
import { NativeChatComposerField } from './NativeChatComposerField'
Expand Down Expand Up @@ -84,7 +88,7 @@ const NativeChatComposerPane = forwardRef<NativeChatComposerHandle, NativeChatCo
draftScopeKey,
imeEnterGesture.isComposing
)
const [caret, setCaret] = useState(draft.length)
const [caret, setCaret] = useNativeChatReturnState(composerCaret, () => draft.length)
useNativeChatLaunchDraftAdoption({
terminalTabId,
agent,
Expand Down Expand Up @@ -348,15 +352,11 @@ const NativeChatComposerPane = forwardRef<NativeChatComposerHandle, NativeChatCo
setCaret
})

const handleDraftChange = useCallback(
(value: string, element: NativeChatComposerInput) => {
const nextCaret = element.selectionStart ?? value.length
setDraft(value)
setCaret(nextCaret)
handleDraftOrCaretChange(value, nextCaret)
setActiveSuggestion(0)
},
[handleDraftOrCaretChange, setDraft]
const handleDraftChange = useNativeChatDraftChange(
setDraft,
setCaret,
handleDraftOrCaretChange,
setActiveSuggestion
)

return (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useNativeChatViewLease } from './native-chat-view-parking-owner'
import { NativeChatPromptEditor } from './NativeChatPromptEditor'
import type { NativeChatComposerInput } from './native-chat-composer-input'
import type { ClipboardEventHandler, KeyboardEventHandler, RefObject } from 'react'
Expand Down Expand Up @@ -177,6 +178,8 @@ export function NativeChatComposerField({
? mentionFiles.files.length
: 0
// Value the IME started from, and whether a programmatic clear was dropped on top of it.
const acquireLease = useNativeChatViewLease()
const compositionLease = useRef<(() => void) | null>(null)
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
const compositionBaseRef = useRef('')
const imageRow = useMemo(() => imageAttachments.map(({ id }) => id), [imageAttachments])
const droppedDraftClearRef = useRef(false)
Expand Down Expand Up @@ -205,6 +208,8 @@ export function NativeChatComposerField({
}, [draft, imeEnterGesture, textareaRef])

const settleImeValue = (element: NativeChatComposerInput): void => {
compositionLease.current?.()
compositionLease.current = null
if (droppedDraftClearRef.current) {
droppedDraftClearRef.current = false
element.value = imeComposedSegment(compositionBaseRef.current, element.value)
Expand Down Expand Up @@ -313,6 +318,8 @@ export function NativeChatComposerField({
// Settle the interrupted composition before the new one takes browser ownership.
flushSync(() => settleImeValue(textareaRef.current!))
}
compositionLease.current?.()
compositionLease.current = acquireLease()
compositionBaseRef.current = textareaRef.current!.value
imeEnterGesture.setComposing(true)
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
screen,
waitFor
} from '@testing-library/react'
import { NativeChatViewIdentity } from './native-chat-view-state-memory'
import { useRef, useState } from 'react'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'

Expand Down Expand Up @@ -188,6 +189,39 @@ afterEach(() => {
})

describe('Continue on a reply an Orca stop cut off', () => {
it('keeps Continue admission and a detached refusal through park/reveal, then retries once', async () => {
let resolve!: (answer: { outcome: string }) => void
mocks.call.mockImplementationOnce(
() =>
new Promise((done) => {
resolve = done
})
)
const returned = () => (
<NativeChatViewIdentity.Provider value="continue-park-refusal">
<Harness />
</NativeChatViewIdentity.Provider>
)
const first = render(returned())
fireEvent.click(continueButton()!)
first.unmount()
const pending = render(returned())
expect(continueButton()).toBeNull()
expect(mocks.call).toHaveBeenCalledTimes(1)
pending.unmount()
await act(async () => resolve({ outcome: 'refused' }))
const refused = render(returned())
expect(screen.getByTestId('error')).toHaveTextContent(FAILED)
expect(continueButton()).not.toBeNull()
refused.unmount()
render(returned())
expect(screen.getByTestId('error')).toHaveTextContent(FAILED)
mocks.call.mockResolvedValueOnce({ outcome: 'pending' })
fireEvent.click(continueButton()!)
expect(mocks.call).toHaveBeenCalledTimes(2)
expect(screen.getByTestId('error')).toHaveTextContent('none')
})

it("asks the chat's own host, paired or local, to continue that cut turn", () => {
mocks.call.mockResolvedValue({ outcome: 'pending' })
render(<Harness />)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { useCallback, useId, useLayoutEffect, useMemo, useRef, useState } from 'react'
import {
createNativeChatReturnField,
useNativeChatReturnState
} from './native-chat-view-state-memory'
import { useCallback, useId, useLayoutEffect, useMemo, useRef } from 'react'
import { Play } from 'lucide-react'
import { Button } from '@/components/ui/button'
import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/tooltip'
Expand Down Expand Up @@ -32,6 +36,13 @@
import type { NativeChatComposerNoticeContent } from './native-chat-composer-notice'
import type { NativeChatStructuredComposerTransport } from './native-chat-composer-types'

const continueAsked = createNativeChatReturnField<string | null>()
const continueFailure = createNativeChatReturnField<{
turnItemId: string
unconfirmed: boolean
} | null>()
const continueFailedOn = createNativeChatReturnField<string | null>()

type ContinueAnswer = { outcome?: string }

export type NativeChatInterruptedContinuation = {
Expand Down Expand Up @@ -63,6 +74,7 @@
/** The composer's send; false when the chat took nothing. */
transport: NativeChatStructuredComposerTransport
pending: readonly Pick<StructuredAgentSessionPendingSend, 'phase'>[]
readCurrent?: boolean
}): NativeChatInterruptedContinuation {
const { target, sessionId, reportComposerError, focusComposer, transport, agent } = input
const latestTransport = useRef(transport)
Expand Down Expand Up @@ -92,15 +104,25 @@
[input.journalItems, input.submissions]
)
// The cut this client already asked to continue: hidden until the journal shows what came of it.
const [asked, setAsked] = useState<string | null>(null)
const [usageFailure, setUsageFailure] = useState<{
turnItemId: string
unconfirmed: boolean
} | null>(null)
const [failedOn, setFailedOn] = useState<string | null>(null)
const [asked, setAsked] = useNativeChatReturnState(continueAsked, () => null)
const [usageFailure, setUsageFailure] = useNativeChatReturnState(continueFailure, () => null)
const [failedOn, setFailedOn] = useNativeChatReturnState(continueFailedOn, () => null)
if (usageFailure !== null && input.pending.length > 0) {
setUsageFailure(null)
}
if (input.readCurrent && asked !== null && asked !== cut?.turnItemId) {
setAsked(null)
}
if (input.readCurrent && failedOn !== null && failedOn !== cut?.turnItemId) {
setFailedOn(null)
}
if (
input.readCurrent &&
usageFailure !== null &&
usageFailure.turnItemId !== usageLimitCut?.turnItemId
) {
setUsageFailure(null)
}
const offered =
capability === 'supported' && cut && !input.isWorking && !resuming && asked !== cut.turnItemId
? cut.turnItemId
Expand All @@ -124,7 +146,7 @@
return
}
const turnItemId = usageLimitTurnItemId
setUsageFailure(null)

Check warning on line 149 in src/renderer/src/components/native-chat/NativeChatInterruptedContinue.tsx

View workflow job for this annotation

GitHub Actions / static analysis and typecheck

react-hooks(exhaustive-deps)

src/renderer/src/components/native-chat/NativeChatInterruptedContinue.tsx:149:7: React Hook useCallback has a missing dependency: 'setUsageFailure'
reportComposerError(null)
// Keeping the draft must not keep the previous send's error.
publishStructuredAgentSessionSends(sessionId, { notice: null })
Expand Down Expand Up @@ -158,7 +180,7 @@
const turnItemId = offered
// Nothing was accepted: one line in the composer, which a retry replaces rather than repeats.
const failed = (): void => {
setAsked((current) => (current === turnItemId ? null : current))

Check warning on line 183 in src/renderer/src/components/native-chat/NativeChatInterruptedContinue.tsx

View workflow job for this annotation

GitHub Actions / static analysis and typecheck

react-hooks(exhaustive-deps)

src/renderer/src/components/native-chat/NativeChatInterruptedContinue.tsx:183:7: React Hook useCallback has missing dependencies: 'setAsked', and 'setFailedOn'
setFailedOn(turnItemId)
}
setAsked(turnItemId)
Expand Down
Loading
Loading