Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(control-api): include the generic lane in the proactive refresh enumeration (R1-L1)
Diego Zacariasec72eb7ceee8
diff --git a/control-api/package-lock.json b/control-api/package-lock.jsonindex 6e248e919..367afda39 100644--- a/control-api/package-lock.json+++ b/control-api/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-control-api",- "version": "0.1.654",+ "version": "0.1.655","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-control-api",- "version": "0.1.654",+ "version": "0.1.655","dependencies": {"@clerum/display-field": "file:../packages/display-field","@clerum/grok-provider-attempt-contract": "file:../packages/grok-provider-attempt-contract",diff --git a/control-api/package.json b/control-api/package.jsonindex 182cc1cf8..924123efd 100644--- a/control-api/package.json+++ b/control-api/package.json@@ -1,6 +1,6 @@{"name": "clerum-control-api",- "version": "0.1.654",+ "version": "0.1.655","description": "Internal Clerum control plane REST API + UI for managing CRDs and secrets","main": "dist/main.js","engines": {diff --git a/control-api/src/oauth/store.ts b/control-api/src/oauth/store.tsindex ab8f45283..b65037f49 100644--- a/control-api/src/oauth/store.ts+++ b/control-api/src/oauth/store.ts@@ -765,8 +765,9 @@ interface RemoteGrantWindowDbRow {}/**- * Reconstruct the flavored {@link OAuthGrantKey} for an mcpserver-owned remote- * grant enumerated by {@link listRemoteGrantsInProactiveWindow}. The enumeration+ * Reconstruct the flavored {@link OAuthGrantKey} for an mcpserver-owned grant+ * enumerated by {@link listRemoteGrantsInProactiveWindow} (remote OR generic lane;+ * the key is derived from `grant_kind`, independent of provider). The enumeration* filter admits only `shared` and background `user` grants, so those are the only* two flavors handled; a `service`/unexpected row throws (fail loud, never mint a* malformed key).@@ -798,14 +799,20 @@ function remoteGrantKeyFromRow(row: RemoteGrantWindowDbRow): OAuthGrantKey {}/**- * Enumerate the mcpserver-owned REMOTE grants whose access token sits inside the- * proactive window (mini-spec L §6.3). A snapshot SELECT with NO lock — the cron- * re-claims each row under `FOR UPDATE SKIP LOCKED` in its own short transaction+ * Enumerate the mcpserver-owned grants whose access token sits inside the+ * proactive window (mini-spec L §6.3). Covers BOTH the remote and generic+ * (mcpserver-owned) lanes: a `generic` grant admits background/context use and a+ * rotating refresh token exactly like remote (its reactive refresh already runs+ * via `refreshGenericGrant`), so an unattended one has the same silent-expiry risk+ * and belongs in the sweep (R1-L1). The DCR secret-expiry sweep stays remote-only+ * — dynamic clients are a remote-lane concept — so this function keeps its name.+ * A snapshot SELECT with NO lock — the cron re-claims each row under+ * `FOR UPDATE SKIP LOCKED` in its own short transaction* ({@link claimRemoteGrantForRefresh}) so no pool connection is pinned across the* refresh POSTs.*- * Filter (§4 eligibility + window): `provider='remote'`, non-null expiry in- * `(now+Br, now+Bp]`, and `grant_kind='shared' OR (grant_kind='user' AND+ * Filter (§4 eligibility + window): `provider IN ('remote','generic')`, non-null+ * expiry in `(now+Br, now+Bp]`, and `grant_kind='shared' OR (grant_kind='user' AND* background=true)` (SEC-5: unattended use only — non-background user grants are* excluded here as a first line of defense, `requireBackground:true` being the* second). Returns the flavored keys; tokens are never read.@@ -819,7 +826,7 @@ export async function listRemoteGrantsInProactiveWindow(oauth_client_id, grant_kindFROM oauth_grantsWHERE owner_kind = 'mcpserver'- AND provider = 'remote'+ AND provider IN ('remote', 'generic')AND access_token_expires_at IS NOT NULLAND access_token_expires_at > NOW() + ($1::bigint * INTERVAL '1 millisecond')AND access_token_expires_at <= NOW() + ($2::bigint * INTERVAL '1 millisecond')diff --git a/control-api/test/oauth.proactiveRefresh.realPostgres.integration.test.ts b/control-api/test/oauth.proactiveRefresh.realPostgres.integration.test.tsindex 1cb830dbc..5e68e0ab1 100644--- a/control-api/test/oauth.proactiveRefresh.realPostgres.integration.test.ts+++ b/control-api/test/oauth.proactiveRefresh.realPostgres.integration.test.ts@@ -245,6 +245,20 @@ describeRealPostgres('oauth proactive refresh — enumeration + claim (real Postexpect(names).toEqual(['e-shared-in', 'e-user-bg'])})+ it('R1-L1: a generic mcpserver grant in the window is enumerated (like remote)', async () => {+ // A generic-lane grant admits background/context use and a rotating refresh+ // token just like remote; an unattended one has the same silent-expiry risk,+ // so the proactive sweep must include it. Pre-fix (`provider='remote'`) it was+ // excluded.+ await seedShared('e-generic-in', 'ctx-g', 'generic', IN_WINDOW_SEC)+ await seedShared('e-generic-healthy', 'ctx-gh', 'generic', HEALTHY_SEC) // out of window++ const keys = await listRemoteGrantsInProactiveWindow(db, WINDOW)+ const names = keys.map(k => k.recipeName)+ expect(names).toContain('e-generic-in')+ expect(names).not.toContain('e-generic-healthy')+ })+it('FOR UPDATE SKIP LOCKED serializes the claim across connections', async () => {await seedShared('claim-a', 'ctx-1', 'remote', IN_WINDOW_SEC)const key = sharedKey('claim-a', 'ctx-1')