Reason from proven invariants before coding. Use when reviewing fallback logic, narrowing types, handling conversions, deciding whether an error path is real or impossible, removing overdefensive code, or when the user questions whether code is being too theatrical, too hedged, or not fail-closed enough.
Write code that matches the real system.
If a system invariant already proves a condition, encode that invariant directly. Do not add fallback branches, saturation logic, or “safe-looking” defaults just to appear careful.
This skill is about coding and review discipline, not architecture or testing in isolation.
Before writing or approving a branch, ask:
If the branch exists only because a conversion is typed as fallible, or because the author felt nervous, that branch is probably theater.
Common examples:
try_from(...).unwrap_or(MAX) when the value is already tightly boundedunwrap_or(false) after I/O or parsing where failure should be surfacedThe problem is not style. The problem is lying about the system.
Every suspicious branch is one of three things:
The case can happen during correct operation.
Examples:
Handle it as part of the interface contract.
The case should be impossible if the surrounding system is correct.
Examples:
Do not paper over this with fallback behavior. Assert it, crash fast, or return an explicit internal error, depending on the layer.
The language forces a fallible conversion or optional path, but the domain has already ruled failure out.
Examples:
u32::try_from(count) where count <= 253 by invariantPrefer code that states the invariant plainly instead of pretending the conversion is meaningfully uncertain.
If the value is naturally bounded, choose a type that encodes the bound.
Bad:
let slots = u32::try_from(count).unwrap_or(u32::MAX);Better:
let slots = u32::try_from(count)
.expect("per-host slot count must fit in u32");Best, if practical:
struct HostSlotCount(u16);The goal is to make invalid states unrepresentable or at least explicit.
If a condition is impossible by invariant, say so.
Bad:
let count = u32::try_from(value).unwrap_or(u32::MAX);Good:
let count = u32::try_from(value)
.expect("workspace count must fit in u32");Use:
debug_assert! when the check is only for programmer sanity in developmentassert! / expect when startup or internal corruption should abortIf the case can happen normally, model it.
Bad:
let enabled = env::var("FEATURE").ok().unwrap_or("false".into()) == "true";Good:
let raw = env::var("FEATURE").map_err(ConfigError::MissingFeatureFlag)?;
let enabled = parse_feature_flag(&raw)?;If an old branch no longer represents a real mode, delete it.
Bad:
if canUsePrimary() {
return primary()
}
return fallback()Good:
if !canUsePrimary() {
return ErrPrimaryUnavailable
}
return primary()Or, if the primary is the only supported mode:
return primary()At an API boundary:
Inside a daemon or service:
During startup:
Startup is one of the few legitimate places for hard assertions.
Use this checklist when you see defensive-looking code:
TryFrom + explicit assertion when the invariant proves the bound.unwrap_or, unwrap_or_default, and saturating math used to mask impossible states.Example:
fn u32_from_host_slot_count(value: usize) -> u32 {
u32::try_from(value).expect("per-host slot count must fit in u32")
}panic-free internal error returns for impossible service states if the process must stay alive.Code that exists only to make the author feel prudent:
catch / match _ behavior that erases failure modesIf the interface promises strong semantics, do not quietly weaken them in the implementation.
Comments like:
without stating the actual invariant are a red flag.
State the invariant, or redesign the code.
These former standalone skills are bundled here as references to keep the runtime list compact. Load only the reference that matches the user's exact product, framework, or failure mode.
| Former skill | Reference | Description |
|---|---|---|
dedalus-invariant-first-coding | references/skills/dedalus-invariant-first-coding/SKILL.md | Reason from proven invariants before coding. Use when reviewing fallback logic, narrowing types, handling conversions, deciding whether an error path is real or impossible, removing overdefensive code, or when the user questions whether code is being too theatrical, too hedged, or not fail-closed enough. |