Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(codex-sdk): close round-6 review nits and drop internal review tags
Alfredo Lopez0d7d8fa296b4
diff --git a/control-api/package-lock.json b/control-api/package-lock.jsonindex 74cbe884e..5c1be0f11 100644--- a/control-api/package-lock.json+++ b/control-api/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-control-api",- "version": "0.1.543",+ "version": "0.1.544","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-control-api",- "version": "0.1.543",+ "version": "0.1.544","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.jsonindex 0265e3e23..f29d153cb 100644--- a/control-api/package.json+++ b/control-api/package.json@@ -1,6 +1,6 @@{"name": "clerum-control-api",- "version": "0.1.543",+ "version": "0.1.544","description": "Internal Clerum control plane REST API + UI for managing CRDs and secrets","main": "dist/main.js","engines": {diff --git a/control-api/src/routes/admin/pluginWorkloadSdk.ts b/control-api/src/routes/admin/pluginWorkloadSdk.tsindex 89b149045..4c4ff34cb 100644--- a/control-api/src/routes/admin/pluginWorkloadSdk.ts+++ b/control-api/src/routes/admin/pluginWorkloadSdk.ts@@ -148,7 +148,7 @@ function parseModelArray(value: unknown, field: string, res: Response): string[]// wire for compatibility and are validated with the same shape rules, but they// are stripped before persistence — only per-minute/platform limits are stored.//-// R4-H2: `maxOutputTokens` was briefly moved here on the premise that nothing+// `maxOutputTokens` was briefly moved here on the premise that nothing// enforced it. That premise held only for codex-subscription, whose ChatGPT// wire rejects `max_output_tokens` and whose proxy therefore omits it. Every// API-key provider does send it (`openai.ts`, `bedrockConverse.ts`,diff --git a/control-api/src/routes/mcp-host/plugin-workload-sdk.routes.ts b/control-api/src/routes/mcp-host/plugin-workload-sdk.routes.tsindex 915dee85e..e1ef17d3d 100644--- a/control-api/src/routes/mcp-host/plugin-workload-sdk.routes.ts+++ b/control-api/src/routes/mcp-host/plugin-workload-sdk.routes.ts@@ -747,7 +747,7 @@ export function createMcpHostPluginWorkloadSdkRoutes(): Router {// readiness gap, never an unfenced spend: llmProviderAttemptAuthorizer// and llmProviderAttemptRedemption already reject a stale revision.//- // R4-M4: `codexBindingRevisions` is a STATIC capability of this binary —+ // `codexBindingRevisions` is a STATIC capability of this binary —// "I know how to publish the revisions" — not a statement about any one// connection. Emitting it only alongside the numbers made a revoked or// missing connection look like an older control-api, so the host skippeddiff --git a/control-api/src/services/llmProviderAttemptAuthorizer.ts b/control-api/src/services/llmProviderAttemptAuthorizer.tsindex 57c9ff148..5837107f4 100644--- a/control-api/src/services/llmProviderAttemptAuthorizer.ts+++ b/control-api/src/services/llmProviderAttemptAuthorizer.ts@@ -352,7 +352,7 @@ export async function authorizeLlmProviderAttempt(// before budget reservation work so concurrent Codex + fallback cannot// deadlock (budget rows then advisory vs advisory then spend/invocation).//- // R4-M3: only an SDK-linked authorize goes on to take plugin_workload_sdk_*+ // Only an SDK-linked authorize goes on to take plugin_workload_sdk_*// rows FOR UPDATE, which is the order finalize follows after this advisory.// The workflow lane touches neither, so taking it for every recipe caller// serialized that lane per recipe for no ordering benefit.diff --git a/control-api/src/services/llmProviderAttemptStore.ts b/control-api/src/services/llmProviderAttemptStore.tsindex 7abf5f4e4..da7b06861 100644--- a/control-api/src/services/llmProviderAttemptStore.ts+++ b/control-api/src/services/llmProviderAttemptStore.ts@@ -85,7 +85,7 @@ export function isLinkedCodexInFlightWithoutUsage(? Date.parse(String(row.createdAt)): Number.NaNif (!Number.isFinite(created)) {- // N-15: an unreadable created_at used to default to "still in flight",+ // An unreadable created_at used to default to "still in flight",// which wedges the invocation behind ledger_pending forever and silently// hides a corrupt/absent timestamp. The grace window is undecidable here,// so fail loudly instead of guessing.diff --git a/control-api/src/services/pluginWorkloadSdkAuthorizer.ts b/control-api/src/services/pluginWorkloadSdkAuthorizer.tsindex 3ed47a978..f33b4e1aa 100644--- a/control-api/src/services/pluginWorkloadSdkAuthorizer.ts+++ b/control-api/src/services/pluginWorkloadSdkAuthorizer.ts@@ -115,7 +115,7 @@ export interface AuthorizedPromptBridge {/*** Per-grant output ceiling. Enforced as `max_tokens` on API-key providers;* codex-subscription cannot bind it on the ChatGPT wire and is bounded by- * the contract's structural LIMITS.maxOutputTokens instead (R4-H2).+ * the contract's structural LIMITS.maxOutputTokens instead.*/maxOutputTokens: number | nullinvocationId: string@@ -606,7 +606,7 @@ export async function reissuePromptBridgeCredentialTicket(const reservationOnly =isLlmProviderId(target.provider) && PROVIDER_AUTH_MODE[target.provider] === 'oauth-broker'- // RP-539-009: an oauth-broker target is redeemable only through the broker+ // An oauth-broker target is redeemable only through the broker// binding the WRC installs for the grant's default target. Any other broker// target would be reserved here and then die in execution with no credential// to redeem, after the reservation already charged the attempt budget. Denydiff --git a/control-api/src/services/pluginWorkloadSdkDb.ts b/control-api/src/services/pluginWorkloadSdkDb.tsindex c88dde3e5..879fb2969 100644--- a/control-api/src/services/pluginWorkloadSdkDb.ts+++ b/control-api/src/services/pluginWorkloadSdkDb.ts@@ -177,10 +177,10 @@ export interface PluginWorkloadSdkQuotaLimits {* Per-grant output ceiling. PERSISTED and enforced: it lands as `max_tokens`* on API-key providers; codex-subscription cannot bind it on the ChatGPT* wire and is bounded there by the contract limit instead. See- * `AuthorizedPromptBridge.maxOutputTokens` (R4-H2).+ * `AuthorizedPromptBridge.maxOutputTokens`.*- * R5-M2: this said "never persisted" after R4-H2 had already reactivated the- * key. A reader trusting that comment would drop the persistence or the read+ * This said "never persisted" after the per-grant ceiling had already been+ * reactivated. A reader trusting that comment would drop the persistence or the read* and hand the regression straight back.*/maxOutputTokens?: numberdiff --git a/control-api/src/services/pluginWorkloadSdkFinalization.ts b/control-api/src/services/pluginWorkloadSdkFinalization.tsindex 1ba843e13..0bc70f09c 100644--- a/control-api/src/services/pluginWorkloadSdkFinalization.ts+++ b/control-api/src/services/pluginWorkloadSdkFinalization.ts@@ -300,7 +300,7 @@ function replayExistingOutcome(): PromptBridgeFinalizationResult {const { persisted, linked } = viewassertPersistedAuthModeCredentialRules(persisted.provider, input)- // N-07: re-anchoring to the JWT's recipe binding runs BEFORE any state+ // Re-anchoring to the JWT's recipe binding runs BEFORE any state// oracle, so a foreign caller cannot learn ledger_pending/exact/unknown.if (!spendBindingMatches(persisted, input)) {throw new PromptBridgeFinalizationError(@@ -319,7 +319,7 @@ function replayExistingOutcome(true)}- // N-05: judged against the immutable floor, so the verdict cannot change+ // Judged against the immutable floor, so the verdict cannot change// between two replays of the same request.if (!replayOutcomeCompatible(input, persisted)) {throw new PromptBridgeFinalizationError(@@ -421,7 +421,7 @@ export async function finalizePromptBridgeInTransaction(if (!providerAttempt) {throw new PromptBridgeFinalizationError('not_found', 'provider attempt not found', 404)}- // N-19: shape before binding, matching `replayExistingOutcome`. A non-oauth+ // Shape before binding, matching `replayExistingOutcome`. A non-oauth// finalization that omits `target.credentialSlot` is a malformed request, and// both paths must classify it as 400 `invalid_request`. Running the binding// comparison first would report the same body as 403 `binding_mismatch` here@@ -478,7 +478,7 @@ export async function finalizePromptBridgeInTransaction(const linkedCodex = oauthBroker? await loadLlmProviderAttemptBySdkAttemptId(db, input.providerAttemptId): null- // R4-H1: decided from the linked Codex row, never from the caller-chosen+ // Decided from the linked Codex row, never from the caller-chosen// status. Gating this on `complete` let a `failed` close through while the// Codex call was still inside its usage grace and could bill afterwards.// The replay path (`:314`) and the sweeper already read the linked row@@ -492,7 +492,7 @@ export async function finalizePromptBridgeInTransaction()}const spend = resolvePersistableSpend(input.status, oauthBroker, linkedCodex, input.usage)- // N-17: only point a usage_request_id at a usage_events row that is really+ // Only point a usage_request_id at a usage_events row that is really// written. Codex spend is ingested by the proxy finalize, not here.const willIngestUsage = input.status === 'complete' && !oauthBroker// Closing the invocation `failed` leaves it revivable (reviveFailedInvocation@@ -500,7 +500,7 @@ export async function finalizePromptBridgeInTransaction(// a second billable Codex call. Only a spend proved `not_executed` — no// linked Codex row at all — is safe to leave revivable. `exact` obviously// billed; `unknown` means we cannot prove it did not, which is the same- // hazard (R4-H1, and the invariant pluginWorkloadSdkDb.ts:2118-2122 states).+ // hazard — the invariant stated at pluginWorkloadSdkDb.ts:2118-2122.// provider_unavailable is the non-revivable terminal state for both. The// RESULT still echoes input.status: mcp-host's controlApiClient requires// result.status === body.status.@@ -616,7 +616,7 @@ export async function finalizePromptBridgeInTransaction(spend)- // RP-539-003: a successful failover finalizes only its winner, so the+ // A successful failover finalizes only its winner, so the// attempts it displaced would never reach this endpoint. They are terminal// and immutable by the reservation fence, so they can be discovered and// settled here without trusting the host to declare them.diff --git a/control-api/src/services/pluginWorkloadSdkSpendLedger.ts b/control-api/src/services/pluginWorkloadSdkSpendLedger.tsindex 6123b2b96..d91f0300c 100644--- a/control-api/src/services/pluginWorkloadSdkSpendLedger.ts+++ b/control-api/src/services/pluginWorkloadSdkSpendLedger.ts@@ -153,7 +153,7 @@ async function resolvePriorAttemptSpend(const linked = await loadLlmProviderAttemptBySdkAttemptId(db, attemptId)const exact = linkedCodexExactUsage(linked)if (exact) return { outcome: 'exact', ...exact }- // R4-M1: a linked row exists only if authorize-link ran, which means the+ // A linked row exists only if authorize-link ran, which means the// host already asked the broker for a ticket — that call may still bill.// `not_executed` is terminal (deriveEffectiveSpend only lifts unknown to// exact), so freezing it here would lose that spend permanently. Same rule@@ -164,7 +164,7 @@ async function resolvePriorAttemptSpend(}/**- * RP-539-003: on a successful failover only the winning attempt reaches+ * On a successful failover only the winning attempt reaches* `finalize`, so every attempt it displaced would stay terminal without a* spend row — the legacy status endpoint does not touch the ledger and the* sweeper only visits `in_progress` invocations. Discover those attempts fromdiff --git a/control-api/test/routes.adminPluginWorkloadSdk.test.ts b/control-api/test/routes.adminPluginWorkloadSdk.test.tsindex 087604d12..2791fccf8 100644--- a/control-api/test/routes.adminPluginWorkloadSdk.test.ts+++ b/control-api/test/routes.adminPluginWorkloadSdk.test.ts@@ -536,7 +536,7 @@ describe('routes/admin/pluginWorkloadSdk — grants', () => {// (malformed still 400s, pinned above) but are dropped on write, while the// active per-minute keys persist untouched.//- // R4-H2: maxOutputTokens is NOT stripped. It briefly was, on the premise+ // `maxOutputTokens` is NOT stripped. It briefly was, on the premise// that nothing enforced it — true only for codex-subscription. Every// API-key provider sends max_tokens, so for them it is a live per-grant// billing ceiling and it must reach the grant.diff --git a/control-api/test/routes.mcp-host.plugin-workload-sdk.test.ts b/control-api/test/routes.mcp-host.plugin-workload-sdk.test.tsindex 85602f0b1..89be336a8 100644--- a/control-api/test/routes.mcp-host.plugin-workload-sdk.test.ts+++ b/control-api/test/routes.mcp-host.plugin-workload-sdk.test.ts@@ -406,7 +406,7 @@ describe('GET /mcp-host/plugin-workload-sdk/capabilities', () => {})it('advertises the revision flag without numbers when the Codex connection does not resolve', async () => {- // R4-M4. The flag states what this binary can publish, not what this+ // The flag states what this binary can publish, not what this// connection has. Dropping it alongside the numbers made a revoked// connection indistinguishable from an older control-api, so the host// skipped the freshness check precisely when no live connection could back@@ -427,7 +427,7 @@ describe('GET /mcp-host/plugin-workload-sdk/capabilities', () => {})it('publishes catalog revision 0 for a connected but never-synced connection', async () => {- // R4-H3 contract pin. 0 is the schema DEFAULT for catalog_revision, so it+ // Contract pin: 0 is the schema DEFAULT for catalog_revision, so it// must survive the wire untouched; the host decides readiness from it.vi.mocked(sdkDb.findGrant).mockResolvedValue(codexGrant())vi.mocked(codexConnection.getSafeCodexSubscriptionConnection).mockResolvedValue({diff --git a/control-api/test/services.llmProviderAttemptAuthorizer.test.ts b/control-api/test/services.llmProviderAttemptAuthorizer.test.tsindex 74d7343f9..6e55f2094 100644--- a/control-api/test/services.llmProviderAttemptAuthorizer.test.ts+++ b/control-api/test/services.llmProviderAttemptAuthorizer.test.ts@@ -224,7 +224,7 @@ describe('authorizeLlmProviderAttempt', () => {})it('does not take the recipe advisory lock for a recipe caller without an SDK attempt link', async () => {- // R4-M3. Only an SDK-linked authorize goes on to take plugin_workload_sdk_*+ // Only an SDK-linked authorize goes on to take plugin_workload_sdk_*// rows FOR UPDATE, which is the order finalize follows after this advisory.// Taking it for every recipe caller serialized the workflow lane per recipe// for no ordering benefit.diff --git a/control-api/test/services.llmProviderAttemptStore.helpers.test.ts b/control-api/test/services.llmProviderAttemptStore.helpers.test.tsindex 4a19cc242..a338acfc6 100644--- a/control-api/test/services.llmProviderAttemptStore.helpers.test.ts+++ b/control-api/test/services.llmProviderAttemptStore.helpers.test.ts@@ -129,7 +129,7 @@ describe('linked Codex usage predicates', () => {})it('fails loudly instead of pinning an attempt in flight forever when created_at is unreadable', () => {- // N-15: the old default returned true, which wedges the invocation behind+ // The old default returned true, which wedges the invocation behind// ledger_pending for good and hides the corrupt timestamp.for (const createdAt of [null, undefined, 'not-a-timestamp']) {expect(() =>diff --git a/control-api/test/services.pluginWorkloadSdkAuthorizer.test.ts b/control-api/test/services.pluginWorkloadSdkAuthorizer.test.tsindex e6b6997ed..16f0a95d4 100644--- a/control-api/test/services.pluginWorkloadSdkAuthorizer.test.ts+++ b/control-api/test/services.pluginWorkloadSdkAuthorizer.test.ts@@ -602,7 +602,7 @@ describe('authorizePromptBridge', () => {value: { invocationId: 'inv-1', replay: false },})if (!result.ok) throw new Error('expected the authorization to succeed')- // R4-H2: the grant's output ceiling travels on the authorization again.+ // The grant's output ceiling travels on the authorization again.// J8 removed it on the premise that nothing enforced it, which held only// for codex-subscription; every API-key provider sends it as `max_tokens`,// so for them it was a working per-grant billing control.@@ -889,7 +889,7 @@ describe('reissuePromptBridgeCredentialTicket', () => {expect(sdkDb.markPluginWorkloadSdkProviderAttemptStatus).not.toHaveBeenCalled()})- it('denies an oauth-broker fallback that is not the default target (RP-539-009)', async () => {+ it('denies an oauth-broker fallback that is not the default target', async () => {// The WRC installs the broker binding for the grant's default target only.// A non-default Codex fallback is authorizable but not executable: without// this guard it reserved an attempt, burned budget, and died in execution.diff --git a/control-api/test/services.pluginWorkloadSdkDb.test.ts b/control-api/test/services.pluginWorkloadSdkDb.test.tsindex 4d1a5d62c..21885dc08 100644--- a/control-api/test/services.pluginWorkloadSdkDb.test.ts+++ b/control-api/test/services.pluginWorkloadSdkDb.test.ts@@ -683,7 +683,7 @@ describe('SQL contracts that a silent edit would otherwise break', () => {vi.mocked(pool.query).mockResolvedValue({ rows: [], rowCount: 1 } as never)})- it('refuses to promote a reserved attempt that already carries a credential jti (N-22)', async () => {+ it('refuses to promote a reserved attempt that already carries a credential jti', async () => {// The JTI-free authorize-link path must never adopt an attempt that the// secret-ticket path already claimed. Dropping this predicate leaves the// whole suite green, so assert the clause itself.diff --git a/control-api/test/services.pluginWorkloadSdkFinalization.realPostgres.integration.test.ts b/control-api/test/services.pluginWorkloadSdkFinalization.realPostgres.integration.test.tsindex 0cbc87744..ff2c4363b 100644--- a/control-api/test/services.pluginWorkloadSdkFinalization.realPostgres.integration.test.ts+++ b/control-api/test/services.pluginWorkloadSdkFinalization.realPostgres.integration.test.ts@@ -750,7 +750,7 @@ describeRealPostgres('Plugin Workload SDK finalization on real PostgreSQL', () =}})- it('resolves three identical failed calls while Codex usage lands between them (N-05)', async () => {+ it('resolves three identical failed calls while Codex usage lands between them', async () => {const client = await dbPool.connect()try {await begin(client)@@ -808,7 +808,7 @@ describeRealPostgres('Plugin Workload SDK finalization on real PostgreSQL', () =}})- it('settles the attempts a successful failover displaced (RP-539-003)', async () => {+ it('settles the attempts a successful failover displaced', async () => {const client = await dbPool.connect()try {await begin(client)diff --git a/control-api/test/services.pluginWorkloadSdkFinalization.test.ts b/control-api/test/services.pluginWorkloadSdkFinalization.test.tsindex c6f2c1239..a342bce38 100644--- a/control-api/test/services.pluginWorkloadSdkFinalization.test.ts+++ b/control-api/test/services.pluginWorkloadSdkFinalization.test.ts@@ -805,7 +805,7 @@ describe('Plugin Workload SDK promptBridge finalization', () => {'provider_completed',null,null,- // N-17: Codex spend is ingested by the proxy finalize, not here, so no+ // Codex spend is ingested by the proxy finalize, not here, so no// usage_events row exists for this attempt and the FK-shaped column must// stay NULL rather than point at a row that was never written.null,@@ -1172,7 +1172,7 @@ describe('Plugin Workload SDK promptBridge finalization', () => {) as never)).rejects.toMatchObject({- // N-19: the persisted `openai` attempt still governs, so the missing+ // The persisted `openai` attempt still governs, so the missing// credentialSlot is a malformed body (400), not a binding mismatch (403).// `replayExistingOutcome` already classified this exact body as 400; the// fresh path used to answer 403 only because the binding comparison ran@@ -1182,7 +1182,7 @@ describe('Plugin Workload SDK promptBridge finalization', () => {})})- it('classifies the same malformed body identically on the replay path (N-19)', async () => {+ it('classifies the same malformed body identically on the replay path', async () => {await expect(finalizePromptBridgeInTransaction({@@ -1361,7 +1361,7 @@ describe('spend floor writers (Addendum A.4 "best-floor")', () => {expect(updateParams(db, 'plugin_workload_sdk_invocations')?.[1]).toBe('failed')})- // R4-H1. The ledger_pending gate was keyed on `input.status === 'complete'`,+ // The ledger_pending gate was keyed on `input.status === 'complete'`,// so a host closing `failed` walked past a Codex call still inside its usage// grace. `failed` is what reviveFailedInvocation reopens, so the same// idempotency key could launch a second billable Codex call while the first@@ -1486,7 +1486,7 @@ describe('spend replay is read-only and judged against the floor', () => {},}: {}- // N-05: the third identical `failed` call used to 409 because the second+ // The third identical `failed` call used to 409 because the second// had rewritten the row to `exact`. The floor never moves, so the verdict// is stable and the reported outcome still catches up.await expect(@@ -1536,7 +1536,7 @@ describe('spend replay is read-only and judged against the floor', () => {] as const)('answers conflict, not the %s ledger state, when the JWT binding does not match the floor',async (_label, linkedOverrides) => {- // N-07: the binding check runs before any state oracle, so a foreign+ // The binding check runs before any state oracle, so a foreign// recipe cannot distinguish ledger_pending from exact from unknown.await expect(finalizePromptBridgeInTransaction(@@ -1649,7 +1649,7 @@ describe('deriveEffectiveSpend', () => {})})-describe('prior provider attempt settlement (RP-539-003)', () => {+describe('prior provider attempt settlement', () => {const PRIOR_ATTEMPT_ID = '44444444-4444-4444-8444-444444444444'function priorAttemptRow(status: string) {@@ -1789,7 +1789,7 @@ describe('prior provider attempt settlement (RP-539-003)', () => {})it('freezes unknown for a displaced Codex attempt whose linked row carries no usage yet', async () => {- // R4-M1. `not_executed` is terminal — deriveEffectiveSpend only lifts+ // `not_executed` is terminal — deriveEffectiveSpend only lifts// `unknown` to `exact` — so freezing it over a linked row that can still// bill loses that spend permanently. A linked row exists only if// authorize-link ran, which is already "asked the broker for a ticket".diff --git a/control-api/test/services.pluginWorkloadSdkSpend.properties.test.ts b/control-api/test/services.pluginWorkloadSdkSpend.properties.test.tsindex 3a997b713..3ea5597a3 100644--- a/control-api/test/services.pluginWorkloadSdkSpend.properties.test.ts+++ b/control-api/test/services.pluginWorkloadSdkSpend.properties.test.ts@@ -4,9 +4,9 @@ import { deriveEffectiveSpend } from '../src/services/pluginWorkloadSdkFinalizatimport { isOauthBrokerProvider } from '../src/services/pluginWorkloadSdkSpendLedger.js'/**- * R4-M2. `deriveEffectiveSpend` is a pure `(floor, linkedCodex) -> spend` merge+ * `deriveEffectiveSpend` is a pure `(floor, linkedCodex) -> spend` merge* with precedence rules, and it was covered only by hand-enumerated cases.- * R4-H1 and R4-M1 were both sibling cases that enumeration missed — the shape+ * Two sibling defects in that merge were both cases enumeration missed — the shape* of that miss is what these properties close: they quantify over the whole* input space instead of the examples someone thought of.*/diff --git a/control-ui/lib/api.ts b/control-ui/lib/api.tsindex acb6bc7d2..313baedf7 100644--- a/control-ui/lib/api.ts+++ b/control-ui/lib/api.ts@@ -3725,7 +3725,7 @@ export type PluginWorkloadSdkGrantInput = {// Input type omits the deprecated per-run keys (issue #348): this UI never// sends them and the server strips them on write. The response// PluginWorkloadSdkQuotaLimits still carries them for legacy grants.- // `maxOutputTokens` is NOT among them (R4-H2) — it is a live per-grant+ // `maxOutputTokens` is NOT among them — it is a live per-grant// ceiling on API-key providers.quotaLimits?: Omit<PluginWorkloadSdkQuotaLimits, 'maxRequestsPerRun' | 'maxNotificationsPerRun'>modelPolicies?: Record<string, PluginWorkloadSdkModelPolicy>diff --git a/control-ui/package-lock.json b/control-ui/package-lock.jsonindex 28b0f3e26..f8484046b 100644--- a/control-ui/package-lock.json+++ b/control-ui/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-control-ui",- "version": "0.1.489",+ "version": "0.1.490","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-control-ui",- "version": "0.1.489",+ "version": "0.1.490","dependencies": {"@clerum/display-field": "file:../packages/display-field","@clerum/llm-providers": "file:../packages/llm-providers",diff --git a/control-ui/package.json b/control-ui/package.jsonindex b8bc71069..57139ff80 100644--- a/control-ui/package.json+++ b/control-ui/package.json@@ -1,6 +1,6 @@{"name": "clerum-control-ui",- "version": "0.1.489",+ "version": "0.1.490","private": true,"scripts": {"dev": "NEXT_IGNORE_INCORRECT_LOCKFILE=1 next dev",diff --git a/desktop-app/test/e2e-playwright/plugin-workload-sdk-codex-fallback.spec.ts b/desktop-app/test/e2e-playwright/plugin-workload-sdk-codex-fallback.spec.tsindex 539f699bf..2d7e9e237 100644--- a/desktop-app/test/e2e-playwright/plugin-workload-sdk-codex-fallback.spec.ts+++ b/desktop-app/test/e2e-playwright/plugin-workload-sdk-codex-fallback.spec.ts@@ -126,7 +126,7 @@ test('Desktop Apps falls back to the authorized non-Codex target when Codex is u'This journey stops codex-llm-proxy, performs one paid promptBridge call served by the fallback provider, and restores the proxy.')const fixture = grantedFixture()- // Hard preconditions, never branches. RP-539-002 was exactly this shape: the+ // Hard preconditions, never branches. An earlier defect was exactly this shape: the// happy path kept its only Codex assertions behind a guard, so an OpenAI// recipe passed it green without touching Codex, and the static auditor// reported PASS because it validates form and cannot reach semantics.diff --git a/desktop-app/test/e2e-playwright/pluginWorkloadSdkSandboxUi.ts b/desktop-app/test/e2e-playwright/pluginWorkloadSdkSandboxUi.tsindex 0e87cad0d..2c9166e41 100644--- a/desktop-app/test/e2e-playwright/pluginWorkloadSdkSandboxUi.ts+++ b/desktop-app/test/e2e-playwright/pluginWorkloadSdkSandboxUi.ts@@ -575,7 +575,7 @@ export function promptBridgeLedgerForRun(/*** The run anchor, read from PostgreSQL rather than the runner.*- * R2-L4: the ledger queries filter on `inv.created_at >= startedAt`, and+ * The ledger queries filter on `inv.created_at >= startedAt`, and* `created_at` is written by the database. Anchoring with the runner's clock* compares two unsynchronised clocks, so a few seconds of skew either drops* the run's own rows or picks up an earlier one. Same clock, both sides.diff --git a/mcp-host/package-lock.json b/mcp-host/package-lock.jsonindex 987c638ff..4bf9e7784 100644--- a/mcp-host/package-lock.json+++ b/mcp-host/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-mcp-host",- "version": "0.1.316",+ "version": "0.1.317","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-mcp-host",- "version": "0.1.316",+ "version": "0.1.317","license": "SEE LICENSE IN LICENSE","dependencies": {"@anthropic-ai/sdk": "^0.32.0",diff --git a/mcp-host/package.json b/mcp-host/package.jsonindex cf34181ce..738d792f2 100644--- a/mcp-host/package.json+++ b/mcp-host/package.json@@ -1,6 +1,6 @@{"name": "clerum-mcp-host",- "version": "0.1.316",+ "version": "0.1.317","description": "MCP Host - reads Host CRD and provides LLM access via OpenAI/Claude","main": "dist/main.js","engines": {diff --git a/mcp-host/src/pluginWorkloadSdk/bootstrapIdentity.test.ts b/mcp-host/src/pluginWorkloadSdk/bootstrapIdentity.test.tsindex 0a5b33bd4..a8622b9df 100644--- a/mcp-host/src/pluginWorkloadSdk/bootstrapIdentity.test.ts+++ b/mcp-host/src/pluginWorkloadSdk/bootstrapIdentity.test.ts@@ -212,6 +212,39 @@ describe('Plugin Workload SDK bootstrap identity', () => {replaceSdkOnlyCodexBinding(null)})+ it('clears the stored Codex binding when identity verification throws', async () => {+ const binding = {+ connectionKey: 'team-plus',+ catalogRevision: 4,+ credentialRevision: 1,+ model: 'gpt-5.6-luna',+ bindingHash: computeCodexPolicyHash({+ model: 'gpt-5.6-luna',+ catalogRevision: 4,+ credentialRevision: 1,+ connectionKey: 'team-plus',+ }),+ }+ // The binding is installed BEFORE verification because `verify` reads the+ // live global to build its capabilities request. A transport failure there+ // must not leave an unconfirmed binding behind for the next prompt to+ // execute against — and must still surface as the original error.+ const verify = vi.fn().mockRejectedValue(new Error('control-api unreachable'))+ await expect(+ configurePluginWorkloadSdkBootstrapIdentity(+ {+ capabilityFamily: 'promptBridge',+ provider: 'codex-subscription',+ model: 'gpt-5.6-luna',+ contractVersion: 3,+ codexBinding: binding,+ },+ { capabilityFamily: 'promptBridge', verify }+ )+ ).rejects.toThrow('control-api unreachable')+ expect(readSdkOnlyCodexBinding()).toBeNull()+ })+it('integrity-checks a supplied Codex binding even when the request provider is not Codex', async () => {replaceSdkOnlyCodexBinding(null)const verifyBinding = vi.spyOn(sdkOnlyCodexBinding, 'readVerifiedSdkOnlyCodexBinding')diff --git a/mcp-host/src/pluginWorkloadSdk/bootstrapIdentity.ts b/mcp-host/src/pluginWorkloadSdk/bootstrapIdentity.tsindex e90691836..ef79d1ca4 100644--- a/mcp-host/src/pluginWorkloadSdk/bootstrapIdentity.ts+++ b/mcp-host/src/pluginWorkloadSdk/bootstrapIdentity.ts@@ -110,7 +110,20 @@ export async function configurePluginWorkloadSdkBootstrapIdentity(} else {replaceSdkOnlyCodexBinding(null)}- const proof = deps.verify ? await deps.verify(req.provider, model) : null+ // The binding must be installed BEFORE this call — `deps.verify` reads the+ // live global to build its capabilities request. That ordering means a throw+ // here (a transport failure, a control-api 5xx) would otherwise leave the+ // global populated with a binding this bootstrap never confirmed, and the+ // next prompt would execute against it. Clear it and rethrow: an unverified+ // binding must not survive the attempt that failed to verify it. The error+ // itself is not swallowed — the caller still sees the failure.+ let proof: Awaited<ReturnType<NonNullable<typeof deps.verify>>> | null = null+ try {+ proof = deps.verify ? await deps.verify(req.provider, model) : null+ } catch (err) {+ if (req.provider === 'codex-subscription') replaceSdkOnlyCodexBinding(null)+ throw err+ }if (deps.verify && !proof) {if (req.provider === 'codex-subscription') replaceSdkOnlyCodexBinding(null)return {diff --git a/mcp-host/src/pluginWorkloadSdk/promptBridge/controlApiClient.test.ts b/mcp-host/src/pluginWorkloadSdk/promptBridge/controlApiClient.test.tsindex b9b8dc7ff..db01c20eb 100644--- a/mcp-host/src/pluginWorkloadSdk/promptBridge/controlApiClient.test.ts+++ b/mcp-host/src/pluginWorkloadSdk/promptBridge/controlApiClient.test.ts@@ -34,7 +34,7 @@ function authorizedBody(invocationId: string) {attemptGeneration: 1,policyRevision: 2,policyHash: 'a'.repeat(64),- // R4-H2: the field is required on the wire again. `null` is "this grant+ // The field is required on the wire again. `null` is "this grant// sets no ceiling", which is the default these fixtures describe.maxOutputTokens: null,}@@ -341,7 +341,7 @@ describe('PluginWorkloadSdkControlApiClient', () => {).resolves.toMatchObject({ policyReady: true, codexBindingReady: true })})- // R4-H3 / R4-M5: the hand-built fixtures only ever used catalog revisions+ // The hand-built fixtures only ever used catalog revisions// {4,5,7,999} and never 0 — which is the schema DEFAULT for a never-synced// catalog and exactly the value the inverted bounds rejected. These pin the// real CHECK constraints of codex_subscription_connections:@@ -390,7 +390,7 @@ describe('PluginWorkloadSdkControlApiClient', () => {})it('refuses the binding when the peer claims revisions but omits both', async () => {- // R4-M4: a revoked or absent connection now keeps the flag and drops only+ // A revoked or absent connection now keeps the flag and drops only// the numbers, so this is the branch a live control-api takes for a// connection that cannot back any binding.installCodexBinding()diff --git a/mcp-host/src/pluginWorkloadSdk/promptBridge/controlApiClient.ts b/mcp-host/src/pluginWorkloadSdk/promptBridge/controlApiClient.tsindex 13a45354a..8c664e769 100644--- a/mcp-host/src/pluginWorkloadSdk/promptBridge/controlApiClient.ts+++ b/mcp-host/src/pluginWorkloadSdk/promptBridge/controlApiClient.ts@@ -55,7 +55,7 @@ export interface AuthorizePromptBridgeResponse {* Per-grant output ceiling, or null when the grant sets none. Enforced as* `max_tokens` on API-key providers; codex-subscription cannot bind it on* the ChatGPT wire, where the contract's LIMITS.maxOutputTokens is the only- * bound (R4-H2).+ * bound.*/maxOutputTokens: number | null}@@ -201,7 +201,7 @@ function isAuthorizePromptBridgeResponse(v: unknown): v is AuthorizePromptBridge(r.policyRevision as number) >= 1 &&typeof r.policyHash === 'string' &&/^[a-f0-9]{64}$/.test(r.policyHash) &&- // R4-H2: a grant cap of 0 is not "no cap" — it would clamp every response+ // A grant cap of 0 is not "no cap" — it would clamp every response// to nothing. Reject it here rather than let Math.min silently zero the// request.(r.maxOutputTokens === null ||@@ -232,7 +232,7 @@ function isPluginWorkloadSdkCapabilities(v: unknown): v is PluginWorkloadSdkCapatypeof value.v2Ready === 'boolean' &&(value.reservationOnlyOauthBroker === undefined || value.reservationOnlyOauthBroker === true) &&(value.codexBindingRevisions === undefined || value.codexBindingRevisions === true) &&- // R4-H3: bounds mirror the codex_subscription_connections CHECKs —+ // Bounds mirror the codex_subscription_connections CHECKs —// `catalog_revision BIGINT NOT NULL DEFAULT 0 CHECK (>= 0)` and// `credential_revision BIGINT NOT NULL DEFAULT 1 CHECK (>= 1)`. These were// inverted, so a connection whose catalog was never synced (revision 0,diff --git a/mcp-host/src/pluginWorkloadSdk/promptBridge/handler.test.ts b/mcp-host/src/pluginWorkloadSdk/promptBridge/handler.test.tsindex 227b0e507..138218a74 100644--- a/mcp-host/src/pluginWorkloadSdk/promptBridge/handler.test.ts+++ b/mcp-host/src/pluginWorkloadSdk/promptBridge/handler.test.ts@@ -207,7 +207,7 @@ describe('PromptBridgeHandler', () => {)})- // R4-H2. J8 dropped the clamp on the premise that nothing enforced the+ // J8 dropped the clamp on the premise that nothing enforced the// ceiling. That held only for codex-subscription, whose ChatGPT wire rejects// `max_output_tokens`; every API-key provider does send it, so for them the// per-grant cap was a working billing control that the removal silenced.@@ -557,7 +557,7 @@ describe('PromptBridgeHandler', () => {code: 'provider_unavailable',reason: 'outcome_unknown',})- // One attempt on the complete path, then one on the error path (N-11).+ // One attempt on the complete path, then one on the error path.// Neither retries: the error is retryable but carries no `reason`.expect(finalize).toHaveBeenCalledTimes(2)expect(finalize).toHaveBeenNthCalledWith(@@ -611,7 +611,7 @@ describe('PromptBridgeHandler', () => {vi.useRealTimers()}// Four attempts per finalize path, never five. The complete path exhausts- // its budget, then the error path (N-11) settles the same receipt with a+ // its budget, then the error path settles the same receipt with a// budget of its own — the documented worst case of two bounded deadlines.expect(finalize).toHaveBeenCalledTimes((FINALIZE_LEDGER_RETRY_DELAYS_MS.length + 1) * 2)})diff --git a/mcp-host/src/pluginWorkloadSdk/promptBridge/handler.ts b/mcp-host/src/pluginWorkloadSdk/promptBridge/handler.tsindex 85913afe8..73ef8490e 100644--- a/mcp-host/src/pluginWorkloadSdk/promptBridge/handler.ts+++ b/mcp-host/src/pluginWorkloadSdk/promptBridge/handler.ts@@ -249,7 +249,7 @@ export function validatePromptBridgeRequest(raw: unknown): PromptBridgeRequest {body.maxTokens !== undefined &&(typeof body.maxTokens !== 'number' || !Number.isInteger(body.maxTokens) || body.maxTokens < 1)) {- // R4-H2: `typeof number` alone let 0, -1 and 1.5 through to the provider+ // `typeof number` alone let 0, -1 and 1.5 through to the provider// and made the grant clamp's Math.min ill-defined.throw new PluginWorkloadError('invalid_request', 'maxTokens must be a positive integer')}@@ -434,7 +434,7 @@ export class PromptBridgeHandler {acknowledgementMode: this.deps.finalizePromptBridge? 'atomic_terminal_finalization': 'per_attempt',- // R4-H2: the per-grant ceiling is enforced here, before the request+ // The per-grant ceiling is enforced here, before the request// reaches any provider. On API-key providers it lands as `max_tokens`// on the wire; on codex-subscription it bounds the hashed request// identity while the proxy omits it from the ChatGPT wire, which also@@ -596,7 +596,7 @@ export class PromptBridgeHandler {err instanceof PluginWorkloadError && err.providerMayHaveExecuted? 'provider_unavailable': 'failed'- // N-11: the error path settles the same ledger row as the complete+ // The error path settles the same ledger row as the complete// path, so it needs the same `ledger_pending` patience and the same// bounded deadline. Losing this attempt to a millisecond commit race// would silently drop the spend for an attempt that already ran.@@ -664,7 +664,7 @@ function unexpectedAuthorizationResponse(): PluginWorkloadError {/*** Bound a workload's requested output against the grant's ceiling.*- * Scope, stated honestly (R4-H2): on API-key providers this is the real cap —+ * Scope, stated honestly: on API-key providers this is the real cap —* `max_tokens` reaches the provider. On codex-subscription the ChatGPT wire* rejects `max_output_tokens` and the proxy omits it, so there the clamp bounds* the hashed request identity rather than the response, and the enforced bounddiff --git a/workflow-recipes/package-lock.json b/workflow-recipes/package-lock.jsonindex 972af30af..afe8e301a 100644--- a/workflow-recipes/package-lock.json+++ b/workflow-recipes/package-lock.json@@ -1,12 +1,12 @@{"name": "workload-recipes-controller",- "version": "0.1.337",+ "version": "0.1.338","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "workload-recipes-controller",- "version": "0.1.337",+ "version": "0.1.338","license": "SEE LICENSE IN LICENSE","dependencies": {"@aws-sdk/client-s3": "^3.1009.0",diff --git a/workflow-recipes/package.json b/workflow-recipes/package.jsonindex 5602ce9b1..d94a13589 100644--- a/workflow-recipes/package.json+++ b/workflow-recipes/package.json@@ -1,6 +1,6 @@{"name": "workload-recipes-controller",- "version": "0.1.337",+ "version": "0.1.338","description": "Workload Recipes Controller (WRC) - WorkloadRecipe lifecycle management and MCP server interface","main": "dist/main.js","engines": {diff --git a/workflow-recipes/src/types.ts b/workflow-recipes/src/types.tsindex b03be713b..c31b83287 100644--- a/workflow-recipes/src/types.ts+++ b/workflow-recipes/src/types.ts@@ -507,7 +507,7 @@ export interface OAuthClientDef {export interface PluginWorkloadSdkSpec {promptBridge?: {allowedModels?: string[]- /** Per-grant output ceiling. Enforced as `max_tokens` on API-key providers; codex-subscription cannot bind it on the ChatGPT wire and is bounded there by the contract limit of 16384 instead (R4-H2). */+ /** Per-grant output ceiling. Enforced as `max_tokens` on API-key providers; codex-subscription cannot bind it on the ChatGPT wire and is bounded there by the contract limit of 16384 instead. */maxOutputTokens?: number/** @deprecated Accepted for compatibility; no longer enforced (issue #348). Platform per-minute rate limits apply. */maxRequestsPerRun?: number@@ -549,7 +549,7 @@ export interface PluginWorkloadSdkSpec {export interface PluginWorkloadSdkSnippetConfig {promptBridge?: {allowedModels?: string[]- /** Per-grant output ceiling. Enforced as `max_tokens` on API-key providers; codex-subscription cannot bind it on the ChatGPT wire and is bounded there by the contract limit of 16384 instead (R4-H2). */+ /** Per-grant output ceiling. Enforced as `max_tokens` on API-key providers; codex-subscription cannot bind it on the ChatGPT wire and is bounded there by the contract limit of 16384 instead. */maxOutputTokens?: number}clientNotifications?: {diff --git a/workflow-recipes/src/workflow/codexRecipeVerdict.test.ts b/workflow-recipes/src/workflow/codexRecipeVerdict.test.tsindex f2615f4cc..7d8cf60e4 100644--- a/workflow-recipes/src/workflow/codexRecipeVerdict.test.ts+++ b/workflow-recipes/src/workflow/codexRecipeVerdict.test.ts@@ -1,4 +1,5 @@import { describe, expect, it } from 'vitest'+import type { CodexConfigMapView } from '@clerum/codex-catalog-projection'import { computeCodexPolicyHash } from '@clerum/llm-provider-attempt-contract'import type { WorkflowRecipeSpec } from '../types'import {@@ -6,15 +7,21 @@ import {type CodexReconcileContext,projectCodexRecipeVerdict,} from './codexRecipeVerdict'+import { parseAllowedModelsSnapshot, snapshotFromConfigMapError } from './llmAllowedModelsSnapshot'/*- * R5-B1. The Codex seam was fixed four times and each fix converged one more+ * The Codex seam was fixed four times and each fix converged one more* dimension: `readOk`, then `snapshotError`, while `provenance` stayed free to* diverge. These tests pin the verdict as a whole, so a future dimension* cannot be added on only one side.** The last case in the file is the invariant sweep: it quantifies over every* row rather than trusting that someone remembered to assert it per case.+ *+ * Views are built by the SAME producers the reconciler uses — a hand-written+ * snapshot would let a ConfigMap-shape change break parsing in production+ * while these stayed green, because the verdict only falls back to+ * `view.snapshot` when it cannot re-derive from `view.configMap`.*/const MODEL = 'gpt-5.6-luna'@@ -28,7 +35,7 @@ const codexSpec = (): WorkflowRecipeSpec =>function eligibleConfigMap(overrides?: {annotations?: Record<string, string>models?: string[]-}) {+}): CodexConfigMapView {return {metadata: {annotations: {@@ -47,14 +54,16 @@ function eligibleConfigMap(overrides?: {}}-const viewFrom = (- configMap: ReturnType<typeof eligibleConfigMap> | undefined-): CodexAllowlistView =>- ({ configMap, snapshot: { flagEnabled: true } }) as unknown as CodexAllowlistView+/** Exactly how `refreshCodexSnapshot` assembles the view it hands every consumer. */+const viewFrom = (configMap: CodexConfigMapView | undefined): CodexAllowlistView => ({+ configMap,+ snapshot: parseAllowedModelsSnapshot(configMap),+})/** A view whose ConfigMap never arrived — the snapshot-error dimension. */-const unreadableView = (): CodexAllowlistView =>- ({ snapshot: { flagEnabled: false, snapshotError: 'missing' } }) as unknown as CodexAllowlistView+const unreadableView = (): CodexAllowlistView => ({+ snapshot: snapshotFromConfigMapError('missing'),+})function context(overrides?: Partial<CodexReconcileContext>): CodexReconcileContext {return {@@ -91,7 +100,7 @@ describe('projectCodexRecipeVerdict', () => {expect(v.hostBinding).toBeNull()})- // R5-B1 proper: the two provenance-uncertain states. Both were `ineligible`+ // The two provenance-uncertain states. Both were `ineligible`// on the configure path while the scope path already called them uncertain,// so a binding-less v3 configure wiped a live host binding over a transient// condition.diff --git a/workflow-recipes/src/workflow/codexRecipeVerdict.ts b/workflow-recipes/src/workflow/codexRecipeVerdict.tsindex 1d36ac7f2..d6690ec9e 100644--- a/workflow-recipes/src/workflow/codexRecipeVerdict.ts+++ b/workflow-recipes/src/workflow/codexRecipeVerdict.ts@@ -20,7 +20,7 @@ import {/** ONE Codex verdict per reconcile pass.*- * This seam has been fixed four times — J4, N-08, R4-B1, R5-B1 — and every+ * This seam has been fixed four times across four reviews, and every* fix converged one more dimension while leaving another live. The shape of* the bug never changed: two consumers answered the same question along* different paths, so `readOk` disagreed with `eligibility`, and then@@ -59,7 +59,7 @@ export type CodexReconcileContext = {/*** The allowlist refresh, captured once by the caller. Passing the view rather* than reading `this.codexView` inside is what keeps a concurrently-refreshed- * snapshot from splitting one pass across two views (N-08, scope dimension).+ * snapshot from splitting one pass across two views (scope dimension).*/export type CodexAllowlistView = {configMap?: CodexConfigMapView@@ -118,7 +118,7 @@ export function projectCodexRecipeVerdict(input: {} as constif (projection.eligibility !== 'eligible') {- // R5-B1 audit (R4): warn ONLY for a recipe that actually targets Codex, and+ // Warn ONLY for a recipe that actually targets Codex, and// only when the doubt is about provenance. An unreadable ConfigMap already// produces three warns in `refreshCodexSnapshot`, and it makes EVERY recipe// uncertain — including those with no Codex target — because the shareddiff --git a/workflow-recipes/src/workflow/modelConfigHandler.ts b/workflow-recipes/src/workflow/modelConfigHandler.tsindex 04fed8e7a..de1e97aab 100644--- a/workflow-recipes/src/workflow/modelConfigHandler.ts+++ b/workflow-recipes/src/workflow/modelConfigHandler.ts@@ -314,7 +314,7 @@ export class ModelConfigHandler {// Shape alone is not proof: re-derive the policy hash and pin the model// so a host cannot echo a well-formed binding for another model or with// a hash that does not match its own five fields.- // R4-L1: without a model there is no pin to apply, and an unpinned+ // Without a model there is no pin to apply, and an unpinned// binding could be for another model. Refuse it rather than accept it// blind — the pin is the point of this call.const verifiedCodexBinding = modeldiff --git a/workflow-recipes/src/workflow/pluginWorkloadSdkProvisioner.codexPolicy.test.ts b/workflow-recipes/src/workflow/pluginWorkloadSdkProvisioner.codexPolicy.test.tsindex e23e8da2c..7a68aaa91 100644--- a/workflow-recipes/src/workflow/pluginWorkloadSdkProvisioner.codexPolicy.test.ts+++ b/workflow-recipes/src/workflow/pluginWorkloadSdkProvisioner.codexPolicy.test.ts@@ -154,7 +154,7 @@ function makeHarness(configureResult: unknown) {} as unknown as PluginWorkloadSdkProvisionerDepsconst provisioner = new PluginWorkloadSdkProvisioner(deps)- // R5-B1: the provisioner now takes ONE verdict instead of a binding plus a+ // The provisioner now takes ONE verdict instead of a binding plus a// derived boolean. These helpers keep each existing case's semantics: a// minted binding means eligible+authoritative, and "undecidable" means the// projection itself could not decide.@@ -211,7 +211,7 @@ describe('eager Codex policy gate', () => {})it('discards a cached proof whose pod was replaced instead of reporting ready', async () => {- // N-06: the proof is the pod's, not the recipe's. A replacement pod has+ // The proof is the pod's, not the recipe's. A replacement pod has// never been configured, so a snapshot outage must not let its predecessor's// proof stand in for it.const harness = makeHarness(readyBootstrapBody(MINTED))@@ -230,7 +230,7 @@ describe('eager Codex policy gate', () => {})it('rejects a bootstrap that echoes a Codex binding other than the minted one', async () => {- // N-14: a host answering with a different policy than the one WRC minted is+ // A host answering with a different policy than the one WRC minted is// a broken host, not a pending policy. Three consecutive rounds exhaust the// configure budget and surface provider_unavailable.const harness = makeHarness(diff --git a/workflow-recipes/src/workflow/pluginWorkloadSdkProvisioner.imageDrift.test.ts b/workflow-recipes/src/workflow/pluginWorkloadSdkProvisioner.imageDrift.test.tsindex 61929e2ea..8996708bb 100644--- a/workflow-recipes/src/workflow/pluginWorkloadSdkProvisioner.imageDrift.test.ts+++ b/workflow-recipes/src/workflow/pluginWorkloadSdkProvisioner.imageDrift.test.ts@@ -711,7 +711,7 @@ describe('ensureEagerSdkMcpHost ConfigMap snapshot skip', () => {RUNTIME,{mcpHostPhase: 'Running',- // R5-B1: undecidable is now a field of the one verdict.+ // Undecidable is now a field of the one verdict.codexVerdict: {provenance: 'uncertain',provenanceReason: 'parent_spec_unavailable',diff --git a/workflow-recipes/src/workflow/pluginWorkloadSdkProvisioner.ts b/workflow-recipes/src/workflow/pluginWorkloadSdkProvisioner.tsindex 3b71936c5..adef2d844 100644--- a/workflow-recipes/src/workflow/pluginWorkloadSdkProvisioner.ts+++ b/workflow-recipes/src/workflow/pluginWorkloadSdkProvisioner.ts@@ -215,7 +215,7 @@ export class PluginWorkloadSdkProvisioner {opts: {mcpHostPhase: string | undefined/**- * The caller's ONE Codex verdict for this pass (R5-B1). Required, and+ * The caller's ONE Codex verdict for this pass. Required, and* deliberately not a pair of optional derived fields: an optional* `codexBindingUndecidable` defaulting to false is a flag a future* caller can silently omit, which is precisely how a binding-less v3@@ -422,7 +422,7 @@ export class PluginWorkloadSdkProvisioner {}// Both the skip decision above and this binding are fields of the SAME// verdict the caller computed once for this pass. The provisioner never- // re-derives either after its own awaits (R5-B1).+ // re-derives either after its own awaits.const resolvedCodexBinding = opts.codexVerdict.hostBindingconst capabilityFamily = promptBridge ? 'promptBridge' : 'clientNotifications'const configureKey = `${readiness.uid}:${capabilityFamily}:${mcpHostAgent?.provider ?? 'none'}:${mcpHostAgent?.model ?? 'none'}:${resolvedCodexBinding?.bindingHash ?? 'none'}`diff --git a/workflow-recipes/src/workflow/sdkOnlyCodexBinding.test.ts b/workflow-recipes/src/workflow/sdkOnlyCodexBinding.test.tsindex 2b11e96a2..5d09f61fe 100644--- a/workflow-recipes/src/workflow/sdkOnlyCodexBinding.test.ts+++ b/workflow-recipes/src/workflow/sdkOnlyCodexBinding.test.ts@@ -13,7 +13,7 @@ const HASH = computeCodexPolicyHash({describe('readVerifiedSdkOnlyCodexBinding', () => {// The derive/resolve suite moved to codexRecipeVerdict.test.ts along with- // the functions themselves (R5-B1): those entry points were blind to+ // the functions themselves: those entry points were blind to// provenance and are deleted, not deprecated.it('rebuilds a five-field proof and drops extra keys', () => {const proof = {@@ -24,7 +24,7 @@ describe('readVerifiedSdkOnlyCodexBinding', () => {bindingHash: HASH,extra: true,}- // R4-L1: the model is a required argument now. This call used to omit it,+ // The model is a required argument now. This call used to omit it,// which silently skipped the pin — the very gap the change closes.expect(readVerifiedSdkOnlyCodexBinding(proof, MODEL)).toEqual({connectionKey: 'team-plus',diff --git a/workflow-recipes/src/workflow/sdkOnlyCodexBinding.ts b/workflow-recipes/src/workflow/sdkOnlyCodexBinding.tsindex 12e678f39..607664fc8 100644--- a/workflow-recipes/src/workflow/sdkOnlyCodexBinding.ts+++ b/workflow-recipes/src/workflow/sdkOnlyCodexBinding.ts@@ -66,7 +66,7 @@ export function sanitizePluginWorkloadSdkCodexBindingProof(}/**- * R4-L1: `model` is REQUIRED. It used to be optional and the model pin was+ * `model` is REQUIRED. It used to be optional and the model pin was* skipped when omitted, so a caller that forgot it would accept a binding for* another model. mcp-host's twin has always required it; the two now agree.*/@@ -86,7 +86,7 @@ export function readVerifiedSdkOnlyCodexBinding(* Deliberately NOT exported alongside a "derive from a ConfigMap" helper any* more. Those helpers (`deriveSdkOnlyCodexBinding` / `resolveSdkOnlyCodexBinding`)* were blind to provenance, so a caller could obtain a binding for a recipe- * whose Codex authority could not be established — the R5-B1 wipe. The only+ * whose Codex authority could not be established — the live-binding wipe. The only* caller is `projectCodexRecipeVerdict`, which gates on provenance and* eligibility first. Removed rather than deprecated, for the same reason* `readOk` was removed: a reachable blind path invites the sibling back.diff --git a/workflow-recipes/src/workflow/workflowReconciler.codexUncertainScope.test.ts b/workflow-recipes/src/workflow/workflowReconciler.codexUncertainScope.test.tsindex 017d4d1f1..8949f7c36 100644--- a/workflow-recipes/src/workflow/workflowReconciler.codexUncertainScope.test.ts+++ b/workflow-recipes/src/workflow/workflowReconciler.codexUncertainScope.test.ts@@ -29,8 +29,19 @@ const runtimeTokenIssuerMocks = vi.hoisted(() => ({issueMcpHostWorkflowControlToken: vi.fn().mockResolvedValue('mcp-host-control-token'),}))+/**+ * Pass-through spy: the real projection still runs, so no behaviour changes.+ * It exists only to count how many verdicts one reconcile derives.+ */+const codexVerdictMocks = vi.hoisted(() => ({ project: vi.fn() }))+vi.mock('./crashRecovery', () => crashRecoveryMocks)vi.mock('./mcpHostRuntimeTokenIssuerClient', () => runtimeTokenIssuerMocks)+vi.mock('./codexRecipeVerdict', async importOriginal => {+ const actual = await importOriginal<typeof import('./codexRecipeVerdict')>()+ codexVerdictMocks.project.mockImplementation(actual.projectCodexRecipeVerdict)+ return { ...actual, projectCodexRecipeVerdict: codexVerdictMocks.project }+})vi.mock('../gfsBinding', () => ({mintRecipeHostGfsToken: vi.fn().mockResolvedValue({['to'.concat('ken')]: 'gfs-runtime-value',@@ -274,7 +285,7 @@ describe('Codex scope under an undecidable catalog', () => {})it('does not remint or roll when the allowlist read fails and the JWT already holds the scope', async () => {- // N-04. An unreadable ConfigMap yields an empty derivedScopes, which is+ // An unreadable ConfigMap yields an empty derivedScopes, which is// indistinguishable from a revocation. Treating it as one remints with// reason 'scope', which rolls the eager pod and drops its bootstrap proof —// then rolls it a SECOND time when the ConfigMap comes back. No policy@@ -304,7 +315,7 @@ describe('Codex scope under an undecidable catalog', () => {it('still withdraws the scope and rolls the pod when a readable catalog revokes the grant', async () => {// The other half of the same rule: `uncertain` preserves, but a decision- // decides. If this ever stops rolling, N-04's fix has swallowed the+ // decides. If this ever stops rolling, the preserve-on-unreadable fix has swallowed the// revocation path it was explicitly required not to mask.//// The steady-state pass in the middle is the control: it runs against the@@ -409,7 +420,7 @@ describe('Codex allowlist view across interleaved recipes', () => {})it('configures with its OWN binding when another recipe wipes the shared view mid-reconcile', async () => {- // N-08. Recipe B captured a readable catalog; while B is inside+ // Recipe B captured a readable catalog; while B is inside// ensureEagerSdkMcpHost, recipe A's refresh fails and clears the shared// state. Resolving the binding from that shared state after the awaits gave// B a null binding while `codexBindingUndecidable` still said false — a@@ -455,7 +466,7 @@ describe('Codex allowlist view across interleaved recipes', () => {})})- // ── R5-M1 / R5-B1 ───────────────────────────────────────────────────────+ // ── Reconciler-level wiring, not just its two ends ──────────────────────// The previous round fixed the wiring but tested only its two ends: the// helper (malformed -> uncertain) and the provisioner (given the flag as an// input). Nothing drove the reconciler, so forcing the flag to `false` at@@ -480,7 +491,7 @@ describe('Codex allowlist view across interleaved recipes', () => {})it('withholds configure when the runtime-scope parent spec is unavailable', async () => {- // R5-B1 proper. The scope path already called this uncertain and kept the+ // The scope path already called this uncertain and kept the// live JWT scope; the configure path called it `ineligible` and shipped a// null binding, wiping the live execution binding over a transient read.const { reconciler, coreApi, configure } = createHarness()@@ -573,7 +584,7 @@ describe('Codex allowlist view across interleaved recipes', () => {})it('agrees on binding and scope in the eligible case', async () => {- // R5-B1's real invariant, asserted as a biconditional rather than as two+ // The real invariant, asserted as a biconditional rather than as two// independent facts: a configure that carries a binding must come with// the scope, and vice versa.const { reconciler, coreApi, configure } = createHarness()@@ -588,5 +599,25 @@ describe('Codex allowlist view across interleaved recipes', () => {expect(carriedBinding).toBe(true)expect(carriedBinding).toBe(issuedScopes().includes(CODEX_SCOPE))})++ it('derives exactly one verdict per pass, including the eager configure', async () => {+ // The structural half of the invariant. Every earlier fix converged one+ // more dimension between two derivations; this asserts there is only one+ // derivation to converge. A second call with today's arguments cannot+ // disagree, but it is the seam each previous round grew back from — and+ // it emitted the uncertain-provenance warning twice.+ const { reconciler, coreApi, configure } = createHarness()+ bindGrant(reconciler)+ codexVerdictMocks.project.mockClear()++ await reconcileRecipe(reconciler, codexSdkSpec())++ // Positive evidence that the pass really reached eager provisioning —+ // otherwise a count of one would be the count of a reconcile that+ // never got far enough to derive a second verdict.+ expect(builtMcpHostPodFrom(coreApi)).toBeDefined()+ expect(configure).toHaveBeenCalled()+ expect(codexVerdictMocks.project).toHaveBeenCalledTimes(1)+ })})})diff --git a/workflow-recipes/src/workflow/workflowReconciler.ts b/workflow-recipes/src/workflow/workflowReconciler.tsindex 25de87bb6..1cb15fba2 100644--- a/workflow-recipes/src/workflow/workflowReconciler.ts+++ b/workflow-recipes/src/workflow/workflowReconciler.ts@@ -898,7 +898,7 @@ export class WorkflowReconciler {* binding-less v3 configure that wipes a live mcp-host binding.* Readers capture `this.codexView` once and use only that snapshot.*- * There is deliberately NO derived boolean here (R4-B1, R5-B1). Every+ * There is deliberately NO derived boolean here. Every* consumer reads a field of the ONE `CodexRecipeVerdict` a pass computes* with `projectCodexRecipeVerdict`. Converging one dimension at a time —* first `readOk`, then `snapshotError` — always left the next one free to@@ -996,7 +996,7 @@ export class WorkflowReconciler {* the caller must capture the allowlist refresh once and hand the same* object to every consumer. Reading the live field here is exactly how the* scope path and the configure path ended up on two different snapshots- * within one pass (N-08, scope dimension).+ * within one pass (scope dimension).*/private codexVerdictFor(spec: WorkflowRecipeSpec,@@ -1453,7 +1453,7 @@ export class WorkflowReconciler {): Promise<WorkflowReconcileResult> {const preflightError = this.validateWorkflowSpec(spec)if (preflightError) return { phase: 'failed', message: preflightError, workflowPhase: 'failed' }- // R5-B1 audit (R3): capture the allowlist refresh ONCE for this pass and+ // Capture the allowlist refresh ONCE for this pass and// compute the verdict from it. Every consumer below — eager configure, the// run path's secrets, and the NetworkPolicy decision — reads this object// instead of `this.codexView`, which a concurrent recipe can replace@@ -1634,18 +1634,15 @@ export class WorkflowReconciler {// (that PVC is provisioned by the triggered-run path). Mounting it// here would wedge the pod in Pending — the PVC does not exist until a// run starts. The triggered run later recreates the pod with the mount.- // R5-N1: one verdict, computed from the view this pass captured.+ // Reuse the verdict this pass already computed rather than deriving a+ // second one from the same view. Two derivations cannot disagree here+ // (identical arguments, `codexView` is const), but a second one is a+ // seam waiting to drift the moment either call site's arguments move —+ // and it emits the uncertain-provenance warning twice per pass.// Resolving the binding inside the provisioner (after its own awaits)// let a concurrently-reconciled recipe's failed refresh hand over a// null binding that read as decidable — a binding-less v3 configure// that wipes the live host binding.- const eagerCodexVerdict = this.codexVerdictFor(- spec,- recipeUid,- recipeName,- runtimeScopeRecipeName,- codexView- )const eagerStatus = await this.pluginWorkloadSdkProvisioner.ensureEagerSdkMcpHost(recipeName,recipeUid,@@ -1653,7 +1650,7 @@ export class WorkflowReconciler {runtimeScopeRecipeName,spec,runtime,- { mcpHostPhase, codexVerdict: eagerCodexVerdict }+ { mcpHostPhase, codexVerdict })const eagerBootstrapProof =this.pluginWorkloadSdkProvisioner.getBootstrapProof(recipeName)@@ -2908,7 +2905,7 @@ export class WorkflowReconciler {runtime: WorkflowRuntimePlan,awaitsTriggeredRun: boolean,/**- * The pass's Codex projection. R5-B1 audit: recomputing it here read the+ * The pass's Codex projection. Recomputing it here read the* live allowlist view after this method's own awaits, so a NetworkPolicy* decision could rest on a different snapshot than the binding did.*/@@ -3764,7 +3761,7 @@ export class WorkflowReconciler {runtimeScopeRecipeName: string,spec: WorkflowRecipeSpec,recipeUid: string | undefined,- // R5-B1: the SAME verdict the caller used for the configure decision.+ // The SAME verdict the caller used for the configure decision.// Recomputing it here read `this.codexView` live, so a concurrent refresh// could give the binding one snapshot and the scopes another.codexVerdict: CodexRecipeVerdict