Skip to content

fix(validator): stop caching constraint focus paths and cap the AST cache - #2971

Open
angela-helios wants to merge 1 commit into
mainfrom
fix/validator-constraint-cache-bound
Open

angela-helios wants to merge 1 commit into
mainfrom
fix/validator-constraint-cache-bound

Conversation

@angela-helios

Copy link
Copy Markdown
Contributor

Stacked on #2901. This branch starts from #2901's branch so that Test FHIRPath passes against the current fhir-test-cases master; its commit leaves this diff once #2901 merges.

Closes #2970

Summary

FhirPathConstraintEvaluator lives as long as the process and cached every expression it parsed, with no ceiling. That included the focus path of each constrained node, which carries the array indices of the resource being validated (contact[0], contact[1], …), so the cache grew by one permanent entry per distinct index any caller sent.

  • Focus paths are now parsed per evaluation with helios_fhirpath::parse_expression and not cached.
  • The invariant cache keeps at most MAX_CACHED_ASTS (4096) entries. Past that, a new invariant is parsed for its own evaluation and not kept, so tenant profiles with ever more distinct invariants cannot grow it without bound either.

Tests

fhirpath_effects::tests::focus_paths_do_not_grow_the_ast_cache_and_invariants_are_capped (R4, fhirpath feature):

  • evaluating name.exists() on 50 Patient.contact.N paths passes and leaves one cache entry;
  • 4106 distinct invariants leave exactly 4096.

With focus paths cached again and no ceiling, the first assertion fails with 51 entries.

cargo test -p helios-fhir-validator --features fhirpath: 142 passed. Clippy on the crate (--features fhirpath --lib --tests) is clean.

…ache

The process-lifetime FHIRPath constraint evaluator cached every expression
it parsed, focus paths included, and those carry the array indices of the
resource being validated, so each distinct index added a permanent entry.
Focus paths are now parsed per evaluation and not cached, and the invariant
cache keeps at most 4096 entries.

Closes #2970

This branch has not been deployed

No deployments
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.

Validator constraint AST cache grows by one entry per array index validated

1 participant