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
1 change: 1 addition & 0 deletions SESSIONLOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
5 changes: 5 additions & 0 deletions upstreaming/INTEGRATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions upstreaming/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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=<clean head sha>
```
Expand Down Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions upstreaming/command_feedback.py
Original file line number Diff line number Diff line change
Expand Up @@ -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="..."',
}

Expand Down
3 changes: 3 additions & 0 deletions upstreaming/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
52 changes: 50 additions & 2 deletions upstreaming/lifecycle.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down Expand Up @@ -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:
Expand All @@ -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)
Expand Down Expand Up @@ -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}")
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions upstreaming/schemas/contribution.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@
"type": "integer",
"minimum": 0
},
"generation": {
"type": "integer",
"minimum": 0
},
"phase": {
"enum": [
"queued",
Expand Down
2 changes: 2 additions & 0 deletions upstreaming/status_ledger.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
8 changes: 8 additions & 0 deletions upstreaming/tests/test_command_feedback.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand Down
3 changes: 3 additions & 0 deletions upstreaming/tests/test_commands_intake.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
47 changes: 47 additions & 0 deletions upstreaming/tests/test_lifecycle.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
9 changes: 9 additions & 0 deletions upstreaming/tests/test_status_ledger.py
Original file line number Diff line number Diff line change
Expand Up @@ -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("<!-- upstreaming-ledger:", body)

def test_abandoned_ledger_offers_same_issue_restart(self):
record = contribution(phase="abandoned", activity="idle", revision=8,
terminal_reason="restart requested")
event = lifecycle._event(record, record, "command:abandon", "command", "c", NOW, False)
event["sequence"] = 9
body = status_ledger.render(event, record, "https://github.com/run")
self.assertIn('/upstreaming restart revision=8 reason="..."', body)
self.assertNotIn("/upstreaming resume", body)

def test_publish_appends_one_app_authored_comment_for_written_event(self):
with tempfile.TemporaryDirectory() as td:
root = Path(td); _record, _event, path = self.records(root); api = FakeApi()
Expand Down