M1-audit: org approve can strand a request Approved with no tenant — retry impossible #93

Closed
opened 2026-11-07 08:40:57 +01:00 by amiryahaya · 1 comment
Owner

ApproveRequest.cs commits the Status flip FIRST (ExecuteUpdate, 33-38), then slug generation (409 on exhaustion, 49-50) and SaveChanges (409 'retry', 92-95) — but a retry hits 'already decided' (39-40). SaveChanges-failure variant leaves founder TenantId pointing at a tenant with no UserTenant Owner row. Audit-Log throw after commit 500s an operation that actually committed.

Fix: one transaction around flip+tenant+founder+membership (slug loop inside; unique failure = rollback → clean 409). Test: slug-collision + injected save failure.

Part of M1 closure audit #84.

ApproveRequest.cs commits the Status flip FIRST (ExecuteUpdate, 33-38), then slug generation (409 on exhaustion, 49-50) and SaveChanges (409 'retry', 92-95) — but a retry hits 'already decided' (39-40). SaveChanges-failure variant leaves founder TenantId pointing at a tenant with no UserTenant Owner row. Audit-Log throw after commit 500s an operation that actually committed. **Fix**: one transaction around flip+tenant+founder+membership (slug loop inside; unique failure = rollback → clean 409). Test: slug-collision + injected save failure. Part of M1 closure audit #84.
Author
Owner

Fixed in PR #116 (squash-merged as b0945c9). ApproveRequest wraps flip + slug + tenant + founder + membership + audit in ONE transaction — slug exhaustion or a mid-tx save failure rolls the Pending→Approved flip back; the request stays Pending and 'please retry' is actually possible. Audit moved inside the tx (no more 500-after-commit); notifications/email remain post-commit best-effort. Tests: slug-exhaustion (101 occupied slugs → 409, still Pending, founder untouched) + injected mid-transaction failure (409 → retry succeeds with exactly one Owner seat).

Fixed in PR #116 (squash-merged as b0945c9). ApproveRequest wraps flip + slug + tenant + founder + membership + audit in ONE transaction — slug exhaustion or a mid-tx save failure rolls the Pending→Approved flip back; the request stays Pending and 'please retry' is actually possible. Audit moved inside the tx (no more 500-after-commit); notifications/email remain post-commit best-effort. Tests: slug-exhaustion (101 occupied slugs → 409, still Pending, founder untouched) + injected mid-transaction failure (409 → retry succeeds with exactly one Owner seat).
Sign in to join this conversation.
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
primatekuntech/failsulit#93
No description provided.