Skip to content

fix: convert webhook timeout from seconds to milliseconds before comparison#2974

Open
joonas wants to merge 2 commits intodefenseunicorns:mainfrom
joonas:fix/webhook-timeout-unit-mismatch
Open

fix: convert webhook timeout from seconds to milliseconds before comparison#2974
joonas wants to merge 2 commits intodefenseunicorns:mainfrom
joonas:fix/webhook-timeout-unit-mismatch

Conversation

@joonas
Copy link
Copy Markdown
Member

@joonas joonas commented Mar 1, 2026

Description

MeasureWebhookTimeout.start() stored config.webhookTimeout as-is (seconds, 1-30), but stop() computed elapsed time via performance.now() (milliseconds). The comparison elapsedTime > this.timeout therefore treated a 10-second timeout as 10ms.

Multiply the timeout by 1000 on entry so both sides of the comparison are in milliseconds.

Update existing tests to use realistic units (timeout in seconds, elapsed time in milliseconds) instead of abstract values that accidentally passed despite the bug. Add a boundary test for the exact-equals case.

End to End Test:
(See Pepr Excellent Examples)

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Other (security config, docs update, etc)

Checklist before merging

…arison

`MeasureWebhookTimeout.start()` stored `config.webhookTimeout` as-is
(seconds, 1-30), but `stop()` computed elapsed time via
`performance.now()` (milliseconds). The comparison
`elapsedTime > this.timeout` therefore treated a 10-second timeout as
10ms.

Multiply the timeout by 1000 on entry so both sides of the comparison
are in milliseconds.

Update existing tests to use realistic units (timeout in seconds,
elapsed time in milliseconds) instead of abstract values that
accidentally passed despite the bug. Add a boundary test for the
exact-equals case.

Signed-off-by: Joonas Bergius <joonas@defenseunicorns.com>
@joonas joonas requested a review from a team as a code owner March 1, 2026 02:04
@samayer12
Copy link
Copy Markdown
Contributor

@greptileai

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Apr 22, 2026

Greptile Summary

This PR fixes a unit mismatch bug in MeasureWebhookTimeout: start() stored config.webhookTimeout in seconds while stop() measured elapsed time via performance.now() in milliseconds, causing a 10-second timeout to fire after just 10ms. The fix multiplies the timeout by 1000 on entry in start(), and the tests are updated with realistic second/millisecond values plus a new exact-equality boundary case.

Confidence Score: 5/5

Safe to merge — minimal, targeted fix with correct logic and well-updated tests.

Single-line production change multiplying by 1000 in the right place; callers in mutate-processor and validate-processor already pass seconds so no call-site changes needed. Test coverage correctly exercises under, over, and exact-equals boundary.

No files require special attention.

Important Files Changed

Filename Overview
src/lib/telemetry/webhookTimeouts.ts One-line fix: multiplies timeout by 1000 in start() so both sides of the elapsedTime > this.timeout comparison are in milliseconds
src/lib/telemetry/webhookTimeout.test.ts Tests updated to use realistic units (seconds for timeout parameter, ms for getNow()); adds a new boundary test for the exact-equals case

Sequence Diagram

sequenceDiagram
    participant Processor as mutate/validate-processor
    participant MWT as MeasureWebhookTimeout
    participant perf as performance.now()
    participant metrics as metricsCollector

    Processor->>MWT: start(config.webhookTimeout) [seconds, e.g. 10]
    Note over MWT: this.timeout = 10 * 1000 = 10000ms
    MWT->>perf: getNow()
    perf-->>MWT: startTime (ms)

    Note over Processor: webhook processing...

    Processor->>MWT: stop()
    MWT->>perf: getNow()
    perf-->>MWT: endTime (ms)
    Note over MWT: elapsedTime = endTime - startTime (ms)
    alt elapsedTime > this.timeout (both in ms)
        MWT->>metrics: incCounter("mutate_timeouts")
    else within budget
        Note over MWT: no counter increment
    end
Loading

Reviews (1): Last reviewed commit: "Merge branch 'main' into fix/webhook-tim..." | Re-trigger Greptile

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

2 participants