Fixing dockey/doc_id mismatch when no metadata is found#1288
Merged
jamesbraza merged 2 commits intomainfrom Feb 14, 2026
Merged
Fixing dockey/doc_id mismatch when no metadata is found#1288jamesbraza merged 2 commits intomainfrom
dockey/doc_id mismatch when no metadata is found#1288jamesbraza merged 2 commits intomainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a bug where dockey and doc_id could become mismatched when metadata providers fail to return metadata for a document. The issue caused flaky test failures in test_get_directory_index[check-md-query].
Changes:
- Modified the fallback path in
upgrade_doc_to_doc_detailsto include"doc_id"infields_to_overwrite_from_metadatawhendockeywas auto-generated fromcontent_hash - This allows the Pydantic validator to sync
dockeywith the newly computeddoc_id, ensuring both fields use the same 16-character hash
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
73b5fe7 to
a0f1439
Compare
a0f1439 to
aa5011d
Compare
aa5011d to
5caf393
Compare
When both metadata providers fail, `upgrade_doc_to_doc_details`'s fallback path set `fields_to_overwrite_from_metadata` to an empty set. This prevented the Pydantic validator from syncing `dockey` with the newly computed `doc_id` (which incorporates `content_hash`), leaving `dockey` as the raw 32-char content hash while `doc_id` became a 16-char truncated hash via `compute_unique_doc_id()`. Now, when `dockey` was auto-generated from `content_hash`, `"doc_id"` is included in `fields_to_overwrite_from_metadata` so the validator can sync them. User-provided dockey values are still preserved. Fixes the flaky `test_get_directory_index[check-md-query]` CI failure. Co-authored-by: Cursor <cursoragent@cursor.com>
5caf393 to
35e8ce5
Compare
Same inconsistency from #1029: `check-md-query` was updated to expect `compute_unique_doc_id`-based IDs but `check-txt-query` still expected the raw 32-char `md5sum`. With the dockey/doc_id sync fix, dockey is now always aligned with `compute_unique_doc_id`, so update the assertion. Co-authored-by: Cursor <cursoragent@cursor.com>
02a4a0b to
0bbff19
Compare
sidnarayanan
approved these changes
Feb 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
test_get_directory_index[check-md-query]CI failure caused by adockey/doc_idmismatch when both Crossref and Semantic Scholar fail to return metadata for "Gravity Hill"upgrade_doc_to_doc_detailsfalls back (no metadata found) and thedockeywas auto-generated fromcontent_hash,"doc_id"is now included infields_to_overwrite_from_metadataso the Pydantic validator can syncdockeywith the newly computeddoc_iddockeyvalues (e.g.dockey="test"intest_docs_lifecycle) are still preservedRoot cause
When both metadata providers fail, the fallback path in
DocMetadataClient.upgrade_doc_to_doc_detailssetfields_to_overwrite_from_metadata = set(). This preventedoverwrite_docname_dockey_for_compatibility_w_docfrom syncingdockeywithdoc_id. Thedockeystayed as the raw 32-charcontent_hashwhile the Pydantic validator recomputeddoc_idas a 16-char hash viacompute_unique_doc_id(), so neither expected ID in the test matched.The latent bug was introduced by #1029, which changed the test expectations from raw
md5sum()(32-char) tocompute_unique_doc_id(None, md5sum(...))(16-char) without updating the fallback path to keepdockeyin sync. CI passed at the time because the bug only surfaces when metadata providers fail — before #1029, the fallbackdockey(raw content hash) still matched the expected IDs, so provider failures were harmless. The test started failing now because Crossref is returning errors in CI (likely an expiredCROSSREF_API_KEYsecret), pushing the test into the broken fallback path.Test plan
dockeynow equalsdoc_id(93085aa5ff54865c)test_docs_lifecyclestill passes (user-provideddockey="test"is preserved)test_clients.pyandtest_paperqa.py::test_docs_lifecyclepass