fix deployment (#1712)

# 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 deployment issues by updating concurrency settings, improving Gmail API calls, and adjusting wrangler configuration for new classes.

- **Bug Fixes**
  - Set thread processing concurrency to 1 to prevent overload.
  - Improved Gmail API label and thread fetching logic.
  - Added delay in thread syncing to reduce rate limit errors.

- **Dependencies**
  - Updated wrangler.jsonc to register new SQLite classes for deployment.

<!-- End of auto-generated description by cubic. -->
This commit is contained in:
Adam
2025-07-11 11:30:08 -07:00
committed by GitHub
parent 5d7421194c
commit 992dc8079a
4 changed files with 31 additions and 23 deletions

View File

@@ -8,7 +8,6 @@ import {
sanitizeContext,
StandardizedError,
} from './utils';
import { Effect } from 'effect';
import { mapGoogleLabelColor, mapToGoogleLabelColor } from './google-label-color-map';
import { parseAddressList, parseFrom, wasSentWithTLS } from '../email-utils';
import type { IOutgoingMessage, Label, ParsedMessage } from '../../types';
@@ -21,6 +20,7 @@ import { createMimeMessage } from 'mimetext';
import { people } from '@googleapis/people';
import { cleanSearchValue } from '../utils';
import { env } from 'cloudflare:workers';
import { Effect } from 'effect';
import * as he from 'he';
export class GoogleMailManager implements MailManager {
@@ -190,19 +190,20 @@ export class GoogleMailManager implements MailManager {
if (!userLabels.data.labels) {
return [];
}
const labelRequests = userLabels.data.labels.map((label) =>
Effect.tryPromise({
try: () => this.gmail.users.labels.get({
userId: 'me',
id: label.id ?? undefined,
}),
try: () =>
this.gmail.users.labels.get({
userId: 'me',
id: label.id ?? undefined,
}),
catch: (error) => ({ _tag: 'LabelFetchFailed' as const, error }),
})
}),
);
const results = await Effect.runPromise(
Effect.all(labelRequests, { concurrency: 'unbounded' })
Effect.all(labelRequests, { concurrency: 'unbounded' }),
);
return results.map((res) => ({
@@ -785,7 +786,8 @@ export class GoogleMailManager implements MailManager {
const res = await this.gmail.users.threads.get({
userId: 'me',
id: threadId,
format: 'metadata', // Fetch only metadata
format: 'metadata', // Fetch only metadata,
quotaUser: this.config.auth?.email,
});
// Process res.data.messages to extract id and labelIds
return {

View File

@@ -329,7 +329,7 @@ export const runZeroWorkflow = (
);
}),
),
{ concurrency: 5 }, // Process up to 5 threads concurrently
{ concurrency: 1 }, // Process up to 5 threads concurrently
);
yield* Console.log('[ZERO_WORKFLOW] All thread workflows completed:', threadResults.length);

View File

@@ -45,10 +45,10 @@ import { FOLDERS } from '../lib/utils';
import { and, eq } from 'drizzle-orm';
import { McpAgent } from 'agents/mcp';
import { createDb } from '../db';
import { z } from 'zod';
import { Effect } from 'effect';
import { withGmailRetry } from '../lib/gmail-rate-limit';
import { createDb } from '../db';
import { Effect } from 'effect';
import { z } from 'zod';
const decoder = new TextDecoder();
@@ -940,21 +940,13 @@ export class ZeroAgent extends AIChatAgent<typeof env> {
private async listWithRetry(params: Parameters<MailManager['list']>[0]) {
if (!this.driver) throw new Error('No driver available');
return Effect.runPromise(
withGmailRetry(
Effect.tryPromise(() => this.driver!.list(params))
),
);
return Effect.runPromise(withGmailRetry(Effect.tryPromise(() => this.driver!.list(params))));
}
private async getWithRetry(threadId: string): Promise<IGetThreadResponse> {
if (!this.driver) throw new Error('No driver available');
return Effect.runPromise(
withGmailRetry(
Effect.tryPromise(() => this.driver!.get(threadId))
),
);
return Effect.runPromise(withGmailRetry(Effect.tryPromise(() => this.driver!.get(threadId))));
}
async syncThreads(folder: string) {
@@ -985,6 +977,8 @@ export class ZeroAgent extends AIChatAgent<typeof env> {
while (hasMore) {
_pageCount++;
await new Promise((resolve) => setTimeout(resolve, 2000));
const result = await this.listWithRetry({
folder,
maxResults: maxCount,

View File

@@ -78,6 +78,10 @@
"tag": "v3",
"new_classes": ["ZeroDB"],
},
{
"tag": "v4",
"new_sqlite_classes": ["ZeroAgent"],
},
],
"observability": {
@@ -211,6 +215,10 @@
"tag": "v3",
"new_classes": ["ZeroDB"],
},
{
"tag": "v4",
"new_sqlite_classes": ["ZeroAgent"],
},
],
"observability": {
"enabled": true,
@@ -346,6 +354,10 @@
"tag": "v3",
"new_classes": ["ZeroDB"],
},
{
"tag": "v4",
"new_sqlite_classes": ["ZeroAgent"],
},
],
"vars": {
"NODE_ENV": "production",