-
Notifications
You must be signed in to change notification settings - Fork 762
[Beta]: Budgets and rate limits alongwith UI and everything #1375
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?
Conversation
narengogi
commented
Oct 10, 2025

fix errors
Co-authored-by: matter-code-review[bot] <150888575+matter-code-review[bot]@users.noreply.github.com>
Co-authored-by: matter-code-review[bot] <150888575+matter-code-review[bot]@users.noreply.github.com>
Co-authored-by: matter-code-review[bot] <150888575+matter-code-review[bot]@users.noreply.github.com>
Co-authored-by: matter-code-review[bot] <150888575+matter-code-review[bot]@users.noreply.github.com>
…nt is greater than the available tokens
DescriptionMotivationType of Change
How Has This Been Tested?
Screenshots (if applicable)N/A Checklist
Related IssuesN/A Summary By MatterAI
🔄 What ChangedThis pull request introduces a new admin API endpoint and corresponding UI functionality to reset integration rate limits. In 🔍 Impact of the ChangeThese changes empower administrators to directly manage and reset rate limits for specific integrations via the local admin UI, enhancing control over resource consumption. The JSON editor streamlines local configuration management for integrations, including budgets and rate limits. The 📁 Total Files Changed
🧪 Test AddedManual testing is implied for the new admin UI to verify the functionality of the JSON editor, saving integrations, and resetting rate limits. No explicit unit or integration tests were provided for the new backend endpoint or UI logic. 🔒Security VulnerabilitiesThe admin UI in Caution Package Vulnerabilities
Tip Quality Recommendations
Tanka Poem ♫
Sequence DiagramsequenceDiagram
participant AdminUI as Admin UI (index.html)
participant AdminAPI as Admin API (adminRoutesHandler.ts)
participant Cache as Cache Service
AdminUI->>AdminAPI: PUT /admin/integrations/ratelimit/:integrationId/reset (adminApiKey)
Note over AdminAPI: resetIntegrationRateLimitHandler(c)
AdminAPI->>AdminAPI: Get integrationId from c.req.param('integrationId')
AdminAPI->>AdminAPI: Get settings, organisationId, workspaceId
AdminAPI->>AdminAPI: Find rate_limits for integrationId
opt If rate_limits exist
loop For each rateLimit in rate_limits
AdminAPI->>AdminAPI: Generate rateLimitKey(organisationId, rateLimit.type, RateLimiterKeyTypes.INTEGRATION_WORKSPACE, workspaceKey, rateLimit.unit)
AdminAPI->>AdminAPI: Construct finalKey (e.g., {rate:key}:type)
AdminAPI->>Cache: delete(finalKey)
Cache-->>AdminAPI: Deletion confirmation
end
end
AdminAPI-->>AdminUI: 200 OK / Error Response
AdminUI-->>AdminUI: Display success/error alert
|
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.
Potential security and performance issues identified in the new code additions.
Skipped files
conf.example.json
: Skipped file patternconf_sample.json
: File hunk diff too largepackage-lock.json
: Skipped file pattern
console.warn( | ||
'you need to set the REDIS_CONNECTION_STRING environment variable for rate limits to wrok' | ||
); |
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.
🔴 Security Issue
Issue: Insecure Redis connection warning message
Fix: Improve the warning message to be more descriptive and actionable
Impact: Better developer experience and security awareness
console.warn( | |
'you need to set the REDIS_CONNECTION_STRING environment variable for rate limits to wrok' | |
); | |
console.warn( | |
'Redis connection string is missing. Rate limits will not work without Redis.' | |
); |
if ([MODES.PROXY && MODES.PROXY_V2].includes(store.proxyMode)) { | ||
splitPattern = getStreamModeSplitPattern( | ||
provider, | ||
winkyBaseLog.requestURL | ||
); | ||
} |
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.
🟡 Performance Issue
Issue: Inefficient conditional check for streaming mode split pattern
Fix: Simplify the condition to avoid unnecessary array creation
Impact: Minor performance improvement
if ([MODES.PROXY && MODES.PROXY_V2].includes(store.proxyMode)) { | |
splitPattern = getStreamModeSplitPattern( | |
provider, | |
winkyBaseLog.requestURL | |
); | |
} | |
let splitPattern = '\ | |
\ | |
'; | |
if (store.proxyMode === MODES.PROXY || store.proxyMode === MODES.PROXY_V2) { | |
splitPattern = getStreamModeSplitPattern( | |
provider, | |
winkyBaseLog.requestURL | |
); | |
} |
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.
Reviewing the new budget and rate limit implementation for potential issues.
const rateLimits = settings.integrations.find( | ||
(integration) => integration.slug === integrationId | ||
)?.integration_details?.rate_limits; |
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.
🔴 Security Issue
Issue: Potential null dereference when accessing rate_limits
Fix: Add null check for integration_details before accessing rate_limits
Impact: Prevent runtime errors when integration details are missing
const rateLimits = settings.integrations.find( | |
(integration) => integration.slug === integrationId | |
)?.integration_details?.rate_limits; | |
const rateLimits = settings.integrations.find( | |
(integration) => integration.slug === integrationId | |
)?.integration_details?.rate_limits || []; |
); | ||
const finalKey = `{rate:${rateLimitKey}}:${rateLimit.type}`; | ||
const cache = getDefaultCache(); | ||
await cache.delete(finalKey); |
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.
🔴 Error Handling Issue
Issue: Missing error handling for cache operations
Fix: Add try-catch around cache operations to handle potential failures
Impact: Prevent unhandled exceptions that could crash the application
await cache.delete(finalKey); | |
try { | |
await cache.delete(finalKey); | |
} catch (cacheError) { | |
console.error(`Failed to delete cache key ${finalKey}:`, cacheError); | |
} |
alert('Integration must have provider and slug fields'); | ||
return; |
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.
🟡 Input Validation Issue
Issue: Missing validation for integration slug uniqueness
Fix: Add check to ensure slug is unique among existing integrations
Impact: Prevent accidental overwrites of existing integrations
// Basic validation
if (!integration.provider || !integration.slug) {
alert('Integration must have provider and slug fields');
return;
}
// Check for duplicate slug
const isDuplicate = integrationsData.some((existing, i) =>
existing.slug === integration.slug && i !== index
);
if (isDuplicate) {
alert('Integration slug must be unique');
return;
}
adminApiKey = ''; | ||
throw new Error('Invalid Admin API Key. Please refresh and try again.'); | ||
} | ||
throw new Error(`Failed to reset rate limit: ${rateLimit.type}`); |
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.
🔴 Error Handling Issue
Issue: Incorrect error message in rate limit reset function
Fix: Reference the correct rate limit variable in error message
Impact: Provide accurate error information to users
throw new Error(`Failed to reset rate limits for integration: ${integration.slug}`);