<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Daniel Neata</title>
    <description>The latest articles on DEV Community by Daniel Neata (@danielmason77).</description>
    <link>https://dev.to/danielmason77</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4184538%2F1ba4abb0-5ae5-4bcb-b8e2-bbe30bec3f44.png</url>
      <title>DEV Community: Daniel Neata</title>
      <link>https://dev.to/danielmason77</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/danielmason77"/>
    <language>en</language>
    <item>
      <title>Build a Crash-Safe Scheduled Publisher with Leases and Reconciliation</title>
      <dc:creator>Daniel Neata</dc:creator>
      <pubDate>Thu, 19 Nov 2026 19:58:27 +0000</pubDate>
      <link>https://dev.to/danielmason77/build-a-crash-safe-scheduled-publisher-with-leases-and-reconciliation-1n48</link>
      <guid>https://dev.to/danielmason77/build-a-crash-safe-scheduled-publisher-with-leases-and-reconciliation-1n48</guid>
      <description>&lt;h1&gt;
  
  
  Build a Crash-Safe Scheduled Publisher with Leases and Reconciliation
&lt;/h1&gt;

&lt;p&gt;A scheduler that runs once is easy. A scheduler that can run twice, overlap with itself, lose a network response, and still avoid duplicate public posts needs a more deliberate design.&lt;/p&gt;

&lt;p&gt;This guide builds a small Node.js publishing worker around three ideas: stable delivery identities, expiring leases, and remote reconciliation. The examples use generic adapters so that the same control flow can be applied to any publishing API that can list or retrieve posts. They are intentionally focused on delivery safety rather than text generation.&lt;/p&gt;

&lt;h2&gt;
  
  
  Start with a durable delivery identity
&lt;/h2&gt;

&lt;p&gt;Do not use a workflow run number as the identity of a post. Retries receive new run numbers, so the same intended publication would appear new.&lt;/p&gt;

&lt;p&gt;Instead, derive a stable key from the reviewed content item and its destination:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;createHash&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s2"&gt;"node:crypto"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;deliveryKey&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;contentId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;platform&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;accountId&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;createHash&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"sha256"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;update&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sb"&gt;`${contentId}\0${platform}\0${accountId}`&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;digest&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"hex"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Store a unique record for that key. A useful record has a state, lease owner, lease expiry, external ID, public URL and last error. The database must enforce the unique key; checking in application code is not enough when two workers start together.&lt;/p&gt;

&lt;h2&gt;
  
  
  Claim one item with an expiring lease
&lt;/h2&gt;

&lt;p&gt;A worker should claim an approved delivery atomically. In SQL, that can be an update whose condition proves the item is still available:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;UPDATE&lt;/span&gt; &lt;span class="n"&gt;deliveries&lt;/span&gt;
&lt;span class="k"&gt;SET&lt;/span&gt; &lt;span class="n"&gt;state&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'claimed'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;lease_owner&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="n"&gt;worker_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;lease_until&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="n"&gt;lease_until&lt;/span&gt;
&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;delivery_key&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="n"&gt;delivery_key&lt;/span&gt;
  &lt;span class="k"&gt;AND&lt;/span&gt; &lt;span class="n"&gt;state&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'approved'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Continue only when exactly one row changed. A second worker attempting the same claim receives zero changed rows and skips it.&lt;/p&gt;

&lt;p&gt;The lease prevents a crashed process from blocking the item forever. However, lease expiry is not permission to publish again. The crashed worker may have completed the remote write before dying. An expired claim must enter reconciliation first.&lt;/p&gt;

&lt;h2&gt;
  
  
  Record stages, not one success flag
&lt;/h2&gt;

&lt;p&gt;Model the important states explicitly:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;approved&lt;/code&gt;: editorially reviewed and eligible.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;claimed&lt;/code&gt;: owned temporarily by one worker.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;publishing&lt;/code&gt;: the remote request may have been sent.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;published&lt;/code&gt;: confirmed by an external ID.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;uncertain&lt;/code&gt;: the request outcome is unknown.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;rejected&lt;/code&gt;: the remote service definitively refused it.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This distinction changes retry behaviour. A validation error before the request can return to an editorial or repair queue. A timeout after bytes were sent becomes uncertain and must not trigger an immediate second POST.&lt;/p&gt;

&lt;h2&gt;
  
  
  Separate the remote adapter from orchestration
&lt;/h2&gt;

&lt;p&gt;Give every platform adapter the same narrow contract:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;PublisherAdapter&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="nf"&gt;create&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;delivery&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="nf"&gt;getByExternalId&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;externalId&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="nf"&gt;findByDeliveryKey&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;deliveryKey&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;options&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The create method should return the platform's real identifier and, when available, its public URL. The lookup must be scoped to the intended account. If it scans history, it must paginate until it either finds a match or reaches a documented boundary.&lt;/p&gt;

&lt;p&gt;A result such as &lt;code&gt;{complete: false}&lt;/code&gt; is important. Authentication failure, a truncated page sequence, or a rate limit means the worker did not prove absence.&lt;/p&gt;

&lt;h2&gt;
  
  
  Reconcile before any retry
&lt;/h2&gt;

&lt;p&gt;The recovery path should prefer the strongest available evidence:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;reconcile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;delivery&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;adapter&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;store&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;delivery&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;externalId&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;post&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;adapter&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getByExternalId&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;delivery&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;externalId&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;post&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;store&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;confirmPublished&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;delivery&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;post&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;scan&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;adapter&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;findByDeliveryKey&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;delivery&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;deliveryKey&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;maxAgeHours&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;48&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;paginate&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;scan&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;complete&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;store&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;markUncertain&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;delivery&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"remote history incomplete"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;scan&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;match&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;store&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;confirmPublished&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;delivery&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;scan&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;match&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;store&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;returnForReviewedRetry&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;delivery&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The method deliberately does not publish. It establishes whether the first attempt already produced a remote object. Only a confirmed complete search with no match makes the delivery eligible for a reviewed retry.&lt;/p&gt;

&lt;p&gt;If the platform supports idempotency keys for create operations, use the stable delivery key according to that API's documented scope and expiry. Do not assume that adding a custom HTTP header provides idempotency.&lt;/p&gt;

&lt;h2&gt;
  
  
  Make scheduled runs safe to overlap
&lt;/h2&gt;

&lt;p&gt;GitHub Actions can reduce overlap with a concurrency group:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;concurrency&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;group&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;scheduled-publisher&lt;/span&gt;
  &lt;span class="na"&gt;cancel-in-progress&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That is useful but insufficient as the only guard. A manually dispatched run, another repository, or an interrupted runner may bypass the assumption. The durable claim remains the authority.&lt;/p&gt;

&lt;p&gt;Schedules can also be delayed. Select work from explicit eligibility rules, not from an exact minute comparison. If the business rule allows one item per day, use a destination-local date key and check confirmed remote history before writing. Do not publish several missed slots merely because the scheduler woke up late.&lt;/p&gt;

&lt;h2&gt;
  
  
  Preserve evidence in the right order
&lt;/h2&gt;

&lt;p&gt;After a successful create response, save the external ID before performing optional work such as analytics tagging or a dashboard refresh. If the database update fails, write non-secret recovery evidence to durable logs.&lt;/p&gt;

&lt;p&gt;Never invent a public URL from an assumed pattern. Some APIs return only an ID; in that case, query the resource or account feed. Report the ID as confirmed and the public URL as pending verification.&lt;/p&gt;

&lt;p&gt;A workflow exit code describes job health. A publication receipt requires a remote ID. Keep those two facts separate in summaries.&lt;/p&gt;

&lt;h2&gt;
  
  
  Test failures at every boundary
&lt;/h2&gt;

&lt;p&gt;A useful test adapter counts write calls and can simulate failure after the remote object is created:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;adapter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;FakeAdapter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;createThenThrow&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"socket closed"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;runOnce&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;recoverExpiredClaims&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nf"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;adapter&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;createCalls&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toBe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nf"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;store&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;delivery&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toBe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"published"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Also test two concurrent claims, an expired lease with no remote match, an incomplete paginated scan, a definitive rejection, and a successful write followed by failed local persistence. Assert the number of remote writes, not merely the worker's final exit status.&lt;/p&gt;

&lt;h2&gt;
  
  
  Operational checklist
&lt;/h2&gt;

&lt;p&gt;Before enabling a schedule:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Confirm that only editorially approved content can be selected.&lt;/li&gt;
&lt;li&gt;Enforce a unique delivery key in durable storage.&lt;/li&gt;
&lt;li&gt;Verify that two concurrent workers produce at most one remote write.&lt;/li&gt;
&lt;li&gt;Confirm that dry run performs no claim or create request.&lt;/li&gt;
&lt;li&gt;Test a create-then-timeout response and reconcile it without duplication.&lt;/li&gt;
&lt;li&gt;Verify paginated history for the correct destination account.&lt;/li&gt;
&lt;li&gt;Require a real external ID before reporting a publication.&lt;/li&gt;
&lt;li&gt;Keep tokens out of logs and give them only the permissions required.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;A reliable publisher is not one that never fails. It is one that can explain what happened, preserve uncertainty, and recover without turning an infrastructure failure into a duplicate public post.&lt;/p&gt;

&lt;h2&gt;
  
  
  Shop Daniel Mason
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Reversible belt: &lt;a href="https://danielmason.uk/products/daniel-mason%E2%84%A2-classic-reversible-belt-black-brown?utm_source=dev&amp;amp;utm_medium=organic_social&amp;amp;utm_campaign=dm_social&amp;amp;utm_content=dev_d554eb91e03c" rel="noopener noreferrer"&gt;Official store&lt;/a&gt; · &lt;a href="https://www.amazon.co.uk/dp/B0HBKTZRRT" rel="noopener noreferrer"&gt;Amazon UK&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Braided belt: &lt;a href="https://danielmason.uk/products/men-s-braided-leather-belt-stretch-woven-casual-belt-adjustable-one-size-elastic-plaited-belt-for-jeans-chinos-gift-for-him?utm_source=dev&amp;amp;utm_medium=organic_social&amp;amp;utm_campaign=dm_social&amp;amp;utm_content=dev_d554eb91e03c" rel="noopener noreferrer"&gt;Official store&lt;/a&gt; · &lt;a href="https://www.amazon.co.uk/dp/B0GXS6542B" rel="noopener noreferrer"&gt;Amazon UK&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Leather wallet: &lt;a href="https://danielmason.uk/products/daniel-mason%E2%84%A2-leather-wallet-full-grain-italian-leather?utm_source=dev&amp;amp;utm_medium=organic_social&amp;amp;utm_campaign=dm_social&amp;amp;utm_content=dev_d554eb91e03c" rel="noopener noreferrer"&gt;Official store&lt;/a&gt; · &lt;a href="https://www.amazon.co.uk/dp/B0GZB3P3JR" rel="noopener noreferrer"&gt;Amazon UK&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Leather keyring: &lt;a href="https://danielmason.uk/products/daniel-mason%E2%84%A2-leather-keyring-dark-brown?utm_source=dev&amp;amp;utm_medium=organic_social&amp;amp;utm_campaign=dm_social&amp;amp;utm_content=dev_d554eb91e03c" rel="noopener noreferrer"&gt;Official store&lt;/a&gt; · &lt;a href="https://www.amazon.co.uk/dp/B0GY9VDW5W" rel="noopener noreferrer"&gt;Amazon UK&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>automation</category>
      <category>webdev</category>
      <category>github</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>JavaScript: Preserve External IDs Before JSON Parsing Loses Precision</title>
      <dc:creator>Daniel Neata</dc:creator>
      <pubDate>Sun, 25 Oct 2026 14:05:42 +0000</pubDate>
      <link>https://dev.to/danielmason77/javascript-preserve-external-ids-before-json-parsing-loses-precision-5fe1</link>
      <guid>https://dev.to/danielmason77/javascript-preserve-external-ids-before-json-parsing-loses-precision-5fe1</guid>
      <description>&lt;p&gt;An external identifier can look like a number without being a quantity. You may need to place it in a URL, compare it with a provider response or store it in a ledger. None of those operations requires arithmetic.&lt;/p&gt;

&lt;p&gt;Treating such an identifier as an ordinary JavaScript number can quietly change it before your duplicate check even runs. The resulting bug often appears somewhere else: a history lookup misses a post, a reconciliation step cannot find its receipt, or a URL points at the wrong resource.&lt;/p&gt;

&lt;h2&gt;
  
  
  The conversion can happen during parsing
&lt;/h2&gt;

&lt;p&gt;JavaScript's Number type cannot represent every sufficiently large integer exactly. Converting an already-rounded value to a string does not restore the original digits.&lt;/p&gt;

&lt;p&gt;You can demonstrate the boundary without calling any external API:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;assert&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;node:assert/strict&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;supplied&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;831204016708108288&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;numeric&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;parse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;{"id":&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;supplied&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;}&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;assert&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;equal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Number&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;isSafeInteger&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;numeric&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;stringified&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;parse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;{"id":"&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;supplied&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;"}&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;assert&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;equal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;stringified&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;supplied&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The first assertion does not tell you which resource was intended. It only tells you that the parsed value is outside the safe integer range. The second response shape preserves the identifier because JSON contains a string rather than a numeric token.&lt;/p&gt;

&lt;p&gt;This distinction matters before the application reaches its usual validation code. The HTTP response can be complete and valid JSON while the chosen parsing representation is still unsuitable for an identifier.&lt;/p&gt;

&lt;h2&gt;
  
  
  Prefer the provider's string representation
&lt;/h2&gt;

&lt;p&gt;If an API supplies a documented string identifier, use that field consistently. Some responses expose both numeric and string forms. Do not select the numeric form merely because its property name is shorter.&lt;/p&gt;

&lt;p&gt;When a provider returns only a numeric token, choose a parsing strategy that preserves the original token before it becomes a Number. That may mean a lossless JSON parser appropriate to the response schema or a controlled tokenizer that keeps the relevant numeric lexeme as text.&lt;/p&gt;

&lt;p&gt;A broad regular expression is not a general JSON parser. It can confuse quoted text, escaped characters or an unrelated field that happens to use the same name. If you use any narrow adapter for a known response shape, document the assumptions and test the actual edge cases.&lt;/p&gt;

&lt;h2&gt;
  
  
  A normal reviver is too late to repair lost digits
&lt;/h2&gt;

&lt;p&gt;The familiar JSON.parse reviver receives values after the parser has constructed them. Calling String(value) or BigInt(value) on a number that has already lost precision preserves the rounded interpretation, not the original response token.&lt;/p&gt;

&lt;p&gt;Similarly, checking that a value contains only digits after converting it to text does not establish correctness. It can be a perfectly well-formed identifier that belongs to the wrong resource.&lt;/p&gt;

&lt;p&gt;Validation should distinguish representation from provenance. Knowing that a string contains decimal digits is useful. Knowing that those are the exact digits received from the provider is a separate requirement.&lt;/p&gt;

&lt;h2&gt;
  
  
  Keep IDs opaque at every boundary
&lt;/h2&gt;

&lt;p&gt;Once an identifier is safely represented as a string, preserve that contract through storage and comparison. Watch for implicit conversions in database columns, CSV imports, analytics exports and helper functions that call Number on every numeric-looking value.&lt;/p&gt;

&lt;p&gt;Avoid converting two identifiers to Number just to compare them. Compare their documented string representations instead. Do not strip leading zeroes unless the provider explicitly defines them as insignificant.&lt;/p&gt;

&lt;p&gt;For a URL, encode the string for the intended URL component. Encoding protects the syntax of the URL; it does not validate the identifier or recover precision. These are separate concerns and should remain separate in the code review.&lt;/p&gt;

&lt;h2&gt;
  
  
  Test round trips, not just the happy path
&lt;/h2&gt;

&lt;p&gt;Include a small identifier, one near the safe integer boundary and one beyond it. Add an identifier containing leading zeroes if the upstream schema permits that form. Test serialisation and deserialisation through the actual storage format you use.&lt;/p&gt;

&lt;p&gt;For a publishing ledger, verify that the identifier from the write response remains unchanged when it is read back and used in a provider-history lookup. This connects the representation test to the failure that would matter operationally.&lt;/p&gt;

&lt;p&gt;Also check error handling. If the provider response cannot be parsed without losing required information, stop before reporting a verified publication. Logging an uncertain receipt is more honest than manufacturing a reliable-looking identifier.&lt;/p&gt;

&lt;p&gt;The &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER" rel="noopener noreferrer"&gt;Number.MAX_SAFE_INTEGER reference&lt;/a&gt; explains the numeric boundary. The practical design decision is simpler: an opaque external ID should stay an identifier throughout the system.&lt;/p&gt;

</description>
      <category>automation</category>
      <category>webdev</category>
      <category>github</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>GitHub Actions: A Successful Job Is Not Publication Evidence</title>
      <dc:creator>Daniel Neata</dc:creator>
      <pubDate>Sat, 24 Oct 2026 14:05:12 +0000</pubDate>
      <link>https://dev.to/danielmason77/github-actions-a-successful-job-is-not-publication-evidence-1oh4</link>
      <guid>https://dev.to/danielmason77/github-actions-a-successful-job-is-not-publication-evidence-1oh4</guid>
      <description>&lt;p&gt;A scheduled publishing job can finish successfully without creating a public post. That is not necessarily a defect. The job might have selected the other daylight-saving trigger, found no reviewed content, performed a dry run, or recognised a publication that already exists.&lt;/p&gt;

&lt;p&gt;The mistake is treating every successful workflow conclusion as the same business outcome. A useful publisher records what happened to the publication attempt, then keeps that evidence separate from the health of the surrounding job.&lt;/p&gt;

&lt;h2&gt;
  
  
  Separate execution health from delivery
&lt;/h2&gt;

&lt;p&gt;A workflow conclusion answers whether its steps met the runner's success conditions. It does not establish that a provider accepted a post, made it public, or returned the destination you expected.&lt;/p&gt;

&lt;p&gt;For example, a guard can deliberately return zero after deciding that a run is outside its publishing window. Reporting that as a successful publication invents an event. Reporting it as a failed publication also misrepresents the system: there may have been no expected publication for that trigger.&lt;/p&gt;

&lt;p&gt;Use explicit outcome names such as &lt;code&gt;skipped_outside_slot&lt;/code&gt;, &lt;code&gt;no_eligible_content&lt;/code&gt;, &lt;code&gt;dry_run_passed&lt;/code&gt;, &lt;code&gt;submitted_unverified&lt;/code&gt; and &lt;code&gt;published_verified&lt;/code&gt;. Attach a reason and observation time rather than relying on the label alone.&lt;/p&gt;

&lt;h2&gt;
  
  
  Make the publishing step identifiable
&lt;/h2&gt;

&lt;p&gt;Give the actual publishing step an identifier. Preserve its outcome separately from validation, checkout and artifact upload. A successful setup step is useful operational evidence, but it is several stages removed from a public post.&lt;/p&gt;

&lt;p&gt;The same applies to dry runs. A dry run can verify account ownership, content selection and media availability. It should say that no publication was attempted. If it returns the next eligible item, record its identity so that someone reviewing the run can see what was checked.&lt;/p&gt;

&lt;p&gt;Do not make a live post simply to learn whether an unfamiliar field is required. Read the provider's documentation and validate the prepared content first. Reserve a live publication for the actual authorised item and destination.&lt;/p&gt;

&lt;h2&gt;
  
  
  Model uncertainty before making the write
&lt;/h2&gt;

&lt;p&gt;Suppose a provider creates a post, but the connection closes before your process receives the response. A timeout alone cannot distinguish that case from a request that never reached the provider.&lt;/p&gt;

&lt;p&gt;Persist a pending record before the request. Include a stable local identity, destination, intended source and claim time. Where supported, send the provider's idempotency key. Otherwise, reconcile the pending record against provider history before considering another write.&lt;/p&gt;

&lt;p&gt;An unresolved record is a reason to stop that publisher, not a reason to try several alternate routes. Two routes can each appear helpful while creating the same post twice. Continuing unaffected destinations is different from retrying the uncertain destination.&lt;/p&gt;

&lt;p&gt;A pending record also needs durable storage. An in-memory flag disappears when the runner exits. If you use a repository file, guard updates with the current file revision and inspect conflicts before retrying. Workflow concurrency and durable state solve related but different problems.&lt;/p&gt;

&lt;h2&gt;
  
  
  Keep the evidence small and concrete
&lt;/h2&gt;

&lt;p&gt;A useful record might look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"slot"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"2026-10-24/08:15"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"outcome"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"submitted_unverified"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"destination"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"example-account"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"providerId"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"831204016708108288"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"publicUrl"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"observedAt"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"2026-10-24T07:15:12Z"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This example deliberately leaves the public URL empty. A provider identifier is valuable, but the evidence does not yet support calling the item publicly available. After read-back, append the verified URL and the time of that observation.&lt;/p&gt;

&lt;p&gt;Never put access tokens, refresh tokens or authentication headers in these records. Diagnostic convenience is not a reason to copy credentials into artifacts or source control.&lt;/p&gt;

&lt;h2&gt;
  
  
  Test the decisions that change reporting
&lt;/h2&gt;

&lt;p&gt;Test daylight-saving boundaries, future slots, a previously recorded slot, an empty reviewed queue and an uncertain provider response. Also test the case where a write succeeded but storing the final receipt failed: reconciliation should recover the existing post rather than create another.&lt;/p&gt;

&lt;p&gt;A useful daily report states the expected interval, the number of confirmed deliveries and the number still unknown. It does not turn every green run into a delivery, or every deliberate skip into a missed post.&lt;/p&gt;

&lt;p&gt;GitHub's &lt;a href="https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions" rel="noopener noreferrer"&gt;workflow syntax reference&lt;/a&gt; describes the execution primitives. Your application still needs to define what successful delivery means and which evidence is sufficient to claim it.&lt;/p&gt;

</description>
      <category>automation</category>
      <category>webdev</category>
      <category>github</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Why a Black and Brown Reversible Leather Belt Is a Smart Addition to Every Man’s Wardrobe

One belt, two classic colours — a practical approach to everyday men’s style.

When it comes to men’s accessories, versatility matters. A well-chosen belt can bring</title>
      <dc:creator>Daniel Neata</dc:creator>
      <pubDate>Thu, 22 Oct 2026 19:39:27 +0000</pubDate>
      <link>https://dev.to/danielmason77/why-a-black-and-brown-reversible-leather-belt-is-a-smart-addition-to-every-mans-wardrobe-one-59c0</link>
      <guid>https://dev.to/danielmason77/why-a-black-and-brown-reversible-leather-belt-is-a-smart-addition-to-every-mans-wardrobe-one-59c0</guid>
      <description></description>
    </item>
    <item>
      <title>Design a Reliable Webhook Consumer with Signatures, Replay Protection and Idempotency</title>
      <dc:creator>Daniel Neata</dc:creator>
      <pubDate>Wed, 21 Oct 2026 14:17:07 +0000</pubDate>
      <link>https://dev.to/danielmason77/design-a-reliable-webhook-consumer-with-signatures-replay-protection-and-idempotency-394i</link>
      <guid>https://dev.to/danielmason77/design-a-reliable-webhook-consumer-with-signatures-replay-protection-and-idempotency-394i</guid>
      <description>&lt;h1&gt;
  
  
  Design a Reliable Webhook Consumer with Signatures, Replay Protection and Idempotency
&lt;/h1&gt;

&lt;p&gt;A webhook endpoint looks simple: accept an HTTP request, parse JSON and update a record. Production failures usually appear in the gaps between those steps. Providers retry deliveries, requests arrive out of order, workers crash after completing an action, and attackers can replay a captured request. A reliable consumer treats delivery as an untrusted, repeatable event rather than a one-time command.&lt;/p&gt;

&lt;p&gt;This guide develops a concrete Node.js pattern around four controls: verify the signature over the raw body, enforce a short timestamp window, claim a stable event identity atomically, and acknowledge only after durable state has been recorded.&lt;/p&gt;

&lt;h2&gt;
  
  
  Verify the exact bytes that were signed
&lt;/h2&gt;

&lt;p&gt;Most providers calculate an HMAC over the original request bytes. If middleware parses and serialises the JSON first, whitespace or property ordering can change and a legitimate signature may fail.&lt;/p&gt;

&lt;p&gt;Capture the raw body and compare signatures in constant time:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;createHmac&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;timingSafeEqual&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;node:crypto&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;verifyHmac&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;&lt;span class="nx"&gt;rawBody&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;suppliedHex&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;secret&lt;/span&gt;&lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;expected&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;createHmac&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;sha256&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;secret&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;update&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;rawBody&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;digest&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;supplied&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;Buffer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;from&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;suppliedHex&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;hex&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;supplied&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="nx"&gt;expected&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;timingSafeEqual&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;supplied&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;expected&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The real provider may include a version prefix, timestamp or delivery ID in the signed payload. Follow that provider's documented construction exactly. Do not invent a generic signature header, and never log the shared secret or full authentication header.&lt;/p&gt;

&lt;p&gt;Reject malformed signatures before parsing the body. Return a clear 4xx status so the provider does not interpret an authentication failure as a transient server problem.&lt;/p&gt;

&lt;h2&gt;
  
  
  Add a replay window
&lt;/h2&gt;

&lt;p&gt;A valid HMAC proves that somebody possessed the secret when the message was signed. It does not prove that a captured message is fresh.&lt;/p&gt;

&lt;p&gt;If the provider signs a Unix timestamp, require it to be close to the server clock:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;timestampIsFresh&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;headerValue&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;nowMs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;now&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;seconds&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Number&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;headerValue&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nb"&gt;Number&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;isInteger&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;seconds&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;ageMs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;abs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;nowMs&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;seconds&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;ageMs&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;60&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Five minutes is an example, not a universal standard. Choose the provider's recommended tolerance and keep server time synchronised. A timestamp check reduces the replay window, but it does not replace event-level deduplication because the same delivery can be retried legitimately inside that window.&lt;/p&gt;

&lt;h2&gt;
  
  
  Claim a stable event ID atomically
&lt;/h2&gt;

&lt;p&gt;Use the provider's immutable event or delivery ID. Do not hash only the JSON body: two different legitimate events can contain identical data. Scope the identity by provider and account when IDs are not globally unique.&lt;/p&gt;

&lt;p&gt;Create a table with a unique constraint:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="n"&gt;webhook_deliveries&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="n"&gt;provider&lt;/span&gt; &lt;span class="nb"&gt;TEXT&lt;/span&gt; &lt;span class="k"&gt;NOT&lt;/span&gt; &lt;span class="k"&gt;NULL&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;account_id&lt;/span&gt; &lt;span class="nb"&gt;TEXT&lt;/span&gt; &lt;span class="k"&gt;NOT&lt;/span&gt; &lt;span class="k"&gt;NULL&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;event_id&lt;/span&gt; &lt;span class="nb"&gt;TEXT&lt;/span&gt; &lt;span class="k"&gt;NOT&lt;/span&gt; &lt;span class="k"&gt;NULL&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="k"&gt;state&lt;/span&gt; &lt;span class="nb"&gt;TEXT&lt;/span&gt; &lt;span class="k"&gt;NOT&lt;/span&gt; &lt;span class="k"&gt;NULL&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;payload_sha256&lt;/span&gt; &lt;span class="nb"&gt;TEXT&lt;/span&gt; &lt;span class="k"&gt;NOT&lt;/span&gt; &lt;span class="k"&gt;NULL&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;received_at&lt;/span&gt; &lt;span class="n"&gt;TIMESTAMPTZ&lt;/span&gt; &lt;span class="k"&gt;NOT&lt;/span&gt; &lt;span class="k"&gt;NULL&lt;/span&gt; &lt;span class="k"&gt;DEFAULT&lt;/span&gt; &lt;span class="n"&gt;now&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
  &lt;span class="n"&gt;processed_at&lt;/span&gt; &lt;span class="n"&gt;TIMESTAMPTZ&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;last_error&lt;/span&gt; &lt;span class="nb"&gt;TEXT&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="k"&gt;PRIMARY&lt;/span&gt; &lt;span class="k"&gt;KEY&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;provider&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;account_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;event_id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;At ingress, insert a row in state &lt;code&gt;received&lt;/code&gt;. If the insert conflicts, load the existing row. A previously completed event should return a successful acknowledgement without repeating its side effect. An event still being processed should not be run concurrently.&lt;/p&gt;

&lt;p&gt;Store a digest of the raw payload. If the same event ID later arrives with a different digest, quarantine it and alert an operator. Silently accepting two payloads under one identity weakens the audit trail.&lt;/p&gt;

&lt;h2&gt;
  
  
  Separate receipt from processing
&lt;/h2&gt;

&lt;p&gt;Slow business logic should not keep the provider's HTTP request open. After verification and the durable insert, enqueue the database key and return an accepted response. The queue message is only a wake-up signal; the database row remains the source of truth.&lt;/p&gt;

&lt;p&gt;The worker claims the event with a conditional update:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;UPDATE&lt;/span&gt; &lt;span class="n"&gt;webhook_deliveries&lt;/span&gt;
&lt;span class="k"&gt;SET&lt;/span&gt; &lt;span class="k"&gt;state&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'processing'&lt;/span&gt;
&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;provider&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;
  &lt;span class="k"&gt;AND&lt;/span&gt; &lt;span class="n"&gt;account_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;
  &lt;span class="k"&gt;AND&lt;/span&gt; &lt;span class="n"&gt;event_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;
  &lt;span class="k"&gt;AND&lt;/span&gt; &lt;span class="k"&gt;state&lt;/span&gt; &lt;span class="k"&gt;IN&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'received'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'retryable'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Continue only when one row changed. This protects against queue duplication and overlapping workers.&lt;/p&gt;

&lt;p&gt;For higher throughput, add an expiring lease rather than leaving crashed rows permanently in &lt;code&gt;processing&lt;/code&gt;. An expired lease should move to reconciliation, not blindly repeat an external action.&lt;/p&gt;

&lt;h2&gt;
  
  
  Make side effects idempotent
&lt;/h2&gt;

&lt;p&gt;Deduplicating deliveries does not automatically make every downstream action safe. Consider a payment event that grants account credit. If the worker updates the balance and crashes before marking the delivery complete, a retry can grant credit twice.&lt;/p&gt;

&lt;p&gt;Prefer a single database transaction containing both the business change and completion marker:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;BEGIN&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;INSERT&lt;/span&gt; &lt;span class="k"&gt;INTO&lt;/span&gt; &lt;span class="n"&gt;account_credits&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;account_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;source_event_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;amount&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;VALUES&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;ON&lt;/span&gt; &lt;span class="n"&gt;CONFLICT&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;source_event_id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;DO&lt;/span&gt; &lt;span class="k"&gt;NOTHING&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;UPDATE&lt;/span&gt; &lt;span class="n"&gt;webhook_deliveries&lt;/span&gt;
&lt;span class="k"&gt;SET&lt;/span&gt; &lt;span class="k"&gt;state&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'completed'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;processed_at&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;now&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;provider&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt; &lt;span class="k"&gt;AND&lt;/span&gt; &lt;span class="n"&gt;account_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="k"&gt;AND&lt;/span&gt; &lt;span class="n"&gt;event_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;COMMIT&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The unique constraint on &lt;code&gt;source_event_id&lt;/code&gt; is the decisive guard. An application-level “already processed” check alone has a race between reading and writing.&lt;/p&gt;

&lt;p&gt;When the side effect calls another API, use that API's documented idempotency key if available. Persist the remote request key and returned resource ID before optional work. If a timeout leaves the outcome uncertain, query the destination by that key or ID before retrying.&lt;/p&gt;

&lt;h2&gt;
  
  
  Handle ordering explicitly
&lt;/h2&gt;

&lt;p&gt;Webhook arrival order is not business order. A delayed “updated” event can arrive after “deleted”, and retries can overtake newer messages.&lt;/p&gt;

&lt;p&gt;If the payload provides a monotonically increasing version, update the aggregate only when the incoming version is newer. If it provides an event time, remember that clocks and delivery delays can still make timestamps ambiguous. For critical state, fetch the current object from the provider instead of reconstructing truth from event order.&lt;/p&gt;

&lt;p&gt;Treat deletion carefully. A tombstone with a version is safer than removing all evidence and later accepting an older update as new.&lt;/p&gt;

&lt;h2&gt;
  
  
  Classify failures
&lt;/h2&gt;

&lt;p&gt;Use distinct outcomes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;completed&lt;/code&gt;: the business effect is durably confirmed.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;retryable&lt;/code&gt;: a temporary dependency failure occurred before an uncertain external write.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;uncertain&lt;/code&gt;: a write may have succeeded; reconciliation is required.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;rejected&lt;/code&gt;: the payload is authentic but invalid for a permanent reason.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;quarantined&lt;/code&gt;: the identity or payload conflicts with recorded evidence.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Retry only retryable work with exponential backoff and jitter. Put a finite limit on automatic attempts, then move the item to a review queue with non-secret diagnostics.&lt;/p&gt;

&lt;h2&gt;
  
  
  Test the boundaries
&lt;/h2&gt;

&lt;p&gt;A useful test suite sends the same event concurrently and asserts exactly one business effect. It also covers a valid request with an expired timestamp, an invalid signature, the same ID with a changed payload, a worker crash after the side effect, and an external API timeout followed by reconciliation.&lt;/p&gt;

&lt;p&gt;Do not stop at HTTP status assertions. Count durable rows and downstream writes. The safety property is not “both requests returned 200”; it is “one intended event produced at most one side effect, and every uncertain outcome remained visible”.&lt;/p&gt;

&lt;p&gt;A robust webhook consumer accepts that networks retry and processes crash. Signatures establish authenticity, replay controls establish freshness, atomic identities prevent duplicate claims, and idempotent side effects make recovery safe.&lt;/p&gt;

</description>
      <category>automation</category>
      <category>webdev</category>
      <category>github</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>SEO Automation: Validate Canonical URLs Before Syndicating Content</title>
      <dc:creator>Daniel Neata</dc:creator>
      <pubDate>Tue, 20 Oct 2026 14:16:16 +0000</pubDate>
      <link>https://dev.to/danielmason77/seo-automation-validate-canonical-urls-before-syndicating-content-3l8a</link>
      <guid>https://dev.to/danielmason77/seo-automation-validate-canonical-urls-before-syndicating-content-3l8a</guid>
      <description>&lt;h1&gt;
  
  
  SEO Automation: Validate Canonical URLs Before Syndicating Content
&lt;/h1&gt;

&lt;p&gt;Publishing the same article to several platforms can extend its reach, but it also creates an engineering problem: every destination needs to know which URL represents the preferred source. A canonical tag is only a hint to search engines, yet a broken hint is worse than no automation at all. It can point at a redirect, a missing page, a preview environment or a URL that has never become publicly accessible.&lt;/p&gt;

&lt;p&gt;A safe syndication pipeline therefore treats the canonical URL as verified input. It publishes the source first, confirms that the public response is suitable, creates the remote article once, and records enough evidence to reconcile an uncertain result before retrying.&lt;/p&gt;

&lt;p&gt;This guide builds that workflow in Node.js without assuming that a successful job automatically means a successful publication.&lt;/p&gt;

&lt;h2&gt;
  
  
  Define a canonical contract
&lt;/h2&gt;

&lt;p&gt;Before writing code, define what the source URL must satisfy:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It uses HTTPS.&lt;/li&gt;
&lt;li&gt;Its hostname is on an allow-list controlled by the publisher.&lt;/li&gt;
&lt;li&gt;It returns a successful public response without authentication.&lt;/li&gt;
&lt;li&gt;Redirects finish on the expected hostname.&lt;/li&gt;
&lt;li&gt;The final HTML declares the same canonical URL, after normalisation.&lt;/li&gt;
&lt;li&gt;The page is not marked &lt;code&gt;noindex&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;The article has passed editorial review and is already public.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Normalisation should be conservative. Lower-case the hostname, remove the default port and discard a trailing slash only when the site treats both forms as equivalent. Do not remove arbitrary query parameters or change path casing without evidence that the origin does the same.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;normaliseUrl&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;input&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;url&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;URL&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;input&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;protocol&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;https:&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Canonical URL must use HTTPS&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;hostname&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;hostname&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toLowerCase&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;port&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;443&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;port&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;""&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;hash&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;""&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;pathname&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;pathname&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;pathname&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="se"&gt;\/&lt;/span&gt;&lt;span class="sr"&gt;$/&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;""&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;href&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Keep an explicit host allow-list. Checking &lt;code&gt;hostname.endsWith("example.com")&lt;/code&gt; can accidentally accept &lt;code&gt;notexample.com&lt;/code&gt;. Match the exact host or an intentional subdomain boundary.&lt;/p&gt;

&lt;h2&gt;
  
  
  Verify the public source before syndication
&lt;/h2&gt;

&lt;p&gt;Use a bounded request with a clear user agent. Follow only a small number of redirects and reject a final URL outside the allow-list.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;inspectSource&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;sourceUrl&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;controller&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;AbortController&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;timeout&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;setTimeout&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;controller&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;abort&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="nx"&gt;_000&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;sourceUrl&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;redirect&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;follow&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;signal&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;controller&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;signal&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;User-Agent&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;SafeSyndicator/1.0&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;

    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;ok&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Source returned HTTP &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;status&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;finalUrl&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;normaliseUrl&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;type&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;content-type&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="dl"&gt;""&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;type&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toLowerCase&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;includes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;text/html&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Expected HTML, received &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;type&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;unknown&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;html&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;text&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;finalUrl&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;html&lt;/span&gt;&lt;span class="p"&gt;};&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;finally&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;clearTimeout&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;timeout&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The request proves reachability at that moment. It does not prove that a search engine has indexed the page, and the automation should never claim otherwise.&lt;/p&gt;

&lt;p&gt;Parse the document with an HTML parser rather than a regular expression in production. Read the &lt;code&gt;rel="canonical"&lt;/code&gt; element and robots directives, resolve relative URLs against the final response URL, then compare the normalised values.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nx"&gt;cheerio&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;cheerio&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;validateDocument&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;&lt;span class="nx"&gt;html&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;finalUrl&lt;/span&gt;&lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;$&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;cheerio&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;load&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;html&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;href&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;$&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;link[rel="canonical"]&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;attr&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;href&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;href&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Source has no canonical element&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;declared&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;normaliseUrl&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;URL&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;href&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;finalUrl&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;href&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;declared&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="nx"&gt;finalUrl&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Canonical mismatch: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;declared&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; != &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;finalUrl&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;robots&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="nf"&gt;$&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;meta[name="robots"]&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;attr&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;content&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="nf"&gt;$&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;meta[name="googlebot"]&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;attr&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;content&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Boolean&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;,&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;toLowerCase&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;robots&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;,&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;trim&lt;/span&gt;&lt;span class="p"&gt;()).&lt;/span&gt;&lt;span class="nf"&gt;includes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;noindex&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Source is marked noindex&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;declared&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Use a publication identity, not a hopeful retry
&lt;/h2&gt;

&lt;p&gt;A scheduler can time out after sending a create request. The remote platform may have created the article even though the client never received its ID. Retrying immediately can create a duplicate.&lt;/p&gt;

&lt;p&gt;Generate a stable publication key from the destination, canonical URL and content revision. Store it before the remote write.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="n"&gt;syndication_jobs&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="n"&gt;destination&lt;/span&gt; &lt;span class="nb"&gt;TEXT&lt;/span&gt; &lt;span class="k"&gt;NOT&lt;/span&gt; &lt;span class="k"&gt;NULL&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;canonical_url&lt;/span&gt; &lt;span class="nb"&gt;TEXT&lt;/span&gt; &lt;span class="k"&gt;NOT&lt;/span&gt; &lt;span class="k"&gt;NULL&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;revision&lt;/span&gt; &lt;span class="nb"&gt;TEXT&lt;/span&gt; &lt;span class="k"&gt;NOT&lt;/span&gt; &lt;span class="k"&gt;NULL&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="k"&gt;state&lt;/span&gt; &lt;span class="nb"&gt;TEXT&lt;/span&gt; &lt;span class="k"&gt;NOT&lt;/span&gt; &lt;span class="k"&gt;NULL&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;remote_id&lt;/span&gt; &lt;span class="nb"&gt;TEXT&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;remote_url&lt;/span&gt; &lt;span class="nb"&gt;TEXT&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;attempted_at&lt;/span&gt; &lt;span class="n"&gt;TIMESTAMPTZ&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;confirmed_at&lt;/span&gt; &lt;span class="n"&gt;TIMESTAMPTZ&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="k"&gt;PRIMARY&lt;/span&gt; &lt;span class="k"&gt;KEY&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;destination&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;canonical_url&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;revision&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Move a job through explicit states such as &lt;code&gt;ready&lt;/code&gt;, &lt;code&gt;publishing&lt;/code&gt;, &lt;code&gt;uncertain&lt;/code&gt;, &lt;code&gt;confirmed&lt;/code&gt; and &lt;code&gt;blocked&lt;/code&gt;. A unique constraint prevents two workers from claiming the same revision.&lt;/p&gt;

&lt;p&gt;If the destination accepts idempotency keys, send the stable publication key. If it does not, search the destination by canonical URL and title before every create operation. A title alone is not a safe identity because an editor may reuse or change it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Reconcile ambiguous outcomes
&lt;/h2&gt;

&lt;p&gt;Treat network timeouts and malformed responses differently from clear rejections.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A 4xx validation response is normally a permanent failure that needs an editorial or configuration fix.&lt;/li&gt;
&lt;li&gt;A 429 response is retryable after the documented delay.&lt;/li&gt;
&lt;li&gt;A 5xx response before any body is uncertain because the destination may have committed the write.&lt;/li&gt;
&lt;li&gt;A response containing a remote ID and public URL is evidence, but the URL should still be fetched or read back through the platform API.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For an uncertain job, query remote history using every supported page of results. Compare the canonical URL, stable marker and content revision. If exactly one match exists, store its ID and URL and mark the job confirmed. If no match exists after the platform's normal indexing delay, the operator may retry once. If several matches exist, stop and require review rather than deleting content automatically.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;reconcile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;job&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;client&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="k"&gt;await &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;article&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nx"&gt;client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;listAllArticles&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;normaliseUrl&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;article&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;canonicalUrl&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;job&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;canonicalUrl&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;state&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;confirmed&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;remoteId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;article&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;remoteUrl&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;article&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;url&lt;/span&gt;
      &lt;span class="p"&gt;};&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="na"&gt;state&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;uncertain&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Pagination matters. Looking only at the first page can falsely conclude that an older article is missing.&lt;/p&gt;

&lt;h2&gt;
  
  
  Preserve evidence without leaking secrets
&lt;/h2&gt;

&lt;p&gt;Record the request timestamp, destination, canonical URL, content revision, HTTP status, remote ID and public URL. Do not store API tokens, full authentication headers or private payload fields in logs.&lt;/p&gt;

&lt;p&gt;A daily audit can then answer useful questions:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Which source revisions were confirmed remotely?&lt;/li&gt;
&lt;li&gt;Which jobs are still uncertain?&lt;/li&gt;
&lt;li&gt;Did two remote IDs claim the same publication key?&lt;/li&gt;
&lt;li&gt;Did a source canonical change after syndication?&lt;/li&gt;
&lt;li&gt;Does every recorded public URL still return a successful response?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This evidence is more valuable than a green scheduler badge. A workflow can exit successfully after skipping outside its time window, finding no eligible content or running in dry-run mode.&lt;/p&gt;

&lt;h2&gt;
  
  
  Test the failure boundaries
&lt;/h2&gt;

&lt;p&gt;Automated tests should cover more than the happy path. Use a local HTTP server to simulate a redirect to an unapproved host, a missing canonical element, a &lt;code&gt;noindex&lt;/code&gt; page, a timeout after the remote write, duplicate scheduler invocations and paginated history.&lt;/p&gt;

&lt;p&gt;The central safety assertion is: one reviewed source revision produces at most one confirmed remote article. A second assertion is equally important: every ambiguous write remains visible until it is reconciled.&lt;/p&gt;

&lt;p&gt;Canonical URLs support attribution, but they do not guarantee ranking or indexing. The reliable engineering work is making sure the hint is correct, the source is public, the remote write is deduplicated and failures can be explained from durable evidence.&lt;/p&gt;

</description>
      <category>automation</category>
      <category>webdev</category>
      <category>github</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>GitHub Actions Scheduling: Match the Trigger Before the Clock</title>
      <dc:creator>Daniel Neata</dc:creator>
      <pubDate>Mon, 19 Oct 2026 14:21:45 +0000</pubDate>
      <link>https://dev.to/danielmason77/github-actions-scheduling-match-the-trigger-before-the-clock-3ahi</link>
      <guid>https://dev.to/danielmason77/github-actions-scheduling-match-the-trigger-before-the-clock-3ahi</guid>
      <description>&lt;h1&gt;
  
  
  GitHub Actions Scheduling: Match the Trigger Before the Clock
&lt;/h1&gt;

&lt;p&gt;A scheduled worker can run successfully and still publish at the wrong time. One subtle cause is a workflow that contains two cron expressions for each desired local time: one for summer and one for winter. Checking whether the current clock is near a publishing slot does not prove that the expression which triggered the run belongs to the current season.&lt;/p&gt;

&lt;p&gt;This guide uses a small publishing worker as an example. The design is deliberately limited to fixed daily slots in Europe/London. It is not a general calendar library, and workflows involving several countries or arbitrary recurrence rules need a broader scheduling model.&lt;/p&gt;

&lt;h2&gt;
  
  
  Understand the two different times
&lt;/h2&gt;

&lt;p&gt;Record both the scheduled occurrence and the actual execution time. They answer different questions. The scheduled occurrence identifies the work the runner intended to process. The execution time tells you how late the runner started.&lt;/p&gt;

&lt;p&gt;Suppose a workflow is intended to run at 17:20 local time. A second seasonal expression fires an hour later. If that run is delayed again, a nearest-slot check might associate it with a different publishing slot. A tolerance window makes that mistake easier to miss.&lt;/p&gt;

&lt;p&gt;Instead, first determine whether the triggering expression represents a valid local slot under the current timezone offset. Only then decide whether the execution is still timely enough to process it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Filter the alternate seasonal expression
&lt;/h2&gt;

&lt;p&gt;Keep a small explicit set of allowed local times. Convert the hour and minute in the triggering cron expression into the local hour and minute for the relevant date. Reject the expression if that local time is not in the allowed set.&lt;/p&gt;

&lt;p&gt;For example, our fixed daily worker uses this decision structure:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;acceptOccurrence&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;targetMinutes&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;allowedMinutes&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;nowMinutes&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;allowedMinutes&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;has&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;targetMinutes&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;delay&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;nowMinutes&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;targetMinutes&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;delay&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;delay&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="mi"&gt;80&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The example assumes that timezone conversion has already happened and that the occurrence and execution are on the same local day. Do not copy it unchanged into a workflow that can cross midnight. Store a full timestamp for the intended occurrence in that case.&lt;/p&gt;

&lt;p&gt;The important order is expression validation first, lateness validation second. Merely widening the tolerance window does not solve the seasonal problem.&lt;/p&gt;

&lt;h2&gt;
  
  
  Make the lateness policy explicit
&lt;/h2&gt;

&lt;p&gt;A delayed run creates a product decision. Should a post appear late, be skipped, or wait for a later slot? Write that policy down before choosing a number in the workflow.&lt;/p&gt;

&lt;p&gt;In our example, adjacent slots are more than 90 minutes apart, so an 80-minute allowance stays within the gap. That allowance is a chosen policy, not a platform guarantee. Another schedule with closer slots would require a smaller window or stronger occurrence tracking.&lt;/p&gt;

&lt;p&gt;Reject early execution as well as excessively late execution. A negative delay can indicate that the wrong seasonal trigger was matched to an upcoming slot. Do not treat an early run as an opportunity to publish ahead of schedule.&lt;/p&gt;

&lt;h2&gt;
  
  
  Keep scheduling separate from content eligibility
&lt;/h2&gt;

&lt;p&gt;Passing the time gate should not be the only permission to publish. The content still needs editorial approval, the correct destination account and an unpublished delivery record.&lt;/p&gt;

&lt;p&gt;Likewise, a valid publishing slot with an empty reviewed queue is not an authentication failure. Log it as a content-supply issue. Operators need that distinction to decide whether to prepare more content or repair credentials.&lt;/p&gt;

&lt;p&gt;Use a separate read-only mode to check account authentication and queue selection. A manual diagnostic run should not silently become a public post merely because a repository variable enables scheduled publishing.&lt;/p&gt;

&lt;h2&gt;
  
  
  Test boundaries with fixed timestamps
&lt;/h2&gt;

&lt;p&gt;Clock-dependent code is easier to test when it accepts a date argument. Avoid tests that depend on the current machine time. Include a summer date, a winter date, the exact slot, one minute before it and one minute beyond the permitted lateness.&lt;/p&gt;

&lt;p&gt;Also test the alternate seasonal expression on each date. A test suite that only verifies the correct expression can miss the duplicate-trigger problem completely.&lt;/p&gt;

&lt;p&gt;For a production calendar spanning clock changes, add cases on both transition days and document whether a repeated or missing local time should execute. The simple same-day design here assumes ordinary daytime slots. Its scope should remain visible to anyone who extends it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Report why a run did nothing
&lt;/h2&gt;

&lt;p&gt;Use distinct messages for an alternate seasonal trigger, an expired publishing window and an empty queue. All three can legitimately avoid publishing, but they are different operational facts.&lt;/p&gt;

&lt;p&gt;After publication, record the remote post ID and public URL. A scheduler badge only describes job completion. It does not establish that the intended content reached the intended account at the intended time.&lt;/p&gt;

&lt;p&gt;That separation makes the automation easier to operate: the scheduler identifies an occurrence, the worker verifies eligibility, and the delivery record supplies evidence of publication. Each stage can then be checked and repaired without guessing what a successful exit code meant.&lt;/p&gt;

</description>
      <category>automation</category>
      <category>webdev</category>
      <category>github</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Automation Health Checks: A Green Job Is Not a Publication Receipt</title>
      <dc:creator>Daniel Neata</dc:creator>
      <pubDate>Sun, 18 Oct 2026 14:03:00 +0000</pubDate>
      <link>https://dev.to/danielmason77/automation-health-checks-a-green-job-is-not-a-publication-receipt-bda</link>
      <guid>https://dev.to/danielmason77/automation-health-checks-a-green-job-is-not-a-publication-receipt-bda</guid>
      <description>&lt;h1&gt;
  
  
  Automation Health Checks: A Green Job Is Not a Publication Receipt
&lt;/h1&gt;

&lt;p&gt;A publishing workflow can finish with a successful exit code after making no public post. That is sometimes correct: the queue may be empty, a seasonal trigger may be irrelevant, or every candidate may already exist on the destination account. The operational problem appears when the dashboard presents all of these outcomes as published.&lt;/p&gt;

&lt;p&gt;This guide describes a reporting contract for a small publishing worker. It follows the data from selection through the remote write and into the final summary. The examples are illustrative application code; they do not depend on a particular platform API.&lt;/p&gt;

&lt;h2&gt;
  
  
  Define an outcome for each delivery
&lt;/h2&gt;

&lt;p&gt;Separate the state of the job from the state of the delivery. A job can complete normally with a skipped delivery. It can also fail after the remote service created the post but before the local database recorded the result.&lt;/p&gt;

&lt;p&gt;Useful delivery outcomes are published, skipped, rejected and uncertain. Include a reason for skipped or rejected items. For a published delivery, require an external identifier and retain the public URL when the platform supplies one.&lt;/p&gt;

&lt;p&gt;Do not use a single boolean named success to represent all of these facts. That makes every downstream dashboard reconstruct information that the worker already knew.&lt;/p&gt;

&lt;h2&gt;
  
  
  Return structured results from helpers
&lt;/h2&gt;

&lt;p&gt;A fallback publisher is a common source of misleading counts. The parent worker sees an empty queue, calls a helper that publishes a reviewed reserve post, then returns its original counter of zero. The helper performed the work, but the parent never collected the outcome.&lt;/p&gt;

&lt;p&gt;Prefer a structured return value when both components are in the same process:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;processQueue&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;queue&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;reserve&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;item&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;queue&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;nextApproved&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;publishReviewed&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;reserve&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;publishNextReviewed&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Both paths should produce the same result shape. If the helper is a separate process, establish a machine-readable output contract. Keep diagnostic messages on a separate stream, or use a clearly identified result record. Parsing a human log phrase can be a temporary compatibility repair, but changing the phrase would then risk breaking the counter.&lt;/p&gt;

&lt;h2&gt;
  
  
  Preserve evidence before counting
&lt;/h2&gt;

&lt;p&gt;A published count should be backed by a response you can reconcile. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"outcome"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"published"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"contentId"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"reviewed-item-42"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"externalId"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"remote-record-123"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"publicUrl"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"https://example.test/posts/remote-record-123"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The URL is illustrative. In a real adapter, use the service response or a verified lookup. Do not invent a URL format just to make the report look complete.&lt;/p&gt;

&lt;p&gt;A missing URL does not necessarily mean the write failed. Preserve the external ID and report that public-link verification remains unavailable. A missing external ID after an ambiguous response needs an uncertain outcome and reconciliation before another write.&lt;/p&gt;

&lt;h2&gt;
  
  
  Track content supply as a separate dependency
&lt;/h2&gt;

&lt;p&gt;An empty reviewed queue can stop publishing even when credentials, scheduling and API calls work correctly. Measure the number of unpublished, editorially approved candidates, rather than counting all files in a content directory.&lt;/p&gt;

&lt;p&gt;A directory containing 40 drafts and one already-published article has no usable reserve. The file count alone conceals the problem. Count only items that satisfy the current eligibility rules and are absent from verified remote history.&lt;/p&gt;

&lt;p&gt;Set an alert threshold appropriate to the publishing cadence. Replenishment still requires writing and review; changing a status field on an unfinished draft does not create usable content.&lt;/p&gt;

&lt;h2&gt;
  
  
  Keep dry runs observably read only
&lt;/h2&gt;

&lt;p&gt;A dry run should authenticate, read history and identify a candidate without claiming or publishing it. Be careful with shared setup code: token persistence or queue mutation can happen before the code reaches the branch labelled dry run.&lt;/p&gt;

&lt;p&gt;Test the boundary by replacing the network adapter with a recording fake. Run the diagnostic path and assert that no publication or claim request occurred. Checking the final exit code is insufficient.&lt;/p&gt;

&lt;p&gt;A useful dry-run summary states the account, candidate identity, remaining reviewed reserve and the fact that no public write was attempted. Credentials must never appear in that summary.&lt;/p&gt;

&lt;h2&gt;
  
  
  Test the report against the side effects
&lt;/h2&gt;

&lt;p&gt;For each test scenario, compare reported counts with recorded remote writes. Include an empty queue with a usable reserve, an exhausted reserve, a rejected request and a write followed by a failed local confirmation.&lt;/p&gt;

&lt;p&gt;The helper case is particularly important. If the helper creates one post, the parent summary must acknowledge that publication. Conversely, an authentication check that succeeds must not increment the published count.&lt;/p&gt;

&lt;p&gt;Finally, inspect the actual remote record during operational validation. Tests establish the application's contract; the destination account provides evidence that the live publication exists.&lt;/p&gt;

&lt;p&gt;With these distinctions, the dashboard becomes useful for diagnosis. It can show that the scheduler ran, the account authenticated, the reserve was empty, or a particular post was published. Those are separate facts, and keeping them separate makes each repair much more precise.&lt;/p&gt;

</description>
      <category>automation</category>
      <category>webdev</category>
      <category>github</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Failure Recovery for Publishing APIs: Reconcile Before Retrying</title>
      <dc:creator>Daniel Neata</dc:creator>
      <pubDate>Sat, 17 Oct 2026 14:02:54 +0000</pubDate>
      <link>https://dev.to/danielmason77/failure-recovery-for-publishing-apis-reconcile-before-retrying-3b</link>
      <guid>https://dev.to/danielmason77/failure-recovery-for-publishing-apis-reconcile-before-retrying-3b</guid>
      <description>&lt;h1&gt;
  
  
  Failure Recovery for Publishing APIs: Reconcile Before Retrying
&lt;/h1&gt;

&lt;p&gt;A network timeout does not tell you whether a publishing request failed. The remote service may have rejected the request, accepted it and lost the response, or created the record while your process was already disconnecting. Retrying immediately can turn one uncertain delivery into two public posts.&lt;/p&gt;

&lt;p&gt;This guide presents a limited recovery pattern for workers that publish approved content to remote APIs. The design combines stable operation keys, explicit delivery states and reconciliation against remote history. It is intended for systems that can search recent records or attach a client-supplied identifier. If the destination provides neither capability, the worker must remain conservative and escalate uncertain writes instead of guessing.&lt;/p&gt;

&lt;h2&gt;
  
  
  Model uncertainty as a real state
&lt;/h2&gt;

&lt;p&gt;A delivery table often begins with pending, published and failed. That model is incomplete because a transport error can leave the remote result unknown.&lt;/p&gt;

&lt;p&gt;Add an uncertain state. Enter it when the request may have reached the destination but the response cannot be trusted. Do not automatically return an uncertain item to the normal retry queue.&lt;/p&gt;

&lt;p&gt;A useful record contains the internal content ID, destination, operation key, request start time, response status when known, remote ID, public URL and last reconciliation time. Store error summaries, but never store access tokens or complete authorization headers.&lt;/p&gt;

&lt;h2&gt;
  
  
  Create a stable operation key
&lt;/h2&gt;

&lt;p&gt;Generate the operation key before the first network request and persist it with the delivery attempt. It must remain stable across process restarts and operator-approved retries.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;createHash&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;node:crypto&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;operationKey&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;destination&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;contentId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;revision&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;createHash&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;sha256&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;update&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;destination&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;:&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;contentId&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;:&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;revision&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;digest&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;hex&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The revision matters. A corrected article can be a legitimate new operation, while restarting the worker for the same revision should not create another delivery.&lt;/p&gt;

&lt;p&gt;If the API supports an idempotency header, send this key in the documented field. That is the strongest option because the destination can reject duplicate requests. Keep local reconciliation anyway; providers can have retention windows or endpoint-specific behaviour.&lt;/p&gt;

&lt;h2&gt;
  
  
  Separate selection from delivery
&lt;/h2&gt;

&lt;p&gt;Claim one approved item transactionally before making a remote call. The claim prevents two runners from selecting the same item at the same time.&lt;/p&gt;

&lt;p&gt;The worker should then use a small state machine:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;deliver&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;adapter&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;store&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;attempt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;store&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;beginAttempt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;adapter&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;publish&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;attempt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;operationKey&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;store&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;markPublished&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;attempt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;remoteId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;publicUrl&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;url&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;isDefiniteRejection&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;store&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;markRejected&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;attempt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;safeSummary&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;store&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;markUncertain&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;attempt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;safeSummary&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A validated 400 response is normally a definite rejection. A timeout, connection reset or invalid response body after the request was sent is not. A 500 response may also be uncertain if the provider could have completed the write before returning the error.&lt;/p&gt;

&lt;h2&gt;
  
  
  Reconcile before any retry
&lt;/h2&gt;

&lt;p&gt;A reconciliation worker reads uncertain attempts and searches the destination using the strongest available evidence.&lt;/p&gt;

&lt;p&gt;First, search by operation key when the platform exposes custom fields or request metadata. Otherwise, compare a bounded time window using destination account, normalized title or text, source URL and creation time. Require more than one weak attribute before declaring a match.&lt;/p&gt;

&lt;p&gt;Do not compare only the first few recent posts. Paginate until the search crosses the attempt time plus a documented safety margin. Stop at a hard page limit and report that history verification was incomplete.&lt;/p&gt;

&lt;p&gt;When exactly one credible match exists, save its remote ID and URL and mark the attempt published. When no match exists and the provider's consistency delay has passed, move the attempt to retry-approved rather than publishing immediately. When several matches exist, flag the attempt for review because a duplicate may already exist.&lt;/p&gt;

&lt;h2&gt;
  
  
  Make retry a deliberate transition
&lt;/h2&gt;

&lt;p&gt;Only attempts in retry-approved may return to the delivery worker. Reuse the original operation key. Record who or what approved the retry and the evidence produced during reconciliation.&lt;/p&gt;

&lt;p&gt;Limit attempts with a small retry budget and exponential backoff. Backoff protects the provider, but it does not solve duplication by itself. The safety property comes from stable identity and reconciliation.&lt;/p&gt;

&lt;p&gt;For systems without remote search or idempotency support, the correct automatic action after an uncertain write may be no action. Manual inspection is slower than a retry, but safer than publishing repeated content under an account you cannot reconcile.&lt;/p&gt;

&lt;h2&gt;
  
  
  Verify the response before reporting success
&lt;/h2&gt;

&lt;p&gt;A successful HTTP status is not enough. Require the documented identifier field and validate its type. Prefer the public URL supplied by the API. If the service returns only an ID, perform a follow-up read and use the verified URL from that response.&lt;/p&gt;

&lt;p&gt;Keep publication counts tied to these receipts. Authentication checks, queue polling and dry runs should never increment a published counter.&lt;/p&gt;

&lt;p&gt;Return a structured result from every adapter:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"outcome"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"published"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"operationKey"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"stable-key"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"remoteId"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"remote-record-id"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"publicUrl"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"https://example.test/posts/remote-record-id"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The URL is illustrative. A production adapter must use the actual destination response or a verified lookup.&lt;/p&gt;

&lt;h2&gt;
  
  
  Test the difficult boundaries
&lt;/h2&gt;

&lt;p&gt;Use a fake adapter that records requests and can simulate a timeout after creating a remote record. The first run should leave the attempt uncertain. Reconciliation should discover the fake record, and the retry worker should make no second publish call.&lt;/p&gt;

&lt;p&gt;Add tests for a definite rejection, an uncertain attempt with no remote match, paginated history, multiple candidate matches and a process crash after the remote write but before the local commit.&lt;/p&gt;

&lt;p&gt;Also test two concurrent workers. Only one should acquire the claim. A reliable single-worker test does not prove that scheduled jobs cannot overlap in production.&lt;/p&gt;

&lt;h2&gt;
  
  
  Operate with evidence
&lt;/h2&gt;

&lt;p&gt;A useful operational report separates four facts: the scheduler ran, a candidate was approved, the remote write was attempted, and a public record was verified. A green workflow badge proves only the first fact.&lt;/p&gt;

&lt;p&gt;Log the operation key, internal content ID, outcome and remote receipt. Keep credentials redacted. Alert when uncertain attempts exceed their reconciliation window or when remote history cannot be read completely.&lt;/p&gt;

&lt;p&gt;Recovery is not the same as repeating the request. The safe order is identify the intended operation, inspect the destination, reconcile the result and only then decide whether a retry is justified.&lt;/p&gt;

</description>
      <category>automation</category>
      <category>webdev</category>
      <category>github</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>API Publishing Deduplication with Failure Recovery: Reconcile Before You Retry</title>
      <dc:creator>Daniel Neata</dc:creator>
      <pubDate>Fri, 16 Oct 2026 15:40:38 +0000</pubDate>
      <link>https://dev.to/danielmason77/api-publishing-deduplication-with-failure-recovery-reconcile-before-you-retry-2m28</link>
      <guid>https://dev.to/danielmason77/api-publishing-deduplication-with-failure-recovery-reconcile-before-you-retry-2m28</guid>
      <description>&lt;h1&gt;
  
  
  API Publishing Deduplication with Failure Recovery: Reconcile Before You Retry
&lt;/h1&gt;

&lt;p&gt;A publishing job sends a request. The connection closes before a response arrives. Should the job send the same request again?&lt;/p&gt;

&lt;p&gt;The answer depends on something the worker does not yet know: whether the remote platform accepted the first request. A network timeout describes the worker's observation. It does not prove that publication failed. Treating every timeout as permission to retry is an easy way to create duplicate posts.&lt;/p&gt;

&lt;p&gt;This guide describes a small worker design. It is an implementation pattern, not a claim that every publishing platform offers the same API features. Adapt the remote lookup and idempotency mechanism to the platform you actually use.&lt;/p&gt;

&lt;h2&gt;
  
  
  Separate content identity from delivery attempts
&lt;/h2&gt;

&lt;p&gt;Give each reviewed content item a stable internal identifier. Then create a separate delivery record for each destination account. The combination of content ID, platform and account identifies the intended publication; an attempt ID identifies one execution of the worker.&lt;/p&gt;

&lt;p&gt;Do not generate a new content ID merely because a request failed. That would make a retry look like a new publication. Likewise, do not use the current timestamp as the only identity: each execution would receive a different one.&lt;/p&gt;

&lt;p&gt;A minimal delivery record might look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"contentId"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"guide-2026-10-16-01"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"platform"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"example-network"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"accountId"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"brand-account"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"state"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"approved"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"externalId"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"lastAttemptId"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Enforce uniqueness for that destination identity in the database. Application-level checks alone can race when two workers read the same queue.&lt;/p&gt;

&lt;h2&gt;
  
  
  Claim work atomically
&lt;/h2&gt;

&lt;p&gt;The worker should change an eligible delivery from approved to claimed in one atomic operation. If another worker has already claimed it, stop processing that delivery. A read followed by an unrelated write leaves a gap in which both workers can believe they own the item.&lt;/p&gt;

&lt;p&gt;Keep the claim's timestamp and worker identifier. A crashed worker can leave a claim behind, so a recovery process needs to identify stale claims. However, an expired claim is not itself permission to publish again. The first worker might have reached the remote platform before it crashed.&lt;/p&gt;

&lt;p&gt;When recovering an expired claim, move it into reconciliation. Check remote state before creating another public post.&lt;/p&gt;

&lt;h2&gt;
  
  
  Model uncertainty as its own state
&lt;/h2&gt;

&lt;p&gt;Useful states include approved, claimed, published, rejected and uncertain. Define their transitions explicitly. In particular, do not collapse uncertain into rejected simply to make the retry queue easier to implement.&lt;/p&gt;

&lt;p&gt;Examples help distinguish them:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A local validation failure before any network request is a known failure.&lt;/li&gt;
&lt;li&gt;A confirmed remote rejection can be recorded as rejected, following that API's documented response semantics.&lt;/li&gt;
&lt;li&gt;A timeout after sending a publication request is uncertain.&lt;/li&gt;
&lt;li&gt;A remote ID followed by a failed database update means the remote publication succeeded while local recording failed.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That last case deserves special handling. Record the external ID in durable logs or another recovery store before acknowledging the job. Do not issue a second publication request just because the final database write needs retrying.&lt;/p&gt;

&lt;h2&gt;
  
  
  Reconcile using the strongest available evidence
&lt;/h2&gt;

&lt;p&gt;If the platform provides an idempotency key for this exact operation, reuse a stable key according to its documented scope and retention rules. Do not assume an arbitrary request header creates idempotency.&lt;/p&gt;

&lt;p&gt;If you have an external ID, query that resource directly. Otherwise, use an authenticated listing for the correct account and compare the intended publication with remote records. A stable marker can help where supported. Exact text alone is weaker evidence: legitimate posts can share wording, and platforms can transform URLs or formatting.&lt;/p&gt;

&lt;p&gt;Read all pages needed to cover the relevant history. If pagination stops unexpectedly, authentication fails or a safety limit is reached, preserve the uncertain state. An incomplete search cannot establish absence. It is safer to surface that delivery for investigation than to silently duplicate it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Retry the failed stage
&lt;/h2&gt;

&lt;p&gt;Structure the implementation around stages rather than wrapping the entire worker in a broad retry loop:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;recover&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;delivery&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;remote&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;store&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;delivery&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;externalId&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;post&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;remote&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;delivery&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;externalId&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;store&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;confirmPublished&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;delivery&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;post&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;remote&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;findDelivery&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;delivery&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;complete&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;store&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;markUncertain&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;delivery&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;match&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;store&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;confirmPublished&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;delivery&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;match&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;store&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;markForReviewedRetry&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;delivery&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The example deliberately does not publish. It resolves what is known and hands a confirmed absence to the retry policy. A production adapter must define what a complete search means and how it handles eventual visibility of newly created posts.&lt;/p&gt;

&lt;p&gt;Use bounded backoff for transient read failures. Avoid repeatedly querying a platform in a tight loop. Authentication problems need credential recovery, not more publication attempts.&lt;/p&gt;

&lt;h2&gt;
  
  
  Test the failure between each pair of stages
&lt;/h2&gt;

&lt;p&gt;The most useful tests interrupt the worker at meaningful boundaries: after the claim, after the remote write, and before local confirmation. Simulate a remote service that creates the post but throws a timeout to the caller. Recovery should discover the existing publication and avoid a second write.&lt;/p&gt;

&lt;p&gt;Also test concurrent claims, multi-page history, an incomplete history response and a failed local confirmation. Count remote writes in the test, not just successful worker exits. A worker can exit successfully after publishing nothing, or fail after publishing something; neither exit code alone tells the full story.&lt;/p&gt;

&lt;h2&gt;
  
  
  Report publication separately from job health
&lt;/h2&gt;

&lt;p&gt;For each run, report selected, published, rejected, uncertain and skipped counts. Include the external ID and public URL when available. A green scheduler badge means the job completed according to its exit policy. It should never be presented as proof that a new post exists.&lt;/p&gt;

&lt;p&gt;Keep credentials out of logs, and retain enough non-secret delivery metadata to reconcile an interrupted attempt. This approach makes recovery a controlled state transition instead of a guess. It also makes a quiet day explainable: an empty reviewed queue is a content-supply issue, while an uncertain publication is a delivery issue. Each needs a different fix.&lt;/p&gt;

</description>
      <category>automation</category>
      <category>webdev</category>
      <category>github</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>API Authentication Across Multiple Platforms: A Practical Implementation Guide</title>
      <dc:creator>Daniel Neata</dc:creator>
      <pubDate>Thu, 15 Oct 2026 14:16:53 +0000</pubDate>
      <link>https://dev.to/danielmason77/api-authentication-across-multiple-platforms-a-practical-implementation-guide-4i0f</link>
      <guid>https://dev.to/danielmason77/api-authentication-across-multiple-platforms-a-practical-implementation-guide-4i0f</guid>
      <description>&lt;h1&gt;
  
  
  API Authentication Across Multiple Platforms: A Practical Implementation Guide
&lt;/h1&gt;

&lt;p&gt;Publishing to several platforms from one GitHub Actions repository sounds simple: store tokens, call APIs, and schedule a job. The difficult part is not sending the request. It is proving that a post was created exactly once, recovering when authentication expires, and keeping credentials out of logs. This guide walks through a small Node.js publisher design suitable for Bluesky, Blogger, and other OAuth-backed APIs. The examples are illustrative; endpoint contracts differ by provider.&lt;/p&gt;

&lt;h2&gt;
  
  
  Separate credentials by destination
&lt;/h2&gt;

&lt;p&gt;Treat every platform as its own security boundary. A Bluesky app password is not an OAuth refresh token, and a Blogger refresh token cannot be handled as a short-lived access token. Use individual GitHub Actions secrets for each credential. Give each token the minimum scopes needed to create posts. Do not embed tokens in article content, URLs, build artifacts, or debug output.&lt;/p&gt;

&lt;p&gt;Use environment variables only at the step that needs them. Avoid printing the complete environment. If an API returns an authentication error, log the HTTP status and a redacted provider error code rather than the raw response body, which can occasionally contain sensitive values.&lt;/p&gt;

&lt;h2&gt;
  
  
  Build one timeout-aware request helper
&lt;/h2&gt;

&lt;p&gt;Network requests can hang or fail after the remote service has accepted a write. Always set a timeout, distinguish read operations from writes, and do not automatically retry a timed-out create request. Node.js 20+ provides AbortSignal.timeout, which keeps the example dependency-free.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;
&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;apiRequest&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;method&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;GET&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;token&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;body&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{})&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="nx"&gt;method&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

    &lt;span class="na"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

      &lt;span class="na"&gt;Authorization&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;`Bearer &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;token&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

      &lt;span class="p"&gt;...(&lt;/span&gt;&lt;span class="nx"&gt;body&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Content-Type&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;application/json&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{}),&lt;/span&gt;

    &lt;span class="p"&gt;},&lt;/span&gt;

    &lt;span class="na"&gt;body&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;body&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;undefined&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

    &lt;span class="na"&gt;signal&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;AbortSignal&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;timeout&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;15&lt;/span&gt;&lt;span class="nx"&gt;_000&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;

  &lt;span class="p"&gt;});&lt;/span&gt;

  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;status&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;401&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;AUTH_REQUIRED&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;status&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;429&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;RATE_LIMITED&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;ok&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`API_HTTP_&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;status&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This helper deliberately avoids logging the request URL because some legacy APIs accept credentials in query parameters. Prefer Authorization headers whenever supported. Rate-limit responses should be handled according to the provider's Retry-After guidance, with a bounded retry policy for safe reads.&lt;/p&gt;

&lt;h2&gt;
  
  
  Keep authentication lifecycle separate from publication
&lt;/h2&gt;

&lt;p&gt;For OAuth providers, access tokens typically expire before refresh tokens. A refresh operation is a credential-management step, not a reason to retry a post blindly. Refresh securely, then inspect remote publication history before deciding whether a previous attempt needs to be repeated. For app-password systems, create a session for each short-lived job and discard the session afterward.&lt;/p&gt;

&lt;p&gt;Record the destination, account identifier, and token expiry where appropriate, but never the token itself. If authentication fails, stop the workflow with a nonzero exit code. A green workflow that silently skipped a broken publisher is a misleading operational signal.&lt;/p&gt;

&lt;h2&gt;
  
  
  Make the queue claim atomic
&lt;/h2&gt;

&lt;p&gt;Two GitHub scheduled jobs may overlap because cron runs can be delayed. The database should offer an atomic transition from approved to claimed, so that only one worker owns a post. A plain GET followed by POST is not sufficient protection against a race condition. If the queue is empty, an optional curated fallback may run, but only after it confirms the intended account and scans for previously published content.&lt;/p&gt;

&lt;h2&gt;
  
  
  Design publication as a state machine
&lt;/h2&gt;

&lt;p&gt;Use explicit states: approved, claimed, published, and failed. Save the remote ID and URL after the provider confirms creation. A remote ID is stronger evidence than a successful process exit; a publicly accessible post URL is stronger still. A network timeout during a create request is an &lt;em&gt;uncertain outcome&lt;/em&gt;, not proof of failure.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;
&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;publishClaimed&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;provider&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;known&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;provider&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;findByFingerprint&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;fingerprint&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;known&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;status&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;published&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;remoteId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;known&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;

  &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;created&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;provider&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;create&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;created&lt;/span&gt;&lt;span class="p"&gt;?.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;NO_REMOTE_ID&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;status&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;published&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;remoteId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;created&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;

  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="c1"&gt;// A write may have succeeded before the connection failed.&lt;/span&gt;

    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;TimeoutError&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;AbortError&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;status&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;uncertain&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;reason&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;CHECK_REMOTE_BEFORE_RETRY&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;

    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The provider adapter must implement findByFingerprint using the platform's actual read API. This example is a design pattern, not a drop-in implementation: some providers do not support a fingerprint query. In those cases, scan the account's recent posts, store a durable local publication ledger, or use an idempotency key if the API supports one.&lt;/p&gt;

&lt;h2&gt;
  
  
  Handle pagination and duplicate detection honestly
&lt;/h2&gt;

&lt;p&gt;Fetching the first 100 posts is not a complete history check for a long-lived account. Follow pagination until you have covered the entire relevant window, or stop publishing if you cannot establish that a candidate is unused. A fixed list of ten fallback messages will eventually be exhausted. Treat exhaustion as a normal no-op and generate new editorially reviewed content separately; do not silently cycle the same copy.&lt;/p&gt;

&lt;p&gt;Use a stable fingerprint derived from normalized text and destination URL. Preserve the original text for exact comparisons when platforms expose it. A cryptographic hash can identify your own content, but a remote API cannot search by that hash unless you also store a ledger or add an allowed marker.&lt;/p&gt;

&lt;h2&gt;
  
  
  Configure GitHub Actions to fail visibly
&lt;/h2&gt;

&lt;p&gt;Run syntax checks and dry-run authentication on code changes. Reserve live publication for a scheduled or explicitly authorized job. GitHub cron is best-effort: it can start late, so evaluate publishing windows in the intended timezone and account for daylight saving time. Avoid broad windows that let multiple delayed runs publish the same fallback post without a shared lock.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;
&lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Safe publisher&lt;/span&gt;

&lt;span class="na"&gt;on&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;

  &lt;span class="na"&gt;workflow_dispatch&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;

    &lt;span class="na"&gt;inputs&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;

      &lt;span class="na"&gt;dry_run&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;

        &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;boolean&lt;/span&gt;

        &lt;span class="na"&gt;default&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;

&lt;span class="na"&gt;jobs&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;

  &lt;span class="na"&gt;check&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;

    &lt;span class="na"&gt;runs-on&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;ubuntu-latest&lt;/span&gt;

    &lt;span class="na"&gt;steps&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;

      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;actions/checkout@v4&lt;/span&gt;

      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;actions/setup-node@v4&lt;/span&gt;

        &lt;span class="na"&gt;with&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;

          &lt;span class="na"&gt;node-version&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;24'&lt;/span&gt;

      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;node --check publisher.js&lt;/span&gt;

      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Run publisher&lt;/span&gt;

        &lt;span class="na"&gt;env&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;

          &lt;span class="na"&gt;PLATFORM_TOKEN&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;${{ secrets.PLATFORM_TOKEN }}&lt;/span&gt;

          &lt;span class="na"&gt;DRY_RUN&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;${{ inputs.dry_run }}&lt;/span&gt;

        &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;node publisher.js&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Never interpret a successful syntax check or dry run as a published post. For live runs, emit structured, non-sensitive fields such as platform, slot, claimed item ID, remote post ID, public URL, and final outcome. The monitoring process should flag missing IDs and repeated empty queues without inventing publication success.&lt;/p&gt;

&lt;h2&gt;
  
  
  Test the failure paths before enabling automation
&lt;/h2&gt;

&lt;p&gt;Test with an invalid token, an empty queue, a 429 response, a delayed cron execution, and a simulated timeout immediately after a write. Also test the case where the remote post exists but the local database update fails. In that case, reconcile the remote ID instead of posting again. Keep dry runs side-effect-free, including avoiding state changes that would consume queued content.&lt;/p&gt;

&lt;h2&gt;
  
  
  A practical operating checklist
&lt;/h2&gt;

&lt;p&gt;Before enabling a new destination, verify the account identity, permissions, token rotation process, duplicate detection, timeout behavior, scheduled timezone, and evidence logs. Confirm that an error produces a failed job and that a genuinely empty queue produces an explicit no-op. Review published links periodically, because an API response can succeed even if a platform later moderates or removes content.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Reliable multi-platform publishing depends on state, not just schedules. Keep secrets isolated, make queue claims atomic, reconcile uncertain writes, and require remote evidence before calling a publication successful. Those controls are less glamorous than adding another social network, but they are what make unattended automation maintainable.&lt;/p&gt;

&lt;p&gt;Source: &lt;a href="https://github.com/danielmason77/danielmason-threads-publisher/blob/main/content-library/dev-community/api-authentication-across-multiple-platforms-a-practical-implementation-guide.md" rel="noopener noreferrer"&gt;https://github.com/danielmason77/danielmason-threads-publisher/blob/main/content-library/dev-community/api-authentication-across-multiple-platforms-a-practical-implementation-guide.md&lt;/a&gt;&lt;/p&gt;

</description>
      <category>automation</category>
      <category>webdev</category>
      <category>github</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
