Skip to content

feat(backend): track first organization onboarding in Bento - #2841

Merged
WcaleNieWolny merged 19 commits into
mainfrom
wolny/bento-first-org-lifecycle
Aug 4, 2026
Merged

feat(backend): track first organization onboarding in Bento#2841
WcaleNieWolny merged 19 commits into
mainfrom
wolny/bento-first-org-lifecycle

Conversation

@WcaleNieWolny

@WcaleNieWolny WcaleNieWolny commented Aug 3, 2026

Copy link
Copy Markdown
Member

Summary

  • mark future direct registrations that still have no active organization access with onboarding:awaiting_first_org and emit user:registered_without_org
  • atomically clear awaiting state and add permanent recovery suppression when active direct organization access appears, then emit user:joined_org
  • permanently suppress recovery for normalized email changes so a queued message cannot be sent to the wrong address
  • permanently suppress and unsubscribe deletion-scheduled users with abortable, ordered Bento requests while allowing Stripe, organization, and image cleanup to proceed independently
  • route organization-access changes through the existing pgmq trigger/consumer system and document the Bento workflow guard

Safety and rollout

  • Capgo's database remains the source of truth: registration and role-binding handlers reconcile deletion state after every terminal Bento tag/event, including ambiguous delivery failures, before propagating any retryable error.
  • Bento subscriber imports are asynchronous, so every terminal organization-access transition adds monotonic suppression in the same update that removes awaiting state; malformed or short provider acknowledgements fail closed and retry.
  • Default API-key provisioning is serialized with account deletion and rejects deletion-scheduled users inside the same database transaction.
  • Invited registrations and users who already have active direct organization access are not enrolled.
  • This is prospective only: there is no backfill and no existing subscriber is enrolled by this PR.
  • The database migration may deploy before the Cloudflare route. That ordering is safe for this prospective cohort because tag creation and the join handler activate together in the same worker deployment; role-binding messages from before that activation cannot strand a newly tagged subscriber.
  • This PR does not enable or edit a Bento workflow. Before enabling the non-transactional recovery email, its final pre-send branch must require onboarding:awaiting_first_org and reject both onboarding:first_org_recovery_suppressed and onboarding_disabled.

Verification

  • TZ=UTC bun test:unit — 1,323 passed
  • bun lint
  • bun lint:backend
  • bun typecheck:backend
  • bash scripts/check-supabase-migration-order.sh
  • clean bun run supabase:db:reset
  • bun scripts/supabase-worktree.ts test db — 816 passed
  • SQLFluff on the new migration and pgTAP test
  • bun scripts/supabase-worktree.ts db lint -s public --fail-on warning
  • production Cloudflare worker wrangler deploy --dry-run --env=prod

@coderabbitai

coderabbitai Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds Bento first-organization recovery handling for user creation, email changes, deletion, and direct organization access. Adds queue delivery, authenticated trigger routes, deletion/API-key race protection, tests, and Bento setup guidance.

Changes

First-organization recovery lifecycle

Layer / File(s) Summary
Bento lifecycle synchronization
supabase/functions/_backend/utils/bento_first_org.ts, supabase/functions/_backend/utils/bento.ts, supabase/functions/_backend/utils/stripe.ts, tests/bento-first-org-lifecycle.unit.test.ts, tests/bento-abort-signal.unit.test.ts
Adds lifecycle state, eligibility checks, email normalization, suppression sequencing, reconciliation, abort handling, and aggregate subscription-cancellation results.
User lifecycle integration
supabase/functions/_backend/triggers/on_user_create.ts, supabase/functions/_backend/triggers/on_user_update.ts, supabase/functions/_backend/triggers/on_user_delete.ts, tests/bento-first-org-lifecycle.unit.test.ts, tests/on-user-delete-bento.unit.test.ts
Connects Bento synchronization to user creation, email changes, and deletion. Tests cover lifecycle events, cleanup ordering, timeouts, retries, and unconfigured Bento.
Role-binding queue transport
supabase/migrations/..., supabase/tests/66_test_on_user_org_access_queue.sql
Queues qualifying direct organization bindings, validates cron configuration, and tests filtering, updates, envelopes, and delete behavior.
Trigger and route integration
supabase/functions/_backend/triggers/on_user_org_access.ts, supabase/functions/triggers/index.ts, cloudflare_workers/api/index.ts, supabase/functions/_backend/utils/hono.ts, tests/bento-first-org-route.unit.test.ts
Adds authenticated role-binding webhook validation and registers the route in Supabase and Cloudflare trigger routers.
Safety checks and validation
supabase/functions/_backend/utils/supabase.ts, tests/create-api-key-deletion-race.unit.test.ts, tests/on-user-update-bento.unit.test.ts, tests/user-preference-bento-tags.unit.test.ts, docs/BENTO_EMAIL_PREFERENCES_SETUP.md
Blocks API-key creation for scheduled deletions. Tests race handling, update sequencing, suppression tags, route validation, cleanup behavior, and workflow configuration.

Estimated code review effort: 4 (Complex) | ~60 minutes

Suggested labels: codex

Sequence Diagram(s)

sequenceDiagram
  participant UserTrigger
  participant BentoFirstOrg
  participant PostgreSQL
  participant Bento
  UserTrigger->>BentoFirstOrg: process user lifecycle event
  BentoFirstOrg->>PostgreSQL: query eligibility and organization access
  PostgreSQL-->>BentoFirstOrg: return registration state
  BentoFirstOrg->>Bento: update tags and emit lifecycle event
Loading
sequenceDiagram
  participant role_bindings
  participant Queue
  participant on_user_org_access
  participant BentoFirstOrg
  participant Bento
  role_bindings->>Queue: enqueue qualifying access change
  Queue->>on_user_org_access: deliver role-binding webhook
  on_user_org_access->>BentoFirstOrg: synchronize role-binding access
  BentoFirstOrg->>Bento: remove awaiting tag and emit join event
Loading
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly and concisely describes the main change: tracking first-organization onboarding in Bento.
Description check ✅ Passed The description clearly covers the change, safety, rollout, and verification; screenshots are not needed for this backend-only PR.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch

Comment @coderabbitai help to get the list of available commands.

@codspeed-hq

codspeed-hq Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 43 untouched benchmarks
⏩ 2 skipped benchmarks1


Comparing wolny/bento-first-org-lifecycle (476cade) with main (c294277)

Open in CodSpeed

Footnotes

  1. 2 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 13 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread supabase/functions/_backend/triggers/on_user_update.ts Outdated
Comment thread supabase/functions/_backend/triggers/on_user_update.ts Outdated
Comment thread supabase/functions/_backend/triggers/on_user_org_access.ts Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 13

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@docs/BENTO_EMAIL_PREFERENCES_SETUP.md`:
- Around line 75-90: Update the “First-Organization Recovery” documentation to
explicitly name user:joined_org as the exit or goal event emitted when active
direct organization access is established. Keep the existing
user:registered_without_org entry event and tag-removal behavior, and clarify
that operators should configure this event in the workflow.

In `@supabase/functions/_backend/triggers/on_user_create.ts`:
- Line 19: Update the on_user_create flow around syncBentoFirstOrgOnUserCreate
so Bento delivery failures are caught and logged without propagating an HTTP 500
or triggering queue_consumer retries. Keep this handling after core user
provisioning completes, and preserve the existing provisioning behavior.

In `@supabase/functions/_backend/triggers/on_user_org_access.ts`:
- Around line 6-27: The role-binding webhook currently performs ad hoc
table/type checks and does not validate the webhook ID format. Extend
triggerValidator to allow both INSERT and UPDATE events, apply it to
role_bindings in the app.post handler, then validate c.get('webhookBody').id as
a UUID before calling syncBentoFirstOrgOnRoleBindingWrite; retain separate UUID
validation because triggerValidator does not validate field types.

In `@supabase/functions/_backend/triggers/on_user_update.ts`:
- Around line 26-27: Update the email normalization in the user-update handler
to safely accept null or undefined record.email, and reuse the exported
normalizedEmail helper from utils/bento_first_org.ts for both newEmail and
oldEmail instead of duplicating trim/lowercase logic. Preserve the nullable
email values passed to syncUserPreferenceTags.

In `@supabase/functions/_backend/utils/bento_first_org.ts`:
- Around line 54-74: Update the cleanup calls in hasActiveDirectOrgAccess and
syncBentoFirstOrgOnUserCreate to use pgClient.release() after normal query
execution, replacing release(true). Only pass a truthy argument when a client is
unusable or must be destroyed, while preserving cleanup for both helper
invocations.
- Around line 15-25: Update the CurrentRoleBinding.granted_at type to match the
pg query result by using Date, or explicitly cast role_bindings.granted_at to a
string in SQL if downstream code requires string values; keep the selected data
and JSON serialization behavior consistent.
- Around line 94-106: Make the first-org event handling idempotent across queue
retries by adding a durable, atomic claim keyed by user.id for registration
events and role_binding_id for joined-org events, or by passing a
Bento-supported unique key to trackBentoEvent. Update the relevant handler flow
around setAwaitingFirstOrgTag and trackBentoEvent so the claim is recorded
before delivery and repeated retries skip already-claimed events while
preserving the existing tag behavior.

In `@supabase/migrations/20260803161022_on_user_org_access_queue.sql`:
- Around line 29-48: Update the WHEN clause of the on_user_org_access trigger to
compare OLD and NEW qualification states, so it executes only when a
role_bindings row transitions into the qualifying user/org/direct/non-expired
state. Preserve inserts as qualifying while preventing re-enqueueing for updates
that remain qualifying, including expiry extensions and org changes.
- Around line 50-57: Update the cron_tasks UPDATE statement in the migration to
capture its affected-row count and fail the migration when no row is updated.
Preserve the existing name, task_type, and target conditions, and ensure the
failure occurs before queue creation or message enqueueing proceeds.

In `@tests/bento-first-org-lifecycle.unit.test.ts`:
- Around line 251-269: Rename the test case around postUser to describe the
access-check query contract it actually verifies, since it does not seed or
return an expired invitation row. Keep the existing assertions for the generated
query text, parameters, lifecycle tag, and event count unchanged.

In `@tests/bento-first-org-route.unit.test.ts`:
- Around line 105-129: Extend the validation tests around requestPayload to
cover object payloads with a non-role_bindings table, an unsupported type, and a
missing record.id. Assert each returns status 400 with the corresponding
table_not_match, type_not_match, or missing-id validation error, and verify
syncBentoFirstOrgOnRoleBindingWriteMock is not called.
- Around line 131-135: Update the test “registers the same route in the Supabase
trigger router” to import the trigger router from
supabase/functions/triggers/index.ts and assert the /on_user_org_access route
through its registered behavior or route table rather than matching source text.
Remove the unused readFile import; if the router cannot be imported in this
environment, retain the source check and document that constraint in a comment.

In `@tests/user-preference-bento-tags.unit.test.ts`:
- Around line 64-72: Normalize each recorded argument from
syncBentoSubscriberTagsMock before asserting: handle both a single update object
and an array of updates, then iterate over the resulting update objects and
verify their segments and deleteSegments exclude SUPPRESSION_TAG. Remove the
unsafe single-object cast and follow the normalization pattern used in
bento-first-org-lifecycle.unit.test.ts.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: c5297e5a-17f4-4214-8c7b-19871d850cab

📥 Commits

Reviewing files that changed from the base of the PR and between d3c7974 and 56cd6e1.

📒 Files selected for processing (13)
  • cloudflare_workers/api/index.ts
  • docs/BENTO_EMAIL_PREFERENCES_SETUP.md
  • supabase/functions/_backend/triggers/on_user_create.ts
  • supabase/functions/_backend/triggers/on_user_org_access.ts
  • supabase/functions/_backend/triggers/on_user_update.ts
  • supabase/functions/_backend/utils/bento_first_org.ts
  • supabase/functions/triggers/index.ts
  • supabase/migrations/20260803161022_on_user_org_access_queue.sql
  • supabase/tests/66_test_on_user_org_access_queue.sql
  • tests/bento-first-org-lifecycle.unit.test.ts
  • tests/bento-first-org-route.unit.test.ts
  • tests/on-user-update-bento.unit.test.ts
  • tests/user-preference-bento-tags.unit.test.ts
🔗 Linked repositories identified

CodeRabbit considers these linked repositories for cross-repo context during reviews:

  • Cap-go/capacitor-updater (manual)

Comment thread docs/BENTO_EMAIL_PREFERENCES_SETUP.md
Comment thread supabase/functions/_backend/triggers/on_user_create.ts
Comment thread supabase/functions/_backend/triggers/on_user_org_access.ts Outdated
Comment thread supabase/functions/_backend/triggers/on_user_update.ts Outdated
Comment thread supabase/functions/_backend/utils/bento_first_org.ts
Comment thread supabase/migrations/20260803161022_on_user_org_access_queue.sql Outdated
Comment thread tests/bento-first-org-lifecycle.unit.test.ts Outdated
Comment thread tests/bento-first-org-route.unit.test.ts
Comment thread tests/bento-first-org-route.unit.test.ts
Comment thread tests/user-preference-bento-tags.unit.test.ts

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 4 files (changes from recent commits).

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread supabase/functions/_backend/triggers/on_user_update.ts

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 12 files (changes from recent commits).

Tip: Review your code locally with the cubic CLI to iterate faster.

Re-trigger cubic

Comment thread tests/bento-first-org-route.unit.test.ts Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@supabase/functions/_backend/triggers/on_user_create.ts`:
- Around line 19-21: Rename prepareBentoFirstOrgOnUserCreate to a name
describing the broader user-provisioning eligibility decision, such as
shouldProvisionNewUser or prepareUserProvisioning, and update its declaration
and all call sites, including the shouldProvisionUser flow. Preserve the
existing gating of createApiKey and preference-tag synchronization.

In `@supabase/functions/_backend/triggers/on_user_delete.ts`:
- Around line 334-338: Update deleteUser and finishDeleteUserResponse so the
final status reflects both Bento cleanup and cleanupDeletedUserResources
outcomes. Make cleanupDeletedUserResources propagate RBAC, organization lookup,
and resource cleanup failures instead of returning silently, and pass that
result into finishDeleteUserResponse so failed Stripe/resource cleanup triggers
a retry while successful cleanup returns 200.

In `@supabase/functions/_backend/triggers/on_user_org_access.ts`:
- Line 3: Replace direct Hono construction in the trigger app with the shared
createHono factory, calling createHono('', version) and removing the Hono
import. Preserve the existing trigger routes and middleware behavior.

In `@supabase/functions/_backend/utils/supabase.ts`:
- Around line 797-803: Set a transaction-local lock_timeout immediately after
BEGIN in the transaction setup around pgClient and before any FOR UPDATE query,
using the existing pgClient.query flow. Keep the timeout scoped to this
transaction so competing delete_user() locks fail promptly without affecting
other pooled connections or transactions.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: bdfae13f-7752-44d0-a7e7-f0cb963e88e9

📥 Commits

Reviewing files that changed from the base of the PR and between 56cd6e1 and 15f704b.

📒 Files selected for processing (16)
  • docs/BENTO_EMAIL_PREFERENCES_SETUP.md
  • supabase/functions/_backend/triggers/on_user_create.ts
  • supabase/functions/_backend/triggers/on_user_delete.ts
  • supabase/functions/_backend/triggers/on_user_org_access.ts
  • supabase/functions/_backend/triggers/on_user_update.ts
  • supabase/functions/_backend/utils/bento_first_org.ts
  • supabase/functions/_backend/utils/hono.ts
  • supabase/functions/_backend/utils/supabase.ts
  • supabase/migrations/20260803161022_on_user_org_access_queue.sql
  • supabase/tests/66_test_on_user_org_access_queue.sql
  • tests/bento-first-org-lifecycle.unit.test.ts
  • tests/bento-first-org-route.unit.test.ts
  • tests/create-api-key-deletion-race.unit.test.ts
  • tests/on-user-delete-bento.unit.test.ts
  • tests/on-user-update-bento.unit.test.ts
  • tests/user-preference-bento-tags.unit.test.ts
🔗 Linked repositories identified

CodeRabbit considers these linked repositories for cross-repo context during reviews:

  • Cap-go/capacitor-updater (manual)

Comment thread supabase/functions/_backend/triggers/on_user_create.ts Outdated
Comment thread supabase/functions/_backend/triggers/on_user_delete.ts Outdated
Comment thread supabase/functions/_backend/triggers/on_user_org_access.ts Outdated
Comment thread supabase/functions/_backend/utils/supabase.ts

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 16 files (changes from recent commits).

Tip: Review your code locally with the cubic CLI to iterate faster.

Re-trigger cubic

Comment thread supabase/functions/_backend/utils/bento_first_org.ts Outdated
Comment thread supabase/functions/_backend/triggers/on_user_delete.ts
Comment thread supabase/functions/_backend/triggers/on_user_create.ts Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
supabase/functions/_backend/utils/bento_first_org.ts (1)

132-148: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Keep the previous export as a compatibility alias.

Line 132 replaces the exported prepareBentoFirstOrgOnUserCreate symbol. Existing importers will fail at module load. Keep a deprecated alias to prepareNewUserProvisioning until consumers migrate.

Proposed compatibility alias
 export async function prepareNewUserProvisioning(
   c: Context<MiddlewareKeyVariables>,
   user: Database['public']['Tables']['users']['Row'],
 ) {
   // ...
 }
+
+export const prepareBentoFirstOrgOnUserCreate = prepareNewUserProvisioning

As per coding guidelines, “Public API and plugin changes must remain backward compatible: do not remove or change existing fields, meanings, formats, or status codes.”

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@supabase/functions/_backend/utils/bento_first_org.ts` around lines 132 - 148,
Preserve the existing exported prepareBentoFirstOrgOnUserCreate symbol as a
deprecated compatibility alias for prepareNewUserProvisioning, while retaining
the new function export and behavior. Ensure existing importers can continue
resolving the previous name until they migrate.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@supabase/functions/_backend/utils/bento_first_org.ts`:
- Around line 132-148: Preserve the existing exported
prepareBentoFirstOrgOnUserCreate symbol as a deprecated compatibility alias for
prepareNewUserProvisioning, while retaining the new function export and
behavior. Ensure existing importers can continue resolving the previous name
until they migrate.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: f9d81cf4-6d06-4953-933a-e69ae0f56608

📥 Commits

Reviewing files that changed from the base of the PR and between 15f704b and 335af5b.

📒 Files selected for processing (9)
  • supabase/functions/_backend/triggers/on_user_create.ts
  • supabase/functions/_backend/triggers/on_user_delete.ts
  • supabase/functions/_backend/triggers/on_user_org_access.ts
  • supabase/functions/_backend/utils/bento_first_org.ts
  • supabase/functions/_backend/utils/stripe.ts
  • supabase/functions/_backend/utils/supabase.ts
  • tests/bento-first-org-lifecycle.unit.test.ts
  • tests/create-api-key-deletion-race.unit.test.ts
  • tests/on-user-delete-bento.unit.test.ts
🔗 Linked repositories identified

CodeRabbit considers these linked repositories for cross-repo context during reviews:

  • Cap-go/capacitor-updater (manual)

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 9 files (changes from recent commits).

Tip: Review your code locally with the cubic CLI to iterate faster.

Re-trigger cubic

Comment thread tests/bento-first-org-lifecycle.unit.test.ts

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 5 files (changes from recent commits).

Tip: Review your code locally with the cubic CLI to iterate faster.

Re-trigger cubic

Comment thread supabase/functions/_backend/utils/bento_first_org.ts Outdated
Comment thread tests/bento-first-org-lifecycle.unit.test.ts

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@supabase/functions/_backend/utils/bento_first_org.ts`:
- Around line 163-186: Update runBentoMutationWithFirstOrgReconciliation to
preserve the original mutate failure when
reconcileFirstOrgStateAfterBentoMutation also throws. Ensure reconciliation
errors do not replace mutationError; retain the existing behavior of rethrowing
the mutation error after successful reconciliation while exposing or chaining
both failures when reconciliation fails.

In `@tests/on-user-delete-bento.unit.test.ts`:
- Around line 220-281: The hanging-operation tests should derive their timer
advancement from the production timeout instead of using the literal 2_001.
Export BENTO_DELETED_USER_OPERATION_TIMEOUT_MS from bento_first_org.ts, import
it into these tests, and replace both advanceTimersByTimeAsync calls with
BENTO_DELETED_USER_OPERATION_TIMEOUT_MS + 1.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 7d7e9307-722e-4e91-b5ff-d303409d2e62

📥 Commits

Reviewing files that changed from the base of the PR and between 335af5b and f24c3c1.

📒 Files selected for processing (6)
  • docs/BENTO_EMAIL_PREFERENCES_SETUP.md
  • supabase/functions/_backend/triggers/on_user_delete.ts
  • supabase/functions/_backend/utils/bento.ts
  • supabase/functions/_backend/utils/bento_first_org.ts
  • tests/bento-first-org-lifecycle.unit.test.ts
  • tests/on-user-delete-bento.unit.test.ts
🔗 Linked repositories identified

CodeRabbit considers these linked repositories for cross-repo context during reviews:

  • Cap-go/capacitor-updater (manual)

Comment thread supabase/functions/_backend/utils/bento_first_org.ts
Comment thread tests/on-user-delete-bento.unit.test.ts
@sonarqubecloud

sonarqubecloud Bot commented Aug 3, 2026

Copy link
Copy Markdown

@WcaleNieWolny
WcaleNieWolny merged commit 8e691db into main Aug 4, 2026
122 of 123 checks passed
@WcaleNieWolny
WcaleNieWolny deleted the wolny/bento-first-org-lifecycle branch August 4, 2026 06:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant