{# Audit's standalone opportunity detail page. PR / dry-run / shadow / clearing surfaces are deliberately absent — audit is read-only and never generates solutions — but the page header, breadcrumb, ui-metric-grid stat strip, evidence section, and source-SQL viewer are intentionally consistent. #} {% extends "layout.html" %} {% block content %}
Opportunities {% if row.dbt_model_name %}{{ row.dbt_model_name }}{% else %}{{ row.opportunity_type | replace('_', ' ') }}{% endif %}

Recommendation

{% if row.dbt_model_name %}

{{ row.dbt_model_name }}

{% else %}

{{ row.affected_table }}

{% endif %}
{{ row.opportunity_type | replace('_', ' ') }} {% if row.severity_bucket == 'critical' %} Severity {{ row.severity_score }} · critical {% elif row.severity_bucket == 'high' %} Severity {{ row.severity_score }} · high {% elif row.severity_bucket == 'medium' %} Severity {{ row.severity_score }} · medium {% else %} Severity {{ row.severity_score }} · low {% endif %} {% if row.dbt_model_name %} dbt {% endif %}

{% if row.dbt_model_name %} {{ row.affected_table }} {% else %} {{ row.opportunity_type | replace('_', ' ') }} {% endif %}

{# Stat strip — matches the /jobs/{id} job-detail layout exactly so the user sees the same four cards (Type → Cost → Bytes Processed → Slot Time → Statement Type) on both pages. The cloud's ui-metric-grid was replaced with ui-stat-card here for parity. #}

Type

{{ row.opportunity_type | replace('_', ' ') }}

Cost

{{ row.query_cost_value | format_usd }}

Bytes Processed

{% if job and job.total_bytes_processed is not none %}

{{ job.total_bytes_processed | format_bytes }}

{% if job.total_bytes_billed is not none %}

billed: {{ job.total_bytes_billed | format_bytes }}

{% endif %} {% else %}

{% endif %}

Slot Time (hours)

{% if job and job.total_slot_ms is not none %}

{{ "%.1f" | format((job.total_slot_ms or 0) / 3600000) }}

{% if job.duration_ms is not none %}

duration: {{ job.duration_ms | format_duration }}

{% endif %} {% else %}

{% endif %}
{# Why this fired + Recommended fix — mirror the cloud's "explanation" + "Solution" pair #}

Why this fired

{{ row.explanation }}

{% if rule_meta and rule_meta.description %}

{{ rule_meta.description }}

{% endif %}

Recommended fix

{% if template_result %}

{{ template_result.explanation }}

{% if diff_lines %}
{% include "components/code_diff.html" %}
{% endif %} {% if template_result.rollback %}
Rollback instructions

{{ template_result.rollback }}

{% endif %} {% else %}

{{ row.explanation }}

This issue type doesn't have a single-query SQL rewrite. The fix is at the workload-scheduling or schema layer — see the explanation above.

{% endif %}
{# Available improvements — SQL-rewrite suggestions that fire on the same destination table as this issue. Each is a deterministic rewrite (no LLM) and renders inline as its own green/red diff. #} {% if improvements %}

Available improvements

{{ improvements | length }} found

SQL-rewrite suggestions that apply to the same query as this issue. Applying them won't necessarily resolve the issue on its own, but each reduces work the query is doing and may move the needle on cost / slot pressure.

{% for imp in improvements %}
{{ imp.display_name }} {% if imp.template_id %} deterministic rewrite {% endif %} {% if imp.occurrences and imp.occurrences > 1 %} ×{{ imp.occurrences }} {% endif %}
{% if imp.explanation %}

{{ imp.explanation }}

{% endif %} {% if imp.diff_lines or imp.before_content %}
{% if imp.diff_lines %} {% set diff_lines = imp.diff_lines %} {% set file_path = imp.template_id %} {% include "components/code_diff.html" %} {% else %}

No diff available — template did not produce a change.

{% endif %}
{% endif %} {% if imp.rollback %}
Rollback instructions

{{ imp.rollback }}

{% endif %}
{% endfor %}

All diffs are generated by deterministic templates (no LLM). Apply each one to {% if row.dbt_model_name %}your dbt model {{ row.dbt_model_name }}{% else %}the source SQL{% endif %} manually.

{% endif %} {# Source SQL — only rendered when there are no improvement cards above. With improvements, each card's "Original SQL" tab carries the same query, so a standalone block would duplicate. Without improvements (e.g. a slot_contention with clean SQL where no SQL-rewrite rule fires), this is the user's only way to read the SQL on the detail page. The Diff tab is intentionally absent — there's no rewrite to compare against. #} {% if not improvements and job and job.query %}

Original SQL

No deterministic SQL rewrite applies to this issue. The query is shown below as-is — review it and apply changes manually if needed.

Job {{ job.job_id }} view job → {{ job.query | length }} chars
{% for line in job.query.split('\n') %}{{ loop.index }}{{ line }}
{% endfor %}
{% endif %} {# Evidence + BigQuery query lookup — two side-by-side cards on >=lg, stacked on smaller screens. Each card collapses independently. The right-hand card renders the INFORMATION_SCHEMA.JOBS_BY_PROJECT SELECT pre-filtered by job_id so the user can paste it into the BigQuery console and inspect the row themselves — no need to hand-craft the predicate. Evidence's internal scratch keys (``_improvements``, ``_template_result``) are filtered out by the route handler. #} {% if visible_evidence or job_lookup_sql %}
{% if visible_evidence %}

Evidence

{% for key, value in visible_evidence.items() %}
{{ key }}
{% if value is mapping or (value is iterable and value is not string) %} {{ value | tojson }} {% else %} {{ value }} {% endif %}
{% endfor %}
{% endif %} {% if job_lookup_sql %}

BigQuery query

Paste this into the BigQuery console to inspect the underlying job row.

{{ job_lookup_sql }}
{% endif %}
{% endif %}
{% endblock %}