← Back to Pull requests

Make the MSK IAM token provider example survive Config deepcopy and return seconds #1386

Closed
unknown closed this pull request without merging on Oct 08, 2026 08:06 UTC
View on GitHub
unknown unknown commented on Oct 05, 2026 18:11 UTC
Author

What

Fixes examples/msk_iam_token_provider.py so it works when used exactly as its docstring says, and documents the two protocol constraints it was violating.

1. Lazy signer import. The example cached the aws_msk_iam_sasl_signer module on self. Config.model_post_init instantiates the provider and keeps it in a private attribute, and dependency_injector deep-copies the Config while wiring containers, so startup failed with:

   TypeError: cannot pickle 'module' object
   dependency_injector.errors.NonCopyableArgumentError: Couldn't copy keyword argument config for provider <Singleton(ForwardClient)>
   

The signer is now imported inside token_with_expiry; the instance holds only the optional region string.

2. Expiry in seconds. token_with_expiry is passed straight to librdkafka as oauth_cb, which reads the expiry in seconds. The MSK signer returns milliseconds. Passing them through made librdkafka treat the token as expiring in the year ~58000, so it never refreshed and the broker rejected the stale token about 15 minutes after startup. The example now divides by 1000.

3. Region from env first. AWS_REGION / AWS_DEFAULT_REGION are checked before importing boto3 for the session default.

The module docstring and examples/README.rst now state both constraints: the expiry unit, and that provider instances must stay picklable.

Tests

tests/unit/test_msk_iam_token_provider_example.py loads the example by path (no new test dependency; the AWS signer is stubbed in sys.modules) and checks: the instance deep-copies, it can be constructed without the signer installed, the returned expiry is in seconds, and the region falls back to the env. Against the previous example the deepcopy test fails with cannot pickle 'module' object and the unit test with 1800000000000 == 1800000000.

Diff: 232 lines (+174 / -58) across 2 files Reviewer: muralibasani Review duration: 3715m
All Vouch review confidence checks passed
Residual risk 0.24 = Change Risk (0.60) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.60 · 232 lines diff across 2 files
0.60
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.326
Shallow Review Depth shallow_review_depth
0.289
Sensitive Paths sensitive_paths
0.060
Real PR Conversation Timeline
1 comments
"Review active on #1386"
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: 60.2% (MEDIUM) · Higher = larger blast radius
60.2%
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: 23.8% · Safe to merge
23.8%