fix(#380): tolerate Claude harness output-scan markers in strict JSON gates#381
Merged
Conversation
… gates Claude Code v2.1.210+ may prepend a marker line starting with "[harness: subagent output matched instruction-shaped pattern(s):" to a subagent report when the output matches instruction-shaped patterns. The payload itself is the original valid agent JSON. `detect_truncated_agent_output` previously treated any leading text as a "wrapped in prose" signal and returned `truncated: true`, causing valid Monitor / Predictor / Evaluator / Actor payloads to be rejected and wasting a retry (or stopping the workflow with a misleading error). Changes: - Add `_HARNESS_MARKER_PREFIX` constant documenting the exact marker form - Add `_strip_harness_markers(text)` helper that removes only lines whose stripped form starts with that prefix; arbitrary prose is left intact - Call the helper inside `detect_truncated_agent_output` before JSON parsing, after the empty-response check - Add `harness_markers_stripped: list[str]` to every return dict so the event is observable downstream - 6 new regression tests covering: monitor + actor payloads with a harness marker, multiple markers, arbitrary prose still rejected, marker + trailing prose still rejected, clean JSON has empty list - Run `make render-templates` to propagate to all generated trees Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VpTee1uc3iXXeGZspqkkNh
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
📝 WalkthroughWalkthroughChangesHarness marker tolerance
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant AgentOutput
participant detect_truncated_agent_output
participant _strip_harness_markers
participant JSONParser
AgentOutput->>detect_truncated_agent_output: provide agent output
detect_truncated_agent_output->>_strip_harness_markers: strip leading harness markers
_strip_harness_markers-->>detect_truncated_agent_output: cleaned text and stripped markers
detect_truncated_agent_output->>JSONParser: parse cleaned text
JSONParser-->>detect_truncated_agent_output: parsed payload or validation result
detect_truncated_agent_output-->>AgentOutput: return truncation result and stripped markers
Poem
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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 #380.
Claude Code v2.1.210+ may prepend a marker line like
[harness: subagent output matched instruction-shaped pattern(s): ...]to a subagent report when the output matches instruction-shaped patterns. The payload itself is the original valid agent JSON.detect_truncated_agent_outputpreviously treated any leading text as a "wrapped in prose" signal and returnedtruncated: true, causing valid Monitor / Predictor / Evaluator / Actor payloads to be spuriously rejected — wasting a retry or stopping the workflow with a misleading JSON-format error.Changes
_HARNESS_MARKER_PREFIX— module-level constant documenting the exact documented marker form_strip_harness_markers(text)— helper that removes only lines whose stripped form starts with that prefix; arbitrary prose is left intact so the downstream parser still rejects itdetect_truncated_agent_output— calls the helper before JSON parsing (after the empty-response check); addsharness_markers_stripped: list[str]to every return dict so the event is observablemake render-templatespropagated the change to all generated trees (.map/scripts/,src/mapify_cli/templates/,.claude/dev copy)Test plan
pytest tests/test_map_step_runner.py::TestDetectTruncatedAgentOutput— 28/28 pass (22 existing + 6 new)make check— 3802 passed, 4 skipped, ruff/mypy/pyright all cleanmake check-render— generated trees match sourceGenerated by Claude Code
Summary by CodeRabbit
Bug Fixes
Tests