Skip to content

impl(011): the feasibility record and the inference dependencies - #455

Merged
bartekus merged 1 commit into
mainfrom
impl/011-feasibility-record
Nov 3, 2026
Merged

bartekus merged 1 commit into
mainfrom
impl/011-feasibility-record

Conversation

@bartekus

@bartekus bartekus commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

Commits spec 011's feasibility record (3.2.1) and takes the inference dependencies that stages 1 to 3 passing allows (3.2.3).

What changes

  • backends/rustev-backend-embed-linear/qualification/: the 2026-10-22 record and its evidence, re-recorded under A-73 by rerecord.py with no new measurement. On macos-aarch64 stages 1 to 3 pass. Stage 4 refuses (p95 105.4 ms against 100 ms), so no platform is qualified. This directory is excluded from AI review (ops: the AI review leaves out spec 011's feasibility evidence #447); the test below checks it instead.
  • tests/feasibility_record.rs: checks that the record is a closed rustev.embed-feasibility/1 envelope in the contract's canonical encoding, that its contract digest matches feasibility.sha256, that every evidence file matches its recorded length and SHA-256, and the stage verdicts (pass, pass, pass, refuse; every platform refuses).
  • Cargo.toml: ort =2.0.0-rc.15 and tokenizers =1.0.0-rc.3, pinned exactly and without default features. rust-version rises to 1.92, which ort requires. autoexamples = false: the measured probe (examples/feasibility.rs) is kept byte-identical as evidence and is not built, because it uses unsafe for dlopen, which the workspace forbids.
  • Spec 011: a record paragraph for this step. Merging ratifies it.

Checks

  • cargo test -p rustev-backend-embed-linear --locked: 12 tests pass locally, including the three record tests.
  • make gate and the authored-content check pass.

@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown

AI review (findings)

Reviewing the diff across all five changed paths.


Cargo.lock – unicode-normalization downgrade

The incoming change downgrades unicode-normalization from 0.1.26 (checksum 75cd3fb…) to 0.1.25 (checksum 5fd4f6878c…). This is a concrete regression: Cargo's resolver normally selects the highest compatible version, so a downgrade means one of the new transitive dependencies forces an upper-bound pin that drops the whole workspace to the older patch. If 0.1.26 contained a bug fix (e.g., NFC/NFD correctness) that the rest of the workspace relied on, this silently regresses all callers.


Cargo.lock – rdst brings criterion (a benchmarking framework) as a non-dev dependency

tokenizers → tk-encode → ptr_hash → rdst resolves rdst v0.20.14, whose [dependencies] block (not [dev-dependencies]) lists criterion. This pulls the full benchmarking stack — criterion-plot, ciborium, plotters, plotters-backend, plotters-svg, anes, oorandom, tinytemplate — into every production build of rustev-backend-embed-linear. plotters in turn depends on wasm-bindgen and web-sys, adding a WebAssembly compilation surface to the ordinary build graph. Benchmarking infrastructure has no place in a production dependency.


Cargo.lock – rdst brings tikv-jemallocator as a non-dev dependency

Same transitive chain. rdst lists tikv-jemallocator in its regular [dependencies], pulling in the jemalloc allocator (tikv-jemalloc-sys, cc, libc build script) into production builds. A non-default allocator landing in a library crate's non-dev dependency graph is a latent conflict risk for any embedding application.


examples/feasibility.rs – TOCTOU between SHA-256 check and dlopen

Lines ~140–146: the code reads args[2] into memory, computes its SHA-256, compares it to a hardcoded digest, and returns an error if they differ. Then, separately, runtime_version calls dlopen(path.as_ptr(), 2) with the same path, and ort::init_from(&args[2]) loads it again. Between the hash check and the two load calls, the file at the path can be replaced. This is a time-of-check/time-of-use race on a user-controlled absolute path fed to dlopen. The file is not built (autoexamples = false), but it is committed and documented as reproducible evidence, and the defect is concrete.

{"head": "daea92ea00260af352fe3ae58d077ba052ba18e7", "verdict": "findings", "findings": [{"path": "Cargo.lock", "line": null, "summary": "Adding tokenizers downgrades unicode-normalization from 0.1.26 to 0.1.25, a concrete patch-level regression for all workspace callers."}, {"path": "Cargo.lock", "line": null, "summary": "rdst v0.20.14 (transitive via tokenizers → tk-encode → ptr_hash) lists criterion as a regular dependency, pulling benchmarking infrastructure (plotters, ciborium, wasm-bindgen, web-sys) into production builds."}, {"path": "Cargo.lock", "line": null, "summary": "rdst v0.20.14 lists tikv-jemallocator as a regular dependency, introducing the jemalloc allocator into the production dependency graph of rustev-backend-embed-linear."}, {"path": "backends/rustev-backend-embed-linear/examples/feasibility.rs", "line": 141, "summary": "The SHA-256 check on the runtime path and the subsequent dlopen/init_from calls use the same user-supplied path, creating a TOCTOU race where the file can be swapped between verification and loading."}]}

Subject: 9fca258...daea92e, diff digest 32cde61ffb670ddc12c395bccfdcca657ecbe3632a6adf1065bf56bec5bf455f, 1 call(s). An AI comment is not an approval.

@bartekus

bartekus commented Nov 2, 2026

Copy link
Copy Markdown
Contributor Author

Review note on the two Cargo.lock findings at daea92e.

  1. unicode-normalization 0.1.26 to 0.1.25. Real, and forced by the pinned dependency. tk-encode 0.1.0-rc.3, which tokenizers =1.0.0-rc.3 requires, declares unicode-normalization = "=0.1.25"; cargo update -p unicode-normalization --precise 0.1.26 is refused for that reason. The tokenizers pin is the one the feasibility record measured (3.2.2), so changing it would invalidate the record. The other workspace user is the Aicortex integration (through aicortex-claims and aicortex-gate); 0.1.25 to 0.1.26 carries no security advisory. When 011 moves to a tokenizers release that lifts the pin, the lock returns to the newer version.
  2. criterion through rdst. A false positive for builds. rdst 0.20.14 declares criterion only under [target."cfg(any(bench, tuning))".dependencies] and as a dev-dependency. Neither cfg is set by any build here, and cargo tree -p rustev-backend-embed-linear -e normal -i criterion prints nothing for x86_64 and aarch64 Linux, aarch64 macOS, x86_64 Windows and wasm32. Its entry in Cargo.lock is lockfile resolution, not a compiled dependency.

No change is made for either. The owner's review exception is requested for this head.

@bartekus
bartekus temporarily deployed to statecraft-review-exception November 2, 2026 21:42 — with GitHub Actions Inactive
@bartekus
bartekus enabled auto-merge November 2, 2026 23:11
@bartekus
bartekus added this pull request to the merge queue Nov 2, 2026
@bartekus
bartekus removed this pull request from the merge queue due to a manual request Nov 2, 2026
@bartekus
bartekus force-pushed the impl/011-feasibility-record branch from daea92e to 4c8edd6 Compare November 2, 2026 23:54
@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown

AI review (no-findings)

Reviewing the five changed paths for bugs, security problems, and inconsistencies.


backends/rustev-backend-embed-linear/Cargo.toml

  • rust-version = "1.92" overrides the workspace MSRV. Comment and spec text both explain why (ort 2.0.0-rc.15 requires it). Crate is publish = false and outside the release family, so this does not affect released artifacts. ✓
  • autoexamples = false is the correct mechanism to exclude examples/feasibility.rs from normal builds. Comment correctly explains the unsafe_code = "forbid" conflict. ✓
  • ort and tokenizers pinned with exact versions and default-features = false to prohibit download features (matching spec 011, 3.6.1 and 3.18.2(c)). ✓

backends/rustev-backend-embed-linear/examples/feasibility.rs

  • unsafe FFI block (dlopen/dlsym/dlclose/transmute) is macOS-only; the non-macOS stub is pure-safe. The workspace lint would only trip on macOS. autoexamples = false prevents compilation in CI regardless. Intentional and documented. ✓
  • Hash check on the runtime binary (runtime_sha != "2a50a63e...") runs before dlopen, giving a TOCTOU window. This is an offline measurement probe run by the operator, not a deployed service; the risk is not meaningful in context. ✓
  • embedding mean-pool loop: values.as_chunks::<384>().0 has an empty remainder because the shape check [1, shape[1] as i64, 384] guarantees the flat buffer is exactly divisible by 384. ✓
  • Division by shape[1] as f32: shape[1] is ids.len(); the fixture filter (ids.len() > 256 → continue) and the probe argument ("hello ".repeat(254)) ensure non-zero lengths in all execution paths. ✓
  • p95 at timings[949] and p99 at timings[989] over 1000 sorted samples are correct. ✓

backends/rustev-backend-embed-linear/tests/feasibility_record.rs

  • PLATFORMS array is in alphabetical order matching BTreeMap iteration: linux-aarch64-gnu < linux-x86_64-gnu < macos-aarch64. ✓
  • Digest construction (SCHEMA bytes + NUL + canonical bytes) matches spec 011's rustev.embed-feasibility/1 contract envelope definition. ✓
  • #[serde(deny_unknown_fields)] on FeasibilityRecord enforces the "closed envelope" requirement. ✓
  • no_platform_is_qualified_and_stages_one_to_three_pass_on_macos: asserts all three platforms verdict == "refuse", global stages ["pass","pass","pass","refuse"], and macos-aarch64 platform stages equal the global stages. Consistent with spec text ("Both Linux platforms are not measured"). ✓
  • Dependency graph file bound only by SHA-256 (no length) while evidence files are bound by both: intentional asymmetry, not a defect. ✓

Cargo.lock

  • New rdst 0.20.14 entry lists criterion as a production (non-dev) dependency, which transitively pulls in plotters → wasm-bindgen, web-sys. This is an upstream crate defect in rdst. The spec text explicitly states the resolved graph "passes make boundaries with the 3.18 rules," and rustev-backend-embed-linear is publish = false and outside the release family, so this does not affect released artifacts. No actionable finding here beyond noting the unusual upstream dependency.

specs/011-semantic-backend/spec.md

  • Contract digest quoted in the spec (sha256:6a85fb28eba4222e75d1efde7cbd25c1869eda60403d695a6d137c12d09899e5) is verified at runtime by the_record_is_closed_canonical_and_matches_its_contract_digest. Cannot verify directly against the excluded qualification directory, but that is the test's purpose. ✓
  • Stage 4 refusal reason ("encoder p95 105.4 ms against 100 ms") is consistent with the code outputting p95_ms and the test asserting stage 4 verdict is "refuse". ✓
  • Spec description of tests/feasibility_record.rs and examples/feasibility.rs matches what those files actually do. ✓

No concrete defects found.

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

Subject: f31ed26...4c8edd6, diff digest 32cde61ffb670ddc12c395bccfdcca657ecbe3632a6adf1065bf56bec5bf455f, 1 call(s). An AI comment is not an approval.

Commits the 2026-10-22 feasibility record and its evidence, re-recorded
under A-73 with no new measurement: on macos-aarch64 stages 1 to 3 pass
and stage 4 refuses (p95 105.4 ms against 100 ms); no platform is
qualified. With stages 1 to 3 passing for one platform, the crate takes
the pinned ort and tokenizers without default features (3.2.3).
tests/feasibility_record.rs checks the record's envelope, encoding,
digest and evidence files; the measured probe is kept byte-identical and
not built.
@bartekus
bartekus force-pushed the impl/011-feasibility-record branch from 4c8edd6 to 37bb6a1 Compare November 3, 2026 03:39
@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown

AI review (findings)

Looking at the five changed paths: the new dependencies and inference stack in Cargo.toml/Cargo.lock, the feasibility probe in examples/feasibility.rs, the test in tests/feasibility_record.rs, and the spec narrative in spec.md.

examples/feasibility.rs: dlclose skipped on non-UTF-8 version string

In runtime_version, if CStr::from_ptr(((*base).GetVersionString)()).to_str() returns Err, the ? operator propagates the error before reaching line 51's dlclose(handle). The library handle is leaked. Every other early-exit in that function calls dlclose first (lines 38 and 45), so the omission on the .to_str()? path at line 49 is inconsistent. The process is short-lived and the file is not built in CI (autoexamples = false), but the code defect is present.

Cargo.lock: unicode-normalization downgraded from 0.1.26 to 0.1.25

The resolved version of unicode-normalization moves backward — from 0.1.26 (present in the base lock file) to 0.1.25. This is driven by the new tokenizers/tk-encode transitive dependency tree pinning the older version exactly. A downgrade can silently reintroduce bugs fixed in 0.1.26; the existing crates that already depend on unicode-normalization will now compile against the older release.

No other concrete defects found. The runtime_version TOCTOU between the SHA-256 check and dlopen/ort::init_from is acknowledged in a comment and is expected for a single-machine one-shot probe. The FeasibilityRecord struct's deny_unknown_fields attribute, the canonical-encoding digest check, and the BTreeMap iteration-order reliance in the platform/verdict assertions are all correct. The autoexamples = false approach for suppressing the unsafe-bearing example is sound.

{"head": "37bb6a1ec7826dae81a492cfbbb9b2633d982c87", "verdict": "findings", "findings": [{"path": "backends/rustev-backend-embed-linear/examples/feasibility.rs", "line": 49, "summary": "dlclose is not called when CStr::to_str() fails, leaking the library handle on that error path while every other early-exit in runtime_version calls dlclose first."}, {"path": "Cargo.lock", "line": null, "summary": "unicode-normalization is downgraded from 0.1.26 to 0.1.25 by the new tokenizers dependency tree, which may silently reintroduce bugs fixed in the newer release for all existing consumers."}]}

Subject: e8d1c0f...37bb6a1, diff digest 303165bc0a662acb76c9da5df417bb5f3acaaf9873c6d5e9aef6d5daebc7c66c, 1 call(s). An AI comment is not an approval.

@bartekus
bartekus temporarily deployed to statecraft-review-exception November 3, 2026 03:43 — with GitHub Actions Inactive
@bartekus

bartekus commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

Review note on the two findings at head 37bb6a1 (the restack onto #445).

  1. backends/rustev-backend-embed-linear/examples/feasibility.rs line 49 (no dlclose when CStr::to_str() fails): forced. The probe is measured evidence. qualification/record.py binds its SHA-256 into feasibility.json, qualification/README.md keeps it byte-identical as measured, and tests/feasibility_record.rs checks every bound file's digest. Any edit invalidates the recorded measurement. The path leaks one library handle in a one-shot probe process that exits right after; nothing reuses the handle.
  2. Cargo.lock unicode-normalization 0.1.26 to 0.1.25: forced, as at daea92e. tk-encode pins unicode-normalization =0.1.25, so no resolution keeps 0.1.26 alongside tokenizers.

The restack changed only the spec 011 record paragraph and its derived shards. Requesting the review exception for this head.

@bartekus
bartekus enabled auto-merge November 3, 2026 09:42
@bartekus
bartekus added this pull request to the merge queue Nov 3, 2026
Merged via the queue into main with commit 3dca8fd Nov 3, 2026
30 checks passed
@bartekus
bartekus deleted the impl/011-feasibility-record branch November 3, 2026 10:26

This branch was previously deployed

1 inactive deployment
statecraft-review-exception — 37bb6a1e Deployed Nov 3, 2026 by bartekus via review-exception #3073
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