Skip to content

fix(cli): cap every repeat the layout expander walks - #6565

Merged
josephfarina merged 1 commit into
mainfrom
cli-spec/templates-layout/layout-repeat-cap
Sep 24, 2026
Merged

josephfarina merged 1 commit into
mainfrom
cli-spec/templates-layout/layout-repeat-cap

Conversation

@josephfarina

Copy link
Copy Markdown
Contributor

User impact

Anyone — usually an agent — who passes a large *N repeat to astryx layout expand (or layoutExpand()). The expander caps each repeat at 10000 copies when it emits children, but two paths walked the uncapped count first:

  • the root count that decides whether the output needs a fragment ran through every copy, so astryx layout expand 'B*5000000' took 21 s and B*999999999 would run for over an hour or exhaust memory, even though the output only ever held 10000 buttons;
  • table rows are flattened before they are emitted, so T > TR*20000 > TC emitted all 20000 rows and T > TR*999999999 > TC had no bound at all.

After the change both return in about two seconds with 10000 copies, the same result the emit path already produced.

Problem and solution fit

  1. Why does it occur? foundation/xle/expand.mjs has two loops over a repeat count. emitItems clamps with Math.min(item.repeat || 1, MAX_REPEAT); flattenItems used item.repeat || 1. flattenItems serves the root count and partitionTableChildren.
  2. Why does it harm the task? The repeat count comes straight from the expression. An expression is a bounded input; one path treated its count as trusted.
  3. Why does that matter? An agent that mistypes a count gets a hung subprocess instead of a result, and the cap that exists for exactly this case does not protect it.

The fix applies the same clamp in flattenItems. MAX_REPEAT is exported so astryx layout grammar can state the cap next to *N instead of repeating the number.

Expected behavior and authority

docs/architecture/cli-surface.md (authority: current), INV10: "Bounded inputs are capped rather than trusted."

Automatic behavior must also be discoverable: docs/specs/AST-017/spec.md (authority: current), FR14: "Any Astryx CLI behavior available in a supported flow—including behavior selected automatically ... MUST be documented and discoverable." The grammar cheatsheet is where *N is documented, so the cap is stated there.

Smallest restoration

One clamp in flattenItems, the constant exported, one cheatsheet line. No new option, code, or output field; expressions whose repeats are at most 10000 expand exactly as before.

Evidence

  • Reproduction before the change: astryx --json layout expand 'B*5000000' 21 s (linear in the count, output fixed at 10000 buttons); astryx --json layout expand 'T > TR*20000 > TC' emitted 20000 TableRows.
  • Result after the change: B*999999999 and T > TR*999999999 > TC each return in about 2 s with 10000 copies.
  • Representative unchanged path: V > B*10005 still emits 10000 buttons (new test, passes before and after); the existing layout and XLE suites pass unchanged.
  • Regression test or other mutation-sensitive proof: foundation/xle/expand.test.mjs › "caps repeated table rows at MAX_REPEAT copies too". With only the flattenItems clamp reverted, it fails (10005 rows); with the fix it passes.

Not in this change: nested repeats multiply per-level caps ((B*1000)*1000 asks for a million copies and fails with a stack overflow). Bounding the product is a separate decision about total expansion size.

Scope

  • One defect is restored.
  • Separable contradictory or unsettled tagalongs were removed or split.
  • No new public API, visual representation, default, or interaction model is hidden under the bug-fix label.
  • Public text and artifacts contain no internal Meta context.

Testing

pnpm exec vitest run packages/cli/foundation/xle/expand.test.mjs packages/cli/foundation/xle/xle.test.mjs packages/cli/api/layout/layout.test.mjs
pnpm -F @astryxdesign/cli exec tsc --project tsconfig.api-dts.json
pnpm check:cli-structure
pnpm -F @astryxdesign/cli readme:check
pnpm -F @astryxdesign/cli typecheck:json-api
ASTRYX_STRICT_LINT=1 pnpm exec eslint packages/cli/api/layout/grammar/grammar.mjs packages/cli/foundation/xle/expand.mjs packages/cli/foundation/xle/expand.test.mjs
pnpm check:repo
pnpm exec vitest run packages/cli

The 10000-copy repeat cap applied where children are emitted but not where
repeats are flattened, so table rows bypassed it and the root count walked
every copy of `B*999999999`. The flattener now clamps the same way.
@vercel

vercel Bot commented Sep 24, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated
astryx Ready Ready Preview Sep 24, 2026 7:52am UTC

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Sep 24, 2026
@astracat-bot

astracat-bot Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
🟢 Reviewed (for maintainers only) Sep 24, 2026, 9:55 AM UTC

@astracat-bot astracat-bot Bot 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.

This change correctly caps the remaining uncapped repeat paths in the layout expander.

  • flattenItems now applies the same 10000-copy limit that emission already used, so both the root-count walk and repeated table rows are bounded; repeats at or below 10000 are unchanged.
  • Stating the cap in astryx layout grammar, sourced from the exported constant, makes the behavior discoverable without duplicating the number.
  • The new table-row regression test is mutation-sensitive, and the targeted expand, XLE, and layout suites pass.

The nested-repeat case where per-level caps multiply (for example (B*1000)*1000) remains a separate total-expansion-size decision, as noted in the PR description, and does not block this per-repeat fix.

[Automated review]

@josephfarina
josephfarina marked this pull request as ready for review September 24, 2026 20:57
@josephfarina
josephfarina merged commit c802014 into main Sep 24, 2026
38 checks passed
@github-actions
github-actions Bot deleted the cli-spec/templates-layout/layout-repeat-cap branch September 25, 2026 06:23
cixzhang added a commit that referenced this pull request Oct 2, 2026
…6887)

`astryx layout expand`, `astryx layout check` and `astryx layout grammar`
shipped in published `@astryxdesign/[email protected]`, as ordinary registered
top-level commands with documented examples, manifest entries, a `layout`
docs topic, and the `layout.expand` / `layout.check` / `layout.grammar`
response schemas. Four fixes to them (#6564, #6569, #6565, #6572) are in
0.6.4's changelog. They are a stable released CLI surface under
`spec:AST-017` FR3.

#6615 removed that surface in one step. `spec:AST-017` (authority: current)
does not allow this yet:

- FR28 requires a replacement-first deprecation patch and a public `DEP-*`
  record before a removal becomes eligible. There is none.
- FR31 allows a removal only when its `DEP-*` and `CLN-*` ids appear in a
  frozen minor manifest. There is no such manifest.
- FR37 requires an owner-approved public minor plan before freeze. There is
  no approved minor plan.
- FR22 forbids retroactively demoting a released stable surface to
  experimental. `layout` was never behind an experimental boundary: FR27
  requires a dedicated experimental namespace, and only the
  `experimental.xle.components` config key had one — the command did not.

So this reverts #6615 and drops its `[breaking]` Changeset.

Effect on the next release, measured with `changeset status`:

- before: all ten fixed-group packages bump **minor** -> 0.7.0
- after:  all ten bump **patch** -> 0.6.5

The ten manifests read 0.6.4, which is the published base; the target is
derived from that base plus the highest pending bump. One `minor` Changeset
in a `fixed` group moves all ten, which is why a single unplanned removal
re-targeted the whole release.

This is compatibility restoration, not new behavior. Nothing is invented and
no deprecation metadata is added: `layout` returns to exactly its 0.6.4
shape, and its deprecation is left to be decided explicitly under AST-017.
Because the removal was never published, main after this change is identical
to 0.6.4 for consumers, so the restoration needs no Changeset of its own.
The retained `@astryxdesign/cli/xle` barrel and the
`experimental.xle.components` config key are untouched.

Conflicts with later main commits were resolved toward main, not toward the
revert:

- `packages/cli/README.md` keeps main's rewritten descriptions and is
  regenerated, so the `layout` row and config row come from the restored
  docs.
- `packages/cli/test/docs-graph.test.mjs` stays deleted; #6737 removed it
  for unrelated reasons.
- `doc-routes.ids.json` keeps both `integration verify` (#6737) and the
  layout ids.

Note for a follow-up: #6737 re-added the layout ids to
`packages/cli/test/doc-routes.ids.json` while the command stayed deleted, so
main currently claims four layout commands and three layout functions that
do not exist. This change makes that file honest again.

Test plan:
- `npx vitest run --root . packages/cli` — 5314 passed, 0 failed
- `pnpm check:repo` — passes, including `check:changesets`
- `npx changeset status` — all ten packages at patch (0.6.5), none at minor
- `astryx layout grammar|check|expand` run again from the built CLI
- `astryx manifest --json` reports 17 top-level commands, matching the
  restored `spec:AST-042` text

This branch was successfully deployed

1 active deployment
Preview — 7473ca2d Deployed Sep 24, 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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant