Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
feat(guardrails): unattended ask fails safe to deny + execution_mode metric (phase 1)
Andy Pavia1a6160149236
diff --git a/mcp-host/package-lock.json b/mcp-host/package-lock.jsonindex 6b495a027..a62cdc464 100644--- a/mcp-host/package-lock.json+++ b/mcp-host/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-mcp-host",- "version": "0.1.237",+ "version": "0.1.238","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-mcp-host",- "version": "0.1.237",+ "version": "0.1.238","license": "SEE LICENSE IN LICENSE","dependencies": {"@anthropic-ai/sdk": "^0.32.0",diff --git a/mcp-host/package.json b/mcp-host/package.jsonindex c4d1823eb..2b209bb31 100644--- a/mcp-host/package.json+++ b/mcp-host/package.json@@ -1,6 +1,6 @@{"name": "clerum-mcp-host",- "version": "0.1.237",+ "version": "0.1.238","description": "MCP Host - reads Host CRD and provides LLM access via OpenAI/Claude","main": "dist/main.js","engines": {diff --git a/mcp-host/src/agent/taskExecutor.ts b/mcp-host/src/agent/taskExecutor.tsindex c5421b8ab..a91d6d094 100644--- a/mcp-host/src/agent/taskExecutor.ts+++ b/mcp-host/src/agent/taskExecutor.ts@@ -1193,6 +1193,9 @@ export class TaskExecutor {// Undefined when no rules are configured (no-config compatibility, §5); a// malformed set throws here (fail-closed admission, §3/§5).loopConfig.guardrails = buildToolLaneGuardrail(this.deps.guardrailsConfig)+ // §6.3: cron/autonomous tasks have no human to answer an approval, so a+ // guardrail `ask` there fails safe to deny.+ loopConfig.executionMode = this.task.source === 'cron' ? 'unattended' : 'interactive'loopConfig.skipContextManager =opts?.skipContextManager ?? this.conversation?.pending_approval !== undefined// T1.5 — pass the storage + taskId down so `executeSingleTool` can persistdiff --git a/mcp-host/src/core/guardrails/boundary.ts b/mcp-host/src/core/guardrails/boundary.tsindex 436484da3..376af0fd3 100644--- a/mcp-host/src/core/guardrails/boundary.ts+++ b/mcp-host/src/core/guardrails/boundary.ts@@ -82,18 +82,21 @@ export async function evaluateBoundary<Input, Result, Identity>(return { decision, reasonCode, effectiveInput, source }}+type ExecutionMode = 'interactive' | 'unattended' | 'unknown'+function record(lane: 'tool' | 'llm',decision: Decision,source: string,outcome: 'executed' | 'denied' | 'ask',- reasonCode: string+ reasonCode: string,+ executionMode: ExecutionMode = 'unknown'): void {guardrailDecisionsTotal.inc({lane,decision,source,- execution_mode: 'unknown', // enriched by the lane adapter when known (spec §6.3)+ execution_mode: executionMode, // enriched by the lane adapter when known (spec §6.3)phase: 'pre',outcome,reason_code: reasonCode,@@ -106,9 +109,10 @@ export function recordDecision(decision: Decision,source: string,outcome: 'executed' | 'denied' | 'ask',- reasonCode: string+ reasonCode: string,+ executionMode: ExecutionMode = 'unknown'): void {- record(lane, decision, source, outcome, reasonCode)+ record(lane, decision, source, outcome, reasonCode, executionMode)}export function createGuardrailBoundary<Input, Result, Identity>(diff --git a/mcp-host/src/core/orchestration/__tests__/guardrailGate.test.ts b/mcp-host/src/core/orchestration/__tests__/guardrailGate.test.tsindex 885829c53..06ac157cb 100644--- a/mcp-host/src/core/orchestration/__tests__/guardrailGate.test.ts+++ b/mcp-host/src/core/orchestration/__tests__/guardrailGate.test.ts@@ -144,6 +144,17 @@ describe('guardrail gate in executeToolCalls', () => {expect(tool.calls).toHaveLength(0)})+ it('ask in unattended mode → fail-safe deny, no suspension (§6.3)', async () => {+ const tool = new StubTool('do_thing')+ const config = makeConfig(tool, fixedGuardrail('ask', 'needs_ok'))+ config.executionMode = 'unattended'+ const { toolResults, pendingApproval } = await executeToolCalls([call], config, 0)+ expect(pendingApproval).toBeUndefined()+ expect(toolResults[0].is_error).toBe(true)+ expect(toolResults[0].content).toContain('no approver is available')+ expect(tool.calls).toHaveLength(0)+ })+it('doom-loop: 3rd consecutive identical call is denied (§6.4)', async () => {const tool = new StubTool('do_thing')const config = makeConfig(tool, fixedGuardrail('allow'))diff --git a/mcp-host/src/core/orchestration/loopConfig.ts b/mcp-host/src/core/orchestration/loopConfig.tsindex 3f5d8d5d9..a4caa80de 100644--- a/mcp-host/src/core/orchestration/loopConfig.ts+++ b/mcp-host/src/core/orchestration/loopConfig.ts@@ -49,6 +49,14 @@ export interface LoopConfig {*/guardrails?: ToolLaneGuardrail+ /**+ * Execution mode for the guardrail lane (spec §6.3): `unattended` when there is+ * no human to answer an approval (e.g. a cron/autonomous task). A guardrail+ * `ask` in unattended mode fails safe to deny (`approval_unavailable`).+ * Absent → treated as interactive.+ */+ executionMode?: 'interactive' | 'unattended'+// Progress reportingprogressReporter?: ProgressReporterdiff --git a/mcp-host/src/core/orchestration/toolUseLoopToolBatch.ts b/mcp-host/src/core/orchestration/toolUseLoopToolBatch.tsindex 55e5256cd..642679c1a 100644--- a/mcp-host/src/core/orchestration/toolUseLoopToolBatch.ts+++ b/mcp-host/src/core/orchestration/toolUseLoopToolBatch.ts@@ -283,8 +283,10 @@ export async function executeToolCalls(timestamp: new Date(),})+ const mode = config.executionMode ?? 'interactive'+if (gd.decision === 'deny') {- recordDecision('tool', 'deny', gd.source, 'denied', gd.reasonCode)+ recordDecision('tool', 'deny', gd.source, 'denied', gd.reasonCode, mode)toolResults.push({tool_call_id: call.id,name: call.name,@@ -306,17 +308,28 @@ export async function executeToolCalls(const pending = config.conversation.pending_approvalif (pending && pending.tool_name === call.name) {config.conversation.pending_approval = undefined- recordDecision('tool', 'ask', gd.source, 'executed', gd.reasonCode)+ recordDecision('tool', 'ask', gd.source, 'executed', gd.reasonCode, mode)gate = 'proceed'+ } else if (mode === 'unattended') {+ // §6.3: an `ask` with no human to answer it fails safe to deny.+ recordDecision('tool', 'deny', gd.source, 'denied', 'approval_unavailable', mode)+ toolResults.push({+ tool_call_id: call.id,+ name: call.name,+ content:+ 'Blocked: approval required but no approver is available in an autonomous run.',+ is_error: true,+ })+ continue} else {- recordDecision('tool', 'ask', gd.source, 'ask', gd.reasonCode)+ recordDecision('tool', 'ask', gd.source, 'ask', gd.reasonCode, mode)gate = buildGuardrailSuspension(call, config, gd.reasonCode)}} else {// allow / no_decision → the existing approval path. Phase 1: guardrail// `allow` does NOT bypass existing approvals (separating containment from// approval is deferred — the safe direction).- recordDecision('tool', gd.decision, gd.source, 'executed', gd.reasonCode)+ recordDecision('tool', gd.decision, gd.source, 'executed', gd.reasonCode, mode)gate = loopController.beforeTool(call.name, call.arguments)}} else {