elegance: type LanceDBBackend.get_by_source() failure instead of swallowing it to []#224
Merged
Antawari merged 1 commit intoJun 14, 2026
Conversation
get_by_source() caught `except Exception` and returned [], making a genuine LanceDB lookup failure (corrupt table, unreachable store, vector-op error) indistinguishable from "no entries for this source path" — the swallowed failure the Elegance Law forbids, and the exact masquerade its structural sibling query() already had removed. Now a thrown lookup surfaces as a typed, retryable RetrievalError (the one Bonfire failure vocabulary) carrying the originating exception as __cause__ and structured context (source_path). A genuine empty result (zero matching entries) stays a legitimate success and still returns []. exists() keeps its deliberate, separately-tested fail-open dedup contract untouched. The implementation is net-zero in line/statement count, so the src/bonfire file budget is unmoved; the only baseline ratchet is the tests/unit package total re-frozen for the new contract test (a new file under the 500-line ceiling, re-anchored per BASELINE-CONVENTIONS.md). RED: tests/unit/test_knowledge_backend_get_by_source_typed_failure.py pins the typed-failure-vs-swallow contract using a fake exploding table (lancedb is not a test dependency). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
DO NOT MERGE — fleet quality burn unit; opened for review only.
The unit
LanceDBBackend.get_by_source()caughtexcept Exception as exc:and returned[], making a genuine LanceDB lookup failure (corrupt table, unreachable store,a vector-op error) indistinguishable from "no entries for this source path".
That is the swallowed-failure the Elegance Law forbids — and the exact masquerade
its structural sibling
query()already had removed (it now raises a typedRetrievalError).get_by_source()was the overlooked sibling: sametable.search(...).where(...).to_list()shape, same "list of entries" return,same indistinguishable
[].It is the deliberate inverse of
exists(), whose fail-open-to-Falseis adocumented, separately-test-pinned dedup contract (a false negative there only
causes a harmless duplicate store).
get_by_source()has no such fail-opencaller — its list is the answer — so, like
query(), it must raise ratherthan degrade. That
exists()contract is left untouched.The falsifiable claim it satisfies
After this change the oracle is satisfied: a thrown lookup surfaces as a typed,
retryable
RetrievalError(code == "retrieval",retryable is True) carryingthe originating exception as
__cause__and structured context (source_path).A genuine empty result (zero matching entries) stays a legitimate success and
still returns
[].TDD
tests/unit/test_knowledge_backend_get_by_source_typed_failure.py(RED first):4 tests — typed-raise on backend failure,
__cause__chaining,source_pathin context, and zero-hits-is-a-success. Uses a fake exploding table
(
lancedbis not a test dependency), mirroring the siblingquery()test.Budget / anti-gaming notes
(
backend.pymeasure 244 → 244), so thesrc/bonfirefile budget isunmoved — no budget was inflated.
tests/unitpackage total re-frozen58858 → 59014 (+156, exactly the new test file, which is a new file under
the 500-line ceiling), the documented re-anchor per
configs/BASELINE-CONVENTIONS.md. No file row changed; no offender waslaundered.
Gate
Reproduced locally against a clean export at the pinned kit SHA: CI lint
(
ruff check+ruff format --check), fullpytest(4421 passed), theBubbleGum kit battery (
cf-sticky-check,cf-file-budget: clean,cf-mirror-check,cf-recursion-check,cf-exemptions, mypy ratchet =0 new errors), and the smoke gate (wheel + sdist build/twine/smoke) — all green.