The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:
TypeScript analyticsbibusiness-intelligencebusinessintelligenceclojuredashboarddatadata-analysisdata-visualizationdatabasemetabasemysqlpostgrespostgresqlreportingslacksql-editorvisualization
reprobot: bug reproduction agent (#73132)
Nathan Voxland09f80ed3bc6c
diff --git a/.claude/commands/autobot-quit.md b/.claude/commands/autobot-kill.mdsimilarity index 89%rename from .claude/commands/autobot-quit.mdrename to .claude/commands/autobot-kill.mdindex 15da253bd7b..8ff7fc8a34f 100644--- a/.claude/commands/autobot-quit.md+++ b/.claude/commands/autobot-kill.md@@ -5,13 +5,13 @@ The user provided: `$ARGUMENTS`Run this from the **current working directory** (don't `cd` anywhere) — `./bin/mage` works from any worktree, and the no-argument case relies on being inside the worktree you want to remove:```-./bin/mage -autobot-quit $ARGUMENTS+./bin/mage -autobot-kill $ARGUMENTS```The mage command handles both cases:- **With an argument**: uses it as the session name. If no session matches, mage prints the available sessions and exits non-zero.- **Without an argument**: auto-detects the current worktree's session from its path. If the caller is in the main repo (not a worktree), mage prints a usage error and exits non-zero.-Do NOT preemptively run `-autobot-list` and ask the user to pick. Just run `-autobot-quit` with whatever the user gave you (or nothing) and show the output.+Do NOT preemptively run `-autobot-list` and ask the user to pick. Just run `-autobot-kill` with whatever the user gave you (or nothing) and show the output.Show the user the full stdout+stderr of the command.diff --git a/.claude/commands/autobot.md b/.claude/commands/autobot.mdindex 3c560e7f53a..57ac4c151de 100644--- a/.claude/commands/autobot.md+++ b/.claude/commands/autobot.md@@ -53,14 +53,19 @@ If no precheck skill exists for the inner bot, skip this step.### 3. Discover context-Run the `/<bot-name>-discover` skill, passing the inner-args as its arguments. For example, if the command is `/fixbot MB-12345`, run `/fixbot-discover MB-12345`.+Generate a timestamp in `YYYYMMDD-HHMMSS` format (use the current wall-clock time if known; otherwise run `./bin/mage -bot-timestamp` — do NOT use `date` directly). Set:++- `TIMESTAMP=<YYYYMMDD-HHMMSS>`+- `OUTPUT_DIR=.bot/<BOT_NAME>/<TIMESTAMP>`++Run the `/<bot-name>-discover` skill, passing the inner-args plus `--output-dir <OUTPUT_DIR>`. For example, if the command is `/fixbot MB-12345`, run `/fixbot-discover MB-12345 --output-dir <OUTPUT_DIR>`.This will:- Gather external context (Linear issues, PR descriptions, etc.)- Determine the correct app database-- Write results to `.bot/<bot-name>/discover/result.env`+- Write results to `<OUTPUT_DIR>/config.env` (per-run, not in any shared location)-After the discover skill completes, read `.bot/<bot-name>/discover/result.env` and extract the `APP_DB` value. If the file doesn't exist or APP_DB is missing, default to `postgres`.+After the discover skill completes, read `<OUTPUT_DIR>/config.env` and extract the `APP_DB` value. If the file doesn't exist or APP_DB is missing, default to `postgres`.### 4. Launch the autobot session@@ -86,4 +91,4 @@ Tell the user:- How to attach: `tmux attach -t <session-name>`- How to stop: `/autobot-stop <session-name>` (or `/autobot-stop` from inside the session)- How to list all sessions: `/autobot-list`-- How to remove: `/autobot-quit <session-name>`+- How to remove: `/autobot-kill <session-name>`diff --git a/.claude/commands/reprobot-discover.md b/.claude/commands/reprobot-discover.mdnew file mode 100644index 00000000000..157b21e9d59--- /dev/null+++ b/.claude/commands/reprobot-discover.md@@ -0,0 +1,56 @@+Discover context for reprobot. This is called by `/reprobot` (or `/autobot` before launching the session) to determine the app database and gather issue context.++The user provided: `$ARGUMENTS`++`$ARGUMENTS` must include a `--output-dir <PATH>` flag — the caller (`/reprobot` or `/autobot`) generates the per-run path. Discover never picks a directory itself, so nothing is ever written to a shared `.bot/reprobot/...` location.++## Steps++### 1. Resolve the issue ID++The positional argument can be one of three formats:+- **Linear issue ID** (e.g., `MB-12345`, `UXW-3155`) — use directly+- **GitHub issue number** (e.g., `12345`) — resolve to Linear first+- **GitHub issue URL** (e.g., `https://github.com/metabase/metabase/issues/12345`) — extract the number, then resolve to Linear++**If the input is a GitHub issue number or URL:**+1. Fetch the GitHub issue with `gh issue view <NUMBER> --repo metabase/metabase --json body,comments,title`+2. Search the issue body and comments for a Linear issue link (pattern: `https://linear.app/metabase/issue/[A-Z]+-[0-9]+`). Extract the Linear issue ID.+3. If no Linear link found, search Linear directly: run `./bin/mage -bot-fetch-issue` with a search term derived from the GitHub issue title.++**Validation:** Confirm the issue ID looks like `[A-Z]+-[0-9]+`. If not, tell the user the expected format and stop.++Set `ISSUE_ID=<LINEAR_ID>`.++### 2. Determine run directory++Parse `$ARGUMENTS` for `--output-dir <PATH>`. If absent, stop and tell the caller to pass `--output-dir`. Set `OUTPUT_DIR=<PATH>` and `TIMESTAMP=` the trailing timestamp portion of the path. All artifacts in subsequent steps go directly under `<OUTPUT_DIR>/`.++### 3. Fetch the issue from Linear++Run:+```+./bin/mage -bot-fetch-issue <ISSUE_ID>+```+Read the output to extract issue details.++Save the full output to `<OUTPUT_DIR>/linear-context.txt` using the `Write` tool.++### 4. Determine app database++From the issue description/comments:+- If the issue mentions **MySQL** problems, MySQL-specific SQL syntax, or MySQL error messages → `mysql`+- If the issue mentions **MariaDB** specifically → `mariadb`+- Otherwise → `postgres` (the default)++### 5. Write result++Write the structured result to `<OUTPUT_DIR>/config.env` using the `Write` tool:++```+APP_DB=<postgres|mysql|mariadb>+ISSUE_ID=<ISSUE_ID>+TIMESTAMP=<TIMESTAMP>+OUTPUT_DIR=<OUTPUT_DIR>+```+diff --git a/.claude/commands/reprobot.md b/.claude/commands/reprobot.mdnew file mode 100644index 00000000000..05c03773579--- /dev/null+++ b/.claude/commands/reprobot.md@@ -0,0 +1,36 @@+You are the orchestrator for the reprobot workflow. ReproBot attempts to reproduce a reported bug against the locally running server, classifies the result, and optionally writes a failing test. For an isolated worktree version, use `/autobot <branch> /reprobot <args>` instead.++## Steps++### 1. Generate per-run directory++Generate a timestamp in `YYYYMMDD-HHMMSS` format. If you know the current wall-clock time, construct it directly. Otherwise run `./bin/mage -bot-timestamp`. Do NOT use `date` directly.++Set:+- `TIMESTAMP=<YYYYMMDD-HHMMSS>`+- `OUTPUT_DIR=.bot/reprobot/<TIMESTAMP>`++Every file this run writes — including discover artifacts — lives under `<OUTPUT_DIR>/`. There must be **no shared paths across runs**, so multiple `/reprobot` invocations in the same repo do not collide.++### 2. Gather context++If `<OUTPUT_DIR>/config.env` does NOT exist, run `/reprobot-discover $ARGUMENTS --output-dir <OUTPUT_DIR>` first. (Discover writes its artifacts directly into `<OUTPUT_DIR>/`, never in a shared location.)++Then read:+- `<OUTPUT_DIR>/config.env` — extract `ISSUE_ID`, `APP_DB`+- `<OUTPUT_DIR>/linear-context.txt` — the full Linear issue content++### 3. Generate agent prompt++Run:+```+./bin/mage -bot-generate-prompt \+ --template dev/bot/reprobot-agent.md \+ --output <OUTPUT_DIR>/prompt.md \+ --set "ISSUE_ID=<ISSUE_ID>" \+ --set "OUTPUT_DIR=<OUTPUT_DIR>"+```++### 4. Execute++Read the generated `<OUTPUT_DIR>/prompt.md` and follow its instructions (Phases 0–4) in sequence. Execute all phases in a single turn — do not stop between phases unless a STOP condition is triggered.diff --git a/bb.edn b/bb.ednindex e856966872a..5d1ec6b34c5 100644--- a/bb.edn+++ b/bb.edn@@ -710,13 +710,13 @@:arg-schema [:tuple [:string {:name "branch"}] [:string {:name "bot"}]]:task (task! (autobot/result! parsed))}- -autobot-quit+ -autobot-kill{:doc "Tear down and remove an autobot session. No args = remove current session."- :examples [["./bin/mage -autobot-quit qabot-master" "Remove named session"]- ["./bin/mage -autobot-quit" "Remove current session (from inside an autobot session)"]]+ :examples [["./bin/mage -autobot-kill qabot-master" "Remove named session"]+ ["./bin/mage -autobot-kill" "Remove current session (from inside an autobot session)"]]:requires [[mage.bot.autobot :as autobot]]:arg-schema [:? [:string {:name "name-or-id"}]]- :task (task! (autobot/quit! parsed))}+ :task (task! (autobot/kill! parsed))};;; Shared bot tasksdiff --git a/dev/bot/reprobot-agent.md b/dev/bot/reprobot-agent.mdnew file mode 100644index 00000000000..4f270b2e998--- /dev/null+++ b/dev/bot/reprobot-agent.md@@ -0,0 +1,205 @@+# ReproBot Agent — {{ISSUE_ID}}++## Mission++You are a bug reproduction specialist. Your job is to take a reported issue, try to reproduce it, classify the result, and optionally write a failing test. You do NOT fix bugs — you confirm them and provide evidence.++## CRITICAL: Getting the User's Attention++When you need user input, are reporting a blocker, or presenting findings, use an eye-catching banner:++```+╔══════════════════════════════════════════════════════════════╗+║ 🔬 REPROBOT — <STATUS> ║+╠══════════════════════════════════════════════════════════════╣+║ ║+║ <your message here> ║+║ ║+╚══════════════════════════════════════════════════════════════╝+```++## Classification System++At the end of reproduction, classify the result:++| Status | Meaning |+|--------|---------|+| **REPRODUCED** | Bug confirmed — you triggered the wrong behavior and have evidence |+| **SEEN FIXED** | Bug existed in older code but is fixed on current branch (confirmed by code comparison or runtime test) |+| **NOT REPRODUCED** | Tested thoroughly and the reported behavior does not occur |+| **INCONCLUSIVE** | Could not determine — missing infrastructure, external dependency, or ambiguous issue |++## Instructions++Execute all phases in sequence. Do not stop between phases unless a STOP condition is triggered.++## Phase 1: Issue Resolution & Parsing++### Fetch the issue++Run `./bin/mage -fixbot-fetch-issue {{ISSUE_ID}}` to get the full issue details from Linear.++### Parse the issue++Extract from the issue title, description, and comments:+- **Repro steps**: Numbered list of how to trigger the bug+- **Expected behavior**: What should happen+- **Actual behavior**: What actually happens (the bug)+- **Version**: Metabase version where the bug was reported (if mentioned)+- **Stack traces**: Any error messages or stack traces+- **Database type**: H2 (default), Postgres, MySQL, MariaDB — look for keywords in the description++### Classify the bug type++- **Frontend/UI**: Visual bugs, broken interactions, rendering issues+- **Backend/API**: Wrong data, errors, permission issues+- **Query/SQL**: Wrong query results, SQL generation bugs+- **Mixed**: Both frontend and backend components involved++### Write summary++Write a brief issue summary to `{{OUTPUT_DIR}}/issue-summary.md`.++## Environment++Use the determined database type for the APP_DB when applicable++{{FILE:dev/bot/common/environment-discovery.md}}++---++## Phase 2: Reproduction (max 3 attempts)++{{FILE:dev/bot/common/reproduction-strategies.md}}++{{FILE:dev/bot/common/metabase-patterns.md}}++### Attempt structure++For each attempt (up to 3):++1. **Form hypothesis**: Based on the issue description and code analysis, hypothesize what causes the bug+2. **Choose strategy**: Use the strategy selection matrix above+3. **Execute**: Try to trigger the bug using the chosen approach+4. **Capture evidence**: Screenshots, API responses, REPL output → save to `{{OUTPUT_DIR}}/output/`+5. **Classify**: Did it reproduce?++### Classification rules++- **REPRODUCED**: You triggered the wrong behavior. You have concrete evidence (screenshot, API response, REPL output showing incorrect result).+- **SEEN FIXED**: Code analysis shows the bug existed in the reported version but the defective code path has been fixed on the current branch. Confirmed by either: (a) reading the fix in source, or (b) runtime test showing correct behavior where the old code was wrong.+- **NOT REPRODUCED**: You followed the repro steps (or reasonable variations) and the behavior is correct. Tested with multiple approaches.+- **INCONCLUSIVE**: After 3 attempts, couldn't determine either way. Document what you tried and why it was inconclusive.++**STOP** as soon as you have a definitive classification. Don't continue attempting if you've already confirmed REPRODUCED or SEEN FIXED.++---++## Phase 3: Write Failing Test (if REPRODUCED)++**Gate**: Only if status is REPRODUCED and the bug is still present on the current branch.++{{FILE:dev/bot/common/test-strategy.md}}++### Steps++1. Identify the source file with the bug+2. Find or create the corresponding test file+3. Write a minimal failing test that demonstrates the bug+4. Run the test to confirm it fails:+ - **Backend**: `./bin/test-agent :only '[namespace/test-name]'`+ - **Frontend**: `bun run test-unit-keep-cljs path/to/file.unit.spec.ts`+5. Save the test changes as a patch: `git diff > {{OUTPUT_DIR}}/test-diff.patch`++If you can't write a useful test (complex setup, external dependencies), note the reason and skip to Phase 4.++---++## Phase 4: Report++### Write the report++Create `{{OUTPUT_DIR}}/report.md`:++```markdown+# Reproduction Report: {{ISSUE_ID}}++## Summary++- **Issue:** {{ISSUE_ID}}+- **Status:** REPRODUCED / SEEN FIXED / NOT REPRODUCED / INCONCLUSIVE+- **Bug Type:** Frontend / Backend / Query / Mixed+- **Date:** YYYY-MM-DD++<1-2 sentence summary>++## Reproduction Method++<Primary strategy used: REPL / API / Playwright / Code analysis>++## Key Findings++<Up to 5 bullets describing what was discovered>++## Evidence++<References to screenshots, API responses, REPL output in output/>++## Root Cause Hypothesis++<If identified — specific file, function, and logic error. If not, explain why.>++## Failing Test++<If written: describe the test, which file, confirm it fails. If not: explain why.>+<Reference test-diff.patch if created>++## Attempts++| # | Approach | Hypothesis | Result |+|---|----------|-----------|--------|+| 1 | ... | ... | ... |++## Approaches Not Tried++<Any strategies skipped and why>+```++### Generate PDF++```bash+./bin/mage -bot-md-to-pdf {{OUTPUT_DIR}}/report.md+```++{{FILE:dev/bot/common/report-generation.md}}++### Present results++Show the user the report path and a brief summary using a banner:++**If findings exist:**+```+╔══════════════════════════════════════════════════════════════╗+║ 🔬 REPROBOT REPORT — <STATUS> ║+╠══════════════════════════════════════════════════════════════╣+║ ║+║ Report: <absolute path to report.pdf> ║+║ Test: <absolute path to test-diff.patch, if created> ║+║ ║+║ <1-line summary> ║+║ ║+╚══════════════════════════════════════════════════════════════╝+```++---++{{FILE:dev/bot/common/playwright-guide.md}}+++## Important Rules++- **Read-only by default**: Do NOT modify source code except for writing tests in Phase 3. You are investigating, not fixing.+- **Evidence-based**: Every finding must have evidence — a screenshot, API response, REPL output, or specific code reference.+- **Use wrapper commands**: `./bin/mage -bot-api-call` for metabase API calls.+- **Parallelization**: Batch independent REPL calls, Grep calls, and API calls in the same turn.+- **Time awareness**: Don't spend more than 30 minutes total. If you're stuck after 3 attempts, classify as INCONCLUSIVE and write the report.diff --git a/mage/src/mage/bot/autobot.clj b/mage/src/mage/bot/autobot.cljindex f25010a16b8..295b428f940 100644--- a/mage/src/mage/bot/autobot.clj+++ b/mage/src/mage/bot/autobot.clj@@ -1,5 +1,5 @@(ns mage.bot.autobot- "Unified autobot session management — launch, stop, list, quit."+ "Unified autobot session management — launch, stop, list, kill."(:require[babashka.fs :as fs][clojure.java.io :as io]@@ -88,7 +88,7 @@(zero? exit)));;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-;; Self-detection (for running stop/quit from inside a session)+;; Self-detection (for running stop/kill from inside a session)(defn- current-worktree-path"Return the absolute path of the git worktree the caller is currently in,@@ -200,7 +200,8 @@[{:keys [session-name branch-name branch-ref prompt-file workmux-config display-info]}](let [cfg-path (launch-config-path u/project-root-directory session-name)ref (or branch-ref branch-name)- attached? (in-tmux?)]+ attached? (in-tmux?)+ bootstrap "workmux-bootstrap"](with-workmux-config! cfg-path workmux-config(fn [];; Fetch latest refs@@ -215,16 +216,46 @@(println (c/yellow "Prompt: ") prompt-file)(println)- ;; Synchronous workmux invocation. With --config we don't touch- ;; ./.workmux.yaml. With -s (when not already in tmux) workmux owns- ;; session creation. workmux returns once the worktree + window are- ;; up, so the cfg file is safe to delete in the finally.- (apply shell/sh- (concat ["workmux" "add" ref- "--config" cfg-path- "--name" session-name- "-P" prompt-file]- (when-not attached? ["-s"])))+ ;; workmux requires a running tmux server with at least one+ ;; session before it will create another. `tmux start-server` is+ ;; a no-op on macOS without a session, so spin up a throwaway+ ;; detached session if nothing is running yet.+ (let [created-bootstrap?+ (when-not attached?+ (let [{:keys [exit]} (shell/sh* {:quiet? true} "tmux" "has-session")]+ (when-not (zero? exit)+ (shell/sh* {:quiet? true}+ "tmux" "new-session" "-d" "-s" bootstrap)+ true)))]++ ;; Synchronous workmux invocation. With --config we don't touch+ ;; ./.workmux.yaml. When not attached we pass -s (own session)+ ;; and -b (background — skip switch-client, which fails with no+ ;; current client). workmux returns once the worktree + window+ ;; are up, so the cfg file is safe to delete in the finally.+ (apply shell/sh+ (concat ["workmux" "add" ref+ "--config" cfg-path+ "--name" session-name+ "-P" prompt-file]+ (when-not attached? ["-s" "-b"])))++ ;; If we had to spin up the bootstrap session and the real+ ;; autobot session is now live, clean up the bootstrap so it+ ;; doesn't clutter `tmux ls`. Only kill it when at least one+ ;; non-bootstrap session exists, so we don't tear down the+ ;; whole tmux server on a partial-failure path.+ (when created-bootstrap?+ (let [{:keys [exit out]}+ (shell/sh* {:quiet? true}+ "tmux" "list-sessions" "-F" "#{session_name}")+ others (when (zero? exit)+ (->> (str/split-lines (or out ""))+ (remove #(or (str/blank? %) (= % bootstrap)))+ seq))]+ (when others+ (shell/sh* {:quiet? true}+ "tmux" "kill-session" "-t" bootstrap)))))(when-not attached?(println)@@ -504,7 +535,7 @@(println (c/bold (c/green "Session stopped: ") (c/cyan session)))(println (c/yellow "Worktree preserved. Use /autobot to restart."))))-(defn quit!+(defn kill!"Tear down and remove a session.Works with a session name argument, or detects current session if no args."[{:keys [arguments]}]