Skip to content

Fix: Attempt at improving worker actions query#3774

Open
mrkaye97 wants to merge 14 commits into
mainfrom
mk/worker-page
Open

Fix: Attempt at improving worker actions query#3774
mrkaye97 wants to merge 14 commits into
mainfrom
mk/worker-page

Conversation

@mrkaye97
Copy link
Copy Markdown
Contributor

@mrkaye97 mrkaye97 commented Apr 28, 2026

Description

Lots of slow traces, which I think are happening because we're pulling a ton of rows down out of the db. I figured we could hash the action names and store them with the worker, and then try to only look up actions for each hash once, and then map them back to the relevant worker that way, which should cut down the number of rows we need to pull out of the db by a factor of the number of replicas of a worker any given tenant has

Unfortunately we can't make the action hash non-null and backfill so we need to also have a lookup by worker id for backwards compat for now

Type of change

  • Bug fix (non-breaking change which fixes an issue)

@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 28, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
hatchet-docs Ready Ready Preview, Comment May 7, 2026 8:59pm

Request Review

Comment thread pkg/repository/sqlcv1/workers.sql Outdated
;

-- name: GetWorkerActionsByWorkerActionHash :many
SELECT DISTINCT ON (w."actionHash")
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

goal here is we'll just move to this completely in a little bit, once all the workers have hashes

@mrkaye97 mrkaye97 marked this pull request as ready for review April 28, 2026 22:05
Copilot AI review requested due to automatic review settings April 28, 2026 22:05
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR aims to reduce slow traces in the worker actions lookup path by adding an actionHash to workers and using it to de-duplicate action lookups across identical worker replicas, falling back to worker-id lookups for backward compatibility.

Changes:

  • Add Worker.actionHash (BYTEA) plus a (tenantId, actionHash) index (schema + migrations).
  • Introduce a new repository method to fetch worker actions using action-hash de-duplication with worker-id fallback.
  • Update worker list/get handlers to call the new repository API and pass full worker rows.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
sql/schema/v0.sql Adds actionHash column and a (tenantId, actionHash) index to the baseline schema.
cmd/hatchet-migrate/migrate/migrations/20260428204451_v1_0_103.sql Adds the actionHash column for existing installations.
cmd/hatchet-migrate/migrate/migrations/20260428213451_v1_0_104.sql Adds the (tenantId, actionHash) index concurrently for existing installations.
pkg/repository/worker.go Implements action-hash-based action lookup and hashes actions on worker creation.
pkg/repository/sqlcv1/workers.sql Updates worker-actions queries and adds a new query by actionHash.
pkg/repository/sqlcv1/workers.sql.go Regenerated sqlc output for updated queries/columns.
pkg/repository/sqlcv1/models.go Adds ActionHash field to the Worker model.
api/v1/server/handlers/workers/list.go Uses the new worker-actions repository method and passes worker rows.
api/v1/server/handlers/workers/get.go Uses the new worker-actions repository method for single-worker fetch.

Comment thread pkg/repository/sqlcv1/workers.sql Outdated
Comment thread pkg/repository/worker.go
Comment thread pkg/repository/worker.go
Comment thread pkg/repository/worker.go Outdated
Comment thread pkg/repository/worker.go Outdated
Comment thread pkg/repository/sqlcv1/workers.sql Outdated
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.

2 participants