GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — fix(backend): stop mistaking a saturated llama-server for a dead one by couragehong · Pull Request #16 · CryptoLabInc/runed Conversation
Contributor
Under sustained embedding load (20 concurrent capture workers), EnsureStarted entered a kill/restart loop: the single-slot llama-server starves its /health endpoint while inference saturates it, the per-RPC 500ms probe missed, and one missed probe was treated as death. Worse, the restart path called stopLocked directly — skipping the inflightMu drain that Stop performs — so every queued embed was severed with a connection EOF. The restarted child saturated again immediately and the loop repeated every ~6s (observed: dozens of restarts over 3 minutes, 244 embeds cut, 240/1000 captures failed). Three defenses, in escalation order:
Serving() gets the same busy-vs-dead awareness so health dashboards stop reporting DEGRADED during every heavy burst. Regression tests (verdict_test.go, -race): a busy child with fresh life signs is left alone; a child that recovers after the drain is not restarted and the in-flight embed completes un-severed; a truly dead child is replaced.
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactionsUnder sustained embedding load (20 concurrent capture workers), EnsureStarted entered a kill/restart loop: the single-slot llama-server starves its /health endpoint while inference saturates it, the per-RPC 500ms probe missed, and one missed probe was treated as death. Worse, the restart path called stopLocked directly — skipping the inflightMu drain that Stop performs — so every queued embed was severed with a connection EOF. The restarted child saturated again immediately and the loop repeated every ~6s (observed: dozens of restarts over 3 minutes, 244 embeds cut, 240/1000 captures failed). Three defenses, in escalation order: 1. Proof-of-life tracking: every completed embed (doJSON success) and every successful health probe stamps lastAlive. A running child with a proof of life within aliveGrace (15s) that misses the quick probe is busy, not dead — EnsureStarted leaves it alone. Under saturation embeds complete continuously, so this short-circuits almost every false alarm. 2. Drain-then-reprobe (restartIfDead): with no life signs, take the inflightMu writer lock — which by construction waits for every in-flight embed, so nothing is ever severed — then re-probe with a generous budget. A merely-saturated child empties its queue during the drain and answers; the restart is skipped. restartMu single-flights bursts of suspicious RPCs. Lock order restartMu → inflightMu → lifecycleMu (Stop keeps its inflightMu → lifecycleMu suffix). 3. Only a child that stays unresponsive with zero in-flight work is killed and relaunched. Serving() gets the same busy-vs-dead awareness so health dashboards stop reporting DEGRADED during every heavy burst. Regression tests (verdict_test.go, -race): a busy child with fresh life signs is left alone; a child that recovers after the drain is not restarted and the in-flight embed completes un-severed; a truly dead child is replaced. Co-Authored-By: Claude Fable 5 <[email protected]> … test Review findings on the busy-vs-dead verdict: 1. restartIfDead did not re-check proof of life after acquiring restartMu. Followers queued behind a leader (whose drain let embeds complete and stamp lastAlive) would each run their own 2s reprobe and — under renewed saturation — their own full drain cycle in series. Re-check recentlyAlive first; the leader's drain or a restart's startup health poll has usually stamped it, so followers exit immediately. 2. TestEnsureStartedDrainRecoverySkipsRestart synchronized on a 100ms sleep to assume the in-flight embed held its RLock; on a slow runner the drain could acquire instantly while /health still reported busy, restarting a healthy child and flaking the test. Replace the sleep with the same received-channel handshake inflight_test.go uses. Co-Authored-By: Claude Fable 5 <[email protected]>
esifea
reviewed
Uh oh!
There was an error while loading. Please reload this page.
esifea
reviewed
Uh oh!
There was an error while loading. Please reload this page. …recovery doJSON used http.DefaultClient (no timeout) with the caller's ctx, which carries no deadline on the embed path (the server handler forwards the gRPC ctx unchanged). A llama-server that accepts the TCP connection but never responds — a hang, not a crash, since a crash resets the connection — would block the call forever. That call holds inflightMu.RLock, so it would also wedge restartIfDead's inflightMu.Lock() drain: the recovery path that exists to replace a stuck server would itself hang on the stuck server. Wrap each embed request in context.WithTimeout(ctx, embedRequestTimeout=120s) (WithTimeout takes the earlier of the caller's deadline and the ceiling). The ceiling is far above any legitimate embed, including the ~10s deep-queue waits seen under heavy concurrency, so it only trips on a genuinely wedged backend; the request then errors, releases the RLock, and the next EnsureStarted restarts the child. TestStuckServerDoesNotWedgeDrain: a fake server that never responds — the embed returns on the timeout and a subsequent inflightMu.Lock drains, proving the recovery path no longer hangs. Co-Authored-By: Claude Fable 5 <[email protected]> … (review) Per review: probeHealthy is now a pure "does /health answer 200?" query with no side effect, and IsHealthy records proof of life on success. The direct probeHealthy callers that only decide whether to restart (EnsureStarted's quick probe, restartIfDead's verdict probe) no longer reset the liveness clock as a side effect of asking. Measured trade-off (documented on IsHealthy, TestQuickProbeStampEdge): dropping the quick-probe stamp reopens one narrow edge — idle >aliveGrace, a slow first embed, then a concurrent second request whose quick probe is starved — where that second request's EnsureStarted escalates into restartIfDead and pays the verdict probe (~1.7s vs ~0.5s before). It never false-restarts, never blocks on the drain, and self-corrects on the next embed completion, so at most one request in a rare window sees the extra latency — acceptable for the cleaner separation. Co-Authored-By: Claude Fable 5 <[email protected]>
esifea
approved these changes
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ReviewersUh oh!
There was an error while loading. Please reload this page. AssigneesNo one assignedLabels
None yet
ProjectsMilestoneNo milestoneDevelopmentSuccessfully merging this pull request may close these issues. Uh oh!
There was an error while loading. Please reload this page. Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later. |
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |