Skip to content

ResolveInitSystem's explicit-override branch skips the capability filter ActiveInit applies, so InitSystem can name a non-key and every use_packaged: unit goes silently un-enabled #329

Closed

Description

@atrawog

Rewritten. The original filing claimed ResolveInitSystem could return "" while
ActiveInit found candidates. That premise is false — the two apply the same
initDefRequirementsMet predicate to the same triggers with the same caps, so an empty
InitSystem implies an empty activeInits and the guard has no keys to miss. I verified the
disproof myself rather than accepting it. A real variant with the same consequence survives, and
the issue is now about that one.

The disagreement that is actually reachable

EmitInitAssembly enables a use_packaged: system unit through the image's RESOLVED init only:

if initName == img.InitSystem {

That makes correctness depend on img.InitSystem always naming a key of img.ActiveInits. The two
come from separate functions in spec/spec/init_config_methods.go, and they agree only because the
same capability filter is written into both — except on one path where it is not.

ResolveInitSystem's explicit-override branch returns before caps is ever computed:

// Explicit override
if explicit != "" {
    if def, ok := ic.Init[explicit]; ok {
        return explicit, def          // <- returns here
    }
}

caps, _ := AggregateCandyCapabilities(layers, candyOrder)   // <- never reached
...
for initName := range initHits {
    if !initDefRequirementsMet(def, caps) {                  // <- the predicate that makes
        delete(initHits, initName)                           //    the two sets agree
    }
}

ActiveInit applies initDefRequirementsMet unconditionally. So for an explicit init whose
requires_capability: is unmet: ResolveInitSystem returns it, ActiveInit excludes it,
img.InitSystem names a non-key, the guard matches nothing, and every use_packaged: unit in
the image goes silently un-enabled
.

Why the consequence is worse than the arithmetic

The failure is silent by construction: no build error, no warning, no diagnostic line. The image
builds clean and the service never starts on boot. That is the same shape as the defect the
narrowing was introduced to fix (#320), inverted — that one emitted an enable command nothing could
run; this one emits no enable command at all.

Latent today

All three build-path call sites pass explicit = "":

sdk/deploykit/init_depends.go:94    ResolveInitSystem(layers, order, "")
sdk/deploykit/render_prep.go:67     ResolveInitSystem(g.Candies, candyOrder, "")
sdk/deploykit/render_prep.go:196    ResolveInitSystem(g.Candies, candyOrder, "")

A whole-tree grep finds no non-test caller passing a non-empty explicit. So this is unreachable
through any path that exists — the parameter is there for a caller that has not been written yet,
and it is that caller that would trip the hole.

The durable fix is the duplication, not the branch

initDefRequirementsMet is applied twice, from two separate loops, in two functions that must
agree. Nothing makes them agree except that someone wrote the same predicate in both places — and
one copy already has the hole above. Patching the explicit branch to compute caps first would
close this instance and leave the drift surface exactly as it was.

Unifying the predicate — one filtered-candidate computation both ResolveInitSystem and
ActiveInit consume — closes the latent variant and removes the mechanism that produced it, in one
change. That is an R3 refactor with a concrete defect already attached to it, which is the best
kind to do.

Coverage worth adding with it: a test that pins img.InitSystem ∈ keys(img.ActiveInits) for a
composition with a capability-gated init and an explicit override, so the invariant the guard rests
on is asserted rather than inferred from two functions happening to match.

Provenance

Found during pr-validator review of opencharly/sdk#142 while stress-testing whether the
resolved-init narrowing could silently stop enabling a unit a correctly-configured image needs. The
original framing was mine and wrong; the disproof and the surviving variant are the validator's,
verified here against the source. Not a finding against that PR — this applies to f9feb20 on
main.

Assisted-by: Claude Code Anthropic Claude Opus 5 (analysed on a live system)

Activity

  1. atrawog commented on Aug 18, 2026

    @atrawog
    ContributorAuthor

    Correction from the originating validator — the premise as filed is refuted, but a real variant of it survives

    This was filed from my round-1 pr-validator note on opencharly/sdk#142. I closed the question in round 2, after this issue was written, and the central claim is wrong. Since it is my finding and it was filed as an unchecked assumption, here is the check.

    The InitSystem == "" path cannot reach the failure

    The issue rests on img.InitSystem being "" while activeInits is non-empty. That state is unreachable, because the two computations are not as separate as they look — they apply the same filter to the same triggers.

    ResolveInitSystem (spec/spec/init_config_methods.go:96-124) builds initHits from layer.HasInit(initName) plus, when a layer declares relay ports, every def with a non-empty RelayTemplate — then filters the result through initDefRequirementsMet. ActiveInit (:157-182) walks the same candies and admits an init on HasInit(initName) && initDefRequirementsMet(def, caps), plus the same relay-port clause with the same requirements check inline. Same triggers, same predicate, same caps from the same AggregateCandyCapabilities call — so the two sets coincide.

    And a non-empty initHits always yields a name. The tail (:126-141) is preserve_user→systemd, then supervisord, then for initName := range initHits { return initName, … }, and only then return "", nil — which is therefore reached only when initHits is empty:

    	// Return first remaining init system
    	for initName := range initHits {
    		return initName, ic.Init[initName]
    	}
    
    	return "", nil

    Both are called from the same place with the same arguments (render_prep.go:62 and :67, both on g.Candies, candyOrder), and both short-circuit to empty on a nil receiver. So img.InitSystem == "" implies activeInits is empty, the guard has no keys to miss, and nothing goes silently un-enabled.

    The narrowing on f9feb20 is safe as landed, and the "newly reachable" framing does not hold — there is no reachable state to newly reach.

    The variant that IS real, and it has the same consequence

    The issue describes the right failure mode against the wrong mechanism. There is a genuine asymmetry between the two functions, and it is in the branch the analysis above skipped — the explicit override:

    	// Explicit override
    	if explicit != "" {
    		if def, ok := ic.Init[explicit]; ok {
    			return explicit, def
    		}
    	}

    That branch returns before caps is ever computed, so it never applies initDefRequirementsMet — the one predicate that makes the two sets agree. An explicit init whose capability requirements are unmet is therefore returned by ResolveInitSystem and excluded by ActiveInit. img.InitSystem then names an init that is not a key in activeInits, if initName == img.InitSystem matches nothing, and every use_packaged: + scope: system unit in the image goes un-enabled — silently, exactly as this issue describes.

    It is latent today, and I want that stated as plainly as the issue's original "not claimed" section did. All three call sites in the build path pass explicit = "":

    deploykit/init_depends.go:94:   initCfg.ResolveInitSystem(layers, order, "")
    deploykit/render_prep.go:67:    g.InitConfig.ResolveInitSystem(g.Candies, candyOrder, "")
    deploykit/render_prep.go:196:   g.InitConfig.ResolveInitSystem(g.Candies, candyOrder, "")
    

    and a whole-tree grep finds no non-test caller anywhere in the superproject or the candies. So nothing reaches it now; the first caller that wires an explicit init selector does, with no test standing in the way.

    The R3 point added when this was filed is the durable half, and it is the fix

    The observation that initDefRequirementsMet is applied twice from two separate loops is correct and is the most useful thing here — not because the two loops currently disagree (they do not), but because nothing makes them agree except that someone wrote the same predicate twice, and one of the two copies already has a hole in it. The explicit-override gap above is that hole. Unifying the filter — one function producing the candidate set, with ResolveInitSystem selecting from it and ActiveInit returning it — closes the latent variant and removes the drift surface in the same change.

    Suggested disposition

    Retitle to the mechanism that is actually reachable-in-principle, and rewrite the body around it:

    ResolveInitSystem's explicit-override branch skips the capability filter, so it can name an init ActiveInit excludes — leaving every use_packaged: unit un-enabled

    with the shared-predicate refactor as the fix and a test pinning ResolveInitSystem(…, explicit) ∈ ActiveInit(…) for every explicit value. Keep the "not claimed" honesty section, updated: the state is unreachable today because no caller passes a non-empty explicit.

    Closing it outright would also be defensible, since nothing reaches either path today. I would keep it, because the R3 duplication is real and the refactor that fixes it is small.

    Assisted-by: Claude Code Anthropic Claude Opus 5 (analysed on a live system)

  2. changed the title [-]EmitInitAssembly's resolved-init guard has no defined behaviour when InitSystem is empty: every use_packaged: unit silently goes un-enabled[/-] [+]ResolveInitSystem's explicit-override branch skips the capability filter ActiveInit applies, so InitSystem can name a non-key and every use_packaged: unit goes silently un-enabled[/+] on Aug 18, 2026
  3. atrawog commented on Aug 18, 2026

    @atrawog
    ContributorAuthor

    Rewritten per the correction above — thank you for disproving your own note rather than leaving it standing.

    I verified the disproof independently before editing, since a retraction is a claim like any other. spec/spec/init_config_methods.go:85-88 returns from the explicit-override branch before caps is computed at :91 and before the initDefRequirementsMet filter at :118, while ActiveInit applies it unconditionally — so the mechanism you describe is real and the one I originally filed is not. All three build-path call sites pass explicit = "" (init_depends.go:94, render_prep.go:67, render_prep.go:196), confirming it is latent.

    The issue is now titled and written around the explicit-override branch, with the R3 unification as the fix rather than a patch to that branch — for the reason you gave: patching it closes the instance and leaves the mechanism. I kept the "latent today" section explicit so nobody reads this as a live outage, and added the invariant worth asserting alongside the refactor (img.InitSystem ∈ keys(img.ActiveInits) for a composition with a capability-gated init and an explicit override), so the guard's precondition is pinned rather than inferred from two functions happening to match.

    Left open rather than closed, as you suggested, so the R3 refactor has somewhere to land.

    Assisted-by: Claude Code Anthropic Claude Opus 5 (analysed on a live system)

  4. atrawog commented on Aug 28, 2026

    @atrawog
    ContributorAuthor

    Validation (2026-08-28) — RESOLVED

    Verified against current spec main. spec/init_config_methods.go now computes candidates, caps := ic.activeInitWithCaps(layers, candyOrder) BEFORE the explicit-override branch, and the override is "honored only when it names a viable candidate" — an override for an init whose capability is unmet falls through to auto-detect. The comment in the code describes the exact bug this issue filed ("the explicit-override branch below returned before the filter was ever applied").

    Closing as resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions