← Back to Pull requests

fix(guard): support request-scoped guards #2735

Closed
unknown closed this pull request without merging on Nov 03, 2026 08:01 UTC
View on GitHub
unknown unknown commented on Nov 02, 2026 19:46 UTC
Author

PR Checklist


Please check if your PR fulfills the following requirements:

  • The commit message follows our guidelines: https://github.com/nestjs/nest/blob/master/CONTRIBUTING.md

  • Tests for the changes have been added (for bug fixes / features)

  • Docs have been added / updated (for bug fixes / features)
  • PR Type


    What kind of change does this PR introduce?

  • Bugfix

  • Feature

  • Code style update (formatting, local variables)

  • Refactoring (no functional changes, no api changes)

  • Build related changes

  • CI related changes

  • Other... Please describe:
  • What is the current behavior?

    A guard that is request-scoped, or that depends on a request-scoped provider, fails every request with a 500 error:

    TypeError: this.throttlers is not iterable
    

    ThrottlerGuard only sets throttlers in onModuleInit(), and Nest does not call that hook on request-scoped instances.

    @Injectable({ scope: Scope.REQUEST })
    class RequestScopedGuard extends ThrottlerGuard {}
    

    Issue Number: N/A

    What is the new behavior?

    canActivate() calls onModuleInit() when the instance is not initialized yet. Static guards still initialize once at startup. The limit works across requests, because the storage is a shared singleton.

    Does this PR introduce a breaking change?


  • Yes

  • No
  • Other information

    The new e2e test runs on Express and Fastify and failed on both before the fix. Unit tests (52), e2e tests (36), build and lint pass.

    A request-scoped guard initializes once per request. With an empty configuration, the existing "no throttlers" warning is therefore logged per request.

    Diff: 207 lines (+155 / -52) across 2 files Reviewer: kamilmysliwiec Review duration: 735m
    All Vouch review confidence checks passed
    Residual risk 0.14 = Change Risk (0.36) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.36 · 207 lines diff across 2 files
    0.36
    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.319
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #2735"
    general weight: 0.35
    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: 36.4% (MEDIUM) · Higher = larger blast radius
    36.4%
    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: 14.4% · Safe to merge
    14.4%