Repository navigation
fix(cli): cap the layout expression read from stdin - #6572
Conversation
`--file` refused an expression over 5 MB, but `-` buffered stdin without a bound, so an endless or oversized pipe ran the process out of memory. Stdin now stops at the same cap and fails with ERR_INVALID_ARGUMENT.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
AI review status for this pull request.
|
There was a problem hiding this comment.
Thanks — this restores the documented bounded-input behavior for the stdin path.
layout check - and layout expand - now stop reading stdin at the same 5 MB cap --file already enforced and fail with ERR_INVALID_ARGUMENT (exit 1, with a valid --json envelope), instead of buffering an oversized or endless pipe until the process died with no output. I verified the new spawned-bin regression test passes, that layout expand - inherits the same cap through the shared reader, that exactly 5 MB is still accepted, and that an endless yes pipeline now terminates in about a second with the coded envelope. Normal piped input and the --file path are unchanged, and the generated CLI docs stay in sync.
One scoped-out note, not a blocker: an oversized --file still reports its pre-existing ERR_FILE_NOT_FOUND; aligning that code is a separate decision, as the PR states.
[Automated review]
…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
User impact
Anyone who pipes an expression into
astryx layout check -orastryx layout expand -.--filerefuses anything over 5 MB, but the stdin path buffered the whole stream first, soyes V | astryx layout check -(or any runaway producer) grew memory until the process died, with no envelope and no code. After the change stdin stops at the same 5 MB and the command fails withERR_INVALID_ARGUMENTin both modes; theyespipeline now ends in about a second.Problem and solution fit
readExpressioninclients/cli/commands/layout.mjssize-checks--filebefore reading it, while the-branch concatenated every stdin chunk with no limit.The stdin loop now counts bytes and stops with a coded error once the total passes the cap. The cap is one constant shared by both paths.
Expected behavior and authority
docs/architecture/cli-surface.md(authority: current):--jsonemission is one valid envelope." — an out-of-memory crash emits none.Smallest restoration
The byte count and check in the stdin branch, the shared constant, and the exit-code lines of the
layout check/layout expanddocs (now "over 5 MB (from stdin or --file)"). No change to the--filepath's behavior or code.ERR_INVALID_ARGUMENTis the existing code the layout commands already use for an unusable expression (an empty one). The--filepath still reports an oversized file asERR_FILE_NOT_FOUND, a code documented as "A required input file did not exist"; changing that emitted code is a separate decision and is not part of this change.Evidence
Vwas read whole and reported valid (exit 0);yes V | astryx layout check - --jsonproduced no output and had grown to 2.5 GB resident when a 3-second timeout killed it.{"code": "ERR_INVALID_ARGUMENT", "error": "The layout expression on stdin is too large (max 5 MB)"}; theyespipeline exits in about 1 s.echo 'V > B' | astryx layout check - --jsonis still valid (exit 0), and--filebehaves as before.clients/cli/commands/layout.stdin-cap.test.mjsspawns the real bin with piped input (the in-process harness has no stdin). With the fix reverted the oversize test fails (exit 0); with the fix it passes, and the normal-input test passes both ways.Scope
Testing