Add :compact-aware Base.show methods for callback events and supporting types#602
Conversation
Helpers keep the single-line event repr compact (first 4 hex chars +
ellipsis) while remaining greppable across matching Before/After pairs;
the long-form variant prints the full UUID for MIME("text/plain") show
methods that follow.
Renders MessageMapping as a single-line summary:
`MessageMapping(NormalMeanVariance, :out, msgs=[:mu, :tau])` so trace
events that carry a mapping field stop dumping its full struct contents.
The names tuples are stored as `Val{(...)}()` for type stability;
extract via a small internal helper.
Single-line summary that surfaces the two distinguishing knobs (form constraint check strategy and fold direction) instead of dumping every default kwarg, which dominated the trace output for product events.
Default repr is now `AnnotationDict(n=K)` so the trace logger does not inline annotation values that may themselves be large distributions. Full key/value listing moves to `show(io, MIME"text/plain", ann)` for interactive debugging. Test updated to assert both forms.
Renders as `CheckEach` and `CheckLast` instead of the fully-qualified type name, so MessageProductContext.show stays compact in trace output.
Renders mapping inline (now that MessageMapping has its own show), counts messages / marginals tuples instead of dumping them, and truncates the span identifier to the first 4 hex chars so the matching Before/After pair stays visually correlatable in compact log output.
Surfaces the variable label, the two factor messages being multiplied, and (for the After variant) the result distribution + annotation count, joined to its Before partner via the truncated span identifier.
Replaces the full-tuple dump of messages with a count and surfaces only the variable label, message count, and (for After) the resulting message plus the span id linking it back to the Before event.
Compact one-line summary listing the variable label, the constraint check strategy (rendered via the new short FormConstraintCheck shows), the input distribution, and (After only) the constrained result.
Final Tier B event: variable label, message count and (After only) the computed marginal, joined to its Before partner via the span identifier. With this in place every `Event` subtype defined in callbacks.jl has a compact, single-line representation suitable for trace-logger output.
Locks down the new compact `Base.show` output for every Before/After
event pair plus the supporting types they render (MessageMapping,
MessageProductContext, FormConstraintCheck variants). Includes a
regression guard that fails if a future change reintroduces the raw
struct dump shape (`MessageMapping{` or `Event{` braces) that issue
#599 / RxInfer.jl#638 set out to remove. Also covers the `nothing`
span_id path so disabled callbacks do not panic.
Records the user-visible behavior change for the upcoming 6.x release: trace-logger output for callback events is now compact and structured instead of dumping raw struct contents, and AnnotationDict's compact form drops inline values in favour of a count.
Captures the design rationale (which package, which events, format conventions, sequencing options) that produced the Base.show methods landing in this branch. Kept alongside the code so the trade-offs behind compact-vs-MIME-form choices stay discoverable for the eventual RxInfer-side cleanup PR.
Drop the local _message_mapping_names helper in favor of the existing
src/helpers/helpers.jl unval, which has the same Val{S} unwrapping
semantics and is already used by the annotation input-arguments code.
Rework all event Base.show methods plus their supporting types (MessageMapping, MessageProductContext, FormConstraintCheckEach/Last, AnnotationDict) to honor the standard :compact IOContext flag instead of unconditionally emitting the compact form. Default form (REPL, Pluto, Jupyter — :compact => false) prints actual messages/marginals, the full UUID span id, and the additional context fields. Compact form (used by trace loggers like RxInfer's TensorBoardLoggerExt) keeps the previous nmsgs=N / 4-char span prefix shape so log lines stay greppable and one-per-event. Also drop the span=nothing noise when callbacks are disabled — the helper now emits no field at all when span_id === nothing. The AnnotationDict show switches from MIME-based dispatch to the same :compact branching for consistency with the rest of the family. Tests cover both forms and assert that span is omitted when nil.
Update the [Unreleased] entries to describe the :compact-flag-based design instead of the previous unconditional-compact framing, and call out that span fields are now omitted entirely when callbacks are disabled.
🤖 Code FormattingYour PR still has some code formatting issues. I've updated PR #603 with the necessary formatting changes. You can merge that PR into this branch to fix the code style check. Alternatively, you can run |
🤖 Code FormattingYour PR still has some code formatting issues. I've updated PR #603 with the necessary formatting changes. You can merge that PR into this branch to fix the code style check. Alternatively, you can run |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #602 +/- ##
==========================================
+ Coverage 82.02% 82.41% +0.38%
==========================================
Files 208 208
Lines 6402 6555 +153
==========================================
+ Hits 5251 5402 +151
- Misses 1151 1153 +2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
The documentation build fails with All documented functions must be present in the |
|
Fixed. Checks now pass |
Resolves #599.
Summary
Base.showmethods for every callback event insrc/callbacks.jl(Before/AfterMessageRuleCallEvent,Before/AfterProductOfTwoMessagesEvent,Before/AfterProductOfMessagesEvent,Before/AfterFormConstraintAppliedEvent,Before/AfterMarginalComputationEvent) plus the supporting types they reference (MessageMapping,MessageProductContext,FormConstraintCheckEach,FormConstraintCheckLast,AnnotationDict).IOContext:compactflag::compact => true(used by trace loggers like the RxInferTensorBoardLoggerExt) → short, single-line form:nmsgs=N, 4-char span prefix.:compact => false(default — REPL, Pluto, Jupyter) → full form: actualmessages=(Message(...), ...), full UUIDspan_id=…, and the otherwise-elided context fields._show_spanhelper emits no field at all whenspan_id === nothing(callbacks disabled), instead ofspan=nothing.AnnotationDictswitched fromMIME"text/plain"dispatch to:compactbranching for consistency.MessageMapping.shownow reuses the existingunvalhelper fromsrc/helpers/helpers.jl:81instead of a local duplicate.Why
Trace loggers were rendering raw struct dumps like
BeforeMessageRuleCallEvent{ReactiveMP.MessageMapping{…}, …}(...)because the events had noBase.show. This makes TBLogger Text-tag breadcrumbs unreadable (RxInfer.jl#638).Review feedback applied
All four points from @bvdmitri's review on this issue:
_show_spanno longer printsspan=nothing— the field is omitted entirely.Base.showhonors the:compactflag rather than compacting unconditionally — full content (actual messages) is preserved for REPL/Pluto, compact form is opt-in for trace loggers.:compactdistinction applies toFormConstraintCheckEach/Last,MessageMapping,MessageProductContext, andAnnotationDict._message_mapping_nameswas deleted; the show method uses the existingunvalhelper.Downstream
Pairs with the matching RxInfer side: ReactiveBayes/RxInfer.jl#638 / branch
feat/event-show-methods. RxInfer'sTensorBoardLoggerExtwas updated to render viasprint(show, ev; context = :compact => true)so it gets the short trace form.