feat(db): role-keyed dbFor clients for cleanup and exec workloads#5583
feat(db): role-keyed dbFor clients for cleanup and exec workloads#5583TheodoreSpeaks wants to merge 3 commits into
Conversation
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NNy9Fzpfc1FdHAzYyb6Ycy
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
PR SummaryMedium Risk Overview Cleanup path: background jobs ( Exec path: Test mocks expose Reviewed by Cursor Bugbot for commit 143b382. Bugbot is set up for automated code reviews on this repo. Configure here. |
|
@greptile review |
Greptile SummaryThis PR adds role-specific database clients for cleanup and execution workloads. The main changes are:
Confidence Score: 5/5This looks safe to merge.
Important Files Changed
Reviews (4): Last reviewed commit: "fix(db): dbFor falls back to the process..." | Re-trigger Greptile |
Greptile SummaryThis PR adds workload-specific database clients for cleanup and execution logging. The main changes are:
Confidence Score: 5/5This looks safe to merge.
Important Files Changed
Reviews (2): Last reviewed commit: "feat(db): role-keyed dbFor clients for c..." | Re-trigger Greptile |
…e pools Route markLargeValuesDeleted / pruneLargeValueMetadata (optional dbClient) and chat-cleanup's file collection through the cleanup pool, and getSnapshot through the exec pool, so the cleanup and inline-execution workloads stop borrowing the process-wide pool for these queries. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NNy9Fzpfc1FdHAzYyb6Ycy
|
@greptile review |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit c7ac96b. Configure here.
With DATABASE_URL_WEB/TRIGGER set (as in prod) and the sub-pool URLs unset, falling back to the base URL would silently shift execution-log and cleanup traffic to a different PgBouncer endpoint on deploy. Chain the fallback through the URL the process itself resolved so the rollout stays inert. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NNy9Fzpfc1FdHAzYyb6Ycy
|
@greptile review |

Summary
cleanupandexecentries toDB_POOL_PROFILESand a lazy, per-role-cacheddbFor('cleanup' | 'exec')factory in@sim/db— sub-process pools selected per call-site, for workloads that live inside an existing process: cleanup jobs run in the trigger.dev worker, inline execution log writes run in the Next.js web server.SIM_DB_ROLEremains restricted toweb/trigger/realtime.dbForresolvesDATABASE_URL_CLEANUP/DATABASE_URL_EXECwith fallback to the baseDATABASE_URL, so today these clients hit the same Postgres with their own local pool.DB_APP_NAMEdoes not leak into them — they always report their profileappName(sim-cleanup/sim-exec). Both are tripwire-instrumented (instrumentPoolClient) with the role as the pool label.background/cleanup-logs.ts,cleanup-soft-deletes.ts, andcleanup-tasks.tsrun all their queries ondbFor('cleanup'); thelib/cleanup/batch-delete.tshelpers now accept an optionaldbClient(default: globaldb, so other consumers are unchanged).snapshotService.cleanupOrphanedSnapshots(only invoked from cleanup-logs) also moved to the cleanup pool.lib/logs/execution/logger.ts(idempotency read, start INSERT, the self-contained completion transaction,getWorkflowExecution), allworkflow_execution_logswrites inlogging-session.ts(progress-marker fallback UPDATEs, status reads,markExecutionAsFailed), and the workflow-state snapshot upsert insnapshot/service.tsrun ondbFor('exec'). Billing/usage-ledger work (advisory-lock reconcile transaction, subscription/org lookups, PII-settings read) deliberately stays on the default client.databaseMock/dbChainMockin@sim/testingexposedbForreturning the shared mock instance; local@sim/dbmocks in the touched suites updated the same way.Type of Change
Testing
packages/db:tsc --noEmitclean; vitest 24/24 (tx-tripwire + connection-url).apps/sim:tsc --noEmit— no new errors (one pre-existing error inproviders/meta/index.tsexists on cleanorigin/staging).lib/logs/execution/**(191 tests), plus every other suite that locally mocks@sim/dband transitively imports the touched modules (66 tests) — all passing.bun run lint:checkandbun run check:api-validation:strictpass.Checklist
🤖 Generated with Claude Code
https://claude.ai/code/session_01NNy9Fzpfc1FdHAzYyb6Ycy