Skip to content

feat: add model state artifacts linked through subject - #240

Open
JGalego wants to merge 4 commits into
modelpack:mainfrom
JGalego:feat/model-state-artifacts
Open

JGalego wants to merge 4 commits into
modelpack:mainfrom
JGalego:feat/model-state-artifacts

Conversation

@JGalego

@JGalego JGalego commented Nov 12, 2026 •

Copy link
Copy Markdown

Description

Adds OCI artifacts for runtime state, such as prompt caches and saved conversations.

  • Manifest: application/vnd.cncf.model.state.manifest.v1+json with a required subject referencing the model artifact's manifest.
  • Config: application/vnd.cncf.model.state.config.v1+json with required format (encoding and version) and tokens, and optional precision.
  • Layers: application/vnd.cncf.model.state.v1.raw, .tar, .tar+gzip, and .tar+zstd.
  • Discovery: OCI referrers API with the referrers tag schema as a fallback.

Adds Go types and constants, a JSON schema, typed config validation, and tests for invalid configs and the documentation example.

State encoding is runtime-specific and identified by format. Loading rules:

  • A state MUST NOT be loaded for a model other than the one its subject references, or by a runtime that does not support its format.
  • A runtime SHOULD produce the same output as it would by processing the state's tokens without the state.
  • Runtimes SHOULD load only states they trust, not every state listed as a referrer of the model.

States built from images, audio or other non-token input, or with an adapter applied, are out of scope. Existing media types and the model config schema are unchanged.

Related Issue

Closes #239

Motivation and Context

ModelPack does not currently define how to package reusable runtime state. This supports two use cases:

  • Replicas, including new ones during autoscaling, load a precomputed prompt cache instead of reprocessing a shared prompt or document.
  • A saved conversation resumes on another machine.

Linking through subject leaves the model artifact unchanged and lets multiple states be published independently. As discussed on #60, the doc notes that this link is advisory.

This PR proposes defining state artifacts in ModelPack rather than a separate spec.

Define an artifact for state that a runtime builds while running a
model, such as a prompt cache or a saved conversation. Its manifest
references the model artifact through subject, and its config records
the state's format, the tokens it was built from and, optionally, its
precision.

Refs modelpack#239

Signed-off-by: João Galego <jgalego1990@gmail.com>
Add the artifact, config and layer media types for model state
artifacts, a State type for the config, and a JSON schema registered
under ValidatorMediaTypeModelStateConfig. As with model configs, the
validator decodes a state config into its Go type before validating it
against the schema.

Refs modelpack#239

Signed-off-by: João Galego <jgalego1990@gmail.com>
@JGalego
JGalego force-pushed the feat/model-state-artifacts branch from 1435155 to dc063a4 Compare November 12, 2026 10:56
@JGalego
JGalego marked this pull request as ready for review November 12, 2026 16:00

@aftersnow aftersnow left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please align the Go state validator with the published schema and clarify how runtimes establish trust in a state before loading it.

Comment thread schema/validator.go
func validateState(buf []byte) error {
state := v1.State{}

err := json.Unmarshal(buf, &state)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ran ValidatorMediaTypeModelStateConfig.Validate on {"format":"example/v1","tokens":[1.0]}. Both 1.0 and 1e0 fail to decode into []int, while 1 succeeds. All three represent the same integer under the declared JSON Schema. Please validate the numeric value exactly, retaining the existing regression case for 1.0000000000000001, and add passing cases for both integral spellings. JSON Schema integer semantics

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. validateState now checks each token ID's exact value: 1.0 and 1e0 pass, 1.0000000000000001 still fails. Added passing cases for both spellings.

Comment thread docs/state.md Outdated

A state MUST NOT be loaded for a model other than the one its `subject` references. A runtime MUST NOT load a state whose `format` it does not support.

A runtime cannot check that a state's layers match its `tokens` without processing the tokens, which is the work the state saves. Runtimes SHOULD load only states they trust, for example states with a verified signature or states referenced by digest, and SHOULD NOT load a state only because it is listed as a referrer of the model.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Every descriptor returned by the referrers API already carries a digest. Reusing that digest to check the downloaded blob establishes integrity, but gives the runtime no independent evidence of who produced the state or whether it corresponds to the stated tokens. Please qualify the example as a digest pinned through a trusted channel, or a signature verified against an authorized producer. OCI referrers API

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reworded: "a state pinned by a digest obtained through a trusted channel, or one whose signature was verified against an authorized producer".

…onent

Check each token ID's exact value instead of decoding into []int, so
1.0 and 1e0 pass as the schema allows, while 1.0000000000000001 still
fails.

Refs modelpack#239

Signed-off-by: João Galego <jgalego1990@gmail.com>
A digest from the referrers listing proves integrity, not who produced
the state. Name a digest pinned through a trusted channel or a
signature verified against an authorized producer instead.

Refs modelpack#239

Signed-off-by: João Galego <jgalego1990@gmail.com>
@JGalego

JGalego commented Nov 25, 2026

Copy link
Copy Markdown
Author

Both addressed: the validator now accepts any integral spelling, and the trust example names the trusted channel or the authorized signer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Model state artifacts: prompt caches and primed sessions linked to their model through subject

2 participants