Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ latest_status() {
# This proves ownership, not original source success. Old base SHA and failed or
# cancelled publisher steps identify provenance only and cannot grant proof.
native_identity() {
local run_id="$1" attempt="$2" current="$3" run title title_base jobs check check_id
local run_id="$1" attempt="$2" current="$3" require_current_base="${4:-false}" run title title_base jobs check check_id
if [[ "${current}" == true ]]; then
run="$(gh api --method GET "${api_root}/actions/runs/${run_id}")" || return 1
else
Expand All @@ -84,7 +84,7 @@ native_identity() {
title_base="$(jq -ern --arg title "${title}" --arg name "${workflow_name}" --arg pr "${PR_NUMBER}" --arg head "${HEAD_SHA}" '
$title | capture("^(?<name>.*) pr-(?<pr>[1-9][0-9]*) base-(?<base>[0-9A-Fa-f]{40}) head-(?<head>[0-9A-Fa-f]{40})$")
| select(.name == $name and .pr == $pr and .head == $head) | .base')" || return 1
[[ "${current}" != true || "${title_base}" == "${BASE_SHA}" ]] || return 1
[[ "${current}" != true && "${require_current_base}" != true || "${title_base}" == "${BASE_SHA}" ]] || return 1
jq -e --argjson id "${run_id}" --argjson attempt "${attempt}" --argjson workflow "${workflow_id}" \
--arg repo "${GITHUB_REPOSITORY}" --arg head_repo "${head_repository}" --arg branch "${head_branch}" \
--arg head "${HEAD_SHA}" --arg title "${title}" --arg name "${workflow_name}" --arg path "${EXPECTED_WORKFLOW_PATH}" \
Expand Down Expand Up @@ -128,16 +128,29 @@ native_identity() {
.head_sha == $head and .status == $job.status and .conclusion == $job.conclusion' <<<"${check}" >/dev/null
}
owned_status() {
local suffix run_id attempt
local status="$1" require_current_base="${2:-false}" suffix run_id attempt
jq -e --arg url "${api_url}/statuses/${HEAD_SHA}" '
.creator.id == 41898282 and .creator.login == "github-actions[bot]" and .creator.type == "Bot" and
.url == $url and (.state == "pending" or .state == "success" or .state == "failure" or .state == "error")' <<<"$1" >/dev/null || return 1
suffix="$(jq -er '.target_url' <<<"$1")" || return 1
.url == $url and (.state == "pending" or .state == "success" or .state == "failure" or .state == "error")' <<<"${status}" >/dev/null || return 1
suffix="$(jq -er '.target_url' <<<"${status}")" || return 1
[[ "${suffix}" == "${run_url}"* ]] || return 1
suffix="${suffix#"${run_url}"}"
[[ "${suffix}" =~ ^([1-9][0-9]*)/attempts/([1-9][0-9]*)$ ]] || return 1
run_id="${BASH_REMATCH[1]}"; attempt="${BASH_REMATCH[2]}"
native_identity "${run_id}" "${attempt}" false
native_identity "${run_id}" "${attempt}" false "${require_current_base}"
}
acknowledge_existing_pending() {
local status="$1" fresh
[[ "$(jq -r '.state' <<<"${status}")" == pending ]] || return 1
owned_status "${status}" true || return 1
native_identity "${GITHUB_RUN_ID}" "${GITHUB_RUN_ATTEMPT}" true ||
fail_closed "Current metadata native gate is not attributable."
pr="$(current_pr)"
pr_matches "${pr}" || unchanged
fresh="$(latest_status)" || fail_closed "Latest context became unavailable."
[[ "${fresh}" == "${status}" ]] || unchanged
report pending-acknowledged
exit 0
}
pr="$(current_pr)"
pr_matches "${pr}" || unchanged
Expand All @@ -159,7 +172,10 @@ jq -e --arg title "${current_title}" --argjson id "${GITHUB_RUN_ID}" --argjson a
current_run_number="$(jq -er '.run_number' <<<"${run}")"
latest="$(latest_status)" || fail_closed "Latest context is incomplete or ambiguous."
owned=false
if [[ "${latest}" != null ]] && owned_status "${latest}"; then owned=true; fi
if [[ "${latest}" != null ]]; then
if [[ "${ASSESSMENT}" == dependency-deferred ]] && acknowledge_existing_pending "${latest}"; then :; fi
if owned_status "${latest}"; then owned=true; fi
fi
if [[ "${ASSESSMENT}" == success ]]; then
if [[ "${owned}" != true || "$(jq -r '.state' <<<"${latest}")" == success ]]; then unchanged; fi
assessment_output="$(mktemp)"
Expand All @@ -177,7 +193,10 @@ native_identity "${GITHUB_RUN_ID}" "${GITHUB_RUN_ATTEMPT}" true || fail_closed "
pr="$(current_pr)"
pr_matches "${pr}" || unchanged
fresh="$(latest_status)" || fail_closed "Latest context became unavailable."
[[ "${fresh}" == "${latest}" ]] || unchanged
if [[ "${fresh}" != "${latest}" ]]; then
if [[ "${ASSESSMENT}" == dependency-deferred ]] && acknowledge_existing_pending "${fresh}"; then :; fi
unchanged
fi
# One POST, no retry. Its native REST shape has creator and URL, not sha/app_id.
ack="$(gh api --method POST "${api_root}/statuses/${HEAD_SHA}" -f state="${state}" -f context="${gate_name}" \
-f target_url="${current_target}" -f description="Metadata gate original proof: ${state}")" ||
Expand Down
2 changes: 1 addition & 1 deletion design/architecture/system-architecture-cicd.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ All five metadata gate producers call the shared publisher after canonical prese

The existing substantive and metadata completion callbacks reconcile both completion orders, including a pending status published after original proof has already completed. The existing trusted resolve job holds `statuses: write` for supplementary reconciliation; producer gate jobs hold it only for the shared metadata publisher. The assessor retains its unchanged selection contract. A fresh attributable current-tuple completion may reconcile a recognized owned pending, failure or error barrier using independently selected current substantive proof. This explicitly supersedes the pending-only terminal-write restriction for source recovery: a same-head retarget/base advancement or legitimate source retry must recover without a new metadata edit. Already successful and foreign barriers remain untouched. Historical base-A success cannot authorize current base-B success, and obsolete base-A callbacks remain no-ops. The resolver re-reads current PR identity, both historical ownership and selected current native proof, and the unchanged latest status immediately before posting. Its replacement fence is the selected latest status identity; it does not require an original run number to exceed a later metadata run, since original completion after metadata publication is ordinary. Replaced, stale or unbound statuses are never overwritten. GitHub provides no conditional Commit Status write: the final read and POST are not atomic, and this boundary is practical race suppression rather than an atomic replacement guarantee. A rejected or ambiguous POST is never retried within that callback; subsequent callbacks assess fresh evidence. No polling, global expiry, new credentials, or independent proof ledger is introduced.

The [publisher action](../../.github/actions/publish-required-gate-status/action.yml) runs in the dedicated metadata-only step after both successful and dependency-deferred assessments, so a successful assessment can also recover an existing owned barrier. It accepts `assessment`, `gate-name`, `workflow-name`, `workflow-file`, and `workflow-path`, and outputs `pending-acknowledged`, `success-acknowledged`, or `unchanged`. A dependency-deferred assessment publishes the current run's pending barrier only when the latest same-context status is absent or independently recognized as owned. A success assessment leaves absent, foreign, and already successful barriers unchanged. An owned pending/failure/error barrier requires a refreshed canonical assessment for the current base before publishing success; refreshed pending follows the pending policy, and failed or ambiguous assessment prevents publication. A dependency-deferred assessment permits the native metadata gate to succeed only with `pending-acknowledged`; `unchanged`, missing, unknown, or contradictory publication outputs fail distinctly as dependency deferral. A successful assessment permits `unchanged`, `success-acknowledged`, or `pending-acknowledged`: the last means refreshed proof became pending and the acknowledged status continues withholding readiness. A successful assessment with an absent or already successful barrier needs no write; a foreign barrier remains untouched and independently blocking when non-successful. Missing or unknown assessment/publication outputs fail closed. The metadata-result guard uses `!cancelled()` with the unchanged metadata predicate so it still executes after publisher failure, and requires the publisher outcome itself to be `success` before accepting any assessment/publication pair. Publisher failure, denial, malformed acknowledgment, cancellation, or missing/skipped execution never grants native gate success. The publisher retains normal success-dependent execution without `continue-on-error`; no caller ignores its errors or changes substantive enforcement.
The [publisher action](../../.github/actions/publish-required-gate-status/action.yml) runs in the dedicated metadata-only step after both successful and dependency-deferred assessments, so a successful assessment can also recover an existing owned barrier. It accepts `assessment`, `gate-name`, `workflow-name`, `workflow-file`, and `workflow-path`, and outputs `pending-acknowledged`, `success-acknowledged`, or `unchanged`. A dependency-deferred assessment publishes the current run's pending barrier only when the latest same-context status is absent or independently recognized as owned. If an owned pending barrier already binds the exact current PR, base, head, workflow, run, and attempt, including one that becomes latest during the publisher's replacement fence, the publisher reports `pending-acknowledged` without duplicating the status only after validating the current metadata native gate and re-reading both the unchanged current PR tuple and unchanged latest status identity; a stale-base, moved, foreign, malformed, missing, failed, or successful status cannot use that durable acknowledgment path. A success assessment leaves absent, foreign, and already successful barriers unchanged. An owned pending/failure/error barrier requires a refreshed canonical assessment for the current base before publishing success; refreshed pending follows the pending policy, and failed or ambiguous assessment prevents publication. A dependency-deferred assessment permits the native metadata gate to succeed only with `pending-acknowledged`; `unchanged`, missing, unknown, or contradictory publication outputs fail distinctly as dependency deferral. A successful assessment permits `unchanged`, `success-acknowledged`, or `pending-acknowledged`: the last means refreshed proof became pending and the acknowledged status continues withholding readiness. A successful assessment with an absent or already successful barrier needs no write; a foreign barrier remains untouched and independently blocking when non-successful. Missing or unknown assessment/publication outputs fail closed. The metadata-result guard uses `!cancelled()` with the unchanged metadata predicate so it still executes after publisher failure, and requires the publisher outcome itself to be `success` before accepting any assessment/publication pair. Publisher failure, denial, malformed acknowledgment, cancellation, or missing/skipped execution never grants native gate success. The publisher retains normal success-dependent execution without `continue-on-error`; no caller ignores its errors or changes substantive enforcement.

Ownership recognition allows an older base in the canonical title as provenance, and accepts a bound dedicated publisher step in progress or completed successfully, unsuccessfully, or cancelled. It binds the exact run/attempt, workflow, repository, head, PR title, gate job and native Actions app without requiring old preservation success. This permits replacing an owned barrier left by overlapping or cancelled metadata runs. Positive native workflow `run_number` and `run_attempt` counters order replacement within the same exact workflow: an older run number is replaceable; equal run numbers require the same run ID and no newer attempt. Historical attempt-specific run/job evidence binds older attempts. Missing or conflicting counters and newer barriers are not overwritten; timestamps and global run IDs do not establish ordering. Skipped, missing, conflicting or unbound publisher evidence is not ownership and grants no overwrite permission. Old-base provenance never becomes current-base proof. The current publishing run must be attributable to its exact metadata-only event and current PR tuple. Both publisher and resolver read rich status records from `/repos/<owner>/<repo>/statuses/<head>`; the combined `/commits/<head>/status` projection omits `creator` and cannot establish ownership. The [GitHub status-list contract](https://docs.github.com/en/rest/commits/statuses#list-commit-statuses-for-a-reference) returns newest first. Readers stop at the first exact-context record regardless of actor, using that API order even when creation timestamps share a second; they never search older records for an owned predecessor or infer chronology from numeric IDs. Explicit 100-record pages have a ten-page safety budget. Only a short page without a matching context establishes absence; budget exhaustion, unavailable/malformed required pages, duplicate IDs in the traversed prefix, or mismatched head-bound status URLs fail closed. Older records after the selected context are not admission evidence. Null, missing, or foreign creators remain untouched rather than inferred from a URL. Native job reads retain their complete one-page cap of 100 records. Immediately before a single non-retried POST, the publisher re-reads the current PR and unchanged latest context. A successful command must return exactly one valid acknowledgment with a positive status ID, exact `https://api.github.com/repos/<owner>/<repo>/statuses/<head>` URL, requested state/context/target URL, bot creator and native timestamps. REST statuses have no per-status SHA or App ID. Missing, malformed, denied or ambiguous acknowledgment never yields a pending native-success allowance. Pending POST acknowledgment has native evidence; repaired recovery and read-only fork-token qualification remain outstanding in [Platform Operations and Delivery](../project-management/implementation-tracking/platform-operations-and-delivery.md#required-ci-gate-preservation). A fork token denied status-write authority leaves the publisher and native gate failed. For a non-cancelled metadata run whose canonical preservation assessment succeeded, the executed failed deferral guard retains eligibility for existing trusted legacy recovery after independent original success. Cancellation remains fail-closed. Callers never escalate fork credentials or substitute a status for original proof.

Expand Down
Loading
Loading