feat: publish the reserved per-record field registry + misspelling guard (#262)#299
Conversation
Review: independent pass (cd-reviewer-2)Ran from a throwaway worktree of No-behaviour-change claim — confirmedThe diff only restructures the error branch of Edit-distance false-positive surface — the important one, checked directlyBuilt a tree with a genuine event actually named tree = sequential(:onset => Gamma(2.0, 1.0), :weights => Gamma(1.5, 1.0))
logpdf(tree, rand(Xoshiro(1), tree)) # scores fine, no error, no hintThis can't go wrong structurally: New public accessor docstring
NEWS wording on the deferred merge-guard"the covariate-context merge-overwrite guard the issue also raises is a Suites + hygiene
VerdictApprove. Narrow, additive, well-tested change. The false-positive concern |
…ard (#262) Add a public `reserved_record_fields()` accessor returning the reserved per-record field names (weight/count/obs_time/obs_window/branch_probs/ branch_prob), documented with each field's owner, type, default and when it is read, plus a note that the covariate context is a separate open namespace. A row that misspells a reserved field (e.g. `obs_tim`) now raises a clear error naming the reserved field, via a bounded edit-distance near-miss check, instead of the bare "not an event of this tree". Additive: valid records (including reserved fields) score exactly as before. This is the non-conflicting half of #262. The covariate-context merge-overwrite guard the issue also raises conflicts with released, tested last-writer-wins behaviour (test/composers/varying.jl) and is left open as a design decision (posted on #262 for review); this PR touches only tree_events.jl, not the covariate/Context code, to avoid the in-flight #257/#266 lane. Co-authored-by: Sam Abbott <contact@samabbott.co.uk>
9837dce to
795f7d4
Compare
Try this Pull Request!Option 1: Julia Package ManagerOpen Julia and type: import Pkg
Pkg.activate(temp=true)
Pkg.add(url="https://github.com/EpiAware/ComposedDistributions.jl", rev="feat/262-reserved-key-registry")
using ComposedDistributionsOption 2: Local CheckoutIf you have the repo locally: git checkout feat/262-reserved-key-registry
julia --project=. -e "using Pkg; Pkg.instantiate()" |
Part of #262 (the additive, non-conflicting half).
What
reserved_record_fields()— publishes the reserved per-record fieldnames (
weight/count/obs_time/obs_window/branch_probs/branch_prob)that a scoring row carries for their own meaning rather than as events,
documented with each field's owner, type, default and when it is read, and a
note that the covariate context is a separate open namespace.
obs_tim) now raises a clearerror naming the reserved field (bounded edit-distance near-miss), instead of
the bare "row field :obs_tim is not an event of this tree".
Additive: valid records — including those carrying reserved fields — score
exactly as before. Only
tree_events.jlis touched (plus the export + a test);no change to the covariate/
Contextcode.Scope note: the merge-overwrite guard is deferred (design decision on #262)
#262 also asks to "raise an explicit error when the context merge would overwrite
a key." That half is not in this PR: a blanket overwrite-error conflicts with
released, tested behaviour —
test/composers/varying.jl:243assertswith_covariates(Context(a=1); a=9).covariates.a == 9("later keys win"), and thesampler uses the same merge to thread latent params — and at the merge level an
accidental collision is indistinguishable from an intentional update. I posted
the semantics question (break / opt-in strict merge / defer) on #262 for review.
Deliberately keeping this PR off
varying.jlalso avoids the in-flight#257/#266 covariate lane.
Tests
test/composers/reserved_fields.jl(4@testitems): the registry is published;a valid record (with a reserved field) scores unchanged; a misspelled reserved
field errors helpfully while a genuine unknown field does not get a false hint;
and the near-miss/edit-distance unit checks.
task test-fastandtask test-qualitypass.This was opened by a bot. Please ping @seabbs for any questions.