machinelearning

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 16, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

Package machinelearning owns FrogML's versioned model layout and publication invariants. Temporary uploads are never published model versions.

A version's files are published under models/<name>/<version>, in the files, dependencies and code categories, beside its model-manifest.json; a transaction stages them first under models/<name>/tmp/<version>/<tx>, owned by the principal who started it.

Role

artifacts module, ecosystem layer: the FrogML model layout and publication rules of the Machine Learning slice. Its Handler plugs into the item service through the format hooks (decision 0032), so every write, read, restore, delete and transfer in a Machine Learning repository reaches it whichever API carried it; the slice's http package (artifacts/ecosystem/machinelearning/http) serves the SDK's transaction and manifest API.

Inputs

  • Driving: the format registry (artifacts/ecosystem), which hands the item service's hooks for machinelearning repositories to Handler; the protocol, which checks identities, decodes and verifies manifests, rechecks transactions and marks its own writes (Publication); and the server's item routes, which answer 404 for a private record (Private), its checksum sidecars and archive entries included.
  • Driven: the generic deploy policy (artifacts/ecosystem/generic), which Admit applies first; the store's items and the blob store, read through format.Env; and the package index (artifacts/core/pkgindex), which Reindex reconciles.
  • Settings: none.

Outputs

  • Handler: the hooks that admit writes only into the writer's own live staging transaction (Admit), check restored files against the manifest (Deployed), withdraw versions on delete (Deleted), keep private records from being copied or moved (GuardTransferSource), serve only complete versions' files (Resolve), class private records as metadata (Classify) and publish exactly the complete versions (Reindex).
  • The layout and its checks: Identity with Prefix, Manifest and Staging; Name, Segment, Version, File and Transaction; ParsePath and Private.
  • The manifest: Manifest and its parts, Decode, Read, Verify and Missing; and CheckTransaction and Publication.

Invariants

  • Names are one segment or a namespace and a name; segments are 1 to 60 ASCII letters, digits, underscores, hyphens and dots; tmp is reserved in names, and tmp, files, dependencies and code in versions, so no model's manifest or staging folder reads as another model's file.
  • No write reaches a published path except through the native transaction; raw writes land only in a live staging transaction of their own writer (403 for another principal, 409 after 24 hours).
  • A manifest is at most 4 MiB, declares at least one model artifact and at most 10,000 files, each of at most 10 GiB with a lower-case SHA-256, and has no duplicate or upper-case key and no nesting deeper than 32 levels (400).
  • A version is published, resolved and transferred only while its manifest is stored and every declared file has its declared size and SHA-256; deleting one withdraws the version and restoring the full set publishes it again.
  • Staging files and manifests are private: never resolved as raw downloads, copied or moved.

References

Status

Implemented P9c, which delivered the plan's P32 group (issues #777 to #780 and #789). Moved here in P9d.

Testing

  • handler_test.go (external, machinelearning_test): staging admission only into a live transaction of its owner, the index following complete stored versions, and a reindex that fails closed on corruption, storage failure and revocation.
  • manifest_test.go (external): manifest bounds and serialization metadata, stored manifest identity and content verification, and ambiguous JSON and excessive depth refused.
  • path_test.go (external): names, versions and file paths, and the layout round trip without namespace or category ambiguity.

The model routes' tests in artifacts/ecosystem/machinelearning/http exercise the hooks through the item service.

Index

Constants

View Source
const (
	// ManifestName is a published version's manifest, directly under its
	// prefix (Identity.Manifest).
	ManifestName = "model-manifest.json"
	// TransactionName is the record that starting a transaction stores in
	// its staging folder; the principal who created it owns the
	// transaction (CheckTransaction).
	TransactionName = ".transaction.json"
	// MaxManifestSize is the largest manifest read or committed, 4 MiB.
	MaxManifestSize = 4 << 20
	// MaxFiles is the most files one manifest may declare, its model,
	// dependency and code artifacts together.
	MaxFiles = 10000
	// MaxFileSize is the largest file a manifest may declare or an upload
	// may stage, 10 GiB.
	MaxFileSize = 10 << 30
)

The layout's two file names and the manifest limits. The limits are the ones docs/operations/machinelearning.md documents, so a change to one is a change to the other.

Variables

This section is empty.

Functions

func CheckTransaction

func CheckTransaction(
	ctx context.Context,
	env format.Env,
	c repo.Config,
	id Identity,
	tx string, by string,
) error

CheckTransaction rechecks ownership and expiry on every upload and commit. Knowing the millisecond transaction ID is not an authorization capability.

func File

func File(s string) bool

File reports whether s is a declared file's path within its category: at most 1,024 bytes of UTF-8, in segments of 1 to 255 bytes that are neither "." nor ".." and hold no control character, with no backslash, "?", "#", "%" or ";" and no "!/" archive-entry delimiter anywhere, so the path can neither leave the version's folder nor be read as an escape, a query, a fragment, a matrix parameter or an archive entry.

func Missing

func Missing(err error) bool

Missing reports whether err, from Read or Verify, means an item is not stored (kernel.ErrNotFound): the version has no manifest or has lost a declared file, so it is unpublished or withdrawn rather than broken.

func Name

func Name(s string) bool

Name reports whether s is a model name: one segment, or a namespace and a name, each a Segment other than tmp, which the staging layout reserves.

func Private

func Private(p string) bool

Private identifies staging records and manifests, which must not bypass transaction ownership or the native manifest's per-artifact authorization.

func Publication

func Publication(ctx context.Context) context.Context

Publication is used only inside the native transaction which verifies every file before publishing the manifest and rebuilding the index once.

func Segment

func Segment(s string) bool

Segment reports whether s is one name, namespace or version segment: 1 to 60 ASCII letters, digits, underscores, hyphens and dots, and neither "." nor "..".

func Serves

func Serves(t repo.PackageType) bool

Serves reports whether t is the Machine Learning package type.

func Transaction

func Transaction(s string) bool

Transaction reports whether s is a transaction ID: a positive 13-digit decimal with no leading zero, the Unix millisecond time that starting a transaction assigns.

func Verify

func Verify(
	ctx context.Context,
	env format.Env,
	c repo.Config,
	prefix string,
	m Manifest,
) ([]model.Item, error)

Verify checks the exact declared files against immutable stored checksums. It returns ErrNotFound for a version made incomplete by item deletion.

func Version

func Version(s string) bool

Version excludes layout markers: with an optional namespace, category names would make one model's manifest indistinguishable from another model's file.

Types

type Artifact

type Artifact struct {
	Path        string    `json:"artifact_path"`
	Size        int64     `json:"size"`
	Checksums   Checksums `json:"checksums"`
	DownloadURL string    `json:"download_url,omitempty"`
}

Artifact is one declared file: its path within its category, its size and SHA-256, and the download URL that only the manifest GET's answer carries.

type Checksums

type Checksums struct {
	SHA256 string `json:"sha2"`
}

Checksums is a declared file's digest. The SDK calls its SHA-256 "sha2".

type FileEntry

type FileEntry struct {
	Path     string
	Artifact Artifact
}

FileEntry is a declared file's path below the version's folder, category included, and the artifact that declares it.

type Handler

type Handler struct{ generic.Handler }

Handler is the Machine Learning format's hooks: a model version is written only through a FrogML transaction, private records are never served, copied or moved, and only complete, verified versions are published. It embeds the generic hooks, whose deploy policy Admit applies first.

func (Handler) Admit

func (Handler) Admit(
	ctx context.Context,
	env format.Env,
	c repo.Config,
	w format.Write,
) (format.Write, error)

Admit applies the generic deploy policy, whose refusal it wraps, and then refuses (400) a path outside the model layout (ParsePath), a cache write and a file over MaxFileSize. Writes inside the native transaction (Publication) pass. Any other write must deploy a file into a staging folder (409 otherwise, so no published file or transaction record is written directly) whose transaction is live and the writer's own (CheckTransaction: 403 for another principal, 409 once it has expired).

func (Handler) Classify

func (Handler) Classify(_ repo.Config, p string) format.Class

Classify marks a private record (a staging file or a manifest, Private) as metadata, and every published model file as unique content.

func (Handler) Deleted

func (h Handler) Deleted(ctx context.Context, env format.Env, c repo.Config, _ []model.Item) error

Deleted rebuilds the index (Reindex) after any delete outside the native transaction, so removing a declared file withdraws its version at once.

func (Handler) Deployed

func (h Handler) Deployed(ctx context.Context, env format.Env, c repo.Config, it model.Item) error

Deployed lets folders, writes inside the native transaction and staging files pass, and refuses (400) any other path outside the model layout. A published file stored again, as by a restore, must be one its version's manifest declares, with that size and SHA-256, whenever the manifest is stored (409). The index is then rebuilt (Reindex), so a version made complete again is published again.

func (Handler) GuardTransferSource

func (Handler) GuardTransferSource(
	ctx context.Context,
	env format.Env,
	c repo.Config,
	it model.Item,
) error

GuardTransferSource refuses (403) to copy or move a private record (a staging file or a manifest, Private), and lets a published file go only while its version's manifest is stored and every declared file verifies (Verify).

func (Handler) Reindex

func (Handler) Reindex(ctx context.Context, env format.Env, c repo.Config) error

Reindex publishes only complete manifest-backed versions. Removing one file withdraws the version; restoring the full set makes it visible again.

func (Handler) Resolve

func (Handler) Resolve(
	ctx context.Context,
	env format.Env,
	c repo.Config,
	d format.Download,
) (string, error)

Resolve serves a model file only from a complete published version: staging files, the manifest and any path its version's manifest does not declare answer 404, and a download also fails while a declared file is missing or differs (Verify). The manifest GET is the manifest's only reader.

type Identity

type Identity struct{ Name, Version string }

Identity names a model, optionally within one SDK namespace, and its version.

func ParsePath

func ParsePath(p string) (id Identity, tx, rest string, ok bool)

ParsePath distinguishes committed files from one transaction's private files.

func (Identity) Manifest

func (id Identity) Manifest() string

Manifest is the path of the version's published manifest.

func (Identity) Prefix

func (id Identity) Prefix() string

Prefix is the version's published folder, models/<name>/<version>.

func (Identity) Staging

func (id Identity) Staging(tx string) string

Staging is transaction tx's private folder, models/<name>/tmp/<version>/<tx>, which no published version's folder can be, because names and versions both reserve tmp.

type Manifest

type Manifest struct {
	Created      string        `json:"created_date"`
	Artifacts    []Artifact    `json:"model_artifacts"`
	Format       Serialization `json:"model_format"`
	Dependencies []Artifact    `json:"dependency_artifacts,omitempty"`
	Code         *Artifact     `json:"code_artifacts,omitempty"`
	ID           string        `json:"id,omitempty"`
	Version      string        `json:"version,omitempty"`
}

Manifest is the FrogML SDK's model manifest: the creation time, the model, dependency and code artifacts, the serialization metadata, and the model's name (ID) and version, which a stored manifest must repeat (Read).

func Decode

func Decode(body io.Reader) (Manifest, error)

Decode reads one manifest of at most MaxManifestSize bytes and refuses (400) one that is malformed, ambiguous or out of bounds: a duplicate or upper-case key, nesting deeper than 32 levels, a creation time in neither RFC 3339 nor the SDK's zone-less UTC form, no model artifact or more than MaxFiles files, missing or invalid serialization metadata, or a file with an invalid path, a size outside 0 to MaxFileSize, a SHA-256 that is not 64 lower-case hexadecimal characters, or a path declared twice.

func Read

func Read(
	ctx context.Context,
	env format.Env,
	c repo.Config,
	id Identity,
) (Manifest, model.Item, error)

Read opens the bounded manifest, independently of any HTTP route.

func (Manifest) Files

func (m Manifest) Files() []FileEntry

Files lists the declared files in manifest order: the model artifacts under files/, the dependencies under dependencies/ and the code artifact under code/.

type Serialization

type Serialization struct {
	Framework        string `json:"framework"`
	FrameworkVersion string `json:"framework_version"`
	Format           string `json:"serialization_format"`
	Runtime          string `json:"runtime"`
	RuntimeVersion   string `json:"runtime_version"`
}

Serialization is the model's format metadata. Every field but the framework version is required, and none may exceed 128 bytes or hold a NUL, CR or LF.

Directories

Path Synopsis
Package machinelearninghttp implements the FrogML SDK's Artifactory model transaction and manifest API on local and one-node federated repositories.
Package machinelearninghttp implements the FrogML SDK's Artifactory model transaction and manifest API on local and one-node federated repositories.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL