Built to fail loud, not silent
The interesting engineering isn't the happy path. It's the four places the system refuses to lie when something goes wrong. Here is each guard, in the real code.
Want how it works instead? The build walkthrough →
The auto-poster fires one approved draft per tick. The risk is a flaky network response causing the same draft to post twice. So the draft is marked posting before the network call returns. Success moves it to posted. Failure rolls it back to approved for an intentional retry. A duplicated or timed-out response can never re-fire it.
before call posting →
on ok posted ↵
on fail back to approved
// optimistic lock — mark in-flight BEFORE the call updateDraft(draft.id, { status: 'posting', post_attempted_at: stamp }); const result = await postDraftToFacebook(draft); if (result.ok) { updateDraft(draft.id, { status: 'posted', fb_post_id: result.postId }); } else { // roll back so a human can retry on purpose, and log LOUD updateDraft(draft.id, { status: 'approved', last_post_error: result.error }); }
Google Places can return a different business than the one searched. Stapling a low-confidence match to the audit produces a Frankenstein result: one business's reviews describing another's website. Anything below a 0.7 confidence floor is thrown out before scoring or narrative can trust it.
const PLACES_MATCH_FLOOR = 0.7; if (places.found && places.matchScore < PLACES_MATCH_FLOOR) { places = { found: false, weakMatch: true, /* ...zeroed... */ }; }
The site is read in headless Chromium so GTM-injected tags actually run. If rendering crashes, it falls back to a static fetch rather than failing outright. The fallback re-introduces the old false-negative, so it's flagged as renderFailed, but a partial audit still beats nothing.
let fetchResult = await fetchRenderedHtml(url); // headless if (!fetchResult.ok) { const staticResult = await fetchHtml(url); // fallback if (staticResult.ok) fetchResult = { ...staticResult, renderFailed: true }; }
A 403 or 429 means bot protection blocked the read. An empty page means the site really is bare. Scoring these the same way would email a prospect a confident zero about a site nobody could see. The blocked case is flagged so scoring treats it as couldn't scan, not as a bare site.
const blocked = !fetchResult.ok && ( fetchResult.status === 403 || fetchResult.status === 401 || fetchResult.status === 429 || [502,503,520,521,522,530].includes(fetchResult.status) ); // downstream: inspectionRan === false => emit "couldn't scan", not a zero