Skip to content

perf(dashboard): fix executions list slowness and 500s - #39

Merged
adham90 merged 1 commit into
mainfrom
adham90/fix-executions-page-perf
Sep 2, 2026
Merged

perf(dashboard): fix executions list slowness and 500s#39
adham90 merged 1 commit into
mainfrom
adham90/fix-executions-page-perf

Conversation

@adham90

@adham90 adham90 commented Sep 2, 2026

Copy link
Copy Markdown
Owner

The executions list ran 12 queries per view (four full-table scans, a duplicated COUNT, and SUMs that ActiveRecord turned into a LEFT JOIN without DISTINCT, inflating cost/token totals once per child execution) and preloaded every execution_details payload column for the page just to render error_message, which is the memory blowup behind the 500s. This adds a narrow error_detail association and preloads it on every list path (executions index, agent show, dashboard recent strip, CSV export), collapses the aggregates into single queries (Execution.totals, stats_for, cache_hit_rate/streaming_rate, SQL-side TTFT average), caches the DISTINCT dropdown scans for 5 minutes, adds the DISTINCT the agent-show filter pluck was missing, and adds a [:parent_execution_id, :created_at] index with an upgrade migration. The requests page also gets a single stats query and STRING_AGG on PostgreSQL, where GROUP_CONCAT does not exist and the page 500'd. Query-shape regression specs pin the counts and assert list paths never load payload columns; the PostgreSQL branches follow the existing adapter idiom but CI runs SQLite only, so please smoke-test /agents/requests and an agent show page on PG. Host apps should run rails generate ruby_llm_agents:upgrade for the index migration, and a newly seen agent/model/tenant takes up to 5 minutes to appear in the filter dropdowns.

🤖 Generated with Claude Code

…ages

The executions list ran 12 queries per view, four of them full table
scans, and preloaded every execution_details payload column (prompts,
response JSON) for the page just to render error_message on error rows.
Summing on an includes() relation also joined children without DISTINCT,
inflating the cost/token totals once per child execution.

- Add Execution#error_detail (id, execution_id, error_message only) and
  preload it on every list path: executions index, agent show table,
  dashboard recent strip, CSV export
- Execution.totals: count + both sums in one query, shared with pagination
- Execution.stats_for in one query (was 8, called once per agent on the
  agents index); cache_hit_rate / streaming_rate in one query each;
  avg_time_to_first_token averaged in SQL instead of plucking metadata
- Cache the DISTINCT agent/model/tenant dropdown scans for 5 minutes via
  shared ApplicationController helpers; cache AgentRegistry.execution_agents
- Agent show: DISTINCT on the model/temperature filter pluck
- Requests index: one stats query shared with pagination; STRING_AGG on
  PostgreSQL where GROUP_CONCAT does not exist
- Paginatable: accept total_count:, load the page relation
- Add [:parent_execution_id, :created_at] index and upgrade migration
- spec/support/sql_capture.rb and query-shape regression specs

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@adham90
adham90 merged commit 23d9db2 into main Sep 2, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant