Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
perf(control-api): bound publish-scope cache lifetime
Josué2b132307fc20
diff --git a/control-api/package-lock.json b/control-api/package-lock.jsonindex 6059fe77a..2f9aeda00 100644--- a/control-api/package-lock.json+++ b/control-api/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-control-api",- "version": "0.1.402",+ "version": "0.1.403","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-control-api",- "version": "0.1.402",+ "version": "0.1.403","dependencies": {"@clerum/image-policy": "file:../packages/image-policy","@clerum/llm-providers": "file:../packages/llm-providers",diff --git a/control-api/package.json b/control-api/package.jsonindex da67d9803..debd4fdbd 100644--- a/control-api/package.json+++ b/control-api/package.json@@ -1,6 +1,6 @@{"name": "clerum-control-api",- "version": "0.1.402",+ "version": "0.1.403","description": "Internal Clerum control plane REST API + UI for managing CRDs and secrets","main": "dist/main.js","engines": {diff --git a/control-api/src/services/registryClient.ts b/control-api/src/services/registryClient.tsindex f07979b80..c7460147f 100644--- a/control-api/src/services/registryClient.ts+++ b/control-api/src/services/registryClient.ts@@ -680,6 +680,7 @@ export async function listOrgEntries(// client to its bound org / curator status). The module-level cache is scoped to// the current registry identity generation and is invalidated when the local// registry connection row or credentials change.+const PUBLISH_SCOPE_CACHE_TTL_MS = CATALOG_CACHE_TTL_MSexport interface PublishScope {curator: boolean@@ -687,7 +688,7 @@ export interface PublishScope {scope: string | null}-let _scopeCache: { generation: number; scope: PublishScope } | null = null+let _scopeCache: { generation: number; scope: PublishScope; ts: number } | null = nulllet _scopePending: { generation: number; promise: Promise<PublishScope> } | null = nullexport async function whoami(): Promise<{@@ -702,7 +703,12 @@ export async function whoami(): Promise<{export async function resolvePublishScope(opts?: { force?: boolean }): Promise<PublishScope> {return withCurrentRegistryIdentity(generation => {- if (_scopeCache && _scopeCache.generation === generation && !opts?.force)+ if (+ _scopeCache &&+ _scopeCache.generation === generation &&+ Date.now() - _scopeCache.ts < PUBLISH_SCOPE_CACHE_TTL_MS &&+ !opts?.force+ )return Promise.resolve(_scopeCache.scope)const pending =!opts?.force && _scopePending?.generation === generation ? _scopePending : null@@ -718,7 +724,7 @@ export async function resolvePublishScope(opts?: { force?: boolean }): Promise<Pscope: w.curator || !w.orgName ? null : `@${w.orgName}`,}if (isRegistryIdentityCacheGenerationCurrent(generation)) {- _scopeCache = { generation, scope }+ _scopeCache = { generation, scope, ts: Date.now() }}return scope})diff --git a/control-api/test/registryClient.test.ts b/control-api/test/registryClient.test.tsindex 3938dd6b6..14aadf9fd 100644--- a/control-api/test/registryClient.test.ts+++ b/control-api/test/registryClient.test.ts@@ -570,6 +570,48 @@ describe('registryClient — resolvePublishScope', () => {expect(fetchMock.mock.calls.length).toBe(callsAfterFirst)})+ it('revalidates cached publish scope after the registry cache TTL expires', async () => {+ vi.useFakeTimers()+ vi.setSystemTime(new Date('2026-01-01T00:00:00Z'))+ let whoamiCalls = 0+ const fetchMock = vi.fn().mockImplementation((url: string) => {+ if (url.endsWith('/oauth/token')) {+ return Promise.resolve(fakeTokenResponse('tok-scope', 6000))+ }+ whoamiCalls += 1+ const orgName = whoamiCalls === 1 ? 'alpha' : 'bravo'+ return Promise.resolve(+ new Response(JSON.stringify({ clientId: orgName, orgName, curator: false }), {+ status: 200,+ headers: { 'content-type': 'application/json' },+ })+ )+ })+ vi.stubGlobal('fetch', fetchMock)+ Object.assign(process.env, ENV_OVERRIDE)++ await expect(resolvePublishScope()).resolves.toEqual({+ curator: false,+ orgName: 'alpha',+ scope: '@alpha',+ })++ vi.setSystemTime(Date.now() + 14_999)+ await expect(resolvePublishScope()).resolves.toEqual({+ curator: false,+ orgName: 'alpha',+ scope: '@alpha',+ })++ vi.setSystemTime(Date.now() + 1)+ await expect(resolvePublishScope()).resolves.toEqual({+ curator: false,+ orgName: 'bravo',+ scope: '@bravo',+ })+ expect(whoamiCalls).toBe(2)+ })+it('invalidates cached token and publish scope when registry identity changes', async () => {let tokenCalls = 0let whoamiCalls = 0