Explicit positive typed application execution

reasoning.adapters.execution.execute_typed_closure connects the existing GenericEngine to explicit executor selection, generation admission and the same StageTelemetry schema used by binary application paths. It does not replace the binary dispatcher or introduce a new reasoning algorithm.

Standalone example. Install with python -m pip install "gestaltdb".

 1from gestaltdb.reasoning.model import Variable, ReasoningLimits
 2from gestaltdb.reasoning.terms import Literal
 3from gestaltdb.reasoning.typed import GenericProgram, GenericRule, TypedAtom, TypedFact, Comparison
 4from gestaltdb.reasoning.adapters.execution import execute_typed_closure
 5
 6x, y = Variable("x"), Variable("y")
 7program = GenericProgram([GenericRule("adult", [TypedAtom("age", [x, y])],
 8    [Comparison(">=", y, Literal("integer", 18))], TypedAtom("adult", [x]))])
 9outcome = execute_typed_closure(program,
10    [TypedFact("age", ["alice", Literal("integer", 30)])], limits=ReasoningLimits())
11assert TypedFact("adult", ["alice"]) in outcome.result.facts
12assert outcome.telemetry.executor == "typed-indexed-python-v1"

Capabilities and conversion ownership

The default request for this typed entry point explicitly names positive-typed-point-v1. select_executor selects the distinct typed-indexed-python-v1 kind for this profile, with default or indexed-python preference and closure mode only. Ordinary ExecutorRequest() and the binary execute_closure default remain unchanged. Neither entry point infers a representation from input values or silently calls the other one. Literal types and n-ary tuples remain TypedFact values; there is no binary stringification, compact dictionary adoption or recoding.

Explicit dispatch capability boundary

Request / program

Admitted path

Binary positive closure / bounded witnesses

Existing binary dispatcher; existing reference/SCC/explicit Polars restrictions

Positive typed rules, n-ary relations, strict literals and filters

execute_typed_closure / existing GenericEngine, closure only

Typed proofs, prepared SCC or Polars preference

Reject before input; never weaken witnesses or recode

Typed negation, aggregate or closed-scope program

Reject before input; separate explicit stratified/aggregate APIs remain available

Maintenance supports or finite-range closure

Existing dedicated session/maintenance/range paths; not this dispatcher

Optional raw typed generation admission requires generation, admission_request and independently supplied context together. Before input iteration, the dispatcher checks the actual program/context/profile/ representation, selected executor and closure mode. The representation is exactly typed-values-v1. Shared admit has an explicit typed point closure row; it rejects other modes, profiles, current/range sources and representations for the typed executor. Legacy binary compatibility rows are unchanged. Raw typed facts and caller identity strings are not independently authenticated by this API.

Authenticated session input

reasoning.adapters.typed_execution.execute_authenticated_session connects the source-verified typed-point session contract to actual fresh execution:

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

Typed execution from authenticated temporal sessions preserves its explicit closure-only capability profile.

1python -m pip install "gestaltdb[lmdb]"
 1from pathlib import Path
 2from tempfile import TemporaryDirectory
 3from gestaltdb.graphdb import GraphDB
 4from gestaltdb.reasoning.model import Variable, ReasoningLimits
 5from gestaltdb.reasoning.terms import Literal
 6from gestaltdb.reasoning.typed import GenericProgram, GenericRule, TypedAtom, TypedFact
 7from gestaltdb.reasoning.adapters.claims import ClaimSelection, ClaimMapping
 8from gestaltdb.reasoning.adapters.sessions import SessionScope, start_session
 9from gestaltdb.reasoning.adapters.session_generation import bind_session_generation, catalog_for_typed_program
10from gestaltdb.reasoning.adapters.typed_execution import execute_authenticated_session
11
12x, y = Variable("x"), Variable("y")
13program = GenericProgram([GenericRule("tag", [TypedAtom("memberOf", [x, y])], [],
14    TypedAtom("tagged", [x, y, Literal("integer", 1)]))])
15with TemporaryDirectory() as root:
16    graph = GraphDB.create(Path(root) / "db", backend='lmdb', serializer='json')
17    try:
18        for agent in ("one", "two"):
19            graph.epistemic.assert_claim(subject="a", predicate="memberOf", object="g", agent=agent,
20                               polarity="positive", valid=(0, 100))
21        session = start_session(graph, program, catalog_for_typed_program(program),
22            scope=SessionScope("default", 50, ClaimSelection(), ClaimMapping()), limits=ReasoningLimits())
23        binding = bind_session_generation(graph, session)
24        executed = execute_authenticated_session(graph, session,
25            expected_generation=binding.identity, expected_session_digest=binding.session_digest,
26            limits=ReasoningLimits())
27        assert TypedFact("tagged", ["a", "g", Literal("integer", 1)]) in executed.outcome.result.facts
28        assert len(executed.evidence) == 2
29        assert executed.outcome.telemetry.input_facts == 2
30        assert executed.outcome.telemetry.admission_digest == binding.identity.digest
31    finally:
32        graph.close()

Both exact caller pins are required. The adapter independently re-admits the complete active assertion ledger, including every alternative version and its mapped fact/logical claim ID. It then evaluates only active base input, not the supplied session’s derived closure, and compares complete fresh closure to the supplied state before returning. An internally consistent forged extra fact can pass source-only binding but fails this fresh-execution comparison. This is same-engine recomputation, not an independent proof verifier; support index correctness is not certified by matching closure facts.

AuthenticatedTypedExecution.evidence retains exact independent active AssertionVersion values. The engine consumes their facts as a multiset and computes set closure; common input_facts counts version rows, not unique logical facts. No witnesses, all-support provenance or proof of a particular rule application is returned. Retired versions do not enter the engine.

The existing source policy remains positive entity claims at a temporal point. Typed literals/n-ary values may be produced by rules; this does not silently admit literal-valued database claims or n-ary source storage. Raw typed execution can consume literal/n-ary TypedFact input without database source authentication, as in the first example.

Freshness, bounds and side effects

Default freshness="latest" rejects source movement. Explicit historical mode authenticates and evaluates the exact old prefix, never relabelling it as current. The temporal writer guard spans admission, execution and final source/store/decoder checks. Cooperating temporal writers wait; reentrant source movement or handle rebinding fails before return. This may be a long-held guard, not a low-latency or continuing freshness lease. Hostile raw storage writers are outside this coordination contract.

SessionAdmissionLimits governs source verification and retained state; ReasoningLimits governs engine rules, input versions, candidates, iterations and closure facts. The raw dispatcher buffers at most max_input_facts rows and consumes one additional row only to detect overflow. Cancellation is checked before/after iterator advancement and through existing engine/admission checks; it cannot interrupt a blocked iterator, lock wait or backend/native operation. Cancellation and bound errors return no successful partial outcome and poison no reusable state. These counters are not hard RSS/deadline guarantees.

The adapter does not advance, persist, repair or publish a session and writes no database claims. New source state needs explicit session advance/rebinding. Existing durable-session and interval-publication APIs stay separate; no automatic executor adoption, optional dependency or performance claim is added.