Issue #2948: A clean build rewrites nikaia.lock with newer crates: pin Cargo’s versions before the build

Open and answer this issue on GitHub.

lock, build, ready · opened 2026-11-29 · updated 2026-11-29 · 0 comments

Found while working on the bug lane: merge conflicts on tests/language/nikaia.lock that no change to dependencies caused.

Today

Cargo resolves a fresh Cargo.lock under target/ on every clean checkout, because nothing gives it the old one. nikaia.lock [dependencies] only records the result afterwards: record_resolved_dependencies (host in crates/nikaia/src/project.rs, called from project_drive_drive_to in crates/nikaia-std/src/compiler/project_drive.nika after cargo returns) reads resolved_versions (crates/orchestrator/src/project.rs) and writes name → versions (Lockfile::dependencies, crates/orchestrator/src/cache.rs). So a new worktree or CI takes whatever crates.io holds that day, e.g. ahash 0.8.12 vs 0.8.15 or getrandom 0.3.4 vs 0.4.3, and rewrites the committed file.

Probe (in any project with a nikaia.lock, e.g. tests/language):

rm -rf target && nikaia build && git diff --stat nikaia.lock

This shows nikaia.lock modified as soon as crates.io has a newer compatible release than the one recorded.

Decision

ADR-021 §5 is amended by the supervisor’s decision of 2026-11-29: the record pins, a build does not resolve. It follows ADR-registry-1 D7, keeps ADR-002 D1 (Cargo still resolves) and meets ADR-021 D2. In short:

To build

  1. Record the whole entry. [dependencies] in nikaia.lock holds, per resolved crate, name, version, source, checksum and dependencies (Cargo’s own fields). A lock in today’s form (name → versions) is read as “no pins”: the next build resolves and writes the new form once. The reader and writer are written in Nikaia, next to toml.nika / project_drive.nika; they replace resolved_versions (crates/orchestrator/src/project.rs) and the dependencies field’s load and save in Lockfile (crates/orchestrator/src/cache.rs). The builder chooses the file. Test: a .nika in tests/compiler/tests/ that round-trips a two-crate record (one crate at two versions) and prints it.
  2. Pin before cargo. In project_drive_drive_to, before the backend runs, write Cargo.lock into the build directory from the record. Skip this under --no-cache, and when there is no nikaia.lock (the conditions record_resolved_dependencies has today). After cargo returns, record only if the resolved graph differs from the record, which happens only when nikaia.toml changed. record_resolved_dependencies moves out of crates/nikaia/src/project.rs into Nikaia; what stays on the host is at most a file read or write (ADR-platform-layer-v1). Test: a project test whose build directory is emptied between two builds and whose nikaia.lock is byte-identical afterwards.
  3. --locked reaches Cargo. Under nikaia build --locked (and check, test, run), --locked is added to the Cargo invocation (cargo_config / the command project_drive_drive_to assembles). A manifest that needs a resolution the record lacks then fails with Cargo’s message, under this language’s words. Test: a project test with a dependency added to nikaia.toml but not to the record, built with --locked, showing the refusal on stderr.
  4. nikaia update. A subcommand in cli_commands.nika that builds with no Cargo.lock in place and records what Cargo resolved. Test: the nikaia update line in the help output and a project test showing the record rewritten.
  5. The committed locks once. Run nikaia update in each project that commits a nikaia.lock (git ls-files '*nikaia.lock') and commit the new form. This is the commit that says Fixes #N.

Done when

rm -rf target && nikaia build && git diff --exit-code nikaia.lock exits 0 in tests/language on a machine whose crates.io index is newer than the record. Step 5 carries Fixes #N. The report has one Found: line per finding.

Files and limits

Ruled out


Generated by Claude Code

Back to Open Issues