Skip to content

Commit 8fdbe89

Browse files
authored
Harden unbloat-docs dev-server readiness gate to prevent pre-agent 0-turn failures (#30910)
1 parent ab76427 commit 8fdbe89

3 files changed

Lines changed: 50 additions & 32 deletions

File tree

.github/workflows/shared/docs-server-lifecycle.md

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,18 @@
1717
Navigate to the docs directory and start the development server in the background, binding to all network interfaces on a fixed port:
1818

1919
```bash
20+
mkdir -p /tmp/gh-aw
2021
cd docs
21-
nohup npm run dev -- --host 0.0.0.0 --port 4321 > /tmp/preview.log 2>&1 &
22+
nohup npm run dev -- --host 0.0.0.0 --port 4321 > /tmp/gh-aw/preview.log 2>&1 &
2223
PID=$!
23-
echo $PID > /tmp/server.pid
24+
echo $PID > /tmp/gh-aw/server.pid
2425
echo "Server PID: $PID"
2526
```
2627

2728
This will:
2829
- Start the Astro development server on port 4321, bound to all interfaces (`0.0.0.0`)
29-
- Redirect output to `/tmp/preview.log`
30-
- Save the process ID to `/tmp/server.pid` for later cleanup
30+
- Redirect output to `/tmp/gh-aw/preview.log`
31+
- Save the process ID to `/tmp/gh-aw/server.pid` for later cleanup
3132

3233
**Note on the `nohup ... & PID=$!` pattern:** The `$!` variable (background PID) is captured into `PID` first, then written to file. Avoid `echo $! > file` in a single line — the AWF bash guard may flag `$!` as a dangerous expansion when it appears directly in a redirection context.
3334

@@ -51,16 +52,26 @@ The agent runs inside a Docker container. Binding to `0.0.0.0` ensures the serve
5152
Poll the server with curl until the `/gh-aw/` path returns HTTP 200:
5253

5354
```bash
55+
URL="http://localhost:4321/gh-aw/"
56+
STATUS=""
57+
echo "Readiness check target: $URL"
5458
for i in {1..45}; do
55-
STATUS=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:4321/gh-aw/)
56-
[ "$STATUS" = "200" ] && echo "Server ready at http://localhost:4321/gh-aw/!" && break
59+
STATUS=$(curl -sS -o /dev/null -w "%{http_code}" --connect-timeout 5 --max-time 5 "$URL" || true)
60+
[ "$STATUS" = "200" ] && echo "Server ready at $URL" && break
61+
if [ -z "$STATUS" ]; then STATUS="curl_error"; fi
5762
echo "Waiting for server... ($i/45) (status: $STATUS)" && sleep 3
5863
done
64+
if [ "$STATUS" != "200" ]; then
65+
echo "Dev server failed to start after 135 seconds (final status: $STATUS)"
66+
cat /tmp/gh-aw/preview.log || true
67+
exit 1
68+
fi
5969
```
6070

6171
This will:
6272
- Attempt to connect up to 45 times (135 seconds total) to allow for Astro dev server startup
6373
- Check that `/gh-aw/` specifically returns HTTP 200 (not just that the port is open)
74+
- Avoid exiting early on transient curl connection failures (`|| true` keeps the loop running under `set -e`)
6475
- Wait 3 seconds between attempts
6576
- Exit successfully when the docs site is fully accessible
6677

@@ -88,8 +99,8 @@ curl -s http://localhost:4321/gh-aw/ | head -20
8899
After you're done using the server, clean up the process:
89100

90101
```bash
91-
kill $(cat /tmp/server.pid) 2>/dev/null || true
92-
rm -f /tmp/server.pid /tmp/preview.log
102+
kill $(cat /tmp/gh-aw/server.pid) 2>/dev/null || true
103+
rm -f /tmp/gh-aw/server.pid /tmp/gh-aw/preview.log
93104
```
94105

95106
This will:
@@ -102,6 +113,6 @@ This will:
102113
- The server runs on `http://localhost:4321` and is accessible at `http://localhost:4321/gh-aw/` for curl/bash and playwright-cli
103114
- With CLI mode (`mode: cli`), use `localhost` directly for all playwright-cli commands — no bridge IP needed
104115
- Always clean up the server when done to avoid orphan processes
105-
- If the server fails to start, check `/tmp/preview.log` for errors
116+
- If the server fails to start, check `/tmp/gh-aw/preview.log` for errors
106117
- Node.js >= 22 is required; ensure `runtimes: node: version: "22"` is set in the workflow frontmatter
107118
- No `npm run build` step is required before starting the dev server

.github/workflows/unbloat-docs.lock.yml

Lines changed: 17 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.github/workflows/unbloat-docs.md

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -171,23 +171,30 @@ pre-agent-steps:
171171
172172
- name: Start documentation dev server
173173
run: |
174+
mkdir -p /tmp/gh-aw
174175
cd docs
175-
nohup npm run dev -- --host 0.0.0.0 --port 4321 > /tmp/preview.log 2>&1 &
176+
nohup npm run dev -- --host 0.0.0.0 --port 4321 > /tmp/gh-aw/preview.log 2>&1 &
176177
PID=$!
177-
echo $PID > /tmp/server.pid
178+
echo $PID > /tmp/gh-aw/server.pid
178179
echo "Dev server started (PID: $PID)"
179180
180181
- name: Wait for documentation server readiness
181182
run: |
183+
URL="http://localhost:4321/gh-aw/"
182184
STATUS=""
185+
echo "Readiness check target: $URL"
186+
echo "Preview log: /tmp/gh-aw/preview.log"
183187
for i in $(seq 1 45); do
184-
STATUS=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:4321/gh-aw/)
185-
[ "$STATUS" = "200" ] && echo "Server ready at http://localhost:4321/gh-aw/" && break
186-
echo "Waiting for server... ($i/45) (status: $STATUS)" && sleep 3
188+
STATUS=$(curl -sS -o /dev/null -w "%{http_code}" --connect-timeout 5 --max-time 5 "$URL" || true)
189+
[ "$STATUS" = "200" ] && echo "Server ready at $URL" && break
190+
if [ -z "$STATUS" ]; then STATUS="curl_error"; fi
191+
echo "Waiting for server... ($i/45) (status: $STATUS)"
192+
sleep 3
187193
done
188194
if [ "$STATUS" != "200" ]; then
189195
echo "Dev server failed to start after 135 seconds:"
190-
cat /tmp/preview.log || true
196+
echo "Final readiness status: $STATUS"
197+
cat /tmp/gh-aw/preview.log || true
191198
exit 1
192199
fi
193200

0 commit comments

Comments
 (0)