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
7 changes: 7 additions & 0 deletions docs/execution/architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,13 @@ secondary-rate responses persist shared back-pressure. A capacity-one fenced
lease enforces at least one second between review mutation starts across
sessions.

When the authenticated reviewer is the pull request's author, requested
`APPROVE` and `REQUEST_CHANGES` events are published as `COMMENT`. The publisher
chooses from preflight identities before any mutation, adds a fixed disclosure,
and records both events in the receipt. This comment provides neither a GitHub
approval nor a changes-requested review and does not itself satisfy a required
approval. The skills' verdict and gate are independent of the effective event.

Final success requires a server-authored receipt with the operation identity,
review/comment IDs, response and reconciliation classes, and an exhaustive
posted/already-present/omitted disposition for every original finding. Dry-run
Expand Down
2 changes: 2 additions & 0 deletions src/autoskillit/core/types/constants/_type_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,7 @@ class SkillFamilyDef(NamedTuple):
"drift-discipline",
"graphql-batch-aliases",
"mutating-call-delay",
"response-body-guard",
}
),
),
Expand All @@ -461,6 +462,7 @@ class SkillFamilyDef(NamedTuple):
required_patterns=frozenset(
{
"unpostable-prefilter",
"response-body-guard",
}
),
),
Expand Down
13 changes: 13 additions & 0 deletions src/autoskillit/execution/github_ops/_github_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from __future__ import annotations

import json
from collections.abc import Mapping
from email.utils import parsedate_to_datetime
from typing import Any
Expand All @@ -16,6 +17,18 @@ def github_error_message(data: Any) -> str | None:
return message if isinstance(message, str) and message else None


def github_error_detail(data: Any) -> str | None:
"""Return GitHub's message plus bounded string or object ``errors[]`` details."""
message = github_error_message(data)
errors = data.get("errors") if isinstance(data, Mapping) else None
if not isinstance(errors, list) or not errors:
return message[:500] if message else None
items = "; ".join(
item if isinstance(item, str) else json.dumps(item, sort_keys=True) for item in errors
)
return (f"{message}: {items}" if message else items)[:500]


def is_secondary_rate_limit(
*,
status_code: int,
Expand Down
12 changes: 11 additions & 1 deletion src/autoskillit/execution/github_review/_poster_retry.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,19 @@ async def resume_pending_retry(
retry_findings = tuple(
finding for finding in findings if finding.canonical_index in retry_indexes
)
error = None
if tuple(finding.canonical_index for finding in retry_findings) != (attempt.canonical_indexes):
error = "persisted review retry references unknown canonical findings"
elif (
_poster_support.author_effective_event(
request.event,
authenticated_login=authenticated_login,
pr_author_login=pr_author_login,
)
!= attempt.effective_event
):
error = "persisted review retry event no longer matches current reviewer identity"
if error is not None:
poster.ledger.complete_attempt(
operation_key=operation_key,
attempt_number=attempt.attempt_number,
Expand Down Expand Up @@ -142,7 +153,6 @@ async def resume_pending_retry(
attempt_number=attempt.attempt_number,
omitted=attempt.omitted_dispositions,
authenticated_login=authenticated_login,
pr_author_login=pr_author_login,
resume_pending=True,
)

Expand Down
50 changes: 36 additions & 14 deletions src/autoskillit/execution/github_review/_poster_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,41 @@ class RemoteFindingScan:
error: str | None = None


_AUTHOR_EVENT_DISCLOSURES = {
"APPROVE": (
"Requested review event APPROVE was published as COMMENT because GitHub does not allow "
"a pull request's author to approve it; this is not a GitHub approval."
),
"REQUEST_CHANGES": (
"Requested review event REQUEST_CHANGES was published as COMMENT because GitHub does "
"not allow a pull request's author to request changes on it; this review does not "
"block merging."
),
}


def author_effective_event(
requested_event: str, *, authenticated_login: str, pr_author_login: str
) -> str:
"""Choose the event for GitHub's known own-author restriction."""
if (
requested_event in _AUTHOR_EVENT_DISCLOSURES
and authenticated_login.casefold() == pr_author_login.casefold()
):
return "COMMENT"
return requested_event


def _disclose_author_event(body: str, *, requested_event: str, event: str) -> str:
if event == requested_event:
return body
if event != "COMMENT" or requested_event not in _AUTHOR_EVENT_DISCLOSURES:
raise ValueError(
f"unsupported review event transformation: {requested_event!r} -> {event!r}"
)
return append_marker(body, _AUTHOR_EVENT_DISCLOSURES[requested_event])


def payload(
*,
request: GitHubReviewRequest,
Expand Down Expand Up @@ -81,6 +116,7 @@ def payload(
)
if entries:
body += "\n\n## Outside Diff Range\n\n" + "\n\n".join(entries)
body = _disclose_author_event(body, requested_event=request.event, event=event)
if len(body) > 60000:
raise ValueError("review body including omitted findings exceeds 60000 characters")
return {
Expand Down Expand Up @@ -161,20 +197,6 @@ def structured_invalid_comment_index(
return index if 0 <= index < comment_count else None


def is_structured_self_review(response: GatewayResult) -> bool:
if response.status_code != 422:
return False
data = response.data if isinstance(response.data, Mapping) else {}
errors = data.get("errors")
return isinstance(errors, list) and any(
isinstance(item, Mapping)
and item.get("field") == "event"
and item.get("code") == "invalid"
and "own pull request" in str(item.get("message", "")).casefold()
for item in errors
)


def structured_error_message(response: GatewayResult) -> str | None:
if not isinstance(response.data, Mapping):
return None
Expand Down
Loading
Loading