we-promise/sure · error · ActiveRecord::RecordNotFound

record_not_found

record_not_found

Error message

Rule run not found

What it means

Raised by set_rule_run in Api::V1::RuleRunsController (app/controllers/api/v1/rule_runs_controller.rb:34-38). A non-UUID params[:id] trips the guard with the custom message 'Rule run not found'; otherwise rule_runs_scope — RuleRun joined to rules filtered on rules.family_id = current family — must find the row. RecordNotFound surfaces as 404 record_not_found.

Source

Thrown at app/controllers/api/v1/rule_runs_controller.rb:35

    @pagy, @rule_runs = pagy(
      rule_runs_query,
      page: safe_page_param,
      limit: @per_page
    )

    render :index
  rescue InvalidFilterError => e
    render_validation_error(e.message)
  end

  def show
    render :show
  end

  private

    def set_rule_run
      raise ActiveRecord::RecordNotFound, "Rule run not found" unless valid_uuid?(params[:id])

      @rule_run = rule_runs_scope.find(params[:id])
    end

    def ensure_read_scope
      authorize_scope!(:read)
    end

    def rule_runs_scope
      RuleRun
        .joins(:rule)
        .where(rules: { family_id: current_resource_owner.family.id })
        .includes(:rule)
    end

    def apply_filters(query)
      if params[:rule_id].present?
        raise InvalidFilterError, "rule_id must be a valid UUID" unless valid_uuid?(params[:rule_id])

View on GitHub (pinned to e69894adb9)

Solutions

  1. List runs with GET /api/v1/rule_runs (optionally ?rule_id=) and use a returned id
  2. Confirm the parent rule still exists and belongs to the token's family
  3. Validate the id is a UUID before the call
  4. Expire cached run ids when rules are deleted
Defensive patterns

Strategy: try-catch

Validate before calling

UUID_RE = /\A[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\z/i
UUID_RE.match?(id) or raise ArgumentError, 'rule run id must be a UUID'

Try / catch

begin
  client.get("/api/v1/rule_runs/#{id}")
rescue Faraday::ResourceNotFound
  # 404 'Rule run not found': malformed id or run under another family's rule
end

Prevention

When it happens

Trigger: GET /api/v1/rule_runs/:id with a malformed id; a rule run whose rule belongs to another family; a run for a rule that was deleted (orphaned runs are out of scope if the rule row is gone).

Common situations: Copying a rule run id from another workspace/family; rules deleted during cleanup leaving stale ids in client logs or dashboards; pagination caches holding ids after a rule purge.

Related errors


AI-assisted analysis of we-promise/sure@e69894adb9 (2026-08-21). Data as JSON: /api/errors/07c05a0eaad5b3ec. Report an issue: GitHub.