> ## Documentation Index
> Fetch the complete documentation index at: https://docs.m-star.org/llms.txt
> Use this file to discover all available pages before exploring further.

# Maintain a legacy resource

> Read a hand-written NodeResourceSpec and trace its binding, step, and deployment settings.

Some older model packages still construct engine resources directly in `get_node_resources()`. Check the package’s entry in [test\_state\_lint.py](https://github.com/mstar-project/mstar/blob/main/test/modular/test_state_lint.py). Its `UNPORTED` list names the legacy packages, and the lint refuses `get_node_resources()` in a ported file. For a new model, use [declare\_state](https://docs.m-star.org/contributing/state-contract.md).

## Identify the resource

Start at the model’s `get_node_resources()`. Each [NodeResourceSpec](https://github.com/mstar-project/mstar/blob/main/mstar/engine/resources/spec.py) names a `resource_key`, the `nodes` sharing the resource, and any dependencies. A paged attention spec and a positions spec both depend on their KV pool. A worker binds only the resources its node declares. The YAML’s `resources:` overrides use those same keys.

Most legacy specs have a counterpart in the [state contract](https://docs.m-star.org/contributing/state-contract.md#names). Check the geometry and lifetime before replacing one. These examples need particular care:

| Existing resource | Semantics to preserve |
| - | - |
| [DSASpec](https://github.com/mstar-project/mstar/blob/main/mstar/engine/resources/dsa/config.py) and MLA | Sparse attention uses an MLA cache and an indexer that selects the keys for each query. A dense causal read would change the computation. On the state contract, a latent array's `Selected(of=)` read and its `TopK` key array declare it ([DSA](https://docs.m-star.org/contributing/state-contract.md#attention)). |
| [KDA](https://github.com/mstar-project/mstar/blob/main/mstar/engine/resources/linear_attn/kda.py) | Kimi delta attention keeps recurrent state and uses a model-specific update. Verify the state after several steps, including a batched step. On the state contract, a `Value`'s `KimiDelta` update declares it ([Recurrent state](https://docs.m-star.org/contributing/state-contract.md#recurrent-state)). |
| [Ring KV](https://github.com/mstar-project/mstar/blob/main/mstar/engine/resources/kv/ring/manager.py) | A fixed frame ring has capacity per session and layer. FlexAttention reads its ordered frame layout. |
| [Rolling KV](https://github.com/mstar-project/mstar/blob/main/mstar/engine/resources/kv/rolling/config.py) | Keeps a request’s sink and most recent window contiguous in a shared startup pool. The model supplies the attention. A bounded ring can keep equivalent positions with a different physical layout and its own read. |
| [Block-causal ragged attention](https://github.com/mstar-project/mstar/blob/main/mstar/engine/resources/attn/ragged/block_causal.py) | A query can attend throughout its block and preceding blocks. A key-prefix mask instead limits a row to the valid keys of its segment. Test partially padded final blocks. |
| [Block-causal paged attention](https://github.com/mstar-project/mstar/blob/main/mstar/engine/resources/attn/block_causal.py) | The same block-level masking rule applies over persisted KV as new tokens arrive. Per-step cache writes and the read must agree on block boundaries. |

A non-causal read between two spans pairs a request’s query span with its own key span. When batching requests, preserve both identities. A custom bounded read may need source, relative bias, or another field outside the declared window’s default behavior. [Resource specifications](https://github.com/mstar-project/mstar/tree/main/mstar/engine/resources)

## Trace a step

`declare_step` names the operation for each resource key, such as a KV write and the attention over it. Read the actual engine step before changing a model that implements speculative verification. GLM-5.2’s verifier can commit an entire draft block and then use `correct_len` before the next admission to remove its rejected suffix. Both the KV cache and its position counter must move. Performing the correction between admission and commit leaves an inconsistent reservation. [KV manager](https://github.com/mstar-project/mstar/blob/main/mstar/engine/resources/kv/manager.py) · [GLM implementation](https://github.com/mstar-project/mstar/tree/main/mstar/model/glm52)

A step that combines prefill and decode may run different kernels for each sub-batch. The spec’s `combined_splits()` describes that split. If a replacement merges the rows into one plan, check the per-row positions and output order against separate runs.

## Follow the binding

Find where the submodule and its layers take their resource handles. An older attention layer can bind a label for the step and set the layer index before calling its attention wrapper. A fused writer can ask `kv.write_target(layer_idx, label)` for the layer’s NHD pages, the destination slots, and the number of real tokens to write. A padded capture must stop writing at that count. Consult the [legacy forward helpers](https://github.com/mstar-project/mstar/blob/main/mstar/engine/resources/convenience.py) before changing an index or replacing a resource call.

A recurrent pool needs a separate slot per live row and a sink for padding when its gather/scatter helpers require one. A cacheless attention reads the current step’s ragged plan. A sequence shard supplies scatter and gather with the label of the split. Each of these has a distinct lifetime. Reuse an existing [bound state operation](https://docs.m-star.org/contributing/state-contract.md#names) when it expresses the same operation.

## Preserve layouts and captures

Legacy models return a `kv_layout` per label in `process_prompt`. The modern counterpart is `state_layout`. Carry over the prompt spans, which writes commit, growth per loop, scratch space, and the maximum retained length. A model that can stop short of its maximum iterations may reserve less than the loop limit suggests.

For a packed piecewise capture, an old ragged spec can supply `attn_key` to obtain the default non-causal row layout. A port that declares the segments explicitly must reproduce their lengths and labels, including padding. Compare the effective spec and per-walk steps before checking numerical output. [State port equivalence tests](https://github.com/mstar-project/mstar/blob/main/test/modular/test_state_ports.py)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.