Skip to content

fix: Qwen Coder responses not rendering — enhance stream-json parser#59

Open
algojogacor wants to merge 1 commit into
nexu-io:mainfrom
algojogacor:fix/qwen-coder-response-rendering
Open

fix: Qwen Coder responses not rendering — enhance stream-json parser#59
algojogacor wants to merge 1 commit into
nexu-io:mainfrom
algojogacor:fix/qwen-coder-response-rendering

Conversation

@algojogacor
Copy link
Copy Markdown

Summary

The Qwen Coder parser in parseLineWithState shared a minimal code path with opencode that only matched bare text/content/message string fields. Qwen Coder actually outputs a stream-json envelope like Claude (stream_event with content_block_delta/text_delta, assistant messages with tool_use, result with usage metadata). Every structured JSON line was classified as noise and never filled into the source panel — responses only appeared in the log pane.

Root Cause

The agent === "opencode" || agent === "qwen" condition in the parser meant Qwen got the same minimal parsing as opencode, which only handles flat string fields. Qwen Coder's default output format is stream-json with nested structured objects, so the parser's JSON.parse succeeded but none of the field checks matched, returning { kind: "noise" } for every line.

What was fixed

Separated Qwen into its own parser block that handles:

  • stream_eventcontent_block_delta / text_delta (fine-grained streaming text)
  • stream_eventcontent_block_delta / thinking_delta (thinking metadata)
  • assistant message with tool_use rescue (HTML from Write/create_file tools)
  • assistant message text content (fallback when no stream deltas seen)
  • result with usage/duration_ms/total_cost_usd metadata
  • Bare text/content/message fields as a last-resort fallback

Testing Done

  • Verified the change compiles with the existing TypeScript configuration
  • The parser now handles the same JSON envelope shapes as the Claude and Qoder parsers
  • Falls back gracefully to bare field extraction when structured content is absent
  • No changes to opencode parsing behavior (separated into its own condition)

Related

Fixes #58
Closes #58

The Qwen parser only matched bare text/content/message string fields.
Qwen Coder actually outputs stream-json (stream_event with text_delta,
assistant messages with tool_use) so structured JSON was classified
as noise and never filled into the source panel. Fixes nexu-io#58
@lefarcen lefarcen requested a review from Siri-Ray May 18, 2026 07:03
@lefarcen lefarcen added size/S Small change: 20-99 changed lines risk/medium Medium risk change type/bugfix Bug fix labels May 18, 2026
@PerishCode
Copy link
Copy Markdown
Contributor

Thanks for the PR. I checked the current main shape, and I am not going to patch this branch directly yet because this touches the agent stdout parser. That path is easy to regress across agents, so the rebase should land with focused fixtures rather than only a mechanical path move.

Suggested migration to current main:

  • Move the parser change from src/lib/agents/argv.ts to next/src/lib/agents/argv.ts.
  • Add Vitest coverage under the Next package, for example next/src/lib/agents/argv.test.ts or next/src/lib/agents/__tests__/argv.test.ts.
  • Keep Qwen separate from opencode, and include fixtures for:
    • Qwen stream_event text deltas
    • Qwen assistant message text fallback
    • Qwen tool_use / file-write HTML rescue
    • Qwen result metadata
    • opencode flat text / content / message behavior staying unchanged

Recommended validation:

  • pnpm install --frozen-lockfile
  • pnpm exec tsx scripts/guard.ts
  • pnpm -F @html-anything/next typecheck
  • pnpm -F @html-anything/next test
  • pnpm -F @html-anything/next build

Once the parser fixtures are in place, this should be much easier to review and safely rebase onto the new workspace shape.

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

Labels

risk/medium Medium risk change size/S Small change: 20-99 changed lines type/bugfix Bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Qwen Coder返回的响应不能自动渲染,等于不可用

3 participants