Skip to content

Enhanced ChatGPT Clone: Features Agents, MCP, Skills, DeepSeek, Anthropic, AWS, OpenAI, Responses API, Azure, Groq, o1, GPT-5, Mistral, OpenRouter, Vertex AI, Gemini, Artifacts, AI model switching, message search, Code Interpreter, langchain, DALL-E-3, OpenAPI Actions, Functions, Secure Multi-User Auth, Presets, open-source for self-hosting. Active

🏰 fix: Read OpenID Flight State From Mongo Primary (#15849)

Danny Avila1ef4aa9f1406
diff --git a/packages/data-schemas/src/methods/openidRefreshFlight.spec.ts b/packages/data-schemas/src/methods/openidRefreshFlight.spec.ts
index a4c71c0d17..42072be42b 100644
--- a/packages/data-schemas/src/methods/openidRefreshFlight.spec.ts
+++ b/packages/data-schemas/src/methods/openidRefreshFlight.spec.ts
@@ -71,6 +71,26 @@ describe('OpenIDRefreshFlight Methods', () => {
expect(second.flight?.status).toBe('pending');
});
+ it('reads an existing flight from the primary when resolving an acquisition conflict', async () => {
+ const readSpy = jest.spyOn(mongoose.Query.prototype, 'read');
+ await methods.acquireOpenIDRefreshFlight({
+ key: 'flight-key',
+ ownerId: 'owner-1',
+ lockExpiresAt: new Date(Date.now() + 30000),
+ expiresAt: new Date(Date.now() + 60000),
+ });
+
+ await methods.acquireOpenIDRefreshFlight({
+ key: 'flight-key',
+ ownerId: 'owner-2',
+ lockExpiresAt: new Date(Date.now() + 30000),
+ expiresAt: new Date(Date.now() + 60000),
+ });
+
+ expect(readSpy).toHaveBeenCalledWith('primary');
+ readSpy.mockRestore();
+ });
+
it('reclaims an expired pending lock', async () => {
await methods.acquireOpenIDRefreshFlight({
key: 'flight-key',
@@ -213,6 +233,15 @@ describe('OpenIDRefreshFlight Methods', () => {
await expect(methods.findOpenIDRefreshFlight({ key: 'flight-key' })).resolves.toBeNull();
});
+ it('reads publication state from the primary', async () => {
+ const readSpy = jest.spyOn(mongoose.Query.prototype, 'read');
+
+ await methods.findOpenIDRefreshFlight({ key: 'flight-key' });
+
+ expect(readSpy).toHaveBeenCalledWith('primary');
+ readSpy.mockRestore();
+ });
+
it('persists a logout revocation fence that an active owner cannot publish through', async () => {
await methods.acquireOpenIDRefreshFlight({
key: 'flight-key',
diff --git a/packages/data-schemas/src/methods/openidRefreshFlight.ts b/packages/data-schemas/src/methods/openidRefreshFlight.ts
index 140c658ad8..9c080bd657 100644
--- a/packages/data-schemas/src/methods/openidRefreshFlight.ts
+++ b/packages/data-schemas/src/methods/openidRefreshFlight.ts
@@ -130,7 +130,9 @@ export function createOpenIDRefreshFlightMethods(mongoose: typeof import('mongoo
const existing = await OpenIDRefreshFlight.findOne({
key: data.key,
expiresAt: { $gt: now },
- }).lean<IOpenIDRefreshFlight>();
+ })
+ .read('primary')
+ .lean<IOpenIDRefreshFlight>();
return { acquired: false, flight: existing };
} catch (error) {
@@ -243,7 +245,9 @@ export function createOpenIDRefreshFlightMethods(mongoose: typeof import('mongoo
return await OpenIDRefreshFlight.findOne({
key: query.key,
expiresAt: { $gt: new Date() },
- }).lean<IOpenIDRefreshFlight>();
+ })
+ .read('primary')
+ .lean<IOpenIDRefreshFlight>();
} catch (error) {
logger.debug('[findOpenIDRefreshFlight] Error finding flight:', error);
throw error;