Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
c7920ec
test: share authoritative GitHub review receipt fixture
Trecek Oct 25, 2026
89ae14f
fix: preserve server review receipts with publisher-owned bindings
Trecek Oct 25, 2026
bea7a6a
fix: align review binding integration with repository guards
Trecek Oct 25, 2026
355086e
test: include review publication in private file cascade expectations
Trecek Oct 25, 2026
15654dd
test: close review receipt audit coverage and import gaps
Trecek Oct 25, 2026
d729cc0
fix(review): reject invalid receipt filename identifiers
Trecek Oct 25, 2026
34510d5
fix(review): share strict review JSON decoding
Trecek Oct 25, 2026
f3d70a1
fix(review): check review skill receipt names against the formatter
Trecek Oct 25, 2026
356167c
fix(review): preserve every publication rollback failure
Trecek Oct 25, 2026
a791faa
refactor(review): remove redundant rollback payload deduplication
Trecek Oct 25, 2026
be95d89
fix(review): validate publication diff context before binding receipts
Trecek Oct 25, 2026
e1697d8
fix(review): enforce mode-specific publication markers
Trecek Oct 25, 2026
560c43c
test(review): allow additional receipt formatter callers
Trecek Oct 25, 2026
2833652
refactor(review): move receipt fixtures out of execution test fakes
Trecek Oct 25, 2026
eaf4c19
test(review): cover malformed receipt verification requests
Trecek Oct 25, 2026
0a9849f
test(review): detect in-place server receipt rewrites
Trecek Oct 25, 2026
24ff7d8
refactor(review): keep handoff helper imports at module scope
Trecek Oct 25, 2026
cf26638
refactor(review): reuse shared publication fixture setup
Trecek Oct 25, 2026
20081d2
test(review): scope handoff path assertions to their owning step
Trecek Oct 25, 2026
e502780
refactor(review): use the receipt formatter in test setup
Trecek Oct 25, 2026
79b84c4
fix(review): preserve client errors for invalid receipt identifiers
Trecek Oct 25, 2026
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
2 changes: 2 additions & 0 deletions src/autoskillit/core/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -1430,6 +1430,7 @@ from .types import (
from .types import compute_remaining as compute_remaining
from .types import compute_runtime_binding_digest as compute_runtime_binding_digest
from .types import context_admission_envelope_header as context_admission_envelope_header
from .types import decode_github_review_json_object as decode_github_review_json_object
from .types import (
decode_stored_context_admission_envelope as decode_stored_context_admission_envelope,
)
Expand All @@ -1443,6 +1444,7 @@ from .types import extract_path_arg as extract_path_arg
from .types import extract_positional_args as extract_positional_args
from .types import extract_skill_name as extract_skill_name
from .types import fleet_error as fleet_error
from .types import github_review_receipt_filename as github_review_receipt_filename
from .types import group_by_pair as group_by_pair
from .types import hookdef_session_scope as hookdef_session_scope
from .types import is_canonical_integer_text as is_canonical_integer_text
Expand Down
27 changes: 27 additions & 0 deletions src/autoskillit/core/types/github/_type_github_review.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from __future__ import annotations

import json
import re
from collections.abc import Mapping
from dataclasses import asdict, dataclass
Expand All @@ -21,6 +22,8 @@
"ReviewOperationState",
"ReviewReconciliationResult",
"ReviewResponseClass",
"decode_github_review_json_object",
"github_review_receipt_filename",
"is_final_github_review_state",
"is_valid_github_review_head_sha",
"is_valid_github_review_logical_iteration",
Expand Down Expand Up @@ -60,6 +63,30 @@ def is_valid_github_review_repository(value: object) -> bool:
return isinstance(value, str) and _REPOSITORY_RE.fullmatch(value) is not None


def github_review_receipt_filename(pr_number: int) -> str:
"""Return the server receipt filename for a pull request."""
if not _is_positive_int(pr_number):
raise ValueError("pr_number must be a positive integer")
return f"batch_review_response_{pr_number}.json"


def decode_github_review_json_object(data: bytes) -> dict[str, object]:
"""Decode a review JSON object, rejecting duplicate keys and preserving all fields."""

def unique_object(pairs: list[tuple[str, Any]]) -> dict[str, Any]:
result: dict[str, Any] = {}
for key, value in pairs:
if key in result:
raise ValueError(f"duplicate JSON object key: {key!r}")
result[key] = value
return result

value = json.loads(data, object_pairs_hook=unique_object)
if not isinstance(value, dict):
raise TypeError("review receipt must be a JSON object")
return value


class ReviewOperationState(StrEnum):
DRY_RUN = "DRY_RUN"
PREPARED = "PREPARED"
Expand Down
181 changes: 104 additions & 77 deletions src/autoskillit/server/tools/tools_pr_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import time
from dataclasses import replace
from pathlib import Path
from typing import Any

import structlog
from fastmcp import Context
Expand All @@ -23,8 +22,10 @@
ReviewOperationState,
ReviewResponseClass,
atomic_write,
decode_github_review_json_object,
destination_location,
get_logger,
github_review_receipt_filename,
is_final_github_review_state,
is_valid_github_review_head_sha,
is_valid_github_review_logical_iteration,
Expand Down Expand Up @@ -90,23 +91,91 @@ def _map_pr_view_reviews(data: dict) -> list:
]


def _load_unique_json_object(data: bytes) -> dict[str, object]:
def _unique_object(pairs: list[tuple[str, Any]]) -> dict[str, Any]:
result: dict[str, Any] = {}
for key, value in pairs:
if key in result:
raise ValueError(f"duplicate JSON object key: {key!r}")
result[key] = value
return result
def _review_verification_result(rejection: str | None) -> str:
if rejection is None:
return json.dumps({"reviews_posted": "true"})
return json.dumps({"reviews_posted": "false", "rejection_reason": rejection})

value = json.loads(data, object_pairs_hook=_unique_object)
if not isinstance(value, dict):
raise TypeError("review receipt must be a JSON object")
return value

def _load_receipt_payload(receipt: Path, root: Path) -> dict[str, object] | str:
try:
_, receipt_bytes = read_stable_contained_bytes(
receipt,
root,
max_size_bytes=1_000_000,
)
except (ContainmentError, OSError):
return "receipt_unreadable"
try:
return decode_github_review_json_object(receipt_bytes)
except (TypeError, ValueError):
return "receipt_malformed"

def _review_verification_result(success: bool) -> str:
return json.dumps({"reviews_posted": "true" if success else "false"})

def _github_receipt_rejection(
*,
cwd: str,
receipt_path: str,
repository: str,
pr_number: int,
head_sha: str,
logical_iteration: str,
post_state: str,
) -> str | None:
if (
not Path(cwd).is_absolute()
or not os.path.isdir(cwd)
or not is_valid_github_review_repository(repository)
or not isinstance(pr_number, int)
or isinstance(pr_number, bool)
or pr_number <= 0
or not is_valid_github_review_head_sha(head_sha)
or not is_valid_github_review_logical_iteration(logical_iteration)
or not is_final_github_review_state(post_state)
):
return "invalid_request"
receipt = Path(receipt_path)
if not receipt.is_absolute() or receipt.name != github_review_receipt_filename(pr_number):
return "invalid_request"
payload = _load_receipt_payload(receipt, Path(cwd) / ".autoskillit" / "temp")
if isinstance(payload, str):
return payload
operation_key = payload.get("operation_key")
if not is_valid_github_review_operation_key(operation_key):
return "receipt_malformed"

poster = _get_ctx().github_review_poster
if poster is None:
return "ledger_receipt_missing"
authoritative = poster.verify_receipt(operation_key)
if authoritative is None:
return "ledger_receipt_missing"
if (
authoritative.repository.casefold() != repository.casefold()
or authoritative.pr_number != pr_number
or authoritative.head_sha != head_sha
or authoritative.logical_iteration != logical_iteration
or authoritative.state.value != post_state
):
return "identity_mismatch"

artifact_wire = json.dumps(
payload,
sort_keys=True,
separators=(",", ":"),
ensure_ascii=False,
allow_nan=False,
)
authoritative_wire = json.dumps(
authoritative.to_dict(),
sort_keys=True,
separators=(",", ":"),
ensure_ascii=False,
allow_nan=False,
)
if artifact_wire != authoritative_wire:
return "receipt_wire_mismatch"
return None


async def _close_issues_sequentially(
Expand Down Expand Up @@ -266,68 +335,25 @@ async def verify_review_receipt(
if (gate := _require_enabled()) is not None:
return gate
if mode == "local":
return _review_verification_result(post_state == "LOCAL")
return _review_verification_result(
None if post_state == "LOCAL" else "invalid_request"
)
if mode != "github":
return _review_verification_result(False)
if (
not Path(cwd).is_absolute()
or not os.path.isdir(cwd)
or not is_valid_github_review_repository(repository)
or not isinstance(pr_number, int)
or isinstance(pr_number, bool)
or pr_number <= 0
or not is_valid_github_review_head_sha(head_sha)
or not is_valid_github_review_logical_iteration(logical_iteration)
or not is_final_github_review_state(post_state)
):
return _review_verification_result(False)
receipt = Path(receipt_path)
if not receipt.is_absolute() or receipt.name != f"batch_review_response_{pr_number}.json":
return _review_verification_result(False)
root = Path(cwd) / ".autoskillit" / "temp"
_, receipt_bytes = read_stable_contained_bytes(
receipt,
root,
max_size_bytes=1_000_000,
)
payload = _load_unique_json_object(receipt_bytes)
operation_key = payload.get("operation_key")
if not is_valid_github_review_operation_key(operation_key):
return _review_verification_result(False)

poster = _get_ctx().github_review_poster
if poster is None:
return _review_verification_result(False)
authoritative = poster.verify_receipt(operation_key)
if authoritative is None:
return _review_verification_result(False)
artifact_wire = json.dumps(
payload,
sort_keys=True,
separators=(",", ":"),
ensure_ascii=False,
allow_nan=False,
)
authoritative_wire = json.dumps(
authoritative.to_dict(),
sort_keys=True,
separators=(",", ":"),
ensure_ascii=False,
allow_nan=False,
)
identity_matches = (
authoritative.repository.casefold() == repository.casefold()
and authoritative.pr_number == pr_number
and authoritative.head_sha == head_sha
and authoritative.logical_iteration == logical_iteration
and authoritative.state.value == post_state
)
return _review_verification_result("invalid_request")
return _review_verification_result(
identity_matches and artifact_wire == authoritative_wire
_github_receipt_rejection(
cwd=cwd,
receipt_path=receipt_path,
repository=repository,
pr_number=pr_number,
head_sha=head_sha,
logical_iteration=logical_iteration,
post_state=post_state,
)
)
except Exception:
logger.error("verify_review_receipt unhandled exception", exc_info=True)
return _review_verification_result(False)
return _review_verification_result("unexpected_error")


@mcp.tool(tags={"autoskillit", "headless", "github"}, annotations={"readOnlyHint": True})
Expand Down Expand Up @@ -369,25 +395,26 @@ async def post_pr_review(
state=ReviewOperationState.AMBIGUOUS,
response_class=ReviewResponseClass.SERVER_ERROR,
)
if not os.path.isdir(cwd):
if not os.path.isdir(cwd) or type(pr_number) is not int or pr_number <= 0:
return _review_post_error(
head_sha=head_sha,
error="cwd must be an existing directory",
error="cwd must be an existing directory and pr_number a positive integer",
state=ReviewOperationState.TERMINAL,
response_class=ReviewResponseClass.CLIENT_ERROR,
)
root = (Path(cwd) / ".autoskillit" / "temp").resolve()
destination = destination_location(Path(receipt_path))
expected_name = github_review_receipt_filename(pr_number)
if (
not Path(cwd).is_absolute()
or not destination.is_relative_to(root)
or destination.name != f"batch_review_response_{pr_number}.json"
or destination.name != expected_name
):
return _review_post_error(
head_sha=head_sha,
error=(
"receipt_path must be an absolute contained path under "
f"{root} named batch_review_response_{pr_number}.json"
f"{root} named {expected_name}"
),
state=ReviewOperationState.TERMINAL,
response_class=ReviewResponseClass.CLIENT_ERROR,
Expand Down Expand Up @@ -439,7 +466,7 @@ async def post_pr_review(
max_size_bytes=1_000_000,
)
authority = DiffAnchorAuthority.from_wire(
_load_unique_json_object(authority_bytes)
decode_github_review_json_object(authority_bytes)
)
except (ContainmentError, OSError) as exc:
return _review_post_error(
Expand Down
25 changes: 18 additions & 7 deletions src/autoskillit/skills_extended/resolve-review/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -346,13 +346,18 @@ After saving the raw review responses, check for the handoff file from review-pr

```bash
# Read review-pr artifacts from the iteration-scoped directory
REVIEW_PR_DIR="${AUTOSKILLIT_TEMP}/review-pr"
REVIEW_PR_DIR="{{AUTOSKILLIT_TEMP}}/review-pr"
# If iter_N directory exists under review-pr/, use the latest iteration
REVIEW_PR_ITER_DIR=$(ls -d "${REVIEW_PR_DIR}"/iter_* 2>/dev/null | sort -V | tail -1)
REVIEW_PR_OUTPUT="${REVIEW_PR_ITER_DIR:-${REVIEW_PR_DIR}}"
REVIEW_PR_OUTPUT="$(realpath -- "$REVIEW_PR_OUTPUT")"
DIFF_CONTEXT_PATH="${REVIEW_PR_OUTPUT}/diff_context_{pr_number}.json"
printf '%s\n' "$REVIEW_PR_OUTPUT"
```

Paste the printed absolute path as a string literal in the Python helper call's
`output_dir` argument.

If the file exists:
- Parse it as JSON
- Build `diff_context_map: dict[tuple[str, int], dict]` where key is `(entry.path, entry.line)`
Expand All @@ -364,12 +369,15 @@ If the file exists:
- In `mode=local`, read `local_findings_{pr_number}.json` and
`diff_context_{pr_number}.json` from the same `REVIEW_PR_OUTPUT`, then call
`review_handoff_pair_error(diff_context, local_findings)`.
- In `mode=github`, pair `diff_context_{pr_number}.json` with the published
`batch_review_response_{pr_number}.json` receipt from the same
`REVIEW_PR_OUTPUT`, then call
`review_handoff_pair_error(diff_context, batch_review_response)`. Do not require
a local-findings artifact in GitHub mode. A helper error for either
mode-appropriate pair rejects the handoff and uses the existing fallback path.
- In `mode=github`, pair `diff_context_{pr_number}.json` with the publisher's
`github_review_binding_{pr_number}.json` marker from the same directory by calling
`github_review_handoff_error(output_dir=<printed path as a string literal>,
pr_number="{pr_number}")` from `autoskillit.smoke_utils`; it also checks the marker
against the server-written receipt. Do not require a local-findings artifact in
GitHub mode. On a non-null result, set `diff_context_map = {}`, print
`Pre-built context rejected: {error}`, skip schema processing and pre-built
review-level ingestion, and use the existing fallback path. Continue schema
validation and ingestion only when the helper returns `None`.
- After that mode-appropriate handoff-pair authority check, require
`schema_version == 2`. Every `context_entries` entry with an integer `line` must
have a non-empty `anchor_digest`; a null line must omit it. Reject incomplete or
Expand All @@ -381,6 +389,9 @@ If the file exists:
stale, not permission to mint an anchor digest from this checkout.
- Log: `"Loaded pre-built context for N findings from review-pr handoff (schema_version: {v})"`

The existing fallback reconstructs code context from review comments and live source
under Step 3.5's checks; it does not retry or redeliver the publication.

After the same pair-authority and v2 schema validation, load
`review_level_findings` separately from line-anchored `context_entries`. Preserve
each `candidate_id`, path, diagnostic line, message, severity, and dimension; deduplicate
Expand Down
Loading
Loading