Skip to content

refactor(core): migrate lang_analyzer cache from bincode to postcard - #16

Merged
inureyes merged 2 commits into
mainfrom
refactor/issue-8-migrate-bincode-to-postcard
May 18, 2026
Merged

inureyes merged 2 commits into
mainfrom
refactor/issue-8-migrate-bincode-to-postcard

Conversation

@inureyes

Copy link
Copy Markdown
Member

Summary

  • Replace bincode 1.x (RUSTSEC-2025-0141, permanently unmaintained) with postcard 1.x in mlxcel-core's lang_analyzer disk cache
  • Remove the corresponding [advisories.ignore] entry from deny.toml now that bincode is gone from the dep tree

Architectural decision

postcard 1.x was chosen over the other alternatives (bitcode, rkyv, bincode 2.x) for these reasons:

  • 1.0+ stable with frozen wire format: production users' on-disk caches are safe across future dependency upgrades; bitcode is pre-1.0 and has changed wire formats between minor versions
  • Drop-in serde API: postcard::to_allocvec(&v)? / postcard::from_bytes::<T>(&bytes)? — minimal change to the 3 call sites in one file
  • Embedded ecosystem standard: natural fit for an inference runtime crate; actively maintained
  • Use case is not performance-critical (one startup read, KB-scale cache file), so bitcode's speed/size advantages do not apply here

Cache format compatibility

mlxcel-core's corrupt-detection path in lang_analyzer/cache.rs renames any file that fails deserialization to *.broken.<epoch>.bak before rebuilding from the tokenizer source. Production users with old bincode-format caches will gracefully degrade on upgrade — the postcard from_bytes call will fail, the corrupt-detection path fires, and the cache is rebuilt automatically. No explicit migration code is needed.

What changed

  • src/lib/mlxcel-core/Cargo.toml: bincode = "1" → postcard = { version = "1", features = ["alloc"] }
  • src/lib/mlxcel-core/src/lang_analyzer/cache.rs: bincode::deserialize → postcard::from_bytes, bincode::serialize → postcard::to_allocvec, doc comments updated
  • src/lib/mlxcel-core/src/lang_analyzer/mod.rs: Bincode(#[from] bincode::Error) → Postcard(#[from] postcard::Error), module doc updated
  • deny.toml: removed RUSTSEC-2025-0141 ignore entry; paste entry retained

Verification

  • cargo check --lib -p mlxcel-core --no-default-features — passes cleanly
  • cargo tree -p mlxcel-core -i bincode — returns "package not found" (bincode fully removed)
  • cargo deny check — passes with advisories ok and RUSTSEC-2025-0141 no longer ignored

Closes #8

inureyes added 2 commits May 18, 2026 17:48
Replace bincode 1.x (RUSTSEC-2025-0141 — permanently unmaintained) with postcard 1.x in the three call sites inside mlxcel-core's lang_analyzer/cache.rs. postcard 1.x is 1.0+ stable with a frozen wire format, serde-based (drop-in API), and is the embedded Rust ecosystem standard — a natural fit for an inference runtime crate.

Changed files: Cargo.toml (bincode → postcard 1 alloc feature), cache.rs (bincode::deserialize → postcard::from_bytes, bincode::serialize → postcard::to_allocvec, doc comments updated), mod.rs (Bincode error variant → Postcard, module doc updated).
bincode 1.x is no longer in the dependency tree (replaced by postcard 1.x in mlxcel-core). Remove the ignore entry so cargo deny enforces the advisory going forward. The paste advisory (RUSTSEC-2024-0436) is retained — it is a separate transitive-via-tokenizers concern, unchanged by this PR.
@inureyes inureyes added status:review Under review type:refactor Code restructuring without changing functionality priority:medium Medium priority area:core mlxcel-core: MLX FFI, primitives, KV cache, layers labels May 18, 2026
@inureyes
inureyes merged commit a84284e into main May 18, 2026
3 of 4 checks passed
@inureyes
inureyes deleted the refactor/issue-8-migrate-bincode-to-postcard branch May 18, 2026 08:49
@inureyes inureyes self-assigned this May 18, 2026
@inureyes inureyes added status:done Completed and removed status:review Under review labels May 18, 2026
@inureyes inureyes added this to the 0.1 milestone Jun 21, 2026
be-free-snowboy pushed a commit to freestylejs/snowbrain-mlxcel that referenced this pull request Oct 27, 2026
…ablup#16)

Closes lablup#8.

Migrates `mlxcel-core`'s `TokenLanguageIndex` on-disk cache off the
unmaintained `bincode` 1.x (RUSTSEC-2025-0141 — project permanently
ceased development) to `postcard` 1.x.

## Architectural choice — postcard

- Drop-in serde-based API (`postcard::to_allocvec(&v)?` /
  `postcard::from_bytes::<T>(&bytes)?`) — minimal call-site change.
- 1.0+ stable with frozen wire format — protects production users'
  cache compatibility across future dependency upgrades.
- Embedded Rust ecosystem standard — natural fit for an
  inference-runtime cache.

Alternatives considered: `bitcode` (faster but pre-1.0, wire-format
changes between minors), `rkyv` (zero-copy over-engineering for a
startup-time cache), `bincode` 2.x / 3.x (different maintainer team,
name-confusion risk — Dependabot's auto-PR lablup#10 to bincode 3.x was
explicitly closed in favor of this approach).

## Cache compatibility — graceful degradation

`lang_analyzer/cache.rs` already has corrupt-detection: a
deserialization failure renames the existing bincode-format file to
`*.broken.<epoch>.bak` and rebuilds the cache from source. Users
upgrading from a prior mlxcel release will trip this path
automatically on the first cache read — no explicit migration code
needed.

## Scope (3 files + Cargo.lock)

- `src/lib/mlxcel-core/Cargo.toml` — `bincode = "1"` → `postcard = { version = "1", features = ["alloc"] }`
- `src/lib/mlxcel-core/src/lang_analyzer/cache.rs` — 3 call sites + doc comments
- `src/lib/mlxcel-core/src/lang_analyzer/mod.rs` — error variant `Bincode` → `Postcard` (no external match-arms on it, safe rename)
- `deny.toml` — RUSTSEC-2025-0141 `[advisories.ignore]` entry removed (no longer applicable)

Verified locally: `cargo deny check` clean (advisories ok, bans ok,
licenses ok, sources ok); `cargo tree -p mlxcel-core -i bincode`
returns "package not found" — bincode is fully removed from the
dependency tree.

Self-hosted clippy + test gate is queued behind the PR lablup#14 cold-build
backlog at merge time; will run on main after the runner clears.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:core mlxcel-core: MLX FFI, primitives, KV cache, layers priority:medium Medium priority status:done Completed type:refactor Code restructuring without changing functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refactor: migrate mlxcel-core off unmaintained bincode 1.x

1 participant