73 interactive: bool =
False,
74 prompter: Prompter |
None =
None,
76 """Resume the most recent resumable round-job for ``ctx.round_no``."""
79 backend = ctx.registry.backend
80 job = backend.latest_round_job(ctx.round_no, statuses=RESUMABLE_STATUSES)
81 job_id =
None if job
is None else str(job[
"job_id"])
82 preflight = preflight_resume(ctx.registry, round_no=ctx.round_no, job_id=job_id)
85 assert job
is not None
86 ctx.job_id = str(job[
"job_id"])
87 steps = build_step_plan(ctx)
88 step_rows = backend.list_round_job_steps(ctx.job_id)
89 done = [row
for row
in step_rows
if str(row[
"status"]) ==
"done"]
90 highest_done = max((int(row[
"step_no"])
for row
in done), default=0)
91 start_step = highest_done + 1
92 if start_step > len(steps):
93 backend.set_round_job_status(
94 ctx.job_id, status=
"done", current_step=
"cleanup"
96 _dbg(
"OC_CHAT.MAIN", func,
"nothing left to resume", 2)
103 next_phase=steps[start_step - 1].phase,
105 if divergence
is not None:
106 backend.set_round_job_status(
107 ctx.job_id, status=
"failed", current_step=steps[start_step - 1].step_name
109 _dbg(
"OC_CHAT.MAIN", func,
"staging branch diverged", 2)
112 _dbg(
"OC_CHAT.MAIN", func, f
"resume from step {start_step}", 2)
115 start_step=start_step,
116 interactive=interactive,
124 job: dict[str, object],
125 done_rows: list[dict[str, object]],
127) -> Escalation |
None:
128 func =
"_check_divergence"
129 if not ctx.git.branch_exists(ctx.staging_branch):
130 return _diverged(ctx, expected=
_text(job.get(
"staging_branch_head_sha")), actual=
None)
131 actual_head = ctx.git.rev_parse(ctx.staging_branch)
132 expected_head =
_text(job.get(
"staging_branch_head_sha"))
133 known_heads: set[str] = set()
135 known_heads.add(expected_head)
136 for row
in done_rows:
137 head =
_text(row.get(
"post_step_head_sha"))
139 known_heads.add(head)
140 if actual_head
in known_heads:
141 _dbg(
"OC_CHAT.MAIN", func,
"head matches known state", 3)
145 next_phase ==
"merge"
147 and ctx.git.is_ancestor(expected_head, actual_head)
149 _dbg(
"OC_CHAT.MAIN", func,
"crash-after-merge; re-attempt", 2)
151 return _diverged(ctx, expected=expected_head, actual=actual_head)