Skip to content

fix: resolve entity expansion limit for container deploys#594

Open
jesseturner21 wants to merge 1 commit intomainfrom
fix/container-deploy-entity-expansion-limit
Open

fix: resolve entity expansion limit for container deploys#594
jesseturner21 wants to merge 1 commit intomainfrom
fix/container-deploy-entity-expansion-limit

Conversation

@jesseturner21
Copy link
Contributor

Summary

  • Patch fast-xml-parser entity expansion limit in wrapper.ts to prevent container deploys from failing with Entity expansion limit exceeded: 1015 > 1000. Container build stacks create enough CloudFormation resources that DescribeStackEvents XML responses exceed the library's default 1000-entity limit.
  • Improve e2e test teardown in e2e-helper.ts to handle stacks in ROLLBACK_COMPLETE/ROLLBACK_FAILED states by deleting them directly via CloudFormation API, with a fallback for normal teardown failures.

Root Cause

The fast-xml-parser v5.x library (used by AWS SDK → CDK toolkit) defaults maxTotalExpansions to 1000. Container builds create ~30+ CloudFormation resources (ECR, KMS, CodeBuild, Lambda custom resource, IAM roles/policies), pushing the XML entity count in API responses over 1000 — especially in CI accounts with accumulated stack event history.

Approach

The fast-xml-parser CJS bundle uses webpack-style configurable: false getters on its exports, preventing replacement of XMLParser. Instead, we patch XMLParser.prototype.parse (which is writable) to raise the limit to 100,000 before every parse call. The require() uses a split module name (['fast-xml', 'parser'].join('-')) to prevent esbuild from bundling it, ensuring the patch targets the same node_modules copy that @aws-cdk/toolkit-lib loads at runtime.

Test plan

  • Manual container deploy succeeded (CREATE_COMPLETE) — previously failed with entity expansion error
  • Stack cleanup (empty deploy) succeeded
  • Build passes (tsc, eslint, prettier, secretlint)
  • CI e2e tests pass (container-strands-bedrock)

Related

🤖 Generated with Claude Code

The fast-xml-parser v5.x library defaults maxTotalExpansions to 1000.
Container build stacks create enough CloudFormation resources that
DescribeStackEvents XML responses exceed this limit (1015+ entities),
causing CDK deploy to fail with "Entity expansion limit exceeded".

Patch XMLParser.prototype.parse to raise the limit to 100000 before
every parse call. The fast-xml-parser CJS bundle uses non-configurable
webpack getters, so we cannot replace the XMLParser constructor — but
prototype methods are writable. The module name is split in the require
call to prevent esbuild from bundling it, ensuring the patch targets
the same node_modules copy that @aws-cdk/toolkit-lib loads at runtime.

Also improve e2e test teardown to handle stacks in ROLLBACK_COMPLETE
or ROLLBACK_FAILED states by deleting them directly via CloudFormation
API, with a fallback for normal teardown failures.

Constraint: fast-xml-parser exports are configurable:false (webpack getter)
Constraint: @aws-cdk/toolkit-lib is externalized by esbuild, so it uses the node_modules copy of fast-xml-parser
Rejected: Monkey-patch module.exports.XMLParser | non-configurable getter prevents override
Rejected: Object.defineProperty on exports | configurable:false throws TypeError
Rejected: Patching fxp.cjs file on disk | fragile, undone by npm install
Confidence: high
Scope-risk: narrow

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@jesseturner21 jesseturner21 requested a review from a team March 22, 2026 18:43
@github-actions github-actions bot added the size/m PR size: M label Mar 22, 2026
@github-actions
Copy link
Contributor

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 43.09% 4907 / 11387
🔵 Statements 42.69% 5197 / 12172
🔵 Functions 42.43% 901 / 2123
🔵 Branches 44.48% 3164 / 7112
Generated in workflow #1107 for commit beff600 by the Vitest Coverage Report Action

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/m PR size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant