← Back to Pull requests

refactor(sweep): tenacity-based resilience core + hermetic tests (#924, stacked on #933) #936

Closed
unknown closed this pull request without merging on Sep 29, 2026 18:06 UTC
View on GitHub
unknown unknown commented on Sep 24, 2026 21:40 UTC
Author

Sweep resilience core + module split — #924 (sweep half)

Base main (#933 fix/teardown-sweep-zero-residue is merged). Ready to merge.

This is the sweep half of #924: it splits the 1417-line sweep-workshop-resources.py
monolith into a focused workshop/scripts/sweep/ package and lands a reusable
resilience core, without regressing the zero-residue behavior from #933.

What this delivers


  • Module split (+2642 / −1382, 26 files): the entrypoint is now a thin

  • orchestrator over a sweep/ package — resilience.py, context.py,
    orchestrator.py, and 16 per-service reapers (reapers/: eks, ec2/vpc,
    eip, ecr, rds, s3, elb, iam, secrets, logs, cloudfront, grafana, amp, verify,
    resweep, finalnet). Section order §1–§17 is preserved and the
    VPC-ownership safety guards (never touch a aws:cloudformation:*-tagged /
    IDE VPC) are carried over intact.
  • resilience.py — centralized AWS error classification in one place

  • (classify → gone / access_denied / transient / permanent), plus
    retry_aws / poll_until to replace hand-rolled
    for i in range(N): … time.sleep(S) loops.
  • Defensive tenacity bootstrap with a stdlib fallback. The sweep runs inside

  • the teardown CodeBuild (amazonlinux2-standard:5.0) whose buildspec
    installs helm/terraform/kubectl/yq but no pip. This is a
    destruction-critical path that must never hard-fail on a missing dependency, so
    the module bootstraps tenacity and degrades to a stdlib retry shim if it can't.
  • Hermetic tests (test_sweep_resilience.py + test_sweep_orchestration.py)

  • — fake boto3, no network, no real sleeping; both the tenacity and stdlib
    fallback paths are exercised. 61 test cases pass.

    Scope — what tenacity retry does and does NOT cover yet (honest)


    Retry/backoff via retry_aws currently engages mainly in the new final-net
    reaper
    and in the shared vpc.reap_single_vpc re-drive. The 15 pre-existing
    sections were relocated, not yet re-wired
    onto classify() / retry_aws — that
    broader, section-by-section adoption follows incrementally, which is the right
    call on a destruction-critical path. This PR does not claim tenacity is adopted
    everywhere; it lands the tested core + the split and wires retry where it earns
    its keep first.

    Review fixes applied (shapirov103 on this PR)


    1. classify() no longer reports real failures as "already gone" — check
    access_denied before gone, drop the generic InvalidParameterValue from
    GONE_CODES, and apply the message-substring heuristic only when the error
    code is otherwise unrecognised. Closes the #932 mode (a hidden AccessDenied)
    and stops counting failed deletes as successes in finalnet.run.
    2. poll_until fallback parity — the stdlib-fallback branch now wraps the
    call in try/except so a raising predicate yields a timeout (False)
    identically to the tenacity branch; previously it would propagate and silently
    skip a whole section in the CodeBuild (no-tenacity) path.
    3. vpc.reap_single_vpc — delete_vpc attempts=1 → attempts=3, wait=5,
    so retry_aws actually absorbs the transient DependencyViolation within a
    poll iteration, matching its docstring.
    4. logs.reap_log_groups — records error_code(e) instead of
    e.__class__.__name__ (always ClientError), making the #932 AccessDenied
    diagnostic real.

    Regression tests added for the misclassification and raising-predicate cases.

    Refs #924. Companion to the IDC half in #935.

    Diff: 444 lines (+333 / -111) across 5 files Reviewer: shapirov103 Review duration: 6986m
    All Vouch review confidence checks passed
    Residual risk 0.20 = Change Risk (0.50) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.50 · 444 lines diff across 5 files
    0.50
    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.365
    Shallow Review Depth shallow_review_depth
    0.289
    Ai Authored ai_authored
    0.050
    Real PR Conversation Timeline
    1 comments
    "Review active on #936"
    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: 50.3% (MEDIUM) · Higher = larger blast radius
    50.3%
    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: 19.9% · Safe to merge
    19.9%