feat(ai-chat): reconcile stream-transport failure instead of blind retry (ADR-0013 D2)#1742
Merged
Merged
Conversation
…y retrying (ADR-0013 D2) The agent runtime persists the final assistant reply BEFORE it streams it, so a network drop AFTER the turn completed leaves a complete reply in the conversation — but the chat UI shows a scary "Response failed / Retry", and Retry re-runs the whole turn (re-plans, can leave orphan drafts). On a chat stream error, first GET the conversation and check whether the turn actually finished (last message is an assistant reply with non-empty text). If so, re-hydrate the thread with the persisted messages and suppress the error banner — the failure becomes a non-event. Only a genuinely-incomplete turn still shows Retry. - useChatConversation.ts: export `fetchConversation` + `toUIMessages` for reuse. - useObjectChat.ts: expose the underlying `setMessages` (API mode) so the host can re-hydrate the thread. - reconcileTurn.ts: pure `isReconcilableCompletedTurn()` decision helper + 6 unit tests (ends-on-assistant-text → true; ends-on-tool-call/tool-result/whitespace/ empty/user → false). - AiChatPage.tsx: onError → reconcile (fetch → helper → setMessages + suppress), reset suppression on a fresh send, gate the error banner behind it. Server-only-persists-before-yield is the load-bearing fact (framework service-ai ai-service.ts) — no framework/schema change needed; this is objectui-only. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
Contributor
✅ Console Performance Budget
📦 Bundle Size Report
Size Limits
|
os-zhuang
added a commit
that referenced
this pull request
Jun 15, 2026
…DR-0013 D1) (#1755) * feat(plugin-chatbot): send a stable per-turn turnId for safe Retry (ADR-0013 D1) The chat transport now stamps a stable `turnId` on every outgoing turn, derived from the id of the user message that triggered it. On Retry the AI SDK re-sends the SAME triggering user message (regenerate-message keeps the trailing user turn), so the id — and thus the turnId — is identical across the original send and the retry. The server (framework @objectstack/service-ai) uses this key to dedup the inbound user message and short-circuit a completed turn instead of re-running tools / re-planning. Builds on D2 (#1742), which reconciles a turn that actually succeeded; D1 covers the genuinely-failed retry path. - useObjectChat: DefaultChatTransport.prepareSendMessagesRequest → withTurnId (extracted + exported for unit testing). - tests: withTurnId — derivation, stability across Retry, distinct per new turn, defensive no-user case. Cross-repo: pairs with framework turnId dedup/short-circuit + a cloud SHA bump, per the ADR-0012 cross-repo recipe. Refs cloud#334. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * fix(plugin-chatbot): reconstruct full request body in prepareSendMessagesRequest (ADR-0013 D1) Browser E2E caught this: when DefaultChatTransport.prepareSendMessagesRequest returns a `body`, the AI SDK sends it VERBATIM — it does NOT merge back the default fields (id/messages/trigger/messageId). The first version returned only `{...body, turnId}`, dropping `messages`, so the live agent rejected the turn with 400 "messages array is required". withTurnId now replicates the transport's default body exactly and only ADDS turnId. Verified end-to-end in the browser against the running cloud+runtime stack: send → turn completes with a draft; Retry (regenerate) reuses the same turnId, the server short-circuits (no duplicate user row, no tool re-run, no second draft), and returns the stored reply. Refs cloud#334. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
os-zhuang
added a commit
that referenced
this pull request
Jun 15, 2026
…R-0013) (#1758) D2 (#1742) added "reconcile a stream-transport failure instead of blindly retrying" only to AiChatPage. The console floating chatbot still surfaced a scary "Response failed / Retry" even when the turn had actually completed server-side (the runtime persists the final reply before streaming). Extract the wiring into a shared `useReconcileOnError` hook (GET conversation → isReconcilableCompletedTurn → re-hydrate via setMessages + suppress banner) and use it on BOTH surfaces: - AiChatPage: refactored onto the hook (behaviour unchanged). - ConsoleFloatingChatbot: now reconciles too (wires onError + setMessages, gates the error banner, resets suppression on a fresh send). Retry on a genuinely-incomplete turn re-sends with the same turnId, so it stays idempotent under D1 (no duplicate user row, no tool re-run). End-to-end with D1: completed turn → reconciled to a non-event; failed turn → safe retry. Tests: 4 new renderHook cases for the hook; existing reconcileTurn (6) intact; app-shell builds clean. Refs #334. Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
ADR-0013 D2 (objectui-only). The agent runtime persists the final assistant reply before it streams it (framework
service-aiai-service.ts:779/895persist →789/905yield). So a transport drop after the turn completed leaves a complete reply in the DB — but the chat UI shows "Response failed" and Retry re-runs the whole turn (re-plans, risks orphan drafts).Change: on a chat stream error, GET the conversation and check if the turn actually finished; if so, re-hydrate the thread from the server and suppress the error banner. Only a genuinely-incomplete turn still shows Retry. Turns the most common "it actually succeeded" failure into a non-event.
Files
useChatConversation.ts— exportfetchConversation+toUIMessagesuseObjectChat.ts— exposesetMessages(API mode)reconcileTurn.ts— pureisReconcilableCompletedTurn()+ 6 unit tests (pass)AiChatPage.tsx— onError reconcile + suppress, reset on send, gate bannerVerification
reconcileTurn.test.ts: 6/6 pass (ends-on-assistant-text → reconcile; ends-on-tool-call/tool-result/whitespace/empty/user → fall through to banner).Pairs with the (heavier, cross-repo) ADR-0013 D1 turnId idempotency, which handles the genuinely-failed retry path; D2 here handles "it actually succeeded."
🤖 Generated with Claude Code