Fix: n8n Supabase support bot broken
Duplicate Telegram replies, silent failures, and repeated escalations usually come from missing idempotency boundaries between n8n and Supabase. Add retry-safe state records, explicit error paths, and ticket-state checks.
Last updated: 2026-06-08 · Tested on: n8n 1.x with Supabase PostgreSQL · ~6 min read
Symptoms — what you're seeing
- A Telegram customer receives the same answer twice after a slow or retried n8n execution
- The bot says it is escalating a request, but two tickets are created for the same conversation
- A failed Supabase query or AI node leaves the customer with no reply at all
- The rate-limit check fails, and the workflow either blocks every message or allows unlimited requests without an audit trail
- A critic agent rejects or rewrites an answer using facts that were not present in the question, database result, or proposed answer
- A teammate resolves a ticket in Slack, but the next customer message still treats the request as new
Why this happens
An n8n support agent is not one operation. It is a set of state transitions: receive an update, deduplicate it, enforce traffic controls, retrieve context, answer, validate, reply, and possibly create or update a ticket. If those boundaries are left to the AI agent or to execution order alone, retries produce duplicate replies and duplicate side effects.
1. Deduplication happens too late. Telegram can deliver an update again when the first execution is slow or the transport retries. If the workflow calls the AI model before recording the update ID, the second execution can repeat the model call and the customer-facing reply. Put the idempotency write immediately after the Telegram Trigger or Webhook node, but track whether the downstream reply actually completed.
2. A read-then-insert ticket check is not atomic. Two executions can both query Supabase, see no open ticket, and then both insert one. A separate Supabase lookup is useful for the response text, but it is not a concurrency guard. The database needs a unique key, an upsert, or a transaction that makes the escalation idempotent.
3. Fail-open rate limiting is treated as a free pass. If the rate-limit query fails and the workflow simply continues, a Supabase outage becomes unlimited access to the model and support tools. Fail-open can be an intentional availability decision, but it must produce an error log, an execution metric, and a bounded fallback behavior. Do not silently ignore the failed check.
4. The critic has authority it should not have. A critic agent should classify the proposed answer against known inputs. It should not become a second answer-writing agent. If it can introduce new facts, it can create the exact hallucination control it was meant to prevent.
5. The error path is missing. n8n's normal path can terminate on a failed Supabase, Telegram, or model node without sending a customer-facing response. A support workflow needs a separate error workflow or explicit error branch that records the failure, marks the update retryable, and sends a safe fallback message.
The fix, step by step
- Record the incoming update with a retryable state before doing useful work. Extract the Telegram update ID and chat ID from the Telegram Trigger output. Insert the update ID into a Supabase table with a unique constraint and an explicit lifecycle state. A duplicate record is not automatically a reason to stop: stop when its state is
replied, but retry records inreceivedorfailed. Claim the row asprocessingwith a guarded update so two concurrent executions cannot process it at the same time.create table processed_updates ( update_id bigint primary key, chat_id text not null, status text not null default 'received' check (status in ('received', 'processing', 'replied', 'failed')), attempts integer not null default 0, last_error text, processed_at timestamptz not null default now(), replied_at timestamptz ); insert into processed_updates (update_id, chat_id) values ($1, $2) on conflict (update_id) do nothing; update processed_updates set status = 'processing', attempts = attempts + 1, last_error = null where update_id = $1 and status in ('received', 'failed');Use the insert and guarded update results as the gate. A row already marked
repliedends the duplicate execution. A row inreceivedorfailedcan be claimed for another attempt. If an execution remains inprocessing, reclaim it only after an explicit lease timeout or from the error workflow; do not let two active executions process it concurrently.After the Telegram Send Message node succeeds, update the row to
replied. On a Supabase, model, or Telegram failure, update it tofailedand store a bounded error message so the next delivery or controlled retry can send the normal reply or fallback. A Telegram timeout can leave delivery ambiguous, so keep the reply transition and retry policy explicit rather than assuming that every failed request was undelivered. - Make the rate-limit decision explicit. Query recent messages for the chat ID and count them inside a 60-second window. If the check succeeds and the limit is reached, send a rate-limit reply and stop. If the check errors, write the error to your execution log and apply the availability policy you chose. If that policy is fail-open, keep it bounded with an alert and a fallback cap rather than treating every database failure as unlimited access.
The rate-limit path must not be confused with the OpenAI 429 retry problem. A chat-level limit controls customer traffic; a 429 handler controls provider capacity. You need both when the bot calls an AI model.
- Retrieve facts before generating an answer. Use the Supabase node or an HTTP Request node against the Supabase REST API to retrieve the relevant knowledge-base rows and live order data. Pass the returned records to the agent as structured context. Keep the customer question, database records, and proposed answer as separate fields so the critic can inspect the actual evidence rather than a flattened prompt.
- Make escalation idempotent. Before the agent sends an escalation claim, query for an unresolved ticket using a stable conversation key such as the Telegram chat ID plus the issue or conversation identifier. If an open or pending ticket exists, tell the customer that the request is already with the team. Do not create another ticket.
For stronger concurrency protection, give each escalation an idempotency key and enforce it in PostgreSQL. The key can be based on the conversation identifier and escalation subject. The exact columns depend on your existing schema, so confirm the ticket table and status values against your own schema before adapting this SQL. The important part is that the database, not only the n8n branch logic, rejects a duplicate.
Stuck on this for more than 30 minutes? Book a 30-min call. I'll get on Zoom, look at your workflow, and either fix it on the call or scope what it'll take. No upsell, no decks.
- Constrain the critic to a verdict. Give the critic the database record, the customer's question, and the proposed answer. Its output should be a structured verdict such as
approve,reject_contradiction,reject_off_topic, orreject_tone, with a short reason. It should not write a replacement answer or add facts.Validate every incoming item in the Code node. Do not use
$input.first()when the node may receive multiple records:const items = $input.all(); return items.map((item) => { const verdict = item.json.critic?.verdict; const allowed = new Set([ "approve", "reject_contradiction", "reject_off_topic", "reject_tone", ]); return { json: { ...item.json, criticAccepted: verdict === "approve", criticValid: allowed.has(verdict), }, }; });If the verdict is missing or outside the allowed set, route it to the error path. A malformed critic response must not silently pass as approval.
- Separate normal replies from failure replies. The normal branch sends the approved answer. The failure branch sends a short message such as “I couldn't complete that lookup. Your message is recorded and the support team can review it.” Do not expose stack traces, Supabase error details, prompts, or credentials to the customer. Store the execution ID, chat ID, failed node, and error message in an internal log, and mark the update
failedso the retry path does not discard it as already processed. - Close the ticket loop from Slack. The Slack
/resolve-ticketcommand should identify the ticket, update its status, and return a confirmation stating whether a matching ticket was found and changed. Make the command idempotent: resolving an already-resolved ticket should return its current state instead of creating another update. When the customer messages again, retrieve the current ticket status before deciding whether to answer, reopen, or tell them that the team is still handling it.
Stuck on this for more than 30 minutes? Book a 30-min call. I'll get on Zoom, look at your workflow, and either fix it on the call or scope what it'll take. No upsell, no decks.
Common variations
- “The Telegram bot replies twice after a timeout.” Check the processed-update state first. Stop only when the update is marked
replied; allowfailedrecords to retry, and define how ambiguous Telegram send timeouts are handled. - “Supabase says no ticket exists, but two tickets appear.” This is the read-then-insert race. Add a database-level uniqueness rule or idempotent upsert; a second IF node does not solve concurrent executions.
- “The critic approves answers that contain plausible but unsupported facts.” Remove answer-generation authority from the critic and pass it only the evidence, question, and proposed answer. Reject malformed structured output.
- “The customer gets silence when the knowledge-base lookup fails.” Add an error workflow or error branch connected to the Telegram reply path. Mark the update
failedfor retry; a failed node is not a customer response. - “Slack says the ticket was resolved, but the bot escalates it again.” Check whether the customer-facing lookup filters the wrong status or uses a different conversation key from the Slack command. Log both identifiers and compare them on the same ticket record.
The same failure pattern appears when an n8n workflow loses state between executions. If your agent is also throwing null prompt or memory errors, check the n8n Simple Memory node error diagnostic rather than adding more instructions to the agent.
When this isn't the issue
If the update is deduplicated correctly and the ticket state is consistent, continue down this diagnostic ladder:
- Telegram delivery: inspect the Send Message node input and response. Confirm the chat ID belongs to the incoming update and that the bot token can still send messages.
- Supabase authorization: check the REST response status and the service role or authenticated key used by n8n. A row-level security policy can make a valid table look empty or reject an insert.
- Agent tool output: log the tool name, arguments, result status, and execution ID. Do not log customer secrets or full credentials. If the model is calling tools with invalid arguments, validate the arguments before the tool node.
- Workflow concurrency: review n8n execution history for overlapping runs from the same chat. A correct state transition and deduplication key should stop duplicate side effects even when executions overlap.
Related pages
- Fix n8n OpenAI 429 rate-limit errors
- Fix n8n Simple Memory node errors
- Fix GoHighLevel workflow not triggering
Still broken? Book a 30-min scope call or email Basit. I'll inspect the n8n execution history, Supabase constraints, and ticket state transitions with you.
Need this workflow customized or debugged? Book a 30-min scope call →
Stuck configuring this workflow?
I build and fix n8n workflows for agencies and SaaS teams. 30-minute scope call — bring the problem, leave with an estimate.