perf(dashboard): fix executions list slowness and 500s - #39
Merged
Conversation
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_detailspayload column for the page just to rendererror_message, which is the memory blowup behind the 500s. This adds a narrowerror_detailassociation 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 theDISTINCTthe 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 andSTRING_AGGon PostgreSQL, whereGROUP_CONCATdoes 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/requestsand an agent show page on PG. Host apps should runrails generate ruby_llm_agents:upgradefor 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