feat(rls): Phase 1 #9 — HeartbeatRun RLS + callsite fixes#137
Merged
Conversation
Migration 20260603000000: TENANT_DIRECT RLS on HeartbeatRun. Worker wraps all 4 heartbeatRun ops individually (create + 3 updates) with withOrgContext using job.data.organizationId — ops span the full job lifetime so no batch transaction is feasible. Route wraps findMany via agent org lookup.
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.
Summary
20260603000000_rls_phase1_heartbeatrun: TENANT_DIRECT RLS onHeartbeatRun(SELECT/INSERT/UPDATE/DELETE policies + compositeorganizationId, idindex)heartbeat-worker.ts): wraps all 4heartbeatRunops individually withwithOrgContext(prisma, organizationId, …)usingjob.data.organizationId— ALS empty in workers. No batch transaction possible: ops span the full job lifetime withexecuteFlowbetween them (potentially minutes)/api/agents/[agentId]/heartbeat/runs): agent lookup fororgId,findManywrapped inwithOrgContextHot-path analysis
"Append-only" per runbook = one row per job (not bulk inserts). Lifecycle per job:
createRUNNINGupdateFAILEDupdateCOMPLETEDupdateFAILED.catch()— non-critical)Ops are separated by
executeFlow(can take 30s+) — cannot be batched into one$transaction. Four individualwithOrgContextcalls is the correct approach here (unlike #8 where HeartbeatContext ops were adjacent).ALS per callsite
runs/route.tsGETwithOrgContextheartbeat-worker.tscreatejob.data.organizationIdwithOrgContextheartbeat-worker.tsupdate ×3job.data.organizationIdwithOrgContexteachTest plan
pnpm precheck— 4/4 pass ✅RLS state after this PR
Phase 1: 9/14 live — OrganizationMember, Invitation, CompanyMission, Department, Goal, AgentPermissionGrant, HeartbeatConfig, HeartbeatContext, HeartbeatRun
🤖 Generated with Claude Code