World Heartbeat #2840
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
| name: World Heartbeat | |
| on: | |
| push: | |
| branches: [main] | |
| pull_request: | |
| branches: [main] | |
| workflow_dispatch: | |
| schedule: | |
| - cron: '*/30 * * * *' | |
| permissions: | |
| contents: write | |
| jobs: | |
| verify: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.11' | |
| - name: Install | |
| run: python -m pip install -e '.[dev]' | |
| - name: Test | |
| run: pytest -q | |
| commit-state: | |
| needs: verify | |
| runs-on: ubuntu-latest | |
| if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.11' | |
| - run: python -m pip install -e '.[dev]' | |
| - name: Run heartbeat + commit state | |
| env: | |
| GH_TOKEN: ${{ secrets.FEDERATION_PAT || secrets.GITHUB_TOKEN }} | |
| GITHUB_TOKEN: ${{ secrets.FEDERATION_PAT || secrets.GITHUB_TOKEN }} | |
| run: | | |
| python -m agent_world.cli heartbeat | |
| git config user.name "agent-world-bot" | |
| git config user.email "bot@agent-world" | |
| git add data/world_state.json data/federation/ || true | |
| if git diff --cached --quiet; then | |
| echo "No state changes." | |
| else | |
| git commit -m "chore: world heartbeat state update" | |
| git push || echo "Push failed (non-fatal)" | |
| fi | |
| - name: Write heartbeat payload | |
| run: | | |
| mkdir -p data/federation | |
| echo '[{"agent_id":"agent-world","operation":"heartbeat","source":"agent-world","status":"alive","role":"world_faculty"}]' > data/federation/nadi_outbox.json | |
| - name: Relay outbox to steward-federation hub | |
| if: always() | |
| env: | |
| GH_TOKEN: ${{ secrets.FEDERATION_PAT || secrets.GITHUB_TOKEN }} | |
| run: | | |
| mkdir -p data/federation | |
| OUTBOX="data/federation/nadi_outbox.json" | |
| if [ ! -f "$OUTBOX" ]; then | |
| echo "[]" > "$OUTBOX" | |
| fi | |
| if [ "$(cat "$OUTBOX" | tr -d '[:space:]')" = "[]" ]; then | |
| echo "Outbox empty, skipping relay" | |
| exit 0 | |
| fi | |
| git clone --depth=1 https://x-access-token:${GH_TOKEN}@github.com/kimeisele/steward-federation.git /tmp/hub | |
| mkdir -p /tmp/hub/nadi | |
| cp "$OUTBOX" /tmp/hub/nadi/agent-world_to_steward.json | |
| cd /tmp/hub | |
| git config user.name "agent-world-bot" | |
| git config user.email "bot@agent-world" | |
| git add nadi/agent-world_to_steward.json | |
| git diff --cached --quiet || git commit -m "relay: agent-world outbox → steward (heartbeat #${{ github.run_number }})" | |
| max_retries=10 | |
| count=0 | |
| until git push origin main; do | |
| count=$((count+1)) | |
| if [ $count -gt $max_retries ]; then | |
| echo "Push failed after $max_retries attempts" | |
| exit 1 | |
| fi | |
| backoff=$(( (RANDOM % 15) + 2 )) | |
| echo "Race condition. Backoff ${backoff}s then rebase..." | |
| sleep $backoff | |
| git pull --rebase origin main | |
| done | |
| echo "[]" > "$OUTBOX" | |
| echo "Outbox relayed and cleared" | |
| publish-authority-feed: | |
| needs: [verify, commit-state] | |
| if: always() && needs.verify.result == 'success' | |
| uses: kimeisele/agent-internet/.github/workflows/reusable-publish-authority-feed.yml@main | |
| with: | |
| install-command: python -m pip install -e '.[dev]' | |
| build-command: | | |
| python -m agent_world.cli heartbeat | |
| python -m agent_world.cli export-authority-feed --repo-root . --output-dir .authority-feed-out |