Skip to content

fix(shannon-worker): strip markdown fences when parsing result_val#32

Open
peteromallet wants to merge 1 commit into
mainfrom
fix/shannon-strip-markdown-fences
Open

fix(shannon-worker): strip markdown fences when parsing result_val#32
peteromallet wants to merge 1 commit into
mainfrom
fix/shannon-strip-markdown-fences

Conversation

@peteromallet
Copy link
Copy Markdown
Owner

Summary

  • Claude commonly wraps structured JSON in ```json … ``` markdown fences. _parse_shannon_output was calling strict json.loads on the trailing type=result event's result field and silently continueing on JSONDecodeError, so fenced responses fell through and surfaced downstream as parse_error: <step> output missing required keys: plan.
  • Fall back to _extract_json_object on JSONDecodeError at all three call sites: the type=result loop, the assistant-message result field, and the assistant-message content-block text path.
  • Add _extract_json_object helper in shannon_worker.py that uses raw_decode from 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_flag fails on baseline main too when run in isolation; unrelated to this change).
  • New regression tests cover all three call sites:
    • test_parse_shannon_output_result_event_markdown_fenced_json (trailing result event)
    • test_parse_shannon_output_assistant_message_markdown_fenced_json (assistant result field)
    • test_parse_shannon_output_assistant_content_block_fenced_json (assistant content-block text)

Branched off main, independent of #31.

🤖 Generated with Claude Code

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant