Skip to content

fix(cli): anchor dense/zh doc overlays to base sections instead of array index (#2182) - #3891

Merged
josephfarina merged 1 commit into
meta:mainfrom
AKnassa:fix/2182-doc-overlay-drift
Jul 20, 2026
Merged

josephfarina merged 1 commit into
meta:mainfrom
AKnassa:fix/2182-doc-overlay-drift

Conversation

@AKnassa

@AKnassa AKnassa commented Jul 12, 2026 •

Copy link
Copy Markdown
Contributor

Refs #2182.

I've scoped this as a self-standing bug fix rather than claiming to close out the umbrella work — the issue carries a research label and reads like it may be an umbrella for the broader "how should agents consume our docs" question. This defect is correct to fix on its own merits regardless of where that lands. Happy to retitle/close-link if you'd rather.

The bug

The --dense and --zh reference-doc overlays were merged into the base doc by array position: for each base section index, the loader took the overlay entry at the same index and applied that overlay's title to the base section's body. An overlay ordered differently from the base — or missing a section — grafted every title onto the wrong content.

The output is actively misleading, not merely untidy:

$ astryx docs tokens --dense

## Spacing

defined in tokens.stylex.ts. gap props use space0-space12.

Token                      | Light   | Dark
--color-accent             | #0064E0 | #2694FE
--color-background-surface | #FFFFFF | #1F1F22

A heading reading Spacing, prose about gap props, and the colour table beneath it. An agent reading that learns spacing tokens are named --color-*.

The tokens overlay was misaligned from index 0 — its own order is Spacing, Size, Color…, the base is Color, Spacing, Size… — so every one of its sections was wrong. docs theme --dense lost Extending a Theme and Token Utilities entirely and printed useTheme twice. docs theme --zh emitted four headings in both Chinese and English.

Why this is more than a docs nit: CLAUDE.md tells every AI agent to run docs tokens --dense and docs theme --dense at bootstrap. The scrambled output is the first thing an agent reads about this design system — a mechanically sufficient cause of the context degradation the issue reports. principles and layout happened to be index-aligned, which is why it went unnoticed: the two docs agents are told to read are the two that were broken.

The fix

Overlay sections now name the base section they override:

{ section: 'Spacing Tokens', title: 'Spacing', content: [...] }

Order becomes irrelevant, and an overlay may cover any subset — sections it doesn't name keep their base content. That's also why the partially-translated zh overlay now falls back to English cleanly instead of scrambling.

docs-types.ts previously documented the footgun ("Array indices must match base doc sections"); it now documents the anchor.

One judgment call worth your eye: the tokens overlay's Typography entry is dropped, not re-anchored. It carried no content overrides (title only), and the base has four separate typography sections (Font Family / Size / Weight, Type Scale) with no single section to anchor it to. Its only effect had been renaming whichever section sat at index 5 — the shadow table. If you'd rather keep a compressed typography title, tell me which base section should own it.

Test plan

  • 18 tests red before the fix, including the behavioural one (docs tokens --dense must not print --color-* under the Spacing heading).
  • After: ## Spacing renders the spacing table, ## Color the colour table, theme --dense shows all 14 headings with Extending a Theme restored and no duplicate useTheme.
  • Mutation-tested: restoring the positional merge fails 3 of the behavioural tests. Being precise — the Spacing/colour test does not fail under that mutation, because the realigned tokens overlay is now coincidentally index-correct too. The anchor assertions are the durable guard against future drift, not that one test.
  • pnpm exec vitest run — 337 files, 6318 tests, all passing.
  • pnpm -F @astryxdesign/core typecheck — clean.
  • pnpm check:repo — all five gates pass.

…ray index (meta#2182)

The --dense and --zh reference-doc overlays were merged into the base doc by
array position: for each base section index, the loader took the overlay entry
at the same index and applied that overlay's TITLE to the base section's BODY.
An overlay whose sections were ordered differently, or which omitted one, then
grafted every title onto the wrong content.

The output was actively misleading, not merely untidy:

  $ astryx docs tokens --dense
  ## Spacing
  defined in tokens.stylex.ts. gap props use space0-space12.
  Token                      | Light   | Dark
  --color-accent             | #0064E0 | #2694FE
  --color-background-surface | #FFFFFF | #1F1F22

A heading reading Spacing, prose about gap props, and the colour table beneath
it. An agent reading that learns spacing tokens are named `--color-*`. The
tokens overlay was misaligned from index 0 (its own order is Spacing, Size,
Color...; the base is Color, Spacing, Size...), so every one of its sections
was wrong.

`docs theme --dense` dropped `Extending a Theme` and `Token Utilities`
entirely and printed `useTheme` twice; `docs theme --zh` emitted four headings
in both Chinese and English.

This is what makes it more than a docs nit: CLAUDE.md tells every AI agent to
run `docs tokens --dense` and `docs theme --dense` at bootstrap, so the
scrambled output is the first thing an agent reads about this design system.
`principles` and `layout` happened to be index-aligned, which is why it went
unnoticed — the two docs agents are told to read are the two that were broken.

Overlay sections now name the base section they override:

  { section: 'Spacing Tokens', title: 'Spacing', content: [...] }

so order is irrelevant and an overlay may cover any subset — sections it does
not name keep their base content, which is also why the partially-translated
zh overlay now falls back to English cleanly instead of scrambling.

docOverlays.test.mjs asserts every overlay anchors to a real base section and
that none is overridden twice, so an overlay cannot silently drift back. The
type contract in docs-types.ts previously *documented* the footgun ("Array
indices must match base doc sections"); it now documents the anchor.

The tokens overlay's `Typography` entry is dropped rather than re-anchored: it
carried no content overrides (title only), and the base has four separate
typography sections (Font Family/Size/Weight, Type Scale) with no single
section to anchor it to. Its sole effect had been renaming whichever section
sat at index 5 — the shadow table.

Claude-Session: https://claude.ai/code/session_01VYm8FsvUjk3xwDmonZRYeE
@vercel

vercel Bot commented Jul 12, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
astryx Ready Ready Preview, Comment Jul 12, 2026 11:09pm

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Jul 12, 2026
@github-actions github-actions Bot added community Authored by a community contributor (not on the eng/design team) needs:code-review High-risk change (new package/component/API) — needs human code review before merge labels Jul 12, 2026
@github-actions

Copy link
Copy Markdown
Contributor

PR Analysis Report

No new or modified components detected.

Bundle Size Summary

Package Size (ESM) Size (CJS) Gzipped
@astryxdesign/core N/A 4.6KB 0B

Accessibility Audit

Status: No accessibility violations detected.


Generated by PR Enrichment workflow | View full report

@AKnassa
AKnassa marked this pull request as ready for review July 13, 2026 01:17

@josephfarina josephfarina left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dug into this and it's a solid, well-scoped fix — recommending merge.

Verified: reproduced on main (docs tokens --dense prints the color table under the ## Spacing heading; docs theme --dense drops "Extending a Theme" and duplicates "useTheme" from index 5 on). The anchor-by-section approach is the right design, the 20 tests + drift guard are exactly right, and it's green + merges clean into main.

Non-blocking nits:

  • The docs-types.ts union reformatting is unrelated churn — optional to drop.
  • Block overrides are still index-matched within a section — a smaller residual of the same class; dovetails with the prose-only overlay direction @cixzhang raised on #3892.

For the record, so we frame it accurately: I ran ~46 controlled agent generations (scrambled vs fixed vs full vs no-docs) and couldn't reproduce the compliance-degradation causation in the description — scrambled ≈ fixed ≈ full on veer/purity/real-API usage, and no-docs was actually the worst. That doesn't diminish the fix at all; it's a correctness bug worth fixing on its own merits. Suggest we land it as the correctness fix it is and keep #2182 open for the doc-size angle — "Refs" (not "Closes") is already right.

@josephfarina josephfarina left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified: reproduced the scramble on main, the anchor-by-section fix is correct, 20 tests + drift guard, full CI green, clean merge. Landing this as a standalone correctness fix — #2182 stays open for the doc-size work (full details in my review above).

@github-actions github-actions Bot removed the needs:code-review High-risk change (new package/component/API) — needs human code review before merge label Jul 20, 2026
@josephfarina
josephfarina merged commit ff5dfca into meta:main Jul 20, 2026
25 checks passed
josephfarina added a commit that referenced this pull request Jul 20, 2026
Make reference-doc dense/zh overlays structurally unable to drop, misalign, or
override canonical content (the #2182 / #3891 bug class).

- ContentBlock gains an optional stable id; ReferenceTranslationDoc is prose-only,
  id-keyed blocks and cannot express type/code/table/structure
- api/docs.mjs merge is id-anchored and fail-safe: unmatched or unexpressible
  overrides fall back to canonical English; no array positions anywhere
- all reference docs migrated: principles, theme, layout (per-block ids), tokens
  (ids emitted from scripts/generate-token-docs.mjs); overlays rewritten to blocks
- docOverlays.test.mjs gate: every overlay block id resolves, prose-only, unique
  base ids, and the legacy positional content shape is rejected
- component/hook overlays already safe on main via #3892 (overlayComponentDoc)

Refs #2182

Co-authored-by: Cursor <[email protected]>
@github-actions
github-actions Bot deleted the fix/2182-doc-overlay-drift branch July 21, 2026 08:24

This branch was successfully deployed

1 active deployment
Preview — 7d1ad0db Deployed Jul 12, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot. community Authored by a community contributor (not on the eng/design team)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants