vxpu/plan: three states in run record, carry segments, count not measured #773
🟠 Medium · behaviour — host_executions grows without bound when the engine runs without generate or chat
Whenever an External is bound, External.record_host_op appends a (body, rows) tuple to self.host_executions[(op, key)] on every vxpu::moe_experts and vxpu::engram_rows call. It does this whether or not run_record_file is set. The only thing that clears the dict is reset_host_executions(), and only Engine._generate_locked calls it (engine.py:1446-1447).
Engine.run_range is the pipeline range server that handles decode and prefill steps for a head engine. It enters external_scope() (engine.py:1208-1209) but never goes through _generate_locked. The same is true of a direct per-layer probe under external_scope(). On those engines the dict gains one tuple per expert or engram layer per step and is never cleared, so memory keeps growing for as long as the server runs.
On an engine that serves generate, the dict is cleared at the start of each request, but it still fills during that request even when no run record will ever be written. Recording only when run_record_file is set, or clearing at the start of each run_range call, would bound it.
_How often, as the check that scored this judged it: Every decode or prefill step served by a pipeline range server (run_range) adds about one tuple per MoE or engram layer, and nothing clears them for the life of the process, so any long-running range deployment builds up memory steadily._
<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/3bce4073e49e1292f617b7689c5d38f917265745/vxpu/python/vxpu/ops.py#L74-L84:
host_executions grows without bound when the engine runs without generate or chat
Whenever an External is bound, External.record_host_op appends a (body, rows) tuple to self.host_executions[(op, key)] on every vxpu::moe_experts and vxpu::engram_rows call. It does this whether or not run_record_file is set. The only thing that clears the dict is reset_host_executions(), and only Engine._generate_locked calls it (engine.py:1446-1447).
Engine.run_range is the pipeline range server that handles decode and prefill steps for a head engine. It enters external_scope() (engine.py:1208-1209) but never goes through _generate_locked. The same is true of a direct per-layer probe under external_scope(). On those engines the dict gains one tuple per expert or engram layer per step and is never cleared, so memory keeps growing for as long as the server runs.
On an engine that serves generate, the dict is cleared at the start of each request, but it still fills during that request even when no run record will ever be written. Recording only when run_record_file is set, or clearing at the start of each run_range call, would bound it.
_How often, as the check that scored this judged it: Every decode or prefill step served by a pipeline range server (run_range) adds about one tuple per MoE or engram layer, and nothing clears them for the life of the process, so any long-running range deployment builds up memory steadily._
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 — tree.html renders an empty run badge when a record-only tree has a site whose RecordBody is ""
AttachPlan used to set cs.RecordBody only when rs.Body != "". It now always sets cs.RecordBody = &rs.Body for a matched record site (vxpu/pkg/kernelplan/segment.go:233), so a site that ran the default implementation now carries a non-nil pointer to "".
The PR updated the plan branches of tree.html to handle this. Line 885 now shows "default implementation" and line 891 adds a (ne .GetRecordBody "") check. The no-plan branch at line 903 still tests only {{if .RecordBody}}. In text/template/html/template a non-nil pointer counts as true, so the test passes. When you render a record without --plan, every default-implementation site gets <span class="badge badge-body"><span class="badge-label">run</span></span> with nothing after the run label.
Line 900 (the "not covered in plan" branch) has the same shape but can't fire with a non-nil RecordBody. When both a plan and a record are loaded, segment.go:184-188 rejects any record site that isn't listed in the plan. So a call site with a record entry always has a PlanSite.
The fix is to give line 903 the same guard as line 891, or to show "default implementation" there as line 885 does.
_How often, as the check that scored this judged it: Every record-only render (plan tree --record without --plan) of a model that has any call site without a catalog body hits this, for each such site._
<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/3bce4073e49e1292f617b7689c5d38f917265745/vxpu/cmd/vxpu/treeui/tree.html#L901-L905:
tree.html renders an empty run badge when a record-only tree has a site whose RecordBody is ""
AttachPlan used to set cs.RecordBody only when rs.Body != "". It now always sets cs.RecordBody = &rs.Body for a matched record site (vxpu/pkg/kernelplan/segment.go:233), so a site that ran the default implementation now carries a non-nil pointer to "".
The PR updated the plan branches of tree.html to handle this. Line 885 now shows "default implementation" and line 891 adds a (ne .GetRecordBody "") check. The no-plan branch at line 903 still tests only {{if .RecordBody}}. In text/template/html/template a non-nil pointer counts as true, so the test passes. When you render a record without --plan, every default-implementation site gets <span class="badge badge-body"><span class="badge-label">run</span></span> with nothing after the run label.
Line 900 (the "not covered in plan" branch) has the same shape but can't fire with a non-nil RecordBody. When both a plan and a record are loaded, segment.go:184-188 rejects any record site that isn't listed in the plan. So a call site with a record entry always has a PlanSite.
The fix is to give line 903 the same guard as line 891, or to show "default implementation" there as line 885 does.
_How often, as the check that scored this judged it: Every record-only render (plan tree --record without --plan) of a model that has any call site without a catalog body hits this, for each such site._
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>
_Anchored on the nearest line this diff shows in this file rather than where it points: GitHub only accepts a review comment on a line this pull request's diff shows, and vxpu/cmd/vxpu/treeui/tree.html L901–L905 is not one. It says nothing about this line._
Fixed: gated recording on self.recording = bool(self.run_record_file) so no recording occurs when run records are disabled, stored row counts as bounded sets per body, and cleared them on _generate_locked and run_range.
Fixed: updated tree.html to iterate over .ExecutedBodies directly and render default implementation or did not run, avoiding empty run badges in record-only views.
🔴 High · behaviour — Host-op node_name argument is included in NativeNode.code, breaking native package deduplication across layers
This change appends a trailing node_name: str to every vxpu::moe_experts and vxpu::engram_rows call:
deepseek_v41.py:214 adds it at export as f"moe_experts_{layer.layer_id}".engine.py:1027-1035 and segments.py:231-254 rewrite it to the FX node.name (moe_experts, moe_experts_1, ...).NativeNode.__init__ builds the package's cache code by dropping only int arguments from the host call:
self.code = aoti.canonical_code(sub, args_of={call: tuple(a for a in call.args if not isinstance(a, int))})
canonical_code keeps literal arguments in its output (aoti.py:150-152), so the per-layer name string ends up in self.code. That code is what native_package passes as code= to packages.path. As a result, every experts layer gets its own cache key and its own AOTInductor package. Before this change, all layers shared one package. Two things say they should share one:
nodes.py:207-208: "every layer's node with the same constants is the same package";nodes.py:38-41: "every experts layer of a model is one package, built once".The name is not needed at this point. NativeNode.forward passes only tensor arguments to the lowered function (nodes.py:219). Once the keys differ:
nodeserver.start (nodeserver.py:95-107) and StepGraph.build_packages (stepgraph.py:625-635) compile one package per layer.len(experts) != 1 check in vectors_test.py:2243 fails.nodeserver and the engine can no longer share packages with each other. nodeserver reads the export-time name moe_experts_<layer_id> from decode.pt2 through decode_split, while the engine rewrites it to the FX node name._How often, as the check that scored this judged it: Every native host-node build (node server start, and step-graph package builds for engines with host nodes) on any model with more than one experts layer, which is every multi-layer MoE model, hits this every time packages are built._
Suggested replacement for vxpu/python/vxpu/nodes.py L210:
<pre>
self.code = aoti.canonical_code(sub, args_of={call: tuple(a for a in call.args if not isinstance(a, (int, str)))})
</pre>
<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/59ae9757b730ac273231ccb89cc7ab69cb207f45/vxpu/python/vxpu/nodes.py#L206-L212:
Host-op node_name argument is included in NativeNode.code, breaking native package deduplication across layers
This change appends a trailing node_name: str to every vxpu::moe_experts and vxpu::engram_rows call:
deepseek_v41.py:214 adds it at export as f"moe_experts_{layer.layer_id}".engine.py:1027-1035 and segments.py:231-254 rewrite it to the FX node.name (moe_experts, moe_experts_1, ...).NativeNode.__init__ builds the package's cache code by dropping only int arguments from the host call:
self.code = aoti.canonical_code(sub, args_of={call: tuple(a for a in call.args if not isinstance(a, int))})
canonical_code keeps literal arguments in its output (aoti.py:150-152), so the per-layer name string ends up in self.code. That code is what native_package passes as code= to packages.path. As a result, every experts layer gets its own cache key and its own AOTInductor package. Before this change, all layers shared one package. Two things say they should share one:
nodes.py:207-208: "every layer's node with the same constants is the same package";nodes.py:38-41: "every experts layer of a model is one package, built once".The name is not needed at this point. NativeNode.forward passes only tensor arguments to the lowered function (nodes.py:219). Once the keys differ:
nodeserver.start (nodeserver.py:95-107) and StepGraph.build_packages (stepgraph.py:625-635) compile one package per layer.len(experts) != 1 check in vectors_test.py:2243 fails.nodeserver and the engine can no longer share packages with each other. nodeserver reads the export-time name moe_experts_<layer_id> from decode.pt2 through decode_split, while the engine rewrites it to the FX node name._How often, as the check that scored this judged it: Every native host-node build (node server start, and step-graph package builds for engines with host nodes) on any model with more than one experts layer, which is every multi-layer MoE model, hits this every time packages are built._
It proposed this replacement for vxpu/python/vxpu/nodes.py L210:
self.code = aoti.canonical_code(sub, args_of={call: tuple(a for a in call.args if not isinstance(a, (int, str)))})
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>
_Anchored here rather than where it points: GitHub only accepts a review comment on a line this pull request's diff shows, and vxpu/python/vxpu/nodes.py L206–L212 is not one. It says nothing about this line._
🟠 Medium · behaviour — tree.html shows — in the Body column of UnmatchedMeasurements for every real run record
The Unmatched Measurements table still takes its Body column from .Body (vxpu/cmd/vxpu/treeui/tree.html:831). This change moves executed-body data off that field:
physplan.fill_run_record now calls site.ClearField("body") on every record site whenever executed_bodies is passed (vxpu/python/vxpu/physplan.py:146-157).site.executed_bodies, or the site gets site.not_measured = True.executed_bodies (vxpu/python/vxpu/engine.py:1535-1548).AttachPlan copies the record's PlanSite messages unchanged into tree.UnmatchedMeasurements (vxpu/pkg/kernelplan/segment.go:285-291). So on a record the engine produced, .Body is always empty, and the column always shows —.
Before this change, the record kept the body on the site, so the column showed what ran. The matched call-site branches were updated to read .ExecutedBodies and .NotMeasured (lines 925-933 and 938-947), but this table was not. The fix is to render the Body cell the same way as lines 938-947: show "not measured" when .NotMeasured is set, "did not run" when .ExecutedBodies is empty, and otherwise list each executed body.
_How often, as the check that scored this judged it: Every tree render with a record written by the engine that has at least one site not matched in the exported graph shows this, for every such row. Synthetic fixtures that set PlanSite.Body directly do not._
<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/59ae9757b730ac273231ccb89cc7ab69cb207f45/vxpu/cmd/vxpu/treeui/tree.html#L827-L835:
tree.html shows &mdash; in the Body column of UnmatchedMeasurements for every real run record
The Unmatched Measurements table still takes its Body column from .Body (vxpu/cmd/vxpu/treeui/tree.html:831). This change moves executed-body data off that field:
physplan.fill_run_record now calls site.ClearField("body") on every record site whenever executed_bodies is passed (vxpu/python/vxpu/physplan.py:146-157).site.executed_bodies, or the site gets site.not_measured = True.executed_bodies (vxpu/python/vxpu/engine.py:1535-1548).AttachPlan copies the record's PlanSite messages unchanged into tree.UnmatchedMeasurements (vxpu/pkg/kernelplan/segment.go:285-291). So on a record the engine produced, .Body is always empty, and the column always shows &mdash;.
Before this change, the record kept the body on the site, so the column showed what ran. The matched call-site branches were updated to read .ExecutedBodies and .NotMeasured (lines 925-933 and 938-947), but this table was not. The fix is to render the Body cell the same way as lines 938-947: show "not measured" when .NotMeasured is set, "did not run" when .ExecutedBodies is empty, and otherwise list each executed body.
_How often, as the check that scored this judged it: Every tree render with a record written by the engine that has at least one site not matched in the exported graph shows this, for every such row. Synthetic fixtures that set PlanSite.Body directly do not._
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>
_Anchored on the nearest line this diff shows in this file rather than where it points: GitHub only accepts a review comment on a line this pull request's diff shows, and vxpu/cmd/vxpu/treeui/tree.html L827–L835 is not one. It says nothing about this line._
🟠 Medium · behaviour — write_run_record marks host ops served by a remote node (and family-named sites) as "did not run" instead of not measured
vxpu/proto/plan/v1alpha1/plan.proto (lines 237–240) defines three states for a site, and puts "a host op served by a remote node" in state 3, not measured. vxpu/docs/design.md says the same thing: "Call sites with no execution observation, including kept ops and remote host ops, are reported as not measured".
Engine.write_run_record doesn't follow this. It adds a site to not_measured_sites only when site.kind is something other than SITE_KIND_EXPERT_OP / SITE_KIND_DRAFTER. Any expert or engram site with no recorded execution gets executed_bodies = [] and stays out of not_measured_sites. physplan.fill_run_record then sets not_measured = False, which is state 2, "Measured and did not run". The tree page shows that as did not run and counts it as a differing call site.
This is guaranteed when a layer or table is served remotely. ops.moe_experts returns remote(x_in, weights, indices) at ops.py:233-240, and ops.engram_rows returns remote(indices) at ops.py:477-483. Both returns come before any ext.record_host_op(...) call, so host_executions never gets an entry for that node.
The same thing happens to any PlanFile site whose id is not an FX node name. For example, vxpu plan emit produces family ids like layers.<N>.experts / layers.<N>.engram (pkg/kernelplan/plan.go:729,766), and record_host_op keys on node_name, so these ids never match.
Suggested fix: decide "measured" by whether the site is a host op that runs locally, not by its kind alone. Concretely, add the site to not_measured_sites when its node is in external.remote_nodes, or when the id is not a host node of the artifact.
_How often, as the check that scored this judged it: Every run record from a deployment that sets the plan's remote_nodes hits this, once per remotely served expert layer or engram table, and so does every record built from a plan whose sites use family ids. remote_nodes is a supported plan knob, wired up in engine.py:617,866 and tested in vectors_test.py:2277._
<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/59ae9757b730ac273231ccb89cc7ab69cb207f45/vxpu/python/vxpu/engine.py#L1519-L1534:
write_run_record marks host ops served by a remote node (and family-named sites) as "did not run" instead of not measured
vxpu/proto/plan/v1alpha1/plan.proto (lines 237–240) defines three states for a site, and puts "a host op served by a remote node" in state 3, not measured. vxpu/docs/design.md says the same thing: "Call sites with no execution observation, including kept ops and remote host ops, are reported as not measured".
Engine.write_run_record doesn't follow this. It adds a site to not_measured_sites only when site.kind is something other than SITE_KIND_EXPERT_OP / SITE_KIND_DRAFTER. Any expert or engram site with no recorded execution gets executed_bodies = [] and stays out of not_measured_sites. physplan.fill_run_record then sets not_measured = False, which is state 2, "Measured and did not run". The tree page shows that as did not run and counts it as a differing call site.
This is guaranteed when a layer or table is served remotely. ops.moe_experts returns remote(x_in, weights, indices) at ops.py:233-240, and ops.engram_rows returns remote(indices) at ops.py:477-483. Both returns come before any ext.record_host_op(...) call, so host_executions never gets an entry for that node.
The same thing happens to any PlanFile site whose id is not an FX node name. For example, vxpu plan emit produces family ids like layers.<N>.experts / layers.<N>.engram (pkg/kernelplan/plan.go:729,766), and record_host_op keys on node_name, so these ids never match.
Suggested fix: decide "measured" by whether the site is a host op that runs locally, not by its kind alone. Concretely, add the site to not_measured_sites when its node is in external.remote_nodes, or when the id is not a host node of the artifact.
_How often, as the check that scored this judged it: Every run record from a deployment that sets the plan's remote_nodes hits this, once per remotely served expert layer or engram table, and so does every record built from a plan whose sites use family ids. remote_nodes is a supported plan knob, wired up in engine.py:617,866 and tested in vectors_test.py:2277._
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 · wording — vxpu/docs/design.md says run records report compiled bodies for lowered call sites and keep PlanSite.body; the code does neither
This PR rewrote the run-record paragraph in vxpu/docs/design.md. Two of its claims don't match what the code ships:
1. Lowered call sites. The paragraph says "For lowered call sites, this names the body the compiled package was built with." In engine.py:1520-1533, only SITE_KIND_EXPERT_OP and SITE_KIND_DRAFTER sites get entries built from host_executions. Every other site, lowered ones included, gets executed_bodies[site.id] = [] and is added to not_measured_sites. plan.proto:218 agrees with the code: "Call sites that are not host ops are not measured and leave executed_bodies empty with not_measured set to true." So a lowered site never shows the body its compiled package was built with. It is reported as not measured.
2. Planned body. The paragraph says "The executor preserves the plan's planned choices… On PlanSite, the planner writes … and planned body." But physplan.fill_run_record calls site.ClearField("body") on every site whenever executed_bodies is not None (physplan.py:146-148). engine.py:1546 always passes a dict, so every run record the engine writes has body removed from every site.
Someone reading the run record by this paragraph will expect a lowered site to show what ran and to sit next to its planned body. They will get not_measured = true and no body at all. Either fix the paragraph to match the code, or keep body and drop the lowered-site sentence.
_How often, as the check that scored this judged it: Everyone who reads design.md to understand the run record hits this, and every run record the engine writes behaves as the code says, not as the paragraph says._
<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/59ae9757b730ac273231ccb89cc7ab69cb207f45/vxpu/docs/design.md#L288-L290:
vxpu/docs/design.md says run records report compiled bodies for lowered call sites and keep PlanSite.body; the code does neither
This PR rewrote the run-record paragraph in vxpu/docs/design.md. Two of its claims don't match what the code ships:
1. Lowered call sites. The paragraph says "For lowered call sites, this names the body the compiled package was built with." In engine.py:1520-1533, only SITE_KIND_EXPERT_OP and SITE_KIND_DRAFTER sites get entries built from host_executions. Every other site, lowered ones included, gets executed_bodies[site.id] = [] and is added to not_measured_sites. plan.proto:218 agrees with the code: "Call sites that are not host ops are not measured and leave executed_bodies empty with not_measured set to true." So a lowered site never shows the body its compiled package was built with. It is reported as not measured.
2. Planned body. The paragraph says "The executor preserves the plan's planned choices… On PlanSite, the planner writes … and planned body." But physplan.fill_run_record calls site.ClearField("body") on every site whenever executed_bodies is not None (physplan.py:146-148). engine.py:1546 always passes a dict, so every run record the engine writes has body removed from every site.
Someone reading the run record by this paragraph will expect a lowered site to show what ran and to sit next to its planned body. They will get not_measured = true and no body at all. Either fix the paragraph to match the code, or keep body and drop the lowered-site sentence.
_How often, as the check that scored this judged it: Everyone who reads design.md to understand the run record hits this, and every run record the engine writes behaves as the code says, not as the paragraph says._
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>
Fixed: removed the node_name argument from moe_experts and engram_rows, removed all graph passes in engine.py and segments.py, and reverted deepseek_v41.py back to main. The op records its executed body directly where chosen, and the engine maps step calls to the planner's host node names in sequence during decode.
Fixed: updated tree.html's UnmatchedMeasurements table to render .ExecutedBodies when present, badge 'did not run' when empty, and badge 'not measured' when .NotMeasured is set.
Fixed: updated write_run_record so only local host ops of the artifact are recorded or marked as 'did not run'; remote host ops served by node servers, family-named sites, and non-host ops are left out of executed_bodies and reported as 'not measured'.
Fixed: updated vxpu/docs/design.md to specify that run records report executed bodies for host ops under executed_bodies (with non-host ops reported as not measured, deferred to #790) and accurately reflect PlanSite field handling.
🔴 High · behaviour — Remote host calls shift step_host_calls positions and misattribute executed bodies to later sites
Engine._generate_scoped matches each decode step's recorded host-op executions (self.external.step_host_calls) to graph node names by position in self._host_node_names (engine.py:1702-1707).
self._host_node_names lists every moe_experts and engram_rows node in the decode graph (engine.py:1028-1031). That includes nodes a node server serves (self.external.remote_nodes). But in ops.moe_experts (ops.py:234-241) and ops.engram_rows (ops.py:476-482), a remote call returns before ext.record_host_op(...) runs, so a remote node adds nothing to step_host_calls.
So when any host node is remote, step_host_calls is shorter than self._host_node_names. enumerate(self.external.step_host_calls) then gives every later local call the index of an earlier node. Two things follow:
1. A local node's execution is credited to an earlier node name, sometimes the remote node's own name. write_run_record then drops that name from local_host_nodes, and the data goes with it.
2. The last k local host nodes, where k is the number of remote nodes ahead of them, get no entry in host_executions. The run record reports them with executed_bodies = [], which reads as "did not run".
The same mismatch probably happens when self.plan["layer_range"] is set. There the dataflow runner runs only the slice's host nodes (engine.py:1094-1096), while self._host_node_names still holds every host node in the full decode graph.
This follows from the round-2 change that removed the node_name argument and maps step calls to host node names in order. The fix is to stop relying on position. Either record (op_kind, layer_or_table, body, rows) in record_host_op and key on (kind, index), or build _host_node_names from only the local host nodes that actually run in this engine. Either way, each call stays matched to its own node no matter which other nodes are remote.
_How often, as the check that scored this judged it: Every run record written by an engine whose plan sets remote_nodes (a supported knob, tested in vectors_test.py:2277) hits this on every decode step whenever a remote node comes before a local host node in the graph; single-node local runs line up one-to-one and are not affected._
<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/bb4660a959aeeb8752364ace389821ba81cf88e2/vxpu/python/vxpu/engine.py#L1701-L1708:
Remote host calls shift step_host_calls positions and misattribute executed bodies to later sites
Engine._generate_scoped matches each decode step's recorded host-op executions (self.external.step_host_calls) to graph node names by position in self._host_node_names (engine.py:1702-1707).
self._host_node_names lists every moe_experts and engram_rows node in the decode graph (engine.py:1028-1031). That includes nodes a node server serves (self.external.remote_nodes). But in ops.moe_experts (ops.py:234-241) and ops.engram_rows (ops.py:476-482), a remote call returns before ext.record_host_op(...) runs, so a remote node adds nothing to step_host_calls.
So when any host node is remote, step_host_calls is shorter than self._host_node_names. enumerate(self.external.step_host_calls) then gives every later local call the index of an earlier node. Two things follow:
1. A local node's execution is credited to an earlier node name, sometimes the remote node's own name. write_run_record then drops that name from local_host_nodes, and the data goes with it.
2. The last k local host nodes, where k is the number of remote nodes ahead of them, get no entry in host_executions. The run record reports them with executed_bodies = [], which reads as "did not run".
The same mismatch probably happens when self.plan["layer_range"] is set. There the dataflow runner runs only the slice's host nodes (engine.py:1094-1096), while self._host_node_names still holds every host node in the full decode graph.
This follows from the round-2 change that removed the node_name argument and maps step calls to host node names in order. The fix is to stop relying on position. Either record (op_kind, layer_or_table, body, rows) in record_host_op and key on (kind, index), or build _host_node_names from only the local host nodes that actually run in this engine. Either way, each call stays matched to its own node no matter which other nodes are remote.
_How often, as the check that scored this judged it: Every run record written by an engine whose plan sets remote_nodes (a supported knob, tested in vectors_test.py:2277) hits this on every decode step whenever a remote node comes before a local host node in the graph; single-node local runs line up one-to-one and are not affected._
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 — self.external.recording starts True and is never reset on the run_range path, so step_host_calls grows without bound when VXPU_RUN_RECORD is set
This is the Round 1 finding ("host_executions grows without bound when the engine runs without generate or chat") one round on. In reply you said recording is now gated and the record is cleared on _generate_locked and run_range. The gating is in. The clearing in run_range is not, and the gate itself is set open at construction.
Engine.__init__ sets self.external.recording = bool(self.run_record_file) (engine.py:582). Any engine built with run_record_file, or in a process that has VXPU_RUN_RECORD set (engine.py:470-471), starts out recording._generate_scoped closes the gate, at engine.py:1718.run_range (engine.py:1200-1215) never calls reset_host_executions() and never sets recording.So on a range-server engine (rangeserver.py:79, engine.py:1856), every moe_experts call reaches ext.record_host_op (ops.py:255-256, ops.py:262-263) and appends a (body, rows) tuple to step_host_calls (ops.py:85). The same goes for engram_rows (ops.py:486). Nothing clears that list for the life of the process.
A generate stream can also leave the gate open. If the caller closes the stream at the yield on engine.py:1691, or _decode_run or logits_sink raises, line 1718 never runs because there is no try/finally. Any later run_range call on that engine then accumulates the same way.
The generate path itself stays bounded. _generate_locked resets at 1452 and the loop resets again at 1687, so the only gap is the one above.
A fix that closes both routes:
recording = False.recording = True … False in try/finally.step_host_calls at the top of run_range, or leave recording off on that path._How often, as the check that scored this judged it: Any pipeline range-server engine running with VXPU_RUN_RECORD/run_record_file set adds one tuple per MoE or engram layer per step on every run_range call, as does any engine whose generate stream was abandoned or raised mid-decode; engines without a run record configured are unaffected._
<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/bb4660a959aeeb8752364ace389821ba81cf88e2/vxpu/python/vxpu/engine.py#L581-L584:
self.external.recording starts True and is never reset on the run_range path, so step_host_calls grows without bound when VXPU_RUN_RECORD is set
This is the Round 1 finding ("host_executions grows without bound when the engine runs without generate or chat") one round on. In reply you said recording is now gated and the record is cleared on _generate_locked and run_range. The gating is in. The clearing in run_range is not, and the gate itself is set open at construction.
Engine.__init__ sets self.external.recording = bool(self.run_record_file) (engine.py:582). Any engine built with run_record_file, or in a process that has VXPU_RUN_RECORD set (engine.py:470-471), starts out recording._generate_scoped closes the gate, at engine.py:1718.run_range (engine.py:1200-1215) never calls reset_host_executions() and never sets recording.So on a range-server engine (rangeserver.py:79, engine.py:1856), every moe_experts call reaches ext.record_host_op (ops.py:255-256, ops.py:262-263) and appends a (body, rows) tuple to step_host_calls (ops.py:85). The same goes for engram_rows (ops.py:486). Nothing clears that list for the life of the process.
A generate stream can also leave the gate open. If the caller closes the stream at the yield on engine.py:1691, or _decode_run or logits_sink raises, line 1718 never runs because there is no try/finally. Any later run_range call on that engine then accumulates the same way.
The generate path itself stays bounded. _generate_locked resets at 1452 and the loop resets again at 1687, so the only gap is the one above.
A fix that closes both routes:
recording = False.recording = True … False in try/finally.step_host_calls at the top of run_range, or leave recording off on that path._How often, as the check that scored this judged it: Any pipeline range-server engine running with VXPU_RUN_RECORD/run_record_file set adds one tuple per MoE or engram layer per step on every run_range call, as does any engine whose generate stream was abandoned or raised mid-decode; engines without a run record configured are unaffected._
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 — StepGraph decode and zero-step generations record no host executions, so every local host op is reported as "did not run"
write_run_record treats every local host-op site with no entry in self.external.host_executions as measured. It sets executed_bodies[site.id] = [] (engine.py:1540-1541). physplan.fill_run_record then writes not_measured = False (physplan.py:149-150). That is state 2 in plan.proto:235-237, "Measured and did not run", which the tree page counts as a differing call site. The only thing that fills host_executions is the Python ops.moe_experts / ops.engram_rows calling record_host_op, which the decode loop then copies over (engine.py:1702-1707). Two common paths never reach those Python ops:
1. plan["step_graph"]
- self._decode_run is a StepGraph (engine.py:1112-1114).
- StepGraph.forward sends only self.steps == 1 through the Python runner (stepgraph.py:447-449). self.steps is set once in __init__ (stepgraph.py:419) and never reset.
- Every later forward replays the captured CUDA graph. The host nodes run in the C++ StepHost over the native packages (stepgraph.py:458-459, 791-805), and nothing calls record_host_op.
- _generate_locked clears host_executions at the start of each request (engine.py:1687). So on every generate call after the engine's very first decode forward, step_host_calls stays empty. Every local host op in the model is then written as "did not run" even though it ran on every step.
- The engine expects run records with a StepGraph: engine.py:1677-1681 computes phase_k_start for exactly that case.
2. No decode step
- When the first token picked after prefill is EOS (engine.py:1692-1694), the cache is already full (engine.py:1695-1696), or max_tokens_to_generate == 0, the loop never calls _decode_run.
- Nothing was observed, yet every local host site is still reported as measured and did not run.
This is the same pattern as the round-2 finding on write_run_record, where sites served by a remote node were reported as "did not run" instead of not measured. That fix decides "measured" by whether a site is a local host op of the artifact. It should be decided by whether this run could observe the site at all. The structural fix is to fill executed_bodies only when at least one decode step went through the Python ops. One way: count the steps whose step_host_calls were recorded, and leave every site out (so it becomes not_measured) when that count is zero or when _decode_run is a StepGraph past its first step. Patching each path separately would leave the next one, such as the dataflow runner, with the same problem.
_How often, as the check that scored this judged it: Every run record from a step-graph deployment hits this on every generate call after the first decode forward, and any run on any configuration whose first token is EOS or that hits the cache limit hits it too._
<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/bb4660a959aeeb8752364ace389821ba81cf88e2/vxpu/python/vxpu/engine.py#L1532-L1542:
StepGraph decode and zero-step generations record no host executions, so every local host op is reported as "did not run"
write_run_record treats every local host-op site with no entry in self.external.host_executions as measured. It sets executed_bodies[site.id] = [] (engine.py:1540-1541). physplan.fill_run_record then writes not_measured = False (physplan.py:149-150). That is state 2 in plan.proto:235-237, "Measured and did not run", which the tree page counts as a differing call site. The only thing that fills host_executions is the Python ops.moe_experts / ops.engram_rows calling record_host_op, which the decode loop then copies over (engine.py:1702-1707). Two common paths never reach those Python ops:
1. plan["step_graph"]
- self._decode_run is a StepGraph (engine.py:1112-1114).
- StepGraph.forward sends only self.steps == 1 through the Python runner (stepgraph.py:447-449). self.steps is set once in __init__ (stepgraph.py:419) and never reset.
- Every later forward replays the captured CUDA graph. The host nodes run in the C++ StepHost over the native packages (stepgraph.py:458-459, 791-805), and nothing calls record_host_op.
- _generate_locked clears host_executions at the start of each request (engine.py:1687). So on every generate call after the engine's very first decode forward, step_host_calls stays empty. Every local host op in the model is then written as "did not run" even though it ran on every step.
- The engine expects run records with a StepGraph: engine.py:1677-1681 computes phase_k_start for exactly that case.
2. No decode step
- When the first token picked after prefill is EOS (engine.py:1692-1694), the cache is already full (engine.py:1695-1696), or max_tokens_to_generate == 0, the loop never calls _decode_run.
- Nothing was observed, yet every local host site is still reported as measured and did not run.
This is the same pattern as the round-2 finding on write_run_record, where sites served by a remote node were reported as "did not run" instead of not measured. That fix decides "measured" by whether a site is a local host op of the artifact. It should be decided by whether this run could observe the site at all. The structural fix is to fill executed_bodies only when at least one decode step went through the Python ops. One way: count the steps whose step_host_calls were recorded, and leave every site out (so it becomes not_measured) when that count is zero or when _decode_run is a StepGraph past its first step. Patching each path separately would leave the next one, such as the dataflow runner, with the same problem.
_How often, as the check that scored this judged it: Every run record from a step-graph deployment hits this on every generate call after the first decode forward, and any run on any configuration whose first token is EOS or that hits the cache limit hits it too._
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 — write_run_record reloads and re-splits decode.pt2 from disk on every generate to map host nodes the engine already knows
At the end of every generate, write_run_record runs nodes.decode_split(self.artifact_dir). It does this whenever a plan file is set and self.external.remote_nodes is non-empty. That call runs torch.export.load(.../decode.pt2) and segments.split_at_host_ops(...). The only reason is to find which host-op FX node names belong to remote (collection, index) pairs and drop them from local_host_nodes.
The engine already has that mapping in memory:
_build walks self._decode.graph.nodes (engine.py:1028-1031) to build self._host_node_names._connect_remote_nodes already runs nodes.host_calls(nodes.decode_split(self.artifact_dir)) once at startup (engine.py:893).So a full program deserialise and graph split is repeated after every request. Two ways to fix it:
{node name: (collection, index)} map from _connect_remote_nodes, and store the set of remote node names once.(n.name, (LOWERINGS[_host_op(n.target)][0], int arg)) while walking the graph in _build.Either way, write_run_record can filter in memory. Separately, the reload sits inside except Exception: pass. If it fails, remote nodes stay in local_host_nodes with nothing to say so, and they are reported as local sites with empty executed_bodies.
_How often, as the check that scored this judged it: Every generate call on an engine with run_record_file, a plan file and at least one configured remote node pays one extra decode.pt2 load and split; runs without remote nodes skip 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/bb4660a959aeeb8752364ace389821ba81cf88e2/vxpu/python/vxpu/engine.py#L1515-L1532:
write_run_record reloads and re-splits decode.pt2 from disk on every generate to map host nodes the engine already knows
At the end of every generate, write_run_record runs nodes.decode_split(self.artifact_dir). It does this whenever a plan file is set and self.external.remote_nodes is non-empty. That call runs torch.export.load(.../decode.pt2) and segments.split_at_host_ops(...). The only reason is to find which host-op FX node names belong to remote (collection, index) pairs and drop them from local_host_nodes.
The engine already has that mapping in memory:
_build walks self._decode.graph.nodes (engine.py:1028-1031) to build self._host_node_names._connect_remote_nodes already runs nodes.host_calls(nodes.decode_split(self.artifact_dir)) once at startup (engine.py:893).So a full program deserialise and graph split is repeated after every request. Two ways to fix it:
{node name: (collection, index)} map from _connect_remote_nodes, and store the set of remote node names once.(n.name, (LOWERINGS[_host_op(n.target)][0], int arg)) while walking the graph in _build.Either way, write_run_record can filter in memory. Separately, the reload sits inside except Exception: pass. If it fails, remote nodes stay in local_host_nodes with nothing to say so, and they are reported as local sites with empty executed_bodies.
_How often, as the check that scored this judged it: Every generate call on an engine with run_record_file, a plan file and at least one configured remote node pays one extra decode.pt2 load and split; runs without remote nodes skip 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>
Fixed: each host segment is wrapped by _HostSegment around that call, binding execution recording directly to that segment's planned site name. Remote host ops record nothing into last_host_call and do not shift any other host op.
Fixed: self.external.recording starts False, is activated strictly during decode wrapped in try/finally, and remains False on the run_range path.
Fixed: write_run_record populates executed_bodies only when decode steps were observed through Python ops. When 0 decode steps run (e.g. EOS on step 0 or cache limit) or when StepGraph replayed CUDA graphs past its first step, all sites are reported as not_measured = True.
Fixed: eliminated the redundant decode.pt2 reload and split in write_run_record. Remote host node names are recorded once during initialization, and write_run_record reads local host segments directly from the in-memory engine structures without swallowing exceptions.
justinsb
codebot-robot
Fixes #772