DJ-Goanna-Coding commited on
Commit
dd11681
·
verified ·
1 Parent(s): 7d24a84

Upload .github/workflows/librarian_healthcheck.yml with huggingface_hub

Browse files
.github/workflows/librarian_healthcheck.yml ADDED
@@ -0,0 +1,97 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: Librarian Healthcheck
2
+
3
+ # Polls the deployed HF Space's /v1/system/status endpoint on a schedule.
4
+ # If the Space is unhealthy (non-2xx, missing fields, or unreachable) the
5
+ # job triggers `hf-sync.yml` so the Space is rebuilt from the latest main.
6
+ #
7
+ # Self-healing per Phase 3.3 of UNIVERSAL_ALIGNMENT_PROTOCOL_QGTNL.
8
+
9
+ on:
10
+ schedule:
11
+ # Every 6 hours, on the hour.
12
+ - cron: '0 */6 * * *'
13
+ workflow_dispatch:
14
+
15
+ permissions:
16
+ contents: read
17
+ actions: write # required to dispatch hf-sync.yml on failure
18
+
19
+ concurrency:
20
+ group: librarian-healthcheck
21
+ cancel-in-progress: false
22
+
23
+ jobs:
24
+ ping-status:
25
+ runs-on: ubuntu-latest
26
+ env:
27
+ HF_SPACE: DJ-Goanna-Coding/Oppo-TIA
28
+ STATUS_URL: https://dj-goanna-coding-oppo-tia.hf.space/v1/system/status
29
+ steps:
30
+ - name: Checkout repository
31
+ uses: actions/checkout@v4
32
+ with:
33
+ fetch-depth: 1
34
+
35
+ - name: Probe /v1/system/status
36
+ id: probe
37
+ run: |
38
+ set +e
39
+ # Allow the Space up to 90s to wake up if it was sleeping.
40
+ response=$(curl -fsS --max-time 90 --retry 3 --retry-delay 10 \
41
+ -H "Accept: application/json" "$STATUS_URL")
42
+ rc=$?
43
+ set -e
44
+
45
+ if [ $rc -ne 0 ]; then
46
+ echo "::warning::Status endpoint unreachable (curl rc=$rc)"
47
+ echo "healthy=false" >> "$GITHUB_OUTPUT"
48
+ echo "reason=unreachable" >> "$GITHUB_OUTPUT"
49
+ exit 0
50
+ fi
51
+
52
+ echo "$response" | python3 -c "
53
+ import json, sys
54
+ payload = json.load(sys.stdin)
55
+ required = {'repo', 'version', 'commit', 'index_built', 'personas', 'uptime_seconds'}
56
+ missing = required - payload.keys()
57
+ if missing:
58
+ print(f'::warning::status payload missing fields: {sorted(missing)}')
59
+ sys.exit(2)
60
+ print(f\"OK repo={payload['repo']} commit={payload['commit']} \"
61
+ f\"personas={len(payload['personas'])} \"
62
+ f\"index_built={payload['index_built']} \"
63
+ f\"uptime={payload['uptime_seconds']}s\")
64
+ "
65
+ rc=$?
66
+ if [ $rc -eq 0 ]; then
67
+ echo "healthy=true" >> "$GITHUB_OUTPUT"
68
+ else
69
+ echo "healthy=false" >> "$GITHUB_OUTPUT"
70
+ echo "reason=schema-mismatch" >> "$GITHUB_OUTPUT"
71
+ fi
72
+
73
+ - name: Trigger hf-sync.yml on failure
74
+ if: steps.probe.outputs.healthy != 'true'
75
+ env:
76
+ GH_TOKEN: ${{ github.token }}
77
+ REASON: ${{ steps.probe.outputs.reason }}
78
+ run: |
79
+ echo "Space unhealthy (${REASON}); dispatching hf-sync.yml to rebuild..."
80
+ gh workflow run hf-sync.yml \
81
+ --repo "${{ github.repository }}" \
82
+ --ref "${{ github.ref_name }}"
83
+ echo "Dispatched."
84
+
85
+ - name: Emit librarian action log
86
+ if: always()
87
+ env:
88
+ STATUS: ${{ steps.probe.outputs.healthy == 'true' && 'ok' || 'fail' }}
89
+ REASON: ${{ steps.probe.outputs.reason }}
90
+ run: |
91
+ # Best-effort: never fail the job because of logging.
92
+ python3 scripts/emit_action_log.py \
93
+ --action librarian-healthcheck \
94
+ --actor github-actions \
95
+ --status "${STATUS}" \
96
+ --detail "{\"reason\": \"${REASON:-none}\", \"space\": \"${HF_SPACE}\"}" \
97
+ --quiet || true