From 369ca5550970d8dc0a8ae64503168beb91d668f8 Mon Sep 17 00:00:00 2001 From: Ludovic Henry Date: Fri, 20 Nov 2026 20:05:42 +0100 Subject: [PATCH] upstreaming: restart abandoned work on the same issue --- SESSIONLOG.md | 1 + upstreaming/INTEGRATION.md | 5 ++ upstreaming/README.md | 8 +++ upstreaming/command_feedback.py | 1 + upstreaming/commands.py | 3 ++ upstreaming/lifecycle.py | 52 +++++++++++++++++++- upstreaming/schemas/contribution.schema.json | 4 ++ upstreaming/status_ledger.py | 2 + upstreaming/tests/test_command_feedback.py | 8 +++ upstreaming/tests/test_commands_intake.py | 3 ++ upstreaming/tests/test_lifecycle.py | 47 ++++++++++++++++++ upstreaming/tests/test_status_ledger.py | 9 ++++ 12 files changed, 141 insertions(+), 2 deletions(-) diff --git a/SESSIONLOG.md b/SESSIONLOG.md index bd668996340a..204466fa535a 100644 --- a/SESSIONLOG.md +++ b/SESSIONLOG.md @@ -31,3 +31,4 @@ - Added a hash-pinned gh-aw v1.2.2 console guard that preserves canonical agent evidence while preventing untrusted model or MCP text from being parsed as GitHub Actions workflow commands. - Replaced console-byte rewriting with GitHub's native stop-commands protocol: trusted pre/post agent steps bracket exact output with a random step-output token and always restore command processing. - 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. diff --git a/upstreaming/INTEGRATION.md b/upstreaming/INTEGRATION.md index bec56296d551..c8a82d747915 100644 --- a/upstreaming/INTEGRATION.md +++ b/upstreaming/INTEGRATION.md @@ -32,6 +32,11 @@ release-path rehearsal still need live evidence. overridden with an authorized stale-proof `force-develop` command. - Human approval starts at upstream handoff. No automatic upstream PR creation or production package publication is authorized. +- An authorized exact-revision `restart` command may reactivate only an abandoned + contribution on the same tracking issue. It starts a new lifecycle generation + and queued investigation after clearing mutable dossier, scope, fork/PR, CI, + review, budget and operation state. The append-only event history and old-run + replay fence remain. Remote PR/repository cleanup is separate and explicit. - Keep gh-aw v1.2.2 until a stable, coordinated upgrade is reviewed. No alternate scheduler, publication route, salted branch or unverified-artifact fallback. - Only the investigator has approved unsandboxed internet access. It remains diff --git a/upstreaming/README.md b/upstreaming/README.md index bf3633531fb9..f309288519d0 100644 --- a/upstreaming/README.md +++ b/upstreaming/README.md @@ -264,6 +264,7 @@ work that moved meanwhile: ```text /upstreaming resume revision=1 reason="quota back" +/upstreaming restart revision=8 reason="Restart from a fresh investigation." /upstreaming force-develop revision=2 class=configuration_integration paths=".github/workflows/*" reason="Concrete override scope." /upstreaming approve-handoff revision=3 head= ``` @@ -302,6 +303,13 @@ None of these perform remote writes. current-revision `force-develop` instead records a bounded override scope and proceeds directly to automatic provisioning. Duplicates, timers and prerequisite changes never resume a parked contribution. +- **Restart after abandon** requires the exact current revision and fails while + Work, a writer operation or publication is active. It preserves the same + tracking issue, contribution identity, append-only event ledger and old-run + replay fence, increments `generation` and revision, then clears the old + dossier, scope, fork/PR, CI/review cursors, budget consumption and mutable + operation state before returning to queued investigation. It does not delete + or close remote resources; perform that explicit cleanup while abandoned. - **Handoff**: `request-handoff` needs executed CI evidence for the exact head. `approve-handoff` binds to the clean head after `{debug}` removal. Any new change made before submission clears the approval. diff --git a/upstreaming/command_feedback.py b/upstreaming/command_feedback.py index b202bb418d2f..de029252a8f2 100644 --- a/upstreaming/command_feedback.py +++ b/upstreaming/command_feedback.py @@ -18,6 +18,7 @@ "park": '/upstreaming park revision=N reason="..."', "block": '/upstreaming block revision=N reason="..."', "abandon": '/upstreaming abandon revision=N reason="..."', + "restart": '/upstreaming restart revision=N reason="..."', "resume": '/upstreaming resume revision=N reason="..."', } diff --git a/upstreaming/commands.py b/upstreaming/commands.py index bddd0dbf6abe..ce63373bc1e2 100644 --- a/upstreaming/commands.py +++ b/upstreaming/commands.py @@ -46,6 +46,9 @@ "revise-scope": {"contribution": _ID, "revision": _INT, "proposal": _ID}, "block": {"contribution": _ID, "revision": _INT, "reason": _REASON}, "abandon": {"contribution": _ID, "revision": _INT, "reason": _REASON}, + # Start a new lifecycle generation on the same tracking issue. This is + # deliberately allowed only after abandon and requires an exact revision. + "restart": {"contribution": _ID, "revision": _INT, "reason": _REASON}, "resolve-operation": { "operation": _ID, "disposition": r"confirmed|not-launched|failed", diff --git a/upstreaming/lifecycle.py b/upstreaming/lifecycle.py index 08aab7866d56..20b9a71cec7a 100644 --- a/upstreaming/lifecycle.py +++ b/upstreaming/lifecycle.py @@ -64,7 +64,8 @@ class Outcome: def _event(before: dict, after: dict, kind: str, cause_type: str, cause_id: str | None, now: str, bumped: bool) -> dict: - keys = ("phase", "activity", "paused", "revision", "blocked_reason", "parked_reason") + keys = ("phase", "activity", "paused", "revision", "generation", + "blocked_reason", "parked_reason") return { "schema_version": 1, "contribution_id": after["contribution_id"], @@ -158,6 +159,43 @@ def _reject(record: dict, reason: str) -> Outcome: return Outcome(record, False, reason, None) +def _restart_generation(record: dict, now: str) -> dict: + """Reset mutable lifecycle state while retaining identity and replay fences.""" + rec = copy.deepcopy(record) + rec.update({ + "generation": int(record.get("generation", 0)) + 1, + "phase": "queued", "activity": "idle", "paused": False, + "blocked_reason": None, "parked_reason": None, "terminal_reason": None, + "previous_phase": None, + "owners": {"primary": None, "backup": None, "submitter": None, + "handoff_reviewer": None}, + "admission_class": None, + "upstream": {"repository_id": None, "full_name": record["upstream"]["full_name"], + "base_ref": None, "base_sha": None}, + "fork": None, "upstream_pr": None, "target_contract_id": None, + "prerequisite_ids": [], "active_operation_id": None, + "queue_work_id": None, "queue_claim_handle": None, "queue_result_id": None, + "proposal_artifact": None, "publication_operation_id": None, + "pending_publication": None, + # Keep processed_publications as a replay fence against old run artifacts. + "processed_review_ids": [], "processed_review_comment_ids": [], + "processed_pr_conversation_comment_ids": [], + "pending_feedback_evidence_ids": [], "active_work": None, + "dossier_evidence_id": None, "scope_coverage_complete": False, + "scope_paths": None, "debug_commits": [], "clean_head_sha": None, + "handoff_request": None, "handoff_approval": None, + "last_ci_evidence_id": None, "merge": None, "retirement": None, + "release_acceptance": None, "pending_human_action": None, + "next_poll_at": None, "updated_at": now, + }) + budget = record["budget"] + rec["budget"] = {"policy_id": budget["policy_id"], "attempts_used": 0, + "no_progress_streak": 0, "clusters": {}, + "spent_estimate_usd_cents": 0} + _bump(rec) + return rec + + def apply_command(record: dict, cmd: Command, *, command_id: str, actor: dict, now: str, verified_pr: dict | None = None, provisioning: dict | None = None, backup_user: dict | None = None) -> Outcome: @@ -184,7 +222,7 @@ def apply_command(record: dict, cmd: Command, *, command_id: str, actor: dict, n # Everything that (re)activates or approves work must name the current revision. if cmd.verb not in ("pause", "block", "park", "abandon") and rev != cur: return _reject(record, f"stale revision {rev}, current is {cur}") - if phase in TERMINAL and cmd.verb != "authorize-followup": + if phase in TERMINAL and cmd.verb not in ("authorize-followup", "restart"): return _reject(record, f"contribution is terminal ({phase})") rec = copy.deepcopy(record) @@ -226,6 +264,15 @@ def apply_command(record: dict, cmd: Command, *, command_id: str, actor: dict, n rec["phase"] = "abandoned" rec["terminal_reason"] = a["reason"] rec["activity"] = "idle" + elif v == "restart": + if phase != "abandoned": + return _reject(record, f"restart needs phase abandoned, not {phase}") + if record.get("active_work"): + return _reject(record, "cannot restart while Work is active") + if record.get("active_operation_id") or record.get("pending_publication"): + return _reject(record, "cannot restart while a writer operation is active") + rec = _restart_generation(record, now) + bumped = True elif v == "request-handoff": if phase != "development": return _reject(record, f"request-handoff needs phase development, not {phase}") @@ -424,6 +471,7 @@ def new_contribution(*, contribution_id: str, project_id: str, issue: dict, upst "contribution_id": contribution_id, "project_id": project_id, "revision": 0, + "generation": 0, "phase": "queued", "activity": "idle", "paused": False, diff --git a/upstreaming/schemas/contribution.schema.json b/upstreaming/schemas/contribution.schema.json index 559b3b4a6650..f54c9c8c8e38 100644 --- a/upstreaming/schemas/contribution.schema.json +++ b/upstreaming/schemas/contribution.schema.json @@ -34,6 +34,10 @@ "type": "integer", "minimum": 0 }, + "generation": { + "type": "integer", + "minimum": 0 + }, "phase": { "enum": [ "queued", diff --git a/upstreaming/status_ledger.py b/upstreaming/status_ledger.py index 330a59af1925..de6fb8b12095 100644 --- a/upstreaming/status_ledger.py +++ b/upstreaming/status_ledger.py @@ -40,6 +40,8 @@ def _command_lines(record: dict) -> list[str]: f'/upstreaming abandon revision={revision} reason="..."'] if record.get("paused") or record.get("blocked_reason"): lines.append(f'/upstreaming resume revision={revision} reason="..."') + if phase == "abandoned": + lines.append(f'/upstreaming restart revision={revision} reason="..."') if phase == "parked": paths = ",".join(record.get("scope_paths") or [".github/workflows/*"]) admission = record.get("admission_class") or "configuration_integration" diff --git a/upstreaming/tests/test_command_feedback.py b/upstreaming/tests/test_command_feedback.py index 13c1b6dc8cce..37feaeb8951e 100644 --- a/upstreaming/tests/test_command_feedback.py +++ b/upstreaming/tests/test_command_feedback.py @@ -27,6 +27,14 @@ def request(self, method, path, body=None): class TestCommandFeedback(unittest.TestCase): + def test_rejected_restart_has_actionable_template(self): + receipt = {"comment_id": 42, "actor": {"login": "luhenry"}, "verb": "restart", + "reason": "stale revision 7, current is 8"} + original = {"body": "/upstreaming restart revision=7 reason=r", + "user": {"login": "luhenry"}} + body = command_feedback.render(receipt, original) + self.assertIn('/upstreaming restart revision=7 reason="..."', 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_commands_intake.py b/upstreaming/tests/test_commands_intake.py index 8b3de6c8f286..886e3a886038 100644 --- a/upstreaming/tests/test_commands_intake.py +++ b/upstreaming/tests/test_commands_intake.py @@ -75,8 +75,11 @@ def test_stop_commands_need_no_ids(self): def test_work_changing_commands_still_need_revision(self): self.assertEqual(commands.parse("/upstreaming resume revision=3 reason=r").revision, 3) + self.assertEqual(commands.parse("/upstreaming restart revision=8 reason=r").revision, 8) with self.assertRaises(commands.CommandError): commands.parse("/upstreaming resume reason=r") + with self.assertRaises(commands.CommandError): + commands.parse("/upstreaming restart reason=r") with self.assertRaises(commands.CommandError): commands.parse("/upstreaming park") # park still needs a reason diff --git a/upstreaming/tests/test_lifecycle.py b/upstreaming/tests/test_lifecycle.py index 8f32d6b55829..475a6945c66f 100644 --- a/upstreaming/tests/test_lifecycle.py +++ b/upstreaming/tests/test_lifecycle.py @@ -114,6 +114,53 @@ def test_terminal_rejects(self): self.assertFalse(apply(rec, f"/upstreaming resume contribution={CID} revision=0 reason=r").accepted) +class TestRestartGeneration(unittest.TestCase): + def test_abandoned_contribution_restarts_on_same_identity(self): + rec = contribution( + phase="abandoned", generation=2, revision=8, terminal_reason="old attempt", + scope_paths=[".github/workflows/wheels.yml"], dossier_evidence_id="dossier-old", + scope_coverage_complete=True, processed_publications=[11, 12], + processed_review_ids=[21], processed_review_comment_ids=[22], + processed_pr_conversation_comment_ids=[23], + pending_feedback_evidence_ids=["review-old"], + proposal_artifact={"artifact_id": 1}, last_ci_evidence_id="ci-old", + budget={"policy_id": "test", "attempts_used": 3, "no_progress_streak": 2, + "clusters": {"x": 2}, "spent_estimate_usd_cents": 99}) + out = apply(rec, f'/upstreaming restart contribution={CID} revision=8 reason="clean start"') + self.assertTrue(out.accepted) + restarted = out.record + self.assertEqual(restarted["contribution_id"], CID) + self.assertEqual(restarted["tracking_issue"], rec["tracking_issue"]) + self.assertEqual((restarted["generation"], restarted["revision"]), (3, 9)) + self.assertEqual((restarted["phase"], restarted["activity"]), ("queued", "idle")) + self.assertIsNone(restarted["fork"]) + self.assertIsNone(restarted["dossier_evidence_id"]) + self.assertIsNone(restarted["scope_paths"]) + self.assertIsNone(restarted["proposal_artifact"]) + self.assertEqual(restarted["processed_publications"], [11, 12]) + self.assertEqual(restarted["processed_review_comment_ids"], []) + self.assertEqual(restarted["pending_feedback_evidence_ids"], []) + self.assertEqual(restarted["budget"]["attempts_used"], 0) + self.assertEqual(out.event["kind"], "command:restart") + self.assertTrue(out.event["revision_bumped"]) + schemas.validate("contribution", restarted) + + def test_restart_is_abandoned_only_and_stale_proof(self): + self.assertFalse(apply(contribution(), + f"/upstreaming restart contribution={CID} revision=0 reason=r").accepted) + abandoned = contribution(phase="abandoned", revision=2) + self.assertFalse(apply(abandoned, + f"/upstreaming restart contribution={CID} revision=1 reason=r").accepted) + + def test_restart_waits_for_writer_quiescence(self): + for rec in (contribution(phase="abandoned", active_work={"x": 1}), + contribution(phase="abandoned", active_operation_id="op-1"), + contribution(phase="abandoned", pending_publication={"x": 1})): + with self.subTest(record=rec): + self.assertFalse(apply(rec, + f"/upstreaming restart contribution={CID} revision=0 reason=r").accepted) + + class TestHandoff(unittest.TestCase): def test_request_needs_evidence_and_head(self): rec = contribution() diff --git a/upstreaming/tests/test_status_ledger.py b/upstreaming/tests/test_status_ledger.py index e0bfd68b37a5..739a418dfe1e 100644 --- a/upstreaming/tests/test_status_ledger.py +++ b/upstreaming/tests/test_status_ledger.py @@ -49,6 +49,15 @@ def test_render_has_short_summary_and_folded_prefilled_commands(self): self.assertIn("/upstreaming force-develop revision=4", body) self.assertIn("