Repository navigation
fix(console): AI chat keeps a draft typed before the conversation is known, and gives back a send held when a linked conversation fails to load - #33727
Conversation
…on survives the id remount ChatPane stays keyed on the conversation id; a pending pane hands its composer text to the pane that replaces it in the same commit, when the endpoint is the same and the host still asks for the conversation it asked for when the text was typed. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FEkQ5peXUXXQ6HU4H89s6J
…s given back when the load fails The resolve's catch tells a send recorded during that run it was not sent (the existing create-error path gives its text back with the notice) and marks the key failed, so the next send loads the conversation again instead of waiting on a resolve that never comes. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FEkQ5peXUXXQ6HU4H89s6J
…om an effect The react-hooks globals rule refuses a module variable written during render. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FEkQ5peXUXXQ6HU4H89s6J
|
domain:ui#2 · os-project-manager · session_01FEkQ5oF8GgTHN2jBZoDwz8 席位核对Verdict: ACCEPT · head
|
Requested by Leehom · project thread
Fixes #33674
Fixes #33685
Clause-②: no
Metadata-protocol: none
Seat
domain:ui#2· os-project-manager · card threadsession_01FEkQ5peXUXXQ6HU4H89s6J· claims 6890508556 and 6890872696 · one PR for both cards, two commits (one per card), as the seat ruled.维护者速读
/ai全页、控制台聊天停靠栏、Studio copilot)两处输入丢失。① 会话还没确定时(打开会话链接正在加载,或新会话正在创建)在输入框里打了但没发送的文字,会话确定后不再被清空,光标停在末尾、焦点保留,不会自动发送;切换到另一个会话时草稿不跟过去(与今天一致)。② 打开会话链接后、会话还在加载时发出的消息,如果加载失败(5xx 或断网),不再永远转圈:消息退回输入框(连发两条时两条都退回,先后不变)并显示"未发送"提示,不发送任何内容;再发一次会重新加载该会话并只发一次。@object-ui/app-shell的两个文件(AiChatPage.tsx的ChatPane、useChatConversation.ts的加载失败分支),不改ChatbotEnhanced的属性、服务端、spec;面板 key 保持不变。回滚即还原本 PR(两个提交可分别还原)。ui/packages/app-shell/src/hooks/useChatConversation.ts(resolve 的catch与ensureConversation的重试分支)、ui/packages/app-shell/src/console/ai/AiChatPage.tsx(useComposerDraftHandoff与ChatPane的requestedConversationId)、ui/packages/app-shell/src/console/ai/__tests__/AiChatPage.firstMessageDrawnAtOnce-33420.test.tsx(新增的钉子)。/ai/build,发一条消息后在会话创建期间输入第二段文字不发送:创建完成后第二段仍在输入框里。再在开发者工具把GET /conversations/ID设为 503,打开/ai/build/ID时立刻发一条消息:消息退回输入框并出现未发送提示;取消拦截后再发,只发出一次。What changes
#33674: a draft typed before the pane knows its conversation survives the id remount (commit 0d69e25)
ChatPaneis keyed on${chatApi}:${conversationId ?? 'pending'}in all three hosts, and the composer's text lives inside the pane, so the remount from…:pendingto the real id dropped text typed but not sent: on a deep link whose conversation GET answers, and on a new conversation whose create answers while a second message is being typed.useComposerDraftHandoff(inAiChatPage.tsx, called byChatPane). A pending pane (no conversation id) reads its composer box (textarea[name="message"]inside the pane) as it unmounts and leaves the text, whether the box had focus, the chat endpoint and the conversation the host was asking for when the text was last typed. The replacing pane reads that in its mount layout effect, in the same commit, and puts the text into its empty box with the cursor at the end, focusing it when the old box had focus. Nothing is sent. A microtask drops a hand-off no pane took, so it never reaches a later, unrelated mount. The hand-off is keyed by the host's page-ownedpendingFirstMessageRef, the one object a host keeps across the remount, so two hosts never trade drafts.ChatPaneproprequestedConversationId, which the/aipage passes (urlConversationId ?? legacyConversationId, the same value it givesuseChatConversationasactiveId). The dock and the Studio copilot pass nothing, which matches theiractiveId: undefined, so neither host file changes. Decision for the order's third CONTROL: opening ANOTHER conversation leaves a draft behind, both from a new chat and from an open conversation (today's behaviour), and a pin holds it.ChatPanepasses the hook's recorder toChatbotEnhanced's existingonInputChange. No newChatbotEnhancedprop, so@object-ui/plugin-chatbotis untouched:Clause-②: no.#33685: a send held while a linked conversation loads is given back when the load fails (commit 8702038)
On a deep link (
/ai/build/conv-7, and the dock resuming a cached conversation the same way), a send made whileGET /conversations/conv-7is pending is held byuseDeferredFirstSendand recorded byensureConversation. When that GET failed with a 5xx or a network error, the resolve'scatchcleared the id without settling the surface and itsfinallydropped the recorded request, so the held message hung with its thinking dots, nothing was sent and no notice showed.catchnow reports to the recorded send. When a send was recorded during the failed run, the hook setscreateErrorto a not-sent error (the GET's status when it had one). That is the existing AI chat: on a new conversation the user's first message is not drawn until POST /conversations answers, so the thread sits blank for that long #33420 / AI chat: two messages sent while a new conversation is being created, then a failed create, give back only the second message (the first is dropped) #33562 path:useDeferredFirstSenddrops the held message andChatPanehands its text (joined parts included) toChatbotEnhancedasunsentText, so the box gets the text back with the not-sent notice. Nothing is sent and no create is made.catchmarks the key as failed. The nextensureConversationfor that key, finding nothing resolving, records the request, clears the oldcreateErrorand runs the resolve again (aresolveAttemptcounter in the resolve effect's deps). If the GET answers, the held message is sent once intoconv-7, as AI chat: a message sent from a conversation link before the conversation finishes loading may be dropped (seen in a test harness, unconfirmed) #33567's pin shows for a GET that answers the first time.fetchConversation's thrown error now carriesstatus(the notice reads it); its 404 / 403 answer (null) is unchanged.catch(a failed re-read of the conversation already held keeps it) is untouched.Changesets
.changeset/33674-ai-chat-draft-survives-remount.mdand.changeset/33685-ai-chat-failed-load-gives-held-send-back.md:@object-ui/app-shelland@object-ui/consolepatch each (app-shell is private and the console'sdistships it), both declaration linesClause-②: no/Metadata-protocol: none.Tests
All pins are in the #33420 harness,
AiChatPage.firstMessageDrawnAtOnce-33420.test.tsx: the REALAiChatPage/ChatDockConversation,ChatPane,useChatConversation,useObjectChattransport andChatbotEnhanced, driven through the composer, withfetchholdingGET /conversations/:idandPOST /conversationsopen until the test answers or fails them.#33674 (top-level describes
… a draft typed before the pane knows its conversation survives the remount,… switching to another conversation does not carry a draft,useComposerDraftHandoff — which remount carries the composer text):/ai/build/conv-9, its GET answers): the box is empty. Likewise from an open conversation to another.#33685 (top-level describe
… a send held while the conversation loads, when the load fails, on the full page and on the dock):first part\n\nsecond part.conv-7, no create.The harness's held GET now also takes a network failure (
Held.fail).Red first, on origin/main 5604aeb (which carries #33673)
expected '' to be 'add a due date field'/expected '' to be 'and add a due date', the box comes back empty; the four hook unit pins failuseComposerDraftHandoff is not a function(the hook does not exist on base). Every CONTROL is green on base.useChatConversation.tsat 5604aeb, everything else at 0d69e25, harness at 8702038: 8 failed / 26 passed: GET 503, GET network, joined, retry, on the page and the dock (the box stays empty, the bubble stays drawn). Both CONTROLs (a GET that answers; the 404 path) are green on base, on both hosts.Ablations, through scripts/ablation-replace.mjs (ui vitest resolves app-shell from src, no build), each restored with the blob equal to HEAD and git diff HEAD empty
Run over the whole harness file (34 tests):
box.value = handoff.text;tovoid handoff.text;): 5 failed / 29 passed, the four path pins and the hook pin "a pending pane hands its text to the pane that gets the id".if (conversationId) return;) made never true: 1 failed, "a pane that already had a conversation hands nothing on".catch's report skipped (an early return after marking the key failed): 8 failed / 26 passed, the eight AI chat: a message sent while a linked conversation loads hangs forever when that load fails (bubble and thinking dots stay, nothing sent, no notice) #33685 pins. A first attempt at this leg was refused by the tool before running (its replacement still contained the anchor, so the anchor count did not drop) and measured nothing; it was redone with a distinct replacement.ensureConversationmade never true: 2 failed, the two retry pins (page and dock).Acceptance notes
change,submit) and real request timing (held then answered or failedfetch); the hand-off is read from the DOM box the next pane renders, not from the hook.ChatPanewith norequestedConversationId(itsactiveIdis undefined), so it takes both fixes unchanged; it has no rendered pin of its own here, the order names the page and the dock.POST /conversations, fix(console): draw a new AI chat conversation's first message at once, and give its text back when the create fails #33561's first-message drawing, server, spec and cloud.react-hooks/globalsrefused the first form). The branch is the thread's harness branch, so it is not rewritten (AGENTS.md multi-agent §3, criterion ①).Verification
Local gates, type-check, lint and suites (head 8500bab, base origin/main 5604aeb)
node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstackderives 38 families for this diff (tree 8500bab; the same list as at 8702038). All 38 exit 0 on 8500bab after the@object-ui/app-shell^...closure build plus a rebuild of the ui packages the rebase moved.pnpm --dir ui exec vitest run scripts/first answered exit 99 (the lock's queue budget ran out behind the chat suites, nothing measured) and was re-run alone under the lock with--maxWorkers=2: 171 files passed, 2 skipped, VERDICT command-exit 0.--ranreconciliation: 38 derived, 38 run, 0 NOT-MEASURED, 0 UNRUN.pnpm --filter @object-ui/app-shell run type-check: exit 0.--no-inline-config) onAiChatPage.tsx,useChatConversation.tsand the harness: exit 0, 0 errors; one more warning than on base,react-refresh/only-export-componentsfor the new exported hook (the file already exportsuseDeferredFirstSendthe same way).pnpm check:new-line-citations(fromui/): 0 new citations, exit 0.pnpm exec vitest run --maxWorkers=2fromui/overpackages/app-shell/src/hooks/__tests__/useChatConversation.test.tsx,packages/app-shell/src/console/ai/,packages/app-shell/src/layout/,packages/app-shell/src/views/studio-design/andpackages/plugin-chatbot/: 627 files, 4848 tests passed (VERDICT command-exit 0, head 8500bab).origin/mainmoved to ee627c6 while the gates ran; none of those commits touchesui/packages/app-shell/orui/packages/plugin-chatbot/.🤖 Generated with Claude Code
https://claude.ai/code/session_01FEkQ5peXUXXQ6HU4H89s6J
Generated by Claude Code