Skip to content

fix: 模型输出被截断时不再标记为转换成功 (#87) - #90

Merged
haywolf merged 1 commit into
masterfrom
fix/87-truncation-status
Nov 5, 2026
Merged

haywolf merged 1 commit into
masterfrom
fix/87-truncation-status

Conversation

@haywolf

@haywolf haywolf commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

Fixes #87

改动

  • 在 LLMClient 基类里统一映射截断原因(length / max_tokens / MAX_TOKENS 等统一为 FINISH_REASON_TRUNCATED);五类客户端(OpenAI、Anthropic、Gemini、Ollama、OpenAI Responses)都改为读取真实的结束原因,不再写死 stop
  • Ollama 读取 done_reason;Responses 客户端读取 incomplete_details.reason,流式处理 response.incomplete
  • ConverterWorker 检测到截断时抛错,走现有的重试和失败流程:页面标记为 FAILED 并写入错误原因,部分内容不保存
  • 客户端本身不抛错,连接测试(maxTokens: 8)不受影响

测试

  • 新增 43 个用例:FinishReason.test.ts(五类客户端,流式和非流式)、ConverterWorker.test.ts、completion.handler.test.ts
  • npm run test:unit:50 个文件,1069 个用例全部通过
  • npm run typecheck、eslint:通过
  • 变异检查:撤掉 Worker 判断、基类映射或 Ollama 的 done_reason 读取后,都有对应测试失败

行为变化

  • 截断的页面会先重试 3 次,仍截断才判为失败,会多消耗 token
  • 以前“成功”但实际被截断的任务,现在会显示为部分失败,建议写进发版说明

未验证项

  • 没有连接真实服务商,只用 mock fetch 验证
  • 没有启动 Electron 界面实际查看失败提示,界面沿用现有的失败页 Tooltip

A page cut off by the output token limit was marked as converted, so the
user got incomplete Markdown with nothing in the UI to show it. Ollama
always reported `stop`, and ConverterWorker never read finishReason.

- Report truncation with one value, FINISH_REASON_TRUNCATED, from all five
  clients (length / max_tokens / MAX_TOKENS / max_output_tokens). Other
  reasons pass through as before.
- Read the reason the Responses API really uses, incomplete_details.reason,
  including the response.incomplete stream event.
- ConverterWorker treats truncation as a retryable failure, so the reason
  reaches the existing page and task error display.
- Clients don't throw on truncation, so the connection test with
  maxTokens: 8 keeps working.
@haywolf
haywolf merged commit 627efc7 into master Nov 5, 2026
2 checks passed
@haywolf
haywolf deleted the fix/87-truncation-status branch November 5, 2026 01:47
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.

模型输出被截断(length/max_tokens)时页面仍标记为转换成功

1 participant