GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||
GeezerVison is showing github.com — providers: surface non-normal terminal turns instead of silent empty completions by gnanam1990 · Pull Request #263 · Twigpine/zero Conversation
|
| Adapter | Bug | Fix |
|---|---|---|
| Responses (codex) | A tool call with output_index 0 and no item_id had its argument deltas dropped — the tool ran with empty/partial JSON. output_index was an int, so a real 0 was indistinguishable from "absent". |
output_index is now a *int; toolCallKey keys on it even when 0. |
| Responses (codex) | response.failed / response.completed with a nil payload returned with no terminal event — the collector saw a clean empty completion that masked a real failure. |
failed emits StreamEventError, completed emits StreamEventDone. |
| Gemini | Terminal finishReasons (RECITATION, MALFORMED_FUNCTION_CALL, IMAGE_SAFETY, OTHER, LANGUAGE, UNEXPECTED_TOOL_CALL) mapped to a normal stop → silent empty/truncated turn. |
Safety reasons → content_filter; remaining non-STOP reasons surface the raw reason so the "ended early (…)" notice fires. Only ""/STOP/FINISH_REASON_UNSPECIFIED are normal. |
| Anthropic | stop_reason: refusal treated as a normal completion → silent empty turn. |
refusal → content_filter. |
TestToolCallKeyOutputIndexZero, TestHandleTerminalResponseNilPayload, TestMapFinishReasonNonNormal, TestMapStopReasonRefusal.
go build ./..., go vet ./..., gofmt, and the full go test ./... are all green.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…completions Four stream-adapter cases where a non-normal turn was treated as a clean empty completion, hiding the real outcome. Each ships a regression test. - openai/codex: a tool call arriving with output_index 0 and no item_id had its argument deltas dropped (the call dispatched with empty JSON). output_index is now a *int so a real 0 is distinguishable from absent. - openai/codex: response.failed / response.completed with a nil payload returned silently with no terminal event; now failed emits an error and completed emits done, so a failure is never masked as an empty success. - gemini: terminal finishReasons (RECITATION, MALFORMED_FUNCTION_CALL, IMAGE_SAFETY, OTHER, LANGUAGE, UNEXPECTED_TOOL_CALL) were treated as a normal stop; safety reasons now map to content_filter and the rest surface the raw reason so the truncation notice fires. - anthropic: stop_reason "refusal" was treated as a normal completion; it now maps to content_filter.
There was an error while loading. Please reload this page.
ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Free Run ID: 📒 Files selected for processing (2)
WalkthroughThree provider-level correctness fixes: Anthropic's ChangesProvider finish/stop reason fixes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Note 🎁 Summarized by CodeRabbit FreeYour organization is on the Free plan. CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please upgrade your subscription to CodeRabbit Pro by visiting https://app.coderabbit.ai/login. Comment |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Zero automated PR reviewVerdict: No blockers found Blockers
Validation
ScopeHead: This deterministic review checks validation status and basic diff hygiene. A human reviewer still owns product judgment and design quality. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
The core fixes are sound and well-motivated. Three real bugs are addressed:
OutputIndex was a plain int defaulting to 0, so a no-item_id call with output_index: 0 was dropped (the > 0 guard rejected it). Switching to *int distinguishes "absent" from a real first-output zero — correct fix, and toolCallKey now keys on it. Good unit coverage in TestToolCallKeyOutputIndexZero.handleTerminalResponse returned silently when event.Response == nil, so a response.failed with no payload became a clean-looking empty completion. Now it emits StreamEventError for failed and a clean Done for completed. Correct, and the test in TestHandleTerminalResponseNilPayload covers both branches.RECITATION, IMAGE_SAFETY for Gemini; refusal for Anthropic) were collapsed to "" (clean completion). Now Gemini surfaces the raw reason for anything not in the normal set, and Anthropic maps refusal to content_filter. Both are correct and align with TruncationNotice's "Response ended early ()" rendering.P1 — None. No correctness, security, or data-loss issues in the diff.
P2
responsesEvent struct — internal/providers/openai/codex_responses.go:118-121. The PR changes OutputIndex from int to *int, which shifts the alignment column, but ItemID's tag was not re-aligned. gofmt -d flags this:
- ItemID string `json:"item_id,omitempty"`
+ ItemID string `json:"item_id,omitempty"`
gofmt -l / lint in CI. The other struct lines (OutputIndex, Item) are already misaligned in the same way in the PR snippet, so the whole block needs re-running through gofmt -w. (I verified by reconstructing the changed struct and running gofmt -d — it wants ItemID string with the extra padding to match the new widest type *int/*itemPayload.)P3
Gemini: significant end-to-end test coverage is deleted and not replaced — internal/providers/gemini/finish_reason_test.go. The PR replaces 145 lines with a single unit test (TestMapFinishReasonNonNormal) of mapFinishReason only. This deletes:
TestStreamCompletionSurfacesMaxTokensFinishReasonTestStreamCompletionSurfacesSafetyFinishReasonTestStreamCompletionNormalFinishReasonHasNoReasonTestStreamCompletionEmitsDroppedOnNamelessFunctionCallPartTestStreamCompletionEmitsDroppedOnNamelessTopLevelFunctionCallTestStreamCompletionDoesNotDropValidFunctionCallThe new unit test covers mapFinishReason in isolation, but the deleted tests verified the full SSE → streamState.finishReason → Done event wiring. The M3 change widens mapFinishReason's default branch to return the raw reason, and that new behavior is exercised by the unit test — but the integration path (does a RECITATION candidate actually reach the Done event's FinishReason?) is now untested. The three ToolCallDropped tests are orthogonal to this PR's goal and their deletion removes the only coverage for the nameless-functionCall drop behavior in the Gemini provider (the production code in provider.go:248 and provider.go:265 is unchanged, so this is a net loss of coverage rather than a behavior regression). Recommendation: keep TestMapFinishReasonNonNormal and restore at least the three dropped-tool-call tests (they belong to a different feature and shouldn't ride along with this PR); consider restoring the finish-reason integration tests too, or moving them to a streaming-test file if the file name was the issue.
Anthropic: mapStopReason comment lists pause_turn as normal without verification — internal/providers/anthropic/provider.go:607. The new default-branch comment says pause_turn (and "") are normal. The test asserts this, but there's no citation to Anthropic's API docs that pause_turn is a non-terminal/normal reason. If pause_turn is actually an early-stop signal (e.g. for the new pause-and-resume feature), collapsing it to "" would re-introduce the silent-empty-completion bug this PR is fixing. Worth a quick doc/link confirmation, or dropping it from the "normal" list until confirmed.
Codex M2: response.incomplete is not a terminal event here — internal/providers/openai/codex_responses.go:494 routes only response.completed/response.failed to handleTerminalResponse; response.incomplete falls through to the default (ignored) branch. That's pre-existing behavior, but the PR's M2 comment frames the nil-payload fix as closing the "silent empty completion" hole — response.incomplete with a nil Response payload would still be silently ignored. Out of scope for this PR, but worth a follow-up note since the PR title is broad ("non-normal terminal turns").
gofmt -w internal/providers/openai/codex_responses.go and re-check the struct alignment (P2 #1).ToolCallDropped tests (P3 #2) — they're unrelated to this PR's goal and shouldn't be deleted.pause_turn being normal, or drop it from the comment (P3 #3).Overall this is a good, focused fix; the blocking item is the gofmt issue, the rest are nits/coverage observations.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…ause_turn Review follow-ups on the provider silent-failure fixes: - Gemini: restore the end-to-end finish-reason and dropped-tool-call tests that the earlier refactor removed, alongside the mapFinishReason unit test. This re-covers the full SSE -> done-event wiring (MAX_TOKENS -> length, SAFETY -> content_filter, normal STOP -> "") and the nameless-functionCall drop signal, and adds a RECITATION integration test that exercises the M3 widening through the streaming path (not just mapFinishReason in isolation). - Anthropic: document why pause_turn is classified as a normal stop — it is the long-running-turn pause (server-side tools) the client resumes by sending the response back, not a truncation/refusal, so it correctly maps to "" rather than firing a spurious truncation notice. gofmt/vet/build clean; gemini/anthropic/openai suites pass.
|
Thanks for the thorough review — addressed in P2 (gofmt — P3 #2 (deleted Gemini coverage) — restored. Brought back all six tests the refactor dropped, alongside the
And added P3 #3 ( P3 #4 ( gofmt/vet/build clean; gemini/anthropic/openai suites green. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…object A response.failed terminal event carrying a non-nil Response whose `error` object is null/omitted (the backend can report the failure only via `status`) fell through to a clean StreamEventDone — reporting a real failure as a normal successful turn. Only the nil-payload path was guarded. Branch on the failed terminal (event type / Response.Status) before the clean-done fallthrough and emit StreamEventError. Adds a regression test for the non-nil-payload-without- error case (verified to fail without the fix).
|
Follow-up hardening from a self-review pass ( |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Re-reviewed after 8efb611 ("address review: restore Gemini tests; justify pause_turn"). All three items from my prior CHANGES_REQUESTED are resolved, and a new-issue scan found nothing blocking. Approving.
gofmt -l is clean on internal/providers/openai/codex_responses.go; the doc comment on OutputIndex correctly breaks the alignment block so OutputIndex *int / Item *itemPayload align as their own group.TestMapFinishReasonNonNormal, TestStreamCompletionSurfacesRecitationFinishReason, and the SSE-wired RECITATION integration test). Coverage is strictly better than main.anthropic/provider.go now explains pause_turn is Anthropic's long-running-turn pause for server-side tools (client resumes by sending the response back — not a truncation/refusal), so mapping it to "" correctly avoids a spurious truncation notice. TestMapStopReasonRefusal pins pause_turn → "".OutputIndex int → *int change is internally consistent: toolCallKey keys on *event.OutputIndex directly and drops the old +1 offset (the offset only existed to reserve 0 for "absent", which nil now expresses). TestToolCallKeyOutputIndexZero covers 0 / 2 / absent / item_id-precedence.default: return reason is safe end-to-end — it sets state.finishReason → Done event → Result.TruncationNotice(), surfaced in exec + TUI; no raw enum leaks improperly.response.failed (emits StreamEventError) from response.completed (clean Done); TestHandleTerminalResponseNilPayload covers both.Thanks for the thorough turnaround on the feedback — this is a clean, well-tested fix.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.