Skip to content

Bind spreadsheet reuse to canonical concept existence - #299

Merged
witbrock merged 1 commit into
mainfrom
jvnautosci-2592-reuse-existence-gate
Jul 23, 2026
Merged

witbrock merged 1 commit into
mainfrom
jvnautosci-2592-reuse-existence-gate

Conversation

@witbrock

Copy link
Copy Markdown
Member

Outcome

Fix the live JVNAUTOSCI-2592 failure where a model-valid reuse_existing plan referenced deterministic future concept IDs that did not yet exist, causing every first-write parent relationship to fail with source_concept_not_found.

Change

  • Preview the deterministic spreadsheet KR guard and collect only its authorised stable concept IDs.
  • Resolve all candidates in one access-controlled, projection-only, indexed and 3-second-bounded canonical read.
  • Bind each slot before model planning:
    • absent ID -> create only;
    • accessible existing ID -> reuse_existing only.
  • Fail closed with a typed aggregate error if the canonical store/read is unavailable.
  • Preserve the generic model-driven KR plan; the existing guard rejects any model decision that conflicts with canonical existence.
  • Reuse the existing Atlas-efficient concept-existence helper rather than introducing per-concept reads.

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

  • 114 focused spreadsheet, KR workflow, control-flow and metadata tests pass.
  • Ruff and diff checks pass.
  • Seed-version guard passes; no represented workflow authority changed.
  • A privacy-safe read-only probe against the actual failed record now yields 10 create-only slots, 0 reuse-only slots and 0 ambiguous decisions.
  • Independent review found no blocking issue; the unrelated untracked uv.lock is excluded.

Jira: JVNAUTOSCI-2592

Copilot AI review requested due to automatic review settings July 23, 2026 23:16

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.

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 vs reuse_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)
@witbrock
witbrock merged commit b648afb into main Jul 23, 2026
5 checks passed
@witbrock
witbrock deleted the jvnautosci-2592-reuse-existence-gate branch July 28, 2026 12:09
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