Skip to content

Conversation

leedongwei
Copy link
Member

Used by #97953

@github-actions github-actions bot added the Scope: Frontend Automatically applied to PRs that change frontend components label Aug 16, 2025
cursor[bot]

This comment was marked as outdated.

export function useMetricDetectorLimit(): MetricDetectorLimitResponse {
const organization = useOrganization();
const subscription = useSubscription();
const {data: detectors, isLoading, isError} = useDetectorsQuery();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const {..., getResponseHeader} = useDetectorsQuery({
  query: 'type:metric'
  limit: 0
}, {
  enabled: !organization.features.includes('workflow-engine-metric-detector-limit') ||
       detectorLimit === UNLIMITED_QUOTA
})

const hits = getResponseHeader()['X-Hits'];
const totalMetricDetectors = hits ? parseInt(hits): 0;

This will get the max number through the header so we don't return every detector in the response data, and limit it to metric detectors. Also skips the request if it's not necessary

@leedongwei leedongwei force-pushed the dlee/use-metric-detector-limit branch from 2381da5 to 2f863e9 Compare August 19, 2025 23:55
@leedongwei leedongwei requested review from a team as code owners August 19, 2025 23:55
@leedongwei leedongwei changed the base branch from master to malwilley/feat/metric-alert-quota August 19, 2025 23:55
@leedongwei leedongwei requested a review from malwilley August 20, 2025 16:08
query: 'type:metric',
limit: 0,
},
{enabled: has_flag}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can also disable this request if there is an unlimited quota

@leedongwei leedongwei force-pushed the dlee/use-metric-detector-limit branch from 0323d7f to e74969b Compare August 25, 2025 15:48
@leedongwei leedongwei merged commit b326c21 into malwilley/feat/metric-alert-quota Aug 25, 2025
36 of 37 checks passed
@leedongwei leedongwei deleted the dlee/use-metric-detector-limit branch August 25, 2025 15:50
detectorLimit: -1,
detectorCount: -1,
detectorLimit: UNLIMITED_QUOTA,
detectorCount,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Hook Misinterprets Header, Bypasses Limits

The hook incorrectly parses non-numeric X-Hits header values, resulting in detectorCount being NaN. This causes hasReachedLimit to always be false and isError to be incorrect, potentially bypassing detector limits. Additionally, the detector query runs unnecessarily when detectorLimit is unlimited, and the hook's early return then misreports isLoading and isError states.

Fix in Cursor Fix in Web

@github-actions github-actions bot locked and limited conversation to collaborators Sep 10, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Scope: Frontend Automatically applied to PRs that change frontend components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants