Skip to content

tests: hybrid_route waits on a deadline, not a try count (engine #850) - #851

Merged
bong-water-water-bong merged 3 commits into
mainfrom
1bit/i850-hybrid-route-startup
Nov 2, 2026
Merged

bong-water-water-bong merged 3 commits into
mainfrom
1bit/i850-hybrid-route-startup

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

What

tests/hybrid_route.sh's start() waited for /health with for _ in $(seq 1 100); … sleep 0.1; done. The sleep is
inside the loop, so the budget was 100 × (0.1 s + one curl) — 6.7 s on a quiet box, 15.2 s on a loaded CI runner.
On the runner it exhausted, start() returned non-zero, and the arm's four checks cascaded into failures that looked
like a routing defect. Same commit, two runs six minutes apart, pass and fail (engine #850).

The change (one file, tests/hybrid_route.sh)

  • A deadline in seconds, 60 s by default, HYBRID_ROUTE_START_S so the test can be driven quickly. Wall clock is
    the right unit here: the same try count is a different amount of real time on every runner.
  • The fast path is unchanged — a serve that answers at once is accepted on the first poll, in the same second.
  • One diagnostic line on exhaustion: elapsed, the last /health code, whether the pid is alive, and tail -5 of
    the serve's log. Today the only signal is the check's own FAIL … and the end-of-run dump prints 20 lines of a log
    the serve had not written yet.

Measured (stub serve answering /health with 503 for ~18 s, then 200; the stub answers no chat requests, so the

later checks fail there by design and are not part of this change)

arm result
old loop, seq 1 100 FAIL serve starts with the fake provider after 11 s (100 tries exhausted)
new loop, same stub ok serve starts with the fake provider, accepted at ~18 s
new loop, immediate 200 accepted in the same second (no added latency)
new loop, never 200 (HYBRID_ROUTE_START_S=3) one line: FAIL serve did not answer …/health within 3s: last code 503, pid … alive, then the log tail, then FAIL serve starts with the fake provider

bash -n clean. No behaviour change on the passing path, so the six passing CI runs of the last hour stay passing.

Closes engine #850.

The failing-provider arm reddened the CI `build` check at random: `start()`'s
startup wait was `seq 1 100` with `sleep 0.1` inside the loop, so its real
budget was data-dependent (6.7 s on a quiet box, 15.2 s on a loaded runner)
and every arm that used it could fail as if routing had broken.

Now: a deadline in seconds (60 s default, `HYBRID_ROUTE_START_S` for tests),
the fast path unchanged (a serve that answers at once is accepted in the same
second), and one diagnostic line on exhaustion with elapsed time, the last
`/health` code, whether the serve is alive, and the tail of its log.

Measured with a stub serve answering `/health` 503 for ~18 s then 200:
  old loop -> "FAIL serve starts with the fake provider" after 11 s (100 tries exhausted)
  new loop -> "ok   serve starts with the fake provider", accepted at ~18 s
  new loop, immediate 200 -> accepted in the same second
(The stub answers no chat requests, so the later checks still fail there by
design; they are not part of this change.)
@github-actions

github-actions Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

PR Reviewer Guide 🔍

(Review updated until commit c9c0ff1)

Here are some key observations to aid the review process:

🎫 Ticket compliance analysis 🔶

850 - Partially compliant

Compliant requirements:

  • The test now uses a deadline in seconds instead of a fixed try count
  • The startup budget is increased to 60 seconds by default, configurable via HYBRID_ROUTE_START_S
  • Improved diagnostics on failure showing elapsed time, last HTTP code, PID status, and last 5 lines of log

Non-compliant requirements:

  • None

Requires further human verification:

  • None
⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 No relevant tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Startup Timeout Logic

The change introduces a deadline-based timeout mechanism using SECONDS variable, which is a bash built-in that tracks elapsed time since the script started. This is a good approach for handling variable system load, but it assumes that SECONDS is properly initialized and behaves consistently across different bash environments. Ensure that SECONDS is not being modified elsewhere in the script or test environment, as this could lead to incorrect timeout calculations.

local code=000 deadline=$((SECONDS + ${HYBRID_ROUTE_START_S:-60}))
while :; do
    code=$(curl -s -o /dev/null -w '%{http_code}' "$api/health")
    [ "$code" = 200 ] && break
    [ $SECONDS -lt $deadline ] || break
    sleep 0.1
done

@bong-water-water-bong bong-water-water-bong added the tprs-ready TPRS: review verdict READY posted by the standing reviewer; merge gate satisfied label Nov 2, 2026

@bong-water-water-bong bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VERDICT: READY at 20b9e3fc37 — this is the fix for the flake I filed as #850, and I reproduced all four arms of its table on this box rather than reading them.

Method: the real tests/hybrid_route.sh (this head, and main's version for the A/B) driven with a stub in place of 1bit serve that answers /health 503 for N seconds and 200 after that — the stub answers no chat requests, so the later checks fail by design and are not part of this change. Only the first check and the wall clock matter here.

arm                                    first line                                            elapsed
old loop (main, seq 1 100), 18 s stub  FAIL serve starts with the fake provider                11.0 s
new loop (#851), same 18 s stub        ok   serve starts with the fake provider                18.5 s
new loop, immediate 200                ok   serve starts with the fake provider                 0.5 s
new loop, never 200, HYBRID_ROUTE_START_S=3
   FAIL serve did not answer http://127.0.0.1:51985/health within 3s: last code 503, pid 46102 alive

So: the old loop really does give up in ~11 s on a serve that needs 18 s (that is #850, and it is a try count, not a deadline), the fast path costs nothing (0.5 s wall for the whole harness, no added poll), and the exhausted path now says elapsed, the last status code, whether the pid is alive and the serve log tail — the three things I had to reconstruct by hand when triaging the CI failure.

bash -n clean. shellcheck -S warning reports two SC2034 for reply and out, both pre-existing and both false positives (they are read inside the eval in the next check); main's copy has the same line 103. Copyright header present, as CI's first step re-checks.

One nit, not a blocker: the diagnostic computes the elapsed time as $((SECONDS - deadline + ${HYBRID_ROUTE_START_S:-60})), which is correct but reads as if it could go negative — start=$SECONDS at the top and $((SECONDS - start)) would say the same thing plainly.

@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown

Persistent review updated to latest commit 6e1d873

@bong-water-water-bong bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VERDICT: READY at 6e1d87318 (re-verdict after the update-branch onto 1f2dfe99f; own patch identical to
20b9e3fc3 — one file, tests/hybrid_route.sh +14/-2)

Re-checked the behaviour at this head, not the patch text, with the real script and a stub serve that answers
/health 503 until a delay I set:

18 s stub, 20 s budget   ok   serve starts with the fake provider          (the #850 flake arm now passes)
never 200, 3 s budget    FAIL serve did not answer http://127.0.0.1:…/health within 3s:
                              last code 503, pid 1530921 alive              (fails fast, names why, ~3 s)
bash -n ok; shellcheck -S warning: only the pre-existing SC2034 at :95 (`reply`, read inside eval)

@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown

Persistent review updated to latest commit c9c0ff1

@bong-water-water-bong bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VERDICT: READY at c9c0ff1cf (re-posted; my verdict is a gate only at the head it names).

Head moved by update-branch only: c9c0ff1cf is Merge branch 'main' into 1bit/i850-hybrid-route-startup with parents 6e1d87318 (the head I verdicted) and 801a4a60c (main). The PR's own commit is untouched, so the earlier evidence — the stub arms: 18 s stub against a 20 s budget starts OK, never-200 against a 3 s budget fails in ~3 s naming 503 and the pid — applies to this tree unchanged.

CI on this head: build SUCCESS, all four Analyze jobs SUCCESS, hw_gate SKIPPED. pr_agent is green again (coder-llm back on :8090), so it is no longer a known-red check.

Nit carried, not a gate: the test asserts the deadline path with a stub server; the real hybrid_route serve is still only exercised by the lane, not by CI.

@bong-water-water-bong
bong-water-water-bong merged commit 1347d4f into main Nov 2, 2026
8 checks passed
@bong-water-water-bong
bong-water-water-bong deleted the 1bit/i850-hybrid-route-startup branch November 2, 2026 23:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Review effort 2/5 tprs-ready TPRS: review verdict READY posted by the standing reviewer; merge gate satisfied

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant