Uh oh!
There was an error while loading. Please reload this page.
feat(db): role-keyed dbFor clients for cleanup and exec workloads - #5583
Conversation
The latest updates on your projects. Learn more about Vercel for GitHub.
|
PR SummaryMedium Risk Overview Cleanup path — background jobs ( Exec path — workflow execution log persistence, logging-session writes, snapshot upserts/reads, large-value registration/reference writes, and human-in-the-loop DB work use Tests and Reviewed by Cursor Bugbot for commit d106359. Bugbot is set up for automated code reviews on this repo. Configure here. |
TheodoreSpeaks
commented
Jul 11, 2026
@greptile review |
Greptile SummaryThis PR adds role-keyed database clients for cleanup and execution workloads. The main changes are:
Confidence Score: 5/5This looks safe to merge.
Important Files Changed
Reviews (8): Last reviewed commit: "feat(db): route pause/resume and large-v..." | Re-trigger Greptile |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
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 |
TheodoreSpeaks
commented
Jul 11, 2026
@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.
Uh oh!
There was an error while loading. Please reload this page.
TheodoreSpeaks
commented
Jul 11, 2026
@greptile review |
143b382 to
950746eCompareTheodoreSpeaks
commented
Jul 21, 2026
@greptile review |
TheodoreSpeaks
commented
Jul 22, 2026
@greptile review |
TheodoreSpeaks
commented
Jul 22, 2026
@greptile review |
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NNy9Fzpfc1FdHAzYyb6Ycy
…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
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
One line per role at first use: the dedicated DATABASE_URL_<ROLE> when set, otherwise an explicit fallback message naming the process connection it shares — so a missing/typo'd env var is visible at rollout instead of silent. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NNy9Fzpfc1FdHAzYyb6Ycy
…the exec pool
Coverage scan follow-up: the paused_executions / resume_queue /
workflow_execution_logs transactions in human-in-the-loop-manager.ts and the
large-value owner/reference registration writes on the execution path now use
dbFor('exec'), matching the completion writes in the execution logger. All are
self-contained; billing calls remain outside the moved transactions on the
default client.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NNy9Fzpfc1FdHAzYyb6Ycyfe5a9ce to
d106359CompareTheodoreSpeaks
commented
Jul 22, 2026
@greptile review |
Uh oh!
There was an error while loading. Please reload this page.

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