Skip to content

Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.

feat(x-content): treat three posts a day as a quota, never a ceiling

nirholas5b6740272ecc
diff --git a/api/_lib/x-content/runner.js b/api/_lib/x-content/runner.js
index 78bf4b63d..d392e171a 100644
--- a/api/_lib/x-content/runner.js
+++ b/api/_lib/x-content/runner.js
@@ -14,7 +14,7 @@
// reads the timeline again if the stored record has gone stale.
import { loadQueue, validateQueue } from './queue.js';
-import { TIERS, pickDue, tierOf } from './schedule.js';
+import { DEFAULT_CADENCE, SLOT_OPEN_MINUTES, TIERS, pickDue, slotOpenings, tierOf } from './schedule.js';
import { loadLifts } from './priority.js';
import { loadReview, contentHash } from './review.js';
import { previewClient, publishItem, xClientFromEnv } from './publisher.js';
@@ -22,6 +22,7 @@ import { itemTexts, linkChecks, probeChecks } from './verify.js';
import { collectOutcomes, learnLifts, outcomesAreStale, outcomesStore } from './outcomes.js';
const HOUR = 60 * 60_000;
+const DAY = 24 * HOUR;
// Tries per tick before giving up the slot: enough to skip a few broken posts,
// bounded so one tick cannot spend an hour on pre-flight checks.
const MAX_ATTEMPTS_PER_TICK = 5;
@@ -128,6 +129,37 @@ async function refreshOutcomes({ outcomes, stored, collect, client, ledger, now
}
}
+// ── Missed slots ────────────────────────────────────────────────────────────
+// Three a day is a quota (owner, 2026-09-30). An open slot with nothing to post
+// is raised the moment it is seen, and a slot that closed unfilled is recorded
+// and raised once, so a quiet day is never quiet by accident.
+async function alertEmptySlot(state, store, slot, reason) {
+ state.emptySlotAlerted ||= {};
+ if (state.emptySlotAlerted[slot.key]) return;
+ state.emptySlotAlerted[slot.key] = new Date().toISOString();
+ await store.save(state);
+ const { sendOpsAlert } = await import('../alerts.js');
+ await sendOpsAlert(`x-content: slot ${slot.key} (T${slot.tier}) is open with nothing to post`, `${reason}. Approve or advance a post now: npm run x:content -- advance --ship`);
+}
+
+export function missedSlots(state, cadence, seed, now = Date.now()) {
+ const openFor = Number(cadence.slotOpenMinutes ?? SLOT_OPEN_MINUTES) * 60_000;
+ const used = new Set((state.published || []).map((row) => row.slot).filter(Boolean));
+ const noted = state.missedSlots || {};
+ return slotOpenings(now, { ...DEFAULT_CADENCE, ...cadence }, seed).filter((slot) => slot.opensAt + openFor <= now && now - slot.opensAt < DAY && !used.has(slot.key) && !noted[slot.key]);
+}
+
+async function alertMissedSlots(state, store, cadence, seed, now) {
+ const missed = missedSlots(state, cadence, seed, now);
+ if (!missed.length) return [];
+ state.missedSlots ||= {};
+ for (const slot of missed) state.missedSlots[slot.key] = new Date(now).toISOString();
+ await store.save(state);
+ const { sendOpsAlert } = await import('../alerts.js');
+ await sendOpsAlert(`x-content: ${missed.length} slot(s) closed with no post`, missed.map((slot) => `${slot.key} (T${slot.tier})`).join(', '));
+ return missed.map((slot) => slot.key);
+}
+
// `client` and `checks` default to the real X client and the real pre-flight;
// tests pass their own to drive the hold-and-fall-through path. `outcomes` and
// `collect` default to the stored record and the real timeline read.
@@ -203,11 +235,19 @@ async function fillSlot({ queue, state, store, root, now, requestedId, client, c
const lowStock = requestedId ? null : await alertLowInventory(state, store, stock, now).catch(() => null);
const exclude = requestedId ? new Set() : activeHolds(state, publishable, root, now);
+ const missed = requestedId ? [] : await alertMissedSlots(state, store, queue.cadence || {}, context.seed, now).catch(() => []);
const held = [];
for (let attempt = 0; attempt < MAX_ATTEMPTS_PER_TICK; attempt++) {
- const decision = pickDue({ ...context, exclude });
- if (!decision.item) return { published: null, reason: decision.reason, held, blocked, stock, lowStock };
+ const decision = pickDue({ ...context, exclude, yieldVeto: !requestedId });
+ if (!decision.item) {
+ if (decision.slot && !requestedId) await alertEmptySlot(state, store, decision.slot, decision.reason).catch(() => {});
+ return { published: null, reason: decision.reason, held, blocked, stock, lowStock, missed };
+ }
const item = decision.item;
+ if (decision.vetoYielded) {
+ const { sendOpsAlert } = await import('../alerts.js');
+ await sendOpsAlert(`x-content: ${item.id} goes out before its veto window ends`, `Slot ${decision.slot.key} (T${decision.slot.tier}) had nothing else ready. Its embargo ran until ${item.notBefore}.`, { severity: 'info' }).catch(() => {});
+ }
// A resumed thread must finish what it started, so it skips pre-flight.
if (!decision.resuming) {
@@ -228,7 +268,7 @@ async function fillSlot({ queue, state, store, root, now, requestedId, client, c
delete state.holds[item.id];
await store.save(state);
}
- return { published: row, stock, lowStock, score: decision.score, tier: decision.tier, filledDown: Boolean(decision.filledDown), resumed: Boolean(decision.resuming), held, blocked };
+ return { published: row, stock, lowStock, score: decision.score, tier: decision.tier, filledDown: Boolean(decision.filledDown), vetoYielded: Boolean(decision.vetoYielded), resumed: Boolean(decision.resuming), held, blocked, missed };
} catch (err) {
if (!isPostSpecific(err) || !untouched(state, item)) throw err;
const reason = `X rejected the post: ${err.message}`;
diff --git a/api/_lib/x-content/schedule.js b/api/_lib/x-content/schedule.js
index b3cbc1867..1a1f41a77 100644
--- a/api/_lib/x-content/schedule.js
+++ b/api/_lib/x-content/schedule.js
@@ -158,6 +158,7 @@ export function pickDue({
lifts = null,
reviews = null,
exclude = new Set(),
+ yieldVeto = false,
}) {
const cadence = { ...DEFAULT_CADENCE, ...rawCadence };
const published = [...(state?.published || [])].sort((a, b) => a.publishedAt.localeCompare(b.publishedAt));
@@ -198,7 +199,17 @@ export function pickDue({
// On a weekend a flagship post waits for Monday instead of filling a lower slot.
const holdFlagship = Boolean(cadence.flagshipWeekdaysOnly) && isWeekend(slot.opensAt);
- const ready = unpublished.filter((item) => !exclude.has(item.id) && Date.parse(item.notBefore) <= now && !(holdFlagship && tierOf(item) === 1));
+ const candidates = unpublished.filter((item) => !exclude.has(item.id) && !(holdFlagship && tierOf(item) === 1));
+ let ready = candidates.filter((item) => Date.parse(item.notBefore) <= now);
+ // Three a day is a quota, not a ceiling (owner, 2026-09-30). A post the
+ // policy released is embargoed only so the owner can take it back; when the
+ // alternative is an empty slot, the schedule wins and the embargo yields.
+ // The owner's own embargo (an item approved by hand) is never shortened.
+ let vetoYielded = false;
+ if (!ready.length && yieldVeto) {
+ ready = candidates.filter((item) => item.approvedBy === 'policy');
+ vetoYielded = ready.length > 0;
+ }
const context = { lifts, published, quality, reviews, now };
const readyByTier = new Map(TIERS.map((tier) => [tier, ready.filter((item) => tierOf(item) === tier).length]));
for (const tier of tierOrder(slot.tier, readyByTier)) {
@@ -210,6 +221,7 @@ export function pickDue({
slot,
tier,
filledDown: tier !== slot.tier,
+ vetoYielded,
score: top.score,
parts: top.parts,
ranking: ranked.map((row) => ({ id: row.item.id, score: row.score })),
diff --git a/tests/x-content-approval.test.js b/tests/x-content-approval.test.js
index 6598f4867..1945826f9 100644
--- a/tests/x-content-approval.test.js
+++ b/tests/x-content-approval.test.js
@@ -134,3 +134,43 @@ describe('a story covers backlog surfaces', () => {
expect(validateItem(item({ covers: [42] }), sandbox()).join('\n')).toMatch(/covers must list backlog keys/);
});
});
+
+describe('three a day is a quota', () => {
+ const cadence = { slots: [{ tier: 3, at: '04:00' }, { tier: 2, at: '12:00' }, { tier: 1, at: '20:00' }], windowMinutes: 0, minimumMinutesApart: 1, dailyCap: 3, quietHoursUtc: null };
+ const at = (iso) => Date.parse(iso);
+ const post = (id, overrides = {}) => ({ id, status: 'approved', kind: 'post', tier: 2, lane: 'community', pattern: 'walkthrough', notBefore: '2026-09-29T00:00:00Z', posts: [{ text: `${id} post about a feature: three.ws/${id}`, media: [{ path: `public/x-media/${id}/reel.mp4` }] }], ...overrides });
+
+ it('lets a policy embargo yield when the slot would otherwise go empty', async () => {
+ const { pickDue } = await import('../api/_lib/x-content/schedule.js');
+ const now = at('2026-09-30T12:30:00Z');
+ const embargoed = post('later', { approvedBy: 'policy', notBefore: '2026-09-30T14:00:00Z' });
+ const state = { published: [], inflight: {} };
+ expect(pickDue({ items: [embargoed], state, now, cadence }).item).toBe(null);
+ const decision = pickDue({ items: [embargoed], state, now, cadence, yieldVeto: true });
+ expect(decision.item?.id).toBe('later');
+ expect(decision.vetoYielded).toBe(true);
+ });
+
+ it('never shortens an embargo the owner set, and prefers a ready post to a yielded one', async () => {
+ const { pickDue } = await import('../api/_lib/x-content/schedule.js');
+ const now = at('2026-09-30T12:30:00Z');
+ const owner = post('owner-held', { notBefore: '2026-10-02T00:00:00Z' });
+ expect(pickDue({ items: [owner], state: { published: [], inflight: {} }, now, cadence, yieldVeto: true }).item).toBe(null);
+ const ready = post('ready');
+ const embargoed = post('later', { approvedBy: 'policy', notBefore: '2026-09-30T14:00:00Z' });
+ const decision = pickDue({ items: [embargoed, ready], state: { published: [], inflight: {} }, now, cadence, yieldVeto: true });
+ expect(decision.item.id).toBe('ready');
+ expect(decision.vetoYielded).toBe(false);
+ });
+
+ it('names every slot of the last day that closed with no post, once', async () => {
+ const { missedSlots } = await import('../api/_lib/x-content/runner.js');
+ const now = at('2026-09-30T11:00:00Z');
+ const state = { published: [{ id: 'a', slot: '2026-09-30#0', publishedAt: '2026-09-30T04:10:00Z' }], missedSlots: { '2026-09-29#2': '2026-09-30T00:00:00Z' } };
+ const missed = missedSlots(state, cadence, null, now).map((slot) => slot.key);
+ expect(missed).toContain('2026-09-29#1');
+ expect(missed).not.toContain('2026-09-29#2');
+ expect(missed).not.toContain('2026-09-30#0');
+ expect(missed).not.toContain('2026-09-30#1');
+ });
+});