explain_failure: Explain a minex failure with an LLM

View source: R/explain.R

explain_failureR Documentation

Explain a minex failure with an LLM

Description

Hands a minex() result's minimal snippet to a language model and returns a structured explanation: why it fails, a fix (optionally executed to verify it is gone), a paste-ready bug report, and a diagnosis. Opt-in; requires the suggested ellmer package and a configured chat backend.

Usage

explain_failure(
  x,
  chat = NULL,
  verify_fix = TRUE,
  timeout = 60,
  session_info = TRUE,
  modes = c("explain", "fix", "report", "diagnose")
)

Arguments

x

A minex_result from minex().

chat

An ellmer Chat object (e.g. ellmer::chat_ollama()). Defaults to getOption("minex.chat"). Used statelessly (cloned per call).

verify_fix

Logical. Run the proposed fix to check the failure is gone.

timeout

Seconds for the sandboxed fix execution.

session_info

Logical. Include utils::sessionInfo() in the bug report.

modes

Which sections to produce.

Details

Executing model output: with verify_fix = TRUE (default) the proposed fix is run in a fresh callr process with a timeout. callr isolates R session state, not the OS; a fix may still have side effects. Use verify_fix = FALSE for input you would not run yourself.

Value

A minex_explanation object.

Examples

## Not run: 
# Write a failing script and reduce it, then explain the failure.
tmp <- tempfile(fileext = ".R")
writeLines("x <- c(1, 2, NA)\nif (is.na(mean(x))) stop('mean is NA')", tmp)
res <- minex(tmp, backend = "inprocess")
# Requires a configured chat backend (e.g. ellmer::chat_ollama()).
explain_failure(res, chat = ellmer::chat_ollama(model = "llama3.2"),
                verify_fix = FALSE)

## End(Not run)

minex documentation built on Aug. 30, 2026, 1:07 a.m.