Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix(gmail): keep transport endpoint and retry policy fixed
[._.]/ Adam Eivyfa5b5de95d46
diff --git a/server/services/README.md b/server/services/README.mdindex 50114d395e..cfeb98d8c9 100644--- a/server/services/README.md+++ b/server/services/README.md@@ -11,7 +11,7 @@ image-generation paths below are useful entry points when tracing render jobs.| `databaseMaintenanceCutover.js` | Internal cutover worker body (transfer → forward-only `.env` mode commit → server restart with target proof → release → CoS restart) and `recoverDatabaseCutover(id)` same-operation recovery for the CLI/API. || `databaseMaintenanceProducers.js` | Internal one-use coordinator stage: retain producer identity, stop this install's PM2 CoS/server, and verify fresh readback while admission remains fenced. || `databaseMaintenanceQuiescence.js` | Internal coordinator stage after producer shutdown: terminate verified running detached-writer groups, prove every registry record quiescent from process-table evidence, archive it with the operation, and refuse pending, legacy, orphaned, ambiguous or unregistered writers. |-| `gmailApi.js` | Six-operation Gmail v1 adapter (`createGmailApi(auth)`) over the shared OAuth client's `request()`: fixed origin, encoded IDs, URLSearchParams queries, explicit JSON bodies. Callers pass `{ retry: false }` for send; auth, refresh and transport stay in `googleAuth.js`. |+| `gmailApi.js` | Six-operation Gmail v1 adapter (`createGmailApi(auth)`) over the shared OAuth client's `request()`: fixed origin, encoded IDs, URLSearchParams queries, explicit JSON bodies, capped 30s request timeout and no automatic send retries. Auth, refresh and transport stay in `googleAuth.js`. || `imageGen/prepareParams.js` | Shared image request preparation and the canonical local image model selector. Use `selectLocalImageModelFromSettings()` for model identity and `resolveLocalImageModel()` when the caller must also enforce local runtime, hardware, and edit-image requirements. || `musicVideo/renderCancellation.js` | Shared capture-abort and ffmpeg kill selection for full/excerpt renders; records explicit cancellation before signaling and classifies nonzero closes without releasing ownership. || `musicVideo/sharingCopy.js` | Source-hashed private sharing MP4s: queued 720p H.264/AAC export, strict decimal 100 MB cap, supervised cancellation, verified download and owned-file cleanup. |diff --git a/server/services/gmailApi.js b/server/services/gmailApi.jsindex 131ec46eb3..0b43b96aa5 100644--- a/server/services/gmailApi.js+++ b/server/services/gmailApi.js@@ -14,14 +14,18 @@ const GMAIL_ORIGIN = 'https://gmail.googleapis.com/gmail/v1/users/me';* @param {{ request: Function }} auth - authenticated OAuth2 client*/export function createGmailApi(auth) {- const call = (method, path, { query, body, options } = {}) => {+ const call = (method, path, { query, body, options, neverRetry = false } = {}) => {const search = query?.toString();+ const requestedTimeout = options?.timeout;+ const timeout = Number.isFinite(requestedTimeout) && requestedTimeout > 0+ ? Math.min(requestedTimeout, GOOGLE_API_TIMEOUT_MS)+ : GOOGLE_API_TIMEOUT_MS;return auth.request({url: `${GMAIL_ORIGIN}${path}${search ? `?${search}` : ''}`,method,- timeout: GOOGLE_API_TIMEOUT_MS,+ timeout,...(body !== undefined && { data: body }),- ...options+ ...((neverRetry || options?.retry === false) && { retry: false })}).then((res) => res.data);};const messagePath = (id) => `/messages/${encodeURIComponent(id)}`;@@ -37,8 +41,9 @@ export function createGmailApi(auth) {return call('GET', '/messages', { query });},- // `options` overrides per-request transport settings (e.g. a shorter- // `timeout`, `retry: false`) without widening the endpoint surface.+ // Only a shorter timeout and explicitly disabled retries are accepted as+ // transport options. The fixed endpoint, verb, data and timeout ceiling+ // are always owned by this adapter.getMessage: (id, { format, metadataHeaders = [] } = {}, options) => {const query = new URLSearchParams();if (format) query.set('format', format);@@ -46,9 +51,9 @@ export function createGmailApi(auth) {return call('GET', messagePath(id), { query, options });},- // No idempotency key exists for send: the caller passes `retry: false` so- // the transport never resubmits after a lost acknowledgement.- sendMessage: (body, options) => call('POST', '/messages/send', { body, options }),+ // No idempotency key exists for send, so the transport never resubmits it+ // after a lost acknowledgement, regardless of caller-supplied options.+ sendMessage: (body, options) => call('POST', '/messages/send', { body, options, neverRetry: true }),trashMessage: (id) => call('POST', `${messagePath(id)}/trash`),diff --git a/server/services/gmailApi.test.js b/server/services/gmailApi.test.jsindex 11eef01cf2..c5c55c3e1f 100644--- a/server/services/gmailApi.test.js+++ b/server/services/gmailApi.test.js@@ -1,6 +1,7 @@import { beforeEach, describe, expect, it, vi } from 'vitest';import { auth as googleAuth } from '@googleapis/calendar';import { createGmailApi } from './gmailApi.js';+import { GOOGLE_API_TIMEOUT_MS } from './googleAuth.js';import { messageLogError } from '../lib/messageLogError.js';// Real OAuth client and request pipeline; only the network (fetch) is stubbed,@@ -57,6 +58,34 @@ describe('Gmail adapter HTTP contract', () => {expect(url.searchParams.getAll('metadataHeaders')).toEqual(['Message-ID', 'Subject']);});+ it('accepts only capped timeout and no-retry transport settings for reads', async () => {+ const oauth = client();+ const request = vi.spyOn(oauth, 'request');+ const api = createGmailApi(oauth);+ await api.getMessage('m/1', { format: 'full' }, {+ url: 'https://attacker.example/collect',+ method: 'DELETE',+ data: { forged: true },+ timeout: GOOGLE_API_TIMEOUT_MS * 2,+ retry: false,+ });+ await api.getMessage('m/2', {}, { timeout: 10_000, retry: false });++ const [capped, shorter] = request.mock.calls.map(([options]) => options);+ expect(capped).toMatchObject({+ url: `${ORIGIN}/messages/m%2F1?format=full`, method: 'GET',+ timeout: GOOGLE_API_TIMEOUT_MS, retry: false,+ });+ expect(capped).not.toHaveProperty('data');+ expect(shorter).toMatchObject({+ url: `${ORIGIN}/messages/m%2F2`, method: 'GET', timeout: 10_000, retry: false,+ });+ expect(calls.map(({ method, url, body }) => [method, url, body])).toEqual([+ ['GET', `${ORIGIN}/messages/m%2F1?format=full`, undefined],+ ['GET', `${ORIGIN}/messages/m%2F2`, undefined],+ ]);+ });+it('posts send, trash and modify with explicit methods and JSON bodies', async () => {const api = createGmailApi(client());await api.sendMessage({ raw: 'ZXhhbXBsZQ', threadId: 'thread-1' }, { retry: false });@@ -96,4 +125,51 @@ describe('Gmail adapter HTTP contract', () => {expect(failure.response.status).toBe(503);expect(calls).toHaveLength(1);});++ it('keeps send endpoint, method, body, timeout ceiling and no-retry policy adapter-owned', async () => {+ answer = () => json(503, { error: { code: 503, message: 'Example backend error' } });+ const oauth = client();+ const request = vi.spyOn(oauth, 'request');+ const payload = { raw: 'ZXhhbXBsZQ', threadId: 'thread-1' };+ const overrides = {+ url: 'https://attacker.example/collect',+ method: 'DELETE',+ data: { raw: 'forged' },+ timeout: GOOGLE_API_TIMEOUT_MS * 2,+ retry: true,+ headers: { authorization: 'Bearer attacker' },+ };++ const failure = await createGmailApi(oauth).sendMessage(payload, overrides).catch(err => err);++ expect(failure.response.status).toBe(503);+ expect(request).toHaveBeenCalledTimes(1);+ const requestOptions = request.mock.calls[0][0];+ expect(requestOptions).toMatchObject({+ url: `${ORIGIN}/messages/send`,+ method: 'POST',+ timeout: GOOGLE_API_TIMEOUT_MS,+ data: payload,+ retry: false,+ });+ expect(Object.keys(requestOptions).sort()).toEqual(['data', 'headers', 'method', 'retry', 'timeout', 'url']);+ expect(requestOptions.headers.get('authorization')).toBe('Bearer example-token');+ expect(calls).toHaveLength(1);+ expect(calls[0]).toMatchObject({ url: `${ORIGIN}/messages/send`, method: 'POST', body: payload });+ expect(calls[0].headers.get('authorization')).toBe('Bearer example-token');+ });++ it('preserves a shorter send timeout without allowing retries', async () => {+ const oauth = client();+ const request = vi.spyOn(oauth, 'request');+ const payload = { raw: 'ZXhhbXBsZQ' };++ await createGmailApi(oauth).sendMessage(payload, { timeout: 10_000, retry: true });++ expect(request.mock.calls[0][0]).toMatchObject({+ url: `${ORIGIN}/messages/send`, method: 'POST', timeout: 10_000,+ data: payload, retry: false,+ });+ expect(calls).toHaveLength(1);+ });});