From 4c8ab22737e4184c42ef59ffb97f9dc29e96c68f Mon Sep 17 00:00:00 2001 From: Ludovic Henry Date: Fri, 20 Nov 2026 20:45:46 +0100 Subject: [PATCH] upstreaming: separate inquiries from repair feedback --- SESSIONLOG.md | 1 + upstreaming/INTEGRATION.md | 5 ++ upstreaming/collect.py | 49 ++++++++++-- upstreaming/command_feedback.py | 13 +++- upstreaming/observe_ci.py | 86 +++++++++++++++------- upstreaming/schemas/evidence.schema.json | 1 + upstreaming/status_ledger.py | 3 +- upstreaming/tests/test_command_feedback.py | 10 +++ upstreaming/tests/test_observation.py | 47 ++++++++++++ upstreaming/tests/test_status_ledger.py | 10 +++ 10 files changed, 189 insertions(+), 36 deletions(-) diff --git a/SESSIONLOG.md b/SESSIONLOG.md index 8263ae839fd5..45926c1e5831 100644 --- a/SESSIONLOG.md +++ b/SESSIONLOG.md @@ -33,3 +33,4 @@ - Required investigator and worker dependency audits to use the RISE simple index plus `PIP_PREFER_BINARY=true` when public PyPI lacks compatible riscv64 build/test wheels, and updated both mirrored porting-skill paths with resolver-scope guidance. - Added a stale-proof `/upstreaming restart` command for abandoned contributions that keeps the same tracking issue and append-only ledger while starting a fresh queued lifecycle generation after writer quiescence. - Added `/upstreaming refresh` to re-investigate an existing development PR with current prompts, replace its verified dossier scope, and require a fresh worker pass carrying the full new dossier plus pending review and CI evidence. +- Separated explicit explanation-only PR comments from change feedback so they are audited without revision bumps, `fix_needed` transitions, repair evidence, or misleading repair ledger text; repeated-pause rejection feedback now confirms the pause remains effective instead of repeating the submitted syntax. diff --git a/upstreaming/INTEGRATION.md b/upstreaming/INTEGRATION.md index 5266df1d0a62..82c1ae4886bf 100644 --- a/upstreaming/INTEGRATION.md +++ b/upstreaming/INTEGRATION.md @@ -205,6 +205,11 @@ requests `development_repair`. Pending feedback evidence survives branch-head changes and is attached to every repair until exact-head CI is green. A repair proposal must acknowledge every required evidence record. Observation does not replace `fix_needed` before the controller can allocate that repair. +Explanation-only comments are classified separately as `human_inquiry` when +an explicit no-change instruction is present, or when they clearly request an +explanation without a repair instruction. They are marked processed and retained +for audit, but do not bump the revision, set `fix_needed`, enter pending repair +evidence, invalidate CI or handoff state, or claim that repair was requested. Exact-head CI is green only when every executed build or test job succeeds, in addition to the target riscv64 job and wheel contract. Failures confined to diff --git a/upstreaming/collect.py b/upstreaming/collect.py index a96862a23113..111e5c4619a3 100644 --- a/upstreaming/collect.py +++ b/upstreaming/collect.py @@ -153,8 +153,34 @@ def tracking_issues(api: Api, contributions: Iterable[dict], intake_issues: list return issues +_EXPLANATION_WORDS = re.compile( + r"(?:^|\b)(?:why|what happened|how did|explain|explanation|diagnose|diagnosis)(?:\b|$)", re.IGNORECASE) +_REPAIR_WORDS = re.compile( + r"(?:^|\b)(?:fix|update|add|remove|revert|disable|enable|implement|rename|delete|replace|set|use)(?:\b|$)", + re.IGNORECASE) +_NO_CHANGE = re.compile( + r"(?:do not|don't|dont|please do not|please don't)\s+(?:make\s+(?:any\s+)?)?(?:change|changes|modify|edit|push|commit|fix)\b|" + r"\bwithout\s+(?:changing|modifying|editing|pushing|committing|fixing)\b|" + r"\bno\s+(?:code\s+)?changes?\b", + re.IGNORECASE) + + +def review_comment_intent(body: str) -> str: + """Conservatively distinguish an explanation request from repair feedback. + + An explicit no-change instruction is authoritative. Otherwise only a clear + explanatory question with no repair verb is treated as inquiry-only. + """ + text = " ".join(body.split()) + if _NO_CHANGE.search(text): + return "inquiry" + if _EXPLANATION_WORDS.search(text) and not _REPAIR_WORDS.search(text): + return "inquiry" + return "repair" + + def development_review_feedback(api: Api, record: dict, authority: Iterable[int]) -> dict | None: - """Return new authorized review feedback bound to the current fork head.""" + """Return new authorized review feedback or inquiries bound to the current fork head.""" fork = record.get("fork") or {} number = fork.get("pr_number") head = fork.get("head_sha") @@ -191,7 +217,7 @@ def development_review_feedback(api: Api, record: dict, authority: Iterable[int] "review_id": comment.get("pull_request_review_id"), "reviewer": (comment.get("user") or {}).get("login"), "path": comment.get("path"), "line": comment.get("line") or comment.get("original_line"), - "commit_id": head}) + "commit_id": head, "intent": review_comment_intent(body)}) conversation_items = [] for comment in conversation: body = (comment.get("body") or "").strip() @@ -203,14 +229,23 @@ def development_review_feedback(api: Api, record: dict, authority: Iterable[int] conversation_items.append({"id": comment["id"], "body": body[:8000], "url": comment.get("html_url"), "reviewer": (comment.get("user") or {}).get("login"), - "created_at": created, "commit_id": head}) + "created_at": created, "commit_id": head, + "intent": review_comment_intent(body)}) if not review_items and not comment_items and not conversation_items: return None - return {"reviews": review_items, "comments": comment_items, - "conversation_comments": conversation_items, + inquiry_comments = [item for item in comment_items if item["intent"] == "inquiry"] + inquiry_conversation = [item for item in conversation_items if item["intent"] == "inquiry"] + repair_comments = [item for item in comment_items if item["intent"] == "repair"] + repair_conversation = [item for item in conversation_items if item["intent"] == "repair"] + return {"reviews": review_items, "comments": repair_comments, + "conversation_comments": repair_conversation, "review_ids": [item["id"] for item in review_items], - "comment_ids": [item["id"] for item in comment_items], - "conversation_comment_ids": [item["id"] for item in conversation_items]} + "comment_ids": [item["id"] for item in repair_comments], + "conversation_comment_ids": [item["id"] for item in repair_conversation], + "inquiry_comments": inquiry_comments, + "inquiry_conversation_comments": inquiry_conversation, + "inquiry_comment_ids": [item["id"] for item in inquiry_comments], + "inquiry_conversation_comment_ids": [item["id"] for item in inquiry_conversation]} def upstream_snapshots(api: Api, contributions: Iterable[dict], issues: list[dict], policy: dict) -> dict[str, dict]: diff --git a/upstreaming/command_feedback.py b/upstreaming/command_feedback.py index adf0eb2145a2..c77d7a5d43d1 100644 --- a/upstreaming/command_feedback.py +++ b/upstreaming/command_feedback.py @@ -39,7 +39,18 @@ def render(receipt: dict, original: dict) -> str: quoted = "\n".join("> " + line for line in body.splitlines()) reason = (receipt.get("reason") or receipt.get("result") or "command rejected").strip() text = f"@{login}, this command was rejected:\n\n{quoted}\n\n**Reason:** {reason}" - template = TEMPLATES.get(_verb(body, receipt)) + verb = _verb(body, receipt) + if reason == "already paused": + revision = receipt.get("revision") + suffix = f" revision={revision}" if revision is not None else " revision=N" + text += ("\n\n**No action is needed:** the contribution remains paused. " + "To continue it, use:\n```text\n" + f'/upstreaming resume{suffix} reason="..."\n```') + return text + f"\n\n" + if reason == "not paused" and verb == "resume": + text += "\n\n**No action is needed:** the contribution is already active." + return text + f"\n\n" + template = TEMPLATES.get(verb) if template: revision = receipt.get("revision") if revision is None: diff --git a/upstreaming/observe_ci.py b/upstreaming/observe_ci.py index 383f7c1d564a..faf2825bee35 100644 --- a/upstreaming/observe_ci.py +++ b/upstreaming/observe_ci.py @@ -91,34 +91,66 @@ def observe(api: collect.Api, *, contributions: dict[str, dict], operations: dic feedback = collect.development_review_feedback( api, cur, policy["command_authority"]["actor_ids"]) if feedback: + inquiry_ids = (feedback["inquiry_comment_ids"] + + feedback["inquiry_conversation_comment_ids"]) + if inquiry_ids: + inquiry_items = (feedback["inquiry_comments"] + + feedback["inquiry_conversation_comments"]) + inquiry_id = safe_id( + f"inquiry-{cur['fork']['repository_id']}-{cur['fork']['pr_number']}-{max(inquiry_ids)}") + inquiry_data = {"comments": feedback["inquiry_comments"], + "conversation_comments": feedback["inquiry_conversation_comments"]} + inquiry_ev = {"schema_version": 1, "evidence_id": inquiry_id, + "contribution_id": cid, "kind": "human_inquiry", + "policy_version": policy["policy_version"], "collected_at": now, + "summary": "\n\n".join(item["body"] for item in inquiry_items)[:8000], + "limitations": ["Explanation-only; no repair or mutation requested."], + "data": inquiry_data, "digests": {"head": head["head"]}} + schemas.validate("evidence", inquiry_ev) + before_inquiry = cur + cur = dict(cur, + processed_review_comment_ids=( + (cur.get("processed_review_comment_ids") or []) + + feedback["inquiry_comment_ids"])[-512:], + processed_pr_conversation_comment_ids=( + (cur.get("processed_pr_conversation_comment_ids") or []) + + feedback["inquiry_conversation_comment_ids"])[-512:], + updated_at=now) + schemas.validate("contribution", cur) + obs.staged.extend([("evidence", inquiry_ev), ("contributions", cur), + ("events", lifecycle._event( + before_inquiry, cur, "development_review_inquiry", + "observation", inquiry_id, now, False))]) + entry["review_inquiry"] = inquiry_id ids = feedback["review_ids"] + feedback["comment_ids"] + feedback["conversation_comment_ids"] - eid = safe_id(f"review-{cur['fork']['repository_id']}-{cur['fork']['pr_number']}-{max(ids)}") - summaries = [item["body"] for item in - feedback["reviews"] + feedback["comments"] + feedback["conversation_comments"]] - ev = {"schema_version": 1, "evidence_id": eid, "contribution_id": cid, - "kind": "human_relay", "policy_version": policy["policy_version"], - "collected_at": now, "summary": "\n\n".join(summaries)[:8000], - "limitations": [], "data": feedback, "digests": {"head": head["head"]}} - schemas.validate("evidence", ev) - before = cur - cur = dict(cur, revision=cur["revision"] + 1, phase="development", activity="fix_needed", - active_work=None, active_operation_id=None, clean_head_sha=None, - handoff_request=None, handoff_approval=None, pending_human_action=None, - last_ci_evidence_id=eid, - processed_review_ids=((cur.get("processed_review_ids") or []) + feedback["review_ids"])[-256:], - processed_review_comment_ids=((cur.get("processed_review_comment_ids") or []) - + feedback["comment_ids"])[-512:], - processed_pr_conversation_comment_ids=( - (cur.get("processed_pr_conversation_comment_ids") or []) - + feedback["conversation_comment_ids"])[-512:], - pending_feedback_evidence_ids=list(dict.fromkeys( - (cur.get("pending_feedback_evidence_ids") or []) + [eid]))[-64:], - updated_at=now) - schemas.validate("contribution", cur) - obs.staged.extend([("evidence", ev), ("contributions", cur), - ("events", lifecycle._event(before, cur, "development_review_feedback", - "observation", eid, now, True))]) - entry["review_feedback"] = eid + if ids: + eid = safe_id(f"review-{cur['fork']['repository_id']}-{cur['fork']['pr_number']}-{max(ids)}") + summaries = [item["body"] for item in + feedback["reviews"] + feedback["comments"] + feedback["conversation_comments"]] + ev = {"schema_version": 1, "evidence_id": eid, "contribution_id": cid, + "kind": "human_relay", "policy_version": policy["policy_version"], + "collected_at": now, "summary": "\n\n".join(summaries)[:8000], + "limitations": [], "data": feedback, "digests": {"head": head["head"]}} + schemas.validate("evidence", ev) + before = cur + cur = dict(cur, revision=cur["revision"] + 1, phase="development", activity="fix_needed", + active_work=None, active_operation_id=None, clean_head_sha=None, + handoff_request=None, handoff_approval=None, pending_human_action=None, + last_ci_evidence_id=eid, + processed_review_ids=((cur.get("processed_review_ids") or []) + feedback["review_ids"])[-256:], + processed_review_comment_ids=((cur.get("processed_review_comment_ids") or []) + + feedback["comment_ids"])[-512:], + processed_pr_conversation_comment_ids=( + (cur.get("processed_pr_conversation_comment_ids") or []) + + feedback["conversation_comment_ids"])[-512:], + pending_feedback_evidence_ids=list(dict.fromkeys( + (cur.get("pending_feedback_evidence_ids") or []) + [eid]))[-64:], + updated_at=now) + schemas.validate("contribution", cur) + obs.staged.extend([("evidence", ev), ("contributions", cur), + ("events", lifecycle._event(before, cur, "development_review_feedback", + "observation", eid, now, True))]) + entry["review_feedback"] = eid obs.report.append(entry) continue # A requested repair must reach the controller before another CI poll diff --git a/upstreaming/schemas/evidence.schema.json b/upstreaming/schemas/evidence.schema.json index 9608570e7a43..2c958cd7c129 100644 --- a/upstreaming/schemas/evidence.schema.json +++ b/upstreaming/schemas/evidence.schema.json @@ -41,6 +41,7 @@ "benchmark", "merge", "human_relay", + "human_inquiry", "resolution" ] }, diff --git a/upstreaming/status_ledger.py b/upstreaming/status_ledger.py index 5670cd6dcf9e..25f98fe4c1cf 100644 --- a/upstreaming/status_ledger.py +++ b/upstreaming/status_ledger.py @@ -25,7 +25,8 @@ class LedgerError(ValueError): "dossier_parked": "Verified the investigation dossier and parked the contribution because no bounded patch is actionable.", "fork_provisioned": "Provisioned and verified the contribution fork and exact `riscv64` base.", "development_pr_created": "Created and verified the same-fork development PR.", - "development_review_feedback": "Recorded authorized development-PR review feedback and requested repair.", + "development_review_feedback": "Recorded authorized development-PR change feedback and requested repair.", + "development_review_inquiry": "Recorded an authorized explanation-only development-PR comment. No repair was requested; lifecycle state is unchanged.", "handoff_ready": "Accepted clean-head development CI and reached human upstream handoff.", } diff --git a/upstreaming/tests/test_command_feedback.py b/upstreaming/tests/test_command_feedback.py index 37feaeb8951e..b9a053917b10 100644 --- a/upstreaming/tests/test_command_feedback.py +++ b/upstreaming/tests/test_command_feedback.py @@ -35,6 +35,16 @@ def test_rejected_restart_has_actionable_template(self): body = command_feedback.render(receipt, original) self.assertIn('/upstreaming restart revision=7 reason="..."', body) + def test_repeated_pause_explains_that_pause_remains_effective(self): + receipt = {"comment_id": 42, "actor": {"login": "luhenry"}, "verb": "pause", + "reason": "already paused", "revision": 8} + original = {"body": '/upstreaming pause revision=8 reason="saving tokens"', + "user": {"login": "luhenry"}} + body = command_feedback.render(receipt, original) + self.assertIn("the contribution remains paused", body) + self.assertIn('/upstreaming resume revision=8 reason="..."', body) + self.assertNotIn("**Expected form:**", body) + def test_rejected_command_is_quoted_pings_author_and_shows_expected_form(self): receipt = {"schema_version": 1, "command_id": "comment-42", "command_version": 1, "comment_id": 42, "issue_number": 1138, "actor": {"id": 660779, "login": "luhenry"}, diff --git a/upstreaming/tests/test_observation.py b/upstreaming/tests/test_observation.py index c69c526dcdac..2a6fb50dc1d9 100644 --- a/upstreaming/tests/test_observation.py +++ b/upstreaming/tests/test_observation.py @@ -5,6 +5,7 @@ import json import tempfile import unittest +from unittest import mock from datetime import datetime, timedelta, timezone from pathlib import Path @@ -237,6 +238,52 @@ def get(self, path): date = "2030-01-01T00:00:00Z" if path.endswith(SHA_B) else "2026-01-01T00:00:00Z" return {"commit": {"committer": {"date": date}}} + def test_explanation_only_observation_does_not_bump_or_request_repair(self): + from upstreaming import observe_ci + rec = contribution(phase="development", activity="fix_needed", revision=8, paused=True) + inquiry = {"reviews": [], "comments": [], "conversation_comments": [], + "review_ids": [], "comment_ids": [], "conversation_comment_ids": [], + "inquiry_comments": [], + "inquiry_conversation_comments": [{"id": 32, "body": "Explain why it failed. Do not change anything."}], + "inquiry_comment_ids": [], "inquiry_conversation_comment_ids": [32]} + with mock.patch("upstreaming.observe_ci.collect.branch_head", return_value={"head": SHA_A}), \ + mock.patch("upstreaming.observe_ci.collect.development_review_feedback", return_value=inquiry): + observed = observe_ci.observe(object(), contributions={"c": rec}, operations={}, contracts={}, + policy=policy(), now=NOW) + final = [item for kind, item in observed.staged if kind == "contributions"][-1] + event = [item for kind, item in observed.staged if kind == "events"][-1] + evidence = [item for kind, item in observed.staged if kind == "evidence"][-1] + self.assertEqual((final["revision"], final["activity"], final["paused"]), + (8, "fix_needed", True)) + self.assertEqual(final.get("pending_feedback_evidence_ids"), rec.get("pending_feedback_evidence_ids")) + self.assertEqual(event["kind"], "development_review_inquiry") + self.assertFalse(event["revision_bumped"]) + self.assertEqual(evidence["kind"], "human_inquiry") + self.assertNotIn("review_feedback", observed.report[0]) + + def test_explanation_only_comments_are_separated_from_repairs(self): + self.assertEqual(collect.review_comment_intent( + "Explain me why it failed. Do not change anything."), "inquiry") + self.assertEqual(collect.review_comment_intent("Why did this CI job fail?"), "inquiry") + self.assertEqual(collect.review_comment_intent("Why did this fail? Fix it."), "repair") + self.assertEqual(collect.review_comment_intent("Disable this temporarily."), "repair") + + class InquiryApi(self.Api): + def paginate(inner, path, **kw): + if "/issues/" in path: + return [{"id": 32, "body": "Explain why it failed. Do not change anything.", + "created_at": NOW, "user": {"id": OWNER["id"], "login": OWNER["login"]}}] + if path.endswith("/reviews?per_page=100"): + return [] + return [] + + rec = contribution(phase="development", activity="fix_needed") + rec["fork"] = dict(rec["fork"], head_sha=SHA_A, pr_number=1) + result = collect.development_review_feedback(InquiryApi(), rec, [OWNER["id"]]) + self.assertEqual(result["inquiry_conversation_comment_ids"], [32]) + self.assertEqual(result["conversation_comment_ids"], []) + self.assertEqual(result["inquiry_conversation_comments"][0]["intent"], "inquiry") + def test_only_new_authorized_current_head_review_feedback_is_returned(self): rec = contribution(phase="development", activity="waiting_ci") rec["fork"] = dict(rec["fork"], head_sha=SHA_A, pr_number=1) diff --git a/upstreaming/tests/test_status_ledger.py b/upstreaming/tests/test_status_ledger.py index e91b94a56c40..57af62d619a9 100644 --- a/upstreaming/tests/test_status_ledger.py +++ b/upstreaming/tests/test_status_ledger.py @@ -49,6 +49,16 @@ def test_render_has_short_summary_and_folded_prefilled_commands(self): self.assertIn("/upstreaming force-develop revision=4", body) self.assertIn("