guide
guide8 min read

How to debug a failed Snowflake task (and let an agent do it for you)

Five steps from a red task to a root cause, and how to hand them to an agent

To debug a failed Snowflake task, query the TASK_HISTORY table function for the failed run, read its ERROR_CODE and ERROR_MESSAGE, then follow its QUERY_ID into query history to see the exact statement that failed. Most failures fall into four groups: the SQL itself, privileges, the warehouse, or an upstream task in the graph. This guide walks through each check in order, then shows how an agent can run the same steps from your terminal.

Key Takeaways

  • •A failed task run records an ERROR_CODE, an ERROR_MESSAGE and a QUERY_ID in TASK_HISTORY. Start there, not in the task definition.
  • •Check the task STATE first. FAILED means one run failed. FAILED_AND_AUTO_SUSPENDED means the task has stopped scheduling and needs a manual resume.
  • •In a task graph, the failing task is often not the root cause. A failed or skipped predecessor changes what its children do.
  • •Many failures come from privileges (the task owner role) or warehouse access, and neither shows up by reading the SQL.
  • •The lookup chain is the same every time (task history, query history, grants, upstream tasks), which makes it a good job to hand to an MCP agent.

How to debug a failed Snowflake task: the five-step method

The method below uses only documented Snowflake views and functions. Run it by hand once so you know what the evidence looks like. After that, the agent section shows how to stop doing the lookups yourself.

The Snowflake tasks documentation is the reference for the behaviors we mention here: task graphs, the owner role, serverless versus warehouse-backed tasks, and automatic suspension.

Step 1: Find the failed run in TASK_HISTORY

Start with the task history for the failing task. Filter to errors so you see only runs that did not succeed:

  • •SELECT name, state, error_code, error_message, query_id, scheduled_time, completed_time FROM TABLE(INFORMATION_SCHEMA.TASK_HISTORY(TASK_NAME => 'MY_TASK', ERROR_ONLY => TRUE, RESULT_LIMIT => 20)) ORDER BY scheduled_time DESC;

Read the STATE column before the message. FAILED means that run errored and the task will try again on its next schedule. FAILED_AND_AUTO_SUSPENDED means Snowflake suspended the task after repeated failures, so it will not run again until you resume it. The threshold is controlled by the SUSPEND_TASK_AFTER_NUM_FAILURES parameter. A task that was never resumed at all will not appear as failed, because tasks are created in a suspended state. If you see no runs, check that first with SHOW TASKS.

Copy the QUERY_ID from the failed row. It is your bridge to the statement that actually ran.

Step 2: Follow the query ID to the failing statement

TASK_HISTORY tells you that a run failed. The query record tells you what the warehouse did. Look up the QUERY_ID in query history, either through the QUERY_HISTORY table function or the ACCOUNT_USAGE view if the run is older than the information schema retains.

Check these columns on that record:

  • •ERROR_MESSAGE and ERROR_CODE: the SQL-level failure, such as a missing column, a type mismatch or a failed MERGE.
  • •QUERY_TEXT: the statement the task executed. If the task calls a stored procedure, the failing statement may be inside it, and you will need the child queries for that procedure call.
  • •EXECUTION_STATUS and the timing columns: a run that spent most of its time queued or compiling points at the warehouse, not the SQL.
  • •WAREHOUSE_NAME and ROLE_NAME: confirm the task ran where and as whom you expected.

If the error is a SQL error, the most common cause is that something upstream changed: a column was renamed, a type widened, a source table was recreated. Ask what changed in the source since the last good run. That is the same question our users type as "What changed in the orders schema since last deploy?"

Step 3: Check privileges and the task owner role

A task runs with the privileges of its owner role, not the privileges of whoever created it or whoever is debugging it. This is the source of a lot of confusing failures: the SQL works when you run it in a worksheet, and fails inside the task.

  • •Confirm the owner role has the global EXECUTE TASK privilege. Serverless tasks need EXECUTE MANAGED TASK instead.
  • •Confirm the owner role has USAGE on the database, schema and warehouse, and the right object privileges on every table the SQL touches.
  • •Check recent grant changes. A revoke, a role restructuring or an ownership transfer can break a task that has run for months.
  • •Run the task's SQL manually while using the same role (USE ROLE) to reproduce the failure.

If the error mentions an object that "does not exist or not authorized," assume privileges before assuming the object is missing. Snowflake deliberately does not distinguish the two.

Step 4: Check the warehouse and the task graph

If the SQL and grants are fine, look at the surroundings. Two things cause failures that look unrelated to the task itself.

First, the warehouse. A task assigned to a warehouse that was dropped, renamed, suspended without auto-resume, or resized down can fail or time out. Compare the failed run's duration against previous successful runs. A run that hits the task timeout, controlled by USER_TASK_TIMEOUT_MS, often means a data volume jump or a contended warehouse. That is the same shape of problem behind "Why is the nightly pipeline 3x slower this week?"

Second, the graph. If your task has a predecessor, look at the predecessor's history for the same run group. Query TASK_HISTORY with the graph's root task and compare GRAPH_RUN_GROUP_ID across rows. A failed predecessor means children are skipped for that run, so the task you were paged on may be a symptom. Also confirm that the graph is fully resumed. A child that is suspended will not run even when the root succeeds.

Step 5: Fix it, resume it, and confirm the next run

Apply the fix at the right layer: change the SQL with ALTER TASK ... MODIFY AS, fix the grant, repair the warehouse, or repair the upstream table. Then resume what was suspended. For a graph, resume the child tasks before the root, or use the SYSTEM$TASK_DEPENDENTS_ENABLE function to enable the root and its dependents together.

Do not stop at resuming. Either trigger a run with EXECUTE TASK or wait for the next schedule, and then confirm in TASK_HISTORY that the state is SUCCEEDED. A resumed task that fails again will auto-suspend again, and you will have lost another cycle.

Common Snowflake task failures and where to look

SymptomLikely causeWhere to check
State is FAILED_AND_AUTO_SUSPENDEDRepeated failures hit SUSPEND_TASK_AFTER_NUM_FAILURESTASK_HISTORY, then SHOW PARAMETERS on the task
Error says object does not exist or not authorizedOwner role lacks a privilege, or a grant was revokedGrants on the owner role; reproduce with USE ROLE
Run exceeds the time limitData volume growth or warehouse contentionQuery history timing; USER_TASK_TIMEOUT_MS
Task never appears in historyTask is still suspended, or the schedule or condition never firesSHOW TASKS; the WHEN condition and schedule
Child task did not runPredecessor failed or was skipped, or the child is suspendedTASK_HISTORY for the root, grouped by GRAPH_RUN_GROUP_ID
SQL compile error on a columnUpstream schema changeCompare current schema to the last successful run

Let an agent run the five steps

Every step above is a lookup. Read task history, read query history, read grants, read the upstream graph, then correlate. A human does this serially across tabs, which is why the gap between "the alert fired" and "it's fixed" is still hours of labor in many teams. Our own estimate from working with data teams is two to four hours per incident, and we treat that as our observation, not an industry benchmark.

An agent can do the same lookups in one pass. Our Incidents Agent is an MCP server, so you invoke it from Claude Code, Cursor or any client that speaks the Model Context Protocol. You ask the question in plain language, for example "Why did the nightly load task fail?", and the agent traces the failed run, pulls the query record, checks the owner role and warehouse, walks the upstream graph, and returns a root cause with a proposed fix. In the open-source edition it is read-only by default, so it diagnoses and proposes but does not change anything. Writes arrive with approval workflows in Pro.

The agent does not work alone. When the root cause is an upstream schema change, the Incidents Agent chains with the Schema Agent to map the blast radius, which answers "What's the blast radius if I drop this column?" before you apply a fix that might break a different consumer. Our Connectors Agent handles the Snowflake connection, so the credentials stay in your infrastructure and the data does not leave it.

The value is not that an agent knows Snowflake better than you do. It is that the five lookups cost seconds instead of an hour, and the evidence arrives together instead of scattered across tabs. We covered how the agents share context across ingestion, quality and governance in a separate post on why a coordinated swarm beats point tools. Detection tools tell you something is wrong. The harder part is the diagnosis and the fix.

What we would not automate

We keep a per-domain autonomy dial for a reason. Diagnosis is safe to automate fully, since it is read-only. Fixes are different. Resuming a task is low risk. Rewriting a task's SQL or changing a grant on a role that owns production objects is not. Our opinion is that teams should start with diagnosis on, fixes behind approval, and loosen the dial per domain as the track record builds. In our early pilot testing, 60% of incidents auto-resolved before a human was notified. That is our pilot data, and your mix of incident types will differ.

A short checklist to keep

  • •Read STATE, ERROR_CODE and ERROR_MESSAGE from TASK_HISTORY, and copy the QUERY_ID.
  • •Open the query record: statement, status, timing, warehouse, role.
  • •Verify the owner role's privileges and reproduce the SQL under that role.
  • •Compare run duration to prior runs, then check the predecessor and the graph's resume state.
  • •Fix, resume children before the root, and confirm a SUCCEEDED run.

Frequently Asked Questions

Where do I find the error for a failed Snowflake task? Query the TASK_HISTORY table function (or the ACCOUNT_USAGE task history view for older runs) and read ERROR_CODE and ERROR_MESSAGE. Then use the QUERY_ID from the same row to open the underlying query record for the full statement and timing.

Why does my Snowflake task say FAILED_AND_AUTO_SUSPENDED? Snowflake suspends a task after it fails a set number of consecutive times, controlled by the SUSPEND_TASK_AFTER_NUM_FAILURES parameter. The task stops scheduling until you fix the cause and run ALTER TASK ... RESUME. Fix the cause first, or it will suspend again.

Why does the SQL work in a worksheet but fail as a task? The task runs as its owner role, not as you. A missing privilege, a different default warehouse or a role without USAGE on a schema produces this exact behavior. Switch to the owner role with USE ROLE and rerun the statement to reproduce the failure.

Can an AI agent debug a Snowflake task failure for me? Yes, for the diagnosis. The steps are read-only lookups that an agent can run through an MCP server from Claude Code or Cursor. Applying the fix is a separate decision, and we recommend keeping it behind approval until you trust the agent on that class of failure.

Does the agent need my data to debug a task? No. The diagnosis uses metadata: task and query history, grants and lineage. Data Workers runs inside your infrastructure, and the data does not leave it.