Skip to content

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

TypeScript

test(control-api): a fenced reauth mark that matches no row is a lost race (#753)

Alfredo Lopeze3e3292f76de
diff --git a/control-api/package-lock.json b/control-api/package-lock.json
index e21fcf1e4..c0f7b6769 100644
--- a/control-api/package-lock.json
+++ b/control-api/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-control-api",
- "version": "0.1.610",
+ "version": "0.1.611",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-control-api",
- "version": "0.1.610",
+ "version": "0.1.611",
"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.json
index 7e01ada66..b9757d8d4 100644
--- a/control-api/package.json
+++ b/control-api/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-control-api",
- "version": "0.1.610",
+ "version": "0.1.611",
"description": "Internal Clerum control plane REST API + UI for managing CRDs and secrets",
"main": "dist/main.js",
"engines": {
diff --git a/control-api/test/services.codexSubscriptionRefreshRejected.realPostgres.integration.test.ts b/control-api/test/services.codexSubscriptionRefreshRejected.realPostgres.integration.test.ts
index e91b6f409..60ff24a47 100644
--- a/control-api/test/services.codexSubscriptionRefreshRejected.realPostgres.integration.test.ts
+++ b/control-api/test/services.codexSubscriptionRefreshRejected.realPostgres.integration.test.ts
@@ -314,6 +314,46 @@ describeRealPostgres('Codex refresh rejected by the vendor on real PostgreSQL (#
expect(await statusOf(key)).toBe('connected')
})
+ it('T-753h a revoke landing between the fence check and the mark is a lost race, not a persisted reauth', async () => {
+ const key = 'codex-753h-revoked'
+ await seedConnected(key)
+ const fetchFn = tokenEndpoint(400, { error: 'invalid_grant' })
+ // The fence reads pass; the revoke lands just before the fenced UPDATE, so
+ // the mark matches no row. Only the status write is intercepted; every other
+ // statement runs unchanged against the real database.
+ let markAttempts = 0
+ const racingDb = {
+ query: async (text: string, values?: unknown[]) => {
+ if (text.includes("SET status = 'reauth_required'")) {
+ markAttempts += 1
+ await pool.query(
+ `UPDATE codex_subscription_connections
+ SET revoked_at = now()
+ WHERE connection_key = $1`,
+ [key]
+ )
+ }
+ return pool.query(text, values)
+ },
+ }
+
+ const failure = await ensureFreshCodexAccessToken({
+ ...deps(key, fetchFn as typeof fetch),
+ db: racingDb,
+ }).then(
+ () => null,
+ (err: unknown) => err
+ )
+
+ // Liveness witness: the exchange ran and the mark was attempted, so the
+ // outcome below is the empty UPDATE and not an earlier exit.
+ expect(fetchFn).toHaveBeenCalledTimes(1)
+ expect(markAttempts).toBe(1)
+ expect(failure).toBeInstanceOf(CodexSubscriptionOAuthError)
+ expect(failure).toMatchObject({ code: 'stale_revision', persistedConnectionStatus: false })
+ expect(await statusOf(key)).not.toBe('reauth_required')
+ })
+
it('T-753e a 503 from the token endpoint stays provider_unavailable and leaves the row connected', async () => {
const key = 'codex-753e-503'
await seedConnected(key)