Skip to content
36 changes: 36 additions & 0 deletions docs/trusted-local-delivery.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,42 @@ create its reports before the dedicated browser gate. Nested output parents are
created only inside an authenticated checkout. Existing unregistered outputs,
tracked contents, protected paths and symlinked parents remain rejected.

A check stopped before launch by execution readiness records a versioned failure
class with its stage, candidate and immutable readiness-receipt digest. The
existing zero-repair gate control can admit at most two fresh readiness retries
for the unchanged candidate, preserving the old receipt, attempt and effect
ledger. Every retry probes readiness again and runs the original frozen gate;
its readiness receipt is never a gate pass. Other failed gates, pending product
findings, uncertain cleanup, changed source or unsettled effects refuse admission.
The first readiness retry waits 30 seconds after the authenticated predecessor
closes; the second waits 60 seconds after its predecessor closes. A missing or
ambiguous close time is reported as `readiness_retry_clock_unknown`, and an
unexpired delay as `readiness_retry_backoff`. Waiting allocates no new attempt,
admission, effect or product-repair grant. The delay is derived from the closed
workflow, so restarting the control service does not restart or bypass it.
The initial route is qualified only for the fake fixture provider: native runs
refuse with `native_descendant_settlement_unknown` until a complete descendant
settlement contract can be authenticated. An exhausted retry allowance reports
`readiness_retry_limit_exhausted`. Neither blocker is a launch grant. A transient
unpublished stop with a recorded passing implementation is retained for an
authenticated same-candidate continuation; the automatic fresh-run path refuses
to replace it with another implementation. For a feature worker, the new
readiness path also requires an already authenticated successor assignment. The
current coordinator examines the stopped worker before reserving that assignment,
so an unreserved continuation remains blocked rather than bypassing ownership.

For a feature-plan correction stopped before its review launch envelope is
written, the unreviewed-predecessor check can reconstruct the review identity
from the sealed revision, proposal, candidate and owner. It also requires the
supervisor's completed prelaunch result, registered workspace, an empty attempt
directory and the original unheld owner lease. A missing request alone does not
prove the exception, and a real adverse review remains a rejection. The strict
reconsideration reader classifies the same evidence as prelaunch, never as an
independent review. When a later genuine review is reconsidered, its history
retains the earlier prelaunch intent digest without inventing a request digest.
Generic completed-resource observation still requires its existing request
evidence for this early shape.

An older run stopped by that browser-output registration defect can use one
`published_check_prelaunch_retry` with zero additional implementation turns.
Admission requires its exact closed UNKNOWN checkpoint, passed local checks and
Expand Down
12 changes: 7 additions & 5 deletions runtime/src/devflow_temporal/delivery_activities.py
Original file line number Diff line number Diff line change
Expand Up @@ -1221,12 +1221,13 @@ def _check_readiness(broker, request, attempt):
workspace = broker.gate_checkout("verify", request["iteration"], request["candidate"])
requirements = describe_requirements(
request["spec"], workspace, request["spec"].get("accepted_plan", ""))
generation = int(digest({"spec": request["spec"], "candidate": request["candidate"]})[:5],
16) % 300000
probe_attempt = 10 + generation * 3 + {100: 0, 101: 1, 102: 2}[attempt]
from .delivery_readiness_gate_retry import SLOTS, failure, probe_attempt

stage = next(name for name, slot in SLOTS.items() if slot == attempt)
selected_attempt = probe_attempt(request["spec"], request["candidate"], attempt)
readiness = prepare_and_probe(broker.store, request["spec"], request["candidate"],
requirements, "plan", iteration=request["iteration"],
attempt=probe_attempt, workspace=workspace)
attempt=selected_attempt, workspace=workspace)
if readiness.get("state") == "passed":
verify_receipt(broker.store, request["spec"], request["candidate"], readiness, requirements)
return readiness
Expand All @@ -1237,7 +1238,8 @@ def _check_readiness(broker, request, attempt):
"failure_kind": "readiness_preparation", "launched": False,
"cleanup": cleanup, "candidate_id": request["candidate"]["id"],
"source_unchanged": broker.candidate() == request["candidate"],
"reason": "execution readiness prevented the check", "readiness": readiness}
"reason": "execution readiness prevented the check", "readiness": readiness,
"failure_class": failure(readiness, stage, request["candidate"]["id"], cleanup)}


@activity.defn(name="delivery_checks")
Expand Down
13 changes: 13 additions & 0 deletions runtime/src/devflow_temporal/delivery_automatic_retry.py
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,19 @@ def retry_once(store, *, stopped=lambda: False):
'SELECT issue_url FROM delivery_runs'))
if count >= spec['policy']['max_attempts'] or unavailable(store, db, spec):
continue
roles = result.get('roles')
if not isinstance(roles, list) or any(not isinstance(role, dict) for role in roles):
_record_skip(store, row, ValueError(
'closed run lacks its complete implementation history'))
continue
if any(role.get('role') == 'implement' and role.get('status') == 'pass'
for role in roles):
# A fresh run would start implementation again and abandon the
# stopped candidate. It is not a same-candidate retry grant.
_record_skip(store, row, ValueError(
'retained implementation requires an authenticated same-candidate '
'continuation; inspect the stopped recovery options'))
continue
base = fresh_unpublished_base(store, spec)
identity = digest({'run_id': spec['run_id'],
'request_digest': row['request_digest']})[:24]
Expand Down
59 changes: 56 additions & 3 deletions runtime/src/devflow_temporal/delivery_feature_revisions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1652,6 +1652,32 @@ def _private_canonical(path, expected):
return hashlib.sha256(encoded).hexdigest()


def _early_revision_prelaunch(store, spec, attempt, expected, *, closed_at=None):
"""Observe a sealed revision review that stopped before persisting its envelope."""
from .delivery_prelaunch_cleanup import completed_prelaunch
from .delivery_resources import RunResources

intent = {key: expected[key] for key in (
"spec", "role", "iteration", "candidate", "resume_session", "revision_context",
"workspace",
)}
registry = RunResources(spec, read_only=True)
with registry.locked(read_only=True) as manifest:
with completed_prelaunch(spec, dict(attempt), {Path(spec["state_dir"]): spec}, manifest,
early_revision_intent=intent) as observed:
with store._connect() as db:
current = db.execute(
"SELECT * FROM delivery_attempts WHERE run_id=? AND job_key=?",
(spec["run_id"], attempt["job_key"]),
).fetchone()
finished = datetime.fromisoformat(attempt["finished_at"])
if (not current or dict(current) != dict(attempt) or finished.tzinfo is None
or (closed_at is not None and finished > closed_at)):
raise ValueError("early revision attempt changed or did not precede closure")
result = json.loads(attempt["result_json"])
return result, observed


def _saved_revision_role(store, spec, context, proposal, candidate, role, *, closed_at=None,
shared=None):
"""Authenticate the exact supervised launcher and actual completed provider."""
Expand Down Expand Up @@ -1692,6 +1718,13 @@ def _saved_revision_role(store, spec, context, proposal, candidate, role, *, clo
if steering and json.loads(steering[0]):
expected["steering"] = json.loads(steering[0])
request_path = folder / "request.json"
if role == "review" and not os.path.lexists(request_path):
result, observed = _early_revision_prelaunch(store, spec, saved, expected,
closed_at=closed_at)
return result, {"run_id": spec["run_id"], "job_key": key,
"intent_sha256": observed["revision_intent_sha256"],
"result_sha256": digest(result), "session_id": None,
"classification": "prelaunch", "prelaunch_evidence": observed}
if request_path.resolve(strict=True) != request_path:
raise ValueError("historical native request left its exact owned path")
request = read_private(request_path)
Expand Down Expand Up @@ -2011,10 +2044,13 @@ def _prove_reconsideration(store, spec, selectors, record, closure, values, *, p
_text(text, "unresolved prior finding", maximum=16 * 1024)
if text not in findings:
findings.append(text)
review = proof["review"]
review_identity = ({"review_request_sha256": review["request_sha256"]}
if "request_sha256" in review else
{"review_intent_sha256": review["intent_sha256"]})
predecessors.append({"revision_id": proof["revision_id"],
"classification": proof["classification"],
"review_request_sha256": proof["review"]["request_sha256"],
"review_result_sha256": proof["review"]["result_sha256"]})
"classification": proof["classification"], **review_identity,
"review_result_sha256": review["result_sha256"]})
product_findings = [text for worker in subject["worker_summaries"]
for text in (worker.get("current_review_subject") or {}).get(
"unresolved_product_findings", [])]
Expand Down Expand Up @@ -2261,6 +2297,23 @@ def _unreviewed_rejection(store, spec, context, rejected, values):
str(Path(historical["state_dir"]) / "gates" / "0" / "review")),
)
request_path = folder / "request.json"
if role == "review" and not os.path.lexists(request_path):
# The revision and proposal identity were reconstructed from
# immutable coordinator checkpoints above, not from a caller.
# A supervisor may refuse preparation before it persists the
# later native launch envelope, so prove the typed terminal
# attempt under its original owner lease instead.
if not attempt:
return None
result, observed = _early_revision_prelaunch(
store, historical, attempt, expected, closed_at=closed_at)
proof = {
"revision_id": revision_id, "review_job_key": key,
"review_intent_digest": observed["revision_intent_sha256"],
"review_result_digest": digest(result), "predecessor_closure": closure,
"prelaunch_evidence": observed,
}
continue
if request_path.resolve(strict=True) != request_path:
return None
request = read_private(request_path)
Expand Down
Loading
Loading