Skip to content

Conversation

@github-actions
Copy link
Contributor

@github-actions github-actions bot commented Jul 25, 2025

This is an automated pull request to deploy the staging branch to production.
Please review the pull request and comment /deploy to merge this PR and deploy to production.


Summary by cubic

Added Grafana monitoring by exposing Prometheus metrics for tRPC API calls and ZeroDriver email operations, with a new /metrics endpoint and environment-based configuration.

  • New Features
    • Centralized metrics utility for tracking API and email operation performance.
    • tRPC middleware and ZeroDriver methods now record timing and status metrics.
    • /metrics endpoint added for Prometheus scraping.
    • Environment variables support Grafana integration.

…ormance (#1816)

# feat: add Grafana monitoring for ZeroAgent, ZeroDriver, and tRPC performance

## Summary

Implements centralized Grafana monitoring for the Zero server to track performance metrics across tRPC API calls, ZeroDriver operations, and email handling. The implementation uses Prometheus-format metrics that can be scraped by Grafana Cloud for observability and performance analysis.

**Key Components:**
- **Centralized metrics utility** (`src/lib/metrics.ts`) with Prometheus counters and histograms
- **tRPC middleware** for automatic API call timing and success/error tracking  
- **ZeroDriver instrumentation** for email operations (markAsRead, create)
- **Metrics endpoint** (`/metrics`) for Prometheus scraping
- **Environment-based configuration** for Grafana Cloud integration

**Metrics Tracked:**
- `trpc_request_duration_seconds` - API call timing by procedure and status
- `trpc_requests_total` - API call counts by procedure and status  
- `zero_driver_operation_duration_seconds` - Email operation timing
- `email_operations_total` - Email operation counts by provider and status
- `zero_agent_operation_duration_seconds` - Agent operation timing (framework ready)

## Review & Testing Checklist for Human

- [ ] **Test actual metric collection** - Perform real email operations (read, compose, sync) and verify metrics are collected at `/metrics` endpoint
- [ ] **Performance verification** - Monitor response times during normal usage to ensure no degradation from monitoring overhead
- [ ] **Environment configuration** - Set up `GRAFANA_ENDPOINT`, `GRAFANA_USERNAME`, `GRAFANA_PASSWORD` in staging/production environments
- [ ] **Staging deployment test** - Deploy to staging and verify Cloudflare Workers compatibility (removed `collectDefaultMetrics()` due to Node.js API incompatibility)
- [ ] **Complete instrumentation** - Consider adding monitoring to remaining ZeroAgent operations and additional ZeroDriver methods as needed

---

### Diagram

```mermaid
%%{ init : { "theme" : "default" }}%%
graph TD
    subgraph "Core Server"
        A["src/main.ts<br/>+metrics endpoint"]:::major-edit
        B["src/trpc/trpc.ts<br/>+middleware"]:::major-edit
    end
    
    subgraph "Monitoring Infrastructure"
        C["src/lib/metrics.ts<br/>NEW centralized utility"]:::major-edit
        D["src/overrides.d.ts<br/>+TypeScript types"]:::minor-edit
    end
    
    subgraph "Email Operations"
        E["src/routes/agent/index.ts<br/>+ZeroDriver monitoring"]:::major-edit
    end
    
    subgraph "Configuration"
        F["wrangler.jsonc<br/>+environment vars"]:::minor-edit
        G["package.json<br/>+prom-client"]:::minor-edit
    end
    
    A --> C
    B --> C
    E --> C
    C --> F
    D --> F
    
    subgraph Legend
        L1[Major Edit]:::major-edit
        L2[Minor Edit]:::minor-edit
        L3[Context/No Edit]:::context
    end

classDef major-edit fill:#90EE90
classDef minor-edit fill:#87CEEB  
classDef context fill:#FFFFFF
```

### Notes

- **Cloudflare Workers Compatibility**: Removed `collectDefaultMetrics()` due to `process.cpuUsage` incompatibility - this is expected and handled
- **Async Design**: Metrics collection is non-blocking to minimize performance impact
- **Partial Implementation**: Currently instruments key ZeroDriver operations; additional operations can be added incrementally
- **Environment Variables**: All Grafana configuration is externalized for security and flexibility

**Link to Devin run**: https://app.devin.ai/sessions/f88e66bd577843aba5f0d452d4dfe0e8  
**Requested by**: @MrgSub

![Metrics Endpoint Screenshot](file:///home/ubuntu/screenshots/localhost_8787_064620.png)
    
<!-- This is an auto-generated description by cubic. -->
---

## Summary by cubic
Added Grafana monitoring for ZeroAgent, ZeroDriver, and tRPC performance by exposing Prometheus-format metrics and instrumenting key operations.

- **New Features**
  - Centralized metrics utility for tracking API and email operation performance.
  - tRPC middleware and ZeroDriver methods now record timing and status metrics.
  - `/metrics` endpoint added for Prometheus scraping.
  - Environment variables support Grafana Cloud integration.

<!-- End of auto-generated description by cubic. -->
@github-actions github-actions bot added the production-deploy This PR is meant to update production label Jul 25, 2025
@jazzberry-ai
Copy link

jazzberry-ai bot commented Jul 25, 2025

Bug Report

Name Severity Example test case Description
Incorrect file path for metrics.ts Critical Check if metrics are being collected by the mail application. The file metrics.ts was created in the wrong directory (apps/server/src/lib/ instead of apps/mail/src/lib/), preventing the mail application from collecting metrics.

Comments? Email us. Your free trial ends in 4 days.

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Jul 25, 2025

Deploying zero-staging with  Cloudflare Pages  Cloudflare Pages

Latest commit: e7a0463
Status: ✅  Deploy successful!
Preview URL: https://05ab43cb.zero-staging-c02.pages.dev

View logs

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 25, 2025

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Join our Discord community for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Jul 25, 2025

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
zero-server-production e7a0463 Jul 25 2025, 08:42 PM

@graphite-app graphite-app bot requested a review from MrgSub July 25, 2025 17:57
@graphite-app
Copy link
Contributor

graphite-app bot commented Jul 25, 2025

Graphite Automations

"Deploy to Production Helper" took an action on this PR • (07/25/25)

1 reviewer was added to this PR based on Rahul Mishra's automation.

@cloudflare-workers-and-pages
Copy link

Deploying zero-prod with  Cloudflare Pages  Cloudflare Pages

Latest commit: 5fda69d
Status:🚫  Build failed.

View logs

# READ CAREFULLY THEN REMOVE

Remove bullet points that are not relevant.

PLEASE REFRAIN FROM USING AI TO WRITE YOUR CODE AND PR DESCRIPTION. IF YOU DO USE AI TO WRITE YOUR CODE PLEASE PROVIDE A DESCRIPTION AND REVIEW IT CAREFULLY. MAKE SURE YOU UNDERSTAND THE CODE YOU ARE SUBMITTING USING AI.

- Pull requests that do not follow these guidelines will be closed without review or comment.
- If you use AI to write your PR description your pr will be close without review or comment.
- If you are unsure about anything, feel free to ask for clarification.

## Description

Please provide a clear description of your changes.

---

## Type of Change

Please delete options that are not relevant.

- [ ] 🐛 Bug fix (non-breaking change which fixes an issue)
- [ ] ✨ New feature (non-breaking change which adds functionality)
- [ ] 💥 Breaking change (fix or feature with breaking changes)
- [ ] 📝 Documentation update
- [ ] 🎨 UI/UX improvement
- [ ] 🔒 Security enhancement
- [ ] ⚡ Performance improvement

## Areas Affected

Please check all that apply:

- [ ] Email Integration (Gmail, IMAP, etc.)
- [ ] User Interface/Experience
- [ ] Authentication/Authorization
- [ ] Data Storage/Management
- [ ] API Endpoints
- [ ] Documentation
- [ ] Testing Infrastructure
- [ ] Development Workflow
- [ ] Deployment/Infrastructure

## Testing Done

Describe the tests you've done:

- [ ] Unit tests added/updated
- [ ] Integration tests added/updated
- [ ] Manual testing performed
- [ ] Cross-browser testing (if UI changes)
- [ ] Mobile responsiveness verified (if UI changes)

## Security Considerations

For changes involving data or authentication:

- [ ] No sensitive data is exposed
- [ ] Authentication checks are in place
- [ ] Input validation is implemented
- [ ] Rate limiting is considered (if applicable)

## Checklist

- [ ] I have read the [CONTRIBUTING](https://github.com/Mail-0/Zero/blob/staging/.github/CONTRIBUTING.md) document
- [ ] My code follows the project's style guidelines
- [ ] I have performed a self-review of my code
- [ ] I have commented my code, particularly in complex areas
- [ ] I have updated the documentation
- [ ] My changes generate no new warnings
- [ ] I have added tests that prove my fix/feature works
- [ ] All tests pass locally
- [ ] Any dependent changes are merged and published

## Additional Notes

Add any other context about the pull request here.

## Screenshots/Recordings

Add screenshots or recordings here if applicable.

---

_By submitting this pull request, I confirm that my contribution is made under the terms of the project's license._

    
<!-- This is an auto-generated description by cubic. -->
---

## Summary by cubic
Added a patch for the novel dependency to pnpm-lock.yaml to apply custom fixes during installation.

<!-- End of auto-generated description by cubic. -->
@jazzberry-ai
Copy link

jazzberry-ai bot commented Jul 25, 2025

An error occured.

This error may be due to rate limits. If this error persists, please email us.

…1828)

# READ CAREFULLY THEN REMOVE

Remove bullet points that are not relevant.

PLEASE REFRAIN FROM USING AI TO WRITE YOUR CODE AND PR DESCRIPTION. IF YOU DO USE AI TO WRITE YOUR CODE PLEASE PROVIDE A DESCRIPTION AND REVIEW IT CAREFULLY. MAKE SURE YOU UNDERSTAND THE CODE YOU ARE SUBMITTING USING AI.

- Pull requests that do not follow these guidelines will be closed without review or comment.
- If you use AI to write your PR description your pr will be close without review or comment.
- If you are unsure about anything, feel free to ask for clarification.

## Description

Please provide a clear description of your changes.

---

## Type of Change

Please delete options that are not relevant.

- [ ] 🐛 Bug fix (non-breaking change which fixes an issue)
- [ ] ✨ New feature (non-breaking change which adds functionality)
- [ ] 💥 Breaking change (fix or feature with breaking changes)
- [ ] 📝 Documentation update
- [ ] 🎨 UI/UX improvement
- [ ] 🔒 Security enhancement
- [ ] ⚡ Performance improvement

## Areas Affected

Please check all that apply:

- [ ] Email Integration (Gmail, IMAP, etc.)
- [ ] User Interface/Experience
- [ ] Authentication/Authorization
- [ ] Data Storage/Management
- [ ] API Endpoints
- [ ] Documentation
- [ ] Testing Infrastructure
- [ ] Development Workflow
- [ ] Deployment/Infrastructure

## Testing Done

Describe the tests you've done:

- [ ] Unit tests added/updated
- [ ] Integration tests added/updated
- [ ] Manual testing performed
- [ ] Cross-browser testing (if UI changes)
- [ ] Mobile responsiveness verified (if UI changes)

## Security Considerations

For changes involving data or authentication:

- [ ] No sensitive data is exposed
- [ ] Authentication checks are in place
- [ ] Input validation is implemented
- [ ] Rate limiting is considered (if applicable)

## Checklist

- [ ] I have read the [CONTRIBUTING](https://github.com/Mail-0/Zero/blob/staging/.github/CONTRIBUTING.md) document
- [ ] My code follows the project's style guidelines
- [ ] I have performed a self-review of my code
- [ ] I have commented my code, particularly in complex areas
- [ ] I have updated the documentation
- [ ] My changes generate no new warnings
- [ ] I have added tests that prove my fix/feature works
- [ ] All tests pass locally
- [ ] Any dependent changes are merged and published

## Additional Notes

Add any other context about the pull request here.

## Screenshots/Recordings

Add screenshots or recordings here if applicable.

---

_By submitting this pull request, I confirm that my contribution is made under the terms of the project's license._

    
<!-- This is an auto-generated description by cubic. -->
---

## Summary by cubic
Fixed the order of CSS classes in the privacy policy page and removed the line about storing Google account credentials.

<!-- End of auto-generated description by cubic. -->
@jazzberry-ai
Copy link

jazzberry-ai bot commented Jul 25, 2025

Bug Report

Name Severity Example test case Description
Invalid Grafana Credentials Medium Set GRAFANA_USERNAME or GRAFANA_PASSWORD to an empty string in the environment. The MetricsCollector does not validate that GRAFANA_USERNAME and GRAFANA_PASSWORD are set, which leads to btoa() being called with potentially empty strings, leading to invalid authorization headers being sent to Grafana. Added a check to ensure the variables are set.
Incorrect Email Operation Total Medium Call ZeroDriver's markAsRead or create methods and cause them to throw an error. The emailOperationTotal counter is incremented within the try block of the ZeroDriver's markAsRead and create methods. If an error occurs during the operation, the counter is not incremented. Moved the counter increment to the finally block, and made the status (success/failure) a parameter to timeOperation.

Comments? Email us. Your free trial ends in 4 days.

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Bugbot free trial expires on July 29, 2025
Learn more in the Cursor dashboard.

# READ CAREFULLY THEN REMOVE

Remove bullet points that are not relevant.

PLEASE REFRAIN FROM USING AI TO WRITE YOUR CODE AND PR DESCRIPTION. IF YOU DO USE AI TO WRITE YOUR CODE PLEASE PROVIDE A DESCRIPTION AND REVIEW IT CAREFULLY. MAKE SURE YOU UNDERSTAND THE CODE YOU ARE SUBMITTING USING AI.

- Pull requests that do not follow these guidelines will be closed without review or comment.
- If you use AI to write your PR description your pr will be close without review or comment.
- If you are unsure about anything, feel free to ask for clarification.

## Description

Please provide a clear description of your changes.

---

## Type of Change

Please delete options that are not relevant.

- [ ] 🐛 Bug fix (non-breaking change which fixes an issue)
- [ ] ✨ New feature (non-breaking change which adds functionality)
- [ ] 💥 Breaking change (fix or feature with breaking changes)
- [ ] 📝 Documentation update
- [ ] 🎨 UI/UX improvement
- [ ] 🔒 Security enhancement
- [ ] ⚡ Performance improvement

## Areas Affected

Please check all that apply:

- [ ] Email Integration (Gmail, IMAP, etc.)
- [ ] User Interface/Experience
- [ ] Authentication/Authorization
- [ ] Data Storage/Management
- [ ] API Endpoints
- [ ] Documentation
- [ ] Testing Infrastructure
- [ ] Development Workflow
- [ ] Deployment/Infrastructure

## Testing Done

Describe the tests you've done:

- [ ] Unit tests added/updated
- [ ] Integration tests added/updated
- [ ] Manual testing performed
- [ ] Cross-browser testing (if UI changes)
- [ ] Mobile responsiveness verified (if UI changes)

## Security Considerations

For changes involving data or authentication:

- [ ] No sensitive data is exposed
- [ ] Authentication checks are in place
- [ ] Input validation is implemented
- [ ] Rate limiting is considered (if applicable)

## Checklist

- [ ] I have read the [CONTRIBUTING](https://github.com/Mail-0/Zero/blob/staging/.github/CONTRIBUTING.md) document
- [ ] My code follows the project's style guidelines
- [ ] I have performed a self-review of my code
- [ ] I have commented my code, particularly in complex areas
- [ ] I have updated the documentation
- [ ] My changes generate no new warnings
- [ ] I have added tests that prove my fix/feature works
- [ ] All tests pass locally
- [ ] Any dependent changes are merged and published

## Additional Notes

Add any other context about the pull request here.

## Screenshots/Recordings

Add screenshots or recordings here if applicable.

---

_By submitting this pull request, I confirm that my contribution is made under the terms of the project's license._

    
<!-- This is an auto-generated description by cubic. -->
---

## Summary by cubic
Removed unused Grafana environment variables from wrangler.jsonc to clean up configuration.

<!-- End of auto-generated description by cubic. -->
@jazzberry-ai
Copy link

jazzberry-ai bot commented Jul 25, 2025

Bug Report

Name Severity Example test case Description
Missing Grafana Error Handling Medium Simulate a Grafana endpoint outage. Verify that the application logs the error, but metrics are lost. The sendToGrafana function in src/lib/metrics.ts lacks proper error handling for the fetch call. This can lead to loss of metrics data if the Grafana endpoint is unavailable. Retries with exponential backoff should be implemented.
Storing Refresh Tokens in DB Critical Compromise the database. Verify the refresh tokens can be used to access email accounts. Storing refresh tokens in the database represents a significant security risk. If the database is compromised, attackers could use the refresh tokens to gain persistent access to user email accounts. The application needs to use a more secure method of storing credentials, such as encryption, token revocation, or secrets management.

Comments? Email us. Your free trial ends in 4 days.

# READ CAREFULLY THEN REMOVE

Remove bullet points that are not relevant.

PLEASE REFRAIN FROM USING AI TO WRITE YOUR CODE AND PR DESCRIPTION. IF YOU DO USE AI TO WRITE YOUR CODE PLEASE PROVIDE A DESCRIPTION AND REVIEW IT CAREFULLY. MAKE SURE YOU UNDERSTAND THE CODE YOU ARE SUBMITTING USING AI.

- Pull requests that do not follow these guidelines will be closed without review or comment.
- If you use AI to write your PR description your pr will be close without review or comment.
- If you are unsure about anything, feel free to ask for clarification.

## Description

Please provide a clear description of your changes.

---

## Type of Change

Please delete options that are not relevant.

- [ ] 🐛 Bug fix (non-breaking change which fixes an issue)
- [ ] ✨ New feature (non-breaking change which adds functionality)
- [ ] 💥 Breaking change (fix or feature with breaking changes)
- [ ] 📝 Documentation update
- [ ] 🎨 UI/UX improvement
- [ ] 🔒 Security enhancement
- [ ] ⚡ Performance improvement

## Areas Affected

Please check all that apply:

- [ ] Email Integration (Gmail, IMAP, etc.)
- [ ] User Interface/Experience
- [ ] Authentication/Authorization
- [ ] Data Storage/Management
- [ ] API Endpoints
- [ ] Documentation
- [ ] Testing Infrastructure
- [ ] Development Workflow
- [ ] Deployment/Infrastructure

## Testing Done

Describe the tests you've done:

- [ ] Unit tests added/updated
- [ ] Integration tests added/updated
- [ ] Manual testing performed
- [ ] Cross-browser testing (if UI changes)
- [ ] Mobile responsiveness verified (if UI changes)

## Security Considerations

For changes involving data or authentication:

- [ ] No sensitive data is exposed
- [ ] Authentication checks are in place
- [ ] Input validation is implemented
- [ ] Rate limiting is considered (if applicable)

## Checklist

- [ ] I have read the [CONTRIBUTING](https://github.com/Mail-0/Zero/blob/staging/.github/CONTRIBUTING.md) document
- [ ] My code follows the project's style guidelines
- [ ] I have performed a self-review of my code
- [ ] I have commented my code, particularly in complex areas
- [ ] I have updated the documentation
- [ ] My changes generate no new warnings
- [ ] I have added tests that prove my fix/feature works
- [ ] All tests pass locally
- [ ] Any dependent changes are merged and published

## Additional Notes

Add any other context about the pull request here.

## Screenshots/Recordings

Add screenshots or recordings here if applicable.

---

_By submitting this pull request, I confirm that my contribution is made under the terms of the project's license._

    
<!-- This is an auto-generated description by cubic. -->
---

## Summary by cubic
Removed the MetricsCollector class and added authentication to the /metrics endpoint to restrict access.

- **Security**
  - The /metrics endpoint now requires a valid Authorization header with the Grafana password.

<!-- End of auto-generated description by cubic. -->
@jazzberry-ai
Copy link

jazzberry-ai bot commented Jul 25, 2025

Bug Report

Name Severity Example test case Description
Metrics are not sent to Grafana High Check Grafana dashboard; no new metrics are visible. The MetricsCollector class was removed, which was responsible for collecting and sending metrics to Grafana.

Comments? Email us. Your free trial ends in 4 days.

# READ CAREFULLY THEN REMOVE

Remove bullet points that are not relevant.

PLEASE REFRAIN FROM USING AI TO WRITE YOUR CODE AND PR DESCRIPTION. IF YOU DO USE AI TO WRITE YOUR CODE PLEASE PROVIDE A DESCRIPTION AND REVIEW IT CAREFULLY. MAKE SURE YOU UNDERSTAND THE CODE YOU ARE SUBMITTING USING AI.

- Pull requests that do not follow these guidelines will be closed without review or comment.
- If you use AI to write your PR description your pr will be close without review or comment.
- If you are unsure about anything, feel free to ask for clarification.

## Description

Please provide a clear description of your changes.

---

## Type of Change

Please delete options that are not relevant.

- [ ] 🐛 Bug fix (non-breaking change which fixes an issue)
- [ ] ✨ New feature (non-breaking change which adds functionality)
- [ ] 💥 Breaking change (fix or feature with breaking changes)
- [ ] 📝 Documentation update
- [ ] 🎨 UI/UX improvement
- [ ] 🔒 Security enhancement
- [ ] ⚡ Performance improvement

## Areas Affected

Please check all that apply:

- [ ] Email Integration (Gmail, IMAP, etc.)
- [ ] User Interface/Experience
- [ ] Authentication/Authorization
- [ ] Data Storage/Management
- [ ] API Endpoints
- [ ] Documentation
- [ ] Testing Infrastructure
- [ ] Development Workflow
- [ ] Deployment/Infrastructure

## Testing Done

Describe the tests you've done:

- [ ] Unit tests added/updated
- [ ] Integration tests added/updated
- [ ] Manual testing performed
- [ ] Cross-browser testing (if UI changes)
- [ ] Mobile responsiveness verified (if UI changes)

## Security Considerations

For changes involving data or authentication:

- [ ] No sensitive data is exposed
- [ ] Authentication checks are in place
- [ ] Input validation is implemented
- [ ] Rate limiting is considered (if applicable)

## Checklist

- [ ] I have read the [CONTRIBUTING](https://github.com/Mail-0/Zero/blob/staging/.github/CONTRIBUTING.md) document
- [ ] My code follows the project's style guidelines
- [ ] I have performed a self-review of my code
- [ ] I have commented my code, particularly in complex areas
- [ ] I have updated the documentation
- [ ] My changes generate no new warnings
- [ ] I have added tests that prove my fix/feature works
- [ ] All tests pass locally
- [ ] Any dependent changes are merged and published

## Additional Notes

Add any other context about the pull request here.

## Screenshots/Recordings

Add screenshots or recordings here if applicable.

---

_By submitting this pull request, I confirm that my contribution is made under the terms of the project's license._

    
<!-- This is an auto-generated description by cubic. -->
---

## Summary by cubic
Removed all Prometheus metrics code and related configuration from the server to simplify the codebase.

- **Refactors**
  - Deleted metrics library and middleware.
  - Removed metrics usage from agent routes and tRPC procedures.
  - Cleaned up unused Grafana environment variables.

<!-- End of auto-generated description by cubic. -->
@jazzberry-ai
Copy link

jazzberry-ai bot commented Jul 25, 2025

An error occured.

This error may be due to rate limits. If this error persists, please email us.

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Bug: Driver Null Check Inconsistency

The null check for this.driver was removed from the create method, making it inconsistent with other methods in the class (e.g., sendDraft, delete). This omission causes a runtime error (e.g., TypeError) if create is called when this.driver is null/undefined, instead of providing the expected "No driver available" error.

apps/server/src/routes/agent/index.ts#L122-L125

async create(data: IOutgoingMessage) {
return await this.driver.create(data);
}

Fix in CursorFix in Web


## Description

Added 'style' tag to the list of allowed HTML tags in the email sanitization configuration. This change enables the preservation of inline CSS styles when processing email HTML content, which is important for maintaining the original formatting and appearance of emails.

<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
## Summary by CodeRabbit

* **New Features**
  * Enhanced email content display by allowing inline styles in emails.
  * Improved security by sanitizing CSS within email styles to allow only safe properties and block harmful rules.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
@jazzberry-ai
Copy link

jazzberry-ai bot commented Jul 25, 2025

Bug Report

Name Severity Example test case Description
Incomplete CSS Sanitization Medium Send an email with font-family, width, border-radius, or @media rules. The allowedProperties in css-sanitizer is incomplete, leading to stripping of CSS styles and degradation of email appearance.
Insufficient Protection of /metrics Endpoint High Leak the GRAFANA_PASSWORD through logs or misconfiguration. The /metrics endpoint is protected only by a bearer token, which is vulnerable to leakage and unauthorized access.

Comments? Email us. Your free trial ends in 4 days.

# READ CAREFULLY THEN REMOVE

Remove bullet points that are not relevant.

PLEASE REFRAIN FROM USING AI TO WRITE YOUR CODE AND PR DESCRIPTION. IF YOU DO USE AI TO WRITE YOUR CODE PLEASE PROVIDE A DESCRIPTION AND REVIEW IT CAREFULLY. MAKE SURE YOU UNDERSTAND THE CODE YOU ARE SUBMITTING USING AI.

- Pull requests that do not follow these guidelines will be closed without review or comment.
- If you use AI to write your PR description your pr will be close without review or comment.
- If you are unsure about anything, feel free to ask for clarification.

## Description

Please provide a clear description of your changes.

---

## Type of Change

Please delete options that are not relevant.

- [ ] 🐛 Bug fix (non-breaking change which fixes an issue)
- [ ] ✨ New feature (non-breaking change which adds functionality)
- [ ] 💥 Breaking change (fix or feature with breaking changes)
- [ ] 📝 Documentation update
- [ ] 🎨 UI/UX improvement
- [ ] 🔒 Security enhancement
- [ ] ⚡ Performance improvement

## Areas Affected

Please check all that apply:

- [ ] Email Integration (Gmail, IMAP, etc.)
- [ ] User Interface/Experience
- [ ] Authentication/Authorization
- [ ] Data Storage/Management
- [ ] API Endpoints
- [ ] Documentation
- [ ] Testing Infrastructure
- [ ] Development Workflow
- [ ] Deployment/Infrastructure

## Testing Done

Describe the tests you've done:

- [ ] Unit tests added/updated
- [ ] Integration tests added/updated
- [ ] Manual testing performed
- [ ] Cross-browser testing (if UI changes)
- [ ] Mobile responsiveness verified (if UI changes)

## Security Considerations

For changes involving data or authentication:

- [ ] No sensitive data is exposed
- [ ] Authentication checks are in place
- [ ] Input validation is implemented
- [ ] Rate limiting is considered (if applicable)

## Checklist

- [ ] I have read the [CONTRIBUTING](https://github.com/Mail-0/Zero/blob/staging/.github/CONTRIBUTING.md) document
- [ ] My code follows the project's style guidelines
- [ ] I have performed a self-review of my code
- [ ] I have commented my code, particularly in complex areas
- [ ] I have updated the documentation
- [ ] My changes generate no new warnings
- [ ] I have added tests that prove my fix/feature works
- [ ] All tests pass locally
- [ ] Any dependent changes are merged and published

## Additional Notes

Add any other context about the pull request here.

## Screenshots/Recordings

Add screenshots or recordings here if applicable.

---

_By submitting this pull request, I confirm that my contribution is made under the terms of the project's license._

    
<!-- This is an auto-generated description by cubic. -->
---

## Summary by cubic
Removed all Prometheus metrics and Grafana integration from the server codebase.

- **Dependencies**
  - Removed prom-client and related packages from dependencies and lockfile.

<!-- End of auto-generated description by cubic. -->
@jazzberry-ai
Copy link

jazzberry-ai bot commented Jul 25, 2025

Bug Report

Name Severity Example test case Description
Potential CSS Sanitizer Bypass Medium Inject CSS with content property or complex animation syntax. The @barkleapp/css-sanitizer might be vulnerable to bypasses, allowing malicious CSS to be injected into emails. The current configuration might not be sufficient to prevent all potential attacks. Additionally, the use of @ts-ignore suggests a potential underlying type issue that should be properly resolved.

Comments? Email us. Your free trial ends in 4 days.

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Bug: Inconsistent Null Handling Across Methods

The null check for this.driver was removed from the create method, making it inconsistent with other methods in the same class (e.g., sendDraft, delete) that retain this check. If this.driver is null, this will cause a runtime error (e.g., TypeError) when attempting to call this.driver.create(data), instead of throwing the explicit "No driver available" error.

apps/server/src/routes/agent/index.ts#L122-L125

async create(data: IOutgoingMessage) {
return await this.driver.create(data);
}

Fix in CursorFix in Web


# READ CAREFULLY THEN REMOVE

Remove bullet points that are not relevant.

PLEASE REFRAIN FROM USING AI TO WRITE YOUR CODE AND PR DESCRIPTION. IF YOU DO USE AI TO WRITE YOUR CODE PLEASE PROVIDE A DESCRIPTION AND REVIEW IT CAREFULLY. MAKE SURE YOU UNDERSTAND THE CODE YOU ARE SUBMITTING USING AI.

- Pull requests that do not follow these guidelines will be closed without review or comment.
- If you use AI to write your PR description your pr will be close without review or comment.
- If you are unsure about anything, feel free to ask for clarification.

## Description

Please provide a clear description of your changes.

---

## Type of Change

Please delete options that are not relevant.

- [ ] 🐛 Bug fix (non-breaking change which fixes an issue)
- [ ] ✨ New feature (non-breaking change which adds functionality)
- [ ] 💥 Breaking change (fix or feature with breaking changes)
- [ ] 📝 Documentation update
- [ ] 🎨 UI/UX improvement
- [ ] 🔒 Security enhancement
- [ ] ⚡ Performance improvement

## Areas Affected

Please check all that apply:

- [ ] Email Integration (Gmail, IMAP, etc.)
- [ ] User Interface/Experience
- [ ] Authentication/Authorization
- [ ] Data Storage/Management
- [ ] API Endpoints
- [ ] Documentation
- [ ] Testing Infrastructure
- [ ] Development Workflow
- [ ] Deployment/Infrastructure

## Testing Done

Describe the tests you've done:

- [ ] Unit tests added/updated
- [ ] Integration tests added/updated
- [ ] Manual testing performed
- [ ] Cross-browser testing (if UI changes)
- [ ] Mobile responsiveness verified (if UI changes)

## Security Considerations

For changes involving data or authentication:

- [ ] No sensitive data is exposed
- [ ] Authentication checks are in place
- [ ] Input validation is implemented
- [ ] Rate limiting is considered (if applicable)

## Checklist

- [ ] I have read the [CONTRIBUTING](https://github.com/Mail-0/Zero/blob/staging/.github/CONTRIBUTING.md) document
- [ ] My code follows the project's style guidelines
- [ ] I have performed a self-review of my code
- [ ] I have commented my code, particularly in complex areas
- [ ] I have updated the documentation
- [ ] My changes generate no new warnings
- [ ] I have added tests that prove my fix/feature works
- [ ] All tests pass locally
- [ ] Any dependent changes are merged and published

## Additional Notes

Add any other context about the pull request here.

## Screenshots/Recordings

Add screenshots or recordings here if applicable.

---

_By submitting this pull request, I confirm that my contribution is made under the terms of the project's license._

    
<!-- This is an auto-generated description by cubic. -->
---

## Summary by cubic
Removed an unused import of prom-client from main.ts to clean up the code.

<!-- End of auto-generated description by cubic. -->
@jazzberry-ai
Copy link

jazzberry-ai bot commented Jul 25, 2025

Bug Report

Name: Missing CSS properties in sanitization

Severity: Medium

Example test case: Emails using font-family will not render correctly, as font-family is not in the allowedProperties list.

Description: The CSS sanitization logic in apps/server/src/lib/email-processor.ts might be too restrictive, preventing legitimate CSS properties like font-family from being used, leading to incorrect email rendering.

Comments? Email us. Your free trial ends in 4 days.

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Bug: Inconsistent Driver Null Handling

The null check for this.driver was removed from the create method. This creates an inconsistency, as other methods in the ZeroDriver class (e.g., sendDraft, delete) retain this safety check. If this.driver is null, calling create will now throw a generic TypeError (e.g., "Cannot read property 'create' of null") instead of the descriptive "No driver available" error, making debugging more difficult and breaking consistent error handling.

apps/server/src/routes/agent/index.ts#L122-L126

async create(data: IOutgoingMessage) {
return await this.driver.create(data);
}

Fix in CursorFix in Web


# READ CAREFULLY THEN REMOVE

Remove bullet points that are not relevant.

PLEASE REFRAIN FROM USING AI TO WRITE YOUR CODE AND PR DESCRIPTION. IF YOU DO USE AI TO WRITE YOUR CODE PLEASE PROVIDE A DESCRIPTION AND REVIEW IT CAREFULLY. MAKE SURE YOU UNDERSTAND THE CODE YOU ARE SUBMITTING USING AI.

- Pull requests that do not follow these guidelines will be closed without review or comment.
- If you use AI to write your PR description your pr will be close without review or comment.
- If you are unsure about anything, feel free to ask for clarification.

## Description

Please provide a clear description of your changes.

---

## Type of Change

Please delete options that are not relevant.

- [ ] 🐛 Bug fix (non-breaking change which fixes an issue)
- [ ] ✨ New feature (non-breaking change which adds functionality)
- [ ] 💥 Breaking change (fix or feature with breaking changes)
- [ ] 📝 Documentation update
- [ ] 🎨 UI/UX improvement
- [ ] 🔒 Security enhancement
- [ ] ⚡ Performance improvement

## Areas Affected

Please check all that apply:

- [ ] Email Integration (Gmail, IMAP, etc.)
- [ ] User Interface/Experience
- [ ] Authentication/Authorization
- [ ] Data Storage/Management
- [ ] API Endpoints
- [ ] Documentation
- [ ] Testing Infrastructure
- [ ] Development Workflow
- [ ] Deployment/Infrastructure

## Testing Done

Describe the tests you've done:

- [ ] Unit tests added/updated
- [ ] Integration tests added/updated
- [ ] Manual testing performed
- [ ] Cross-browser testing (if UI changes)
- [ ] Mobile responsiveness verified (if UI changes)

## Security Considerations

For changes involving data or authentication:

- [ ] No sensitive data is exposed
- [ ] Authentication checks are in place
- [ ] Input validation is implemented
- [ ] Rate limiting is considered (if applicable)

## Checklist

- [ ] I have read the [CONTRIBUTING](https://github.com/Mail-0/Zero/blob/staging/.github/CONTRIBUTING.md) document
- [ ] My code follows the project's style guidelines
- [ ] I have performed a self-review of my code
- [ ] I have commented my code, particularly in complex areas
- [ ] I have updated the documentation
- [ ] My changes generate no new warnings
- [ ] I have added tests that prove my fix/feature works
- [ ] All tests pass locally
- [ ] Any dependent changes are merged and published

## Additional Notes

Add any other context about the pull request here.

## Screenshots/Recordings

Add screenshots or recordings here if applicable.

---

_By submitting this pull request, I confirm that my contribution is made under the terms of the project's license._

    
<!-- This is an auto-generated description by cubic. -->
---

## Summary by cubic
Added a check in ZeroDriver's create method to throw an error if no driver is available, preventing calls without a valid driver.

<!-- End of auto-generated description by cubic. -->
@jazzberry-ai
Copy link

jazzberry-ai bot commented Jul 25, 2025

Bug Report

Name Severity Example test case Description
CSS Sanitization Bypass via border Property Medium <style>.test { border: 100px solid red !important; }</style> The allowed border property in the CSS sanitizer can be abused to create unexpected layout effects or visual distortions, especially when combined with !important. The limited number of other allowed CSS properties makes this more impactful.

Comments? Email us. Your free trial ends in 4 days.

@MrgSub
Copy link
Collaborator

MrgSub commented Jul 25, 2025

/deploy

@github-actions github-actions bot merged commit e7a0463 into main Jul 25, 2025
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

production-deploy This PR is meant to update production

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants