On the evening of 27 November I merged the subscribe page for this blog. The site deployed, and the RSS feed had five new items at the top: “Get New Posts by Email”, “Check Your Inbox”, “Confirm Your Subscription”, “You’re Subscribed” and “That Link Has Expired”. Every feed reader watching the site saw five new posts, and so did the bot that relays the feed into a Discord channel.

The channel’s a personal one on my Discord, but I was still shocked watching it blow up from my own site. I’m sure anyone else who’d put the feed in their RSS reader felt the same.

The fix merged ten minutes after the page did. It had company. Between that Friday evening and Sunday afternoon I merged eight pull requests to add email notifications for new posts, and half of them were fixes for the ones before. This is the last of three posts about that work. Emailing New Posts From a Hugo Deploy With Amazon SES covers the sending side and A Double Opt-In Signup Form on Azure Static Web Apps covers the signup form. This one is the list of what went wrong once the code met the real services. The current code quoted here is the sanitized copy in Hugo/new-post-email in my companion repo.

Five pages at the top of the feed

The subscribe flow is five Markdown files in content/: the form and four helper pages. I’d marked the helpers robotsNoIndex and searchHidden and taken them out of the sitemap. The feed wasn’t on that list.

PaperMod’s rss.xml builds the home feed from every regular page on the site:

1
2
3
4
5
6
7
{{- $pages := slice }}
{{- if or $.IsHome $.IsSection }}
{{- $pages = $pctx.RegularPages }}
{{- else }}
{{- $pages = $pctx.Pages }}
{{- end }}
{{- $pages = where $pages "Params.hiddenInRss" "!=" true -}}

A regular page is any single content file. Your posts are regular pages, and so is your About page, and so is a confirmation page. The only way out is that last line, a hiddenInRss parameter on the page. If you run PaperMod and have ever wondered why a new page showed up in your feed, this is why.

That means About, Resources and Start Here had been eligible for the feed all along. They stayed out because the feed keeps the 20 newest items and those pages are old. The subscribe pages were dated that evening at 19:30 Pacific, newer than any post, so they took the top five places. Editing the About page and giving it a new date would have done the same thing with one item.

I could have added hiddenInRss: true to five files. That fixes these pages and leaves the trap set for the next one. A cascade in hugo.toml sets it on every top-level page (it’s in hugo.example.toml in the companion folder):

1
2
3
4
[[cascade]]
  hiddenInRss = true
  [cascade.target]
    path = '/*'

path = '/*' matches each content file at the top level. content/about.md is /about and content/subscribe-confirm.md is /subscribe-confirm. A post lives at /posts/<slug>, one level down, so the pattern doesn’t touch it. The gap that’s left is a page in some other subfolder, and I wrote that down in the repo’s notes for whoever adds one.

After the fix, a production build had 20 items in index.xml, all posts, with the newest post first again.

Fixing the feed doesn’t unsend anything, and you don’t control what a reader does next. The five items left the feed and five older posts moved back into the 20-item window. Whether a reader announces those as new depends on how it decides what’s new. One that remembers the newest date it has seen won’t, since they’re older than anything it already posted. The five messages already in Discord stayed in Discord.

I cleaned up the channel by hand, and new posts have come through normally since.

An error message cut off before the cause

Earlier that same evening, the first real test send through SES had been refused. The Actions log said this (the account ID is a stand-in):

1
aws sesv2 send-email failed: aws: [ERROR]: An error occurred (AccessDeniedException) when calling the SendEmail operation: User 'arn:aws:sts::111122223333:assumed-role/gh-blog-send/GitHubActions' is

And stopped. My script kept the first 200 characters of an error, and as you can see, the AWS CLI spends most of 200 characters on its own prefixes and the role’s ARN. The useful half of the sentence came right after the cut:

1
on resource 'arn:aws:ses:us-west-2:111122223333:identity/test-address@example.com'

The resource SES refused was the recipient’s identity. I’d scoped the role to send as news@techbyjeff.net. I found the resource by reading the contact’s stored attributes, where the script had saved a slightly longer copy of the error. The log I was staring at had thrown it away.

The error formatter in scripts/lib/Ses.ps1 now strips the CLI’s prefixes, folds the message onto one line and keeps 500 characters of what’s left:

1
2
3
4
5
6
7
function Get-SesErrorText {
    param([string] $Message, [int] $Max = 500, [string] $Hide)
    $t = ($Message -replace '^\s*aws sesv2 \S+ failed:\s*', '' -replace 'aws: \[ERROR\]:\s*', '' -replace '\s+', ' ').Trim()
    if ($Hide) { $t = $t -ireplace [regex]::Escape($Hide), '<recipient>' }
    if ($t.Length -gt $Max) { $t = $t.Substring(0, $Max) + '...' }
    return $t
}

The $Hide parameter came later that weekend. SES sometimes quotes the recipient’s address back in an error, as it did above, and a subscriber’s address has no business in a build log. Every message the script logs now has the address replaced with <recipient> first.

That first test left me with another question. The email arrived at a Proton address with a Content-Type: text/html header, and I’d sent multipart/alternative with a text part and an HTML part. I captured the request and confirmed the script sends both, a 421-character text part and a 2,458-character HTML part. In an issue on hydroxide, a third-party Proton bridge, the maintainer suggests Proton keeps only the HTML part when a message has both. That matches what I saw. I haven’t looked at the raw message in any other mailbox yet.

A fast clock made a reader look like a bot

The signup form has a cheap bot check: a form sent within three seconds of the page loading is treated as a script. My first version did that with a timestamp. The page wrote the current time into a hidden field when it loaded, and the Function subtracted that from its own clock when the form arrived:

1
2
-  document.getElementById('tbj-sub-ts').value = Date.now();
-    if (form.get('website') || !renderedAt || now() - renderedAt < 3000) return done();

Date.now() in the first line is your device’s clock. now() in the second is the server’s. The subtraction only means “time spent on the page” if those two clocks agree.

I found it while testing the live endpoint. One of my test requests was supposed to be “too fast” and get dropped, and it was stored as a real signup, because the test’s timestamp was several seconds old by the time it was sent. That’s the harmless direction. The other direction is a visitor whose device clock runs fast. Say it’s a minute ahead and you take twenty seconds to type your address. The server sees a form that arrived forty seconds before the page loaded, which is less than three seconds, and treats you as a bot. Bots get the normal “Check your inbox” page and no email. You’d have waited for a confirmation that was never sent, with nothing on screen to say why.

The page now measures how long it’s been open and sends that:

1
2
3
4
5
6
+  // How long the page has been open, in ms. performance.now() counts from page load and
+  // ignores the device clock, so a clock that is off can't make a signup look like a bot.
+  document.querySelector('.tbj-subscribe').addEventListener('submit', function () {
+    document.getElementById('tbj-sub-elapsed').value = Math.round(performance.now());
+  });
+    if (form.get('website') || !Number.isFinite(elapsed) || elapsed < MIN_ELAPSED_MS) return done();

performance.now() counts milliseconds from page load on a monotonic clock, and you can change the system time without moving it. The server reads one number and compares it to 3,000. A bot can fake elapsed as easily as it could fake the timestamp, so the check is no stronger than before. It just stopped catching people.

The test for it signs up with the server’s clock moved a day in each direction and expects both to go through.

Cache headers on the API responses

The site sends cache-control: public, max-age=600 by default, set under globalHeaders in staticwebapp.config.json. I didn’t want that on the signup Functions’ redirects, so the first version added a route rule:

1
2
{ "route": "/api/*",
  "headers": { "cache-control": "no-store" } },

Then I looked at a live response:

1
2
3
HTTP/1.1 303 See Other
Location: /subscribe/?invalid=1
Strict-Transport-Security: max-age=31536000; includeSubDomains

No cache-control header at all. The route rule had done nothing, and neither had the global header I was trying to override. Microsoft’s configuration reference does say so, in a note under global headers: they don’t affect API responses, and whatever headers the API sets are passed through to the client. If you host Functions behind Azure Static Web Apps, your API’s headers are yours to set.

Nothing was being cached anyway, since a 303 answer to a POST isn’t cacheable without a header saying so. I still wanted the intent in code that runs, at the top of api/src/lib/handlers.js:

1
2
3
// SWA applies none of staticwebapp.config.json's headers to API responses, so the
// Functions say no-store themselves.
const redirect = (path) => ({ status: 303, headers: { Location: path, 'Cache-Control': 'no-store' } });

Every answer either Function gives goes through redirect, there’s a test that checks each one carries the header, and the route rule is gone.

SES clears attributes you leave out

An SES contact has a free-form AttributesData string you can put anything in, and I store JSON in it: the signup’s one-time code and timestamps, and the send script’s record of which posts the contact has had. Two programs write to the same field.

On 27 November I watched an UpdateContact call that didn’t include AttributesData wipe the attributes on a live contact. Every write from the signup side now sends the complete attribute set, read first and merged.

The natural next assumption is that TopicPreferences behaves the same way, and that would be worse: recording “sent” on a contact would reset their subscription. AWS’s reference for UpdateContact has a note that reads like a warning about just that. You have to pass every existing topic preference, it says, “otherwise, all your existing preferences will be removed.” That note is about passing a partial list. Leaving the field out altogether is a different request, so I checked it on the live list. The send script’s update carries the result in its comment:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# No TopicPreferences in this call, on purpose. UpdateContact leaves the subscription
# as it is when they are left out, so recording a send cannot undo an unsubscribe
# that landed mid-run. AWS's note on UpdateContact reads the other way; this was
# checked on the live list on 29 November 2026 (an update with only AttributesData
# left the contact OPT_IN). If sends ever stop reaching people, check it again:
# get-contact on the test address after a self send must still show OPT_IN.
Invoke-Ses 'update-contact' @{
    ContactListName = $List
    EmailAddress    = $Email
    AttributesData  = $json
} | Out-Null

Same API call, two fields, opposite behavior when omitted. I only trust each one because I tested it on my own list.

A 1,000-character ceiling on a contact

On 29 November I measured a limit on the live list. SES refuses a longer write with this:

1
Attributes must be valid JSON and it can contain up to 1000 characters

The consequence is specific to how the send script works. It records a post as sending on the contact before it sends, and if that write is refused, it skips the send. At the time the script kept up to 20 slugs per contact plus an error note of up to 400 characters, so a contact would have hit the limit after about 15 posts. From then on, every send to that contact would have been skipped at the first step.

scripts/Send-PostEmail.ps1 now writes to a budget of 850 characters, which leaves about 150 for the signup fields that share the space:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
# Fit the budget. $posts is the same object as $Attributes['posts'], and the post
# being recorded is its last entry, so it is never the one removed.
$json = $Attributes | ConvertTo-Json -Compress -Depth 4
while ($json.Length -gt $AttributeBudget) {
    if ($posts.Count -gt $KeepPostsOverError) { $posts.RemoveAt(0) }
    elseif ($Attributes.Contains('lastError')) { $Attributes.Remove('lastError') }
    elseif ($posts.Count -gt 1) { $posts.RemoveAt(0) }
    else { break }   # what is left is not this script's to remove; SES decides
    $json = $Attributes | ConvertTo-Json -Compress -Depth 4
}

The oldest posts go first, down to five. Then the stored error note goes. Then the rest of the posts, down to the one being recorded. If it still doesn’t fit, what’s left belongs to the signup side and the script lets SES decide.

The stored error note had to shrink too. Two days earlier I’d grown it to 400 characters so the cause of a refusal would survive. With a 1,000-character total that’s most of the room, so it’s now 150 with the middle cut out:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
if ($ErrorText) {
    # The start of SES's sentence names the error and the end says what was denied,
    # so when it is too long the middle is what goes.
    $note = Get-SesErrorText $ErrorText 2000 $Email
    if ($note.Length -gt $MaxErrorChars) {
        $head = [int]($MaxErrorChars * 0.4); $tail = $MaxErrorChars - $head - 3
        $note = $note.Substring(0, $head) + '...' + $note.Substring($note.Length - $tail)
    }
    $Attributes['lastError'] = "${PostSlug}: $note"
}

The start of an SES error names the error and the end says what was denied. The full sentence is still in the Actions log.

In practice a contact remembers about its last ten posts, fewer when slugs are long. Inside that window a post can’t reach the same person twice. Re-sending an older post by hand could reach people who already had it.

The signup Functions trim the same field as a backstop, with the priorities reversed. They give up the send script’s data and keep their own:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
export const ATTRIBUTE_LIMIT = 1000;
export const fitAttributes = (attributes) => {
  const fitted = { ...attributes };
  const tooLong = () => JSON.stringify(fitted).length > ATTRIBUTE_LIMIT;
  if (tooLong()) delete fitted.lastError;
  if (tooLong() && fitted.posts && typeof fitted.posts === 'object' && !Array.isArray(fitted.posts)) {
    const posts = { ...fitted.posts };
    fitted.posts = posts;
    for (const slug of Object.keys(posts)) {
      if (!tooLong()) break;
      delete posts[slug];
    }
  }
  return fitted;
};

If they didn’t, a long-time subscriber who unsubscribed could find the form refusing to let them back in.

list-contacts stops at one page

This one hadn’t bitten yet, since my list fits on one page with room to spare. The first version of the send script read the list with a single call, under this comment:

1
# The CLI follows NextToken itself, so this is the whole list, not a first page.

The AWS CLI does follow NextToken on its own for most list-* commands. For sesv2 list-contacts it doesn’t. The CLI gets its pagination from botocore’s data files, and as of botocore 1.44.13 the SESv2 paginator file names six operations, none of them ListContacts. If you call list-contacts once, you get the first page, and my script would have mailed the first page of subscribers and no one after it.

It pages by hand now:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
function Get-SesContactList {
    param([hashtable] $Filter)
    $all = [System.Collections.Generic.List[object]]::new()
    $token = $null
    $pages = 0
    do {
        $request = @{ ContactListName = $List }
        if ($Filter) { $request['Filter'] = $Filter }
        if ($token) { $request['NextToken'] = $token }
        $page = Invoke-Ses 'list-contacts' $request
        if ($page -and $page.PSObject.Properties['Contacts'] -and $page.Contacts) {
            foreach ($contact in @($page.Contacts)) { $all.Add($contact) }
        }
        $token = if ($page -and $page.PSObject.Properties['NextToken']) { [string]$page.NextToken } else { $null }
        $pages++
        if ($pages -ge 1000) { throw "list-contacts was still returning a NextToken after $pages pages; stopping." }
    } while ($token)
    return $all.ToArray()
}

The loop goes by the token alone. A page can come back short, or empty, and still carry a NextToken, so the number of contacts on a page says nothing about whether there’s another. The 1,000-page limit is there so a token that never ends can’t hang the job.

A dry run with an empty summary

The last fix is one flag. Both PowerShell scripts support -WhatIf and both write a few lines to the GitHub Actions step summary at the end. The first dry run of the prune workflow printed its counts as an annotation and left the Summary tab blank. The last line of the log explained it:

1
What if: Performing the operation "Add Content" on target "Path: .../step_summary_....md".

scripts/Remove-PendingContact.ps1 writes its summary with Add-Content. Add-Content supports -WhatIf, and when you run a script with -WhatIf, that preference flows down to every cmdlet it calls. The summary write was skipped on the one kind of run whose summary gets read.

1
2
3
# -WhatIf:$false: a dry run is the one run whose summary is read, and without this the
# script's own -WhatIf would also skip writing it (seen on the first dry run, 2026-11-29).
if ($InActions -and $env:GITHUB_STEP_SUMMARY) { "### Pending signups`n$line" | Add-Content -LiteralPath $env:GITHUB_STEP_SUMMARY -WhatIf:$false }

-WhatIf:$false on that one call opts it back out. The send script got the same flag on its summary line. The deploy doesn’t run that one with -WhatIf, but I do by hand.

The feed, the response headers, the attribute cap and the cleared attributes only showed up on the real thing. hugo server doesn’t serve Azure’s headers, and a stand-in for the AWS CLI only knows the rules I gave it.