Open and answer this issue on GitHub.
ledger, blocked, ci · opened 2026-11-21 · updated 2026-11-29 · 12 comments
Blocks “The corpus-wide ledger tests are 4-6x slower in CI since the panics inference goes through loops” (#2474). Found by its third run (docs/briefs/ci/issue-2474-d3.md.run1.report.md).
Facts: Ledger and bounds proofs
bounding_past_loop (crates/nikaia-std/src/compiler/bounds_walk.nika) walks the statements after a loop twice: leaves from the facts past the loop, and, where the loop’s invariant settles, again from the facts with the invariant; again stands only where it proves more. Each of the two walks meets the later loops and walks past each of them twice again, so a run of n loops costs 2^n walks of what follows.
Measured (counter in the lowered bounds_walk.rs, check --bounds), 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])):
rs2nika_free_methods in benches/lowering/source.nika: 5151 past-loop walks, 3583 searches over 427 s; walks per loop start go 1, 2, 4 … 512; one loop (byte 817536) has 1024 searches over 372 s.Two routes tried, neither enough:
docs/briefs/ci/issue-2474-d2.patch, held): again is first walked without asking its loops again, and in full only where the trial beats end. 0 differences in 2910 D10 decisions of std, 10 loops in 2 s. Not proved: a full again could stand while its trial does not, where a later loop’s invariant settles only under the first loop’s facts.leaves and again walks of each loop before it, so the memo hits 50 % (N loops), 0 % in rs2nika_free_methods, and saves at most a third. The misses still double per loop.Supervisor, 2026-11-21: the owner’s rule stands, “exactly, not probably”: no cut lands that is only measured identical. The cut lands with a proof - an argument in the report, by the code, that for every program it returns exactly the proofs the double walk returns - and a test that pins the shapes where it matters. This keeps every proof, so it is not the owner’s trade; if no exact cut is found, the run stops (Result: blocked) and the question whether the walk past loops may change what it proves goes to the owner as a decision paper.
Candidates, in order:
again returns.again proves at least what leaves proves, and leaves is needed only to find the wanted names. Show monotonicity in the code (or name what breaks it - a budget, poisoned, written - which is then its own finding), and find wanted without the full recursive leaves.bounding_past_loop, bounding_loop_invariant, bounding_stmts and run 2’s patch; write the argument for the chosen candidate in the report first. If neither can be proved, stop as the Decision says, with the case that breaks it as a probe.bounds_walk.nika (Nikaia; the lowered file is output).tests/compiler/tests/ with a .stdout: several loops in a row and nested, including a later loop whose invariant needs the first loop’s, whose results are the same as before.Ledger::infer on packages/logic/src/sv_strategy.nika and on benches/lowering/source.nika.rs2nika_free_methods no longer dominates source.nika.crates/nikaia-std/src/compiler/bounds_walk.nika and its lowered output, tests/compiler/tests/.#[ignore] a test, or weaken a proof. Do not take the performance lane’s issues.Brief queued: issue-2646
agent: builder model: opus max_turns: 200 budget_usd: 30 effort: medium —
Your work order is issue #2646, 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/2646/comments -F body=@file,
ending with the Claude Code footer), rule I13.
develop in the main checkout; other agents’ uncommitted files are not yours: never touch or stage them.target/fast/nikaia run scripts/commit.nika -- REPORT (it adds exactly the report’s Files:); the driver pushes.cargo build --profile fast -p nikaia, lower-std and its fixpoint when a tools/*.nika changed, cargo fmt, cargo clippy --all-targets -- -D warnings, nikaia run scripts/pre-push.nika, the tests the issue names and the ones your change touches.CHANGELOG.md, badges and NK codes are the supervisor’s. New tests in Nikaia only: a Rust test file an older issue names is built as a tests/compiler/tests/ program, no Deviation: and no Issue: point (I9, #1671).Body:. Found: is only for what lies outside the area, cannot be fixed this run or needs a decision; the driver files it as an issue.std or the toolchain lacks stops the work, unless an ADR or Part I-III refuses it (name it): Result: blocked, Found: the gap with a probe, Needs: supervisor decision.NIKAIA_CACHE_LIMIT=2G; at the end delete your own clone’s target/ and target/release/nikaia-scratch.suspected, or does not mark (docs/issues.md I7), is a hypothesis: run the check that settles it (nikaia run scripts/where.nika -- NAME, the probe with a trace, callgrind for a cost) before you build on it (owner, 2026-11-16). Shown false: say so in Issue: as wrong I7: <what the check showed> (the driver comments it on the issue) and follow the real cause.Result: partial with what you ruled out, the probe, and the suspected file and function./home/user/Nikaia/docs/briefs/ci/issue-2646.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.
Result:, Gate: (green or red <check>), Deviation:, Found: and the other fields with nothing to say hold the bare word: done, none. Anything after it reads as content.Result: done only when the issue’s Done when holds; partial with the items left otherwise.Deviation: only for an item of the issue built otherwise than written, or not built. Found: only for a defect outside your area, or one this run cannot fix: one defect per Found: line, with its probe and the output it gives, only the shapes that fail today, and the suspected file and function or cause unknown (#1695); a by-design behaviour is none (#1677). A correct program your own change refuses (a fail-closed check’s false refusal) is no Deviation: but one Found: line per shape, with its probe (#1680). Everything else goes into Body:; how you verified goes into Tests:.Issue: by docs/issues.md, How a run judges its issue: complete, or broke I<n>: ..., rules-gap: ..., wrong I<n>: ..., joined with ;; a point your own commit built gets (built) after its kind (rules-gap (built): ...), and the driver does not file it. complete is the bare word: prose after it (complete; the earlier runs ...) is filed as an improvement issue (#1931); history or a note for your own issue goes into Body: or Comment: #N <text>.done <sha>, report <path> (or BLOCKED: ... / PUSH REJECTED ...).Generated by Claude Code
Run: issue-2646, Result: blocked
Tokens: input 90, cache read 3412183, cache write 97976, output 37734 Cost: 2.27 USD, time 0 min 23 s, turns 45
Result: blocked
Files: none
Commit: none
Body: No exact cut found, so per the Decision nothing is committed; the decision paper for the owner is docs/briefs/ci/issue-2646-decision.md (options A-D, recommendation C). Candidate 1 (run 2’s trial) is refuted by a probe; candidate 1 refined and candidate 2 (monotonicity) are refuted from the code of bounds_walk.nika. The gap was found with an env-gated detector (thread-local trial flag; NIKAIA_D10=check runs the trial, then the full again, and prints D10GAP where the full again stands but its trial does not) patched into the lowered bounds_walk.rs and built once. The lowered file was then restored by copy (md5 9b4560cf… matches HEAD) and target/fast rebuilt clean.
Fixes: none
Pushed: none
Tests: 2026-11-21 f03819a5e, scratch detector build: the probe in Needs gives 8 D10GAP at byte 161; packages/logic/src/sv_strategy.nika has 4063 past-loop walks and 0 gaps (20 s); crates/nikaia-std/src/compiler/libraries.nika: 11654 walks, 0 gaps before the 900 s timeout cut it off (bounds_walk.nika and ledger.nika were not reached: the background limit stopped the run). No test run, nothing changed
Gate: green
Deviation: To build 2-5 not built: the Decision stops the run when no exact cut can be proved (step 1’s argument fails for both candidates)
Found: none
Needs: owner decision: may the walk past loops (bounding_past_loop, ADR-361 D10) prove fewer checks than today in rare shapes, so that n loops in a row cost linear walks instead of 2^n? Paper: docs/briefs/ci/issue-2646-decision.md. Candidate 1 (run 2’s trial) loses a proof: let mut k = lo; let mut s = lo; let mut t = lo; while t < hi { t = t + 1; if a[t - 1] > 0 { s = s + 1 }; if a[t - 1] > 5 { k = s } }; while t < a.len() { t = t + 1; if a[t - 1] > 2 { s = s + 1 }; if a[t - 1] > 7 { k = s } }; return a[s - k] (fn chained(a: ref Vec[i64], lo: i64, hi: i64) -> i64 with assert(0 < lo), assert(lo <= hi), assert(hi <= a.len())): s - k proved today, s - k checked: a counter the loop on line 8 changes ... (ADR-361 D13, #1634) under the trial, because the second loop’s invariant settles only from the first loop’s invariant. Candidate 1 refined (ask a later loop that changes a differing name) keeps that shape but has no proof for the loops it skips: the reach check bounding_proves asks bounding_known’s 48 nearest of up to 256 held facts, and a candidate may read names the loop leaves alone. Candidate 2 fails because the walk is not monotone in its entry facts: bounding_hold evicts and most_facts outranks; again starts from invariant.past, not a superset of leaves’ facts; it stands by count, not inclusion; and the state outside BoundsMark carries over between walks
Changelog: none
Issue: wrong I7: the Decision expected one of its two candidates to be provable, but the walk is not monotone (most_held/most_facts caps, the count-based stand rule, state outside BoundsMark), and run 2’s gap holds in a 2-loop probe
Owner: may ADR-361 D10’s walk past loops prove fewer checks than the double walk in shapes like the probe in Needs (a later loop whose invariant settles only from an earlier loop’s invariant), in exchange for linear cost? Recommended: run 2’s trial plus a later loop asked through in the trial wherever it changes a name the earlier invariant reads, with the probe pinned as a test
Comment: #2474 #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
Friction: checking whether a cut changes results needed a hand-patched lowered bounds_walk.rs, a build and a restore in the shared checkout, because no --bounds mode compares the full D10 walk against a trial
Disk freed: target/nikaia-project-tests absent (nothing cached by this run, no entry over 100 MB); / 6.8G free of 252G (83 %); scratch detector binary removed
Attribution:
Co-Authored-By: Claude Opus 5.5 noreply@anthropic.com
Claude-Session: https://claude.ai/code/session_01UVxJDtmukJNapbMLmZMzTV
most_held 256, most_facts 48), and that --bounds-trace LINE shows a loop’s search rows only at the loop’s own line.off, check and trial run side by side), the gap6 example, and sv_strategy (20 s, 0 gaps). Wasted were the shapes that never searched an invariant, and starting three compiler files in a row: one check of a std file ran past 900 s.bounds_walk.rs, behind an env var.wrong I7: the Decision expected one of the two candidates to be provable. The code is not monotone: fact caps, a count-based stand rule, and state outside BoundsMark that carries between walks.rules-gap: no rule asks an issue that demands a proof to say first whether the code’s shape allows one. Here the caps and the count rule rule it out.knowledge: Ledger and bounds proofs | an invariant search is needed only where the per-turn steps and relatives rules cannot state the relation, e.g. a reset like k = s; shapes where a counter only steps are proved without one.Fact: Ledger and bounds proofs | a scratch counter or flag in the lowered bounds_walk.rs must be thread_local, not a static atomic, because the ledger's first search runs in parallel.
Fact: Ledger and bounds proofs | nikaia check on one crates/nikaia-std/src/compiler/*.nika file with a D10 detector runs past 900 s; use packages/logic files for whole-file checks.Fact: Ledger and bounds proofs | 2026-11-21 f03819a5e: check packages/logic/src/sv_strategy.nika makes 4063 past-loop walks in 20 s; run 2's trial misses 0 proofs there.
Fact: Ledger and bounds proofs | 2026-11-21 f03819a5e: libraries.nika made 11654 past-loop walks, 0 trial misses, before a 900 s timeout cut it off.
Fact: Ledger and bounds proofs | the example that breaks run 2's trial, and the options A-D for the owner, are in docs/briefs/ci/issue-2646-decision.md.Generated by Claude Code
Driver: not queued, this issue waits for #1634, which is still open (#1819). Set ready again when it is closed.
Generated by Claude Code
Supervisor, 2026-11-21: run 1 is blocked. No exact cut was found; the report is docs/briefs/ci/issue-2646.md.run1.report.md. The question whether the walk past loops may prove fewer checks now goes to the owner as “Decision: may the walk past loops prove fewer checks in rare shapes, in exchange for a cost linear in the loops?” (#2652). This issue waits for that decision. The driver’s “waits for #1634” was a misread: #1634 is the ADR-361 D13 reference in the probe’s message, not a blocker.
Generated by Claude Code
Run 2: a measurement only (owner, 2026-11-21, on #2652). This comment replaces this issue’s To build and Done when for this run. Commit no change to the walk.
Option E: per function, run the flat trial of run 1 (candidate 1). If every check of the function stands, keep that result. Otherwise walk the function again with today’s double walk (bounding_past_loop, ADR-361 D10) and keep the full walk’s result.
Option E’: like E, but walk again only when an unproved check lies after a loop where the trial cut the full walk.
To build
NIKAIA_D10=check: a patch to the lowered bounds_walk.rs, built once. Restore it afterwards by copy, check the md5 against HEAD, and rebuild target/fast clean.docs/measuring.md; never time) on cases small enough for callgrind. Cases:
rs2nika_free_methods included (walk counts where callgrind is too slow);sv_strategy, libraries.nika and std;fn chained probe of docs/briefs/ci/issue-2646-decision.md.Done when
Body: has the table: case, walks A/E/E’, instructions A/E/E’ where measured, reruns and their kind.Result: done with Owner: naming E or E’ as buildable, or not, by the figures. The decision stays with the owner.Generated by Claude Code
Driver: not queued, this issue waits for #1634, which is still open (#1819). Set ready again when it is closed.
Generated by Claude Code
Back to ready. The driver held this issue on #1634 by mistake: that number only appears inside the backtick probe in the run-1 report’s Needs: owner decision. The driver commit “drive: a #N a report only quotes holds no issue up” (15c267871) makes it ignore numbers inside quotes, and the driver’s appended Needs: #1634 line is gone from the report. Run 2 is the measurement order in the comment above.
Generated by Claude Code
Run: issue-2646, Result: done
Tokens: input 138, cache read 4741633, cache write 129541, output 48657 Cost: 3.12 USD, time 0 min 31 s, turns 69
Result: done
Files: none
Commit: none (measurement only, owner on #2652)
Body: HEAD 15c267871, run 2’s flat trial gated by NIKAIA_D10 in a patched lowered bounds_walk.rs, restored by copy (md5 de718d42 = HEAD), target/fast rebuilt clean. Each row is case | past-loop walks in checks A/E/E’ | Ir A/E/E’ | reruns E/E’ (kind) | ledger returns walks (E does not touch them). corpus (#2474 ledger tests: std, libraries.nika, source.nika, 10112 common functions) | 17484/22408/18904 | callgrind not run (800-930 s per run) | 3264/301 (3263/300 same, 1 gap: 253858..255723 trial lacks d19063:0 i18959, recovered by the rerun) | 13167-13377. rs2nika_free_methods (812181..819773) | 5151/5170/5170 | in corpus | 1/1 same | -. sv_strategy | 4505/6627/5466 | 54.8 s/64.5 s/60.5 s wall | 1148/189 all same | 3484. 10-loop probe | ~4092 (from 8 loops: 4x(2^n-1))/-/4132 | 1627 s wall for E’ | 4/4 gap (trial lacks i129 i148 i167 i186) | 8184. 8-loop probe | 1020/1052/1052 | 283 s/285 s/289 s | 4/4 gap | 2040. 6-loop probe | 252/276/276 | 256.42G/259.44G/259.44G | 4/4 gap | 504. fn chained | 12/20/20 | 17.10G/18.67G/18.67G | 4/4 gap (s - k) | 12. Diff against A: 0 lost proofs (every gap rerun gives back A’s set; E with NIKAIA_D10_VERIFY gave 8629 + 1655 functions, every one same; --bounds output of sv_strategy identical in A/E/E’). The trial proves more nowhere (trial_more empty in every log).
Fixes:
Pushed: none
Tests: bytes::the_corpus_needs_no_tether passed in A, E’ and E+verify (patched it binary); check –bounds of sv_strategy, chained and the 6/8/10-loop probes in each mode; no commit, nothing else run
Gate: green
Deviation: no callgrind on the corpus or on sv_strategy (55-930 s native each, hours under valgrind). Wall times and deterministic walk counts stand in for them. The 10-loop probe in A and E was not run (27 min for E’ alone); A’s figure is extrapolated from the 4x(2^n-1) pattern measured at 6 and 8 loops.
Found:
Needs:
Changelog:
Issue: meets I1-I13. Its premise (D10’s again-walk drives the cost) does not hold for the ledger: the 2^n lies in bounds_returns’ own walks (8184 at 10 loops, untouched by E/E’), and a function with an unproved check after a cut loop pays the trial on top of A.
Owner: by these figures neither is buildable. E costs +28 % walks on the corpus and +47 % on sv_strategy; E’ costs +8 % and +21 %. Neither saves a walk in any case, because the functions whose cost is 2^n are exactly those whose checks stay open after a cut loop, so they always rerun (the decision stays with the owner).
Comment: #2652 Measured E/E’ (HEAD 15c267871, deterministic walk counts per function). Past-loop walks in checks, A/E/E’: corpus 17484/22408/18904; rs2nika_free_methods 5151/5170/5170; sv_strategy 4505/6627/5466 (54.8/64.5/60.5 s); 8 loops 1020/1052/1052; 6 loops Ir 256.42G/259.44G/259.44G; fn chained Ir 17.10G/18.67G/18.67G. 0 lost proofs, the trial nowhere proves more. Every 2^n function reruns (its open checks lie after cut loops), and bounds_returns’ walks (8184 at 10 loops), the larger 2^n, are untouched. Neither E nor E’ pays.
Friction: each corpus run took 800-930 s and the 10-loop probe 27 min, so three modes of the corpus filled most of the run’s wall time
Disk freed: scratch 150M->5.3M (binaries, callgrind outputs); target/nikaia-project-tests 379M (one new 379M rlib entry), / 5.8G free
Attribution:
Co-Authored-By: Claude Opus 5.5 noreply@anthropic.com
Claude-Session: https://claude.ai/code/session_01UVxJDtmukJNapbMLmZMzTV
format! there returns Text.bounds_aggressive, bounding_past_loop, bounding_pass). I also had to find that bounds_returns has walks of its own, outside D10, and the byte range of rs2nika_free_methods in benches/lowering/source.nika. The brief could have named all three.check --bounds on sv_strategy, chained and the 6/8/10-loop probes, callgrind on chained and loops6, and the md5 check plus clean rebuild.
std::format!/String, log per function to a file via an env var”, and name the cheap cases first (8 loops, chained), so the expensive corpus runs come only after the shape is settled.wrong I7 |
the premise that D10’s again-walk drives the ledger cost: the 2^n that dominates is in bounds_returns’ own walks (8184 at 10 loops), which E/E’ never touch. |
rules-gap |
the expected run time of each measured case, which would have let me drop the corpus callgrind up front. |
| Fact: Lowering | In a lowered .rs, format! is shadowed to return Text; a hand patch uses std::format! and std::string::String. |
| Fact: Core | Callgrind on check --bounds of a 6-loop probe already runs about 256 G Ir; use deterministic counters logged by an env-gated patch instead. |
| Fact: Ledger and bounds proofs | Key files: bounds_walk.nika (bounds_aggressive, bounding_past_loop, bounding_pass); bounds_returns makes its own 2^n walks outside D10. |
| Fact: Ledger and bounds proofs | 2026-11-21 HEAD 15c267871: past-loop walks in checks A/E/E’, corpus 17484/22408/18904, sv_strategy 4505/6627/5466; 0 lost proofs, the trial nowhere proves more. |
| Fact: Ledger and bounds proofs | 2026-11-21 HEAD 15c267871: bytes::the_corpus_needs_no_tether takes 800–930 s; rs2nika_free_methods (bytes 812181..819773) alone makes 5151 past-loop walks. |
Generated by Claude Code
Run 2 (measurement) is done. The figures are on the decision issue “may the walk past loops prove fewer checks…” (#2652). Neither E nor E’ saves a walk: E adds 28 % walks on the corpus and E’ adds 8 %. This issue is now blocked, waiting on the owner’s decision in #2652.
Generated by Claude Code
Stays blocked. The measured variants E and E’ are not built: neither saves a walk, and the owner refused proving less (2026-11-21, see “Decision: may the walk past loops prove fewer checks in rare shapes…” (#2652), closed). This issue waits for the solver lane’s “The bounds walk walks a pass again whose inputs did not change” (#2695), “The bounds walk walks a loop’s rest again within one pass from an equal state” (#2697) and the decision on factorising by loop cones (#2698).
Generated by Claude Code
Research result: is there an exact linear walk (one where every result stays the same)?
Not today. The losing walk leaves state behind that BoundsMark does not restore: return summaries, axioms, fresh-name counters, flagged, leaving and the arena. Later questions read that state. An exact speed-up could only share work where two walks reach a loop in the same state, and that never happens, because these fields only grow.
Ideas we checked and ruled out:
again early once it can no longer win. Not exact: the cut-short walk leaves different state behind.The route, in order:
Options B, C and D of the decision paper stay out under the owner’s rule.
Generated by Claude Code
From the report of the run of issue-2897 (#2897):
The work gate (#2897) is blocked on item 2: the bounds walk has no file path (it lives only in Rust), so the per-file WORK line needs a decision on Rust plumbing of the path into bounds_proven
Generated by Claude Code