{
  "name": "ClawdCall - Human escalation for blocked AI workflow",
  "nodes": [
    {
      "parameters": {},
      "id": "1f3b09bf-8903-446c-ae07-1743230399f4",
      "name": "Manual self-test",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [-820, -180]
    },
    {
      "parameters": {
        "jsCode": "return [{ json: { synthetic: true, self_test: true, event_id: 'synthetic-n8n-block-001', state: 'waiting', failure_count: 3, deadline_minutes: 10, owner_known: true, impact: 'test', workflow_name: 'Synthetic approval workflow', failure_class: 'approval timeout', owner_phone: 'REPLACE_WITH_YOUR_OWN_E164_NUMBER', allowed_decisions: ['acknowledge', 'retry', 'pause', 'delegate'] } }];"
      },
      "id": "9a3ec5fd-faa0-4a8a-a196-278c805e3396",
      "name": "Synthetic blocked workflow",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [-580, -180]
    },
    {
      "parameters": {},
      "id": "d5994b20-3ead-4eef-8df0-a8c60ba395f6",
      "name": "Production Error Trigger",
      "type": "n8n-nodes-base.errorTrigger",
      "typeVersion": 1,
      "position": [-820, 120]
    },
    {
      "parameters": {
        "jsCode": "const input = $json;\nconst execution = input.execution ?? {};\nconst workflow = input.workflow ?? {};\nreturn [{ json: { synthetic: false, self_test: false, event_id: String(execution.id ?? ''), state: 'error', failure_count: Number(input.failure_count ?? 1), deadline_minutes: Number(input.deadline_minutes ?? 999), owner_known: input.owner_known === true, impact: String(input.impact ?? 'unknown'), workflow_name: String(workflow.name ?? 'Unnamed workflow'), failure_class: String(input.failure_class ?? execution.lastNodeExecuted ?? 'workflow error'), owner_phone: String(input.owner_phone ?? ''), allowed_decisions: ['acknowledge', 'retry', 'pause', 'delegate'] } }];"
      },
      "id": "5dcc156d-3470-4fda-b482-ce15a0879ad6",
      "name": "Normalize production error",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [-580, 120]
    },
    {
      "parameters": {
        "jsCode": "const event = $json;\nconst allowedState = ['error', 'waiting'].includes(event.state);\nconst retriesExhausted = Number(event.failure_count) >= 3;\nconst deadlineIsClose = Number(event.deadline_minutes) <= 15;\nconst safeRecipient = event.owner_known === true;\nconst material = ['customer', 'revenue', 'operations', 'test'].includes(event.impact);\nconst approvedSyntheticTest = event.synthetic === true && event.self_test === true;\nif (!(allowedState && retriesExhausted && deadlineIsClose && safeRecipient && material)) return [];\nif (event.synthetic && !approvedSyntheticTest) return [];\nconst decisions = Array.isArray(event.allowed_decisions) ? event.allowed_decisions.join(', ') : 'acknowledge or pause';\nconst tasks = [\n  'Purpose: notify the pre-authorized workflow owner that an n8n process cannot safely continue.',\n  `Workflow: ${event.workflow_name}.`,\n  `Safe failure class: ${event.failure_class}.`,\n  `State: ${event.state} after ${event.failure_count} attempts; deadline in ${event.deadline_minutes} minutes.`,\n  `Ask the recipient to choose one bounded response: ${decisions}.`,\n  'Confirm the response once, close politely, and do not request credentials or customer data.',\n  'This payload contains no raw stack trace, secret, or customer record.'\n].join('\\n');\nreturn [{ json: { dedupe_key: event.event_id, dry_run: true, clawdcall: { target: event.owner_phone, tasks, raw: { introMessage: `n8n escalation test for ${event.workflow_name}.` } } } }];"
      },
      "id": "f3f4b70f-5f27-48e0-abde-1e40fd76e84d",
      "name": "Gate and build safe call",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [-300, -20]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.clawdcall.com/external/v1/agent/outbound?conversionFlag=1",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Accept",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify($json.clawdcall) }}",
        "options": {
          "timeout": 30000
        }
      },
      "id": "93ad05dd-989b-4eea-b714-b05a8b8113e1",
      "name": "Call yourself - enable after review",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [0, -20],
      "disabled": true,
      "credentials": {
        "httpHeaderAuth": {
          "name": "ClawdCall Bearer"
        }
      }
    }
  ],
  "connections": {
    "Manual self-test": {
      "main": [
        [
          {
            "node": "Synthetic blocked workflow",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Synthetic blocked workflow": {
      "main": [
        [
          {
            "node": "Gate and build safe call",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Production Error Trigger": {
      "main": [
        [
          {
            "node": "Normalize production error",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Normalize production error": {
      "main": [
        [
          {
            "node": "Gate and build safe call",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Gate and build safe call": {
      "main": [
        [
          {
            "node": "Call yourself - enable after review",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "pinData": {},
  "active": false,
  "settings": {
    "executionOrder": "v1",
    "saveManualExecutions": true
  },
  "versionId": "31c2fb61-75a8-4edc-a469-b18a6d62c4ed",
  "meta": {
    "templateCredsSetupCompleted": false,
    "clawdcallRecipe": "workflow_n8n_agent_failure",
    "safeTest": true
  },
  "tags": []
}
