Skip to content

fix(persistence): refuse a chained search whose hop passes a ceiling - #2949

Open
angela-helios wants to merge 1 commit into
mainfrom
fix/chain-resolution-id-cap
Open

angela-helios wants to merge 1 commit into
mainfrom
fix/chain-resolution-id-cap

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 #2948

Summary

The chain resolver drained each hop of a chained or _has search whole into memory before turning it into an _id filter. On a large tenant, one Patient?_has:Observation:subject:status=final held every matching Observation id, and in search_all_pages every whole resource.

Each hop now has a ceiling, checked after every page:

  • search_all_ids: 300,000 ids (MAX_HOP_IDS), the ceiling MongoDB already puts on its result id sets;
  • search_all_pages: 100,000 resources (MAX_HOP_RESOURCES), lower because it keeps whole resources.

A hop that passes its ceiling fails with SearchError::TooManyResults { count, max }, which the REST search handler already maps to 422. The hop is not truncated into a wrong answer. A test-only task-local lowers the ceiling, as MongoDB's with_result_id_cap does.

Tests

chain_resolver::tests::a_hop_past_its_ceiling_is_refused_not_truncated runs on both drain paths, with the ceiling lowered to 3:

  • four scripted matches fail with TooManyResults { count: 4, max: 3 };
  • three drain whole.

With the ceiling disabled, the four are drained (Ok(["a","b","c","d"])) and the test fails.

The existing 33 resolver tests pass, including the 2101-row multi-page drain. Clippy on helios-persistence --lib --tests is clean.

The chain resolver drained every hop of a chained or _has search into memory
before turning it into an _id filter, with no ceiling. A hop now stops at
300,000 ids (100,000 whole resources on the full-page path) and fails with
TooManyResults, answered 422, instead of growing without bound.

Closes #2948
@claude

claude Bot commented Nov 25, 2026

Copy link
Copy Markdown

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

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.

Chained and _has search hops are drained into memory with no ceiling

1 participant