Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .github/actions/claude-pr-review/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,13 @@ Family: [Claude CI](../CLAUDE-CI.md).
1. Prepare immutable review context
1. Compose bounded LLM analysis
1. Analyze and verify findings — `anthropics/claude-code-action` *(only if `steps.prepare.outputs.mode != 'skip'`)*
1. Capture first analysis transcript before retry *(only if `always() && steps.prepare.outputs.mode != 'skip'`)*
1. Classify first analysis attempt *(only if `steps.prepare.outputs.mode != 'skip'`)*
1. Retry missing structured review output — `anthropics/claude-code-action` *(only if `steps.prepare.outputs.mode != 'skip' && steps.classify.outputs.retryable != 'false' && (steps.review.outcome == 'failure' || steps.review.outputs.structured_output == '')`)*
1. Capture analysis session transcript *(only if `always()`)*
1. Compile and validate review
1. Publish atomically and persist state
1. Salvage completed retry output *(only if `always() && steps.prepare.outputs.mode != 'skip' && steps.review_retry.outcome == 'failure'`)*
1. Compile and validate review *(only if `always() && steps.prepare.outcome == 'success' && steps.compose.outcome == 'success'`)*
1. Publish atomically and persist state *(only if `${{ !cancelled() && steps.compile.outcome == 'success' }}`)*
1. Report concise review outcome *(only if `always()`)*
1. Upload review state for inspection — `actions/upload-artifact` *(only if `always() && inputs.state_artifact == 'true'`)*
<!-- /generated -->
Expand Down
44 changes: 41 additions & 3 deletions .github/actions/claude-pr-review/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,23 @@ runs:

${{ inputs.extra_prompt }}

- name: Capture first analysis transcript before retry
id: capture_first
if: always() && steps.prepare.outputs.mode != 'skip'
continue-on-error: true
shell: bash
env:
EXECUTION_FILE: ${{ steps.review.outputs.execution_file }}
STATE_DIR: ${{ github.workspace }}/.pr-review
run: |
set -euo pipefail
# Both invocations reuse the vendor's execution-file path.
if [[ -n "$EXECUTION_FILE" && -f "$EXECUTION_FILE" ]]; then
mkdir -p "$STATE_DIR"
cp "$EXECUTION_FILE" "$STATE_DIR/analysis-transcript.json"
echo "captured first analysis transcript before retry"
fi

- name: Classify first analysis attempt
id: classify
if: steps.prepare.outputs.mode != 'skip'
Expand All @@ -363,6 +380,7 @@ runs:

- name: Retry missing structured review output
id: review_retry
continue-on-error: true
if: >-
steps.prepare.outputs.mode != 'skip' &&
steps.classify.outputs.retryable != 'false' &&
Expand Down Expand Up @@ -430,14 +448,19 @@ runs:
mkdir -p "$STATE_DIR"
copy_transcript() {
local source="$1" name="$2" session="$3"
if [[ -n "$source" && -f "$source" ]]; then
if [[ "$name" == "analysis-transcript.json" && -f "$STATE_DIR/$name" ]]; then
echo "preserved $name captured before retry"
elif [[ -n "$source" && -f "$source" ]]; then
cp "$source" "$STATE_DIR/$name"
echo "captured $name from $source (session ${session:-unknown})"
else
echo "no transcript available for $name"
fi
}
copy_transcript "$EXECUTION_FILE" "analysis-transcript.json" "$SESSION_ID"
# After a retry the shared source is no longer the first attempt.
if [[ -z "$RETRY_EXECUTION_FILE" ]]; then
copy_transcript "$EXECUTION_FILE" "analysis-transcript.json" "$SESSION_ID"
fi
copy_transcript "$RETRY_EXECUTION_FILE" "analysis-retry-transcript.json" "$RETRY_SESSION_ID"
# Keep the raw structured output beside the transcript. `compile` also
# writes a parsed copy, but it never runs when compilation is what
Expand All @@ -449,11 +472,24 @@ runs:
printf '%s' "$RETRY_STRUCTURED_OUTPUT" > "$STATE_DIR/structured-output-retry.json"
fi

- name: Salvage completed retry output
id: salvage
if: always() && steps.prepare.outputs.mode != 'skip' && steps.review_retry.outcome == 'failure'
shell: bash
env:
REVIEW_STRUCTURED_OUTPUT: ${{ steps.review.outputs.structured_output || steps.review_retry.outputs.structured_output }}
STATE_DIR: ${{ github.workspace }}/.pr-review
run: |
set -euo pipefail
python3 "$GITHUB_ACTION_PATH/review_pipeline.py" salvage \
--state-dir "$STATE_DIR"

- name: Compile and validate review
id: compile
if: always() && steps.prepare.outcome == 'success' && steps.compose.outcome == 'success'
shell: bash
env:
REVIEW_STRUCTURED_OUTPUT: ${{ steps.review.outputs.structured_output || steps.review_retry.outputs.structured_output }}
REVIEW_STRUCTURED_OUTPUT: ${{ steps.review.outputs.structured_output || steps.review_retry.outputs.structured_output || steps.salvage.outputs.structured_output }}
STATE_DIR: ${{ github.workspace }}/.pr-review
run: |
set -euo pipefail
Expand All @@ -462,6 +498,7 @@ runs:

- name: Publish atomically and persist state
id: publish
if: ${{ !cancelled() && steps.compile.outcome == 'success' }}
shell: bash
env:
GH_TOKEN: ${{ inputs.github_identity_token || github.token }}
Expand All @@ -485,6 +522,7 @@ runs:
COMPOSE_OUTCOME: ${{ steps.compose.outcome }}
REVIEW_OUTCOME: ${{ steps.review.outcome }}
REVIEW_RETRY_OUTCOME: ${{ steps.review_retry.outcome }}
REVIEW_SALVAGED: ${{ steps.salvage.outputs.salvaged }}
COMPILE_OUTCOME: ${{ steps.compile.outcome }}
PUBLISH_OUTCOME: ${{ steps.publish.outcome }}
PUBLISH_PUBLISHED: ${{ steps.publish.outputs.published }}
Expand Down
60 changes: 60 additions & 0 deletions .github/actions/claude-pr-review/review_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -1363,6 +1363,55 @@ def classify_command(args: argparse.Namespace) -> None:
write_github_output({"retryable": "true", "code": ""})


def salvage_command(args: argparse.Namespace) -> None:
"""Recover only a completed SDK result, never intermediate tool output."""
state_dir = Path(args.state_dir)
if os.environ.get("REVIEW_STRUCTURED_OUTPUT", ""):
log("salvaged=0 reason=action_output_available")
write_github_output({"salvaged": "0"})
return
path = state_dir / "analysis-retry-transcript.json"
try:
text = path.read_text(encoding="utf-8")
except (OSError, UnicodeError) as error:
log(f"salvaged=0 reason=transcript_unavailable error={error}")
write_github_output({"salvaged": "0"})
return
try:
try:
value = json.loads(text)
records = value if isinstance(value, list) else [value]
except json.JSONDecodeError:
records = [json.loads(line) for line in text.splitlines() if line.strip()]
except json.JSONDecodeError:
log("salvaged=0 reason=malformed_transcript")
write_github_output({"salvaged": "0"})
return
# Only inspect top-level SDK records: nested tool results and stream events
# can contain arbitrary repository text resembling a completed result.
for record in reversed(records):
if not isinstance(record, dict) or record.get("type") != "result":
continue
output = record.get("structured_output")
if (
record.get("terminal_reason") != "completed"
or record.get("subtype") != "success"
or record.get("is_error") is not False
or not isinstance(output, dict)
or not output
):
break
raw = compact_json(output)
(state_dir / "structured-output-retry.json").write_text(
raw + "\n", encoding="utf-8"
)
write_github_output({"salvaged": "1", "structured_output": raw})
log("salvaged=1 reason=completed_retry_result")
return
log("salvaged=0 reason=no_completed_structured_result")
write_github_output({"salvaged": "0"})


def write_github_output(values: dict[str, Any]) -> None:
output_path = os.environ.get("GITHUB_OUTPUT")
if not output_path:
Expand Down Expand Up @@ -3417,6 +3466,8 @@ def inferred_action_failure(
),
)
for phase, code, message in candidates:
if phase == "review_retry" and outcomes.get("compile") == "success":
continue
if outcomes.get(phase) == "failure":
return diagnostic_for(
phase,
Expand All @@ -3426,6 +3477,7 @@ def inferred_action_failure(
if (
outcomes.get("review") == "failure"
and outcomes.get("review_retry") != "success"
and outcomes.get("compile") != "success"
):
return diagnostic_for(
"review",
Expand Down Expand Up @@ -3606,6 +3658,10 @@ def report(args: argparse.Namespace) -> None:
f"`{'enabled' if review_input.get('thread_resolution_enabled') else 'disabled'}`",
f"- **Model retry used:** `{'yes' if retry_used else 'no'}`",
]
if os.environ.get("REVIEW_SALVAGED", "") == "1":
rows.append(
"- **Note:** Retry output was salvaged after a wrapper turn-count rejection."
)
rows.extend(analysis_settings())
if payload:
rows.append(
Expand Down Expand Up @@ -3840,6 +3896,10 @@ def parser() -> argparse.ArgumentParser:
classify_parser.add_argument("--execution-file", default="")
classify_parser.set_defaults(func=classify_command)

salvage_parser = subparsers.add_parser("salvage")
salvage_parser.add_argument("--state-dir", required=True)
salvage_parser.set_defaults(func=salvage_command)

compile_parser = subparsers.add_parser("compile")
compile_parser.add_argument("--state-dir", required=True)
compile_parser.set_defaults(func=compile_command)
Expand Down
Loading
Loading