@elvis1513/auto-coding-skill 4.3.3 → 4.3.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +52 -1
- package/cli/assets/managed-install.json +1 -1
- package/cli/assets/skill/SKILL.md +8 -0
- package/cli/assets/skill/data/policies/workflow-migrations-v1.json +2 -2
- package/cli/assets/skill/data/templates/ENGINEERING.md +2 -2
- package/cli/assets/skill/data/templates/bridges/AGENTS.md +9 -1
- package/cli/assets/skill/scripts/ap.py +1044 -35
- package/cli/tests/ap_concurrency_test.py +335 -2
- package/cli/tests/core_shell_test.py +5 -5
- package/cli/tests/index.test.js +34 -33
- package/package.json +1 -1
|
@@ -97,10 +97,23 @@ _REVIEW_RUNTIME_FIELDS = (
|
|
|
97
97
|
"runtime_override_path",
|
|
98
98
|
"runtime_override_sha256",
|
|
99
99
|
)
|
|
100
|
+
_REVIEW_RETRY_FIELDS = (
|
|
101
|
+
"runtime_retry_token",
|
|
102
|
+
"runtime_retry_version",
|
|
103
|
+
"runtime_retry_reason_code",
|
|
104
|
+
"runtime_retry_audit_path",
|
|
105
|
+
"runtime_retry_audit_sha256",
|
|
106
|
+
)
|
|
107
|
+
_REVIEW_RUNTIME_RETRY_REASON = "managed-review-artifact-access"
|
|
108
|
+
_REVIEW_RUNTIME_RETRY_AFFECTED_MIN = (4, 2, 8)
|
|
109
|
+
_REVIEW_RUNTIME_RETRY_AFFECTED_MAX = (4, 3, 2)
|
|
110
|
+
_REVIEW_RUNTIME_RETRY_FIXED_IN = (4, 3, 4)
|
|
111
|
+
_REVIEW_RUNTIME_RETRY_REPAIRED_IN = (4, 3, 5)
|
|
100
112
|
_REVIEW_OUTPUT_MAX_BYTES = 1024 * 1024
|
|
101
113
|
_REVIEW_DIFF_ARTIFACT_FORMAT = "git-binary-patch-v1"
|
|
102
114
|
_REVIEW_DIFF_ARTIFACT_MAX_BYTES = 64 * 1024 * 1024
|
|
103
115
|
_REVIEW_SHA256_RE = re.compile(r"^[0-9a-f]{64}$")
|
|
116
|
+
_REVIEW_ATTEMPT_TOKEN_RE = re.compile(r"^retry-v[0-9]+\.[0-9]+\.[0-9]+$")
|
|
104
117
|
_FEEDBACK_SCHEMAS = {
|
|
105
118
|
"auto-coding-skill-feedback/v1",
|
|
106
119
|
"auto-coding-skill-feedback/v2",
|
|
@@ -287,7 +300,7 @@ _FINAL_GATE_CACHE_ALGORITHM = "final-gate-v1"
|
|
|
287
300
|
_WORKFLOW_MIGRATION_POLICY = Path("data/policies/workflow-migrations-v1.json")
|
|
288
301
|
_FALLBACK_WORKFLOW_MIGRATION_POLICY = {
|
|
289
302
|
"schema_version": 1,
|
|
290
|
-
"managed_versions": {"agents": "4.3.
|
|
303
|
+
"managed_versions": {"agents": "4.3.5", "engineering": "4.3.5"},
|
|
291
304
|
"known_official_engineering_body_sha256": [
|
|
292
305
|
"d1306cc626e8baf8c83c953b760fd771066de2bf125168eca3a7b7d6ff2b87a2",
|
|
293
306
|
"305931c6edef770033a4f1970b00e5fb1c1728351856a173dbfa497daf563021",
|
|
@@ -5811,6 +5824,8 @@ def _validate_review_runtime_override(repo: Path, manifest: dict, fingerprint: s
|
|
|
5811
5824
|
repo,
|
|
5812
5825
|
_text(manifest.get("task_id")),
|
|
5813
5826
|
fingerprint,
|
|
5827
|
+
_review_attempt_token(review),
|
|
5828
|
+
create=False,
|
|
5814
5829
|
)
|
|
5815
5830
|
del expected_result_path
|
|
5816
5831
|
if receipt_path != expected_receipt_path.resolve():
|
|
@@ -5875,6 +5890,15 @@ def _require_approved_review(repo: Path, cfg: dict, manifest: dict) -> str:
|
|
|
5875
5890
|
_validate_review_diff_artifact(repo, assignment)
|
|
5876
5891
|
if verdict == "runtime-bypassed":
|
|
5877
5892
|
_validate_review_runtime_override(repo, manifest, fingerprint)
|
|
5893
|
+
elif _review_attempt_token(review):
|
|
5894
|
+
receipt_path = Path(_text(review.get("runtime_receipt_path"))).resolve()
|
|
5895
|
+
_validate_bound_review_runtime_receipt(
|
|
5896
|
+
repo,
|
|
5897
|
+
manifest,
|
|
5898
|
+
assignment,
|
|
5899
|
+
receipt_path,
|
|
5900
|
+
"completed",
|
|
5901
|
+
)
|
|
5878
5902
|
return fingerprint
|
|
5879
5903
|
|
|
5880
5904
|
|
|
@@ -13242,12 +13266,27 @@ def _task_status_payload(repo: Path, manifest: dict) -> dict:
|
|
|
13242
13266
|
)
|
|
13243
13267
|
review = manifest.get("review") or {}
|
|
13244
13268
|
deadline_at = _text(review.get("deadline_at"))
|
|
13269
|
+
effective_deadline_at = deadline_at
|
|
13245
13270
|
review_seconds_remaining: Optional[int] = None
|
|
13246
13271
|
review_deadline_expired = False
|
|
13272
|
+
if _review_attempt_token(review):
|
|
13273
|
+
try:
|
|
13274
|
+
assignment = _load_bound_review_assignment(
|
|
13275
|
+
repo,
|
|
13276
|
+
manifest,
|
|
13277
|
+
Path(_text(review.get("assignment_path"))).resolve(),
|
|
13278
|
+
)
|
|
13279
|
+
effective_deadline_at = _effective_review_deadline(
|
|
13280
|
+
repo,
|
|
13281
|
+
manifest,
|
|
13282
|
+
assignment,
|
|
13283
|
+
).isoformat()
|
|
13284
|
+
except APError:
|
|
13285
|
+
effective_deadline_at = ""
|
|
13247
13286
|
if deadline_at:
|
|
13248
13287
|
try:
|
|
13249
13288
|
remaining = (
|
|
13250
|
-
_parse_iso_timestamp(
|
|
13289
|
+
_parse_iso_timestamp(effective_deadline_at, "effective_deadline_at")
|
|
13251
13290
|
- _dt.datetime.now(_dt.timezone.utc)
|
|
13252
13291
|
).total_seconds()
|
|
13253
13292
|
seconds = int(remaining)
|
|
@@ -13264,6 +13303,7 @@ def _task_status_payload(repo: Path, manifest: dict) -> dict:
|
|
|
13264
13303
|
"tip": tip,
|
|
13265
13304
|
"has_task_commits": has_task_commits,
|
|
13266
13305
|
"merged_into_target": merged,
|
|
13306
|
+
"review_effective_deadline_at": effective_deadline_at,
|
|
13267
13307
|
"review_deadline_expired": review_deadline_expired,
|
|
13268
13308
|
"review_seconds_remaining": review_seconds_remaining,
|
|
13269
13309
|
"current_diff_fingerprint": _task_review_fingerprint(worktree, manifest)
|
|
@@ -13495,10 +13535,30 @@ def _parse_iso_timestamp(value: object, field: str) -> _dt.datetime:
|
|
|
13495
13535
|
return parsed.astimezone(_dt.timezone.utc)
|
|
13496
13536
|
|
|
13497
13537
|
|
|
13498
|
-
def
|
|
13538
|
+
def _review_attempt_token(review: object) -> str:
|
|
13539
|
+
payload = review if isinstance(review, dict) else {}
|
|
13540
|
+
token = _text(payload.get("runtime_retry_token"))
|
|
13541
|
+
if token and not _REVIEW_ATTEMPT_TOKEN_RE.fullmatch(token):
|
|
13542
|
+
raise APError("Reviewer runtime retry token is invalid.")
|
|
13543
|
+
return token
|
|
13544
|
+
|
|
13545
|
+
|
|
13546
|
+
def _review_attempt_stem(fingerprint: str, attempt_token: str = "") -> str:
|
|
13499
13547
|
if not _REVIEW_SHA256_RE.fullmatch(_text(fingerprint)):
|
|
13500
13548
|
raise APError("Review fingerprint must be a lowercase SHA-256 value.")
|
|
13501
|
-
|
|
13549
|
+
token = _text(attempt_token)
|
|
13550
|
+
if token and not _REVIEW_ATTEMPT_TOKEN_RE.fullmatch(token):
|
|
13551
|
+
raise APError("Reviewer runtime retry token is invalid.")
|
|
13552
|
+
return f"{fingerprint}.{token}" if token else fingerprint
|
|
13553
|
+
|
|
13554
|
+
|
|
13555
|
+
def _review_assignment_path(
|
|
13556
|
+
control_repo: Path,
|
|
13557
|
+
task_id: str,
|
|
13558
|
+
fingerprint: str,
|
|
13559
|
+
) -> Path:
|
|
13560
|
+
stem = _review_attempt_stem(fingerprint)
|
|
13561
|
+
return _task_review_dir(control_repo, task_id) / f"{stem}.assignment.json"
|
|
13502
13562
|
|
|
13503
13563
|
|
|
13504
13564
|
def _review_diff_artifact_path(control_repo: Path, task_id: str, fingerprint: str) -> Path:
|
|
@@ -13811,8 +13871,16 @@ def cmd_review_assignment(args: argparse.Namespace) -> None:
|
|
|
13811
13871
|
"scope_revision": int(manifest.get("scope_revision") or 1),
|
|
13812
13872
|
}
|
|
13813
13873
|
_validate_orchestration_contract("assignment", assignment)
|
|
13814
|
-
assignment_path = _review_assignment_path(control_repo, task_id, fingerprint)
|
|
13815
13874
|
prior_review = manifest.get("review") or {}
|
|
13875
|
+
assignment_path = _review_assignment_path(control_repo, task_id, fingerprint)
|
|
13876
|
+
if (
|
|
13877
|
+
_text(prior_review.get("diff_fingerprint")) == fingerprint
|
|
13878
|
+
and _review_attempt_token(prior_review)
|
|
13879
|
+
):
|
|
13880
|
+
raise APError(
|
|
13881
|
+
"A bounded Reviewer runtime retry is already authorized; run review-run with "
|
|
13882
|
+
"the original Reviewer identity."
|
|
13883
|
+
)
|
|
13816
13884
|
if (
|
|
13817
13885
|
_text(prior_review.get("diff_fingerprint")) == fingerprint
|
|
13818
13886
|
and (
|
|
@@ -13962,7 +14030,7 @@ def cmd_review_assignment(args: argparse.Namespace) -> None:
|
|
|
13962
14030
|
"deadline_at": assignment["deadline_at"],
|
|
13963
14031
|
}
|
|
13964
14032
|
if _text(prior_review.get("diff_fingerprint")) == fingerprint:
|
|
13965
|
-
for field in _REVIEW_RUNTIME_FIELDS:
|
|
14033
|
+
for field in _REVIEW_RUNTIME_FIELDS + _REVIEW_RETRY_FIELDS:
|
|
13966
14034
|
if field in prior_review:
|
|
13967
14035
|
review_state[field] = prior_review[field]
|
|
13968
14036
|
manifest["review"] = review_state
|
|
@@ -13993,10 +14061,15 @@ def cmd_review_artifact(args: argparse.Namespace) -> None:
|
|
|
13993
14061
|
raise APError(
|
|
13994
14062
|
f"Review artifact must be read from its assigned worktree: expected={assigned_worktree}, current={repo}."
|
|
13995
14063
|
)
|
|
13996
|
-
|
|
13997
|
-
|
|
13998
|
-
|
|
13999
|
-
|
|
14064
|
+
deadline = _effective_review_deadline(
|
|
14065
|
+
repo,
|
|
14066
|
+
manifest,
|
|
14067
|
+
assignment,
|
|
14068
|
+
require_environment=bool(_review_attempt_token(manifest.get("review") or {})),
|
|
14069
|
+
require_same_runtime=bool(_review_attempt_token(manifest.get("review") or {})),
|
|
14070
|
+
verify_worktree_snapshot=False,
|
|
14071
|
+
)
|
|
14072
|
+
if _dt.datetime.now(_dt.timezone.utc) >= deadline:
|
|
14000
14073
|
raise APError("Review assignment deadline expired before diff artifact access.")
|
|
14001
14074
|
payload = _validate_review_diff_artifact(repo, assignment)
|
|
14002
14075
|
sys.stdout.flush()
|
|
@@ -14011,26 +14084,61 @@ def _write_private_json(path: Path, payload: dict) -> None:
|
|
|
14011
14084
|
_write_private_bytes(path, encoded)
|
|
14012
14085
|
|
|
14013
14086
|
|
|
14087
|
+
def _create_private_json(path: Path, payload: dict, label: str) -> None:
|
|
14088
|
+
encoded = (
|
|
14089
|
+
json.dumps(payload, ensure_ascii=False, indent=2, sort_keys=True) + "\n"
|
|
14090
|
+
).encode("utf-8")
|
|
14091
|
+
handle = _open_private_review_event_log(path)
|
|
14092
|
+
try:
|
|
14093
|
+
handle.write(encoded.decode("utf-8"))
|
|
14094
|
+
handle.flush()
|
|
14095
|
+
os.fsync(handle.fileno())
|
|
14096
|
+
except Exception:
|
|
14097
|
+
handle.close()
|
|
14098
|
+
path.unlink(missing_ok=True)
|
|
14099
|
+
raise
|
|
14100
|
+
handle.close()
|
|
14101
|
+
if _private_review_file_sha256(path, label) != hashlib.sha256(encoded).hexdigest():
|
|
14102
|
+
raise APError(f"Review {label} changed during create-only publication.")
|
|
14103
|
+
|
|
14104
|
+
|
|
14014
14105
|
def _review_runtime_paths(
|
|
14015
14106
|
control_repo: Path,
|
|
14016
14107
|
task_id: str,
|
|
14017
14108
|
fingerprint: str,
|
|
14109
|
+
attempt_token: str = "",
|
|
14110
|
+
*,
|
|
14111
|
+
create: bool = True,
|
|
14018
14112
|
) -> tuple[Path, Path]:
|
|
14019
|
-
|
|
14020
|
-
|
|
14021
|
-
root
|
|
14022
|
-
return root / f"{fingerprint}.result.json", root / f"{fingerprint}.run.json"
|
|
14113
|
+
stem = _review_attempt_stem(fingerprint, attempt_token)
|
|
14114
|
+
root = _task_review_dir(control_repo, task_id, create=create)
|
|
14115
|
+
return root / f"{stem}.result.json", root / f"{stem}.run.json"
|
|
14023
14116
|
|
|
14024
14117
|
|
|
14025
14118
|
def _review_runtime_event_log_path(
|
|
14026
14119
|
control_repo: Path,
|
|
14027
14120
|
task_id: str,
|
|
14028
14121
|
fingerprint: str,
|
|
14122
|
+
attempt_token: str = "",
|
|
14123
|
+
*,
|
|
14124
|
+
create: bool = True,
|
|
14029
14125
|
) -> Path:
|
|
14030
|
-
|
|
14031
|
-
|
|
14032
|
-
root
|
|
14033
|
-
|
|
14126
|
+
stem = _review_attempt_stem(fingerprint, attempt_token)
|
|
14127
|
+
root = _task_review_dir(control_repo, task_id, create=create)
|
|
14128
|
+
return root / f"{stem}.events.jsonl"
|
|
14129
|
+
|
|
14130
|
+
|
|
14131
|
+
def _review_runtime_retry_audit_path(
|
|
14132
|
+
control_repo: Path,
|
|
14133
|
+
task_id: str,
|
|
14134
|
+
fingerprint: str,
|
|
14135
|
+
attempt_token: str,
|
|
14136
|
+
*,
|
|
14137
|
+
create: bool = True,
|
|
14138
|
+
) -> Path:
|
|
14139
|
+
stem = _review_attempt_stem(fingerprint, attempt_token)
|
|
14140
|
+
root = _task_review_dir(control_repo, task_id, create=create)
|
|
14141
|
+
return root / f"{stem}.audit.json"
|
|
14034
14142
|
|
|
14035
14143
|
|
|
14036
14144
|
def _review_runtime_override_path(
|
|
@@ -14061,6 +14169,366 @@ def _private_review_file_sha256(path: Path, label: str) -> str:
|
|
|
14061
14169
|
return hashlib.sha256(payload).hexdigest()
|
|
14062
14170
|
|
|
14063
14171
|
|
|
14172
|
+
def _review_runtime_version_tuple(value: object, label: str) -> tuple[int, int, int]:
|
|
14173
|
+
raw = _text(value)
|
|
14174
|
+
match = re.fullmatch(r"(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)", raw)
|
|
14175
|
+
if not match:
|
|
14176
|
+
raise APError(f"{label} must be a stable semantic version.")
|
|
14177
|
+
return tuple(int(match.group(index)) for index in range(1, 4))
|
|
14178
|
+
|
|
14179
|
+
|
|
14180
|
+
def _managed_review_runtime_identity() -> dict:
|
|
14181
|
+
script_path = Path(__file__).resolve()
|
|
14182
|
+
script_sha256 = hashlib.sha256(script_path.read_bytes()).hexdigest()
|
|
14183
|
+
agents_dir = next((parent for parent in script_path.parents if parent.name == ".agents"), None)
|
|
14184
|
+
if agents_dir is None:
|
|
14185
|
+
raise APError(
|
|
14186
|
+
"Reviewer runtime retry requires an installed managed Skill runtime; "
|
|
14187
|
+
"source-tree execution is not accepted."
|
|
14188
|
+
)
|
|
14189
|
+
install_root = agents_dir.parent.resolve()
|
|
14190
|
+
expected_relative = Path(".agents/skills/auto-coding-skill/scripts/ap.py")
|
|
14191
|
+
try:
|
|
14192
|
+
actual_relative = script_path.relative_to(install_root)
|
|
14193
|
+
except ValueError as exc:
|
|
14194
|
+
raise APError("Managed Reviewer runtime escapes its install root.") from exc
|
|
14195
|
+
if actual_relative != expected_relative:
|
|
14196
|
+
raise APError(
|
|
14197
|
+
"Reviewer runtime retry must execute the canonical managed ap.py entry."
|
|
14198
|
+
)
|
|
14199
|
+
manifest_path = agents_dir / "managed-install.json"
|
|
14200
|
+
try:
|
|
14201
|
+
manifest_bytes = manifest_path.read_bytes()
|
|
14202
|
+
except OSError as exc:
|
|
14203
|
+
raise APError(f"Cannot read managed Reviewer runtime manifest: {manifest_path}: {exc}") from exc
|
|
14204
|
+
if len(manifest_bytes) > 4 * 1024 * 1024:
|
|
14205
|
+
raise APError("Managed Reviewer runtime manifest exceeds 4 MiB.")
|
|
14206
|
+
try:
|
|
14207
|
+
manifest = json.loads(manifest_bytes.decode("utf-8"))
|
|
14208
|
+
except (UnicodeDecodeError, json.JSONDecodeError) as exc:
|
|
14209
|
+
raise APError("Managed Reviewer runtime manifest is invalid JSON.") from exc
|
|
14210
|
+
if not isinstance(manifest, dict) or int(manifest.get("schema_version") or 0) != 1:
|
|
14211
|
+
raise APError("Managed Reviewer runtime manifest schema is invalid.")
|
|
14212
|
+
version = _text(manifest.get("skill_version"))
|
|
14213
|
+
_review_runtime_version_tuple(version, "Managed Reviewer runtime version")
|
|
14214
|
+
entries = manifest.get("entries")
|
|
14215
|
+
if not isinstance(entries, list):
|
|
14216
|
+
raise APError("Managed Reviewer runtime manifest entries are invalid.")
|
|
14217
|
+
matches = [
|
|
14218
|
+
entry
|
|
14219
|
+
for entry in entries
|
|
14220
|
+
if isinstance(entry, dict) and entry.get("path") == expected_relative.as_posix()
|
|
14221
|
+
]
|
|
14222
|
+
if len(matches) != 1:
|
|
14223
|
+
raise APError("Managed Reviewer runtime manifest must bind one canonical ap.py entry.")
|
|
14224
|
+
entry = matches[0]
|
|
14225
|
+
if (
|
|
14226
|
+
entry.get("source") != "skill/scripts/ap.py"
|
|
14227
|
+
or entry.get("ownership") != "exact"
|
|
14228
|
+
or entry.get("scope") != "shared"
|
|
14229
|
+
or entry.get("version") != version
|
|
14230
|
+
or _text(entry.get("sha256")) != script_sha256
|
|
14231
|
+
):
|
|
14232
|
+
raise APError("Managed Reviewer runtime ap.py identity check failed.")
|
|
14233
|
+
integrity = verify_managed_install(
|
|
14234
|
+
install_root,
|
|
14235
|
+
mode="global",
|
|
14236
|
+
expected_version=version,
|
|
14237
|
+
manifest_path=manifest_path,
|
|
14238
|
+
)
|
|
14239
|
+
if not integrity.get("ok"):
|
|
14240
|
+
raise APError(
|
|
14241
|
+
"Managed Reviewer runtime install integrity failed: "
|
|
14242
|
+
+ "; ".join(str(item) for item in integrity.get("errors") or [])
|
|
14243
|
+
)
|
|
14244
|
+
return {
|
|
14245
|
+
"version": version,
|
|
14246
|
+
"script_path": str(script_path),
|
|
14247
|
+
"script_sha256": script_sha256,
|
|
14248
|
+
"manifest_path": str(manifest_path.resolve()),
|
|
14249
|
+
"manifest_sha256": hashlib.sha256(manifest_bytes).hexdigest(),
|
|
14250
|
+
}
|
|
14251
|
+
|
|
14252
|
+
|
|
14253
|
+
def _load_review_runtime_retry_audit(
|
|
14254
|
+
control_repo: Path,
|
|
14255
|
+
manifest: dict,
|
|
14256
|
+
assignment: dict,
|
|
14257
|
+
*,
|
|
14258
|
+
require_environment: bool = False,
|
|
14259
|
+
require_same_runtime: bool = False,
|
|
14260
|
+
verify_worktree_snapshot: bool = True,
|
|
14261
|
+
) -> Optional[dict]:
|
|
14262
|
+
review = manifest.get("review") or {}
|
|
14263
|
+
token = _review_attempt_token(review)
|
|
14264
|
+
if not token:
|
|
14265
|
+
return None
|
|
14266
|
+
task_id = _text(manifest.get("task_id"))
|
|
14267
|
+
fingerprint = _text(review.get("diff_fingerprint"))
|
|
14268
|
+
audit_path = _review_runtime_retry_audit_path(
|
|
14269
|
+
control_repo,
|
|
14270
|
+
task_id,
|
|
14271
|
+
fingerprint,
|
|
14272
|
+
token,
|
|
14273
|
+
create=False,
|
|
14274
|
+
).resolve()
|
|
14275
|
+
if Path(_text(review.get("runtime_retry_audit_path"))).resolve() != audit_path:
|
|
14276
|
+
raise APError("Reviewer runtime retry audit path is not canonical.")
|
|
14277
|
+
audit_sha256 = _text(review.get("runtime_retry_audit_sha256"))
|
|
14278
|
+
payload = _read_verified_private_review_file(audit_path, audit_sha256, "runtime retry audit")
|
|
14279
|
+
try:
|
|
14280
|
+
audit = json.loads(payload.decode("utf-8"))
|
|
14281
|
+
except (UnicodeDecodeError, json.JSONDecodeError) as exc:
|
|
14282
|
+
raise APError("Reviewer runtime retry audit is invalid JSON.") from exc
|
|
14283
|
+
if not isinstance(audit, dict) or int(audit.get("schema") or 0) != 1:
|
|
14284
|
+
raise APError("Reviewer runtime retry audit schema is invalid.")
|
|
14285
|
+
runtime_version = _text(audit.get("managed_runtime_version"))
|
|
14286
|
+
if token != f"retry-v{runtime_version}":
|
|
14287
|
+
raise APError("Reviewer runtime retry token does not bind its managed version.")
|
|
14288
|
+
if _text(review.get("runtime_retry_version")) != runtime_version:
|
|
14289
|
+
raise APError("Reviewer runtime retry version does not match its audit.")
|
|
14290
|
+
if (
|
|
14291
|
+
_text(review.get("runtime_retry_reason_code")) != _REVIEW_RUNTIME_RETRY_REASON
|
|
14292
|
+
or _text(audit.get("reason_code")) != _REVIEW_RUNTIME_RETRY_REASON
|
|
14293
|
+
):
|
|
14294
|
+
raise APError("Reviewer runtime retry reason code is invalid.")
|
|
14295
|
+
expected = {
|
|
14296
|
+
"task_id": task_id,
|
|
14297
|
+
"task_uuid": _text(manifest.get("task_uuid")),
|
|
14298
|
+
"owner": _text(manifest.get("owner")),
|
|
14299
|
+
"reviewer": _text(review.get("reviewer")),
|
|
14300
|
+
"task_skill_version": _text(manifest.get("skill_version")),
|
|
14301
|
+
"base_sha": _text(manifest.get("base_sha")),
|
|
14302
|
+
"diff_head": _text(assignment.get("diff_head")),
|
|
14303
|
+
"diff_fingerprint": fingerprint,
|
|
14304
|
+
"scope_revision": int(manifest.get("scope_revision") or 1),
|
|
14305
|
+
"owned_paths": list(manifest.get("owned_paths") or []),
|
|
14306
|
+
"retry_token": token,
|
|
14307
|
+
"assignment_path": str(_review_assignment_path(control_repo, task_id, fingerprint).resolve()),
|
|
14308
|
+
"assignment_sha256": _text(review.get("assignment_sha256")),
|
|
14309
|
+
"diff_artifact_path": str(_review_diff_artifact_path(control_repo, task_id, fingerprint).resolve()),
|
|
14310
|
+
"diff_artifact_sha256": _text(review.get("diff_artifact_sha256")),
|
|
14311
|
+
"original_deadline_at": _text(assignment.get("deadline_at")),
|
|
14312
|
+
}
|
|
14313
|
+
mismatched = [field for field, value in expected.items() if audit.get(field) != value]
|
|
14314
|
+
if mismatched:
|
|
14315
|
+
raise APError(
|
|
14316
|
+
"Reviewer runtime retry audit does not match task state: " + ", ".join(mismatched)
|
|
14317
|
+
)
|
|
14318
|
+
if verify_worktree_snapshot:
|
|
14319
|
+
worktree = Path(_text(manifest.get("worktree_path"))).resolve()
|
|
14320
|
+
if not worktree.exists() or _resolve_commit(worktree, "HEAD") != _text(
|
|
14321
|
+
assignment.get("diff_head")
|
|
14322
|
+
):
|
|
14323
|
+
raise APError("Reviewer runtime retry task HEAD changed after authorization.")
|
|
14324
|
+
if _task_review_fingerprint(worktree, manifest, _load_cfg(worktree)) != fingerprint:
|
|
14325
|
+
raise APError("Reviewer runtime retry diff changed after authorization.")
|
|
14326
|
+
retry_result_path, retry_receipt_path = _review_runtime_paths(
|
|
14327
|
+
control_repo,
|
|
14328
|
+
task_id,
|
|
14329
|
+
fingerprint,
|
|
14330
|
+
token,
|
|
14331
|
+
create=False,
|
|
14332
|
+
)
|
|
14333
|
+
retry_event_path = _review_runtime_event_log_path(
|
|
14334
|
+
control_repo,
|
|
14335
|
+
task_id,
|
|
14336
|
+
fingerprint,
|
|
14337
|
+
token,
|
|
14338
|
+
create=False,
|
|
14339
|
+
)
|
|
14340
|
+
retry_expected = {
|
|
14341
|
+
"retry_result_path": str(retry_result_path.resolve()),
|
|
14342
|
+
"retry_receipt_path": str(retry_receipt_path.resolve()),
|
|
14343
|
+
"retry_event_log_path": str(retry_event_path.resolve()),
|
|
14344
|
+
}
|
|
14345
|
+
retry_mismatched = [field for field, value in retry_expected.items() if audit.get(field) != value]
|
|
14346
|
+
if retry_mismatched:
|
|
14347
|
+
raise APError(
|
|
14348
|
+
"Reviewer runtime retry audit paths are invalid: " + ", ".join(retry_mismatched)
|
|
14349
|
+
)
|
|
14350
|
+
for field, label in (
|
|
14351
|
+
("prior_result", "prior result"),
|
|
14352
|
+
("prior_receipt", "prior runtime receipt"),
|
|
14353
|
+
("prior_event_log", "prior event log"),
|
|
14354
|
+
):
|
|
14355
|
+
path = Path(_text(audit.get(f"{field}_path"))).resolve()
|
|
14356
|
+
expected_path = {
|
|
14357
|
+
"prior_result": _review_runtime_paths(
|
|
14358
|
+
control_repo, task_id, fingerprint, create=False
|
|
14359
|
+
)[0].resolve(),
|
|
14360
|
+
"prior_receipt": _review_runtime_paths(
|
|
14361
|
+
control_repo, task_id, fingerprint, create=False
|
|
14362
|
+
)[1].resolve(),
|
|
14363
|
+
"prior_event_log": _review_runtime_event_log_path(
|
|
14364
|
+
control_repo, task_id, fingerprint, create=False
|
|
14365
|
+
).resolve(),
|
|
14366
|
+
}[field]
|
|
14367
|
+
if path != expected_path:
|
|
14368
|
+
raise APError(f"Reviewer runtime retry {label} path is not canonical.")
|
|
14369
|
+
_read_verified_private_review_file(path, _text(audit.get(f"{field}_sha256")), label)
|
|
14370
|
+
superseded_token = _text(audit.get("superseded_retry_token"))
|
|
14371
|
+
if superseded_token:
|
|
14372
|
+
if superseded_token != "retry-v4.3.4":
|
|
14373
|
+
raise APError("Reviewer runtime repair may supersede only retry-v4.3.4.")
|
|
14374
|
+
superseded_audit_path = _review_runtime_retry_audit_path(
|
|
14375
|
+
control_repo,
|
|
14376
|
+
task_id,
|
|
14377
|
+
fingerprint,
|
|
14378
|
+
superseded_token,
|
|
14379
|
+
create=False,
|
|
14380
|
+
).resolve()
|
|
14381
|
+
if Path(_text(audit.get("superseded_retry_audit_path"))).resolve() != superseded_audit_path:
|
|
14382
|
+
raise APError("Superseded Reviewer retry audit path is not canonical.")
|
|
14383
|
+
superseded_payload = _read_verified_private_review_file(
|
|
14384
|
+
superseded_audit_path,
|
|
14385
|
+
_text(audit.get("superseded_retry_audit_sha256")),
|
|
14386
|
+
"superseded runtime retry audit",
|
|
14387
|
+
)
|
|
14388
|
+
try:
|
|
14389
|
+
superseded_audit = json.loads(superseded_payload.decode("utf-8"))
|
|
14390
|
+
except (UnicodeDecodeError, json.JSONDecodeError) as exc:
|
|
14391
|
+
raise APError("Superseded Reviewer runtime retry audit is invalid JSON.") from exc
|
|
14392
|
+
superseded_result_path, superseded_receipt_path = _review_runtime_paths(
|
|
14393
|
+
control_repo,
|
|
14394
|
+
task_id,
|
|
14395
|
+
fingerprint,
|
|
14396
|
+
superseded_token,
|
|
14397
|
+
create=False,
|
|
14398
|
+
)
|
|
14399
|
+
superseded_event_path = _review_runtime_event_log_path(
|
|
14400
|
+
control_repo,
|
|
14401
|
+
task_id,
|
|
14402
|
+
fingerprint,
|
|
14403
|
+
superseded_token,
|
|
14404
|
+
create=False,
|
|
14405
|
+
)
|
|
14406
|
+
superseded_expected = {
|
|
14407
|
+
"schema": 1,
|
|
14408
|
+
"reason_code": _REVIEW_RUNTIME_RETRY_REASON,
|
|
14409
|
+
"task_id": task_id,
|
|
14410
|
+
"task_uuid": _text(manifest.get("task_uuid")),
|
|
14411
|
+
"owner": _text(manifest.get("owner")),
|
|
14412
|
+
"reviewer": _text(review.get("reviewer")),
|
|
14413
|
+
"task_skill_version": _text(manifest.get("skill_version")),
|
|
14414
|
+
"base_sha": _text(manifest.get("base_sha")),
|
|
14415
|
+
"diff_head": _text(assignment.get("diff_head")),
|
|
14416
|
+
"diff_fingerprint": fingerprint,
|
|
14417
|
+
"scope_revision": int(manifest.get("scope_revision") or 1),
|
|
14418
|
+
"owned_paths": list(manifest.get("owned_paths") or []),
|
|
14419
|
+
"retry_token": superseded_token,
|
|
14420
|
+
"assignment_path": str(
|
|
14421
|
+
_review_assignment_path(control_repo, task_id, fingerprint).resolve()
|
|
14422
|
+
),
|
|
14423
|
+
"assignment_sha256": _text(review.get("assignment_sha256")),
|
|
14424
|
+
"diff_artifact_path": str(
|
|
14425
|
+
_review_diff_artifact_path(control_repo, task_id, fingerprint).resolve()
|
|
14426
|
+
),
|
|
14427
|
+
"diff_artifact_sha256": _text(review.get("diff_artifact_sha256")),
|
|
14428
|
+
"original_deadline_at": _text(assignment.get("deadline_at")),
|
|
14429
|
+
"managed_runtime_version": "4.3.4",
|
|
14430
|
+
"retry_result_path": str(superseded_result_path.resolve()),
|
|
14431
|
+
"retry_receipt_path": str(superseded_receipt_path.resolve()),
|
|
14432
|
+
"retry_event_log_path": str(superseded_event_path.resolve()),
|
|
14433
|
+
}
|
|
14434
|
+
superseded_mismatched = [
|
|
14435
|
+
field
|
|
14436
|
+
for field, value in superseded_expected.items()
|
|
14437
|
+
if not isinstance(superseded_audit, dict) or superseded_audit.get(field) != value
|
|
14438
|
+
]
|
|
14439
|
+
if superseded_mismatched:
|
|
14440
|
+
raise APError(
|
|
14441
|
+
"Superseded Reviewer runtime retry audit does not match task state: "
|
|
14442
|
+
+ ", ".join(superseded_mismatched)
|
|
14443
|
+
)
|
|
14444
|
+
superseded_state = _text(audit.get("superseded_retry_state"))
|
|
14445
|
+
if superseded_state == "pending":
|
|
14446
|
+
if any(
|
|
14447
|
+
path.exists() or path.is_symlink()
|
|
14448
|
+
for path in (
|
|
14449
|
+
superseded_result_path,
|
|
14450
|
+
superseded_receipt_path,
|
|
14451
|
+
superseded_event_path,
|
|
14452
|
+
)
|
|
14453
|
+
):
|
|
14454
|
+
raise APError("Superseded pending Reviewer retry unexpectedly has runtime evidence.")
|
|
14455
|
+
elif superseded_state == "blocked":
|
|
14456
|
+
for field, path, label in (
|
|
14457
|
+
("superseded_retry_result", superseded_result_path, "superseded retry result"),
|
|
14458
|
+
("superseded_retry_receipt", superseded_receipt_path, "superseded retry receipt"),
|
|
14459
|
+
("superseded_retry_event_log", superseded_event_path, "superseded retry event log"),
|
|
14460
|
+
):
|
|
14461
|
+
if Path(_text(audit.get(f"{field}_path"))).resolve() != path.resolve():
|
|
14462
|
+
raise APError(f"Reviewer runtime repair {label} path is not canonical.")
|
|
14463
|
+
_read_verified_private_review_file(
|
|
14464
|
+
path,
|
|
14465
|
+
_text(audit.get(f"{field}_sha256")),
|
|
14466
|
+
label,
|
|
14467
|
+
)
|
|
14468
|
+
else:
|
|
14469
|
+
raise APError("Reviewer runtime repair has an invalid superseded retry state.")
|
|
14470
|
+
issued = _parse_iso_timestamp(audit.get("retry_issued_at"), "retry_issued_at")
|
|
14471
|
+
deadline = _parse_iso_timestamp(audit.get("retry_deadline_at"), "retry_deadline_at")
|
|
14472
|
+
timeout_seconds = int(audit.get("retry_timeout_seconds") or 0)
|
|
14473
|
+
if timeout_seconds != int(assignment.get("timeout_seconds") or 0):
|
|
14474
|
+
raise APError("Reviewer runtime retry timeout does not match the original fixed policy.")
|
|
14475
|
+
if int((deadline - issued).total_seconds()) != timeout_seconds:
|
|
14476
|
+
raise APError("Reviewer runtime retry deadline duration is invalid.")
|
|
14477
|
+
identity = _managed_review_runtime_identity()
|
|
14478
|
+
current_version = _review_runtime_version_tuple(identity["version"], "Current managed runtime version")
|
|
14479
|
+
audit_version = _review_runtime_version_tuple(runtime_version, "Retry managed runtime version")
|
|
14480
|
+
if current_version < audit_version:
|
|
14481
|
+
raise APError("Current managed runtime is older than the authorized Reviewer retry runtime.")
|
|
14482
|
+
if require_same_runtime and any(
|
|
14483
|
+
audit.get(field) != identity[value]
|
|
14484
|
+
for field, value in (
|
|
14485
|
+
("managed_runtime_version", "version"),
|
|
14486
|
+
("managed_runtime_script_path", "script_path"),
|
|
14487
|
+
("managed_runtime_script_sha256", "script_sha256"),
|
|
14488
|
+
("managed_runtime_manifest_path", "manifest_path"),
|
|
14489
|
+
("managed_runtime_manifest_sha256", "manifest_sha256"),
|
|
14490
|
+
)
|
|
14491
|
+
):
|
|
14492
|
+
raise APError("Reviewer retry must use the exact managed runtime that authorized it.")
|
|
14493
|
+
if require_environment:
|
|
14494
|
+
environment_expected = {
|
|
14495
|
+
"AUTOCODING_REVIEW_RETRY_TOKEN": token,
|
|
14496
|
+
"AUTOCODING_REVIEW_RETRY_AUDIT": str(audit_path),
|
|
14497
|
+
"AUTOCODING_REVIEW_RETRY_AUDIT_SHA256": audit_sha256,
|
|
14498
|
+
}
|
|
14499
|
+
missing = [
|
|
14500
|
+
key for key, value in environment_expected.items() if _text(os.environ.get(key)) != value
|
|
14501
|
+
]
|
|
14502
|
+
if missing:
|
|
14503
|
+
raise APError(
|
|
14504
|
+
"Reviewer retry artifact access lacks its supervised audit binding: "
|
|
14505
|
+
+ ", ".join(missing)
|
|
14506
|
+
)
|
|
14507
|
+
return audit
|
|
14508
|
+
|
|
14509
|
+
|
|
14510
|
+
def _effective_review_deadline(
|
|
14511
|
+
control_repo: Path,
|
|
14512
|
+
manifest: dict,
|
|
14513
|
+
assignment: dict,
|
|
14514
|
+
*,
|
|
14515
|
+
require_environment: bool = False,
|
|
14516
|
+
require_same_runtime: bool = False,
|
|
14517
|
+
verify_worktree_snapshot: bool = True,
|
|
14518
|
+
) -> _dt.datetime:
|
|
14519
|
+
audit = _load_review_runtime_retry_audit(
|
|
14520
|
+
control_repo,
|
|
14521
|
+
manifest,
|
|
14522
|
+
assignment,
|
|
14523
|
+
require_environment=require_environment,
|
|
14524
|
+
require_same_runtime=require_same_runtime,
|
|
14525
|
+
verify_worktree_snapshot=verify_worktree_snapshot,
|
|
14526
|
+
)
|
|
14527
|
+
if audit is None:
|
|
14528
|
+
return _parse_iso_timestamp(assignment.get("deadline_at"), "deadline_at")
|
|
14529
|
+
return _parse_iso_timestamp(audit.get("retry_deadline_at"), "retry_deadline_at")
|
|
14530
|
+
|
|
14531
|
+
|
|
14064
14532
|
def _reviewer_cli_version(command: list[str], runner_kind: str) -> str:
|
|
14065
14533
|
if runner_kind != "codex" or not command:
|
|
14066
14534
|
return "test-override"
|
|
@@ -14257,6 +14725,15 @@ def _update_review_runtime(
|
|
|
14257
14725
|
review = dict(manifest.get("review") or {})
|
|
14258
14726
|
if _text(review.get("diff_fingerprint")) != fingerprint:
|
|
14259
14727
|
raise APError("Reviewer runtime assignment became stale while the process was running.")
|
|
14728
|
+
_, expected_receipt_path = _review_runtime_paths(
|
|
14729
|
+
control_repo,
|
|
14730
|
+
task_id,
|
|
14731
|
+
fingerprint,
|
|
14732
|
+
_review_attempt_token(review),
|
|
14733
|
+
create=False,
|
|
14734
|
+
)
|
|
14735
|
+
if receipt_path.resolve() != expected_receipt_path.resolve():
|
|
14736
|
+
raise APError("Reviewer runtime attempt token changed while the process was running.")
|
|
14260
14737
|
review.update(updates)
|
|
14261
14738
|
manifest["review"] = review
|
|
14262
14739
|
receipt = _read_json_object(receipt_path) or {}
|
|
@@ -14289,6 +14766,8 @@ def _validate_bound_review_runtime_receipt(
|
|
|
14289
14766
|
control_repo,
|
|
14290
14767
|
task_id,
|
|
14291
14768
|
fingerprint,
|
|
14769
|
+
_review_attempt_token(review),
|
|
14770
|
+
create=False,
|
|
14292
14771
|
)
|
|
14293
14772
|
if receipt_path.resolve() != expected_receipt_path.resolve():
|
|
14294
14773
|
raise APError("Reviewer runtime receipt path is not canonical.")
|
|
@@ -14311,11 +14790,35 @@ def _validate_bound_review_runtime_receipt(
|
|
|
14311
14790
|
"result_path": str(expected_result_path),
|
|
14312
14791
|
"command_sha256": _text(review.get("runtime_command_sha256")),
|
|
14313
14792
|
"event_log_path": str(
|
|
14314
|
-
_review_runtime_event_log_path(
|
|
14793
|
+
_review_runtime_event_log_path(
|
|
14794
|
+
control_repo,
|
|
14795
|
+
task_id,
|
|
14796
|
+
fingerprint,
|
|
14797
|
+
_review_attempt_token(review),
|
|
14798
|
+
create=False,
|
|
14799
|
+
)
|
|
14315
14800
|
),
|
|
14316
14801
|
"status": expected_status,
|
|
14317
14802
|
}
|
|
14318
14803
|
mismatched = [field for field, value in expected.items() if receipt.get(field) != value]
|
|
14804
|
+
retry_audit = _load_review_runtime_retry_audit(
|
|
14805
|
+
control_repo,
|
|
14806
|
+
manifest,
|
|
14807
|
+
assignment,
|
|
14808
|
+
)
|
|
14809
|
+
if retry_audit is not None:
|
|
14810
|
+
retry_expected = {
|
|
14811
|
+
"runtime_retry_token": _review_attempt_token(review),
|
|
14812
|
+
"runtime_retry_audit_path": _text(review.get("runtime_retry_audit_path")),
|
|
14813
|
+
"runtime_retry_audit_sha256": _text(review.get("runtime_retry_audit_sha256")),
|
|
14814
|
+
"managed_runtime_version": _text(retry_audit.get("managed_runtime_version")),
|
|
14815
|
+
"managed_runtime_script_sha256": _text(
|
|
14816
|
+
retry_audit.get("managed_runtime_script_sha256")
|
|
14817
|
+
),
|
|
14818
|
+
}
|
|
14819
|
+
mismatched.extend(
|
|
14820
|
+
field for field, value in retry_expected.items() if receipt.get(field) != value
|
|
14821
|
+
)
|
|
14319
14822
|
if mismatched:
|
|
14320
14823
|
raise APError(
|
|
14321
14824
|
"Reviewer runtime receipt does not match task state: " + ", ".join(mismatched)
|
|
@@ -14349,25 +14852,466 @@ def _blocked_reviewer_runtime_result(
|
|
|
14349
14852
|
return _validate_orchestration_contract("result", result)
|
|
14350
14853
|
|
|
14351
14854
|
|
|
14352
|
-
def
|
|
14855
|
+
def _known_review_artifact_access_failure(
|
|
14856
|
+
control_repo: Path,
|
|
14857
|
+
result: dict,
|
|
14858
|
+
) -> bool:
|
|
14859
|
+
if (
|
|
14860
|
+
_text(result.get("verdict")) != "blocked"
|
|
14861
|
+
or _text(result.get("status")) != "blocked"
|
|
14862
|
+
or list(result.get("findings") or [])
|
|
14863
|
+
or list(result.get("changed_paths") or [])
|
|
14864
|
+
):
|
|
14865
|
+
return False
|
|
14866
|
+
evidence = result.get("evidence")
|
|
14867
|
+
if not isinstance(evidence, list) or len(evidence) != 1 or not isinstance(evidence[0], str):
|
|
14868
|
+
return False
|
|
14869
|
+
state_root = re.escape(str(_task_state_root(control_repo).resolve()))
|
|
14870
|
+
pattern = re.compile(
|
|
14871
|
+
r"^review-artifact exited(?: with code)? 2: Cannot protect Git-local review storage"
|
|
14872
|
+
rf"(?: at |: ){state_root}: (?:\[Errno 1\] )?Operation not permitted\.?$"
|
|
14873
|
+
)
|
|
14874
|
+
if not pattern.fullmatch(evidence[0]):
|
|
14875
|
+
return False
|
|
14876
|
+
summaries = {
|
|
14877
|
+
"Review could not start because review-artifact failed while protecting Git-local review storage.",
|
|
14878
|
+
"Review could not begin because review-artifact failed before verifying or emitting the immutable patch.",
|
|
14879
|
+
"Review could not begin because review-artifact failed before emitting the verified immutable patch.",
|
|
14880
|
+
"Review could not begin because review-artifact failed before emitting the verified immutable patch: the read-only sandbox denied protection of Git-local review storage.",
|
|
14881
|
+
"Review could not begin because the mandatory frozen artifact verification failed under the read-only filesystem.",
|
|
14882
|
+
"Review could not begin because review-artifact failed before emitting the immutable patch.",
|
|
14883
|
+
}
|
|
14884
|
+
if _text(result.get("summary")) not in summaries:
|
|
14885
|
+
return False
|
|
14886
|
+
risks = result.get("risks")
|
|
14887
|
+
allowed_risks = {
|
|
14888
|
+
"The immutable patch was not emitted or substantively reviewed because mandatory artifact verification did not complete.",
|
|
14889
|
+
"The artifact mode and SHA-256 were not verified, so the frozen diff was not analyzed. Re-run the same assignment in an environment permitting review-artifact to protect and read Git-local review storage.",
|
|
14890
|
+
"The frozen diff artifact was not emitted or substantively reviewed; no correctness or security conclusion can be made.",
|
|
14891
|
+
"The frozen diff was not emitted or substantively reviewed; no correctness or security conclusion is available.",
|
|
14892
|
+
"The immutable patch was neither verified nor analyzed; no substantive correctness or security conclusion is available.",
|
|
14893
|
+
"The immutable patch was not emitted or substantively reviewed.",
|
|
14894
|
+
}
|
|
14895
|
+
if not isinstance(risks, list) or len(risks) != 1 or risks[0] not in allowed_risks:
|
|
14896
|
+
return False
|
|
14897
|
+
return True
|
|
14898
|
+
|
|
14899
|
+
|
|
14900
|
+
def cmd_review_runtime_retry(args: argparse.Namespace) -> None:
|
|
14353
14901
|
repo = Path(args.repo).resolve()
|
|
14354
14902
|
ensure_git_repo(repo)
|
|
14355
14903
|
cfg = _load_cfg(repo)
|
|
14356
14904
|
task_id = _validate_task_id(args.task_id)
|
|
14357
|
-
|
|
14358
|
-
|
|
14359
|
-
|
|
14360
|
-
|
|
14361
|
-
|
|
14362
|
-
|
|
14363
|
-
|
|
14364
|
-
|
|
14905
|
+
if _text(args.reason_code) != _REVIEW_RUNTIME_RETRY_REASON:
|
|
14906
|
+
raise APError(
|
|
14907
|
+
f"--reason-code must be {_REVIEW_RUNTIME_RETRY_REASON} for this bounded migration."
|
|
14908
|
+
)
|
|
14909
|
+
if not bool(args.confirm_managed_runtime_retry):
|
|
14910
|
+
raise APError("Reviewer runtime retry requires --confirm-managed-runtime-retry.")
|
|
14911
|
+
identity = _managed_review_runtime_identity()
|
|
14912
|
+
runtime_version = _text(identity.get("version"))
|
|
14913
|
+
runtime_version_tuple = _review_runtime_version_tuple(
|
|
14914
|
+
runtime_version,
|
|
14915
|
+
"Managed Reviewer runtime version",
|
|
14916
|
+
)
|
|
14917
|
+
if runtime_version_tuple < _REVIEW_RUNTIME_RETRY_FIXED_IN:
|
|
14918
|
+
raise APError("Managed Reviewer runtime is too old to authorize the bounded retry.")
|
|
14919
|
+
|
|
14920
|
+
control_repo, worktree, _ = _task_lifecycle_context(repo, cfg, task_id)
|
|
14921
|
+
timeout_s = float(_concurrency_cfg(cfg).get("lock_timeout_sec") or 30)
|
|
14922
|
+
with _repo_lock(control_repo, f"task-{task_id}", timeout_s=timeout_s):
|
|
14923
|
+
manifest = _load_task_manifest(control_repo, task_id)
|
|
14924
|
+
lifecycle_actor = _text(os.environ.get("CODEX_THREAD_ID"))
|
|
14925
|
+
if not lifecycle_actor or lifecycle_actor != _text(manifest.get("owner")):
|
|
14926
|
+
raise APError("Only the task lifecycle owner may authorize a Reviewer runtime retry.")
|
|
14927
|
+
if _text(manifest.get("state")) != "active":
|
|
14928
|
+
raise APError("Reviewer runtime retry is limited to active tasks.")
|
|
14929
|
+
if not bool(manifest.get("review_required")):
|
|
14930
|
+
raise APError("Reviewer runtime retry requires an independent-review task.")
|
|
14931
|
+
task_version = _text(manifest.get("skill_version"))
|
|
14932
|
+
task_version_tuple = _review_runtime_version_tuple(task_version, "Task Skill version")
|
|
14933
|
+
if not (
|
|
14934
|
+
_REVIEW_RUNTIME_RETRY_AFFECTED_MIN
|
|
14935
|
+
<= task_version_tuple
|
|
14936
|
+
<= _REVIEW_RUNTIME_RETRY_AFFECTED_MAX
|
|
14937
|
+
):
|
|
14938
|
+
raise APError("Task Skill version is outside the bounded Reviewer retry migration range.")
|
|
14939
|
+
if runtime_version_tuple <= task_version_tuple:
|
|
14940
|
+
raise APError("Managed Reviewer retry runtime must be newer than the task runtime.")
|
|
14941
|
+
review = dict(manifest.get("review") or {})
|
|
14942
|
+
existing_token = _review_attempt_token(review)
|
|
14943
|
+
repairing_retry = existing_token == "retry-v4.3.4"
|
|
14944
|
+
if existing_token and (
|
|
14945
|
+
not repairing_retry or runtime_version_tuple < _REVIEW_RUNTIME_RETRY_REPAIRED_IN
|
|
14946
|
+
):
|
|
14947
|
+
raise APError("A Reviewer runtime retry is already authorized for this diff fingerprint.")
|
|
14948
|
+
if not existing_token and any(
|
|
14949
|
+
_text(review.get(field)) for field in _REVIEW_RETRY_FIELDS
|
|
14950
|
+
):
|
|
14951
|
+
raise APError("Reviewer runtime retry state is incomplete.")
|
|
14952
|
+
if _text(review.get("runtime_override_path")) or _text(review.get("runtime_override_sha256")):
|
|
14953
|
+
raise APError("Reviewer runtime retry cannot follow a user-authorized runtime override.")
|
|
14954
|
+
fingerprint = _task_review_fingerprint(worktree, manifest, _load_cfg(worktree))
|
|
14955
|
+
supplied = _text(args.diff_fingerprint)
|
|
14956
|
+
if supplied != fingerprint or _text(review.get("diff_fingerprint")) != fingerprint:
|
|
14957
|
+
raise APError(
|
|
14958
|
+
f"Reviewer runtime retry fingerprint mismatch: supplied={supplied or '(missing)'}, "
|
|
14959
|
+
f"current={fingerprint}."
|
|
14960
|
+
)
|
|
14961
|
+
assignment_path = Path(_text(review.get("assignment_path"))).resolve()
|
|
14962
|
+
assignment = _load_bound_review_assignment(control_repo, manifest, assignment_path)
|
|
14963
|
+
_validate_review_diff_artifact(control_repo, assignment)
|
|
14964
|
+
expected_assignment_fields = {
|
|
14965
|
+
"task_id": task_id,
|
|
14966
|
+
"base_sha": _text(manifest.get("base_sha")),
|
|
14967
|
+
"diff_base": _text(manifest.get("base_sha")),
|
|
14968
|
+
"diff_head": _resolve_commit(worktree, "HEAD"),
|
|
14969
|
+
"diff_fingerprint": fingerprint,
|
|
14970
|
+
"owned_paths": list(manifest.get("owned_paths") or []),
|
|
14971
|
+
"node_id": _text(review.get("reviewer")),
|
|
14972
|
+
"scope_revision": int(manifest.get("scope_revision") or 1),
|
|
14973
|
+
}
|
|
14974
|
+
assignment_mismatches = [
|
|
14975
|
+
field for field, value in expected_assignment_fields.items() if assignment.get(field) != value
|
|
14976
|
+
]
|
|
14977
|
+
if assignment_mismatches:
|
|
14978
|
+
raise APError(
|
|
14979
|
+
"Prior Reviewer assignment no longer matches task state: "
|
|
14980
|
+
+ ", ".join(assignment_mismatches)
|
|
14981
|
+
)
|
|
14982
|
+
superseded_audit: Optional[dict] = None
|
|
14983
|
+
superseded_state = ""
|
|
14984
|
+
if repairing_retry:
|
|
14985
|
+
superseded_audit = _load_review_runtime_retry_audit(
|
|
14986
|
+
control_repo,
|
|
14987
|
+
manifest,
|
|
14988
|
+
assignment,
|
|
14989
|
+
)
|
|
14990
|
+
if (
|
|
14991
|
+
not superseded_audit
|
|
14992
|
+
or _text(superseded_audit.get("managed_runtime_version")) != "4.3.4"
|
|
14993
|
+
):
|
|
14994
|
+
raise APError("Only the exact 4.3.4 managed retry may be repaired.")
|
|
14995
|
+
retry_paths = (*_review_runtime_paths(
|
|
14996
|
+
control_repo,
|
|
14997
|
+
task_id,
|
|
14998
|
+
fingerprint,
|
|
14999
|
+
existing_token,
|
|
15000
|
+
create=False,
|
|
15001
|
+
), _review_runtime_event_log_path(
|
|
15002
|
+
control_repo,
|
|
15003
|
+
task_id,
|
|
15004
|
+
fingerprint,
|
|
15005
|
+
existing_token,
|
|
15006
|
+
create=False,
|
|
15007
|
+
))
|
|
15008
|
+
if (
|
|
15009
|
+
_text(review.get("verdict")) == "pending"
|
|
15010
|
+
and _text(review.get("reason")) == "bounded managed runtime retry authorized"
|
|
15011
|
+
and not any(field in review for field in _REVIEW_RUNTIME_FIELDS)
|
|
15012
|
+
and not any(path.exists() or path.is_symlink() for path in retry_paths)
|
|
15013
|
+
):
|
|
15014
|
+
superseded_state = "pending"
|
|
15015
|
+
elif (
|
|
15016
|
+
_text(review.get("verdict")) == "blocked"
|
|
15017
|
+
and _text(review.get("runtime_state")) == "blocked"
|
|
15018
|
+
and review.get("runtime_exit_code") == 0
|
|
15019
|
+
and not _text(review.get("runtime_failure_kind"))
|
|
15020
|
+
and int(review.get("runtime_attempt_count") or 0) == 1
|
|
15021
|
+
):
|
|
15022
|
+
superseded_state = "blocked"
|
|
15023
|
+
else:
|
|
15024
|
+
raise APError(
|
|
15025
|
+
"The 4.3.4 Reviewer retry is not an untouched pending attempt or the exact procedural block."
|
|
15026
|
+
)
|
|
15027
|
+
elif (
|
|
15028
|
+
_text(review.get("verdict")) != "blocked"
|
|
15029
|
+
or _text(review.get("runtime_state")) != "blocked"
|
|
15030
|
+
or review.get("runtime_exit_code") != 0
|
|
15031
|
+
or _text(review.get("runtime_failure_kind"))
|
|
15032
|
+
or int(review.get("runtime_attempt_count") or 0) != 1
|
|
15033
|
+
):
|
|
15034
|
+
raise APError(
|
|
15035
|
+
"Prior Reviewer state is not the exact completed procedural block eligible for retry."
|
|
15036
|
+
)
|
|
15037
|
+
|
|
15038
|
+
blocked_result_path: Optional[Path] = None
|
|
15039
|
+
blocked_receipt_path: Optional[Path] = None
|
|
15040
|
+
blocked_event_path: Optional[Path] = None
|
|
15041
|
+
if not repairing_retry or superseded_state == "blocked":
|
|
15042
|
+
blocked_result_path, blocked_receipt_path = _review_runtime_paths(
|
|
15043
|
+
control_repo,
|
|
15044
|
+
task_id,
|
|
15045
|
+
fingerprint,
|
|
15046
|
+
existing_token,
|
|
15047
|
+
create=False,
|
|
15048
|
+
)
|
|
15049
|
+
blocked_event_path = _review_runtime_event_log_path(
|
|
15050
|
+
control_repo,
|
|
15051
|
+
task_id,
|
|
15052
|
+
fingerprint,
|
|
15053
|
+
existing_token,
|
|
15054
|
+
create=False,
|
|
15055
|
+
)
|
|
15056
|
+
if Path(_text(review.get("runtime_result_path"))).resolve() != blocked_result_path.resolve():
|
|
15057
|
+
raise APError("Prior Reviewer result path is not canonical.")
|
|
15058
|
+
if Path(_text(review.get("runtime_receipt_path"))).resolve() != blocked_receipt_path.resolve():
|
|
15059
|
+
raise APError("Prior Reviewer receipt path is not canonical.")
|
|
15060
|
+
if Path(_text(review.get("runtime_event_log_path"))).resolve() != blocked_event_path.resolve():
|
|
15061
|
+
raise APError("Prior Reviewer event log path is not canonical.")
|
|
15062
|
+
receipt = _validate_bound_review_runtime_receipt(
|
|
15063
|
+
control_repo,
|
|
15064
|
+
manifest,
|
|
15065
|
+
assignment,
|
|
15066
|
+
blocked_receipt_path,
|
|
15067
|
+
"blocked",
|
|
15068
|
+
)
|
|
15069
|
+
attempts = receipt.get("attempts") or []
|
|
15070
|
+
if (
|
|
15071
|
+
int(receipt.get("schema") or 0) != 2
|
|
15072
|
+
or _text(receipt.get("verdict")) != "blocked"
|
|
15073
|
+
or receipt.get("exit_code") != 0
|
|
15074
|
+
or _text(receipt.get("failure_kind"))
|
|
15075
|
+
or len(attempts) != 1
|
|
15076
|
+
or _text(attempts[0].get("status")) != "completed"
|
|
15077
|
+
or attempts[0].get("exit_code") != 0
|
|
15078
|
+
):
|
|
15079
|
+
raise APError(
|
|
15080
|
+
"Prior Reviewer receipt is not the exact completed procedural block eligible for retry."
|
|
15081
|
+
)
|
|
15082
|
+
try:
|
|
15083
|
+
result_payload = json.loads(_read_bounded_reviewer_output(blocked_result_path))
|
|
15084
|
+
except (json.JSONDecodeError, UnicodeDecodeError) as exc:
|
|
15085
|
+
raise APError("Prior Reviewer result is invalid JSON.") from exc
|
|
15086
|
+
if not isinstance(result_payload, dict):
|
|
15087
|
+
raise APError("Prior Reviewer result must contain one JSON object.")
|
|
15088
|
+
normalized_result = _normalize_reviewer_runtime_result(assignment, result_payload)
|
|
15089
|
+
if result_payload != normalized_result or not _known_review_artifact_access_failure(
|
|
15090
|
+
control_repo,
|
|
15091
|
+
normalized_result,
|
|
15092
|
+
):
|
|
15093
|
+
raise APError(
|
|
15094
|
+
"Prior Reviewer result is not the exact non-substantive Git-local access failure."
|
|
15095
|
+
)
|
|
15096
|
+
|
|
15097
|
+
if superseded_audit:
|
|
15098
|
+
prior_result_path = Path(_text(superseded_audit.get("prior_result_path"))).resolve()
|
|
15099
|
+
prior_receipt_path = Path(_text(superseded_audit.get("prior_receipt_path"))).resolve()
|
|
15100
|
+
prior_event_path = Path(_text(superseded_audit.get("prior_event_log_path"))).resolve()
|
|
15101
|
+
prior_result_sha256 = _text(superseded_audit.get("prior_result_sha256"))
|
|
15102
|
+
prior_receipt_sha256 = _text(superseded_audit.get("prior_receipt_sha256"))
|
|
15103
|
+
prior_event_sha256 = _text(superseded_audit.get("prior_event_log_sha256"))
|
|
15104
|
+
else:
|
|
15105
|
+
assert blocked_result_path and blocked_receipt_path and blocked_event_path
|
|
15106
|
+
prior_result_path = blocked_result_path
|
|
15107
|
+
prior_receipt_path = blocked_receipt_path
|
|
15108
|
+
prior_event_path = blocked_event_path
|
|
15109
|
+
prior_result_sha256 = _private_review_file_sha256(prior_result_path, "prior result")
|
|
15110
|
+
prior_receipt_sha256 = _private_review_file_sha256(
|
|
15111
|
+
prior_receipt_path, "prior runtime receipt"
|
|
14365
15112
|
)
|
|
15113
|
+
prior_event_sha256 = _private_review_file_sha256(
|
|
15114
|
+
prior_event_path, "prior event log"
|
|
15115
|
+
)
|
|
15116
|
+
|
|
15117
|
+
token = f"retry-v{runtime_version}"
|
|
15118
|
+
audit_path = _review_runtime_retry_audit_path(
|
|
15119
|
+
control_repo,
|
|
15120
|
+
task_id,
|
|
15121
|
+
fingerprint,
|
|
15122
|
+
token,
|
|
15123
|
+
)
|
|
15124
|
+
retry_result_path, retry_receipt_path = _review_runtime_paths(
|
|
15125
|
+
control_repo,
|
|
15126
|
+
task_id,
|
|
15127
|
+
fingerprint,
|
|
15128
|
+
token,
|
|
15129
|
+
)
|
|
15130
|
+
retry_event_path = _review_runtime_event_log_path(
|
|
15131
|
+
control_repo,
|
|
15132
|
+
task_id,
|
|
15133
|
+
fingerprint,
|
|
15134
|
+
token,
|
|
15135
|
+
)
|
|
15136
|
+
for path in (audit_path, retry_result_path, retry_receipt_path, retry_event_path):
|
|
15137
|
+
if path.exists() or path.is_symlink():
|
|
15138
|
+
raise APError(f"Reviewer runtime retry evidence already exists: {path}")
|
|
15139
|
+
issued = _dt.datetime.now(_dt.timezone.utc).replace(microsecond=0)
|
|
15140
|
+
retry_timeout = int(assignment.get("timeout_seconds") or 0)
|
|
15141
|
+
if retry_timeout not in {_FOCUSED_REVIEW_TIMEOUT_SECONDS, _DEEP_REVIEW_TIMEOUT_SECONDS}:
|
|
15142
|
+
raise APError("Original Reviewer timeout is outside the fixed managed policy.")
|
|
15143
|
+
deadline = issued + _dt.timedelta(seconds=retry_timeout)
|
|
15144
|
+
audit = {
|
|
15145
|
+
"schema": 1,
|
|
15146
|
+
"reason_code": _REVIEW_RUNTIME_RETRY_REASON,
|
|
15147
|
+
"authorized_at": issued.isoformat(),
|
|
15148
|
+
"authorized_by": lifecycle_actor,
|
|
15149
|
+
"task_id": task_id,
|
|
15150
|
+
"task_uuid": _text(manifest.get("task_uuid")),
|
|
15151
|
+
"owner": lifecycle_actor,
|
|
15152
|
+
"reviewer": _text(review.get("reviewer")),
|
|
15153
|
+
"task_skill_version": task_version,
|
|
15154
|
+
"base_sha": _text(manifest.get("base_sha")),
|
|
15155
|
+
"diff_head": _text(assignment.get("diff_head")),
|
|
15156
|
+
"diff_fingerprint": fingerprint,
|
|
15157
|
+
"scope_revision": int(manifest.get("scope_revision") or 1),
|
|
15158
|
+
"owned_paths": list(manifest.get("owned_paths") or []),
|
|
15159
|
+
"retry_token": token,
|
|
15160
|
+
"retry_issued_at": issued.isoformat(),
|
|
15161
|
+
"retry_deadline_at": deadline.isoformat(),
|
|
15162
|
+
"retry_timeout_seconds": retry_timeout,
|
|
15163
|
+
"original_issued_at": _text(assignment.get("issued_at")),
|
|
15164
|
+
"original_deadline_at": _text(assignment.get("deadline_at")),
|
|
15165
|
+
"assignment_path": str(assignment_path),
|
|
15166
|
+
"assignment_sha256": _text(review.get("assignment_sha256")),
|
|
15167
|
+
"diff_artifact_path": _text(review.get("diff_artifact_path")),
|
|
15168
|
+
"diff_artifact_sha256": _text(review.get("diff_artifact_sha256")),
|
|
15169
|
+
"prior_result_path": str(prior_result_path),
|
|
15170
|
+
"prior_result_sha256": prior_result_sha256,
|
|
15171
|
+
"prior_receipt_path": str(prior_receipt_path),
|
|
15172
|
+
"prior_receipt_sha256": prior_receipt_sha256,
|
|
15173
|
+
"prior_event_log_path": str(prior_event_path),
|
|
15174
|
+
"prior_event_log_sha256": prior_event_sha256,
|
|
15175
|
+
"prior_review_state_sha256": hashlib.sha256(
|
|
15176
|
+
json.dumps(review, ensure_ascii=False, sort_keys=True, separators=(",", ":")).encode(
|
|
15177
|
+
"utf-8"
|
|
15178
|
+
)
|
|
15179
|
+
).hexdigest(),
|
|
15180
|
+
"prior_verdict": _text(review.get("verdict")),
|
|
15181
|
+
"prior_runtime_state": _text(review.get("runtime_state")) or "pending",
|
|
15182
|
+
"managed_runtime_version": runtime_version,
|
|
15183
|
+
"managed_runtime_script_path": identity["script_path"],
|
|
15184
|
+
"managed_runtime_script_sha256": identity["script_sha256"],
|
|
15185
|
+
"managed_runtime_manifest_path": identity["manifest_path"],
|
|
15186
|
+
"managed_runtime_manifest_sha256": identity["manifest_sha256"],
|
|
15187
|
+
"retry_result_path": str(retry_result_path),
|
|
15188
|
+
"retry_receipt_path": str(retry_receipt_path),
|
|
15189
|
+
"retry_event_log_path": str(retry_event_path),
|
|
15190
|
+
}
|
|
15191
|
+
if superseded_audit:
|
|
15192
|
+
audit.update(
|
|
15193
|
+
{
|
|
15194
|
+
"superseded_retry_token": existing_token,
|
|
15195
|
+
"superseded_retry_audit_path": _text(
|
|
15196
|
+
review.get("runtime_retry_audit_path")
|
|
15197
|
+
),
|
|
15198
|
+
"superseded_retry_audit_sha256": _text(
|
|
15199
|
+
review.get("runtime_retry_audit_sha256")
|
|
15200
|
+
),
|
|
15201
|
+
"superseded_retry_state": superseded_state,
|
|
15202
|
+
}
|
|
15203
|
+
)
|
|
15204
|
+
if superseded_state == "blocked":
|
|
15205
|
+
assert blocked_result_path and blocked_receipt_path and blocked_event_path
|
|
15206
|
+
audit.update(
|
|
15207
|
+
{
|
|
15208
|
+
"superseded_retry_result_path": str(blocked_result_path),
|
|
15209
|
+
"superseded_retry_result_sha256": _private_review_file_sha256(
|
|
15210
|
+
blocked_result_path, "superseded retry result"
|
|
15211
|
+
),
|
|
15212
|
+
"superseded_retry_receipt_path": str(blocked_receipt_path),
|
|
15213
|
+
"superseded_retry_receipt_sha256": _private_review_file_sha256(
|
|
15214
|
+
blocked_receipt_path, "superseded retry receipt"
|
|
15215
|
+
),
|
|
15216
|
+
"superseded_retry_event_log_path": str(blocked_event_path),
|
|
15217
|
+
"superseded_retry_event_log_sha256": _private_review_file_sha256(
|
|
15218
|
+
blocked_event_path, "superseded retry event log"
|
|
15219
|
+
),
|
|
15220
|
+
}
|
|
15221
|
+
)
|
|
15222
|
+
_create_private_json(audit_path, audit, "runtime retry audit")
|
|
15223
|
+
audit_sha256 = _private_review_file_sha256(audit_path, "runtime retry audit")
|
|
15224
|
+
next_review = {
|
|
15225
|
+
key: value
|
|
15226
|
+
for key, value in review.items()
|
|
15227
|
+
if key not in _REVIEW_RUNTIME_FIELDS and key not in _REVIEW_RETRY_FIELDS
|
|
15228
|
+
}
|
|
15229
|
+
next_review.update(
|
|
15230
|
+
{
|
|
15231
|
+
"verdict": "pending",
|
|
15232
|
+
"reviewed_at": "",
|
|
15233
|
+
"reason": "bounded managed runtime retry authorized",
|
|
15234
|
+
"runtime_retry_token": token,
|
|
15235
|
+
"runtime_retry_version": runtime_version,
|
|
15236
|
+
"runtime_retry_reason_code": _REVIEW_RUNTIME_RETRY_REASON,
|
|
15237
|
+
"runtime_retry_audit_path": str(audit_path),
|
|
15238
|
+
"runtime_retry_audit_sha256": audit_sha256,
|
|
15239
|
+
}
|
|
15240
|
+
)
|
|
15241
|
+
manifest["review"] = next_review
|
|
15242
|
+
try:
|
|
15243
|
+
_save_task_manifest(control_repo, manifest, strict_worktree=True)
|
|
15244
|
+
except Exception:
|
|
15245
|
+
audit_path.unlink(missing_ok=True)
|
|
15246
|
+
raise
|
|
15247
|
+
_load_review_runtime_retry_audit(
|
|
15248
|
+
control_repo,
|
|
15249
|
+
manifest,
|
|
15250
|
+
assignment,
|
|
15251
|
+
require_same_runtime=True,
|
|
15252
|
+
)
|
|
15253
|
+
result = {
|
|
15254
|
+
"task_id": task_id,
|
|
15255
|
+
"status": "retry-authorized",
|
|
15256
|
+
"diff_fingerprint": fingerprint,
|
|
15257
|
+
"reviewer": _text(next_review.get("reviewer")),
|
|
15258
|
+
"retry_token": token,
|
|
15259
|
+
"retry_deadline_at": deadline.isoformat(),
|
|
15260
|
+
"audit_path": str(audit_path),
|
|
15261
|
+
"audit_sha256": audit_sha256,
|
|
15262
|
+
}
|
|
15263
|
+
if bool(getattr(args, "json", False)):
|
|
15264
|
+
print(json.dumps(result, ensure_ascii=False, indent=2))
|
|
15265
|
+
else:
|
|
15266
|
+
print(
|
|
15267
|
+
f"[review-runtime-retry] task={task_id} status=retry-authorized "
|
|
15268
|
+
f"fingerprint={fingerprint} token={token}"
|
|
15269
|
+
)
|
|
15270
|
+
print(f"[review-runtime-retry] deadline_at={deadline.isoformat()}")
|
|
15271
|
+
print(
|
|
15272
|
+
"[review-runtime-retry] next=review-run "
|
|
15273
|
+
f"{task_id} --reviewer {_text(next_review.get('reviewer'))}"
|
|
14366
15274
|
)
|
|
14367
15275
|
|
|
15276
|
+
|
|
15277
|
+
def cmd_review_run(args: argparse.Namespace) -> None:
|
|
15278
|
+
repo = Path(args.repo).resolve()
|
|
15279
|
+
ensure_git_repo(repo)
|
|
15280
|
+
cfg = _load_cfg(repo)
|
|
15281
|
+
task_id = _validate_task_id(args.task_id)
|
|
15282
|
+
reviewer = _text(args.reviewer)
|
|
14368
15283
|
control_repo, worktree, _ = _task_lifecycle_context(repo, cfg, task_id)
|
|
15284
|
+
initial_manifest = _load_task_manifest(control_repo, task_id)
|
|
15285
|
+
initial_review = initial_manifest.get("review") or {}
|
|
15286
|
+
if _review_attempt_token(initial_review):
|
|
15287
|
+
if reviewer != _text(initial_review.get("reviewer")):
|
|
15288
|
+
raise APError("Reviewer runtime retry must preserve the original Reviewer identity.")
|
|
15289
|
+
initial_assignment_path = Path(_text(initial_review.get("assignment_path"))).resolve()
|
|
15290
|
+
initial_assignment = _load_bound_review_assignment(
|
|
15291
|
+
control_repo,
|
|
15292
|
+
initial_manifest,
|
|
15293
|
+
initial_assignment_path,
|
|
15294
|
+
)
|
|
15295
|
+
_load_review_runtime_retry_audit(
|
|
15296
|
+
control_repo,
|
|
15297
|
+
initial_manifest,
|
|
15298
|
+
initial_assignment,
|
|
15299
|
+
require_same_runtime=True,
|
|
15300
|
+
)
|
|
15301
|
+
else:
|
|
15302
|
+
with contextlib.redirect_stdout(io.StringIO()):
|
|
15303
|
+
cmd_review_assignment(
|
|
15304
|
+
argparse.Namespace(
|
|
15305
|
+
repo=str(repo),
|
|
15306
|
+
task_id=task_id,
|
|
15307
|
+
reviewer=reviewer,
|
|
15308
|
+
json=False,
|
|
15309
|
+
)
|
|
15310
|
+
)
|
|
15311
|
+
|
|
14369
15312
|
manifest = _load_task_manifest(control_repo, task_id)
|
|
14370
15313
|
review = manifest.get("review") or {}
|
|
15314
|
+
attempt_token = _review_attempt_token(review)
|
|
14371
15315
|
assignment_path = Path(_text(review.get("assignment_path"))).resolve()
|
|
14372
15316
|
assignment = _load_bound_review_assignment(
|
|
14373
15317
|
control_repo,
|
|
@@ -14379,7 +15323,12 @@ def cmd_review_run(args: argparse.Namespace) -> None:
|
|
|
14379
15323
|
_validate_review_diff_artifact(control_repo, assignment)
|
|
14380
15324
|
if _task_review_fingerprint(worktree, manifest, _load_cfg(worktree)) != fingerprint:
|
|
14381
15325
|
raise APError("Review assignment is stale; the task-owned working tree changed before Reviewer start.")
|
|
14382
|
-
result_path, receipt_path = _review_runtime_paths(
|
|
15326
|
+
result_path, receipt_path = _review_runtime_paths(
|
|
15327
|
+
control_repo,
|
|
15328
|
+
task_id,
|
|
15329
|
+
fingerprint,
|
|
15330
|
+
attempt_token,
|
|
15331
|
+
)
|
|
14383
15332
|
|
|
14384
15333
|
command_override = _text(getattr(args, "runner_command_json", ""))
|
|
14385
15334
|
if command_override:
|
|
@@ -14409,7 +15358,12 @@ def cmd_review_run(args: argparse.Namespace) -> None:
|
|
|
14409
15358
|
command_sha256 = _review_command_sha256(command)
|
|
14410
15359
|
command_metadata = _reviewer_command_metadata(command, runner_kind)
|
|
14411
15360
|
started_at = _now_iso()
|
|
14412
|
-
event_log_path = _review_runtime_event_log_path(
|
|
15361
|
+
event_log_path = _review_runtime_event_log_path(
|
|
15362
|
+
control_repo,
|
|
15363
|
+
task_id,
|
|
15364
|
+
fingerprint,
|
|
15365
|
+
attempt_token,
|
|
15366
|
+
)
|
|
14413
15367
|
receipt = {
|
|
14414
15368
|
"schema": 2,
|
|
14415
15369
|
"task_id": task_id,
|
|
@@ -14431,6 +15385,24 @@ def cmd_review_run(args: argparse.Namespace) -> None:
|
|
|
14431
15385
|
"finished_at": "",
|
|
14432
15386
|
"exit_code": None,
|
|
14433
15387
|
}
|
|
15388
|
+
retry_audit = _load_review_runtime_retry_audit(
|
|
15389
|
+
control_repo,
|
|
15390
|
+
manifest,
|
|
15391
|
+
assignment,
|
|
15392
|
+
require_same_runtime=bool(attempt_token),
|
|
15393
|
+
)
|
|
15394
|
+
if retry_audit is not None:
|
|
15395
|
+
receipt.update(
|
|
15396
|
+
{
|
|
15397
|
+
"runtime_retry_token": attempt_token,
|
|
15398
|
+
"runtime_retry_audit_path": _text(review.get("runtime_retry_audit_path")),
|
|
15399
|
+
"runtime_retry_audit_sha256": _text(review.get("runtime_retry_audit_sha256")),
|
|
15400
|
+
"managed_runtime_version": _text(retry_audit.get("managed_runtime_version")),
|
|
15401
|
+
"managed_runtime_script_sha256": _text(
|
|
15402
|
+
retry_audit.get("managed_runtime_script_sha256")
|
|
15403
|
+
),
|
|
15404
|
+
}
|
|
15405
|
+
)
|
|
14434
15406
|
timeout_s = float(_concurrency_cfg(_load_cfg(control_repo)).get("lock_timeout_sec") or 30)
|
|
14435
15407
|
with _repo_lock(control_repo, f"task-{task_id}", timeout_s=timeout_s):
|
|
14436
15408
|
manifest = _load_task_manifest(control_repo, task_id)
|
|
@@ -14449,7 +15421,12 @@ def cmd_review_run(args: argparse.Namespace) -> None:
|
|
|
14449
15421
|
raise APError(
|
|
14450
15422
|
"The supervised Reviewer runtime has already started for this diff fingerprint."
|
|
14451
15423
|
)
|
|
14452
|
-
deadline =
|
|
15424
|
+
deadline = _effective_review_deadline(
|
|
15425
|
+
control_repo,
|
|
15426
|
+
manifest,
|
|
15427
|
+
assignment,
|
|
15428
|
+
require_same_runtime=bool(attempt_token),
|
|
15429
|
+
)
|
|
14453
15430
|
if _dt.datetime.now(_dt.timezone.utc) >= deadline:
|
|
14454
15431
|
raise APError("Review assignment deadline expired before Reviewer runtime start.")
|
|
14455
15432
|
if result_path.exists() or result_path.is_symlink():
|
|
@@ -14490,11 +15467,20 @@ def cmd_review_run(args: argparse.Namespace) -> None:
|
|
|
14490
15467
|
"AUTOCODING_REVIEW_DIFF_ARTIFACT": _text(assignment.get("diff_artifact_path")),
|
|
14491
15468
|
"AUTOCODING_REVIEW_DIFF_ARTIFACT_SHA256": _text(assignment.get("diff_artifact_sha256")),
|
|
14492
15469
|
"AUTOCODING_REVIEW_RESULT": str(result_path),
|
|
14493
|
-
"AUTOCODING_REVIEW_DEADLINE":
|
|
15470
|
+
"AUTOCODING_REVIEW_DEADLINE": deadline.isoformat(),
|
|
14494
15471
|
"AUTOCODING_REVIEW_TIMEOUT_SECONDS": str(int(assignment.get("timeout_seconds") or 0)),
|
|
14495
15472
|
}
|
|
14496
15473
|
)
|
|
14497
|
-
|
|
15474
|
+
if retry_audit is not None:
|
|
15475
|
+
env.update(
|
|
15476
|
+
{
|
|
15477
|
+
"AUTOCODING_REVIEW_RETRY_TOKEN": attempt_token,
|
|
15478
|
+
"AUTOCODING_REVIEW_RETRY_AUDIT": _text(review.get("runtime_retry_audit_path")),
|
|
15479
|
+
"AUTOCODING_REVIEW_RETRY_AUDIT_SHA256": _text(
|
|
15480
|
+
review.get("runtime_retry_audit_sha256")
|
|
15481
|
+
),
|
|
15482
|
+
}
|
|
15483
|
+
)
|
|
14498
15484
|
attempts: list[dict] = []
|
|
14499
15485
|
completed: Optional[subprocess.CompletedProcess[str]] = None
|
|
14500
15486
|
runtime_failure: Optional[_ReviewerRuntimeFailure] = None
|
|
@@ -14922,6 +15908,7 @@ def cmd_review_runtime_override(args: argparse.Namespace) -> None:
|
|
|
14922
15908
|
control_repo,
|
|
14923
15909
|
task_id,
|
|
14924
15910
|
fingerprint,
|
|
15911
|
+
_review_attempt_token(review),
|
|
14925
15912
|
)
|
|
14926
15913
|
if receipt_path != expected_receipt_path.resolve():
|
|
14927
15914
|
raise APError("Reviewer runtime receipt path is not canonical.")
|
|
@@ -15117,6 +16104,8 @@ def cmd_task_review(args: argparse.Namespace) -> None:
|
|
|
15117
16104
|
control_repo,
|
|
15118
16105
|
task_id,
|
|
15119
16106
|
fingerprint,
|
|
16107
|
+
_review_attempt_token(assigned_review),
|
|
16108
|
+
create=False,
|
|
15120
16109
|
)
|
|
15121
16110
|
result_path = Path(_text(assigned_review.get("runtime_result_path"))).resolve()
|
|
15122
16111
|
receipt_path = Path(_text(assigned_review.get("runtime_receipt_path"))).resolve()
|
|
@@ -15150,6 +16139,8 @@ def cmd_task_review(args: argparse.Namespace) -> None:
|
|
|
15150
16139
|
control_repo,
|
|
15151
16140
|
task_id,
|
|
15152
16141
|
fingerprint,
|
|
16142
|
+
_review_attempt_token(assigned_review),
|
|
16143
|
+
create=False,
|
|
15153
16144
|
).resolve()
|
|
15154
16145
|
if Path(_text(receipt.get("event_log_path"))).resolve() != expected_event_log_path:
|
|
15155
16146
|
raise APError("Reviewer runtime event log path is not canonical.")
|
|
@@ -15182,6 +16173,13 @@ def cmd_task_review(args: argparse.Namespace) -> None:
|
|
|
15182
16173
|
+ ", ".join(receipt_mismatches)
|
|
15183
16174
|
)
|
|
15184
16175
|
deadline_at = _text(assigned_review.get("deadline_at"))
|
|
16176
|
+
effective_deadline = (
|
|
16177
|
+
_effective_review_deadline(control_repo, manifest, assignment)
|
|
16178
|
+
if assignment is not None
|
|
16179
|
+
else _parse_iso_timestamp(deadline_at, "deadline_at")
|
|
16180
|
+
if deadline_at
|
|
16181
|
+
else None
|
|
16182
|
+
)
|
|
15185
16183
|
completed_at = _dt.datetime.now(_dt.timezone.utc)
|
|
15186
16184
|
if (
|
|
15187
16185
|
_text(assigned_review.get("runtime_state")) == "completed"
|
|
@@ -15191,7 +16189,7 @@ def cmd_task_review(args: argparse.Namespace) -> None:
|
|
|
15191
16189
|
assigned_review.get("runtime_finished_at"),
|
|
15192
16190
|
"runtime_finished_at",
|
|
15193
16191
|
)
|
|
15194
|
-
if
|
|
16192
|
+
if effective_deadline is not None and completed_at > effective_deadline:
|
|
15195
16193
|
raise APError(
|
|
15196
16194
|
"Review assignment deadline expired; the single review attempt is blocked."
|
|
15197
16195
|
)
|
|
@@ -15213,7 +16211,7 @@ def cmd_task_review(args: argparse.Namespace) -> None:
|
|
|
15213
16211
|
"review_depth": _text(manifest.get("review_depth")),
|
|
15214
16212
|
"review_timeout_seconds": int(manifest.get("review_timeout_seconds") or 0),
|
|
15215
16213
|
}
|
|
15216
|
-
for field in _REVIEW_RUNTIME_FIELDS:
|
|
16214
|
+
for field in _REVIEW_RUNTIME_FIELDS + _REVIEW_RETRY_FIELDS:
|
|
15217
16215
|
if field in assigned_review:
|
|
15218
16216
|
review_state[field] = assigned_review[field]
|
|
15219
16217
|
manifest["review"] = review_state
|
|
@@ -16519,6 +17517,17 @@ def main(argv: Optional[List[str]] = None) -> int:
|
|
|
16519
17517
|
s.add_argument("--runner-command-json", help=argparse.SUPPRESS)
|
|
16520
17518
|
s.set_defaults(func=cmd_review_run)
|
|
16521
17519
|
|
|
17520
|
+
s = sp.add_parser(
|
|
17521
|
+
"review-runtime-retry",
|
|
17522
|
+
help="Authorize one audited retry for the fixed 4.2.8-4.3.2 review-artifact access defect",
|
|
17523
|
+
)
|
|
17524
|
+
s.add_argument("task_id")
|
|
17525
|
+
s.add_argument("--diff-fingerprint", required=True)
|
|
17526
|
+
s.add_argument("--reason-code", required=True)
|
|
17527
|
+
s.add_argument("--confirm-managed-runtime-retry", action="store_true")
|
|
17528
|
+
s.add_argument("--json", action="store_true")
|
|
17529
|
+
s.set_defaults(func=cmd_review_runtime_retry)
|
|
17530
|
+
|
|
16522
17531
|
s = sp.add_parser(
|
|
16523
17532
|
"review-runtime-override",
|
|
16524
17533
|
help="Record an explicit user-authorized bypass for an exhausted Reviewer runtime failure",
|