#3913·hatchet

UserSession table in Hatchet Postgres grows unboundedly from Bearer API requests

Author: luislee818Created May 14, 2026Updated Sep 30, 2026
Labelsaccepted

Problem

In our self-hosted Hatchet deployment, the UserSession table in the Hatchet Postgres instance has grown to 2.6M rows (~1 GB) over ~30 days.

SELECT count(*) FILTER (WHERE "userId" IS NULL), count(*) FILTER (WHERE "userId" IS NOT NULL)
FROM "UserSession";
-- 2,604,487 anonymous   |   9 with userId (4 real users)
  • ~1 row/sec sustained insertion rate, matching our REST API call volume.
  • Every row has userId = NULL, expiresAt = createdAt + 30d, createdAt == updatedAt (written once, never read again).
  • The only DELETE in pkg/repository/sqlcv1/users.sql is DeleteUserSession by id (explicit logout). Nothing purges by expiresAt. Tenant retention (SERVER_LIMITS_DEFAULT_TENANT_RETENTION_PERIOD) doesn't cover this table.

Likely cause

Bearer-authenticated REST requests (SDK calls, worker callbacks) appear to trip the cookie session middleware, which calls Save() → no cookie → fresh UserSession row inserted. Our setup: ALB OIDC for dashboard humans, Bearer tokens for SDK/workers — so essentially every row is from Bearer traffic.

Suggested fix

Skip cookie session creation for Bearer-authenticated requests, and/or add a periodic DELETE FROM "UserSession" WHERE "expiresAt" < NOW() to the retention cron.

Version: hatchet-lite:v0.82.3.