fix: adversarial review round 5 — release v0.1.7#9
Merged
Conversation
Address all findings from the round-5 review of v0.1.6: - Compaction: summary is now always a :user message (valid as the first Anthropic message), merged into the first preserved message when that is also :user to avoid consecutive same-role messages; empty preserved window yields a lone :user summary. Removed the unreachable mirror-case branch. - BaseProvider: stop retrying deterministic ProviderError (raised during request construction); ApiError/RateLimitError/TimeoutError still retry. - Loop: rebuild ToolCalls with symbol-keyed arguments so hooks, events, tool_calls_made, and the tool block all observe the same shape. Removed the dead streamed_content accumulator. - Anthropic: guard streaming finish_reason against a trailing message_delta with no stop_reason clobbering it to nil. - Gemini: coerce finishReason via to_s before downcase on both paths. - Fallback: correct the stale class docstring (direct streaming, not buffering). Verified env.status is available in faraday-net_http 3.3.0 on_data, so the streaming error_body recovery needs no change. Regression specs added in spec/ruby_pi/fixes/review_round5_spec.rb and spec/ruby_pi/agent/loop_spec.rb; updated two compaction specs that encoded the old :assistant-first behavior. Full suite: 470 examples, 0 failures. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Addresses all findings from the round-5 code review of v0.1.6. Each fix has a regression test; the full suite passes (470 examples, 0 failures).
:assistantfirst message → Anthropic HTTP 400 ("first message must use the 'user' role") whenever the first preserved message was:useror the preserved window emptied:user; merged into the first preserved message when that is also:user(no consecutive same-role); empty window → lone:usersummary. Extracted toCompaction#build_compacted_historywhileguaranteespreserved.firstis never:tool)droppable.empty?guardProviderError(missingtool_call_id, invalid arg JSON — raised before any HTTP call) was retried through the backoff scheduleProviderErrorfrom the retry set; Fallback failover unaffected (rescues theRubyPi::Errorsuperclass)before_tool_call/after_tool_callhooks saw string-keyed args while events &tool_calls_madesaw symbol keysLoop#actrebuilds eachToolCallwith symbol-keyed args once, so all consumers agreefinish_reasonclobbered to nil by a trailingmessage_deltawith nostop_reasonfinishReason.downcaseassumed a Stringto_s, now consistentstreamed_contentaccumulator + inaccurate comment inLoop#think:provider_fallbackevent still firesFallbackclass docstring still described removed happy-path buffering:fallback_startInvestigated, no change
Streaming error bodies via
env.status— verified against the actual stack (faraday 2.14.1 / faraday-net_http 3.3.0): the net_http adapter callssave_http_response(setsenv.status) beforeresponse.read_bodystreams chunks, andEnv#stream_responsepasses that same populatedenvto theon_dataproc.env.statusis reliably available before the first chunk, so the existingerror_bodyrecovery works. No fix needed — documented in CHANGELOG.Testing
spec/ruby_pi/fixes/review_round5_spec.rb(9 examples) covering compaction ordering/merge/empty-window, retry policy (incl. anApiError-still-retries control), Anthropicfinish_reason, and GeminifinishReasonrobustness.spec/ruby_pi/agent/loop_spec.rb.compaction_specexamples that encoded the old:assistant-first behavior.bundle exec rspec→ 470 examples, 0 failures.🤖 Generated with Claude Code