Issue #2442: Where the compiler states its own untrusted-paths allowance (ADR-raw-sinks-1 D15)

Open and answer this issue on GitHub.

blocked, safety · opened 2026-11-20 · updated 2026-11-22 · 4 comments

Part of #2302

Decision

Owner, 2026-11-21: alternative C, written as ADR-raw-sinks-1 D17 (commit 83ab4b0cf). The compiler gets no [allow] line for its build paths; it proves them.

Found

project_drive.nika’s rustc wrapper reads paths from Cargo dep-info and the compiler’s record (about lines 685-728, 1644) and writes to rustc’s --out-dir (about 1664, 1682, 1685). Today these are fs::Root::Anywhere with outside data (file, args): NK1308 in the self-check.

To build

  1. Probe first. Check that the prover accepts path::is_below(p, root) with root from env::var("NIKAIA_GEN_DIR") / env::var("CARGO_TARGET_DIR") as the proof for a read/write through fs::Root::Dir(root) (D12, D14). If it does not, stop: Result: blocked, Found: the probe (a few lines), Needs: supervisor decision. No trusted:, no [allow].
  2. Reads: before the cache reuses a run, every dep-info and record path is proved below NIKAIA_GEN_DIR and read through a root on it. A path outside: no cache for this run, rustc runs (D17.3); not an error.
  3. Writes: --out-dir is proved below CARGO_TARGET_DIR; outputs are written through a root on it. Outside: no cache, rustc runs.
  4. Manifest: add crates/nikaia-std/nikaia.toml with an empty [allow]; project_check_raw_sinks_in_std (project_check.nika:333) reads its allowances from it instead of allow=[]; --trust shows them (trust::render_allowed).
  5. Tests (.nika with .stdout/.stderr): the self-check reports no NK1308 for project_drive; a dep-info path outside the root skips the cache and the build still succeeds.

Done when

The self-check of std reports no NK1308 in project_drive.nika, crates/nikaia-std/nikaia.toml exists with zero allowances and is read by the check, and no trusted: or Root::Anywhere with outside data remains on these paths.


Generated by Claude Code

Comments

keywan-ghadami, 2026-11-21

Brief queued: issue-2442


agent: builder model: opus max_turns: 200 budget_usd: 30 effort: medium —

Issue #2442

Your work order is issue #2442, inlined below with its comments. There is no brief written around it: plan your own steps from its To build list, build them in order, commit after each finished step, and end when its Done when holds (or at the limits of builder.md, reporting what is left). The facts in your prompt are Core of docs/builder-facts.md; more on a topic: nikaia run scripts/syntax.nika -- KEYWORD, a probe: nikaia run scripts/probe.nika -- SNIPPET.

Measure the issue against docs/issues.md while you work: what it lacked, what was wrong in it. That answer goes into the report’s Issue: field. A finding, a changed plan or a finished item also goes into the issue as a comment (gh api repos/Nikaia-Foundation/Nikaia/issues/2442/comments -F body=@file, ending with the Claude Code footer), rule I13.

Rules (CLAUDE.md; shared checkout)

Report (at most 15 lines, to exactly /home/user/Nikaia/docs/briefs/safety/issue-2442.md.report.md)

Fields: Result, Files, Commit, Body (optional), Fixes, Pushed, Tests, Gate, Deviation, Found, Needs, Changelog, Issue, Owner (a question for the owner), Comment (#N <text>, what to say on another issue; the driver posts it, one line each), Friction, Disk freed, and last Attribution: with your commit trailer lines below it.


Generated by Claude Code

keywan-ghadami, 2026-11-21

Run: issue-2442, Result: partial: items 2 (the store reads only) and 5 (the outside-path test) built; left: item 2 for the outer Cargo-fresh record (project_drive.nika 685-728), item 3 (writes), item 4 (manifest), each waiting for a supervisor decision

Tokens: input 112, cache read 3955388, cache write 90626, output 30054 Cost: 2.17 USD, time 7 min 22 s, turns 56

Report

Result: partial: items 2 (the store reads only) and 5 (the outside-path test) built; left: item 2 for the outer Cargo-fresh record (project_drive.nika 685-728), item 3 (writes), item 4 (manifest), each waiting for a supervisor decision Files: crates/nikaia-std/src/compiler/project_drive.nika crates/nikaia-std/src/compiler/lowered/project_drive.rs crates/nikaia-std/src/compiler/lowered.rs tests/compiler/tests/rustc_store_reads_only_below_the_generated_sources.nika tests/compiler/tests/rustc_store_reads_only_below_the_generated_sources.stdout Commit: The rustc store reads the inputs it records only below NIKAIA_GEN_DIR, through a root on it (ADR-raw-sinks-1 D17.1) Part: #2442 Body: ProjectDriveRustcStore gets within (NIKAIA_GEN_DIR and /) and sources (fs::Root::Dir on it); no NIKAIA_GEN_DIR means no store. project_drive_rustc_inputs (record) and project_drive_rustc_reused (reuse) take each path’s part below within (new project_drive_rustc_below, guarded by path::is_below) and read it under sources. A path outside means nothing is recorded or reused and rustc runs (D17.3). This removes NK1308 at the old lines 1644 and 1685. Probe of item 1 passed: let gen = env::var("NIKAIA_GEN_DIR") ?? return; let gen_root = fs::Root::Dir(gen.clone()); let rest = line.strip_prefix(f"{gen}/") ?? continue; if !path::is_below(rest) { continue }; fs::read(rest, gen_root), with a line from fs::read_to_string, gives Checked. The same form with CARGO_TARGET_DIR and fs::write/fs::copy under Root::Dir(target) also gives Checked. Pushed: local 7af31096565c2a67b767f5bf9fbbfb3125d69912 Tests: new rustc_store_reads_only_below_the_generated_sources passes; on the unfixed binary it FAILED (an input outside: built 0; outside rustc reused). rustc_runs_once_on_the_same_rust passes. pre-push green. lower-std fixpoint clean. Self-check of project_drive.nika: NK1308 left at 685, 694, 698, 727, 728 (outer record) and at the store’s two fs::copy calls (old lines 1664 and 1682). No Rust changed. Gate: green Deviation: item 3 not built: Cargo gives rustc no CARGO_TARGET_DIR. In the default (shared) build the orchestrator passes --target-dir (crates/orchestrator/src/project.rs:474), so D17.2 as written would turn the store off for every default build. Deviation: item 2 not built for the outer Cargo-fresh record (#1750, project_drive_fresh/project_drive_record): Cargo’s {binary}.d lists crates/nikaia-std/src/*.rs and the program’s .nika sources, none below NIKAIA_GEN_DIR, so D17.1 as written would turn that cache off for every build. Deviation: item 4 not built: a nikaia.toml in crates/nikaia-std makes every file below it a project member (orchestrator Layout::resolve searches upward for nikaia.toml), which changes check, run and lower-std of std files. Found: wrapper writes have no root in the environment (no decision yet): an env-printing RUSTC_WRAPPER under env -u CARGO_TARGET_DIR cargo build --target-dir X sees no CARGO_TARGET_DIR. The outer could export it beside --target-dir, but project_drive.nika:980 (check_dir = env::var("CARGO_TARGET_DIR") ?? ...) and nested cargo calls would then share the outer target dir, the Cargo-lock wait of #1774. A NIKAIA_ variable or another root needs choosing; expected after the decision: the store’s fs::copy calls (project_drive.nika, around lines 1676 and 1694) carry no NK1308 and the store still hits in a default build. Found: the outer Cargo-fresh record cannot be kept below NIKAIA_GEN_DIR (no decision yet): target/nikaia-project-tests/rlib//x86_64-unknown-linux-gnu/debug/locker-*.d names 26 files in /home/user/Nikaia/crates/nikaia-std/src. The roots it needs (the sysroot, the project root, the target dir) must be chosen; expected after the decision: no NK1308 at project_drive.nika 685-728 and #1750's cache still hits. Found: the place of the compiler's manifest (no decision yet): crates/nikaia-std/nikaia.toml (D17.5) would be found by Layout::resolve (crates/orchestrator/src/cache.rs:680) for every std source, turning `nikaia check crates/nikaia-std/src/compiler/X.nika` into a project build. Needed: Layout::resolve skips it, or another file name or path, or the manifest is read at comptime. Needs: supervisor decision Changelog: The compiler's rustc store reads the inputs it records only below its generated sources; an entry naming a file elsewhere is not reused, and rustc runs (ADR-raw-sinks-1 D17.1). Issue: wrong I7: item 2 assumes every dep-info and record path lies below NIKAIA_GEN_DIR, but the outer record lists std's and the program's sources; wrong I7: item 3 assumes CARGO_TARGET_DIR is in the wrapper's environment, but Cargo sets none and the default build uses --target-dir; rules-gap: item 4 places nikaia.toml where project discovery picks it up Owner: none Comment: #2442 Store reads built (D17.1). Writes, the outer #1750 record and the manifest's place each need a decision; the report's Found lines give the probes. Friction: each `nikaia check crates/nikaia-std/src/compiler/project_drive.nika` takes 4-5 minutes (it checks the whole compiler module set), so one self-check costs as much as a build Disk freed: none; target/nikaia-project-tests 1.3G, / 9.1G free (77% used), no new cache entry over 100 MB Reviewed: ef594cdacd72508442d7074437329bf1ee47158e1d5c73f4af960ca1b8745be3 Attribution: Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UVxJDvbkNUUMs8HdjJ8ixV

Debrief

  1. What cost the most time: the self-check, nikaia check crates/nikaia-std/src/compiler/project_drive.nika. Each run took 4–5 minutes and I ran it three times. The cycle (lower-std, build, fixpoint) took about 15 minutes more. Turns went to proving the issue’s premises wrong: that CARGO_TARGET_DIR reaches rustc, and that dep-info paths lie under NIKAIA_GEN_DIR.
  2. What I looked up that the brief could have handed me: D11–D17 of ADR-raw-sinks-1. Also that the target dir reaches Cargo as --target-dir (orchestrator/src/project.rs:474). Also that Layout::resolve walks upward looking for nikaia.toml, and that rustc_runs_once_on_the_same_rust is the store’s existing test.
  3. Checks run, and which were wasted:
    • Run: the item-1 probe and two negative probes; the wrapper-env experiment with Cargo; the test on the old binary (fails-before); one cycle and the fixpoint build; two tests; pre-push; the self-check three times.
    • Wasted: the second self-check, which died on a ?? type error I could have caught with a probe. The third one only repeated what the second had already shown.
  4. The one change that would have saved the most: a builder.md note on how slow the self-check is. Put new code in a scratch probe first, and run the slow self-check once, at the end.
  5. What the issue lacked:
    • wrong I7: item 2 assumes every dep-info and record path lies below NIKAIA_GEN_DIR. The outer #1750 record lists std’s sources and the program’s .nika sources.
    • wrong I7: item 3 assumes the wrapper sees CARGO_TARGET_DIR. Cargo never passes it, and the default build uses --target-dir.
    • rules-gap: item 4 places a nikaia.toml where project discovery (Layout::resolve) picks it up. No rule asks an issue to check what a new manifest’s place does to discovery.
    • knowledge: Core | The compiler's own emitter writes no include!, so a program crate's rustc dep-info names only generated files; to test a store input outside them, plant a line in an entry's kept/inputs.
  6. Traps the next builder will meet:
    • Fact: Core | nikaia check of one crates/nikaia-std/src/compiler/*.nika file checks the whole compiler module set and takes 4-5 minutes, so try forms in a scratch probe first and self-check once.
    • Fact: Core | Cargo sets no CARGO_TARGET_DIR for rustc or a RUSTC_WRAPPER, and nikaia's default build passes --target-dir, so a wrapper cannot learn the target dir from the environment.
    • Fact: Core | A nikaia.toml anywhere above a file makes it a project member (Layout::resolve walks up), so never add one under crates/.

Generated by Claude Code

keywan-ghadami, 2026-11-21

From the report of the run of issue-2442 (#2442):

Store reads built (D17.1). Writes, the outer #1750 record and the manifest’s place each need a decision; the report’s Found lines give the probes.


Generated by Claude Code

keywan-ghadami, 2026-11-22

Supervisor, 2026-11-22: what is left of this issue after its run (items 3 and 4 and the outer record) moved to “The compiler’s build writes and outer record proved below their roots” (#2460) as ADR-raw-sinks-1 D17.6-8. Relabelled from ready to blocked. Needs #2460


Generated by Claude Code

Back to Open Issues