Skip to content

fix(#380): tolerate Claude harness output-scan markers in strict JSON gates#381

Merged
azalio merged 1 commit into
mainfrom
claude/compassionate-cerf-ooawte
Jul 22, 2026
Merged

fix(#380): tolerate Claude harness output-scan markers in strict JSON gates#381
azalio merged 1 commit into
mainfrom
claude/compassionate-cerf-ooawte

Conversation

@azalio

@azalio azalio commented Jul 22, 2026

Copy link
Copy Markdown
Owner

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_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 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 it
  • detect_truncated_agent_output — calls the helper before JSON parsing (after the empty-response check); adds harness_markers_stripped: list[str] to every return dict so the event is observable
  • 6 new regression tests covering: monitor + actor payloads with a harness marker, multiple markers, arbitrary prose still rejected, marker followed by trailing prose still rejected, clean JSON produces empty list
  • make render-templates propagated 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 clean
  • make check-render — generated trees match source

Generated by Claude Code

Summary by CodeRabbit

  • Bug Fixes

    • Improved parsing of agent responses that begin with recognized harness marker lines.
    • Prevented valid JSON responses from being incorrectly flagged as truncated when these markers are present.
    • Continued to flag unexpected leading prose as malformed or truncated.
  • Tests

    • Added coverage for single and repeated harness markers, valid responses, and invalid leading text.
    • Responses now report which harness markers were removed during processing.

… 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
@azalio
azalio merged commit 1bf45c9 into main Jul 22, 2026
1 of 2 checks passed
@coderabbitai

coderabbitai Bot commented Jul 22, 2026

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 842fe378-0258-4aa5-9380-17227c9f2966

📥 Commits

Reviewing files that changed from the base of the PR and between cd00d02 and aa9fdf2.

📒 Files selected for processing (4)
  • .map/scripts/map_step_runner.py
  • src/mapify_cli/templates/map/scripts/map_step_runner.py
  • src/mapify_cli/templates_src/map/scripts/map_step_runner.py.jinja
  • tests/test_map_step_runner.py

📝 Walkthrough

Walkthrough

Changes

Harness marker tolerance

Layer / File(s) Summary
Marker normalization and result propagation
.map/scripts/map_step_runner.py, src/mapify_cli/templates/..., src/mapify_cli/templates_src/...
Leading Claude harness marker lines are stripped before JSON parsing, recorded in harness_markers_stripped, and propagated through detector return paths.
Marker parsing regression coverage
tests/test_map_step_runner.py
Tests cover valid JSON with one or more markers, clean JSON, and rejection of arbitrary leading prose.

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
Loading

Poem

I’m a rabbit with markers tucked neatly away,
JSON hops through the gate without delay.
Prose still gets stopped at the strict little door,
Clean results report what was stripped before.
Thump-thump—tests keep the contract in store!

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/compassionate-cerf-ooawte

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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.

[Claude sub-agents] Tolerate harness output-scan markers in strict JSON gates

2 participants