Skip to content

Cold start crash when no experiment data exists #10

@jjroelofs

Description

@jjroelofs

Problem

Views with AI Sorting crash with "No scores for experiment... Check RL tracking" when no reinforcement learning data exists yet. This creates a chicken-and-egg problem where views can't display content to generate the initial tracking data.

Root Cause

The execution order causes the issue:

  1. AISorting::query() runs first → requests scores from RL module
  2. No experiment registered yet → getThompsonScores() returns empty array
  3. Exception thrown: "No scores for experiment..."
  4. hook_views_pre_render() never runs → experiment never gets registered
  5. No content displayed → no tracking data collected → permanent failure

The experiment registration happens in hook_views_pre_render() which runs AFTER the query builder, so on first page load the experiment doesn't exist yet.

Solution Implemented

Remove the exception and gracefully handle empty scores by returning early, allowing the view to use its default sort order during cold start:

if (empty($scores)) {
  // No experiment data exists yet - gracefully handle cold start.
  // The RL module's Thompson sampling already handles this with tie-breakers,
  // but we need some initial arm IDs to work with.
  return;
}

Benefits

  • Eliminates cold start crashes: Views display content immediately, even with no RL data
  • Enables data collection: Content displays with default sorting, allowing users to interact and generate initial tracking data
  • Seamless transition: Once tracking data is collected, automatically switches to ML-based sorting
  • Production ready: Clean, simple fix without adding duplicate sorting logic

Testing

  • Verified with empty RL database - no crashes
  • Content displays with default sort order on first load
  • After user interactions, RL scoring takes over
  • All Drupal coding standards checks pass

Compatibility

  • Drupal 10/11 compatible
  • Works with any node-based Views
  • No database schema changes required
  • Backward compatible with existing experiments

Pull Request: #11
Related to RL module production updates: dxpr/rl#7

🤖 Generated with Claude Code

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions