refactor: derivation.derive() pure function for ingest pipeline (#261) - #270
Closed
robotrocketscience wants to merge 4 commits into
Closed
refactor: derivation.derive() pure function for ingest pipeline (#261)#270robotrocketscience wants to merge 4 commits into
robotrocketscience wants to merge 4 commits into
Conversation
LLM-router path retains direct Belief construction: the router returns a custom origin (DOCUMENT_RECENT, etc.) that is not expressible through the current DerivationInput fields. Regex path (production default) is fully routed through derive().
Owner
Author
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
Closes #261 (partial — see Scope below). Adds
src/aelfrice/derivation.pyexposing a purederive(DerivationInput) -> DerivationOutputcallable that takes raw text + source metadata and returns aBelief + Edge[](or a skip with reason). ZeroMemoryStoredependency — same input, same output, no I/O.The derivation half of the pipeline is now testable in isolation and provides the pure callable the v2.x
replay_full_equalityflip-readiness probe needs. Each call site that goes throughderive()is rewritten to: build input → derive → check duplicate → record_ingest + insert.Changes
src/aelfrice/derivation.py(213 lines):DerivationInput,DerivationOutput,derive(). Two dispatch paths: classify-based (filesystem/git/python_ast/feedback_loop_synthesis/legacy_unknown) and lock-based (mcp_remember/cli_remember).tests/test_derivation.py(319 lines, 23 tests): purity, each source_kind, lock priors, classifier rejection, unknown-kind ValueError.src/aelfrice/ingest.pyandsrc/aelfrice/scanner.py(regex path) to callderive().Scope: 2 of 6 entry points refactored
The issue body asked for all six entry points. Three were left direct-construction; reasons:
mcp_server.tool_lockandcli._cmd_lock— usesha256("lock\x00" + content)as belief id, a deliberately distinct namespace fromderive()'ssha256(source_path \x00 text)scheme. Routing throughderive()would compute different ids and silently break belief lookup for existing locked beliefs in production stores. Data-identity break, not a refactor — rejected.triple_extractor._resolve_or_create_belief— usessha256("triple\x00normalized_phrase")id namespace + fixed (1.0, 1.0) priors for noun-phrase entity beliefs. Same id-namespace incompatibility — rejected.classification.accept_classifications— applies host-LLM classification results that have already been computed. Callingderive()here would re-run the regex classifier and potentially override the host's typed results. Behavior change, not a refactor — rejected.llm_routerpath — returns customorigin(e.g.DOCUMENT_RECENT) not representable in currentDerivationInput. The default no-LLM regex path (production default) is fully routed.These four sites need follow-up design work before they can be unified — id-namespace migration for #1/#2, classifier-replay handling for #3,
DerivationInputextension for #4. Each is queen-tier, not mechanical refactor. Recommend filing as follow-up issues if the unification is wanted; otherwise leaving them as their own derivation paths is defensible.Test plan
tests/test_derivation.py: 23 new tests, all pass.test_serve_raises_clear_error_when_fastmcp_missing— environment-dependent, fails onmainHEAD too).main(post fix: stamp beliefs.last_retrieved_at on hook-driven retrieval (#222) #266 merge); no conflicts.Commits
f258fa1— add derivation.derive() pure functiona76fb18— route ingest through derive()14ac869— route scanner regex path through derive()Out of scope
replay_full_equalityconsumption ([v2.x] Implement replay_full_equality — flip-readiness probe #262).legacy_unknownmigration ([v2.x] legacy_unknown migration for pre-v2.0 stores #263).