Skip to content

fix(responses): show GLM-5.3 thinking from its reasoning item - #225

Merged
pierreraby merged 1 commit into
mainfrom
fix/glm53-reasoning
Nov 17, 2026
Merged

pierreraby merged 1 commit into
mainfrom
fix/glm53-reasoning

Conversation

@pierreraby

Copy link
Copy Markdown
Collaborator

Summary

Show the zai-org/GLM-5.3 thinking that the Provider API returns but never streams.

The model emits no response.reasoning*.delta event. Its whole chain of thought arrives as plaintext encrypted_content on the reasoning output item at response.output_item.done, with summary: []. The host keeps that field only as a replay signature, so the content was received and never displayed. This PR rewrites the completed item into a canonical response.reasoning_text.delta before it reaches the host.

Fixes the behaviour reported in #221. The issue stays open until a release ships the fix.

Live evidence (2026-11-17)

Two bounded /provider/v1/responses requests, reasoning.effort = high and max, max_output_tokens = 512, cost about $0.0025 total. Both returned HTTP 200:

Effort Reasoning deltas Reasoning item content Tokens
high 0 63 characters of plaintext chain of thought 166 out / 31 reasoning
max 0 725 characters of plaintext chain of thought 388 out / 254 reasoning

Control: mistral/mistral-large-4 on the same endpoint emitted 106 response.reasoning.delta events, which the existing normalizer already handles. The transport is not the cause.

Behaviour and risk

  • The rewrite is gated per model (PLAINTEXT_REASONING_CONTENT_MODELS). For OpenAI models the same field holds real ciphertext, so it must stay invisible; the compat test pins mistral/mistral-large-4, z-ai/glm-5.3-flash and z-ai/glm-5.3-flashx as opt-out until a capture proves the shape for them.
  • No rewrite when the item already carries summary or content, or when that output_index already streamed reasoning text, so a canonical stream cannot be duplicated.
  • The injected frame keeps the stream's line endings; the original frame is emitted unchanged after it.
  • No change to request bodies, endpoint routing, prices or model metadata.

Validation

  • Replay of the two real captures through pi-ai 1.5.2: 0 characters of thinking before the change, 63 and 725 after, with the expected thinking_end content and a clean done event.
  • npm test with both hosts required (PI_LOCAL_REQUIRED=1 OMP_REQUIRED=1): PASS, including 5 new transport cases and 1 new compat case.
  • typecheck and typecheck:entrypoint against installed Pi 1.5.2 declarations: PASS.
  • format:check, git diff --check: PASS. No workflow files touched.

Authorization boundary

This PR is code only. No release, tag, npm publication or production installation is included; a 0.8.6 release stays separately authorized. The live probes above were explicitly authorized and bounded; no other paid checks were run.

The Provider API returns the zai-org/GLM-5.3 chain of thought only as
plaintext `encrypted_content` on the completed reasoning item, with an
empty `summary` and no reasoning delta. pi-ai keeps that field as a replay
signature and renders nothing, so the thinking was received and never
shown.

Rewrite the completed reasoning item into a canonical
`response.reasoning_text.delta` before it reaches the host, gated per
model because other providers use the same field for real ciphertext. Skip
the rewrite when the item carries a summary or content, or when that output
index already streamed reasoning text.

Live evidence: two /responses requests on 2026-11-17 at effort high and max
returned no reasoning delta and 63/725 characters of plaintext item
content. Replaying those captures through pi-ai 1.5.2 yields 0 characters
of thinking before this change and the exact text after it.

Refs #221.
@github-actions

Copy link
Copy Markdown
Contributor

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

@github-actions

Copy link
Copy Markdown
Contributor

Memory benchmark

Compared base b3555ad with PR head 0c5fa52 on the same GitHub-hosted darwin runner. Lower values are better.

Metric Base PR PR − Base Change
Stable RSS 107.0 MiB ± 0.5 MiB 106.9 MiB ± 1.1 MiB -0.4 MiB ± 1.0 MiB -0.4%
Physical footprint 60.7 MiB ± 0.5 MiB 61.0 MiB ± 0.7 MiB +0.4 MiB ± 1.0 MiB +0.7%
Physical peak 72.5 MiB ± 0.6 MiB 72.5 MiB ± 1.8 MiB +0.1 MiB ± 1.4 MiB +0.1%

Interpretation: No metric shows a clear Base-to-PR difference beyond its measured run-to-run variation.

Extension overhead above pi baseline

Metric Base overhead PR overhead Difference
Stable RSS +5.8 MiB ± 0.6 MiB +5.6 MiB ± 0.4 MiB -0.4 MiB ± 1.0 MiB
Physical footprint +2.9 MiB ± 0.8 MiB +3.3 MiB ± 0.5 MiB +0.4 MiB ± 1.0 MiB
Physical peak +3.7 MiB ± 0.7 MiB +3.6 MiB ± 1.1 MiB +0.1 MiB ± 1.4 MiB

Values are medians of 6 alternating, paired runs. The value after ± is the median absolute deviation (MAD). Each process was sampled 12 times after a 2500 ms warm-up.

Environment: pi 0.84.4, Bun 1.4.4, darwin arm64. RSS comes from ps; physical footprint and peak come from macOS footprint.

This is a comparative signal, not a pass/fail threshold. GitHub-hosted runner noise can affect absolute values.

@pierreraby
pierreraby merged commit 8597c79 into main Nov 17, 2026
13 checks passed
@pierreraby
pierreraby deleted the fix/glm53-reasoning branch November 17, 2026 12:33
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