Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

fix(desktop-app): log oauth completion-queue cap evictions (R4-L8b)

Diego Zacarias9f9eacadad0e
diff --git a/desktop-app/src/__tests__/mcpOauthCompletionQueue.test.ts b/desktop-app/src/__tests__/mcpOauthCompletionQueue.test.ts
index 6bf8d73d7..1443b05f9 100644
--- a/desktop-app/src/__tests__/mcpOauthCompletionQueue.test.ts
+++ b/desktop-app/src/__tests__/mcpOauthCompletionQueue.test.ts
@@ -79,4 +79,47 @@ describe('McpOauthCompletionQueue — U5 cold-start delivery (T5)', () => {
expect(queue.pendingCount()).toBe(1)
})
+
+ it('L8b: an over-cap drop invokes onCapEvict with the OLDEST completion and the cap', () => {
+ const deliver = vi.fn().mockReturnValue(false) // nothing accepted → everything queues
+ const onCapEvict = vi.fn()
+ const queue = new McpOauthCompletionQueue(deliver, 2, onCapEvict)
+
+ const C = { mcpServerName: 'asana', provider: 'asana' }
+ queue.submit(A) // [A]
+ queue.submit(B) // [A, B]
+ expect(onCapEvict).not.toHaveBeenCalled()
+ queue.submit(C) // push → over cap → drop A (oldest)
+
+ // The drop is now observable — it is NOT silent.
+ expect(onCapEvict).toHaveBeenCalledOnce()
+ expect(onCapEvict).toHaveBeenCalledWith(A, 2)
+ expect(queue.pendingCount()).toBe(2)
+
+ // Policy unchanged: the OLDEST (A) is gone, B and C survive.
+ const delivered: Array<typeof A> = []
+ deliver.mockImplementation(c => {
+ delivered.push(c)
+ return true
+ })
+ queue.drain()
+ expect(delivered).toEqual([B, C])
+ })
+
+ it('L8b: the default cap-evict hook logs a warning (production observability)', () => {
+ const warn = vi.spyOn(console, 'warn').mockImplementation(() => undefined)
+ const deliver = vi.fn().mockReturnValue(false)
+ // Default onCapEvict (no injection) → must reach console.warn on a drop.
+ const queue = new McpOauthCompletionQueue(deliver, 1)
+
+ queue.submit(A) // [A]
+ queue.submit(B) // over cap → drop A via the default warn hook
+
+ expect(warn).toHaveBeenCalledOnce()
+ const [message, context] = warn.mock.calls[0]!
+ expect(String(message)).toContain('dropping oldest')
+ // Non-sensitive context only: server/provider identity + cap, no URL/token.
+ expect(context).toMatchObject({ mcpServerName: A.mcpServerName, provider: A.provider })
+ warn.mockRestore()
+ })
})
diff --git a/desktop-app/src/mcpOauthCompletionQueue.ts b/desktop-app/src/mcpOauthCompletionQueue.ts
index 4ce3a3ae2..c215c5f85 100644
--- a/desktop-app/src/mcpOauthCompletionQueue.ts
+++ b/desktop-app/src/mcpOauthCompletionQueue.ts
@@ -18,6 +18,21 @@ export interface McpOauthCompletion {
provider: string
}
+/**
+ * Default cap-eviction hook: log the silent drop so an over-cap queue (an
+ * abnormal flood of deep links before the renderer drains) is observable in
+ * the main-process log. Only NON-sensitive context is emitted — the server and
+ * provider identity plus the cap — never the deep-link URL, its query, or any
+ * token.
+ */
+function warnOnCapEvict(evicted: McpOauthCompletion, capacity: number): void {
+ console.warn('[McpOauthCompletion] queue at capacity, dropping oldest pending completion', {
+ mcpServerName: evicted.mcpServerName,
+ provider: evicted.provider,
+ capacity,
+ })
+}
+
export class McpOauthCompletionQueue {
private readonly pending: McpOauthCompletion[] = []
@@ -25,10 +40,18 @@ export class McpOauthCompletionQueue {
* @param deliver Sends the completion to the renderer, returning `true` iff it
* was accepted (window alive AND renderer past its ready handshake). A
* `false` return means "not ready" → the completion is queued.
+ * @param onCapEvict Invoked with the dropped completion and the cap whenever a
+ * push exceeds `maxSize`. Defaults to a `console.warn`; injectable so the
+ * observability is unit-testable. The eviction policy is unchanged (still
+ * drops the OLDEST) — this only makes the drop observable.
*/
constructor(
private readonly deliver: (completion: McpOauthCompletion) => boolean,
- private readonly maxSize = 20
+ private readonly maxSize = 20,
+ private readonly onCapEvict: (
+ evicted: McpOauthCompletion,
+ capacity: number
+ ) => void = warnOnCapEvict
) {}
/** Deliver now if the renderer accepts it; otherwise queue for `drain()`. */
@@ -41,7 +64,10 @@ export class McpOauthCompletionQueue {
)
if (duplicate) return
this.pending.push(completion)
- if (this.pending.length > this.maxSize) this.pending.shift()
+ if (this.pending.length > this.maxSize) {
+ const evicted = this.pending.shift()
+ if (evicted) this.onCapEvict(evicted, this.maxSize)
+ }
}
/**