← Back to Pull requests

refactor(idc): split configure_identity_center into a package with tenacity resilience (#924) #935

Closed
unknown closed this pull request without merging on Sep 30, 2026 20:04 UTC
View on GitHub
unknown unknown commented on Sep 24, 2026 16:34 UTC
Author

Summary

Implements the IDC half of #924: refactor the oversized
scripts/configure_identity_center.py (995 lines) to apply the maintainability
principles Mikhail raised in the #917 review
— reduce the single-file size, and replace hand-rolled range()/sleep()
resilience with the standard tenacity
library.

What changed

New scripts/idc/ package, split by concern (principle 2):

| module | responsibility |
|---|---|
| resilience.py | centralized tenacity retry policies + transient-error classification (tenacity + stdlib only — import-light, unit-testable) |
| constants.py | shared temp-file paths + realm name |
| credentials.py | AWS credential load/refresh + console sign-in URL |
| keycloak.py | Keycloak admin API + SAML client creation |
| scim.py | SCIM user/group export + federation verification |
| browser.py | Playwright/Chromium console-navigation helpers |
| orchestrator.py | the end-to-end configure_identity_center flow |

scripts/configure_identity_center.py is now a thin CLI entrypoint (108 lines,
down from 995)
. The argparse interface and stdout SCIM-token redaction are
preserved verbatim, so task idc:configure and the SSM bashrc.d path are
unchanged.

How the principles are applied

1 + 3 — standard resilience, centralized classification. The three bespoke
retry loops are replaced by shared policies in resilience.py:

  • federation request loop → retry_http (3 attempts, 5s fixed) on a

  • TransientHTTPError
  • Playwright page.goto retry → retry_nav (exponential backoff) on the

  • transient nav-error token set
  • Keycloak SAML-descriptor wait → poll_until (300s / 30s)
  • The transient-nav token set and the transient-HTTP classification now live in
    one place instead of being duplicated per call site.

    4 — tighten broad excepts. The SAML-descriptor poll retries only on
    requests.RequestException + a falsy result, instead of a blanket
    except Exception: that could mask a real bug for five minutes.

    5 — unit tests. scripts/tests/test_idc_resilience.py — 24 hermetic tests
    (no network/boto3/playwright) covering transient classification and the
    retry_nav / retry_http / poll_until policies: recover-after-transient,
    give-up-after-N, no-retry-on-deterministic-error, timeout,
    unlisted-exception-propagation, and async-coroutine support.

    $ python -m pytest scripts/tests/test_idc_resilience.py -q
    ........................  24 passed
    

    Dependency

    tenacity is added to the idc:configure pip line and bootstrapped at
    entrypoint import (mirroring the existing Playwright bootstrap), so the SSM
    bashrc.d path — which has no pip step — still gets it. It runs on the IDE
    (mise/uv-managed) where adding it is trivial.

    Behavior preserved (acceptance criteria)

  • The #917 transient-network fix is kept (now retry_nav) — not regressed.

  • The full flow, the CLI, and the AWS-side federation assertion

  • (verify_federation_active) are unchanged.
  • Static-checked with pyflakes (no undefined names) and every module

  • py_compiles clean.

    Scope note — the sweep script follows separately

    #924 also covers workshop/scripts/sweep-workshop-resources.py. That half is
    intentionally sequenced behind #933 (which is actively editing that file, so
    refactoring it now would conflict massively) and additionally needs the teardown
    CodeBuild buildspec dependency change (destruction-critical runtime — see the
    runtime caveat in the issue). It will land in a follow-up PR once #933 merges.

    Closes the IDC portion of #924.

    Diff: 462 lines (+346 / -116) across 5 files Reviewer: shapirov103 Review duration: 8849m
    All Vouch review confidence checks passed
    Residual risk 0.27 = Change Risk (0.69) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.69 · 462 lines diff across 5 files
    0.69
    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.367
    Shallow Review Depth shallow_review_depth
    0.289
    Sensitive Paths sensitive_paths
    0.069
    Real PR Conversation Timeline
    1 comments
    "Review active on #935"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed sensitive_module
    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: 68.8% (HIGH) · Higher = larger blast radius
    68.8%
    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: 27.2% · Safe to merge
    27.2%