Skip to content

Predict oracle rearchitecture #225

Predict oracle rearchitecture

Predict oracle rearchitecture #225

Workflow file for this run

name: Predict Gas Benchmark
on:
push:
branches:
- main
pull_request:
workflow_dispatch:
inputs:
sha:
description: 'Git SHA to benchmark (defaults to HEAD of triggering branch)'
required: false
type: string
concurrency:
group: predict-bench-${{ github.sha }}
cancel-in-progress: true
env:
BENCH_API_URL: https://deepbook-predict-bench.api.mystenlabs.com
jobs:
trigger-benchmark:
runs-on: ubuntu-latest
if: >
github.event_name != 'pull_request' ||
github.event.pull_request.author_association == 'MEMBER' ||
github.event.pull_request.author_association == 'COLLABORATOR'
steps:
- name: Trigger benchmark
id: trigger
run: |
SHA="${{ inputs.sha || github.sha }}"
# PRs run with 200 rows for faster feedback; post-merge runs all rows.
if [ "${{ github.event_name }}" = "pull_request" ]; then
BODY=$(jq -n --arg sha "$SHA" '{sha: $sha, max_rows: 200}')
else
BODY=$(jq -n --arg sha "$SHA" '{sha: $sha}')
fi
echo "Triggering benchmark: $BODY"
HTTP_CODE=$(curl -s -o /tmp/bench_response.json -w "%{http_code}" -X POST \
-H "Authorization: Bearer ${{ secrets.PREDICT_BENCH_API_TOKEN }}" \
-H "Content-Type: application/json" \
-d "$BODY" \
"${BENCH_API_URL}/api/v1/benchmark")
RESPONSE=$(cat /tmp/bench_response.json)
echo "HTTP $HTTP_CODE: $RESPONSE"
if [ "$HTTP_CODE" -ge 400 ]; then
echo "::error::Benchmark API returned HTTP $HTTP_CODE: $RESPONSE"
exit 1
fi
RUN_ID=$(echo "$RESPONSE" | jq -r '.run_id')
echo "run_id=$RUN_ID" >> "$GITHUB_OUTPUT"
echo "Benchmark queued: $RUN_ID"
- name: Wait for benchmark to complete
run: |
RUN_ID="${{ steps.trigger.outputs.run_id }}"
TIMEOUT=1800 # 30 minutes
POLL_INTERVAL=30
ELAPSED=0
echo "Waiting for benchmark $RUN_ID to complete..."
while [ "$ELAPSED" -lt "$TIMEOUT" ]; do
HTTP_CODE=$(curl -s -o /tmp/poll_response.json -w "%{http_code}" \
-H "Authorization: Bearer ${{ secrets.PREDICT_BENCH_API_TOKEN }}" \
"${BENCH_API_URL}/api/v1/benchmark/${RUN_ID}")
RESPONSE=$(cat /tmp/poll_response.json)
if [ "$HTTP_CODE" = "404" ]; then
echo "::error::Run $RUN_ID not found (pod may have restarted)"
exit 1
fi
STATUS=$(echo "$RESPONSE" | jq -r '.status // empty')
echo "[${ELAPSED}s] Status: $STATUS"
case "$STATUS" in
success)
echo "Benchmark completed successfully"
exit 0
;;
failed)
ERROR=$(echo "$RESPONSE" | jq -r '.error // "unknown error"')
echo "::error::Benchmark failed: $ERROR"
exit 1
;;
queued|creating|running)
sleep "$POLL_INTERVAL"
ELAPSED=$((ELAPSED + POLL_INTERVAL))
;;
*)
echo "::error::Unexpected status: $STATUS (HTTP $HTTP_CODE)"
exit 1
;;
esac
done
echo "::error::Benchmark timed out after ${TIMEOUT}s"
exit 1