← Back to Pull requests

feat(testing): add a lock ttl option to the store contract #28

Closed
unknown closed this pull request without merging on Oct 13, 2026 18:27 UTC
View on GitHub
unknown unknown commented on Oct 13, 2026 02:20 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?


    idempotencyStoreContract() hard-codes LOCK_TTL = 600 ms, and derives the expiry margin (150) and the record ttl (1800) from it. For a store that performs a network round trip per call (e.g. a PostgreSQL store, one transaction per call), the keeps keys apart exactly, however similar or long case acquires 18 keys in a row and then expects key #0 to still be locked. Under parallel load on a shared database those acquires can take longer than 600 ms, so key #0 expires and the case fails with acquired instead of in-flight.

    Issue Number: #21

    What is the new behavior?

    idempotencyStoreContract() accepts a lockTtl option (in ms). The expiry margin is derived as lockTtl / 4 and the record ttl as 3 * lockTtl, so the default 600 reproduces today's 600 / 150 / 1800 exactly, and there is no behavior change for existing callers. A non-positive-integer value throws a RangeError, mirroring the existing concurrent.callers validation.

    A store that needs more time per call can now run the contract without a flaky case, for example idempotencyStoreContract(createStore, { lockTtl: 2_000 }). The expiry cases still wait through advanceTime, so a larger ttl only makes them slower, never less correct.

    Does this PR introduce a breaking change?


  • Yes

  • No
  • The option is additive and the default preserves the current values.

    Other information

    Tests: added refuses a lock ttl that is not a positive whole number of milliseconds and threaded lockTtl: 120 through the existing async-factory/async-clock test. npm run test:e2e (381 passed), npm run lint, and npm run build all pass.

    Diff: 284 lines (+213 / -71) across 3 files Reviewer: kamilmysliwiec Review duration: 967m
    All Vouch review confidence checks passed
    Residual risk 0.17 = Change Risk (0.40) × (1 − Review Confidence (0.57)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.40 · 284 lines diff across 3 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%
    56%
    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.338
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #28"
    general weight: 0.35
    Assignees
    Unassigned
    Labels
    risk: low confidence: 56.8% 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: 39.7% (MEDIUM) · Higher = larger blast radius
    39.7%
    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: 56.8% · Lower = rushed or shallow review
    56.8%
    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: 17.2% · Safe to merge
    17.2%