<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
  <title>TaskToHuman blog</title>
  <subtitle>Practical articles on putting a person in the loop of automations and AI agents: approval design, signed callbacks and idempotency.</subtitle>
  <id>https://tasktohuman.com/blog</id>
  <link rel="alternate" type="text/html" href="https://tasktohuman.com/blog"/>
  <link rel="self" type="application/atom+xml" href="https://tasktohuman.com/blog/feed.xml"/>
  <updated>2026-11-15T00:00:00Z</updated>
  <icon>https://tasktohuman.com/icon-192.png</icon>
  <author><name>TaskToHuman</name><uri>https://tasktohuman.com/</uri></author>
  <entry>
    <title>Designing an approval step that people actually answer</title>
    <id>https://tasktohuman.com/blog/designing-approval-steps-people-answer</id>
    <link rel="alternate" type="text/html" href="https://tasktohuman.com/blog/designing-approval-steps-people-answer"/>
    <published>2026-11-15T00:00:00Z</published>
    <updated>2026-11-15T00:00:00Z</updated>
    <category term="approvals"/>
    <category term="reliability"/>
    <summary>Most approval steps fail quietly: the request sits in an inbox until it no longer matters. Owners, reminders, backups and deadlines turn an approval into something that reliably ends with an answer.</summary>
    <content type="html">&lt;div class=&quot;prose-post&quot;&gt;&lt;p&gt;An approval step looks simple on a whiteboard: the system asks, a person answers, the system continues. In production the common failure is not a wrong answer. It is no answer. The request lands in an inbox on a Friday afternoon, the approver is travelling, and on Monday the order has been cancelled by an annoyed customer.&lt;/p&gt;&lt;p&gt;An approval step is only as good as its worst case. Here is how to design one that ends with a decision, on time, nearly every time.&lt;/p&gt;&lt;h2 id=&quot;ask-one-person-not-a-group&quot;&gt;Ask one person, not a group&lt;/h2&gt;&lt;p&gt;Sending the request to a shared channel or a group address feels safe: more people see it. In practice it creates the bystander effect. Everyone assumes someone else will handle it, and when two people do, you get two answers.&lt;/p&gt;&lt;p&gt;Give every request a single &lt;strong&gt;owner&lt;/strong&gt;: the person who is asked first and who knows it is theirs. Groups are useful as the next step, not the first.&lt;/p&gt;&lt;h2 id=&quot;make-the-request-answerable-in-thirty-seconds&quot;&gt;Make the request answerable in thirty seconds&lt;/h2&gt;&lt;p&gt;People answer what they can answer immediately. Everything you add to the request should help a decision in half a minute:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;strong&gt;A title that is the question.&lt;/strong&gt; &amp;quot;Refund €249 to order #4821?&amp;quot; beats &amp;quot;New approval request&amp;quot;.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;The few facts that matter.&lt;/strong&gt; Amount, recipient, reason, and whatever your rule flagged. Not the whole record.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;The reason it is being asked.&lt;/strong&gt; &amp;quot;Above the €200 limit&amp;quot; or the agent&amp;#x27;s explanation. It tells the approver what to check.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;Clear actions.&lt;/strong&gt; Approve or reject, and, where it makes sense, correct a value before approving. Correcting a typo is better than rejecting and starting over.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;A comment field.&lt;/strong&gt; For &amp;quot;approved, but tell the customer it&amp;#x27;s a one-off&amp;quot;.&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;And it has to work on a phone, without signing in. An approver who must find a laptop and remember a password will answer later, which often means never.&lt;/p&gt;&lt;h2 id=&quot;remind-before-you-escalate&quot;&gt;Remind before you escalate&lt;/h2&gt;&lt;p&gt;Most unanswered requests are not refusals. They were missed. A single reminder, sent when half of the allowed wait has passed, recovers a large share of them at almost no cost. Make the reminder say what happens next: &amp;quot;If nobody answers in time, this may go to someone else.&amp;quot; That is honest, and it nudges.&lt;/p&gt;&lt;p&gt;Avoid reminder storms. One reminder per person per step is usually enough. More than that teaches people to ignore the sender.&lt;/p&gt;&lt;h2 id=&quot;escalate-to-a-named-backup&quot;&gt;Escalate to a named backup&lt;/h2&gt;&lt;p&gt;When the wait runs out, the request should move on, not die. Decide in advance who the &lt;strong&gt;backup&lt;/strong&gt; is for each kind of request: the owner&amp;#x27;s deputy, the team lead, the person on duty. The backup gets the same request with the same context, plus the fact that the first person didn&amp;#x27;t answer.&lt;/p&gt;&lt;p&gt;For important flows you may want more than one step: owner, then backup, then a manager. Keep chains short. Each step adds waiting time, and a chain of six people usually means nobody really owns the decision.&lt;/p&gt;&lt;p&gt;Also plan for the case where a message can&amp;#x27;t be delivered at all. If the owner&amp;#x27;s email bounces, waiting for the full timeout helps nobody; moving to the next person straight away does.&lt;/p&gt;&lt;h2 id=&quot;always-have-a-deadline-and-a-default&quot;&gt;Always have a deadline and a default&lt;/h2&gt;&lt;p&gt;Every request needs an end. A deadline answers the question your code will otherwise have to answer badly: &lt;em&gt;what happens if nobody ever decides?&lt;/em&gt;&lt;/p&gt;&lt;p&gt;Choose the default deliberately, per kind of request:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;strong&gt;Expire and do nothing.&lt;/strong&gt; The safe choice for most irreversible actions: no refund, no deploy, no deletion. Your code is told and can inform the customer or open a ticket.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;Reject.&lt;/strong&gt; Similar, but explicit, for flows that need a clear &amp;quot;no&amp;quot;.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;Approve.&lt;/strong&gt; Only for low-risk actions where waiting is worse than a rare mistake, and never for money leaving the company.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;Alert the admins.&lt;/strong&gt; When an unanswered request is itself a problem someone must look at.&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Write the default down where the approver can see it. People answer differently when they know silence means &amp;quot;no&amp;quot;.&lt;/p&gt;&lt;h2 id=&quot;separate-approvals-from-follow-ups&quot;&gt;Separate approvals from follow-ups&lt;/h2&gt;&lt;p&gt;Not every request is a yes or no. Some are &amp;quot;someone needs to take care of this&amp;quot;: a chargeback, an unhappy customer, a failed job. For those, the useful answer is &amp;quot;I&amp;#x27;ve got it&amp;quot;, followed later by &amp;quot;done&amp;quot; or &amp;quot;I can&amp;#x27;t, handing it back&amp;quot;.&lt;/p&gt;&lt;p&gt;Treat them differently. An approval is answered once. A follow-up has an owner and a second timer: if the person who took it on doesn&amp;#x27;t finish in time, it moves on, just like an unanswered request.&lt;/p&gt;&lt;h2 id=&quot;keep-the-record&quot;&gt;Keep the record&lt;/h2&gt;&lt;p&gt;Afterwards, someone will ask who approved that payout and why. Keep, for every request: who was asked and when, who reminded and escalated, who decided, the comment, any corrected values, and the time. Keep it in a form that can&amp;#x27;t be quietly edited later.&lt;/p&gt;&lt;h2 id=&quot;test-it-like-code&quot;&gt;Test it like code&lt;/h2&gt;&lt;p&gt;Finally, test the unhappy paths before they happen in production: the owner who never answers, the bounced email, the deadline that passes on a weekend, the approval that arrives after the task was cancelled. Use test requests that reach only you, so nobody else is bothered while you wire it up.&lt;/p&gt;&lt;h2 id=&quot;a-checklist&quot;&gt;A checklist&lt;/h2&gt;&lt;ul&gt;&lt;li&gt;One owner per request, and a named backup.&lt;/li&gt;&lt;li&gt;A title that is the question, and the few facts that matter.&lt;/li&gt;&lt;li&gt;Answerable from a phone, without an account.&lt;/li&gt;&lt;li&gt;One reminder at half the wait.&lt;/li&gt;&lt;li&gt;A deadline and a default chosen per kind of request.&lt;/li&gt;&lt;li&gt;A tamper-proof record of every step.&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;These are the defaults TaskToHuman is built around: an owner and a backup per task type, a reminder at half the wait, deadlines with a chosen default action, and a mobile task page that needs no account. You can read how the pieces fit in the &lt;a href=&quot;https://docs.tasktohuman.com/escalation&quot; rel=&quot;noopener&quot;&gt;developer docs&lt;/a&gt;.&lt;/p&gt;&lt;/div&gt;</content>
  </entry>
  <entry>
    <title>Idempotency keys, explained</title>
    <id>https://tasktohuman.com/blog/idempotency-keys-explained</id>
    <link rel="alternate" type="text/html" href="https://tasktohuman.com/blog/idempotency-keys-explained"/>
    <published>2026-11-15T00:00:00Z</published>
    <updated>2026-11-15T00:00:00Z</updated>
    <category term="idempotency"/>
    <category term="reliability"/>
    <summary>A request times out. Did it work? Idempotency keys let a client retry without creating duplicates. How they work, what a server must store, and the edge cases that matter in practice.</summary>
    <content type="html">&lt;div class=&quot;prose-post&quot;&gt;&lt;p&gt;Your code sends a request to create something: a payment, an order, an approval task. The connection drops before the response arrives. Did the server create it or not?&lt;/p&gt;&lt;p&gt;You can&amp;#x27;t tell. If you don&amp;#x27;t retry, you may have lost the request. If you retry, you may create it twice: two refunds, two shipments, two approval requests in someone&amp;#x27;s inbox. Idempotency keys exist to remove that dilemma.&lt;/p&gt;&lt;h2 id=&quot;what-idempotent-means&quot;&gt;What &amp;quot;idempotent&amp;quot; means&lt;/h2&gt;&lt;p&gt;An operation is idempotent if doing it twice has the same effect as doing it once. Reading a record is idempotent. Setting a field to a value is idempotent. &amp;quot;Create a new task&amp;quot; is not: each call creates another one.&lt;/p&gt;&lt;p&gt;An idempotency key makes a non-idempotent operation behave idempotently from the client&amp;#x27;s point of view. The client generates a unique key for each &lt;em&gt;intended&lt;/em&gt; operation and sends it with the request. The server remembers which keys it has seen. If the same key arrives again, the server doesn&amp;#x27;t perform the operation a second time; it returns the result of the first one.&lt;/p&gt;&lt;figure class=&quot;on-band code-figure overflow-hidden rounded-card border border-band-edge bg-band text-on-band&quot;&gt;&lt;pre class=&quot;overflow-x-auto px-4 py-3.5 text-table leading-6 focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-signal&quot;&gt;&lt;code class=&quot;block font-mono [font-variant-ligatures:none]&quot;&gt;&lt;span class=&quot;block min-h-[1lh] whitespace-pre&quot;&gt;&lt;span class=&quot;text-band-code-keyword&quot;&gt;POST&lt;/span&gt; /v1/tasks&lt;/span&gt;&lt;span class=&quot;block min-h-[1lh] whitespace-pre&quot;&gt;&lt;span class=&quot;text-band-code-key&quot;&gt;Idempotency-Key&lt;/span&gt;&lt;span class=&quot;text-on-band/60&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;text-band-code-string&quot;&gt;refund-4821&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;block min-h-[1lh] whitespace-pre&quot;&gt;&lt;span class=&quot;text-band-code-key&quot;&gt;Content-Type&lt;/span&gt;&lt;span class=&quot;text-on-band/60&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;text-band-code-string&quot;&gt;application/json&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;block min-h-[1lh] whitespace-pre&quot;&gt;&lt;/span&gt;&lt;span class=&quot;block min-h-[1lh] whitespace-pre&quot;&gt;&lt;span class=&quot;text-on-band/60&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;text-band-code-key&quot;&gt;&amp;quot;task_type&amp;quot;&lt;/span&gt;&lt;span class=&quot;text-on-band/60&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;text-band-code-string&quot;&gt;&amp;quot;approve_refund&amp;quot;&lt;/span&gt;&lt;span class=&quot;text-on-band/60&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;text-band-code-key&quot;&gt;&amp;quot;title&amp;quot;&lt;/span&gt;&lt;span class=&quot;text-on-band/60&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;text-band-code-string&quot;&gt;&amp;quot;Refund €249 to order #4821?&amp;quot;&lt;/span&gt; &lt;span class=&quot;text-on-band/60&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;&lt;p&gt;Now the client can retry freely after a timeout, a crash or a deploy. Either the first request worked, and the retry returns the same task, or it didn&amp;#x27;t, and the retry creates it.&lt;/p&gt;&lt;h2 id=&quot;choosing-the-key&quot;&gt;Choosing the key&lt;/h2&gt;&lt;p&gt;The key identifies the intent, not the HTTP request. Two rules:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;strong&gt;The same intent always gets the same key.&lt;/strong&gt; If your code crashes and restarts, it must produce the same key for the same refund. A random UUID generated in memory just before the call is lost in a crash, so prefer a key derived from your own data, like &lt;code&gt;refund-4821&lt;/code&gt;, or a UUID stored with the record before the first attempt.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;Different intents never share a key.&lt;/strong&gt; If a customer legitimately gets two refunds for the same order, the key must tell them apart, for example &lt;code&gt;refund-4821-2&lt;/code&gt;.&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Keep keys short and free of personal data. They tend to end up in logs.&lt;/p&gt;&lt;h2 id=&quot;what-the-server-has-to-do&quot;&gt;What the server has to do&lt;/h2&gt;&lt;p&gt;A correct implementation is more than &amp;quot;look up the key&amp;quot;. The server needs to handle four cases.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;1. A new key.&lt;/strong&gt; Perform the operation and store the key together with the result, atomically. If the operation and the key are written separately, a crash between the two brings back the duplicate problem.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;2. A key seen before, same request.&lt;/strong&gt; Return the stored result. It helps to say so: TaskToHuman answers &lt;code&gt;200 OK&lt;/code&gt; with an &lt;code&gt;Idempotent-Replayed: true&lt;/code&gt; header instead of &lt;code&gt;201 Created&lt;/code&gt;, so the client can tell a replay from a creation if it cares.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;3. A key seen before, different request.&lt;/strong&gt; This is almost always a bug in the client: a key reused for a different refund. Silently returning the old result would hide it. The server should store a hash of the request body with the key and answer with an error when they don&amp;#x27;t match. TaskToHuman returns &lt;code&gt;409&lt;/code&gt; with the code &lt;code&gt;idempotency_conflict&lt;/code&gt;.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;4. Two requests with the same key at the same moment.&lt;/strong&gt; A client that retries aggressively can send the second attempt while the first is still running. Both look up the key, neither finds it, both create. The fix is a database constraint: a unique index on the key, so only one insert can win, and the loser reads and returns the winner&amp;#x27;s result.&lt;/p&gt;&lt;h2 id=&quot;scope-and-lifetime&quot;&gt;Scope and lifetime&lt;/h2&gt;&lt;p&gt;Two more decisions shape the behaviour.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Scope.&lt;/strong&gt; Keys should be unique per account, not globally, so one customer&amp;#x27;s keys can never collide with another&amp;#x27;s. TaskToHuman also separates test and live mode: a key used with a test API key never replays a live task, and the other way round.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Lifetime.&lt;/strong&gt; A server can&amp;#x27;t keep every key forever. Some APIs expire keys after a day. TaskToHuman keeps a key for as long as the task it created exists, which covers any realistic retry window.&lt;/p&gt;&lt;h2 id=&quot;idempotency-on-the-receiving-end&quot;&gt;Idempotency on the receiving end&lt;/h2&gt;&lt;p&gt;Keys protect the server from duplicate requests. The same problem exists in the other direction: when a server sends you webhooks or callbacks, it retries on timeouts too, and you may receive the same event twice.&lt;/p&gt;&lt;p&gt;The solution mirrors the one above. The sender includes a stable event identifier in every delivery (TaskToHuman sends &lt;code&gt;TTH-Event-Id&lt;/code&gt;, the same on every retry), and your receiver stores the identifiers it has processed, in the same transaction as the change the event triggers. A repeated event is acknowledged and skipped.&lt;/p&gt;&lt;h2 id=&quot;a-short-client-recipe&quot;&gt;A short client recipe&lt;/h2&gt;&lt;figure class=&quot;on-band code-figure overflow-hidden rounded-card border border-band-edge bg-band text-on-band&quot;&gt;&lt;div class=&quot;flex min-h-10 items-center justify-between gap-3 border-b border-band-edge py-1 pr-2 pl-4&quot;&gt;&lt;figcaption class=&quot;text-caption font-medium text-on-band/70&quot;&gt;JavaScript&lt;/figcaption&gt;&lt;/div&gt;&lt;pre class=&quot;overflow-x-auto px-4 py-3.5 text-table leading-6 focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-signal&quot;&gt;&lt;code class=&quot;block font-mono [font-variant-ligatures:none]&quot;&gt;&lt;span class=&quot;block min-h-[1lh] whitespace-pre&quot;&gt;&lt;span class=&quot;text-band-code-keyword&quot;&gt;async&lt;/span&gt; &lt;span class=&quot;text-band-code-keyword&quot;&gt;function&lt;/span&gt; createApproval&lt;span class=&quot;text-on-band/60&quot;&gt;(&lt;/span&gt;order&lt;span class=&quot;text-on-band/60&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;text-on-band/60&quot;&gt;{&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;block min-h-[1lh] whitespace-pre&quot;&gt;  &lt;span class=&quot;text-on-band/60 italic&quot;&gt;// Stored with the order before the first attempt, so a crash and restart reuse it.&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;block min-h-[1lh] whitespace-pre&quot;&gt;  &lt;span class=&quot;text-band-code-keyword&quot;&gt;const&lt;/span&gt; key = order.approvalKey ?? &lt;span class=&quot;text-on-band/60&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;text-band-code-keyword&quot;&gt;await&lt;/span&gt; saveApprovalKey&lt;span class=&quot;text-on-band/60&quot;&gt;(&lt;/span&gt;order&lt;span class=&quot;text-on-band/60&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;text-band-code-string&quot;&gt;`refund-${order.id}`&lt;/span&gt;&lt;span class=&quot;text-on-band/60&quot;&gt;));&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;block min-h-[1lh] whitespace-pre&quot;&gt;&lt;/span&gt;&lt;span class=&quot;block min-h-[1lh] whitespace-pre&quot;&gt;  &lt;span class=&quot;text-band-code-keyword&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;text-on-band/60&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;text-band-code-keyword&quot;&gt;let&lt;/span&gt; attempt = &lt;span class=&quot;text-band-code-number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;text-on-band/60&quot;&gt;;&lt;/span&gt; attempt &amp;lt;= &lt;span class=&quot;text-band-code-number&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;text-on-band/60&quot;&gt;;&lt;/span&gt; attempt++&lt;span class=&quot;text-on-band/60&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;text-on-band/60&quot;&gt;{&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;block min-h-[1lh] whitespace-pre&quot;&gt;    &lt;span class=&quot;text-band-code-keyword&quot;&gt;let&lt;/span&gt; response&lt;span class=&quot;text-on-band/60&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;block min-h-[1lh] whitespace-pre&quot;&gt;    &lt;span class=&quot;text-band-code-keyword&quot;&gt;try&lt;/span&gt; &lt;span class=&quot;text-on-band/60&quot;&gt;{&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;block min-h-[1lh] whitespace-pre&quot;&gt;      response = &lt;span class=&quot;text-band-code-keyword&quot;&gt;await&lt;/span&gt; fetch&lt;span class=&quot;text-on-band/60&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;text-band-code-string&quot;&gt;&amp;quot;https://api.tasktohuman.com/v1/tasks&amp;quot;&lt;/span&gt;&lt;span class=&quot;text-on-band/60&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;text-on-band/60&quot;&gt;{&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;block min-h-[1lh] whitespace-pre&quot;&gt;        &lt;span class=&quot;text-band-code-key&quot;&gt;method&lt;/span&gt;&lt;span class=&quot;text-on-band/60&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;text-band-code-string&quot;&gt;&amp;quot;POST&amp;quot;&lt;/span&gt;&lt;span class=&quot;text-on-band/60&quot;&gt;,&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;block min-h-[1lh] whitespace-pre&quot;&gt;        &lt;span class=&quot;text-band-code-key&quot;&gt;headers&lt;/span&gt;&lt;span class=&quot;text-on-band/60&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;text-on-band/60&quot;&gt;{&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;block min-h-[1lh] whitespace-pre&quot;&gt;          &lt;span class=&quot;text-band-code-key&quot;&gt;Authorization&lt;/span&gt;&lt;span class=&quot;text-on-band/60&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;text-band-code-string&quot;&gt;`Bearer ${process.env.TTH_API_KEY}`&lt;/span&gt;&lt;span class=&quot;text-on-band/60&quot;&gt;,&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;block min-h-[1lh] whitespace-pre&quot;&gt;          &lt;span class=&quot;text-band-code-key&quot;&gt;&amp;quot;Content-Type&amp;quot;&lt;/span&gt;&lt;span class=&quot;text-on-band/60&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;text-band-code-string&quot;&gt;&amp;quot;application/json&amp;quot;&lt;/span&gt;&lt;span class=&quot;text-on-band/60&quot;&gt;,&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;block min-h-[1lh] whitespace-pre&quot;&gt;          &lt;span class=&quot;text-band-code-key&quot;&gt;&amp;quot;Idempotency-Key&amp;quot;&lt;/span&gt;&lt;span class=&quot;text-on-band/60&quot;&gt;:&lt;/span&gt; key&lt;span class=&quot;text-on-band/60&quot;&gt;,&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;block min-h-[1lh] whitespace-pre&quot;&gt;        &lt;span class=&quot;text-on-band/60&quot;&gt;},&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;block min-h-[1lh] whitespace-pre&quot;&gt;        &lt;span class=&quot;text-band-code-key&quot;&gt;body&lt;/span&gt;&lt;span class=&quot;text-on-band/60&quot;&gt;:&lt;/span&gt; JSON.stringify&lt;span class=&quot;text-on-band/60&quot;&gt;({&lt;/span&gt; &lt;span class=&quot;text-band-code-key&quot;&gt;task_type&lt;/span&gt;&lt;span class=&quot;text-on-band/60&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;text-band-code-string&quot;&gt;&amp;quot;approve_refund&amp;quot;&lt;/span&gt;&lt;span class=&quot;text-on-band/60&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;text-band-code-key&quot;&gt;title&lt;/span&gt;&lt;span class=&quot;text-on-band/60&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;text-band-code-string&quot;&gt;`Refund ${order.amount} to order #${order.id}?`&lt;/span&gt; &lt;span class=&quot;text-on-band/60&quot;&gt;}),&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;block min-h-[1lh] whitespace-pre&quot;&gt;      &lt;span class=&quot;text-on-band/60&quot;&gt;});&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;block min-h-[1lh] whitespace-pre&quot;&gt;    &lt;span class=&quot;text-on-band/60&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;text-band-code-keyword&quot;&gt;catch&lt;/span&gt; &lt;span class=&quot;text-on-band/60&quot;&gt;{&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;block min-h-[1lh] whitespace-pre&quot;&gt;      response = &lt;span class=&quot;text-band-code-number&quot;&gt;undefined&lt;/span&gt;&lt;span class=&quot;text-on-band/60&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;text-on-band/60 italic&quot;&gt;// network error or timeout: the task may or may not exist, so retry with the same key&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;block min-h-[1lh] whitespace-pre&quot;&gt;    &lt;span class=&quot;text-on-band/60&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;block min-h-[1lh] whitespace-pre&quot;&gt;    &lt;span class=&quot;text-band-code-keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;text-on-band/60&quot;&gt;(&lt;/span&gt;response?.ok&lt;span class=&quot;text-on-band/60&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;text-band-code-keyword&quot;&gt;return&lt;/span&gt; response.json&lt;span class=&quot;text-on-band/60&quot;&gt;();&lt;/span&gt; &lt;span class=&quot;text-on-band/60 italic&quot;&gt;// 201 Created, or 200 with Idempotent-Replayed: true&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;block min-h-[1lh] whitespace-pre&quot;&gt;    &lt;span class=&quot;text-band-code-keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;text-on-band/60&quot;&gt;(&lt;/span&gt;response &amp;amp;&amp;amp; response.status &amp;lt; &lt;span class=&quot;text-band-code-number&quot;&gt;500&lt;/span&gt; &amp;amp;&amp;amp; response.status !== &lt;span class=&quot;text-band-code-number&quot;&gt;429&lt;/span&gt;&lt;span class=&quot;text-on-band/60&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;text-on-band/60&quot;&gt;{&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;block min-h-[1lh] whitespace-pre&quot;&gt;      &lt;span class=&quot;text-band-code-keyword&quot;&gt;const&lt;/span&gt; problem = &lt;span class=&quot;text-band-code-keyword&quot;&gt;await&lt;/span&gt; response.json&lt;span class=&quot;text-on-band/60&quot;&gt;();&lt;/span&gt; &lt;span class=&quot;text-on-band/60 italic&quot;&gt;// 409 idempotency_conflict, 400 validation_failed …&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;block min-h-[1lh] whitespace-pre&quot;&gt;      &lt;span class=&quot;text-band-code-keyword&quot;&gt;throw&lt;/span&gt; &lt;span class=&quot;text-band-code-keyword&quot;&gt;new&lt;/span&gt; Error&lt;span class=&quot;text-on-band/60&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;text-band-code-string&quot;&gt;`Task not created: ${problem.code}`&lt;/span&gt;&lt;span class=&quot;text-on-band/60&quot;&gt;);&lt;/span&gt; &lt;span class=&quot;text-on-band/60 italic&quot;&gt;// a client error: fix the request, don&amp;#x27;t retry&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;block min-h-[1lh] whitespace-pre&quot;&gt;    &lt;span class=&quot;text-on-band/60&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;block min-h-[1lh] whitespace-pre&quot;&gt;    &lt;span class=&quot;text-band-code-keyword&quot;&gt;await&lt;/span&gt; &lt;span class=&quot;text-band-code-keyword&quot;&gt;new&lt;/span&gt; Promise&lt;span class=&quot;text-on-band/60&quot;&gt;((&lt;/span&gt;resolve&lt;span class=&quot;text-on-band/60&quot;&gt;)&lt;/span&gt; =&amp;gt; setTimeout&lt;span class=&quot;text-on-band/60&quot;&gt;(&lt;/span&gt;resolve&lt;span class=&quot;text-on-band/60&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;text-band-code-number&quot;&gt;2&lt;/span&gt; ** attempt * &lt;span class=&quot;text-band-code-number&quot;&gt;250&lt;/span&gt;&lt;span class=&quot;text-on-band/60&quot;&gt;));&lt;/span&gt; &lt;span class=&quot;text-on-band/60 italic&quot;&gt;// back off before retrying&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;block min-h-[1lh] whitespace-pre&quot;&gt;  &lt;span class=&quot;text-on-band/60&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;block min-h-[1lh] whitespace-pre&quot;&gt;  &lt;span class=&quot;text-band-code-keyword&quot;&gt;throw&lt;/span&gt; &lt;span class=&quot;text-band-code-keyword&quot;&gt;new&lt;/span&gt; Error&lt;span class=&quot;text-on-band/60&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;text-band-code-string&quot;&gt;&amp;quot;Task API unavailable&amp;quot;&lt;/span&gt;&lt;span class=&quot;text-on-band/60&quot;&gt;);&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;block min-h-[1lh] whitespace-pre&quot;&gt;&lt;span class=&quot;text-on-band/60&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;&lt;p&gt;The important parts: the key is created once and stored, the request body is the same on every attempt, client errors are not retried, and network errors, server errors and rate limits are retried with a growing pause. (When a server sends a &lt;code&gt;Retry-After&lt;/code&gt; header with a &lt;code&gt;429&lt;/code&gt;, wait at least that long.)&lt;/p&gt;&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;&lt;ul&gt;&lt;li&gt;Send an idempotency key with every request that creates something.&lt;/li&gt;&lt;li&gt;Derive the key from the intent and store it before the first attempt.&lt;/li&gt;&lt;li&gt;On the server: store key, request hash and result atomically, reject a reused key with a different body, and use a unique index for concurrent retries.&lt;/li&gt;&lt;li&gt;On the receiving side, deduplicate events by their identifier.&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;The details for TaskToHuman&amp;#x27;s API are in the &lt;a href=&quot;https://docs.tasktohuman.com/idempotency&quot; rel=&quot;noopener&quot;&gt;idempotency page of the developer docs&lt;/a&gt;.&lt;/p&gt;&lt;/div&gt;</content>
  </entry>
  <entry>
    <title>Verifying signed webhooks correctly: HMAC, timestamps and replays</title>
    <id>https://tasktohuman.com/blog/verifying-signed-webhooks</id>
    <link rel="alternate" type="text/html" href="https://tasktohuman.com/blog/verifying-signed-webhooks"/>
    <published>2026-11-15T00:00:00Z</published>
    <updated>2026-11-15T00:00:00Z</updated>
    <category term="callbacks"/>
    <category term="security"/>
    <category term="webhooks"/>
    <summary>A webhook endpoint is a public URL that changes things in your system. How HMAC signatures work, the five mistakes that make verification useless, and receivers in Node.js and Python that get it right.</summary>
    <content type="html">&lt;div class=&quot;prose-post&quot;&gt;&lt;p&gt;A webhook receiver is a public URL that makes your system do something: mark an order paid, release a refund, continue a deployment. Anyone on the internet can send a request to it. The only thing that separates a real event from a forged one is the signature, so it is worth getting the verification exactly right.&lt;/p&gt;&lt;p&gt;This article explains how HMAC webhook signatures work and the common mistakes, using the scheme TaskToHuman callbacks use as the example. Most providers use the same idea with different header names.&lt;/p&gt;&lt;h2 id=&quot;how-the-signature-works&quot;&gt;How the signature works&lt;/h2&gt;&lt;p&gt;Sender and receiver share a secret. For every request, the sender computes an HMAC-SHA256 over the &lt;strong&gt;exact bytes&lt;/strong&gt; of the body, together with a timestamp, using that secret as the key, and sends the result in a header:&lt;/p&gt;&lt;figure class=&quot;on-band code-figure overflow-hidden rounded-card border border-band-edge bg-band text-on-band&quot;&gt;&lt;pre class=&quot;overflow-x-auto px-4 py-3.5 text-table leading-6 focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-signal&quot;&gt;&lt;code class=&quot;block font-mono [font-variant-ligatures:none]&quot;&gt;&lt;span class=&quot;block min-h-[1lh] whitespace-pre&quot;&gt;TTH-Signature&lt;span class=&quot;text-on-band/60&quot;&gt;:&lt;/span&gt; t=&lt;span class=&quot;text-band-code-number&quot;&gt;1763205641&lt;/span&gt;&lt;span class=&quot;text-on-band/60&quot;&gt;,&lt;/span&gt;v1=5257a869e7ecebeda32affa62cdca3fa51cad7e77a0e56ff536d0ce8e108d8bd&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;&lt;p&gt;Here &lt;code&gt;t&lt;/code&gt; is the time of signing in Unix seconds, and &lt;code&gt;v1&lt;/code&gt; is the hex-encoded HMAC-SHA256 of the string &lt;code&gt;t + &amp;quot;.&amp;quot; + body&lt;/code&gt;. The receiver repeats the computation with its copy of the secret and compares. Someone without the secret cannot produce a matching value, and changing a single byte of the body or the timestamp changes the result completely.&lt;/p&gt;&lt;p&gt;Including the timestamp in the signed data is what makes replay protection possible, as we&amp;#x27;ll see below.&lt;/p&gt;&lt;h2 id=&quot;mistake-1-verifying-a-re-serialized-body&quot;&gt;Mistake 1: verifying a re-serialized body&lt;/h2&gt;&lt;p&gt;The most common bug. The framework parses the JSON body, and the code then calls &lt;code&gt;JSON.stringify(req.body)&lt;/code&gt; to get &amp;quot;the body&amp;quot; for verification. The result is almost never byte-for-byte what was sent: key order, whitespace, number formatting and Unicode escaping can all differ. Verification fails at random, and someone &amp;quot;fixes&amp;quot; it by turning verification off.&lt;/p&gt;&lt;p&gt;Always verify against the &lt;strong&gt;raw bytes&lt;/strong&gt; you received, before any parsing. In Express that means &lt;code&gt;express.raw()&lt;/code&gt; on the webhook route; in Flask, &lt;code&gt;request.get_data()&lt;/code&gt;.&lt;/p&gt;&lt;h2 id=&quot;mistake-2-comparing-with&quot;&gt;Mistake 2: comparing with &lt;code&gt;==&lt;/code&gt;&lt;/h2&gt;&lt;p&gt;A normal string comparison stops at the first different character, so it takes slightly longer the more leading characters match. Over many requests, that timing difference can leak the expected signature. Use a constant-time comparison: &lt;code&gt;crypto.timingSafeEqual&lt;/code&gt; in Node.js, &lt;code&gt;hmac.compare_digest&lt;/code&gt; in Python.&lt;/p&gt;&lt;p&gt;Note that Node&amp;#x27;s &lt;code&gt;timingSafeEqual&lt;/code&gt; throws if the two buffers differ in length, so check the length first and treat a mismatch as a failure.&lt;/p&gt;&lt;h2 id=&quot;mistake-3-ignoring-the-timestamp&quot;&gt;Mistake 3: ignoring the timestamp&lt;/h2&gt;&lt;p&gt;A valid signature proves the request was produced by someone with the secret. It does not prove it was produced &lt;em&gt;now&lt;/em&gt;. An attacker who captures one genuine request (from a log, a proxy or a misconfigured debug tool) can send it again tomorrow, and the signature still matches.&lt;/p&gt;&lt;p&gt;Reject requests whose timestamp is too far from your clock. Five minutes is a common tolerance: long enough for clock drift and slow networks, short enough to make a captured request useless soon. Because the timestamp is inside the signed data, an attacker can&amp;#x27;t simply update it.&lt;/p&gt;&lt;h2 id=&quot;mistake-4-not-handling-duplicates&quot;&gt;Mistake 4: not handling duplicates&lt;/h2&gt;&lt;p&gt;Even with a timestamp check, the same event can legitimately arrive twice. Senders retry when your endpoint times out, even if your code did process the first attempt. Each retry is signed again with a new timestamp, so it passes verification.&lt;/p&gt;&lt;p&gt;Make processing idempotent. Most providers send a stable event identifier with each delivery; with TaskToHuman it is the &lt;code&gt;TTH-Event-Id&lt;/code&gt; header, the same on every retry. Record the identifiers you have handled and skip the ones you have already seen, ideally in the same database transaction as the change the event causes.&lt;/p&gt;&lt;h2 id=&quot;mistake-5-one-secret-forever&quot;&gt;Mistake 5: one secret, forever&lt;/h2&gt;&lt;p&gt;Secrets leak: into a log, a screenshot, an old laptop. You need to be able to rotate them without dropping events. A good scheme lets the old and new secret overlap for a while and sends one signature per active secret. TaskToHuman keeps the previous secret signing for 24 hours after a rotation, so the header carries two &lt;code&gt;v1&lt;/code&gt; values. Your receiver should accept the request if &lt;strong&gt;any&lt;/strong&gt; of them matches.&lt;/p&gt;&lt;h2 id=&quot;a-receiver-in-node-js&quot;&gt;A receiver in Node.js&lt;/h2&gt;&lt;figure class=&quot;on-band code-figure overflow-hidden rounded-card border border-band-edge bg-band text-on-band&quot;&gt;&lt;div class=&quot;flex min-h-10 items-center justify-between gap-3 border-b border-band-edge py-1 pr-2 pl-4&quot;&gt;&lt;figcaption class=&quot;text-caption font-medium text-on-band/70&quot;&gt;JavaScript&lt;/figcaption&gt;&lt;/div&gt;&lt;pre class=&quot;overflow-x-auto px-4 py-3.5 text-table leading-6 focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-signal&quot;&gt;&lt;code class=&quot;block font-mono [font-variant-ligatures:none]&quot;&gt;&lt;span class=&quot;block min-h-[1lh] whitespace-pre&quot;&gt;&lt;span class=&quot;text-band-code-keyword&quot;&gt;import&lt;/span&gt; crypto &lt;span class=&quot;text-band-code-keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;text-band-code-string&quot;&gt;&amp;quot;node:crypto&amp;quot;&lt;/span&gt;&lt;span class=&quot;text-on-band/60&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;block min-h-[1lh] whitespace-pre&quot;&gt;&lt;span class=&quot;text-band-code-keyword&quot;&gt;import&lt;/span&gt; express &lt;span class=&quot;text-band-code-keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;text-band-code-string&quot;&gt;&amp;quot;express&amp;quot;&lt;/span&gt;&lt;span class=&quot;text-on-band/60&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;block min-h-[1lh] whitespace-pre&quot;&gt;&lt;/span&gt;&lt;span class=&quot;block min-h-[1lh] whitespace-pre&quot;&gt;&lt;span class=&quot;text-band-code-keyword&quot;&gt;const&lt;/span&gt; app = express&lt;span class=&quot;text-on-band/60&quot;&gt;();&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;block min-h-[1lh] whitespace-pre&quot;&gt;&lt;span class=&quot;text-band-code-keyword&quot;&gt;const&lt;/span&gt; SECRET = process.env.TTH_SIGNING_SECRET&lt;span class=&quot;text-on-band/60&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;block min-h-[1lh] whitespace-pre&quot;&gt;&lt;span class=&quot;text-band-code-keyword&quot;&gt;const&lt;/span&gt; TOLERANCE_SECONDS = &lt;span class=&quot;text-band-code-number&quot;&gt;300&lt;/span&gt;&lt;span class=&quot;text-on-band/60&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;block min-h-[1lh] whitespace-pre&quot;&gt;&lt;/span&gt;&lt;span class=&quot;block min-h-[1lh] whitespace-pre&quot;&gt;app.post&lt;span class=&quot;text-on-band/60&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;text-band-code-string&quot;&gt;&amp;quot;/hooks/tasktohuman&amp;quot;&lt;/span&gt;&lt;span class=&quot;text-on-band/60&quot;&gt;,&lt;/span&gt; express.raw&lt;span class=&quot;text-on-band/60&quot;&gt;({&lt;/span&gt; &lt;span class=&quot;text-band-code-key&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;text-on-band/60&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;text-band-code-string&quot;&gt;&amp;quot;application/json&amp;quot;&lt;/span&gt; &lt;span class=&quot;text-on-band/60&quot;&gt;}),&lt;/span&gt; &lt;span class=&quot;text-band-code-keyword&quot;&gt;async&lt;/span&gt; &lt;span class=&quot;text-on-band/60&quot;&gt;(&lt;/span&gt;req&lt;span class=&quot;text-on-band/60&quot;&gt;,&lt;/span&gt; res&lt;span class=&quot;text-on-band/60&quot;&gt;)&lt;/span&gt; =&amp;gt; &lt;span class=&quot;text-on-band/60&quot;&gt;{&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;block min-h-[1lh] whitespace-pre&quot;&gt;  &lt;span class=&quot;text-band-code-keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;text-on-band/60&quot;&gt;(&lt;/span&gt;!verify&lt;span class=&quot;text-on-band/60&quot;&gt;(&lt;/span&gt;req.body&lt;span class=&quot;text-on-band/60&quot;&gt;,&lt;/span&gt; req.get&lt;span class=&quot;text-on-band/60&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;text-band-code-string&quot;&gt;&amp;quot;TTH-Signature&amp;quot;&lt;/span&gt;&lt;span class=&quot;text-on-band/60&quot;&gt;)&lt;/span&gt; ?? &lt;span class=&quot;text-band-code-string&quot;&gt;&amp;quot;&amp;quot;&lt;/span&gt;&lt;span class=&quot;text-on-band/60&quot;&gt;,&lt;/span&gt; SECRET&lt;span class=&quot;text-on-band/60&quot;&gt;))&lt;/span&gt; &lt;span class=&quot;text-band-code-keyword&quot;&gt;return&lt;/span&gt; res.sendStatus&lt;span class=&quot;text-on-band/60&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;text-band-code-number&quot;&gt;400&lt;/span&gt;&lt;span class=&quot;text-on-band/60&quot;&gt;);&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;block min-h-[1lh] whitespace-pre&quot;&gt;&lt;/span&gt;&lt;span class=&quot;block min-h-[1lh] whitespace-pre&quot;&gt;  &lt;span class=&quot;text-band-code-keyword&quot;&gt;const&lt;/span&gt; eventId = req.get&lt;span class=&quot;text-on-band/60&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;text-band-code-string&quot;&gt;&amp;quot;TTH-Event-Id&amp;quot;&lt;/span&gt;&lt;span class=&quot;text-on-band/60&quot;&gt;);&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;block min-h-[1lh] whitespace-pre&quot;&gt;  &lt;span class=&quot;text-band-code-keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;text-on-band/60&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;text-band-code-keyword&quot;&gt;await&lt;/span&gt; alreadyHandled&lt;span class=&quot;text-on-band/60&quot;&gt;(&lt;/span&gt;eventId&lt;span class=&quot;text-on-band/60&quot;&gt;))&lt;/span&gt; &lt;span class=&quot;text-band-code-keyword&quot;&gt;return&lt;/span&gt; res.sendStatus&lt;span class=&quot;text-on-band/60&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;text-band-code-number&quot;&gt;200&lt;/span&gt;&lt;span class=&quot;text-on-band/60&quot;&gt;);&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;block min-h-[1lh] whitespace-pre&quot;&gt;&lt;/span&gt;&lt;span class=&quot;block min-h-[1lh] whitespace-pre&quot;&gt;  &lt;span class=&quot;text-band-code-keyword&quot;&gt;const&lt;/span&gt; task = JSON.parse&lt;span class=&quot;text-on-band/60&quot;&gt;(&lt;/span&gt;req.body.toString&lt;span class=&quot;text-on-band/60&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;text-band-code-string&quot;&gt;&amp;quot;utf8&amp;quot;&lt;/span&gt;&lt;span class=&quot;text-on-band/60&quot;&gt;));&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;block min-h-[1lh] whitespace-pre&quot;&gt;  &lt;span class=&quot;text-band-code-keyword&quot;&gt;await&lt;/span&gt; handleDecision&lt;span class=&quot;text-on-band/60&quot;&gt;(&lt;/span&gt;task&lt;span class=&quot;text-on-band/60&quot;&gt;,&lt;/span&gt; eventId&lt;span class=&quot;text-on-band/60&quot;&gt;);&lt;/span&gt; &lt;span class=&quot;text-on-band/60 italic&quot;&gt;// marks eventId as handled in the same transaction&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;block min-h-[1lh] whitespace-pre&quot;&gt;  res.sendStatus&lt;span class=&quot;text-on-band/60&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;text-band-code-number&quot;&gt;204&lt;/span&gt;&lt;span class=&quot;text-on-band/60&quot;&gt;);&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;block min-h-[1lh] whitespace-pre&quot;&gt;&lt;span class=&quot;text-on-band/60&quot;&gt;});&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;block min-h-[1lh] whitespace-pre&quot;&gt;&lt;/span&gt;&lt;span class=&quot;block min-h-[1lh] whitespace-pre&quot;&gt;&lt;span class=&quot;text-band-code-keyword&quot;&gt;function&lt;/span&gt; verify&lt;span class=&quot;text-on-band/60&quot;&gt;(&lt;/span&gt;rawBody&lt;span class=&quot;text-on-band/60&quot;&gt;,&lt;/span&gt; header&lt;span class=&quot;text-on-band/60&quot;&gt;,&lt;/span&gt; secret&lt;span class=&quot;text-on-band/60&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;text-on-band/60&quot;&gt;{&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;block min-h-[1lh] whitespace-pre&quot;&gt;  &lt;span class=&quot;text-band-code-keyword&quot;&gt;const&lt;/span&gt; pairs = header.split&lt;span class=&quot;text-on-band/60&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;text-band-code-string&quot;&gt;&amp;quot;,&amp;quot;&lt;/span&gt;&lt;span class=&quot;text-on-band/60&quot;&gt;)&lt;/span&gt;.map&lt;span class=&quot;text-on-band/60&quot;&gt;((&lt;/span&gt;part&lt;span class=&quot;text-on-band/60&quot;&gt;)&lt;/span&gt; =&amp;gt; part.trim&lt;span class=&quot;text-on-band/60&quot;&gt;()&lt;/span&gt;.split&lt;span class=&quot;text-on-band/60&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;text-band-code-string&quot;&gt;&amp;quot;=&amp;quot;&lt;/span&gt;&lt;span class=&quot;text-on-band/60&quot;&gt;));&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;block min-h-[1lh] whitespace-pre&quot;&gt;  &lt;span class=&quot;text-band-code-keyword&quot;&gt;const&lt;/span&gt; t = pairs.find&lt;span class=&quot;text-on-band/60&quot;&gt;(([&lt;/span&gt;key&lt;span class=&quot;text-on-band/60&quot;&gt;])&lt;/span&gt; =&amp;gt; key === &lt;span class=&quot;text-band-code-string&quot;&gt;&amp;quot;t&amp;quot;&lt;/span&gt;&lt;span class=&quot;text-on-band/60&quot;&gt;)&lt;/span&gt;?.&lt;span class=&quot;text-on-band/60&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;text-band-code-number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;text-on-band/60&quot;&gt;];&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;block min-h-[1lh] whitespace-pre&quot;&gt;  &lt;span class=&quot;text-band-code-keyword&quot;&gt;const&lt;/span&gt; signatures = pairs.filter&lt;span class=&quot;text-on-band/60&quot;&gt;(([&lt;/span&gt;key&lt;span class=&quot;text-on-band/60&quot;&gt;])&lt;/span&gt; =&amp;gt; key === &lt;span class=&quot;text-band-code-string&quot;&gt;&amp;quot;v1&amp;quot;&lt;/span&gt;&lt;span class=&quot;text-on-band/60&quot;&gt;)&lt;/span&gt;.map&lt;span class=&quot;text-on-band/60&quot;&gt;(([,&lt;/span&gt; value&lt;span class=&quot;text-on-band/60&quot;&gt;])&lt;/span&gt; =&amp;gt; value&lt;span class=&quot;text-on-band/60&quot;&gt;);&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;block min-h-[1lh] whitespace-pre&quot;&gt;  &lt;span class=&quot;text-band-code-keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;text-on-band/60&quot;&gt;(&lt;/span&gt;!/^\d+$/.test&lt;span class=&quot;text-on-band/60&quot;&gt;(&lt;/span&gt;t ?? &lt;span class=&quot;text-band-code-string&quot;&gt;&amp;quot;&amp;quot;&lt;/span&gt;&lt;span class=&quot;text-on-band/60&quot;&gt;)&lt;/span&gt; || signatures.length === &lt;span class=&quot;text-band-code-number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;text-on-band/60&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;text-band-code-keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;text-band-code-number&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;text-on-band/60&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;block min-h-[1lh] whitespace-pre&quot;&gt;  &lt;span class=&quot;text-band-code-keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;text-on-band/60&quot;&gt;(&lt;/span&gt;Math.abs&lt;span class=&quot;text-on-band/60&quot;&gt;(&lt;/span&gt;Date.now&lt;span class=&quot;text-on-band/60&quot;&gt;()&lt;/span&gt; / &lt;span class=&quot;text-band-code-number&quot;&gt;1000&lt;/span&gt; - Number&lt;span class=&quot;text-on-band/60&quot;&gt;(&lt;/span&gt;t&lt;span class=&quot;text-on-band/60&quot;&gt;))&lt;/span&gt; &amp;gt; TOLERANCE_SECONDS&lt;span class=&quot;text-on-band/60&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;text-band-code-keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;text-band-code-number&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;text-on-band/60&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;block min-h-[1lh] whitespace-pre&quot;&gt;&lt;/span&gt;&lt;span class=&quot;block min-h-[1lh] whitespace-pre&quot;&gt;  &lt;span class=&quot;text-band-code-keyword&quot;&gt;const&lt;/span&gt; expected = crypto.createHmac&lt;span class=&quot;text-on-band/60&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;text-band-code-string&quot;&gt;&amp;quot;sha256&amp;quot;&lt;/span&gt;&lt;span class=&quot;text-on-band/60&quot;&gt;,&lt;/span&gt; secret&lt;span class=&quot;text-on-band/60&quot;&gt;)&lt;/span&gt;.update&lt;span class=&quot;text-on-band/60&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;text-band-code-string&quot;&gt;`${t}.`&lt;/span&gt;&lt;span class=&quot;text-on-band/60&quot;&gt;)&lt;/span&gt;.update&lt;span class=&quot;text-on-band/60&quot;&gt;(&lt;/span&gt;rawBody&lt;span class=&quot;text-on-band/60&quot;&gt;)&lt;/span&gt;.digest&lt;span class=&quot;text-on-band/60&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;text-band-code-string&quot;&gt;&amp;quot;hex&amp;quot;&lt;/span&gt;&lt;span class=&quot;text-on-band/60&quot;&gt;);&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;block min-h-[1lh] whitespace-pre&quot;&gt;  &lt;span class=&quot;text-band-code-keyword&quot;&gt;return&lt;/span&gt; signatures.some&lt;span class=&quot;text-on-band/60&quot;&gt;(&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;block min-h-[1lh] whitespace-pre&quot;&gt;    &lt;span class=&quot;text-on-band/60&quot;&gt;(&lt;/span&gt;v&lt;span class=&quot;text-on-band/60&quot;&gt;)&lt;/span&gt; =&amp;gt; v.length === expected.length &amp;amp;&amp;amp; crypto.timingSafeEqual&lt;span class=&quot;text-on-band/60&quot;&gt;(&lt;/span&gt;Buffer.&lt;span class=&quot;text-band-code-keyword&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;text-on-band/60&quot;&gt;(&lt;/span&gt;v&lt;span class=&quot;text-on-band/60&quot;&gt;),&lt;/span&gt; Buffer.&lt;span class=&quot;text-band-code-keyword&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;text-on-band/60&quot;&gt;(&lt;/span&gt;expected&lt;span class=&quot;text-on-band/60&quot;&gt;)),&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;block min-h-[1lh] whitespace-pre&quot;&gt;  &lt;span class=&quot;text-on-band/60&quot;&gt;);&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;block min-h-[1lh] whitespace-pre&quot;&gt;&lt;span class=&quot;text-on-band/60&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;&lt;h2 id=&quot;a-receiver-in-python&quot;&gt;A receiver in Python&lt;/h2&gt;&lt;figure class=&quot;on-band code-figure overflow-hidden rounded-card border border-band-edge bg-band text-on-band&quot;&gt;&lt;div class=&quot;flex min-h-10 items-center justify-between gap-3 border-b border-band-edge py-1 pr-2 pl-4&quot;&gt;&lt;figcaption class=&quot;text-caption font-medium text-on-band/70&quot;&gt;Python&lt;/figcaption&gt;&lt;/div&gt;&lt;pre class=&quot;overflow-x-auto px-4 py-3.5 text-table leading-6 focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-signal&quot;&gt;&lt;code class=&quot;block font-mono [font-variant-ligatures:none]&quot;&gt;&lt;span class=&quot;block min-h-[1lh] whitespace-pre&quot;&gt;&lt;span class=&quot;text-band-code-keyword&quot;&gt;import&lt;/span&gt; hashlib&lt;/span&gt;&lt;span class=&quot;block min-h-[1lh] whitespace-pre&quot;&gt;&lt;span class=&quot;text-band-code-keyword&quot;&gt;import&lt;/span&gt; hmac&lt;/span&gt;&lt;span class=&quot;block min-h-[1lh] whitespace-pre&quot;&gt;&lt;span class=&quot;text-band-code-keyword&quot;&gt;import&lt;/span&gt; json&lt;/span&gt;&lt;span class=&quot;block min-h-[1lh] whitespace-pre&quot;&gt;&lt;span class=&quot;text-band-code-keyword&quot;&gt;import&lt;/span&gt; os&lt;/span&gt;&lt;span class=&quot;block min-h-[1lh] whitespace-pre&quot;&gt;&lt;span class=&quot;text-band-code-keyword&quot;&gt;import&lt;/span&gt; time&lt;/span&gt;&lt;span class=&quot;block min-h-[1lh] whitespace-pre&quot;&gt;&lt;/span&gt;&lt;span class=&quot;block min-h-[1lh] whitespace-pre&quot;&gt;&lt;span class=&quot;text-band-code-keyword&quot;&gt;from&lt;/span&gt; flask &lt;span class=&quot;text-band-code-keyword&quot;&gt;import&lt;/span&gt; Flask&lt;span class=&quot;text-on-band/60&quot;&gt;,&lt;/span&gt; abort&lt;span class=&quot;text-on-band/60&quot;&gt;,&lt;/span&gt; request&lt;/span&gt;&lt;span class=&quot;block min-h-[1lh] whitespace-pre&quot;&gt;&lt;/span&gt;&lt;span class=&quot;block min-h-[1lh] whitespace-pre&quot;&gt;app = Flask&lt;span class=&quot;text-on-band/60&quot;&gt;(&lt;/span&gt;__name__&lt;span class=&quot;text-on-band/60&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;block min-h-[1lh] whitespace-pre&quot;&gt;SECRET = os.environ&lt;span class=&quot;text-on-band/60&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;text-band-code-string&quot;&gt;&amp;quot;TTH_SIGNING_SECRET&amp;quot;&lt;/span&gt;&lt;span class=&quot;text-on-band/60&quot;&gt;]&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;block min-h-[1lh] whitespace-pre&quot;&gt;TOLERANCE_SECONDS = &lt;span class=&quot;text-band-code-number&quot;&gt;300&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;block min-h-[1lh] whitespace-pre&quot;&gt;&lt;/span&gt;&lt;span class=&quot;block min-h-[1lh] whitespace-pre&quot;&gt;&lt;/span&gt;&lt;span class=&quot;block min-h-[1lh] whitespace-pre&quot;&gt;@app.post&lt;span class=&quot;text-on-band/60&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;text-band-code-string&quot;&gt;&amp;quot;/hooks/tasktohuman&amp;quot;&lt;/span&gt;&lt;span class=&quot;text-on-band/60&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;block min-h-[1lh] whitespace-pre&quot;&gt;&lt;span class=&quot;text-band-code-keyword&quot;&gt;def&lt;/span&gt; callback&lt;span class=&quot;text-on-band/60&quot;&gt;():&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;block min-h-[1lh] whitespace-pre&quot;&gt;    raw = request.get_data&lt;span class=&quot;text-on-band/60&quot;&gt;()&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;block min-h-[1lh] whitespace-pre&quot;&gt;    &lt;span class=&quot;text-band-code-keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;text-band-code-keyword&quot;&gt;not&lt;/span&gt; verify&lt;span class=&quot;text-on-band/60&quot;&gt;(&lt;/span&gt;raw&lt;span class=&quot;text-on-band/60&quot;&gt;,&lt;/span&gt; request.headers.get&lt;span class=&quot;text-on-band/60&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;text-band-code-string&quot;&gt;&amp;quot;TTH-Signature&amp;quot;&lt;/span&gt;&lt;span class=&quot;text-on-band/60&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;text-band-code-string&quot;&gt;&amp;quot;&amp;quot;&lt;/span&gt;&lt;span class=&quot;text-on-band/60&quot;&gt;),&lt;/span&gt; SECRET&lt;span class=&quot;text-on-band/60&quot;&gt;):&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;block min-h-[1lh] whitespace-pre&quot;&gt;        abort&lt;span class=&quot;text-on-band/60&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;text-band-code-number&quot;&gt;400&lt;/span&gt;&lt;span class=&quot;text-on-band/60&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;block min-h-[1lh] whitespace-pre&quot;&gt;&lt;/span&gt;&lt;span class=&quot;block min-h-[1lh] whitespace-pre&quot;&gt;    event_id = request.headers.get&lt;span class=&quot;text-on-band/60&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;text-band-code-string&quot;&gt;&amp;quot;TTH-Event-Id&amp;quot;&lt;/span&gt;&lt;span class=&quot;text-on-band/60&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;block min-h-[1lh] whitespace-pre&quot;&gt;    &lt;span class=&quot;text-band-code-keyword&quot;&gt;if&lt;/span&gt; already_handled&lt;span class=&quot;text-on-band/60&quot;&gt;(&lt;/span&gt;event_id&lt;span class=&quot;text-on-band/60&quot;&gt;):&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;block min-h-[1lh] whitespace-pre&quot;&gt;        &lt;span class=&quot;text-band-code-keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;text-band-code-string&quot;&gt;&amp;quot;&amp;quot;&lt;/span&gt;&lt;span class=&quot;text-on-band/60&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;text-band-code-number&quot;&gt;200&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;block min-h-[1lh] whitespace-pre&quot;&gt;&lt;/span&gt;&lt;span class=&quot;block min-h-[1lh] whitespace-pre&quot;&gt;    task = json.loads&lt;span class=&quot;text-on-band/60&quot;&gt;(&lt;/span&gt;raw&lt;span class=&quot;text-on-band/60&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;block min-h-[1lh] whitespace-pre&quot;&gt;    handle_decision&lt;span class=&quot;text-on-band/60&quot;&gt;(&lt;/span&gt;task&lt;span class=&quot;text-on-band/60&quot;&gt;,&lt;/span&gt; event_id&lt;span class=&quot;text-on-band/60&quot;&gt;)&lt;/span&gt;  &lt;span class=&quot;text-on-band/60 italic&quot;&gt;# marks event_id as handled in the same transaction&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;block min-h-[1lh] whitespace-pre&quot;&gt;    &lt;span class=&quot;text-band-code-keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;text-band-code-string&quot;&gt;&amp;quot;&amp;quot;&lt;/span&gt;&lt;span class=&quot;text-on-band/60&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;text-band-code-number&quot;&gt;204&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;block min-h-[1lh] whitespace-pre&quot;&gt;&lt;/span&gt;&lt;span class=&quot;block min-h-[1lh] whitespace-pre&quot;&gt;&lt;/span&gt;&lt;span class=&quot;block min-h-[1lh] whitespace-pre&quot;&gt;&lt;span class=&quot;text-band-code-keyword&quot;&gt;def&lt;/span&gt; verify&lt;span class=&quot;text-on-band/60&quot;&gt;(&lt;/span&gt;raw_body&lt;span class=&quot;text-on-band/60&quot;&gt;:&lt;/span&gt; bytes&lt;span class=&quot;text-on-band/60&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;text-band-code-key&quot;&gt;header&lt;/span&gt;&lt;span class=&quot;text-on-band/60&quot;&gt;:&lt;/span&gt; str&lt;span class=&quot;text-on-band/60&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;text-band-code-key&quot;&gt;secret&lt;/span&gt;&lt;span class=&quot;text-on-band/60&quot;&gt;:&lt;/span&gt; str&lt;span class=&quot;text-on-band/60&quot;&gt;)&lt;/span&gt; -&amp;gt; bool&lt;span class=&quot;text-on-band/60&quot;&gt;:&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;block min-h-[1lh] whitespace-pre&quot;&gt;    pairs = &lt;span class=&quot;text-on-band/60&quot;&gt;[&lt;/span&gt;part.strip&lt;span class=&quot;text-on-band/60&quot;&gt;()&lt;/span&gt;.split&lt;span class=&quot;text-on-band/60&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;text-band-code-string&quot;&gt;&amp;quot;=&amp;quot;&lt;/span&gt;&lt;span class=&quot;text-on-band/60&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;text-band-code-number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;text-on-band/60&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;text-band-code-keyword&quot;&gt;for&lt;/span&gt; part &lt;span class=&quot;text-band-code-keyword&quot;&gt;in&lt;/span&gt; header.split&lt;span class=&quot;text-on-band/60&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;text-band-code-string&quot;&gt;&amp;quot;,&amp;quot;&lt;/span&gt;&lt;span class=&quot;text-on-band/60&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;text-band-code-keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;text-band-code-string&quot;&gt;&amp;quot;=&amp;quot;&lt;/span&gt; &lt;span class=&quot;text-band-code-keyword&quot;&gt;in&lt;/span&gt; part&lt;span class=&quot;text-on-band/60&quot;&gt;]&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;block min-h-[1lh] whitespace-pre&quot;&gt;    t = next&lt;span class=&quot;text-on-band/60&quot;&gt;((&lt;/span&gt;value &lt;span class=&quot;text-band-code-keyword&quot;&gt;for&lt;/span&gt; key&lt;span class=&quot;text-on-band/60&quot;&gt;,&lt;/span&gt; value &lt;span class=&quot;text-band-code-keyword&quot;&gt;in&lt;/span&gt; pairs &lt;span class=&quot;text-band-code-keyword&quot;&gt;if&lt;/span&gt; key == &lt;span class=&quot;text-band-code-string&quot;&gt;&amp;quot;t&amp;quot;&lt;/span&gt;&lt;span class=&quot;text-on-band/60&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;text-band-code-string&quot;&gt;&amp;quot;&amp;quot;&lt;/span&gt;&lt;span class=&quot;text-on-band/60&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;block min-h-[1lh] whitespace-pre&quot;&gt;    signatures = &lt;span class=&quot;text-on-band/60&quot;&gt;[&lt;/span&gt;value &lt;span class=&quot;text-band-code-keyword&quot;&gt;for&lt;/span&gt; key&lt;span class=&quot;text-on-band/60&quot;&gt;,&lt;/span&gt; value &lt;span class=&quot;text-band-code-keyword&quot;&gt;in&lt;/span&gt; pairs &lt;span class=&quot;text-band-code-keyword&quot;&gt;if&lt;/span&gt; key == &lt;span class=&quot;text-band-code-string&quot;&gt;&amp;quot;v1&amp;quot;&lt;/span&gt;&lt;span class=&quot;text-on-band/60&quot;&gt;]&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;block min-h-[1lh] whitespace-pre&quot;&gt;    &lt;span class=&quot;text-band-code-keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;text-band-code-keyword&quot;&gt;not&lt;/span&gt; t.isdigit&lt;span class=&quot;text-on-band/60&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;text-band-code-keyword&quot;&gt;or&lt;/span&gt; &lt;span class=&quot;text-band-code-keyword&quot;&gt;not&lt;/span&gt; signatures&lt;span class=&quot;text-on-band/60&quot;&gt;:&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;block min-h-[1lh] whitespace-pre&quot;&gt;        &lt;span class=&quot;text-band-code-keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;text-band-code-number&quot;&gt;False&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;block min-h-[1lh] whitespace-pre&quot;&gt;    &lt;span class=&quot;text-band-code-keyword&quot;&gt;if&lt;/span&gt; abs&lt;span class=&quot;text-on-band/60&quot;&gt;(&lt;/span&gt;time.time&lt;span class=&quot;text-on-band/60&quot;&gt;()&lt;/span&gt; - int&lt;span class=&quot;text-on-band/60&quot;&gt;(&lt;/span&gt;t&lt;span class=&quot;text-on-band/60&quot;&gt;))&lt;/span&gt; &amp;gt; TOLERANCE_SECONDS&lt;span class=&quot;text-on-band/60&quot;&gt;:&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;block min-h-[1lh] whitespace-pre&quot;&gt;        &lt;span class=&quot;text-band-code-keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;text-band-code-number&quot;&gt;False&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;block min-h-[1lh] whitespace-pre&quot;&gt;&lt;/span&gt;&lt;span class=&quot;block min-h-[1lh] whitespace-pre&quot;&gt;    expected = hmac.&lt;span class=&quot;text-band-code-keyword&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;text-on-band/60&quot;&gt;(&lt;/span&gt;secret.encode&lt;span class=&quot;text-on-band/60&quot;&gt;(),&lt;/span&gt; t.encode&lt;span class=&quot;text-on-band/60&quot;&gt;()&lt;/span&gt; + b&lt;span class=&quot;text-band-code-string&quot;&gt;&amp;quot;.&amp;quot;&lt;/span&gt; + raw_body&lt;span class=&quot;text-on-band/60&quot;&gt;,&lt;/span&gt; hashlib.sha256&lt;span class=&quot;text-on-band/60&quot;&gt;)&lt;/span&gt;.hexdigest&lt;span class=&quot;text-on-band/60&quot;&gt;()&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;block min-h-[1lh] whitespace-pre&quot;&gt;    &lt;span class=&quot;text-band-code-keyword&quot;&gt;return&lt;/span&gt; any&lt;span class=&quot;text-on-band/60&quot;&gt;(&lt;/span&gt;hmac.compare_digest&lt;span class=&quot;text-on-band/60&quot;&gt;(&lt;/span&gt;v&lt;span class=&quot;text-on-band/60&quot;&gt;,&lt;/span&gt; expected&lt;span class=&quot;text-on-band/60&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;text-band-code-keyword&quot;&gt;for&lt;/span&gt; v &lt;span class=&quot;text-band-code-keyword&quot;&gt;in&lt;/span&gt; signatures&lt;span class=&quot;text-on-band/60&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;&lt;h2 id=&quot;a-few-more-habits&quot;&gt;A few more habits&lt;/h2&gt;&lt;ul&gt;&lt;li&gt;&lt;strong&gt;Answer quickly.&lt;/strong&gt; Verify, record the event, and return a &lt;code&gt;2xx&lt;/code&gt; within a few seconds. Do slow work in a background job. A receiver that takes too long gets retries, and retries mean more duplicates.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;Return an error for bad signatures, and log them.&lt;/strong&gt; A burst of failures means a misconfigured secret or someone probing your endpoint. Don&amp;#x27;t log the secret or the full signature.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;Keep the secret out of code.&lt;/strong&gt; Load it from your secret store or environment, and rotate it when people leave or a log is exposed.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;Use HTTPS only.&lt;/strong&gt; The signature protects integrity, not confidentiality. TLS keeps the body private on the way.&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;The full callback format, header list and retry schedule for TaskToHuman are in the &lt;a href=&quot;https://docs.tasktohuman.com/callbacks&quot; rel=&quot;noopener&quot;&gt;developer docs&lt;/a&gt;. In TypeScript and Python, the official &lt;a href=&quot;https://docs.tasktohuman.com/sdks&quot; rel=&quot;noopener&quot;&gt;SDKs&lt;/a&gt; do this check for you: &lt;code&gt;verifyCallback&lt;/code&gt; in &lt;code&gt;@tasktohuman/sdk&lt;/code&gt; and &lt;code&gt;verify_callback&lt;/code&gt; in &lt;code&gt;tasktohuman&lt;/code&gt;.&lt;/p&gt;&lt;/div&gt;</content>
  </entry>
  <entry>
    <title>What human-in-the-loop means for automations and AI agents</title>
    <id>https://tasktohuman.com/blog/what-human-in-the-loop-means</id>
    <link rel="alternate" type="text/html" href="https://tasktohuman.com/blog/what-human-in-the-loop-means"/>
    <published>2026-11-15T00:00:00Z</published>
    <updated>2026-11-15T00:00:00Z</updated>
    <category term="agents"/>
    <category term="approvals"/>
    <summary>Human-in-the-loop is not a person watching every step. It is a deliberate pause in front of the few actions that are expensive to get wrong, with a clear question, a named person and an answer your code can trust.</summary>
    <content type="html">&lt;div class=&quot;prose-post&quot;&gt;&lt;p&gt;&amp;quot;Human-in-the-loop&amp;quot; gets used for almost anything: labelling training data, reviewing a model&amp;#x27;s output, a person approving a refund. For teams that run automations and AI agents in production, it has a narrower and more useful meaning: &lt;strong&gt;a point in an automated process where the process stops, a specific person makes a decision, and the process continues based on that decision.&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;That definition has three parts, and each one matters.&lt;/p&gt;&lt;h2 id=&quot;the-process-stops&quot;&gt;The process stops&lt;/h2&gt;&lt;p&gt;The automation does not carry on while someone &amp;quot;keeps an eye on it&amp;quot;. It reaches a step it is not allowed to take alone, and it waits. Nothing irreversible happens until the answer arrives.&lt;/p&gt;&lt;p&gt;This sounds obvious, but many setups get it wrong. A notification that says &amp;quot;the agent just refunded €400, check it&amp;quot; is not human-in-the-loop. It is human-after-the-fact. Monitoring and alerts are useful, but they only help with actions you can undo. For actions you can&amp;#x27;t undo, such as money leaving, data being deleted, a message reaching a customer or a release going to production, the check has to come before the action.&lt;/p&gt;&lt;h2 id=&quot;a-specific-person-decides&quot;&gt;A specific person decides&lt;/h2&gt;&lt;p&gt;&amp;quot;Someone on the team will look at it&amp;quot; is how approvals get lost. A loop needs an owner: the one person who is asked first, and who knows the question is theirs. It also needs a plan for when that person doesn&amp;#x27;t answer: a reminder, then a backup, then a deadline after which something defined happens.&lt;/p&gt;&lt;p&gt;The person also needs enough context to decide in seconds. A good request answers three questions on one screen:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;strong&gt;What exactly will happen?&lt;/strong&gt; &amp;quot;Refund €249 to order #4821&amp;quot;, not &amp;quot;Approve request 7731&amp;quot;.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;Why is this being asked?&lt;/strong&gt; The rule that triggered it, or the agent&amp;#x27;s reasoning: &amp;quot;Second claim from this customer this month.&amp;quot;&lt;/li&gt;&lt;li&gt;&lt;strong&gt;What can I do?&lt;/strong&gt; Approve, reject, or correct a value and approve. A comment field for anything that doesn&amp;#x27;t fit.&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;If the person has to open three other tools to understand the request, they will postpone it, and the loop stalls.&lt;/p&gt;&lt;h2 id=&quot;the-process-continues-based-on-the-decision&quot;&gt;The process continues based on the decision&lt;/h2&gt;&lt;p&gt;The answer has to get back into the automation reliably. That means a machine-readable result (approved, rejected, edited, expired), delivered to the waiting process in a way it can verify, and handled exactly once.&lt;/p&gt;&lt;p&gt;This is the part that is easy to underestimate. Real systems retry. Networks time out. A callback can arrive twice, or not at all. Your process needs to know the decision really came from the approval system, not from someone who guessed the URL, and it needs a defined path when no decision comes.&lt;/p&gt;&lt;h2 id=&quot;why-agents-make-this-more-pressing&quot;&gt;Why agents make this more pressing&lt;/h2&gt;&lt;p&gt;Rule-based automations are predictable: if the refund is above €200, ask. AI agents are different in two ways.&lt;/p&gt;&lt;p&gt;First, they act on judgement, and their judgement is sometimes confidently wrong. An agent that drafts a reply, decides a customer deserves a credit and issues it can make a mistake no rule anticipated.&lt;/p&gt;&lt;p&gt;Second, they are good at preparing work. An agent can gather the order history, draft the reply, propose the amount and explain why. That makes the human&amp;#x27;s job small: read a clear proposal and say yes, no or &amp;quot;yes, but €25 instead of €40&amp;quot;.&lt;/p&gt;&lt;p&gt;So the useful pattern for agents is: &lt;strong&gt;let the agent do the preparation, and keep the final, irreversible step behind a person.&lt;/strong&gt; The agent calls a tool that creates an approval request with its proposal and reasoning, then waits. If the person approves, the agent continues with the approved, possibly edited values. If they reject, the action never runs, and the agent can tell the user why.&lt;/p&gt;&lt;p&gt;A sensible split looks like this:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Reading data, searching, drafting and summarising: the agent does it on its own.&lt;/li&gt;&lt;li&gt;Actions with a small, bounded cost: the agent does it, within a limit you set.&lt;/li&gt;&lt;li&gt;Actions above that limit, or that can&amp;#x27;t be undone: the agent proposes, a person approves.&lt;/li&gt;&lt;/ul&gt;&lt;h2 id=&quot;where-to-put-the-loop&quot;&gt;Where to put the loop&lt;/h2&gt;&lt;p&gt;You don&amp;#x27;t want a person in front of everything. That just moves the bottleneck and teaches people to click &amp;quot;approve&amp;quot; without reading. Put the loop where three things are true:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;strong&gt;The action is hard or impossible to undo.&lt;/strong&gt; Payments, deletions, messages to customers, production changes.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;A wrong action costs more than a short wait.&lt;/strong&gt; A refund that waits an hour is fine; a fraudulent payout is not.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;A person can actually judge it quickly.&lt;/strong&gt; If the decision needs an hour of research, it is a task for a ticket queue, not an approval.&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;Then make the loop cheap to answer: one clear question, the facts on one screen, an answer from any device, and no account to create for an occasional approver.&lt;/p&gt;&lt;h2 id=&quot;what-it-looks-like-in-practice&quot;&gt;What it looks like in practice&lt;/h2&gt;&lt;p&gt;In practice, a human-in-the-loop step is a small contract between your code and a person:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Your code sends a request with the question, the facts, who should answer and how long it may wait.&lt;/li&gt;&lt;li&gt;The person is reached where they will see it, reminded if they don&amp;#x27;t answer, and replaced by a backup if they still don&amp;#x27;t.&lt;/li&gt;&lt;li&gt;The decision comes back to your code signed, with who decided, when and any comment or corrected values.&lt;/li&gt;&lt;li&gt;If nobody decides in time, your code is told that too, and follows the path you defined.&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;That is what &lt;a href=&quot;https://tasktohuman.com/&quot;&gt;TaskToHuman&lt;/a&gt; does: your code or workflow creates a task with one API call or a webhook, and gets the decision back as a signed callback. Whether you use it or build your own, the principles are the same. Pause before the irreversible step, ask one named person a clear question, and make sure the answer gets back to your code exactly once.&lt;/p&gt;&lt;/div&gt;</content>
  </entry>
</feed>
