WeKnora/frontend/src/composables
lyingbug 093c16cbb3
fix(agent): end the turn when the completion cap truncates an answer (#3449)
* fix(agent): end the turn when the completion cap truncates an answer

A round that came back with finish_reason=length and no tool calls used to
fall through analyzeResponse as non-terminal. With no tool calls to run,
appendToolResults pushed the half-written answer back into the history as a
plain assistant message with nothing telling the model to continue, so the
next round rewrote the answer from the top, hit the same cap, and repeated
until the round budget ran out or the user cancelled.

Three guards, each independently load-bearing:

- analyzeResponse gains a truncation case: deliver the partial text and end
  the turn. A cap hit that produced no text at all has nothing to hand over
  and defers to the existing bounded empty-content retry. No continuation
  nudge is sent — it only grows the prompt with the discarded fragment, and
  assistant prefill, the reliable form, is unavailable on most
  OpenAI-compatible endpoints.
- A consecutive-length breaker stops the loop when truncation keeps landing
  inside tool-call arguments, the one shape that still legitimately loops.
- The stuck-loop detector now counts an identical lack of content. A model
  burning its whole budget on reasoning returns empty every round, which used
  to land in the else branch and reset the counter, so the guard could never
  fire on the case that needed it most.

The answer event and its Done marker carry a truncated flag through the SSE
metadata, and the chat UI shows the same style of notice it already uses for
fallback answers.

Fixes #3446

* fix(agent): treat unterminated reasoning as no answer and keep the truncation marker

Review follow-up on three ways the truncation path could still mislead.

An inline <think> block that the cap cut off never gets its closing tag, so
the pair regex left it whole and the round looked like it had produced an
answer. The truncation case then skipped the empty-content retry it exists
for and emitted the chain of thought as the final answer. StripThinkBlocks
now drops a dangling <think> through end of input, which is what the
streaming splitter already does with the same text, so the two agree on what
counts as an answer.

The truncation marker only rode on the SSE metadata, and a finished
conversation is rebuilt from agent_steps rather than replayed from stream
events. A reloaded, shared or re-opened turn therefore lost the notice and
its half-written answer looked complete. AgentStep carries the flag now — it
is a jsonb column, so no migration — and the frontend marks the rebuilt
answer event and message from it.

The consecutive-length guard ran before the round was recorded, so a final
round of "let me look that up" plus a truncated tool call handed that
preamble over as the final answer, with its tool calls never refused and the
preamble never retracted from the answer area. The guard now records the
round and fails its tool calls the way every other truncated round does, and
a response carrying tool calls never donates its text as the answer.
2026-09-20 13:17:50 +08:00
..
preferenceStorage.ts fix(frontend): drop infectious preference fallback, add migration latch 2026-05-05 00:48:40 +08:00
skillInstallProgress.ts feat(frontend): keep the install drawer open with live circular progress 2026-09-02 15:08:05 +08:00
useApiBaseUrlDisplay.ts feat(frontend): add Chrome extension and Claw Skill integration landing pages 2026-06-28 00:31:38 +08:00
useArtifactArriveMotion.ts feat(chat): pulse the artifact folder when generated files arrive 2026-09-02 15:08:05 +08:00
useChatAttachmentPreviewDrawer.ts feat(chat): add session-scoped temporary attachments with async parsing 2026-07-16 17:41:27 +08:00
useChatCitationPopover.ts refactor(frontend): share citation popover lifecycle 2026-09-17 15:28:31 +08:00
useChatMemoryRow.ts fix(frontend): 修复占位行样式并把记忆行统一收进时间轴 2026-08-13 21:34:21 +08:00
useChatQuestionMinimap.ts fix(ui): 优化对话布局、导航与产物和引用展示 (#3427) 2026-09-19 19:25:52 +08:00
useChatReferencesDrawer.ts feat(quick-qa): add references drawer and polish retrieval source UI 2026-07-08 00:26:34 +08:00
useChatSandboxPanel.test.mjs fix(chat): refine sandbox artifact panel interactions 2026-09-09 21:42:04 +08:00
useChatSandboxPanel.ts Revert "feat(sandbox): add safe live file management to session sandboxes (#3…" 2026-09-11 17:42:08 +08:00
useChatStreamHandler.test.mjs fix(agent): end the turn when the completion cap truncates an answer (#3449) 2026-09-20 13:17:50 +08:00
useChatStreamHandler.ts fix(agent): end the turn when the completion cap truncates an answer (#3449) 2026-09-20 13:17:50 +08:00
useCitationPopover.test.ts refactor(frontend): share citation popover lifecycle 2026-09-17 15:28:31 +08:00
useCitationPopover.ts refactor(frontend): share citation popover lifecycle 2026-09-17 15:28:31 +08:00
useConfigSkillInstallProgress.test.mjs refactor(frontend): share skill install progress subscriptions 2026-09-16 23:12:14 +08:00
useConfigSkillInstallProgress.test.ts fix(skills): upgrade outdated sandbox skills without rolling back the catalog or taking them offline (#3406) 2026-09-18 20:27:43 +08:00
useConfigSkillInstallProgress.ts refactor(frontend): share skill install progress subscriptions 2026-09-16 23:12:14 +08:00
useDocumentPictureInPicture.test.ts feat(browser): add picture-in-picture task preview 2026-09-12 11:11:36 +08:00
useDocumentPictureInPicture.ts feat(browser): add picture-in-picture task preview 2026-09-12 11:11:36 +08:00
useEmbedBridge.ts feat(frontend): embed OAuth wiring and API integration UI polish 2026-06-30 20:01:05 +08:00
useEmbedChatSession.ts fix(chat): prevent pending steer messages from jittering during streaming 2026-09-09 22:58:09 +08:00
useEmbedCitationPopover.ts refactor(frontend): share citation popover lifecycle 2026-09-17 15:28:31 +08:00
useFloatingPreviewDrag.test.ts feat(browser): polish connection settings, open tasks in a new window, and streamline prompts (#3193) 2026-09-11 21:28:58 +08:00
useFloatingPreviewDrag.ts feat(browser): polish connection settings, open tasks in a new window, and streamline prompts (#3193) 2026-09-11 21:28:58 +08:00
useFont.ts fix(frontend): make general-settings font picker actually work 2026-05-07 15:07:24 +08:00
useListUrlState.ts feat(favorites): implement user favorites and recents functionality 2026-05-18 17:28:58 +08:00
useModalShell.ts refactor(frontend): style consistency pass — shared shells, tokens, unified confirmations (#3376) 2026-09-17 23:11:08 +08:00
useResourcePins.ts feat(favorites): implement user favorites and recents functionality 2026-05-18 17:28:58 +08:00
useRoleLabel.ts feat(rbac-ui): rework tenant identity surfaces 2026-05-18 17:28:58 +08:00
useSandboxDesktop.test.mjs feat(sandbox): add a graphical desktop to session sandboxes (#3245) 2026-09-14 20:37:37 +08:00
useSandboxDesktop.ts feat(sandbox): add a graphical desktop to session sandboxes (#3245) 2026-09-14 20:37:37 +08:00
useSandboxTerminal.ts feat(sandbox): unify the interactive PTY prompt and reconnect running sandboxes (#3128) 2026-09-09 18:17:10 +08:00
useSessionTitleMotion.ts fix(ui): 优化对话布局、导航与产物和引用展示 (#3427) 2026-09-19 19:25:52 +08:00
useSkillInstallerModel.test.ts refactor(frontend): share skill installer model configuration 2026-09-16 20:58:03 +08:00
useSkillInstallerModel.ts refactor(frontend): share skill installer model configuration 2026-09-16 20:58:03 +08:00
useStickyBottomOnResize.test.ts fix(ui): 优化对话布局、导航与产物和引用展示 (#3427) 2026-09-19 19:25:52 +08:00
useStickyBottomOnResize.ts fix(ui): 优化对话布局、导航与产物和引用展示 (#3427) 2026-09-19 19:25:52 +08:00
useTagChipsOverflow.ts fix(knowledge): harden multi-tag data integrity and UX follow-ups 2026-06-26 10:52:52 +08:00
useTenantModelReadiness.ts refactor(frontend): streamline knowledge base and agent handling with chat resources store 2026-06-09 18:05:33 +08:00
useTheme.ts fix(frontend): drop infectious preference fallback, add migration latch 2026-05-05 00:48:40 +08:00
useTypewriter.test.ts feat(agent): unify sandbox tools and drop host preloaded skills (#3033) 2026-09-05 16:45:59 +08:00
useTypewriter.ts feat(agent): unify sandbox tools and drop host preloaded skills (#3033) 2026-09-05 16:45:59 +08:00