GLOBALGRID2050 / EXPLORE CODE

Part of: Explore Code / Automation and CI / gridatlas / .github/workflows

GridAtlas Next Version Builders Workflow and 1 more file

A GitHub Actions workflow. Runs on push and by hand.

607 lines of YAML from gridatlas, in 2 files. Topic: Automation and CI. Section 1813 of 2044.

Cut 2026-12-06T03:07:51+00:00. A copy for reading; the repository at the stated commit is the source.

In the State lines below, domain stage, users and canonical status are rule-based first approximations from code and path evidence (rules explore-agent-rules-v1), not observed facts: the rules.

In this section

  1. GridAtlas Overnight Next Versions Workflow automation · gridatlas / .github/workflows/202608310015-gridatlas-overnight-next-versions.yml lines 1–298
  2. GridAtlas Next Version Builders Workflow automation · gridatlas / .github/workflows/202608310050-gridatlas-next-version-builders.yml lines 1–309

GridAtlas Overnight Next Versions Workflow

A GitHub Actions workflow that builds and publishes the site. Runs on push and by hand.

automationgridatlas / .github/workflows/202608310015-gridatlas-overnight-next-versions.yml · lines 1–298 of 298 · version 2026-08-31 00:15 · Entry point

What it does
It builds and publishes its content. Side effects: reads or writes files; makes network requests; starts processes.
Why it exists in the grid workflow
Domain stage upstream_foresight (path word 'gridatlas'): upstream engineering foresight over GB transmission and distribution topology (TSO/DNO, 132kV and above, the REPD pipeline, data centres), which Ventus Ltd states it models for foresight.
Inputs & outputs
In: JSON file 202608310015-gridatlas-programme-ledger.json; JSON file current.json. Out: commits pushed to the repository.
Downstream impact
It is itself an entry point (workflow); no other file was found loading it.
What it achieves
No statement of purpose was found in the file, a README line naming it, or its name.
Why it matters
No other file in the estate was found to import it; it is an entry point.
Application
gridatlas · .github/workflows · workflow
Uses
Assemble Study Build Controller (workflow run), Verify Overnight Candidate (workflow run), Finalise Overnight Candidate (workflow run)
Used by
none found
Produces
none declared
Defines here
202608310015 GridAtlas overnight next versions
Cannot conclude
Whether this code runs, is used by a live app today, or is correct. This is a static reading.
Evidence
gridatlas@98b5004c5eda9f2ed915fb6fca4b9bbcaa426ca5 .github/workflows/202608310015-gridatlas-overnight-next-versions.yml:1-298 · blob eb6d8d00bc327e0f092179bf21d22002cecd2570 · GitHub at these lines
State
achieves: name · context: readme_derived · stage: output · effects: filesystem, network, process · domain stage: upstream_foresight · users: IPP_developer, ICP_grid_engineer · canonical: production_core
name: 202608310015 GridAtlas overnight next versions

on:
  push:
    branches:
      - main
    paths:
      - .github/workflows/202608310015-gridatlas-overnight-next-versions.yml
      - orchestration/202608310015-gridatlas-overnight-next-versions/**
  workflow_dispatch:

# The two schedules that stood here fired for the last time on 2026-08-31.
# Written without their YAML shape on purpose - see the note at the foot of
# this comment:
#
#     schedule   30,45 23 30 8 *
#     schedule   */15 0-7 31 8 *
#
# Both named one calendar day in August, so after that night they could not
# fire again until the same dates in 2027. That is the disease cvaa calls
# no-time-based-gates: automation that dies when the session that wrote it
# does. Measured on a clean clone at 8fb95a2, gridatlas carried three of them.
#
# They are removed rather than rewritten as a live schedule. This programme is
# genuinely over - its own config declares active_until 2026-08-31T08:00:00Z
# and its ledger's last corpus gate is 2026-08-31T03:46Z with the scope never
# reaching the 43,000 words it required - so a recurring cron would wake a
# controller that can only decline, on a branch two agents are cutting in, with
# contents: write in its hand. Nothing that works is lost: push and
# workflow_dispatch both remain, and this workflow still runs on them.
#
# A dead schedule is worse than no schedule, because it reads as automation
# that is running.
#
# The two above are written as `schedule  <fields>` rather than in YAML. The
# cvaa antibody for this vaccine scans the raw workflow text for
# `cron:` followed by a quoted string, with no notion of a YAML comment, so
# quoting a REMOVED cron verbatim leaves the finding standing. Measured: the
# schedules were gone from the parsed triggers - `schedule present: False` on
# both files - and the vaccine still reported all three. A tool that cannot
# tell a record from a trigger will be fought rather than followed, so the
# record is kept and the shape is not.

permissions:
  actions: write
  contents: write
  pages: write

concurrency:
  group: 202608310015-gridatlas-overnight-next-versions
  cancel-in-progress: false

jobs:
  study-build-test:
    runs-on: ubuntu-24.04
    timeout-minutes: 150
    env:
      PROGRAMME_ROOT: nightly/202608310015-gridatlas-overnight-next-versions
      PROGRAMME_CONFIG: orchestration/202608310015-gridatlas-overnight-next-versions/202608310015-programme.json
      ASSEMBLER: orchestration/202608310015-gridatlas-overnight-next-versions/202608310015-assemble-study-build-controller.mjs
      CONTROLLER: work/202608310015-study-build-controller.mjs
      VERIFIER: orchestration/202608310015-gridatlas-overnight-next-versions/202608310015-verify-overnight-candidate.mjs
      FINALISER: orchestration/202608310015-gridatlas-overnight-next-versions/202608310015-finalise-overnight-candidate.mjs
      GH_TOKEN: ${{ github.token }}

    steps:
      - name: Checkout exact current main
        uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
        with:
          ref: main
          fetch-depth: 0
          token: ${{ github.token }}

      - name: Fetch every newly updated artifact branch
        run: git fetch --force --prune origin '+refs/heads/*:refs/remotes/origin/*'

      - name: Validate the timestamped controller
        run: |
          node --version
          node --check "$ASSEMBLER"
          SOURCE_ROOT="$GITHUB_WORKSPACE" CONTROLLER_OUTPUT="$GITHUB_WORKSPACE/$CONTROLLER" node "$ASSEMBLER"
          node --check "$CONTROLLER"
          node --check "$VERIFIER"
          node --check "$FINALISER"
          node -e "const p=require('./${PROGRAMME_CONFIG}'); if(p.generation!=='202608310015'||p.minimum_study_seconds<3600||p.expected_scope_words<43000) process.exit(1)"

      - name: Record study and build only after the one-hour gate
        id: controller
        env:
          SOURCE_ROOT: ${{ github.workspace }}
          FORCE_RUN: ${{ github.event_name == 'workflow_dispatch' }}
        run: node "$CONTROLLER"

      - name: Require the complete 43k scope before any candidate
        id: corpus_gate
        env:
          CONTROLLER_CANDIDATE_CREATED: ${{ steps.controller.outputs.candidate_created }}
          CANDIDATE_DIR: ${{ steps.controller.outputs.candidate_dir }}
          CANDIDATE_ID: ${{ steps.controller.outputs.candidate_id }}
          SOURCE_FINGERPRINT: ${{ steps.controller.outputs.source_fingerprint }}
          VISIBLE_WORDS: ${{ steps.controller.outputs.visible_unique_words }}
        run: |
          REQUIRED_WORDS=$(node -p "require('./${PROGRAMME_CONFIG}').expected_scope_words")
          VISIBLE_WORDS=${VISIBLE_WORDS:-0}
          echo "required_words=$REQUIRED_WORDS" >> "$GITHUB_OUTPUT"
          echo "visible_words=$VISIBLE_WORDS" >> "$GITHUB_OUTPUT"

          export REQUIRED_WORDS VISIBLE_WORDS
          python3 - <<'PY'
          import json
          import os
          from datetime import datetime, timezone
          from pathlib import Path

          ledger_path = Path(os.environ['PROGRAMME_ROOT']) / '202608310015-gridatlas-programme-ledger.json'
          ledger = json.loads(ledger_path.read_text(encoding='utf-8'))
          candidate_id = os.environ.get('CANDIDATE_ID', '')
          visible_words = int(os.environ.get('VISIBLE_WORDS', '0'))
          required_words = int(os.environ.get('REQUIRED_WORDS', '43000'))
          created = os.environ.get('CONTROLLER_CANDIDATE_CREATED', '').lower() == 'true'
          removed = []

          if created and visible_words < required_words:
              removed = [row for row in ledger.get('candidates', []) if row.get('candidate_id') == candidate_id]
              ledger['candidates'] = [row for row in ledger.get('candidates', []) if row.get('candidate_id') != candidate_id]
              if removed:
                  first_sequence = min(int(row.get('sequence', ledger.get('next_candidate_sequence', 1))) for row in removed)
                  ledger['next_candidate_sequence'] = min(int(ledger.get('next_candidate_sequence', first_sequence)), first_sequence)

          ledger['last_corpus_gate'] = {
              'checked_at': datetime.now(timezone.utc).isoformat().replace('+00:00', 'Z'),
              'source_fingerprint': os.environ.get('SOURCE_FINGERPRINT', ''),
              'visible_unique_words': visible_words,
              'required_unique_words': required_words,
              'scope_ready': visible_words >= required_words,
              'candidate_suppressed': bool(removed),
              'candidate_id': candidate_id or None
          }
          ledger_path.write_text(json.dumps(ledger, indent=2) + '\n', encoding='utf-8')
          PY

          if [ "$VISIBLE_WORDS" -lt "$REQUIRED_WORDS" ]; then
            if [ "${CONTROLLER_CANDIDATE_CREATED:-false}" = "true" ] && [ -n "${CANDIDATE_DIR:-}" ]; then
              rm -rf -- "$CANDIDATE_DIR"
            fi
            echo "candidate_allowed=false" >> "$GITHUB_OUTPUT"
            echo "scope_ready=false" >> "$GITHUB_OUTPUT"
            echo "gate_status=WAITING_FOR_COMPLETE_43K_SCOPE" >> "$GITHUB_OUTPUT"
          elif [ "${CONTROLLER_CANDIDATE_CREATED:-false}" = "true" ]; then
            echo "candidate_allowed=true" >> "$GITHUB_OUTPUT"
            echo "scope_ready=true" >> "$GITHUB_OUTPUT"
            echo "gate_status=COMPLETE_SCOPE_CANDIDATE_ALLOWED" >> "$GITHUB_OUTPUT"
          else
            echo "candidate_allowed=false" >> "$GITHUB_OUTPUT"
            echo "scope_ready=true" >> "$GITHUB_OUTPUT"
            echo "gate_status=COMPLETE_SCOPE_STUDYING" >> "$GITHUB_OUTPUT"
          fi

      - name: Install pinned browser tooling for a new candidate only
        if: steps.corpus_gate.outputs.candidate_allowed == 'true'
        run: |
          npm ci
          npx playwright install --with-deps chromium

      - name: Run browser acceptance against the isolated candidate
        id: browser
        if: steps.corpus_gate.outputs.candidate_allowed == 'true'
        env:
          CANDIDATE_DIR: ${{ steps.controller.outputs.candidate_dir }}
          CANDIDATE_GENERATION: ${{ steps.controller.outputs.candidate_generation }}
          SEARCH_GENERATION: ${{ steps.controller.outputs.search_generation }}
          RUN_STAMP: ${{ steps.controller.outputs.run_stamp }}
        run: |
          set -u
          SERVE_ROOT="$RUNNER_TEMP/202608310015-gridatlas-serve"
          rm -rf "$SERVE_ROOT"
          mkdir -p "$SERVE_ROOT"
          ln -s "$GITHUB_WORKSPACE" "$SERVE_ROOT/gridatlas"
          python3 -m http.server 4173 --bind 127.0.0.1 --directory "$SERVE_ROOT" >"$RUNNER_TEMP/202608310015-gridatlas-server.log" 2>&1 &
          SERVER_PID=$!
          cleanup() { kill "$SERVER_PID" 2>/dev/null || true; }
          trap cleanup EXIT
          for attempt in $(seq 1 30); do
            if curl --fail --silent --show-error "http://127.0.0.1:4173/gridatlas/${CANDIDATE_DIR}/current.json" >/dev/null; then break; fi
            sleep 1
          done
          PROOF="${CANDIDATE_DIR}/${RUN_STAMP}-gridatlas-browser-proof.json"
          SCREENSHOT="${CANDIDATE_DIR}/${RUN_STAMP}-gridatlas-browser-proof.png"
          set +e
          GRIDATLAS_URL="http://127.0.0.1:4173/gridatlas/${CANDIDATE_DIR}/" \
          EXPECTED_GENERATION="$CANDIDATE_GENERATION" \
          EXPECTED_SEARCH_GENERATION="$SEARCH_GENERATION" \
          OUTPUT="$PROOF" \
          SCREENSHOT="$SCREENSHOT" \
          node "$VERIFIER"
          EXIT_CODE=$?
          set -e
          echo "exit_code=$EXIT_CODE" >> "$GITHUB_OUTPUT"
          echo "proof=$PROOF" >> "$GITHUB_OUTPUT"
          echo "screenshot=$SCREENSHOT" >> "$GITHUB_OUTPUT"

      - name: Finalise candidate status and quarantine evidence
        id: finaliser
        if: steps.corpus_gate.outputs.candidate_allowed == 'true'
        env:
          SOURCE_ROOT: ${{ github.workspace }}
          CANDIDATE_DIR: ${{ steps.controller.outputs.candidate_dir }}
          CANDIDATE_ID: ${{ steps.controller.outputs.candidate_id }}
          CANDIDATE_MANIFEST: ${{ steps.controller.outputs.candidate_manifest }}
          CANDIDATE_CURRENT: ${{ steps.controller.outputs.candidate_current }}
          PROOF: ${{ steps.browser.outputs.proof }}
          BROWSER_EXIT: ${{ steps.browser.outputs.exit_code }}
          RUN_STAMP: ${{ steps.controller.outputs.run_stamp }}
        run: node "$FINALISER"

      - name: Commit only new timestamped programme and candidate folders
        id: commit
        if: steps.controller.outputs.active == 'true'
        env:
          RUN_STAMP: ${{ steps.controller.outputs.run_stamp }}
          CANDIDATE_CREATED: ${{ steps.corpus_gate.outputs.candidate_allowed }}
          CANDIDATE_DIR: ${{ steps.controller.outputs.candidate_dir }}
        run: |
          git config user.name "gridatlas-overnight-next-versions"
          git config user.email "actions@users.noreply.github.com"
          git add -- "$PROGRAMME_ROOT"
          if [ "$CANDIDATE_CREATED" = "true" ]; then git add -- "$CANDIDATE_DIR"; fi
          if git diff --cached --quiet; then
            echo "committed=false" >> "$GITHUB_OUTPUT"
            exit 0
          fi
          if [ "$CANDIDATE_CREATED" = "true" ]; then
            MESSAGE="${RUN_STAMP}-gridatlas: publish isolated overnight candidate and proof"
          else
            MESSAGE="${RUN_STAMP}-gridatlas: record overnight study observation"
          fi
          git commit -m "$MESSAGE"
          for attempt in 1 2 3; do
            git pull --rebase origin main
            if git push origin HEAD:main; then
              echo "committed=true" >> "$GITHUB_OUTPUT"
              echo "commit_sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"
              exit 0
            fi
            git fetch origin main
            sleep $((attempt * 3))
          done
          echo "Failed to push additive overnight output after three rebases" >&2
          exit 1

      - name: Request Pages rebuild for public testing
        if: steps.commit.outputs.committed == 'true'
        continue-on-error: true
        run: gh api --method POST "repos/${GITHUB_REPOSITORY}/pages/builds"

      - name: Publish run summary
        if: always()
        env:
          ACTIVE: ${{ steps.controller.outputs.active }}
          RUN_STAMP: ${{ steps.controller.outputs.run_stamp }}
          WORDS: ${{ steps.controller.outputs.visible_unique_words }}
          REQUIRED_WORDS: ${{ steps.corpus_gate.outputs.required_words }}
          SCOPE_READY: ${{ steps.corpus_gate.outputs.scope_ready }}
          CORPUS_GATE: ${{ steps.corpus_gate.outputs.gate_status }}
          STUDY_MATURE: ${{ steps.controller.outputs.study_mature }}
          REMAINING: ${{ steps.controller.outputs.study_remaining_seconds }}
          STUDY_FOLDER: ${{ steps.controller.outputs.study_folder }}
          CANDIDATE_CREATED: ${{ steps.corpus_gate.outputs.candidate_allowed }}
          CANDIDATE_DIR: ${{ steps.controller.outputs.candidate_dir }}
          CANDIDATE_VERSION: ${{ steps.controller.outputs.candidate_version }}
          CANDIDATE_STATUS: ${{ steps.finaliser.outputs.candidate_status }}
        run: |
          {
            echo "# 202608310015 GridAtlas overnight controller"
            echo
            echo "- Active: ${ACTIVE:-false}"
            echo "- Run generation: ${RUN_STAMP:-none}"
            echo "- Visible corpus words: ${WORDS:-0} / ${REQUIRED_WORDS:-43000}"
            echo "- Complete scope visible: ${SCOPE_READY:-false}"
            echo "- Corpus gate: ${CORPUS_GATE:-unknown}"
            echo "- Study mature: ${STUDY_MATURE:-false}"
            echo "- Study seconds remaining: ${REMAINING:-unknown}"
            echo "- Study evidence: \`${STUDY_FOLDER:-none}\`"
            echo "- Candidate created: ${CANDIDATE_CREATED:-false}"
            if [ "${CANDIDATE_CREATED:-false}" = "true" ]; then
              OWNER_LOWER=$(printf '%s' "$GITHUB_REPOSITORY_OWNER" | tr '[:upper:]' '[:lower:]')
              REPO_NAME=${GITHUB_REPOSITORY#*/}
              echo "- Candidate version: ${CANDIDATE_VERSION}"
              echo "- Candidate status: ${CANDIDATE_STATUS:-UNKNOWN}"
              echo "- Candidate URL: https://${OWNER_LOWER}.github.io/${REPO_NAME}/${CANDIDATE_DIR}/"
            fi
          } >> "$GITHUB_STEP_SUMMARY"

      - name: Keep quarantined candidates visible but mark the run red
        if: steps.corpus_gate.outputs.candidate_allowed == 'true' && steps.finaliser.outputs.candidate_status == 'FAIL'
        run: |
          echo "Candidate was committed with quarantine evidence; no live pointer was changed." >&2
          exit 1

GridAtlas Next Version Builders Workflow

A GitHub Actions workflow. Runs on push and by hand.

automationgridatlas / .github/workflows/202608310050-gridatlas-next-version-builders.yml · lines 1–309 of 309 · version 2026-08-31 00:50 · Entry point

What it does
It runs the REPD register. Side effects: reads or writes files; starts processes; uses storage (browser storage, DuckDB or Parquet).
Why it exists in the grid workflow
Domain stage upstream_foresight (path word 'gridatlas'): upstream engineering foresight over GB transmission and distribution topology (TSO/DNO, 132kV and above, the REPD pipeline, data centres), which Ventus Ltd states it models for foresight. Domain terms in the code: the REPD register.
Inputs & outputs
In: JSON file inoculate-current.json; JSON file status.json; DuckDB queries. Out: JSON file measurement.json; commits pushed to the repository.
Downstream impact
It is itself an entry point (workflow); no other file was found loading it.
What it achieves
Runs Loop (`tools/scope/loop.mjs`), Select Build Plan (`202608310050-gridatlas-next-version-builders/tools/202608310050-select-build-plan.mjs`) and `202608310050-gridatlas-next-version-builders/tools/202608310050-build-n1-deep-link-candidates.py`.
Why it matters
No other file in the estate was found to import it; it is an entry point.
Application
gridatlas · .github/workflows · workflow
Uses
Loop (workflow run), Select Build Plan (workflow run), Prove Federated Deep Links (workflow run), Build Readiness (workflow run), Finalise Stage (workflow run)
Used by
none found
Produces
none declared
Defines here
202608310050 GridAtlas next-version builders
Cannot conclude
Whether this code runs, is used by a live app today, or is correct. This is a static reading.
Evidence
gridatlas@98b5004c5eda9f2ed915fb6fca4b9bbcaa426ca5 .github/workflows/202608310050-gridatlas-next-version-builders.yml:1-309 · blob 86144d2b96e02daf2263feaae5e05362fd698af7 · GitHub at these lines
State
achieves: comment · context: readme_derived · stage: output · effects: filesystem, process, storage · domain stage: upstream_foresight · users: IPP_developer, ICP_grid_engineer · canonical: production_core
name: 202608310050 GridAtlas next-version builders

on:
  push:
    branches: [main]
    paths:
      - '_build-plan/**'
      - '202608310050-gridatlas-next-version-builders/**'
      - '.github/workflows/202608310050-gridatlas-next-version-builders.yml'
      - 'tools/scope/lib.mjs'
      - 'STATE.md'
  workflow_dispatch:

# The schedule that stood here was, written without its YAML shape so that a
# record of it is not mistaken for the thing itself:
#
#     # 01:07/01:37 BST onwards, offset from the quarter-hour observer.
#     # The source gate still prohibits any build before 01:15 BST.
#     schedule   7,37 0-7 31 8 *
#
# It named 31 August and fired for the last time that morning; the next
# occurrence is 2027. The comment describing it as "01:07/01:37 onwards" is
# what made it look perpetual, and that is the shape worth noticing - a
# schedule can read as a recurring one and be a single date.
#
# Removed rather than rewritten: the overnight programme this offset was
# staggered against is itself finished, so there is nothing left to be offset
# from. This workflow keeps push and workflow_dispatch and still runs on them -
# it ran on 8fb95a2 at 02:35Z and succeeded.

permissions:
  actions: write
  contents: write
  pages: write

concurrency:
  group: 202608310050-gridatlas-next-version-builders
  cancel-in-progress: false

jobs:
  build-one-stage:
    runs-on: ubuntu-24.04
    timeout-minutes: 55
    env:
      BUILD_PLAN_DIR: work/202608310050-build-plan/_build-plan
    steps:
      - name: Checkout exact GridAtlas history
        uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
        with:
          fetch-depth: 0
          token: ${{ secrets.GRIDATLAS_SCOPE_TOKEN || github.token }}

      - name: Fetch every branch carrying overnight build-plan artefacts
        run: |
          git config remote.origin.fetch '+refs/heads/*:refs/remotes/origin/*'
          git fetch origin --prune --tags --force

      - name: Prove the workflow allowlist and derived state
        run: |
          node tools/scope/loop.mjs lint
          node tools/scope/loop.mjs state
          git diff --exit-code -- STATE.md

      - name: Select the most complete 43k+ build plan and next unfinished stage
        id: plan
        run: node 202608310050-gridatlas-next-version-builders/tools/202608310050-select-build-plan.mjs

      - name: Record a non-build source gate in the Actions summary
        if: steps.plan.outputs.ready != 'true' || steps.plan.outputs.mature != 'true' || steps.plan.outputs.active != 'true'
        run: |
          {
            echo '## GridAtlas next-version source gate'
            echo
            echo "- active: ${{ steps.plan.outputs.active }}"
            echo "- one-hour study complete: ${{ steps.plan.outputs.mature }}"
            echo "- complete source ready: ${{ steps.plan.outputs.ready }}"
            echo "- selected ref: ${{ steps.plan.outputs.source_ref }}"
            echo "- selected SHA: ${{ steps.plan.outputs.source_sha }}"
            echo "- visible words: ${{ steps.plan.outputs.source_words }} / 43000"
            echo "- missing: ${{ steps.plan.outputs.missing }}"
            echo
            echo 'No candidate was created and no live pointer was touched.'
          } >> "$GITHUB_STEP_SUMMARY"

      - name: Checkout PipelineNews for N1 candidate generation
        if: steps.plan.outputs.stage == 'n1'
        uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
        with:
          repository: Ventusltd/pipelinenews
          path: work/pipelinenews
          fetch-depth: 0
          persist-credentials: false

      - name: Checkout Companies for N1 candidate generation
        if: steps.plan.outputs.stage == 'n1'
        uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
        with:
          repository: Ventusltd/companies
          path: work/companies
          fetch-depth: 0
          persist-credentials: false

      - name: Build N1 stable-route producer candidates
        if: steps.plan.outputs.stage == 'n1'
        id: n1_build
        continue-on-error: true
        run: |
          python3 202608310050-gridatlas-next-version-builders/tools/202608310050-build-n1-deep-link-candidates.py \
            --output "${{ steps.plan.outputs.output_dir }}" \
            --generation "${{ steps.plan.outputs.generation }}" \
            --pipelinenews work/pipelinenews \
            --companies work/companies \
            --gridatlas-current atlas/current.json

      - name: Install pinned browser harness for N1
        if: steps.plan.outputs.stage == 'n1' && steps.n1_build.outcome == 'success'
        id: n1_browser_install
        continue-on-error: true
        run: |
          npm ci
          npx playwright install --with-deps chromium

      - name: Prove both stable-route sentinels and the stale 404
        if: steps.plan.outputs.stage == 'n1' && steps.n1_build.outcome == 'success' && steps.n1_browser_install.outcome == 'success'
        id: n1_proof
        continue-on-error: true
        run: |
          node 202608310050-gridatlas-next-version-builders/tools/202608310050-prove-federated-deep-links.mjs \
            "${{ steps.plan.outputs.output_dir }}" \
            "${{ steps.plan.outputs.generation }}"

      - name: Install pinned DuckDB for N2
        if: steps.plan.outputs.stage == 'n2'
        id: n2_install
        continue-on-error: true
        env:
          PIP_DISABLE_PIP_VERSION_CHECK: '1'
        run: python3 -m pip install duckdb==1.3.2

      - name: Build the static exact-REPD reference index candidate
        if: steps.plan.outputs.stage == 'n2' && steps.n2_install.outcome == 'success'
        id: n2_build
        continue-on-error: true
        run: |
          python3 202608310050-gridatlas-next-version-builders/tools/202608310050-build-repd-ref-index.py \
            --parquet data/repd_projects_202608290716.parquet \
            --output "${{ steps.plan.outputs.output_dir }}" \
            --generation "${{ steps.plan.outputs.generation }}" \
            --build-plan "$BUILD_PLAN_DIR"

      - name: Checkout pinned CVAA registry for N3
        if: steps.plan.outputs.stage == 'n3'
        uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
        with:
          repository: Ventusltd/cvaa
          ref: d2ebc01f6eab41f2a84b0c53c4cfae0d2625ec5e
          path: work/cvaa
          fetch-depth: 0
          persist-credentials: false

      - name: Measure current GridAtlas findings against pinned CVAA
        if: steps.plan.outputs.stage == 'n3'
        id: n3_measure
        continue-on-error: true
        shell: bash
        run: |
          set +e
          OUT="${{ steps.plan.outputs.output_dir }}/cvaa"
          mkdir -p "$OUT"
          node work/cvaa/tools/selftest.mjs > "$OUT/selftest.log" 2>&1
          SELF_RC=$?
          node work/cvaa/inoculate.mjs . --json --no-write > "$OUT/inoculate-current.json" 2> "$OUT/inoculate-current.stderr.log"
          INOCULATE_RC=$?
          python3 - <<PY
          import json
          from pathlib import Path
          out=Path('$OUT')
          payload={
            'schema':'gridatlas.cvaa-measurement.v1',
            'generation':'${{ steps.plan.outputs.generation }}',
            'cvaa_sha':'d2ebc01f6eab41f2a84b0c53c4cfae0d2625ec5e',
            'selftest_exit_code':$SELF_RC,
            'inoculate_exit_code':$INOCULATE_RC,
            'classification':'MEASURED_NOT_BASELINED',
            'baseline_installed':False,
            'live_product_changed':False
          }
          (out/'measurement.json').write_text(json.dumps(payload,indent=2)+'\n')
          PY
          test "$SELF_RC" -eq 0
          test -s "$OUT/inoculate-current.json"

      - name: Checkout PipelineNews frozen spine for N4
        if: steps.plan.outputs.stage == 'n4'
        uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
        with:
          repository: Ventusltd/pipelinenews
          path: work/pipelinenews
          fetch-depth: 0
          persist-credentials: false

      - name: Build N4 design-freeze calibration candidate
        if: steps.plan.outputs.stage == 'n4'
        id: n4_build
        continue-on-error: true
        run: |
          python3 202608310050-gridatlas-next-version-builders/tools/202608310050-calibrate-design-freeze.py \
            --pipelinenews work/pipelinenews \
            --output "${{ steps.plan.outputs.output_dir }}" \
            --generation "${{ steps.plan.outputs.generation }}"

      - name: Build later-stage source locks and readiness artefacts
        if: contains(fromJSON('["n5","n6","n11","handover"]'), steps.plan.outputs.stage)
        id: readiness
        continue-on-error: true
        run: |
          node 202608310050-gridatlas-next-version-builders/tools/202608310050-build-readiness.mjs \
            "$BUILD_PLAN_DIR" \
            "${{ steps.plan.outputs.output_dir }}" \
            "${{ steps.plan.outputs.stage }}" \
            202608310050-gridatlas-next-version-builders/outputs

      - name: Finalise status and SHA-256 closure
        if: always() && steps.plan.outputs.output_dir != ''
        id: finalise
        env:
          OUTPUT_DIR: ${{ steps.plan.outputs.output_dir }}
          STAGE: ${{ steps.plan.outputs.stage }}
          N1_BUILD_OUTCOME: ${{ steps.n1_build.outcome }}
          N1_BROWSER_INSTALL_OUTCOME: ${{ steps.n1_browser_install.outcome }}
          N1_PROOF_OUTCOME: ${{ steps.n1_proof.outcome }}
          N2_INSTALL_OUTCOME: ${{ steps.n2_install.outcome }}
          N2_BUILD_OUTCOME: ${{ steps.n2_build.outcome }}
          N3_MEASURE_OUTCOME: ${{ steps.n3_measure.outcome }}
          N4_BUILD_OUTCOME: ${{ steps.n4_build.outcome }}
          READINESS_OUTCOME: ${{ steps.readiness.outcome }}
        run: node 202608310050-gridatlas-next-version-builders/tools/202608310050-finalise-stage.mjs

      - name: Assert source, shell and live pointers were not edited
        if: always() && steps.plan.outputs.output_dir != ''
        id: boundary
        shell: bash
        run: |
          set -euo pipefail
          OUT="${{ steps.plan.outputs.output_dir }}"
          git diff --exit-code -- _build-plan atlas/current.json atlas/index.html state/live-set.json releases/current-v5.json
          while IFS= read -r changed; do
            [ -z "$changed" ] && continue
            case "$changed" in
              "$OUT"|"$OUT"/*) ;;
              *) echo "Unexpected changed path: $changed" >&2; exit 1 ;;
            esac
          done < <(git status --porcelain=v1 | sed -E 's/^.. //; s#/$##')

      - name: Commit only the new timestamped candidate folder
        if: always() && steps.plan.outputs.output_dir != '' && steps.finalise.outcome == 'success' && steps.boundary.outcome == 'success'
        id: commit
        shell: bash
        run: |
          set -euo pipefail
          OUT="${{ steps.plan.outputs.output_dir }}"
          git config user.name 'gridatlas-next-version-builder'
          git config user.email 'actions@users.noreply.github.com'
          git add -- "$OUT"
          while IFS= read -r staged; do
            [ -z "$staged" ] && continue
            case "$staged" in
              "$OUT"/*) ;;
              *) echo "Refusing staged path outside candidate folder: $staged" >&2; exit 1 ;;
            esac
          done < <(git diff --cached --name-only)
          git commit -m "${{ steps.plan.outputs.generation }}-${{ steps.plan.outputs.stage }}-gridatlas: isolated next-version candidate [skip ci]"
          for attempt in 1 2 3 4; do
            git pull --rebase origin main
            if git push origin HEAD:main; then
              echo "committed=true" >> "$GITHUB_OUTPUT"
              echo "commit_sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"
              exit 0
            fi
            sleep $((attempt * 5))
          done
          exit 1

      - name: Request Pages rebuild for test artefacts
        if: steps.commit.outputs.committed == 'true'
        continue-on-error: true
        env:
          GH_TOKEN: ${{ github.token }}
        run: gh api --method POST "repos/${GITHUB_REPOSITORY}/pages/builds"

      - name: Chain the next stage after a green bounded stage
        if: steps.commit.outputs.committed == 'true' && steps.finalise.outputs.completed == 'true' && steps.plan.outputs.stage != 'handover'
        continue-on-error: true
        env:
          GH_TOKEN: ${{ secrets.GRIDATLAS_SCOPE_TOKEN || github.token }}
        run: |
          sleep 25
          gh workflow run 202608310050-gridatlas-next-version-builders.yml --ref main

      - name: Preserve a red gate after committing its evidence
        if: always() && steps.plan.outputs.output_dir != ''
        run: |
          STATUS="$(python3 - <<PY
          import json
          print(json.load(open('${{ steps.plan.outputs.output_dir }}/status.json'))['status'])
          PY
          )"
          echo "final-status=$STATUS"
          test "$STATUS" != 'FAILED_WITH_EVIDENCE'