Skip to content

Commit e679f2c

Browse files
Send the pull request's description to merge risk, and carry its new fallback codes
The deciding model reads what the author says the pull request does, so the merge-risk request now carries the description beside the title. With source off it stays on the runner with the patches, since a description can quote code. closed/merge_risk.json keeps the service's codes for a step that fell back: unchecked, unhinted, undecided, unreviewed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent b8ec0bd commit e679f2c

4 files changed

Lines changed: 51 additions & 26 deletions

File tree

‎README.md‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -193,12 +193,13 @@ The guide's request body, the same xz-compressed bytes the service receives, is
193193
never carries `source.json`, and it is left out when no guide request goes out.
194194

195195
A third request, `POST /v1/merge-risk`, goes to the same base URL at the same time and sends
196-
no analysis: only the pull request's title and changed files with their patches, as GitHub lists
197-
them. The service counts size and tests itself and asks a fixed nine-question checklist about the
198-
diff (sign-in and access, billing, stored data, releases, dependency and platform versions, public
199-
interfaces, calls to other services), with a sentence and the changed line behind each yes. With
200-
`closed_features_source: false` it sends no patches, only each file's path, additions and
201-
deletions; a diff too large to send with its patches goes the same way. Without patches the
196+
no analysis: only the pull request's title, description and changed files with their patches, as
197+
GitHub lists them. The service counts size and tests itself, asks a fixed nine-question checklist
198+
about the diff (sign-in and access, billing, stored data, releases, dependency and platform versions,
199+
public interfaces, calls to other services), has a model decide each answer and a second pass drop
200+
the false alarms, with a sentence and the changed line behind each risk it keeps. With
201+
`closed_features_source: false` it sends neither patches nor the description, only each file's
202+
path, additions and deletions; a diff too large to send with its patches goes the same way. Without patches the
202203
checklist cannot run: the answer comes back `partial` with size and tests only, the run logs a
203204
notice, and the web platform shows the level as not assessed rather than reading the silence as
204205
clean. This input does not keep code from the review guide, whose request carries the changed files

‎action.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ inputs:
147147
description: >-
148148
Experimental. Service base URL for POST /v1/review-guide, POST /v1/architecture and
149149
POST /v1/merge-risk. Defaults to production. The first two receive this run's analysis and
150-
the third its title and changed files, independently; results are stored as review_guide.json,
150+
the third its title, description and changed files, independently; results are stored as review_guide.json,
151151
closed/architecture.json and closed/merge_risk.json, and the guide's request as sent as
152152
closed/bundle.json.xz. Merge risk is also summed up in a hidden line of the review comment.
153153
Set to an empty string to disable all three.

‎scripts/remote_features.py‎

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
including partial, skipped and failed results. The guide's request, exactly as sent, is stored as
88
closed/bundle.json.xz, so a guide can be generated again from the same inputs. Merge risk is stored as
99
closed/merge_risk.json when the service answered, and nothing is written when it did not. It sends
10-
only the pull request's title and changed files with their patches, never the analysis, and no
11-
patches when the workflow turns source off, in which case the service answers with size and tests
10+
only the pull request's title, description and changed files with their patches, never the
11+
analysis, and neither patches nor description when the workflow turns source off, in which case the service answers with size and tests
1212
alone and says its checklist did not run.
1313
1414
What a request sends
@@ -741,8 +741,8 @@ def run_architecture(service_url: str, ctx: dict, data: bytes, headers: dict) ->
741741
return _no_architecture(ctx, "skipped" if isinstance(error, Skip) else "failed", str(error))
742742

743743

744-
def merge_risk_files(ctx: dict) -> tuple[str, list[dict]]:
745-
"""The pull request's title and its changed files as GitHub lists them (at most 3,000, a very large
744+
def merge_risk_files(ctx: dict) -> tuple[str, str, list[dict]]:
745+
"""The pull request's title, description and changed files as GitHub lists them (at most 3,000, a very large
746746
file without its patch), or Skip when the head moved on, since a newer run answers for that head."""
747747
files: list[dict] = []
748748
for page in range(1, 31):
@@ -753,7 +753,7 @@ def merge_risk_files(ctx: dict) -> tuple[str, list[dict]]:
753753
pull = _github_json(f"/repos/{ctx['repo']}/pulls/{ctx['pr']}")
754754
if pull["head"]["sha"] != ctx["head"]:
755755
raise Skip("the pull request moved on to a newer head")
756-
return pull.get("title") or "", files
756+
return pull.get("title") or "", pull.get("body") or "", files
757757

758758

759759
def merge_risk_line(result: dict) -> str | None:
@@ -783,11 +783,18 @@ def merge_risk_line(result: dict) -> str | None:
783783
return line if len(line) <= MAX_MARKER_CHARS else None
784784

785785

786-
def merge_risk_request(ctx: dict, title: str, files: list[dict], with_patches: bool) -> bytes:
786+
def merge_risk_request(ctx: dict, title: str, description: str, files: list[dict], with_patches: bool) -> bytes:
787787
"""The merge-risk request, compressed at MERGE_RISK_PRESET. Its patches go when the workflow turns
788788
source off, or when the file list is over either limit with them: before compressing when the JSON
789789
alone is over MERGE_RISK_PATCH_RATIO times the compressed limit. Sizes and paths count without them."""
790-
body = {"version": 1, "repo": ctx["repo"], "pr": ctx["pr"], "title": title, "files": files}
790+
body = {
791+
"version": 1,
792+
"repo": ctx["repo"],
793+
"pr": ctx["pr"],
794+
"title": title,
795+
"description": description,
796+
"files": files,
797+
}
791798
if with_patches:
792799
clearly_over = MERGE_RISK_PATCH_RATIO * MAX_COMPRESSED_BYTES
793800
try:
@@ -803,8 +810,9 @@ def run_merge_risk(service_url: str, ctx: dict, headers: dict, env: dict, artifa
803810
the step's `merge_risk_line` output. It needs neither the analysis nor the guide, so it runs whatever
804811
happens to them, and a failure is one line in the log."""
805812
try:
806-
title, files = merge_risk_files(ctx)
807-
data = merge_risk_request(ctx, title, files, source_allowed(env))
813+
title, description, files = merge_risk_files(ctx)
814+
# With source off the description stays on the runner too: it can quote code.
815+
data = merge_risk_request(ctx, title, description if source_allowed(env) else "", files, source_allowed(env))
808816
answer = _post(f"{service_url.rstrip('/')}/v1/merge-risk", data, headers, timeout=120)
809817
if not isinstance(answer, dict) or not isinstance(answer.get("facts"), dict):
810818
raise ValueError("the service returned no merge-risk facts")
@@ -821,7 +829,7 @@ def run_merge_risk(service_url: str, ctx: dict, headers: dict, env: dict, artifa
821829
"reasons": answer.get("reasons") if isinstance(answer.get("reasons"), list) else [],
822830
"sensitive": [str(question) for question in answer.get("sensitive") or [] if isinstance(question, str)],
823831
}
824-
for step in ("unchecked", "unexplained"):
832+
for step in ("unchecked", "unhinted", "undecided", "unreviewed"):
825833
if isinstance(answer.get(step), str):
826834
result[step] = answer[step]
827835
if "unchecked" in result:

‎tests/test_remote_features.py‎

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -585,9 +585,11 @@ def test_either_limit_omits_source_then_skips_if_required_inputs_too_large(self)
585585
RISK_CHECKLIST = {
586586
"model": "typesafe/jev-1.14-20261014",
587587
"version": 1,
588-
"answers": {"signin": 0.1, "contract": 0.95},
588+
"probabilities": {"signin": 0.1, "contract": 0.95},
589+
"cut": False,
589590
"yes": ["contract"],
590-
"partial": False,
591+
"decided": True,
592+
"reviewed": True,
591593
}
592594
RISK_ANSWER = {
593595
"status": "ok",
@@ -623,7 +625,9 @@ class MergeRiskTests(_ServiceCase):
623625

624626
def setUp(self):
625627
super().setUp()
626-
patch = mock.patch.object(remote_features, "merge_risk_files", return_value=("Add a route", RISK_FILES))
628+
patch = mock.patch.object(
629+
remote_features, "merge_risk_files", return_value=("Add a route", "Adds GET /items.", RISK_FILES)
630+
)
627631
self.files = patch.start()
628632
self.addCleanup(patch.stop)
629633
self.env["GITHUB_OUTPUT"] = str(Path(self.env["ARTIFACT_DIR"]).parent / "github_output")
@@ -643,7 +647,14 @@ def test_sends_the_file_list_and_keeps_the_answer_with_the_head_it_describes(sel
643647
self.assertEqual(request["headers"]["Authorization"], "Bearer ghs_run")
644648
self.assertEqual(
645649
json.loads(lzma.decompress(request["body"])),
646-
{"version": 1, "repo": "o/r", "pr": 7, "title": "Add a route", "files": RISK_FILES},
650+
{
651+
"version": 1,
652+
"repo": "o/r",
653+
"pr": 7,
654+
"title": "Add a route",
655+
"description": "Adds GET /items.",
656+
"files": RISK_FILES,
657+
},
647658
)
648659
stored = {key: value for key, value in RISK_ANSWER.items() if key != "usage"}
649660
expected = {"feature": "merge-risk", "schema": 2, "repo": "o/r", "pr": 7, "headSha": "H", **stored}
@@ -670,12 +681,16 @@ def test_merge_risk_does_not_need_the_analysis_or_the_guide(self):
670681
self.assertEqual(_read(self.env, "closed/architecture.json")["status"], "failed")
671682

672683
def test_without_room_for_patches_it_sends_the_files_without_them(self):
673-
self.files.return_value = ("Add a route", [{**RISK_FILES[0], "patch": os.urandom(3000).hex()}])
684+
self.files.return_value = ("Add a route", "", [{**RISK_FILES[0], "patch": os.urandom(3000).hex()}])
674685
with mock.patch.object(remote_features, "MAX_COMPRESSED_BYTES", 2000):
675686
service = self.run_service(_answer)
676687
[request] = [sent for sent in service.requests if sent["path"] == "/v1/merge-risk"]
677688
self.assertEqual(json.loads(lzma.decompress(request["body"]))["files"], [{**RISK_FILES[0], "patch": None}])
678689

690+
def sent_description(self, service):
691+
[request] = [sent for sent in service.requests if sent["path"] == "/v1/merge-risk"]
692+
return json.loads(lzma.decompress(request["body"]))["description"]
693+
679694
def sent_files(self, service):
680695
[request] = [sent for sent in service.requests if sent["path"] == "/v1/merge-risk"]
681696
return json.loads(lzma.decompress(request["body"]))["files"]
@@ -685,6 +700,7 @@ def test_with_source_turned_off_it_sends_the_files_without_patches(self):
685700
self.env["CLOSED_FEATURES_SOURCE"] = setting
686701
service = self.run_service(_answer)
687702
self.assertEqual(self.sent_files(service), [{**RISK_FILES[0], "patch": None}])
703+
self.assertEqual(self.sent_description(service), "")
688704
self.assertEqual(self.result()["facts"], RISK_ANSWER["facts"])
689705
self.env["CLOSED_FEATURES_SOURCE"] = "true"
690706
self.assertEqual(self.sent_files(self.run_service(_answer)), RISK_FILES)
@@ -770,7 +786,7 @@ def recording(data, preset):
770786

771787
started = time.monotonic()
772788
with mock.patch.object(lzma, "compress", side_effect=recording):
773-
data = remote_features.merge_risk_request({"repo": "o/r", "pr": 7}, "t", files, with_patches=True)
789+
data = remote_features.merge_risk_request({"repo": "o/r", "pr": 7}, "t", "", files, with_patches=True)
774790
elapsed = time.monotonic() - started
775791
sent = json.loads(lzma.decompress(data))["files"]
776792
self.assertEqual(sent, [{**file, "patch": None} for file in files])
@@ -790,12 +806,12 @@ def test_reads_every_page_and_keeps_the_fields_the_service_reads(self):
790806

791807
def github(path):
792808
if path.endswith("/pulls/7"):
793-
return {"head": {"sha": "H"}, "title": "Add files"}
809+
return {"head": {"sha": "H"}, "title": "Add files", "body": "Why."}
794810
return pages[path.rsplit("&", 1)[1]]
795811

796812
with mock.patch.object(remote_features, "_github_json", side_effect=github):
797-
title, files = remote_features.merge_risk_files({"repo": "o/r", "pr": 7, "head": "H"})
798-
self.assertEqual((title, len(files)), ("Add files", 130))
813+
title, description, files = remote_features.merge_risk_files({"repo": "o/r", "pr": 7, "head": "H"})
814+
self.assertEqual((title, description, len(files)), ("Add files", "Why.", 130))
799815
self.assertEqual(files[129], {"filename": "f129.py", "additions": 129, "deletions": 0, "patch": None})
800816

801817
def test_a_head_that_moved_on_is_skipped(self):

0 commit comments

Comments
 (0)