Issue #2154: Driver merges: a lowered-only conflict costs about 30 minutes of re-lowering; cut the conflicts in lowered.rs and re-lower only what changed

Open and answer this issue on GitHub.

lowering, performance, blocked, tooling · opened 2026-11-18 · updated 2026-11-21 · 5 comments

Found while: supervising the yaml lane (YAML package, #928), 2026-11-18. Related: #2078 (the merge re-lowers with the old binary and fails), #1102 (rebase conflicts in lowered files), #1278 (lower-std cache key), #1581 (a cold lowering of the tools package takes 3–5 minutes).

Probe

On 2026-11-18 the yaml driver merged origin/develop before pushing its tested commits, twice. Both merges conflicted only in crates/nikaia-std/src/compiler/lowered.rs (3915 lines, the index every lane’s lowered change touches). Each one cost about 30 minutes of wall time before the push:

  1. In the first merge, the old binary’s lower-std refused the merged sources, because develop had changed code parameters to &mut impl FnMut (ADR-views-3 D17). That is the failure #2078 covers. The supervisor had to bootstrap by hand: build develop’s compiler, then lower-std --sysroot /home/user/Nikaia/crates, then build again.
  2. In the second merge (MERGE cb513c37 re-lowered crates/nikaia-std/src/compiler/lowered.rs), the driver’s own re-lowering in target/ledger-tree ran about 30 minutes, with the short checks after it, before PUSHED cb513c37.

With several lanes pushing to develop, almost every merge conflicts in lowered.rs. That makes each lane’s integration slow, and the owner paused the yaml lane for the day to bring the integration speed back up.

Cause

Done when

A merge of origin/develop whose only conflicts are in lowered files settles in the driver in a few minutes (measured: the time between the MERGE <sha8> line and short checks, logged by the driver), without hand work. The supervisor notes in docs/tokenspeed.md or the driver log how long the next three such merges took.

To build

  1. Measure first: log in drive_merge_regenerate how long each step takes (build, lower-std, build again), and record one real lowered-only merge as the baseline in this issue.
  2. Cut the conflict surface of lowered.rs: see what each lane changes in it (module lines, digests, a list of entries?), and change the lowering so that the index changes only when a module is added or removed. One option is to move the per-file part, such as a digest, into each lowered/<file>.rs. Another is a merge=ours driver in .gitattributes for the index and the lowered files, so that git never stops on them and the driver always regenerates. Decide which of the two in the build and give the reason in the comment.
  3. Re-lower only what the merge changed: lower just the .nika files whose source differs between the merge base and the merged tree, plus their dependants, instead of a full lower-std. If lower-std has no such mode, add one, written in Nikaia. This builds on the cache key of #1278.
  4. Keep #2078’s order: the compiler built from the merged sources lowers, and the old binary is the last fallback.
  5. Update the header comment of scripts/drive.nika and docs/supervisor.md (the merge step) with the new cost.

Generated by Claude Code

Comments

keywan-ghadami, 2026-11-19

Brief queued: issue-2154


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

Issue #2154

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

Tokens: input 112, cache read 3997739, cache write 120341, output 35467 Cost: 2.66 USD, time 16 min 21 s, turns 56

Report

Result: partial Files: scripts/drive.nika docs/supervisor.md tests/compiler/tests/drive_relower.nika tests/compiler/tests/drive_relower.stdout tests/compiler/tests/drive_merge_shared_checkout.nika tests/compiler/tests/drive_merge_shared_checkout.stdout Commit: drive: time each merge-regeneration step, settle on a round that changed only LOWERED_DIGEST, reuse the settled binary for the ledgers Body: drive_merge_regenerate prints a MERGE timing line (each build, lower-std, badges, ledgers, total). drive_lowered_print leaves out the pub const LOWERED_DIGEST: line, so a round that changed only the index digest counts as settled: that saves one build and one cold lower-std per merge, since the digest feeds compiler_identity and makes the cache cold. The ledgers step reuses the binary the settle built (drive_ledgers_refresh_on) and no longer runs another cargo build. #2078’s order is unchanged. Tests: drive_relower gets the cases “index digest only” (settles in 2 rounds; HEAD’s drive.nika escalates “lower-std did not settle after 5 rounds”) and “merge build” (3 cargo runs, the ledgers step adds none). The timing figures are written as Ns in the test output. Part: #2154 Tests: all 30 tests/compiler tests that use scripts/drive.nika pass; pre-push green; target/fast/nikaia check scripts/drive.nika clean; the “index digest only” case failed on HEAD’s drive.nika (escalated after 5 rounds) Gate: green Deviation: item 2 (cut the conflicts in lowered.rs) not built: the driver settles a lowered-only conflict by taking their side and regenerating, the same as a clean merge, so the conflict adds no time. The time goes into the regeneration rounds. Per-file digests would need Rust changes in compiler_identity/commit.nika and would help only hand merges. A merge=union attribute would duplicate the LOWERED_DIGEST line and break the first build. Deviation: item 3 (re-lower only what changed) built as fewer rounds and builds, not per-file reuse: compiler_identity (NIKAIA_COMPILER + LOWERED_DIGEST) changes with every merge, so reusing per-file lowering across identities is unsound without a decision on what the identity covers Found: none Needs: supervisor decision: whether lower-std may reuse per-file lowered output across compiler identities (needed for item 3 as written); the Done-when figure must be read from real merges’ MERGE timing lines Changelog: Driver merges: a MERGE timing line per merge; a round that changed only LOWERED_DIGEST counts as settled, which saves a build and a cold lower-std; the ledgers reuse the settled binary Issue: meets I1-I13 except item 2, which presumes the conflict costs time; in the driver, the regeneration rounds do Comment: #2154 Measure with the new MERGE timing line on the next real merges before building per-file re-lowering; the digest-insensitive settle and the ledger binary reuse should take about one build and one cold lower-std off each merge Friction: none Disk freed: 0 (target/nikaia-project-tests 2.0G, / 19G free) Attribution: Co-Authored-By: Claude Opus 5.5 noreply@anthropic.com Claude-Session: https://claude.ai/code/session_01UVxJDukWgopUzVU2M1TjK7 Reviewed: d018d9416d0c037ce1ef78a232cf68ab0d4e957057c7c3d99e0a71712f280b95 Pushed: local 3a93041a95e5c3484096516dd91572c32ae30a57

Debrief

  1. Most time: the drive tests. Each one builds a git sandbox with stub cargo and lowering, so every rerun cost minutes. On top of that came three of my own slips: a date +%N stub that gave a different result each run, a sh(work, …) call after work had already been moved, and blessing before the test was finished.
  2. Looked up myself: what compiler_identity hashes (NIKAIA_COMPILER plus LOWERED_DIGEST, in crates/nikaia/src/lib.rs), how LoweredBefore::open makes the cache cold, and that drive_ledgers_refresh → drive_tree_exe always runs cargo build again. The brief could have handed me all three.
  3. Checks run: nikaia check scripts/drive.nika, the drive_relower and drive_merge_shared_checkout tests, all 30 tests that use the driver (twice), pre-push, a fails-before run on HEAD’s drive.nika, and the commit dry run. Wasted: the first background run of the 30 tests, which ran before my last edits, and one rebuild of a binary that was stale against HEAD. The “merge build” case gave 3 cargo runs with my change; I did not rerun it on HEAD to show the one-run saving. Also, my report came to 20 lines, over the brief’s limit of 15.
  4. One change that would save the most: builder.md should say that a test of the driver’s merge regeneration (drive_relower) needs a deterministic stub lowering, such as a round counter in a file, and that timing output must be normalised to Ns before blessing.
  5. What the issue lacked:
    • wrong I7: the cause “a lowered-only conflict costs ~30 min” is not marked as suspected. In the driver, a conflict takes their side and regenerates exactly like a clean merge, so the time goes into the regeneration rounds, not the conflict.
    • broke I5: there is no reference figure or per-step timing to measure against, so Done-when (“settles in a few minutes”) cannot be checked locally.
    • rules-gap: it does not say whether per-file re-lowering may reuse output across compiler identities. That needs a decision, and I named it under Needs:.
    • knowledge: Lowering | LOWERED_DIGEST feeds compiler_identity, so every new digest makes lower-std's cache cold.
  6. Traps for the next builder:
    • Fact: Core | Calling a function such as sh(dir, …) takes ownership of a String argument, so pass dir.clone() when dir is used again later.
    • Fact: Lowering | A lowered set that differs only in its LOWERED_DIGEST line lowers to the same files, so a settle check may ignore that line.

Generated by Claude Code

keywan-ghadami, 2026-11-19

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

Measure with the new MERGE timing line on the next real merges before building per-file re-lowering; the digest-insensitive settle and the ledger binary reuse should take about one build and one cold lower-std off each merge


Generated by Claude Code

keywan-ghadami, 2026-11-19

Built in 3a93041a (driver): each merge prints a MERGE timing line; a round that changed only LOWERED_DIGEST counts as settled (saves one build and one cold lower-std per merge); the ledgers reuse the settled binary.

Not built:

Supervisor: accepted as partial; the issue stays open for the Done-when figure.


Generated by Claude Code

keywan-ghadami, 2026-11-21

Supervisor, 2026-11-21: the MERGE timing lines of the last eight real merges in the performance driver (target/drive-performance.log):

build lower-std ledgers total
48 s 187 s 117 s 357 s
153 s 308 s 100 s 567 s
234 s 412 s 117 s 771 s
79 s 326 s 102 s 513 s
18 s + old lower-std 345 s + 49 s 327 s 103 s 848 s
246 s 323 s 112 s 685 s
185 s 303 s 101 s 593 s
44 s 363 s 111 s 524 s

A merge now takes 6 to 14 minutes, against the earlier 30. Done when asks for “a few minutes”, which is not met yet. The full lower-std, at about 5 minutes, is now the largest part. Cutting it is item 3, re-lowering only what the merge changed. Item 3 needs:

This issue is set to blocked until those two land. The ledgers step, at about 110 s, is the next candidate.


Generated by Claude Code

Back to Open Issues