Skip to content

fix(chat): preserve final answers after tool calls - #55

Closed
1052326311 wants to merge 7 commits into
doable-me:mainfrom
1052326311:fix/final-answer-after-tools
Closed

1052326311 wants to merge 7 commits into
doable-me:mainfrom
1052326311:fix/final-answer-after-tools

Conversation

@1052326311

@1052326311 1052326311 commented Sep 30, 2026 •

Copy link
Copy Markdown

Problem

A read-only request such as “inspect the project files, then describe the app” completes its tools but shows no visible answer. The final ordinary-text segment is provisionally stored as thinking, and the end-of-stream branch only promotes it when hadToolCalls is false. A reproduced turn persisted zero content characters and 286 thinking characters.

Change

Promote the final provisional ordinary-text segment after successful completion even when earlier segments invoked tools. Preserve explicit reasoning and tool-confirmed intermediate text, leave deferred-error segments alone, and use the existing thinking_to_text SSE event. Remove the exact buffered segment instead of blindly trimming the thinking suffix. Preserve thinking markers until the channel router classifies them, and track complete-message catch-up offsets per SDK message so earlier reasoning cannot swallow a later non-streamed answer. Offsets use raw SDK text before sanitization, preventing repeated tails when a split term such as package.json expands only in the complete message.

Validation

  • Seven focused regression tests pass, covering post-tool answers, direct answers, explicit reasoning, deferred errors, trailing native reasoning, prior content, and conservative handling of unmatched text.
  • Seven event-processor integration tests pass in the production dependency environment, covering SDK tool round-trips, tagged reasoning, subsequent tools, complete-only final text, split thinking markers, and catch-up offsets when sanitization changes text length.
  • Existing Supabase/MCP recovery guards: three tests pass.
  • Full API type-check in the production dependency environment reports 11 pre-existing errors in src/index.ts and src/routes/preview-proxy/proxy-handler.ts (the affected source is unchanged from main); no changed reply module reports an error. This is not a clean full type-check.
  • Official Docker production API build passed. The final 17 tests also pass in an isolated container using the production dependencies.
  • Real-provider read-only browser validation passed: the model read a project file, the final ordinary answer arrived through thinking_to_text, onDone fired, and the answer remained visible after reauthentication/history reload. The persisted record has 185 content characters, 26 reasoning characters, and tool calls; its final marker occurs once.
  • An independent Chromium HTTP/2 PING transport failure was observed during deployment validation. A site-local HTTP/1.1 compatibility setting restored a clean live SSE run; this environment-specific setting is deliberately excluded from the PR. Multi-user collaboration and broader provider coverage have not been manually exercised.

No automatic history migration is included in this change.

@1052326311

Copy link
Copy Markdown
Author

Superseded by #59, which consolidates this final-response fix with the related lifecycle/session repairs in one clean commit. Closing this duplicate to avoid overlapping merges.

@1052326311 1052326311 closed this Oct 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant