Issue #2474: The corpus-wide ledger tests are 4-6x slower in CI since the panics inference goes through loops

Open and answer this issue on GitHub.

blocked, ci · opened 2026-11-21 · updated 2026-11-28 · 19 comments

Part of the ci lane’s goal, a short CI run. Found while measuring the shards after “CI builds std only once” (#2082). Takes over the Founds of “the ledger’s loop proof spends its cost in bounds_returns” (#2487) and “one function’s walk blows up” (#2488), closed as duplicates of this one.

Facts: Ledger and bounds proofs, CI and caches

What happens today

Since 0.0.1511 the tests that check the whole corpus through the ledger take 4-6 times as long in CI. Per-test times from the CI logs, before → after:

The commit is 5651724e, “The ledger’s panics inference proves a unit through loops, and the lowering takes that proof” (ADR-361 D16, the fix for #2451). Its ×2.7 on packages/logic does not explain a ×10, so the first run measured (report of 2026-11-21, parent of 5651724e → develop):

Two causes are suspected in crates/nikaia-std/src/compiler/bounds_walk.nika, neither settled:

  1. bounding_returns_round (line 11441) walks every body again in each collect, D32 and keep round, and each walk proves the same loops’ invariants again through bounding_past_loop → bounding_loop_invariant (5679).
  2. bounding_past_loop (5903) walks the rest of the block again after each settled invariant (ADR-361 D10), so a run of n loops costs about n² walks.

Decision

Supervisor, 2026-11-21: a settled invariant is a function of the loop and the facts it is entered with, so it is memoized, not proved again. bounds_returns keeps, across its rounds, the invariants it settled, keyed by function, loop start and the entry facts (in a canonical form), and a round that enters the same loop with the same facts takes the stored one. Nothing is skipped: a different entry gives a different key and a fresh proof. If (2) still dominates after the cache, the re-walk after a settled loop is cut to what the invariant changed, within ADR-361 D10; if that would change D10’s meaning, stop with Needs: supervisor decision.

To build

  1. Settle the causes: count bounding_loop_invariant calls per (function, loop start) across rounds, and walks per loop in rs2nika_free_methods. Put both counts in the report.
  2. Build the invariant cache in bounds_walk.nika (Nikaia; the lowered file is output). It lives for one bounds_returns call, not across programs.
  3. If the counts of step 1 show the re-walk of (2) still quadratic, cut it as the Decision says.
  4. Add a test in tests/compiler/tests/ with a .stdout: a function with several loops in sequence and nested whose panics inference result is the same as before (the proof unchanged).
  5. Measure again with callgrind on both sites above.

Done when

Files and limits

Comments

keywan-ghadami, 2026-11-21

Brief queued: issue-2474


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

Issue #2474

Your work order is issue #2474, 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/2474/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-2474.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-2474, Result: partial

Tokens: input 148, cache read 4651010, cache write 126696, output 37094 Cost: 2.87 USD, time 65 min 25 s, turns 74

Report

Result: partial Files: none Commit: none Body: nothing committed; measured only, the instrumentation in bytes.rs and bounds.rs was removed and the files are clean again Pushed: none Tests: bytes::the_corpus_needs_no_tether, 4 local cores, wall time: parent-of-5651724e build 68.7 s, HEAD 729 s; per-file infer: benches/lowering/source.nika 29.7->673 s, of which 545 s is one function (rs2nika_free_methods, 1.74M asks); bounds_walk.nika 5.2->169 s; sv_sat.nika 10.9->38 s; all other files summed about x2 Gate: green Deviation: callgrind was run on one small corpus file (packages/logic/src/sv_strategy.nika) instead of on whole tests, because the rules allow callgrind only on small programs; the four whole tests were timed natively Found: the ledger’s loop proof (ADR-361 D16) spends its cost in bounds_returns, not in bounds_aggressive: callgrind of Ledger::infer on packages/logic/src/sv_strategy.nika (it binary, CORPUS_ONLY filter in bytes::the_corpus_needs_no_tether) gives 7.07 G Ir on the parent of 5651724e and 49.34 G at HEAD (x7.0); in that run bounds_proven goes 6.95->49.22 G, bounds_returns 6.69->47.76 G, of which bounding_loop_invariant is 40.76 G (82 % of the program), and bounds_aggressive goes 0.19->1.39 G; suspected (not settled) cause: bounds_walk.nika bounding_returns_round re-runs bounding_past_loop/bounding_loop_invariant for the same loops on every collect, D32 and keep round; the check that would settle it is counting bounding_loop_invariant calls per (function, loop start) across rounds Found: one function’s walk blows up: in benches/lowering/source.nika, fn rs2nika_free_methods (lines 20045-20259, many sequential and nested while/for loops) takes 545 s and 1,744,684 asks in the per-function walk at HEAD; the next largest functions in the file take 6.6 s (main) and 3.9 s; suspected cause: bounds_walk.nika bounding_past_loop walks the rest of the block again after each settled invariant (ADR-361 D10), which grows with the number of loops in sequence; not settled Needs: supervisor decision: may bounds_returns rounds reuse the loop invariants an earlier round found (a cache keyed by function, loop and entry facts), or must the cost be cut inside bounding_loop_invariant; the digest cache bounds::proven_taken cannot help, since each corpus test infers each file once and the 11,149 slow asks in bounds_walk.nika have 11,146 distinct normal forms Changelog: none Issue: wrong I7: 5651724e’s x2.7 does not explain the tests’ x10.6; that figure comes from bounding_loop_invariant inside bounds_returns (82 % of Ir on sv_strategy.nika) and from one pathological function in benches/lowering/source.nika Comment: #2474 callgrind of Ledger::infer on sv_strategy.nika: parent 7.07 G Ir, HEAD 49.34 G; bounds_returns 6.69->47.76 G, of which bounding_loop_invariant is 40.76 G; whole the_corpus_needs_no_tether locally 68.7 s->729 s, with 545 s in source.nika’s rs2nika_free_methods; CI job times could not be checked (no GitHub access) Friction: nikaia check views.nika checks the whole package (parent 783 s, the HEAD run was OOM-killed at 375 s), so per-file comparisons needed a temporarily instrumented it test Disk freed: 418 MB of scratch binaries; target/nikaia-project-tests 376M; / 4.6G free (89 %); no cache entry over 100 MB new in this run Attribution: Co-Authored-By: Claude Opus 5.5 noreply@anthropic.com Claude-Session: https://claude.ai/code/session_01UVxJDtmukJNapbMLmZMzTV

Debrief

  1. Most cost: getting per-file figures. Running nikaia check views.nika natively checks the whole package: 783 s on the parent, and the HEAD run was killed for running out of memory, so those turns were lost. After that I added temporary timing code to bytes.rs and bounds.rs and rebuilt the it test binary several times. I also timed natively first and ran callgrind only at the very end, which reverses the order the issue asked for.
  2. Looked up: that proven_taken / LEDGER_PROOFS cannot serve the corpus tests, because they parse each file fresh; the call path test → panics::infer → bounds_proven → bounds_returns / bounds_aggressive; that bounding_past_loop re-walks the rest of a block (ADR-361 D10/D16); and the line ranges in the 11k-line bounds_walk.nika.
  3. Checks: the whole corpus test, parent vs HEAD, was useful (68.7 s vs 729 s). Per-file timings, the per-function counts and gdb samples were useful too. One callgrind run on sv_strategy.nika was decisive. Wasted: the native check of views.nika and a duplicate timing build. Callgrind on one small file would have been enough from the start.
  4. Change to builder.md: “To compare one file’s ledger cost across two builds, run callgrind on the it binary with the bytes::the_corpus_needs_no_tether test limited to that file, never nikaia check (it checks the whole package).” That alone would have saved about 25 turns.
  5. What the issue lacked:
    • wrong I7: the ×2.7 does not explain the ×10.6. The cost is bounding_loop_invariant inside bounds_returns, plus one pathological function in benches/lowering/source.nika.
    • broke I5: the issue gives no per-file figure, and no small probe file to run callgrind on.
    • rules-gap: the issue does not rule out the digest-cache path, though each test infers each file once.
    • knowledge: Core | the corpus tests parse and infer each file once per test, so a cache across asks or units does not shorten them.
  6. Traps for the next builder:
    • Fact: Core | nikaia check FILE checks the whole package FILE belongs to, so it cannot compare one file's cost.
    • Fact: Lowering | in the ledger's bounds proof, bounds_returns (ADR-306 D21/D23) costs more than the per-function walk; look there first.

The run ended Result: partial, but my final line began with BLOCKED: because the brief’s one-line format only allows done or BLOCKED.


Generated by Claude Code

keywan-ghadami, 2026-11-21

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

callgrind of Ledger::infer on sv_strategy.nika: parent 7.07 G Ir, HEAD 49.34 G; bounds_returns 6.69->47.76 G, of which bounding_loop_invariant is 40.76 G; whole the_corpus_needs_no_tether locally 68.7 s->729 s, with 545 s in source.nika’s rs2nika_free_methods; CI job times could not be checked (no GitHub access)


Generated by Claude Code

keywan-ghadami, 2026-11-21

Run: issue-2474, Result: partial

Tokens: input 338, cache read 12063663, cache write 302097, output 119282 Cost: 7.66 USD, time 1 min 21 s, turns 169

Report

Result: partial Files: crates/nikaia-std/src/compiler/emit_core_calls.nika crates/nikaia-std/src/compiler/lowered/emit_core_calls.rs crates/nikaia-std/src/compiler/lowered.rs tests/compiler/tests/map_drain_mut_param.nika tests/compiler/tests/map_drain_mut_param.stdout Commit: A B-tree map that is a mut parameter, drained, is taken as it is Body: Found on the way to #2474’s cache (it hands a map in and out of a walk): kept.drain() on a mut BTreeMap parameter lowered to std::mem::take(&mut kept) with kept already &mut, which rustc refused (NK1343). The take-drain emitter now takes a mut parameter itself as it is (ADR-386 D2, ADR-094 D3). For #2474 itself only measurements; the bounds_walk.nika cache is not committed (see Found/Needs). Part: #2474 Tests: map_drain_mut_param (new) failed on the unfixed compiler with NK1343 in 4 places, passes now –both-settings; tests/compiler –filter drain/loop/bound 129 ok; pre-push green; cargo fmt clean; lower-std fixpoint clean Gate: green Deviation: issue item 2 (the loop invariant cache) not committed: a memo of each body’s walk in bounding_returns_round, keyed on wanted, returns, returning, checked_returning, held (sound by determinism), was built and left results unchanged (30 logic/ dumps identical), but it never hit: sv_strategy 48.36 G vs 48.22 G at HEAD. In each of its 64 lookups context.returns differed (e.g. sv_params#steps, #cases, … change every round) and wanted differed in 28 of them, so reverted Found: rs2nika_free_methods in benches/lowering/source.nika (one bounds_rounds, not in bounds_returns) makes 3583 searches / 2559 walks over 14 sequential loops, per loop 1,2,4,…,512,1024 (doubling), every search with distinct (counter-suffixed) facts, so no memo can hit; traced: bounding_past_loop (ADR-361 D10) walks the rest of the block twice, leaves and then again from invariant.past, each with nested D10, T(n)=2T(n-1); again stands only where it proves more than end, which already holds the nested walks’ results, so walking leaves without its nested re-walks can change what is proved; no decision yet Found: loop-level memo on sv_strategy (Ledger::infer 48.22 G, bounding_loop_invariant 39.76 G inclusive, 137 searches over 28 bodies x 4 rounds) has at most 17 distinct keys (facts+written+wanted+missed goals+returns+counters), an upper bound of about 13 G even at 88 % hits (target 10.6 G); a sound key needs the returns each walk reads (walk sites context.returns.get(callee), and the rules’ own walks via rules_check), suspected settleable by tracking reads in BoundsWalk; no decision yet Needs: supervisor decision: whether a D10 re-walk cut that may change proofs (walk leaves without nested re-walks, or only the statements the invariant’s names reach) is within ADR-361 D10; and whether the cache may key on tracked returns reads Changelog: Fixed: draining a B-tree map that is a mut parameter (for (k, v) in kept.drain(), m.extend(kept.drain())) no longer fails to compile Issue: #2474 meets I1-I8; its decision assumed hits across rounds that sv_strategy’s changing returns rule out Owner: none Comment: #2474 Figures: HEAD sv_strategy Ledger::infer 48.22 G (bounds_returns 46.6 G, bounding_loop_invariant 39.76 G). A per-body memo keyed on the whole context.returns never hits (returns change each round). source.nika’s rs2nika_free_methods doubles per sequential loop (1..1024 searches) from the D10 re-walk in bounding_past_loop. Friction: by mistake I ran a bare git reset -q to unstage after a pre-push check (forbidden in the shared checkout); it touched only the index, and git status before it showed no other staged files; scripts/pre-push.nika checks what is staged, so a builder has to stage before committing, and the rule gives no safe way to unstage (git restore --staged <own files>) Disk freed: target/nikaia-project-tests 376M, / 8.2G free of 252G; no new cache entry over 100 MB; crates/nikaia/examples/infer_one.rs (scratch harness) deleted Reviewed: e3ba80ffa109f0e184ef87ef87e1f16e9ac4faf41ce6347f4d219bedb6009f6f Pushed: local 3ad0db621aa362fcd3586337641eb4a2e049dea2 Attribution: Co-Authored-By: Claude Opus 5.5 noreply@anthropic.com Claude-Session: https://claude.ai/code/session_01UVxJDtmukJNapbMLmZMzTV

Debrief

  1. Most cost: the counting phase. Patching the lowered Rust with Python for counts (type-alias errors, rebuilds) took one 705 s instrumented run. Then the cache design: each try cost a std re-prove (10+ min). The decisive fact (the returns change every round) only appeared after two full cycles.
  2. Looked up: the rounds of bounds_returns and bounds_rounds, and which context fields change between them. The around.checked memo (#2396). TermArena (adopt, no hash-consing). Where the take-drain is emitted (emit_core_calls.nika). Whether a BTreeMap == works.
  3. Checks run: HEAD callgrind on sv_strategy (useful), the instrumented counts on both sites (useful), Ledger dump diffs of 30 files (useful), and the new tests plus the drain/loop/bound filters and pre-push (needed). Wasted: the first memo build with checked in its key, and part of the 705 s source.nika run (a 3-loop slice would have shown the doubling).
  4. One change: the brief should require a cheap hit-rate check of the decided cache key before any build. That is one eprintln in the lowered round, which needs no lower-std. It would have shown at once that the returns differ every round.
  5. Issue gaps:
    • wrong I7: the decision assumed loop work repeats across rounds with the same inputs. context.returns changes in every round on sv_strategy, and rs2nika_free_methods is not in bounds_returns at all.
    • rules-gap: no rule asks a decided cache to come with its expected hit rate, or the probe that measured it.
    • knowledge: Lowering | a BTreeMap drain on a mut parameter failed to compile (fixed in 3ad0db62).
  6. Facts for the next builder:
    • Fact: Core | to unstage after pre-push, use git restore --staged <own files>, never a bare git reset.
    • Fact: Lowering | for counts or a hit-rate check, patch the lowered .rs and build only the example binary (about 1 min), then rerun lower-std to restore it; a .nika change to bounds_* re-proves std for 10+ min.
    • Fact: Lowering | context.returns and wanted change in every round of bounds_returns, so a memo keyed on them never hits.

Generated by Claude Code

keywan-ghadami, 2026-11-21

Decision 2 (supervisor, 2026-11-21), after the first run’s figures (sharpened after the owner’s word, 12:10)

This decision replaces the first one. That one assumed a cache would hit across rounds, but the figures show context.returns changes every round, and rs2nika_free_methods has counter-suffixed facts, so no cache hits.

Owner, 2026-11-21: checks left until run time are meant to disappear in the long run; proof at compile time is the language’s mark. So a cut that proves less is not acceptable here, not even if it is sound. Speed may not be bought with a lost proof.

1. The D10 re-walk is cut, without losing a proof; this is the main work. In bounding_past_loop, the rest of the block is walked twice, as leaves and then as again, and each walk carries its own nested re-walks. So a run of n loops costs T(n) = 2·T(n-1). That is 1, 2, 4 … 1024 searches over 14 loops. That is a defect, not a meaning of D10: D10 decides what is asked through a loop, not how often the walk visits the rest of a block. The direction:

The re-walks of one block must stay linear in the number of loops. Whatever form is chosen, the report argues why it proves exactly what it proved before, not “probably”.

2. Not one proof is lost; that is the line.

If any of these differs, the report names each site or function with its before and after, and the run stops with Needs: supervisor decision; it commits nothing that proves less. More proved is fine and is listed.

3. The cache keyed on tracked returns reads is approved, but comes second. It is built only if sv_strategy is still above 10.6 G after the cut. Its key holds the returns each walk actually reads, tracked in BoundsWalk: the walk sites’ context.returns.get(callee) and the rules’ own walks. It must be sound by construction, with no hit when a read value differs, and it proves exactly what the walk without it proves (point 2 holds for it too).

4. Measure. Use callgrind of Ledger::infer on sv_strategy.nika and on benches/lowering/source.nika, before and after.

If the target cannot be reached without losing a proof, the run stops with the figures: that trade is the owner’s to decide, not the builder’s or the supervisor’s.

The two Founds, “rs2nika_free_methods … makes 3583 searches” (#2593) and “loop-level memo on sv_strategy” (#2594), are taken over here and closed as duplicates.

Also on the friction: unstaging your own files with git restore --staged <file>… is allowed, since it is a restore by name. A bare git reset is not.


Generated by Claude Code

keywan-ghadami, 2026-11-21

Brief queued: issue-2474-d2


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

Issue #2474

Your work order is issue #2474, 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/2474/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-2474-d2.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-2474-d2, Result: blocked

Tokens: input 290, cache read 9348141, cache write 265372, output 108162 Cost: 6.55 USD, time 2 min 41 s, turns 145

Report

Result: blocked Pushed: none (nothing committed; the cut, its lowered output and the test are saved as docs/briefs/ci/issue-2474-d2.patch, git apply clean on cfe8f04f) Tests: patch applied, 2026-11-21: lower-std --bounds --asserts report identical to base outside bounds_walk.nika; inside it, sites identical except one from + 1 the patch removes (proved.nika 1527/2358 ops, left at run time 1939, was 1527/2359 and 1940); no other lowered file changed; the 4 corpus tests ok (244 s); tests/compiler –both-settings filters several_loops_in_a_row 1, prove_check_after_loop 1, loop 50, past 23, invariant 1, flag 7, after 55, counter 20, all ok; clippy clean; pre-push green; new test passes on the old binary too (it guards an unchanged result) Gate: green Deviation: cache keyed on tracked returns reads (To build 2) not built: the cut was to come first and is now held for the decision below Found: none Needs: supervisor decision: the D10 cut (a flat trial walk of again, loops not asked, then the full again only when the trial beats end) returns only results the original returns, but by argument it cannot rule out one case: a full again stands while its trial does not, because a later loop’s own invariant settles only under the first loop’s facts. Measured, that case happens 0 times in 2910 D10 decisions of std (instrumented run: 94 stand, 2816 do not, 0 missed) and in 5 shapes built to trigger it (while j < xs.len() { if xs[j] == 2 { other = mark }; j = j + 1 } after a mark loop, then xs[other]), none of which the original proves either. The owner asked for exactly, “not probably”: commit this as it stands, or keep it held Changelog: none (nothing committed) Issue: ok by docs/issues.md; I7 holds: the 2^n re-walk is real (rs.nika past-loop searches per loop start go 1, 2, 4, … 512) Owner: decide whether a cut that is the same everywhere it was measured (all of std, 4 corpus tests, tests/compiler), but not proved the same on every program, may land Comment: #2474 Measured 2026-11-21 on cfe8f04f + patch: callgrind check src/sv_strategy.nika (packages/logic copy) total 230.9 G -> 205.7 G, panics::infer 178.4 G -> 159.3 G, bounding_loop_invariant 99.5 G -> 84.1 G; 10.6 G is out of reach for this cut, because sv_strategy pays for invariant searches, not for loops in a row (the cache, To build 2, is the next lever). check --bounds on N loops in a row: 1: 0.15 -> 0.11 s, 2: 0.36 -> 0.21 s, 4: 2.5 -> 0.37 s, 6: 12.2 -> 0.63 s, 8: 176 -> 1.3 s, 10: killed after more than 10 minutes -> 2.0 s; rs.nika (rs2nika slice of source.nika): more than 215 s -> 29 s; reports for 1-6 loops identical to the old binary’s Friction: nikaia test takes its filter only as --filter TEXT; a bare name is refused (unexpected argument), which cost one test round Disk freed: target/nikaia-project-tests absent; / 3.5G free of 252G (91 %); no cache entry over 100 MB created; scratch binaries removed Attribution: Co-Authored-By: Claude Opus 5.5 noreply@anthropic.com Claude-Session: https://claude.ai/code/session_01UVxJDtmukJNapbMLmZMzTV

Debrief

  1. Most turns and time: a design I built, measured and threw away. My first cut walked the code after the loop flat first, and it ran slower on sv_strategy (241.7 G against 230.9 G). After it came the long background cycles: lower-std with --bounds, callgrind on sv_strategy at about 200 G, the corpus tests at 4–8 minutes, and the instrumented miss-check build. At the end I spent more turns looking for a program that would show a lost proof.
  2. Looked up: how D10 works (ADR-361) and what bounding_mark/bounding_back restore. I also had to find which state is not restored: the arena, the entries counter and settled_loops. And the nikaia test --filter syntax, and that proved.nika needs the report file as its argument.
  3. Checks:
    • Useful: the instrumented miss-check (it settled the question), comparing the std report section by section, the gen2 timings, and the corpus tests and tests/compiler filters.
    • Wasted:
      • the first tests/compiler loop, with no --filter, which ran nothing;
      • a plain diff of the whole report, which can’t separate shifted line numbers;
      • the C* corpus and test runs, done again for B.
  4. Biggest saving: state the exactness standard up front, together with what counts as an argument. If the brief had said “a cut decided by a heuristic trial needs a proof that the trial never says no where the full walk stands; measurement is not enough”, I would have looked for an exact cut first, or asked before building.
  5. What the issue lacked:
    • rules-gap: it named no ruled-out design and no proof obligation for the obvious cheap cut, the flat trial.
    • knowledge: Ledger and bounds proofs | in bounding_past_loop, each D10 decision walks the tail twice, both walks in full, so n loops in a row cost 2^n.
    • broke I7: the measure target of 10.6 G for sv_strategy comes with no traced cause. Callgrind shows its cost is in bounding_loop_invariant and bounds_returns, not in loops in a row.
  6. Fact: Core nikaia test --project tests/compiler takes its filter only as --filter TEXT; a bare name is refused.
    Fact: Ledger and bounds proofs scripts/proved.nika needs the lower-std --bounds --asserts output as its argument (-- REPORT); run with no argument it prints only its usage line.
    Fact: Ledger and bounds proofs comparing two bounds reports needs a per-file comparison with line numbers stripped inside the changed file; a plain diff reports every shifted line.
  7. Fact: Ledger and bounds proofs key code: bounding_past_loop and bounding_loop_invariant in crates/nikaia-std/src/compiler/bounds_walk.nika.
    Fact: Ledger and bounds proofs measure with valgrind --tool=callgrind nikaia check src/sv_strategy.nika in a copy of packages/logic with no target/; read panics::infer inclusive.
    Fact: Ledger and bounds proofs 2026-11-21 cfe8f04f: sv_strategy total 230.9 G, panics::infer 178.4 G, bounding_loop_invariant 99.5 G; with the held cut (docs/briefs/ci/issue-2474-d2.patch): 205.7 G / 159.3 G / 84.1 G.
    Fact: Ledger and bounds proofs 2026-11-21 cfe8f04f: in std, 2910 D10 decisions, 94 stand; check --bounds on 8 loops in a row takes 176 s (1.3 s with the patch).

Generated by Claude Code

keywan-ghadami, 2026-11-21

From the report of the run of issue-2474-d2 (#2474):

Measured 2026-11-21 on cfe8f04f + patch: callgrind check src/sv_strategy.nika (packages/logic copy) total 230.9 G -> 205.7 G, panics::infer 178.4 G -> 159.3 G, bounding_loop_invariant 99.5 G -> 84.1 G; 10.6 G is out of reach for this cut, because sv_strategy pays for invariant searches, not for loops in a row (the cache, To build 2, is the next lever). check --bounds on N loops in a row: 1: 0.15 -> 0.11 s, 2: 0.36 -> 0.21 s, 4: 2.5 -> 0.37 s, 6: 12.2 -> 0.63 s, 8: 176 -> 1.3 s, 10: killed after more than 10 minutes -> 2.0 s; rs.nika (rs2nika slice of source.nika): more than 215 s -> 29 s; reports for 1-6 loops identical to the old binary’s


Generated by Claude Code

keywan-ghadami, 2026-11-21

Driver: not queued, this issue waits for #2632, which is still open (#1819). Set ready again when it is closed.


Generated by Claude Code

keywan-ghadami, 2026-11-21

Decision 3 (supervisor, 2026-11-21)

The d2 run’s cut (a flat trial walk of again, then the full again only when the trial beats end) is held, not landed. It was measured identical: 0 differences in 2910 D10 decisions of std and in 5 crafted shapes. But it is not proved identical. A full again can stand while its trial does not, because a later loop’s invariant may settle only under the first loop’s facts. A speed-up that may cost a proof is the owner’s trade, not the supervisor’s (owner, 2026-11-21: “exactly, not probably”). The patch stays in docs/briefs/ci/issue-2474-d2.patch for reference.

Next run (d3): build the exact route first. This is To build 2 of the issue, which d2 did not build.

  1. Build the invariant memo in bounds_walk.nika. Its key is (function, loop start, canonical entry facts), and it lives for one bounds_returns call. A hit returns the very invariant a fresh proof would settle. A different entry gives a different key and a fresh proof.
  2. Measure whether the memo removes the 2^n of D10. Each D10 decision walks the tail twice. If the tail’s loops are entered with the same facts, both walks should hit the memo. Report the counts: hits and misses per (function, loop start) on rs2nika_free_methods, on the 8- and 10-loop shapes of d2’s test, and on sv_strategy.nika.
  3. Keep d2’s test several_loops_in_a_row_are_each_asked_through_once with its .stdout and .bounds (the proof unchanged).
  4. Run callgrind again on sv_strategy.nika, and time the N-loops shapes against d2’s figures.

Limits. No heuristic cut, no trial walk, nothing that is measured but not proved to give the same proof. If the memo alone leaves a cost that only a cut can remove, stop with Result: blocked and the figures. A cut that is not proved identical goes to the owner as a decision.

Recorded here, so the driver’s “D10 cut” decision issue is closed in favour of this comment.


Generated by Claude Code

keywan-ghadami, 2026-11-21

Brief queued: issue-2474-d3


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

Issue #2474

Your work order is issue #2474, 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/2474/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-2474-d3.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-2474-d3, Result: blocked

Tokens: input 86, cache read 2935116, cache write 77734, output 25649 Cost: 1.77 USD, time 0 min 39 s, turns 43

Report

Result: blocked Pushed: none (nothing committed; the memo was measured, not built) Tests: 2026-11-21 on fbdea3925, measured with an env-gated hit counter patched into the lowered bounds_walk.rs and built once (the lowered file was restored by copy, target/fast rebuilt clean, git status of crates/ unchanged). The memo key was loop node, start, entry facts as text, ints, evicted, written, poisoned, wanted, missed goals since open, outer turn guesses and context.returns. No test was run because nothing changed. Gate: green Deviation: To build 2 (the invariant memo) not built: Decision 3 stops the run when the memo alone leaves a cost that only a cut removes, and the counts below show exactly that; d2’s test was not re-added, because it belongs to the held cut patch Found: none Needs: supervisor decision: an exact invariant memo cannot remove D10’s 2^n, because each past-loop walk’s entry facts differ between the leaves and again walks of every loop before it. For N loops in a row, each with its own counter (let mut iK = lo; for j in lo..<hi { if a[j] < K { iK = iK + 1 } }; out.push(a[iK])), loop K is walked past 122^(K-1) times, and its invariant search hits the memo in exactly half of those calls. Under check --bounds, N=8 takes 273 s, of which 226 s are searches and 80 s hits; N=10 takes 1670 s, of which 1414 s are searches and 549 s hits. So the memo saves at most about a third, and the misses still double per loop. Left to the owner: a cut that is not proved identical (d2’s patch), or a proof that such a cut keeps every result Changelog: none Issue: wrong I7: Decision 3 expected both D10 walks to enter the tail’s loops with the same facts and hit the memo, but they hit only 50 % on loops in a row and 0 % in rs2nika_free_methods; rules-gap: Decision 3 again decided a cache before its hit rate was measured, the gap the first run’s debrief named Owner: may a D10 cut that is not proved identical land? An exact memo cannot reach the figures: rs2nika_free_methods 0 hits in 3583 searches, sv_strategy at most 1169 of 3015 hits even with an unsound key that ignores context.returns Comment: #2474 Memo hit rates measured 2026-11-21 on fbdea3925 with an env-gated counter, key = (loop, entry facts as text, written, poisoned, wanted, missed goals, outer turn guesses, context.returns). sv_strategy.nika: check 19 s; 4063 past-loop walks; 3015 invariant searches take 9.3 s, and 903 hits would save 1.7 s. With context.returns left out of the key (an unsound upper bound), 1169 hits would save 2.8 of 11.5 s. benches/lowering/source.nika: check 690 s; 9558 searches take 492 s, and 550 hits would save 6.4 s. rs2nika_free_methods alone: 5151 past-loop walks, 3583 searches, 427 s, 0 hits; past-loop walks per loop start go 1, 2, 4 … 512. One loop at byte 817536 has 1024 searches taking 372 s. N loops in a row, each with its own counter: loop K is walked past 122^(K-1) times and hits 50 %. N=8: 273 s total, 226 s in searches, 80 s in hits. N=10: 1670 s, 1414 s, 549 s. N<=4 has no search at all. The exact memo leaves the 2^n. Friction: a memo’s hit rate was measurable without lower-std only by hand-patching the lowered .rs (a format! key plus an eprintln) and building once per key variant; a first build failed because String in that file is the Text alias Disk freed: target/nikaia-project-tests absent; / 5.5G free of 252G (86 %); no cache entry over 100 MB created; scratch binaries and the logic copy removed Attribution: Co-Authored-By: Claude Opus 5.5 noreply@anthropic.com Claude-Session: https://claude.ai/code/session_01UVxJDtmukJNapbMLmZMzTV

Debrief

  1. Most time: the two long traces. source.nika took 690 s and the 10-loop shape 1670 s, both under the counter. Two counter builds (about 1.5 min each) and one failed build (the String/Text alias) cost less.
  2. Looked up: whether “waits for #2632” still blocked the run. The prompt did not hold its state, and I found it only through the d2 report’s Needs: and found.txt. Also the byte range of rs2nika_free_methods, d2’s test shape (only in the patch, its N-loop shapes gone), and which walk fields an invariant search writes (about 70).
  3. Checks: useful were the counter runs on N = 2…10 loops in a row, on sv_strategy (19 s) and on source.nika, and the run with context.returns left out of the key. Wasted: the N-loop shape with one shared, reset counter, which never searches an invariant. Running N=10 added little, since 6 and 8 already showed the doubling.
  4. One change: a brief that decides a cache should carry the cache’s measured hit rate, or ask for it as step 1 with the counter recipe (key text, one eprintln in the lowered file). Then this run takes about 20 turns and no decision round is spent on it.
  5. Issue:
    • wrong I7: Decision 3 assumed both D10 walks enter the following loops with the same facts. Measured, they hit 50 % on loops in a row and 0 % in rs2nika_free_methods.
    • rules-gap: no rule asks a decided cache to come with its measured hit rate. This is the second run on this issue to find out.
    • broke I5: the dependency on #2632 was stated, but its closing was not; only Decision 3’s prose implied it.
    • knowledge: Ledger and bounds proofs | an invariant search writes into most of BoundsWalk's roughly 70 fields, so a sound memo must replay those writes on a hit, not only return the result.
  6. Fact: Lowering | in a lowered .rs, String is the Text alias, so a hand-written counter builds its keys with format!, not .to_string() on a slice. Fact: Ledger and bounds proofs | benches/lowering/source.nika exits 1 with NK1102 refusals of the old bench text, but the panics inference still runs over the whole file.
  7. Fact: Ledger and bounds proofs | 2026-11-21 fbdea3925: check sv_strategy.nika (packages/logic copy) takes 19 s, with 3015 invariant searches over 9.3 s and an exact memo hitting 903. Fact: Ledger and bounds proofs | 2026-11-21 fbdea3925: in rs2nika_free_methods, 3583 searches take 427 s with 0 memo hits, and one loop (byte 817536) has 1024 searches over 372 s. Fact: Ledger and bounds proofs | 2026-11-21 fbdea3925: with N loops in a row, loop K is walked past 12·2^(K−1) times; check --bounds takes 273 s at N=8 and 1670 s at N=10.

Generated by Claude Code

keywan-ghadami, 2026-11-21

From the report of the run of issue-2474-d3 (#2474):

Memo hit rates measured 2026-11-21 on fbdea3925 with an env-gated counter, key = (loop, entry facts as text, written, poisoned, wanted, missed goals, outer turn guesses, context.returns). sv_strategy.nika: check 19 s; 4063 past-loop walks; 3015 invariant searches take 9.3 s, and 903 hits would save 1.7 s. With context.returns left out of the key (an unsound upper bound), 1169 hits would save 2.8 of 11.5 s. benches/lowering/source.nika: check 690 s; 9558 searches take 492 s, and 550 hits would save 6.4 s. rs2nika_free_methods alone: 5151 past-loop walks, 3583 searches, 427 s, 0 hits; past-loop walks per loop start go 1, 2, 4 … 512. One loop at byte 817536 has 1024 searches taking 372 s. N loops in a row, each with its own counter: loop K is walked past 12*2^(K-1) times and hits 50 %. N=8: 273 s total, 226 s in searches, 80 s in hits. N=10: 1670 s, 1414 s, 549 s. N<=4 has no search at all. The exact memo leaves the 2^n.


Generated by Claude Code

keywan-ghadami, 2026-11-21

Driver: not queued, this issue waits for #2646, which is still open (#1819). Set ready again when it is closed.


Generated by Claude Code

keywan-ghadami, 2026-11-21

Supervisor, 2026-11-21: run 3 measured the exact memo of Decision 3 and did not build it. The entry facts of each past-loop walk differ between the leaves and again walks of every loop before it, so the memo hits 50 % for N loops in a row and 0 % in rs2nika_free_methods; it would save at most a third, and the misses still double per loop. Decision 3 was wrong to assume equal entry facts.

The 2^n of the walk past loops is now its own issue, with the rule that a cut lands only with a proof that every result stays the same: “The walk past n loops in a row costs n walks, not 2^n, with a proof that every result stays the same” (#2646), queued in the ci lane. This issue stays blocked until it is closed; then its last step (the CI durations of heavy-rest and it-2) is checked again.


Generated by Claude Code

keywan-ghadami, 2026-11-21

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

#2646’s run (2026-11-21, f03819a5e) found no exact cut: run 2’s trial loses s - k in a 2-loop probe where the second loop’s invariant needs the first loop’s (paper docs/briefs/ci/issue-2646-decision.md); this now waits for an owner decision on whether D10 may prove fewer checks for linear cost


Generated by Claude Code

keywan-ghadami, 2026-11-22

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

On HEAD 1bf6cc59f, check --bounds on sv_strategy.nika spends 34 % of its walk time (11.8 of 34.5 s) in the report’s proven_traced, which repeats proven_for_lowering’s walk of the same parse with equal inputs; lower-std and builds already reuse that walk through proven_taken. A per-pass memo inside bounds_walk.nika would save under 1 % (96 of 8100 passes).


Generated by Claude Code

keywan-ghadami, 2026-11-22

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

Fact: Ledger and bounds proofs check --bounds packages/logic/src/sv_strategy.nika 373.2 G -> 268.8 G Ir after the report takes the ledger’s kept proof (2026-11-22, #2711, on 4e16455e0)

Generated by Claude Code

keywan-ghadami, 2026-11-28

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

nikaia check --tethers --user-parallelism yes benches/lowering/source.nika (target/fast, 5baec0db4) printed nothing in 60 minutes and was stopped; #2474 quotes 673 s per infer


Generated by Claude Code

Back to Open Issues