Skip to content

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

Merged
objectstack-fleet[bot] merged 3 commits into
mainfrom
claude/project-thread-ztpzpa
Nov 15, 2026
Merged

objectstack-fleet[bot] merged 3 commits into
mainfrom
claude/project-thread-ztpzpa

Conversation

@objectstack-fleet

Copy link
Copy Markdown
Contributor

Requested by Leehom · project thread

Fixes #33674
Fixes #33685

Clause-②: no
Metadata-protocol: none

Seat domain:ui#2 · os-project-manager · card thread session_01FEkQ5peXUXXQ6HU4H89s6J · claims 6890508556 and 6890872696 · one PR for both cards, two commits (one per card), as the seat ruled.

维护者速读

  • 改了什么:AI 对话(/ai 全页、控制台聊天停靠栏、Studio copilot)两处输入丢失。① 会话还没确定时(打开会话链接正在加载,或新会话正在创建)在输入框里打了但没发送的文字,会话确定后不再被清空,光标停在末尾、焦点保留,不会自动发送;切换到另一个会话时草稿不跟过去(与今天一致)。② 打开会话链接后、会话还在加载时发出的消息,如果加载失败(5xx 或断网),不再永远转圈:消息退回输入框(连发两条时两条都退回,先后不变)并显示"未发送"提示,不发送任何内容;再发一次会重新加载该会话并只发一次。
  • 为什么改:① 聊天面板以会话 id 为 key,id 确定时整块重建,输入框里的文字随旧面板一起丢弃(fix(console): a failed AI chat create gives back every message sent while it waited #33673 开发者实测)。② 会话加载失败的 catch 只清空 id,既不让发送去创建会话,也不通知宿主,暂存的消息就一直挂着(fix(console): a failed AI chat create gives back every message sent while it waited #33673 契约复审发现,开发者实测)。
  • 风险与回滚:只改前端私有包 @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(新增的钉子)。
  • 两分钟验证:pnpm dev,打开 /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)

ChatPane is keyed on ${chatApi}:${conversationId ?? 'pending'} in all three hosts, and the composer's text lives inside the pane, so the remount from …:pending to 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.

  • The key stays. Everything else in the pane (the chat runtime, its messages, the held first message's bookkeeping) belongs to one conversation and must reset with it; only the composer's text is carried.
  • New hook useComposerDraftHandoff (in AiChatPage.tsx, called by ChatPane). 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-owned pendingFirstMessageRef, the one object a host keeps across the remount, so two hosts never trade drafts.
  • What is carried, and what is not. Only from a pending pane (a pane that already had a conversation hands nothing on); only to a pane with an id on the same endpoint; and only while the host still asks for the conversation it asked for when the text was typed. That last guard is the new optional ChatPane prop requestedConversationId, which the /ai page passes (urlConversationId ?? legacyConversationId, the same value it gives useChatConversation as activeId). The dock and the Studio copilot pass nothing, which matches their activeId: 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.
  • ChatPane passes the hook's recorder to ChatbotEnhanced's existing onInputChange. No new ChatbotEnhanced prop, so @object-ui/plugin-chatbot is 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 while GET /conversations/conv-7 is pending is held by useDeferredFirstSend and recorded by ensureConversation. When that GET failed with a 5xx or a network error, the resolve's catch cleared the id without settling the surface and its finally dropped the recorded request, so the held message hung with its thinking dots, nothing was sent and no notice showed.

Changesets

.changeset/33674-ai-chat-draft-survives-remount.md and .changeset/33685-ai-chat-failed-load-gives-held-send-back.md: @object-ui/app-shell and @object-ui/console patch each (app-shell is private and the console's dist ships it), both declaration lines Clause-②: no / Metadata-protocol: none.

Tests

All pins are in the #33420 harness, AiChatPage.firstMessageDrawnAtOnce-33420.test.tsx: the REAL AiChatPage / ChatDockConversation, ChatPane, useChatConversation, useObjectChat transport and ChatbotEnhanced, driven through the composer, with fetch holding GET /conversations/:id and POST /conversations open 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):

#33685 (top-level describe … a send held while the conversation loads, when the load fails, on the full page and on the dock):

The harness's held GET now also takes a network failure (Held.fail).

Red first, on origin/main 5604aeb (which carries #33673)
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):

  • A1, the restore write removed (box.value = handoff.text; to void 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".
  • A2, the requested-conversation guard made always true: 1 failed, "a draft typed in a new conversation stays behind when the user opens another one".
  • A3, the pending-only guard (if (conversationId) return;) made never true: 1 failed, "a pane that already had a conversation hands nothing on".
  • A4, the microtask expiry removed: 1 failed, "a hand-off no pane took in the same commit is dropped".
  • A5, the endpoint guard made always true: 1 failed, "a pane on another chat endpoint takes nothing".
  • B1, the 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.
  • B2, the retry branch in ensureConversation made never true: 2 failed, the two retry pins (page and dock).

Acceptance notes

  • Reachability. Every pin drives the rendered page through the composer's real input events (change, submit) and real request timing (held then answered or failed fetch); the hand-off is read from the DOM box the next pane renders, not from the hook.
  • The Studio copilot renders the same ChatPane with no requestedConversationId (its activeId is undefined), so it takes both fixes unchanged; it has no rendered pin of its own here, the order names the page and the dock.
  • A draft typed in a new chat before switching agent (ask to build) is not carried: the endpoint differs. Unchanged from today.
  • The dock moving between apps: a draft typed in the dock's pending pane of app A, then the dock moving to app B, stays in the same pane while B resolves (same key, no remount, as today) and is now kept when B's conversation lands. A draft typed in an open conversation of app A is not carried. Not pinned beyond the hook unit pins.
  • Out of scope, unchanged: the latency of 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.
  • Three commits, not two. The seat asked for one commit per card. A third commit, 8500bab, changes four lines of the test harness (the navigate helper sets its module variable from an effect instead of during render; react-hooks/globals refused 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/objectstack derives 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. --ran reconciliation: 38 derived, 38 run, 0 NOT-MEASURED, 0 UNRUN.
  • pnpm --filter @object-ui/app-shell run type-check: exit 0.
  • ESLint (--no-inline-config) on AiChatPage.tsx, useChatConversation.ts and the harness: exit 0, 0 errors; one more warning than on base, react-refresh/only-export-components for the new exported hook (the file already exports useDeferredFirstSend the same way).
  • pnpm check:new-line-citations (from ui/): 0 new citations, exit 0.
  • Suites under the lock, pnpm exec vitest run --maxWorkers=2 from ui/ over packages/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/ and packages/plugin-chatbot/: 627 files, 4848 tests passed (VERDICT command-exit 0, head 8500bab).
  • origin/main moved to ee627c6 while the gates ran; none of those commits touches ui/packages/app-shell/ or ui/packages/plugin-chatbot/.
  • The full app-shell suite and the rest of the farm are CI's.

🤖 Generated with Claude Code

https://claude.ai/code/session_01FEkQ5peXUXXQ6HU4H89s6J


Generated by Claude Code

…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
@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

domain:ui#2 · os-project-manager · session_01FEkQ5oF8GgTHN2jBZoDwz8

席位核对

Verdict: ACCEPT · head 8500bab4 · 2026-11-15T08:34Z

  1. Shape. Draft → main, Fixes #33674, Fixes #33685. The PR has 5 files, +506/−6, in three commits: one per card, plus a four-line harness lint fix (a named deviation):

    Everything is on the claimed surface.

  2. Premise and fix.

  3. Declarations. Clause-②: no, Metadata-protocol: none, patch. That is right: every file is in the private @object-ui/app-shell, shipped inside @object-ui/console, and no ChatbotEnhanced prop was needed. No contract record is owed.

  4. Gates on head 8500bab4: All 51 check runs are success (38) or skipped (13). The dev's local run is 38 derived / 38 run / 0 NOT-MEASURED, with the chat suites at 627 files / 4848 tests.

  5. Shape choice. Both cards ship in one PR at the seat's direction. Each card has its own red-first and ablation record, and the PR is about 510 lines. Two serial PRs would have cost an extra merge-queue cycle.

  6. K. 8 first-parent commits since base 5604aeb0 (< 15): no base sync owed. Path face: not governed; 512 changed lines.

  7. Authority. Landing under the maintainer's standing authorisation 「按照 pm-dispatch 规则复核过的都授权」 (2026-10-25T11:35Z).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation size/l tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface

Projects

None yet

1 participant