Skip to content

impl(011): increment 1, the crate, the manifest and the synthetic encoder - #437

Merged
bartekus merged 1 commit into
mainfrom
impl/011-synthetic
Nov 1, 2026
Merged

bartekus merged 1 commit into
mainfrom
impl/011-synthetic

Conversation

@bartekus

@bartekus bartekus commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

Summary

Spec 011, increment 1: the rustev-backend-embed-linear crate with the rustev.embed-linear/1 manifest, bundle verification and the synthetic encoder. Only the parts that need no real artifact (Decision 18).

  • Gate status: the feasibility gate (3.2) has not passed for any platform, so no ort, ONNX Runtime or tokenizers dependency is added (3.2.3). The crate depends only on rustev-contract, serde, serde_json and sha2.
  • src/manifest.rs: every member of 3.4.2 with deny_unknown_fields, parsed with the contract's bounded parser; check refuses each 3.4.3 case (options not unique, proposition options other than ["false", "true"], zero threads, max_tokens above 512, an ONNX graph whose source is not a checkpoint file with its SHA-256), plus path, size and syntax bounds and tolerance bounds other than those of 3.3. artifact_id is the contract's tagged digest of the canonical bytes (3.5.1).
  • src/bundle.rs: verify_bundle reads an absolute bundle directory, refuses a symbolic link on any path component, bounds each read by its declared length, checks the 150 MiB bundle bound, each file's length and SHA-256, and the expected ArtifactId, then parses the head weights. Setup codes reached: bundle_missing, bundle_too_large, manifest_invalid, digest_mismatch, artifact_mismatch, head_invalid; the others are declared for later increments.
  • src/lib.rs: the descriptor derived from the manifest (3.10.1 to 3.10.3): logits per operation in the order classify, proposition, rubric, determinism tolerance, no rank; the cost bound units_per_call + units_per_token * max_tokens.
  • src/head.rs: mean_masked pooling in f32 token order with optional L2 normalization, and the head product b_i + sum_j W_ij e_j in f64 (3.9.2, 3.9.3).
  • src/synthetic.rs (feature synthetic): the SplitMix64 synthetic encoder and the seed formula for synthetic head weights (3.19.1, 3.19.2), documented in the module.
  • tools/rustev-release/release-set.json: the crate is excluded (publish = false) until spec 031 admits it.

Spec: 011's directory is no longer planned; an extends edge on tools/rustev-release/ (031) for the exclusion; the implementation record lists the planned increments, states the gate status, and records increment 1.

No network access, download, checkpoint, runtime library or provider call anywhere in this change.

Verification

  • cargo test -p rustev-backend-embed-linear --locked (tests/bundle.rs, synthetic bundles in a temporary directory), cargo test -p rustev-release --locked, cargo run -p rustev-boundaries.
  • clippy -D warnings on rustev-backend-embed-linear (all targets); cargo fmt --all --check, make gate, scripts/check-authored-content.sh, spec-spine couple.

@bartekus
bartekus force-pushed the impl/011-synthetic branch 2 times, most recently from 006e8b6 to a2e9c0c Compare November 1, 2026 01:10
@github-actions

github-actions Bot commented Nov 1, 2026

Copy link
Copy Markdown

AI review (no-findings)

Reviewing the PR carefully: it introduces the rustev-backend-embed-linear crate (spec 011 increment 1) with manifest parsing, bundle verification, descriptor derivation, pooling/head arithmetic, and the synthetic encoder behind a feature flag.

bundle.rs

The symlink-refusal loop in read_regular (symlink_metadata per component, then fs::File::open) has an inherent TOCTOU window: a symlink could be inserted between the check and the open. Given the spec explicitly requires "refusing a symbolic link on every path component," this gap is worth noting, though exploiting it requires concurrent write access to the bundle directory.

Beyond that, the size check ordering is correct: declared total checked first, then individual files read at f.bytes + 1 (detects over-length), then length equality (detects under-length), then SHA-256. The bytes_of closure's unwrap_or_default() is dead code but safe (all paths are in verified by construction).

manifest.rs

check_heads reports duplicate-head collisions at at("task") while the error message says the key includes operation, task, question, and options — the path field is misleading but not a functional bug.

The exact_version parser splits on the first - so "1.0.0-rc-1" would be refused (the pre-release part "rc-1" contains -, which fails is_ascii_alphanumeric); this is stricter than semver but consistent with the corpus's usage.

No bounds check on FileRef.bytes == 0 in check_files, but a zero-byte weights file is caught downstream by LinearHead::from_bytes returning HeadInvalid. No integer overflow risk: options * hidden is capped by limits::HEADS * limits::HIDDEN_SIZE = 32 * 4096, well within usize.

head.rs / synthetic.rs

pool correctly uses checked_mul for the length invariant and returns None on empty mask, zero norm, and non-finite output. The weight(h) mapping (h >> 40) as f32 / 8_388_608.0 - 1.0 is exact for all 24-bit inputs (f32 can represent integers up to 2²⁴ exactly) and the range [-1, 1) matches the documentation.

spec.md / release-set.json

Removing planned: true from the establishes entry is correct (the directory is now delivered). The extends entry for 031-public-api-and-release-family / tools/rustev-release/ is consistent with the release-set.json exclusion. The implementation record correctly reflects increment 1's scope and the pending feasibility gate.

Cargo.lock

The self-reference under dependencies is a dev-dependency self-reference (path = ".", features = ["synthetic"]) — a valid Cargo pattern, correctly reflected in the lock file.

No concrete functional defect is supported by the available evidence.

{"head": "a2e9c0ccb628dda07f94fe3e314e0880303fb5be", "verdict": "no-findings", "findings": []}

Subject: 09c3c1b...a2e9c0c, diff digest b325ade1176bd10ebc0eff51493b44e06d42f4219f2aa75fe28aa273eccee025, 1 call(s). An AI comment is not an approval.

@github-actions

github-actions Bot commented Nov 1, 2026

Copy link
Copy Markdown

AI review (findings)

Review of PR 9bc1b8e

This PR introduces backends/rustev-backend-embed-linear — the manifest, bundle verifier, pooling/head arithmetic, and synthetic encoder for spec 011 increment 1. I reviewed all changed files.

bundle.rs — TOCTOU race between symlink check and open

read_regular checks each path component via fs::symlink_metadata in a loop, then calls fs::File::open(&path), which follows symlinks. Between the final symlink_metadata call and File::open, an adversary with write access to the bundle directory could atomically swap in a symlink (e.g., via rename). Because the subsequent file.metadata() call uses fstat on the already-opened descriptor, is_file() would return true for a symlink-to-regular-file, letting the read proceed. The SHA-256 check would reject non-matching content, but the bytes of an arbitrary regular file outside the bundle would be read.

The spec explicitly requires "refusing a symbolic link anywhere on the relative path" (bundle.rs line comment, 3.7.1). The current check fails to enforce this atomically. The correct remedy is O_NOFOLLOW (via OpenOptions + custom_flags on Unix) or equivalent per-platform mechanism.

Location: bundle.rs, read_regular function, gap between the loop's last symlink_metadata call (~line 195) and fs::File::open (~line 200).

Everything else reviewed without findings

  • manifest.rs check: All 3.4.3 cases are covered — proposition options order, zero threads, max_tokens > 512, ONNX graph source not in checkpoint files with matching SHA-256, tolerance bounds, 64-hex digests, relative_path guarding against .././NUL/backslash, bundle-size arithmetic with saturation.
  • head.rs from_bytes: Checked-arithmetic length validation, non-finite detection, weight/bias split, and the logits f64 accumulation all match spec 3.9.2–3.9.3.
  • head.rs pool: Empty-mask guard, weight-zero guard, L2 norm zero/non-finite guard, and the final finiteness check are all correct.
  • manifest.rs distinct_files / verify_bundle size check: Saturation is used consistently; the pre-read bundle-size guard (declared + manifest bytes vs. 150 MiB) is correct.
  • synthetic.rs: SplitMix64 formula, weight range [-1, 1), encoder and head-weight generation all match the 3.19 spec text.
  • Cargo.lock self-dependency: The rustev-backend-embed-linear entry in its own dependency list is correct; it reflects the [dev-dependencies] self-reference used to activate the synthetic feature for tests.
  • spec.md change: Removing planned: true from the establishes unit is correct now that the directory exists; the new extends for tools/rustev-release/ is appropriate since release-set.json is modified; the implementation record accurately describes what increment 1 delivers.
  • release-set.json: The exclusion entry matches the publish = false in Cargo.toml and the spec's 3.17.4 constraint.
{"head": "9bc1b8e987ecbfddd70073cc2b84601d94f4fa30", "verdict": "findings", "findings": [{"path": "backends/rustev-backend-embed-linear/src/bundle.rs", "line": 200, "summary": "TOCTOU race: each path component is checked for symlinks via symlink_metadata in a loop, but fs::File::open (which follows symlinks) is called afterward, so a symlink atomically swapped in during the race window bypasses the check and allows reads of arbitrary regular files outside the bundle directory."}]}

Subject: 09c3c1b...9bc1b8e, diff digest 36a28ac218cbe65c0189c8c4cbe0c1c00f4a585d0ff295ceacfc58f3e6e59b25, 1 call(s). An AI comment is not an approval.

@bartekus
bartekus had a problem deploying to statecraft-review-exception November 1, 2026 01:26 — with GitHub Actions Error
…oder

Spec 011 increment 1: establish backends/rustev-backend-embed-linear with
the parts that need no real artifact (Decision 18). The feasibility gate
(3.2) has not passed for any platform, so no ort, ONNX Runtime or
tokenizers dependency is added (3.2.3).

- manifest: rustev.embed-linear/1 with every 3.4.2 member, the 3.4.3
  consistency checks and the artifact identity (3.5.1).
- bundle: verify_bundle reads an absolute directory, refuses symbolic
  links, bounds reads by declared length, checks the 150 MiB bound, each
  file's length and SHA-256 and the expected ArtifactId, and parses head
  weights (3.7.2 bundle and head codes).
- The derived descriptor (logits, tolerance, no rank) and cost bound
  (3.10.1 to 3.10.3); mean_masked pooling and the f64 head product (3.9).
- synthetic (feature): the SplitMix64 encoder and head formula (3.19).
- The crate is publish = false and excluded from the release set until
  spec 031 admits it.
- Spec 011: the directory is no longer planned; an extends edge on
  tools/rustev-release/ (031); the implementation record lists the
  planned increments, the gate status and increment 1.

No network access, download, checkpoint, runtime library or provider
call is made anywhere in this change.
@github-actions

github-actions Bot commented Nov 1, 2026

Copy link
Copy Markdown

AI review (no-findings)

After reviewing the diff — a new rustev-backend-embed-linear crate, a spec update removing planned: true and adding an implementation record, and a release-set exclusion — I found no concrete defects.

Security review (bundle.rs)

  • Path traversal: relative_path rejects .., ., empty components, backslash, and manifest.json as a file reference. read_regular independently checks each Component::Normal before pushing, so an unchecked path cannot reach read_regular for bundle files.
  • Symlink prevention: component-by-component symlink_metadata check plus a post-open inode comparison on Unix (dev/ino from fstat vs lstat) plus a canonical-path comparison after canonicalize. The SHA-256 check is acknowledged as the final bound for any race window.
  • Size bounds: manifest read is bounded by LIMITS.max_bytes; each file is bounded by its declared bytes; the declared total plus manifest size is checked against 150 MiB before reading any file.
  • bytes_of uses unwrap_or_default() (empty Vec on miss) for graph and tokenizer. Since distinct_files and the verification loop both iterate manifest.files(), all files are always in verified at that point; head weights would fail LinearHead::from_bytes immediately on empty bytes, while graph/tokenizer would silently carry empty bytes if the invariant were ever broken by a future refactor. Not a current defect.

Manifest validation (manifest.rs)

  • Proposition options are required to be exactly ["false", "true"] in order.
  • Duplicate heads (same operation + task + question + options) are rejected.
  • For ONNX bundles, the graph source must be among checkpoint.files with the matching SHA-256.
  • Tolerance values are required to match the 3.3 constants exactly.
  • max_units() uses checked arithmetic and the manifest check verifies it is Some.

Spec / governance

  • Removing planned: true is correct since the directory now exists.
  • The additive extends claim on tools/rustev-release/ is appropriate for the release-set exclusion edit.
  • The exclusion reason in release-set.json is internally consistent (feasibility gate not passed, spec 031 admission required).

Cargo

  • The self-referential dev-dependency (rustev-backend-embed-linear = { path = ".", features = ["synthetic"] }) is a valid Cargo pattern to enable a feature only in tests; the resulting self-loop in Cargo.lock is expected.
{"head": "3651d2d09e34a0c4357fea7ccbb0d21fb966763b", "verdict": "no-findings", "findings": []}

Subject: 09c3c1b...3651d2d, diff digest 9f9f5734deb6d719a3a828828ed6ef42b4940cd34213e4ba9f9a0f9b96eef830, 1 call(s). An AI comment is not an approval.

@bartekus
bartekus added this pull request to the merge queue Nov 1, 2026
Merged via the queue into main with commit 5d67df0 Nov 1, 2026
30 checks passed
@bartekus
bartekus deleted the impl/011-synthetic branch November 1, 2026 06:20
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.

1 participant