test(parser): pin missing text/thinking field handling (#260) - #263
Open
delexw wants to merge 1 commit into
Open
test(parser): pin missing text/thinking field handling (#260)#263delexw wants to merge 1 commit into
delexw wants to merge 1 commit into
Conversation
Claude Code v2.1.234 confirmed that on the non-streaming fallback path
(typically via third-party gateways), a text content block can arrive
without its text field, or a thinking block without its thinking field.
Every call site that reads these fields (classify::extract_assistant_details,
sanitize::extract_text, session.rs, subagent.rs) already falls back to an
empty string via serde_json's get().and_then(as_str()).unwrap_or("")
pattern, so no panic is possible today. Add the regression tests the issue
requested to pin this guarantee, and document it in the parser pipeline spec.
Fixes #260
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
Fixes #260. Claude Code v2.1.234's release notes confirmed that, on the non-streaming fallback path (typically via third-party gateways), the API response can contain a
textcontent block missing itstextfield, or athinkingblock missing itsthinkingfield — Claude Code itself used to crash on this and now handles it gracefully.I audited every place in this parser that reads a content block's
textorthinkingfield (classify::extract_assistant_details,sanitize::extract_text, plussession.rsandsubagent.rs). All of them already read viaserde_json's.get("text"/"thinking").and_then(|v| v.as_str()).unwrap_or("")(or an equivalentif let), which defaults to an empty string when the field is absent. No struct anywhere requires these fields, and no code path panics on a missing one — so the crash scenario described in the issue cannot occur in this codebase today. No production code needed to change.This PR adds the regression tests the issue explicitly asked for, so the guarantee is now pinned by tests instead of only being an implicit property of the code, and documents it in
specs/01-parser-pipeline.md's version-compatibility table.Changes
src-tauri/src/parser/classify.rs:classify_text_block_missing_text_field_does_not_panic,classify_thinking_block_missing_thinking_field_does_not_panicsrc-tauri/src/parser/sanitize.rs:extract_text_block_missing_text_field_does_not_panic,extract_text_block_missing_text_field_alongside_real_textspecs/01-parser-pipeline.md: new row in the version-compatibility table for issue [Compat] Claude Code v2.1.234: text/thinking content blocks confirmed to sometimes miss their core field via gateways #260Test plan
npx vitest run— 498 passedcargo test --manifest-path src-tauri/Cargo.toml— 691 passed (including the 4 new tests)cargo clippy --manifest-path src-tauri/Cargo.toml -- -D warnings— cleancargo fmt --manifest-path src-tauri/Cargo.toml -- --check— cleannpx oxlint/npx oxfmt/npx tsc --noEmit— clean