Skip to content

feat(core): a delivery names its receiver entity (#694, 1/3) - #746

Merged
sini merged 5 commits into
mainfrom
feat/694-receiver
Nov 10, 2026
Merged

sini merged 5 commits into
mainfrom
feat/694-receiver

Conversation

@sini

@sini sini commented Nov 6, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

PR 1 of 3 for #694 (spec: https://gist.github.com/sini/de16b6cb510067d6d31bf5f365db832a, §7 item 1). The old subtree merge is still on, so for every den channel the output is unchanged. What this adds is the mechanism PR 3's flip depends on: a delivery says which entity receives it.

route, forward and provide accept receiver = <entity record>, e.g. receiver = host. The delivery lands in the first scope, walking up from its source (inclusive), whose own entity has that record's id_hash. A scope's own entity is the record push-scope links in scopeByEntity, or the resolved root's record. A receiver that isn't on the chain is an error naming the record. Without receiver an edge stays where it is today.

Mechanism

  • One target function. targetScopeOf (edges/route.nix) replaces appendScopeIdOf and is used at every site that hard-coded the source scope: simple routes, complex forwards (applyComplexRouteEdge), provides (applyOneProvide), the toposort producer key, and the edge trace. sourceScopeId keeps meaning the source, which suppressionVerdicts keys on.
  • Readers of a delivered bucket. A simple route still reads the frozen seed unless a delivery writes into a bucket it reads. Then it reads that bucket after the fold, pinned after every producer into it, and producers are keyed by target, so a receiver delivery counts where it lands. This generalises resolveImports drops policy.spawn requests, so host-aspects is silently inert on a static resolve #742's forwarded treatment from complex forwards to every delivery. wsl-to-host reading primary-user's delivered wsl.defaultUser depends on it.
  • Provide dedup. A provide that names a receiver also keys on its source scope's own entity and on its receiver's target scope. One battery policy firing at several user scopes then keeps each user's delivery: two users' shells and unfree lists, for example. id_hash is parent-blind (kind and name), so the target is part of the key: tux on igloo and tux in igloo's guest are two deliveries, and both get their account.
  • push-scope. A push that lands on its parent's scope id overwrites none of that scope's kind, entity link or isolation mark. That covers a routing kind (flake-system, the microvm template's microvm-host) and a re-entry of a record the parent already binds. On main the microvm host scope read scopeEntityKind = "microvm-host". An isEntity push of a new record that adds no nameable key would have to share its parent's node, so it is refused by name. It occurs in no suite and no template.
  • A receiver without an id_hash is matched by value. A receiver with an id_hash keeps the hash walk. One without, such as a guest whose ad-hoc record binds host to itself (so its users' account and shell deliveries name it), is compared by value with the own record of each entity scope that has no id_hash of its own. A scope with an id_hash can't be that receiver, so it is skipped, and a guest named like one of its users is not an error. A receiver that matches nothing still ends in the "not an entity on the chain" error, and one that is not a record keeps the "not an entity record" error. The comparison is fix(core): late dispatch offers the registries of the entities a scope binds #752's loud helpers (an error for two records that differ only in function values), moved from policy/schema.nix into policy/entity-identity.nix. fix(core): late dispatch offers the registries of the entities a scope binds #752's own late-dispatch checks keep their quiet comparison, so the move changes no fix(core): late dispatch offers the registries of the entities a scope binds #752 outcome.
  • Root kind on the full resolve. resolveWithPaths of a directly resolved entity now seeds the root scope's kind, as the static resolve has since fix(core): deliver complex-forward output and spawns to guests and static resolves #743.

Channels moved onto receiver (spec §4)

  • user-to-host (users.users.<n>), the home-manager userForward, and the user-scope arm of the home-manager host-module import (now a keyed provide, so fleet-demo's policy-resolved users keep it).
  • define-user, primary-user and user-shell. Their account settings are delivered as provide { receiver = host; path = [ "users" "users" <name> ]; }. Their host-wide settings (programs.<shell>.enable, environment.shells, system.primaryUser, wsl.defaultUser) are provides to the host. isNormalUser and extraGroups are written only on nixos hosts (spec §9).
  • The unfree and insecure host fallback: a keyed provide, so the same list from several users lands once.
  • The microvm template's guest osProvide, microvmProvide and sharedNixStore.

Every user-scope channel is also gated on home == null. A standalone home tux@igloo binds the real igloo record, which isn't on the home's chain. The content was dropped there before too.

Deliberate changes (for review)

  • Account settings use a provide, not the user class. The spec says the user class. That loses the settings whenever the battery is included on the host instead of the user: the host-scope fan-out emits user content into the host's bucket, which user-to-host doesn't read. diagram-demo's devbox does exactly this. Cell: test-host-included-primary-user.

  • Routes now read locally delivered content. For example, a guest's delivery route now carries its users' user class. This follows from the reader rule above and was approved for this PR.

  • Root-kind seeding is a fix with a visible effect. On main a host-aspects spawn under a directly resolved host was skipped. internal.delivery-edges.test-topology-home-extraction goes from 6 to 12 edges, measured on both. Flake-built hosts are unaffected.

  • internal.delivery-edges expectations for host-users, darwin and home-extraction are rebuilt from the file's helpers (userForwardTail, edge, synthesize), compared as sets. The user channels now target the host and carry the receiver annotation, and the user-scope home-manager host-module import is a provide edge. In home-extraction the forward appears twice: once from the host's fold and once from the host-aspects spawn's surfaced fold, which now materializes because of the root-kind seeding above. The trace concatenates both without dedup.

  • Isolated users' channels cross. If you set isolated on users as a User aspects deliver host-class content (nixos/darwin/os) to their hosts by default #694 workaround, their home-manager, account and shell channels now reach the host. To keep a channel off, exclude its policy. On main, isolated blocked them, because they rode the merge. Here they are deliveries that name the host, and isolated only withholds the merge (spec C13, ruled by the owner).

  • Deliveries only to OS hosts. define-user, primary-user and user-shell deliver only to nixos and darwin hosts, which are the classes main wrote. primary-user's account settings go only to nixos hosts and system.primaryUser only to darwin hosts.

  • Provide dedup follows the entity and the receiver. A provide that names a receiver dedups per source entity and target scope. A scope with no entity of its own (a microvm guest, a routing scope) belongs to its nearest entity ancestor.

Not in this PR

  • The os-user-class-fwd hook stays on the old merge. It moves in PR 2 with mutual-provider, both as provide { receiver = host; } carrying the aspect resolved for host.class.
  • The read-only oracle (edge-trace.nix route and provides lists) renders receiver edges at their source. Production doesn't read those lists.

Tests

templates/ci/modules/deadbugs/issue-694-receiver.nix, 16 cells. Each was driven red on main or by reverting the mechanism it names:

  • §3 topologies: a user route reaches its host, the user scope isolated so the old merge can't carry it; a microvm guest delivers to the real host through two scopes with no own entity.
  • C1, the nix-config-shaped guest: its delivery names the parent record and lands at microvm.vms.<name>.config; a guest user's account reaches the guest, not the parent; a home-manager user inside the guest is carried.
  • C4: the host scope keeps its own kind under a microvm-host push.
  • C6: two users' shells, unfree lists and one same-policy provide all arrive.
  • C7: a policy-resolved user still gets the home-manager NixOS module.
  • A WSL host evaluates with an unkeyed den.default { host } function.
  • The refused collapsed entity push and the unknown-receiver error.
  • From the option oracle below: a host-side primary-user include, and identical unfree lists from two users.
  • Review additions: a darwin host gets system.primaryUser and no nixos-only account options; a non-OS host gets no account or shell settings; a user-rooted static resolve that binds its host but builds no host scope drops the delivery and still resolves the user's own content.

Six of the 16 cells pass on main as well. They are preservation controls; this is what each one pins:

cell revert that turns it red
test-host-included-primary-user account settings back in the user class (measured red during development)
test-identical-unfree-lists-once the unfree host module unkeyed (measured red during development)
test-policy-resolved-user-gets-hm-module the user-scope home-manager host-module provide removed (measured red)
test-non-os-host-gets-no-account-settings none. Reverting the OS-class gate leaves it green; it pins the outcome
test-darwin-primary-user-no-nixos-account none. It pins system.primaryUser delivered and no nixos-only option
test-wsl-host-no-duplicate-default none. It pins that the wsl-host routing push applies a den.default { host } function once

Validation

Bisect evidence for the stack. main gets 7 squash commits, one per PR (#749, #751, #752, #746, #747, #753, #756). Each PR head is verified: the five rewritten heads (#752, #746, #747, #753, #756) with the full local oracle (every suite, templates and main's own templates against main, policy firings, cost), and #749 and #751 published, unchanged and green in CI. The to-users-nested unfree fixture equals main at every head.

All runs under a 12G memory cap, one top-level suite at a time, on this branch rebased onto 2f1ae4a (#744):

suite this branch main (2f1ae4a)
c1 109 109
c2 139 139
c3 248 248
c4 46 46
c5 226 226
deadbugs 291 275
deprecated 5 5
internal 283¹ 283
new 1 1

¹ The full internal run read 281/283. The two reds were internal.fx-spawn-edges, which calls assembleSpawnSubtree directly and now has to pass ownEntityOf (the defaults were removed so that a missed site fails loudly). After the fixture fix the suite reran green, 3/3.

Spec §7 oracle, over every template host, re-run against main 2f1ae4a after the review fixes (results unchanged):

  • Toplevel .drv: 9 hosts build on main, and all 9 are identical on this branch. The other 9 (fleet-demo 4, diagram-demo 3, terranix-demo 2) fail a NixOS assertion on main too.
  • Option values the moved channels write (users, home-manager users, shells, primary user, WSL user, unfree and insecure lists, microvm VMs), with lists sorted: 16 hosts on both sides, with one difference. On diagram-demo devbox, alice's and bob's extraGroups read networkmanager networkmanager wheel wheel on main and networkmanager wheel here. primary-user is included both on the host and on each user, and is now delivered once per user. Two real regressions this oracle found during development are fixed and have cells.

Against main, scaling. diagram-demo's server with N users added (and, for two hosts, the same N on server2), NIX_COUNT_CALLS counters (deterministic per eval), main bf2504f against this head:

N = 0 1 4 16
one host, main 8,883,284 10,835,092 16,695,410 40,226,007
one host, this PR 8,838,694 10,781,254 16,608,264 39,927,237
two hosts, main 9,065,523 11,127,953 17,337,954 42,533,335
two hosts, this PR 9,004,862 11,043,773 17,161,849 41,675,366

This PR is cheaper than main at every point, and the difference grows with N. Fitted per function through N = 0/1/4, the only positive N² terms against main are den-diagram's graph rendering (graph.nix instOf, fullName; it renders more edges, since deliveries are edges now) and trace.nix, at most 3.3 calls per N². Every drv is unchanged. producerScopes is a keyed set, not lib.unique, because the flake-root fold spans the fleet.

The by-value receiver path, bounded. A receiver with an id_hash costs nothing new: it takes the hash walk, as before. A receiver without one costs one comparison per scope on its chain whose own record has no id_hash either. Each comparison checks name first and stops on a mismatch, and it leaves out pipeline products (hasAspect, and __-prefixed attributes such as __resolveResult), so it never resolves an entity again. No template has such a receiver; the main-relative scaling above covers every other path this PR touches.

Cells: deadbugs.issue-694-receiver-identity (6): the same user name on a host and in its guest both get their account (red with the receiver missing from the dedup key), with a distinct-name control and a home-manager control; a guest without an id_hash receives its users' deliveries; a guest named like its user (red with hashed scopes compared); a non-record receiver is an error.

A late-included { host } policy fires at its scope (moved here from #753; reported in GitHub #754). This PR nests unfree's host half in a { host } policy. Delivered to a user through provides.to-users, that policy registers at the user after the user's own dispatch ran, and late dispatch's entity-kind filter (which keeps an ancestor's policies from re-firing at deeper kinds) dropped it, so the package never reached the host's unfree list. Author policies of that shape were dropped on main too. A scope's own late registrations are now exempt from that filter, as its own dispatch would have fired them. Cells: issue-754-to-users-nested-host-policy (unfree's host half and an author { host } policy, both red without the fix) and issue-754-ancestor-host-policy-stays-at-host (an ancestor's own host policy still doesn't fire at the user). With it, this PR alone keeps main's unfree list for a to-users delivery (the nested to-users fixture equals main).

Suites at this head (on #752): c1 109, c2 139, c3 248, c4 44, c5 226, deadbugs 334, deprecated 5, internal 284, new 1. Templates: of 14 configurations, the 9 that build on main give the same drv, and the same 5 fail on both sides; option values equal on 11 of 12 hosts, except the extraGroups difference above. main's own templates with this den: 14/14 equal.

Policy firings against this PR's previous head: 79 fewer across every suite and template configuration, every one a removed duplicate firing of the same instance (#752's fix); per policy, scope and bound arguments, no instance is lost and none added; every drv is identical.

Cost: measured against main above. The owner has given the go-ahead, and it runs after the PR 3 suite. This row will be filled with wall time and peak memory at the head sha.

@github-actions github-actions Bot added the allow-ci allow all CI integration tests label Nov 6, 2026
@sini
sini force-pushed the feat/694-receiver branch from 3bf2577 to ea93f67 Compare November 6, 2026 17:52
@sini
sini force-pushed the feat/694-receiver branch from ea93f67 to cba44b5 Compare November 7, 2026 03:06
@sini
sini changed the base branch from main to perf/claim-trace-quadratic November 7, 2026 03:06
@sini
sini force-pushed the feat/694-receiver branch from cba44b5 to a60a040 Compare November 7, 2026 21:05
@sini
sini changed the base branch from perf/claim-trace-quadratic to fix/late-dispatch-binding-offers November 7, 2026 21:06
@sini
sini marked this pull request as ready for review November 7, 2026 23:22
@sini
sini force-pushed the feat/694-receiver branch from 21fc5d0 to 7908e5f Compare November 10, 2026 22:54
@sini
sini force-pushed the fix/late-dispatch-binding-offers branch from 7c35643 to 6aca516 Compare November 10, 2026 22:59
sini added a commit that referenced this pull request Nov 10, 2026
…e binds (#752)

## Summary

Stacked on #751. A policy applies where the scope's binding for its
registrant's kind is that registrant. In the tree that's an ancestor,
which #751 covers. A scope can also bind an entity that isn't its tree
ancestor: a guest on a prod host that rebinds `environment` to dev.
Before this PR the guest got none of dev's rules (#751 already stops it
getting prod's). Now it gets dev's.

1. **Late dispatch also offers the registries of the entities a scope
binds outside its tree.** Only kinds that the scope's kept tree doesn't
bind, other than the scope's own kind, are searched. `id_hash` is
parent-blind (kind and name), so tux@iceberg must not find tux@igloo's
scope, and igloo@prod's users must not find igloo@dev's.
2. **The scope is found through an index, not a scan.** push-scope
records each entity scope by kind and `id_hash` (records without one, by
kind alone) next to `scopeByEntity`. A lookup is one attribute access
per bound kind; an ordinary scope has no kind to look up.
3. **Matching is loud when it can't be decided.** A record with an
`id_hash` and one without are different entities, unless they share a
name. A same-named pair is a `den:` error that names the kind and both
records. A guest's ad-hoc record binding `host` to itself is therefore
not an error against igloo's. Records without an `id_hash` are compared
by value with function-valued attributes set aside. If they differ only
in functions (rebuilt with fresh lambdas), that's a `den:` error too.
Before, a clash quietly fired none of the entity's rules.
4. **A binding that resolves after its binder re-passes the binder,**
with what the binder's first pass offered marked as seen. Resolution
order isn't something a user controls. So when an entity resolves, every
sibling that bound it before it existed is re-passed with the entity's
registry. The re-pass fires only what the first pass didn't offer, so a
policy registered both at a tree ancestor and at the bound entity fires
once in either order. Pending entries are keyed by kind, `id_hash` and
sibling. A repeated batch therefore doesn't add a sibling twice, and an
entry is removed once it re-passes.
5. **Termination is by construction.** Entries are only added by a
sibling's late pass, one per sibling and per kind its tree doesn't bind.
Each is consumed at most once, and a done set refuses a second (sibling,
kind) re-pass. That count is also the named cap, `maxBoundRepasses`. It
guards the construction: exceeding it is a `den:` error that states both
numbers. In this suite the most re-passes any config runs is 3, against
a cap of 6; the cap also counts bindings that never resolve.

If the bound entity never resolves, none of its rules fire. That's
correct under the rule.

**Spawns see re-passed content by construction.** A spawned sub-pipeline
(a host-aspects projection) is materialized after the walk from
`result.state`: its parent state, pipes, quirks and routes are all read
there (`resolve.nix`, `parentState`). Whatever a re-pass registered is
already in that state, whether the spawn was requested before or after
the re-pass. The projection cells cover a spawn requested by a re-passed
rule.

**Disclosed change to the fired-above set:** a sibling's late pass skips
the policies that already fired at the scopes it's offered, meaning its
kept ancestors and bound scopes. Before, it skipped those that fired at
every tree ancestor. So a guest's users are no longer blocked by a
policy that fired at the host or environment the guest dropped. That
matches the rule: the guest's own entity registers it.

### Fix since review: a late policy fires once per record and instance

Reported in an external review. Late dispatch told policies apart by
name, which went wrong two ways when a scope binds two out-of-tree
entities (a guest binding `environment = dev` and `region = r1`):

- **One record registered at both** (`same-pol`) fired twice when `dev`
resolved after the binder: the bound re-pass offered `dev`'s registry
with a seen set that lacked the first late firing.
- **Two distinct records sharing a name** (`mkPolicy "p" (km "pa")` at
`dev`, `mkPolicy "p" (km "pb")` at `r1`) fired only one of the two,
depending on resolution order. They are two policies (O4) and both must
fire.

A policy is now its record: registration carries the record's `fn` slot
(`builtins.intersectAttrs { fn = null; } p`, which copies of one record
share and two records don't), and late dispatch compares records. The
seen set lists, per name, the records offered under it, and a per-scope
guard records each instance late dispatch fired (the record with its
bound argument values) and skips a repeat. One record fires once per
instance; two records sharing a name both fire. Two `mkPolicy "p" f`
over one `f` are equal records, one policy (O5).

- **Cells:** `late-dispatch-bound-repass-once` (4): `dev` resolving
before or after the binder, `region` first or last, expecting `same-pol`
once, `pa` and `pb` both, and the distinct-policy controls.
`late-dispatch-bound-repass-once-slots` (2): one record's slot is equal
to itself (a `{ inherit (r) fn; }` copy is not), and two equal records
are one policy.
- **Mutants:** the seen set by name turns the two `dev`-first cells red;
the guard by name turns all four red; the guard removed turns the two
`dev`-last cells red (the double firing). A by-name registry merge
mutant stayed green, so that site is unchanged.
- **Effect elsewhere:** none. Across every suite and template, firings
are identical per policy, scope and arguments with the record key as
with the name key.

## Validation

**Bisect evidence for the stack.** `main` gets 7 squash commits, one per
PR (#749, #751, #752, #746, #747, #753, #756). Each PR head is verified:
the five rewritten heads (#752, #746, #747, #753, #756) with the full
local oracle (every suite, templates and `main`'s own templates against
`main`, policy firings, cost), and #749 and #751 published, unchanged
and green in CI. The to-users-nested unfree fixture equals `main` at
every head.

- **Cells:** `deadbugs.late-dispatch-any-depth`, 27/27. Fourteen new
ones; the guest cells share a fixture: environments prod and dev, igloo
in prod, and igloo's guest cuda (two users) rebinding `environment` to
dev. Every new cell is red on the code it fixes. The red-when column is
each one's mutant on this branch:

  | cell | order | red when |
  |---|---|---|
| guest rebinding `environment`, matched by `id_hash` | dev first | on
#751 (binding scopes aren't offered) |
  | the same, matched by value (no `id_hash`) | dev first | on #751 |
| the same, dev resolved after the guest | prod first | the re-pass is
disabled |
| re-passed content's complex forward lands | prod first | the re-pass
is disabled |
| host-aspects projection from a bound rule (the control) | dev first |
host-aspects is dropped |
| host-aspects projection from a re-passed rule | prod first | the
re-pass is disabled, or host-aspects is dropped |
| a policy registered at the guest and at dev fires once (counted in the
raw provides, before any dedup) | dev first | the control |
| the same | prod first | the re-pass doesn't carry the first pass's
seen names (two each at the previous head) |
| same-named users on two hosts keep their own rules | iceberg first |
the search includes the scope's own kind (igloo got `pa-igloo-tux` at
the previous head) |
| one host under two environments keeps per-scope rules | dev first |
the search includes kinds the tree binds |
| a binding with an `id_hash` against one without is an error | — | at
the previous head (no rules, silently) |
| records differing only in functions are an error | — | at the previous
head (no rules, silently) |
| an ad-hoc guest record without an `id_hash` gets dev's rules | dev
first | the mixed-`id_hash` error ignores names (`ddfbfaf`) |
  | the same | prod first | the same |

The two-environments cell decides per scope, not per entity: a
registration applies to its own registering scope (§11a N1, ruled per
scope).

- **Every suite**, single-process nix-unit: c1 109, c2 139, c3 248, c4
44, c5 226, deadbugs 306, deprecated 5, internal 284, new 1.
- **Template oracle** against `main` `bf2504f`: every template
configuration evaluates to the same drv (36/36 result files equal), and
the option values the channels write are equal on all 12 hosts (24/24).
- **Firings** against #751 (`e93246b`), outside the `deadbugs` suite:
identical per file and policy before the fix below. The fix removes 77
firings across every suite and template configuration, every one a
removed duplicate firing of the same instance (the #752 fix); per
policy, scope and bound arguments, no instance is lost and none added;
every drv is identical.
- **Cost**, against #751 on `diagram-demo`'s `server` with N users added
(and, for two hosts, the same N on a second host, `server2`). Counters
are from `NIX_COUNT_CALLS`, which is deterministic per eval; there are N
= 0, 1, 4 and 16 points, the fit runs through 0/1/4 and is checked at
16.
- One host: Δcalls = 3,376 + 348·N, exact at N = 16 (8,944, +0.022%).
Δalloc at N = 16 is +561 KB (+0.011%).
- Two hosts: Δcalls = 4,174 + 700·N, exact at N = 16. That's 350 per
user, the same as one host, so there's no cross-host term.
- The quadratic coefficient is 0 for each of the 241 functions whose
count changes, and for each of the 10 files. The drv is the same at
every point.
Base automatically changed from fix/late-dispatch-binding-offers to main November 10, 2026 23:00
sini added 5 commits November 10, 2026 15:01
`route`, `forward` and `provide` accept `receiver = <entity record>`. The
delivery lands in the first scope, walking up from its source, whose own
entity has that record's id_hash, instead of in the source's bucket. A
receiver not on the chain is an error naming the record.

- targetScopeOf computes the target at every site that hard-coded the source
  scope (simple routes, complex forwards, provides, the toposort producer key,
  the edge trace). sourceScopeId keeps meaning the source.
- A simple route that reads a bucket a delivery writes into reads it after
  the fold, ordered after every producer into it.
- A provide naming a receiver dedups per source entity, so one battery policy
  firing at several user scopes keeps each user's delivery.
- push-scope: a push that lands on its parent's scope id (a routing kind,
  or a re-entry of a record the parent already binds) overwrites none of
  that scope's kind, entity link or isolation mark. An entity push of a new
  record that adds no nameable key is refused by name.
- The full resolve seeds the root scope's entity kind, as the static resolve
  does since #743.
- den's channels move onto receiver: user-to-host, the home-manager forward
  and host module, define-user, primary-user, user-shell, the unfree and
  insecure host fallback, and the microvm template's guest provides.

Reported in Matrix.
den's batteries deliver to `receiver = host`, and a guest whose ad-hoc
record carries no id_hash binds `host` to itself, so its users' account and
shell deliveries named a receiver the walk could not find. A receiver with
an id_hash keeps the hash path; one without is compared with each scope's
own record through the identity function #752 uses, moved out of
policy/schema.nix into policy/entity-identity.nix: by value with function
attributes set aside, and an error where den cannot tell.
…g unhashed records

id_hash is parent-blind, so tux on igloo and tux in igloo's guest gave one
receiver-provide dedup key and igloo's tux lost its account; the key now
includes the receiver's target scope. The by-value receiver walk compared an
unhashed receiver with hashed scopes and threw the same-name error across
kinds (a guest named like its user); a scope whose own record carries an
id_hash is skipped, and an unmatched receiver still ends in the "not on the
chain" error. Only an entity kind has an own record for that walk.

#752's late-dispatch identity checks keep their quiet comparison; only the
loud helpers moved to entity-identity.nix. producerScopes is a keyed set,
not lib.unique, since the flake-root fold spans the fleet.
Reported in GitHub #754. A policy nested in an aspect that reaches its scope
through a late delivery (a host's provides.to-users or provides.<user>, a
host policy's include) registers at that scope after its own dispatch ran.
Late dispatch reached it, but the entity-kind filter that keeps an
ancestor's policies from re-firing at deeper kinds also dropped the scope's
own registrations when their fn names no argument of the scope's kind. So
unfree's { host } host half, nested in a policy since this PR, never fired
for an aspect a host hands its users. A scope's own registrations are now
exempt from that filter, as its own dispatch would have fired them.
@sini
sini force-pushed the feat/694-receiver branch from 7908e5f to a6f446f Compare November 10, 2026 23:01
@sini
sini merged commit b89368b into main Nov 10, 2026
4 checks passed
@sini
sini deleted the feat/694-receiver branch November 10, 2026 23:02
sini added a commit that referenced this pull request Nov 10, 2026
## Summary

PR 2 of 3 for #694 (spec:
https://gist.github.com/sini/de16b6cb510067d6d31bf5f365db832a, §5 and §7
item 2). It stacks on #746.

It adds two batteries for host-side acceptance of what users deliver.
mutual-provider's delivery part is **inert** until PR 3 removes the old
subtree merge: the merge still carries the content, so delivering it as
well would double unkeyed modules. Their receivers are already resolved,
so a delivery that can't land fails now rather than after the flip.

### What PR 3 changes here

- **These deliveries are replaced, not switched on.** The delivery below
re-resolves the provided aspect for `host.class`, and so does the
`os-user-class-fwd` provide. That re-resolve sees pipe values before
assembly (§11 F1). PR 3 replaces both with provenance at emission: the
provided include is wrapped and a route moves exactly the modules
emitted under it. Until then they are inert, so no output here depends
on them.
- **The default is a transition default.** PR 3 makes `mutual-provider`
(and `user-aspects`) opt-in, with a default form of each on every host
until 2027-01-01 that warns for what reaches a host only through it. The
default described below is this PR's interim state.
- **The opt-out is inert before the flip.** Excluding the battery
removes its acceptance key, but the old merge still carries a user's
content, so the exclude doesn't stop `provides.to-hosts` content yet.
The docs now say so.

### `den.batteries.mutual-provider` (on by default)

It replaces the user → host half of cross-entity providers:
`provides.to-hosts` and `provides.<host>`. Each one now also delivers
the provided aspect's `host.class` output to the host, as `provide {
receiver = host; module = <the aspect resolved for host.class at the
user's ctx>; }`. Its other classes stay local through the existing
include. Being a provide, it reads no bucket, so two users' `to-hosts`
can't form the delivery-edge cycle a forward would. Host → user
(`to-users`, `provides.<user>`) is unchanged.

- It's included in `den.schema.host.includes`. Opt out with
`den.schema.host.excludes = [ den.batteries.mutual-provider ];`.
- It gates on `host ? class` and `home == null`: a standalone home binds
a host that isn't its ancestor.
- The earlier inert compat shim
(`modules/compat/mutual-provider-shim.nix`) is removed, since it defined
the same option. The battery stays callable (`den._.mutual-provider {
}`), the form older configs used.
- The battery is the policy record itself, not an aspect. As an aspect
the provider type doubles its identity
(`den/batteries/mutual-provider/mutual-provider`), which
`c1.walkstamp-parametric-roundtrip` rejects. That doubling is
pre-existing for every `den.batteries.*` aspect; this is the first one
included by default.

### `den.batteries.user-aspects` (opt-in, host-side)

A host accepts its users' whole host-class output, own `os` included,
optionally only `{ users = [ ... ]; }`:

```nix
den.aspects.igloo.includes = [ den.batteries.user-aspects ];
den.aspects.igloo.includes = [ (den.batteries.user-aspects { users = [ "tux" ]; }) ];
den.schema.host.includes   = [ den.batteries.user-aspects ];
```

The part you include is a host-scope policy that publishes the host's
acceptance. This PR ships only that: the delivery it gates lands in PR
3, where an accepted (host, user) scope is exempt from the bounded
merge, so the user's whole `host.class` output (provides, routes and
forwards included) keeps reaching the host as it does on main. Included
on a user, it accepts nothing.

### Acceptance keys

Each battery publishes context keyed by the host's `id_hash`
(`den.lib.acceptance`). Enrichment persists into child scopes, so a
guest nested under an accepting host inherits the key but doesn't match
it. `user-aspects` writes one key per argument set, so identical
includes share one.

### Battery identities

- A battery named from its arguments (`user-aspects`, `unfree`,
`insecure`) names them by the sorted, deduplicated JSON of the string
list, e.g. `user-aspects-accept(["a,b"])`. The user named `all`, a comma
inside a name, and argument order can't collide or split. The approved
approach was gen-identity's `hashIdentity`. `builtins.toJSON` gives the
same injectivity for a list of strings and keeps den at zero flake
inputs.
- `unfree`, `insecure`, `tty-autologin`, `vm-autologin` and
`import-tree` are now `den/batteries/<name>`, with every instance under
that identity, so `excludes = [ den.batteries.unfree ]` removes each
argument set; one set is excluded with `excludes = [
(den.batteries.unfree [ "z1" ]) ]`. Before, the bare battery's identity
was `<anon>` and its exclude removed nothing (on main too). A battery
exclude follows #613's tree position like any aspect exclude: a host's
exclude doesn't reach what its users include.
- An `import-tree` root is identified by its whole path, with only the
store directory stripped (the hash stays, so two inputs both stored as
`source` stay distinct). Two roots sharing a basename, and two
`provides.host` roots for one host, were one aspect on main, so one tree
was never imported; both now land. Messages show the root without its
hash (`den.lib.argsName.withoutStoreHash`), e.g. `source/hosts/igloo`.
Only a hash at the start of a path segment is dropped, so a name that
merely contains a hash-like run is shown as written.
- A root's identity is its store path, so `./dir` and `"${./dir}"` are
two roots: a path literal is copied as part of the flake, a string
interpolation as its own store object. Mix them and the same files are
imported twice. On main they deduplicated by accident, through the
shared basename. Write each root one way.
- **A main defect fixed here:** `baseNameOf` kept the root's string
context, so a root given as a string into a flake input
(`"${inputs.x}/hosts"`) built an identity den rejects with "is not
allowed to refer to a store path".

Because the key persists into user scopes, `take.exactly` now ignores
acceptance keys, the same way it already ignores `class`. Otherwise
every `take.exactly ({ host, user }: …)` would stop firing once the
default-on battery publishes. Caught by `internal.ctx-transformation`.

### `os-user-class-fwd`

The home-env hook's host-class output is also delivered as a receiver
provide (inert here, like the batteries), resolved at the user scope's
full context. The delivery is its own schema policy,
`<env>-os-user-class-fwd-host`, next to `<env>-user-detect`. Provides
dedup by policy name, class and path, so sharing a policy with the
home-manager host-module provide would drop one of them. Its include
stays and carries the merge until the flip.

### Inert deliveries in the ordering

An inert delivery isn't applied, but its trace edge still exists and
still counts as a producer in the toposort, so it constrains the order
of the routes that read its target bucket. That's extra ordering work
per inert delivery. It doesn't change any output, because an inert
delivery appends nothing. The flip removes the marker, after which
they're ordinary deliveries.

## Tests

- `deadbugs/issue-694-battery-names.nix` (8 cells): `["all"]` vs the
bare battery, `["a,b"]` vs `["a" "b"]`, order, equal arguments
registering once, unfree and insecure names. Restoring the old naming
turns them red from #753 on (before the flip the comma cell's content
arrives anyway).
- `deadbugs/issue-694-battery-excludes.nix` (11 cells): host-side and
user-side exclude of each of `unfree`, `insecure`, `tty-autologin`,
`vm-autologin`, a one-set exclude, and two controls. Red 8/8 with the
instance chain back at `den/provides` or with the record unnamed.
- `deadbugs/issue-694-import-tree-identity.nix` (8 cells): `a/disko` and
`b/disko` both land; one root twice is one identity; two `provides.host`
roots both land; excluding one root or the battery; two `source` store
roots with the same tail both land; the readable form, and text that
only contains a hash-like run shown as written. Restoring `baseNameOf`
turns the five naming cells red; stripping the hash from the identity,
unnaming the record, or unanchoring the display regex turns its cell
red.

`templates/ci/modules/deadbugs/issue-694-batteries.nix`, 13 cells, green
in this PR:

- a standalone home with `provides.igloo`, and a bound home with
`to-hosts`, still evaluate;
- the default battery publishes its key; excluding it removes the key,
from `den.schema.host.excludes`, `den.hosts.<sys>.<host>.excludes` (with
the other host's key kept) and `den.aspects.<host>.excludes`;
- the callable form still evaluates;
- two users' `to-hosts` evaluate together;
- `user-aspects` publishes one key per argument set; included on a user
it publishes nothing;
- a user's `take.exactly ({ host, user }: …)` still fires with
mutual-provider on: green with the fix, red with the acceptance-key
filter removed;
- the os-user-class-fwd delivery and the home-manager host-module
provide both reach the trace: green with the fix, red with the hook's
provide sharing the user-detect policy;
- a user's `to-hosts` emits its host delivery at the user scope on a
built host, and a standalone home emits none. Removing the battery's
`home == null` gate leaves this cell green: the delivery is already
dropped by #746's rule for receivers the resolve doesn't build, so the
gate isn't observable. The cell pins the outcome.

The six cells that need the flip (spec §7, N6) are written against this
PR's code and land in PR 3. Each was driven red at this PR's head.

## Commits

1. `211fe46` feat(batteries): mutual-provider and user-aspects
2. `32caa09` fix(batteries): argument batteries and import-tree roots
have distinct, excludable identities
3. `ed60fef` docs(batteries): battery identity and excludes

## Validation

**Bisect evidence for the stack.** `main` gets 7 squash commits, one per
PR (#749, #751, #752, #746, #747, #753, #756). Each PR head is verified:
the five rewritten heads (#752, #746, #747, #753, #756) with the full
local oracle (every suite, templates and `main`'s own templates against
`main`, policy firings, cost), and #749 and #751 published, unchanged
and green in CI. The to-users-nested unfree fixture equals `main` at
every head.

Each top-level suite ran with nix-unit as a single process, at the head:

| suite | this branch |
|---|---|
| c1 | 109 |
| c2 | 139 |
| c3 | 248 |
| c4 | 44 |
| c5 | 226 |
| deadbugs | 355 |
| deprecated | 5 |
| internal | 284 |
| new | 1 |
| battery-excludes | 11 |
| import-tree-identity | 8 |

(c4 counts 46 under `just ci` and 44 under nix-unit, on main too.)

- **Docs:** `nix-shell --run 'just docs-build'` passes, and all internal
links are valid. The pages updated are `reference/batteries.mdx`,
`guides/batteries.mdx`, `guides/mutual.mdx` and
`explanation/where-config-lands.mdx`.
- **Template `.drv` / option oracle** against main (`bf2504f`): of the
14 template configurations, 9 build and produce the same toplevel `.drv`
as main, and the same 5 fail to evaluate on both sides (diagram-demo
alice/devbox/laptop, terranix-demo web-1/web-2). Main's own unadapted
templates give the same result with this branch as `den`. Option values
match on 11 of 12 hosts; the twelfth is `diagram-demo`'s `devbox`, where
main lists `extraGroups` entries twice and this branch once.
- **Policy firings:** against this branch's previous head, 79 fewer
across every suite and template configuration, every one a removed
duplicate firing of the same instance (#752's fix); per policy, scope
and bound arguments, no instance is lost and none added; every drv is
identical. Apart from that, firings are identical to the branch before
the battery-identity fixes, except the intended rename
(`unfree-host(vscode)` → `unfree-host(["vscode"])`).
- **Cost:** on 8 template hosts the drvs are unchanged; evaluation adds
at most 66 thunks per host against the branch before the identity fixes.
sini added a commit that referenced this pull request Nov 10, 2026
…defaults (#694, 3/3) (#753)

## Summary

PR 3 of 3 for #694 (spec:
https://gist.github.com/sini/de16b6cb510067d6d31bf5f365db832a, §2, §5,
§6, §7 item 3, §11, §11a). It stacks on #747.

This is the flip: an entity's content stays in the entity that wrote it.
A user's `nixos`, `darwin` and `os` no longer reach its hosts by
nesting. Content crosses only through a delivery that names its receiver
(#746), because the receiver accepts it (`user-aspects`), or because the
policy that wrote it was registered on the host.

**Nothing changes for existing configs until 2027-01-01.** Until then,
den keeps two transition defaults on every host, `user-aspects` and
`mutual-provider`, so a config behaves as on `main`. A host warns once,
listing the host-class content that reaches it only through those
defaults. `den.migrations.user-host-content.acknowledged = true;` adopts
the end state now.

### The bounded merge

Every scope with an own entity is a boundary (`entityBoundary` in
`materialize-unified.nix`). That one set bounds the default fold,
`collectSubtree` routes and the flat surface (`den.lib.aspects.resolve`
/ `resolveImports`), so the per-host merge and a flat resolve agree.

These stay unbounded:
- flake routes;
- spawn extraction;
- an `instantiate` with no entity on its source chain. Every other
`instantiate` is bounded.

`den.schema.<kind>.isolated` is deprecated and warns.

### A policy applies to the entity it is registered on (§11a)

- **R1, the registrant.** A policy records, when it registers, the
nearest own entity of the registering scope. Dispatched later at a
descendant, it still applies to that entity. A record without an
`id_hash` is identified by value, through the same identity function
#752 and #746 use. Its registrant token is keyed `<kind>:<name>`.
- **R3, delivery.** An instance firing below its registrant lands its
bare includes in full where it fired. Their host-class part reaches the
registrant through a provenance route (mutual-provider's mechanism,
below). A `provide` or `route` with no receiver is aimed at the
registrant. A class-less registrant (an environment) sends its
host-class part to the nearest classed entity below it.
- **R5:** a user the registrant accepts through `user-aspects` is
already unbounded, so the route stands down.
- **R6:** a shared source fanned out at a host for a user the host
accepts is dropped there, since the lifted merge carries the user's own
copy. The drop is keyed by host and user `id_hash`, because `id_hash`
alone is parent-blind.
- **C4:** a policy inside a registrant's delivered include inherits that
registrant.
- The instance rule itself (R2) lands in #751; the combinator repairs in
#751 too. This PR keeps their cells.

### The transition defaults and their warning (until 2027-01-01)

- `den.batteries.user-aspects` and `den.batteries.mutual-provider` each
have a default form: its own policy, publishing its own acceptance key,
while the transition is active. It rides `den.default.includes`, so it
reaches host, user and home; `resolveEntity` adds it for any other
entity kind whose record has a `class` (a guest that is its own host).
It acts only where `host` is bound and neither `user` nor `home` is. An
explicit include of a battery is told apart from its default. Excluding
a battery excludes its default too: an exclude of a ref carrying
`__defaultForm` also registers the default policy's exclude. For the
unmatched-exclude diagnostic the two are one entry, so neither state
reports a false "suppresses nothing". That special case is temporary,
until PR 4's origin-matched excludes.
- **The warning:** one `lib.warn` per host and class, listing by user
and aspect the host-class content that reaches the host only through a
default:
- what the `user-aspects` default lifts that the explicit boundary would
leave with the user;
  - what only `mutual-provider`'s default delivers.

It is computed from the delivery fold's own state, with no second walk,
and only while the transition is active:
  - the explicit-only boundary over `acc.perScope`;
- the deliveries the end state makes, including those the `user-aspects`
default made redundant. Those stand down: mutual-provider's and R3's
routes are recorded in `scopedStandDowns`, the `os-user-class-fwd`
hook's provide in `scopedStandDownProvides`, never delivered;
- what a default-only mutual-provider route delivers, minus what the
host has before any delivery.

The message gives the lines to add (`den.schema.host.includes = [
den.batteries.user-aspects ];`, and the same for `mutual-provider`). It
covers the host's class only.
- **`den.migrations.user-host-content.acknowledged = true;`** turns both
defaults off. Batteries included explicitly still apply, and the warning
stops.
- **On 2027-01-01** (`den.lib.migrations.removalDate`) the defaults, the
warning and the flag are removed. The flag becomes a throwing stub for
one release, tracked by a dated cleanup issue.
- A nested entity with its own class (a guest that is its own host) owns
its host-class content, so the warning does not list it.

### `user-aspects` lifts the boundary

A scope that binds a user its host accepts is not a boundary: the user's
own scope, and an entity resolved for that user. The accepted user's
host gets what `main` gives it: every class, forwards, routes, provides
and the flat surface. The lift is keyed on the host's `id_hash`, so a
guest under an accepting host stays bounded, and so do the guest's
users. `mutual-provider`'s delivery and the `os-user-class-fwd` hook
stand down for accepted users.

### mutual-provider: provenance at emission

- The cross-provider include is wrapped in
`den-provides-to-host=<owner>/<key>`, and the class collector records
the locations emitted under it, per scope.
- The host delivery is a route (`fromClass = intoClass = host.class;
receiver = host; __fromProvenance = token;`) that moves exactly those
modules from the user's folded bucket, so pipe and quirk values bind as
for any user content.
- Named aspects inside the provided aspect come along; the same aspect
included directly by the user does not.
- Route dedup keys on the token, so two owners' deliveries both land.

### Home-env host arm

- The hm/hjem/maid host module is delivered as a keyed provide at host
scope. On `main`, excluding the user arm dropped the host module; the
merge hid that.
- The env's schema includes are their own policy,
`host-to-<env>-schema-includes`, included at user scopes with the host
class stripped.

### Behaviour changes in the end state

These apply once a config acknowledges the migration, and for everyone
from 2027-01-01. Until then, every one of them is listed by the warning.
- A user's own `nixos` / `darwin` / `os`, what it includes, and `{ host,
user }` functions in `den.default` that write host classes stay in the
user.
- `provides.to-hosts` and `provides.<host>` reach a host that includes
`den.batteries.mutual-provider`.
- A policy binding `{ host, user }` that returns a bare `include` of
host-class content lands it at the user scope, unless it was registered
on the host (§11a). The fix is `provide { receiver = host; class =
host.class; … }`.
- A host-rooted flat resolve of a custom class no longer collects users'
content unless the host accepts them.

### Fixes since review
- **A `policy.exclude` effect stops a battery's transition default**
(reported in an external review). The aspect `excludes` list paired a
battery with its default; a `policy.exclude` returned by a policy in an
aspect's `includes` (or on `den.schema.<kind>.includes`) didn't, so it
stopped an explicit battery and left the default on. It now pairs it as
the list does. Cells: `exclude-forms-transition-parity` (14) and
`exclude-forms-mp-parity` (4), list against effect forms with the
transition on and acknowledged; the effect-form cells go red without the
fix. The review's validator-routing probes are kept as
`provided-validator-routing` (9).
- **The #754 late-dispatch filter fix moved to #746**, where unfree's
host half first becomes a nested policy, so every PR in the stack keeps
main's unfree list for a to-users delivery. This PR keeps the
late-delivery grid and the `to-hosts` provenance cells.

- **A policy nested in a late-delivered aspect fires where it lands, as
its direct twin does** (reported in #754). An aspect a host hands its
users (`provides.to-users`, `provides.<user>`), that a user provides to
its hosts (`provides.to-hosts`, `provides.<host>`), or that a host or
user policy includes reaches its scope after that scope's own dispatch.
A policy inside it whose function names no argument of that scope's kind
(a `{ host, ... }:` policy at a user) was dropped by late dispatch's
entity-kind filter. That filter exists for an ancestor's policies, and
now serves only a capture from a host root. So `den.batteries.unfree`'s
host half, nested in a policy by this PR, didn't reach the host for an
aspect delivered through `provides.to-users`. Author policies of that
shape were dropped on `main` too, through the same paths.
- They now fire, and their host-class part goes where §11a sends a
registrant's: to the host that registered them (to-users,
`provides.<user>`, a host policy).
- A policy nested inside `provides.to-hosts` or `provides.<host>` is
part of what `mutual-provider` delivers, as that provide's static
content is (owner ruling, 2026-11-08). That includes an aspect reached
both directly and inside the provide, and a provider nested in a
provider, where the innermost decides. It needs the battery, and
excluding the battery stops it. The warning lists it by its provider.
- The provider is recorded by den itself while it walks the provide,
never read from an aspect name; an author aspect named with den's
internal marker (`den-provides-to-host=…`) is refused.
- A policy the user registers itself keeps its host-class include at the
user.
- In den's own templates nothing changes: the same policies fire and the
same drvs build.
- **The transition warning no longer lists collision validators**
(reported in #755). The validator den adds beside a parametric class
module is bookkeeping, so a migrated `provides.to-hosts` module no
longer leaves a `<collision-validator>` entry behind.
- **The transition warning shows an `import-tree` root without its Nix
store hash** (`source/hosts/igloo`), through the helper #747 adds; the
list a cell reads (`denTransitionDefaultLost`) is the same readable
form. Cell: `issue-694-migration.test-import-tree-root-warned-readable`,
red with the helper removed.

- **Known limit, present on main too:** a `policy.exclude` effect
returned by a policy that is itself delivered by another policy's
`include` takes effect too late and removes nothing. Write the exclude
on the aspect that includes what it removes (`excludes = [ … ]`), or
return it from a policy listed directly in that aspect's `includes`. A
later den release fixes it.

### Test changes

- **The suite tests the end state.** `test-support/end-state.nix` sets
the internal `den.internal.transitionDefaults = false` once for every
cell. `deadbugs/issue-694-migration.nix` (22 cells) turns the defaults
back on and pins, each with the warning list asserted:
  - with the defaults on, nothing changes, and the warning lists it;
  - the acknowledgement turns both defaults off and warns nothing;
  - an explicit include, or a host-placed aspect, gives no warning;
  - excluding either battery stops its default;
  - content the host already has is not listed;
  - the `os-user-class-fwd` hook is not listed;
- a guest kind that copies no host includes gets the default, and a
standalone home publishes none;
  - the steam-shaped dual aspect, by default and acknowledged;
- one warning entry for each form in #694's table (own `nixos`, include,
function, function module, `os`, `classes = [ "homeManager" ]`), plus a
user policy's bare include and `provides.to-hosts`.

Mutants: without mutual-provider's `__defaultForm`, without the
already-on-host filter, without the hook's stand-down or its exemption,
each cell named for it goes red.
- **The switch to the end state turned 56 cells red, each fixed for its
subject:**
- **30** pin `provides.to-hosts` delivery. They now include
`den.batteries.mutual-provider` explicitly, per cell or in the file's
shared setup.
- **26** pinned the hard loss error of an earlier revision of this PR.
They now assert the end state: the content isn't on the host. Their "den
notices" coverage moved to the warning's form cells above. Two cells are
renamed to what they assert: `test-user-policy-to-hosts-stays-in-user`
and `test-excluded-not-delivered`.
- **Fixtures that author user `nixos` but aren't about the user → host
merge:** 34 had a host-side `user-aspects` include, marked as setup.
Each was removed and the suites run. Only 5 stayed green, and those 5
dropped it. The other 29 assert a user's host content on the host, so
they keep it.
- **New cell files:** `issue-694-flip` (each form in the issue's table,
plus a control for each sanctioned channel), `-batteries-flip`,
`-user-aspects-lift`, `-mutual-provider-exclude`, `-channel-exclude`,
`-provenance`, `-registrant`, `-instances`, `-combinators`,
`-migration`.

### Templates (users copy these)

Each now uses a sanctioned channel rather than a user's untargeted
host-class content, and none depends on a transition default:

| Template | Before | After |
|---|---|---|
| `default` | CI disk stub in `den.aspects.tux.nixos` |
`den.aspects.igloo.nixos` (a host setting); `mutual-provider` included
for tux's `provides.to-hosts` example |
| `example` | alice's `nixos` (vim), `cooper` (`nixos` description),
`eg.autologin` included by alice | `provides.to-hosts`, with
`mutual-provider` included on hosts; `policies.to-igloo`'s provide gains
`receiver = host` |
| `diagram-demo` | alice/bob's `nixos.users.users.<n>.isNormalUser` |
the `user` class |
| `diagram-demo` | `hyprland` / `gnome` `nixos` (included by a user),
deploy's system account | `provides.to-hosts.nixos`, with
`mutual-provider` included on hosts |
| `fleet-demo` | `ssh-keys` from a `{ host, user }` aspect in
`den.default` | the `user` class |

### Validation

**Bisect evidence for the stack.** `main` gets 7 squash commits, one per
PR (#749, #751, #752, #746, #747, #753, #756). Each PR head is verified:
the five rewritten heads (#752, #746, #747, #753, #756) with the full
local oracle (every suite, templates and `main`'s own templates against
`main`, policy firings, cost), and #749 and #751 published, unchanged
and green in CI. The to-users-nested unfree fixture equals `main` at
every head.

**Nothing changes by default.** PR 3's den, with the transition defaults
on, against `main`'s own unadapted templates (`bf2504f`): of the 14
configurations, 9 build and evaluate to the same drv as on `main`, and
the same 5 fail to evaluate on both sides (diagram-demo
alice/devbox/laptop, terranix-demo web-1/web-2). `default`, `example`
and `diagram-demo` emit the warning there, so the defaults are
exercised, not bypassed.

Against `main` `bf2504f`, at the head:
- **Suites** (single-process nix-unit per suite): c1 112, c2 139, c3
251, c4 44, c5 226, deadbugs 822, deprecated 5, internal 284, new 1. All
green, in the end state. Two suites added by #747 run on their own:
battery-excludes 11/11 and import-tree-identity 8/8.
- **Templates** (which run with the transition defaults on): of the 14
configurations, the 9 that build are identical to `main`'s, and the same
5 fail on both sides. The option values the channels write are equal on
all hosts (24/24 files), except diagram-demo `devbox`'s `extraGroups`,
no longer doubled (disclosed in #746). No template emits a transition
warning.

### The warning's cost

The warning alone: the head with the defaults on, against the same head
with only the warning stubbed out (`checkLost` returns its modules). 8
template hosts that evaluate on `main`, `NIX_SHOW_STATS` counters
(deterministic per eval): thunks +0.001% to +0.008%, calls +0.001% to
+0.010% (diagram-demo `server`: +1,047 thunks and +868 calls),
allocation +10 KB to +48 KB. Every drv is unchanged. In the end state,
and once acknowledged, the list isn't computed.

The whole transition state (both defaults on and the warning), this PR
without the transition state against it:

| host | thunks | calls | alloc |
|---|---|---|---|
| default igloo | +951 (+0.008%) | +1,038 (+0.013%) | +66 KB |
| example igloo | +2,423 (+0.014%) | +3,018 (+0.025%) | +165 KB |
| example apple (darwin) | +2,717 (+0.033%) | +3,231 (+0.064%) | +177 KB
|
| diagram-demo server | +7,688 (+0.059%) | +7,839 (+0.087%) | +503 KB |
| microvm server | +2,480 (+0.015%) | +2,483 (+0.022%) | +149 KB |
| minimal igloo | +1,253 (+0.014%) | +1,262 (+0.022%) | +78 KB |
| flake-parts-modules igloo | +2,243 (+0.025%) | +2,202 (+0.037%) | +140
KB |
| scoped-import-tree igloo | +1,253 (+0.014%) | +1,262 (+0.022%) | +70
KB |

Every drv is unchanged.

### Policy firings and cost of the review fixes

Against this PR's previous head: 79 fewer firings across every suite and
template configuration, every one a removed duplicate firing of the same
instance (#752's fix); per policy, scope and bound arguments, no
instance is lost and none added. The intended battery rename
(`unfree-host(vscode)` → `unfree-host(["vscode"])`) is the only other
change. On the 8 template hosts every drv is unchanged and evaluation
moves by −0.026% to +0.002%.

### Commits

1. `da80b04` feat(core): an entity's content stays in its entity
2. `3308603` a policy applies to the entity it is registered on (§11a)
3. `b783089` transition defaults for user-aspects and mutual-provider,
and their warning
4. `e2d991e` late-delivered nested policies fire; the transition warning
lists only real losses (#754, #755)
5. `c14ab47` docs: a resolve's bundled includes go to its entities
6. `5f46e83` the transition warning shows an import-tree root without
its store hash
7. `f0cebe6` a `policy.exclude` effect stops a battery's transition
default
8. `6f582b1` test: pin a dispatch-time exclude effect as a known limit
9. `978edc3` docs: crossing-scopes matches the shipped contract

### Docs

- `explanation/crossing-scopes.mdx` (new): receivers, the batteries, and
the transition defaults with the acknowledgement.
- `where-config-lands.mdx`: the #694 caution describes the shipped
behaviour.
- `reference/schema.mdx`: `isolated` is deprecated.
- `reference/batteries.mdx`, `guides/batteries.mdx`,
`guides/mutual.mdx`: `mutual-provider` is opt-in, on by default until
2027-01-01.
- `reference/policies.mdx`: a bare `policy.include` lands where the
policy fires.
sini added a commit that referenced this pull request Nov 10, 2026
…forcement (#694, 4) (#756)

## Summary

PR 4 for #694 (spec:
https://gist.github.com/sini/de16b6cb510067d6d31bf5f365db832a, §12, §11a
O2). It stacks on #753.

With content staying in the entity that wrote it (#753), a policy's
effects now name where they go, and a receiver decides what it takes.
Every piece is additive: a config that uses none of them evaluates as on
#753.

### `include.at` and `include.atClass`

`den.lib.policy.include.at <entity> <aspect>` names the entity the
content attaches to. The entity must be one of the instance's relata,
bound in its context; anything else throws. At the firing scope's own
entity it is a plain include. Anywhere else it becomes a delivery to
that entity: a `provide` into the entity's class, with the aspect
resolved at the firing scope's context, as `user-aspects` delivers.
`include.atClass <class> <entity> <aspect>` gives the class instead, for
an entity with none of its own or for a different one.

`include.atClass <class> <entity> <aspect>` is the default name, open to
later review.

### Excludes match by origin

Excluding an aspect now also excludes the policies that originate from
it. A policy's registry entry records its origin, the include chain it
registered under. An aspect exclude visible at the firing scope (the
scope and its ancestors) matches when the aspect, a path below it
(`id/…`) or a parametric instance (`id(…)`) is on that chain. Unlike an
aspect's own content (#613), where the include sits in the tree doesn't
matter: what matters is that the excluding entity is a relatum of the
instance. The check runs both at dispatch and in the late sibling
re-dispatch, so both remove the same instances.

Only aspect excludes match origins. A policy exclude names one record
and matches it by value; it is never read as a name, so excluding the
policy `den.policies.tools` leaves the policies the aspect
`den.aspects.tools` carries, and an author policy named below a battery
(`mutual-provider/mine`) is not excluded with the battery.

A battery and its transition default are paired by value. Each battery
carries its default policy (`__transitionDefaultPolicy`); an exclude of
the battery records that record on its constraint entry, and a policy
whose registry record equals it is excluded too. An author can't produce
an equal record without copying den's, and an explicit include of the
battery stays a distinct policy from the default, so the two are never
deduplicated. This replaces #753's temporary `__defaultForm` special
case in `excludeList` and in the unmatched-exclude diagnostic. For the
diagnostic, the pair is one entry: matched when either registered.

An exclude removes exactly the instances of the rule it names, no more
and no fewer, whether it is an aspect's `excludes` or a policy's
`exclude` effect:
- A policy exclude names its record by value, in both forms. A different
record of the same name, on another user or displaced on the same one,
is left alone. An aspect of that name is too.
- An aspect exclude matches policies by origin, never by name. The one
exception is den's provides policy, which answers to an exclude of the
aspect it provides by its token: `den.aspects.igloo.excludes = [
den.aspects.tux.provides.to-hosts ]` stops that delivery, and no author
record named `tux/to-hosts`.
- A record wrapped by `policy.when`, `policy.for` or `policy.strict` is
reached by an exclude of the record it wraps. A den combinator's record
is reached by an exclude of what it wraps only while it is exactly what
den built; any `//` the author applies afterwards makes it a different
rule. So a `__wraps` an author sets reaches nothing, and neither does a
graft of one combinator's parts onto another or `(den.lib.policy.strict
w) // { __strict = false; }`. A combinator registered under its own name
(`den.policies.sw = den.lib.policy.strict den.policies.w`) is reached by
an exclude of `w`: a policy's name is its identity, so den also files a
wrapping record under the wrapped record's name, and den's own rename in
the `den.policies` merge isn't a change. A renamed record an author
stores in `den.policies` is re-stamped to its key by that merge, so it
is that key's rule and reached as such. A strict record is still refused
to an excluder that isn't its registrant (§11a O2).
- On `main` a policy's `exclude` effect matched by name, so it could
remove a namesake record or aspect. That's narrowed here. No den
template and no downstream site we checked relies on it.
- **Limit:** a constructor that builds a new record on each call
(`mkThing args`) gives a new value each time, so `excludes = [ (mkThing
args) ]` names nothing that registered, and den warns that it never
registered. When a policy of that name did register, the warning adds
the hint: bind the record once and use that value in both places, or
register it under `den.policies`.

Release note: excluding an aspect on a host now reaches the policies it
carries for that host's users, widening #613 for policies (its content
on the user is unchanged). Counted across den's example templates and a
downstream config with a large den tree, no host-side aspect exclude is
a no-op today that starts working. The 3 host-side excludes found (1 in
the templates, 2 downstream, one of them a `policy.exclude` effect) all
name policy records, which already reached every descendant scope.

### `admits`

A receiver decides what deliveries it takes: `den.schema.<kind>.admits`
and `den.aspects.<name>.admits`, each `{ default; allow; deny; }`.

- The layers are the receiver kind's schema and the receiver's own
aspect. The lists concatenate; `deny` beats `allow`; a `default =
"deny"` in any layer sticks.
- An entry matches the emitting policy by value (the record it
registered from), or an aspect on the policy's origin chain by identity,
so a name can't forge an origin.
- A delivery is a `provide` or `route` with a `receiver`, or a forward
naming a `receiver` anywhere in a policy include's static tree (the
include itself, or nested in `includes` at any depth;
`den.batteries.forward` returns one level). The walk enters each named
aspect once, so a policy including an aspect on an include cycle still
evaluates. It walks each policy include on every firing; the cost is in
the host-evaluation figures below.
- `mutual-provider`'s delivery is matched by the battery: `allow = [
den.batteries.mutual-provider ]` admits what it delivers, by the battery
or its transition default, and `deny` withholds it. That includes the
host-class content of a policy nested inside `provides.to-hosts`, which
#753 makes part of mutual-provider's delivery (#754). The per-user cross
policy that carries `provides.to-hosts` registers with the battery as an
origin record, set at that one registration in den.
- Under `default = "deny"`, a delivery that is neither one of den's
channels nor allowed throws, naming its source and what to allow: ``den:
delivery of `tux/to-hosts` from tux denied on igloo: `admits.default =
"deny"`; to admit it, add `den.batteries.mutual-provider` to
`admits.allow` ``. For an author's delivery the entry named is its
policy, or an aspect it is included through. A denied delivery is
dropped silently, since the receiver asked for that.
- The host-class part of a registrant's own bare include (§11a R7) is
the registrant's content, not a delivery. Den returns it apart from the
policy's own effects, and only the latter go through `admits`; nothing
on a delivery marks it, so an author can't claim the exemption.
- **`user-aspects` is gated whole, not per origin.** Its lifted boundary
is not an effect `admits` sees, so the battery reads the host's layered
`admits` itself when it publishes the acceptance, for the explicit
battery and its transition default alike:
- `deny = [ den.batteries.user-aspects ]` turns the lift off for that
host, so its users' own host-class content stays with them;
- under `default = "deny"`, the battery must be in `allow` (by its
record, `den.batteries.user-aspects`), or den throws: ``den: igloo
includes den.batteries.user-aspects but admits.default = "deny" and it
is not in admits.allow; add it to admits.allow``. Until the transition
ends, that includes the default den adds to every host, so a
default-deny host needs the `allow` or the acknowledgement, and the
message names both: ``den: igloo receives users' content through the
transition default (den.batteries.user-aspects) but admits.default =
"deny"; add den.batteries.user-aspects to admits.allow, or set
den.migrations.user-host-content.acknowledged = true``.

Once the host admits the lift, everything it carries arrives: a
per-origin `deny` inside the lifted content (for example `deny = [
den.batteries.mutual-provider ]` on a host that also lifts user-aspects)
does not filter the provenance-tagged part that arrives through the
lift.
- **Forwards `admits` doesn't see:** a forward written in aspect content
rather than emitted by a policy (`den.aspects.tux.includes = [ ({ host,
user }: den.batteries.forward { …; receiver = host; }) ]`), and a
forward a policy include builds behind a function, which exists only
once it is walked. Both still deliver to their receiver on a
default-deny host. `admits` covers a policy-emitted forward at any depth
of the include's static tree.
- These two limits are the scope of §11a R7 for this release, as amended
by an owner ruling of 2026-11-08: `user-aspects` is gated whole by
`admits`, not per origin, and `admits` covers policy-emitted forwards
only.

**Den's channels always land.** A channel is:
- a policy whose `fn` is defined in one of den's battery files
(`define-user`, `primary-user`, `user-shell`, `unfree`, `insecure`),
found with `builtins.unsafeGetAttrPos`. This names the module that
defines the rule; it does not authenticate the record. A record extended
with `//` keeps its `fn`'s position, so `den.batteries.define-user // {
… }` is still den's channel by design, and copying den's `fn` copies the
channel. A new channel file has to be added to the list in
`children.nix`;
- one of the home-manager, hjem and maid policy records, by value. Each
battery declares its records at its own
`den.internal.channelPolicies.<class>` with an `apply` that ignores
definitions, and den reads only those three keys, so a config can't add
a channel. An integration an author builds with
`den.lib.home-env.makeHomeEnv` shares den's file but not these records,
so it is not a channel and needs an `allow` on a default-deny host;
- `den.policies.user-to-host`, by value.

**Den's own delivery fields are den's.** `__fromProvenance`,
`__standDown`, `__standDownAspect` and `__transitionDefault` (#753's
mutual-provider and stand-down routes) are dropped from the provides and
routes of any policy den didn't make (registered by den's provides
mechanism, or with its `fn` in `home-env.nix`). Measured on #753's code,
an author could set them on its own deliveries only: a `__standDown`
withheld the author's own delivery, and a provenance token moved only
the tagged part of the author's own bucket. Another provider's bucket
was never reachable, because a token is read at the route's own source
scope.

### Den's provides policies claim their name (a bug on `main`, fixed
here)

The policy a `provides.to-hosts` or `provides.<name>` compiles to
(`<owner>/<key>`, for example `tux/to-hosts`) was written straight into
the per-scope policy registry, skipping the claim every other policy
makes. An author policy of the same name and den's provides policy then
overwrote each other, whichever registered last: on `main`, an author
`den.policies."tux/to-hosts"` included on tux replaced mutual-provider's
delivery of tux's `provides.to-hosts`, and included on igloo it was
itself dropped. Both now claim the name through one step
(`aspect/claim.nix`), shared with `registerPolicy`: den's by a value no
author record equals, so the same provider reached again keeps its
identity, and a different same-named record is displaced to its own
identity, as any two same-named policies are. Both fire, in either
order. A denial names the policy as it was written (`tux/to-hosts`), not
the displaced registry key (`tux/tux/to-hosts#1`). Den's claim uses a
value no author record can equal (`{ __denProvides = token; }`), not its
own record, whose closures are rebuilt per walk. That is a precaution:
no cell tells the two apart, because no walk seen re-registers the same
provider at one scope.

### `policyEnforcement` and `den.lib.policy.strict`

Who may exclude a policy instance (§11a O2).
`den.schema.<kind>.policyEnforcement` and
`den.aspects.<name>.policyEnforcement` take `"strict"`, `"per-policy"`
or `"lenient"`. The strictest value any layer sets wins, and with
neither set the mode is `"per-policy"`. `den.lib.policy.strict p` marks
one policy.

Under `"strict"`, or `"per-policy"` with the policy marked strict, only
a registrant may exclude it: the excluding scope's own entity is the
registrant (inherited registrants count), or the policy is registered at
the excluding scope too. A policy on `den.default` is registered on both
sides, so every relatum is a registrant and marking it strict has no
effect. Under `"lenient"` any relatum may exclude, marked or not.
`isPolicyExcluded` keeps its signature; the enforcement-aware form is
`isPolicyInstanceExcluded`.

### Stable identity for anonymous aspects

#753's transition warning compares host-class content across scopes. An
anonymous aspect was known by its position (`<anon>:N`), so the same
aspect included on the host and on its users read as two. The class
collector now records where an anonymous aspect is written
(`unsafeGetAttrPos`) and the warning matches by that position and module
equality. An anonymous function aspect has no attribute position, so it
is still known by its position in the list.

### Cost

`isStructuralKey` used `lib.hasPrefix "__"`, which in the current
nixpkgs goes through a `warnIf` deprecation wrapper on every call. It
now uses `builtins.substring 0 2 k == "__"`. The origin matcher uses
`builtins.substring` for the same reason. The `isStructuralKey` change
also lowers paths `main` already has.

Host evaluation against #753, on the 8 template hosts with a toplevel
drv: function calls −0.026% to +0.021%, thunks +0.020% to +0.088%,
allocation +0.021% to +0.097%.

## Validation

**Bisect evidence for the stack.** `main` gets 7 squash commits, one per
PR (#749, #751, #752, #746, #747, #753, #756). Each PR head is verified:
the five rewritten heads (#752, #746, #747, #753, #756) with the full
local oracle (every suite, templates and `main`'s own templates against
`main`, policy firings, cost), and #749 and #751 published, unchanged
and green in CI. The to-users-nested unfree fixture equals `main` at
every head.

All figures at the PR head, from a clean worktree (the policy-firing
count alone comes from a copy of the head with a trace added to
dispatch).

- Cells: `templates/ci/modules/deadbugs/issue-694-pr4.nix`, 111 cells,
and the exclude grids `issue-694-exclude-exactly.nix` (35) and
`issue-694-exclude-exactly-records.nix` (30). Each piece's cells were
written red before the piece landed, and all are green here. Each
control that is green only because a feature is absent was also shown
red with its enabling entry removed, and each match clause has a mutant
that turns a cell red.
- Suites: c1 112/112, c2 139/139, c3 251/251, c4 44/44, c5 226/226,
deadbugs 998/998, deprecated 5/5, internal 284/284, new 1/1. Two suites
added by #747 run on their own: battery-excludes 11/11 and
import-tree-identity 8/8.
- Templates against `main` (each side its own templates): of the 14
configurations, 9 build and are identical, and the same 5 fail to
evaluate on both sides (diagram-demo alice/devbox/laptop, terranix-demo
web-1/web-2). Option values are identical on 11 of 12 hosts; the
exception is `diagram-demo`'s `devbox` `users`, the `extraGroups`
difference #753 already carries.
- Nothing changes: this PR's den on `main`'s templates against `main` on
`main`'s templates: 9 identical, the same 5 failing on both sides. A
fixture for a shape the templates miss (policies nested in an aspect
delivered through `provides.to-users`, #754) evaluates the same as
`main`.
- Policy firings: against this PR's previous head, 79 fewer across every
suite and template configuration, every one a removed duplicate firing
of the same instance (#752's fix); per policy, scope and bound
arguments, no instance is lost and none added; every drv is identical.
- Against this PR's previous head, before #747's battery-identity fixes:
every policy fires the same number of times (18,692 over all suites and
templates), except the intended battery rename (`unfree-host(vscode)` →
`unfree-host(["vscode"])`). On the 8 template hosts every drv is
unchanged and evaluation adds at most 68 thunks per host.
- A denial shows a policy's name through #747's `withoutStoreHash`, as
#753's warning does. No policy name carries a store path today, so this
is a guard, without a cell of its own.

## Commits

1. `44546e6` feat(#694): origin-matched excludes, receiver admits, and
policy enforcement
2. `79257cb` feat(#694): include.at names the entity a policy's content
attaches to
3. `65e2dd7` fix(#694): transition defaults under origin-matched
excludes
4. `e9537b9` fix(#694): admits knows den's channels by definition and
checks every forward
5. `5b813cd` fix(#694): an exclude names its rule by value, den's
combinators included
6. `fd3f12a` fix(#694): admits decides each delivery an include carries
7. `4f0068c` docs(#694): receiving content: include.at, admits,
policyEnforcement, excludes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

allow-ci allow all CI integration tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant