-
Notifications
You must be signed in to change notification settings - Fork 0
[WRONG BRANCH] fix(usage): bound concurrent filtered scans #520
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -66,6 +66,7 @@ const pinnedAggregates = new Set<RetainedUsageAggregate>(); | |
| let baseFlight: Promise<UsageAggregateResult> | null = null; | ||
| const filteredFlights = new Map<string, Promise<UsageAggregateResult>>(); | ||
| const retainedFilteredAggregates = new Map<string, RetainedUsageAggregate>(); | ||
| const MAX_CONCURRENT_FILTERED_AGGREGATES = 4; | ||
|
|
||
| function currentTimeZone(): string { | ||
| return Intl.DateTimeFormat().resolvedOptions().timeZone; | ||
|
|
@@ -283,6 +284,9 @@ export async function getFilteredUsageAggregate(filter: { | |
| ]); | ||
| const existing = filteredFlights.get(key); | ||
| if (existing) return existing; | ||
| if (filteredFlights.size >= MAX_CONCURRENT_FILTERED_AGGREGATES) { | ||
| throw new Error("too many concurrent filtered usage aggregates"); | ||
|
Comment on lines
+287
to
+288
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When four other keys are scanning, this guard also rejects a request whose own key already has a current entry in AGENTS.md reference: structure/AGENTS.md:L9-L10 Useful? React with 👍 / 👎. |
||
| } | ||
|
|
||
| const flight = refreshFilteredAggregate(key, normalizedFilter, fixedWindow); | ||
| filteredFlights.set(key, flight); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When four distinct scans are active, a filtered management
/api/usagerequest reaches this throw, butlogs-usage-routes.tscatches it and returns HTTP 200 with zero totals anderror: "read_failed". Consumers such asgui/src/pages/Usage.tsxandsrc/cli/observe.tsaccept successful responses without checking that field, so temporary saturation is displayed as genuine zero usage. Translate this overload condition to a non-success response, or otherwise ensure clients reject the synthetic summary.Useful? React with 👍 / 👎.