Data-fidelity fixes (AISD-170)¶
Once the forge started generating for real on stage, the first live runs
surfaced a set of shape/quality defects between what the models return and what
cms-api actually renders. AISD-170 is the correctness pass that closes them.
Each fix is a normalization or a bound applied inside the generator, before
validation and publish, so a benign shape variance never rejects an otherwise
good entity and a runaway prompt never fans out unbounded media.
1. content_blocks normalization¶
Problem. Real models return content_blocks with the body under assorted
keys -- observed {"type": "introduction", "content": "..."} -- while both the
validator and the cms-api payload expect the canonical
{"type": ..., "data": {"text": ...}}. Left unnormalized the body reads as
empty and every article fails body too short (0 words).
Fix. ArticleGenerator._coerce_content rewrites each block in place to the
canonical shape before validate and payload_from_content run
(generators/article.py):
- A bare string block becomes
{"type": "paragraph", "data": {"text": ...}}. - A dict block's body text is pulled from the first of
data.text(canonical) →content→text→body→data.html→html, preferring plain-text sources over HTML. - An image block (
type == "image", or asrc/imagefield present) is coerced to{"type": "image", "data": {"src": ...}}.
The result is that both the quality gates and the cms-api ContentCreate see a
uniform block list regardless of which key the model chose.
2. image_briefs shape + runaway caps¶
Problem. Two failure modes: a model returns a role (featured / inline)
as a bare string instead of a list, and a model returns a long inline list
that would fan out one paid gpt-image child per brief -- a cost/runaway
hazard.
Fix (generators/article.py).
_as_brief_listtreats a bare string (or dict) as one brief and never iterates a string's characters. A list passes through; anything else is empty.- Each role is then capped:
featured≤ 1,inline≤ 4 (_MAX_FEATURED_BRIEFS = 1,_MAX_INLINE_BRIEFS = 4). The excess is dropped before the image chord fans out, so the per-article media cost is bounded no matter how many briefs the model emitted.
At least one featured brief is still required -- an article with no featured image fails validation.
3. Title-derived slugs¶
Slugs are derived deterministically from the entity title, using the article
generator's own slug helper, and the same helper is reused wherever a slug or
canonical is needed (e.g. seo_enrich re-derives canonical_url from the
existing title rather than trusting a provider-supplied canonical). This keeps
the forge's slug identical to the title-derived breadcrumb/slug cms-api
computes, so lookups match and re-runs dedup correctly instead of creating a
divergent second row.
4. cdn_base_url = the site's own domain¶
Problem. The scaffold's SettingsGenerator previously fell back to a dead
https://cdn.example.com placeholder, so cms-api absolutized icon_url /
default_favicon (and every media path) against a host that serves nothing.
Fix (generators/settings.py). cdn_base_url is derived from the site's
own domain (https://{host}), so media is served same-origin and cms-api
absolutizes relative media paths under the real site host. A shared/hardcoded
CDN host is deliberately not used; when the scaffold params carry no usable
domain the key is omitted rather than filled with a placeholder (a PATCH
never clobbers an existing value with a dead one).
5. Real gpt-image logo + favicon¶
Problem. The logo path used the placeholder image provider, which produces a solid square -- not a usable brand mark.
Fix (generators/logo.py). LogoGenerator explicitly resolves the
openai_image provider (gpt-image), not the placeholder. With stubs off it
generates a horizontal wordmark logo and a square monogram favicon and
uploads both through MediaPublisher, returning icon_url / default_favicon.
With stubs on it still returns deterministic stub media paths and performs no
upload, so the offline suite stays network- and key-free.
Why these live in the generator¶
Every fix runs inside the generator pipeline (_coerce_content → validate →
normalize) rather than at the edge, so:
- the stub path is untouched (stub results are trusted and skip coercion);
- both the validator and the publisher see already-normalized data, so there is a single source of truth for shape;
- a re-run is still idempotent -- deterministic slugs and the
ai_content_ledgerdedup mean a corrected re-run updates in place instead of duplicating.