Skip to content

Commit ed843bd

Browse files
committed
fix(mantis): prove the PR merged onto current main instead of the raw head
The Telegram Desktop proof previously built the candidate from the raw PR head, so a head behind main failed for reasons main already fixed (observed on #127770: 59 commits behind, hitting the Unknown-model defect fixed by #127952). GitHub's cached PR test merge cannot be the candidate either: it was observed 50 commits / 12 hours stale and never refreshed. The workflow now resolves the live refs/heads/main tip and merge base at dispatch, requires a main-targeting PR, and builds a deterministic local merge (merge-tree --merge-base + commit-tree with pinned identity/date) as the candidate; conflicts fail with a direct rebase message and there is no fallback to the raw head. Lane labels and docs now say the candidate is the PR merged onto main.
1 parent 963fafb commit ed843bd

6 files changed

Lines changed: 178 additions & 93 deletions

File tree

‎.github/workflows/mantis-telegram-desktop-proof.yml‎

Lines changed: 72 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ jobs:
5858
outputs:
5959
baseline_ref: ${{ steps.resolve.outputs.baseline_ref }}
6060
baseline_revision: ${{ steps.resolve.outputs.baseline_revision }}
61-
candidate_ref: ${{ steps.resolve.outputs.candidate_ref }}
62-
candidate_revision: ${{ steps.resolve.outputs.candidate_revision }}
61+
head_revision: ${{ steps.resolve.outputs.head_revision }}
62+
merge_base_revision: ${{ steps.resolve.outputs.merge_base_revision }}
6363
instructions: ${{ steps.resolve.outputs.instructions }}
6464
pr_context: ${{ steps.resolve.outputs.pr_context }}
6565
publish_artifact_name: ${{ steps.resolve.outputs.publish_artifact_name }}
@@ -98,56 +98,61 @@ jobs:
9898
repo,
9999
pull_number: Number(prNumber),
100100
});
101+
const publishArtifactName = inputs.publish_artifact_name || "";
101102
// The local helper logs values; keep bounded, untrusted PR text out of the public log.
102103
core.setOutput(
103104
"pr_context",
104105
JSON.stringify({ title: pr.title.slice(0, 500), body: (pr.body ?? "").slice(0, 12000) }),
105106
);
106-
const publishArtifactName = inputs.publish_artifact_name || "";
107107
let baselineRevision = pr.base.sha;
108-
const candidateRevision = pr.head.sha;
108+
const headRevision = pr.head.sha;
109+
let mergeBaseRevision = "";
109110
110111
if (!publishArtifactName) {
111112
const immutableSha = /^[0-9a-f]{40}$/u;
112-
if (!immutableSha.test(candidateRevision)) {
113-
core.setFailed(`Candidate ref '${candidateRevision}' is not an immutable commit SHA.`);
113+
if (!immutableSha.test(headRevision)) {
114+
core.setFailed(`PR head SHA '${headRevision}' is not an immutable commit SHA.`);
114115
return;
115116
}
116117
if (pr.state !== "open") {
117-
core.setFailed(`Candidate ref '${candidateRevision}' is not the open PR head.`);
118+
core.setFailed(`PR head '${headRevision}' is not from an open pull request.`);
118119
return;
119120
}
120121
if (!pr.head.repo) {
121-
core.setFailed("Candidate PR source repository is unavailable.");
122+
core.setFailed("PR source repository is unavailable.");
122123
return;
123124
}
124-
125-
const prComparison = await github.request(
126-
"GET /repos/{owner}/{repo}/compare/{basehead}",
127-
{ owner, repo, basehead: `${pr.base.sha}...${candidateRevision}` },
128-
);
129-
baselineRevision = prComparison.data.merge_base_commit?.sha || "";
125+
if (pr.base.ref !== "main") {
126+
core.setFailed(
127+
`Mantis proves landing on main, but this PR targets '${pr.base.ref}'.`,
128+
);
129+
return;
130+
}
131+
const { data: mainRef } = await github.rest.git.getRef({
132+
owner,
133+
repo,
134+
ref: "heads/main",
135+
});
136+
baselineRevision = mainRef.object.sha;
130137
if (!immutableSha.test(baselineRevision)) {
131-
core.setFailed("The PR comparison did not return an immutable merge base.");
138+
core.setFailed(`Main tip SHA '${baselineRevision}' is not an immutable commit SHA.`);
132139
return;
133140
}
134-
135-
const baselineOnMain = await github.request(
141+
const comparison = await github.request(
136142
"GET /repos/{owner}/{repo}/compare/{basehead}",
137-
{ owner, repo, basehead: `${baselineRevision}...main` },
143+
{ owner, repo, basehead: `${baselineRevision}...${headRevision}` },
138144
);
139-
if (
140-
baselineOnMain.data.status !== "ahead" &&
141-
baselineOnMain.data.status !== "identical"
142-
) {
145+
mergeBaseRevision = comparison.data.merge_base_commit.sha;
146+
if (!immutableSha.test(mergeBaseRevision)) {
143147
core.setFailed(
144-
`Baseline ref '${baselineRevision}' is not an ancestor of main ` +
145-
`(comparison status: ${baselineOnMain.data.status}).`,
148+
`Merge base SHA '${mergeBaseRevision}' is not an immutable commit SHA.`,
146149
);
147150
return;
148151
}
149152
150153
if (pr.head.repo.full_name !== `${owner}/${repo}`) {
154+
// Fork approval still pins the exact untrusted head; the local merge only
155+
// adds the trusted main parent on top of those reviewed bytes.
151156
const allowFork =
152157
inputs.allow_fork_candidate === true ||
153158
inputs.allow_fork_candidate === "true";
@@ -159,10 +164,10 @@ jobs:
159164
}
160165
if (
161166
!immutableSha.test(inputs.approved_head_sha || "") ||
162-
inputs.approved_head_sha !== candidateRevision
167+
inputs.approved_head_sha !== headRevision
163168
) {
164169
core.setFailed(
165-
`Fork approval must name the exact current PR head SHA (${candidateRevision}).`,
170+
`Fork approval must name the exact current PR head SHA (${headRevision}).`,
166171
);
167172
return;
168173
}
@@ -172,8 +177,8 @@ jobs:
172177
setOutput("should_run", "true");
173178
setOutput("baseline_ref", baselineRevision);
174179
setOutput("baseline_revision", baselineRevision);
175-
setOutput("candidate_ref", candidateRevision);
176-
setOutput("candidate_revision", candidateRevision);
180+
setOutput("head_revision", headRevision);
181+
setOutput("merge_base_revision", mergeBaseRevision);
177182
setOutput("pr_number", String(pr.number));
178183
setOutput("instructions", body);
179184
setOutput("publish_artifact_name", publishArtifactName);
@@ -301,9 +306,6 @@ jobs:
301306
uses: astral-sh/setup-uv@20cfd1bf945f4377ade1205e4dbc17946fc9a30d # v10.0.1
302307

303308
- name: Install local proof tools
304-
env:
305-
BASELINE_SHA: ${{ needs.resolve_request.outputs.baseline_revision }}
306-
CANDIDATE_SHA: ${{ needs.resolve_request.outputs.candidate_revision }}
307309
shell: bash
308310
run: |
309311
set -euo pipefail
@@ -448,13 +450,11 @@ jobs:
448450
sudo install -m 0755 scripts/mantis/mantis-sut-container.sh /usr/local/sbin/openclaw-mantis-sut-container
449451
printf '/tmp/openclaw-mantis-proof-worktrees-%s-%s\n' "$GITHUB_RUN_ID" "$GITHUB_RUN_ATTEMPT" \
450452
| sudo tee /etc/openclaw-mantis-sut-worktrees >/dev/null
451-
printf 'baseline\t%s\ncandidate\t%s\n' "$BASELINE_SHA" "$CANDIDATE_SHA" \
452-
| sudo tee /etc/openclaw-mantis-sut-revisions >/dev/null
453453
runtime_parent="/tmp/openclaw-mantis-sut-runtime-${GITHUB_RUN_ID}-${GITHUB_RUN_ATTEMPT}"
454454
sudo install -d -m 0711 -o root -g root "$runtime_parent"
455455
sudo install -d -m 0700 -o root -g root "$runtime_parent/attestations"
456456
printf '%s\n' "$runtime_parent" | sudo tee /etc/openclaw-mantis-sut-runtime-root >/dev/null
457-
sudo chmod 0444 /etc/openclaw-mantis-sut-worktrees /etc/openclaw-mantis-sut-revisions /etc/openclaw-mantis-sut-runtime-root
457+
sudo chmod 0444 /etc/openclaw-mantis-sut-worktrees /etc/openclaw-mantis-sut-runtime-root
458458
/usr/local/lib/mantis-toolchain/node --version
459459
/usr/local/lib/mantis-toolchain/pnpm --version
460460
/usr/local/lib/mantis-toolchain/uv --version
@@ -498,8 +498,9 @@ jobs:
498498
id: proof_worktrees
499499
env:
500500
BASELINE_SHA: ${{ needs.resolve_request.outputs.baseline_revision }}
501-
CANDIDATE_SHA: ${{ needs.resolve_request.outputs.candidate_revision }}
502-
MANTIS_PR_NUMBER: ${{ needs.resolve_request.outputs.pr_number }}
501+
HEAD_SHA: ${{ needs.resolve_request.outputs.head_revision }}
502+
MERGE_BASE_SHA: ${{ needs.resolve_request.outputs.merge_base_revision }}
503+
PR_NUMBER: ${{ needs.resolve_request.outputs.pr_number }}
503504
shell: bash
504505
run: |
505506
set -euo pipefail
@@ -509,18 +510,41 @@ jobs:
509510
toolchain_dir=/usr/local/lib/mantis-toolchain
510511
corepack_home="${RUNNER_TEMP}/mantis-corepack"
511512
mkdir -p "$worktree_root" "$corepack_home"
512-
if ! git cat-file -e "${BASELINE_SHA}^{commit}"; then
513-
git fetch --no-tags --depth 1 origin "$BASELINE_SHA"
514-
fi
515-
git cat-file -e "${BASELINE_SHA}^{commit}"
516-
if ! git cat-file -e "${CANDIDATE_SHA}^{commit}"; then
517-
git fetch --no-tags origin "pull/${MANTIS_PR_NUMBER}/head"
513+
for sha in "$BASELINE_SHA" "$HEAD_SHA" "$MERGE_BASE_SHA"; do
514+
if ! git cat-file -e "${sha}^{commit}"; then
515+
git fetch --no-tags --depth 1 origin "$sha"
516+
fi
517+
git cat-file -e "${sha}^{commit}"
518+
done
519+
# Build locally because GitHub's lazily cached PR test merge was observed 50 commits stale.
520+
# The explicit merge base makes depth-1 fetches sufficient; this needs git >= 2.38 (runner: 2.43+).
521+
merge_rc=0
522+
candidate_tree="$(git merge-tree --write-tree --merge-base="$MERGE_BASE_SHA" "$BASELINE_SHA" "$HEAD_SHA")" || merge_rc=$?
523+
# merge-tree exits 1 only for content conflicts; other codes are real git failures.
524+
if ((merge_rc == 1)); then
525+
echo "::error::The PR conflicts with current main and needs a rebase or merge before Mantis can prove it."
526+
exit 1
527+
elif ((merge_rc != 0)); then
528+
exit "$merge_rc"
518529
fi
519-
git cat-file -e "${CANDIDATE_SHA}^{commit}"
530+
merge_date="$(git log -1 --format=%cI "$BASELINE_SHA")"
531+
# Fixed identity and baseline date make this SHA reproducible for the same main/head pair.
532+
CANDIDATE_SHA="$(
533+
GIT_AUTHOR_NAME=mantis-proof [email protected] \
534+
GIT_COMMITTER_NAME=mantis-proof [email protected] \
535+
GIT_AUTHOR_DATE="$merge_date" GIT_COMMITTER_DATE="$merge_date" \
536+
git commit-tree "$candidate_tree" -p "$BASELINE_SHA" -p "$HEAD_SHA" \
537+
-m "mantis candidate: PR #${PR_NUMBER} head ${HEAD_SHA} merged onto main ${BASELINE_SHA}"
538+
)"
539+
[[ "$CANDIDATE_SHA" =~ ^[0-9a-f]{40}$ ]]
520540
git worktree add --detach "$baseline_root" "$BASELINE_SHA"
521541
git worktree add --detach "$candidate_root" "$CANDIDATE_SHA"
542+
printf 'baseline\t%s\ncandidate\t%s\n' "$BASELINE_SHA" "$CANDIDATE_SHA" \
543+
| sudo tee /etc/openclaw-mantis-sut-revisions >/dev/null
544+
sudo chmod 0444 /etc/openclaw-mantis-sut-revisions
522545
{
523546
echo "baseline_root=$baseline_root"
547+
echo "candidate_revision=$CANDIDATE_SHA"
524548
echo "lockfile_sha256=$(sha256sum "$baseline_root/pnpm-lock.yaml" | cut -d ' ' -f1)"
525549
echo "node_version=$($toolchain_dir/node --version)"
526550
echo "pnpm_version=$($toolchain_dir/pnpm --version)"
@@ -540,7 +564,7 @@ jobs:
540564
BASELINE_BUILD_ARCHIVE: ${{ github.workspace }}/.artifacts/mantis-baseline-build.tar
541565
BASELINE_BUILD_CACHE_HIT: ${{ steps.baseline_build_cache.outputs.cache-hit }}
542566
BASELINE_SHA: ${{ needs.resolve_request.outputs.baseline_revision }}
543-
CANDIDATE_SHA: ${{ needs.resolve_request.outputs.candidate_revision }}
567+
CANDIDATE_SHA: ${{ steps.proof_worktrees.outputs.candidate_revision }}
544568
HOST_PNPM_STORE: ${{ steps.setup-node-env.outputs.pnpm-store-cache-path }}
545569
shell: bash
546570
run: |
@@ -822,8 +846,8 @@ jobs:
822846
env:
823847
BASELINE_REF: ${{ needs.resolve_request.outputs.baseline_ref }}
824848
BASELINE_SHA: ${{ needs.resolve_request.outputs.baseline_revision }}
825-
CANDIDATE_REF: ${{ needs.resolve_request.outputs.candidate_ref }}
826-
CANDIDATE_SHA: ${{ needs.resolve_request.outputs.candidate_revision }}
849+
CANDIDATE_REF: ${{ steps.proof_worktrees.outputs.candidate_revision }}
850+
CANDIDATE_SHA: ${{ steps.proof_worktrees.outputs.candidate_revision }}
827851
CODEX_HOME: /tmp/mantis-codex-home-${{ github.run_id }}
828852
CODEX_INTERNAL_ORIGINATOR_OVERRIDE: codex_github_action
829853
CODEX_MODEL: ${{ vars.OPENCLAW_CI_OPENAI_MODEL_BARE }}
@@ -954,8 +978,8 @@ jobs:
954978
env:
955979
BASELINE_REF: ${{ needs.resolve_request.outputs.baseline_ref }}
956980
BASELINE_SHA: ${{ needs.resolve_request.outputs.baseline_revision }}
957-
CANDIDATE_REF: ${{ needs.resolve_request.outputs.candidate_ref }}
958-
CANDIDATE_SHA: ${{ needs.resolve_request.outputs.candidate_revision }}
981+
CANDIDATE_REF: ${{ steps.proof_worktrees.outputs.candidate_revision }}
982+
CANDIDATE_SHA: ${{ steps.proof_worktrees.outputs.candidate_revision }}
959983
SESSION_ROOT: ${{ steps.telegram_credential.outputs.session_root }}
960984
SUT_CREDENTIAL_DIR: ${{ steps.telegram_credential.outputs.sut_credential_dir }}
961985
shell: bash

0 commit comments

Comments
 (0)