Issue #1995: The ledger records panics = true for a function whose every site check --bounds proves (yaml fold, text, scalar_text, walk)

Open and answer this issue on GitHub.

blocked, bugs · opened 2026-11-17 · updated 2026-11-21 · 4 comments

Found while building “yaml: remove the needless collects and copies” (#1981).

Probe

cd packages/yaml
nikaia check --bounds src/main.nika    # proves every index and operation of fn fold
grep -A3 'fn fold' nikaia.contracts    # panics = true

Output

packages/yaml/nikaia.contracts records panics = true for fold, and also for text, scalar_text and walk. The bounds report proves every site of fold.

A function with every site proved should be panics = false, so its callers do not inherit a panic they cannot have.

Suspected

crates/nikaia-std/src/compiler/panics.nika: compare its site walk with the bounds report for fold. It may count a site that the bounds walk proves, or it may not read the proofs at all.

To build

Done when

The yaml ledger records panics = false for fold (and for the others where every site is proved), and scripts/ledgers.nika -- --check is green.

Comments

keywan-ghadami, 2026-11-21

Brief queued: issue-1995


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

Issue #1995

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

Tokens: input 62, cache read 1380196, cache write 53377, output 12061 Cost: 0.99 USD, time 2 min 45 s, turns 31

Report

Result: blocked Body: nothing committed; panics.nika is right: in a scratch package fn idx(xs: ref Vec[i64]) -> i64 sync { if xs.len() > 0 { return xs[0] } return 0 } gets panics = false and fn idx_bad(xs: ref Vec[i64], i: i64) -> i64 sync { return xs[i] } gets panics = true; fold’s own sites are all proved (check –bounds rows 2883-2914), but fold calls push_between (main.nika:2862), which calls t.start().forward(bytes: a) and t.between(p, q), both panics = true in crates/nikaia-std/std.contracts (text::Pos::forward line 8465, str::between line 5590); text, scalar_text and walk reach fold, so all four inherit the panic through what they call, not through a site the pass gets wrong Pushed: none Tests: scratch package (src/main.nika with pb_a let p = t.start().forward(bytes: a) ?? return 0, pb_b out.push_str(t), pb_c forward+between, push_between copied from yaml, idx, idx_bad), target/fast/nikaia run built at HEAD 7fe501f0f: ledger idx false, idx_bad true, pb_a true, pb_b false, pb_c true, push_between true; check --bounds packages/yaml/src/main.nika: 63/63 indexes proved, fold’s operations all proved Gate: green Deviation: none Found: std’s ledger has [fn."text::Pos::forward"] panics = true, but forward(bytes: n) cannot panic: crates/nikaia-std/src/text_pos.rs forward_bytes is p.0.checked_add(..)? plus text.is_char_boundary(at), which answers false past the end, so it has no slice. Only the scalars:/graphemes: forms slice text[p.0..], and that check stays until ADR-374 D5/D8 (#743). Probe in a package with only [package] name = "p": fn pb_a(t: String, a: i64) -> i64 sync { let p = t.start().forward(bytes: a) ?? return 0 \n return 1 } gets panics = true in nikaia.contracts. It should be false for the bytes form, but the ledger has one entry for every unit form, so the fix needs a way to give the forms separate claims; no decision yet Needs: supervisor decision: yaml’s fold can only get panics = false if push_between stops reaching str::between, whose q before p stops the program (ADR-374 D3, text_pos.rs between_backwards), and stops reaching a forward claimed to panic. That means either a yaml rewrite of push_between (yaml lane) or a std ledger change (the Found above); the panics pass needs no change Changelog: none Issue: wrong I7: panics.nika reads the bounds proofs correctly (a proved index gives false, an unproved one true); fold, text, scalar_text and walk panic through push_between’s library calls str::between and text::Pos::forward, which std.contracts claims can panic; broke I5: the Done-when figure (panics = false for fold) contradicts the std contract of between, which ADR-374 D3 says panics Comment: #1995 The panics pass is correct: check --bounds proves all of fold’s own sites, and fold is panics = true only because it calls push_between, which calls str::between (panics when q comes before p, ADR-374 D3) and text::Pos::forward (claimed panics = true in std.contracts, though the bytes: form cannot panic). text, scalar_text and walk reach fold. Getting false needs either a yaml change to push_between or per-form std ledger claims for forward, plus a way to know a <= b before between. Friction: none Disk freed: none; target/nikaia-project-tests 560M, / 19G free, 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_01UVxJDutPTwP5Xj5HkGuidk

Debrief

  1. Most turns: finding where fold’s panic actually came from. It took about 8 turns to go from panics.nika, to the MethodsCalled keys, to sync.nika, to the entries in std.contracts. I first thought the methods had no entry at all. They do, but under str:: and text::Pos:: keys, not String::.
  2. Looked up:
    • that std’s library claims are in crates/nikaia-std/std.contracts, with keys like str::between and text::Pos::forward;
    • that a library method a function calls passes its claim on to that function through panics_methods;
    • ADR-374 D3, which makes between panic on purpose;
    • text_pos.rs, to see which forward forms can really panic.
  3. Checks:
    • Useful: check --bounds on yaml, then one scratch package with six variants. That package settled the cause in a single run.
    • Wasted: the cargo build, since the binary was already current. The age check listed HEAD’s own commit, and I read that as stale.
    • Wasted: the grep for MethodsCalled builders.
  4. One change: builder.md should say: “Before you blame a pass for panics/sync/throws, read the callee chain in the generated nikaia.contracts and the library entries in std.contracts.”
  5. What the issue lacked:
    • wrong I7: it suspected panics.nika, but the panic comes through calls (push_between → str::between/text::Pos::forward). A cause marked suspected, and its settling check (the callees’ ledger rows), was never run.
    • broke I5: the Done-when figure (panics = false for fold) contradicts the documented contract of between. No reference run backed it.
    • knowledge: Probes | a function's ledger 'panics' joins its callees' entries, so the bounds report alone never shows that a function cannot panic.
  6. Traps:
    • Fact: Core The binary-age check git log --since=@$(stat ...) can list HEAD’s own commit when the binary was built right after it; a build that ends in under a second confirms the binary is current.
    • Fact: Probes To find why a ledger says panics = true, put each callee into its own one-line function in a scratch package and read its row; std methods are keyed str::NAME and text::Pos::NAME in std.contracts.
  7. Ledger and bounds proofs:
    • Fact: Ledger and bounds proofs crates/nikaia-std/src/compiler/panics.nika uses the bounds proofs correctly: a proved index gives panics = false and an unproved one true (scratch run, 2026-11-21, HEAD 7fe501f0f).
    • Fact: Ledger and bounds proofs check --bounds packages/yaml/src/main.nika: 63/63 indexes and 80/106 operations proved (2026-11-21, 7fe501f0f).
    • Fact: Ledger and bounds proofs In std.contracts, text::Pos::forward and str::between/before/after/split_at are panics = true, so every caller of theirs inherits a panic; forward(bytes:) cannot actually panic (text_pos.rs forward_bytes).

Generated by Claude Code

keywan-ghadami, 2026-11-21

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

The panics pass is correct: check --bounds proves all of fold’s own sites, and fold is panics = true only because it calls push_between, which calls str::between (panics when q comes before p, ADR-374 D3) and text::Pos::forward (claimed panics = true in std.contracts, though the bytes: form cannot panic). text, scalar_text and walk reach fold. Getting false needs either a yaml change to push_between or per-form std ledger claims for forward, plus a way to know a <= b before between.


Generated by Claude Code

keywan-ghadami, 2026-11-21

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


Generated by Claude Code

Back to Open Issues