vxpu/router: add model status and reconcile loop for model loader #827
<!-- kube-agents-bot:intro -->
Hello, I'm kube-agents-bot 👋 I read
pull requests here and flag what looks wrong. I've started on this one — I'll post my
findings in a few minutes, or tell you I found none.
| Command | What it does |
| --- | --- |
| /review | The strict read of the current commit: what I'm certain of, plus a high-severity finding just under that bar, marked as such. |
| /review all | The same read, kept wider — findings I checked and believe are real as well as the ones I'm certain of. This is what my first review of a pull request does. |
| /review fresh | Reads the commit again from scratch. Without it, a command on a commit I have already read re-cuts that read at the bar you asked for instead of reading again — same findings, other bar, no cost — and says so. |
Comment any of them on a line of its own. Repository owners, members and collaborators only.
Worth knowing:
review. Pushing more commits does _not_ start a new review — comment
/review whenyou want another look, or
/review all for one as wide as the first. The oneexception: if I said the branch doesn't merge, I'll start on my own after your next push.
clean gets a short "no findings" note rather than silence, saying how I read the change
and how many possible issues I checked on the way. The 👀 means I've started; a comment
from me means I've finished. If you get 👀 and nothing follows, I broke.
stale — are folded into a collapsed list in my summary, not posted as findings, and
don't count against the review. Whether to act on them is your call; nothing waits on
them.
written down and pointed me at, and with the review method it has nominated, if it
has one. Whether a feature or a design should exist at all is
a human's call — a review from me saying nothing about that is not an endorsement.
agent:ignore and I will leave it alone entirely, /reviewincluded.
Found 4 issues, left inline on the changed lines.
_This was a wider pass: as well as what I am certain of, it includes findings I checked and believe are real without being sure. Comment /review for a stricter re-read._
---
Automated review by kube-agents-bot 6e585df on kube-agents-bot-gke.
Triggered by this pull request being opened; read c164665 as merged into main.
<sub>React 👍 if this was useful, 👎 if it was not. Add the agent:ignore label to opt this pull request out.</sub>
🔴 High · behaviour — Model marked passed while the executor is still loading when no golden file is configured
Reconcile treats a successful LoadModel reply as a finished load. The executor's LoadModel only starts the load. It starts a background thread and returns success=True straight away (vxpu/python/vxpu/server.py:204-208). Its own docstring says "loads asynchronously. Callers check GetLoad or poll NewSession until the model is ready."
When desired.Golden == nil, nothing after LoadModel checks GetLoad. Control falls through to r.setStatus(key, ModelStatus{Phase: ModelPhasePassed}) at line 328. handleResult then sees err == nil and phase passed, so it calls queue.Forget(key) and does not requeue the key. As a result:
passed while weights are still rehydrating;_load then fails (server.py:145-150 sets load_error, so GetLoad reports LOAD_STATE_FAILED), the status stays passed. Nothing reconciles the key again until some other caller enqueues it.That is a failure recorded as success.
A second, smaller part of the same cause shows up when a golden file is set. verifyGolden → waitForReady returns "model load failed on executor" when GetLoad reports FAILED (router.go:1028-1029). Reconcile passes that error back at line 324 without setting ModelPhaseFailed. The model therefore stays in checking and never gets a NextAttempt, which handleResult only fills in for failed.
One part of the original report does not hold. Re-enqueueing while the executor is LOADING does not restart the load when the request is unchanged: server.py:179-180 returns early when self.loading == digest. Re-calling LoadModel in the FAILED state is the retry-with-backoff the PR description intends.
The fix for both parts is the same: after LoadModel (or when GetLoad reports LOADING), set loading and return an error so the key is requeued, or return without one and rely on a requeue. Only mark the model passed once GetLoad reports LOAD_STATE_READY. Map LOAD_STATE_FAILED to ModelPhaseFailed.
_How often, as the check that scored this judged it: No production code calls SetDesired yet (only reconciler_test.go; router.go:167 only constructs the reconciler), so today only tests reach this path. Once move 2 routes LoadModel through the reconciler as the description says, every model load without a golden file will hit it._
<details>
<summary>Prompt for a coding agent</summary>
<pre>
Verify this against the current code before changing anything.
A code review reported the following against https://github.com/gke-labs/generation-ai/blob/c164665787fc98a345a1f1d1b581dac0574b9cdd/vxpu/pkg/router/reconciler.go#L296-L329:
Model marked passed while the executor is still loading when no golden file is configured
Reconcile treats a successful LoadModel reply as a finished load. The executor's LoadModel only starts the load. It starts a background thread and returns success=True straight away (vxpu/python/vxpu/server.py:204-208). Its own docstring says "loads asynchronously. Callers check GetLoad or poll NewSession until the model is ready."
When desired.Golden == nil, nothing after LoadModel checks GetLoad. Control falls through to r.setStatus(key, ModelStatus{Phase: ModelPhasePassed}) at line 328. handleResult then sees err == nil and phase passed, so it calls queue.Forget(key) and does not requeue the key. As a result:
passed while weights are still rehydrating;_load then fails (server.py:145-150 sets load_error, so GetLoad reports LOAD_STATE_FAILED), the status stays passed. Nothing reconciles the key again until some other caller enqueues it.That is a failure recorded as success.
A second, smaller part of the same cause shows up when a golden file is set. verifyGolden → waitForReady returns "model load failed on executor" when GetLoad reports FAILED (router.go:1028-1029). Reconcile passes that error back at line 324 without setting ModelPhaseFailed. The model therefore stays in checking and never gets a NextAttempt, which handleResult only fills in for failed.
One part of the original report does not hold. Re-enqueueing while the executor is LOADING does not restart the load when the request is unchanged: server.py:179-180 returns early when self.loading == digest. Re-calling LoadModel in the FAILED state is the retry-with-backoff the PR description intends.
The fix for both parts is the same: after LoadModel (or when GetLoad reports LOADING), set loading and return an error so the key is requeued, or return without one and rely on a requeue. Only mark the model passed once GetLoad reports LOAD_STATE_READY. Map LOAD_STATE_FAILED to ModelPhaseFailed.
_How often, as the check that scored this judged it: No production code calls SetDesired yet (only reconciler_test.go; router.go:167 only constructs the reconciler), so today only tests reach this path. Once move 2 routes LoadModel through the reconciler as the description says, every model load without a golden file will hit it._
First confirm the mechanism described is still present in the current code. If it is, make the smallest change that resolves it and add or adjust a test that would have caught it. If it is not, report that and change nothing.
</pre>
</details>
🔴 High · behaviour — Reconcile skips LoadModel when an executor is already LOAD_STATE_READY with a different model or plan
Reconcile only calls execClient.LoadModel when loadResp.State != pb.LoadState_LOAD_STATE_READY. But GetLoadResponse (vxpu/proto/vxpu.proto:378-385) has only state, error and bytes_rehydrated. It says nothing about which model or plan the executor holds, so "READY" cannot tell "this model is loaded" from "some model is loaded". This fails in two ways:
pickExternalExecutor (external.go:67-81) falls back to s.externalExecutors[0] when every external executor is busy. That executor answers READY for the model it already holds. LoadModel is skipped, the golden check is skipped when Golden is nil, and the new key is set to ModelPhasePassed while the executor still serves the old model.SetDesired with a new Request.Plan for a model whose executor is READY leads to the same skip, so the new plan never reaches the executor.The reconciler also never makes the bookkeeping the legacy path does. loadArtifactInternal (router.go:905-907, 992-994) evicts the previous model with forgetModel and records the placement with placedExternally; Reconcile does neither. So modelEndpoint / externalModel stay pointing at the old model.
_How often, as the check that scored this judged it: No production code calls SetDesired yet: the reconciler is created at router.go:167 but only reconciler_test.go drives it. Once the next PR routes LoadModel through it (as the description states), this fires whenever all external executors are busy and a new external model is requested, or whenever a READY model's plan changes._
<details>
<summary>Prompt for a coding agent</summary>
<pre>
Verify this against the current code before changing anything.
A code review reported the following against https://github.com/gke-labs/generation-ai/blob/c164665787fc98a345a1f1d1b581dac0574b9cdd/vxpu/pkg/router/reconciler.go#L296-L315:
Reconcile skips LoadModel when an executor is already LOAD_STATE_READY with a different model or plan
Reconcile only calls execClient.LoadModel when loadResp.State != pb.LoadState_LOAD_STATE_READY. But GetLoadResponse (vxpu/proto/vxpu.proto:378-385) has only state, error and bytes_rehydrated. It says nothing about which model or plan the executor holds, so "READY" cannot tell "this model is loaded" from "some model is loaded". This fails in two ways:
pickExternalExecutor (external.go:67-81) falls back to s.externalExecutors[0] when every external executor is busy. That executor answers READY for the model it already holds. LoadModel is skipped, the golden check is skipped when Golden is nil, and the new key is set to ModelPhasePassed while the executor still serves the old model.SetDesired with a new Request.Plan for a model whose executor is READY leads to the same skip, so the new plan never reaches the executor.The reconciler also never makes the bookkeeping the legacy path does. loadArtifactInternal (router.go:905-907, 992-994) evicts the previous model with forgetModel and records the placement with placedExternally; Reconcile does neither. So modelEndpoint / externalModel stay pointing at the old model.
_How often, as the check that scored this judged it: No production code calls SetDesired yet: the reconciler is created at router.go:167 but only reconciler_test.go drives it. Once the next PR routes LoadModel through it (as the description states), this fires whenever all external executors are busy and a new external model is requested, or whenever a READY model's plan changes._
First confirm the mechanism described is still present in the current code. If it is, make the smallest change that resolves it and add or adjust a test that would have caught it. If it is not, report that and change nothing.
</pre>
</details>
🟠 Medium · behaviour — resolveEndpoint closes the wrong executor connection when the agent assigned a dynamic port
startRuntime returns whatever endpoint the agent publishes. The agent builds that endpoint from a port it allocates on the fly: processmanager.go:238-244 calls allocatePortLocked() and then net.JoinHostPort(m.host, port). The reconciler then dials and pools a grpc.ClientConn under that exact address, in s.conns[endpoint] (router.go:308).
Later the executor process dies, and the dead process is first seen in resolveEndpoint. At that point the agent no longer reports the port: trackedProcess.status() only fills in Endpoint while state == "running" (processmanager.go:744-747). So resolveEndpoint builds the address from the fixed port instead, calling RemoveExecutor(ctx, fmt.Sprintf("%s:%d", podIP, r.server.executorPort)).
removeExecutorLocked looks up s.conns[podIP:50051] and finds nothing. It still closes the agent connection, because that is keyed by host only. The pooled executor connection at the dynamic port, and its s.executors / expertHolders entries, stay behind. The next reconcile calls startRuntime, which usually allocates a new port and dials a fresh connection, so the old one is never closed.
checkRuntimeDied does not have this problem because it is passed the real endpoint. A fix is to remember the endpoint this reconciler last resolved for the key and remove that one, rather than rebuilding the address from executorPort.
_How often, as the check that scored this judged it: Fires every time a managed executor crashes or exits between reconcile passes, or after the model reached passed, and the crash is first noticed in resolveEndpoint; with the agent always assigning dynamic ports, every such crash leaks one connection._
<details>
<summary>Prompt for a coding agent</summary>
<pre>
Verify this against the current code before changing anything.
A code review reported the following against https://github.com/gke-labs/generation-ai/blob/c164665787fc98a345a1f1d1b581dac0574b9cdd/vxpu/pkg/router/reconciler.go#L368-L377:
resolveEndpoint closes the wrong executor connection when the agent assigned a dynamic port
startRuntime returns whatever endpoint the agent publishes. The agent builds that endpoint from a port it allocates on the fly: processmanager.go:238-244 calls allocatePortLocked() and then net.JoinHostPort(m.host, port). The reconciler then dials and pools a grpc.ClientConn under that exact address, in s.conns[endpoint] (router.go:308).
Later the executor process dies, and the dead process is first seen in resolveEndpoint. At that point the agent no longer reports the port: trackedProcess.status() only fills in Endpoint while state == "running" (processmanager.go:744-747). So resolveEndpoint builds the address from the fixed port instead, calling RemoveExecutor(ctx, fmt.Sprintf("%s:%d", podIP, r.server.executorPort)).
removeExecutorLocked looks up s.conns[podIP:50051] and finds nothing. It still closes the agent connection, because that is keyed by host only. The pooled executor connection at the dynamic port, and its s.executors / expertHolders entries, stay behind. The next reconcile calls startRuntime, which usually allocates a new port and dials a fresh connection, so the old one is never closed.
checkRuntimeDied does not have this problem because it is passed the real endpoint. A fix is to remember the endpoint this reconciler last resolved for the key and remove that one, rather than rebuilding the address from executorPort.
_How often, as the check that scored this judged it: Fires every time a managed executor crashes or exits between reconcile passes, or after the model reached passed, and the crash is first noticed in resolveEndpoint; with the agent always assigning dynamic ports, every such crash leaks one connection._
First confirm the mechanism described is still present in the current code. If it is, make the smallest change that resolves it and add or adjust a test that would have caught it. If it is not, report that and change nothing.
</pre>
</details>
🟠 Medium · behaviour — A runtime crash during verifyGolden leaves the model in checking with no error, instead of failed
Reconcile checks for a dead runtime after errors from GetLoad (L290) and LoadModel (L308). It does not do so after a non-mismatch error from verifyGolden (L318–L324). That is the step that waits for weights to load and then runs golden inference, so it is where an OOM or segfault is most likely.
When the executor dies during golden prompts, NewSession, Execute or Recv fails. Reconcile then returns the wrapped error and leaves the status it set at L317: {Phase: checking, LastError: nil}. handleResult calls AddRateLimited, but it only fills in NextAttempt when the phase is failed (L258). So Status() keeps reporting checking with no error and no next attempt. Only the next requeued pass corrects it, when resolveEndpoint sees the dead process and sets failed.
The crash during weight loading is worse than the candidate says. waitForReady (router.go L1017–L1039) only logs GetLoad errors and keeps polling every 200ms for up to 10 minutes. A runtime that dies there holds the single worker and reports checking for up to 10 minutes. It never reaches failed with the exit output in that time, unless the caller's ctx is cancelled first.
The fix is to call r.checkRuntimeDied(ctx, agentClient, endpoint) on the non-mismatch error path, the same way the other two RPC sites do.
_How often, as the check that scored this judged it: This happens whenever a model with a golden file has its executor crash or get OOM-killed during weight loading or golden inference. Those are the heaviest steps of a load, so a crash there is a realistic outcome for any model that is too large or broken._
<details>
<summary>Prompt for a coding agent</summary>
<pre>
Verify this against the current code before changing anything.
A code review reported the following against https://github.com/gke-labs/generation-ai/blob/c164665787fc98a345a1f1d1b581dac0574b9cdd/vxpu/pkg/router/reconciler.go#L315-L326:
A runtime crash during verifyGolden leaves the model in checking with no error, instead of failed
Reconcile checks for a dead runtime after errors from GetLoad (L290) and LoadModel (L308). It does not do so after a non-mismatch error from verifyGolden (L318–L324). That is the step that waits for weights to load and then runs golden inference, so it is where an OOM or segfault is most likely.
When the executor dies during golden prompts, NewSession, Execute or Recv fails. Reconcile then returns the wrapped error and leaves the status it set at L317: {Phase: checking, LastError: nil}. handleResult calls AddRateLimited, but it only fills in NextAttempt when the phase is failed (L258). So Status() keeps reporting checking with no error and no next attempt. Only the next requeued pass corrects it, when resolveEndpoint sees the dead process and sets failed.
The crash during weight loading is worse than the candidate says. waitForReady (router.go L1017–L1039) only logs GetLoad errors and keeps polling every 200ms for up to 10 minutes. A runtime that dies there holds the single worker and reports checking for up to 10 minutes. It never reaches failed with the exit output in that time, unless the caller's ctx is cancelled first.
The fix is to call r.checkRuntimeDied(ctx, agentClient, endpoint) on the non-mismatch error path, the same way the other two RPC sites do.
_How often, as the check that scored this judged it: This happens whenever a model with a golden file has its executor crash or get OOM-killed during weight loading or golden inference. Those are the heaviest steps of a load, so a crash there is a realistic outcome for any model that is too large or broken._
First confirm the mechanism described is still present in the current code. If it is, make the smallest change that resolves it and add or adjust a test that would have caught it. If it is not, report that and change nothing.
</pre>
</details>
(Automatic review) Read and run at c164665; the unit jobs pass, the rest were still running. The shape is the one agreed: one work queue keyed by model, rate-limited requeue (100 ms to 5 s), failed retried and refused not, observed state read fresh from the pod, the agent's process table and the executor's load state, and no sleeps, timers or detached contexts. The six tests pass here with -race -count=20. What is missing is the heart of a reconciler: converging to the desired state when it changes.
1. A changed desired state is never applied. Measured with a scratch test: after a model reaches passed, setting a different desired state leaves the executor's load count at 1 and the status at passed. The executor saying "ready" is taken to mean "the desired model is loaded"; nothing compares what is loaded with what is wanted. The reconcile function compares the identity of the desired state with the identity the executor reports, and acts on a difference. Test it.
2. A stale run can record its result against a newer desired state. A change of desired state during a load keeps the phase, and the run in flight then writes passed or refused for the old request. Give the desired state a generation and have the status say which generation it speaks for, as Kubernetes objects do; a result for an old generation is discarded.
3. Reconciling a passed model re-runs the golden check every time. A reconcile of a model that is already where it should be observes and does nothing. The check's result belongs to a generation and is not repeated for it.
4. One worker, and a step that blocks for the length of a load. A long load holds every other model. A step should start work and return, and a later run observes that it finished (the executor already reports a loading state); or say why a blocking step with several workers is the better trade. Either way, loading one model must not delay another.
5. Guesses and dropped errors, each settled before: the pod's address falls back to 127.0.0.1; an empty endpoint falls back to an address of the router's making (an error since the agent assigns the port); a failed stop is logged at a verbosity nobody runs with. Errors are returned to the queue, which is what requeues.
6. The design note describes the next moves as if they were done ("requests never start work themselves"). Write what is true after this pull request and what the next move changes; and say plainly that until then there are two records of a model's status (the standing and this one) and which one requests read.
7. Size. About 320 non-comment lines. The 40-line rate limiter wrapper exists only to report when the next attempt is due; the queue can be asked, or the status can record it when the key is requeued. With item 4 the reconcile function should get shorter, not longer.
Rebase onto main (two commits behind).
(Automatic review) At 779054c the four main points are solved, measured here with scratch tests under -race: a changed desired state after passed is applied (loads go from 1 to 2 and the status speaks for generation 2); a result for an old generation is discarded and a change mid-load converges to the new one; five more reconciles of a passed model load nothing and check nothing; and a step does not block for a load, because the executor's load returns at once and the next run sees it loading. Generation and observed generation are defined as in Kubernetes. No guessed addresses, a failed stop is returned, and the design note says there are two records of status for now and which one requests read. One goroutine, no timers or sleeps. This is the reconciler that was asked for.
Before it goes to the maintainer, small things:
1. "Still loading" is returned as an error to get a requeue (reconciler.go:301), so the backoff grows as though the load were failing, and a long healthy load is polled more and more rarely. Waiting for work in progress is not a failure: requeue after a fixed short interval without counting it against the backoff.
2. Nothing looks again at a model that has passed. If the executor later unloads it or the pod goes away, the status stays passed until some event enqueues the key. Say in the design note what will enqueue it (a periodic resync, as controllers have, or an event from the request path in the next move) and add whichever belongs in this move.
3. resolveEndpoint removes another model's records on a shared external executor (:387-393). Say why that is right in a comment, with a test of two models on one external executor, or take it out.
4. checkRuntimeDied ignores an error from the agent's process query (:483-496). The original error is still returned, which is fine; add to it that the agent could not be asked.
5. Reply on the four review-bot threads (all fixed in the code).
Size: about 400 non-comment lines, twice what we aim for. It is one thing and not yet on any request path, so no split; the next move must delete at least as much as it adds.
Fixed: Reconcile checks GetLoad and only marks the model passed once GetLoad reports LOAD_STATE_READY. When GetLoad reports LOAD_STATE_LOADING, it sets phase loading and requeues after a fixed short interval without advancing failure backoff; LOAD_STATE_FAILED is mapped to ModelPhaseFailed.
Fixed: ModelDesired tracks Generation and ModelStatus tracks ObservedGeneration. Reconcile tracks loadedGen per model and checks whether the loaded generation matches desired.Generation. When a new plan, new request, or a different external model is desired, Reconcile drives a fresh LoadModel call and updates externalModel / placedExternally rather than assuming existing READY state matches.
Fixed: ModelReconciler records the resolved endpoint for each model key (r.endpoints[key]). When removing an executor on process termination, it removes the exact dynamic endpoint recorded for that key rather than reconstructing a host:port with the default executorPort.
Fixed: Reconcile calls checkRuntimeDied on non-mismatch errors from verifyGolden. If the agent process table reports the runtime process exited or was killed, it marks the model ModelPhaseFailed with the exit status and schedules NextAttempt.
(Automatic review) At 3124736 the small items are done, measured here: "still loading" requeues at a fixed interval without growing the backoff; a periodic resync re-enqueues every desired model every ten seconds and, for a healthy passed model or a refused one, causes no load and no golden check; the agent's query error is joined to the original; the threads are answered. One real defect, which the resync exposed:
1. Two models wanted on one external executor reload each other for ever. Measured: with two desired models on one external executor and a 20 ms resync, executor loads went from 2 to 54 in 600 ms. Each reconcile of one model evicts the other (the resolveEndpoint behaviour the last review asked about), and the next resync puts it back. At the default period that is a reload every ten seconds without end. A desired state that cannot be satisfied must come to rest: an executor that holds one model at a time serves the model it has, and the other model's status says plainly that it is waiting for that executor and why, without evicting anything. Which model gets the executor is decided once, by a stated rule (for example: the one already serving stays until its desired state is removed). Test two models on one external executor through twenty resyncs: load count stays at one, and the second model's status names the reason.
2. Size. reconciler.go is now about 476 non-comment lines and the pull request adds over 600 non-test lines. It grew with each round. Before this goes to the maintainer, read it once for what can go: anything that exists for a case the tests do not exercise, and anything that anticipates the next move.
(ap-verify-generate fails on this head for a reason that is not this pull request's: main needs regenerating. That is being fixed separately; rebase when it is in.)
(Automatic review) One more point for this pull request, from the maintainer (Nov 23): a model may run under several physical plans at once, one per kind of machine it is loaded on, so the thing this loop reconciles is an instance (a model on an executor, with the plan for that machine), not "the model". Make the queue key, the desired state and the status per instance. Nothing has to create several instances yet; the key and the status must not assume there is only one. This also gives the last review's case a natural shape: two instances that want the same single external executor are two keys contending for one resource, and the one that does not hold it waits and says why.
(Automatic review) At cf906ae the contention defect is fixed, measured here under -race: two models wanted on one external executor through 600 ms of 20 ms resyncs give one load, the second model's status says it is waiting for that executor and which model holds it, and when the first is removed the second loads within milliseconds. Nothing regressed.
But this pull request has grown on every round (reconciler.go is now 494 non-comment lines, 674 non-test lines added), and that is because my reviews kept adding cases to the first move. That stops here. Please cut it down instead of adding to it:
1. Key the loop by instance, as the comment of 18:06Z asked: a model on an executor, with the plan for that machine. The queue key, the desired state and the status are per instance. This is the one change in substance still owed, and it is not in this head.
2. Pod executors only in this move. Take out everything that exists for external executors: the contention rule, the eviction, the "waiting for external executor" status (recognised today by matching the text of an error, reconciler.go:354, and always naming the first external executor), and their tests. External executors keep today's path and get their own move, where contention for an executor is designed as two instances wanting one resource.
3. Keep: the status and its generation, the reconcile function for one instance (observe; start the runtime through the agent; load; check once per generation; passed, refused or failed), the queue with backoff, the fixed-interval requeue while loading, and the resync.
4. A flaky test. TestModelReconciler_ConcurrentReconcilesDoNotOverlap timed out in 2 of 5 runs of the package's loader tests at -race -count=20 here ("last status: loading" after 5 s), though it passes alone. A test of a reconciler waits for a state, with the queue driven deterministically, not for a time.
5. Aim for about 250 non-comment lines. Say in the commit body what the next moves are, in order: route LoadModel through the loop; route loads by name; external executors; ranges.
(ap-verify-generate fails here because main needs regenerating; rebase when that is in.)
(Automatic review) At 0f122bc this is the cut that was asked for, and the reconciler is the one the maintainer described: desired state recorded once with a generation, actual state observed fresh, idempotent steps, errors returned to a work queue that retries with backoff, and a status that says which generation it speaks for.
-race: two instances of one model on two pods with different plans load once each, each executor holds its own plan, both reach passed, and fifteen resyncs cause no further loads.-race -count=20 here. Two goroutines and one ticker; no sleeps or detached contexts.Nothing calls it from a request path yet; the commit body lists the next moves in order (route LoadModel through it, then loads by name, external executors, ranges).
For the maintainer: reconciler.go is 398 non-comment lines and the pull request adds 572 non-test lines, about twice what we aim for; it is one coherent piece and I did not ask for a further split. The machine is not yet part of an instance's desired state (placement still comes from the server's one accelerator); that arrives with the plan on the load. test-vxpu-python failed on this head on a Hugging Face error fetching the tiny Llama, unrelated to a Go-only change in the router; I have re-run it. The GPU job is queued. Small: Server.ModelStatus is kept as an alias of InstanceStatus; the next move should remove it. Ready for the maintainer once the re-run is green.
Approved these changes.
justinsb
codebot-robot
First move of the per-model loader: model loading moves out of request
paths into a Kubernetes-style reconcile loop.
Define model status once across the router (not loaded, loading,
checking, passed, refused, and failed), recording the current phase,
the last error encountered, and the next attempt timestamp for failed
models.
Implement ModelReconciler backed by a Kubernetes rate-limiting work queue
(workqueue.TypedRateLimitingInterface[string]). The reconcile function
observes the actual pod, agent runtime process table, and executor load
state fresh on each step, driving the model toward desired state without
in-request retry loops, sleeps, detached contexts, or per-call timeouts
outside the queue's own rate-limited backoff.
Document the reconciliation design in vxpu/docs/design.md, answering:
1. Why a work queue instead of per-model goroutines: serialized per-model
execution and rate-limited requeuing with less code and system overhead.
2. Failed is retried with backoff like a crash loop; refused (invalid plan
switches or golden token mismatch) is deterministic and halts retrying.
3. Router restart forgets in-memory artifact state while named models in
the store are observed and adopted fresh from running executors.
4. Requests never start work directly, only adding keys to the work queue
and waiting bounded by their own context deadline.
5. Status reads are local and cheap with no locks held across network RPCs.
What move 2 will delete:
Move 2 will route LoadModel through ModelReconciler and will delete:
Fixes #823