Repository navigation
Description
Did an LLM bug audit when having access to a particularly powerful model.
Bug audit findings
A systematic audit of all 41 R source files (~7,800 lines). Each finding was verified by running a minimal reproduction against the current main branch (devtools::load_all()); the high-severity reproductions were independently re-run. 18 confirmed bugs, six of which produce silently wrong scores on valid input.
High severity — silently wrong results
1. rps_ordinal() applies the wrong permutation when reordering columns R/metrics-ordinal.R:74-76
To put predicted columns into natural level order it must use the inverse permutation predicted[, order(as.numeric(predicted_label))], but it uses predicted[, as.numeric(predicted_label)]. The score is only correct when the permutation is its own inverse (identity or pairwise swaps); for a 3-cycle relabelling the same forecast scores differently. The existing test at tests/testthat/test-metrics-ordinal.R:122-127 encodes the same wrong permutation, so it must be fixed together with the code. The score() pipeline pre-sorts labels, so only direct callers of the exported function are affected.
rps_ordinal(obs, P, lab_natural) # 1.45 0.10 0.20
rps_ordinal(obs, P2, lab2) # 0.05 0.85 0.32 (same forecast, different score)2. logs_categorical() ignores predicted_label entirely R/metrics-nominal.R:127-137
It indexes predicted[cbind(1:n, as.numeric(observed))], assuming columns are in factor-level order. With permuted labels it returns the log score of the wrong outcome.
logs_categorical(obs, P, lab_natural)[2] # 0.3566749 (= -log(0.7), correct)
logs_categorical(obs, P2, lab2)[2] # 1.6094379 (= -log(0.2), wrong outcome) 3. bias_quantile() sorts predictions but not quantile levels R/metrics-quantile.R:480-481
predicted <- predicted[order] is applied without reordering quantile_level, so unsorted but internally consistent input gives a wrong answer.
ql <- c(0.25, 0.5, 0.75); pred <- c(1, 2, 3); obs <- 1.5; perm <- c(3, 1, 2)
bias_quantile(obs, pred, ql) # 0.5
bias_quantile(obs, pred[perm], ql[perm]) # -0.5 (same forecast, wrong sign) 4. ae_median_sample() / se_mean_sample() mishandle documented vector input R/metrics-sample.R:144-147, 172-175
With scalar observed and a vector of N samples (explicitly allowed by the docs and assertions), as.matrix() turns the samples into N one-sample forecasts. Relatedly, bias_sample() and mad_sample() crash outright on the same documented input shape (R/metrics-sample.R:101, 414).
ae_median_sample(1, c(0, 2, 4)) # returns 1 1 3; correct: |1 - median(0,2,4)| = 1
se_mean_sample(1, c(0, 2, 4)) # returns 1 1 9; correct: (1 - 2)^2 = 1 5. Renaming onto an existing protected column creates duplicate columns R/class-forecast.R:29
If the data already has a predicted column and the user passes predicted = "prob", setnames produces two predicted columns; validation sees one, score() scores the stale one while displaying the other. Affects all as_forecast_<type>() constructors and all five renameable columns (predicted, observed, quantile_level, sample_id, predicted_label).
# data has stale predicted = c(0.9, 0.9) and real prob = c(0.3, 0.7)
fc <- as_forecast_binary(dt, predicted = "prob")
names(fc) # "model" "id" "observed" "predicted" "predicted"
score(fc) # brier_score 0.81 = (0.9-0)^2 — scored the stale column 6. as_forecast_quantile.forecast_sample() breaks with asymmetric probs R/class-forecast-sample.R:110-118
quantile_level is built from c(probs, 1 - probs) but predicted is computed only at probs. With a single asymmetric prob the quantile value is silently recycled into the complementary level; with several asymmetric probs it fails with a cryptic data.table recycling error.
# probs = 0.4, samples 1:100; true q0.4 / q0.6 = 40.6 / 60.4
# quantile_level predicted
# 0.4 40.6
# 0.6 40.6 <- 0.6 level got the 0.4 quantile
# probs = c(0.1, 0.2):
# Error: Supplied 2 items for column 2 of group 1 which has 4 rows. Medium severity
7. interval_coverage() uses exact floating-point %in% on quantile levels R/metrics-quantile.R:334-348
With quantile_level = seq(0.05, 0.95, 0.05), interval_range = 30 errors claiming the 0.35/0.65 quantiles are missing (0.35 %in% seq(...) is FALSE). The package already rounds to 10 dp elsewhere for exactly this reason.
8. Quantile levels 0 and 1 make wis() / interval_score() return NaN R/metrics-interval-range.R:164-171
With alpha = 0 the penalty terms become Inf * 0 = NaN even when the observation is inside the interval, and validation permits these levels. This breaks the documented WIS = mean quantile score identity.
obs <- 5; pred <- c(1, 3, 5, 7, 9); ql <- c(0, 0.25, 0.5, 0.75, 1)
wis(obs, pred, ql) # NaN
quantile_score(obs, matrix(pred, nrow = 1), ql) # 0.4 ae_median_sample(1, c(0, 2, 4)) # returns 1 1 3; correct: |1 - median(0,2,4)| = 1
se_mean_sample(1, c(0, 2, 4)) # returns 1 1 9; correct: (1 - 2)^2 = 1 9. Incomplete-forecast error message names a complete forecast R/class-forecast-nominal.R:101, R/class-forecast-ordinal.R:107
complete[(correct), ...] filters for the forecasts that are fine; it should be !correct. When every forecast is incomplete the message reads model == NA.
10. observed is not required to be constant within a forecast unit R/class-forecast.R:110-155
Conflicting observed values pass validation, and score() then silently emits multiple score rows per forecast unit, each against a different observed value.
11. summarise_scores() accepts metric columns in by R/summarise_scores.R:77-80
by = c("model", "wis") returns an unsummarised table with two wis columns and no warning — the sibling of the recently fixed #1179.
12. get_pairwise_comparisons() aborts entirely if any subgroup has too few models R/pairwise-comparisons.R:273-277
With by = "target_type" and one single-model group, no results are returned even for groups with several models, and the error does not identify the offending group.
13. plot_correlations() misaligns the heatmap with non-default metrics order R/get-correlations.R:80, 101
Columns are selected in metrics-argument order but rows stay in data-column order, so self-correlations are drawn off-diagonal. get_correlations() itself returns correct output; only the plot is wrong.
Low severity
14. bias_quantile(na.rm = TRUE) crashes when NA removal strips one side of the median R/metrics-quantile.R:474-477 — max(numeric(0)) → "argument is of length zero".
15. assert_input_categorical() never checks ncol(predicted) for n > 1 R/metrics-nominal.R:72 — a matrix with extra columns passes and logs_categorical() silently returns meaningless scores. The n = 1 branch does enforce it.
16. Sample and quantile assert_forecast methods skip type checks R/class-forecast-sample.R:59-66, R/class-forecast-quantile.R:82-90 — character observed/predicted validates and only fails later as per-metric warnings, unlike the binary/point methods.
17. Nominal/ordinal assert_forecast return forecast[] visibly R/class-forecast-nominal.R:114, R/class-forecast-ordinal.R:120 — documented to return invisible(NULL), so a top-level call autoprints the whole dataset.
18. Two message/behaviour mismatches
R/class-forecast-quantile.R:61-69: the rounding warning saysdigits = 10
but the code rounds to 9.R/class-forecast-quantile.R:250-253:get_pit_histogram.forecast_quantile()
drops the second line of its warning (unnamedcli_warnargument) and the
advertised fallback never happens — it returns a zero-row table.
Notes (investigated, not bugs)
- The
bias_sample()docstring formula (P(x) + P(x+1)) disagrees with the code (P(x-1)), but the code is correct — documentation error only. transform_forecasts()warning about appending a duplicate label before inevitably erroring is tested, intentional behaviour, though the warning is misleading.
Activity
seabbs commentedon Jul 16, 2026
Shall we spin these into issues ad do PRs vs them?
nikosbosse commentedon Jul 18, 2026
On it
by, returning an unsummarised table #1204nikosbosse commentedon Jul 18, 2026
I opened a bunch of PRs. They are currently marked as draft PRs, as I haven't manually reviewed them yet. Will try to do that tonight and will mark them as regular PRs once I've reviewed them
nikosbosse commentedon Jul 19, 2026
Thanks a lot for this. Phew, there are quite some bugs in here, very happy you flagged them.
nikosbosse commentedon Nov 8, 2026
CLAUDE: Every finding from this audit was split into its own sub-issue (#1195–#1204, #1209–#1211). All are now fixed and closed except #1209 and #1210, which have open PRs #1214 and #1215. A later PIT histogram bug is tracked separately in #1219. Since each remaining item has its own issue, this tracking issue can be closed.