← Back to Pull requests

[AAP-81383] - Handle renamed job templates and organizations during sync #249

Closed
unknown closed this pull request without merging on Jul 14, 2026 13:07 UTC
View on GitHub
unknown unknown commented on Jul 01, 2026 22:08 UTC
Author

When AAP deletes and recreates a resource with the same name but a new external ID, the sync would attempt to create a duplicate DB row rather than updating the existing one. This violated the unique constraint on (cluster, name, organization) and caused the sync task to fail.

Switch from create() to update_or_create() keyed on (cluster, name, organization) so that a changed external ID updates the existing row in place. For job templates, also purge the stale external_id key from the in-memory cleanup map to prevent the just-updated row from being incorrectly deleted at the end of the sync.

<!-- This is an auto-generated comment: release notes by coderabbit.ai -->

Summary by CodeRabbit

Bug Fixes
Improved sync behavior so existing job templates and organizations are updated in place when they reappear with the same name but a new identifier.
Prevented accidental removal or duplication during reconciliation by matching records more reliably.
Ensured related fields like description and external ID stay consistent without breaking the existing cleanup of missing templates.
Tests
Added unit tests covering stale external IDs for job templates and duplicate handling for organizations.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

Diff: 163 lines (+122 / -41) across 2 files Reviewer: justinc1 Review duration: 18179m
All Vouch review confidence checks passed
Residual risk 0.16 = Change Risk (0.40) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.40 · 163 lines diff across 2 files
0.40
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
0.17
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
60%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.305
Shallow Review Depth shallow_review_depth
0.289
Ai Authored ai_authored
0.050
Real PR Conversation Timeline
1 comments
"Review active on #249"
general weight: 0.35
Reviewers
Assignees
Unassigned
Labels
risk: low confidence: 60.5% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 40.0% (MEDIUM) · Higher = larger blast radius
40.0%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 60.5% · Lower = rushed or shallow review
60.5%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 15.8% · Safe to merge
15.8%