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.

fix(x-content): fill an empty slot with any approved post before it goes unused

nirholas7e278b109322
diff --git a/api/_lib/x-content/runner.js b/api/_lib/x-content/runner.js
index 45dbb247c..5f8f8ce45 100644
--- a/api/_lib/x-content/runner.js
+++ b/api/_lib/x-content/runner.js
@@ -270,7 +270,7 @@ async function fillSlot({ queue, state, store, root, now, requestedId, client, c
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, yieldVeto: !requestedId });
+ const decision = pickDue({ ...context, exclude, quota: !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 };
@@ -300,7 +300,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), vetoYielded: Boolean(decision.vetoYielded), resumed: Boolean(decision.resuming), held, blocked, missed };
+ return { published: row, stock, lowStock, score: decision.score, tier: decision.tier, filledDown: Boolean(decision.filledDown), filledUp: Boolean(decision.filledUp), vetoYielded: Boolean(decision.vetoYielded), resumed: Boolean(decision.resuming), held, blocked, missed };
} catch (err) {
if (!isPostSpecific(err) || !untouched(state, item)) {
const refusal = accountRefusal(err);
diff --git a/api/_lib/x-content/schedule.js b/api/_lib/x-content/schedule.js
index 1a1f41a77..b64d7a750 100644
--- a/api/_lib/x-content/schedule.js
+++ b/api/_lib/x-content/schedule.js
@@ -141,6 +141,12 @@ export function tierOrder(slotTier, readyByTier) {
return [...lower, ...higher];
}
+// Every tier, in the order a slot that must not stay empty tries them: its
+// own, the lower ones, then the higher ones nearest first.
+export function everyTier(slotTier) {
+ return [...TIERS.filter((tier) => tier >= slotTier), ...TIERS.filter((tier) => tier < slotTier).reverse()];
+}
+
export const tierOf = (item) => (TIERS.includes(Number(item.tier)) ? Number(item.tier) : 2);
// `requestedId` names one item and skips pacing and ranking; `anyStatus` lets a
@@ -158,7 +164,7 @@ export function pickDue({
lifts = null,
reviews = null,
exclude = new Set(),
- yieldVeto = false,
+ quota = false,
}) {
const cadence = { ...DEFAULT_CADENCE, ...rawCadence };
const published = [...(state?.published || [])].sort((a, b) => a.publishedAt.localeCompare(b.publishedAt));
@@ -200,34 +206,47 @@ 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 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 ready = candidates.filter((item) => Date.parse(item.notBefore) <= now);
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)) {
- const ranked = rankItems(ready.filter((item) => tierOf(item) === tier), context);
- if (!ranked.length) continue;
- const [top] = ranked;
- return {
- item: top.item,
- slot,
- tier,
- filledDown: tier !== slot.tier,
- vetoYielded,
- score: top.score,
- parts: top.parts,
- ranking: ranked.map((row) => ({ id: row.item.id, score: row.score })),
- };
+ const choose = (pool, order, how) => {
+ for (const tier of order) {
+ const ranked = rankItems(pool.filter((item) => tierOf(item) === tier), context);
+ if (!ranked.length) continue;
+ const [top] = ranked;
+ return {
+ item: top.item,
+ slot,
+ tier,
+ filledDown: tier > slot.tier,
+ filledUp: tier < slot.tier,
+ vetoYielded: how === 'veto',
+ score: top.score,
+ parts: top.parts,
+ ranking: ranked.map((row) => ({ id: row.item.id, score: row.score })),
+ };
+ }
+ return null;
+ };
+ const countByTier = (pool) => new Map(TIERS.map((tier) => [tier, pool.filter((item) => tierOf(item) === tier).length]));
+
+ const usual = choose(ready, tierOrder(slot.tier, countByTier(ready)), 'usual');
+ if (usual || !quota) return usual || empty();
+ // Three a day is a quota, not a ceiling (owner, 2026-09-30), so a slot is
+ // never left empty while an approved post could fill it. First a higher
+ // tier's last ready post: keeping it for its own slot only moves the gap,
+ // because a post sent now is one the later slot can still be given new
+ // stock for. Then a post the policy released that is still in its veto
+ // window: that embargo exists so the owner can take the post back, and an
+ // empty slot outweighs it. An embargo the owner set by hand never yields.
+ return (
+ choose(ready, everyTier(slot.tier), 'up') ||
+ choose(candidates.filter((item) => item.approvedBy === 'policy'), everyTier(slot.tier), 'veto') ||
+ empty()
+ );
+
+ function empty() {
+ const embargoed = unpublished.filter((item) => !exclude.has(item.id) && Date.parse(item.notBefore) > now).sort((a, b) => a.notBefore.localeCompare(b.notBefore));
+ if (embargoed[0]) return { item: null, slot, reason: `nothing is ready for slot ${slot.key}; ${embargoed[0].id} is embargoed until ${embargoed[0].notBefore}` };
+ return { item: null, slot, reason: exclude.size ? `every ready post was held this tick; slot ${slot.key} stays open` : 'queue has no approved unpublished posts' };
}
- const embargoed = unpublished.filter((item) => !exclude.has(item.id) && Date.parse(item.notBefore) > now).sort((a, b) => a.notBefore.localeCompare(b.notBefore));
- if (embargoed[0]) return { item: null, slot, reason: `nothing is ready for slot ${slot.key}; ${embargoed[0].id} is embargoed until ${embargoed[0].notBefore}` };
- return { item: null, slot, reason: exclude.size ? `every ready post was held this tick; slot ${slot.key} stays open` : 'queue has no approved unpublished posts' };
}
diff --git a/tests/x-content-approval.test.js b/tests/x-content-approval.test.js
index 1945826f9..0cd43c3f2 100644
--- a/tests/x-content-approval.test.js
+++ b/tests/x-content-approval.test.js
@@ -146,7 +146,7 @@ describe('three a day is a quota', () => {
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 });
+ const decision = pickDue({ items: [embargoed], state, now, cadence, quota: true });
expect(decision.item?.id).toBe('later');
expect(decision.vetoYielded).toBe(true);
});
@@ -155,14 +155,30 @@ describe('three a day is a quota', () => {
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);
+ expect(pickDue({ items: [owner], state: { published: [], inflight: {} }, now, cadence, quota: 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 });
+ const decision = pickDue({ items: [embargoed, ready], state: { published: [], inflight: {} }, now, cadence, quota: true });
expect(decision.item.id).toBe('ready');
expect(decision.vetoYielded).toBe(false);
});
+ it('fills an empty slot with a higher tier last ready post before it yields any embargo', async () => {
+ const { pickDue, everyTier } = await import('../api/_lib/x-content/schedule.js');
+ expect(everyTier(3)).toEqual([3, 2, 1]);
+ expect(everyTier(2)).toEqual([2, 3, 1]);
+ expect(everyTier(1)).toEqual([1, 2, 3]);
+ const morning = at('2026-09-30T04:30:00Z');
+ const feature = post('feature', { tier: 2 });
+ const embargoed = post('later', { tier: 3, approvedBy: 'policy', notBefore: '2026-09-30T06:00:00Z' });
+ const state = { published: [], inflight: {} };
+ expect(pickDue({ items: [feature], state, now: morning, cadence }).item).toBe(null);
+ const up = pickDue({ items: [feature, embargoed], state, now: morning, cadence, quota: true });
+ expect([up.item.id, up.filledUp, up.vetoYielded]).toEqual(['feature', true, false]);
+ const veto = pickDue({ items: [embargoed], state, now: morning, cadence, quota: true });
+ expect([veto.item.id, veto.vetoYielded]).toEqual(['later', true]);
+ });
+
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');