Skip to content

perf: add jittered backoff and parameter building utilities#89

Open
samadrehman wants to merge 2 commits into
calcom:mainfrom
samadrehman:fix/my-fix
Open

perf: add jittered backoff and parameter building utilities#89
samadrehman wants to merge 2 commits into
calcom:mainfrom
samadrehman:fix/my-fix

Conversation

@samadrehman
Copy link
Copy Markdown

@samadrehman samadrehman commented May 18, 2026

Optimized Cal.com Companion MCP server by addressing distributed retry patterns and code duplication:

Performance Improvements:

Added jittered exponential backoff to API retry logic, preventing thundering herd problem in distributed systems
Reduces collision risk when multiple clients retry simultaneously using formula: delay * 2^attempt * (1 + random(0-1))
Code Quality:

Created reusable buildParams() and buildBody() utilities to eliminate verbose if-check patterns
Refactored 7 critical functions across bookings, schedules, and availability tools
Reduced parameter-building boilerplate by ~80 lines of code
Testing & Validation:

All 18 test files passing (203 tests)
Zero compile errors
Full backward compatibility maintained
Files Modified:

api-client.ts - Jittered backoff implementation
params-builder.ts - NEW utility module
bookings.ts - Refactored 4 functions
schedules.ts - Refactored 2 functions
availability.ts - Refactored 1 functio


Summary by cubic

Add jittered exponential backoff to the MCP server API client to smooth retries and prevent thundering herd. Add small utilities to build params/bodies and refactor bookings, schedules, and availability to remove boilerplate with no behavior changes.

  • New Features

    • Jittered exponential backoff in API retries using baseDelay * 2^(attempt-1) * (1 + random[0–1]); delay rounded before wait/log.
  • Refactors

    • Added buildParams and buildBody utils and applied them across bookings, schedules, and availability.
    • Removed ~80 lines of parameter-building boilerplate; behavior remains backward compatible.

Written for commit 7660f6c. Summary will update on new commits. Review in cubic

Copilot AI review requested due to automatic review settings May 18, 2026 20:59
@vercel
Copy link
Copy Markdown

vercel Bot commented May 18, 2026

@samadrehman is attempting to deploy a commit to the cal Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions
Copy link
Copy Markdown

Hey there and thank you for opening this pull request!

We require pull request titles to follow the Conventional Commits specification and it looks like your proposed title needs to be adjusted.

Details:

No release type found in pull request title "Performance & Code Quality Improvements: Jittered Backoff & Parameter Building Utilities". Add a prefix to indicate what kind of release this pull request corresponds to. For reference, see https://www.conventionalcommits.org/

Available types:
 - feat: A new feature
 - fix: A bug fix
 - docs: Documentation only changes
 - style: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)
 - refactor: A code change that neither fixes a bug nor adds a feature
 - perf: A code change that improves performance
 - test: Adding missing tests or correcting existing tests
 - build: Changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm)
 - ci: Changes to our CI configuration files and scripts (example scopes: Travis, Circle, BrowserStack, SauceLabs)
 - chore: Other changes that don't modify src or test files
 - revert: Reverts a previous commit

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Introduces shared helpers for building request params/bodies and improves API retry behavior by adding jittered exponential backoff, then refactors several tools to use the new utilities.

Changes:

  • Added buildParams / buildBody utilities to remove repetitive undefined checks when constructing query params and request bodies
  • Added jitter to exponential backoff in calApi retries to reduce thundering-herd effects
  • Refactored schedules, bookings, and availability tools to use the new builders

Reviewed changes

Copilot reviewed 5 out of 6 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
apps/mcp-server/src/utils/params-builder.ts Adds reusable helpers to construct query params and request bodies while omitting undefined values
apps/mcp-server/src/utils/api-client.ts Introduces jittered exponential backoff for retry sleep timing
apps/mcp-server/src/tools/schedules.ts Replaces manual body construction with buildBody
apps/mcp-server/src/tools/bookings.ts Replaces manual query/body construction with buildParams / buildBody
apps/mcp-server/src/tools/availability.ts Uses buildParams to simplify query param building (with a subtle behavior change)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread apps/mcp-server/src/utils/api-client.ts
Comment thread apps/mcp-server/src/utils/params-builder.ts
Comment thread apps/mcp-server/src/tools/availability.ts
Comment thread apps/mcp-server/src/utils/params-builder.ts
Comment thread apps/mcp-server/src/utils/api-client.ts Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

No issues found across 6 files

Re-trigger cubic

@samadrehman samadrehman changed the title Performance & Code Quality Improvements: Jittered Backoff & Parameter Building Utilities perf: add jittered backoff and parameter building utilities May 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants