Current-graph generation admission and execution

gestaltdb.reasoning.adapters.graph_execution connects complete current-record projection to shared generation admission and the explicit executor pipeline. It does not accept caller triples, existing result objects or partial frontier answers as complete input. Existing full projection and Indexed demand over current property graphs APIs remain unchanged.

Standalone example. Choose the capability-qualified installation tab below.

Current-source admission needs authenticated mutable snapshots; plain PyRex and LevelDB are excluded.

1python -m pip install "gestaltdb[lmdb]"
 1from tempfile import TemporaryDirectory
 2from gestaltdb.graphdb import Edge, GraphDB, Node
 3from gestaltdb.ontology import Ontology, SubPropertyOf, compile_ontology
 4from gestaltdb.reasoning import Fact, ReasoningLimits
 5from gestaltdb.reasoning.adapters.generation import catalog_for_ontology
 6from gestaltdb.reasoning.adapters.graph import GraphMapping
 7from gestaltdb.reasoning.adapters.graph_execution import bind_current_generation, execute_current_graph
 8from gestaltdb.reasoning.adapters.inferred_view import PathPattern, open_inferred_view
 9from gestaltdb.reasoning.executors import ExecutorRequest
10from gestaltdb.reasoning.plans import PreparedProgram
11from gestaltdb.reasoning.relational import CompilationIdentity
12
13compiled = compile_ontology(Ontology("relations", [SubPropertyOf("edge", "related")]))
14catalog = catalog_for_ontology(compiled)
15mapping = GraphMapping(edge_types=(("KNOWS", "edge"),))
16with TemporaryDirectory() as path:
17    graph = GraphDB.create(path, backend='lmdb', serializer='json')
18    try:
19        graph.put_nodes([Node("a"), Node("b")])
20        graph.put_edge(Edge("ab", "a", "b", {"type": "KNOWS"}))
21        with graph.current_read_view(require_verifiable=True) as view:
22            binding = bind_current_generation(view, compiled, catalog, mapping=mapping)
23            identity = CompilationIdentity(compiled.program.digest, binding.identity.context,
24                "external-strings-v1", "positive-binary-entity-v1", "indexed-scc-v1")
25            plan = PreparedProgram(compiled.program, identity)
26            result = execute_current_graph(view, compiled, catalog, mapping=mapping,
27                limits=ReasoningLimits(), expected_generation=binding.identity, plan=plan,
28                executor_request=ExecutorRequest(preferred="indexed-scc"))
29            assert Fact("a", "related", "b") in result.outcome.result.facts
30            assert result.outcome.telemetry.admission_digest == binding.identity.digest
31            result.binding.verify_view(view)
32            inferred = open_inferred_view(view, compiled, catalog, mapping=mapping,
33                                          limits=ReasoningLimits())
34            assert inferred.query_path(PathPattern(edge="related"))[0].target == "b"
35            assert inferred.with_mode("asserted-only").match(predicate="related") == ()
36            assert inferred.require_generation(inferred.generation) is None
37        result.binding.verify_source(graph)
38    finally:
39        graph.close()

Identity and authentication

Storage-neutral CurrentSourceIdentity contains database ID, backend snapshot sequence and provenance token. The token includes the complete state digest, backend/serializer identity and snapshot kind. These fields are not temporal commit horizon or valid time. GenerationIdentity accepts either source kind; current generations use a distinct digest domain and every existing temporal generation digest remains unchanged. Cross-kind compatibility always fails.

The adapter authenticates the caller-owned active snapshot with PinnedGraphSource: snapshot backend/serializer metadata must match the graph manifest independently, and serializer rebinding during reads is rejected. It binds the actual compiled program, ontology revision, full GraphMapping policy, catalog digest, positive binary entity profile and external-strings-v1 representation. Exact single-rule catalog content must match the compiled ontology; caller-supplied version IDs and ordinals remain part of catalog identity, not independently authenticated rule publications. An optional expected_generation must match every dimension before any node/edge record is extracted. Matching metadata never bypasses authentication.

bind_current_generation authenticates metadata without computing closure, for example before constructing a prepared plan. Execution independently authenticates again and reads complete canonical records; it never trusts the binding as an input-completeness certificate. Constructing identity/binding values manually is not authentication or proof of inference soundness.

binding.verify_view(view) reauthenticates the exact active immutable snapshot, including full-state hashing. Live source changes do not alter an already open view. binding.verify_source(graph) instead checks that the latest mutable source still matches; even unrelated source writes can reject reuse conservatively. It does not reopen old snapshots. No historical-mode flag invents an expired mutable snapshot, and neither check is an atomic compare-and-publish permit.

Execution and bounds

Omit executor_request to keep indexed Python. SCC requires explicit opt-in and a compatible PreparedProgram. Polars requires explicit supported closure-only opt-in and an installed runtime; it never receives proof or maintenance work through fallback. The dispatcher independently validates actual program/context/profile/dictionary/executor compatibility and reports shared StageTelemetry. Witness-capable engines preserve exact snapshot-local evidence references but select bounded witnesses, not all-support provenance.

GraphSourceLimits.max_records bounds canonical candidate lookups including unmapped records. ReasoningLimits bounds yielded evidence and evaluation using each engine’s documented accounting. Cancellation is checked between record reads even when nothing maps to a fact. Snapshot authentication and backend-internal work remain outside these counters; hashing/native calls are not interrupted mid-call. Failures return no successful partial result and the caller retains ownership of its view. The adapter performs no writes or repairs.

Complete canonical projection does not depend on secondary indexes, including when those indexes are marked stale; this is not permission to use stale indexes in the separate frontier adapter. Full-state authentication can dominate work and uses memory; this integration makes no performance or constant-time claim. LMDB provides verifiable snapshots, as does transactional PyRex with pyrex-rocksdb>=0.7.0; unsupported backend requests fail closed rather than using unpinned reads.

This completes one current-graph admission/execution consumer, not persistent cache migration, range/session/sampler admission, publication or general typed, negation/equality/aggregate execution. Those require their own source and semantic contracts; see Opt-in generation identity and admission.

Opt-in reasoning-aware queries

For the explicit generation-pinned, read-only Cypher surface over a selected logical graph, see Generation-pinned reasoning-aware Cypher. It reuses the fact-only preparation below while additionally requiring a live current source and active snapshot.

gestaltdb.reasoning.adapters.inferred_view answers triple matches and single-hop path patterns from one admitted generation — never through the Cypher planner, which stays asserted-only by default. open_inferred_view runs the same authenticated admission above, then projects the asserted records in a second bounded pass; both passes enforce GraphSourceLimits. mode selects the fact set explicitly per view: asserted-only reads projected records, asserted-plus-inferred reads the closure (selected in the worked example above). Every answer carries the generation identity: require_generation rejects drifted re-use, assert_current re-authenticates the snapshot, and the view holds fact tuples plus the binding — never a live graph handle, never a write.