ReactiveBayes / ReactiveBayes/ExponentialFamilyProjection.jl
[MEDIUM] `ClosedFormStrategy` closure extraction grabs the first captured field with no type validation (silent wrong target)
Nobody has claimed this yet.
- Dominant language
- Julia
- Stars
- 11
- Forks
- 1
- PR merge metrics
- No merged PRs in 30d
Description
[MEDIUM] ClosedFormStrategy closure extraction grabs the first captured field with no type validation (silent wrong target)
Summary
ext/ClosedFormExpectationsExt/ClosedFormExpectationsExt.jl:150-154:
field_names = fieldnames(F)
if isempty(field_names)
error(...)
end
captured = getfield(argument, first(field_names))
return (strategy, Logpdf(captured))
When RxInfer-style closures capture more than one variable, the code silently takes the first captured field and wraps it in Logpdf, with no validation that it is a Distribution/ProductOf. This can silently project the wrong target distribution (or even a non-distribution), producing an incorrect exponential-family member with no error.
Evidence (Julia 1.12.6, ClosedFormExpectations 0.4.1)
let a = 5, d = Normal(0,1); fn = (x) -> logpdf(d,x) + a; preprocess_strategy_argument(ClosedFormStrategy(), fn)returnsarg.dist == 5(the scalara), notd.- With two captured distributions
(a = Gamma(3,3), d = Normal(0,1)), it returnsarg.dist == Gamma(3,3)(the first captured), not the intendedNormal.
The check isempty(field_names) only guards against zero captured variables; it does not ensure the captured value is the intended target.
Impact
Silent-wrong-inference class bug (produces a wrong distribution without failing). Trigger is narrow (multi-variable closures), but the failure mode is silent.
Suggested fix
After extraction, assert the captured value is a Distribution or ProductOf (and, if the closure has more than one field, either error or attempt to locate the distribution field). At minimum, captured isa Union{Distribution,ProductOf} || error(...).
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at ext/ClosedFormExpectationsExt/ClosedFormExpectationsExt.jl:150-154 and inspect how preprocess_strategy_argument handles captured closure fields. Reproduce the multi-variable closure examples from the issue, then ensure an invalid captured value is rejected rather than silently wrapped; done means the reported wrong-target cases no longer return a scalar or unintended distribution.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- julia
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 76/100