codeant-ai-for-open-source[bot] commented on code in PR #42863:
URL: https://github.com/apache/superset/pull/42863#discussion_r3735765649


##########
superset/commands/deletion_retention/audit.py:
##########
@@ -182,6 +197,146 @@ def block(record_id: UUID | None) -> None:
     finalize(record_id, STATUS_BLOCKED)
 
 
+def _capture_recovery_snapshot(record: PurgeAuditLog) -> 
_AuditRecoverySnapshot:
+    """Capture the content-free fields needed for fail-safe recovery."""
+    return _AuditRecoverySnapshot(
+        id=cast(UUID, record.id),
+        actor=str(record.actor),
+        entity_type=str(record.entity_type),
+        entity_uuid=record.entity_uuid,
+        created_on=cast(datetime, record.created_on),
+    )
+
+
+def _retention_predecessor(
+    session: Session, current: PurgeAuditLog
+) -> PurgeAuditLog | None:
+    """Return the latest row that could unambiguously precede ``current``."""
+    return session.execute(
+        sa.select(PurgeAuditLog)
+        .where(PurgeAuditLog.entity_uuid == current.entity_uuid)
+        .where(PurgeAuditLog.entity_type == current.entity_type)
+        .where(PurgeAuditLog.trigger == TRIGGER_RETENTION)
+        .where(PurgeAuditLog.created_on <= current.created_on)
+        .where(PurgeAuditLog.id != current.id)
+        .order_by(PurgeAuditLog.created_on.desc())
+        .limit(1)
+    ).scalar_one_or_none()

Review Comment:
   **Suggestion:** The predecessor status is read in a separate query before 
the current row is deleted or retained, without locking or an atomic claim. If 
the predecessor is still `pending` when `_retention_predecessor` reads it but 
is finalized as `blocked` before `_suppress_redundant_block` runs, this 
evaluation retains its own row even though it is now a consecutive redundant 
blocker. Concurrent scheduled workers can therefore leave duplicate blocked 
audit records, defeating the deduplication behavior. Serialize the predecessor 
decision with the finalization or use an atomic database operation that 
rechecks the predecessor state. [race condition]
   
   <details>
   <summary><b>Severity Level:</b> Major ⚠️</summary>
   
   ```mdx
   - ⚠️ Overlapping retention workers can preserve duplicate blocked audits.
   - ⚠️ Deduplication metrics and audit-history bounds become inaccurate.
   ```
   </details>
   
   [![Fix in 
Cursor](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-cursor-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=b11d92f11f1a45fdb89b76b911f1abd6&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
 [![Fix in VSCode 
Claude](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-vscode-claude-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=b11d92f11f1a45fdb89b76b911f1abd6&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
   
   *(Use Cmd/Ctrl + Click for best experience)*
   <details>
   <summary><b>Prompt for AI Agent 🤖 </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** superset/commands/deletion_retention/audit.py
   **Line:** 215:224
   **Comment:**
        *Race Condition: The predecessor status is read in a separate query 
before the current row is deleted or retained, without locking or an atomic 
claim. If the predecessor is still `pending` when `_retention_predecessor` 
reads it but is finalized as `blocked` before `_suppress_redundant_block` runs, 
this evaluation retains its own row even though it is now a consecutive 
redundant blocker. Concurrent scheduled workers can therefore leave duplicate 
blocked audit records, defeating the deduplication behavior. Serialize the 
predecessor decision with the finalization or use an atomic database operation 
that rechecks the predecessor state.
   
   Validate the correctness of the flagged issue. If correct, How can I resolve 
this? If you propose a fix, implement it and please make it concise.
   Once fix is implemented, also check other comments on the same PR, and ask 
user if the user wants to fix the rest of the comments as well. if said yes, 
then fetch all the comments validate the correctness and implement a minimal fix
   ```
   </details>
   <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F42863&comment_hash=c27510d6379909cf03546ab92e49625d213780caf37f34d72519acb4e655c8a6&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F42863&comment_hash=c27510d6379909cf03546ab92e49625d213780caf37f34d72519acb4e655c8a6&reaction=dislike'>👎</a>



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to