Repository navigation
feat(spec): name Ripple's finality field for XRP and XRPT (MAG-5339) #1772
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Runs create-spec Phases 8 -> 11 -> summary against an OPEN PR, as one | |
| # claude-code-action job. Two ways in: | |
| # - pull_request: opened -> auto-start the full 8->summary sequence | |
| # - issue_comment: created with a body starting "/rerun-<phase>" -> re-run | |
| # that phase to the end, optionally with amended endpoints / hints. | |
| # State lives in the PR: the spec is the committed <chain>.json on the branch; | |
| # every phase posts its report as a PR comment; a resumed phase reconstructs | |
| # context from those comments (see references/phase-entrypoints.md). | |
| # | |
| # Required repo secrets: | |
| # CLAUDE_CODE_OAUTH_TOKEN - subscription auth (same as create_spec.yml). | |
| # BOT_PAT - one classic PAT, scopes: repo + workflow + read:packages. Used to | |
| # pull the smart-router image AND as the github_token for gh pr comment. It is | |
| # also the identity that opens the PR in create_spec.yml, so pull_request | |
| # events fire (a GITHUB_TOKEN-opened PR would not trigger this workflow). | |
| # Optional (referenced from a comment as use=NAME; only these names are honored): | |
| # PAID_RPC_1, PAID_RPC_2, PAID_RPC_3, PAID_WS_1 - keyed paid/archive node URLs, | |
| # auto-masked by Actions so the key never lands in a PR comment or log. | |
| name: "Spec Pipeline (Phases 8-11)" | |
| on: | |
| pull_request: | |
| types: [opened] | |
| # Specs live flat at the repo root as <chain>.json — only PRs touching one | |
| # are spec PRs. Skill/CI/docs PRs must not auto-start the pipeline; they | |
| # can still be run manually via a /rerun-* comment (path filters don't | |
| # apply to issue_comment). | |
| paths: | |
| - "*.json" | |
| issue_comment: | |
| types: [created] | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| packages: read | |
| concurrency: | |
| group: spec-pipeline-${{ github.event.pull_request.number || github.event.issue.number }} | |
| cancel-in-progress: false | |
| jobs: | |
| pipeline: | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 120 | |
| # Run only for: a PR opened by our automation, OR a /rerun-* comment on a PR. | |
| if: > | |
| (github.event_name == 'pull_request') || | |
| (github.event_name == 'issue_comment' && | |
| github.event.issue.pull_request != null && | |
| startsWith(github.event.comment.body, '/rerun-')) | |
| steps: | |
| - name: Resolve PR ref | |
| id: pr | |
| env: | |
| GH_TOKEN: ${{ secrets.BOT_PAT }} | |
| run: | | |
| set -euo pipefail | |
| if [ "${{ github.event_name }}" = "pull_request" ]; then | |
| echo "number=${{ github.event.pull_request.number }}" >> "$GITHUB_OUTPUT" | |
| echo "head=${{ github.event.pull_request.head.ref }}" >> "$GITHUB_OUTPUT" | |
| else | |
| num="${{ github.event.issue.number }}" | |
| head="$(gh pr view "$num" --repo "${{ github.repository }}" --json headRefName --jq .headRefName)" | |
| echo "number=$num" >> "$GITHUB_OUTPUT" | |
| echo "head=$head" >> "$GITHUB_OUTPUT" | |
| fi | |
| - name: Checkout PR branch | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ steps.pr.outputs.head }} | |
| fetch-depth: 0 | |
| - name: Parse rerun command | |
| id: cmd | |
| env: | |
| # Allow-list of secret names a comment may reference via use=NAME. | |
| ALLOWED_SECRETS: "PAID_RPC_1 PAID_RPC_2 PAID_RPC_3 PAID_WS_1" | |
| PAID_RPC_1: ${{ secrets.PAID_RPC_1 }} | |
| PAID_RPC_2: ${{ secrets.PAID_RPC_2 }} | |
| PAID_RPC_3: ${{ secrets.PAID_RPC_3 }} | |
| PAID_WS_1: ${{ secrets.PAID_WS_1 }} | |
| COMMENT_BODY: "${{ github.event.comment.body }}" | |
| run: | | |
| set -euo pipefail | |
| if [ "${{ github.event_name }}" = "pull_request" ]; then | |
| # Auto-start on PR open: run the WHOLE pipeline (Phase 8 -> 11), no | |
| # endpoint override. | |
| { | |
| echo "IS_COMMAND=true"; echo "START_PHASE=8"; echo "END_PHASE=11" | |
| echo "MAINNET_URLS="; echo "TESTNET_URLS="; echo "HINTS=" | |
| } > /tmp/cmd.env | |
| else | |
| # Export IS_COMMAND=true up-front so the "Report failure to PR" step | |
| # still fires if the parser rejects a malformed command (it exits 2 | |
| # under set -e, before the export loop below could run). For a valid | |
| # command the loop re-exports the same value; for a non-command body | |
| # the loop overwrites it with false (last write wins). | |
| echo "IS_COMMAND=true" >> "$GITHUB_OUTPUT" | |
| bash .github/scripts/parse_rerun_command.sh "$COMMENT_BODY" > /tmp/cmd.env | |
| fi | |
| cat /tmp/cmd.env | |
| # Export each parsed key as a step output. | |
| while IFS='=' read -r k v; do echo "$k=$v" >> "$GITHUB_OUTPUT"; done < /tmp/cmd.env | |
| # If a /rerun-* comment was NOT a recognised command (parser returned | |
| # IS_COMMAND=false), tell the author instead of silently no-op'ing — the | |
| # job otherwise just skips every downstream step with no in-PR signal. | |
| - name: Notify unrecognised command | |
| if: github.event_name == 'issue_comment' && steps.cmd.outputs.IS_COMMAND != 'true' | |
| env: | |
| GH_TOKEN: ${{ secrets.BOT_PAT }} | |
| REPO: ${{ github.repository }} | |
| PR: ${{ github.event.issue.number }} | |
| run: | | |
| set -euo pipefail | |
| gh pr comment "$PR" --repo "$REPO" --body "⚠️ Unrecognised command. Valid commands: \`/rerun-probe\` (Phase 8 — optional \`mainnet=URL testnet=URL\`), \`/rerun-review\` (9), \`/rerun-fix\` (10), \`/rerun-final\` (11), \`/rerun-from <8|9|10|11>\`." | |
| # Fail fast (seconds) on a grossly-misconfigured BOT_PAT before the | |
| # ~hour-long agent run. We can verify auth + write access cheaply; for a | |
| # classic token we also hard-fail on a missing 'repo' scope. We do NOT use a | |
| # POST-pulls probe: GitHub returns 404 on that endpoint even for fully | |
| # authorized fine-grained tokens, so it false-negatives and would block a | |
| # token that actually works (it already opened this PR + posted comments). | |
| - name: Pre-flight — verify BOT_PAT | |
| if: steps.cmd.outputs.IS_COMMAND == 'true' | |
| env: | |
| GH_TOKEN: ${{ secrets.BOT_PAT }} | |
| REPO: ${{ github.repository }} | |
| run: | | |
| set -euo pipefail | |
| if [ -z "${GH_TOKEN:-}" ]; then | |
| echo "::error::BOT_PAT secret is empty/unset."; exit 1 | |
| fi | |
| if ! login="$(gh api user --jq .login 2>/dev/null)"; then | |
| echo "::error::BOT_PAT failed to authenticate (gh api user) — token invalid or expired."; exit 1 | |
| fi | |
| echo "BOT_PAT authenticates as: $login" | |
| push="$(gh api "repos/$REPO" --jq '.permissions.push' 2>/dev/null || echo "unknown")" | |
| echo "Repo push permission: $push" | |
| if [ "$push" = "false" ]; then | |
| echo "::error::BOT_PAT lacks write access to $REPO. Its owner ($login) must be a collaborator with write."; exit 1 | |
| fi | |
| scopes="$(curl -sS -o /dev/null -D - -H "Authorization: token $GH_TOKEN" https://api.github.com/user \ | |
| | tr -d '\r' | awk -F': ' 'tolower($1)=="x-oauth-scopes"{print $2}')" | |
| norm=",$(printf '%s' "$scopes" | tr -d ' ')," | |
| if [ -n "$scopes" ]; then | |
| case "$norm" in | |
| *",repo,"*) echo "OK: classic 'repo' scope present — can comment on PRs." ;; | |
| *) echo "::error::BOT_PAT (classic) is missing the 'repo' scope — it cannot post PR comments. Add repo + workflow + read:packages."; exit 1 ;; | |
| esac | |
| case "$norm" in *",read:packages,"*) : ;; *) echo "::warning::BOT_PAT (classic) missing 'read:packages' — the GHCR pull of the smart-router image (Phase 8) will fail." ;; esac | |
| else | |
| echo "::warning::BOT_PAT is a fine-grained PAT (no OAuth scopes header). Auth + write access confirmed; ensure it has 'Pull requests: Read and write' (post comments) and that its owner can pull the Magma-Devs/smart-router GHCR package (Phase 8)." | |
| fi | |
| echo "Pre-flight OK." | |
| # Transparency: acknowledge in the PR thread that the run has started and is | |
| # really going to do work (token verified). issue_comment runs never appear | |
| # as PR checks, so this comment + the per-phase comments are the in-PR signal. | |
| - name: Acknowledge in PR | |
| if: steps.cmd.outputs.IS_COMMAND == 'true' | |
| env: | |
| GH_TOKEN: ${{ secrets.BOT_PAT }} | |
| REPO: ${{ github.repository }} | |
| PR: ${{ steps.pr.outputs.number }} | |
| START: ${{ steps.cmd.outputs.START_PHASE }} | |
| END: ${{ steps.cmd.outputs.END_PHASE }} | |
| EVENT: ${{ github.event_name }} | |
| RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} | |
| run: | | |
| set -euo pipefail | |
| if [ "$START" = "$END" ]; then | |
| scope="**Phase ${START}** only" | |
| else | |
| scope="**Phase ${START} → ${END}**" | |
| fi | |
| if [ "$EVENT" = "pull_request" ]; then | |
| msg="🤖 **Spec pipeline started** on PR open — running ${scope}. Results post here as comments. [View run]($RUN_URL)" | |
| else | |
| msg="🤖 **Command acknowledged** — running ${scope}. Progress and results post here as comments. [View run]($RUN_URL)" | |
| fi | |
| gh pr comment "$PR" --repo "$REPO" --body "$msg" | |
| - name: Resolve endpoints | |
| id: endpoints | |
| if: steps.cmd.outputs.IS_COMMAND == 'true' | |
| env: | |
| GH_TOKEN: ${{ secrets.BOT_PAT }} | |
| COMMENT_MAINNET: ${{ steps.cmd.outputs.MAINNET_URLS }} | |
| COMMENT_TESTNET: ${{ steps.cmd.outputs.TESTNET_URLS }} | |
| run: | | |
| set -euo pipefail | |
| # The PR body lives on GitHub, not the branch. Fetch it so the ENDPOINTS | |
| # block (written by create_spec.yml) can be parsed as the fallback source. | |
| gh pr view "${{ steps.pr.outputs.number }}" --repo "${{ github.repository }}" \ | |
| --json body --jq .body > /tmp/pr_body.md || true | |
| PR_BODY_FILE=/tmp/pr_body.md bash .github/scripts/resolve_endpoints.sh > /tmp/ep.env | |
| cat /tmp/ep.env | |
| while IFS='=' read -r k v; do echo "$k=$v" >> "$GITHUB_OUTPUT"; done < /tmp/ep.env | |
| - name: Setup Node | |
| if: steps.cmd.outputs.IS_COMMAND == 'true' | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: "22" | |
| - name: Install probe tools | |
| if: steps.cmd.outputs.IS_COMMAND == 'true' | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y jq | |
| GRPCURL_VERSION=1.9.1 | |
| curl -fsSL "https://github.com/fullstorydev/grpcurl/releases/download/v${GRPCURL_VERSION}/grpcurl_${GRPCURL_VERSION}_linux_x86_64.tar.gz" \ | |
| | sudo tar -xz -C /usr/local/bin grpcurl | |
| grpcurl --version || true | |
| - name: Log into GHCR | |
| if: steps.cmd.outputs.IS_COMMAND == 'true' | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.BOT_PAT || secrets.GITHUB_TOKEN }} | |
| # Truncation detector, part 1 of 2. Records how many phase-report comments | |
| # for the span's FINAL phase already exist, so the check at the end of the | |
| # job can require a NEW one. A bare "does a Phase N comment exist" test | |
| # would pass on any rerun of a PR that already carries one - exactly the | |
| # case on PR #128, where a Phase 8 report from the first attempt survives | |
| # every later attempt and would mask the truncation. | |
| - name: Record phase-report baseline | |
| id: baseline | |
| if: steps.cmd.outputs.IS_COMMAND == 'true' | |
| env: | |
| GH_TOKEN: ${{ secrets.BOT_PAT }} | |
| REPO: ${{ github.repository }} | |
| PR: ${{ steps.pr.outputs.number }} | |
| END: ${{ steps.cmd.outputs.END_PHASE }} | |
| run: | | |
| set -euo pipefail | |
| n=$(gh pr view "$PR" --repo "$REPO" --json comments \ | |
| --jq "[.comments[].body | split(\"\n\")[0] | |
| | select(startswith(\"**Phase ${END} \"))] | length" 2>/dev/null || echo 0) | |
| echo "count=${n:-0}" >> "$GITHUB_OUTPUT" | |
| echo "baseline: ${n:-0} existing report comment(s) for Phase ${END}" | |
| # Pin the Claude Code CLI. claude-code-action@v1 otherwise installs the | |
| # newest CLI on every run, and from 2.1.281 an Agent call that leaves | |
| # run_in_background unset starts in the background. The skills dispatch | |
| # researchers/validators that way, so the orchestrator ends its turn with | |
| # agents still pending and the job exits "success" with no spec | |
| # (create_spec runs 36295082608 Etherlink, 36296043796 Conflux eSpace). | |
| # 2.1.278 is the last version seen running every subagent in the | |
| # foreground. Bump deliberately, after checking subagent_stats in a | |
| # test run's transcript. | |
| - name: Install pinned Claude Code CLI | |
| if: steps.cmd.outputs.IS_COMMAND == 'true' | |
| id: claude_cli | |
| env: | |
| CLAUDE_CODE_VERSION: "2.1.278" | |
| run: | | |
| set -euo pipefail | |
| npm install -g "@anthropic-ai/claude-code@${CLAUDE_CODE_VERSION}" | |
| bin="$(command -v claude)" | |
| "$bin" --version | |
| echo "path=$bin" >> "$GITHUB_OUTPUT" | |
| # The add-collection guard's first half, BEFORE the agent: classify the PR | |
| # and record the head the agent starts from (check_add_collection_pr.sh | |
| # holds the rule and why). When the PR is an add-collection PR its | |
| # PROMPT_RULE goes into the prompt below, so the fixer is told the rule | |
| # rather than meeting it as a refused commit after a full 8 -> 11 run. The | |
| # script is read from main, never from the checkout: a spec branch cut | |
| # before it landed has none, and nothing the agent writes reaches the copy | |
| # that runs. | |
| - name: Classify the PR for the add-collection guard | |
| id: addcoll | |
| if: steps.cmd.outputs.IS_COMMAND == 'true' | |
| env: | |
| GH_TOKEN: ${{ secrets.BOT_PAT }} | |
| REPO: ${{ github.repository }} | |
| PR: ${{ steps.pr.outputs.number }} | |
| HEAD_REF_NAME: ${{ steps.pr.outputs.head }} | |
| run: | | |
| set -euo pipefail | |
| git fetch --quiet origin main || { echo "::error::could not fetch origin/main — cannot classify the PR for the add-collection guard."; exit 1; } | |
| G="$RUNNER_TEMP/addcoll-classify"; mkdir -p "$G" | |
| for s in check_add_collection_pr.sh check_collection_addition.sh; do | |
| git show "origin/main:.claude/skills/create-spec/scripts/$s" > "$G/$s" 2>/dev/null || true | |
| done | |
| if [ ! -s "$G/check_add_collection_pr.sh" ]; then | |
| echo "::notice::check_add_collection_pr.sh is not on main — add-collection guard off." | |
| echo "ENFORCE=false" >> "$GITHUB_OUTPUT" | |
| exit 0 | |
| fi | |
| # The title marks an update-mode PR, whose first commit can look like an addition. | |
| PR_TITLE="$(gh pr view "$PR" --repo "$REPO" --json title --jq .title 2>/dev/null || true)" | |
| BASE_REF=origin/main PR_TITLE="$PR_TITLE" bash "$G/check_add_collection_pr.sh" classify >> "$GITHUB_OUTPUT" | |
| - name: Run pipeline phases | |
| id: run | |
| if: steps.cmd.outputs.IS_COMMAND == 'true' | |
| uses: anthropics/claude-code-action@v1 | |
| with: | |
| path_to_claude_code_executable: ${{ steps.claude_cli.outputs.path }} | |
| claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }} | |
| github_token: ${{ secrets.BOT_PAT }} | |
| show_full_output: false | |
| display_report: false | |
| claude_args: | | |
| --model opus | |
| --dangerously-skip-permissions | |
| --max-turns 1000 | |
| prompt: | | |
| Run the /create-spec skill in RESUMABLE mode for an OPEN pull request. | |
| Run Phases ${{ steps.cmd.outputs.START_PHASE }} through ${{ steps.cmd.outputs.END_PHASE }} | |
| INCLUSIVE, then STOP. Do NOT run Phases 1-7, and do NOT run any phase | |
| after Phase ${{ steps.cmd.outputs.END_PHASE }}. Reconstruct context from | |
| the committed <chain>.json on this branch and the existing PR comments, | |
| exactly as references/phase-entrypoints.md specifies (read it fully first). | |
| Phase numbering for the run span (8 → 11): 8 = smart-router boot + probe, | |
| 9 = parallel reviewers, 10 = synthesize gaps + fix (+10b smoke re-probe), | |
| 11 = final reviewer verdict AND the closing Phase-12 summary checklist | |
| (the summary is the tail of Phase 11 here — there is no separate Phase 12 | |
| in the run span). When START==END you run EXACTLY that one phase and post | |
| only its comment(s). | |
| Context: | |
| - PR_NUMBER: ${{ steps.pr.outputs.number }} | |
| - Repo: ${{ github.repository }} | |
| - START_PHASE: ${{ steps.cmd.outputs.START_PHASE }} | |
| - END_PHASE: ${{ steps.cmd.outputs.END_PHASE }} | |
| - Endpoint source: ${{ steps.endpoints.outputs.ENDPOINT_SOURCE }} | |
| - MAINNET_URLS: ${{ steps.endpoints.outputs.MAINNET_URLS }} | |
| - TESTNET_URLS: ${{ steps.endpoints.outputs.TESTNET_URLS }} | |
| - ADDITIONAL_DATA (hints/docs/corrections): ${{ steps.cmd.outputs.HINTS }} | |
| Rules for this unattended run: | |
| - Probe every provided URL over BOTH http and ws (subscription methods | |
| need ws). If the spec has subscription methods and no URL answers ws, | |
| STOP and post a PR comment asking for a ws-capable node. | |
| - If MAINNET_URLS and TESTNET_URLS are both empty, research public nodes | |
| yourself (the normal Phase 3/8 fallback). | |
| - After EACH phase in the span, post its report as a PR comment via | |
| `gh pr comment ${{ steps.pr.outputs.number }} --body-file <report>`, | |
| with a bold one-line header naming the phase. | |
| - At every STOP-and-ask gate, auto-decide with the conservative default | |
| and record it. Report the Phase 11 verdict HONESTLY (never upgrade | |
| CHANGES REQUESTED to APPROVED). | |
| - The Phase-10 fix pass must NEVER introduce any of the 15 fields | |
| smart-router removed in #218 — spec-level governance | |
| (min_stake_provider, providers_types, contributor, | |
| contributor_percentage, shares, identity, block_last_updated, | |
| reliability_threshold, data_reliability_enabled), proposal envelope | |
| (proposal.title, proposal.description, top-level deposit), or api-level | |
| (extra_compute_units, category.local, category.subscription). The fixed | |
| spec stays the canonical envelope { "proposal": { "specs": [ ... ] } }. | |
| compute_units is the ONLY compute-unit input; a method is a subscription | |
| IFF it carries a FUNCTION_TAG_SUBSCRIBE parse directive, never | |
| category.subscription. A CI guard fails this run if the fixed spec | |
| carries any of these fields. | |
| ${{ steps.addcoll.outputs.PROMPT_RULE }} | |
| - Do NOT run git yourself. The Phase-10 fix pass edits the spec in the | |
| working tree and LEAVES it there (uncommitted) — a workflow step after | |
| this run commits and pushes that edit to the PR branch. The branch is | |
| already checked out; do not switch branches or commit/push anything. | |
| - Only when the run span reaches Phase 11, after the verdict comment also | |
| post the closing Phase-12 summary checklist as a final PR comment. If | |
| the span ends before Phase 11, do NOT post a summary. | |
| # Without these the agent's own record is unrecoverable. Five runs so far | |
| # have ended early with a green check, `is_error: false`, and no way to see | |
| # what the agent decided to stop for. create_spec.yml has carried both steps | |
| # all along; spec_pipeline.yml did not, which is precisely why every | |
| # truncation has been undiagnosable from outside. | |
| - name: Redact secrets from transcript | |
| if: always() | |
| env: | |
| # The keyed node URLs a /rerun-* comment may reference as use=NAME. | |
| # They are secrets with no recognisable shape — they are just URLs — | |
| # so a pattern cannot catch them; only their literal values can. | |
| # Scrubbed HERE rather than at each consumer because this step edits | |
| # $execution_file in place and everything downstream reads that one | |
| # file: the uploaded artifact AND the truncation comment. On a public | |
| # repo the artifact is the larger exposure (anyone with the run URL can | |
| # download it) and it was never scrubbed for these. | |
| PAID_RPC_1: ${{ secrets.PAID_RPC_1 }} | |
| PAID_RPC_2: ${{ secrets.PAID_RPC_2 }} | |
| PAID_RPC_3: ${{ secrets.PAID_RPC_3 }} | |
| PAID_WS_1: ${{ secrets.PAID_WS_1 }} | |
| run: | | |
| f="${{ steps.run.outputs.execution_file }}" | |
| [ -f "$f" ] || { echo "no transcript to redact"; exit 0; } | |
| perl -pi -e ' | |
| s/sk-ant-[a-z0-9]+-[A-Za-z0-9_-]+/sk-ant-REDACTED/g; | |
| s/gh[posru]_[A-Za-z0-9]{20,}/ghx_REDACTED/g; | |
| s/eyJ[A-Za-z0-9_-]+\.eyJ[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+/JWT_REDACTED/g; | |
| ' "$f" | |
| # Literal replacement via index(), never a regex: these values are URLs | |
| # full of regex metacharacters, and a value that failed to compile as a | |
| # pattern would silently scrub nothing. | |
| PAID_RPC_1="$PAID_RPC_1" PAID_RPC_2="$PAID_RPC_2" \ | |
| PAID_RPC_3="$PAID_RPC_3" PAID_WS_1="$PAID_WS_1" \ | |
| perl -i -pe ' | |
| BEGIN { | |
| @S = grep { defined $_ && length $_ >= 8 } | |
| @ENV{qw(PAID_RPC_1 PAID_RPC_2 PAID_RPC_3 PAID_WS_1)}; | |
| } | |
| for my $s (@S) { | |
| my $i = 0; | |
| while (($i = index($_, $s, $i)) >= 0) { | |
| substr($_, $i, length($s)) = "PAID_NODE_URL_REDACTED"; | |
| $i += length("PAID_NODE_URL_REDACTED"); | |
| } | |
| } | |
| ' "$f" | |
| echo "redaction pass complete" | |
| # continue-on-error because this artifact is diagnostic, not load-bearing, and | |
| # it sits BEFORE the guards and the fix commit. Without it, a transient upload | |
| # error marks the job failed, and every later step — whose `if:` is implicitly | |
| # ANDed with success() — is skipped, including "Commit spec fixes to PR branch". | |
| # That is not hypothetical: on PR #145 run 34839154144 the upload died with | |
| # `Failed to FinalizeArtifact: ... ECONNRESET` after Phase 10 had applied a real | |
| # fix and Phase 11 had approved it. Steps 16-19 were skipped, the fix was | |
| # discarded with the runner, and the PR kept displaying the approval for a spec | |
| # state that never reached the branch — the failure looks like success (MAG-3637). | |
| # The step still shows as failed in the run UI, so a lost transcript stays visible; | |
| # it just can no longer destroy the work it was only meant to document. | |
| - name: Upload transcript artifact | |
| if: always() | |
| continue-on-error: true | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: spec-pipeline-transcript-pr${{ steps.pr.outputs.number }}-run${{ github.run_id }} | |
| path: ${{ steps.run.outputs.execution_file }} | |
| if-no-files-found: warn | |
| retention-days: 14 | |
| # Reintroduction guard for the smart-router#218 field cleanup. Runs AFTER the | |
| # Phase-10 fix pass (which edits the spec in the working tree) and BEFORE the | |
| # commit below, so the spec is rejected if its FINAL content still carries any | |
| # of the 15 removed fields — whether they were already committed or the fix | |
| # pass reintroduced one. Strict mode exits 1, which stops the job here (no fix | |
| # commit) and lets "Report failure to PR" comment. Targeted: only the PR's own | |
| # root-level spec file(s), read from the post-fix working tree. jq is installed | |
| # by "Install probe tools" above; the script is tracked on `main`. | |
| - name: Guard — reject removed spec fields | |
| if: steps.cmd.outputs.IS_COMMAND == 'true' | |
| env: | |
| GH_TOKEN: ${{ secrets.BOT_PAT }} | |
| REPO: ${{ github.repository }} | |
| PR: ${{ steps.pr.outputs.number }} | |
| run: | | |
| set -euo pipefail | |
| # Fail closed if the API call itself fails — an empty list must mean | |
| # "PR changed no spec", never "we couldn't check". | |
| if ! files_json="$(gh pr view "$PR" --repo "$REPO" --json files 2>/dev/null)"; then | |
| echo "::error::could not list PR files (gh pr view) — cannot verify removed fields." | |
| exit 1 | |
| fi | |
| # Candidate set = the PR's own root-level *.json PLUS any root JSON the | |
| # Phase-10 fix pass changed in the working tree — because the commit step | |
| # stages ALL of them (`git add :(glob)*.json`). Checking only PR-listed | |
| # files would let a fix pass reintroduce a removed field in a strayed file. | |
| # while-read (not mapfile) for bash 3.2+ portability; process substitution | |
| # keeps the loop in this shell so `present` persists. | |
| present=() | |
| while IFS= read -r s; do | |
| [ -n "$s" ] && [ -f "$s" ] && present+=("$s") | |
| done < <( { printf '%s' "$files_json" | jq -r '.files[].path | select(test("^[^/]+\\.json$"))'; \ | |
| git diff --name-only HEAD -- ':(glob)*.json'; } | LC_ALL=C sort -u ) | |
| if [ "${#present[@]}" -eq 0 ]; then | |
| echo "No root-level spec JSON to guard." | |
| exit 0 | |
| fi | |
| echo "Guarding removed fields in: ${present[*]}" | |
| bash .claude/skills/create-spec/scripts/check_unused_fields.sh "${present[@]}" | |
| # Add-testnet preservation guard. Runs AFTER the Phase-10 fix pass and | |
| # BEFORE the commit, beside the removed-fields guard above. create_spec.yml | |
| # guards the CREATION half; this closes the post-PR half so the whole | |
| # add-testnet flow is drift-proof — the Phase-10 fix pass cannot silently | |
| # change the mainnet (or any pre-existing spec) and get committed. | |
| # | |
| # Fires ONLY when the PR — AS OPENED — was a clean add of exactly one spec | |
| # index to a catalog file that already exists on main (i.e. a real | |
| # add-testnet PR). New-chain PRs (file not on main), mainnet-edit PRs (no | |
| # index added), and PRs already mixed when opened are N/A and skipped, so | |
| # this never blocks a legitimately intended mainnet change. `check_unused_ | |
| # fields` above is name-level only; THIS catches semantic value drift. | |
| - name: Guard — preservation (add-testnet PRs) | |
| if: steps.cmd.outputs.IS_COMMAND == 'true' | |
| env: | |
| GH_TOKEN: ${{ secrets.BOT_PAT }} | |
| REPO: ${{ github.repository }} | |
| PR: ${{ steps.pr.outputs.number }} | |
| run: | | |
| set -euo pipefail | |
| SCRIPT=.claude/skills/create-spec/scripts/check_preservation.sh | |
| if [ ! -f "$SCRIPT" ]; then | |
| echo "::notice::check_preservation.sh not on this branch — skipping add-testnet preservation guard." | |
| exit 0 | |
| fi | |
| if ! files_json="$(gh pr view "$PR" --repo "$REPO" --json files 2>/dev/null)"; then | |
| echo "::error::could not list PR files (gh pr view) — cannot verify preservation." | |
| exit 1 | |
| fi | |
| # base = the catalog as it exists on main (before this PR). | |
| git fetch --quiet origin main || { echo "::error::could not fetch origin/main — cannot verify preservation."; exit 1; } | |
| BASE=FETCH_HEAD | |
| # --- Eligibility: resolve the single (target file, new index) from the PR | |
| # AS OPENED. A guarded PR is a clean add of exactly one spec index to | |
| # exactly one file that already exists on main. Anything else (new chain, | |
| # multi-file, mainnet edit, already-mixed) is N/A — skip the whole guard. | |
| prfiles=() | |
| while IFS= read -r s; do | |
| [ -n "$s" ] && prfiles+=("$s") | |
| done < <(printf '%s' "$files_json" | jq -r '.files[].path | select(test("^[^/]+\\.json$"))') | |
| if [ "${#prfiles[@]}" -eq 0 ]; then | |
| echo "No root-level spec JSON in this PR — preservation guard N/A."; exit 0 | |
| fi | |
| TARGET=""; NEW_INDEX="" | |
| for spec in "${prfiles[@]}"; do | |
| if ! git show "$BASE:$spec" > /tmp/pg_base.json 2>/dev/null; then | |
| echo " $spec: new on main (new-chain PR) — preservation guard N/A for this PR."; exit 0 | |
| fi | |
| git show "HEAD:$spec" > /tmp/pg_opened.json 2>/dev/null || { echo " $spec: no committed HEAD — N/A."; exit 0; } | |
| added="$(comm -13 \ | |
| <(jq -r '.proposal.specs[]?.index' /tmp/pg_base.json | LC_ALL=C sort) \ | |
| <(jq -r '.proposal.specs[]?.index' /tmp/pg_opened.json | LC_ALL=C sort))" | |
| n="$(printf '%s\n' "$added" | grep -c . || true)" | |
| if [ "$n" != "1" ] || ! bash "$SCRIPT" /tmp/pg_base.json /tmp/pg_opened.json "$added" >/dev/null 2>&1; then | |
| echo " $spec: opened PR is not a clean single-testnet add — preservation guard N/A for this PR."; exit 0 | |
| fi | |
| if [ -n "$TARGET" ]; then | |
| echo " multiple add-testnet targets ($TARGET, $spec) — ambiguous, preservation guard N/A."; exit 0 | |
| fi | |
| TARGET="$spec"; NEW_INDEX="$added" | |
| done | |
| echo "Add-testnet PR: target='$TARGET' new_index='$NEW_INDEX' — enforcing preservation through the fix pass." | |
| # --- Enforcement anchored on what will actually be COMMITTED, not the PR | |
| # file list. The commit step stages EVERY root JSON (`git add :(glob)*.json`), | |
| # so a fix pass that strays into another chain's catalog would be pushed and | |
| # a PR-file-list guard would miss it. So: (1) assert the fix pass changed | |
| # nothing but the target (working tree vs the opened HEAD), then (2) that the | |
| # target changed only by the new testnet index. | |
| strayed=0 | |
| while IFS= read -r f; do | |
| [ -z "$f" ] && continue | |
| if [ "$f" != "$TARGET" ]; then | |
| echo "::error::fix pass changed '$f', outside this add-testnet PR's target '$TARGET'. Refusing to commit." | |
| strayed=1 | |
| fi | |
| done < <(git diff --name-only HEAD -- ':(glob)*.json') | |
| [ "$strayed" -eq 0 ] || exit 1 | |
| git show "$BASE:$TARGET" > /tmp/pg_base.json | |
| if ! bash "$SCRIPT" /tmp/pg_base.json "$TARGET" "$NEW_INDEX"; then | |
| echo "::error::fix pass drifted a pre-existing spec in '$TARGET'. An add-testnet PR must change only '$NEW_INDEX'. Refusing to commit." | |
| exit 1 | |
| fi | |
| echo "Preservation OK — only '$NEW_INDEX' in '$TARGET' changed; no other catalog file touched." | |
| # The add-collection guard's second half: AFTER the Phase-10 fix pass, | |
| # BEFORE the commit. It judges exactly what the commit step would push — | |
| # every commit since the head the classify step recorded, the working tree, | |
| # untracked root JSON — and refuses it when the fix pass changed anything | |
| # outside the rule. Changes already committed are reported, not refused. | |
| # Neither this nor the add-testnet guard above substitutes for the other: | |
| # an add-collection PR adds no spec index and DOES modify a pre-existing | |
| # spec. Without it the fixer could rewrite collections the PR never touched: | |
| # the Phase-9 reviewers read the whole spec, so on a chain that gains REST | |
| # beside jsonrpc they can flag jsonrpc gaps (MAG-3906, Hedera). | |
| - name: Guard — collection addition (add-collection PRs) | |
| id: addcoll_guard | |
| if: steps.cmd.outputs.IS_COMMAND == 'true' | |
| env: | |
| ENFORCE: ${{ steps.addcoll.outputs.ENFORCE }} | |
| REASON: ${{ steps.addcoll.outputs.REASON }} | |
| BASE: ${{ steps.addcoll.outputs.BASE }} | |
| START: ${{ steps.addcoll.outputs.START }} | |
| TARGETS: ${{ steps.addcoll.outputs.TARGETS }} | |
| ALLOWED_INDEXES: ${{ steps.addcoll.outputs.ALLOWED_INDEXES }} | |
| ADDED_KEYS: ${{ steps.addcoll.outputs.ADDED_KEYS }} | |
| run: | | |
| set -euo pipefail | |
| if [ "${ENFORCE:-}" != "true" ]; then | |
| echo "::notice::add-collection guard N/A for this PR: ${REASON:-see the classify step}." | |
| exit 0 | |
| fi | |
| # From main again, not the classify step's copy: the agent ran in between. | |
| git fetch --quiet origin main || { echo "::error::could not fetch origin/main — cannot run the add-collection guard."; exit 1; } | |
| G="$RUNNER_TEMP/addcoll-enforce"; mkdir -p "$G" | |
| for s in check_add_collection_pr.sh check_collection_addition.sh; do | |
| git show "origin/main:.claude/skills/create-spec/scripts/$s" > "$G/$s" | |
| done | |
| # Exit 1 is a refusal, and "Report failure to PR" gives it its own comment. | |
| # Any other failure (a fetch above, input the script cannot use) is not a | |
| # refusal, and a rerun may clear it, so it gets the usual comment. | |
| rc=0 | |
| bash "$G/check_add_collection_pr.sh" enforce || rc=$? | |
| if [ "$rc" -eq 1 ]; then echo "REFUSED=true" >> "$GITHUB_OUTPUT"; fi | |
| exit "$rc" | |
| # Persist the Phase-10 fix pass. The skill never runs git itself (SKILL.md: | |
| # "User handles all git manually") and the prompt forbids the agent from | |
| # committing — so the fix lives only in the runner's working tree. Without | |
| # this step the branch keeps the pre-fix draft while Phases 10b/11 verify a | |
| # file that was never pushed (exactly what happened on PR #10). Commit any | |
| # root-level spec edit and push it to the PR branch. No-op if nothing changed | |
| # (e.g. /rerun-review, or a fix pass that found nothing to fix). | |
| - name: Commit spec fixes to PR branch | |
| if: steps.cmd.outputs.IS_COMMAND == 'true' | |
| env: | |
| GH_TOKEN: ${{ secrets.BOT_PAT }} | |
| REPO: ${{ github.repository }} | |
| HEAD: ${{ steps.pr.outputs.head }} | |
| PR: ${{ steps.pr.outputs.number }} | |
| RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} | |
| run: | | |
| set -euo pipefail | |
| git config user.name "lava-spec-bot" | |
| git config user.email "lava-spec-bot@users.noreply.github.com" | |
| # ':(glob)*.json' matches only root-level spec files (* does not cross /), | |
| # so skill/docs JSON under .claude/ is never swept in. | |
| if git diff --quiet -- ':(glob)*.json'; then | |
| echo "No spec changes to commit." | |
| exit 0 | |
| fi | |
| git add -- ':(glob)*.json' | |
| changed="$(git diff --cached --name-only | tr '\n' ' ')" | |
| git commit -m "fix(spec): persist pipeline fix pass for ${changed}" \ | |
| -m "Auto-committed by spec_pipeline.yml after the Phase-10 fix pass. Run: ${RUN_URL}" | |
| git push "https://x-access-token:${GH_TOKEN}@github.com/${REPO}.git" "HEAD:${HEAD}" | |
| sha="$(git rev-parse --short HEAD)" | |
| gh pr comment "$PR" --repo "$REPO" --body "📦 Committed pipeline fixes to \`${HEAD}\` (\`${sha}\`): \`${changed}\`— the branch now matches the spec that Phase 10b/11 verified." | |
| # Truncation detector, part 2 of 2. The agent is told to run Phases | |
| # START->END and post one report comment per phase. If no NEW report for the | |
| # final phase appeared, the span did not complete - regardless of the | |
| # action's own exit code, which has been `success` with `is_error: false` on | |
| # every truncation observed. Failing here stops CI from reporting a | |
| # truncated run as a good one, and lets "Report failure to PR" below post | |
| # the retry command. | |
| # | |
| # Placed AFTER the fix-commit step on purpose: if the span died between | |
| # Phase 10 and Phase 11, the fixes it did apply are still committed, and | |
| # only the verdict is missing. | |
| - name: Verify the run span completed | |
| if: steps.cmd.outputs.IS_COMMAND == 'true' | |
| env: | |
| GH_TOKEN: ${{ secrets.BOT_PAT }} | |
| REPO: ${{ github.repository }} | |
| PR: ${{ steps.pr.outputs.number }} | |
| START: ${{ steps.cmd.outputs.START_PHASE }} | |
| END: ${{ steps.cmd.outputs.END_PHASE }} | |
| BEFORE: ${{ steps.baseline.outputs.count }} | |
| RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} | |
| # For the belt-and-braces scrub below. Actions masking covers logs, not | |
| # a body posted through the API with `gh pr comment`. | |
| PAID_RPC_1: ${{ secrets.PAID_RPC_1 }} | |
| PAID_RPC_2: ${{ secrets.PAID_RPC_2 }} | |
| PAID_RPC_3: ${{ secrets.PAID_RPC_3 }} | |
| PAID_WS_1: ${{ secrets.PAID_WS_1 }} | |
| run: | | |
| set -euo pipefail | |
| after=$(gh pr view "$PR" --repo "$REPO" --json comments \ | |
| --jq "[.comments[].body | split(\"\n\")[0] | |
| | select(startswith(\"**Phase ${END} \"))] | length" 2>/dev/null || echo 0) | |
| before="${BEFORE:-0}" | |
| if [ "${after:-0}" -gt "$before" ]; then | |
| echo "span complete: Phase ${END} reported (${before} -> ${after})" | |
| exit 0 | |
| fi | |
| echo "::error::Run span ${START}->${END} ended before Phase ${END}: no new phase report was posted (count still ${before}). The action exited cleanly but the pipeline did not finish." | |
| # Pull the agent's LAST message out of the transcript and put it in the | |
| # comment. "The agent stopped early" is true of every truncation and | |
| # diagnoses none of them; the final message usually names the reason | |
| # outright. On PR #152 it read "Standing by for Phase 8 to complete." — | |
| # which is the whole diagnosis (the orchestrator was waiting on a | |
| # subagent that had already returned, MAG-3810) and it cost two runs and | |
| # an artifact download to find. Surface it in the thread instead. | |
| tail_msg="" | |
| tf="${{ steps.run.outputs.execution_file }}" | |
| X=".github/scripts/transcript_tail.py" | |
| if [ ! -f "$tf" ]; then | |
| # Distinguish this from "extraction failed": they call for different | |
| # next steps, and a single vague fallback made a wrong assumption | |
| # about the script's availability invisible. | |
| tail_msg="_(no transcript was produced for this run)_" | |
| else | |
| # `Checkout PR branch` checks out the SPEC branch, so this script is | |
| # absent from every spec branch cut before it landed — including the | |
| # PR this was written for. A /rerun-* comment runs the workflow from | |
| # the default branch, so the step exists while the file does not. | |
| # Fall back to reading it out of the default branch (the checkout | |
| # uses fetch-depth: 0, so origin/<default> is present). | |
| if [ -f "$X" ]; then | |
| tail_msg="$(python3 "$X" "$tf" 2>/dev/null || true)" | |
| else | |
| tail_msg="$(git show "origin/${{ github.event.repository.default_branch }}:$X" 2>/dev/null \ | |
| | python3 - "$tf" 2>/dev/null || true)" | |
| fi | |
| [ -n "$tail_msg" ] || tail_msg="_(transcript present, but its closing message could not be extracted)_" | |
| fi | |
| # Belt and braces. The transcript was scrubbed in place by "Redact | |
| # secrets from transcript", which is where these are actually handled; | |
| # this repeats it so a future edit that reorders or skips that step | |
| # cannot turn this into a leak. `if` rather than `[ -n "$s" ] && ...` | |
| # on purpose: under `set -e` a trailing false test as the loop's last | |
| # command kills the step before the comment is ever posted, and an | |
| # unset PAID_WS_1 is entirely normal. | |
| for s in "$PAID_RPC_1" "$PAID_RPC_2" "$PAID_RPC_3" "$PAID_WS_1"; do | |
| if [ -n "$s" ]; then tail_msg="${tail_msg//"$s"/PAID_NODE_URL_REDACTED}"; fi | |
| done | |
| body="$(printf '⚠️ **Pipeline run truncated** — the span was Phase %s → %s, but no Phase %s report was posted. The workflow step exited cleanly, so this is *not* a crash; the agent stopped early.\n\n%s\n\nThe agent transcript is attached to the [run](%s) as `spec-pipeline-transcript-pr%s-run%s`.\n\nIf the message above is a wait or standby line, the agent was waiting on a subagent that had already returned (MAG-3810). **Rebase this branch onto `main` before retrying** — the retry command below reproduces the hang on a branch that predates the fix.' \ | |
| "$START" "$END" "$END" "$tail_msg" "$RUN_URL" "$PR" "${GITHUB_RUN_ID}")" | |
| gh pr comment "$PR" --repo "$REPO" --body "$body" || true | |
| exit 1 | |
| - name: Report failure to PR | |
| if: failure() && steps.cmd.outputs.IS_COMMAND == 'true' | |
| env: | |
| GH_TOKEN: ${{ secrets.BOT_PAT }} | |
| REPO: ${{ github.repository }} | |
| PR: ${{ steps.pr.outputs.number }} | |
| START: ${{ steps.cmd.outputs.START_PHASE }} | |
| RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} | |
| GUARD_REFUSED: ${{ steps.addcoll_guard.outputs.REFUSED }} | |
| run: | | |
| set -euo pipefail | |
| # A refusal by the add-collection guard is not a flake: a rerun repeats the | |
| # same fix pass and meets the same refusal, so it gets its own comment. The | |
| # guard step failing for another reason (a fetch, say) is not a refusal. | |
| if [ "${GUARD_REFUSED:-}" = "true" ]; then | |
| # shellcheck disable=SC2016 # the backticks are markdown, not expansions | |
| gh pr comment "$PR" --repo "$REPO" --body "$(printf '**Spec pipeline: the add-collection guard refused the Phase-10 fix pass** (started at Phase %s). The fix pass changed something outside the collections this PR added, so nothing was committed, and any Phase-10 or Phase-11 comment above that describes a fix as applied does **not** reflect the branch. See the [run log](%s) for each refused change.\n\nA plain `/rerun-*` repeats the same fix and the same refusal. If a refused change is one the PR really needs, commit it by hand (a committed change is not judged again), then rerun. Otherwise leave it for a separate PR.' "$START" "$RUN_URL")" | |
| exit 0 | |
| fi | |
| # Suggest the command whose span matches the phase that was running. | |
| case "$START" in | |
| 8) cmd='/rerun-probe (optionally `/rerun-probe mainnet=https://your-node/rpc`, or `mainnet=use=PAID_RPC_1` for a stored secret node)' ;; | |
| 9) cmd='/rerun-review' ;; | |
| 10) cmd='/rerun-fix' ;; | |
| 11) cmd='/rerun-final' ;; | |
| *) cmd="/rerun-from $START" ;; | |
| esac | |
| # Say so when the run dies holding uncommitted spec edits. The commit step is | |
| # gated on success(), so any earlier failure skips it and the Phase 10 fixes | |
| # go down with the runner — while the PR still shows Phase 10's "fix applied" | |
| # and Phase 11's verdict. Reporting only "the pipeline failed" leaves a reader | |
| # to infer the branch matches those comments, which is exactly backwards | |
| # (MAG-3637). Reads the working tree, so it reports what would have been | |
| # committed, not what the PR file list claims. | |
| pending="" | |
| dirty="$(git status --porcelain -- ':(glob)*.json' 2>/dev/null | awk '{print $NF}' | paste -sd' ' - || true)" | |
| if [ -n "$dirty" ]; then | |
| pending="$(printf '\n\n⚠️ **This run ended holding uncommitted spec changes:** `%s`. They were NOT pushed — the commit step is skipped when an earlier step fails, so they were discarded with the runner. Any phase comment above describing a fix as applied does **not** reflect the branch. Re-run to regenerate them.' "$dirty")" | |
| fi | |
| gh pr comment "$PR" --repo "$REPO" --body "$(printf '**Spec pipeline failed** (started at Phase %s). See the [run log](%s).\n\nRetry by commenting:\n`%s`\n\nTo also re-run every later phase on top of the fix, use `/rerun-from %s` instead.%s' "$START" "$RUN_URL" "$cmd" "$START" "$pending")" |