fix(native-chat): keep a command typed while a refused one was answering

A refused conversation command is handed back through the independent
draft merge, which replaces a lone command in the composer. With the
draft now released on send, a /clear typed while /compact was answering
was overwritten by the refused /compact. Return a refused command only
to an empty composer; anything typed since stays as typed, and the
refusal notice still says the command was not done.
This commit is contained in:
mahedi-emon
2026-11-09 04:42:30 +00:00
committed by Kelvin Amoaba
parent c2f71e3e6a
commit 199251e495
2 changed files with 24 additions and 4 deletions
@@ -241,7 +241,7 @@ describe('a conversation command leaves the composer once it is sent', () => {
clearNativeChatComposerDraftsForTests()
})
it('clears /compact while the host is still answering', async () => {
async function sendCompactWhileHostAnswers() {
const host =
Promise.withResolvers<
StructuredAgentSessionWriteOutcome<AgentSessionConversationCommandResult>
@@ -311,9 +311,26 @@ describe('a conversation command leaves the composer once it is sent', () => {
sending = hook.result.current.send('/compact', [])
})
await act(async () => {})
return { host, hook, settled: () => act(async () => sending) }
}
it('clears /compact while the host is still answering', async () => {
const { host, hook, settled } = await sendCompactWhileHostAnswers()
expect(hook.result.current.draft).toBe('')
host.resolve({ kind: 'done', value: { command: 'compact', state: 'completed' } })
await act(async () => sending)
await settled()
expect(hook.result.current.draft).toBe('')
})
it('keeps a command typed while a refused /compact was answering', async () => {
const { host, hook, settled } = await sendCompactWhileHostAnswers()
act(() => hook.result.current.setDraft('/clear'))
host.resolve({
kind: 'not-done',
notice: 'Codex could not compact.',
failure: { kind: 'failed' }
})
await settled()
expect(readNativeChatComposerDraft(scope).text).toBe('/clear')
})
})
@@ -191,6 +191,9 @@ export function useNativeChatStructuredComposerSend({
setCaret(composing ? 0 : left.text.length)
clearSkillOrigin()
}
// A refused command returns only to an empty composer; a lone command typed since would be replaced.
const recoversDraft = () =>
consumed && (!hostCommand || readNativeChatComposerDraft(draftScopeKey).text.trim() === '')
const prepareAttachments: StructuredAgentSessionAttachmentPreparation | undefined =
stagedInput ? (input) => stagedInput.prepare(input, structuredTransport) : undefined
return dispatchNativeChatStructuredComposerText(
@@ -211,7 +214,7 @@ export function useNativeChatStructuredComposerSend({
structuredTransport.onError(error, refusedWhile ? { refusedWhile } : undefined)
}
if (!accepted) {
finishNativeChatComposerSubmission(draftScopeKey, submission, consumed)
finishNativeChatComposerSubmission(draftScopeKey, submission, recoversDraft())
return false
}
transferred = true
@@ -224,7 +227,7 @@ export function useNativeChatStructuredComposerSend({
return true
})
.catch((error) => {
finishNativeChatComposerSubmission(draftScopeKey, submission, consumed)
finishNativeChatComposerSubmission(draftScopeKey, submission, recoversDraft())
if (hostCommand && !isCurrent()) {
return false
}