fix(shannon-worker): strip markdown fences when parsing result_val#32
Open
peteromallet wants to merge 1 commit into
Open
fix(shannon-worker): strip markdown fences when parsing result_val#32peteromallet wants to merge 1 commit into
peteromallet wants to merge 1 commit into
Conversation
Claude commonly wraps structured JSON in ```json ... ``` markdown fences.
_parse_shannon_output used strict json.loads on the result field and
swallowed JSONDecodeError with `continue`, so fenced responses silently
fell through and surfaced as "parse_error: <step> output missing required
keys" downstream.
Fall back to _extract_json_object on JSONDecodeError at all three call
sites (result-event loop, assistant-message result field, content-block
text). _extract_json_object is a small helper added alongside the parser
that handles the fenced shape (via raw_decode from the first `{`) as
well as the prose-before-JSON and JSON-then-trailing-prose cases.
Add regression tests covering all three call sites for the fenced case.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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
```json … ```markdown fences._parse_shannon_outputwas calling strictjson.loadson the trailingtype=resultevent'sresultfield and silentlycontinueing onJSONDecodeError, so fenced responses fell through and surfaced downstream asparse_error: <step> output missing required keys: plan._extract_json_objectonJSONDecodeErrorat all three call sites: thetype=resultloop, the assistant-messageresultfield, and the assistant-message content-block text path._extract_json_objecthelper inshannon_worker.pythat usesraw_decodefrom the first{to handle fenced JSON, prose-then-JSON, and JSON-then-trailing-prose cases.Test plan
pytest tests/test_workers.py -k 'shannon or parse'— 42 passed, 1 pre-existing flaky (test_run_shannon_step_passes_prompt_with_print_flagfails on baselinemaintoo when run in isolation; unrelated to this change).test_parse_shannon_output_result_event_markdown_fenced_json(trailingresultevent)test_parse_shannon_output_assistant_message_markdown_fenced_json(assistantresultfield)test_parse_shannon_output_assistant_content_block_fenced_json(assistant content-block text)Branched off
main, independent of #31.🤖 Generated with Claude Code