notes

The unsafe census, week by week and by trust boundary

Name: ratified 2026-10-18 (calef, convention-rulings Rule 3).

An appendix to the register of measures.

unsafe blocks outside kernel/src/arch/

Blocks per 10,000 code lines, outside kernel/src/arch/. This is script/lint's census and the one number in this tree that is actually gated on a direction. The dashed line is the ceiling.

227, 243, 138, 121, 111, 93, 77, 77. Over the same period the absolute count of unsafe blocks outside arch/ went from 171 to 704, while the density fell by two thirds. Both are true, and only the density is about soundness; the count is a system under construction. That is why the gate holds a ratio.

The one rise is 2026W29 to 2026W30, the shape of an early kernel: the tree was 7,500 lines and one driver moved the number.

How much this series has been checked

This is the one place in the register where a number has been checked two different ways.

A consistency check

Comparing against notes/unsafe-obligations.md is a consistency check. That note carries a seven-point table, 227.8 down to 78.8, taken on seven different dates. It is not an independent record. It is the output of this same derivation, written down seven times by lanes. Reproducing it proves the walk agrees with what was recorded, and nothing more.

It did agree. On 2026-08-18 the reconstruction hits 747 blocks over 80,359 lines exactly, at commit 93607fa4: both figures to the digit. unsafe impl Send/Sync and the inside-arch/ count match the recorded value at five of the seven dates, and are within three at the other two. The residual is which commit inside the day the column was taken at, not a difference in definition.

The 2026-08-23 column is the worked example. The table prints 777 and this reconstruction prints 799. The note's own prose already says the count immediately before that lane's reduction "was 799, not 777", over 85,476 lines. That is this reconstruction to the digit.

An independent check

A second counter was written from scratch for this. It is a character scanner that tracks Rust's real lexical states, rather than blanking comments and literals with one regular expression. It differs deliberately in two places where the regex is loose. Block comments nest in Rust and the regex's do not. And a lifetime 'a is not the start of a character literal.

Run over every in-scope file at 705e3919, the two methods agree on 701 blocks outside arch/ and 253 inside, with zero files disagreeing. (Those are that commit's own row; the number moved with the tree afterwards.) So the shortcuts in script/lint's regex do not bite in this tree.

The same unsafe blocks, by trust boundary

The chart of unsafe_outside_arch mixes two populations that mean opposite things. This is the same census with the two separated. unsafe_outside_arch (824 today) adds every unsafe block not in kernel/src/arch/, kernel and userspace both, into one number.

In a capability microkernel that matters. An unsafe block inside kernel/src runs with nothing confining it. An unsafe block in a userspace program (components/, fixtures/, or a crate that ships only into one of them) is confined by the MMU-plus-capability-table mechanism that confines every other program. A single density cannot answer "how much of the code that matters for isolation is unsafe", because it never separates the two populations that question is about.

A research lane raised exactly this problem on 2026-09-20, in notes/trusted-base.md, written for the RedLeaf comparison (see notes/redleaf.md). It hand-computed a first cut and flagged in its own BUGS that nothing kept it computed. This split is that mechanism. The note has since landed.

Today's split, and a smaller correction

Today, 2026-09-20: 694 kernel, 382 userspace, 19 shared, 37 boot chain, 0 unclassified. That sums to 1,132, not 1,138 (824 + 314). The 6-block difference is not the split disagreeing with the old census. It is a separate, smaller correction this pass found while classifying crates/.

Three crates (board_console, portable_executable, stick_maker) are host tooling. They run on the developer's Mac and never on nife, exactly like bench/host/, xtask/ and the rest of unsafe_census's own HOST_ONLY exclusion. They are just not under one of HOST_ONLY's path prefixes, and each says so in its own header.

unsafe_outside_arch and unsafe_density are left untouched by this finding. They still mean exactly what they meant, and script/lint's ceiling still gates the same number it always has. This split simply does not count those three crates' 6 blocks toward either side. The question it answers, kernel privilege or userspace confinement, has no answer for code that runs on neither. Whether unsafe_census's own HOST_ONLY should widen to match is an architect's call, recorded rather than made here.

What each bucket is

The boundary decisions behind each bucket are in helpers/rust_source.py's own comment on trust_boundary_census.

Which number the ceiling should be held against

script/lint's <!--count-at-most:unsafe-density-outside-arch--> (notes/unsafe-obligations.md) holds the mixed density: currently 88 (2026-09-24) against 77. This pass does not change that marker's value, because a gate's threshold is an architect's. What the ceiling would mean under each candidate:

Recommendation: the kernel density is the one worth a ceiling of its own, because the mixed number's blind spot lives there. But a ceiling set on it starts cold, with no history of it moving deliberately. That decision is an architect's to make with these numbers in hand.

Cinched 2026-10-08 (UTC) at the merge of milestone 139 (drive the unsafe count down) round 10: the marker lowered 72 to 66 over the merged tree's 59.7 (1,029 blocks over 172,506 lines), keeping the milestone's seven points of headroom. The open question above, which population the ceiling should measure, is untouched; the cinch moved the number, not the population.

Cinched again 2026-10-12 (UTC), 66 to 61, with no reduction behind it: the tree had grown to 61.09 (1,103 blocks over 180,545 lines), and the ceiling now sits at its truncated value with no headroom. ceilings.md records why and what it costs.

How each crate is placed, and every week restated

helpers/trust_boundary_crates.tsv gives each crates/ member its side, generated from cargo metadata by helpers/trust_boundary.py (the rule is in its docstring). script/lint regenerates it and fails when the checked-in file differs, and the pre-push hook fails when a member has no row. A crate that leaves the tree keeps a retired row with the side it last had, so the weeks that held it still place its unsafe.

script/metrics cannot run cargo, so it applies today's table to every historical week. That is the restatement trade MILESTONE_STATUSES/NAME_STATUSES make. A crate whose side changed over time is counted on its current side in every week. unsafe_trust_unclassified reads 0 in every week on record. It counts a crates/ directory the table has no row for, which lint refuses on today's tree.

The retired rows were seeded once from cargo metadata run at each charted week's own commit, all fifteen of which still resolve offline. A crate that was linked and then fell out of use before its deletion (heap, slab) keeps the side it had while linked.

The two-day loss, restored 2026-09-23

The unsafe_trust_* columns landed on main at 2026-09-20 23:30 (3764a78d3), with the ten weeks already backfilled to the numbers in this section. weekly.csv was then the single series file; milestone 581 (one metrics file per measure) has since retired it. The next commit to touch it was 6e8934474 ("Rebuild the weekly series after the merge", 2026-09-21). It resolved a conflict between two branches that had each added columns to the same file. Its message says the plan was to restore its own branch's cost columns and "let script/metrics add the trust-boundary columns from the merged script."

What ran next was --update, not --backfill. --update only recomputes the current week and any week missing outright. So it added the ten new column headers to every row, but left these empty, not zero, for 2026W29 through 2026W38: unsafe_trust_kernel, unsafe_trust_kernel_code_lines, unsafe_trust_kernel_density, the userspace triple, unsafe_trust_shared and unsafe_trust_boot_chain. That is why unsafe-trust.svg drew one point instead of ten from 2026-09-21, until this was found and script/metrics --backfill was rerun on 2026-09-23.

The nine restored values match the 2026-09-20 backfill exactly. The unclassified counts for 2026W29 through 2026W37 are the same 57-to-188 figures, and 2026W38 is still exactly 0. So this is the known rename-alias gap reappearing, not a new one.

The lesson is about the merge, not the census. When one branch adds a column while another is independently adding columns to the same CSV, the resolved merge needs a --backfill. --update treats every already-present row as correct, and will not notice blank cells a merge introduced.

The same shape was checked for elsewhere on 2026-09-23 and found nowhere else. Every other column that could go this route was in fact backfilled at the commit that added it: milestones_superseded, milestones_refused, and the fatal-risk columns, then fatal_risks_tested and fatal_risks_untested. The flow columns (milestones_built_this_week, merged_pull_requests, the four cost columns) are recomputed for every row on every run regardless of mode. They cannot hold a stale blank this way.

Adding a measure to the register, worked on the unsafe census

Moved verbatim from the register's EXAMPLES under §212 (a prose budget) on 2026-10-13 (UTC).

The unsafe census went from calef's question to a gated row in four steps.

  1. Apply the test. Unsafe is where verification stops, so something depends on it. 42 non-merge commits changed it in fourteen days, so it moves.

  2. Take the number more than once. A single measurement cannot tell a direction from a level:

    # blocks outside kernel/src/arch/, at four points in the tree's history
    2026-07-15   171 blocks in   7,508 lines   227.8 per 10,000
    2026-08-04   728 blocks in  58,351 lines   124.8 per 10,000
    2026-08-16   817 blocks in  73,129 lines   111.7 per 10,000
    2026-08-18   747 blocks in  80,359 lines    93.0 per 10,000
    

    The count more than quadrupled and the density more than halved. A ceiling on the count would have fired on nearly every lane.

  3. Choose the relation from the shape of the quantity, as the main page's step 3 says.

  4. Watch it fail. Add one unsafe impl Send anywhere and run script/lint:

    $ script/lint
    lint: a counted claim disagrees with the tree:
      notes/unsafe-obligations.md:461: claims at most 17, the tree has 18
    

    The density ceiling's first marker never fired. Written as at most 91 blocks per 10,000 lines, it bound to the line's last number and compared 10,000 against 92. A marker now sits right after its own number.

The ceiling's failure message, in full

The worked example above shows the first lines of what script/lint prints when one unsafe impl Send is added past the ceiling. This is the whole message, as recorded when the ceiling was 17.

# add one `unsafe impl Send` anywhere, then:
$ script/lint
lint: a counted claim disagrees with the tree:
  notes/unsafe-obligations.md:461: claims at most 17, the tree has 18
  (unsafe-thread-safety-claims: how many `unsafe impl Send`/`Sync` claims the tree makes, each one
  a hand-written assertion that the compiler is wrong about a type). A ceiling is only wrong when it
  stops being true, so this means the count went UP by 1 past the headroom. Take the addition back
  out, or raise the ceiling in this commit and say beside it why the addition was worth it

BUGS