Skip to content

Loosen quote matching, unify JSON extraction, and add subagent visibility - #284

Merged
openshift-merge-bot[bot] merged 4 commits into
openshift-eng:mainfrom
redhat-chai-bot:feat/normalize-escapes-and-parse-helper
Sep 9, 2026
Merged

Loosen quote matching, unify JSON extraction, and add subagent visibility#284
openshift-merge-bot[bot] merged 4 commits into
openshift-eng:mainfrom
redhat-chai-bot:feat/normalize-escapes-and-parse-helper

Conversation

@redhat-chai-bot

Copy link
Copy Markdown
Contributor

Summary

Four targeted fixes addressing diagnostics issues observed in CI Doctor run
2097218638762217472.

Changes

1. Normalize escape sequences in quote matching (validate-rca-output.py)

validate_evidence() already normalizes whitespace and case before comparing
agent-cited quotes against log lines, but does not normalize escape sequences.
This causes false "quote not found" warnings when the agent cites \"probe failed\" but the log line has "probe failed" (or vice versa).

Added normalization for:

  • \"" (backslash-escaped double quotes)
  • \u201c / \u201d" (Unicode left/right double quotes)
  • \u2018 / \u2019' (Unicode left/right single quotes)

2. Add parse_json_output() helper (validate-rca-output.py)

New public function that tries json.loads() first, then falls back to
_try_extract_json_array() for prose-wrapped output. Returns a
(parsed_data, errors) tuple.

This consolidates the extraction logic that was previously split between the
hook (which used _try_extract_json_array fallback) and run-doctor.py
(which used bare json.loads with no fallback).

3. Use parse_json_output() in run-doctor.py

Replaced the bare json.loads(final_text) in _analyze_single_job() with the
new parse_json_output() helper. This fixes two issues:

  • Lost results: When agent output had prose preamble before the JSON array,
    json.loads() failed and the output file was never written — even though
    _try_extract_json_array() would have found valid JSON. Jobs
    2097173349762338816 and 2097173364866027520 were lost this way.
  • Validation gap: The stop hook allowed prose-wrapped JSON (via
    _try_extract_json_array), but the save path rejected it (via bare
    json.loads). Now both use the same extraction logic.

4. Add --forward-subagent-text to claude invocation (run-doctor.py)

Adds subagent text and thinking blocks to the parent transcript with
parent_tool_use_id set. This is safe because _extract_job_stats() already
filters by parent_tool_use_id when counting parent-level turns.

Benefits:

  • Diagnostics show the full picture (e.g. 52 subagent turns visible, not just
    "1 turn" for the orchestrator)
  • Subagent output is available in the transcript for fallback extraction
  • Debugging is easier without needing separate debug logs

Testing

  • Both .py files compile cleanly (py_compile)
  • Symlinked copies in plugins/microshift-ci/scripts/ also compile
  • parse_json_output tested with: valid JSON array, prose-wrapped JSON,
    non-JSON text, and dict (non-array)
  • validate_evidence quote normalization tested with: escaped double quotes,
    smart double quotes, and smart single quotes

AI-generated. Review for accuracy.

@pmtk requested in Slack thread

…parse_json_output helper

- validate_evidence: normalize \" → " and Unicode smart quotes
  (U+201C/U+201D → ", U+2018/U+2019 → ') before the quote-in-line
  check to eliminate false negatives from cosmetic quoting differences.
- Add public parse_json_output(text) that tries json.loads then falls
  back to _try_extract_json_array, returning (data, errors) tuple.
- run-doctor.py _analyze_single_job: replace bare json.loads with
  parse_json_output so the save path uses the same extraction logic
  as the validation hook.
- run-doctor.py _run_claude_session: add --forward-subagent-text flag
  (safe because _extract_job_stats already filters by parent_tool_use_id).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@openshift-ci openshift-ci Bot added the ready-for-human-review Indicates a PR has been reviewed by automated tools and is ready for human review label Sep 8, 2026
@coderabbitai

coderabbitai Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: Repository YAML (base), Central YAML (inherited)

Review profile: CHILL

Plan: Advanced

Run ID: bfcfe5dc-be82-493d-934c-730cccf05ba4


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

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
redhat-chai-bot and others added 2 commits September 8, 2026 13:06
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@pmtk

pmtk commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

/lgtm
/approve

@openshift-ci openshift-ci Bot added the lgtm Indicates that a PR is ready to be merged. label Sep 9, 2026
@openshift-ci

openshift-ci Bot commented Sep 9, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: pmtk, redhat-chai-bot

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci Bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Sep 9, 2026
@openshift-merge-bot
openshift-merge-bot Bot merged commit 4e9685e into openshift-eng:main Sep 9, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. ready-for-human-review Indicates a PR has been reviewed by automated tools and is ready for human review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants