Skip to content

feat(rls): Phase 1 #7 — HeartbeatConfig RLS + callsite fixes#135

Merged
webdevcom01-cell merged 1 commit into
mainfrom
feat/rls-phase1-heartbeatconfig
May 24, 2026
Merged

feat(rls): Phase 1 #7 — HeartbeatConfig RLS + callsite fixes#135
webdevcom01-cell merged 1 commit into
mainfrom
feat/rls-phase1-heartbeatconfig

Conversation

@webdevcom01-cell
Copy link
Copy Markdown
Owner

Summary

  • Migration 20260601000000_rls_phase1_heartbeatconfig: TENANT_DIRECT RLS on HeartbeatConfig (SELECT/INSERT/UPDATE/DELETE policies + composite organizationId, id index)
  • BullMQ worker (heartbeat-worker.ts): wraps heartbeatConfig.findUnique in withOrgContext(prisma, organizationId, …) using explicit organizationId from job.data — ALS is empty in BullMQ workers (confirmed in Migration chore(deps): bump node from 20-alpine to 25-alpine #3 audit)
  • Scheduler (heartbeat-scheduler.ts): scheduleHeartbeat and unscheduleHeartbeat gain organizationId: string | null param; all heartbeatConfig reads/writes wrapped with withOrgContext
  • Route (/api/agents/[agentId]/heartbeat): GET and DELETE fetch organizationId via separate agent lookup (same pattern as permissions route); POST uses organizationId from validated body
  • Template engine: exportTemplate wraps agent+include query in withOrgContext to prevent silent null on heartbeatConfig include under RLS; importTemplate wraps heartbeatConfig.create

Test plan

  • pnpm precheck — 4/4 pass (TypeScript, vitest 4119 tests, lucide mocks, placeholder strings) ✅
  • CI green
  • E2E: existing JWTSessionError flake is pre-existing — ignore
  • After merge: apply migration to Railway prod DB, verify heartbeat config still readable with RLS flag off
  • Flag-on smoke: RLS_ENFORCEMENT_ENABLED=true in test org — POST heartbeat config, confirm no 42501

RLS state after this PR

Phase 1: 7/14 live — OrganizationMember, Invitation, CompanyMission, Department, Goal, AgentPermissionGrant, HeartbeatConfig

🤖 Generated with Claude Code

Migration 20260601000000: TENANT_DIRECT RLS on HeartbeatConfig.
BullMQ worker uses explicit organizationId from job.data (ALS empty in workers).
Scheduler functions gain organizationId param; route and template engine wrapped.
@webdevcom01-cell webdevcom01-cell added the e2e Run E2E tests on this PR label May 24, 2026
@webdevcom01-cell webdevcom01-cell merged commit 4ed3232 into main May 24, 2026
6 of 12 checks passed
@webdevcom01-cell webdevcom01-cell deleted the feat/rls-phase1-heartbeatconfig branch May 24, 2026 07:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

e2e Run E2E tests on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant