AI plumbing 2c follow-up: recorded evals that run, set-aside prompt overrides on the family

Merged
JO
4d ago
+1255-78

Follow-up to dgilperez's review of 2c (#4775, review), points 3 and 4. A small PR on refactor/ai-plumbing, separate from the 3a stack.

Problem

The recorded evals gate was always green.

  • ai-evals.yml had no cassettes, so evals:ci_regression printed "No recorded responses … skipping" and passed without testing anything.
  • Recording them showed a second problem. Each evals:import_dataset gave the samples new random UUIDs, and those ids are what the model is sent, so a recording could never match a later import. The same random ids also made the Bayes train/test split differ between imports, since it sorts by id.

A set-aside prompt override lived only in the debug log.

  • When a family had two different per-provider overrides for one feature, 2c's key-collapse migration wrote the one it didn't keep to a DebugLogEntry.
  • That entry was the text's only copy, so DebugLogCleanupJob needed an exception to keep it.

What changes

  • Stable sample ids: Eval::Dataset.import_from_yaml gives a dataset's nth sample the same id on every import, a UUID v5 of sure:eval:<dataset>:<n>. Eval::Runners::Base#samples orders by id, so the ids, the batches and the split are the same on every import.

  • Cassettes for both CI datasets, recorded against Claude Haiku 5.5 through the Kilo gateway:

    DatasetAccuracy
    categorization_golden_v1_light96.0%
    merchant_detection_golden_v194.44%

    ai-evals.yml replays them with the URL and batching settings they were recorded with (EVAL_MODEL/OPENAI_MODEL anthropic/claude-haiku-5.5, OPENAI_URI_BASE https://api.kilo.ai/api/gateway, LLM_CONTEXT_WINDOW 32000). Replay needs no key.

  • Set-aside overrides on the family: the migration now puts the text under families.ai_prompt_overrides["dropped"] ({ key => text }). Family::AiPromptable lists and clears it there, and validates it (known prompt keys, text values). The prompts page still shows it until the next save. DebugLogCleanupJob is back to main's. 2c's migration 20261106130000 is left as it merged; a new migration, 20261122120000, moves the entries it set aside in debug_log_entries onto the family, and its down moves them back.

  • setup-ruby bump: the same commit as 3a's (30fac7355), so ai-evals.yml can install Ruby 3.4.13 here. It drops out when the 3a stack is rebased onto this.

Validation

  • Recorded evals replayed as CI runs them: a fresh database, the workflow's settings, no key, and VCR with record: :none. Both datasets reproduce the recorded accuracy exactly. Without stable ids, replay scored 0%.
  • Secrets: the cassettes hold only <OPENAI_ACCESS_TOKEN> and <OPENAI_COMPATIBLE_X_KILOCODE_ORGANIZATIONID> placeholders. The Pipelock diff scan is clean.
  • Tests:
    • bin/rails test: 18,654 runs, 0 failures.
    • The new test checks that two imports give the same ids.
    • Updated tests cover the dropped override: model, controller, migration and cleanup job.
  • Lint: RuboCop is clean on the changed files.

Points 1 and 5 of the review: the quadratic chain is #5521, and output_config needs nothing. Point 2: failover and escalation stay until PR 7, which brings multiple routes; bisection already runs with one route. The reply on #4775 covers all five.

🤖 Generated with Claude Code

https://claude.ai/code/session_016zAWUUTovNPgC5oNfUHKhd


Summary by cubic

Makes the AI evals recorded gate actually run in CI and stores set-aside prompt overrides on the family instead of the debug log.

Recorded evals

  • ai-evals.yml had no cassettes, so the recorded gate skipped and always passed; it now replays recorded responses for both datasets at 96.0% and 94.44% accuracy, with no API key needed. Each dataset's CI floor is its recorded accuracy less one sample, so a broken matcher can't pass at 80%.
  • Imports gave each sample a new random UUID that the model was sent, so recordings could never match a reimport; samples now get a deterministic UUID v5 per dataset and index, and runs order by id.
  • Cassettes are named by a digest of the samples' inputs and contexts plus the runner's batching settings, so editing a sample or changing batching leaves no cassette to replay, and EVAL_REQUIRE_RECORDING=1 makes a missing cassette fail instead of skip.
  • Recorded responses drop Set-Cookie headers, and existing AI cassettes had their gateway routing cookies removed.
  • A runner test that asserted results by insertion order now looks them up by sample, and a new test covers the generation's fuzzy category match.

Set-aside prompt overrides

  • The key-collapse migration wrote the dropped override to a DebugLogEntry, which the cleanup job had to exempt; a new migration moves it to ai_prompt_overrides["dropped"] on the family, where it's validated and cleared in one UPDATE.
  • The prompts page still shows it until the next save; DebugLogCleanupJob is back to main's behavior. The migration has a down so a rollback keeps the text.

Summary by CodeRabbit

  • Bug Fixes
    • Set-aside AI prompt overrides are now retained with the family’s prompt settings and can be reviewed or cleared there.
    • Older debug log entries are cleaned up after the configured retention period.
  • Improvements
    • Evaluation dataset imports now produce consistent sample IDs and ordering, helping make evaluation runs repeatable.
    • Recorded AI evaluations now use an updated model configuration.