Skip to content

feat(fast-validator): add multi-error accumulation and RFC 6901 JSON pointer precision - #308

Merged
jonhealy1 merged 16 commits into
StacLabs:mainfrom
jonhealy1:improve-fast-error-msg
Sep 4, 2026
Merged

feat(fast-validator): add multi-error accumulation and RFC 6901 JSON pointer precision#308
jonhealy1 merged 16 commits into
StacLabs:mainfrom
jonhealy1:improve-fast-error-msg

Conversation

@jonhealy1

@jonhealy1 jonhealy1 commented Sep 1, 2026

Copy link
Copy Markdown
Collaborator

Summary

This PR resolves issues with vague error reporting during high-speed batch validation. Previously, fastjsonschema swallowed nested field paths behind generic top-level $ root errors when evaluating composite extension schemas (oneOf/anyOf). Additionally, the validation loop short-circuited on the first broken field, requiring multi-pass debugging across large batch jobs.

This release introduces multi-error accumulation, lazy branch unrolling, RFC 6901 JSON Pointer formatting, and multi-tier schema compilation to ensure 100% extension compatibility at full C-speed.


Key Changes

  • Multi-Error Accumulation (FastSTACMultiValidationError)

    • Refactored the FastValidator execution pass to evaluate the base schema and all active item extensions in a single run.
    • Collects every distinct field failure on an item into a container exception rather than aborting on the first error.
  • RFC 6901 JSON Pointer Normalization (parse_json_pointer)

    • Translates fastjsonschema's internal CPython variable names (e.g., data['properties']['eo:cloud_cover'] and data.properties.sat:relative_orbit) into standard JSON Pointers (e.g., $.properties.eo:cloud_cover).
  • Compile-Time Branch Unrolling (compile_unrolled_schema)

    • Pre-compiles oneOf/anyOf subschema branches independently to prevent fastjsonschema's internal try...except exception handling from discarding leaf-node field paths.
    • Unmasks exact failure locations without running fallback validation libraries on failing records.
  • Resilient Multi-Tier Schema Patching

    • Updated optimize_schema_for_compiler() to strip restrictive additionalProperties: false flags from shared extension objects.
    • Prunes empty subschemas ({}) and draft-2020-12 conditional blocks that caused IndentationError or JsonSchemaDefinitionException skips on extensions like file/v2.1.0, product/v1.0.0, and storage/v2.0.0.

Benchmark & Diagnostic Comparison

Before (v4.5.2):

❌ [Extension: https://stac-extensions.github.io/eo/v1.0.0/schema.json] Field '$': must be valid exactly by one definition (0 matches found)

After (v4.6.0):

❌ [Extension: https://stac-extensions.github.io/eo/v2.0.0/schema.json] Field '$.properties.eo:cloud_cover': must be smaller than or equal to 100
   Affected Items: 1
   Examples:       S2A_MSIL2A_20220217T183431_N0510_R027_T13VEK_20240516T022440

❌ [Extension: https://stac-extensions.github.io/sat/v1.1.0/schema.json] Field '$.properties.sat:relative_orbit': must be integer
   Affected Items: 1
   Examples:       S2A_MSIL2A_20220217T183431_N0510_R027_T13VEK_20240516T022440
Execution Overhead: Average execution time remains under ~0.35 ms per object (~3,000 items/sec) on batch runs.

@jonhealy1 jonhealy1 changed the title Improve fast error messaging feat(fast-validator): add multi-error accumulation and RFC 6901 JSON pointer precision Sep 1, 2026
@jonhealy1
jonhealy1 marked this pull request as ready for review September 2, 2026 02:34
@jonhealy1
jonhealy1 requested a balanced review from Copilot September 2, 2026 02:36

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 Needs a closer look

It changes core validation semantics by recursively stripping additionalProperties/unevaluatedProperties: false (silently weakening validation) and reworks error control flow, which warrants human review beyond the flagged stray artifact.

Pull request overview

This PR overhauls the --fast validator (fast_validator.py) to improve error reporting during high-speed batch validation. Instead of aborting on the first failure and surfacing generic $ root errors from fastjsonschema's oneOf/anyOf handling, it now accumulates all failures per item, attributes each to its schema source, and normalizes field paths into $.-style pointers. It also adds more aggressive schema patching so more community extensions compile under fastjsonschema without being skipped.

Changes:

  • Adds parse_json_pointer, FastSTACValidationError, and FastSTACMultiValidationError, plus multi-error accumulation across base + all extension schemas in validator/run/run_dict/_validate_recursive.
  • Adds compile_unrolled_schema (per-branch oneOf/anyOf compilation to recover exact field paths) and expands optimize_schema_for_compiler to strip additionalProperties/unevaluatedProperties: false, $comment, and prune empty subschemas.
  • Bumps version to 4.6.0 (CHANGELOG + pyproject.toml), updates a test collection expectation to v1.1.0 schemas, removes a network-dependent test, and adds tests/test_error_reporting.py.
File summaries
File Description
stac_validator/fast_validator.py Core logic: JSON-pointer normalization, error classes, multi-error accumulation, branch unrolling, broader schema patching.
tests/test_error_reporting.py New offline tests covering pointer parsing, error classes, oneOf unmasking, and multi-error accumulation.
tests/test_validate_item_collection.py Updates expected schema versions to v1.1.0/projection v2.0.0; removes a remote paginated test.
test.json Adds a 3089-line Sentinel-2 item at the repo root (appears to be a benchmarking/debug leftover).
pyproject.toml Version bump 4.5.2 → 4.6.0.
CHANGELOG.md Adds v4.6.0 release notes and compare links.
Review details
  • Files reviewed: 5/6 changed files
  • Comments generated: 2
  • Review effort level: Balanced

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread stac_validator/fast_validator.py Outdated
Comment thread test.json Outdated
@jonhealy1
jonhealy1 merged commit 2b66fd4 into StacLabs:main Sep 4, 2026
6 checks passed
@jonhealy1
jonhealy1 deleted the improve-fast-error-msg branch September 4, 2026 06:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants