Skip to content

Commit 2b4f61d

Browse files
committed
refactor(checkers): let declarations own provider runtimes
Compose declaration-owned clean-process runtimes with the latest batched checker-identity path. Existing checker families retain the legacy registry; new declarations may carry one unassigned provider runtime, and the composition root batches identity material across the full declaration set before authorization.
1 parent 1c926ff commit 2b4f61d

4 files changed

Lines changed: 154 additions & 72 deletions

File tree

src/jacobian/checker_operations.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,11 @@ class ExactReplayCheckerDeclaration:
9090
tags are used as written. If the domain omits the metadata, all four fields
9191
are strictly constructed from the producer capability ID so that no
9292
verifier metadata is absent at installation.
93+
94+
A declaration may own its complete clean-process provider runtime directly.
95+
Existing built-in families may continue to use the legacy central runtime
96+
registry while they are migrated. Direct runtimes must not carry checker
97+
IDs before operator authorization.
9398
"""
9499

95100
capability_id: str
@@ -102,6 +107,7 @@ class ExactReplayCheckerDeclaration:
102107
"operator-authorized Python-FLINT exact replay independent of the "
103108
"SymPy producer"
104109
)
110+
provider_runtime: CapabilityProviderRuntime | None = None
105111
verification_capability_id: str | None = None
106112
verification_title: str | None = None
107113
verification_description: str | None = None
@@ -120,6 +126,10 @@ def __post_init__(self) -> None:
120126
raise ValueError(
121127
f"exact replay checker declaration {field} must not be empty"
122128
)
129+
if self.provider_runtime is not None and self.provider_runtime.checker_ids:
130+
raise ValueError(
131+
"declaration-owned provider runtime must not pre-authorize checker IDs"
132+
)
123133
derived_id = derive_verification_capability_id(self.capability_id)
124134
explicit_text = (
125135
self.verification_title,

src/jacobian/exact_domain_checkers.py

Lines changed: 81 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
from jacobian.capability_adapters import CapabilityAdapter
1515
from jacobian.capability_errors import CapabilityError, CapabilityInvocationError
1616
from jacobian.checker_artifacts import put_witness_envelope
17-
from jacobian.checker_identity import batch_checker_manifest_measurement
1817
from jacobian.checker_installation import CheckerInstaller
1918
from jacobian.checker_operations import CheckerOperation, ExactReplayCheckerDeclaration
2019
from jacobian.contracts.capabilities import (
@@ -160,6 +159,8 @@ class _InstalledDeclaration:
160159

161160

162161
def _provider_runtime_key(declaration: ExactReplayCheckerDeclaration) -> str:
162+
if declaration.provider_runtime is not None:
163+
return f"declaration:{declaration.capability_id}"
163164
if declaration.entrypoint_module == "jacobian_checkers.linear":
164165
return {
165166
"check_rational_solution": "linear-solution",
@@ -234,76 +235,86 @@ def install_exact_domain_checkers(
234235
features=("standard-library-rational-replay", "clean-process-checker"),
235236
),
236237
}
238+
available_declarations = _available_declaration_bundles(bundles)
237239
provider_runtimes = {
238240
runtime_key: factory() for runtime_key, factory in runtime_factories.items()
239241
}
242+
for _installed, declaration in available_declarations:
243+
if declaration.provider_runtime is None:
244+
continue
245+
runtime_key = _provider_runtime_key(declaration)
246+
previous = provider_runtimes.setdefault(
247+
runtime_key,
248+
declaration.provider_runtime,
249+
)
250+
if previous != declaration.provider_runtime:
251+
raise ValueError(
252+
"exact replay declarations disagree on their owned provider runtime"
253+
)
240254
checker_ids: dict[str, str | None] = {}
241255
declarations_by_id: dict[str, ExactReplayCheckerDeclaration] = {}
242256
diagnostics: list[CapabilityDiagnostic] = []
243257
exact_checker_source_available = (
244258
exact_domain_checker_source_provider_runtime().availability
245259
is CapabilityProviderAvailability.AVAILABLE
246260
)
247-
with batch_checker_manifest_measurement():
248-
for installed, declaration in _available_declaration_bundles(bundles):
249-
declarations_by_id[declaration.capability_id] = declaration
250-
runtime_key = _provider_runtime_key(declaration)
251-
provider_runtime = provider_runtimes[runtime_key]
252-
operation = CheckerOperation(
253-
name=f"{declaration.capability_id} independent {declaration.replay_method}",
254-
entrypoint=(f"{declaration.entrypoint_module}:{declaration.function}"),
255-
evidence_kind=EvidenceKind.WITNESS,
256-
format_id=declaration.format_id,
257-
format_version="1",
258-
claim_schema_uris=(
259-
installed.input_schema_uris[declaration.request_model],
261+
for installed, declaration in available_declarations:
262+
declarations_by_id[declaration.capability_id] = declaration
263+
runtime_key = _provider_runtime_key(declaration)
264+
provider_runtime = provider_runtimes[runtime_key]
265+
operation = CheckerOperation(
266+
name=f"{declaration.capability_id} independent {declaration.replay_method}",
267+
entrypoint=(f"{declaration.entrypoint_module}:{declaration.function}"),
268+
evidence_kind=EvidenceKind.WITNESS,
269+
format_id=declaration.format_id,
270+
format_version="1",
271+
claim_schema_uris=(installed.input_schema_uris[declaration.request_model],),
272+
semantics_uris=(installed.semantics_uri,),
273+
candidate_schema_uris=(
274+
installed.result_schema_uris[declaration.capability_id],
275+
),
276+
reason=declaration.reason,
277+
provider_runtime=provider_runtime,
278+
)
279+
if (
280+
provider_runtime.availability
281+
is not CapabilityProviderAvailability.AVAILABLE
282+
):
283+
can_omit = (
284+
runtime_key in _OPTIONAL_EXACT_REPLAY_PROVIDER_KEYS
285+
and exact_checker_source_available
286+
)
287+
if not can_omit:
288+
checker_ids[declaration.capability_id] = installer.install(
289+
operation,
290+
authorize=authorize,
291+
).checker_id
292+
continue
293+
diagnostic = CapabilityDiagnostic(
294+
code="EXACT_REPLAY_PROVIDER_UNAVAILABLE",
295+
stage="provider_availability",
296+
message=(
297+
f"Independent replay for {declaration.capability_id!r} is "
298+
"not installed: "
299+
f"{provider_runtime.diagnostic or 'the provider is unavailable.'}"
260300
),
261-
semantics_uris=(installed.semantics_uri,),
262-
candidate_schema_uris=(
263-
installed.result_schema_uris[declaration.capability_id],
301+
hint=(
302+
"Install or repair the optional python-flint backend, then retry."
264303
),
265-
reason=declaration.reason,
266-
provider_runtime=provider_runtime,
304+
details={
305+
"capability_id": declaration.capability_id,
306+
"provider": provider_runtime.provider,
307+
"checker_authorization_affected": True,
308+
},
267309
)
268-
if (
269-
provider_runtime.availability
270-
is not CapabilityProviderAvailability.AVAILABLE
271-
):
272-
can_omit = (
273-
runtime_key in _OPTIONAL_EXACT_REPLAY_PROVIDER_KEYS
274-
and exact_checker_source_available
275-
)
276-
if not can_omit:
277-
checker_ids[declaration.capability_id] = installer.install(
278-
operation,
279-
authorize=authorize,
280-
).checker_id
281-
continue
282-
diagnostic = CapabilityDiagnostic(
283-
code="EXACT_REPLAY_PROVIDER_UNAVAILABLE",
284-
stage="provider_availability",
285-
message=(
286-
f"Independent replay for {declaration.capability_id!r} is "
287-
"not installed: "
288-
f"{provider_runtime.diagnostic or 'the provider is unavailable.'}"
289-
),
290-
hint=(
291-
"Install or repair the optional python-flint backend, then retry."
292-
),
293-
details={
294-
"capability_id": declaration.capability_id,
295-
"provider": provider_runtime.provider,
296-
"checker_authorization_affected": True,
297-
},
298-
)
299-
diagnostics.append(diagnostic)
300-
_LOGGER.warning("%s", diagnostic.message)
301-
checker_ids[declaration.capability_id] = None
302-
continue
303-
checker_ids[declaration.capability_id] = installer.install(
304-
operation,
305-
authorize=authorize,
306-
).checker_id
310+
diagnostics.append(diagnostic)
311+
_LOGGER.warning("%s", diagnostic.message)
312+
checker_ids[declaration.capability_id] = None
313+
continue
314+
checker_ids[declaration.capability_id] = installer.install(
315+
operation,
316+
authorize=authorize,
317+
).checker_id
307318
authorized_ids = {
308319
runtime_key: tuple(
309320
checker_id
@@ -313,13 +324,21 @@ def install_exact_domain_checkers(
313324
)
314325
for runtime_key in provider_runtimes
315326
}
327+
resolved_provider_runtimes: dict[str, CapabilityProviderRuntime] = {}
328+
for runtime_key, provider_runtime in provider_runtimes.items():
329+
checker_ids_for_runtime = authorized_ids[runtime_key]
330+
factory = runtime_factories.get(runtime_key)
331+
resolved_provider_runtimes[runtime_key] = (
332+
factory(checker_ids=checker_ids_for_runtime)
333+
if factory is not None
334+
else provider_runtime.model_copy(
335+
update={"checker_ids": checker_ids_for_runtime}
336+
)
337+
)
316338
return ExactDomainCheckerInstallation(
317339
checker_ids=checker_ids,
318340
diagnostics=tuple(diagnostics),
319-
provider_runtimes={
320-
runtime_key: factory(checker_ids=authorized_ids[runtime_key])
321-
for runtime_key, factory in runtime_factories.items()
322-
},
341+
provider_runtimes=resolved_provider_runtimes,
323342
)
324343

325344

src/jacobian/portfolio/core_installation.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from dataclasses import dataclass
66

7+
from jacobian.checker_identity import batch_checker_manifest_measurement
78
from jacobian.contracts.capabilities import CapabilityProviderAvailability
89
from jacobian.domain_bundles import DomainBundle
910
from jacobian.domains.polynomial_nullstellensatz.core import (
@@ -68,7 +69,7 @@ def _install_nullstellensatz(self) -> None:
6869
"""Install the named Nullstellensatz family at the composition root.
6970
7071
This family has an artifact-producing core and an optional Singular
71-
producer that depends on that core. It is deliberately not represented
72+
producer that depends on that core. It is deliberately not represented
7273
as a generic portfolio callback: ordinary portfolio plans contain only
7374
:class:`DomainBundle` declarations.
7475
"""
@@ -192,15 +193,19 @@ def install_domain_verification(
192193
}
193194
if not exact_bundles:
194195
return None
195-
adapters, installation = install_exact_domain_verification(
196-
ctx.store,
197-
ctx.schemas,
198-
ctx.artifacts,
199-
ctx.verification,
200-
ctx.checkers,
201-
bundles=exact_bundles,
202-
authorize=ctx.authorizes_bundled_checkers,
203-
)
196+
# Batch identity material across the complete declaration set while the
197+
# exact-domain installer resolves both legacy and declaration-owned
198+
# provider runtimes. Nested measurement remains safe for direct callers.
199+
with batch_checker_manifest_measurement():
200+
adapters, installation = install_exact_domain_verification(
201+
ctx.store,
202+
ctx.schemas,
203+
ctx.artifacts,
204+
ctx.verification,
205+
ctx.checkers,
206+
bundles=exact_bundles,
207+
authorize=ctx.authorizes_bundled_checkers,
208+
)
204209
for adapter in adapters:
205210
self.context.register_capability(adapter)
206211
return installation
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
from __future__ import annotations
2+
3+
import pytest
4+
5+
from jacobian.checker_operations import ExactReplayCheckerDeclaration
6+
from jacobian.contracts.capabilities import CapabilityInstallTier
7+
from jacobian.contracts.exact import CanonicalRational
8+
from jacobian.provider_runtime import source_provider_runtime
9+
10+
11+
def _runtime():
12+
return source_provider_runtime(
13+
"jacobian.test-declaration-checker",
14+
version="1",
15+
entrypoint="jacobian_checkers.linear:check_rational_solution",
16+
install_tier=CapabilityInstallTier.T1,
17+
license_id="MIT",
18+
features=("clean-process-checker",),
19+
)
20+
21+
22+
def test_exact_replay_declaration_owns_unassigned_provider_runtime() -> None:
23+
runtime = _runtime()
24+
declaration = ExactReplayCheckerDeclaration(
25+
"test.compute.value",
26+
CanonicalRational,
27+
"check_rational_solution",
28+
"test.value.replay",
29+
entrypoint_module="jacobian_checkers.linear",
30+
provider_runtime=runtime,
31+
)
32+
33+
assert declaration.provider_runtime == runtime
34+
assert declaration.provider_runtime.checker_ids == ()
35+
36+
37+
def test_exact_replay_declaration_rejects_preauthorized_runtime() -> None:
38+
runtime = _runtime().model_copy(update={"checker_ids": ("checker:test",)})
39+
40+
with pytest.raises(ValueError, match="must not pre-authorize checker IDs"):
41+
ExactReplayCheckerDeclaration(
42+
"test.compute.value",
43+
CanonicalRational,
44+
"check_rational_solution",
45+
"test.value.replay",
46+
entrypoint_module="jacobian_checkers.linear",
47+
provider_runtime=runtime,
48+
)

0 commit comments

Comments
 (0)