Issue #2117: std::thread::id() returns an opaque thread::Id (ADR-401)

Open and answer this issue on GitHub.

blocked, ci · opened 2026-11-18 · updated 2026-11-20 · 5 comments

Part of “Unobservable std tests” (#2088). Decided in ADR-401 (owner, 2026-11-18). Needed by “All tests in Nikaia…” (#2082) for crates/nikaia-std/src/rt/library.rs’s test a_thread_is_kept_for_the_next_call.

What happens today

Decision (ADR-401)

To build

  1. The type thread::Id (equality and hash, nothing else) and a process-wide counter with a per-thread slot filled from it on the thread’s first call to id(), not at thread start. Written as .nika where it can be; what has to stay Rust is listed in the report for “Self-hosting” (#557).
  2. Part I: a short section on std::thread with Id, id() and ADR-401 D3’s note on tasks.
  3. tests/compiler/tests/thread_id.nika: id() twice on one thread is equal; a task started with its own thread (if Part II offers one) or a library thread gives an id that is not equal; an id as a map key finds its value. A compile-fail test (.stderr) shows that arithmetic on a thread::Id is refused.
  4. A test that builds a package as a C library and calls its _async function from a small C program twice one after the other (same id()), then twice at once with the first one blocked (different id()). It replaces a_thread_is_kept_for_the_next_call; delete the Rust test. Where no C compiler is found the builder reports it, never skips silently.

Done when

Files and limits


Generated by Claude Code

Comments

keywan-ghadami, 2026-11-18

Brief queued: issue-2117


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

Issue #2117

Your work order is issue #2117, 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/2117/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/ci/issue-2117.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-18

Run: issue-2117, Result: partial: step 4 (the C-library kept-thread test that replaces a_thread_is_kept_for_the_next_call, with Fixes) and step 3’s compile-fail test of arithmetic on a thread::Id are left; steps 1, 2 and the rest of 3 are built

Tokens: input 144, cache read 5453560, cache write 131254, output 30316 Cost: 2.88 USD, time 15 min 29 s, turns 72

Report

Result: partial: step 4 (the C-library kept-thread test that replaces a_thread_is_kept_for_the_next_call, with Fixes) and step 3’s compile-fail test of arithmetic on a thread::Id are left; steps 1, 2 and the rest of 3 are built Files: crates/nikaia-std/src/runtime/thread.nika crates/nikaia-std/src/runtime/lowered/thread.rs crates/nikaia-std/src/runtime/lowered.rs crates/nikaia-std/src/thread.rs crates/nikaia-std/src/lib.rs crates/nikaia-std/std.contracts docs/specification/10-nikaia-light.md tests/compiler/tests/thread_id.nika tests/compiler/tests/thread_id.stdout tests/compiler/tests/std_compiler_module_refused.stderr tests/specification/EXPECTED.txt tests/specification/COMPILES.txt Commit: std::thread: thread::id() names the calling thread with an opaque thread::Id (ADR-401) Body: thread::Id is a Nikaia struct with one private i64 (runtime/thread.nika, lowered with Copy, Eq, Hash); thread.rs keeps what Nikaia has no word for (for Self-hosting #557): the process-wide AtomicI64 counter and a const thread-local Cell<i64> slot with no destructor, filled on the thread’s first id() (D2), so a thread that never asks costs nothing. std.contracts declares the type equates/hashes/copies with no orders, and thread::id sync with no touches; prelude re-exports thread. Part I gains 6.10 (D1-D3, with the D3 note on tasks). thread_id.nika checks that two ids on one thread are equal, that an id finds its value as a HashMap key and that a HashSet holds one member; the “another thread differs” case is left to step 4, since a task gets its own thread only at user_parallelism = yes and --both-settings would see two outcomes. The NK1186 module list gains thread; the spec baselines move by the new compiling block. Part: #2117 Pushed: local a5d5a4fb488c8b2c299df6f441a6512ead9fe7c8 Tests: thread_id and std_compiler_module_refused pass (nikaia test --both-settings); it specification:: passed; lower-std fixpoint clean (only runtime/lowered changed, by this commit); the no-arithmetic test drew NK1343 (rustc: Id does not implement Add<{integer}>), so it is not committed Gate: green Deviation: step 3’s compile-fail test (arithmetic on a thread::Id refused) is not built: the checker refuses no operator on any std type, so first + 1 reaches rustc as NK1343; step 3’s “a different thread gives a different id” moves to step 4’s library test, since a task’s own thread depends on user_parallelism and would differ between the two settings Found: arithmetic on a std type is refused by no check and reaches rustc: use std::time\nfn main() throws {\n let a = time::now()\n let b = a + 1\n println(f"{b == a}")\n} gives NK1343 “Rustc output: mismatched types” (the same for thread::id() + 1, rustc Id does not implement Add<{integer}>); it should be NK1191, as P { x: 1 } + 1 on a program’s own struct is (“You can’t use + on a P”). Traced: declared_with_no_arithmetic (check_items.nika) looks only at the file’s own struct and enum items, and std.contracts has no key that says which std types have operators (Part I writes self * 2 on a time::Duration, the simd vectors have bit operators), so a fail-closed rule needs a new contracts key; no decision yet Found: < on a type with no order is refused by no check and reaches rustc, for a program’s own struct too: struct P { x: i64 }\nfn main() throws {\n let a = P { x: 1 }\n let b = P { x: 2 }\n println(f"{a < b}")\n} gives NK1343 “Rustc output: binary operation < cannot be applied to type P”; use std::target\nfn main() throws {\n let a = target::Instruction::Crc32c\n println(f"{a < target::Instruction::Bmi2}")\n} gives NK1343 “Instruction does not implement PartialOrd”; it should be a checker refusal (Part I: order is the Ord trait, std.contracts’ orders key); cause unknown, suspected check_compare.nika (the compares/totally walk), settled by a trace of a < b through it Needs: supervisor decision: how step 4’s C caller learns that a kept library thread is idle again, since the issue forbids a sleep and asks to “wait on what the runtime says”, and rt::library says nothing: a thread lists itself idle only after the job, done included, has returned (library.rs start), so a second _async call made from done’s signal may find none idle and start a thread; e.g. list the thread idle before done runs (then a call handed to it waits for done to return, against ADR-284 D9’s “no call waits”) or a runtime query; library.rs is outside the issue’s file limits except to delete the test Changelog: std::thread — thread::id() gives an opaque thread::Id naming the calling thread, compared with ==/!= and usable as a map key or set member, taken from a counter on the thread’s first call and never reused (ADR-401); Part I 6.10. Issue: broke I4a: step 4’s “no sleep … wait on what the runtime says” names a signal the runtime does not give (rt::library lists a thread idle only after the job, done included, returned); broke I4a: step 3 assumes the checker refuses arithmetic on a std type, it refuses none (thread::id() + 1 is NK1343); broke I9: step 3’s “a task started with its own thread” cannot be one tests/compiler test, which --both-settings also runs at user_parallelism = no Owner: none Comment: none Friction: none Disk freed: none (cache 3.2G, disk 6.9G free of 252G; no new cache entry over 100 MB) Attribution: Co-Authored-By: Claude Opus 5.5 noreply@anthropic.com Claude-Session: https://claude.ai/code/session_01UVxJDtmukJNapbMLmZMzTV Reviewed: 9ee5231d1ca85d9a3d671c9efb188e47bb75c4a043c6399bfba25623036b50e3

Debrief

  1. Most turns: the compile-fail test from step 3. I built it, rustc rejected it with NK1343 instead of a checker refusal, and I then had to show the defect predates my change (time::now() + 1, < on a user struct). Second: working out that step 4 can’t be done without a sleep, which meant reading rt::library’s idle bookkeeping.
  2. Looked up: how a new std module is registered (std.contracts keys, prelude re-export, the runtime .nika lowering into runtime/lowered.rs); that adding a Part I block shifts COMPILES.txt ordinals and EXPECTED.txt; that the NK1186 module-list .stderr must be re-blessed.
  3. Checks run: the lower-std/build/lower-std cycle, thread_id and std_compiler_module_refused with --both-settings, it specification::, fmt, clippy, pre-push. Wasted: the build and run of the compile-fail test, which could never pass.
  4. One change: builder.md should say that a new std module touches std.contracts, lib.rs prelude, the NK1186 .stderr and both spec baselines, so all of them are edited before the first build.
  5. What the issue lacked:
    • broke I4a: step 4’s “wait on what the runtime says” names a signal rt::library does not give (a thread lists itself idle only after done returns).
    • broke I4a: step 3 assumes the checker refuses arithmetic on a std type; it refuses none, so thread::id() + 1 reaches rustc as NK1343.
    • broke I9: step 3’s “different thread gives a different id” cannot be one tests/compiler test, because --both-settings also runs it at user_parallelism = no.
    • knowledge: Core A new Part I code block shifts every later ordinal in tests/specification/COMPILES.txt, and EXPECTED.txt is regenerated with cargo run --profile fast -p nikaia --example specification.
  6. Traps for the next builder:
    • Fact: Core Adding a std module changes the NK1186 module list, so tests/compiler/tests/std_compiler_module_refused.stderr must be re-blessed.
    • Fact: Lowering Operators on std types and < on types with no order are not refused by any checker today; they reach rustc as NK1343, so a compile-fail test of them can’t be written yet.
    • Fact: Core Under --both-settings a task gets its own thread only at user_parallelism = yes, so a thread-identity test differs between the two runs.

Generated by Claude Code

keywan-ghadami, 2026-11-18

The report of the run of issue-2117 (#2117) judged this issue against docs/issues.md; the author fixes the issue by the rule it names (How a run judges its issue):


Generated by Claude Code

keywan-ghadami, 2026-11-20

Supervisor, 2026-11-20: blocked. The rest of this issue waits for two decisions:

Steps 1, 2 and the rest of 3 are built.


Generated by Claude Code

keywan-ghadami, 2026-11-20

Open question moved here from the closed improve issue #2124: how does the C caller learn that a kept library thread is idle (ADR-284 D9)? Either the thread is listed idle before done runs, or a runtime query is added.


Generated by Claude Code

Back to Open Issues