Skip to content

ci: reap stray Lemonade processes before starting the server - #1946

Merged
kovtcharov-amd merged 1 commit into
mainfrom
ci/cleanup-stray-lemonade
Jul 7, 2026
Merged

kovtcharov-amd merged 1 commit into
mainfrom
ci/cleanup-stray-lemonade

Conversation

@kovtcharov-amd

Copy link
Copy Markdown
Collaborator

Why this matters

Five of the current open PRs show the same red checks — Test Lemonade Embeddings API and RAG Integration Tests — and none of them are code failures. On the self-hosted stx/strix-halo runners the machine is reused across jobs, so a crashed or leaked Lemonade Server from a prior job keeps listening on port 13305. The next job's Lemonade start then dies with [Errno 10048] only one usage of each socket address (a bind collision on ::1:13305), and any leaked llama-server backend child keeps a model resident so the next /load returns llama-server failed to start. The result is spurious failures that force repeated manual re-runs.

After this change the port is freed and stray Lemonade/llama-server processes are reaped before each server start, so the bind is deterministic. start-lemonade.ps1 already had a weaker version of this (port-owner kill only); the inline-start workflows (embeddings, rag, api) had no cleanup at all — which is exactly where the collisions came from.

The cleanup lives in one script (installer/scripts/cleanup-lemonade.ps1) reused by both start-lemonade.ps1 and the inline workflows, so there's a single source of truth. It frees IPv4 and IPv6 listeners (the collision was on ::1), reaps orphans by name, and blocks until the port is actually free.

Test plan

  • cleanup-lemonade.ps1 parses cleanly (PowerShell AST parser) and runs idempotently — verified locally it kills a live server holding 13305, then is a clean no-op when the port is free.
  • start-lemonade.ps1 parses cleanly after the refactor; the & call keeps its $ErrorActionPreference='Stop' intact (child scope).
  • All three edited workflow YAMLs validate.
  • Re-run Test Lemonade Embeddings API + RAG Integration Tests on a PR that carries this change and confirm they go green on the first attempt (needs a runner that previously had the leak).

Self-hosted stx/strix-halo runners reuse the same machine across jobs, so a
crashed or leaked Lemonade Server from a prior job keeps listening on 13305.
The next job's inline `lemonade-server serve` then dies with
`[Errno 10048] only one usage of each socket address` (bind collision on
::1:13305), and a leaked llama-server child keeps a model resident so the next
/load returns "llama-server failed to start". This is the recurring red on
Test Lemonade Embeddings API and RAG Integration Tests.

Add installer/scripts/cleanup-lemonade.ps1 — frees the port (IPv4+IPv6 owners),
reaps stray Lemonade/llama-server processes by name, then blocks until the port
is free so the caller's bind succeeds. start-lemonade.ps1 now reuses it (single
source of truth); the inline-start workflows (embeddings, rag, api) call it
between install and start.
@github-actions github-actions Bot added installer Installer changes devops DevOps/infrastructure changes labels Jul 7, 2026
@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Verdict: Approve

This PR fixes the spurious red checks on the embeddings/RAG/API workflows by reaping stray Lemonade and llama-server processes (and freeing port 13305) before each server start on the shared self-hosted runners. It extracts the cleanup into a single reusable script so start-lemonade.ps1 and the three inline-start workflows share one source of truth. No blocking issues — the logic is sound, port usage is consistent, and the change stays cleanly scoped to CI/installer glue.

🔍 Technical details

Issues

None blocking.

🟢 Name-based reap can hit a concurrent job (installer/scripts/cleanup-lemonade.ps1:122) — killing every LemonadeServer / llama-server by name is safe only if the runner never runs two Lemonade-using jobs at once. That already holds today (all workflows share port 13305, so concurrency would collide regardless), so this is a note, not a change request — just worth a one-line comment if runner concurrency ever changes.

Verified

  • Port consistency — cleanup runs on 13305 in all three edited workflows, matching their lemonade-server serve --port 13305 calls; the other callers of start-lemonade.ps1 (test_lemonade_server.yml:74, build_cpp.yml:336) pass -Port 13305, and start-lemonade.ps1:68 forwards its own $Port to the cleanup, so the freed port always matches the bound port.
  • $ErrorActionPreference isolation — the child script sets Continue, but the & call gives it its own scope, so start-lemonade.ps1's Stop (line 57) survives the call. Matches the PR's claim.
  • Idempotency / termination — Stop-PortOwners returns $false on no listener, so the wait loop exits early via return when the port is free; the deadline guarantees termination with a non-fatal warning otherwise. Safe to run when nothing is listening.
  • IPv6 coverage — Get-NetTCPConnection -State Listen covers the ::1 listener that caused the original bind collision.

Strengths

  • Correct diagnosis and minimal fix: the root cause (leaked port owner + model-resident llama-server orphan on reused runners) is addressed at both layers — port free and name-based orphan reap.
  • Good de-duplication — one script replaces the weaker inline port-kill in start-lemonade.ps1 and adds the missing cleanup to the three inline workflows, avoiding four divergent copies.
  • Thorough, accurate documentation in the script header explaining why (the 10048 collision, the resident-model failure) rather than just what.

@kovtcharov-amd
kovtcharov-amd merged commit 410368d into main Jul 7, 2026
40 of 42 checks passed
@kovtcharov-amd
kovtcharov-amd deleted the ci/cleanup-stray-lemonade branch July 7, 2026 22:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

devops DevOps/infrastructure changes installer Installer changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants