TikTok Pipeline Build Run: Four Functions, One Silent Failure
Abstract
An engineering record of the November 1, 2026 build run on the TikTok publishing pipeline. The pass audited queueTikTokPosts, publishTikTokPosts, refreshTikTokMusic and manageTikTokPost, removed work that ran on every pass without changing an answer, fixed a client-shape bug that was crashing the publisher, and verified each function against the live Upload-Post connection. Notable measured results: a clean publish pass in 556ms, a full music refresh across nine genre charts in 4.5s, and a queue dry run selecting 7 posts from 1,742 eligible photographs in 4.9s.
A performance and reliability pass over the four backend functions that run the TikTok side of the publishing queue. No new features. The goal was to remove work that ran on every pass without changing an answer, then prove each function still behaves against the live Upload-Post connection.
Status: all four functions audited, optimized and passing.
1. The pipeline as it stands
| Piece | Role | Cadence |
| --- | --- | --- |
| queueTikTokPosts | Builds the automated queue, newest capture first | Scheduled |
| publishTikTokPosts | Reaps stale renders, settles in-flight uploads, renders due posts, publishes one per run (daily cap 3) | Every 15 min |
| refreshTikTokMusic | Refreshes the Commercial Music Library cache from nine genre charts | Daily, 03:30 Detroit |
| manageTikTokPost | Admin-only endpoint: status strip, track picker, edits, preview render, post now, delete | On demand |
Two shared modules carry the plumbing:
shared/tiktokRuntime.ts— the admin-or-internal-secret gate, the singleTikTokStatusrow, and the render polling loop. Previously copy-pasted into every function; a change now lands once instead of four times.shared/tiktokApi.ts— the Upload-Post request layer and the failure classifier that decides whether an error backs off or halts the run.
2. Changes made
Queue builder: compose in parallel, write once
Before every post was composed one after another, and each row was written as its own create. Composition is the only part of the builder that waits on the network — one dimension probe per photo — so the queue was paying the probes serially.
After posts are composed four at a time through a small mapLimit helper and written in a single bulkCreate.
Measured 4.9s for a full dry run, selecting 7 posts from a pool of 1,742 eligible photographs. The same run previously took roughly 6.3s.
Publisher: read less on every pass
The publisher runs 96 times a day. Three reads were doing far more work than the run needed:
- Approved tracks only. The music picker read the whole chart cache (~900 rows) every pass, though only approved tracks can ever be chosen. It now asks for
{ approved: true }and typically gets ~92 rows. If that filtered read fails, it falls back to the full cache so the picker never goes dark. - Live posts only. The queue read was one broad 500-row list. It is now two narrowed queries — posts in a pipeline state, plus recently published posts for the daily cap and track cooldown — with the broad read kept as a fallback.
- Hourly connection probe. The read-only connection probe used to run every 15 minutes; it now skips while the status row is under an hour old.
Measured a clean production pass in 556ms, with the connection probe correctly skipped because the status row was still fresh.
Music refresh: nine charts at once
The nine genre chart reads were awaited one after another. They are independent, so they now run together through Promise.all — the refresh finishes in the time of the slowest single chart instead of the sum of all nine. The upsert already wrote in chunks of 200, which stays as it was: the entity API allows 400 creates per minute per caller, and one create per track previously blew that cap mid-run and silently dropped half the library.
Measured 4.5s for the full refresh: 1 track created, 899 updated, 1 retired. All nine genres returned 100 tracks each.
Bug found and fixed: the wrong client handed to the status helpers
Symptom the publish run failed outright.
Cause the status helpers assumed one client shape. One caller passed the other, so the lookup resolved to nothing and the run broke instead of degrading.
Fix a single statusEntities() resolver in shared/tiktokRuntime.ts accepts either base44.asServiceRole.entities or base44.entities, and all three callers were corrected. The failure cannot recur from either call site.
3. Test results
Every function was exercised against the live connection after the changes.
| Check | Result | | --- | --- | | Queue builder, dry run | 7 posts from 1,742 eligible in 4.9s, nothing written | | Publisher, clean pass | 556ms, no upload attempted (nothing due), probe skipped | | Music refresh | 200 in 4.5s — 9/9 genres at 100 tracks, 899 updated, 1 new, 1 retired | | Admin status strip | 200 in 1.97s — connection ok, music available, no reconnect needed | | Queue depth reported to admin | 7 pending posts, daily limit 3, 0 published in last 24h |
Connection capabilities reported by Upload-Post at the end of the run:
music, location, cover_image, cover_timestamp, draft, video_privacy,
photo_privacy, profile_analytics, comments, trend_search
music is present, so the downgrade path — publishing as photo posts without an attached track — did not fire. Zero posts were downgraded.
4. Open notes
- Render quota unknown. Upload-Post did not report renders used or limit, so the figure stays null until the first render of the period lands.
- Approval is the gate. The music cache holds roughly 900 tracks, but only approved tracks are picked automatically. Approving tracks in the admin TikTok tab is what keeps the picker supplied.
- Silent-publish guard intact. A video with no approved track is held as a draft with a reason rather than published without music. This is deliberate and was not changed.
- The reaper settled nothing. No render outlived its poll budget during the run, so the stuck-render path was not exercised in production.
5. Files touched
base44/functions/queueTikTokPosts/entry.ts
base44/functions/publishTikTokPosts/entry.ts
base44/functions/refreshTikTokMusic/entry.ts
base44/functions/manageTikTokPost/entry.ts
base44/shared/tiktokRuntime.ts
6. Reproducing the checks
Each of these is a read-only pass, safe to re-run at any time:
- Queue builder — invoke
queueTikTokPostswith{ "dry_run": true }. Expect a pool count, awaiting-rating count, per-post slot previews, and nothing written to the database. - Publisher — invoke
publishTikTokPostswith an empty payload. Expect a summary of reaped, settled, rendered, published and failed counts, pluspublished_last_24h. - Music refresh — invoke
refreshTikTokMusicwith an empty payload. Expect per-genre track counts, created, updated and retired totals, and the capability list. - Admin strip — invoke
manageTikTokPostwith{ "action": "status" }. Expect connection state, capabilities, queue depth and daily limit.
7. Why it matters
The publisher is the only part of this system that talks to a third party on a timer. Every wasted read there is a wasted call across 96 daily passes, and every crash is a missed post. Today's pass cut the reads on each pass by roughly an order of magnitude, took the queue builder's slowest step off the critical path, and closed a failure that had already broken a production run.