Title: fix(clickhouse): add execution time cap to task run metrics queries by claude[bot] · Pull Request #4381 · triggerdotdev/trigger.dev · GitHub
Open Graph Title: fix(clickhouse): add execution time cap to task run metrics queries by claude[bot] · Pull Request #4381 · triggerdotdev/trigger.dev
X Title: fix(clickhouse): add execution time cap to task run metrics queries by claude[bot] · Pull Request #4381 · triggerdotdev/trigger.dev
Description: Requested via Slack thread Two of the task run metrics queries are registered with no clickhouseSettings, so they have no server-side max_execution_time — nothing tells ClickHouse to give up on them. Their sibling in the same object literal already has one. Before / After Before getTaskActivity and getAverageDurations were registered as getTaskActivityQueryBuilder(this.reader) and getAverageDurations(this.reader) — no settings argument, so no execution cap reached the server. The only bound on a slow one of these was the client's request_timeout. That is a client-side abort of the HTTP request, not a cancellation of the query: it tears down the socket after 30s and the caller gets an untyped socket timeout, with no indication of which query ran long or why. Whether the query itself stopped depended on ClickHouse noticing the dropped connection rather than on an explicit limit. After Both queries carry max_execution_time: 25. A query that runs long is terminated by ClickHouse itself at 25s and comes back as a real ClickHouse timeout error — typed, attributable to a named query, and raised before the client would have aborted. Queries that complete normally are entirely unaffected. How One-line change on each of the two registrations in internal-packages/clickhouse/src/index.ts: getTaskActivity: getTaskActivityQueryBuilder(this.reader, { max_execution_time: 25 }), getAverageDurations: getAverageDurations(this.reader, { max_execution_time: 25 }), Both builders already accepted an optional settings?: ClickHouseSettings second argument and forwarded it to ch.query({ ..., settings }), so no signature or plumbing changes were needed. Why 25 and not 10 The neighbouring existsQueryBuilder uses { max_execution_time: 10 }, but copying that value here would be a behaviour regression rather than a safeguard: any of these metrics queries that currently completes in the 10–30s window would start failing where today it succeeds. A cap that newly breaks working queries is worse than the problem it fixes. 25s was picked to sit just under the client timeout, verified rather than assumed: internal-packages/clickhouse/package.json depends on @clickhouse/client: ^1.12.1, resolved to 1.12.1 in pnpm-lock.yaml. That version's own config default is request_timeout: config.request_timeout ?? 30000 (@clickhouse/client-common/dist/config.js), i.e. 30s. request_timeout is not set anywhere in this repo — createClient in src/client/client.ts passes keep_alive, http_agent, compression, max_open_connections, clickhouse_settings and log, and nothing else — so the 30s default is what's in effect. So 25s is comfortably above normal latency for these queries, and comfortably below the 30s point at which the client would abort. The server wins the race, which is the whole point: ClickHouse enforces the limit and returns a typed error naming the query, instead of the client blindly tearing down a request. For reference, the repo already treats this as the pattern elsewhere — queryService.server.ts sets max_execution_time from QUERY_CLICKHOUSE_MAX_EXECUTION_TIME, and the logs client sets it from CLICKHOUSE_LOGS_LIST_MAX_EXECUTION_TIME. These two registrations were simply missed. One thing worth flagging for review: the client does set cancel_http_readonly_queries_on_client_close: 1, so on a clean socket teardown ClickHouse will usually cancel the query anyway. That mitigates the wasted-work half of the problem but not the error-quality half, and it makes termination contingent on connection handling rather than on an explicit server-side limit. An explicit cap is the more reliable of the two. Deliberately out of scope: the status skip-index / FINAL question on task_runs_v2. That is schema work and needs a schema owner; this PR is only the missing per-query cap. ✅ Checklist I have followed every step in the contributing guide The PR title follows the convention. I ran and tested the code works Testing pnpm run typecheck --filter @internal/clickhouse — passes. pnpm run typecheck --filter webapp — passes (the webapp is the consumer of these two registrations). pnpm run format and pnpm run lint:fix — clean, no changes produced. The client-timeout default was read out of the installed @clickhouse/client-common rather than assumed, and the repo was checked for any request_timeout override (there is none). Changelog Server-only change, so this carries a .server-changes/ note rather than a changeset: .server-changes/task-run-metrics-query-time-limit.md. Task metrics that take too long to load now stop with a clear error instead of hanging until the request gives up Screenshots No visual change. Generated by Claude Code
Open Graph Description: Requested via Slack thread Two of the task run metrics queries are registered with no clickhouseSettings, so they have no server-side max_execution_time — nothing tells ClickHouse to give up on the...
X Description: Requested via Slack thread Two of the task run metrics queries are registered with no clickhouseSettings, so they have no server-side max_execution_time — nothing tells ClickHouse to give up on the...
Opengraph URL: https://github.com/triggerdotdev/trigger.dev/pull/4381
X: @github
Domain: github.com
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react-reconciler,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@d5750093facf |
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:e99f22a5-6b52-ee94-470f-52a53fd2b240 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | DCC2:1C3CF5:860D1A:C67D1F:6AFAFB65 |
| html-safe-nonce | 6a48da8bb20c0c4cec8a5b97d3f76c6e8f6adce67461d58ea0321fb366a48c27 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEQ0MyOjFDM0NGNTo4NjBEMUE6QzY3RDFGOjZBRkFGQjY1IiwidmlzaXRvcl9pZCI6IjMxOTA0NzczOTkxOTU4NDM0MjkiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | b26ad2e6e9c2bb7061e4094cd9e041b80f8ebe601753b7a1cf2dce003c4365b1 |
| hovercard-subject-tag | pull_request:4137326534 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/triggerdotdev/trigger.dev/pull/4381/files |
| twitter:image | https://avatars.githubusercontent.com/in/1236702?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/in/1236702?s=400&v=4 |
| og:image:alt | Requested via Slack thread Two of the task run metrics queries are registered with no clickhouseSettings, so they have no server-side max_execution_time — nothing tells ClickHouse to give up on the... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 54f7a6886649661c85eee945cca0773566bfb4065370e0429b7c8f7204184650 |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/triggerdotdev/trigger.dev git https://github.com/triggerdotdev/trigger.dev.git |
| octolytics-dimension-user_id | 95297378 |
| octolytics-dimension-user_login | triggerdotdev |
| octolytics-dimension-repository_id | 572570113 |
| octolytics-dimension-repository_nwo | triggerdotdev/trigger.dev |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 572570113 |
| octolytics-dimension-repository_network_root_nwo | triggerdotdev/trigger.dev |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | cf8450eb633ec589502c42ff6f4072e40db65da3 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width