Skip to content

fix: sibling policy.when guard dedup collision; spawn subtree routes; multi-def forwarded identity - #603

Merged
sini merged 4 commits into
denful:mainfrom
sini:fix/sibling-when-guard-dedup
Jun 10, 2026
Merged

sini merged 4 commits into
denful:mainfrom
sini:fix/sibling-when-guard-dedup

Conversation

@sini

@sini sini commented Jun 10, 2026 •

Copy link
Copy Markdown
Collaborator

Three pipeline fixes plus a shared-helper cleanup, each fix with a deadbugs regression test. Full CI: 879/879.

fix: sibling policy.when guards no longer collide at the dedup gate

Two policy.when includes in the same aspect both compile to conditional aspects named <when>, and compile-conditional emitted passing payloads without joining the includes chain. Both anonymous payloads resolved to the same identity (<parent>/<anon>:0), so the gate's dedup silently dropped the second guard's content — first guard's settings landed, second's vanished.

Fix is two coordinated changes:

  • children.nix: synthetic-named children (<...>) now get indexed names like anonymous children do (aspect3/<when>:0, aspect3/<when>:1).
  • compile-conditional.nix: payload emission chain-pushes the conditional's identity (immediate and drain paths), so payloads nest under their guard (aspect3/<when>:0/<anon>:0) instead of colliding at the shared parent. Side benefit: constraint ownerChain now attributes guard-emitted aspects to their conditional.

fix(spawn): apply parent subtree routes in spawned resolution

A policy.route registered at a user scope in the main pipeline (e.g. homeLinux→homeManager from den.schema.user.includes) never applied to the spawned per-user resolution: the spawn re-emits host-aspect class content at the same scope ids but only applied its own walk's routes, stranding routed-class content in its source class. Thread the parent pipeline's scopedRoutes into the spawn and apply the subtree-relevant ones in phase3, deduping against the spawn's own registrations.

fix(types): tag multi-def forwarded children with __provider

aspectContentType's multi-def branch forwarded colliding-key children raw — no name, no __provider — so a navigated aspect under a multi-def namespace lost its identity and was renamed <parent>/<anon>:<idx> per inclusion path. The same aspect included via two roles then double-emitted, producing equal-priority option conflicts in home-manager. Annotate forwarded children recursively, mirroring the single-def path.

refactor: share one-definition helpers

Post-review cleanup of duplication the fixes introduced or exposed — no behavior change:

  • isSyntheticName hoisted next to isMeaningfulName and shared by child naming and gate dedup (the two sites must agree or naming and dedup silently desync).
  • chainWrap moved into the aspect module; resolve-children and compile-conditional both use it.
  • Canonical routeKey lives in the register-route handler; the spawn-node merge imports it instead of duplicating the formula.
  • Repeated provider-path / spawn-route expressions bound once; comments tightened.

Tests

  • deadbugs/policy-when-hasaspect-pair.nix — both sibling guards' settings land
  • deadbugs/route-platform-class-host-aspect.nix — user-scope route applies in spawned resolution
  • deadbugs/multi-def-namespace-identity.nix — multi-def namespace child keeps identity, no double emission

All three tests verified to fail on main and pass on this branch.

sini added 3 commits June 9, 2026 23:13
Both policy.when conditionals compile to aspects named <when>, and
compile-conditional emitted passing payloads without joining the
includes chain — two sibling guards' anonymous payloads both resolved
to <parent>/<anon>:0 and the gate silently dropped the second. Index
synthetic-named children and chain-push the conditional around payload
emission so each guard's payload gets a distinct identity.
A policy.route registered at a user scope in the main pipeline (e.g.
homeLinux->homeManager from den.schema.user.includes) never applied to
the spawned per-user resolution: the spawn re-emits host-aspect class
content at the same scope ids, but only applied its own walk's routes,
so routed-class content stranded in its source class and silently
dropped. Thread the parent pipeline's scopedRoutes into the spawn and
apply the subtree-relevant ones in phase3, deduping against the spawn's
own registrations by route key.
aspectContentType's multi-def branch tagged the colliding key but
forwarded its children raw — no name, no __provider — so a navigated
aspect under a multi-def namespace (apps.dev.security.gpg when gpg.nix
and ssh.nix both define apps.dev.security.*) lost its identity and was
renamed <parent>/<anon>:<idx> per inclusion path. The same aspect
included via two roles then double-emitted: equal-priority option
conflicts in the user's home-manager config. Annotate subForwarded
children recursively, mirroring the single-def annotatedMerged path;
name-based guards run before the isAttrs force (denful#580 discipline).
@sini
sini requested a review from vic as a code owner June 10, 2026 06:14
@github-actions github-actions Bot added the allow-ci allow all CI integration tests label Jun 10, 2026
Hoist isSyntheticName next to isMeaningfulName (naming and gate dedup
must agree), chainWrap into the aspect module (resolve-children and
compile-conditional shared inline copies), and routeKey into the
register-route handler (spawn merge duplicated the formula). Bind
repeated provider-path and spawn-route expressions once; tighten
oversized comments.
@sini
sini requested a review from fmway June 10, 2026 06:28
@sini
sini enabled auto-merge (squash) June 10, 2026 06:33
@sini
sini merged commit 41aa255 into denful:main Jun 10, 2026
18 of 29 checks passed
sini added a commit to sini/den that referenced this pull request Jun 10, 2026
The `self` dispatch guard (fire-once at the registration scope; always bound
in ctx so flake-scope resolution policies can fire) was added on this branch
but never made it into origin/main's squash of the cherry-picked fixes — denful#603
covered spawn subtree routes and multi-def identity, not `self`. Rebasing onto
origin/main therefore silently dropped it.

Without `self`, `{ self, ... }:` policies never dispatch (flake isn't bound in
its own ctx), collapsing any flake-scope resolution cascade — e.g. a consumer's
flake -> fleet -> environment -> host walk produces zero host outputs.

Re-applies the dispatch.nix `self` injection and the policy/schema.nix
late-fan-out exclusion, plus the self-guard regression test.
sini added a commit to sini/den that referenced this pull request Jun 12, 2026
The `self` dispatch guard (fire-once at the registration scope; always bound
in ctx so flake-scope resolution policies can fire) was added on this branch
but never made it into origin/main's squash of the cherry-picked fixes — denful#603
covered spawn subtree routes and multi-def identity, not `self`. Rebasing onto
origin/main therefore silently dropped it.

Without `self`, `{ self, ... }:` policies never dispatch (flake isn't bound in
its own ctx), collapsing any flake-scope resolution cascade — e.g. a consumer's
flake -> fleet -> environment -> host walk produces zero host outputs.

Re-applies the dispatch.nix `self` injection and the policy/schema.nix
late-fan-out exclusion, plus the self-guard regression test.
sini added a commit to sini/den that referenced this pull request Jun 13, 2026
The `self` dispatch guard (fire-once at the registration scope; always bound
in ctx so flake-scope resolution policies can fire) was added on this branch
but never made it into origin/main's squash of the cherry-picked fixes — denful#603
covered spawn subtree routes and multi-def identity, not `self`. Rebasing onto
origin/main therefore silently dropped it.

Without `self`, `{ self, ... }:` policies never dispatch (flake isn't bound in
its own ctx), collapsing any flake-scope resolution cascade — e.g. a consumer's
flake -> fleet -> environment -> host walk produces zero host outputs.

Re-applies the dispatch.nix `self` injection and the policy/schema.nix
late-fan-out exclusion, plus the self-guard regression test.
sini added a commit that referenced this pull request Jul 31, 2026
Two custom forward classes chained (`inner` -> `mid` -> `homeManager`)
collide on the inner hop:

  The option `home-manager.users.<u>.den.fwd."inner/mid/<path>"'
  is already declared

Same #603 cause as the direct case, one hop removed. The inner adapter
declares into the `mid` bucket, which the second hop nests into the
target, so the declaration arrives indirectly. Suppressing the parent's
copy in the spawn does not help here: the spawn's OWN walk registers the
inner forward too, and `spawnKeys` gave the spawn's copy precedence over
the parent's, leaving one producer on each side.

Flip the precedence for declaration-bearing routes only. A declaring
route is dropped from `freshParent` always, and additionally from
`spawnHere` when the parent registered the same identity at that scope,
so the parent is the sole owner. A declaration only the spawn registers
still stands — there is no competing producer for it.

Matching by route identity rather than `intoClass == class` is what
catches the indirect hop; a target-class test would miss it.

Three cases: user-defined, host-defined (the projection this must not
strand), and a no-battery control.
sini added a commit that referenced this pull request Jul 31, 2026
A `homeManager` class module requesting `user` was silently dropped on any
standalone home whose user could not be resolved from a DECLARED host — a
bare `den.homes.<sys>.tux`, or `tux@astra` where `astra` is undeclared.
No error and no warning: `wrapFunctionModule` puts the module on the
`missingDenArgNames` path, and the `lib.warn` it attaches rides on the
discarded module, so it is never forced.

home.nix bound `user` only via `den.hosts.<host>.users.<user>`. The schema
DAG offers no fallback either — `user.parent` and `home.parent` are both
`host`, making `user` a SIBLING of `home`, so #634's descendant fan-out
does not reach it. But a standalone home always names its user, so bind it
from the home itself; a declared host still wins and keeps the full record.

The synthetic user is identity-only and, like the synthetic host, carries
no `class`. That is what keeps OS batteries inert, which is the reason
`user` was left null when the synthetic host was introduced. Two supports
for that gate:

- `user-to-host` now gates on `host ? class`, matching `os-to-host`,
  `hostname`, `unfree` and `insecure`. It read `host.class` unguarded and
  only ever escaped because `user` was absent from a standalone home's ctx.
- the synthetic host carries `system`, which the home knows for certain and
  which host-keyed content needs for platform-dependent values (define-user's
  home directory).

`standalone-homes.test-home-standalone-without-existing-host` asserted the
superseded contract (`user = null`, host without `system`) and is updated.
Its `keyboard.model = "standalone"` is unchanged, which is the evidence
`osConfig` is still not wired and OS routing still does not fire.

Pre-existing, not a #603 regression. Fixes #640.
sini added a commit that referenced this pull request Jul 31, 2026
…#643)

Fixes #642, #644, #645, #640.

The first three are regressions from 41aa255 (#603) in how custom
`_.forward` classes are delivered; #640 is a pre-existing
standalone-home defect. They share a shape — content or a declaration
goes missing with nothing said about it — but four distinct mechanisms,
so four commits.

## 1. Duplicate adapter declaration with `host-aspects` (#642) —
`a2dbe027`

A custom class built with `_.forward` fails to evaluate as soon as the
`host-aspects` battery is also included:

```
The option `home-manager.users.<u>.den.fwd."<from>/<into>/<path>"'
is already declared in `…/flake.nix'.
```

`_.forward` with a guard compiles to a `__complexForward` route whose
materialization (`applyComplexRouteEdge` → `buildForwardAspect` →
`mkAdapterAspect`) emits a functor that **declares**
`options.den.fwd.<adapterKey>`. #603 made a spawned node also apply the
parent pipeline's subtree routes — right for simple routes, since that
is what makes a user-schema `homeLinux→homeManager` route fire against
re-emitted content, but not for adapter-bearing ones. The parent already
materializes the same route at the same scope and both folds land in one
home-manager evaluation. Content *definitions* merge; a duplicated
option *declaration* is a hard error.

Tagging each emitted adapter module's `_file` with
`sourceScopeId|foldRoot` named both producers:

```
in `…:host=igloo,…,user=tux|host=igloo,…,user=tux'            ← host-aspects spawn fold
is already declared in
   `…:host=igloo,…,user=tux|host=igloo,system=x86_64-linux'   ← host pipeline fold
```

Declaration-bearing parent routes are excluded from the spawn's route
merge, leaving the parent's copy as the single owner. It is always there
to take over: an excluded route is by construction inside the spawned
subtree, and the redundant-root suppression only fires on a route *at*
the fold root. Testing `__complexForward` before `adapterKey` is
load-bearing — every complex forward carries an `adapterKey`, so a bare
`adapterKey != null` test would also have excluded non-declaring
forwards, including the home-manager battery's own delivery route.

## 2. Same collision one hop out, on chained classes (#645) — `14d07a1f`

`inner → mid → homeManager` collides on `den.fwd."inner/mid/…"`. The
inner adapter declares into the `mid` bucket, which the second hop nests
into the target, so the declaration arrives indirectly. Suppressing the
parent's copy does not help: the spawn's own walk registers the inner
forward too, and `spawnKeys` gave the *spawn* precedence — one producer
left on each side.

Precedence is now flipped for declaring routes only: dropped from
`freshParent` always, and from `spawnHere` when the parent registered
the same identity at that scope. A declaration only the spawn registers
still stands. Matching on route identity rather than `intoClass ==
class` is what catches the indirect hop.

## 3. Per-user host content leaking across users (#644) — `71ff2b47`

No error, just a wrong configuration:

```
expected { pinguSees = ["pingu"];       tuxSees = ["tux"]; }
actual   { pinguSees = ["pingu" "tux"]; tuxSees = ["pingu" "tux"]; }
```

`bind`'s descendant-arg fan-out emits every instance at the *emitting*
scope, distinguished only by the `@<kind>=<name>` pairs in each
identity's `{ctxId}`. The host bucket therefore legitimately holds one
instance per user:

```
myshell@per-user/<anon>:0/{per-user/<anon>:0@user=pingu}
myshell@per-user/<anon>:0/{per-user/<anon>:0@user=tux}
```

`filterRootModules` handed that bucket to every child-scope forward
whole, narrowing only by class ownership, never by binding — so each
user collected the union. Root modules are now filtered by the bindings
their identity carries: a module naming an entity the child's ctx also
names must name the same one. Bindings for a kind the child has no
record of cannot disqualify it, and unfanned content binds nothing, so
shared host content still reaches every user. `ctxBindings` sits beside
`stripCtxSuffix`, which already reads this suffix; the binding survives
nowhere else by the time routes fold, since a wrapped NixOS module
cannot carry extra attributes.

Reproduces with **no** `host-aspects` battery and therefore no spawn at
all, which is what places it in the parent pipeline's source collection
rather than anywhere the other two fixes touch.

## 4. `{ user, ... }` dropped on standalone homes (#640) — `8f07b0c5`

Pre-existing, not a #603 regression. A `homeManager` class module
requesting `user` vanished on any standalone home whose user could not
be resolved from a *declared* host — a bare `den.homes.<sys>.tux`, or
`tux@astra` with `astra` undeclared. Silent for the same reason as the
others: `wrapFunctionModule` returns `unsatisfied = true` and the
`lib.warn` it attaches rides on the discarded module, so it is never
forced.

The schema DAG offers no fallback — `user.parent` and `home.parent` are
both `host`, making `user` a *sibling* of `home`, so #634's descendant
fan-out does not reach it. But a standalone home always names its user,
so it is bound from the home itself; a declared host still wins and
keeps the full record.

The synthetic user is identity-only and carries no `class`, which is
what keeps OS batteries inert — the reason `user` was deliberately left
null when the synthetic host was introduced. Two supports for that gate:

- `user-to-host` now gates on `host ? class`, matching `os-to-host`,
`hostname`, `unfree` and `insecure`. It read `host.class` unguarded and
only ever escaped because `user` was absent from a standalone home's
ctx.
- the synthetic host carries `system`, which the home knows for certain
and which host-keyed content needs for platform-dependent values
(define-user's home directory).

`standalone-homes.test-home-standalone-without-existing-host` asserted
the superseded contract (`user = null`, host without `system`) and is
updated. Its `keyboard.model = "standalone"` is unchanged — that is the
evidence `osConfig` is still not wired and OS routing still does not
fire.

## Tests

Fourteen cases across four deadbug files, each red before its fix and
green here:

| file | cases |
|---|---|
| `issue-642-host-aspects-custom-class.nix` | user-defined,
host-defined, host-defined across two users, no-battery control |
| `issue-645-chained-forward-classes.nix` | with battery, host-defined,
no-battery control |
| `issue-644-parametric-host-forward-per-user.nix` | no battery, with
battery, static-content sharing control |
| `issue-640-standalone-home-user-arg.nix` | bare home, synthetic host,
declared-host control, `{ home, … }` control |

Every fix ships a control for the failure it could itself cause —
stranding projected content (#642, #645), breaking legitimate
host-content sharing (#644), or disturbing the declared-host path
(#640).

Full CI: `1079/1079`, 0 failures, 0 eval errors. `just fmt` clean.
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.

2 participants