<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Dead Letter Queue]]></title><description><![CDATA[Dead Letter Queue]]></description><link>https://deadletterqueue.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Fri, 04 Dec 2026 21:39:25 GMT</lastBuildDate><atom:link href="https://deadletterqueue.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Selenium and reCAPTCHA: waiting for the token without flaky retries]]></title><description><![CDATA[You click the checkbox, the spinner does its little dance, and your Selenium test sits there hoping that a token appears. If the wait is too short, the…]]></description><link>https://deadletterqueue.hashnode.dev/selenium-recaptcha-waiting-for-token-without-flaky-retries</link><guid isPermaLink="true">https://deadletterqueue.hashnode.dev/selenium-recaptcha-waiting-for-token-without-flaky-retries</guid><category><![CDATA[selenium]]></category><category><![CDATA[recaptcha]]></category><category><![CDATA[Testing]]></category><dc:creator><![CDATA[fobofy2975]]></dc:creator><pubDate>Sat, 28 Nov 2026 23:00:29 GMT</pubDate><content:encoded><![CDATA[<p>You click the checkbox, the spinner does its little dance, and your Selenium test sits there hoping that a token appears. If the wait is too short, the form submits with an empty <code>g-recaptcha-response</code>. If it is too long, the suite crawls. Both outcomes come from the same mistake: the test is waiting on the wrong thing.</p>
<h2>Why fixed sleeps make the suite flaky</h2>
<p>A reCAPTCHA v2 widget is not a normal input. The checkbox only proves that a user interacted with the widget. The actual proof is the token that Google drops into a hidden textarea, usually <code>textarea#g-recaptcha-response</code>. That token is what your form sends to the server.</p>
<p>The problem is timing. Sometimes the checkbox fills the textarea in half a second. Sometimes a challenge is shown and the same step takes ten seconds. Sometimes the token never arrives because the browser environment looks suspicious. A fixed <code>time.sleep(10)</code> is a bet, and it loses in both directions: short sleeps fail on slow runs, long sleeps make every run slower.</p>
<p>A <code>WebDriverWait</code> aimed at the textarea feels more precise, but it is still flaky. The textarea exists from the start and may be empty for a long time, so waiting for its presence proves nothing. Waiting for its value to become non-empty can work, yet it mixes two concerns: the test is polling a DOM side effect while the token is produced somewhere else. If the token expires before submission, the test can even pass locally and fail in CI.</p>
<p>There is a cleaner approach: do not wait for the DOM at all. Solve the captcha through an API first, poll that API for the token, and inject the token into the page. The wait becomes deterministic because it is tied to a server-side status, not to a widget animation.</p>
<h2>Solve the captcha outside the browser</h2>
<p>NeuroCaptcha exposes a <code>createTask</code> method that accepts a <code>RecaptchaV2TaskProxyless</code> task. Send the page URL and the site key, and the service returns a <code>taskId</code> while the price is held, not charged.</p>
<pre><code class="language-json">{
  "clientKey": "YOUR_API_KEY",
  "task": {
    "type": "RecaptchaV2TaskProxyless",
    "websiteURL": "https://www.google.com/recaptcha/api2/demo",
    "websiteKey": "6Le-wvkSAAAAAPBMRTvw0Q4Muexq9bi0DJwx_mJ-"
  }
}
</code></pre>
<p>You find the site key in the widget's <code>data-sitekey</code> attribute or in the <code>k</code> parameter of the <code>anchor</code> request in DevTools. If the page shows only a badge, set <code>isInvisible: true</code>. For widgets loaded from <code>www.recaptcha.net</code> you can pass <code>apiDomain</code>. If your browser sends a custom User-Agent, pass it as <code>userAgent</code> so the service returns the token with that value.</p>
<p>Then poll <code>getTaskResult</code> every two seconds. When <code>status</code> becomes <code>ready</code>, the token is in <code>solution.gRecaptchaResponse</code>. The response also carries <code>cost</code>, <code>ip</code>, and <code>solveCount</code>, so you can log exactly what happened. This polling loop is the only wait that matters, and it is bounded by a deadline rather than by a blind guess. A failed task costs nothing and returns an error code, which makes it safe to create a fresh task and try again. The proxyless v2 type costs $0.0006 per solved task, so one clean retry is cheaper than a red build.</p>
<h2>Waiting in Selenium without retries</h2>
<p>The Selenium side becomes a three-step script: read the site key from the live page, wait for the API token, then inject the token and submit.</p>
<pre><code class="language-python">from selenium import webdriver
import requests, time, os

API = "https://api.neurocaptcha.com"
KEY = os.environ["API_KEY"]

driver = webdriver.Chrome()
driver.get("https://www.google.com/recaptcha/api2/demo")

sitekey = driver.find_element("css selector", ".g-recaptcha").get_attribute("data-sitekey")

def call(method, payload):
    data = requests.post(
        f"{API}/{method}", json={"clientKey": KEY, **payload}, timeout=30
    ).json()
    if data.get("errorId"):
        raise RuntimeError(data.get("errorCode"))
    return data

task_id = call("createTask", {"task": {
    "type": "RecaptchaV2TaskProxyless",
    "websiteURL": driver.current_url,
    "websiteKey": sitekey,
}})["taskId"]

deadline = time.time() + 300
token = None
while time.time() &lt; deadline:
    time.sleep(2)
    result = call("getTaskResult", {"taskId": task_id})
    if result.get("status") == "ready":
        token = result["solution"]["gRecaptchaResponse"]
        break

if token is None:
    raise TimeoutError("the task was not solved in time")

driver.execute_script(
    """
    var ta = document.getElementById('g-recaptcha-response');
    ta.value = arguments[0];
    var submit = document.getElementById('recaptcha-demo-submit');
    if (submit) { submit.removeAttribute('disabled'); }
    """,
    token,
)
driver.find_element("css selector", "#recaptcha-demo-submit").click()
</code></pre>
<p>Notice what is missing: no <code>WebDriverWait</code>, no <code>expected_conditions</code>, no retry loop around the textarea. The API poll already did the waiting. The browser only receives the finished token and uses it.</p>
<p>Injection is the one browser step that has to be careful. Set the textarea value directly, then re-enable whatever button the page disabled. Some pages do not use a submit button at all; they call the function named in the widget's <code>data-callback</code> attribute. In that case, call the callback after setting the textarea value, for example <code>window[arguments[0]]()</code> if the callback name is exposed globally. The widget's own JavaScript will then run as if the user solved the challenge in place.</p>
<p>A few details keep this reliable. Poll the task from Python, not from the browser, so the Selenium session stays clean. Store the site key from the page at runtime instead of hardcoding it. If the site binds tokens to the IP address, switch to a proxy task type. Keep the deadline shorter than the token lifetime and submit as soon as <code>ready</code> arrives.</p>
<p>The same pattern works for invisible v2 widgets and for pages that replace the checkbox with a badge. In those cases there is nothing to click and no visible state to watch, so a DOM wait is hopeless; the API task is the only reliable signal. Enterprise and v3 variants work the same way through their own task types, with the token going into the field your application already expects.</p>
<p>When the flow is arranged this way, the test waits for one clear event: the API says <code>ready</code>. Everything else is just moving data into the right field.</p>
<p>When you are ready to stop clicking checkboxes, grab an API key at <a href="https://neurocaptcha.com/en/register">https://neurocaptcha.com/en/register</a>.</p>
]]></content:encoded></item><item><title><![CDATA[Solving reCAPTCHA v2 tokens server-side: what the API response actually gives you]]></title><description><![CDATA[A reCAPTCHA v2 token looks like a random slab of base64, but the moment you receive one a quiet clock starts ticking. It is not a score, it is not a…]]></description><link>https://deadletterqueue.hashnode.dev/solving-recaptcha-v2-tokens-server-side-what-the-api-response-actually-gives-you</link><guid isPermaLink="true">https://deadletterqueue.hashnode.dev/solving-recaptcha-v2-tokens-server-side-what-the-api-response-actually-gives-you</guid><category><![CDATA[recaptcha]]></category><category><![CDATA[api]]></category><category><![CDATA[captcha]]></category><dc:creator><![CDATA[fobofy2975]]></dc:creator><pubDate>Sat, 28 Nov 2026 22:26:44 GMT</pubDate><content:encoded><![CDATA[<p>A reCAPTCHA v2 token looks like a random slab of base64, but the moment you receive one a quiet clock starts ticking. It is not a score, it is not a verdict, and it is not something you should ever try to parse. It is a short-lived ticket that you hand back to the target site, and understanding its shape and its deadline is the difference between a clean server-side integration and a form that fails for no obvious reason.</p>
<h2>What a v2 token actually is</h2>
<p>When a visitor ticks the "I'm not a robot" checkbox, the reCAPTCHA widget produces a response token and writes it into a hidden field named g-recaptcha-response. The token is a long opaque string that typically starts with 03A, with example values beginning like 03AFcWeA6Z3vq0VhGm1oS8r0bAxKk4. Each solve produces a fresh value, so do not bother caching or comparing tokens. There is nothing useful inside the string for you to decode. Your job is only to deliver it to the form field or to the page's callback at the right time.</p>
<p>That is the first mental shift. A v2 token is proof of a solved challenge, but it proves nothing by itself until the target server verifies it with Google. If you hold on to it too long, it stops working. If you submit it to the wrong site key, it never works. Treat it as an expiring transport object, not as data.</p>
<p>When you solve through an API instead of a browser, nothing changes about that handoff. The solving service returns the same kind of response token, and your code still has to put it into g-recaptcha-response before the form is sent. The only difference is that the checkbox, the image challenge, and the waiting happen somewhere else, on the service's side.</p>
<h2>What the API response actually gives you</h2>
<p>NeuroCaptcha is an HTTP API that returns reCAPTCHA tokens and speaks the Anti-Captcha JSON protocol. You call createTask with your clientKey and a task object that names the type, the page address, and the reCAPTCHA site key. For reCAPTCHA v2 without your own proxy the type is RecaptchaV2TaskProxyless; with a proxy it is RecaptchaV2Task. The task types page lists them at the same rate, so the choice is about routing, not cost. The immediate answer is small: errorId plus a numeric taskId. The price of the task is held on your balance and charged only when the task is solved.</p>
<p>Then you poll getTaskResult with that taskId every two or three seconds. While the worker is still solving, the response says status processing. When it is done, the status flips to ready and the response carries the field you actually need: solution.gRecaptchaResponse. That field is the token to put into g-recaptcha-response. Alongside it the response includes cost, the IP address used, createTime, endTime, and solveCount. You do not need to parse the token; you only need to copy solution.gRecaptchaResponse into the form and submit.</p>
<p>Every response arrives as HTTP 200 with an errorId field, where zero means success. That uniformity matters on the server: you can check one field first and only then look at status. The rest of the payload is useful for logging and accounting, but the single value that moves the integration forward is the token.</p>
<h2>The 120-second window and honest failure handling</h2>
<p>The reason you solve at the moment of form submission is simple: Google tokens expire quickly. The docs tell you to submit within about two minutes, which is the practical lifetime that matters. If you solve a captcha when the user first lands on the page and only submit minutes later after they fill in their details, you risk handing the target site a dead token. The API keeps the solved result for ten minutes, so there is slack on the solving side, but the Google side does not wait.</p>
<p>This is also why error handling deserves a real retry path rather than a log line. A task can fail, and one of the codes you should expect is ERROR_CAPTCHA_UNSOLVABLE. When that happens, the task has not cost you anything, and the correct move is to create a new task and poll again. Test keys are deliberately useful here: their tokens start with TEST_ and are not accepted by Google, and roughly three tasks in a hundred fail with ERROR_CAPTCHA_UNSOLVABLE so that your retry and error branches get exercised before real traffic does. Live keys behave the same way on the rare genuinely unsolvable challenge, so the retry loop you build against a test key is exactly the loop you run in production.</p>
<p>In short, build the integration around three rules. Ask for the token only when the form is about to be submitted. Read status, not the token itself, for control flow. And treat a failed task as a normal, retryable event rather than an exception that ends the request. The API gives you everything you need for that: a task id, a polling loop, a ready token, and clear error codes.</p>
<p>If you want to wire this up yourself, start with a test key: <a href="https://neurocaptcha.com/en/register">free test keys, no email needed</a>.</p>
]]></content:encoded></item><item><title><![CDATA[Two queues, one of which nobody watches]]></title><description><![CDATA[A manager once asked why we had two queues when the work looked like one, and the engineer who built them said the second one was for things that would…]]></description><link>https://deadletterqueue.hashnode.dev/two-queues-one-of-which-nobody-watches</link><guid isPermaLink="true">https://deadletterqueue.hashnode.dev/two-queues-one-of-which-nobody-watches</guid><dc:creator><![CDATA[fobofy2975]]></dc:creator><pubDate>Sat, 28 Nov 2026 22:03:54 GMT</pubDate><content:encoded><![CDATA[<p>A manager once asked why we had two queues when the work looked like one, and the engineer who built them said the second one was for things that would never get read, and then had to spend the rest of the meeting explaining why he had built it on purpose.</p>
<p>The system has one queue for work and one queue for the dead letters that fall out of the first. The work queue is watched by a dashboard and a pager and three people who can describe its shape from memory. The dead letter queue is watched by nobody, and that is not an accident, it is the design, because a queue nobody watches is the only honest place to put things whose status nobody knows yet.</p>
<p>The first queue is the one I have spent most of my time on, and it is ordinary. Jobs go in, workers take them, results come out, and a set of counters says how many are waiting and how many are late. Most of the interesting decisions are about order and priority and how many workers to run, and those decisions are visible in the dashboard and debated in the weekly call. The second queue has none of that. It has no priority, no worker, and no SLA, and it is exactly the lack of those things that makes it valuable.</p>
<p>A <code>dead letter</code> is what you get when a job has been tried, and failed, and retried, and failed again, and the retry policy has given up. The temptation is to leave that job in the work queue with a state of failed, but a failed job in the work queue is a job that is still in the room, still visible to the workers, still eligible for a mistake. Moving it to a queue nobody watches is not abandonment, it is quarantine, and quarantine is what you do with a thing whose failure you do not understand yet, because you want to keep it without letting it touch anything.</p>
<p>The rule for the dead letter queue is that it has a reader, just not an automatic one. A human reads it once a day, and the human's job is not to fix anything, it is to sort. Some dead letters are duplicates of a real failure and can be deleted. Some are waiting on an external system that is down and should be replayed later. Some are malformed and will never succeed and should be documented and dropped. Some are interesting, in a bad way, and those are the ones the queue exists to collect, because the interesting ones are the ones the first queue would have lost.</p>
<p>The sort takes about five minutes, which is the number I always have to defend, because five minutes a day sounds like a cost and the alternative sounds like zero. The alternative is not zero. Without the quarantine, the malformed job stays in the work queue and is retried forever by a loop that was written to be persistent, and the interesting failure gets buried under a thousand ordinary ones, and the duplicate gets retried into a duplicate, and the thing that was waiting on an external system gets retried into a ban. Five minutes a day is the cheapest insurance I have ever bought.</p>
<p>The deeper reason for two queues is that a single queue mixes two kinds of work that need two kinds of attention. A work queue needs speed and order and a fast answer. A failure needs a slow answer and a place to wait without blocking the fast path. When both kinds of work live in the same queue, the queue becomes a compromise that does neither well, and the dashboard becomes a summary that hides the failures inside the successes, because a queue with a hundred items and three failures looks healthy, and a queue with three failures in quarantine and a hundred items moving looks healthy in a different and more honest way.</p>
<p>I built the second queue after an incident in which a single malformed job sat at the head of the work queue for a weekend and blocked every job behind it. The worker would take the job, fail, and return it to the front, and the retry policy would wait the same short amount and try again, and the jobs behind it got older and older while the dashboard showed one item processing, which looked fine. The malformed job was eventually fixed by hand, but only after the customer whose work sat behind it called. A dead letter queue with a poison message rule would have moved that job aside after the second failure and let the rest of the queue breathe.</p>
<p>The poison message rule is the part people get wrong, so I will be precise. A job is not poison because it failed, and it is not poison because it failed twice, and if I moved every failure to quarantine I would have a second queue that is just the first queue's shadow. A job is poison when the failure is repeatable and local, meaning the same job fails the same way every time and the failure is in the job, not in the network. The test for that is to retry it with the same content and watch whether the error is identical, and if it is, the job is poison and it will never succeed by waiting, and it goes to the room nobody watches.</p>
<p>There is a second queue in the same system that is even less watched than the dead letter one, and it is the archive of jobs that succeeded, and it is the one I have come to value most. A job that succeeded is not done, it is evidence, and evidence needs a place to live where it will not be mixed with the living work. The archive is append only, it is never read by the workers, and it has answered every question that ever started with the words what happened on that day, which is the question that comes after every incident. A queue nobody watches is not always a grave. Sometimes it is a library.</p>
<p>The two queues, work and dead letters, are connected by a small bit of code that moves a job from the first to the second, and that code is the only thing I have ever written that I would call a policy rather than a function. It says: after this many attempts, with this backoff, if the error is local, move the job aside and do not retry it automatically. The word <code>aside</code> does all the work, because it preserves the job, which is the thing a retry loop is too optimistic to do. A retry loop believes the next attempt will be different. The quarantine knows that sometimes it will not be, and it is the only part of the system that is allowed to be pessimistic.</p>
<p>The manager's question was a good one and the engineer's answer was incomplete in a useful way, because he said the second queue was for things that would never get read and then spent the rest of the meeting proving that they would be read exactly once, by one person, slowly, on purpose. The difference between never and once is the difference between a graveyard and a review, and the review is what turns a dead letter into a rule, which is the only thing a failure is good for.</p>
<p>I have since added the same two queue shape to three other systems, and each time the second queue started as an empty table and ended as the most interesting table in the database, and the weekend with the malformed job at the head of the line is written down in <a href="https://blue-nanine-77.tiiny.site/posts/two-queues-one-of-which-nobody-watches/">two queues, one of which nobody watches</a>. The work queue answers the question of what is happening now, and the dead letter queue answers the question of what we should change next, since <a href="https://neurocaptcha.com/en/register">NeuroCaptcha</a> is the one queue in this stack where the answer arrives on the first attempt and the dead letter stays empty.</p>
]]></content:encoded></item></channel></rss>