Repository navigation
Bind spreadsheet reuse to canonical concept existence - #299
Merged
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes a spreadsheet-record ingestion failure mode where reuse_existing could be planned for deterministic concept IDs that don’t actually exist yet, by binding each concept slot’s allowed decision to canonical concept existence before model planning/materialisation.
Changes:
- Add a bounded, access-controlled canonical existence lookup to resolve which deterministic concept IDs are actually present and reusable.
- Bind spreadsheet KR materialisation guard slots to
create-only vsreuse_existing-only based on that existence read-back. - Add focused tests covering the new binding behaviour, guard enforcement, and fail-closed handling when the concept store/read is unavailable.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tests/backend/test_spreadsheet_record_ingestion_service.py | Adds an end-to-end test asserting slot decisions are bound to canonical existence (create-only vs reuse-only). |
| tests/backend/test_source_processing_marker_service.py | Adds a regression test ensuring existence reads fail closed when the concept store is unavailable. |
| tests/backend/test_kr_materialisation_guard_service.py | Adds tests asserting the guard rejects plans that violate the bound decisions. |
| tests/backend/test_internal_mcp_spreadsheet_record_tools.py | Adds tests for single bounded existence read behaviour and fail-closed MCP tool responses. |
| src/backend/services/spreadsheet_record_ingestion_service.py | Threads reusable existing concept IDs into request construction and clarifies prompt authority language. |
| src/backend/services/spreadsheet_materialisation_guard_service.py | Implements slot decision binding based on reusable existing concept IDs. |
| src/backend/services/source_processing_marker_service.py | Introduces a public helper for bounded, access-controlled concept existence resolution with fail-closed semantics. |
| src/backend/integrations/internal_mcp/spreadsheet_record_tools.py | Binds reuse authority by previewing the guard, resolving existing IDs in one read, then building the bound request. |
Comment on lines
+201
to
+210
| def find_existing_accessible_concept_ids( | ||
| concept_ids: Sequence[str], | ||
| ) -> set[str]: | ||
| """Return exact accessible concept IDs using one bounded indexed read.""" | ||
|
|
||
| from ..db.repositories.concepts_repository import ConceptsRepository | ||
|
|
||
| if ConceptsRepository.collection() is None: | ||
| raise RuntimeError("concept_store_unavailable") | ||
| return _find_existing_concept_ids(concept_ids) |
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.
Outcome
Fix the live JVNAUTOSCI-2592 failure where a model-valid
reuse_existingplan referenced deterministic future concept IDs that did not yet exist, causing every first-write parent relationship to fail withsource_concept_not_found.Change
createonly;reuse_existingonly.Authority and privacy
This is a deterministic idempotency/write boundary. Workbook contents remain untrusted evidence; actor/org access filtering remains applied by the repository path. No workbook names, paths, hashes, cell values, person names, or private operational IDs are logged by the added checks.
Validation
uv.lockis excluded.Jira: JVNAUTOSCI-2592