PR Helper Contract¶
Applies to PR review and PR remediation; read before PR preparation as required by Helper CLI Contract. The common helper contract still governs creation, historical sources, completion, and re-entry.
A PR review uses its already resolved entry identity in the initial run name. After successful authoritative pr.json collection, invoke PLUGIN_ROOT/bin/python PLUGIN_ROOT/shared/create_run.py --skill code-review --promote-pr-run <run-directory>, capture single printed final path, use that literal .reports/codex/code-review/pr-<number>/run-<NNN>/ path for every remaining operation. Promotion derives PR number from collected artifact, rejects any disagreement with an initial PR-named run before moving or allocating its destination, exclusively claims the next numeric run index before moving the whole directory; interrupted claims reserve a gap rather than being reclaimed; callers never construct either value. A pre-identity collection failure stays in its timestamped unavailable-diagnostic path, never assessed PR review. PR-targeted remediation uses the same sequence under .reports/codex/code-remediate/pr-<number>/run-<NNN>/: after successful collection into <run-directory>/pr, invoke PLUGIN_ROOT/bin/python PLUGIN_ROOT/shared/create_run.py --skill code-remediate --promote-pr-run <run-directory>. Promotion reads pr/pr.json; capture its printed path before writing branch, selection, dispatch or result bindings.
PR review additionally passes --worktree <absolute verified checkout root> to execute checks there and bind that path in source receipts; this option requires --expected-head. Python PR test gates use --pytest-python <absolute interpreter>, one or more --pytest-import <module>, and --pytest-args-json <JSON string array> instead of free-form --tests: the selected interpreter runs pytest in process and records post-test imported module origins; missing, untracked, or outside-worktree origins cannot pass. For xdist, per-worker receipts bind selected tests and imported modules; missing receipts, crashed workers or wrong source origins fail closed. Imports performed only in unobserved test subprocesses remain inconclusive.
From the verified remediation checkout, run PLUGIN_ROOT/bin/python PLUGIN_ROOT/shared/collect_pr.py --target <canonical PR URL> --out <run-directory>/pr --refresh-integration-target before preparing a new target merge. Both initial collection and a later refresh fetch the exact selected base repository URL and verify that Git’s URL rewrite still addresses that repository, including when a named remote has multiple URLs. Refresh observes the live refs/heads/<base>, verifies the commit, and adopts only a fast-forward from the current capture. It archives the previous bytes at pr/target-branch.<previous-oid>.json before replacing pr/target-branch.json. Recompute the merge base, intent and target diffs, merge-tree, collision strategy and ancestry decision when the captured OID changes.
Use --check-integration-target in place of --refresh-integration-target immediately before the merge decision, after a wait, and from the verified delivery checkout at the delivery gates. It fetches missing or advanced objects without changing receipts or local branch or tracking refs. Both forms print a JSON object with status (unchanged or advanced), pr_url, base_ref, previous_target_oid and the verified live target_oid. A nonzero exit supplies no target for integration. On integration-target-moved-during-fetch, repeat the live check and refresh affected evidence. On divergence or contradictory retained coordinates, collect current PR identity and base evidence separately, preserve the old evidence, and reconcile the histories and any revised scope before proceeding. Keep the original target and merge receipt for an in-progress or completed integration. An exact-OID approval uses observation only and requires new authority when its target changes.