Skip to content

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

TypeScript

fix: decide Codex spend upgrade from persisted ledger state

Alfredo Lopeze13b4de81536
diff --git a/control-api/package-lock.json b/control-api/package-lock.json
index f33b73361..ecf62e504 100644
--- a/control-api/package-lock.json
+++ b/control-api/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-control-api",
- "version": "0.1.534",
+ "version": "0.1.535",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-control-api",
- "version": "0.1.534",
+ "version": "0.1.535",
"dependencies": {
"@clerum/display-field": "file:../packages/display-field",
"@clerum/image-policy": "file:../packages/image-policy",
diff --git a/control-api/package.json b/control-api/package.json
index 61aa2e9fb..fb00c01b2 100644
--- a/control-api/package.json
+++ b/control-api/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-control-api",
- "version": "0.1.534",
+ "version": "0.1.535",
"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/pluginWorkloadSdkFinalization.ts b/control-api/src/services/pluginWorkloadSdkFinalization.ts
index fa3281a60..6763952e3 100644
--- a/control-api/src/services/pluginWorkloadSdkFinalization.ts
+++ b/control-api/src/services/pluginWorkloadSdkFinalization.ts
@@ -340,9 +340,15 @@ export async function finalizePromptBridgeInTransaction(
)
const existing = existingResult.rows[0] as SpendOutcomeRow | undefined
if (existing) {
- if (isOauthBrokerProvider(existing.provider) && input.status === 'complete') {
+ if (isOauthBrokerProvider(existing.provider)) {
const linkedCodex = await loadLlmProviderAttemptBySdkAttemptId(db, input.providerAttemptId)
- if (linkedCodex && isLinkedCodexInFlightWithoutUsage(linkedCodex)) {
+ // Upgrade and ledger_pending are decided from persisted spend + the
+ // linked Codex row, not from the caller-chosen finalize status.
+ if (
+ existing.outcome === 'unknown' &&
+ linkedCodex &&
+ isLinkedCodexInFlightWithoutUsage(linkedCodex)
+ ) {
throw new PromptBridgeFinalizationError(
'ledger_pending',
'linked Codex attempt has not finalized usage yet',