Skip to content

Conversation

@markscott-ms
Copy link
Contributor

Description

@ConfuddledPenguin reported an issue during their Advent of CALM, where Copilot generated incorrect schema in a pattern, causing calm validate to fail after many seconds with an out of memory exception.

Here is a minimal pattern that would fail:

{
    "$schema": "https://json-schema.org/draft/2019-09/schema"
}

calm validate -p <filename>.

I traced this to an infinite loop in schema resolution by AJV. If the CALM schema, or JSON Schema Draft 2020-12 is referenced, all is well, but any other JSON Schema Draft leads to an infinite loop.

This PR causes validation to fail quickly and with a meaningful error if AJV seeks to load a JSON Schema:

error [json-schema-validator]:    Error fetching schema from schema directory: Error: Attempted to load standard JSON Schema with ID https://json-schema.org/draft-06/schema. This is not supported.
info [calm-validate]:     Formatting output as json
{
    "jsonSchemaValidationOutputs": [
        {
            "code": "json-schema",
            "severity": "error",
            "message": "Cannot read properties of undefined (reading '$schema')",
            "path": "/",
            "source": "pattern"
        }
    ],
    "spectralSchemaValidationOutputs": [],
    "hasErrors": true,
    "hasWarnings": false
}

Type of Change

  • 🐛 Bug fix (non-breaking change which fixes an issue)
  • ✨ New feature (non-breaking change which adds functionality)
  • 💥 Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • 📚 Documentation update
  • 🎨 Code style/formatting changes
  • ♻️ Refactoring (no functional changes)
  • ⚡ Performance improvements
  • ✅ Test additions or updates
  • 🔧 Chore (maintenance, dependencies, CI, etc.)

Affected Components

  • CLI (cli/)
  • Shared (shared/)
  • CALM Widgets (calm-widgets/)
  • CALM Hub (calm-hub/)
  • CALM Hub UI (calm-hub-ui/)
  • Documentation (docs/)
  • VS Code Extension (calm-plugins/vscode/)
  • Dependencies
  • CI/CD

Commit Message Format ✅

Testing

  • I have tested my changes locally
  • I have added/updated unit tests
  • All existing tests pass

Checklist

  • My commits follow the conventional commit format
  • I have updated documentation if necessary
  • I have added tests for my changes (if applicable)
  • My changes follow the project's coding standards

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes an infinite recursion issue in schema validation that occurs when patterns reference JSON Schema drafts other than CALM schema or JSON Schema Draft 2020-12. The fix adds an early validation check to reject attempts to load standard JSON Schemas, preventing AJV from entering an infinite loop.

Key changes:

  • Added protection against loading standard JSON Schemas by checking for json-schema.org URLs
  • Added unit and E2E tests to verify the fix works correctly
  • Code formatting improvements in test files (whitespace cleanup)

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
shared/src/schema-directory.ts Added check to reject json-schema.org URL references before attempting to load them
shared/src/schema-directory.spec.ts Added unit test for JSON Schema rejection and cleaned up whitespace formatting
shared/src/commands/validate/validate.e2e.spec.ts Added E2E tests for both invalid and valid JSON Schema references

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

public async getSchema(schemaId: string): Promise<object> {
if (!this.schemas.has(schemaId)) {
try {
if (schemaId.startsWith('https://json-schema.org') || schemaId.startsWith('http://json-schema.org')) {
Copy link
Contributor

@aamanrebello aamanrebello Jan 7, 2026

Choose a reason for hiding this comment

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

Could use regex matching here, something like http(s?)://..., but this is not a big deal.

@rocketstack-matt rocketstack-matt merged commit c415b5b into finos:main Jan 8, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants