reckon-rcdr 0.1.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- reckon/__init__.py +27 -0
- reckon/__main__.py +64 -0
- reckon/emit.py +220 -0
- reckon/execution.py +47 -0
- reckon/predicate.py +30 -0
- reckon/py.typed +0 -0
- reckon/record.py +120 -0
- reckon/run.py +174 -0
- reckon/sink.py +32 -0
- reckon/verify.py +122 -0
- reckon_rcdr-0.1.1.dist-info/METADATA +156 -0
- reckon_rcdr-0.1.1.dist-info/RECORD +16 -0
- reckon_rcdr-0.1.1.dist-info/WHEEL +5 -0
- reckon_rcdr-0.1.1.dist-info/entry_points.txt +2 -0
- reckon_rcdr-0.1.1.dist-info/licenses/LICENSE +202 -0
- reckon_rcdr-0.1.1.dist-info/top_level.txt +1 -0
reckon/__init__.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"""Reckon — the capture layer for autonomous decisions.
|
|
2
|
+
|
|
3
|
+
Emits RCDR v0.1 records (`docs/RCDR-v0.1.md`) and verifies which replay capability
|
|
4
|
+
class a record actually supports. Capture is the primitive; replay exists to prove
|
|
5
|
+
capture worked.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from .emit import Decision, Recorder
|
|
9
|
+
from .execution import SDK_VERSION
|
|
10
|
+
from .run import Boundary, RunReport, boundary, verify_run
|
|
11
|
+
from .sink import JsonlSink, MemorySink, Sink
|
|
12
|
+
from .verify import Report, verify
|
|
13
|
+
|
|
14
|
+
__all__ = [
|
|
15
|
+
"Boundary",
|
|
16
|
+
"Decision",
|
|
17
|
+
"JsonlSink",
|
|
18
|
+
"MemorySink",
|
|
19
|
+
"Recorder",
|
|
20
|
+
"Report",
|
|
21
|
+
"RunReport",
|
|
22
|
+
"SDK_VERSION",
|
|
23
|
+
"Sink",
|
|
24
|
+
"boundary",
|
|
25
|
+
"verify",
|
|
26
|
+
"verify_run",
|
|
27
|
+
]
|
reckon/__main__.py
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"""`python -m reckon` — the verifier CLI.
|
|
2
|
+
|
|
3
|
+
Exit code 1 when the requested class is not supported, so this can gate a pipeline.
|
|
4
|
+
That is the whole point of instrumenting: a build should be able to fail because the
|
|
5
|
+
evidence needed to re-adjudicate a decision was never captured.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
import argparse
|
|
9
|
+
import json
|
|
10
|
+
import sys
|
|
11
|
+
from pathlib import Path
|
|
12
|
+
|
|
13
|
+
from .execution import SDK_VERSION
|
|
14
|
+
from .run import boundary, verify_run
|
|
15
|
+
from .verify import CLASS_NAMES
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def load(path: str) -> list[dict]:
|
|
19
|
+
lines = Path(path).read_text(encoding="utf-8").splitlines()
|
|
20
|
+
return [json.loads(line) for line in lines if line.strip()]
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def main(argv: list[str] | None = None) -> int:
|
|
24
|
+
parser = argparse.ArgumentParser(prog="reckon", description=__doc__)
|
|
25
|
+
parser.add_argument(
|
|
26
|
+
"--version",
|
|
27
|
+
action="version",
|
|
28
|
+
version=f"reckon {SDK_VERSION} (RCDR v0.1)",
|
|
29
|
+
)
|
|
30
|
+
sub = parser.add_subparsers(dest="command", required=True)
|
|
31
|
+
|
|
32
|
+
verify_cmd = sub.add_parser("verify", help="report the class a run supports")
|
|
33
|
+
verify_cmd.add_argument("path", help="path to an RCDR .jsonl run")
|
|
34
|
+
verify_cmd.add_argument(
|
|
35
|
+
"--class",
|
|
36
|
+
dest="requested",
|
|
37
|
+
default="C1",
|
|
38
|
+
choices=sorted(CLASS_NAMES),
|
|
39
|
+
help="the counterfactual class you want to run",
|
|
40
|
+
)
|
|
41
|
+
verify_cmd.add_argument("--json", action="store_true", help="machine-readable output")
|
|
42
|
+
|
|
43
|
+
boundary_cmd = sub.add_parser(
|
|
44
|
+
"boundary", help="locate where evidence ends for a counterfactual"
|
|
45
|
+
)
|
|
46
|
+
boundary_cmd.add_argument("path")
|
|
47
|
+
boundary_cmd.add_argument("--decision", required=True, help="the decision to flip")
|
|
48
|
+
boundary_cmd.add_argument("--json", action="store_true")
|
|
49
|
+
|
|
50
|
+
args = parser.parse_args(argv)
|
|
51
|
+
records = load(args.path)
|
|
52
|
+
|
|
53
|
+
if args.command == "verify":
|
|
54
|
+
report = verify_run(records, requested=args.requested)
|
|
55
|
+
print(json.dumps(report.to_dict(), indent=2) if args.json else report.render())
|
|
56
|
+
return 0 if report.satisfied else 1
|
|
57
|
+
|
|
58
|
+
edge = boundary(records, args.decision)
|
|
59
|
+
print(json.dumps(edge.to_dict(), indent=2) if args.json else edge.render())
|
|
60
|
+
return 0
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
if __name__ == "__main__":
|
|
64
|
+
sys.exit(main())
|
reckon/emit.py
ADDED
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
"""The emitter (§7, emitter conformance).
|
|
2
|
+
|
|
3
|
+
The design rule the whole SDK obeys: **the emitter refuses to guess.** It will raise
|
|
4
|
+
rather than invent a policy value it was never told about, or close a decision that
|
|
5
|
+
never declared an outcome. A record that quietly fills its own gaps is the failure
|
|
6
|
+
mode RCDR exists to prevent.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
import uuid
|
|
10
|
+
from contextlib import contextmanager
|
|
11
|
+
from datetime import datetime, timezone
|
|
12
|
+
from typing import Any, Iterator
|
|
13
|
+
|
|
14
|
+
from . import execution as execmodel
|
|
15
|
+
from . import predicate as pred
|
|
16
|
+
from .record import Candidate, Candidates, Execution, Policy, Predicate, digest
|
|
17
|
+
from .sink import Sink
|
|
18
|
+
|
|
19
|
+
OPERATORS = {
|
|
20
|
+
"gte": lambda a, b: a >= b,
|
|
21
|
+
"gt": lambda a, b: a > b,
|
|
22
|
+
"lte": lambda a, b: a <= b,
|
|
23
|
+
"lt": lambda a, b: a < b,
|
|
24
|
+
"eq": lambda a, b: a == b,
|
|
25
|
+
"ne": lambda a, b: a != b,
|
|
26
|
+
"in": lambda a, b: a in b,
|
|
27
|
+
"contains": lambda a, b: b in a,
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class Decision:
|
|
32
|
+
"""One decision in flight. Closed by `admit()` or `reject()`."""
|
|
33
|
+
|
|
34
|
+
def __init__(self, action: str, params: dict | None, pure: bool | None) -> None:
|
|
35
|
+
self.action = action
|
|
36
|
+
self.params = params or {}
|
|
37
|
+
self.pure = pure
|
|
38
|
+
self.policies: dict[str, Policy] = {}
|
|
39
|
+
self.predicate: Predicate | None = None
|
|
40
|
+
self.governing_key: str | None = None
|
|
41
|
+
self.compared_value: Any = None
|
|
42
|
+
self.compared_type: str | None = None
|
|
43
|
+
self.candidates = Candidates()
|
|
44
|
+
self.outcome: str | None = None
|
|
45
|
+
self.reads: list[dict] = []
|
|
46
|
+
self.writes: list[dict] = []
|
|
47
|
+
|
|
48
|
+
# --- policy (§4.4) ---------------------------------------------------------
|
|
49
|
+
|
|
50
|
+
def policy(
|
|
51
|
+
self,
|
|
52
|
+
key: str,
|
|
53
|
+
*,
|
|
54
|
+
value: Any,
|
|
55
|
+
provenance: str,
|
|
56
|
+
source: str,
|
|
57
|
+
revision: str | None = None,
|
|
58
|
+
) -> None:
|
|
59
|
+
"""Register the value in force at call time. A pointer will not do."""
|
|
60
|
+
self.policies[key] = Policy(
|
|
61
|
+
key=key,
|
|
62
|
+
resolved_value=value,
|
|
63
|
+
provenance=provenance,
|
|
64
|
+
source=source,
|
|
65
|
+
revision=revision,
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
# --- the crossing (§4.2, §4.3) ---------------------------------------------
|
|
69
|
+
|
|
70
|
+
def check(self, operator: str, *, left: str, value: Any, right: str) -> bool:
|
|
71
|
+
"""Evaluate the predicate and record its structure, operand and policy.
|
|
72
|
+
|
|
73
|
+
Returns the real boolean so the caller branches on the same value that was
|
|
74
|
+
recorded. An SDK that records a decision the host did not actually make is
|
|
75
|
+
worse than no record at all.
|
|
76
|
+
"""
|
|
77
|
+
if operator not in OPERATORS:
|
|
78
|
+
raise ValueError(f"unknown operator {operator!r}; expected one of {sorted(OPERATORS)}")
|
|
79
|
+
if right not in self.policies:
|
|
80
|
+
raise ValueError(
|
|
81
|
+
f"policy {right!r} is not registered for this decision. "
|
|
82
|
+
"Call .policy() with the value in force before comparing against it."
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
policy = self.policies[right]
|
|
86
|
+
self.predicate = Predicate(
|
|
87
|
+
id=pred.predicate_id(operator, left, right),
|
|
88
|
+
operator=operator,
|
|
89
|
+
expression=pred.expression(operator, left, right),
|
|
90
|
+
)
|
|
91
|
+
self.compared_value = value
|
|
92
|
+
self.compared_type = type(value).__name__
|
|
93
|
+
self.governing_key = right
|
|
94
|
+
return bool(OPERATORS[operator](value, policy.resolved_value))
|
|
95
|
+
|
|
96
|
+
# --- candidates (§4.6) ------------------------------------------------------
|
|
97
|
+
|
|
98
|
+
def candidate(
|
|
99
|
+
self,
|
|
100
|
+
action_id: str,
|
|
101
|
+
*,
|
|
102
|
+
compared_value: Any,
|
|
103
|
+
outcome: str,
|
|
104
|
+
predicate: str,
|
|
105
|
+
) -> None:
|
|
106
|
+
self.candidates.items.append(
|
|
107
|
+
Candidate(
|
|
108
|
+
action_id=action_id,
|
|
109
|
+
compared_value=compared_value,
|
|
110
|
+
outcome=outcome,
|
|
111
|
+
predicate_id=predicate,
|
|
112
|
+
)
|
|
113
|
+
)
|
|
114
|
+
|
|
115
|
+
def candidates_exhaustive(self) -> None:
|
|
116
|
+
"""Declare that every candidate considered was recorded.
|
|
117
|
+
|
|
118
|
+
Only the caller can know this, which is why it is an explicit statement and
|
|
119
|
+
never inferred from the fact that some candidates were logged.
|
|
120
|
+
"""
|
|
121
|
+
self.candidates.completeness = "exhaustive"
|
|
122
|
+
|
|
123
|
+
def candidates_partial(self) -> None:
|
|
124
|
+
self.candidates.completeness = "partial"
|
|
125
|
+
|
|
126
|
+
# --- state (§4.7) -----------------------------------------------------------
|
|
127
|
+
|
|
128
|
+
def read(self, key: str, value: Any, source: str) -> None:
|
|
129
|
+
self.reads.append({"key": key, "value_digest": digest(value), "source": source})
|
|
130
|
+
|
|
131
|
+
def write(self, key: str, value: Any) -> None:
|
|
132
|
+
self.writes.append({"key": key, "value_digest": digest(value)})
|
|
133
|
+
|
|
134
|
+
# --- outcome (§4.5) ---------------------------------------------------------
|
|
135
|
+
|
|
136
|
+
def admit(self) -> None:
|
|
137
|
+
self.outcome = "admit"
|
|
138
|
+
|
|
139
|
+
def reject(self) -> None:
|
|
140
|
+
self.outcome = "reject"
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
class Recorder:
|
|
144
|
+
def __init__(
|
|
145
|
+
self,
|
|
146
|
+
*,
|
|
147
|
+
sink: Sink,
|
|
148
|
+
run_id: str,
|
|
149
|
+
emitter: str,
|
|
150
|
+
seed: int | None = None,
|
|
151
|
+
clock: str | None = None,
|
|
152
|
+
) -> None:
|
|
153
|
+
self.sink = sink
|
|
154
|
+
self.run_id = run_id
|
|
155
|
+
self.emitter = emitter
|
|
156
|
+
self.seed = seed
|
|
157
|
+
self.clock = clock
|
|
158
|
+
self._sequence = 0
|
|
159
|
+
|
|
160
|
+
@contextmanager
|
|
161
|
+
def decision(
|
|
162
|
+
self,
|
|
163
|
+
*,
|
|
164
|
+
action: str,
|
|
165
|
+
params: dict | None = None,
|
|
166
|
+
pure: bool | None = None,
|
|
167
|
+
) -> Iterator[Decision]:
|
|
168
|
+
decision = Decision(action=action, params=params, pure=pure)
|
|
169
|
+
# If the body raises, the exception propagates untouched: no half-formed
|
|
170
|
+
# record is emitted, and the outcome complaint below never masks it.
|
|
171
|
+
yield decision
|
|
172
|
+
if decision.outcome is None:
|
|
173
|
+
raise ValueError(
|
|
174
|
+
f"decision on action {action!r} closed without an outcome; "
|
|
175
|
+
"call .admit() or .reject()"
|
|
176
|
+
)
|
|
177
|
+
self.sink.write(self._build(decision))
|
|
178
|
+
|
|
179
|
+
def _build(self, decision: Decision) -> dict:
|
|
180
|
+
record = {
|
|
181
|
+
"rcdr_version": "0.1",
|
|
182
|
+
"decision_id": f"d-{uuid.uuid4().hex[:12]}",
|
|
183
|
+
"run_id": self.run_id,
|
|
184
|
+
"sequence": self._sequence,
|
|
185
|
+
"ts": datetime.now(timezone.utc).isoformat(),
|
|
186
|
+
"outcome": decision.outcome,
|
|
187
|
+
"action": {
|
|
188
|
+
"id": decision.action,
|
|
189
|
+
"params_digest": digest(decision.params),
|
|
190
|
+
},
|
|
191
|
+
"candidates": decision.candidates.to_dict(),
|
|
192
|
+
"reads": decision.reads,
|
|
193
|
+
"writes": decision.writes,
|
|
194
|
+
"execution": Execution(
|
|
195
|
+
runtime=execmodel.runtime(),
|
|
196
|
+
deps_digest=execmodel.deps_digest(),
|
|
197
|
+
path_digest=execmodel.path_digest(
|
|
198
|
+
[policy.resolution_source for policy in decision.policies.values()],
|
|
199
|
+
self.emitter,
|
|
200
|
+
),
|
|
201
|
+
seed=self.seed,
|
|
202
|
+
clock=self.clock,
|
|
203
|
+
pure=decision.pure,
|
|
204
|
+
).to_dict(),
|
|
205
|
+
"capture": {
|
|
206
|
+
"sdk_version": execmodel.SDK_VERSION,
|
|
207
|
+
"emitter": self.emitter,
|
|
208
|
+
},
|
|
209
|
+
}
|
|
210
|
+
self._sequence += 1
|
|
211
|
+
|
|
212
|
+
if decision.predicate is not None:
|
|
213
|
+
record["predicate"] = decision.predicate.to_dict()
|
|
214
|
+
record["compared"] = {
|
|
215
|
+
"value": decision.compared_value,
|
|
216
|
+
"type": decision.compared_type,
|
|
217
|
+
}
|
|
218
|
+
if decision.governing_key is not None:
|
|
219
|
+
record["policy"] = decision.policies[decision.governing_key].to_dict()
|
|
220
|
+
return record
|
reckon/execution.py
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"""Execution model (§4.8).
|
|
2
|
+
|
|
3
|
+
`path_digest` is the field that carries the OPA finding. Replay soundness is not
|
|
4
|
+
compositional: two runs with identical component versions can differ because one
|
|
5
|
+
resolved its policy from a place the other did not. The path digest covers the
|
|
6
|
+
resolution sources actually used, so those two runs hash differently.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
import hashlib
|
|
10
|
+
import platform
|
|
11
|
+
from importlib.metadata import distributions
|
|
12
|
+
|
|
13
|
+
SDK_VERSION = "0.1.1"
|
|
14
|
+
|
|
15
|
+
_deps_digest_cache: str | None = None
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def runtime() -> str:
|
|
19
|
+
return f"python{platform.python_version()}"
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def deps_digest() -> str:
|
|
23
|
+
"""Digest of the resolved dependency set. Stable within a process."""
|
|
24
|
+
global _deps_digest_cache
|
|
25
|
+
if _deps_digest_cache is None:
|
|
26
|
+
installed = sorted(
|
|
27
|
+
f"{dist.metadata['Name']}=={dist.version}"
|
|
28
|
+
for dist in distributions()
|
|
29
|
+
if dist.metadata["Name"]
|
|
30
|
+
)
|
|
31
|
+
digest = hashlib.sha256("\n".join(installed).encode("utf-8"))
|
|
32
|
+
_deps_digest_cache = f"sha256:{digest.hexdigest()}"
|
|
33
|
+
return _deps_digest_cache
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def path_digest(resolution_sources: list[str], emitter: str) -> str:
|
|
37
|
+
"""Digest over the whole execution path, not a composition of component versions.
|
|
38
|
+
|
|
39
|
+
`resolution_sources` are the `provenance:source` pairs that actually resolved a
|
|
40
|
+
policy in this decision. Two decisions with identical dependencies but different
|
|
41
|
+
resolution regimes — the OPA bundle case versus the Data API case — produce
|
|
42
|
+
different path digests, which is precisely what the bundle revision failed to do.
|
|
43
|
+
"""
|
|
44
|
+
material = "\n".join(
|
|
45
|
+
[deps_digest(), runtime(), SDK_VERSION, emitter, *sorted(resolution_sources)]
|
|
46
|
+
)
|
|
47
|
+
return f"sha256:{hashlib.sha256(material.encode('utf-8')).hexdigest()}"
|
reckon/predicate.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"""Predicate identity (§4.2).
|
|
2
|
+
|
|
3
|
+
A predicate is identified by the hash of its canonical structure — operator plus
|
|
4
|
+
operand identities — not by its name or source location. The LangGraph probe showed
|
|
5
|
+
two gates that were indistinguishable in the record while behaving differently; a
|
|
6
|
+
name does not survive a refactor and a line number does not separate look-alikes.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
import hashlib
|
|
10
|
+
|
|
11
|
+
FIELD_SEPARATOR = "\x1f"
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def canonical_form(operator: str, left: str, right: str) -> str:
|
|
15
|
+
"""The bytes that define a predicate's identity.
|
|
16
|
+
|
|
17
|
+
Operands are joined with an ASCII unit separator so that no operand value can
|
|
18
|
+
forge a boundary between fields.
|
|
19
|
+
"""
|
|
20
|
+
return FIELD_SEPARATOR.join((operator, left, right))
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def predicate_id(operator: str, left: str, right: str) -> str:
|
|
24
|
+
digest = hashlib.sha256(canonical_form(operator, left, right).encode("utf-8"))
|
|
25
|
+
return f"p:{digest.hexdigest()[:16]}"
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def expression(operator: str, left: str, right: str) -> str:
|
|
29
|
+
"""Human rendering. Informational only — never an identity."""
|
|
30
|
+
return f"{left} {operator} {right}"
|
reckon/py.typed
ADDED
|
File without changes
|
reckon/record.py
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"""Record structures (§4). These emit the RCDR field names exactly.
|
|
2
|
+
|
|
3
|
+
Nothing here infers a missing value. Where the emitter cannot establish a fact, the
|
|
4
|
+
record says so — `provenance: unknown`, `completeness: taken_only` — because a format
|
|
5
|
+
with no way to admit ignorance emits records that silently claim a class they cannot
|
|
6
|
+
support (§4.4).
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
import hashlib
|
|
10
|
+
import json
|
|
11
|
+
from dataclasses import dataclass, field
|
|
12
|
+
from typing import Any
|
|
13
|
+
|
|
14
|
+
PROVENANCE = ("bundled", "runtime_override", "environment", "computed", "unknown")
|
|
15
|
+
COMPLETENESS = ("exhaustive", "partial", "taken_only")
|
|
16
|
+
OUTCOMES = ("admit", "reject")
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def digest(value: Any) -> str:
|
|
20
|
+
canonical = json.dumps(value, sort_keys=True, separators=(",", ":"), default=str)
|
|
21
|
+
return f"sha256:{hashlib.sha256(canonical.encode('utf-8')).hexdigest()}"
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
@dataclass
|
|
25
|
+
class Policy:
|
|
26
|
+
key: str
|
|
27
|
+
resolved_value: Any
|
|
28
|
+
provenance: str
|
|
29
|
+
source: str
|
|
30
|
+
revision: str | None = None
|
|
31
|
+
|
|
32
|
+
def __post_init__(self) -> None:
|
|
33
|
+
if self.provenance not in PROVENANCE:
|
|
34
|
+
raise ValueError(
|
|
35
|
+
f"policy.resolution.provenance must be one of {PROVENANCE}, "
|
|
36
|
+
f"got {self.provenance!r}. Use 'unknown' when it cannot be established."
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
@property
|
|
40
|
+
def resolution_source(self) -> str:
|
|
41
|
+
return f"{self.provenance}:{self.source}"
|
|
42
|
+
|
|
43
|
+
def to_dict(self) -> dict:
|
|
44
|
+
resolution: dict[str, Any] = {
|
|
45
|
+
"provenance": self.provenance,
|
|
46
|
+
"source": self.source,
|
|
47
|
+
}
|
|
48
|
+
if self.revision is not None:
|
|
49
|
+
resolution["revision"] = self.revision
|
|
50
|
+
return {
|
|
51
|
+
"key": self.key,
|
|
52
|
+
"resolved_value": self.resolved_value,
|
|
53
|
+
"resolution": resolution,
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
@dataclass
|
|
58
|
+
class Predicate:
|
|
59
|
+
id: str
|
|
60
|
+
operator: str
|
|
61
|
+
expression: str
|
|
62
|
+
|
|
63
|
+
def to_dict(self) -> dict:
|
|
64
|
+
return {"id": self.id, "operator": self.operator, "expression": self.expression}
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
@dataclass
|
|
68
|
+
class Candidate:
|
|
69
|
+
action_id: str
|
|
70
|
+
compared_value: Any
|
|
71
|
+
outcome: str
|
|
72
|
+
predicate_id: str
|
|
73
|
+
|
|
74
|
+
def __post_init__(self) -> None:
|
|
75
|
+
if self.outcome not in OUTCOMES:
|
|
76
|
+
raise ValueError(f"candidate outcome must be one of {OUTCOMES}")
|
|
77
|
+
|
|
78
|
+
def to_dict(self) -> dict:
|
|
79
|
+
return {
|
|
80
|
+
"action_id": self.action_id,
|
|
81
|
+
"compared_value": self.compared_value,
|
|
82
|
+
"outcome": self.outcome,
|
|
83
|
+
"predicate_id": self.predicate_id,
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
@dataclass
|
|
88
|
+
class Candidates:
|
|
89
|
+
completeness: str = "taken_only"
|
|
90
|
+
items: list[Candidate] = field(default_factory=list)
|
|
91
|
+
|
|
92
|
+
def __post_init__(self) -> None:
|
|
93
|
+
if self.completeness not in COMPLETENESS:
|
|
94
|
+
raise ValueError(f"candidates.completeness must be one of {COMPLETENESS}")
|
|
95
|
+
|
|
96
|
+
def to_dict(self) -> dict:
|
|
97
|
+
return {
|
|
98
|
+
"completeness": self.completeness,
|
|
99
|
+
"items": [item.to_dict() for item in self.items],
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
@dataclass
|
|
104
|
+
class Execution:
|
|
105
|
+
runtime: str
|
|
106
|
+
deps_digest: str
|
|
107
|
+
path_digest: str
|
|
108
|
+
seed: int | None = None
|
|
109
|
+
clock: str | None = None
|
|
110
|
+
pure: bool | None = None
|
|
111
|
+
|
|
112
|
+
def to_dict(self) -> dict:
|
|
113
|
+
return {
|
|
114
|
+
"runtime": self.runtime,
|
|
115
|
+
"deps_digest": self.deps_digest,
|
|
116
|
+
"path_digest": self.path_digest,
|
|
117
|
+
"seed": self.seed,
|
|
118
|
+
"clock": self.clock,
|
|
119
|
+
"pure": self.pure,
|
|
120
|
+
}
|
reckon/run.py
ADDED
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
"""Run-level verification and the C3 boundary (§4.7, §5.1, §5.2).
|
|
2
|
+
|
|
3
|
+
Two things happen here that cannot happen one record at a time.
|
|
4
|
+
|
|
5
|
+
The first is that a run's class is its **weakest** decision, not its average. §5.2
|
|
6
|
+
forbids aggregating evidence into a single number, and a mean would do exactly that:
|
|
7
|
+
it would let ninety well-instrumented decisions hide the one that cannot support the
|
|
8
|
+
counterfactual you actually want to run.
|
|
9
|
+
|
|
10
|
+
The second is the C3 boundary. A changed decision perturbs state that later decisions
|
|
11
|
+
read, and past that first flip nothing is replay any more — it is counterfactual
|
|
12
|
+
inference. The boundary report locates the edge where evidence ends. It never
|
|
13
|
+
certifies what lies beyond it; it labels it hypothesis and stops.
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
from dataclasses import dataclass, field
|
|
17
|
+
|
|
18
|
+
from .verify import CLASS_NAMES, LADDER, verify
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def _rank(name: str | None) -> int:
|
|
22
|
+
return -1 if name is None else LADDER.index(name)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
@dataclass
|
|
26
|
+
class RunReport:
|
|
27
|
+
requested: str
|
|
28
|
+
available: str | None
|
|
29
|
+
satisfied: bool
|
|
30
|
+
counts: dict[str, int] = field(default_factory=dict)
|
|
31
|
+
shortfalls: list[tuple[str, str | None, list[str]]] = field(default_factory=list)
|
|
32
|
+
|
|
33
|
+
def render(self) -> str:
|
|
34
|
+
lines = [
|
|
35
|
+
f"Requested: {CLASS_NAMES[self.requested]} ({self.requested})",
|
|
36
|
+
f"Available: {self.available or 'none'}",
|
|
37
|
+
"Decisions: "
|
|
38
|
+
+ ", ".join(f"{name} x{count}" for name, count in sorted(self.counts.items())),
|
|
39
|
+
]
|
|
40
|
+
if self.shortfalls:
|
|
41
|
+
lines.append("Short:")
|
|
42
|
+
for decision_id, available, missing in self.shortfalls:
|
|
43
|
+
lines.append(f" {decision_id} available {available or 'none'}")
|
|
44
|
+
lines.extend(f" missing {item}" for item in missing)
|
|
45
|
+
return "\n".join(lines)
|
|
46
|
+
|
|
47
|
+
def to_dict(self) -> dict:
|
|
48
|
+
return {
|
|
49
|
+
"requested": self.requested,
|
|
50
|
+
"available": self.available,
|
|
51
|
+
"satisfied": self.satisfied,
|
|
52
|
+
"counts": self.counts,
|
|
53
|
+
"shortfalls": [
|
|
54
|
+
{"decision_id": decision_id, "available": available, "missing": missing}
|
|
55
|
+
for decision_id, available, missing in self.shortfalls
|
|
56
|
+
],
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def verify_run(records: list[dict], *, requested: str) -> RunReport:
|
|
61
|
+
ordered = sorted(records, key=lambda record: record.get("sequence", 0))
|
|
62
|
+
reports = [(record, verify(record, requested=requested)) for record in ordered]
|
|
63
|
+
|
|
64
|
+
counts: dict[str, int] = {}
|
|
65
|
+
for _, report in reports:
|
|
66
|
+
key = report.available or "none"
|
|
67
|
+
counts[key] = counts.get(key, 0) + 1
|
|
68
|
+
|
|
69
|
+
available = None
|
|
70
|
+
if reports:
|
|
71
|
+
available = min((report.available for _, report in reports), key=_rank)
|
|
72
|
+
|
|
73
|
+
shortfalls = [
|
|
74
|
+
(record["decision_id"], report.available, report.missing)
|
|
75
|
+
for record, report in reports
|
|
76
|
+
if report.missing
|
|
77
|
+
]
|
|
78
|
+
|
|
79
|
+
satisfied = (
|
|
80
|
+
requested != "C3"
|
|
81
|
+
and bool(reports)
|
|
82
|
+
and _rank(available) >= _rank(requested if requested in LADDER else "C2")
|
|
83
|
+
)
|
|
84
|
+
return RunReport(
|
|
85
|
+
requested=requested,
|
|
86
|
+
available=available,
|
|
87
|
+
satisfied=satisfied,
|
|
88
|
+
counts=counts,
|
|
89
|
+
shortfalls=shortfalls,
|
|
90
|
+
)
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
@dataclass
|
|
94
|
+
class Boundary:
|
|
95
|
+
origin: str
|
|
96
|
+
evidence: list[str]
|
|
97
|
+
hypothesis: list[str]
|
|
98
|
+
edges: list[tuple[str, str, str]]
|
|
99
|
+
|
|
100
|
+
def render(self) -> str:
|
|
101
|
+
lines = [
|
|
102
|
+
f"Counterfactual at: {self.origin}",
|
|
103
|
+
"Evidence: " + ", ".join(self.evidence),
|
|
104
|
+
]
|
|
105
|
+
if self.hypothesis:
|
|
106
|
+
lines.append("Hypothesis: " + ", ".join(self.hypothesis))
|
|
107
|
+
lines.append("Evidence ends at:")
|
|
108
|
+
lines.extend(
|
|
109
|
+
f" {writer} --{key}--> {reader}" for writer, key, reader in self.edges
|
|
110
|
+
)
|
|
111
|
+
lines.append(
|
|
112
|
+
"Everything in the hypothesis region is inference, not replay. "
|
|
113
|
+
"C3 is not certifiable."
|
|
114
|
+
)
|
|
115
|
+
else:
|
|
116
|
+
lines.append("Hypothesis: none — nothing downstream reads what this decision wrote.")
|
|
117
|
+
return "\n".join(lines)
|
|
118
|
+
|
|
119
|
+
def to_dict(self) -> dict:
|
|
120
|
+
return {
|
|
121
|
+
"origin": self.origin,
|
|
122
|
+
"evidence": self.evidence,
|
|
123
|
+
"hypothesis": self.hypothesis,
|
|
124
|
+
"edges": [
|
|
125
|
+
{"writer": writer, "key": key, "reader": reader}
|
|
126
|
+
for writer, key, reader in self.edges
|
|
127
|
+
],
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
def boundary(records: list[dict], decision_id: str) -> Boundary:
|
|
132
|
+
"""Locate where evidence ends if `decision_id` had gone the other way.
|
|
133
|
+
|
|
134
|
+
A decision is downstream if it reads a key written by the origin, or by anything
|
|
135
|
+
already downstream. The closure is taken forward in sequence order only — a
|
|
136
|
+
decision cannot be perturbed by one that had not happened yet.
|
|
137
|
+
"""
|
|
138
|
+
ordered = sorted(records, key=lambda record: record.get("sequence", 0))
|
|
139
|
+
index = {record["decision_id"]: position for position, record in enumerate(ordered)}
|
|
140
|
+
if decision_id not in index:
|
|
141
|
+
raise ValueError(f"decision {decision_id!r} is not in this run")
|
|
142
|
+
|
|
143
|
+
origin_position = index[decision_id]
|
|
144
|
+
perturbed = {decision_id}
|
|
145
|
+
edges: list[tuple[str, str, str]] = []
|
|
146
|
+
# writer_of[key] is the most recent perturbed decision to have written it.
|
|
147
|
+
writer_of: dict[str, str] = {
|
|
148
|
+
write["key"]: decision_id for write in ordered[origin_position].get("writes", [])
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
for record in ordered[origin_position + 1 :]:
|
|
152
|
+
reader = record["decision_id"]
|
|
153
|
+
touched = False
|
|
154
|
+
for read in record.get("reads", []):
|
|
155
|
+
writer = writer_of.get(read["key"])
|
|
156
|
+
if writer is not None:
|
|
157
|
+
edges.append((writer, read["key"], reader))
|
|
158
|
+
touched = True
|
|
159
|
+
if touched:
|
|
160
|
+
perturbed.add(reader)
|
|
161
|
+
for write in record.get("writes", []):
|
|
162
|
+
writer_of[write["key"]] = reader
|
|
163
|
+
|
|
164
|
+
hypothesis = [
|
|
165
|
+
record["decision_id"]
|
|
166
|
+
for record in ordered[origin_position + 1 :]
|
|
167
|
+
if record["decision_id"] in perturbed
|
|
168
|
+
]
|
|
169
|
+
return Boundary(
|
|
170
|
+
origin=decision_id,
|
|
171
|
+
evidence=[decision_id],
|
|
172
|
+
hypothesis=hypothesis,
|
|
173
|
+
edges=edges,
|
|
174
|
+
)
|
reckon/sink.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"""Sinks. A sink takes a finished record dict and puts it somewhere durable."""
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
from typing import Protocol
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class Sink(Protocol):
|
|
9
|
+
def write(self, record: dict) -> None: ...
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class JsonlSink:
|
|
13
|
+
"""One JSON object per line. Append-only; the file is the run."""
|
|
14
|
+
|
|
15
|
+
def __init__(self, path: str | Path) -> None:
|
|
16
|
+
self.path = Path(path)
|
|
17
|
+
self.path.parent.mkdir(parents=True, exist_ok=True)
|
|
18
|
+
|
|
19
|
+
def write(self, record: dict) -> None:
|
|
20
|
+
line = json.dumps(record, sort_keys=True, default=str)
|
|
21
|
+
with self.path.open("a", encoding="utf-8") as handle:
|
|
22
|
+
handle.write(line + "\n")
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class MemorySink:
|
|
26
|
+
"""For tests and for verifying a run without touching disk."""
|
|
27
|
+
|
|
28
|
+
def __init__(self) -> None:
|
|
29
|
+
self.records: list[dict] = []
|
|
30
|
+
|
|
31
|
+
def write(self, record: dict) -> None:
|
|
32
|
+
self.records.append(record)
|
reckon/verify.py
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"""The verifier (§5).
|
|
2
|
+
|
|
3
|
+
It implements §5.1 exactly and obeys §5.2. The output is type-error shaped: the class
|
|
4
|
+
requested, the class actually available, and the specific evidence that separates them.
|
|
5
|
+
Never a score — a percentage over incommensurable kinds of missing evidence is the same
|
|
6
|
+
false confidence that made the OPA failure undetectable.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from dataclasses import dataclass, field
|
|
10
|
+
|
|
11
|
+
CLASS_NAMES = {
|
|
12
|
+
"C0": "Identity Replay",
|
|
13
|
+
"C1": "Tightening Replay",
|
|
14
|
+
"C2": "Loosening Replay",
|
|
15
|
+
"C3": "State-Coupled Replay",
|
|
16
|
+
}
|
|
17
|
+
LADDER = ("C0", "C1", "C2")
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
@dataclass
|
|
21
|
+
class Report:
|
|
22
|
+
requested: str
|
|
23
|
+
available: str | None
|
|
24
|
+
satisfied: bool
|
|
25
|
+
missing: list[str] = field(default_factory=list)
|
|
26
|
+
|
|
27
|
+
def render(self) -> str:
|
|
28
|
+
available = self.available or "none"
|
|
29
|
+
lines = [
|
|
30
|
+
f"Requested: {CLASS_NAMES[self.requested]} ({self.requested})",
|
|
31
|
+
f"Available: {available}",
|
|
32
|
+
]
|
|
33
|
+
if self.missing:
|
|
34
|
+
lines.append(f"Missing: {self.missing[0]}")
|
|
35
|
+
lines.extend(f" {item}" for item in self.missing[1:])
|
|
36
|
+
return "\n".join(lines)
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def _get(record: dict, path: str):
|
|
40
|
+
node = record
|
|
41
|
+
for part in path.split("."):
|
|
42
|
+
if not isinstance(node, dict) or part not in node:
|
|
43
|
+
return None
|
|
44
|
+
node = node[part]
|
|
45
|
+
return node
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def _unmet_c0(record: dict) -> list[str]:
|
|
49
|
+
missing = [
|
|
50
|
+
f"execution.{name}"
|
|
51
|
+
for name in ("runtime", "deps_digest", "path_digest")
|
|
52
|
+
if not _get(record, f"execution.{name}")
|
|
53
|
+
]
|
|
54
|
+
seed = _get(record, "execution.seed")
|
|
55
|
+
pure = _get(record, "execution.pure")
|
|
56
|
+
if seed is None and pure is not True:
|
|
57
|
+
# Determinism must be established, not assumed. Either the seed is recorded
|
|
58
|
+
# or the decision function is declared pure.
|
|
59
|
+
missing.append("execution.seed")
|
|
60
|
+
if pure is None:
|
|
61
|
+
missing.append("execution.pure")
|
|
62
|
+
return missing
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def _unmet_c1(record: dict) -> list[str]:
|
|
66
|
+
missing = []
|
|
67
|
+
if not _get(record, "predicate.id"):
|
|
68
|
+
missing.append("predicate.id")
|
|
69
|
+
if _get(record, "compared.value") is None:
|
|
70
|
+
missing.append("compared.value")
|
|
71
|
+
if _get(record, "policy.resolved_value") is None:
|
|
72
|
+
missing.append("policy.resolved_value")
|
|
73
|
+
if _get(record, "policy.resolution.provenance") == "unknown":
|
|
74
|
+
# §4.4: the record can say it does not know, and saying so caps it at C0.
|
|
75
|
+
missing.append("policy.resolution.provenance != unknown")
|
|
76
|
+
elif _get(record, "policy.resolution.provenance") is None:
|
|
77
|
+
missing.append("policy.resolution.provenance")
|
|
78
|
+
return missing
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def _unmet_c2(record: dict) -> list[str]:
|
|
82
|
+
missing = []
|
|
83
|
+
# §4.6: absent completeness reads as taken_only, the conservative interpretation.
|
|
84
|
+
completeness = _get(record, "candidates.completeness") or "taken_only"
|
|
85
|
+
if completeness != "exhaustive":
|
|
86
|
+
missing.append("candidates.completeness = exhaustive")
|
|
87
|
+
items = _get(record, "candidates.items") or []
|
|
88
|
+
if not items or any(item.get("compared_value") is None for item in items):
|
|
89
|
+
missing.append("candidates.items[].compared_value")
|
|
90
|
+
return missing
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
UNMET = {"C0": _unmet_c0, "C1": _unmet_c1, "C2": _unmet_c2}
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def verify(record: dict, *, requested: str) -> Report:
|
|
97
|
+
if requested not in CLASS_NAMES:
|
|
98
|
+
raise ValueError(f"unknown class {requested!r}; expected one of {sorted(CLASS_NAMES)}")
|
|
99
|
+
|
|
100
|
+
unmet_by_class = {name: UNMET[name](record) for name in LADDER}
|
|
101
|
+
|
|
102
|
+
available: str | None = None
|
|
103
|
+
for name in LADDER:
|
|
104
|
+
if unmet_by_class[name]:
|
|
105
|
+
break
|
|
106
|
+
available = name
|
|
107
|
+
|
|
108
|
+
ceiling = LADDER.index(requested) if requested in LADDER else len(LADDER) - 1
|
|
109
|
+
start = 0 if available is None else LADDER.index(available) + 1
|
|
110
|
+
missing = [item for name in LADDER[start : ceiling + 1] for item in unmet_by_class[name]]
|
|
111
|
+
|
|
112
|
+
if requested == "C3":
|
|
113
|
+
# §3, §6: C3 is never certified. The verifier reports where evidence ends and
|
|
114
|
+
# marks everything downstream as hypothesis. No implementation may do otherwise.
|
|
115
|
+
missing.append(
|
|
116
|
+
"C3 (State-Coupled Replay) is not certifiable by any verifier; "
|
|
117
|
+
"past the first flip this is counterfactual inference, not replay"
|
|
118
|
+
)
|
|
119
|
+
return Report(requested=requested, available=available, satisfied=False, missing=missing)
|
|
120
|
+
|
|
121
|
+
satisfied = available is not None and LADDER.index(available) >= LADDER.index(requested)
|
|
122
|
+
return Report(requested=requested, available=available, satisfied=satisfied, missing=missing)
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: reckon-rcdr
|
|
3
|
+
Version: 0.1.1
|
|
4
|
+
Summary: The capture layer for autonomous decisions — emit and verify replay-complete decision records (RCDR v0.1)
|
|
5
|
+
Author-email: Ola <laolex55@gmail.com>
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/Laolex/reckon
|
|
8
|
+
Project-URL: Specification, https://github.com/Laolex/reckon/blob/main/docs/RCDR-v0.1.md
|
|
9
|
+
Project-URL: Source, https://github.com/Laolex/reckon
|
|
10
|
+
Keywords: replay,audit,provenance,policy,agents,observability,rcdr
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
16
|
+
Classifier: Topic :: Software Development :: Quality Assurance
|
|
17
|
+
Classifier: Topic :: System :: Logging
|
|
18
|
+
Classifier: Typing :: Typed
|
|
19
|
+
Requires-Python: >=3.11
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
License-File: LICENSE
|
|
22
|
+
Provides-Extra: dev
|
|
23
|
+
Requires-Dist: pytest>=8; extra == "dev"
|
|
24
|
+
Requires-Dist: build>=1.2; extra == "dev"
|
|
25
|
+
Requires-Dist: twine>=5; extra == "dev"
|
|
26
|
+
Dynamic: license-file
|
|
27
|
+
|
|
28
|
+
# Reckon
|
|
29
|
+
|
|
30
|
+
**The capture layer for autonomous decisions.** Capture is the primitive; replay exists to
|
|
31
|
+
prove capture worked.
|
|
32
|
+
|
|
33
|
+
An autonomous system that made a decision you now regret leaves behind a record. The
|
|
34
|
+
question you want to ask that record is not "what happened" — it is *"would this have gone
|
|
35
|
+
the other way under a different policy?"* Reckon exists because that question is usually
|
|
36
|
+
unanswerable, and because nothing in the record tells you it is unanswerable.
|
|
37
|
+
|
|
38
|
+
## The finding
|
|
39
|
+
|
|
40
|
+
Five systems were probed: OPA, LangGraph, Temporal, and the decision logs of a live
|
|
41
|
+
Hyperliquid and a live Polymarket agent. Every one produced records that looked sufficient
|
|
42
|
+
and were not.
|
|
43
|
+
|
|
44
|
+
Three are reproducible here from the original probe artifacts, in [`demo/`](demo/):
|
|
45
|
+
|
|
46
|
+
- **OPA.** A sound policy engine, versioned bundles and a complete decision log still
|
|
47
|
+
produced two decisions with **identical input, identical bundle revision and identical
|
|
48
|
+
engine version that came out opposite ways** — and nothing in the record revealed which
|
|
49
|
+
regime was in force.
|
|
50
|
+
- **LangGraph.** Three threads, one identical persisted rationale, two different outcomes.
|
|
51
|
+
The threshold that separated them occurs in **zero of 12,286 persisted bytes**. The record
|
|
52
|
+
faithfully kept the reasoning that did not decide, and dropped the predicate that did.
|
|
53
|
+
- **Temporal.** The hardest case, since deterministic replay *is* its product. The same
|
|
54
|
+
divergence — history says `trade`, replayed code decides `skip` — is caught when the
|
|
55
|
+
decision schedules an activity and **silent when it only changes a returned value**.
|
|
56
|
+
Detection is drawn at command boundaries, not at decisions.
|
|
57
|
+
|
|
58
|
+
So: replay soundness is not compositional. It is a property of the whole execution path, not
|
|
59
|
+
of the components in it. And no record carries its own soundness proof.
|
|
60
|
+
|
|
61
|
+
The argument in full is in [`docs/ARGUMENT.md`](docs/ARGUMENT.md), including the
|
|
62
|
+
non-goals and what would falsify it.
|
|
63
|
+
|
|
64
|
+
## Capability classes
|
|
65
|
+
|
|
66
|
+
The verifier reports a class, never a score. A percentage over incommensurable kinds of
|
|
67
|
+
missing evidence manufactures exactly the false confidence that made the OPA failure
|
|
68
|
+
undetectable.
|
|
69
|
+
|
|
70
|
+
| Class | Counterfactual | Additionally requires |
|
|
71
|
+
|---|---|---|
|
|
72
|
+
| **C0** Identity | reproduce what happened | execution model, determinism |
|
|
73
|
+
| **C1** Tightening | admit strictly fewer actions | predicate structure, compared value, resolved policy |
|
|
74
|
+
| **C2** Loosening | admit more actions | the rejected candidate set and their values |
|
|
75
|
+
| **C3** State-Coupled | a changed decision perturbs later state | **not certifiable by anyone** |
|
|
76
|
+
|
|
77
|
+
C0–C2 are deductive given capture. C3 is not deductive for anyone — past the first flip it
|
|
78
|
+
is counterfactual inference, not replay. Reckon's honest top guarantee is: certify soundness
|
|
79
|
+
through C2, and for C3 certify *where the evidence ends*.
|
|
80
|
+
|
|
81
|
+
## Install
|
|
82
|
+
|
|
83
|
+
```
|
|
84
|
+
pip install reckon-rcdr
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
Python 3.11+, no runtime dependencies. The distribution is `reckon-rcdr`; the import name
|
|
88
|
+
and the CLI command are both `reckon`.
|
|
89
|
+
|
|
90
|
+
## Use
|
|
91
|
+
|
|
92
|
+
```python
|
|
93
|
+
from reckon import JsonlSink, Recorder
|
|
94
|
+
|
|
95
|
+
rec = Recorder(sink=JsonlSink("run.jsonl"), run_id="run-1", emitter="my-agent")
|
|
96
|
+
|
|
97
|
+
with rec.decision(action="transfer", pure=True) as d:
|
|
98
|
+
d.policy("policy.limit", value=5000, provenance="bundled", source="opa:bundle")
|
|
99
|
+
allowed = d.check("lt", left="request.amount", value=4200, right="policy.limit")
|
|
100
|
+
d.candidate("transfer", compared_value=4200, outcome="admit", predicate="p:limit")
|
|
101
|
+
d.candidate("hold", compared_value=4200, outcome="reject", predicate="p:limit")
|
|
102
|
+
d.candidates_exhaustive()
|
|
103
|
+
d.admit() if allowed else d.reject()
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
```
|
|
107
|
+
$ python -m reckon verify run.jsonl --class C2
|
|
108
|
+
Requested: Loosening Replay (C2)
|
|
109
|
+
Available: C2
|
|
110
|
+
Decisions: C2 x1
|
|
111
|
+
|
|
112
|
+
$ python -m reckon boundary run.jsonl --decision d-4f21a0c9e113
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
Exit code is non-zero when the requested class is unsupported, so it can gate a pipeline. A
|
|
116
|
+
build should be able to fail because the evidence needed to re-adjudicate a decision was
|
|
117
|
+
never captured.
|
|
118
|
+
|
|
119
|
+
## The emitter refuses to guess
|
|
120
|
+
|
|
121
|
+
Comparing against a policy that was never registered raises. Closing a decision without an
|
|
122
|
+
outcome raises. `pure` is a declaration the caller makes, never something the SDK infers, so
|
|
123
|
+
an undeclared decision without a seed fails C0. Absent candidate completeness reads as
|
|
124
|
+
`taken_only`; unestablished provenance is written as `unknown` and caps the record at C0.
|
|
125
|
+
|
|
126
|
+
Each of those is deliberately inconvenient. A record that quietly fills its own gaps is the
|
|
127
|
+
failure this whole project is named after.
|
|
128
|
+
|
|
129
|
+
## Layout
|
|
130
|
+
|
|
131
|
+
| Path | |
|
|
132
|
+
|---|---|
|
|
133
|
+
| `docs/RCDR-v0.1.md` | the record format — the normative document |
|
|
134
|
+
| `docs/ARGUMENT.md` | the argument: thesis, evidence, novelty, non-goals |
|
|
135
|
+
| `src/reckon/` | emitter, verifier, run-level verifier, CLI |
|
|
136
|
+
| `demo/` | three before/after arcs over real probe artifacts, plus the ablation |
|
|
137
|
+
| `demo/ABLATION.md` | which fields are load-bearing — generated, not asserted |
|
|
138
|
+
| `tests/` | every assertion traces to a requirement in the spec |
|
|
139
|
+
|
|
140
|
+
```
|
|
141
|
+
pip install -e ".[dev]"
|
|
142
|
+
python -m pytest
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
## License
|
|
146
|
+
|
|
147
|
+
Apache-2.0. Chosen over MIT for the express patent grant: RCDR is meant to be implemented
|
|
148
|
+
by other people, and an implementer should not have to wonder about that.
|
|
149
|
+
|
|
150
|
+
## Scope
|
|
151
|
+
|
|
152
|
+
No tamper evidence, no signatures, no anchoring — the demonstrated threat is omission, not
|
|
153
|
+
modification. No confidentiality. No inference over uninstrumented systems: RCDR describes
|
|
154
|
+
what an instrumented emitter must produce, and recovering decision semantics from arbitrary
|
|
155
|
+
code is a separate and much harder problem. Any implementation reporting a C3 certification
|
|
156
|
+
is non-conforming.
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
reckon/__init__.py,sha256=5po5X_nb_MPRnK5WidJKZVJ_K7QhWpxLejRFmLc5slk,666
|
|
2
|
+
reckon/__main__.py,sha256=ISrATKIgPrex2P5qp5cyhqmgWtJxh7KlbcWtRu0uREo,2163
|
|
3
|
+
reckon/emit.py,sha256=XLhsq_TblNmBVZ6ELmUFtOxccNYXwTJwJDb5C9GIy3I,7518
|
|
4
|
+
reckon/execution.py,sha256=UxiuQcrjuQPchKhVLWNzTmdqPwwKUgXC08FeL0fjU04,1751
|
|
5
|
+
reckon/predicate.py,sha256=FLLiA9lzPqt3LAR_ybhzfKJi2v8Gi0vqsVnpUKTzbE8,1078
|
|
6
|
+
reckon/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
7
|
+
reckon/record.py,sha256=GxPqZqZrKnLK-tbQ1Y3NudJbYqHrPxu1h3gd0ShsBZ0,3361
|
|
8
|
+
reckon/run.py,sha256=lUiUd4hl1hm8pVOTC6OZCW_m48_K0JdZagXZziUCcmI,6163
|
|
9
|
+
reckon/sink.py,sha256=ZiTrfhdeVBB6be6mUCZIFIIuMRS67JWulc-noYMsLSc,893
|
|
10
|
+
reckon/verify.py,sha256=ZRBF32phzXFbODJvn1oODiUFHJf-p56pH90zZ3ctKrc,4528
|
|
11
|
+
reckon_rcdr-0.1.1.dist-info/licenses/LICENSE,sha256=z8d0m5b2O9McPEK1xHG_dWgUBT6EfBDz6wA0F7xSPTA,11358
|
|
12
|
+
reckon_rcdr-0.1.1.dist-info/METADATA,sha256=nhv4Gsik4xfTnk3JCzC0FTEI4ZRvG15ld2qxP8Sktkg,6763
|
|
13
|
+
reckon_rcdr-0.1.1.dist-info/WHEEL,sha256=K260EYznzXsJYBQGqmI8VTxEdiZYNvDZwW9cBh9-_MA,91
|
|
14
|
+
reckon_rcdr-0.1.1.dist-info/entry_points.txt,sha256=bqJxuR8h4Btdk1xCKICqpSZpOu-BiiyA568SZwGXqE8,48
|
|
15
|
+
reckon_rcdr-0.1.1.dist-info/top_level.txt,sha256=HWHjuFBolNZ_qyixEuNjpB_5H-zTjQctHStS29q7j_w,7
|
|
16
|
+
reckon_rcdr-0.1.1.dist-info/RECORD,,
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
reckon
|