@elvis1513/auto-coding-skill 4.3.2 → 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 +61 -1
- package/cli/assets/managed-install.json +1 -1
- package/cli/assets/skill/SKILL.md +7 -0
- package/cli/assets/skill/data/policies/feedback-resolutions-v1.json +48 -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 +931 -51
- package/cli/src/index.js +0 -12
- package/cli/tests/ap_concurrency_test.py +306 -9
- package/cli/tests/ap_profiles_test.py +108 -2
- package/cli/tests/core_shell_test.py +5 -5
- package/cli/tests/index.test.js +40 -34
- 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",
|
|
@@ -4895,9 +4907,19 @@ def _guard_review_directory(path: Path, common_dir: Path, *, create: bool) -> No
|
|
|
4895
4907
|
raise APError(f"Git-local review storage escapes the Git common directory: {path}") from exc
|
|
4896
4908
|
if os.name == "posix" and path.exists():
|
|
4897
4909
|
try:
|
|
4898
|
-
path.
|
|
4910
|
+
metadata = path.lstat()
|
|
4911
|
+
if metadata.st_uid != os.geteuid():
|
|
4912
|
+
raise APError(f"Git-local review storage must be owned by the current user: {path}")
|
|
4913
|
+
if create:
|
|
4914
|
+
path.chmod(0o700)
|
|
4915
|
+
metadata = path.lstat()
|
|
4916
|
+
if stat.S_IMODE(metadata.st_mode) != 0o700:
|
|
4917
|
+
raise APError(f"Git-local review storage must use mode 0700: {path}")
|
|
4918
|
+
except APError:
|
|
4919
|
+
raise
|
|
4899
4920
|
except OSError as exc:
|
|
4900
|
-
|
|
4921
|
+
action = "protect" if create else "verify"
|
|
4922
|
+
raise APError(f"Cannot {action} Git-local review storage: {path}: {exc}") from exc
|
|
4901
4923
|
|
|
4902
4924
|
|
|
4903
4925
|
def _task_review_root(repo: Path, *, create: bool = False) -> Path:
|
|
@@ -5801,6 +5823,8 @@ def _validate_review_runtime_override(repo: Path, manifest: dict, fingerprint: s
|
|
|
5801
5823
|
repo,
|
|
5802
5824
|
_text(manifest.get("task_id")),
|
|
5803
5825
|
fingerprint,
|
|
5826
|
+
_review_attempt_token(review),
|
|
5827
|
+
create=False,
|
|
5804
5828
|
)
|
|
5805
5829
|
del expected_result_path
|
|
5806
5830
|
if receipt_path != expected_receipt_path.resolve():
|
|
@@ -5865,6 +5889,15 @@ def _require_approved_review(repo: Path, cfg: dict, manifest: dict) -> str:
|
|
|
5865
5889
|
_validate_review_diff_artifact(repo, assignment)
|
|
5866
5890
|
if verdict == "runtime-bypassed":
|
|
5867
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
|
+
)
|
|
5868
5901
|
return fingerprint
|
|
5869
5902
|
|
|
5870
5903
|
|
|
@@ -5985,8 +6018,12 @@ def _require_task_context(repo: Path, cfg: dict, task_id: str) -> dict:
|
|
|
5985
6018
|
@contextlib.contextmanager
|
|
5986
6019
|
def _repo_lock(repo: Path, name: str, timeout_s: float = 30.0) -> Iterator[None]:
|
|
5987
6020
|
safe_name = re.sub(r"[^A-Za-z0-9._-]+", "-", name).strip("-") or "repository"
|
|
5988
|
-
|
|
5989
|
-
|
|
6021
|
+
common_dir = _git_common_dir(repo).resolve()
|
|
6022
|
+
state_root = common_dir / "auto-coding-skill"
|
|
6023
|
+
lock_root = state_root / "locks"
|
|
6024
|
+
_guard_review_directory(state_root, common_dir, create=True)
|
|
6025
|
+
_guard_review_directory(lock_root, common_dir, create=True)
|
|
6026
|
+
lock_path = lock_root / f"{safe_name}.lock"
|
|
5990
6027
|
handle = lock_path.open("a+", encoding="utf-8")
|
|
5991
6028
|
try:
|
|
5992
6029
|
try:
|
|
@@ -6153,6 +6190,7 @@ _SCOPE_RANK = {"changed": 0, "standard": 1, "full": 2}
|
|
|
6153
6190
|
_DOC_PATH_PATTERNS = ["*.md", "docs/**"]
|
|
6154
6191
|
_DEFAULT_FULL_PATH_PATTERNS = [
|
|
6155
6192
|
".agents/**",
|
|
6193
|
+
"AGENTS.md",
|
|
6156
6194
|
".github/workflows/**",
|
|
6157
6195
|
"Jenkinsfile",
|
|
6158
6196
|
"Jenkinsfile.*",
|
|
@@ -9047,7 +9085,24 @@ def _classify_paths(paths: list[str]) -> dict:
|
|
|
9047
9085
|
words = {word for word in re.split(r"[^a-z0-9]+", lower) if word}
|
|
9048
9086
|
if _path_matches(path, _DEFAULT_FULL_PATH_PATTERNS):
|
|
9049
9087
|
categories.add("release_or_tooling")
|
|
9050
|
-
|
|
9088
|
+
parts = [part for part in lower.replace("\\", "/").strip("/").split("/") if part]
|
|
9089
|
+
directories = set(parts[:-1])
|
|
9090
|
+
suffix = Path(lower).suffix
|
|
9091
|
+
semantic_path_words = words
|
|
9092
|
+
project_documentation_or_managed_skill = bool(directories & {".agents", "docs"})
|
|
9093
|
+
if (
|
|
9094
|
+
suffix in {".ddl", ".sql"}
|
|
9095
|
+
or directories & {"alembic", "flyway", "liquibase", "prisma"}
|
|
9096
|
+
or (
|
|
9097
|
+
semantic_path_words & {"database", "databases", "db", "schema", "schemas", "sql"}
|
|
9098
|
+
and not project_documentation_or_managed_skill
|
|
9099
|
+
)
|
|
9100
|
+
or (
|
|
9101
|
+
semantic_path_words & {"migration", "migrations"}
|
|
9102
|
+
and not project_documentation_or_managed_skill
|
|
9103
|
+
and "workflow" not in semantic_path_words
|
|
9104
|
+
)
|
|
9105
|
+
):
|
|
9051
9106
|
categories.add("db")
|
|
9052
9107
|
if any(token in lower for token in ["api", "controller", "handler", "route", "server"]):
|
|
9053
9108
|
categories.add("api")
|
|
@@ -9111,7 +9166,10 @@ def _classification_for_categories(categories: set[str], file_count: int) -> dic
|
|
|
9111
9166
|
def _classify_intent(intent: str) -> list[str]:
|
|
9112
9167
|
value = _text(intent).lower()
|
|
9113
9168
|
keyword_categories = {
|
|
9114
|
-
"db": [
|
|
9169
|
+
"db": [
|
|
9170
|
+
"database", "db migration", "data migration", "database migration",
|
|
9171
|
+
"database schema", "table schema", "sql", "数据库", "数据迁移", "表结构",
|
|
9172
|
+
],
|
|
9115
9173
|
"api": ["api", "controller", "endpoint", "接口", "控制器"],
|
|
9116
9174
|
"auth": ["auth", "permission", "security", "登录", "认证", "鉴权", "权限", "安全"],
|
|
9117
9175
|
"payment": ["payment", "billing", "checkout", "支付", "账单", "结算"],
|
|
@@ -9135,7 +9193,8 @@ def _high_confidence_intent_categories(intent: str) -> set[str]:
|
|
|
9135
9193
|
value = _text(intent).lower()
|
|
9136
9194
|
signals = {
|
|
9137
9195
|
"db": [
|
|
9138
|
-
"
|
|
9196
|
+
"database", "db migration", "data migration", "database migration",
|
|
9197
|
+
"database schema", "table schema", "ddl", "sql", "table structure",
|
|
9139
9198
|
"数据迁移", "数据库迁移", "表结构", "数据库结构",
|
|
9140
9199
|
],
|
|
9141
9200
|
"auth": [
|
|
@@ -9755,23 +9814,34 @@ def _codex_reviewer_command(
|
|
|
9755
9814
|
if depth not in {"focused", "deep"}:
|
|
9756
9815
|
raise APError(f"Unsupported Reviewer depth: {review_depth!r}")
|
|
9757
9816
|
reasoning_effort = "high" if depth == "focused" else "xhigh"
|
|
9817
|
+
runtime_python = os.path.abspath(sys.executable)
|
|
9818
|
+
runtime_script = Path(__file__).resolve()
|
|
9758
9819
|
artifact_command = shlex.join(
|
|
9759
9820
|
[
|
|
9760
|
-
|
|
9761
|
-
|
|
9821
|
+
runtime_python,
|
|
9822
|
+
str(runtime_script),
|
|
9762
9823
|
"review-artifact",
|
|
9763
9824
|
"--file",
|
|
9764
9825
|
str(assignment_path),
|
|
9765
9826
|
]
|
|
9766
9827
|
)
|
|
9828
|
+
template_command = shlex.join(
|
|
9829
|
+
[
|
|
9830
|
+
runtime_python,
|
|
9831
|
+
str(runtime_script),
|
|
9832
|
+
"agent-result-template",
|
|
9833
|
+
"--file",
|
|
9834
|
+
str(assignment_path),
|
|
9835
|
+
]
|
|
9836
|
+
)
|
|
9767
9837
|
prompt = (
|
|
9768
9838
|
f"Review the exact assignment at {assignment_path}. "
|
|
9769
9839
|
f"Before analysis, run `{artifact_command}`; it verifies diff_artifact_path, "
|
|
9770
9840
|
"mode 0600, and diff_artifact_sha256, then emits the immutable patch. "
|
|
9771
9841
|
"Review that emitted patch and never substitute a live git diff or diff_base..diff_head. "
|
|
9772
9842
|
"Stay inside its identity and deadline. Use "
|
|
9773
|
-
"`
|
|
9774
|
-
|
|
9843
|
+
f"`{template_command} --verdict approved` when useful, replacing `approved` "
|
|
9844
|
+
"with `changes-requested` or `blocked` when appropriate. "
|
|
9775
9845
|
"Return only one JSON object as the final response; do not modify files."
|
|
9776
9846
|
)
|
|
9777
9847
|
command = [
|
|
@@ -10515,7 +10585,7 @@ def _resolve_execution_plan(
|
|
|
10515
10585
|
detected_profile = "standard"
|
|
10516
10586
|
profile_reasons: list[str] = []
|
|
10517
10587
|
docs_only_paths = _docs_only(classification_inputs)
|
|
10518
|
-
docs_or_tests_only = bool(classification_inputs) and (
|
|
10588
|
+
docs_or_tests_only = "release_or_tooling" not in path_categories and bool(classification_inputs) and (
|
|
10519
10589
|
(docs_only_paths and str(impact["selected_scope"]) != "full")
|
|
10520
10590
|
or _tests_only(classification_inputs)
|
|
10521
10591
|
)
|
|
@@ -12870,6 +12940,11 @@ def cmd_task_start(args: argparse.Namespace) -> None:
|
|
|
12870
12940
|
"only when classify requires isolation/review or the user explicitly requests it."
|
|
12871
12941
|
)
|
|
12872
12942
|
|
|
12943
|
+
owner = _actor_id(args, "owner")
|
|
12944
|
+
runtime_actor = _text(os.environ.get("CODEX_THREAD_ID"))
|
|
12945
|
+
explicit_writer = _text(getattr(args, "writer", ""))
|
|
12946
|
+
writer = _actor_id(args, "writer") if runtime_actor or explicit_writer else owner
|
|
12947
|
+
|
|
12873
12948
|
configured_isolation = _task_isolation(cfg)
|
|
12874
12949
|
access_issues = _access_config_issues(cfg)
|
|
12875
12950
|
if access_issues:
|
|
@@ -12933,10 +13008,6 @@ def cmd_task_start(args: argparse.Namespace) -> None:
|
|
|
12933
13008
|
"prerequisite_shas": prerequisite_shas,
|
|
12934
13009
|
}
|
|
12935
13010
|
_require_dependencies(repo, dependency_contract, base_sha)
|
|
12936
|
-
owner = _text(getattr(args, "owner", "")) or _text(os.environ.get("CODEX_THREAD_ID"))
|
|
12937
|
-
if not owner:
|
|
12938
|
-
raise APError("task-start requires --owner or CODEX_THREAD_ID.")
|
|
12939
|
-
writer = _text(getattr(args, "writer", "")) or owner
|
|
12940
13011
|
plan = _resolve_execution_plan(
|
|
12941
13012
|
cfg,
|
|
12942
13013
|
repo,
|
|
@@ -13194,12 +13265,27 @@ def _task_status_payload(repo: Path, manifest: dict) -> dict:
|
|
|
13194
13265
|
)
|
|
13195
13266
|
review = manifest.get("review") or {}
|
|
13196
13267
|
deadline_at = _text(review.get("deadline_at"))
|
|
13268
|
+
effective_deadline_at = deadline_at
|
|
13197
13269
|
review_seconds_remaining: Optional[int] = None
|
|
13198
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 = ""
|
|
13199
13285
|
if deadline_at:
|
|
13200
13286
|
try:
|
|
13201
13287
|
remaining = (
|
|
13202
|
-
_parse_iso_timestamp(
|
|
13288
|
+
_parse_iso_timestamp(effective_deadline_at, "effective_deadline_at")
|
|
13203
13289
|
- _dt.datetime.now(_dt.timezone.utc)
|
|
13204
13290
|
).total_seconds()
|
|
13205
13291
|
seconds = int(remaining)
|
|
@@ -13216,6 +13302,7 @@ def _task_status_payload(repo: Path, manifest: dict) -> dict:
|
|
|
13216
13302
|
"tip": tip,
|
|
13217
13303
|
"has_task_commits": has_task_commits,
|
|
13218
13304
|
"merged_into_target": merged,
|
|
13305
|
+
"review_effective_deadline_at": effective_deadline_at,
|
|
13219
13306
|
"review_deadline_expired": review_deadline_expired,
|
|
13220
13307
|
"review_seconds_remaining": review_seconds_remaining,
|
|
13221
13308
|
"current_diff_fingerprint": _task_review_fingerprint(worktree, manifest)
|
|
@@ -13447,10 +13534,30 @@ def _parse_iso_timestamp(value: object, field: str) -> _dt.datetime:
|
|
|
13447
13534
|
return parsed.astimezone(_dt.timezone.utc)
|
|
13448
13535
|
|
|
13449
13536
|
|
|
13450
|
-
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:
|
|
13451
13546
|
if not _REVIEW_SHA256_RE.fullmatch(_text(fingerprint)):
|
|
13452
13547
|
raise APError("Review fingerprint must be a lowercase SHA-256 value.")
|
|
13453
|
-
|
|
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"
|
|
13454
13561
|
|
|
13455
13562
|
|
|
13456
13563
|
def _review_diff_artifact_path(control_repo: Path, task_id: str, fingerprint: str) -> Path:
|
|
@@ -13763,8 +13870,16 @@ def cmd_review_assignment(args: argparse.Namespace) -> None:
|
|
|
13763
13870
|
"scope_revision": int(manifest.get("scope_revision") or 1),
|
|
13764
13871
|
}
|
|
13765
13872
|
_validate_orchestration_contract("assignment", assignment)
|
|
13766
|
-
assignment_path = _review_assignment_path(control_repo, task_id, fingerprint)
|
|
13767
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
|
+
)
|
|
13768
13883
|
if (
|
|
13769
13884
|
_text(prior_review.get("diff_fingerprint")) == fingerprint
|
|
13770
13885
|
and (
|
|
@@ -13914,7 +14029,7 @@ def cmd_review_assignment(args: argparse.Namespace) -> None:
|
|
|
13914
14029
|
"deadline_at": assignment["deadline_at"],
|
|
13915
14030
|
}
|
|
13916
14031
|
if _text(prior_review.get("diff_fingerprint")) == fingerprint:
|
|
13917
|
-
for field in _REVIEW_RUNTIME_FIELDS:
|
|
14032
|
+
for field in _REVIEW_RUNTIME_FIELDS + _REVIEW_RETRY_FIELDS:
|
|
13918
14033
|
if field in prior_review:
|
|
13919
14034
|
review_state[field] = prior_review[field]
|
|
13920
14035
|
manifest["review"] = review_state
|
|
@@ -13945,10 +14060,14 @@ def cmd_review_artifact(args: argparse.Namespace) -> None:
|
|
|
13945
14060
|
raise APError(
|
|
13946
14061
|
f"Review artifact must be read from its assigned worktree: expected={assigned_worktree}, current={repo}."
|
|
13947
14062
|
)
|
|
13948
|
-
|
|
13949
|
-
|
|
13950
|
-
|
|
13951
|
-
|
|
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:
|
|
13952
14071
|
raise APError("Review assignment deadline expired before diff artifact access.")
|
|
13953
14072
|
payload = _validate_review_diff_artifact(repo, assignment)
|
|
13954
14073
|
sys.stdout.flush()
|
|
@@ -13963,26 +14082,61 @@ def _write_private_json(path: Path, payload: dict) -> None:
|
|
|
13963
14082
|
_write_private_bytes(path, encoded)
|
|
13964
14083
|
|
|
13965
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
|
+
|
|
13966
14103
|
def _review_runtime_paths(
|
|
13967
14104
|
control_repo: Path,
|
|
13968
14105
|
task_id: str,
|
|
13969
14106
|
fingerprint: str,
|
|
14107
|
+
attempt_token: str = "",
|
|
14108
|
+
*,
|
|
14109
|
+
create: bool = True,
|
|
13970
14110
|
) -> tuple[Path, Path]:
|
|
13971
|
-
|
|
13972
|
-
|
|
13973
|
-
root
|
|
13974
|
-
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"
|
|
13975
14114
|
|
|
13976
14115
|
|
|
13977
14116
|
def _review_runtime_event_log_path(
|
|
13978
14117
|
control_repo: Path,
|
|
13979
14118
|
task_id: str,
|
|
13980
14119
|
fingerprint: str,
|
|
14120
|
+
attempt_token: str = "",
|
|
14121
|
+
*,
|
|
14122
|
+
create: bool = True,
|
|
13981
14123
|
) -> Path:
|
|
13982
|
-
|
|
13983
|
-
|
|
13984
|
-
root
|
|
13985
|
-
|
|
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"
|
|
13986
14140
|
|
|
13987
14141
|
|
|
13988
14142
|
def _review_runtime_override_path(
|
|
@@ -14013,6 +14167,260 @@ def _private_review_file_sha256(path: Path, label: str) -> str:
|
|
|
14013
14167
|
return hashlib.sha256(payload).hexdigest()
|
|
14014
14168
|
|
|
14015
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
|
+
|
|
14016
14424
|
def _reviewer_cli_version(command: list[str], runner_kind: str) -> str:
|
|
14017
14425
|
if runner_kind != "codex" or not command:
|
|
14018
14426
|
return "test-override"
|
|
@@ -14209,6 +14617,15 @@ def _update_review_runtime(
|
|
|
14209
14617
|
review = dict(manifest.get("review") or {})
|
|
14210
14618
|
if _text(review.get("diff_fingerprint")) != fingerprint:
|
|
14211
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.")
|
|
14212
14629
|
review.update(updates)
|
|
14213
14630
|
manifest["review"] = review
|
|
14214
14631
|
receipt = _read_json_object(receipt_path) or {}
|
|
@@ -14241,6 +14658,8 @@ def _validate_bound_review_runtime_receipt(
|
|
|
14241
14658
|
control_repo,
|
|
14242
14659
|
task_id,
|
|
14243
14660
|
fingerprint,
|
|
14661
|
+
_review_attempt_token(review),
|
|
14662
|
+
create=False,
|
|
14244
14663
|
)
|
|
14245
14664
|
if receipt_path.resolve() != expected_receipt_path.resolve():
|
|
14246
14665
|
raise APError("Reviewer runtime receipt path is not canonical.")
|
|
@@ -14263,11 +14682,35 @@ def _validate_bound_review_runtime_receipt(
|
|
|
14263
14682
|
"result_path": str(expected_result_path),
|
|
14264
14683
|
"command_sha256": _text(review.get("runtime_command_sha256")),
|
|
14265
14684
|
"event_log_path": str(
|
|
14266
|
-
_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
|
+
)
|
|
14267
14692
|
),
|
|
14268
14693
|
"status": expected_status,
|
|
14269
14694
|
}
|
|
14270
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
|
+
)
|
|
14271
14714
|
if mismatched:
|
|
14272
14715
|
raise APError(
|
|
14273
14716
|
"Reviewer runtime receipt does not match task state: " + ", ".join(mismatched)
|
|
@@ -14301,25 +14744,355 @@ def _blocked_reviewer_runtime_result(
|
|
|
14301
14744
|
return _validate_orchestration_contract("result", result)
|
|
14302
14745
|
|
|
14303
14746
|
|
|
14304
|
-
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:
|
|
14305
14793
|
repo = Path(args.repo).resolve()
|
|
14306
14794
|
ensure_git_repo(repo)
|
|
14307
14795
|
cfg = _load_cfg(repo)
|
|
14308
14796
|
task_id = _validate_task_id(args.task_id)
|
|
14309
|
-
|
|
14310
|
-
|
|
14311
|
-
|
|
14312
|
-
|
|
14313
|
-
|
|
14314
|
-
|
|
14315
|
-
|
|
14316
|
-
|
|
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}."
|
|
14317
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)
|
|
14873
|
+
)
|
|
14874
|
+
prior_result_path, prior_receipt_path = _review_runtime_paths(
|
|
14875
|
+
control_repo,
|
|
14876
|
+
task_id,
|
|
14877
|
+
fingerprint,
|
|
14878
|
+
create=False,
|
|
14318
14879
|
)
|
|
14880
|
+
prior_event_path = _review_runtime_event_log_path(
|
|
14881
|
+
control_repo,
|
|
14882
|
+
task_id,
|
|
14883
|
+
fingerprint,
|
|
14884
|
+
create=False,
|
|
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
|
+
)
|
|
14319
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)
|
|
14320
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
|
+
|
|
14321
15093
|
manifest = _load_task_manifest(control_repo, task_id)
|
|
14322
15094
|
review = manifest.get("review") or {}
|
|
15095
|
+
attempt_token = _review_attempt_token(review)
|
|
14323
15096
|
assignment_path = Path(_text(review.get("assignment_path"))).resolve()
|
|
14324
15097
|
assignment = _load_bound_review_assignment(
|
|
14325
15098
|
control_repo,
|
|
@@ -14331,7 +15104,12 @@ def cmd_review_run(args: argparse.Namespace) -> None:
|
|
|
14331
15104
|
_validate_review_diff_artifact(control_repo, assignment)
|
|
14332
15105
|
if _task_review_fingerprint(worktree, manifest, _load_cfg(worktree)) != fingerprint:
|
|
14333
15106
|
raise APError("Review assignment is stale; the task-owned working tree changed before Reviewer start.")
|
|
14334
|
-
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
|
+
)
|
|
14335
15113
|
|
|
14336
15114
|
command_override = _text(getattr(args, "runner_command_json", ""))
|
|
14337
15115
|
if command_override:
|
|
@@ -14361,7 +15139,12 @@ def cmd_review_run(args: argparse.Namespace) -> None:
|
|
|
14361
15139
|
command_sha256 = _review_command_sha256(command)
|
|
14362
15140
|
command_metadata = _reviewer_command_metadata(command, runner_kind)
|
|
14363
15141
|
started_at = _now_iso()
|
|
14364
|
-
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
|
+
)
|
|
14365
15148
|
receipt = {
|
|
14366
15149
|
"schema": 2,
|
|
14367
15150
|
"task_id": task_id,
|
|
@@ -14383,6 +15166,24 @@ def cmd_review_run(args: argparse.Namespace) -> None:
|
|
|
14383
15166
|
"finished_at": "",
|
|
14384
15167
|
"exit_code": None,
|
|
14385
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
|
+
)
|
|
14386
15187
|
timeout_s = float(_concurrency_cfg(_load_cfg(control_repo)).get("lock_timeout_sec") or 30)
|
|
14387
15188
|
with _repo_lock(control_repo, f"task-{task_id}", timeout_s=timeout_s):
|
|
14388
15189
|
manifest = _load_task_manifest(control_repo, task_id)
|
|
@@ -14401,7 +15202,12 @@ def cmd_review_run(args: argparse.Namespace) -> None:
|
|
|
14401
15202
|
raise APError(
|
|
14402
15203
|
"The supervised Reviewer runtime has already started for this diff fingerprint."
|
|
14403
15204
|
)
|
|
14404
|
-
deadline =
|
|
15205
|
+
deadline = _effective_review_deadline(
|
|
15206
|
+
control_repo,
|
|
15207
|
+
manifest,
|
|
15208
|
+
assignment,
|
|
15209
|
+
require_same_runtime=bool(attempt_token),
|
|
15210
|
+
)
|
|
14405
15211
|
if _dt.datetime.now(_dt.timezone.utc) >= deadline:
|
|
14406
15212
|
raise APError("Review assignment deadline expired before Reviewer runtime start.")
|
|
14407
15213
|
if result_path.exists() or result_path.is_symlink():
|
|
@@ -14442,11 +15248,20 @@ def cmd_review_run(args: argparse.Namespace) -> None:
|
|
|
14442
15248
|
"AUTOCODING_REVIEW_DIFF_ARTIFACT": _text(assignment.get("diff_artifact_path")),
|
|
14443
15249
|
"AUTOCODING_REVIEW_DIFF_ARTIFACT_SHA256": _text(assignment.get("diff_artifact_sha256")),
|
|
14444
15250
|
"AUTOCODING_REVIEW_RESULT": str(result_path),
|
|
14445
|
-
"AUTOCODING_REVIEW_DEADLINE":
|
|
15251
|
+
"AUTOCODING_REVIEW_DEADLINE": deadline.isoformat(),
|
|
14446
15252
|
"AUTOCODING_REVIEW_TIMEOUT_SECONDS": str(int(assignment.get("timeout_seconds") or 0)),
|
|
14447
15253
|
}
|
|
14448
15254
|
)
|
|
14449
|
-
|
|
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
|
+
)
|
|
14450
15265
|
attempts: list[dict] = []
|
|
14451
15266
|
completed: Optional[subprocess.CompletedProcess[str]] = None
|
|
14452
15267
|
runtime_failure: Optional[_ReviewerRuntimeFailure] = None
|
|
@@ -14655,6 +15470,48 @@ def cmd_review_run(args: argparse.Namespace) -> None:
|
|
|
14655
15470
|
raise APError("Reviewer runtime ended without a process result.")
|
|
14656
15471
|
finished_at = _now_iso()
|
|
14657
15472
|
if completed.returncode != 0:
|
|
15473
|
+
substantive_result = _substantive_reviewer_result(result_path, assignment)
|
|
15474
|
+
if substantive_result is None:
|
|
15475
|
+
try:
|
|
15476
|
+
substantive_result = _substantive_reviewer_event_result(
|
|
15477
|
+
_bounded_reviewer_output(completed.stdout, "stdout"),
|
|
15478
|
+
assignment,
|
|
15479
|
+
)
|
|
15480
|
+
except APError:
|
|
15481
|
+
substantive_result = None
|
|
15482
|
+
if substantive_result is not None:
|
|
15483
|
+
_write_private_json(result_path, substantive_result)
|
|
15484
|
+
result_sha256 = _review_result_file_sha256(result_path)
|
|
15485
|
+
_update_review_runtime(
|
|
15486
|
+
control_repo,
|
|
15487
|
+
task_id,
|
|
15488
|
+
fingerprint,
|
|
15489
|
+
updates={
|
|
15490
|
+
"verdict": substantive_result["verdict"],
|
|
15491
|
+
"reason": "substantive Reviewer result observed before nonzero process exit",
|
|
15492
|
+
"runtime_state": "blocked",
|
|
15493
|
+
"runtime_finished_at": finished_at,
|
|
15494
|
+
"runtime_exit_code": completed.returncode,
|
|
15495
|
+
"runtime_attempt_count": len(attempts),
|
|
15496
|
+
"runtime_failure_kind": "process-exit",
|
|
15497
|
+
},
|
|
15498
|
+
receipt_path=receipt_path,
|
|
15499
|
+
receipt_updates={
|
|
15500
|
+
"status": "blocked",
|
|
15501
|
+
"finished_at": finished_at,
|
|
15502
|
+
"exit_code": completed.returncode,
|
|
15503
|
+
"verdict": substantive_result["verdict"],
|
|
15504
|
+
"attempts": attempts,
|
|
15505
|
+
"failure_kind": "process-exit",
|
|
15506
|
+
"event_log_sha256": event_log_sha256,
|
|
15507
|
+
"result_sha256": result_sha256,
|
|
15508
|
+
},
|
|
15509
|
+
)
|
|
15510
|
+
print(json.dumps(substantive_result, ensure_ascii=False, indent=2))
|
|
15511
|
+
raise APError(
|
|
15512
|
+
"Reviewer produced a substantive result before nonzero process exit; "
|
|
15513
|
+
"it cannot be bypassed."
|
|
15514
|
+
)
|
|
14658
15515
|
result = _blocked_reviewer_runtime_result(
|
|
14659
15516
|
assignment,
|
|
14660
15517
|
"Reviewer runtime exited unsuccessfully.",
|
|
@@ -14832,6 +15689,7 @@ def cmd_review_runtime_override(args: argparse.Namespace) -> None:
|
|
|
14832
15689
|
control_repo,
|
|
14833
15690
|
task_id,
|
|
14834
15691
|
fingerprint,
|
|
15692
|
+
_review_attempt_token(review),
|
|
14835
15693
|
)
|
|
14836
15694
|
if receipt_path != expected_receipt_path.resolve():
|
|
14837
15695
|
raise APError("Reviewer runtime receipt path is not canonical.")
|
|
@@ -15027,6 +15885,8 @@ def cmd_task_review(args: argparse.Namespace) -> None:
|
|
|
15027
15885
|
control_repo,
|
|
15028
15886
|
task_id,
|
|
15029
15887
|
fingerprint,
|
|
15888
|
+
_review_attempt_token(assigned_review),
|
|
15889
|
+
create=False,
|
|
15030
15890
|
)
|
|
15031
15891
|
result_path = Path(_text(assigned_review.get("runtime_result_path"))).resolve()
|
|
15032
15892
|
receipt_path = Path(_text(assigned_review.get("runtime_receipt_path"))).resolve()
|
|
@@ -15060,6 +15920,8 @@ def cmd_task_review(args: argparse.Namespace) -> None:
|
|
|
15060
15920
|
control_repo,
|
|
15061
15921
|
task_id,
|
|
15062
15922
|
fingerprint,
|
|
15923
|
+
_review_attempt_token(assigned_review),
|
|
15924
|
+
create=False,
|
|
15063
15925
|
).resolve()
|
|
15064
15926
|
if Path(_text(receipt.get("event_log_path"))).resolve() != expected_event_log_path:
|
|
15065
15927
|
raise APError("Reviewer runtime event log path is not canonical.")
|
|
@@ -15092,6 +15954,13 @@ def cmd_task_review(args: argparse.Namespace) -> None:
|
|
|
15092
15954
|
+ ", ".join(receipt_mismatches)
|
|
15093
15955
|
)
|
|
15094
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
|
+
)
|
|
15095
15964
|
completed_at = _dt.datetime.now(_dt.timezone.utc)
|
|
15096
15965
|
if (
|
|
15097
15966
|
_text(assigned_review.get("runtime_state")) == "completed"
|
|
@@ -15101,7 +15970,7 @@ def cmd_task_review(args: argparse.Namespace) -> None:
|
|
|
15101
15970
|
assigned_review.get("runtime_finished_at"),
|
|
15102
15971
|
"runtime_finished_at",
|
|
15103
15972
|
)
|
|
15104
|
-
if
|
|
15973
|
+
if effective_deadline is not None and completed_at > effective_deadline:
|
|
15105
15974
|
raise APError(
|
|
15106
15975
|
"Review assignment deadline expired; the single review attempt is blocked."
|
|
15107
15976
|
)
|
|
@@ -15123,7 +15992,7 @@ def cmd_task_review(args: argparse.Namespace) -> None:
|
|
|
15123
15992
|
"review_depth": _text(manifest.get("review_depth")),
|
|
15124
15993
|
"review_timeout_seconds": int(manifest.get("review_timeout_seconds") or 0),
|
|
15125
15994
|
}
|
|
15126
|
-
for field in _REVIEW_RUNTIME_FIELDS:
|
|
15995
|
+
for field in _REVIEW_RUNTIME_FIELDS + _REVIEW_RETRY_FIELDS:
|
|
15127
15996
|
if field in assigned_review:
|
|
15128
15997
|
review_state[field] = assigned_review[field]
|
|
15129
15998
|
manifest["review"] = review_state
|
|
@@ -16429,6 +17298,17 @@ def main(argv: Optional[List[str]] = None) -> int:
|
|
|
16429
17298
|
s.add_argument("--runner-command-json", help=argparse.SUPPRESS)
|
|
16430
17299
|
s.set_defaults(func=cmd_review_run)
|
|
16431
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
|
+
|
|
16432
17312
|
s = sp.add_parser(
|
|
16433
17313
|
"review-runtime-override",
|
|
16434
17314
|
help="Record an explicit user-authorized bypass for an exhausted Reviewer runtime failure",
|