You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
conveyor-engine: expand_conveyors panics (unwrap) on duplicate canonical flow idents where a later flow carries the leak #870
Found by branch review of conveyor-engine before merge (the in-flight XMILE conveyor+queue implementation; specs docs/design/conveyors.md + docs/design/queues.md). Filed from a review report that exceeded its 15-finding cap.
Summary
expand_conveyors decides a conveyor outflow is a leak with flow_is_leak -- an .any() that is true if any same-canonical flow carries leakage -- then fetches the flow with find_map, which returns the first same-canonical flow, and unwraps its .compat.leakage. When two flows canonicalize to the same ident and only a later one carries <leak/>, the unwrap runs on the first (leakage = None) flow and panics. Under libsimlin's panic=abort this aborts the host process.
Failure scenario
An XMILE model with a conveyor stock listing outflow Attrition plus two flows whose names canonicalize identically -- <flow name="Attrition"> (no <leak/>) appearing before <flow name="attrition"><leak/> ...>. flow_is_leak("attrition") is true (the second flow has leakage), so the leak branch runs; find_map returns the first flow (Attrition, leakage = None) because variables are stable-sorted in document order; f.compat.leakage.as_ref().unwrap() panics.
This is reached via simlin_sim_new -> queue_compile::build_compiled -> expand_conveyors, before any duplicate-ident validation (which lives in the bypassed salsa path). Canonicalization also collapses whitespace/underscore, so an accidental net flow / net_flow leak-vs-nonleak pair triggers it too.
Evidence
flow_is_leak: model.variables.iter().any(|v| match v { datamodel::Variable::Flow(f) => canon(&f.ident) == flow && f.compat.leakage.is_some(), _ => false }) (src/simlin-engine/src/conveyor_compile.rs:546-549)
find_map takes the first same-canon flow: let flow_var = model.variables.iter().find_map(|vv| match vv { datamodel::Variable::Flow(f) if canon(&f.ident) == out_c => Some(f), _ => None }); (src/simlin-engine/src/conveyor_compile.rs:643-646)
the unwrap: let lk = f.compat.leakage.as_ref().unwrap(); (src/simlin-engine/src/conveyor_compile.rs:649)
XMILE reader does not dedup and stable-sorts by canonical ident: xmile/model.rs:542-564
production reach under if has_conveyor || has_queue: src/libsimlin/src/simulation.rs:75-79 -> queue_compile.rs:832
Suggested direction
Select the leak flow with the same find_map/any predicate (canon match AND leakage.is_some()) so the fetched flow is guaranteed to be the one that made flow_is_leak true, and return an ErrorCode rather than unwrapping if no such flow exists.
Activity
engine: reject duplicate canonical variable idents at compile time
engine: reject duplicate canonical variable idents at compile time