Issue #1308: lower-std: incremental ledger, facts per function and per unit recomputed only when their inputs change (items 3 and 4 of #1277)

Open and answer this issue on GitHub.

performance, blocked, ci · opened 2026-11-07 · updated 2026-11-19 · 12 comments

Goal

The ledger phase of nikaia lower-std recomputes only what changed. After 645eaeac (#1277) it takes 11.0 s on every run, warm or cold (tether 2.4, check_units 3.6, result_sources+places_stored 3.1, keeps 0.9 s), which alone is most of the 15 s budget of a body edit (14.9 s today).

To build

  1. Per-unit check. Key the result of host.check_units by the unit’s text plus the package declarations it reads (recorded the same way as in the per-file key issue split from #1277, item 2).
  2. Per-function facts. Store the ledger facts per function, keyed by the function’s text plus the entries it reads from its callees (signature, column values). Recompute through a worklist: the dirty set starts with the functions whose key changed; a changed column value wakes the callers. A recursive group is one SCC; the keeps fixpoint runs only inside it. Written in .nika, in or beside crates/nikaia-std/src/tools/ledger_items.nika (ledger_infer_package).
  3. The result_sources / places_stored pass (views::ResultPackage) follows the same store.
  4. Test: an edit sequence (body change, signature change, a column change that wakes callers, a change inside a recursive group); the incremental nikaia.contracts / std.contracts are byte-identical to a fresh-salt full run, and a counter (in NIKAIA_LOWER_TIMES output) shows only the woken functions recomputed. As a tools/*.nika run by nikaia run (tests/compiler cannot drive lower-std).

Done when

Ruled out

A cache of the whole package’s ledger (every edit misses it); reading the committed nikaia.contracts as input (it confirms itself).

Comments

keywan-ghadami, 2026-11-16

Brief queued: issue-1308


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

Issue #1308

Your work order is issue #1308, 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/1308/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-1308.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-16

Run: issue-1308, Result: blocked

Tokens: input 36, cache read 837913, cache write 50053, output 8698 Cost: 0.78 USD, time 5 min 11 s, turns 18

Report

Result: blocked Pushed: none Tests: none run (nothing built); baseline measured on a HEAD copy (git archive 7293a57a, binary target/fast/nikaia built at HEAD), a body edit in fmt.nika, NIKAIA_LOWER_TIMES=1 lower-std –sysroot COPY: wall 54.0 s, ledger 47.7 s (check_units 7.1, panics 28.6, tether 3.5, result_sources 2.8, places_stored 2.7, keeps 1.5, parse 3.0) Gate: green Deviation: none Found: To build item 1 needs a per-unit key of “the unit’s text plus the package declarations it reads, recorded the same way as in the per-file key issue split from #1277 item 2”, and that recording does not exist at HEAD: sysroot_interface in crates/nikaia-std/src/compiler/sysroot_cache.nika still keys every file by the whole package’s bodiless text (bodiless[at] of every file) plus the whole inferred ledger own, with no list of the declarations a file reads; git log -400 --since=2026-11-06 finds no commit that built it, and the issue gives no number for it; no decision yet Found: a per-function or per-unit ledger store that outlives one lower-std process needs on-disk forms nobody has decided: crate::check::Checked (findings, CheckFacts, methods, stored_code; crates/nikaia/src/check/mod.rs:77) has no text or byte form, and the passes the issue wants woken per function (sync, throws, touch, keeps, locks, panics, tether in crates/nikaia/src/contracts/.rs, 1743 lines, plus views::result_sources_in/places_stored_in) are Rust with whole-package infer(ledger, units, ...) entry points, so giving each one a per-function call is new Rust in Rust passes; CLAUDE.md “no new Rust” makes that a supervisor decision (move each pass into Nikaia first, or allow the Rust plumbing as #1277 did); no decision yet Needs: supervisor decision: the issue for the per-file key of #1277 item 2 (recording the declarations a unit reads) filed or built first, and its number written into #1308 as Needs #N Needs: supervisor decision: where and in what form the per-unit Checked and the per-function ledger facts are stored between runs, and whether the Rust passes (contracts/panics.rs, throws.rs, keeps.rs, tether.rs, sync.rs, touch.rs, locks.rs) get per-function entry points in Rust or move into .nika first Changelog: none Issue: wrong I4: the figures are stale: the ledger now takes 47.7 s on a body edit, not 11.0 s, and the panics pass (its second round proves units with the bounds walk, contracts/panics.rs infer) takes 28.6 s of that; *To build does not name panics at all, and it is the largest pass; broke I2: item 1 depends on the “per-file key issue split from #1277” without its number, so the driver cannot see it is still open; rules-gap: the issue orders per-function entry points for Rust passes and a cache of the Rust Checked without saying whether that Rust is allowed under “no new Rust” Comment: #1308 Baseline at 7293a57a (body edit in fmt.nika, warm, NIKAIA_LOWER_TIMES): ledger 47.7 s of 54.0 s wall; panics 28.6, check_units 7.1, tether 3.5, result_sources 2.8, places_stored 2.7, keeps 1.5. Blocked: the per-file declaration key (#1277 item 2) is not built, and the per-function store needs a decision on its on-disk form and on Rust in contracts/*.rs. Owner: none Friction: none Disk freed: 36M (scratch HEAD copy); target/nikaia-project-tests 1.8G, / 8.0G free of 252G; no cache entries over 100 MB created 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 time: measuring. The first lower-std after a rebuild was cold (0 of 297 files from the cache, 2.5 min), and the second, unchanged, was the under-1 s path, which measures nothing. It took a third try, on a scratch HEAD copy with a body edit, to get a real figure.
  2. Lookups the brief could have given me: the issue’s paths are stale (tools/ledger_items.nika now lives in compiler/). It never said whether the per-file key from #1277 item 2 exists (I checked sysroot_interface), or that the passes are Rust adapters in crates/nikaia/src/contracts/*.rs (1743 lines).
  3. Checks run: one cold lower-std, which was wasted, and one unchanged run that printed nothing, also wasted. The useful ones were the copy’s body-edit run plus a few greps and reads; no build and no tests.
  4. One change: builder.md could give the recipe for measuring a body edit: git archive a copy, warm it, edit one line, then NIKAIA_LOWER_TIMES=1 lower-std --sysroot COPY/crates. It should also warn that the first run after a build is cold.
  5. What the issue lacked:
    • broke I2: it depends on the per-file key issue split from #1277 without giving its number.
    • wrong I4: it says the ledger takes 11.0 s; it now takes 47.7 s, of which the panics bounds-walk proofs take 28.6 s, a pass the issue never names.
    • rules-gap: no rule asks an issue that orders work in Rust code (per-function entry points, a saved form for Checked) to say whether the no-new-Rust rule allows it.
    • wrong I4: the file paths still say tools/; the files are in compiler/.
  6. Facts for the next builder:
    • Fact: Core The first lower-std after a rebuild of target/fast/nikaia is cold (the binary is part of the cache key, 2-3 min), and an unchanged tree returns in under a second, so to time a body edit warm a scratch copy first, then edit one line in it.
    • Fact: Core Since the bounds-walk changes, the ledger’s panics pass (its second round proves units, contracts/panics.rs infer) takes about 28 s of a body edit’s lower-std, the largest single pass.

Generated by Claude Code

keywan-ghadami, 2026-11-16

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

Baseline at 7293a57a (body edit in fmt.nika, warm, NIKAIA_LOWER_TIMES): ledger 47.7 s of 54.0 s wall; panics 28.6, check_units 7.1, tether 3.5, result_sources 2.8, places_stored 2.7, keeps 1.5. Blocked: the per-file declaration key (#1277 item 2) is not built, and the per-function store needs a decision on its on-disk form and on Rust in contracts/*.rs.


Generated by Claude Code

keywan-ghadami, 2026-11-16

The report of the run of issue-1308 (#1308) 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-16

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


Generated by Claude Code

keywan-ghadami, 2026-11-16

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

Needs #1912 (per-file declaration key of #1277 item 2). Needs #1913 (on-disk form of the per-unit Checked and per-function ledger facts, and whether contracts/*.rs get per-function entry points in Rust or move into .nika first). Baseline at 7293a57a: ledger 47.7 s of 54.0 s wall on a body edit, panics 28.6 s; To build should name panics.


Generated by Claude Code

keywan-ghadami, 2026-11-16

Measured cost (2026-11-16)

The full table is on “lower-std: key each file on the interface entries it reads” (#1307). In short:

This issue’s open decisions:


Generated by Claude Code

keywan-ghadami, 2026-11-17

The per-function entry is decided: ADR-100 D7 (owner, 2026-11-17, from #1984). Each contract pass gets an entry that returns one function’s final column from its callees’ stored columns, processed callees first, a recursive group (SCC) as one unit with the fixpoint inside it only; the whole-package entry stays and is the reference, compared on a package with a call chain and a recursive pair.


Generated by Claude Code

keywan-ghadami, 2026-11-19

Brief queued: issue-1308


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

Issue #1308

Your work order is issue #1308, 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/1308/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/performance/issue-1308.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-19

Run: issue-1308, Result: blocked

Tokens: input 12, cache read 156419, cache write 19186, output 2261 Cost: 0.26 USD, time 0 min 29 s, turns 6

Report

Result: blocked Files: none Commit: none Body: Stopped before any reading or editing: the issue depends on #1912 and #1913, and git log -400 --grep='Fixes #1912' and --grep='Fixes #1913' find no fix for either. ADR-100 D7 (7937d12a, from #1984) decides the per-function entry (callees first, an SCC as one unit, keyed by text plus callee columns). It does not decide the on-disk form of the stored columns, which #1913 asks. Cache target/nikaia-project-tests 1.8G; disk 7.5G free of 252G; no cache entries created in this run. Fixes: none Pushed: none Tests: none (nothing built) Gate: green Deviation: none Found: none Needs: #1912 (per-unit key of the unit’s text plus the package declarations it reads, #1277 item 2), still open with no Fixes #1912 in the last 400 commits; item 1 of #1308 waits for it Needs: #1913 (on-disk form of the per-unit Checked and per-function ledger store that outlives one lower-std process), still open with no Fixes #1913; ADR-100 D7 settles only the per-function entry, not where or how the columns are stored Changelog: none Issue: broke I2: To build item 1 still names “the per-file key issue split from #1277, item 2” without its number (#1912), and items 2-3 do not say they wait for #1913, so the issue says no Needs #N itself; the dependency is only in the comments; broke I11: the Goal quotes 11.0 s for the ledger without a commit or a split by pass that matches the 2026-11-16 baseline (47.7 s, panics 28.6 s), and To build still does not name the panics pass, the largest cost Owner: none Comment: #1913 ADR-100 D7 (from #1984) decided the per-function contract entry; what is still open for #1308 is the on-disk form of the stored per-function columns and the per-unit Checked (file layout, key, where it lives under target/); once that is written down, #1913 can close Friction: none Disk freed: none (cache 1.8G, 7.5G free) Attribution: Co-Authored-By: Claude Opus 5.5 noreply@anthropic.com Claude-Session: https://claude.ai/code/session_01UVxJDukWgopUzVU2M1TjK7

Debrief

  1. Most cost: very little. It took four tool calls. The only time went to deciding whether ADR-100 D7 (from #1984) counts as closing #1913. It decides the per-function entry but not the on-disk store, so I treated #1913 as still open.
  2. Looked up: whether #1912 and #1913 are open. The prompt did not give their state, so I ran git log --grep='Fixes #N' on each. I also read the ADR-100 D7 text to see how much of #1913 it answers.
  3. Checks: the dependency greps (needed), the ADR diff (needed) and the disk figures (required). None were wasted. I ran no probe because the issue has none, and I did no build. I never opened docs/issues.md: I took I11 from the subject of commit fa1101e9 and I2 from the earlier run’s comment, so those two judgements are unverified.
  4. One change: the driver should not start a builder on an issue whose last driver comment says it waits for issues that are still open (#1912, #1913). If it does start one, the prompt should give those issues’ state.
  5. Issue judgement:
    • broke I2: item 1 refers to “the per-file key issue split from #1277” instead of naming #1912.
    • broke I2: the issue body has no Needs #1912 / Needs #1913 line; the dependencies appear only in comments.
    • broke I11: the 11.0 s figure names no commit, and To build leaves out the panics pass (28.6 s, the largest cost).
    • rules-gap: no rule asks that, when an ADR partly answers an issue’s dependency (D7 for #1913), the issue says what is still open.
  6. Fact: Core | ADR-100 D7 (owner, 2026-11-17) decides the per-function contract entry but not the on-disk form of the store, so #1308 still waits for #1913 until that form is decided.

Generated by Claude Code

keywan-ghadami, 2026-11-19

The report of the run of issue-1308 (#1308) 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-19

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


Generated by Claude Code

Back to Open Issues