@elvis1513/auto-coding-skill 4.3.3 → 4.3.4
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 +37 -1
- package/cli/assets/managed-install.json +1 -1
- package/cli/assets/skill/SKILL.md +7 -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 +7 -1
- package/cli/assets/skill/scripts/ap.py +825 -35
- package/cli/tests/ap_concurrency_test.py +215 -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,22 @@ _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)
|
|
100
111
|
_REVIEW_OUTPUT_MAX_BYTES = 1024 * 1024
|
|
101
112
|
_REVIEW_DIFF_ARTIFACT_FORMAT = "git-binary-patch-v1"
|
|
102
113
|
_REVIEW_DIFF_ARTIFACT_MAX_BYTES = 64 * 1024 * 1024
|
|
103
114
|
_REVIEW_SHA256_RE = re.compile(r"^[0-9a-f]{64}$")
|
|
115
|
+
_REVIEW_ATTEMPT_TOKEN_RE = re.compile(r"^retry-v[0-9]+\.[0-9]+\.[0-9]+$")
|
|
104
116
|
_FEEDBACK_SCHEMAS = {
|
|
105
117
|
"auto-coding-skill-feedback/v1",
|
|
106
118
|
"auto-coding-skill-feedback/v2",
|
|
@@ -287,7 +299,7 @@ _FINAL_GATE_CACHE_ALGORITHM = "final-gate-v1"
|
|
|
287
299
|
_WORKFLOW_MIGRATION_POLICY = Path("data/policies/workflow-migrations-v1.json")
|
|
288
300
|
_FALLBACK_WORKFLOW_MIGRATION_POLICY = {
|
|
289
301
|
"schema_version": 1,
|
|
290
|
-
"managed_versions": {"agents": "4.3.
|
|
302
|
+
"managed_versions": {"agents": "4.3.4", "engineering": "4.3.4"},
|
|
291
303
|
"known_official_engineering_body_sha256": [
|
|
292
304
|
"d1306cc626e8baf8c83c953b760fd771066de2bf125168eca3a7b7d6ff2b87a2",
|
|
293
305
|
"305931c6edef770033a4f1970b00e5fb1c1728351856a173dbfa497daf563021",
|
|
@@ -5811,6 +5823,8 @@ def _validate_review_runtime_override(repo: Path, manifest: dict, fingerprint: s
|
|
|
5811
5823
|
repo,
|
|
5812
5824
|
_text(manifest.get("task_id")),
|
|
5813
5825
|
fingerprint,
|
|
5826
|
+
_review_attempt_token(review),
|
|
5827
|
+
create=False,
|
|
5814
5828
|
)
|
|
5815
5829
|
del expected_result_path
|
|
5816
5830
|
if receipt_path != expected_receipt_path.resolve():
|
|
@@ -5875,6 +5889,15 @@ def _require_approved_review(repo: Path, cfg: dict, manifest: dict) -> str:
|
|
|
5875
5889
|
_validate_review_diff_artifact(repo, assignment)
|
|
5876
5890
|
if verdict == "runtime-bypassed":
|
|
5877
5891
|
_validate_review_runtime_override(repo, manifest, fingerprint)
|
|
5892
|
+
elif _review_attempt_token(review):
|
|
5893
|
+
receipt_path = Path(_text(review.get("runtime_receipt_path"))).resolve()
|
|
5894
|
+
_validate_bound_review_runtime_receipt(
|
|
5895
|
+
repo,
|
|
5896
|
+
manifest,
|
|
5897
|
+
assignment,
|
|
5898
|
+
receipt_path,
|
|
5899
|
+
"completed",
|
|
5900
|
+
)
|
|
5878
5901
|
return fingerprint
|
|
5879
5902
|
|
|
5880
5903
|
|
|
@@ -13242,12 +13265,27 @@ def _task_status_payload(repo: Path, manifest: dict) -> dict:
|
|
|
13242
13265
|
)
|
|
13243
13266
|
review = manifest.get("review") or {}
|
|
13244
13267
|
deadline_at = _text(review.get("deadline_at"))
|
|
13268
|
+
effective_deadline_at = deadline_at
|
|
13245
13269
|
review_seconds_remaining: Optional[int] = None
|
|
13246
13270
|
review_deadline_expired = False
|
|
13271
|
+
if _review_attempt_token(review):
|
|
13272
|
+
try:
|
|
13273
|
+
assignment = _load_bound_review_assignment(
|
|
13274
|
+
repo,
|
|
13275
|
+
manifest,
|
|
13276
|
+
Path(_text(review.get("assignment_path"))).resolve(),
|
|
13277
|
+
)
|
|
13278
|
+
effective_deadline_at = _effective_review_deadline(
|
|
13279
|
+
repo,
|
|
13280
|
+
manifest,
|
|
13281
|
+
assignment,
|
|
13282
|
+
).isoformat()
|
|
13283
|
+
except APError:
|
|
13284
|
+
effective_deadline_at = ""
|
|
13247
13285
|
if deadline_at:
|
|
13248
13286
|
try:
|
|
13249
13287
|
remaining = (
|
|
13250
|
-
_parse_iso_timestamp(
|
|
13288
|
+
_parse_iso_timestamp(effective_deadline_at, "effective_deadline_at")
|
|
13251
13289
|
- _dt.datetime.now(_dt.timezone.utc)
|
|
13252
13290
|
).total_seconds()
|
|
13253
13291
|
seconds = int(remaining)
|
|
@@ -13264,6 +13302,7 @@ def _task_status_payload(repo: Path, manifest: dict) -> dict:
|
|
|
13264
13302
|
"tip": tip,
|
|
13265
13303
|
"has_task_commits": has_task_commits,
|
|
13266
13304
|
"merged_into_target": merged,
|
|
13305
|
+
"review_effective_deadline_at": effective_deadline_at,
|
|
13267
13306
|
"review_deadline_expired": review_deadline_expired,
|
|
13268
13307
|
"review_seconds_remaining": review_seconds_remaining,
|
|
13269
13308
|
"current_diff_fingerprint": _task_review_fingerprint(worktree, manifest)
|
|
@@ -13495,10 +13534,30 @@ def _parse_iso_timestamp(value: object, field: str) -> _dt.datetime:
|
|
|
13495
13534
|
return parsed.astimezone(_dt.timezone.utc)
|
|
13496
13535
|
|
|
13497
13536
|
|
|
13498
|
-
def
|
|
13537
|
+
def _review_attempt_token(review: object) -> str:
|
|
13538
|
+
payload = review if isinstance(review, dict) else {}
|
|
13539
|
+
token = _text(payload.get("runtime_retry_token"))
|
|
13540
|
+
if token and not _REVIEW_ATTEMPT_TOKEN_RE.fullmatch(token):
|
|
13541
|
+
raise APError("Reviewer runtime retry token is invalid.")
|
|
13542
|
+
return token
|
|
13543
|
+
|
|
13544
|
+
|
|
13545
|
+
def _review_attempt_stem(fingerprint: str, attempt_token: str = "") -> str:
|
|
13499
13546
|
if not _REVIEW_SHA256_RE.fullmatch(_text(fingerprint)):
|
|
13500
13547
|
raise APError("Review fingerprint must be a lowercase SHA-256 value.")
|
|
13501
|
-
|
|
13548
|
+
token = _text(attempt_token)
|
|
13549
|
+
if token and not _REVIEW_ATTEMPT_TOKEN_RE.fullmatch(token):
|
|
13550
|
+
raise APError("Reviewer runtime retry token is invalid.")
|
|
13551
|
+
return f"{fingerprint}.{token}" if token else fingerprint
|
|
13552
|
+
|
|
13553
|
+
|
|
13554
|
+
def _review_assignment_path(
|
|
13555
|
+
control_repo: Path,
|
|
13556
|
+
task_id: str,
|
|
13557
|
+
fingerprint: str,
|
|
13558
|
+
) -> Path:
|
|
13559
|
+
stem = _review_attempt_stem(fingerprint)
|
|
13560
|
+
return _task_review_dir(control_repo, task_id) / f"{stem}.assignment.json"
|
|
13502
13561
|
|
|
13503
13562
|
|
|
13504
13563
|
def _review_diff_artifact_path(control_repo: Path, task_id: str, fingerprint: str) -> Path:
|
|
@@ -13811,8 +13870,16 @@ def cmd_review_assignment(args: argparse.Namespace) -> None:
|
|
|
13811
13870
|
"scope_revision": int(manifest.get("scope_revision") or 1),
|
|
13812
13871
|
}
|
|
13813
13872
|
_validate_orchestration_contract("assignment", assignment)
|
|
13814
|
-
assignment_path = _review_assignment_path(control_repo, task_id, fingerprint)
|
|
13815
13873
|
prior_review = manifest.get("review") or {}
|
|
13874
|
+
assignment_path = _review_assignment_path(control_repo, task_id, fingerprint)
|
|
13875
|
+
if (
|
|
13876
|
+
_text(prior_review.get("diff_fingerprint")) == fingerprint
|
|
13877
|
+
and _review_attempt_token(prior_review)
|
|
13878
|
+
):
|
|
13879
|
+
raise APError(
|
|
13880
|
+
"A bounded Reviewer runtime retry is already authorized; run review-run with "
|
|
13881
|
+
"the original Reviewer identity."
|
|
13882
|
+
)
|
|
13816
13883
|
if (
|
|
13817
13884
|
_text(prior_review.get("diff_fingerprint")) == fingerprint
|
|
13818
13885
|
and (
|
|
@@ -13962,7 +14029,7 @@ def cmd_review_assignment(args: argparse.Namespace) -> None:
|
|
|
13962
14029
|
"deadline_at": assignment["deadline_at"],
|
|
13963
14030
|
}
|
|
13964
14031
|
if _text(prior_review.get("diff_fingerprint")) == fingerprint:
|
|
13965
|
-
for field in _REVIEW_RUNTIME_FIELDS:
|
|
14032
|
+
for field in _REVIEW_RUNTIME_FIELDS + _REVIEW_RETRY_FIELDS:
|
|
13966
14033
|
if field in prior_review:
|
|
13967
14034
|
review_state[field] = prior_review[field]
|
|
13968
14035
|
manifest["review"] = review_state
|
|
@@ -13993,10 +14060,14 @@ def cmd_review_artifact(args: argparse.Namespace) -> None:
|
|
|
13993
14060
|
raise APError(
|
|
13994
14061
|
f"Review artifact must be read from its assigned worktree: expected={assigned_worktree}, current={repo}."
|
|
13995
14062
|
)
|
|
13996
|
-
|
|
13997
|
-
|
|
13998
|
-
|
|
13999
|
-
|
|
14063
|
+
deadline = _effective_review_deadline(
|
|
14064
|
+
repo,
|
|
14065
|
+
manifest,
|
|
14066
|
+
assignment,
|
|
14067
|
+
require_environment=bool(_review_attempt_token(manifest.get("review") or {})),
|
|
14068
|
+
require_same_runtime=bool(_review_attempt_token(manifest.get("review") or {})),
|
|
14069
|
+
)
|
|
14070
|
+
if _dt.datetime.now(_dt.timezone.utc) >= deadline:
|
|
14000
14071
|
raise APError("Review assignment deadline expired before diff artifact access.")
|
|
14001
14072
|
payload = _validate_review_diff_artifact(repo, assignment)
|
|
14002
14073
|
sys.stdout.flush()
|
|
@@ -14011,26 +14082,61 @@ def _write_private_json(path: Path, payload: dict) -> None:
|
|
|
14011
14082
|
_write_private_bytes(path, encoded)
|
|
14012
14083
|
|
|
14013
14084
|
|
|
14085
|
+
def _create_private_json(path: Path, payload: dict, label: str) -> None:
|
|
14086
|
+
encoded = (
|
|
14087
|
+
json.dumps(payload, ensure_ascii=False, indent=2, sort_keys=True) + "\n"
|
|
14088
|
+
).encode("utf-8")
|
|
14089
|
+
handle = _open_private_review_event_log(path)
|
|
14090
|
+
try:
|
|
14091
|
+
handle.write(encoded.decode("utf-8"))
|
|
14092
|
+
handle.flush()
|
|
14093
|
+
os.fsync(handle.fileno())
|
|
14094
|
+
except Exception:
|
|
14095
|
+
handle.close()
|
|
14096
|
+
path.unlink(missing_ok=True)
|
|
14097
|
+
raise
|
|
14098
|
+
handle.close()
|
|
14099
|
+
if _private_review_file_sha256(path, label) != hashlib.sha256(encoded).hexdigest():
|
|
14100
|
+
raise APError(f"Review {label} changed during create-only publication.")
|
|
14101
|
+
|
|
14102
|
+
|
|
14014
14103
|
def _review_runtime_paths(
|
|
14015
14104
|
control_repo: Path,
|
|
14016
14105
|
task_id: str,
|
|
14017
14106
|
fingerprint: str,
|
|
14107
|
+
attempt_token: str = "",
|
|
14108
|
+
*,
|
|
14109
|
+
create: bool = True,
|
|
14018
14110
|
) -> tuple[Path, Path]:
|
|
14019
|
-
|
|
14020
|
-
|
|
14021
|
-
root
|
|
14022
|
-
return root / f"{fingerprint}.result.json", root / f"{fingerprint}.run.json"
|
|
14111
|
+
stem = _review_attempt_stem(fingerprint, attempt_token)
|
|
14112
|
+
root = _task_review_dir(control_repo, task_id, create=create)
|
|
14113
|
+
return root / f"{stem}.result.json", root / f"{stem}.run.json"
|
|
14023
14114
|
|
|
14024
14115
|
|
|
14025
14116
|
def _review_runtime_event_log_path(
|
|
14026
14117
|
control_repo: Path,
|
|
14027
14118
|
task_id: str,
|
|
14028
14119
|
fingerprint: str,
|
|
14120
|
+
attempt_token: str = "",
|
|
14121
|
+
*,
|
|
14122
|
+
create: bool = True,
|
|
14029
14123
|
) -> Path:
|
|
14030
|
-
|
|
14031
|
-
|
|
14032
|
-
root
|
|
14033
|
-
|
|
14124
|
+
stem = _review_attempt_stem(fingerprint, attempt_token)
|
|
14125
|
+
root = _task_review_dir(control_repo, task_id, create=create)
|
|
14126
|
+
return root / f"{stem}.events.jsonl"
|
|
14127
|
+
|
|
14128
|
+
|
|
14129
|
+
def _review_runtime_retry_audit_path(
|
|
14130
|
+
control_repo: Path,
|
|
14131
|
+
task_id: str,
|
|
14132
|
+
fingerprint: str,
|
|
14133
|
+
attempt_token: str,
|
|
14134
|
+
*,
|
|
14135
|
+
create: bool = True,
|
|
14136
|
+
) -> Path:
|
|
14137
|
+
stem = _review_attempt_stem(fingerprint, attempt_token)
|
|
14138
|
+
root = _task_review_dir(control_repo, task_id, create=create)
|
|
14139
|
+
return root / f"{stem}.audit.json"
|
|
14034
14140
|
|
|
14035
14141
|
|
|
14036
14142
|
def _review_runtime_override_path(
|
|
@@ -14061,6 +14167,260 @@ def _private_review_file_sha256(path: Path, label: str) -> str:
|
|
|
14061
14167
|
return hashlib.sha256(payload).hexdigest()
|
|
14062
14168
|
|
|
14063
14169
|
|
|
14170
|
+
def _review_runtime_version_tuple(value: object, label: str) -> tuple[int, int, int]:
|
|
14171
|
+
raw = _text(value)
|
|
14172
|
+
match = re.fullmatch(r"(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)", raw)
|
|
14173
|
+
if not match:
|
|
14174
|
+
raise APError(f"{label} must be a stable semantic version.")
|
|
14175
|
+
return tuple(int(match.group(index)) for index in range(1, 4))
|
|
14176
|
+
|
|
14177
|
+
|
|
14178
|
+
def _managed_review_runtime_identity() -> dict:
|
|
14179
|
+
script_path = Path(__file__).resolve()
|
|
14180
|
+
script_sha256 = hashlib.sha256(script_path.read_bytes()).hexdigest()
|
|
14181
|
+
agents_dir = next((parent for parent in script_path.parents if parent.name == ".agents"), None)
|
|
14182
|
+
if agents_dir is None:
|
|
14183
|
+
raise APError(
|
|
14184
|
+
"Reviewer runtime retry requires an installed managed Skill runtime; "
|
|
14185
|
+
"source-tree execution is not accepted."
|
|
14186
|
+
)
|
|
14187
|
+
install_root = agents_dir.parent.resolve()
|
|
14188
|
+
expected_relative = Path(".agents/skills/auto-coding-skill/scripts/ap.py")
|
|
14189
|
+
try:
|
|
14190
|
+
actual_relative = script_path.relative_to(install_root)
|
|
14191
|
+
except ValueError as exc:
|
|
14192
|
+
raise APError("Managed Reviewer runtime escapes its install root.") from exc
|
|
14193
|
+
if actual_relative != expected_relative:
|
|
14194
|
+
raise APError(
|
|
14195
|
+
"Reviewer runtime retry must execute the canonical managed ap.py entry."
|
|
14196
|
+
)
|
|
14197
|
+
manifest_path = agents_dir / "managed-install.json"
|
|
14198
|
+
try:
|
|
14199
|
+
manifest_bytes = manifest_path.read_bytes()
|
|
14200
|
+
except OSError as exc:
|
|
14201
|
+
raise APError(f"Cannot read managed Reviewer runtime manifest: {manifest_path}: {exc}") from exc
|
|
14202
|
+
if len(manifest_bytes) > 4 * 1024 * 1024:
|
|
14203
|
+
raise APError("Managed Reviewer runtime manifest exceeds 4 MiB.")
|
|
14204
|
+
try:
|
|
14205
|
+
manifest = json.loads(manifest_bytes.decode("utf-8"))
|
|
14206
|
+
except (UnicodeDecodeError, json.JSONDecodeError) as exc:
|
|
14207
|
+
raise APError("Managed Reviewer runtime manifest is invalid JSON.") from exc
|
|
14208
|
+
if not isinstance(manifest, dict) or int(manifest.get("schema_version") or 0) != 1:
|
|
14209
|
+
raise APError("Managed Reviewer runtime manifest schema is invalid.")
|
|
14210
|
+
version = _text(manifest.get("skill_version"))
|
|
14211
|
+
_review_runtime_version_tuple(version, "Managed Reviewer runtime version")
|
|
14212
|
+
entries = manifest.get("entries")
|
|
14213
|
+
if not isinstance(entries, list):
|
|
14214
|
+
raise APError("Managed Reviewer runtime manifest entries are invalid.")
|
|
14215
|
+
matches = [
|
|
14216
|
+
entry
|
|
14217
|
+
for entry in entries
|
|
14218
|
+
if isinstance(entry, dict) and entry.get("path") == expected_relative.as_posix()
|
|
14219
|
+
]
|
|
14220
|
+
if len(matches) != 1:
|
|
14221
|
+
raise APError("Managed Reviewer runtime manifest must bind one canonical ap.py entry.")
|
|
14222
|
+
entry = matches[0]
|
|
14223
|
+
if (
|
|
14224
|
+
entry.get("source") != "skill/scripts/ap.py"
|
|
14225
|
+
or entry.get("ownership") != "exact"
|
|
14226
|
+
or entry.get("scope") != "shared"
|
|
14227
|
+
or entry.get("version") != version
|
|
14228
|
+
or _text(entry.get("sha256")) != script_sha256
|
|
14229
|
+
):
|
|
14230
|
+
raise APError("Managed Reviewer runtime ap.py identity check failed.")
|
|
14231
|
+
integrity = verify_managed_install(
|
|
14232
|
+
install_root,
|
|
14233
|
+
mode="global",
|
|
14234
|
+
expected_version=version,
|
|
14235
|
+
manifest_path=manifest_path,
|
|
14236
|
+
)
|
|
14237
|
+
if not integrity.get("ok"):
|
|
14238
|
+
raise APError(
|
|
14239
|
+
"Managed Reviewer runtime install integrity failed: "
|
|
14240
|
+
+ "; ".join(str(item) for item in integrity.get("errors") or [])
|
|
14241
|
+
)
|
|
14242
|
+
return {
|
|
14243
|
+
"version": version,
|
|
14244
|
+
"script_path": str(script_path),
|
|
14245
|
+
"script_sha256": script_sha256,
|
|
14246
|
+
"manifest_path": str(manifest_path.resolve()),
|
|
14247
|
+
"manifest_sha256": hashlib.sha256(manifest_bytes).hexdigest(),
|
|
14248
|
+
}
|
|
14249
|
+
|
|
14250
|
+
|
|
14251
|
+
def _load_review_runtime_retry_audit(
|
|
14252
|
+
control_repo: Path,
|
|
14253
|
+
manifest: dict,
|
|
14254
|
+
assignment: dict,
|
|
14255
|
+
*,
|
|
14256
|
+
require_environment: bool = False,
|
|
14257
|
+
require_same_runtime: bool = False,
|
|
14258
|
+
) -> Optional[dict]:
|
|
14259
|
+
review = manifest.get("review") or {}
|
|
14260
|
+
token = _review_attempt_token(review)
|
|
14261
|
+
if not token:
|
|
14262
|
+
return None
|
|
14263
|
+
task_id = _text(manifest.get("task_id"))
|
|
14264
|
+
fingerprint = _text(review.get("diff_fingerprint"))
|
|
14265
|
+
audit_path = _review_runtime_retry_audit_path(
|
|
14266
|
+
control_repo,
|
|
14267
|
+
task_id,
|
|
14268
|
+
fingerprint,
|
|
14269
|
+
token,
|
|
14270
|
+
create=False,
|
|
14271
|
+
).resolve()
|
|
14272
|
+
if Path(_text(review.get("runtime_retry_audit_path"))).resolve() != audit_path:
|
|
14273
|
+
raise APError("Reviewer runtime retry audit path is not canonical.")
|
|
14274
|
+
audit_sha256 = _text(review.get("runtime_retry_audit_sha256"))
|
|
14275
|
+
payload = _read_verified_private_review_file(audit_path, audit_sha256, "runtime retry audit")
|
|
14276
|
+
try:
|
|
14277
|
+
audit = json.loads(payload.decode("utf-8"))
|
|
14278
|
+
except (UnicodeDecodeError, json.JSONDecodeError) as exc:
|
|
14279
|
+
raise APError("Reviewer runtime retry audit is invalid JSON.") from exc
|
|
14280
|
+
if not isinstance(audit, dict) or int(audit.get("schema") or 0) != 1:
|
|
14281
|
+
raise APError("Reviewer runtime retry audit schema is invalid.")
|
|
14282
|
+
runtime_version = _text(audit.get("managed_runtime_version"))
|
|
14283
|
+
if token != f"retry-v{runtime_version}":
|
|
14284
|
+
raise APError("Reviewer runtime retry token does not bind its managed version.")
|
|
14285
|
+
if _text(review.get("runtime_retry_version")) != runtime_version:
|
|
14286
|
+
raise APError("Reviewer runtime retry version does not match its audit.")
|
|
14287
|
+
if (
|
|
14288
|
+
_text(review.get("runtime_retry_reason_code")) != _REVIEW_RUNTIME_RETRY_REASON
|
|
14289
|
+
or _text(audit.get("reason_code")) != _REVIEW_RUNTIME_RETRY_REASON
|
|
14290
|
+
):
|
|
14291
|
+
raise APError("Reviewer runtime retry reason code is invalid.")
|
|
14292
|
+
expected = {
|
|
14293
|
+
"task_id": task_id,
|
|
14294
|
+
"task_uuid": _text(manifest.get("task_uuid")),
|
|
14295
|
+
"owner": _text(manifest.get("owner")),
|
|
14296
|
+
"reviewer": _text(review.get("reviewer")),
|
|
14297
|
+
"task_skill_version": _text(manifest.get("skill_version")),
|
|
14298
|
+
"base_sha": _text(manifest.get("base_sha")),
|
|
14299
|
+
"diff_head": _text(assignment.get("diff_head")),
|
|
14300
|
+
"diff_fingerprint": fingerprint,
|
|
14301
|
+
"scope_revision": int(manifest.get("scope_revision") or 1),
|
|
14302
|
+
"owned_paths": list(manifest.get("owned_paths") or []),
|
|
14303
|
+
"retry_token": token,
|
|
14304
|
+
"assignment_path": str(_review_assignment_path(control_repo, task_id, fingerprint).resolve()),
|
|
14305
|
+
"assignment_sha256": _text(review.get("assignment_sha256")),
|
|
14306
|
+
"diff_artifact_path": str(_review_diff_artifact_path(control_repo, task_id, fingerprint).resolve()),
|
|
14307
|
+
"diff_artifact_sha256": _text(review.get("diff_artifact_sha256")),
|
|
14308
|
+
"original_deadline_at": _text(assignment.get("deadline_at")),
|
|
14309
|
+
}
|
|
14310
|
+
mismatched = [field for field, value in expected.items() if audit.get(field) != value]
|
|
14311
|
+
if mismatched:
|
|
14312
|
+
raise APError(
|
|
14313
|
+
"Reviewer runtime retry audit does not match task state: " + ", ".join(mismatched)
|
|
14314
|
+
)
|
|
14315
|
+
worktree = Path(_text(manifest.get("worktree_path"))).resolve()
|
|
14316
|
+
if not worktree.exists() or _resolve_commit(worktree, "HEAD") != _text(assignment.get("diff_head")):
|
|
14317
|
+
raise APError("Reviewer runtime retry task HEAD changed after authorization.")
|
|
14318
|
+
if _task_review_fingerprint(worktree, manifest, _load_cfg(worktree)) != fingerprint:
|
|
14319
|
+
raise APError("Reviewer runtime retry diff changed after authorization.")
|
|
14320
|
+
retry_result_path, retry_receipt_path = _review_runtime_paths(
|
|
14321
|
+
control_repo,
|
|
14322
|
+
task_id,
|
|
14323
|
+
fingerprint,
|
|
14324
|
+
token,
|
|
14325
|
+
create=False,
|
|
14326
|
+
)
|
|
14327
|
+
retry_event_path = _review_runtime_event_log_path(
|
|
14328
|
+
control_repo,
|
|
14329
|
+
task_id,
|
|
14330
|
+
fingerprint,
|
|
14331
|
+
token,
|
|
14332
|
+
create=False,
|
|
14333
|
+
)
|
|
14334
|
+
retry_expected = {
|
|
14335
|
+
"retry_result_path": str(retry_result_path.resolve()),
|
|
14336
|
+
"retry_receipt_path": str(retry_receipt_path.resolve()),
|
|
14337
|
+
"retry_event_log_path": str(retry_event_path.resolve()),
|
|
14338
|
+
}
|
|
14339
|
+
retry_mismatched = [field for field, value in retry_expected.items() if audit.get(field) != value]
|
|
14340
|
+
if retry_mismatched:
|
|
14341
|
+
raise APError(
|
|
14342
|
+
"Reviewer runtime retry audit paths are invalid: " + ", ".join(retry_mismatched)
|
|
14343
|
+
)
|
|
14344
|
+
for field, label in (
|
|
14345
|
+
("prior_result", "prior result"),
|
|
14346
|
+
("prior_receipt", "prior runtime receipt"),
|
|
14347
|
+
("prior_event_log", "prior event log"),
|
|
14348
|
+
):
|
|
14349
|
+
path = Path(_text(audit.get(f"{field}_path"))).resolve()
|
|
14350
|
+
expected_path = {
|
|
14351
|
+
"prior_result": _review_runtime_paths(
|
|
14352
|
+
control_repo, task_id, fingerprint, create=False
|
|
14353
|
+
)[0].resolve(),
|
|
14354
|
+
"prior_receipt": _review_runtime_paths(
|
|
14355
|
+
control_repo, task_id, fingerprint, create=False
|
|
14356
|
+
)[1].resolve(),
|
|
14357
|
+
"prior_event_log": _review_runtime_event_log_path(
|
|
14358
|
+
control_repo, task_id, fingerprint, create=False
|
|
14359
|
+
).resolve(),
|
|
14360
|
+
}[field]
|
|
14361
|
+
if path != expected_path:
|
|
14362
|
+
raise APError(f"Reviewer runtime retry {label} path is not canonical.")
|
|
14363
|
+
_read_verified_private_review_file(path, _text(audit.get(f"{field}_sha256")), label)
|
|
14364
|
+
issued = _parse_iso_timestamp(audit.get("retry_issued_at"), "retry_issued_at")
|
|
14365
|
+
deadline = _parse_iso_timestamp(audit.get("retry_deadline_at"), "retry_deadline_at")
|
|
14366
|
+
timeout_seconds = int(audit.get("retry_timeout_seconds") or 0)
|
|
14367
|
+
if timeout_seconds != int(assignment.get("timeout_seconds") or 0):
|
|
14368
|
+
raise APError("Reviewer runtime retry timeout does not match the original fixed policy.")
|
|
14369
|
+
if int((deadline - issued).total_seconds()) != timeout_seconds:
|
|
14370
|
+
raise APError("Reviewer runtime retry deadline duration is invalid.")
|
|
14371
|
+
identity = _managed_review_runtime_identity()
|
|
14372
|
+
current_version = _review_runtime_version_tuple(identity["version"], "Current managed runtime version")
|
|
14373
|
+
audit_version = _review_runtime_version_tuple(runtime_version, "Retry managed runtime version")
|
|
14374
|
+
if current_version < audit_version:
|
|
14375
|
+
raise APError("Current managed runtime is older than the authorized Reviewer retry runtime.")
|
|
14376
|
+
if require_same_runtime and any(
|
|
14377
|
+
audit.get(field) != identity[value]
|
|
14378
|
+
for field, value in (
|
|
14379
|
+
("managed_runtime_version", "version"),
|
|
14380
|
+
("managed_runtime_script_path", "script_path"),
|
|
14381
|
+
("managed_runtime_script_sha256", "script_sha256"),
|
|
14382
|
+
("managed_runtime_manifest_path", "manifest_path"),
|
|
14383
|
+
("managed_runtime_manifest_sha256", "manifest_sha256"),
|
|
14384
|
+
)
|
|
14385
|
+
):
|
|
14386
|
+
raise APError("Reviewer retry must use the exact managed runtime that authorized it.")
|
|
14387
|
+
if require_environment:
|
|
14388
|
+
environment_expected = {
|
|
14389
|
+
"AUTOCODING_REVIEW_RETRY_TOKEN": token,
|
|
14390
|
+
"AUTOCODING_REVIEW_RETRY_AUDIT": str(audit_path),
|
|
14391
|
+
"AUTOCODING_REVIEW_RETRY_AUDIT_SHA256": audit_sha256,
|
|
14392
|
+
}
|
|
14393
|
+
missing = [
|
|
14394
|
+
key for key, value in environment_expected.items() if _text(os.environ.get(key)) != value
|
|
14395
|
+
]
|
|
14396
|
+
if missing:
|
|
14397
|
+
raise APError(
|
|
14398
|
+
"Reviewer retry artifact access lacks its supervised audit binding: "
|
|
14399
|
+
+ ", ".join(missing)
|
|
14400
|
+
)
|
|
14401
|
+
return audit
|
|
14402
|
+
|
|
14403
|
+
|
|
14404
|
+
def _effective_review_deadline(
|
|
14405
|
+
control_repo: Path,
|
|
14406
|
+
manifest: dict,
|
|
14407
|
+
assignment: dict,
|
|
14408
|
+
*,
|
|
14409
|
+
require_environment: bool = False,
|
|
14410
|
+
require_same_runtime: bool = False,
|
|
14411
|
+
) -> _dt.datetime:
|
|
14412
|
+
audit = _load_review_runtime_retry_audit(
|
|
14413
|
+
control_repo,
|
|
14414
|
+
manifest,
|
|
14415
|
+
assignment,
|
|
14416
|
+
require_environment=require_environment,
|
|
14417
|
+
require_same_runtime=require_same_runtime,
|
|
14418
|
+
)
|
|
14419
|
+
if audit is None:
|
|
14420
|
+
return _parse_iso_timestamp(assignment.get("deadline_at"), "deadline_at")
|
|
14421
|
+
return _parse_iso_timestamp(audit.get("retry_deadline_at"), "retry_deadline_at")
|
|
14422
|
+
|
|
14423
|
+
|
|
14064
14424
|
def _reviewer_cli_version(command: list[str], runner_kind: str) -> str:
|
|
14065
14425
|
if runner_kind != "codex" or not command:
|
|
14066
14426
|
return "test-override"
|
|
@@ -14257,6 +14617,15 @@ def _update_review_runtime(
|
|
|
14257
14617
|
review = dict(manifest.get("review") or {})
|
|
14258
14618
|
if _text(review.get("diff_fingerprint")) != fingerprint:
|
|
14259
14619
|
raise APError("Reviewer runtime assignment became stale while the process was running.")
|
|
14620
|
+
_, expected_receipt_path = _review_runtime_paths(
|
|
14621
|
+
control_repo,
|
|
14622
|
+
task_id,
|
|
14623
|
+
fingerprint,
|
|
14624
|
+
_review_attempt_token(review),
|
|
14625
|
+
create=False,
|
|
14626
|
+
)
|
|
14627
|
+
if receipt_path.resolve() != expected_receipt_path.resolve():
|
|
14628
|
+
raise APError("Reviewer runtime attempt token changed while the process was running.")
|
|
14260
14629
|
review.update(updates)
|
|
14261
14630
|
manifest["review"] = review
|
|
14262
14631
|
receipt = _read_json_object(receipt_path) or {}
|
|
@@ -14289,6 +14658,8 @@ def _validate_bound_review_runtime_receipt(
|
|
|
14289
14658
|
control_repo,
|
|
14290
14659
|
task_id,
|
|
14291
14660
|
fingerprint,
|
|
14661
|
+
_review_attempt_token(review),
|
|
14662
|
+
create=False,
|
|
14292
14663
|
)
|
|
14293
14664
|
if receipt_path.resolve() != expected_receipt_path.resolve():
|
|
14294
14665
|
raise APError("Reviewer runtime receipt path is not canonical.")
|
|
@@ -14311,11 +14682,35 @@ def _validate_bound_review_runtime_receipt(
|
|
|
14311
14682
|
"result_path": str(expected_result_path),
|
|
14312
14683
|
"command_sha256": _text(review.get("runtime_command_sha256")),
|
|
14313
14684
|
"event_log_path": str(
|
|
14314
|
-
_review_runtime_event_log_path(
|
|
14685
|
+
_review_runtime_event_log_path(
|
|
14686
|
+
control_repo,
|
|
14687
|
+
task_id,
|
|
14688
|
+
fingerprint,
|
|
14689
|
+
_review_attempt_token(review),
|
|
14690
|
+
create=False,
|
|
14691
|
+
)
|
|
14315
14692
|
),
|
|
14316
14693
|
"status": expected_status,
|
|
14317
14694
|
}
|
|
14318
14695
|
mismatched = [field for field, value in expected.items() if receipt.get(field) != value]
|
|
14696
|
+
retry_audit = _load_review_runtime_retry_audit(
|
|
14697
|
+
control_repo,
|
|
14698
|
+
manifest,
|
|
14699
|
+
assignment,
|
|
14700
|
+
)
|
|
14701
|
+
if retry_audit is not None:
|
|
14702
|
+
retry_expected = {
|
|
14703
|
+
"runtime_retry_token": _review_attempt_token(review),
|
|
14704
|
+
"runtime_retry_audit_path": _text(review.get("runtime_retry_audit_path")),
|
|
14705
|
+
"runtime_retry_audit_sha256": _text(review.get("runtime_retry_audit_sha256")),
|
|
14706
|
+
"managed_runtime_version": _text(retry_audit.get("managed_runtime_version")),
|
|
14707
|
+
"managed_runtime_script_sha256": _text(
|
|
14708
|
+
retry_audit.get("managed_runtime_script_sha256")
|
|
14709
|
+
),
|
|
14710
|
+
}
|
|
14711
|
+
mismatched.extend(
|
|
14712
|
+
field for field, value in retry_expected.items() if receipt.get(field) != value
|
|
14713
|
+
)
|
|
14319
14714
|
if mismatched:
|
|
14320
14715
|
raise APError(
|
|
14321
14716
|
"Reviewer runtime receipt does not match task state: " + ", ".join(mismatched)
|
|
@@ -14349,25 +14744,355 @@ def _blocked_reviewer_runtime_result(
|
|
|
14349
14744
|
return _validate_orchestration_contract("result", result)
|
|
14350
14745
|
|
|
14351
14746
|
|
|
14352
|
-
def
|
|
14747
|
+
def _known_review_artifact_access_failure(
|
|
14748
|
+
control_repo: Path,
|
|
14749
|
+
result: dict,
|
|
14750
|
+
) -> bool:
|
|
14751
|
+
if (
|
|
14752
|
+
_text(result.get("verdict")) != "blocked"
|
|
14753
|
+
or _text(result.get("status")) != "blocked"
|
|
14754
|
+
or list(result.get("findings") or [])
|
|
14755
|
+
or list(result.get("changed_paths") or [])
|
|
14756
|
+
):
|
|
14757
|
+
return False
|
|
14758
|
+
evidence = result.get("evidence")
|
|
14759
|
+
if not isinstance(evidence, list) or len(evidence) != 1 or not isinstance(evidence[0], str):
|
|
14760
|
+
return False
|
|
14761
|
+
state_root = re.escape(str(_task_state_root(control_repo).resolve()))
|
|
14762
|
+
pattern = re.compile(
|
|
14763
|
+
r"^review-artifact exited(?: with code)? 2: Cannot protect Git-local review storage"
|
|
14764
|
+
rf"(?: at |: ){state_root}: (?:\[Errno 1\] )?Operation not permitted\.?$"
|
|
14765
|
+
)
|
|
14766
|
+
if not pattern.fullmatch(evidence[0]):
|
|
14767
|
+
return False
|
|
14768
|
+
summaries = {
|
|
14769
|
+
"Review could not start because review-artifact failed while protecting Git-local review storage.",
|
|
14770
|
+
"Review could not begin because review-artifact failed before verifying or emitting the immutable patch.",
|
|
14771
|
+
"Review could not begin because review-artifact failed before emitting the verified immutable patch.",
|
|
14772
|
+
"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.",
|
|
14773
|
+
"Review could not begin because the mandatory frozen artifact verification failed under the read-only filesystem.",
|
|
14774
|
+
"Review could not begin because review-artifact failed before emitting the immutable patch.",
|
|
14775
|
+
}
|
|
14776
|
+
if _text(result.get("summary")) not in summaries:
|
|
14777
|
+
return False
|
|
14778
|
+
risks = result.get("risks")
|
|
14779
|
+
allowed_risks = {
|
|
14780
|
+
"The immutable patch was not emitted or substantively reviewed because mandatory artifact verification did not complete.",
|
|
14781
|
+
"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.",
|
|
14782
|
+
"The frozen diff artifact was not emitted or substantively reviewed; no correctness or security conclusion can be made.",
|
|
14783
|
+
"The frozen diff was not emitted or substantively reviewed; no correctness or security conclusion is available.",
|
|
14784
|
+
"The immutable patch was neither verified nor analyzed; no substantive correctness or security conclusion is available.",
|
|
14785
|
+
"The immutable patch was not emitted or substantively reviewed.",
|
|
14786
|
+
}
|
|
14787
|
+
if not isinstance(risks, list) or len(risks) != 1 or risks[0] not in allowed_risks:
|
|
14788
|
+
return False
|
|
14789
|
+
return True
|
|
14790
|
+
|
|
14791
|
+
|
|
14792
|
+
def cmd_review_runtime_retry(args: argparse.Namespace) -> None:
|
|
14353
14793
|
repo = Path(args.repo).resolve()
|
|
14354
14794
|
ensure_git_repo(repo)
|
|
14355
14795
|
cfg = _load_cfg(repo)
|
|
14356
14796
|
task_id = _validate_task_id(args.task_id)
|
|
14357
|
-
|
|
14358
|
-
|
|
14359
|
-
|
|
14360
|
-
|
|
14361
|
-
|
|
14362
|
-
|
|
14363
|
-
|
|
14364
|
-
|
|
14797
|
+
if _text(args.reason_code) != _REVIEW_RUNTIME_RETRY_REASON:
|
|
14798
|
+
raise APError(
|
|
14799
|
+
f"--reason-code must be {_REVIEW_RUNTIME_RETRY_REASON} for this bounded migration."
|
|
14800
|
+
)
|
|
14801
|
+
if not bool(args.confirm_managed_runtime_retry):
|
|
14802
|
+
raise APError("Reviewer runtime retry requires --confirm-managed-runtime-retry.")
|
|
14803
|
+
identity = _managed_review_runtime_identity()
|
|
14804
|
+
runtime_version = _text(identity.get("version"))
|
|
14805
|
+
runtime_version_tuple = _review_runtime_version_tuple(
|
|
14806
|
+
runtime_version,
|
|
14807
|
+
"Managed Reviewer runtime version",
|
|
14808
|
+
)
|
|
14809
|
+
if runtime_version_tuple < _REVIEW_RUNTIME_RETRY_FIXED_IN:
|
|
14810
|
+
raise APError("Managed Reviewer runtime is too old to authorize the bounded retry.")
|
|
14811
|
+
|
|
14812
|
+
control_repo, worktree, _ = _task_lifecycle_context(repo, cfg, task_id)
|
|
14813
|
+
timeout_s = float(_concurrency_cfg(cfg).get("lock_timeout_sec") or 30)
|
|
14814
|
+
with _repo_lock(control_repo, f"task-{task_id}", timeout_s=timeout_s):
|
|
14815
|
+
manifest = _load_task_manifest(control_repo, task_id)
|
|
14816
|
+
lifecycle_actor = _text(os.environ.get("CODEX_THREAD_ID"))
|
|
14817
|
+
if not lifecycle_actor or lifecycle_actor != _text(manifest.get("owner")):
|
|
14818
|
+
raise APError("Only the task lifecycle owner may authorize a Reviewer runtime retry.")
|
|
14819
|
+
if _text(manifest.get("state")) != "active":
|
|
14820
|
+
raise APError("Reviewer runtime retry is limited to active tasks.")
|
|
14821
|
+
if not bool(manifest.get("review_required")):
|
|
14822
|
+
raise APError("Reviewer runtime retry requires an independent-review task.")
|
|
14823
|
+
task_version = _text(manifest.get("skill_version"))
|
|
14824
|
+
task_version_tuple = _review_runtime_version_tuple(task_version, "Task Skill version")
|
|
14825
|
+
if not (
|
|
14826
|
+
_REVIEW_RUNTIME_RETRY_AFFECTED_MIN
|
|
14827
|
+
<= task_version_tuple
|
|
14828
|
+
<= _REVIEW_RUNTIME_RETRY_AFFECTED_MAX
|
|
14829
|
+
):
|
|
14830
|
+
raise APError("Task Skill version is outside the bounded Reviewer retry migration range.")
|
|
14831
|
+
if runtime_version_tuple <= task_version_tuple:
|
|
14832
|
+
raise APError("Managed Reviewer retry runtime must be newer than the task runtime.")
|
|
14833
|
+
review = dict(manifest.get("review") or {})
|
|
14834
|
+
if _review_attempt_token(review) or any(_text(review.get(field)) for field in _REVIEW_RETRY_FIELDS):
|
|
14835
|
+
raise APError("A Reviewer runtime retry is already authorized for this diff fingerprint.")
|
|
14836
|
+
if _text(review.get("runtime_override_path")) or _text(review.get("runtime_override_sha256")):
|
|
14837
|
+
raise APError("Reviewer runtime retry cannot follow a user-authorized runtime override.")
|
|
14838
|
+
fingerprint = _task_review_fingerprint(worktree, manifest, _load_cfg(worktree))
|
|
14839
|
+
supplied = _text(args.diff_fingerprint)
|
|
14840
|
+
if supplied != fingerprint or _text(review.get("diff_fingerprint")) != fingerprint:
|
|
14841
|
+
raise APError(
|
|
14842
|
+
f"Reviewer runtime retry fingerprint mismatch: supplied={supplied or '(missing)'}, "
|
|
14843
|
+
f"current={fingerprint}."
|
|
14844
|
+
)
|
|
14845
|
+
if (
|
|
14846
|
+
_text(review.get("verdict")) != "blocked"
|
|
14847
|
+
or _text(review.get("runtime_state")) != "blocked"
|
|
14848
|
+
or review.get("runtime_exit_code") != 0
|
|
14849
|
+
or _text(review.get("runtime_failure_kind"))
|
|
14850
|
+
or int(review.get("runtime_attempt_count") or 0) != 1
|
|
14851
|
+
):
|
|
14852
|
+
raise APError("Prior Reviewer state is not the exact completed procedural block eligible for retry.")
|
|
14853
|
+
assignment_path = Path(_text(review.get("assignment_path"))).resolve()
|
|
14854
|
+
assignment = _load_bound_review_assignment(control_repo, manifest, assignment_path)
|
|
14855
|
+
_validate_review_diff_artifact(control_repo, assignment)
|
|
14856
|
+
expected_assignment_fields = {
|
|
14857
|
+
"task_id": task_id,
|
|
14858
|
+
"base_sha": _text(manifest.get("base_sha")),
|
|
14859
|
+
"diff_base": _text(manifest.get("base_sha")),
|
|
14860
|
+
"diff_head": _resolve_commit(worktree, "HEAD"),
|
|
14861
|
+
"diff_fingerprint": fingerprint,
|
|
14862
|
+
"owned_paths": list(manifest.get("owned_paths") or []),
|
|
14863
|
+
"node_id": _text(review.get("reviewer")),
|
|
14864
|
+
"scope_revision": int(manifest.get("scope_revision") or 1),
|
|
14865
|
+
}
|
|
14866
|
+
assignment_mismatches = [
|
|
14867
|
+
field for field, value in expected_assignment_fields.items() if assignment.get(field) != value
|
|
14868
|
+
]
|
|
14869
|
+
if assignment_mismatches:
|
|
14870
|
+
raise APError(
|
|
14871
|
+
"Prior Reviewer assignment no longer matches task state: "
|
|
14872
|
+
+ ", ".join(assignment_mismatches)
|
|
14365
14873
|
)
|
|
14874
|
+
prior_result_path, prior_receipt_path = _review_runtime_paths(
|
|
14875
|
+
control_repo,
|
|
14876
|
+
task_id,
|
|
14877
|
+
fingerprint,
|
|
14878
|
+
create=False,
|
|
14879
|
+
)
|
|
14880
|
+
prior_event_path = _review_runtime_event_log_path(
|
|
14881
|
+
control_repo,
|
|
14882
|
+
task_id,
|
|
14883
|
+
fingerprint,
|
|
14884
|
+
create=False,
|
|
14366
14885
|
)
|
|
14886
|
+
if Path(_text(review.get("runtime_result_path"))).resolve() != prior_result_path.resolve():
|
|
14887
|
+
raise APError("Prior Reviewer result path is not canonical.")
|
|
14888
|
+
if Path(_text(review.get("runtime_receipt_path"))).resolve() != prior_receipt_path.resolve():
|
|
14889
|
+
raise APError("Prior Reviewer receipt path is not canonical.")
|
|
14890
|
+
if Path(_text(review.get("runtime_event_log_path"))).resolve() != prior_event_path.resolve():
|
|
14891
|
+
raise APError("Prior Reviewer event log path is not canonical.")
|
|
14892
|
+
receipt = _validate_bound_review_runtime_receipt(
|
|
14893
|
+
control_repo,
|
|
14894
|
+
manifest,
|
|
14895
|
+
assignment,
|
|
14896
|
+
prior_receipt_path,
|
|
14897
|
+
"blocked",
|
|
14898
|
+
)
|
|
14899
|
+
attempts = receipt.get("attempts") or []
|
|
14900
|
+
if (
|
|
14901
|
+
int(receipt.get("schema") or 0) != 2
|
|
14902
|
+
or _text(receipt.get("verdict")) != "blocked"
|
|
14903
|
+
or receipt.get("exit_code") != 0
|
|
14904
|
+
or _text(receipt.get("failure_kind"))
|
|
14905
|
+
or len(attempts) != 1
|
|
14906
|
+
or _text(attempts[0].get("status")) != "completed"
|
|
14907
|
+
or attempts[0].get("exit_code") != 0
|
|
14908
|
+
):
|
|
14909
|
+
raise APError("Prior Reviewer receipt is not the exact completed procedural block eligible for retry.")
|
|
14910
|
+
try:
|
|
14911
|
+
result_payload = json.loads(_read_bounded_reviewer_output(prior_result_path))
|
|
14912
|
+
except (json.JSONDecodeError, UnicodeDecodeError) as exc:
|
|
14913
|
+
raise APError("Prior Reviewer result is invalid JSON.") from exc
|
|
14914
|
+
if not isinstance(result_payload, dict):
|
|
14915
|
+
raise APError("Prior Reviewer result must contain one JSON object.")
|
|
14916
|
+
normalized_result = _normalize_reviewer_runtime_result(assignment, result_payload)
|
|
14917
|
+
if result_payload != normalized_result or not _known_review_artifact_access_failure(
|
|
14918
|
+
control_repo,
|
|
14919
|
+
normalized_result,
|
|
14920
|
+
):
|
|
14921
|
+
raise APError(
|
|
14922
|
+
"Prior Reviewer result is not the exact non-substantive Git-local access failure."
|
|
14923
|
+
)
|
|
14367
14924
|
|
|
14925
|
+
token = f"retry-v{runtime_version}"
|
|
14926
|
+
audit_path = _review_runtime_retry_audit_path(
|
|
14927
|
+
control_repo,
|
|
14928
|
+
task_id,
|
|
14929
|
+
fingerprint,
|
|
14930
|
+
token,
|
|
14931
|
+
)
|
|
14932
|
+
retry_result_path, retry_receipt_path = _review_runtime_paths(
|
|
14933
|
+
control_repo,
|
|
14934
|
+
task_id,
|
|
14935
|
+
fingerprint,
|
|
14936
|
+
token,
|
|
14937
|
+
)
|
|
14938
|
+
retry_event_path = _review_runtime_event_log_path(
|
|
14939
|
+
control_repo,
|
|
14940
|
+
task_id,
|
|
14941
|
+
fingerprint,
|
|
14942
|
+
token,
|
|
14943
|
+
)
|
|
14944
|
+
for path in (audit_path, retry_result_path, retry_receipt_path, retry_event_path):
|
|
14945
|
+
if path.exists() or path.is_symlink():
|
|
14946
|
+
raise APError(f"Reviewer runtime retry evidence already exists: {path}")
|
|
14947
|
+
issued = _dt.datetime.now(_dt.timezone.utc).replace(microsecond=0)
|
|
14948
|
+
retry_timeout = int(assignment.get("timeout_seconds") or 0)
|
|
14949
|
+
if retry_timeout not in {_FOCUSED_REVIEW_TIMEOUT_SECONDS, _DEEP_REVIEW_TIMEOUT_SECONDS}:
|
|
14950
|
+
raise APError("Original Reviewer timeout is outside the fixed managed policy.")
|
|
14951
|
+
deadline = issued + _dt.timedelta(seconds=retry_timeout)
|
|
14952
|
+
audit = {
|
|
14953
|
+
"schema": 1,
|
|
14954
|
+
"reason_code": _REVIEW_RUNTIME_RETRY_REASON,
|
|
14955
|
+
"authorized_at": issued.isoformat(),
|
|
14956
|
+
"authorized_by": lifecycle_actor,
|
|
14957
|
+
"task_id": task_id,
|
|
14958
|
+
"task_uuid": _text(manifest.get("task_uuid")),
|
|
14959
|
+
"owner": lifecycle_actor,
|
|
14960
|
+
"reviewer": _text(review.get("reviewer")),
|
|
14961
|
+
"task_skill_version": task_version,
|
|
14962
|
+
"base_sha": _text(manifest.get("base_sha")),
|
|
14963
|
+
"diff_head": _text(assignment.get("diff_head")),
|
|
14964
|
+
"diff_fingerprint": fingerprint,
|
|
14965
|
+
"scope_revision": int(manifest.get("scope_revision") or 1),
|
|
14966
|
+
"owned_paths": list(manifest.get("owned_paths") or []),
|
|
14967
|
+
"retry_token": token,
|
|
14968
|
+
"retry_issued_at": issued.isoformat(),
|
|
14969
|
+
"retry_deadline_at": deadline.isoformat(),
|
|
14970
|
+
"retry_timeout_seconds": retry_timeout,
|
|
14971
|
+
"original_issued_at": _text(assignment.get("issued_at")),
|
|
14972
|
+
"original_deadline_at": _text(assignment.get("deadline_at")),
|
|
14973
|
+
"assignment_path": str(assignment_path),
|
|
14974
|
+
"assignment_sha256": _text(review.get("assignment_sha256")),
|
|
14975
|
+
"diff_artifact_path": _text(review.get("diff_artifact_path")),
|
|
14976
|
+
"diff_artifact_sha256": _text(review.get("diff_artifact_sha256")),
|
|
14977
|
+
"prior_result_path": str(prior_result_path),
|
|
14978
|
+
"prior_result_sha256": _private_review_file_sha256(prior_result_path, "prior result"),
|
|
14979
|
+
"prior_receipt_path": str(prior_receipt_path),
|
|
14980
|
+
"prior_receipt_sha256": _private_review_file_sha256(
|
|
14981
|
+
prior_receipt_path, "prior runtime receipt"
|
|
14982
|
+
),
|
|
14983
|
+
"prior_event_log_path": str(prior_event_path),
|
|
14984
|
+
"prior_event_log_sha256": _private_review_file_sha256(
|
|
14985
|
+
prior_event_path, "prior event log"
|
|
14986
|
+
),
|
|
14987
|
+
"prior_review_state_sha256": hashlib.sha256(
|
|
14988
|
+
json.dumps(review, ensure_ascii=False, sort_keys=True, separators=(",", ":")).encode(
|
|
14989
|
+
"utf-8"
|
|
14990
|
+
)
|
|
14991
|
+
).hexdigest(),
|
|
14992
|
+
"prior_verdict": "blocked",
|
|
14993
|
+
"prior_runtime_state": "blocked",
|
|
14994
|
+
"managed_runtime_version": runtime_version,
|
|
14995
|
+
"managed_runtime_script_path": identity["script_path"],
|
|
14996
|
+
"managed_runtime_script_sha256": identity["script_sha256"],
|
|
14997
|
+
"managed_runtime_manifest_path": identity["manifest_path"],
|
|
14998
|
+
"managed_runtime_manifest_sha256": identity["manifest_sha256"],
|
|
14999
|
+
"retry_result_path": str(retry_result_path),
|
|
15000
|
+
"retry_receipt_path": str(retry_receipt_path),
|
|
15001
|
+
"retry_event_log_path": str(retry_event_path),
|
|
15002
|
+
}
|
|
15003
|
+
_create_private_json(audit_path, audit, "runtime retry audit")
|
|
15004
|
+
audit_sha256 = _private_review_file_sha256(audit_path, "runtime retry audit")
|
|
15005
|
+
next_review = {
|
|
15006
|
+
key: value
|
|
15007
|
+
for key, value in review.items()
|
|
15008
|
+
if key not in _REVIEW_RUNTIME_FIELDS and key not in _REVIEW_RETRY_FIELDS
|
|
15009
|
+
}
|
|
15010
|
+
next_review.update(
|
|
15011
|
+
{
|
|
15012
|
+
"verdict": "pending",
|
|
15013
|
+
"reviewed_at": "",
|
|
15014
|
+
"reason": "bounded managed runtime retry authorized",
|
|
15015
|
+
"runtime_retry_token": token,
|
|
15016
|
+
"runtime_retry_version": runtime_version,
|
|
15017
|
+
"runtime_retry_reason_code": _REVIEW_RUNTIME_RETRY_REASON,
|
|
15018
|
+
"runtime_retry_audit_path": str(audit_path),
|
|
15019
|
+
"runtime_retry_audit_sha256": audit_sha256,
|
|
15020
|
+
}
|
|
15021
|
+
)
|
|
15022
|
+
manifest["review"] = next_review
|
|
15023
|
+
try:
|
|
15024
|
+
_save_task_manifest(control_repo, manifest, strict_worktree=True)
|
|
15025
|
+
except Exception:
|
|
15026
|
+
audit_path.unlink(missing_ok=True)
|
|
15027
|
+
raise
|
|
15028
|
+
_load_review_runtime_retry_audit(
|
|
15029
|
+
control_repo,
|
|
15030
|
+
manifest,
|
|
15031
|
+
assignment,
|
|
15032
|
+
require_same_runtime=True,
|
|
15033
|
+
)
|
|
15034
|
+
result = {
|
|
15035
|
+
"task_id": task_id,
|
|
15036
|
+
"status": "retry-authorized",
|
|
15037
|
+
"diff_fingerprint": fingerprint,
|
|
15038
|
+
"reviewer": _text(next_review.get("reviewer")),
|
|
15039
|
+
"retry_token": token,
|
|
15040
|
+
"retry_deadline_at": deadline.isoformat(),
|
|
15041
|
+
"audit_path": str(audit_path),
|
|
15042
|
+
"audit_sha256": audit_sha256,
|
|
15043
|
+
}
|
|
15044
|
+
if bool(getattr(args, "json", False)):
|
|
15045
|
+
print(json.dumps(result, ensure_ascii=False, indent=2))
|
|
15046
|
+
else:
|
|
15047
|
+
print(
|
|
15048
|
+
f"[review-runtime-retry] task={task_id} status=retry-authorized "
|
|
15049
|
+
f"fingerprint={fingerprint} token={token}"
|
|
15050
|
+
)
|
|
15051
|
+
print(f"[review-runtime-retry] deadline_at={deadline.isoformat()}")
|
|
15052
|
+
print(
|
|
15053
|
+
"[review-runtime-retry] next=review-run "
|
|
15054
|
+
f"{task_id} --reviewer {_text(next_review.get('reviewer'))}"
|
|
15055
|
+
)
|
|
15056
|
+
|
|
15057
|
+
|
|
15058
|
+
def cmd_review_run(args: argparse.Namespace) -> None:
|
|
15059
|
+
repo = Path(args.repo).resolve()
|
|
15060
|
+
ensure_git_repo(repo)
|
|
15061
|
+
cfg = _load_cfg(repo)
|
|
15062
|
+
task_id = _validate_task_id(args.task_id)
|
|
15063
|
+
reviewer = _text(args.reviewer)
|
|
14368
15064
|
control_repo, worktree, _ = _task_lifecycle_context(repo, cfg, task_id)
|
|
15065
|
+
initial_manifest = _load_task_manifest(control_repo, task_id)
|
|
15066
|
+
initial_review = initial_manifest.get("review") or {}
|
|
15067
|
+
if _review_attempt_token(initial_review):
|
|
15068
|
+
if reviewer != _text(initial_review.get("reviewer")):
|
|
15069
|
+
raise APError("Reviewer runtime retry must preserve the original Reviewer identity.")
|
|
15070
|
+
initial_assignment_path = Path(_text(initial_review.get("assignment_path"))).resolve()
|
|
15071
|
+
initial_assignment = _load_bound_review_assignment(
|
|
15072
|
+
control_repo,
|
|
15073
|
+
initial_manifest,
|
|
15074
|
+
initial_assignment_path,
|
|
15075
|
+
)
|
|
15076
|
+
_load_review_runtime_retry_audit(
|
|
15077
|
+
control_repo,
|
|
15078
|
+
initial_manifest,
|
|
15079
|
+
initial_assignment,
|
|
15080
|
+
require_same_runtime=True,
|
|
15081
|
+
)
|
|
15082
|
+
else:
|
|
15083
|
+
with contextlib.redirect_stdout(io.StringIO()):
|
|
15084
|
+
cmd_review_assignment(
|
|
15085
|
+
argparse.Namespace(
|
|
15086
|
+
repo=str(repo),
|
|
15087
|
+
task_id=task_id,
|
|
15088
|
+
reviewer=reviewer,
|
|
15089
|
+
json=False,
|
|
15090
|
+
)
|
|
15091
|
+
)
|
|
15092
|
+
|
|
14369
15093
|
manifest = _load_task_manifest(control_repo, task_id)
|
|
14370
15094
|
review = manifest.get("review") or {}
|
|
15095
|
+
attempt_token = _review_attempt_token(review)
|
|
14371
15096
|
assignment_path = Path(_text(review.get("assignment_path"))).resolve()
|
|
14372
15097
|
assignment = _load_bound_review_assignment(
|
|
14373
15098
|
control_repo,
|
|
@@ -14379,7 +15104,12 @@ def cmd_review_run(args: argparse.Namespace) -> None:
|
|
|
14379
15104
|
_validate_review_diff_artifact(control_repo, assignment)
|
|
14380
15105
|
if _task_review_fingerprint(worktree, manifest, _load_cfg(worktree)) != fingerprint:
|
|
14381
15106
|
raise APError("Review assignment is stale; the task-owned working tree changed before Reviewer start.")
|
|
14382
|
-
result_path, receipt_path = _review_runtime_paths(
|
|
15107
|
+
result_path, receipt_path = _review_runtime_paths(
|
|
15108
|
+
control_repo,
|
|
15109
|
+
task_id,
|
|
15110
|
+
fingerprint,
|
|
15111
|
+
attempt_token,
|
|
15112
|
+
)
|
|
14383
15113
|
|
|
14384
15114
|
command_override = _text(getattr(args, "runner_command_json", ""))
|
|
14385
15115
|
if command_override:
|
|
@@ -14409,7 +15139,12 @@ def cmd_review_run(args: argparse.Namespace) -> None:
|
|
|
14409
15139
|
command_sha256 = _review_command_sha256(command)
|
|
14410
15140
|
command_metadata = _reviewer_command_metadata(command, runner_kind)
|
|
14411
15141
|
started_at = _now_iso()
|
|
14412
|
-
event_log_path = _review_runtime_event_log_path(
|
|
15142
|
+
event_log_path = _review_runtime_event_log_path(
|
|
15143
|
+
control_repo,
|
|
15144
|
+
task_id,
|
|
15145
|
+
fingerprint,
|
|
15146
|
+
attempt_token,
|
|
15147
|
+
)
|
|
14413
15148
|
receipt = {
|
|
14414
15149
|
"schema": 2,
|
|
14415
15150
|
"task_id": task_id,
|
|
@@ -14431,6 +15166,24 @@ def cmd_review_run(args: argparse.Namespace) -> None:
|
|
|
14431
15166
|
"finished_at": "",
|
|
14432
15167
|
"exit_code": None,
|
|
14433
15168
|
}
|
|
15169
|
+
retry_audit = _load_review_runtime_retry_audit(
|
|
15170
|
+
control_repo,
|
|
15171
|
+
manifest,
|
|
15172
|
+
assignment,
|
|
15173
|
+
require_same_runtime=bool(attempt_token),
|
|
15174
|
+
)
|
|
15175
|
+
if retry_audit is not None:
|
|
15176
|
+
receipt.update(
|
|
15177
|
+
{
|
|
15178
|
+
"runtime_retry_token": attempt_token,
|
|
15179
|
+
"runtime_retry_audit_path": _text(review.get("runtime_retry_audit_path")),
|
|
15180
|
+
"runtime_retry_audit_sha256": _text(review.get("runtime_retry_audit_sha256")),
|
|
15181
|
+
"managed_runtime_version": _text(retry_audit.get("managed_runtime_version")),
|
|
15182
|
+
"managed_runtime_script_sha256": _text(
|
|
15183
|
+
retry_audit.get("managed_runtime_script_sha256")
|
|
15184
|
+
),
|
|
15185
|
+
}
|
|
15186
|
+
)
|
|
14434
15187
|
timeout_s = float(_concurrency_cfg(_load_cfg(control_repo)).get("lock_timeout_sec") or 30)
|
|
14435
15188
|
with _repo_lock(control_repo, f"task-{task_id}", timeout_s=timeout_s):
|
|
14436
15189
|
manifest = _load_task_manifest(control_repo, task_id)
|
|
@@ -14449,7 +15202,12 @@ def cmd_review_run(args: argparse.Namespace) -> None:
|
|
|
14449
15202
|
raise APError(
|
|
14450
15203
|
"The supervised Reviewer runtime has already started for this diff fingerprint."
|
|
14451
15204
|
)
|
|
14452
|
-
deadline =
|
|
15205
|
+
deadline = _effective_review_deadline(
|
|
15206
|
+
control_repo,
|
|
15207
|
+
manifest,
|
|
15208
|
+
assignment,
|
|
15209
|
+
require_same_runtime=bool(attempt_token),
|
|
15210
|
+
)
|
|
14453
15211
|
if _dt.datetime.now(_dt.timezone.utc) >= deadline:
|
|
14454
15212
|
raise APError("Review assignment deadline expired before Reviewer runtime start.")
|
|
14455
15213
|
if result_path.exists() or result_path.is_symlink():
|
|
@@ -14490,11 +15248,20 @@ def cmd_review_run(args: argparse.Namespace) -> None:
|
|
|
14490
15248
|
"AUTOCODING_REVIEW_DIFF_ARTIFACT": _text(assignment.get("diff_artifact_path")),
|
|
14491
15249
|
"AUTOCODING_REVIEW_DIFF_ARTIFACT_SHA256": _text(assignment.get("diff_artifact_sha256")),
|
|
14492
15250
|
"AUTOCODING_REVIEW_RESULT": str(result_path),
|
|
14493
|
-
"AUTOCODING_REVIEW_DEADLINE":
|
|
15251
|
+
"AUTOCODING_REVIEW_DEADLINE": deadline.isoformat(),
|
|
14494
15252
|
"AUTOCODING_REVIEW_TIMEOUT_SECONDS": str(int(assignment.get("timeout_seconds") or 0)),
|
|
14495
15253
|
}
|
|
14496
15254
|
)
|
|
14497
|
-
|
|
15255
|
+
if retry_audit is not None:
|
|
15256
|
+
env.update(
|
|
15257
|
+
{
|
|
15258
|
+
"AUTOCODING_REVIEW_RETRY_TOKEN": attempt_token,
|
|
15259
|
+
"AUTOCODING_REVIEW_RETRY_AUDIT": _text(review.get("runtime_retry_audit_path")),
|
|
15260
|
+
"AUTOCODING_REVIEW_RETRY_AUDIT_SHA256": _text(
|
|
15261
|
+
review.get("runtime_retry_audit_sha256")
|
|
15262
|
+
),
|
|
15263
|
+
}
|
|
15264
|
+
)
|
|
14498
15265
|
attempts: list[dict] = []
|
|
14499
15266
|
completed: Optional[subprocess.CompletedProcess[str]] = None
|
|
14500
15267
|
runtime_failure: Optional[_ReviewerRuntimeFailure] = None
|
|
@@ -14922,6 +15689,7 @@ def cmd_review_runtime_override(args: argparse.Namespace) -> None:
|
|
|
14922
15689
|
control_repo,
|
|
14923
15690
|
task_id,
|
|
14924
15691
|
fingerprint,
|
|
15692
|
+
_review_attempt_token(review),
|
|
14925
15693
|
)
|
|
14926
15694
|
if receipt_path != expected_receipt_path.resolve():
|
|
14927
15695
|
raise APError("Reviewer runtime receipt path is not canonical.")
|
|
@@ -15117,6 +15885,8 @@ def cmd_task_review(args: argparse.Namespace) -> None:
|
|
|
15117
15885
|
control_repo,
|
|
15118
15886
|
task_id,
|
|
15119
15887
|
fingerprint,
|
|
15888
|
+
_review_attempt_token(assigned_review),
|
|
15889
|
+
create=False,
|
|
15120
15890
|
)
|
|
15121
15891
|
result_path = Path(_text(assigned_review.get("runtime_result_path"))).resolve()
|
|
15122
15892
|
receipt_path = Path(_text(assigned_review.get("runtime_receipt_path"))).resolve()
|
|
@@ -15150,6 +15920,8 @@ def cmd_task_review(args: argparse.Namespace) -> None:
|
|
|
15150
15920
|
control_repo,
|
|
15151
15921
|
task_id,
|
|
15152
15922
|
fingerprint,
|
|
15923
|
+
_review_attempt_token(assigned_review),
|
|
15924
|
+
create=False,
|
|
15153
15925
|
).resolve()
|
|
15154
15926
|
if Path(_text(receipt.get("event_log_path"))).resolve() != expected_event_log_path:
|
|
15155
15927
|
raise APError("Reviewer runtime event log path is not canonical.")
|
|
@@ -15182,6 +15954,13 @@ def cmd_task_review(args: argparse.Namespace) -> None:
|
|
|
15182
15954
|
+ ", ".join(receipt_mismatches)
|
|
15183
15955
|
)
|
|
15184
15956
|
deadline_at = _text(assigned_review.get("deadline_at"))
|
|
15957
|
+
effective_deadline = (
|
|
15958
|
+
_effective_review_deadline(control_repo, manifest, assignment)
|
|
15959
|
+
if assignment is not None
|
|
15960
|
+
else _parse_iso_timestamp(deadline_at, "deadline_at")
|
|
15961
|
+
if deadline_at
|
|
15962
|
+
else None
|
|
15963
|
+
)
|
|
15185
15964
|
completed_at = _dt.datetime.now(_dt.timezone.utc)
|
|
15186
15965
|
if (
|
|
15187
15966
|
_text(assigned_review.get("runtime_state")) == "completed"
|
|
@@ -15191,7 +15970,7 @@ def cmd_task_review(args: argparse.Namespace) -> None:
|
|
|
15191
15970
|
assigned_review.get("runtime_finished_at"),
|
|
15192
15971
|
"runtime_finished_at",
|
|
15193
15972
|
)
|
|
15194
|
-
if
|
|
15973
|
+
if effective_deadline is not None and completed_at > effective_deadline:
|
|
15195
15974
|
raise APError(
|
|
15196
15975
|
"Review assignment deadline expired; the single review attempt is blocked."
|
|
15197
15976
|
)
|
|
@@ -15213,7 +15992,7 @@ def cmd_task_review(args: argparse.Namespace) -> None:
|
|
|
15213
15992
|
"review_depth": _text(manifest.get("review_depth")),
|
|
15214
15993
|
"review_timeout_seconds": int(manifest.get("review_timeout_seconds") or 0),
|
|
15215
15994
|
}
|
|
15216
|
-
for field in _REVIEW_RUNTIME_FIELDS:
|
|
15995
|
+
for field in _REVIEW_RUNTIME_FIELDS + _REVIEW_RETRY_FIELDS:
|
|
15217
15996
|
if field in assigned_review:
|
|
15218
15997
|
review_state[field] = assigned_review[field]
|
|
15219
15998
|
manifest["review"] = review_state
|
|
@@ -16519,6 +17298,17 @@ def main(argv: Optional[List[str]] = None) -> int:
|
|
|
16519
17298
|
s.add_argument("--runner-command-json", help=argparse.SUPPRESS)
|
|
16520
17299
|
s.set_defaults(func=cmd_review_run)
|
|
16521
17300
|
|
|
17301
|
+
s = sp.add_parser(
|
|
17302
|
+
"review-runtime-retry",
|
|
17303
|
+
help="Authorize one audited retry for the fixed 4.2.8-4.3.2 review-artifact access defect",
|
|
17304
|
+
)
|
|
17305
|
+
s.add_argument("task_id")
|
|
17306
|
+
s.add_argument("--diff-fingerprint", required=True)
|
|
17307
|
+
s.add_argument("--reason-code", required=True)
|
|
17308
|
+
s.add_argument("--confirm-managed-runtime-retry", action="store_true")
|
|
17309
|
+
s.add_argument("--json", action="store_true")
|
|
17310
|
+
s.set_defaults(func=cmd_review_runtime_retry)
|
|
17311
|
+
|
|
16522
17312
|
s = sp.add_parser(
|
|
16523
17313
|
"review-runtime-override",
|
|
16524
17314
|
help="Record an explicit user-authorized bypass for an exhausted Reviewer runtime failure",
|