Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(plugin-sdk): address Codex-review findings — E2E gate + contract/docs (#348)
Alfredo Lopeze74c0e6f4f96
diff --git a/charts/clerum-crds/crds/workflowrecipe.yaml b/charts/clerum-crds/crds/workflowrecipe.yamlindex c12a9d897..addda89cc 100644--- a/charts/clerum-crds/crds/workflowrecipe.yaml+++ b/charts/clerum-crds/crds/workflowrecipe.yaml@@ -1723,7 +1723,7 @@ spec:maxInvocationsPerMinute:type: integerminimum: 1- description: Rate limit per workload; default 60.+ description: Rate limit per workload; platform default 120 when unset (ENV CONTROL_API_PLUGIN_SDK_PROMPTBRIDGE_PER_MIN, issue #348).resultRetentionHours:type: integerminimum: 1@@ -1770,7 +1770,7 @@ spec:maxNotificationsPerMinute:type: integerminimum: 1- description: Rate limit per workload; default 120.+ description: Rate limit per workload; platform default 150 when unset (ENV CONTROL_API_PLUGIN_SDK_NOTIFICATIONS_PER_MIN, issue #348).maxTitleBytes:type: integerminimum: 1diff --git a/control-api/package-lock.json b/control-api/package-lock.jsonindex f72bfaab7..6006e9e13 100644--- a/control-api/package-lock.json+++ b/control-api/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-control-api",- "version": "0.1.444",+ "version": "0.1.445","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-control-api",- "version": "0.1.444",+ "version": "0.1.445","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 cad177848..383884035 100644--- a/control-api/package.json+++ b/control-api/package.json@@ -1,6 +1,6 @@{"name": "clerum-control-api",- "version": "0.1.444",+ "version": "0.1.445","description": "Internal Clerum control plane REST API + UI for managing CRDs and secrets","main": "dist/main.js","engines": {diff --git a/control-api/test/config.pluginSdkRateLimits.test.ts b/control-api/test/config.pluginSdkRateLimits.test.tsindex 87d86074b..467be895b 100644--- a/control-api/test/config.pluginSdkRateLimits.test.ts+++ b/control-api/test/config.pluginSdkRateLimits.test.ts@@ -17,10 +17,10 @@ import { readFileSync } from 'node:fs'* 2. Each ENV override honored.* 3. Invalid values fail loudly at import (positiveIntegerFromEnv).* 4. Empty string falls back to the code default.- * 5. Deploy mirror: the base ConfigMap AND the full-copy minikube overlay- * both register every key at the code default (plan D1/R1 — omitting a- * key in the minikube full-copy overlay silently falls back to code- * defaults, so drift must fail HERE in CI).+ * 5. Deploy mirror: the base ConfigMap AND the minikube strategic-merge+ * patch overlay both register every key at the code default (plan D1/R1 —+ * the overlay is a strategic-merge patch, so an omitted key inherits the+ * BASE value; all four keys are pinned so drift must fail HERE in CI).*/const RATE_LIMIT_KEYS = [@@ -146,7 +146,7 @@ describe('plugin SDK platform rate-limit config (issue #348)', () => {}})- it('registers every key at the code default in the minikube full-copy overlay', async () => {+ it('registers every key at the code default in the minikube strategic-merge patch overlay', async () => {const config = await loadConfigWith({})const source = read('../../deploy/overlays/minikube/configmaps/control-api-config.yaml')@@ -159,4 +159,24 @@ describe('plugin SDK platform rate-limit config (issue #348)', () => {expect(Number(value), env).toBe(config[field])}})++ it('documents the platform per-minute defaults and ENV keys in the WorkflowRecipe CRD', () => {+ const source = read('../../charts/clerum-crds/crds/workflowrecipe.yaml')++ const invocationsDescription = extractOne(+ source,+ /maxInvocationsPerMinute:\s*\n\s*type: integer\s*\n\s*minimum: 1\s*\n\s*description: (.+)/,+ 'maxInvocationsPerMinute description in charts/clerum-crds/crds/workflowrecipe.yaml'+ )+ expect(invocationsDescription).toContain('default 120')+ expect(invocationsDescription).toContain('CONTROL_API_PLUGIN_SDK_PROMPTBRIDGE_PER_MIN')++ const notificationsDescription = extractOne(+ source,+ /maxNotificationsPerMinute:\s*\n\s*type: integer\s*\n\s*minimum: 1\s*\n\s*description: (.+)/,+ 'maxNotificationsPerMinute description in charts/clerum-crds/crds/workflowrecipe.yaml'+ )+ expect(notificationsDescription).toContain('default 150')+ expect(notificationsDescription).toContain('CONTROL_API_PLUGIN_SDK_NOTIFICATIONS_PER_MIN')+ })})diff --git a/control-ui/app/plugin-workload-sdk/Views.tsx b/control-ui/app/plugin-workload-sdk/Views.tsxindex 4295e4fb6..cea47fa16 100644--- a/control-ui/app/plugin-workload-sdk/Views.tsx+++ b/control-ui/app/plugin-workload-sdk/Views.tsx@@ -165,7 +165,7 @@ export function GrantsView({<span className="cu-field__hint"> · users: {userRefsDisplay}</span>) : null}</td>- {/* No grant-level overrides: the platform per-minute ENV rate limits apply. */}+ {/* Per-run caps removed (issue #348). Shows API-set per-minute grant overrides when present (they take precedence over the platform ENV defaults); 'platform defaults' otherwise. The edit form does not manage these overrides. */}<td>{quotaParts.length === 0 ? 'platform defaults' : quotaParts.join(', ')}</td><td className="cu-cell--right"><Button type="button" variant="ghost" size="sm" onClick={() => onEdit(grant)}>diff --git a/control-ui/package-lock.json b/control-ui/package-lock.jsonindex ce8768032..51480167a 100644--- a/control-ui/package-lock.json+++ b/control-ui/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-control-ui",- "version": "0.1.423",+ "version": "0.1.424","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-control-ui",- "version": "0.1.423",+ "version": "0.1.424","dependencies": {"@clerum/llm-providers": "file:../packages/llm-providers","@clerum/workflow-recipe-capability-policy": "file:../packages/workflow-recipe-capability-policy",diff --git a/control-ui/package.json b/control-ui/package.jsonindex 653ecf0fd..180be428b 100644--- a/control-ui/package.json+++ b/control-ui/package.json@@ -1,6 +1,6 @@{"name": "clerum-control-ui",- "version": "0.1.423",+ "version": "0.1.424","private": true,"scripts": {"dev": "NEXT_IGNORE_INCORRECT_LOCKFILE=1 next dev",diff --git a/deploy/base/control-plane/configmaps.yaml b/deploy/base/control-plane/configmaps.yamlindex d229ac617..0559df810 100644--- a/deploy/base/control-plane/configmaps.yaml+++ b/deploy/base/control-plane/configmaps.yaml@@ -58,9 +58,10 @@ data:APPROVAL_RL_REQUEST_PER_MIN: "120"# Plugin Workload SDK platform rate limits (issue #348). Per-run SDK quotas# (maxRequestsPerRun / maxNotificationsPerRun) are deprecated and ignored;- # these per-minute windows reset every 60s, so stepless recipes are never- # permanently trapped. Values MUST equal the code defaults in- # control-api/src/config.ts (150/120/600/600) — the config deploy-mirror+ # limits are enforced over a trailing 60s window (no fixed reset); once+ # traffic slows below the limit the window drains within ~60s — stepless+ # recipes are never permanently trapped. Values MUST equal the code defaults+ # in control-api/src/config.ts (150/120/600/600) — the config deploy-mirror# test fails on drift.CONTROL_API_PLUGIN_SDK_NOTIFICATIONS_PER_MIN: "150"CONTROL_API_PLUGIN_SDK_PROMPTBRIDGE_PER_MIN: "120"diff --git a/deploy/overlays/minikube/configmaps/control-api-config.yaml b/deploy/overlays/minikube/configmaps/control-api-config.yamlindex e08f8f168..9ff03e0ad 100644--- a/deploy/overlays/minikube/configmaps/control-api-config.yaml+++ b/deploy/overlays/minikube/configmaps/control-api-config.yaml@@ -53,11 +53,16 @@ data:WORKFLOW_APPROVAL_DEFAULT_TTL_SEC: '86400'WORKFLOW_APPROVAL_MAX_TTL_SEC: '172800'WORKFLOW_APPROVAL_EXPIRY_INTERVAL_MS: '60000'- # Plugin Workload SDK platform rate limits (issue #348). This overlay is a- # FULL-COPY of the base ConfigMap — omitting a key here silently falls back- # to code defaults, so all four keys are registered at the code defaults- # (150/120/600/600). Per-run SDK quotas are deprecated and ignored; the- # per-minute windows reset every 60s.+ # Plugin Workload SDK platform rate limits (issue #348). This file is a+ # strategic-merge PATCH over the base ConfigMap (registered under patches:+ # in the minikube kustomization). A key omitted here inherits the BASE value+ # from deploy/base/control-plane/configmaps.yaml (the deploy-mirror test+ # pins base to the code defaults). All four keys are set explicitly so+ # minikube's effective values (150/120/600/600) are visible here. Per-run+ # SDK quotas are deprecated and ignored; limits are enforced over a+ # trailing 60s window (no fixed reset); once traffic slows below the limit+ # the window drains within ~60s — stepless recipes are never permanently+ # trapped.CONTROL_API_PLUGIN_SDK_NOTIFICATIONS_PER_MIN: "150"CONTROL_API_PLUGIN_SDK_PROMPTBRIDGE_PER_MIN: "120"CONTROL_API_PLUGIN_SDK_REQUEST_BUCKET_PER_MIN: "600"diff --git a/docs/crds/workflowrecipe.md b/docs/crds/workflowrecipe.mdindex 9d97945ad..f421cec34 100644--- a/docs/crds/workflowrecipe.md+++ b/docs/crds/workflowrecipe.md@@ -1382,6 +1382,7 @@ Declaring this block forces an always-on `mcp-host`. Runtime enforcement is addi| `clientNotifications.allowedTargetRefs` | string[] | No | Max 64. || `clientNotifications.allowedUserRefs` | boolean | No | Whether `userRef` targets are permitted. || `clientNotifications.maxNotificationsPerRun` | integer | No | Min 1. **Deprecated:** accepted but ignored; platform per-minute rate limits apply. Removal planned. |+| `clientNotifications.maxNotificationsPerMinute` | integer | No | Min 1. Platform default 150 when unset (ENV `CONTROL_API_PLUGIN_SDK_NOTIFICATIONS_PER_MIN`, issue #348). || `allowedCallers` | string[] | No | Workload ids permitted to call the SDK. **Empty = all declared workloads.** || `idempotencyKeyPattern` | string | No | Regex; runtime default `^[a-zA-Z0-9_-]{1,128}$`. Must compile. |diff --git a/docs/deploy/plugin-workload-sdk-upgrade.md b/docs/deploy/plugin-workload-sdk-upgrade.mdindex 81cd14eac..ab3b378fa 100644--- a/docs/deploy/plugin-workload-sdk-upgrade.md+++ b/docs/deploy/plugin-workload-sdk-upgrade.md@@ -53,9 +53,13 @@ The SDK enforces platform-level per-minute rate limits configured through the`control-api-config` ConfigMap. The per-run grant quotas `maxRequestsPerRun`and `maxNotificationsPerRun` are deprecated: they are still accepted in grantpayloads for backward compatibility but are ignored by the authorizer. Each-per-minute window resets every 60 seconds, so a stepless recipe that exhausts-a window is throttled for at most one minute and is never permanently trapped-(the failure mode the per-run counters had).+per-minute limit is enforced over a **trailing (rolling) 60-second window**+computed from the invocation audit trail — there is no fixed reset tick.+Denied attempts are recorded and count toward the window, so traffic that+stays above the limit remains throttled while it keeps arriving; once the+caller slows below the limit the trailing window drains within ~60 seconds.+Unlike the deprecated per-run counters, a stepless recipe is never+permanently trapped.| ENV variable | Default | Limits ||---|---|---|@@ -66,7 +70,8 @@ a window is throttled for at most one minute and is never permanently trappedThe defaults above equal the code defaults in `control-api/src/config.ts` andare registered in both `deploy/base/control-plane/configmaps.yaml` and the-full-copy minikube overlay+minikube overlay patch (strategic-merge over the base ConfigMap; omitted keys+inherit base values)`deploy/overlays/minikube/configmaps/control-api-config.yaml`; a drift betweencode and manifests fails the config deploy-mirror test.@@ -77,7 +82,10 @@ Limits are tunable without a code deploy. Edit the key in theControl API so the new environment is picked up:```bash-kubectl rollout restart deployment/control-api -n control-plane+# Preflight: confirm you are pointed at the intended cluster before mutating it.+kubectl config current-context # must print the target environment's context ("$K8S_CONTEXT")+kubectl --context "$K8S_CONTEXT" -n control-plane rollout restart deployment/control-api+kubectl --context "$K8S_CONTEXT" -n control-plane rollout status deployment/control-api --timeout=240s```Values must be positive integers; the Control API fails loudly at startup ondiff --git a/scripts/e2e/e2e-plugin-workload-sdk.sh b/scripts/e2e/e2e-plugin-workload-sdk.shindex 31cb69c36..47317ba75 100755--- a/scripts/e2e/e2e-plugin-workload-sdk.sh+++ b/scripts/e2e/e2e-plugin-workload-sdk.sh@@ -755,7 +755,10 @@ create_grant() {if [ "$family" = "promptBridge" ]; thenpayload="$(prompt_grant_payload "$WORKLOAD_ID")"else- payload='{"recipeNamespace":"sandbox-recipes","recipeName":"'"$RECIPE_NAME"'","capabilityFamily":"clientNotifications","allowedEventTypes":["'"$EVENT_TYPE"'"],"allowedUserRefs":["'"$USER_REF"'"],"allowedCallers":["'"$WORKLOAD_ID"'"],"quotaLimits":{"maxNotificationsPerRun":10}}'+ # issue #348: active per-minute override (maxNotificationsPerMinute) drives the+ # rate-limit gate; the deprecated maxNotificationsPerRun stays on the wire to+ # exercise the admin validate-but-strip path (it is accepted then stripped).+ payload='{"recipeNamespace":"sandbox-recipes","recipeName":"'"$RECIPE_NAME"'","capabilityFamily":"clientNotifications","allowedEventTypes":["'"$EVENT_TYPE"'"],"allowedUserRefs":["'"$USER_REF"'"],"allowedCallers":["'"$WORKLOAD_ID"'"],"quotaLimits":{"maxNotificationsPerMinute":10,"maxNotificationsPerRun":10}}'fiadmin_curl POST "/api/v1/admin/plugin-workload-sdk/grants" "$payload"}@@ -778,7 +781,7 @@ prompt_grant_payload() {--arg fallbackTargetRef "$E2E_PROMPT_FALLBACK_TARGET_REF" \--arg fallbackCredentialSlot "$E2E_PROMPT_FALLBACK_CREDENTIAL_SLOT" \--arg caller "$caller" \- '{recipeNamespace:$namespace,recipeName:$recipe,capabilityFamily:"promptBridge",provider:$provider,allowedModels:[$model,$fallbackModel],promptTargets:[{targetRef:$targetRef,provider:$provider,model:$model,credentialSlot:$credentialSlot},{targetRef:$fallbackTargetRef,provider:$fallbackProvider,model:$fallbackModel,credentialSlot:$fallbackCredentialSlot}],defaultTargetRef:$targetRef,allowedCallers:[$caller],quotaLimits:{maxRequestsPerRun:4}}'+ '{recipeNamespace:$namespace,recipeName:$recipe,capabilityFamily:"promptBridge",provider:$provider,allowedModels:[$model,$fallbackModel],promptTargets:[{targetRef:$targetRef,provider:$provider,model:$model,credentialSlot:$credentialSlot},{targetRef:$fallbackTargetRef,provider:$fallbackProvider,model:$fallbackModel,credentialSlot:$fallbackCredentialSlot}],defaultTargetRef:$targetRef,allowedCallers:[$caller],quotaLimits:{maxInvocationsPerMinute:4,maxRequestsPerRun:4}}'}# ─── prerequisites ───────────────────────────────────────────────────────@@ -1038,6 +1041,16 @@ elsefail "promptBridge grant creation failed"exit 1fi+# issue #348: prove the admin API accepted the deprecated per-run key on the wire+# (grant creation returned 200 above) but STRIPPED it, persisting only the active+# per-minute override. This is the deprecate-and-ignore contract exercised end-to-end.+persisted_pb_quota="$(psql_query "SELECT quota_limits::text FROM plugin_workload_sdk_grants WHERE recipe_namespace='${RECIPE_NS}' AND recipe_name='${RECIPE_NAME}' AND capability_family='promptBridge';")"+if printf '%s' "$persisted_pb_quota" | jq -e '(.maxInvocationsPerMinute == 4) and (has("maxRequestsPerRun") | not)' >/dev/null 2>&1; then+ ok "deprecate-and-strip verified: maxInvocationsPerMinute=4 persisted, deprecated maxRequestsPerRun stripped"+else+ fail "persisted promptBridge quota_limits violate deprecate-and-strip (got: ${persisted_pb_quota})"+ exit 1+fiif create_grant clientNotifications >/dev/null; thenok "created clientNotifications grant"else@@ -1362,11 +1375,13 @@ elseexit 1fi-# Quota enforcement: N+1 call is rejected after quota exhausted.+# Per-minute rate limit (issue #348): the 5th call is rejected once the grant's+# maxInvocationsPerMinute=4 window is exhausted. The wire error code stays+# `quota_exceeded` (HTTP 429), so the fixture marker names are unchanged.if printf "%s" "$logs" | grep -q E2E_SDK_QUOTA_EXCEEDED_OK; then- ok "quota enforcement correctly rejected call after 4/4 requests consumed"+ ok "per-minute rate limit rejected the 5th call after 4/4 invocations in the window"else- fail "quota enforcement did not reject the excess call (fixture marker missing; caller logs redacted)"+ fail "per-minute rate limit did not reject the 5th call (fixture marker missing; caller logs redacted)"exit 1fi