Bug
The mapStopReason function in @mariozechner/pi-ai (providers/openai-completions.js) throws on unrecognized finish_reason values:
default: {
const _exhaustive = reason;
throw new Error(`Unhandled stop reason: ${_exhaustive}`);
}
Z.AI's GLM-5 model (OpenAI-compatible API at api.z.ai) returns a non-standard finish_reason value not in the handled set (stop, length, tool_calls, function_call, content_filter). This causes the function to throw even though the model response content streamed successfully.
Impact
Every GLM-5 completion triggers an Unhandled stop reason: abort error visible to the end user. The content still arrives (streams before finish_reason), but the thrown error propagates and gets displayed.
Suggested Fix
Map unknown stop reasons to "stop" instead of throwing:
default: {
return "stop";
}
Non-standard providers using the OpenAI-compatible API should degrade gracefully.
Workaround
Manually patch the installed file:
sudo sed -i.bak 's/throw new Error(`Unhandled stop reason: ${_exhaustive}`);/return "stop";/' node_modules/@mariozechner/pi-ai/dist/providers/openai-completions.js
Environment
@mariozechner/pi-ai v0.52.10
- Provider: Z.AI GLM-5 (
openai-completions API mode)
- OpenClaw v2026.2.13
Note: badlogic/pi-mono has issues disabled, filing here instead.
Bug
The
mapStopReasonfunction in@mariozechner/pi-ai(providers/openai-completions.js) throws on unrecognizedfinish_reasonvalues:Z.AI's GLM-5 model (OpenAI-compatible API at
api.z.ai) returns a non-standardfinish_reasonvalue not in the handled set (stop,length,tool_calls,function_call,content_filter). This causes the function to throw even though the model response content streamed successfully.Impact
Every GLM-5 completion triggers an
Unhandled stop reason: aborterror visible to the end user. The content still arrives (streams before finish_reason), but the thrown error propagates and gets displayed.Suggested Fix
Map unknown stop reasons to
"stop"instead of throwing:Non-standard providers using the OpenAI-compatible API should degrade gracefully.
Workaround
Manually patch the installed file:
sudo sed -i.bak 's/throw new Error(`Unhandled stop reason: ${_exhaustive}`);/return "stop";/' node_modules/@mariozechner/pi-ai/dist/providers/openai-completions.jsEnvironment
@mariozechner/pi-aiv0.52.10openai-completionsAPI mode)Note:
badlogic/pi-monohas issues disabled, filing here instead.