Skip to content

bug(llc): the KB context's sources answers tenancy, not where the document came from #17618

Description

@mrveiss

The defect

llc/kb/context_builder.py's _format_inherited_context returned
{chunks, sources}, and built sources like this:

if result.get("source_company_id"):
    sources_set.add(result["source_company_id"])

So on the LLC side sources means the company a chunk was inherited from, not the
document it came from.
The document's provenance rides along inside each chunk's
metadata and is never surfaced. A caller asking where a chunk came from receives a
tenant id, with no signal that it answered a different question.

Why it is its own issue

It is independent of the other two provenance defects found under #17527 and has a
different cause:

layer what occupies the provenance slot owner
graph "source": "ecl_pipeline", a constant #17588
LLC retrieval source_company_id, a tenancy answer under a provenance-shaped name this
ingest vocabulary five dialects of source, one leg with none #17527's decision

All three are one shape — a plausible value from a different question, with nothing
signalling the substitution — but each needs its own fix, and this one was reached by
asking what the LLC leg of #17527's round trip actually returns.

The cause is the third row. sources answered tenancy because there was no
single field it could have answered with: metadata["source"] is a filename, a
URN, a literal category or free text depending on the intake leg, and for a
connector-ingested fact the key does not exist.

Fixed

document_sources is returned beside sources, from
knowledge/provenance.py's accessor, which speaks all five dialects and returns
nothing for a shape it does not recognise rather than a placeholder.

The tenancy list is deliberately unchanged — a caller relies on it, and removing it
to make room for the other meaning would trade one wrong answer for a break.

Acceptance criteria

  • The document's origin is retrievable from the LLC context, not only the
    tenant's — document_sources, asserted in
    llc/tests/test_context_builder_document_sources.py.
  • sources keeps its existing meaning and its existing callers.
  • A chunk whose provenance is unrecognisable adds no entry, rather than a
    placeholder.
  • The key is present on an empty result, so a caller need not branch on whether
    it exists.
  • The chunk still carries its raw metadata, so a caller that knows a leg's
    dialect better than the accessor does can read it directly.

Parent: #17527.

Activity

  1. mrveiss commented on Oct 12, 2026

    @mrveiss
    OwnerAuthor

    AC evidence (merged in #18504, e83eb77)

    • ✅ AC1 document_sources returned at autobot-backend/llc/kb/context_builder.py:279; test llc/tests/test_context_builder_document_sources.py::test_document_origin_is_surfaced_alongside_the_tenancy_list
    • ✅ AC2 sources unchanged (context_builder.py:271-276); test_the_two_lists_answer_different_questions
    • ✅ AC3 test_a_chunk_with_no_recognisable_provenance_adds_no_entry
    • ✅ AC4 empty result returns the key (context_builder.py:256); test_no_results_still_carries_the_key
    • ✅ AC5 chunk keeps raw metadata (context_builder.py:268); test_the_chunk_still_carries_its_raw_metadata
    • (body boxes were already ticked; no edit needed)

    All verifiable criteria met on origin/main; issue stays closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    backendbugSomething isn't working

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions