On November 14 at 09:42:55 my publisher clicked the publish button in a blog platform's web editor. The page did not navigate and no CAPTCHA appeared. From then on, every scheduled run returned the same line, {"status": "awaiting_captcha"}, and never pressed the button again. The post was not public, and the CAPTCHA relay had no tab to show me, because there was no CAPTCHA.
When I went looking, it was not the first time. The state files held 16 runs stuck in phase=screen_clicked, spread across two queue entries. The run logs recorded the click results as captcha=True 37 times and captcha=False 4 times. This note is about why a wait state with only one way out turned every failure into more waiting, and how I gave it a second and third way out while guarding against a duplicate post.
The publisher is an unattended job that runs every 15 minutes. It drives a browser through the platform's editor and clicks publish. When the platform answers with a CAPTCHA, a relay forwards it to me, I answer, and the post goes public. The job then finds the new post in my post list and records it as published. Each run keeps a small state file with a phase field; after the click, the phase is screen_clicked.
The function that drives a run, screen_publish_task, handled phase == 'screen_clicked' like this: if the new post was not in the owner's post list, return awaiting_captcha. There was no other condition.
That left exactly two ways out of the state:
The second is a timeout for the whole run, not for the wait. Nothing checked whether a CAPTCHA was actually on screen. Two real situations fell into that gap:
captcha=False).In both cases the post would never appear. Until the run expired, the job reported awaiting_captcha every 15 minutes, the same line a healthy run prints while it waits for me.
The log for the November 14 run showed the first case:
screen press left for the captcha relay (captcha=False, dialogs=['<a dialog asking whether to change the writing mode>'])
When I checked the browser profile at 11:12, there was no editor tab at all. I did not confirm why the click raised that dialog instead of publishing.
I added two constants:
PRESS_SETTLE = timedelta(minutes=10)
MAX_RELEASES = 2
The 10 minutes covers the 5-minute CAPTCHA answer window plus a late publication, and matches the settle value another of my queues uses.
When the phase is screen_clicked and the post is not in the list, the job now calls _release_or_wait, which decides between three outcomes:
window.name carries the entry and revision) is showing a CAPTCHA: wait. That one belongs to the relay. If the check for a CAPTCHA on that tagged tab fails, it also waits, because waiting is safer than publishing twice.phase=screen_released, increments releases, and records released_at and released_click. Then it falls back to the ordinary publish path.The ordinary path has its own gate. If a press-now permission flag is not set, the released run goes back into the queue as press_deferred. If it is set, the job presses again on the spot.
If a run has already been released 2 times, the job does not press again. It returns {"status": "failed", "reason": "press_unconfirmed"}, main exits with rc=2, and the queue summary shows it as a failure. That gives the wait a third exit: an honest failure that I can see, instead of another awaiting_captcha.
A release ends in another click, and a second click is how you get two copies of a post. Before releasing, the job runs _post_after at the start of the same run with visibility=all. It looks for a post with the same title and an id newer than the latest id recorded before the click, and it checks both public and private posts. Only when there is none does the release go ahead.
The unattended 15-minute job does not hold the press-now permission. In practice that means a released run is only put back into the queue. It gets pressed again, and a CAPTCHA reaches me, only when I send "publish" in my chat approval message.
I wrote 7 regression tests, one per new branch: waiting before 10 minutes, re-pressing with no post and no tab, waiting on a CAPTCHA tab, closing a leftover tab without a CAPTCHA, recording a post that appears after 10 minutes, failed press_unconfirmed after 2 releases, and press_deferred with screen_released when permission is missing. The publisher's test file passed 23/23. The full suite showed 6592 passing and 31 failing. The 31 failures sit in 8 files, none of which import the publisher module, so I do not think this change caused them. That still needs a separate check; I have not confirmed what causes them.
For the stuck run, the admin screen's title search found nothing. I moved the stuck state file aside instead of deleting it and re-ran the same command with the press-now permission set. This time the click returned captcha=True, I answered it, and the post went public at 11:25:13. At 11:31 the regular 15-minute run, now on the new code, logged that it found the post after the press and recorded it as published, with the state at phase=public and publication_confirmed: true.
The defect sat in what the waiting state accepted as a reason to stop waiting. With success as the only exit, every outcome that would never become success was reported as still waiting, in the same words as a healthy run, and 16 stuck runs built up before one made me look. The fix re-evaluates the wait once the CAPTCHA window has passed, keeps waiting only while the tab tagged for this run shows a CAPTCHA (or its CAPTCHA check fails), and otherwise releases, with a visible failure once 2 releases are used up.
I wrote down two conditions:
phase=screen_clicked for more than 30 minutes, the fix failed.MAX_RELEASES = 0 immediately.The duplicate guard depends on _post_after seeing the first post when the job checks, and on the release closing the tabs tagged for this run before a late answer lands; a tab whose tag it cannot confirm is not in that set. The stuck post above does not test that path: I cleared its state by hand and approved the re-press myself, and the regular run only found and recorded the result. No live run has gone through _release_or_wait releasing a run yet, as far as this record shows. The cause of the 31 suite failures is also still unchecked.
When the phase was screen_clicked and the new post was not in the post list, screen_publish_task returned awaiting_captcha with no other condition. The only exits were the post appearing or the whole run expiring, so a click that made neither a CAPTCHA nor a post, or a CAPTCHA that expired unanswered, waited until the run ended.
Before PRESS_SETTLE (10 minutes) it waits. After that it keeps waiting while this run's tagged tab is showing a CAPTCHA, or while the CAPTCHA check on that tagged tab fails. Otherwise it closes the tabs it can confirm carry this run's tag, marks the phase screen_released and goes back to the normal publish path.
Before releasing, _post_after checks with visibility=all for a public or private post with the same title and a newer id than before the click. The release also closes the tabs confirmed as tagged for this run to make it less likely that a late CAPTCHA answer creates a second post, and the unattended job only re-queues a released run as press_deferred until I approve it. The guard reduces the risk; a duplicate is one of the two conditions that would show the fix is wrong.
The release limit only applies once a run has passed the wait checks. If it would be released again after 2 releases (MAX_RELEASES), the job does not press. It returns failed with reason press_unconfirmed, exits with rc=2, and the queue summary shows it as a failure.
If by November 28 a current run is stuck in screen_clicked for more than 30 minutes, the fix failed. If the same post is published twice, the re-click condition is wrong and MAX_RELEASES goes to 0 immediately.