Compare commits

...
Author SHA1 Message Date
Nick ba57eb8177 refactor(construction_commands): Phase B language-advantage pass — dichotomy wave
deploy / deploy (push) Skipped
CI Pipeline / lint (push) Canceled after 0s
CI Pipeline / unit-tests (push) Canceled after 0s
CI Pipeline / go-surface (push) Canceled after 0s
CI Pipeline / rust-surface (push) Canceled after 0s
CI Pipeline / canary (push) Canceled after 0s
CI Pipeline / best-practices (push) Canceled after 0s
CI Pipeline / documentation (push) Canceled after 0s
CI Pipeline / type-check (push) Canceled after 0s
CI Pipeline / gitea-offline (push) Canceled after 0s
CI Pipeline / required-checks (push) Canceled after 0s
CI Pipeline / CI Pipeline / notify-event-bridge (push) Canceled after 0s
Typed CommandType/Op/PhaseClass lattices replace the string-arm chains:
parse IS the unknown-command refusal surface, the (command, phase-class)
tuple match in _validate is exhaustive, and command_to_operation maps
through to_op. Behavior byte-identical to the Phase A parity port —
frozen battery the referee, zero truth changes (sha256 ba9fb44d pre ==
post; replay 54/54; pytest 12/12 both pins; clippy -D warnings clean).
2026-10-14 16:10:12 +01:00
Nick 8aa21d3da0 feat(construction_commands): port to FULL Rust — dichotomy wave 2026-10-14 15:31:00 +01:00
Nick 573158e692 feat(progressive_escalation): close PARTIAL gaps — dichotomy wave
2/8 -> 9/9 FULL (RUST): execute_with_escalation (the full loop over
Executor/Verifier trait seams — the oracle's MockExecutor/MockVerifier are
the concrete contract), test_escalation (self-test scenario through the
loop kernel), handle_hook, EscalationResult.to_dict (nine-key dict, key
ORDER asserted via serde_json preserve_order), the execute/verify seam
traits (ScenarioSeams per-tier canned data — callables cannot cross the
FFI, contracts resolution precedent), and the _pe_core probe mirror
(salience_gate _sg_core pattern, pin semantics battery-asserted).
should_escalate/get_next_tier REWRITTEN onto oracle truth: the stale W6
sketch carried a 4-trigger list + non-escalating default; the oracle
freezes 10 ESCALATION_TRIGGERS and escalates on EVERY failure (membership
branch informational) + py_truthy for the truthy passed domain.

Facade: progressive_escalation.py delegates the four kernels through the
new progressive_escalation_loader.py (doc-envelope FFI, cs_free_string);
RUNE_PROGRESSIVE_ESCALATION_CORE=python pins the floor. Fix over the
cancelled attempt: probe+call wrapped in ONE try per delegating fn (a
raising _pe_core escaped the old split try — caught by the parity
fallback layer).

Truth: 35 harness cases + 12 loop scenarios (scripts/
gen_progressive_escalation_truth.py under scripts/pe_freeze_seams rig) —
regen byte-identical, freeze_truth.py --verify byte-identical. Battery
8/8 (gap_battery.rs, truth embedded VERBATIM); replay failures=0;
live parity frozen=48 fuzz=550 live=14 failures=0 (seed 2479); clippy
-D warnings clean; selftest + native suite (19 passed) green BOTH pins;
ruff clean. Audit: progressive_escalation 9/9 RUST. Evidence:
verification/cv-summary.md (+ cv-*.exit).
2026-10-14 15:22:08 +01:00
Nick e3c5c62a1c refactor(event_bus): Phase B language-advantage pass — dichotomy wave
typed CorruptEventStoreError (errors.As + offset>=2 message fix), journalMu
serialized appends, atomic eeUUIDNext mint; phase_b race battery 8x4 fan-out
with id-uniqueness law; re-verified freeze 61/61, parity 73/73, build/vet/
gofmt/race, pytest both pins (eb2-*.exit evidence)
2026-10-14 15:16:40 +01:00
Nick a8d7867143 feat(event_bus): close PARTIAL gaps — dichotomy wave 2026-10-14 15:16:40 +01:00
Nick dba124bfce chore(store): close construction_projection dichotomy contract BUILDER-2026-10-14T13:05:09Z-7a8cd9-factory-gap-cpj (parity 184a93ce) 2026-10-14 15:09:00 +01:00
Nick 9ce798ec1d feat(construction_projection): close PARTIAL gaps — dichotomy wave
Port all 4 oracle fns name-preserving to Rust (audit 1/4 -> 4/4):
_contract_entity, validate, write_mini_doc (markdown build only — the
file write stays adapter-side), and project (the W6-era facade path was
dead code: cp_loader.project never existed). cproj_loader ctypes FFI
(cp_project/cp_contract_entity/cp_validate/cp_write_mini_doc,
doc-envelope law); facade delegation under
RUNE_CONSTRUCTION_PROJECTION_CORE with crash-parity floor fallback; the
operation-wait bridge stays adapter-side (resolved scalars ride the
frozen rows — SPEC-grammar law). Dead W6 canary
(canary_construction_projection.py + frozen_projection.json, calling
the non-existent cp_loader.project, invoked by nothing) deleted.

Truth: 52-case shared-harness corpus (scripts/freeze_truth.py +
cproj_freeze_seams rig: pinned fake scaffold/bridge, hermetic scratch,
no absolute paths/wall clock), --verify byte-identical; gap_battery.rs
replays VERBATIM (include_str!, envelope pinned to verify file) 8/8.
Live 3-way parity 100% (843 comparisons: 52 frozen + 240 fuzz project +
40 mini-doc + 7 crash). clippy -D warnings + fmt clean. Python both
pins: test_contract_minidoc 3/3 + test_substrate_seam 12/12 (delegation
live + python pin). Fix-first with proof: minidoc fixture
raw-transition to closed refused since 2597b58b (verified failing at
pristine HEAD) — now closes via iface.close(), re-exercising mini-doc
emission end-to-end through the kernel. Evidence:
verification/cpj-summary.md + cpj-*.exit.
2026-10-14 15:08:00 +01:00
Nick 279eb5a316 chore(store): close context_pressure dichotomy contract BUILDER-2026-10-14T13:22:17Z-f45cd6-factory-gap-cps (parity e8f15030) 2026-10-14 15:00:51 +01:00
conductor 7147c1a0d1 chore(release): auto-bump version to 0.304.0 — earned by # (minor: converged release (push-to-master bump))
deploy / deploy (push) Skipped
CI Pipeline / lint (push) Canceled after 0s
CI Pipeline / unit-tests (push) Canceled after 0s
CI Pipeline / go-surface (push) Canceled after 0s
CI Pipeline / rust-surface (push) Canceled after 0s
CI Pipeline / canary (push) Canceled after 0s
CI Pipeline / best-practices (push) Canceled after 0s
CI Pipeline / documentation (push) Canceled after 0s
CI Pipeline / type-check (push) Canceled after 0s
CI Pipeline / gitea-offline (push) Canceled after 0s
CI Pipeline / required-checks (push) Canceled after 0s
CI Pipeline / CI Pipeline / notify-event-bridge (push) Canceled after 0s
Promotion record: (unknown)
2026-10-14 14:44:02 +01:00
Nick 35add00493 refactor(token_optimizer): Phase B language-advantage pass — dichotomy wave
Op::run — the enum owns its execution: every variant's semantics live
next to its name and the exhaustive match moved into the type (adding an
op without semantics stays a compile error, now enforced where the
behavior lives, not at the call site). _write_snapshot_doc as a
filter_map-collect iterator chain over the transfer array (no mutable
accumulator; the entry-key projection is one declarative pipeline).

Behavior unchanged: battery 7/7, live parity 60/60, clippy -D warnings
clean, module tests 5/5 both pins. Evidence: verification/to-phaseb-parity.exit.
2026-10-14 14:43:43 +01:00
Nick 19c062e15c feat(token_optimizer): close PARTIAL gaps — dichotomy wave
Name-preserving counterparts for the 9 audit-gap fns (16/25 -> 25/25 FULL):
Entry::to_dict, State::_to_state/_apply_state, _run_kernel (op dispatch),
_compress_context (tc delegation mirror), _write_snapshot_doc (file-doc
conversion promoted out of the battery), get_optimizer (construction
decision + FFI op), _tc_core/_to_core pin contracts (frozen rows +
battery assertions). _tc_core/_to_core/get_optimizer I/O halves documented
as facade seams (memory_selector pattern).

New truth: 19-case gap freeze via the shared harness (rig
scripts/to_freeze_seams) — byte-identical across gen runs and --verify.
Pins the _load partial-adoption quirk (bad entry mid-loop: partial cache
in file document order, stats skipped) + CacheEntry kwargs semantics
(optional use_count/hit_count, unknown key TypeError); serde_json
preserve_order for document-order iteration.

Battery 7/7; live parity 60/60 (FFI construction rows + 40 dual-mode fuzz
trials + module-API/singleton E2E); clippy -D warnings clean; module
tests 5/5 both pins. Evidence: verification/to-*.
2026-10-14 14:43:43 +01:00
Nick e481184fff chore(store): close self_improve dichotomy contract BUILDER-2026-10-14T13:37:52Z-949c40-factory-gap-si (parity bd5c46f9, phase B eef472cd) 2026-10-14 14:41:55 +01:00
Nick eef472cdca refactor(self_improve): Phase B language-advantage pass — dichotomy wave
Typed Seam (Ok/Failed/Missing) and Severity (Warning/Info/Error) enums:
analyze_system and _warn_stderr match exhaustively on Seam::from_probe,
suggest_improvements classifies via Severity::classify — the oracle's
elif-chain fall-through semantics preserved (battery-proven: 8/8 cargo
tests incl. 61-row frozen-truth replay, 61/61 live parity both pins,
clippy -D warnings + fmt clean, freeze regen byte-identical modulo the
wall-clock stamp).
2026-10-14 14:32:20 +01:00
Nick bd5c46f9d9 feat(self_improve): port to FULL Rust — dichotomy wave
Kernel/facade split per the intent ledger: the pure kernels (analyze
probe→findings threshold ladder, suggest ⚠️/ℹ️/❌ mapping, hook
passthrough record, pinned-clock _now isoformat kernel, CLI rendering
switch) live in src/rust/self_improve behind the doc-envelope FFI
(si_analyze/si_suggest/si_handle_hook/si_now/si_main); all five file/DB
seams stay in the Python facade probe builder with error strings crossing
FFI verbatim. si_loader ctypes bridge (RUNE_SI_CORE=python pin,
SI_RUST_LIB override, shared cs_free_string allocator). Frozen truth:
61 rows (26 analyze / 10 suggest / 4 hook / 8 now / 13 cli) generated
from the live oracle with path-free fixture messages, pinned clock, and
exact-representable :.0% ratios; 61/61 byte-identical at replay across
facade both-pins + kernel direct; branch_battery replays the frozen file
natively; pytest port battery 8/8; clippy -D warnings clean.
2026-10-14 14:29:51 +01:00
Nick e8f1503028 feat(context_pressure): close PARTIAL gaps — dichotomy wave
FULL parity port to Rust (9/9 fns, was 3/9): token estimation (codepoint
len law), the pressure ladder (raw-gate vs round3 display), degradation
signals (int-0 max law, \w+ runs), JSONL entry assembly (dict-spread
override), log tail reader (deque(maxlen) + file-iteration law), stats
counter (crash parity on non-dict lines), on-message hook (truthiness,
message/text/str(data) fallback, pyrepr), CLI dispatch (argparse shapes,
.1% renders, code-2 law). File IO + wall clock stay in the Python facade
(no-clock law); cps_loader.py is the ctypes seam (RUNE_CPS_CORE /
RUNE_CONTEXT_PRESSURE_CORE pins).

Frozen truth 75 cases under the cps_freeze_seams rig (byte-identical x2,
shared-harness --verify OK 28 envelope cases); branch battery 10/10;
live parity frozen=78 regen=6 fuzz=1400 live=18 failures=0; pytest 34/34
both pins; clippy -D warnings + fmt clean; audit 3/9 PARTIAL -> 9/9 FULL
(RUST). Evidence: verification/summary-cp.md + cp-* files.
2026-10-14 14:06:31 +01:00
Nick c63717adfb fix(store): refresh construction_pattern close-evidence with Phase B 45a7dd6a 2026-10-14 12:35:52 +01:00
Nick 45a7dd6a8c refactor(construction_pattern): Phase B language-advantage pass — dichotomy wave
SignalTally struct + free _check fn (evaluate closure accumulators as one
struct); _surface_text zero-copy BTreeSet<&str> borrowing input JSON (per-
token allocations eliminated, sorted projection byte-identical);
_need_dict Map::with_capacity(3). Battery 14/14, clippy 0, harness 18/18
byte-identical, live parity 192/192 both pins, pytest 30/30+66/66.
2026-10-14 12:33:14 +01:00
Nick ee77255c65 chore(store): close adaptive_router Phase B dichotomy contract BUILDER-2026-10-14T09:00:07Z-70ebf0-factory-gap-ar (parity f7855558, phase B 71a7c053) 2026-10-14 12:05:42 +01:00
Nick 9ea8c00701 refactor(safety_override): Phase B language-advantage pass — dichotomy wave
* contains_ci: zero-alloc ASCII needle matching for the keyword-count
    check (py_matches) — pure-ASCII (text, keyword) pairs match through
    an eq_ignore_ascii_case window scan (ASCII case folding is 1:1 with
    the oracle's .lower(), byte-identical semantics); ANY non-ASCII byte
    on either side falls to the full Python-parity to_lowercase() path so
    Unicode case mappings (ſ, İ) are never skipped. The hot pattern-match
    path no longer allocates the lowered text copy per keyword.
  * safety_extract_keywords: pure-ASCII text scans bytes in place for
    [a-z]{4,} runs (identical to the oracle's findall over .lower() on
    ASCII; non-ASCII keeps the Unicode char path) — the lowered-copy
    allocation disappears for ASCII inputs.
  * #[must_use] on the whole pure surface (14 gap-close kernel fns).
  * battery: ASCII-scan <=> Unicode-path equivalence self-checks over the
    frozen corpus (contains_ci pairs, extract_keywords mirror, 200-unit
    slice law) + std-only Phase B bench (is_refusal and contains_ci over
    the frozen corpus, 2k iterations each).

Truth untouched; battery replays byte-identically (64+5 tests green),
live parity 2065/2065 (65 frozen + 2000 fuzz, seed 2479), gen freeze
verify byte-identical, clippy --all-targets -D warnings clean, pytest
21/22 both pins (1 kernel-absent skip under python pin). Evidence:
/tmp/so_{cargo_pb,clippy_pb,parity_pb,t_pb1,t_pb2}.txt
2026-10-14 11:40:37 +01:00
Nick 3318c99171 chore(store): close tiered_executor dichotomy contract BUILDER-2026-10-14T10:25:17Z-940a71-factory-gap-te (parity a858ab13) 2026-10-14 11:29:52 +01:00
Nick de6a01fca1 chore(store): close standardized_providers dichotomy contract BUILDER-2026-10-14T10:18:54Z-6a57c2-factory-gap-sp (parity 649febff) 2026-10-14 11:26:59 +01:00
Nick a858ab1392 feat(tiered_executor): close PARTIAL gaps — dichotomy wave
audit 3/8 PARTIAL -> 8/8 FULL (GO side). Ported to_dict (CognitiveJob/CognitiveResult via the real constructors), the full execute surface (no-profile early return with attempts=1 and zero latency, T0-deterministic vs model dispatch), _execute_model (OO OLLAMA payload json.dumps byte-parity: ', '/' : ' separators, insertion order, ensure_ascii + surrogate pairs, rune-safe [:2000] response slice, crash-parity envelopes for unknown-url-type + connection-refused), _ctx_budget + vendored ResolveCtxBudget (GO SIBLING ISOLATION law), and test_executor assert-parity (Python True/False literals, crash exit 1 after the Coding line).

Frozen truth: 27-case envelope via the shared freeze_truth.py + scripts/te_freeze_seams rig (time.time pinned -> latency 0.0 mirrored by the TE_LATENCY_MS seam; OLLAMA echo server reflects the request body so payload bytes ride the truth rows; ModelRegistry({}) falsiness -> DEFAULT_PROFILES, no-profile rows via the T9 sentinel). Verified byte-identical twice. Battery 11 tests green; CI replay binary PARITY OK 27/27; live parity sweep 31/31 (25 op families + 6 CLI incl. test / execute / usage); gofmt/vet/build clean; python smoke both pins (no loader seam - vacuous pin, PP precedent).

Evidence: verification/te-*.exit/*.exit files + te-summary.md (logs local, * log gitignored).
2026-10-14 11:23:27 +01:00
Nick 649febfff7 feat(standardized_providers): close PARTIAL gaps — dichotomy wave 2026-10-14 11:15:48 +01:00
Nick da8d705221 chore(store): close model_registry dichotomy contract BUILDER-2026-10-14T10:09:47Z-65f7a4-factory-gap-mreg (parity 268aa4b3) 2026-10-14 11:12:35 +01:00
Nick 268aa4b332 feat(model_registry): close PARTIAL gaps — dichotomy wave
2/8 -> 8/8 FULL: to_dict/get_profile/get_enabled_profiles/
get_profiles_by_tier/list_profiles/test_registry ported name-preserving
onto the existing get_cheapest_capable/resolve_context_budget surface.
KNOWN FLAG FIXED (model_connect, 2026-10-14): batch-67 hardcoded
toolReserve=2048 and a single outputReserve; the live oracle holds
TOOL_RESULT_RESERVE=1024 and the OUTPUT_RESERVE per-task-kind ladder
{default 2048, verify 512, summarize 1024, embed 0} — gated by LOCAL,
not tier (legacy truth.json never noticed: both its budget rows are
local models).

Truth: 35-case envelope via the shared harness + scripts/mreg_freeze_seams
(JSON-safe seam wrappers; pairs carry registry insertion order —
key-vs-attribute lookup, first-id-match, stable ties, falsy->DEFAULT ctor
law all pinned; the (or {}) empty branch pinned via a __new__ seam).
--verify byte-identical + fresh regen byte-identical. Battery 4 tests +
binary replay-gap 35/35 (+ legacy replay 4/4 regression); live parity
4/4 scenarios (36 ops, scripts/check_model_registry_parity.py);
gofmt/vet/go build clean; Python suite green both pins + oracle smoke.
No loader seam exists (RUNE pin vacuous, documented). Audit:
model_registry 8/8 GO; programme 55% (105/192).
2026-10-14 11:08:37 +01:00
Nick 80853ece02 chore(store): close scaffold dichotomy contract BUILDER-2026-10-14T10:02:32Z-14a61b-factory-gap-sc (parity 5c4ba1cc, phase B 4f9f0424) 2026-10-14 11:06:46 +01:00
Nick f24e78826d chore(store): contracts contract evidence — phase B SHA e09bbedc (parity 11e4bd20) 2026-10-14 10:47:14 +01:00
Nick e09bbedca0 refactor(contracts): Phase B language-advantage pass — dichotomy wave
Phase enum (exhaustive match on the resolution phase — string matching
retired inside the kernels; unknown phases fall to Found, the oracle's
catch-all arm) with Display/as_str/parse and RunSpec::phase(); #[must_use]
on the eight pure kernels; Phase round-trip unit test. Both frozen-truth
batteries UNCHANGED and green (20/20 crate tests, clippy -D warnings
clean, harness --verify 23/23 byte-identical, live replay failures=0).

Fix-first completion of the parity commit's claimed loader wiring: the
eight gap-close kernel wrappers (gate/resolve/run_python/run_all/capture/
save/load/main_cli) land here with five loader-level parity tests; port
tests 11/11 green both pins (delegated + RUNE_CONTRACTS_CORE=python).
2026-10-14 10:39:56 +01:00
Nick 71a7c05336 refactor(adaptive_router): Phase B language-advantage pass — dichotomy wave
Behavior-neutral Go advantages in src/go/adaptive-router (battery stays
green proving no behavior change; frozen truth 25/25 byte-identical;
live parity 32/32):

- typed Route constants (RouteLocalFix/RouteStandard/RouteResearched):
  route comparisons compile against named constants — a typo'd route is
  a compile error at every use site (ROUTES map, floor guard, returns)
- floorRiskSet/floorUncertaintySet O(1) membership maps replace the
  O(n) slice scans in FloorAppliesFromFlags / FloorReason / FloorApplies
- single-pass floor in ClassifyRoute: FloorReason hits computed once,
  floor = hits nonempty — one walk instead of the oracle's two-call
  shape (equivalent union, comment pins the equivalence)
- FloorReason preallocates the hits slice (cap 3: one hit per source)

Follow-up to contract BUILDER-2026-10-13T16:25:22Z-7e3fd4-factory-gap-ar
(parity f7855558); Phase B contract
BUILDER-2026-10-14T09:00:07Z-70ebf0-factory-gap-ar closes on this
commit's pushed SHA.
2026-10-14 10:21:13 +01:00
Nick f07d8f3843 chore(store): close voice_sync dichotomy contract BUILDER-2026-10-14T05:29:33Z-a69ece-factory-gap-vs (parity 056fa974, phase B 86ece218) 2026-10-14 06:34:59 +01:00
Nick a915a3b072 chore(factory): layout_contract landed (close 4402c428, 6/6, 35/35 parity) 2026-10-14 06:28:42 +01:00
Nick 86ece2180c refactor(voice_sync): Phase B language-advantage pass — dichotomy wave
* contains_ci_upper: ASCII-anchored zero-alloc needle matching for the
    section capture chain — pure-ASCII haystacks match through an
    eq_ignore_ascii_case byte scan (ASCII case folding is 1:1, so this is
    byte-identical to the oracle's needle-in-upper()); ANY non-ASCII byte
    falls to the full Python-parity to_uppercase() path so Unicode case
    mappings (ſ -> S, İ) are never skipped. The common parse case no
    longer allocates the uppercased line copy.
  * get_delivery_register_from_db: chars().take(201).count() bounds the
    codepoint-length probe at the predicate's own threshold instead of
    counting every char of the row (identical oracle semantics:
    len(text) > 200).
  * #[must_use] on the whole pure surface (11 kernel fns).
  * battery: ci-scan <=> upper-contains equivalence self-check over
    every frozen extraction row (5 needles) + std-only Phase B bench
    (register probe 8.6 us/call over 65 rows incl. bounded length scan;
    needle scans 3.3 us/text over the 19-text frozen corpus; full chain
    10.8 us/extract+generate call).

Truth untouched; battery replays byte-identically (16 tests green),
gen --replay 125/125, canary 15/15, pytest 17/17 live + pinned,
clippy -D warnings clean. Evidence:
verification/voice-sync-phaseb-{cargotest,parity,canary,python}.log
2026-10-14 06:26:47 +01:00
Nick 056fa974a8 feat(voice_sync): port to FULL Rust — dichotomy wave
Name-preserving port of the 7 audit-missing functions into
src/rust/voice_sync (the module's classification side is RUST — sqlite3
storage-backed; a stale Go voice-sync dir exists from an early partial
register-substring helper):

  get_delivery_register_from_db / get_delivery_register
      -> the chunk row-selection loop (rows arrive fetched Python-side;
         the SQL WHERE + fresh-store OperationalError guard stay in the
         facade), len>200 pinned as a CODEPOINT count
  extract_voice_section
      -> section parser: influence capture incl. '- **:**',
         TECHNICAL+DELIVERY double-hit header captured as a technical
         line, elif-section persistence, case-sensitive THE VOICE /
         THE FEMININE prefixes, truthy all-empty-lists parse
  generate_voice_section
      -> assembler with the exact fixed block + calibration cap-3
  update_rune_md_content / update_rune_md
      -> pure splice view (composite {"result", "new_content"} so the
         facade performs the write) — the oracle gains the same
         oracle-level JSON view the shared freeze gate pins
         (update_rune_md_content; salience_gate evaluate_salience_dict
         precedent); char-boundary-safe +10 offset past ## Voice
  check_sync / handle_hook / sync_voice
      -> parts-shaped decisions (register, prompt_content in as
         arguments); handle_hook pins the oracle's auto-sync 'synced:
         true with error details' verbatim
  _vs_core
      -> kernel mirror of the facade probe contract (pin lattice,
         salience_gate _sg_core precedent)

Facade delegation: voice_sync.py wires vs_loader.py (10 vs_* doc-envelope
symbols, free via capability_scoring cs_free_string, no free-symbol
export, VOICE_SYNC_RUST_LIB override, RUNE_VOICE_SYNC_CORE=python pin —
the shared harness derives EXACTLY this pin name, inverting salience's
wrong-name quirk); _py_* fallbacks are the strangler-fig machinery class;
SQLite I/O, rune.md writes, wall-clock _now and the argparse main() CLI
stay facade-side (behavior crate precedent).

Frozen truth via the shared scripts/freeze_truth.py harness (generator
scripts/gen_voice_sync_truth.py, poisoned-truth law
RUNE_VOICE_SYNC_CORE=python):
  frozen_vs_truth.verify.json — 37 pure rows byte-identical under
  freeze_truth.py --verify (plain process, core-state independent);
  frozen_vs_truth.json — 64-row envelope: verify rows first, then the
  rig-required store/file rows whose kernel-shaped inputs ride in args
  with fixtures for --replay (len<=200/201 boundary, first-match order,
  fresh-store None, lowercase delivery-register passes-SQL-but-loses-
  python-filter, missing-influence scan order, auto-sync write capture).
  branch_battery.rs replays both VERBATIM (include_str!, order-sensitive
  canonical-string compare — the facade consumes kernel JSON directly so
  Python insertion order must survive: serde_json preserve_order).
  Live parity 125/125 (gen --replay: facade-delegating + kernel-direct);
  canary 15/15; second-modality differential 486 comparisons / 0
  divergences (2479-seed fuzz beyond the corpus incl. multibyte splices
  and sandboxed I/O decisions); pytest 17/17 in three pin states (live /
  RUNE_VOICE_SYNC_CORE=python / VOICE_SYNC_RUST_LIB poisoned).

Dichotomy audit: voice_sync PARTIAL 3/10 -> FULL 12/12 (update_rune_md_
content + _vs_core join the surface per the salience precedent; _py_*
helpers are the audit's machinery class).
2026-10-14 06:26:47 +01:00
Nick 4402c4284b chore(store): close layout_contract dichotomy contract BUILDER-2026-10-14T05:21:12Z-4723a5-factory-gap-lc (parity 4bbed58d)
Walk draft->approved->building->verifying in one process; final entry
via close() per the quality-gate law (predicted-vs-observed
contract_quality computed; raw closed-transition refused — the first
walk attempt hit exactly that gate and completed through close()).
2026-10-14 06:25:44 +01:00
Nick ea7b9a0ca3 chore(factory): claim_audit landed (close d53569e4, 184/184 parity), drift_compression landed (close e383331f — kernels live in memory_scoring crate per audit-alias fix; verified 8/0 via the right home); audit regenerated 2026-10-14 06:21:46 +01:00
Nick 4bbed58d2c feat(layout_contract): close PARTIAL gaps — dichotomy wave-5
Audit 2/6 -> 6/6 FULL (RUST): the four audit-missing fns ported
name-preserving (define_region, bind_component, amend_layout_contract,
record_layout_observation) as pure doc-in/doc-out Rust kernels
(now is an argument — no-clock law; structural_store add_entity/entity
merge law replicated: high-water maturity, sorted-set evidence union,
identities key-level update, alias-following resolution).

Freeze rig scripts/lc_freeze_seams (PYTHONPATH auto-import, used by BOTH
generator and --verify): blanket RUNE_*_CORE=python + EXPLICIT
RUNE_LC_CORE/RUNE_STRUCTURAL_CORE pins (the blanket loop only pins vars
already in the env — an unpinned first re-freeze ran through live
delegation and CAUGHT the absorb divergence), frozen clock on both now
seams, DOC-CARRYING wrappers ({result, doc:{entities,observations}}),
errors frozen as {error: Type: message}.

Truth: 35-case frozen corpus (frozen_lc_gap_truth.json, envelope with
frozen_now) via the shared harness, embedded VERBATIM in gap_battery.rs;
regeneration byte-identical; freeze_truth --verify OK.

Real bugs the ladder caught (fixed pre-commit): (1) re-bind ASSIGNS a
fresh amendments ledger — insert-if-missing diverged from assignment
(live-facade smoke, discriminating frozen case added); (2) identities
merge is wholesale key assignment (add_entity .update() law — tech
reset on no-op re-define; recursive-merge absorb diverged, caught by the
parity LIVE layer); (3) bind_component has NO framework_attrs param —
framework detail rides **framework_attrs, dispatch collects unknown
kwargs; (4) serde_json preserve_order keeps observed-dict insertion
order (json insertion-order quirk).

FFI: lc_define_region/lc_bind_component/lc_amend_layout_contract/
lc_record_observation (doc-envelope) + lc_replay (raw replay surface).
Facade delegates with RuntimeError->ValueError translation and
identity-preserving absorb (lc_loader.absorb — returned entity IS the
stored one; aliasing survives round-trips).

Battery 10/10 (verbatim replay + FFI roundtrip + 6 branch proofs);
clippy -D warnings clean; parity 100% (35/35 frozen + byte-identical
live re-freeze); layout+consumer tests 64/64 BOTH pins. Full-suite
baseline failures pre-exist identically with/without this port
(coordinator-owned debt).
2026-10-14 06:20:13 +01:00
Nick 29ba4341c2 docs(claim_audit): record close SHA in gap-close summary 2026-10-14 06:16:26 +01:00
Nick d53569e4f8 chore(store): close claim_audit dichotomy contract BUILDER-2026-10-14T05:12:31Z-7ed388-factory-gap-ca (parity e489c100, phase B 05ba4fdd) 2026-10-14 06:15:10 +01:00
Nick 050e142d61 chore(store): close builder_bridge dichotomy contract BUILDER-2026-10-14T04:51:14Z-20ac15-factory-gap-bb (parity 7cc134c2)
builder_bridge gap-close: 3/11 PARTIAL -> 11/11 FULL (GO); frozen truth
22 cases byte-identical (generation, --verify, regeneration under the
bb_freeze_seams rig), Go battery + -race green, live parity 11/11 case
families byte-equal vs the live oracle (dict + markdown + construction
lines + store resolution incl. the default-store branch), gofmt/vet/
build clean, Python both pins green. Evidence: verification/bb_*.{log,
txt,exit,md}.
2026-10-14 06:10:10 +01:00
Nick 94a748a4ad chore(store): close structural_model dichotomy contract BUILDER-2026-10-14T05:01:34Z-f0cd1b-factory-gap-stm (parity 00839d1a, phase B c0073a5d) 2026-10-14 06:08:44 +01:00
Nick 85f20cfe9d feat(builder_bridge): close PARTIAL gaps — dichotomy wave
Port the 8 audit-missing functions name-preserving into the GO impl at
src/go/builder-bridge (audit 3/11 PARTIAL -> 11/11 FULL): ToDict,
ConstructionStore, ActiveConstructionLines (segment-architecture store
projection incl. pattern/layout obligations), DefaultSelector,
GetSelector, RetrieveMemory, CachedMemory, ValidatedLessonsFor, plus the
Preflight wiring over a vendored adaptive-router (pure-Go detectFlags
transcribed from the oracle's route_risk_flags insertion order; the
sibling module's cgo/Rust link is deliberately not vendored — this
module's oracle computes flags in pure Python).

Frozen truth: 22 shared-harness rows (to_dict/to_markdown recv forms
incl. line caps + inject-nothing + floor-only, cache key, lessons,
memory abstention + cache-hit, store env branch, active-construction
fixture projection) — byte-identical across generation, --verify and
regeneration under the bb_freeze_seams rig. Live parity: 11 case
families byte-equal on dict+markdown+lines+store vs the live oracle,
including the default-store branch (real store, both sides live) and
the doubled floor-prefix quirk. go build/vet/gofmt/test -race green;
Python suite green under both pins (one pre-existing env-dependent test
failure verified identical on pristine main). Documented divergences:
populated-store hybrid recall stays Python-side (frozen surface is the
degrade-safe abstention both sides reproduce).

Evidence: verification/bb-*.{txt,exit,md}.
2026-10-14 06:07:32 +01:00
Nick 05ba4fdd4e refactor(claim_audit): Phase B language-advantage pass — dichotomy wave
Compile every 'static-sourced regex once (OnceLock cache keyed by
pattern; case-insensitive subs via a mutex-guarded map): zero per-call
Regex::new compiles on the scan/verify/degrade/audit hot paths. Behavior
unchanged — battery 10/10, parity 184/184, freeze --verify byte-identical,
clippy + rustfmt clean.
2026-10-14 06:05:10 +01:00
Nick e489c10067 feat(claim_audit): close PARTIAL gaps — dichotomy wave
Port the 10 audit-missing fns name-preserving into src/rust/claim_audit
(audit 4/14 PARTIAL -> 14/14 FULL): reframe, _graph_has (system-libsqlite3
read-only FFI, oracle SQL verbatim), _warm_has (gathered-row kernel),
verify (verdict tree), journal (timestamp-as-argument line serialiser),
report, _symmetry_safe (never-fatal {} floor — research_lens absent),
handle_hook, main (CLI dispatch with byte-parity renderers), plus the
already-matched scan/scan_text/degrade/evidence_terms in-crate.

Freeze: scripts/gen_claim_audit_truth.py under scripts/ca_freeze_seams
(hermetic /tmp/ca_gap_freeze) — 14 rows byte-identical via --verify;
battery embeds truth via include_str!. Live parity 184/184 (frozen FFI
rows + main CLI replay + 155 fuzz + 9 dual-mode facade). Clippy clean,
rustfmt clean, Python 29 passed, polyglot lint clean.
2026-10-14 06:05:10 +01:00
Nick e383331f05 chore(store): close drift_compression dichotomy contract BUILDER-2026-10-14T04:58:34Z-5fc73f-factory-gap-dcomp (parity d4640a7f, phase B 998c2adf) 2026-10-14 06:04:59 +01:00
Nick 224bcfe3e0 chore(store): close voice_hybrid dichotomy contract BUILDER-2026-10-14T04:46:10Z-415e82-factory-gap-vh (parity 833d7af4, phase B 6c1c4fea) 2026-10-14 06:04:32 +01:00
Nick 7c1d818b7a chore(factory): claims recovery — restored from last parseable version (b3342289), flood landings + wave-5 re-registered; corruption entered master via concurrent writes 2026-10-14 06:03:44 +01:00
Nick 7d26a1465b chore(factory): claims repair + wave-5 re-registration (concurrent-write corruption class: claims file needs file-lock discipline — noted as process debt) 2026-10-14 06:03:24 +01:00
Nick 37f2ae16b8 chore(store): claims file corruption repair (concurrent agent writes) — recovered from HEAD, wave-5 re-registered 2026-10-14 06:03:13 +01:00
Nick b3342289e3 chore(factory): wave-5 backfill — 13 lanes to restore the 20-floor (wait_guard_corpus requeued as data drift per divergence evidence) 2026-10-14 06:02:18 +01:00
Nick f32fd62838 chore(factory): claims recovery from concurrent-write corruption + parallel_processor/salience_gate claimed (both verified via ladder) 2026-10-14 06:00:37 +01:00
Nick 3c55605da3 chore(store): merge concurrent batch state (factory-gap-ee push round 2)
# Conflicts:
#	docs/dichotomy-rebase-honest-audit.md
#	store/scaffold/segments/observations.jsonl
2026-10-14 05:59:29 +01:00
Nick d8093e2c5d chore(store): close stage_guards dichotomy contract BUILDER-2026-10-14T04:10:26Z-284744-factory-gap-cz (parity 84162de4)
One-process walk: submit → approved → building → verifying →
iface.close(observed_evidence, scope_files) per the QUALITY-GATE LAW
(raw transition→closed refused). The 04:08:04Z duplicate from the
refused first attempt was abandoned with a note. Coverage 7/9 → 9/9
FULL; evidence in verification/sg-*.{log,exit} + sg-summary.md.
2026-10-14 05:58:42 +01:00
Nick 546c11f547 chore(store): merge concurrent batch state (factory-gap-ee event_envelope + upstream drift_core/structural_model)
# Conflicts:
#	docs/dichotomy-rebase-honest-audit.md
#	store/scaffold/segments/observations.jsonl
2026-10-14 05:58:08 +01:00
Nick 998c2adf38 refactor(drift_compression): Phase B language-advantage pass — dichotomy wave
Behavior-identical (frozen battery 7/7 + live parity 1935/1935 re-run
green on this commit):
- compress_text: zero-copy prefix — char_indices().nth() finds the byte
  offset and slices &text[..cut]; the intermediate collected String is
  gone, the ellipsis path preallocates once.
- get_compression_ratio: exhaustive match dispatch — the rock-status tier
  is a closed set, the wash ladder is scoped inside the open arm.
- get_compression_stats: single-pass try_fold carrying both accumulators
  (Result-carrying — the first malformed row aborts with the oracle's
  exception message; no mutable accumulators).
2026-10-14 05:55:58 +01:00
Nick d4640a7f12 feat(drift_compression): close PARTIAL gaps — dichotomy wave
Audit 3/7 PARTIAL -> 7/7 FULL (RUST). The five pure kernels already lived
in src/rust/memory_scoring (H3 slice 2, d58e88da) but the audit alias
mapped the module to cognition_core — the instrument now follows the live
delegation chain (drift_compression -> drift_core._ms_core -> ms_loader ->
libmemory_scoring.so). New kernel work: get_compression_stats — SQL stays
in the Python facade (boundary law), the row-reduction math (int()
truncation after the float multiply, banker's rounding at 1e2, SQL-null
coercion, empty-store int-shaped 0) is a Rust kernel + ms_get_compression_stats
FFI + loader wrapper + oracle delegation with a load-bearing _py fallback.

Fix-first (proven by the new frozen battery): warn_before_compress emitted
the COERCED rock_status; the oracle emits the raw value — a present None
rides the warning dict as null (entry.get default only fires when the key
is absent).

Verification: frozen truth 65 cases via the shared harness, byte-identical
across repeated gen + freeze_truth --verify runs; cargo battery 7/7
(include_str! embed); clippy -D warnings + fmt clean; live parity 1935/1935
(pinned facade / live facade / kernel direct / db-level / fuzz seed 2479);
Python both pins green (seam file 7/7 both; shims failures pre-exist on
base); ruff clean. Evidence: verification/dc-*.log.
2026-10-14 05:55:58 +01:00
Nick c0073a5dcb refactor(structural_model): Phase B language-advantage pass — dichotomy wave
Behavior-identical Rust idiom upgrades over the parity commit:
- add() mutates the stored entity by index in ONE pass (was: three linear
  scans with a clone round-trip mirroring the Python object identity)
- beneath()/impact_closure() track visited nodes in BTreeSet (O(log n)
  membership instead of Vec::contains' O(n)); traversal and output order
  unchanged — the walks still emit insertion order and sort at the end
- scope_of unions through BTreeSet (the oracle's sorted-set semantics
  expressed as the set itself, not a contains-guarded Vec)
- merge_sorted_set is a genuine sorted set union (BTreeSet) matching
  Python's sorted(set(...) | set(...))

Gates re-run green: battery 16/16, clippy -D warnings clean, frozen truth
byte-identical, live parity 4620/4620, Python tests both pins.
2026-10-14 05:53:36 +01:00
Nick 00839d1af7 feat(structural_model): close PARTIAL gaps — dichotomy wave
Port the 11 audit-missing functions of src/rune/structural_model.py to the
Rust crate (name-preserving, logic-1:1): workspace_record, workspace_advance,
_init_project, save, reload, add, relate, state_owned,
verification_surfaces, canonical_state_owner, supersession — plus a true
deployment_surfaces (the old deployment_surfaces_for stub is gone, no
callers), the lowercase-stale filters on dependencies/consumers, and the
full §18F impact_closure shape the W6-era port had reduced.

Fix-first: the delegation seam imported rune.sm_loader — the SHARD_MANAGER
loader (no query symbol), so every kernel call died into the Python floor.
The seam now targets stm_loader (the crate's sm_* FFI, RUNE_STM_CORE=python
pins the floor). workspace_advance keeps the oracle's in-place law.

Verification (verification/structural_model-summary.md): frozen truth 70
cases byte-identical (gen_structural_model_truth.py --verify), battery 16/16
with truth embedded via include_str!, live parity 4620/4620 (frozen replay +
300-doc seeded fuzz + dual-mode facade), clippy -D warnings clean, Python
suites green in both pins (pre-existing 2F/12E verified identical on the
stashed base). Audit: 9/20 PARTIAL -> 21/21 FULL.
2026-10-14 05:53:36 +01:00
Nick 1a1ac0b516 chore(store): close drift_core dichotomy contract BUILDER-2026-10-14T04:45:57Z-42397f-factory-gap-dc (parity d77d1bce, phase B 558dd2cb) 2026-10-14 05:48:24 +01:00
Nick 9ee62d87b3 chore(store): close event_envelope dichotomy contract BUILDER-2026-10-14T04:22:42Z-8a4d5b-factory-gap-ee (parity fb1fd834)
Walked submit_need -> approved -> building -> verifying -> close()
(predicted-vs-observed quality gate) in the worktree process.
Evidence: verification/ee-*.exit + ee-summary.md — frozen-truth
83 cases byte-identical (freeze_truth --verify x2 under the
ee_freeze_seams rig), live parity 91/91 with a divergence-detecting
negative control, gofmt/vet/go build clean, Python suite 25+25 both
pins, ruff clean. Audit regenerated (event_envelope 8/8 FULL,
programme headline 98/192); factory-claims: event_envelope landed.
2026-10-14 05:44:23 +01:00
Nick 558dd2cbb0 refactor(drift_core): Phase B language-advantage pass — dichotomy wave
One generic py_round(x, digits) replaces the py_round2/py_round4 twins
(same round_ties_even-at-scale law, one definition), and fail_dict()
carries promote_entry's three failure shapes. Behavior unchanged:
battery 3/3, live parity 30+600+11 failures=0, clippy -D warnings 0.
2026-10-14 05:43:15 +01:00
Nick d77d1bce93 feat(drift_core): close PARTIAL gaps — dichotomy wave
Port the 8 audit-gap fns to Rust (name-preserving): _ms_core, _now_iso,
promote_entry, compute_fama, compute_drift_velocity, compute_drift_direction,
pre_commit_gate, pre_commit_gate_entry. The scoring surface delegates to
memory_scoring (path dep — the authoritative kernel since its Python oracle
was retired); the new decision kernels live in src/rust/drift_core while the
sqlite IO stays in the facade (RUNE_DRIFT_CORE pin, dcore_loader seam,
doc-envelope FFI, Python-typed JSON output: int/float split preserved).

Audit 3/11 PARTIAL -> 12/12 FULL RUST. 30-row frozen truth (dc_freeze_seams
rig, shared harness, gen+verify byte-identical x3), Rust battery 3/3 with the
truth embedded via include_str!, live parity 30 frozen + 600 fuzz + 11
dual-mode facade rows failures=0, clippy -D warnings 0, fmt clean, pytest
both pins 41 passed/4 skipped (drift-files test_211d_g failure verified
pre-existing on the stashed base), ruff clean.
2026-10-14 05:43:15 +01:00
Nick 6c1c4fea97 refactor(voice_hybrid): Phase B language-advantage pass — dichotomy wave
The duplicated exact-decimal readers behind round3/format_percent fold
into one Decimal6 struct (single {:.6} expansion + one banker's
round_up decision); the format_percent odd-kept-digit ladder
(end_with 1/3/5/7/9) becomes int parity. Behavior identical: battery
11 green, clippy -D warnings 0, live parity 1140/1140.
2026-10-14 05:36:16 +01:00
Nick 833d7af476 feat(voice_hybrid): close PARTIAL gaps — dichotomy wave
Name-preserving port of the 7 audit-missing functions (_relevance kernel,
source_profiles hit counting, blend composition, always baseline, grow
weight update, handle_hook envelope, main already matched) into
src/rust/voice_hybrid with IO behind injectable seams (ConnectSeam /
GrowthSeam / VhCoreSeam); 7 new FFI kernels (vh_relevance, vh_profiles,
vh_blend, vh_always, vh_grow, vh_handle_hook, vh_plugin) wired in
vh_loader with RUNE_VOICE_HYBRID_CORE=python pin discipline.

Frozen truth: src/rust/voice_hybrid/frozen_truth.json (19 rows, freeze
byte-identical + harness --verify 19/19 clean) + frozen_plugin.json;
battery src/rust/voice_hybrid/src/branch_battery.rs 11/11 green; live
parity failures=0 (frozen 25, fuzz 1104, live 11); clippy -D warnings
clean; Python both pins green (8/8 each). Audit: voice_hybrid 11/11 FULL.

Two documented divergences (integral-float FFI rendering; IO+probe stay
facade-side per the storage-backed precedent) — see verification/vh-summary.md.
2026-10-14 05:36:16 +01:00
Nick c997880ffc docs(verification): construction_mode gap-close evidence summary 2026-10-14 05:29:45 +01:00
Nick 1fee01b103 chore(store): close construction_mode dichotomy contract BUILDER-2026-10-14T04:41:12Z-9b2e6c-factory-gap-cm (parity 662dfa8a, phase B 870130cc)
Walked submit_need -> approved -> building -> verifying -> closed in ONE
process (scripts/walk_close_contract_construction_mode.py, CS_RUST_LIB
pointed at the built capability_scoring .so). capability_ledger updated by
the close's material-change record.
2026-10-14 05:26:53 +01:00
Nick fb1fd83466 feat(event_envelope): close PARTIAL gaps — dichotomy wave
Oracle src/rune/event_envelope.py 303 lines / 8 fns: 5/8 -> 8/8
per scripts/dichotomy_audit.py (name-preserving match). The three
audit-named gaps land as Go surface in src/go/event-bus: ToDict
(to_dict), ToCanonicalDict (to_canonical_dict, incl. the loud
RuntimeError branch for un-bridged envelopes), TestEnvelope
(test_envelope), plus the canonical-bridge classmethod CreateEnvelope
(EventEnvelope.create) they depend on: event_type follows the CHANNELS
prior vocabulary (tool -> tool_result) with the prior-or-channel-or-
source-or-unknown fallback chain.

Parity repairs found on the way (all oracle-pinned):
- classifyAuthority/classifyUrgency were word-splitting: bare 'stop'
  hit the amendment list (oracle: 'stop doing' is the multi-word
  entry; 'Stop everything!' is emergency), 'stop,' and 'unstoppable'
  misfired, and the low-urgency list matched 'when'/'you'/'can'/'no'/
  'rush' as single words (oracle: 'when you can'/'no rush'; bare
  'when' stays normal). Now \b<word>\b semantics with Unicode word
  chars ('stopé' never matches).
- pyQuoteEvent had no ensure_ascii: unicode payloads hashed with raw
  UTF-8 where the oracle hashes \uXXXX escapes — payload_hash
  diverged on every unicode payload.
- createEnvelope now derives text from payload["text"] (oracle
  signature; CLI folds --text in).
- minted ids/timestamps go through the no-clock/no-random seams
  (EE_FROZEN_NOW + per-op uuid counter) — replayable under pins,
  random uuid4-shaped ids in production.

Truth: scripts/gen_event_envelope_truth.py under the
scripts/ee_freeze_seams sitecustomize rig via the shared freeze_truth
harness (83-case envelope, frozen clock + deterministic uuid counter);
byte-identical across regens and freeze_truth --verify x2; embedded
VERBATIM in truth_envelope_test.go TestFrozenEnvelopeTruthReplay +
seam units (\b matcher, ensure_ascii escaping, event_type fallbacks,
loud bridge failure). Live parity 91/91 (scripts/
check_event_envelope_parity.py, PYTHON-json byte compare; negative
control detects divergence). gofmt/vet/go build clean; Python suite
green both pins (25 live + 25 RUNE_*_CORE=python). Dichotomy audit
5/8 PARTIAL -> 8/8 FULL.
2026-10-14 05:20:27 +01:00
Nick 870130ccc3 refactor(construction_mode): Phase B language-advantage pass — dichotomy wave
Real language advantages over the Python oracle, battery output
byte-stable (frozen corpus green, live parity 100% re-verified):

* Mode enum — the five construction modes as a closed set; the decision
  tree carries Mode values and the compiler proves the wire mapping
  exhaustive (as_str). A mistyped mode name is now a build error, not a
  silent wrong-string bug.
* matches!-based escalation guard — the affected-surface escalation
  reads as a closed-set membership test instead of three string compares.
* Zero-copy _contains_any — hits borrow the 'static lexicon
  (Vec<&'static str>) instead of allocating an owned String per phrase;
  the lowering happens once inside the fn, mirroring the oracle's
  signature (construction_mode.py:194-196).
* py_repr_list over borrowed &[&str] — evidence lines format without an
  owned-string intermediate (surface lists build a borrowed view).

cargo test --release 5/5, clippy --all-targets -D warnings clean,
check_construction_mode_parity.py 100% (92 comparisons),
freeze_truth --verify byte-identical (39 cases).
2026-10-14 05:09:26 +01:00
Nick 662dfa8af1 feat(construction_mode): close PARTIAL gaps — dichotomy wave
Oracle src/rune/construction_mode.py 412 lines / 5 fns: 2/5 -> 5/5 per
scripts/dichotomy_audit.py (name-preserving match). The three audit-named
gaps land as ported Rust functions: ConstructionMode::to_dict (the ten-key
projection in the oracle's insertion order, construction_mode.py:155-167),
ConstructionMode::from_dict (known-keys-only + dataclass defaults, mode
required — TypeError message carried on the err envelope,
construction_mode.py:169-187), and _contains_any (renamed to the oracle's
name; lowering moved inside to mirror the Python signature). classify_mode
now routes every return through the ported ConstructionMode struct.

PARITY BUGS FIXED WITH PROOF (frozen truth from the live oracle):
1. Early-return defaults law — the override/NOT_CONSTRUCTION/empty-objective
   branches left target_project/project_authority/proposed_by_model at
   their dataclass defaults in the oracle but leaked kwargs through in the
   port (construction_mode.py:249-259/276/279-286). Frozen cases
   'what is a chord' + target_project/model_proposal and '' + kwargs pin
   the None/None/None shape.
2. model_proposal falsy collapse — 'model_proposal if model_proposal else
   None' (construction_mode.py:400): empty dict now collapses to None.
3. Evidence list rendering — Rust {:?} emitted double quotes where Python
   repr emits single ('affected surface known: [\'module:deploy_stage\']');
   py_repr_list/py_repr_tuple reproduce the oracle's repr, including the
   MODES tuple in the invalid-override ValueError text.
4. Lexicon set-iteration order — the oracle's lexicons are Python sets, so
   multi-hit evidence order is hash-random per process (dichotomy quirk);
   truth is frozen under PYTHONHASHSEED=0 (generator re-execs itself,
   memory_consolidation precedent) and the Rust const arrays reproduce
   the seed-0 order.

COLLATERAL (fix-first): construction_decision's frozen truth was frozen
with RUNE_CM_CORE unpinned, so its construction_mode trace captured the
old divergent Rust output (double-quoted evidence). gen_construction_decision_truth.py
now pins RUNE_CM_CORE=python (transitive-core law) + the seed; truth
regenerated (11 evidence lines corrected), byte-identical verify green,
cd battery 18/18.

Truth: scripts/gen_construction_mode_truth.py via the shared freeze_truth.py
harness + rig scripts/cm_freeze_seams (pins RUNE_CM_CORE +
RUNE_CONSTRUCTION_DECISION_CORE for the file-scope branch's transitive
classify_surface import; binds the cm_classify_to_dict seam — classify_mode
returns a dataclass instance, the frozen contract is its to_dict projection).
39 harness cases (36 classify + 3 to_dict receivers) + 5 from_dict
projections + 3 error shapes in the battery envelope; freeze_truth --verify
byte-identical. Battery replays the corpus VERBATIM via include_str!
(frozen_cm_truth.json + frozen_cm_truth.verify.json pinned together by
envelope_cases_match_verify_file) with FULL structural equality.

FFI: cm_to_dict / cm_from_dict doc-envelope externs; cm_loader gains
to_dict/from_dict bindings. Live parity scripts/check_construction_mode_parity.py:
100% — 36 classify + 3 to_dict + 5 from_dict + 4 error shapes, rust == oracle
== frozen (92 comparisons; oracle side subprocessed under PYTHONHASHSEED=0).
clippy --all-targets -D warnings clean (construction_mode +
construction_decision + construction_interface). Python suite green in BOTH
pins (RUNE_CM_CORE=python and delegation live): 138 passed each.

Audit: construction_mode 5/5 FULL (85/192 modules at FULL).
2026-10-14 05:09:26 +01:00
Nick 84162de459 feat(stage_guards): close PARTIAL gaps — dichotomy wave
Port the 2 audit-missing fns name-preserving (StageContract.to_dict +
nested chk → (*StageContract).ToDict / chk) and bring every kernel to
oracle evidence-shape parity: exact key sets (no omitempty zero-drops),
Python True/False rationale rendering, numeric half-even idle_secs
(pyRound1, was %.1f string), stdout-only pattern search, rune-safe
[:100]/[-500:] truncation, crash-parity messages (IndexError/ENOENT/
NoneType, StageBlocked/ExitCanaryFailed list-repr, FileNotFoundError on
bad cwd), oracle TestExpectations defaults, Python == reconcile
semantics (True==1, want-null quirk, non-dict actual).

Truth: 40 harness cases (recv form for first-arg dataclasses) +
30 rig seam rows (callables/TestExpectations), byte-identical across
gen x2 and verify x2, embedded verbatim in the Go battery. Live parity
56/56. Kernel-vs-floor cross-check: frozen corpus fully stable; the
bool-vs-number reconcile divergence is documented and excluded by the
stability law. freeze_truth.py _out now recurses (list-of-dataclass
receiver attrs); backward-compat proven on witness truth. Audit:
7/9 -> 9/9 FULL (85/192 programme FULL).
2026-10-14 05:06:19 +01:00
Nick 0aa2021dcc chore(store): close builder_bridge_cli dichotomy contract BUILDER-2026-10-14T03:59:08Z-d2713f-factory-batch-i (parity abb60344, phase B 53ca1b60) 2026-10-14 05:02:42 +01:00
Nick 991f55e57f refactor(builder_bridge_cli): Phase B language-advantage pass — dichotomy wave
Allocation-flat render, measured and asserted: single-pass markdown
builder (no intermediate lines slice, no final Join), exact pre-sized
buffers (pyJSONEscapedLen for the escaped length; fmt-free hex escapes —
fmt.Fprintf allocates), branch-before-join argv path (one task-string
build per invocation). TestPhaseBRenderAllocs pins <=1 alloc per render;
frozen-truth replay stays byte-identical; live parity re-verified 13/13.
2026-10-14 05:02:13 +01:00
Nick d005f64f53 feat(builder_bridge_cli): port to FULL Go — dichotomy wave
The CLI shell (argv join/strip, --json consumed only at argv[1], the
always-trailing-newline print quirk, Python json.dumps byte-parity:
insertion order + ", "/": " separators + ensure_ascii) over the full
deterministic preflight chain — route authority mirrored from
src/go/adaptive-router (rrf cgo membrane, DeriveSufficiency,
ClassifyRoute), capsule render from src/go/builder-bridge. Reactive
seams excluded per event-wait precedent (memory retrieval, construction
projection — the oracle's own degrade paths; PL1 lessons empty by
design). Frozen truth 13 cases from the live oracle subprocess under
pinned seams (frozen clock via sitecustomize rig, empty memory/
construction stores, HOME isolation — the selector's shard sources read
a hardcoded ~/.config/opencode that ignores RUNE_* isolation); replay
byte-identical; live parity Go binary == Python oracle 13/13; go build/
vet/gofmt clean; rune's truncate is rune-safe (Python str[:n] law).
2026-10-14 05:02:13 +01:00
Nick 1003e56cad chore(store): close capability_broker dichotomy contract BUILDER-2026-10-13T16:01:25Z-9b9389-factory-gap-cb (feat 1a35b4ce, Phase B 2eb91c0e)
One-process walk building->verifying->closed with SHA evidence
(scripts/close_contract_gap_cb.py; verification/cb-close-walk.{log,exit}).
Module audit 10/19 PARTIAL -> 19/19 FULL; parity 468/468; freeze --verify
33 byte-identical; both-pins green; full-suite zero-delta vs master
baseline.
2026-10-14 04:56:08 +01:00
Nick 1203f23d02 chore(store): close contract BUILDER-2026-10-14T03:18:15Z-056c94-factory-gap-gm (parity 16b55694)
graph_memory gap-close: 2/9 PARTIAL -> 9/9 FULL (RUST); frozen truth 38
cases byte-identical, battery 2/2, live parity 1330/1330, clippy clean,
Python both pins green (pre-existing baselines unchanged on stashed
base). Evidence: verification/gm_*.{log,exit}.
2026-10-14 04:37:23 +01:00
Nick 56d30e0536 chore(store): close behavior dichotomy contract BUILDER-2026-10-14T03:20:23Z-934482-factory-gap-bh (parity d23000f3, phase B 4d324803) 2026-10-14 04:27:48 +01:00
conductor 6734bae4ea chore(release): auto-bump version to 0.303.0 — earned by # (minor: converged release (push-to-master bump))
deploy / deploy (push) Skipped
CI Pipeline / lint (push) Canceled after 0s
CI Pipeline / unit-tests (push) Canceled after 0s
CI Pipeline / go-surface (push) Canceled after 0s
CI Pipeline / rust-surface (push) Canceled after 0s
CI Pipeline / canary (push) Canceled after 0s
CI Pipeline / best-practices (push) Canceled after 0s
CI Pipeline / documentation (push) Canceled after 0s
CI Pipeline / type-check (push) Canceled after 0s
CI Pipeline / gitea-offline (push) Canceled after 0s
CI Pipeline / required-checks (push) Canceled after 0s
CI Pipeline / CI Pipeline / notify-event-bridge (push) Canceled after 0s
Promotion record: (unknown)
2026-10-14 04:24:51 +01:00
Nick a574ff0879 chore(store): minidoc/t21/adversarial contract entities for the 2026-10-13T22:59→10-14T00:14 sessions
Pairs with the journal catch-up and mini-doc projections (same
sessions; the cancelled-worktree store never got committed).
2026-10-14 04:24:32 +01:00
Nick 35a721b4c0 chore(store): mini-doc projections for the 2026-10-13T22:59→10-14T00:09 builder sessions
Companion artifacts of the journal catch-up (entities tracked, journal
committed); zero name-overlap with master's docs tree.
2026-10-14 04:24:32 +01:00
Nick 796162b09c chore(store): journal catch-up — minidoc builder sessions (append-only union)
Lines 2026-10-13T16:30→2026-10-14T00:09 from minidoc-test builder
sessions against this worktree's store; the later batch pairs with
already-tracked contract entities. Union law: both sides append,
content-dedup on merge.
2026-10-14 04:24:32 +01:00
Nick 2eb91c0e81 test(capability_broker): Phase B — full-ladder evidence green, parity instrument, connection_pool flag fix
Ladder results (evidence under verification/, Read-back per the
file-based evidence protocol; summary in cb-summary.md): battery 11/0;
freeze --verify 33 cases byte-identical (fixture-pinned standalone
re-verify + self-verifying regen); live parity 468/468 (frozen=33
fuzz=421 live=14) — LIVE PARITY 100% on the gap fns; clippy -D warnings
clean; adjacent Python 107/107 in BOTH pins (delegation live and
RUNE_CAPABILITY_BROKER_CORE=python); full suite both pins: failure set
ZERO-delta vs the master baseline (118 pre-existing).

Phase B language advantages proven by the battery-after-landing:
trait CbIo IO injection (deterministic mtime pins in-test), Result
error paths, exhaustive handle_hook match, zero-copy static tables,
in-process Rust-to-Rust cs kernel delegation in _py_score_card.

Fix-first with proof: test_connection_pool's evict-oldest flag read
raw temp-dir paths so any 'a' in the random tempdir name flipped it
(~17% isolated flake, sole live full-suite delta on first run);
normalized to basenames like the status comparison — 15/15 green
after, both full-suite deltas zero. 1e4598aa instrument class.
2026-10-14 04:24:32 +01:00
Nick 1a35b4ce2d feat(capability_broker): close PARTIAL gaps — dichotomy wave
Port the 10 audit-missing fns name-preserving into the existing Rust
crate (gap.rs): _native_tool_schemas, load_registry, _cards_are_stale,
load_cards, generate_card, build_cards, _cs_core, _py_score_card,
match_capabilities, handle_hook. Doc-envelope cb_* FFI entries (lib.rs,
cs_free_string stays with capability_scoring), ctypes loader bindings
(broker_loader.py), facade delegation under the
RUNE_CAPABILITY_BROKER_CORE=python pin (capability_broker.py), and a
cfg(test) battery (gap_battery.rs) replaying the shared freeze_truth.py
frozen corpus VERBATIM via include_str. synthesize_card capabilities list
pinned to the oracle law ([name]). Module audit 10/19 PARTIAL -> 19/19
FULL. Ladder evidence lands with the Phase B commit. Contract
BUILDER-2026-10-13T16:01:25Z-9b9389-factory-gap-cb.
2026-10-14 04:24:32 +01:00
Nick 3c3d881125 chore(store): close microkernel dichotomy contract BUILDER-2026-10-14T02:55:03Z-907bab-factory-gap-mk (parity b9b089fa, audit 60197993) 2026-10-14 04:21:18 +01:00
conductor 6847638f78 chore(release): auto-bump version to 0.302.0 — earned by # (minor: converged release (push-to-master bump))
deploy / deploy (push) Skipped
CI Pipeline / lint (push) Canceled after 0s
CI Pipeline / unit-tests (push) Canceled after 0s
CI Pipeline / go-surface (push) Canceled after 0s
CI Pipeline / rust-surface (push) Canceled after 0s
CI Pipeline / canary (push) Canceled after 0s
CI Pipeline / best-practices (push) Canceled after 0s
CI Pipeline / documentation (push) Canceled after 0s
CI Pipeline / type-check (push) Canceled after 0s
CI Pipeline / gitea-offline (push) Canceled after 0s
CI Pipeline / required-checks (push) Canceled after 0s
CI Pipeline / CI Pipeline / notify-event-bridge (push) Canceled after 0s
Promotion record: (unknown)
2026-10-14 04:09:03 +01:00
Nick 4d32480348 refactor(behavior): Phase B language-advantage pass — dichotomy wave
Collapse the gap-close duplication the audit-motivated first pass
left behind, no behavioral change:

* scope_pattern_matches/trigger_matches — the regex cores shared by
  the SQL-side predicates (correction_matches/habit_matches) and the
  Python-pin twins (_correction_matches_python/_habit_matches_python);
  four inline regex blocks → two cores + four delegations.
* ItemKind — the stringly item_type parsed once ("habit" explicit,
  everything else corrects, mirroring Outcome/HabitState/Correction-
  State); reinforce_plan matches exhaustively instead of comparing
  strings twice. not_found(kind, id) is the single envelope builder
  for the missing-row and undecodable-row branches.

Re-verified: battery 17/17 (full pre→final row replay verbatim),
clippy --all-targets -D warnings 0, release build OK, parity FROZEN
137/137 through the cdylib FFI + LIVE 14/14, pytest 7/7 both pins
(delegation live + RUNE_BEHAVIOR_CORE=python).
2026-10-14 04:08:47 +01:00
Nick d23000f3f1 feat(behavior): close PARTIAL gaps — dichotomy wave
Audit 6/14 → 14/14 FULL (missing fns _bh_core, connect,
_correction_matches_python, _habit_matches_python, _reinforce_rust,
_reinforce_python, list_items, behavior_stats). All ported
name-preserving into src/rust/behavior as REAL public fns, rows-in/
decisions-out — SQLite open/exec IO stays Python (no crate in this
repo links a sqlite driver; the memory_storage precedent):

* _bh_core() -> Option<BhCore> — the core probe, RUNE_BEHAVIOR_CORE=
  python pin honored (the in-process core has no load-failure branch).
* connect() -> ConnectSpec — path + WAL pragma + the 7 schema stmts
  VERBATIM as sqlite stores them on a fresh oracle connect.
* _correction_matches_python/_habit_matches_python — the inline
  Python-pin predicates over row structs.
* _reinforce_rust/_reinforce_python — both oracle halves as one
  fetch-row→math→write-back ReinforcePlan (result dict + UPDATE
  payload + activation-log row; ts an argument, no-clock law). The
  ep-shim's habitmath IS this crate's reinforce math — the battery
  replays both names and pins their coincidence.
* list_items — filters, ORDER BY confidence DESC (stable sort = the
  sqlite rowid-order tie law, pinned by a frozen tie case), LIMIT,
  item_type key law.
* behavior_stats — the five counters over row collections.

Row structs gain the stored columns (created_at/last_reinforced/
supersedes_id, decay_rate/last_activated) for verbatim row replay.
New FFI: bh_connect, bh_core_probe, bh_python_predicates,
bh_reinforce_plan, bh_list_items, bh_behavior_stats (doc-envelope
law, no free symbol).

Truth: gen_behavior_truth.py now pins the clock (RUNE_FROZEN_NOW →
freeze_truth._pin_clock over behavior.datetime) — every timestamp in
the corpus frozen, regeneration byte-identical x2; new sections:
pre-rows for all reinforce cases, 42+36-row predicate matrix, 5 full
list outputs, stats_full row dumps, connect schema (sqlite_master,
sqlite_% filtered), core_probe, tie pin. bh_pure_truth.json: 81-case
freeze_truth envelope corpus — freeze_truth --verify byte-identical.

Divergence documented (oracle behavior, not a bug): the ep kernel's
Num wire law renders integral confidences as JSON integers in RESULT
dicts ("confidence": 1) while sqlite REAL read-back renders 1.0 —
the plan applies the wire law to results, REAL floats to write-backs.

Battery: 17 tests — full pre→final row replay (timestamps verbatim),
schema verbatim, predicate matrix, list/stats verbatim, pure corpus.
clippy --all-targets -D warnings 0. Parity
scripts/check_behavior_parity.py: FROZEN 137/137 pure-fn replay
through the cdylib FFI + LIVE 14/14 facade-vs-pin. Python 7/7 both
pins (delegation live + RUNE_BEHAVIOR_CORE=python).
2026-10-14 04:08:47 +01:00
conductor d139560829 chore(release): auto-bump version to 0.301.0 — earned by # (minor: converged release (push-to-master bump))
deploy / deploy (push) Skipped
CI Pipeline / lint (push) Canceled after 0s
CI Pipeline / unit-tests (push) Canceled after 0s
CI Pipeline / go-surface (push) Canceled after 0s
CI Pipeline / rust-surface (push) Canceled after 0s
CI Pipeline / canary (push) Canceled after 0s
CI Pipeline / best-practices (push) Canceled after 0s
CI Pipeline / documentation (push) Canceled after 0s
CI Pipeline / type-check (push) Canceled after 0s
CI Pipeline / gitea-offline (push) Canceled after 0s
CI Pipeline / required-checks (push) Canceled after 0s
CI Pipeline / CI Pipeline / notify-event-bridge (push) Canceled after 0s
Promotion record: (unknown)
2026-10-14 04:05:48 +01:00
Nick 16b5569411 feat(graph_memory): close PARTIAL gaps to FULL Rust — dichotomy wave
Kernel port of the 6 audit-gap fns (now_iso, connect, resolve_entity,
add_edge, query, stats) + handle_hook into src/rust/graph_memory (was a
W6 stub): the write-time gating (gm_strength_to_conf — exact float
semantics incl. the 3.5->0.8200000000000001 artifact, unlike the Go
twin's 2-decimal rounding), pred vocabulary gate (gm_normalize_pred),
node-type fallback (gm_node_type), duplicate-vs-supersede decision
(gm_supersede), 400-char evidence cap (gm_trim_evidence), query-fact
projection (gm_query_fact), stats top-8 projection (gm_stats), hook
contract (gm_handle_hook). SQLite IO stays Python (every oracle fn
takes a live db handle); the facade (graph_memory.py) delegates the
decisions through gm_loader with RUNE_GRAPH_MEMORY_CORE=python pin
honor; the probe is _core (machinery-excluded).

Truth: frozen_truth.json 38 cases (scripts/gen_graph_memory_truth.py
under scripts/gm_freeze_seams — wiped-per-process hermetic store,
RUNE_MEMORY_DIR pin, envelope clock) — byte-identical across
generation and two --verify runs. Rust battery 2/2 with the truth
embedded via include_str! (scripted store mirrors the SQL semantics
row for row: OR-IGNORE aliases, sqlite_sequence in the connect shape).

Live parity 1330/1330 (15 frozen FFI rows + 1310 fuzz checks over 60
seeded op-sequences dual-mode python-pin vs live core + 5 live
supersession-chain checks). clippy --all-targets -D warnings 0.
Python suite both pins: test_graph_health+test_graph_projection
7 passed + 1 pre-existing worktree-only failure (store cache
current.json missing — verified identical on stashed base);
test_p1_03 baseline 23 pre-existing failures identical on stashed
base (zero regressions). ruff clean.

Audit: graph_memory 2/9 PARTIAL -> 9/9 FULL (RUST); headline
FULL 43% (83/192), fn 64% (1447/2278).

Evidence: verification/gm_*.{log,exit} (all exit 0 except the two
pre-existing pytest baselines).
2026-10-14 04:03:51 +01:00
Nick c441a536bb chore(store): close cache dichotomy contract BUILDER-2026-10-14T02:10:49Z-4ef2c5-factory-gap-ca (parity f944d7df, phase B e0fd1440) 2026-10-14 03:50:37 +01:00
Nick 666e9a84a9 chore(store): close cron_engine dichotomy contract BUILDER-2026-10-14T01:32:43Z-61be7a-factory-gap-ce (parity 4204667f, phase B folded)
Walked submit→approved→building→verifying in one process, closed via the
contract_quality evidence path (port_evidence: 27/27 FULL audit, 46-case
byte-identical frozen truth + regen, gap replay 46/46, legacy 25/25, live
parity 3/3, CLI byte-identical both pins; verification/ce-*).
2026-10-14 03:45:22 +01:00
Nick 57eeeedd62 chore(store): close provider_registry dichotomy contract BUILDER-2026-10-14T01:46:46Z-a51bd5-factory-gap-pr (parity 3d21fe3d, phase B b0d7380f) 2026-10-14 03:14:53 +01:00
Nick 1099deed2f chore(store): close parallel_processor dichotomy contract BUILDER-2026-10-14T01:15:08Z-089711-factory-gap-pp (parity 621b9023)
Walk note: the first one-process walk parked at verifying — the closed
transition now REQUIRES contract_quality evidence (quality gate; mp
precedent walk_contract_model_profiles_gap.py). Resumed with
iface.close(observed_evidence=port_evidence, scope_files=...) on the
same contract id; FINAL PHASE closed.
2026-10-14 03:06:43 +01:00
conductor a6b29c7823 chore(release): auto-bump version to 0.300.0 — earned by # (minor: converged release (push-to-master bump))
deploy / deploy (push) Skipped
CI Pipeline / lint (push) Canceled after 0s
CI Pipeline / unit-tests (push) Canceled after 0s
CI Pipeline / go-surface (push) Canceled after 0s
CI Pipeline / rust-surface (push) Canceled after 0s
CI Pipeline / canary (push) Canceled after 0s
CI Pipeline / best-practices (push) Canceled after 0s
CI Pipeline / documentation (push) Canceled after 0s
CI Pipeline / type-check (push) Canceled after 0s
CI Pipeline / gitea-offline (push) Canceled after 0s
CI Pipeline / required-checks (push) Canceled after 0s
CI Pipeline / CI Pipeline / notify-event-bridge (push) Canceled after 0s
Promotion record: (unknown)
2026-10-14 03:02:05 +01:00
Nick e0fd14409e refactor(cache): Phase B language-advantage pass — dichotomy wave
One pooled *sql.DB per Env (lazily created, schema verified once — the
oracle re-ran the PRAGMA/DDL block on every call; identical observable
behavior since IF NOT EXISTS is idempotent and WAL persists in the
file). ContentHash hex-encodes only the 8 bytes it returns; Compress
builds via strings.Builder. Benchmarks added (hash 140ns/op, compress
6.5µs, recordHit 0.9µs, getCache-hit 23.7µs, putCache 42.6µs).

Full ladder re-run after the rewrite: frozen battery green, gofmt/vet/
build clean, live parity 100% (16/16), freeze --verify 78/78, Python
battery 12 passed both pins.
2026-10-14 02:59:43 +01:00
Nick f944d7df38 feat(cache): close PARTIAL gaps — dichotomy wave
Port the eleven audit-named missing fns name-preserving 1:1 from
src/rune/cache.py (recordHit/_record_hit, recordMiss, flushStats,
getCache, putCache, invalidateScope, invalidateAll, nowTs, parseTs,
cacheStats, handleHook) with the in-memory hit/miss accumulation
(threshold 50 / interval 30s), INVALIDATION_MAP, full schema (both
indexes) and an oracle-byte-parity CLI (usage gates, --json indent=2,
rune-aware :20 padding and [:200] truncation, compact hook line,
PLUGIN manifest). Clock/monotonic/DB behind Env seams.

Frozen truth: 78 cases via the shared freeze_truth.py harness
(envelope, pinned clock, sandboxed RUNE_MEMORY_DIR), byte-identical
regen + --verify green. Go battery replays verbatim + flush-branch
seam pins + 16-case CLI live parity (100%). Python oracle battery 12
passed BOTH pins. Audit: cache 6/17 -> 17/17 FULL (GO).
2026-10-14 02:59:43 +01:00
conductor e9a25cd6cf chore(release): auto-bump version to 0.299.1 — earned by # (patch: converged release (push-to-master bump))
deploy / deploy (push) Skipped
CI Pipeline / lint (push) Canceled after 0s
CI Pipeline / unit-tests (push) Canceled after 0s
CI Pipeline / go-surface (push) Canceled after 0s
CI Pipeline / rust-surface (push) Canceled after 0s
CI Pipeline / canary (push) Canceled after 0s
CI Pipeline / best-practices (push) Canceled after 0s
CI Pipeline / documentation (push) Canceled after 0s
CI Pipeline / type-check (push) Canceled after 0s
CI Pipeline / gitea-offline (push) Canceled after 0s
CI Pipeline / required-checks (push) Canceled after 0s
CI Pipeline / CI Pipeline / notify-event-bridge (push) Canceled after 0s
Promotion record: (unknown)
2026-10-14 02:44:52 +01:00
Nick 802015376f chore(store): close evidence_capsule dichotomy contract BUILDER-2026-10-14T01:26:52Z-fadf97-factory-batch-i (parity db06ee46, phase B 7885e057, truth-fix b4ae305e) 2026-10-14 02:42:48 +01:00
Nick 6e5b69a657 fix(evidence_capsule): harness-compliant frozen truth — shared freeze_truth --verify green
The prior freeze packed kwargs into the per-case 'args' field, which the
shared harness's --verify replays as positional args (fn(*list(dict))) —
MISMATCH despite a correct port. Regenerate via the shared harness
(kwargs convention + envelope, fixed frozen_now), battery reads kwargs.
Layer-3 law now passes: --verify reports 16 cases byte-identical.
2026-10-14 02:42:48 +01:00
conductor 85f4f3ca5e chore(release): auto-bump version to 0.299.0 — earned by # (minor: converged release (push-to-master bump))
deploy / deploy (push) Skipped
CI Pipeline / lint (push) Canceled after 0s
CI Pipeline / unit-tests (push) Canceled after 0s
CI Pipeline / go-surface (push) Canceled after 0s
CI Pipeline / rust-surface (push) Canceled after 0s
CI Pipeline / canary (push) Canceled after 0s
CI Pipeline / best-practices (push) Canceled after 0s
CI Pipeline / documentation (push) Canceled after 0s
CI Pipeline / type-check (push) Canceled after 0s
CI Pipeline / gitea-offline (push) Canceled after 0s
CI Pipeline / required-checks (push) Canceled after 0s
CI Pipeline / CI Pipeline / notify-event-bridge (push) Canceled after 0s
Promotion record: (unknown)
2026-10-14 02:39:22 +01:00
Nick b0d7380fb5 refactor(provider_registry): Phase B language-advantage pass — dichotomy wave 2026-10-14 02:38:57 +01:00
Nick 3d21fe3dac feat(provider_registry): close PARTIAL gaps — dichotomy wave 2026-10-14 02:38:57 +01:00
conductor 257bf77f91 chore(release): auto-bump version to 0.298.0 — earned by # (minor: converged release (push-to-master bump))
deploy / deploy (push) Skipped
CI Pipeline / lint (push) Canceled after 0s
CI Pipeline / unit-tests (push) Canceled after 0s
CI Pipeline / go-surface (push) Canceled after 0s
CI Pipeline / rust-surface (push) Canceled after 0s
CI Pipeline / canary (push) Canceled after 0s
CI Pipeline / best-practices (push) Canceled after 0s
CI Pipeline / documentation (push) Canceled after 0s
CI Pipeline / type-check (push) Canceled after 0s
CI Pipeline / gitea-offline (push) Canceled after 0s
CI Pipeline / required-checks (push) Canceled after 0s
CI Pipeline / CI Pipeline / notify-event-bridge (push) Canceled after 0s
Promotion record: (unknown)
2026-10-14 02:30:46 +01:00
Nick 60197993e5 chore(dichotomy): regenerate audit — microkernel FULL (82->83 modules) 2026-10-14 02:30:29 +01:00
Nick b9b089fa49 feat(microkernel): close PARTIAL gaps — dichotomy wave
Name-preserving port of the 6 unmatched fns into src/go/microkernel:
NowIso (+clock seam), ExtractManifest (brace-counted PLUGIN block +
literal_eval-subset parser), Discover, RunHook (subprocess hook runner),
LoadRegistry/SaveRegistry (renamed; corrupt-file full-default parity),
plus Fire wiring the CLI fire case to real 8-way parallel dispatch with
the bounded fire-log. Register now honors Python truthiness for hook
values (string targets index) and plumbs _file into entries.

Frozen truth: 25-case envelope via the shared harness (regen-stable,
--verify byte-identical x2); Go battery 25/25 subtests, -race clean;
live oracle-vs-Go parity 24/24 (scripts/check_microkernel_parity.py);
gofmt/vet/go build ./... clean; Python both-pins green for the module
(18 test_p1_01 failures proven pre-existing on stashed base).
Audit: microkernel 6/12 PARTIAL -> 12/12 FULL (evidence:
verification/summary-microkernel.md + microkernel-*.exit).
2026-10-14 02:30:29 +01:00
Nick 49ba669fa6 chore(factory): salience_gate landed (verified 9/0 on synced tree; agent's 3 parity defects fixed via frozen truth; quality-gate law live-tested) + salience_gate lane backfilled 2026-10-14 02:29:00 +01:00
Nick 593cddba5d chore(store): archive conflict resolution (ours) 2026-10-14 02:28:40 +01:00
Nick d2fd546aa0 chore(store): close salience_gate dichotomy contract BUILDER-2026-10-14T01:24:10Z-2a26ea-factory-gap-sg (parity 07096f2c, phase B 3d158800) 2026-10-14 02:27:25 +01:00
conductor 4475fed547 chore(release): auto-bump version to 0.297.0 — earned by # (minor: converged release (push-to-master bump))
deploy / deploy (push) Skipped
CI Pipeline / lint (push) Canceled after 0s
CI Pipeline / unit-tests (push) Canceled after 0s
CI Pipeline / go-surface (push) Canceled after 0s
CI Pipeline / rust-surface (push) Canceled after 0s
CI Pipeline / canary (push) Canceled after 0s
CI Pipeline / best-practices (push) Canceled after 0s
CI Pipeline / documentation (push) Canceled after 0s
CI Pipeline / type-check (push) Canceled after 0s
CI Pipeline / gitea-offline (push) Canceled after 0s
CI Pipeline / required-checks (push) Canceled after 0s
CI Pipeline / CI Pipeline / notify-event-bridge (push) Canceled after 0s
Promotion record: (unknown)
2026-10-14 02:24:13 +01:00
Nick 3d158800c7 refactor(salience_gate): Phase B language-advantage pass — dichotomy wave
Genuine Rust-side advantages over the Python oracle shape (parity pinned
by the frozen battery — 12/12, replay 119/119, shared verify
byte-identical):
  * lower_for_match: ASCII-anchored Cow — already-lowercase gate texts (the
    common case) match with ZERO allocation; non-ASCII/uppercase takes the
    full Python-parity to_lowercase() path so Unicode case mappings (İ, ẛ)
    are never skipped (borrow predicate is ASCII-only BY CONSTRUCTION).
  * std-only hot-path bench in branch_battery: evaluate_decision over the
    56-envelope frozen corpus + word_boundary_contains micro (evidence:
    verification/salience-gate-phaseb-cargotest.log).
  * #[must_use] on the pure surface (evaluate_decision, evaluate_salience,
    evaluate_salience_dict, to_dict, handle_hook, _sg_core).
  * iterator any() family scans with single-append semantics matching the
    oracle's one-condition-per-family guards (feat fix, made idiomatic).
2026-10-14 02:23:49 +01:00
Nick 07096f2c59 feat(salience_gate): close PARTIAL gaps — dichotomy wave
Name-preserving port of the 4 audit-missing functions into
src/rust/salience_gate (the module's existing delegation side; there is
no Go salience-gate dir):
  _sg_core      -> kernel mirror of the facade availability probe (pin
                   lattice, Some <=> probe answered, None <=> python pin)
  to_dict       -> SalienceDecision struct + to_dict projection
                   (evaluate_salience now flows through it)
  handle_hook   -> plugin hook handler (event echo, data accepted+ignored)
  test_salience -> embedded oracle smoke test, print-byte-matched
plus a module-level evaluate_salience_dict JSON view in the oracle (the
shared freeze harness cannot serialize the dataclass return —
construction_decision's normalize_need_json precedent; audited 5/6 -> 6/6).

Defect fixes found by parity (frozen-truth battery caught all three):
  1. novel family: oracle guards ONE if (any(new/never) or first time/
     haven't) — previous port appended a second NOVEL flag for the regex
     arm, inflating len(flags) and flipping the witness rule.
  2. failure family: oracle guards ONE if including the 'doesn't work |
     not working' regex arm — previous port omitted that arm entirely.
  3. word_boundary_contains: Python \b is unicode/underscore-aware;
     previous is_ascii_alphanumeric boundary matched new_thing/a_new/
     man-new — now alphanumeric + '_' + UTF-8 continuation bytes.

Frozen truth (poisoned-truth law: RUNE_SALIENCE_CORE=python via the
generator + SG_RUST_LIB poisoned — the module's real floor pins):
  frozen_sg_truth.verify.json — 52 harness rows, byte-identical under
  freeze_truth.py --verify in BOTH core states; frozen_sg_truth.json —
  63-row envelope (multi-family evaluation-order rows + _sg_core row;
  the shared gate's RUNE_SALIENCE_GATE_CORE pin can never reach this
  oracle). Battery branch_battery.rs replays both verbatim
  (include_str); gen --replay: facade live 119/119 + kernel exact
  (eval order). canary 6/6; oracle smoke green in 3 pin states.
2026-10-14 02:23:49 +01:00
conductor b4315878e4 chore(release): auto-bump version to 0.296.0 — earned by # (minor: converged release (push-to-master bump))
deploy / deploy (push) Skipped
CI Pipeline / lint (push) Canceled after 0s
CI Pipeline / unit-tests (push) Canceled after 0s
CI Pipeline / go-surface (push) Canceled after 0s
CI Pipeline / rust-surface (push) Canceled after 0s
CI Pipeline / canary (push) Canceled after 0s
CI Pipeline / best-practices (push) Canceled after 0s
CI Pipeline / documentation (push) Canceled after 0s
CI Pipeline / type-check (push) Canceled after 0s
CI Pipeline / gitea-offline (push) Canceled after 0s
CI Pipeline / required-checks (push) Canceled after 0s
CI Pipeline / CI Pipeline / notify-event-bridge (push) Canceled after 0s
Promotion record: (unknown)
2026-10-14 02:14:49 +01:00
Nick 4204667f0a feat(cron_engine): close PARTIAL gaps — dichotomy wave
Name-preserving GO port of the 14 audit-missing fns (to_dict, run_task
method+module, fire_on_task_complete, start/stop, _run_loop, _execute_task,
_log_execution/_log_error with 5MB rotation, get_cron_engine singleton family;
_parse_cron_field/_should_run carried as mirror-commented parseCronField/
shouldRun) + Python-exact ordered _save/_load (insertion order, ensure_ascii,
CronTask(**data) TypeError semantics), shlex.split port with oracle ValueError
messages, isoformat/pyISO parity, subprocess error-message translation
(FileNotFoundError/PermissionError/TimeoutExpired str(e) forms, ExitError →
returncode value). Phase B folded: injectable clock/sleep/exec/recordFailure
seams, ordered-JSON truth decoding, snapshot to_dict (no live aliasing).

Truth: 46-case truth_gap.json via the shared harness + wrapper shims
(frozen clock, hermetic <CE_HOME> rows, stopper-time _run_loop, neutralized
record_failure) — --verify byte-identical, fresh re-freeze byte-identical.
Battery: legacy replay 25/25, gap replay 46/46, 5 tests green, gofmt/vet/
build clean. Live parity 3/3 scenarios (31 ops) oracle-vs-GO identical;
CLI byte-identical both pins. Audit: cron_engine 27/27 FULL (83/192).
CI cron-engine gate extended (replay-gap + TestGapParity). Evidence:
verification/ce-*.
2026-10-14 02:14:01 +01:00
Nick 9acfb73645 chore(factory): model_profiles landed (close bf2f3f0a verified 8/0, 143/143 parity); cp worktree freed 2026-10-14 02:05:22 +01:00
conductor a691a701d5 chore(release): auto-bump version to 0.295.0 — earned by # (minor: converged release (push-to-master bump))
deploy / deploy (push) Skipped
CI Pipeline / lint (push) Canceled after 0s
CI Pipeline / unit-tests (push) Canceled after 0s
CI Pipeline / go-surface (push) Canceled after 0s
CI Pipeline / rust-surface (push) Canceled after 0s
CI Pipeline / canary (push) Canceled after 0s
CI Pipeline / best-practices (push) Canceled after 0s
CI Pipeline / documentation (push) Canceled after 0s
CI Pipeline / type-check (push) Canceled after 0s
CI Pipeline / gitea-offline (push) Canceled after 0s
CI Pipeline / required-checks (push) Canceled after 0s
CI Pipeline / CI Pipeline / notify-event-bridge (push) Canceled after 0s
Promotion record: (unknown)
2026-10-14 01:57:08 +01:00
Nick bf2f3f0a25 chore(store): close model_profiles dichotomy contract BUILDER-2026-10-13T23:56:33Z-c011dd-factory-gap-mp (parity 1ca647e4) 2026-10-14 01:54:38 +01:00
Nick 59ff243cc1 feat(model_profiles): close PARTIAL gaps — dichotomy wave
Oracle src/rune/model_profiles.py 438 lines / 15 fns: 5/15 -> 15/15
per scripts/dichotomy_audit.py (name-preserving match). The ten
audit-named gaps land as Go functions: getProfilePath, loadProfile
(suppressed-exception floor + unknown-key filtering), saveProfile
(Python-shaped JSON writer), buildProfileFromOllama (knowledge merge +
uncensored tier + injected clock), scanAllModels (Ollama sweep with
banker's rounding + learned-data preservation), getOrCreateProfile,
recordInteraction (learning accumulator), getPromptContext (operator
string assembly), to_dict/from_dict (the dataclass lens via
profileFromMap), plus the stdin-op serve CLI over the same code paths.

Freeze rig scripts/mp_freeze_seams (HOME pinned before the oracle
import, per-case hermetic store wipe+seed, canned Ollama server,
frozen clock via the harness envelope): 36-case frozen truth
regenerates byte-identical across runs; freeze_truth --verify OK
against the live oracle. Battery 36/36 replay VERBATIM from the
embedded truth (gen_mp_battery.py generator). Parity
scripts/check_model_profiles_parity.py 143/143 LIVE (detection
surface, sanitization matrix, lens, build assembly, record sequences,
prompt contexts, save byte-parity, scan sweep incl. dead-port
degrade). gofmt+vet+build clean, pytest 31/31 both pins.

Divergences (documented, not bugs): non-string profile names are
accepted by the oracle dataclass but rejected by the typed port
(local_tool_runtime precedent); integral-float rendering is
canonicalized in the sweep (context_broker precedent) while the
frozen save_profile rows pin the file writer byte-exact.
2026-10-14 01:54:38 +01:00
conductor 537c65b10d chore(release): auto-bump version to 0.294.0 — earned by # (minor: converged release (push-to-master bump))
deploy / deploy (push) Skipped
CI Pipeline / lint (push) Canceled after 0s
CI Pipeline / unit-tests (push) Canceled after 0s
CI Pipeline / go-surface (push) Canceled after 0s
CI Pipeline / rust-surface (push) Canceled after 0s
CI Pipeline / canary (push) Canceled after 0s
CI Pipeline / best-practices (push) Canceled after 0s
CI Pipeline / documentation (push) Canceled after 0s
CI Pipeline / type-check (push) Canceled after 0s
CI Pipeline / gitea-offline (push) Canceled after 0s
CI Pipeline / required-checks (push) Canceled after 0s
CI Pipeline / CI Pipeline / notify-event-bridge (push) Canceled after 0s
Promotion record: (unknown)
2026-10-14 01:53:15 +01:00
Nick 621b90236d feat(parallel_processor): close PARTIAL gaps — dichotomy wave
Oracle src/rune/parallel_processor.py 194 lines / 14 fns: 3/14 -> 14/14
per scripts/dichotomy_audit.py (name-preserving match). The 11
audit-named gaps land as ported Go functions in src/go/parallel-processor:
RunParallelWithArgs, GetStatus, Shutdown, ShutdownProcessor
(_shutdown_processor), GetProcessor, TestParallel (with the nested
task_1/task_2/task_3 closures) — plus the class/module run_parallel and
get_status module delegates; the CLI now mirrors the oracle main()
(status/test/usage/unknown) alongside the pre-existing run and the new
replay/op gates. Logic 1:1 with the Python oracle (semaphore-bounded
goroutine pool, submission-order results, per-task error envelopes).

Oracle quirks preserved and frozen as truth rows: submit-after-shutdown
raises from the submit loop itself (port panics 'cannot schedule new
futures after shutdown' — crash parity), ParallelProcessor(0) raises
'max_workers must be greater than 0', non-callable tasks degrade to
Python-TYPE-NAME TypeError envelopes ('int'/'NoneType'/'dict' object is
not callable), with-args parse errors carry type(task).__name__ and
repr shapes (42, 'x', True, None, [1, 2]), non-seq args wrapped to a
single-arg tuple, non-dict kwargs reset to {}, len-0 list vs () tuple
distinction, pool_threads reported as the configured bound,
active_threads pinned (rig threading.active_count patch / Go
PP_ACTIVE_THREADS seam).

Truth: scripts/gen_parallel_processor_truth.py via the shared
freeze_truth.py harness (23-case envelope; kind/fn/value SPEC grammar so
callables ride JSON rows — rig builds real Python callables, battery
rebuilds Go specCallable tasks); freeze_truth --verify byte-identical
twice; truth.json embedded VERBATIM and replayed by the go test battery
(5/5) and the binary replay gate (PARITY OK 23/23). Live parity 19/19
(scripts/check_parallel_processor_parity.py: 15 op families + 4 CLI
checks). gofmt/vet/go build clean. Python oracle smoke green both pins
(module has no loader seam; the byte-identity gate replays the live
oracle itself). Audit 3/14 PARTIAL -> 14/14 FULL.
2026-10-14 01:52:53 +01:00
Nick a3045b0b75 chore(store): quality repairs + first reconciliation pass (0 stale — authorities healthy, machinery now exercised) 2026-10-14 01:11:24 +01:00
conductor 405dcc78e0 chore(release): auto-bump version to 0.293.2 — earned by # (patch: converged release (push-to-master bump))
deploy / deploy (push) Skipped
CI Pipeline / lint (push) Canceled after 0s
CI Pipeline / unit-tests (push) Canceled after 0s
CI Pipeline / go-surface (push) Canceled after 0s
CI Pipeline / rust-surface (push) Canceled after 0s
CI Pipeline / canary (push) Canceled after 0s
CI Pipeline / best-practices (push) Canceled after 0s
CI Pipeline / documentation (push) Canceled after 0s
CI Pipeline / type-check (push) Canceled after 0s
CI Pipeline / gitea-offline (push) Canceled after 0s
CI Pipeline / required-checks (push) Canceled after 0s
CI Pipeline / CI Pipeline / notify-event-bridge (push) Canceled after 0s
Promotion record: (unknown)
2026-10-14 01:09:30 +01:00
Nick 2597b58b88 fix(scaffold): quality-gate law — transition-to-closed refuses without contract_quality evidence + post-hoc quality for the two lapsed closes (hook_engine, adaptive_router) 2026-10-14 01:09:01 +01:00
conductor 49bd788442 chore(release): auto-bump version to 0.293.1 — earned by # (patch: converged release (push-to-master bump))
deploy / deploy (push) Skipped
CI Pipeline / lint (push) Canceled after 0s
CI Pipeline / unit-tests (push) Canceled after 0s
CI Pipeline / go-surface (push) Canceled after 0s
CI Pipeline / rust-surface (push) Canceled after 0s
CI Pipeline / canary (push) Canceled after 0s
CI Pipeline / best-practices (push) Canceled after 0s
CI Pipeline / documentation (push) Canceled after 0s
CI Pipeline / type-check (push) Canceled after 0s
CI Pipeline / gitea-offline (push) Canceled after 0s
CI Pipeline / required-checks (push) Canceled after 0s
CI Pipeline / CI Pipeline / notify-event-bridge (push) Canceled after 0s
Promotion record: (unknown)
2026-10-14 00:55:49 +01:00
Nick 7d20ef9b64 fix(scaffold): kernel-rebuild trap in close_contract — entity re-resolved after record_observed_impact
The Rust core's doc.clear()/update() semantics inside record_observed_impact
rebuild doc['entities'] with fresh objects; the previously captured entity
reference became an orphan, quality mutations silently vanished from the
store, and construction_interface.close() KeyError'd. Fires only where the
structural .so is built (coordinator checkouts, CI) — fresh worktrees took
the pure-Python path, which is why agents never saw it.

Includes the growth_pipeline salvage contract close (phase=closed, quality
persisted — proves the fix in production) + regression test.
2026-10-14 00:55:23 +01:00
Nick bc66b33ebf chore(factory): witness landed (9/0, 50039ed8); model_connect confirmed (claimed at watchdog); lanes backfilled — event_envelope/cy, stage_guards/cz 2026-10-14 00:00:49 +01:00
Nick 885f52ee22 chore(store): close witness dichotomy contract BUILDER-2026-10-13T22:30:08Z-fd6e49-factory-gap-wi (parity 50039ed8) 2026-10-13 23:40:05 +01:00
Nick cfb50b7576 chore(factory): watchdog C1 — model_connect claimed (close verified on master) 2026-10-13 23:39:22 +01:00
Nick 80249a0ac5 chore(factory): true-floor restoration — dead worktrees removed, 4 new lanes registered (construction_mode, layout_contract, builder_bridge, drift_compression) 2026-10-13 23:29:28 +01:00
conductor 69083f1970 chore(release): auto-bump version to 0.293.0 — earned by # (minor: converged release (push-to-master bump))
deploy / deploy (push) Skipped
CI Pipeline / lint (push) Canceled after 0s
CI Pipeline / unit-tests (push) Canceled after 0s
CI Pipeline / go-surface (push) Canceled after 0s
CI Pipeline / rust-surface (push) Canceled after 0s
CI Pipeline / canary (push) Canceled after 0s
CI Pipeline / best-practices (push) Canceled after 0s
CI Pipeline / documentation (push) Canceled after 0s
CI Pipeline / type-check (push) Canceled after 0s
CI Pipeline / gitea-offline (push) Canceled after 0s
CI Pipeline / required-checks (push) Canceled after 0s
CI Pipeline / CI Pipeline / notify-event-bridge (push) Canceled after 0s
Promotion record: (unknown)
2026-10-13 23:22:45 +01:00
Nick 50039ed83b feat(witness): close PARTIAL gaps — dichotomy wave 2026-10-13 23:22:01 +01:00
Nick 28f5ed5ee1 chore(store): close model_connect dichotomy contract BUILDER-2026-10-13T22:11:49Z-3df478-factory-gap-mconn (parity 290ed734) 2026-10-13 23:21:08 +01:00
conductor 2bc95aca8d chore(release): auto-bump version to 0.292.0 — earned by # (minor: converged release (push-to-master bump))
deploy / deploy (push) Skipped
CI Pipeline / lint (push) Canceled after 0s
CI Pipeline / unit-tests (push) Canceled after 0s
CI Pipeline / go-surface (push) Canceled after 0s
CI Pipeline / rust-surface (push) Canceled after 0s
CI Pipeline / canary (push) Canceled after 0s
CI Pipeline / best-practices (push) Canceled after 0s
CI Pipeline / documentation (push) Canceled after 0s
CI Pipeline / type-check (push) Canceled after 0s
CI Pipeline / gitea-offline (push) Canceled after 0s
CI Pipeline / required-checks (push) Canceled after 0s
CI Pipeline / CI Pipeline / notify-event-bridge (push) Canceled after 0s
Promotion record: (unknown)
2026-10-13 23:09:21 +01:00
Nick 290ed7341e feat(model_connect): close PARTIAL gaps — dichotomy wave
Oracle src/rune/model_connect.py 471 lines / 11 fns: 7/11 -> 11/11 per
scripts/dichotomy_audit.py (name-preserving match). The four audit-named
gaps land as ported Go functions: CtxBudget (_ctx_budget — vendored
model_registry.resolve_context_budget num_ctx kernel with the live
oracle's constants), Now (_now — behind the injectable clock seam),
GetCloudModels (_get_cloud_models — ordered-JSON JSONC reader with the
oracle's naive quirks), HandleHook (handle_hook).

Oracle quirks preserved and frozen as truth rows: string-blind JSONC //
strip (URLs corrupt the parse -> []), trailing-comma strip, partial
cloud list on mid-provider shape errors (try/except wraps the whole
loop), insertion-order provider/model iteration (json.Decoder token
walk), null models dict -> items() raises, OUTPUT_RESERVE['default']/
TOOL_RESULT_RESERVE=2048/1024 from the live registry oracle.

Truth: scripts/gen_model_connect_truth.py via the shared freeze_truth.py
harness (40-case envelope, pinned clock 2026-10-14T08:00:00+00:00 +
pinned HOME via scripts/mconn_freeze_seams); freeze_truth --verify
byte-identical; truth.json embedded VERBATIM in truth_test.go
TestFrozenTruthReplay (3/3). Live parity 44/44
(scripts/check_model_connect_parity.py). gofmt/vet/go build clean.
Python oracle smoke green both pins (module has no loader seam; the
byte-identity gate replays the live oracle itself).
2026-10-13 23:09:01 +01:00
Nick 70f8775838 chore(factory): watchdog C2/C3 — capability_broker+provider_registry completed-uncommitted (resume agents 83/84 spawned); duplicate worktrees cg/ci removed; lanes backfilled (parallel_processor/cs, structural_model/ct) 2026-10-13 22:50:16 +01:00
Nick 060daaa44c chore(factory): claims — 22-close backfill (bookkeeping debt from session handover): all closes SHA-cited on master; memory_types+research_budget verified 10/0 and 9/0 at CURRENT standard; pre-7e closes grandfathered per retrofit doctrine (ratchet forward, not backward); duplicate-spawn corrected (token_optimizer/prompt_sync agents cancelled — closed 2d ago) 2026-10-13 22:12:24 +01:00
conductor 32533500ed chore(release): auto-bump version to 0.291.0 — earned by # (minor: converged release (push-to-master bump))
deploy / deploy (push) Skipped
CI Pipeline / lint (push) Canceled after 0s
CI Pipeline / unit-tests (push) Canceled after 0s
CI Pipeline / go-surface (push) Canceled after 0s
CI Pipeline / rust-surface (push) Canceled after 0s
CI Pipeline / canary (push) Canceled after 0s
CI Pipeline / best-practices (push) Canceled after 0s
CI Pipeline / documentation (push) Canceled after 0s
CI Pipeline / type-check (push) Canceled after 0s
CI Pipeline / gitea-offline (push) Canceled after 0s
CI Pipeline / required-checks (push) Canceled after 0s
CI Pipeline / CI Pipeline / notify-event-bridge (push) Canceled after 0s
Promotion record: (unknown)
2026-10-13 21:32:06 +01:00
Nick e34a3fb1cd feat(factory): live status script — one-command factory visibility 2026-10-13 21:31:43 +01:00
Nick 45598be00d chore(factory): claims — wave-4 registered (13 gap-closers); archive conflict resolved (ours — newest) 2026-10-13 20:34:26 +01:00
conductor d7412f0855 chore(release): auto-bump version to 0.290.2 — earned by # (patch: converged release (push-to-master bump))
deploy / deploy (push) Skipped
CI Pipeline / lint (push) Canceled after 0s
CI Pipeline / unit-tests (push) Canceled after 0s
CI Pipeline / go-surface (push) Canceled after 0s
CI Pipeline / rust-surface (push) Canceled after 0s
CI Pipeline / canary (push) Canceled after 0s
CI Pipeline / best-practices (push) Canceled after 0s
CI Pipeline / documentation (push) Canceled after 0s
CI Pipeline / type-check (push) Canceled after 0s
CI Pipeline / gitea-offline (push) Canceled after 0s
CI Pipeline / required-checks (push) Canceled after 0s
CI Pipeline / CI Pipeline / notify-event-bridge (push) Canceled after 0s
Promotion record: (unknown)
2026-10-13 20:08:56 +01:00
Nick b2adffbbbd chore(factory): claims — 11-landings batch verified (ladder 8-10 PASS each): safety_override, construction_decision, spine, elastic_cognition, construction_pattern, memory_selector, identity_anchors, contracts, construction_interface, adaptive_router, hook_engine; audit regenerated 2026-10-13 20:08:32 +01:00
Nick a1ecd59d10 fix(verify): 7b accepts replay-surface crates (same kernel-FFI evidence as 7a) 2026-10-13 20:08:32 +01:00
conductor 373891985e chore(release): auto-bump version to 0.290.1 — earned by # (patch: converged release (push-to-master bump))
deploy / deploy (push) Skipped
CI Pipeline / lint (push) Canceled after 0s
CI Pipeline / unit-tests (push) Canceled after 0s
CI Pipeline / go-surface (push) Canceled after 0s
CI Pipeline / rust-surface (push) Canceled after 0s
CI Pipeline / canary (push) Canceled after 0s
CI Pipeline / best-practices (push) Canceled after 0s
CI Pipeline / documentation (push) Canceled after 0s
CI Pipeline / type-check (push) Canceled after 0s
CI Pipeline / gitea-offline (push) Canceled after 0s
CI Pipeline / required-checks (push) Canceled after 0s
CI Pipeline / CI Pipeline / notify-event-bridge (push) Canceled after 0s
Promotion record: (unknown)
2026-10-13 20:07:56 +01:00
Nick 15aeb9a890 fix(verify): 7a accepts replay-surface crates (kernel FFI + truth battery, no loader by design — construction_interface's ci_replay shape) 2026-10-13 20:07:37 +01:00
Nick 0b7e89b4f5 chore(store): close construction_interface dichotomy contract BUILDER-2026-10-13T18:05:50Z-7c2bad-factory-gap-ci (parity 192c63b3, phase B 0569a2e5) 2026-10-13 19:08:17 +01:00
conductor 32c16c544d chore(release): auto-bump version to 0.290.0 — earned by # (minor: converged release (push-to-master bump))
deploy / deploy (push) Skipped
CI Pipeline / lint (push) Canceled after 0s
CI Pipeline / unit-tests (push) Canceled after 0s
CI Pipeline / go-surface (push) Canceled after 0s
CI Pipeline / rust-surface (push) Canceled after 0s
CI Pipeline / canary (push) Canceled after 0s
CI Pipeline / best-practices (push) Canceled after 0s
CI Pipeline / documentation (push) Canceled after 0s
CI Pipeline / type-check (push) Canceled after 0s
CI Pipeline / gitea-offline (push) Canceled after 0s
CI Pipeline / required-checks (push) Canceled after 0s
CI Pipeline / CI Pipeline / notify-event-bridge (push) Canceled after 0s
Promotion record: (unknown)
2026-10-13 19:05:23 +01:00
Nick 0569a2e599 refactor(construction_interface): Phase B language-advantage pass — dichotomy wave
kernel: contract_pos — the ONE contract locator (index by id) replaces
the four inline position scans (amend_scope x2, transition_doc,
close_contract); the position is unstable across normalize_sorted, so
callers re-find instead of caching — the helper's contract documents
that law. fail_envelope — the single-error failure shape every
contract-scoped operation shares (ids={contract_id}, empty state, one
error row) collapses eight inline projection::envelope blocks
(unknown_contract, close not-found + wrong-phase, transition
unknown-phase + illegal-edge, report_observation validation x3).
contract_of now delegates to find_contract (one definition of
contract-by-id lookup).

No behavioral change: battery 25/25 green (85 verbatim + 5
shape-pinned), clippy --all-targets -D warnings 0, release build OK,
parity FROZEN 85/85 + LIVE re-freeze byte-identical.
2026-10-13 19:03:37 +01:00
Nick 192c63b36e feat(construction_interface): close PARTIAL gaps — dichotomy wave
Audit 25/27 → 27/27 FULL (main + _programme_continuation were the two
unmatched fns; the port carries the full envelope surface). Freeze rig
scripts/ci_freeze_seams/sitecustomize.py (PYTHONPATH auto-import, used by
BOTH generator and --verify): every RUNE_*_CORE gate pinned python for
the whole dependency cone, frozen clock on structural_store.now +
scaffold.now + capability_ledger._now + programme_continuation.time,
deterministic uuid mint (counter resets per rig helper), hermetic
per-case stores under CI_FREEZE_HOME (mini-doc paths replay
byte-identically), doc-carrying seam bindings for every stateful method.

Truth: 85-case frozen corpus + 5-case hash corpus (obligation ids carry
Python's process-randomized str hash — captured with PYTHONHASHSEED=0,
SHAPE-pinned downstream, the memory_consolidation law). Regeneration
byte-identical; freeze_truth --verify OK both corpora.

Rust kernels (src/rust/construction_interface): kernel.rs adds the
doc-in/doc-out halves of submit_need (need assembly + envelope over the
construction_decision make_decision kernel + contract generation twin),
verify (scope check + layout gate via the layout_contract kernel),
transition (guard canary over frozen command outcomes + legality map +
checkpoint/session assembly + normalize_sorted commit twin),
close (close_contract + observed-impact + close_quality bucket math +
contract_quality projection), _programme_continuation (load/save shape
twins + continuation canary), _auto_material_change (via the
capability_ledger op_material_change kernel), main (CLI dispatch + exit
law), ladder_walk (full ladder in ONE process); projection.rs the pure
helpers (to_stage_check, guard_specs, obligations projection with the
FNV-1a stand-in id, envelope with extra merge, _match).

Store-normalization law discovered: the oracle's commit path sorts
lists by canonical JSON (structural_store._sorted) — the kernel applies
the same normalization at its commit points or read-back projections
(patterns_considered) diverge.

Battery: 25 tests — the 85-case corpus replays VERBATIM through
kernel::dispatch, the 5 hash cases shape-pinned, gap-fns-are-real-ports
probe. clippy --all-targets -D warnings 0. Parity
scripts/check_construction_interface_parity.py: FROZEN layer 85/85 + 5
through the ci_replay ctypes FFI of the built cdylib; LIVE layer
fresh re-freeze byte-identical. Python 37/37 both pins (floors pinned
python + live cores).
2026-10-13 19:03:37 +01:00
Nick b433be3e33 docs(audit): contracts FULL 11/11 — honest audit refresh (81/192 FULL) 2026-10-13 18:58:48 +01:00
conductor 60eec844ed chore(release): auto-bump version to 0.289.0 — earned by # (minor: converged release (push-to-master bump))
deploy / deploy (push) Skipped
CI Pipeline / lint (push) Canceled after 0s
CI Pipeline / unit-tests (push) Canceled after 0s
CI Pipeline / go-surface (push) Canceled after 0s
CI Pipeline / rust-surface (push) Canceled after 0s
CI Pipeline / canary (push) Canceled after 0s
CI Pipeline / best-practices (push) Canceled after 0s
CI Pipeline / documentation (push) Canceled after 0s
CI Pipeline / type-check (push) Canceled after 0s
CI Pipeline / gitea-offline (push) Canceled after 0s
CI Pipeline / required-checks (push) Canceled after 0s
CI Pipeline / CI Pipeline / notify-event-bridge (push) Canceled after 0s
Promotion record: (unknown)
2026-10-13 18:57:55 +01:00
Nick 8f9835fb9b chore(store): close contracts dichotomy contract BUILDER-2026-10-13T17:54:28Z-10bd7d-factory-gap-ct (parity 11e4bd20)
gap-close 4/11 -> 11/11 (FULL): the 7 audit-missing fns (_ct_core,
_resolve_and_project, _run_contract_python, capture_signatures,
save_signatures, load_signatures, main as contracts_main) ported
name-preserving into src/rust/contracts with IO behind injectable
seams; 8 new doc-envelope FFI kernels via contracts_loader
(cs_free_string, never re-exported). Frozen truth ct_gap_truth.json
127 rows (harness --verify 23/23 byte-identical) embedded VERBATIM in
gap_battery; battery 19/19; live parity replay failures=0 (facade 30,
kernel 15); clippy -D warnings 0; fmt clean; pytest 6/6 both pins;
full-suite failure set byte-identical to base. One documented
eager/lazy divergence (projection-crash row) pinned both ways. Full
lifecycle walked in ONE process (approved->building->verifying->closed).
2026-10-13 18:57:28 +01:00
Nick 11e4bd20d5 feat(contracts): close PARTIAL gaps — dichotomy wave
Name-preserving 1:1 port of the 7 audit-missing functions (_ct_core,
_resolve_and_project, _run_contract_python, capture_signatures,
save_signatures, load_signatures, main as contracts_main) into
src/rust/contracts with IO behind injectable seams (CoreProbe /
Invoker / Signaturer / MainIO); 8 new FFI kernels (ct_gate,
ct_resolve, ct_run_python, ct_run_all, ct_capture, ct_save, ct_load,
ct_main) wired in contracts_loader.

Frozen truth: src/rust/contracts/src/ct_gap_truth.json (127 rows,
freeze byte-identical + harness --verify 23/23 clean); battery
src/rust/contracts/src/gap_battery.rs 19/19 green; live parity
replay failures=0 (facade 30, kernel 15); clippy -D warnings clean;
Python both pins green. Audit: contracts 11/11 FULL.

One documented eager/lazy divergence (projection-crash row): crash on
the delegated path, PASS on the lazy oracle path — pinned both ways.
2026-10-13 18:48:11 +01:00
Nick 59866dc8a7 chore(store): close identity_anchors dichotomy contract BUILDER-2026-10-13T17:40:21Z-dca2b3-factory-gap-ia (parity 62eb2bf9, phase B 9964e01e)
gap-close 6/14 → 14/14 (FULL): 8 identity kernels in the cognition_core
broker, doc-envelope FFI cc_* via cc_loader (cc_free_string, never
re-exported), facade delegation behind the existing RUNE_COGNITION_CORE
gate; 44 frozen-oracle cases battery-replayed VERBATIM (freeze_truth
--verify byte-identical, ia_freeze_seams rig); live parity 88/88 both
pins; clippy 0; pytest 48/48 both pins; Phase B OnceLock caches +
prefixed() combinator + fmt::Write renderers. Full lifecycle walked in
ONE process (approved→building→verifying→closed).
2026-10-13 18:43:36 +01:00
901 changed files with 434293 additions and 4905 deletions

No files matched your search

+2 -2
View File
@@ -231,9 +231,9 @@ jobs:
- name: curator-core candidate-decay parity gate (HARD — #2479 batch: ledger decay + journal render + cosine)
run: |
cd src/go/curator-core && go build -o /tmp/curator-core-${{ gitea.run_id }} . && /tmp/curator-core-${{ gitea.run_id }} replay truth_candidate_decay.json && go test -run TestCandidateDecayParity -v
- name: cron-engine parity gate (HARD — #2479 batches 1+126: parser + lifecycle)
- name: cron-engine parity gate (HARD — #2479 batches 1+126 + gap-close: parser + lifecycle + execution family)
run: |
cd src/go/cron-engine && go build -o /tmp/cron-engine-${{ gitea.run_id }} . && /tmp/cron-engine-${{ gitea.run_id }} replay truth.json && go test -run TestLifecycleParity -v
cd src/go/cron-engine && go build -o /tmp/cron-engine-${{ gitea.run_id }} . && /tmp/cron-engine-${{ gitea.run_id }} replay truth.json && /tmp/cron-engine-${{ gitea.run_id }} replay-gap truth_gap.json && go test -run 'TestLifecycleParity|TestGapParity' -v
- name: goal-engine parity gate (HARD — #2479 batches 2+129: verifier + lifecycle)
run: |
cd src/go/goal-engine && go build -o /tmp/goal-engine-${{ gitea.run_id }} . && /tmp/goal-engine-${{ gitea.run_id }} replay truth.json && go test -run TestLifecycleParity -v
+3
View File
@@ -23,4 +23,7 @@ src/go/*/[^.]*
!src/go/*/*.json
!src/go/*/*.mod
!src/go/*/*.sum
# committed fixture stores (frozen-truth construction rigs)
!src/go/*/fixtures/
!src/go/*/fixtures/**
store/scaffold/current.json
+1 -1
View File
@@ -1,6 +1,6 @@
# Rune
**Current release: v0.288.1**
**Current release: v0.304.0**
**Rune is a persistent personal agent designed to accumulate experience, develop reusable competence, and remain recognisably the same agent even when its underlying foundation model changes.**
+6 -1
View File
@@ -18,6 +18,11 @@
{"trap": "oracle CRASH parity: if the oracle crashes (AttributeError etc.) on an input class, the port returns the matching error envelope", "port": "never silently skip — the facade's fallback reproduces the exact exception", "proved_by": "execution_trace fuzz"},
{"trap": "glob+mtime ordering ties within the same second", "port": "explicit os.utime in test fixtures; deterministic per-case dirs", "proved_by": "sleep_time"},
{"trap": "Go evaluation order: arg-list trace(x, f.Mutating()) snapshots BEFORE mutation; Python passes live references", "port": "capture returns/reports into locals first", "proved_by": "failure_auto_filer"},
{"trap": "absolute temp paths in frozen truth are machine-specific", "port": "repo-relative names or REPO_ROOT placeholder + battery substitution", "proved_by": "paths"}
{"trap": "absolute temp paths in frozen truth are machine-specific", "port": "repo-relative names or REPO_ROOT placeholder + battery substitution", "proved_by": "paths"},
{"trap": "ThreadPoolExecutor.submit AFTER shutdown raises from the submit loop itself — run_parallel's per-task capture never sees it, the WHOLE call raises", "port": "Go port panics with 'cannot schedule new futures after shutdown' at the same site (crash parity, recovered by battery/parity)", "proved_by": "parallel_processor (2026-10-14)"},
{"trap": "callable corpora cannot ride JSON truth rows", "port": "freeze a shared kind/fn/value SPEC grammar via a rig that builds real Python callables; the battery rebuilds Go tasks from the same rows (extends the memory_consolidation seam pattern)", "proved_by": "parallel_processor (2026-10-14)"},
{"trap": "threading.active_count() in oracle output is process-random (pool threads, harness state)", "port": "pin via rig patch to a constant; Go side reads the matching PP_ACTIVE_THREADS seam (default: native goroutine count)", "proved_by": "parallel_processor (2026-10-14)"},
{"trap": "epoch microseconds beyond ~2^53 (year >285 CE) lose sub-second digits when crossing f64 JSON (253402300799000001 → …799000000)", "port": "instants cross FFI as STRINGS; kernel parses i64 (si_now micros_str law)", "proved_by": "self_improve (2026-10-14)"},
{"trap": "f'{x:.0%}' scales the DOUBLE's exact decimal expansion by 100 then rounds half-even; a binary r*100.0 multiply can sit 1 ulp off the tie and round differently", "port": "Rust format!('{:.0}%') matches on exactly-representable ratios; frozen truth pins ties with power-of-two denominators only (1/8 → 12.5% → '12%')", "proved_by": "self_improve (2026-10-14)"}
]
}
+45 -45
View File
@@ -2,16 +2,16 @@
_Regenerate with `python3 scripts/dichotomy_audit.py --write`. A module is FULL only when 80%+ of its Python functions have name-preserving counterparts in the Go/Rust implementation — directories without the functions are facades and count as NOT TOUCHED._
**FULL completion: 41%** (79/192 runtime modules at FULL)
**FULL completion: 60%** (116/192 runtime modules at FULL)
Function-level detail: 62% (1403/2278 runtime functions matched) — secondary; includes in-flight work
Function-level detail: 73% (1669/2288 runtime functions matched) — secondary; includes in-flight work
| Status | Modules | Lines | Meaning |
|---|---|---|---|
| FULL | 79 | 31836 | 80%+ of functions ported |
| PARTIAL | 73 | 30782 | 20–80% — real logic exists, gaps named below |
| NOT TOUCHED | 40 | 11513 | no name-preserving implementation |
| Total runtime | 192 | 74131 | |
| FULL | 116 | 48317 | 80%+ of functions ported |
| PARTIAL | 37 | 15677 | 20–80% — real logic exists, gaps named below |
| NOT TOUCHED | 39 | 11471 | no name-preserving implementation |
| Total runtime | 192 | 75465 | |
## NOT TOUCHED — the port queue, in priority order (largest first)
@@ -50,7 +50,6 @@ Function-level detail: 62% (1403/2278 runtime functions matched) — secondary;
| canary_schema_migration | 86 | 1 | TEST-INFRA |
| wait_guard_corpus | 46 | 0 | RUST |
| canary_cognitive_strata | 44 | 1 | TEST-INFRA |
| builder_bridge_cli | 42 | 1 | GO |
| __init__ | 40 | 1 | RUST |
| canary_memory_synthesis | 33 | 1 | TEST-INFRA |
| canary_resource_authority | 33 | 1 | TEST-INFRA |
@@ -64,65 +63,29 @@ Function-level detail: 62% (1403/2278 runtime functions matched) — secondary;
|---|---|---|---|
| rune_operator | 2746 | 25/68 | _build_model_router, _sorted_tool_names, _filter_safety_noise, _wire_auto_filer, _reconcile_guarded, get_operator |
| memory_store | 2333 | 30/68 | _ctx_budget, now_iso, ensure_memory_type_column, _embed, _temp_json, _entities_to_json |
| construction_interface | 1193 | 6/27 | _to_stage_check, _guard_specs_from_obligations, t_layout, _obligations_projection, _obligation_scope_files, main |
| provider_registry | 679 | 11/28 | _ctx_budget, _format_tools_openai, _execute_tool_calls, _execute_tool_calls_anthropic, get_registry, connect_provider |
| warm_router | 1518 | 17/33 | _ensure_use_history_table, record_outcome, record_neuron_fire, base_level_activation, _db, _aaak |
| cron_engine | 440 | 13/27 | get_cron_engine, run_task, start_engine, stop_engine, to_dict, fire_on_task_complete |
| tool_executor | 1836 | 33/47 | _execute_tool_now, serialize_prepared_tool, deserialize_prepared_tool, confirm_write, _resolve_execution_cwd, _run_command |
| cache | 492 | 6/17 | _record_hit, _record_miss, flush_stats, get_cache, put_cache, invalidate_scope |
| parallel_processor | 194 | 3/14 | _shutdown_processor, get_processor, run_parallel_with_args, get_status, test_parallel, run_parallel_with_args |
| structural_model | 388 | 9/20 | workspace_record, workspace_advance, _init_project, save, reload, add |
| claim_audit | 484 | 4/14 | _get_warm_neuron_store, reframe, _graph_has, _warm_has, verify, journal |
| model_profiles | 438 | 5/15 | get_profile_path, load_profile, save_profile, build_profile_from_ollama, scan_all_models, get_or_create_profile |
| capability_broker | 798 | 10/19 | _native_tool_schemas, load_registry, _cards_are_stale, load_cards, generate_card, build_cards |
| token_optimizer | 514 | 16/25 | get_optimizer, _tc_core, _to_core, to_dict, _to_state, _apply_state |
| behavior | 537 | 6/14 | _bh_core, connect, _correction_matches_python, _habit_matches_python, _reinforce_rust, _reinforce_python |
| builder_bridge | 326 | 3/11 | _construction_store, _active_construction_lines, _default_selector, _cached_memory, _get_selector, _retrieve_memory |
| drift_core | 471 | 3/11 | _ms_core, _now_iso, promote_entry, compute_fama, compute_drift_velocity, compute_drift_direction |
| identity_anchors | 542 | 6/14 | show_anchors, show_rules, show_pronouns, _announcement_patterns, _pronoun_patterns, _hedge_patterns |
| time_awareness | 402 | 12/20 | _clock_args, _ta_core, get_time_awareness, to_dict, _to_state, _apply_state |
| contracts | 743 | 4/11 | _ct_core, _resolve_and_project, _run_contract_python, capture_signatures, save_signatures, load_signatures |
| graph_memory | 474 | 2/9 | now_iso, connect, resolve_entity, add_edge, query, stats |
| intent_continuity | 284 | 6/13 | _now, _raise_core_err, to_dict, from_dict, save, _ledger_state |
| voice_hybrid | 427 | 3/10 | _connect, _load_growth, _save_growth, source_profiles, always, grow |
| voice_sync | 299 | 3/10 | _now, get_delivery_register_from_db, get_delivery_register, update_rune_md, check_sync, handle_hook |
| audit_ledger | 212 | 2/8 | _compute_hash, get_entries, log_promotion, log_gate_result, log_drift_alert, main |
| context_pressure | 262 | 3/9 | log_measurement, read_log, log_stats, _now, handle_hook, main |
| core_server | 234 | 6/12 | make_server, log_message, _send_json, _send_ndjson, do_GET, do_POST |
| microkernel | 434 | 6/12 | now_iso, discover, _extract_manifest, _load_registry, _save_registry, _run_hook |
| model_registry | 253 | 2/8 | test_registry, to_dict, get_profile, get_enabled_profiles, get_profiles_by_tier, list_profiles |
| progressive_escalation | 279 | 2/8 | execute_with_escalation, test_escalation, handle_hook, to_dict, execute, verify |
| voicebox | 164 | 5/11 | _run, start_recording, stop_recording, _transcribe_and_type, on_press, on_release |
| persona_definition | 210 | 2/7 | _by_topic, compile_full, emit_constitution, emit_identity, emit_persona |
| task_persist | 269 | 5/10 | _save, export, restore, main, handle_hook |
| tiered_executor | 291 | 3/8 | _ctx_budget, test_executor, to_dict, to_dict, _execute_model |
| construction_commands | 268 | 1/5 | _refuse, _validate, _accept, dispatch |
| drift_compression | 307 | 3/7 | get_compression_ratio, compress_entry, warn_before_compress, get_compression_stats |
| drift_observability | 399 | 5/9 | _do_core, main, _load_alerts, _save_alerts |
| layout_contract | 336 | 2/6 | define_region, bind_component, amend_layout_contract, record_layout_observation |
| model_connect | 471 | 7/11 | _ctx_budget, _now, _get_cloud_models, handle_hook |
| pins | 282 | 7/11 | _store_path, _detail_blob, unpin, list_pins |
| prompt_sync | 487 | 11/15 | _now, _rust_available, get_store, main |
| salience_gate | 276 | 1/5 | _sg_core, test_salience, handle_hook, to_dict |
| self_improve | 246 | 1/5 | _now, suggest_improvements, handle_hook, main |
| task_gate | 301 | 5/9 | _tg_core, _now, list_gates, main |
| tier_manager | 262 | 6/10 | demotion_sweep, get_tier_config, should_search, should_compress |
| witness | 446 | 11/15 | _now, log_entry, read_log, log_stats |
| connection_pool | 226 | 7/10 | get_pool, _kernel_state, _get_connection_core |
| construction_activation | 237 | 1/4 | _scaffold_for, _auto_structural_awareness, dispatch_from_decision |
| construction_mode | 412 | 2/5 | _contains_any, to_dict, from_dict |
| construction_projection | 254 | 1/4 | _contract_entity, validate, write_mini_doc |
| dependency_tracker | 202 | 2/5 | check_propagation, get_full_map, main |
| event_envelope | 303 | 5/8 | test_envelope, to_canonical_dict, to_dict |
| graph_projection | 134 | 3/6 | _model_to_dicts, write_all, _now |
| state_checkpoint | 182 | 6/9 | _sck_core, _load_ledger, _save_ledger |
| warm_neuron_store | 122 | 3/6 | _db, neuron_slugs, handle_hook |
| cognitive_budgeter | 221 | 1/3 | test_budgeter, to_dict |
| event_bus | 244 | 5/7 | _store_path, handle_hook |
| inference_trace | 204 | 4/6 | record_trace, read_traces |
| response_adapter | 222 | 5/7 | test_adapter, to_dict |
| stage_guards | 303 | 7/9 | to_dict, chk |
| standardized_providers | 281 | 3/5 | list_providers, connect_all_local |
| structural_migration | 77 | 2/4 | apply_migration, consent_brief |
| subconscious_pass | 236 | 3/5 | main, get_recent_findings |
| subsystem_health | 213 | 4/6 | set_auto_filer, configure_logging |
@@ -142,59 +105,95 @@ Function-level detail: 62% (1403/2278 runtime functions matched) — secondary;
|---|---|---|---|
| curator | 1838 | 43/43 | GO |
| construction_decision | 1211 | 21/24 | RUST |
| construction_interface | 1193 | 27/27 | RUST |
| sleep_time | 1056 | 26/26 | GO |
| spine | 975 | 25/25 | RUST |
| structural_store | 921 | 34/41 | RUST |
| scaffold | 881 | 30/30 | GO |
| scaffold | 908 | 30/30 | GO |
| context_broker | 870 | 24/24 | GO |
| capability_broker | 865 | 19/19 | RUST |
| hook_engine | 860 | 8/8 | GO |
| local_tool_runtime | 809 | 30/30 | GO |
| elastic_cognition | 774 | 14/14 | GO |
| memory_consolidation | 770 | 22/22 | GO |
| contracts | 743 | 11/11 | RUST |
| persona_gate | 724 | 23/23 | GO |
| provider_registry | 687 | 28/28 | GO |
| abstraction | 656 | 16/16 | GO |
| safety_override | 649 | 20/20 | RUST |
| adaptive_router | 625 | 19/19 | GO |
| memory_selector | 609 | 14/14 | RUST |
| system_registry | 603 | 14/16 | RUST |
| work_manager | 594 | 25/25 | GO |
| structural_model | 593 | 21/21 | RUST |
| construction_intent | 580 | 13/16 | RUST |
| identity_anchors | 575 | 14/14 | RUST |
| capability_ledger | 571 | 18/18 | RUST |
| graph_memory | 563 | 9/9 | RUST |
| drift_ledger | 548 | 20/21 | RUST |
| construction_pattern | 547 | 13/13 | RUST |
| voice_hybrid | 540 | 11/11 | RUST |
| drift_core | 539 | 12/12 | RUST |
| behavior | 537 | 14/14 | RUST |
| failure_auto_filer | 527 | 24/24 | GO |
| build_mode | 521 | 33/33 | GO |
| growth_delta | 520 | 16/18 | GO |
| growth_delta | 520 | 17/18 | GO |
| event_wait | 518 | 14/14 | GO |
| token_optimizer | 514 | 25/25 | RUST |
| cache | 492 | 17/17 | GO |
| claim_audit | 484 | 14/14 | RUST |
| model_connect | 471 | 11/11 | GO |
| worthiness | 469 | 12/13 | unclassified |
| tool_protocol | 461 | 22/27 | GO |
| auto_tasks | 460 | 14/14 | GO |
| programme_continuation | 458 | 11/12 | RUST |
| goal | 453 | 20/20 | GO |
| release_notes | 446 | 16/16 | GO |
| witness | 446 | 15/15 | GO |
| cron_engine | 440 | 27/27 | GO |
| model_profiles | 438 | 15/15 | GO |
| layout_contract | 434 | 6/6 | RUST |
| microkernel | 434 | 12/12 | GO |
| model_routing | 432 | 13/13 | GO |
| voice_sync | 426 | 12/12 | RUST |
| night_mode | 421 | 19/19 | GO |
| construction_mode | 412 | 5/5 | RUST |
| construction_commands | 393 | 5/5 | RUST |
| self_improve | 384 | 7/8 | RUST |
| build_basis | 375 | 11/13 | RUST |
| attention_capsule | 365 | 6/7 | RUST |
| testing_mode | 362 | 11/13 | RUST |
| drift_cache | 357 | 12/14 | RUST |
| provider_budget | 357 | 20/20 | GO |
| drift-ledger | 355 | 14/14 | unclassified |
| context_pressure | 351 | 9/9 | RUST |
| progressive_escalation | 340 | 9/9 | RUST |
| builder_bridge | 326 | 11/11 | GO |
| drift_compression | 323 | 7/7 | RUST |
| outcome_ledger | 318 | 7/8 | RUST |
| construction_projection | 317 | 4/4 | RUST |
| message_queue | 316 | 13/13 | GO |
| lexicon_evolution | 304 | 7/8 | unclassified |
| event_envelope | 303 | 8/8 | GO |
| stage_guards | 303 | 9/9 | GO |
| message_graph | 295 | 12/13 | unclassified |
| toolchain | 295 | 5/6 | RUST |
| tiered_executor | 291 | 8/8 | GO |
| salience_gate | 283 | 6/6 | RUST |
| standardized_providers | 281 | 5/5 | GO |
| shard_manager | 276 | 9/9 | RUST |
| auto_context | 273 | 8/8 | GO |
| spine_language | 269 | 5/5 | RUST |
| construction_patterns_builtin | 266 | 1/1 | RUST |
| iteration | 261 | 7/8 | RUST |
| model_registry | 253 | 8/8 | GO |
| event_bus | 244 | 7/7 | GO |
| openai_compat_transport | 227 | 9/9 | GO |
| evidence_probe | 213 | 9/9 | GO |
| project_registry | 205 | 10/12 | RUST |
| forge_client | 203 | 18/18 | GO |
| behaviour_ledger | 195 | 10/12 | RUST |
| parallel_processor | 194 | 14/14 | GO |
| construction_depth | 172 | 2/2 | RUST |
| self_modify | 149 | 7/8 | unclassified |
| forge | 146 | 11/11 | GO |
@@ -218,4 +217,5 @@ Function-level detail: 62% (1403/2278 runtime functions matched) — secondary;
| evidence_capsule | 74 | 3/3 | unclassified |
| paths | 53 | 6/6 | unclassified |
| provider_context | 48 | 1/1 | GO |
| builder_bridge_cli | 42 | 1/1 | GO |
| route_risk_flags | 37 | 1/1 | RUST |
+71 -17
View File
@@ -1,90 +1,144 @@
{
"landed": [
"abstraction",
"abstraction_ladder",
"adaptive_router",
"attention_capsule",
"auto_context",
"auto_tasks",
"behavior",
"behaviour_ledger",
"build_basis",
"build_mode",
"builder_bridge_cli",
"cache",
"capability_broker",
"capability_ledger",
"claim_audit",
"concept_topology",
"connection_pool",
"construction_decision",
"construction_depth",
"construction_intent",
"construction_interface",
"construction_mode",
"construction_pattern",
"construction_patterns_builtin",
"context_broker",
"contracts",
"cron_engine",
"curator",
"drift-ledger",
"drift_cache",
"drift_compression",
"drift_core",
"drift_ledger",
"drift_observability",
"drift_resume",
"elastic_cognition",
"event_envelope",
"event_wait",
"evidence_capsule",
"evidence_probe",
"execution_trace",
"experience_encoding",
"failure_auto_filer",
"failure_recovery",
"forge",
"forge_client",
"goal",
"grading",
"graph_memory",
"growth_delta",
"growth_pipeline",
"hook_engine",
"identity_anchors",
"impact_preview",
"inference_paths",
"intent_continuity",
"iteration",
"layout_contract",
"lexicon_evolution",
"local_tool_runtime",
"meaningful_events",
"memory_consolidation",
"memory_selector",
"memory_types",
"message_graph",
"message_queue",
"microkernel",
"model_connect",
"model_profiles",
"model_routing",
"mutation_guards",
"night_mode",
"openai_compat_transport",
"outcome_ledger",
"outcome_utility",
"pane_authority",
"parallel_processor",
"paths",
"persona_gate",
"programme_continuation",
"programme_gates",
"project_registry",
"prompt_sync",
"provider_budget",
"provider_context",
"provider_registry",
"recall_uplift",
"release_notes",
"research_budget",
"route_risk_flags",
"rune_profiler",
"rune_spinner",
"safety_override",
"salience_gate",
"scaffold",
"self_model",
"self_modify",
"shard_manager",
"skill_compiler",
"sleep_time",
"spine",
"spine_language",
"stage_guards",
"state_checkpoint",
"structural_store",
"subconscious_pass",
"subsystem_health",
"system_registry",
"task_gate",
"testing_mode",
"time_awareness",
"token_optimizer",
"tool_protocol",
"toolchain",
"verification_layer",
"wait_guard",
"witness",
"work_manager",
"worthiness"
],
"in_flight": {
"memory_types": "rune-wave-bd",
"wait_guard_corpus": "rune-wave-be",
"research_budget": "rune-wave-be",
"evidence_capsule": "rune-wave-be",
"builder_bridge_cli": "rune-wave-be",
"safety_override": "rune-wave-bn",
"construction_decision": "rune-wave-bo",
"provider_registry": "rune-wave-bq",
"construction_interface": "rune-wave-bu",
"spine": "rune-wave-bv",
"elastic_cognition": "rune-wave-bx",
"contracts": "rune-wave-by",
"adaptive_router": "rune-wave-bz",
"memory_selector": "rune-wave-ca",
"capability_broker": "rune-wave-cd",
"identity_anchors": "rune-wave-ce",
"construction_pattern": "rune-wave-cb [agent: naming-artifact claim UNPROVEN \u2014 audit reads PARTIAL 7/14; awaiting per-fn proof or re-port]"
"voice_hybrid": "rune-wave-cr",
"structural_model": "rune-wave-ct",
"builder_bridge": "rune-wave-cw",
"event_envelope": "rune-wave-cy",
"voice_sync": "rune-wave-db",
"tiered_executor": "rune-wave-tiered_executor",
"pins": "rune-wave-pins",
"standardized_providers": "rune-wave-standardized_providers",
"progressive_escalation": "rune-wave-progressive_escalation",
"task_persist": "rune-wave-task_persist",
"construction_commands": "rune-wave-construction_commands",
"context_pressure": "rune-wave-context_pressure",
"tier_manager": "rune-wave-tier_manager",
"construction_projection": "rune-wave-construction_projection",
"model_registry": "rune-wave-model_registry",
"self_improve": "rune-wave-self_improve",
"event_bus": "rune-wave-event_bus",
"construction_activation": "rune-wave-construction_activation"
},
"excluded": [
"TUI-LAST modules",
+1 -1
View File
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
[project]
name = "rune"
version = "0.288.1"
version = "0.304.0"
description = "Rune — a stateful coding assistant with persistent memory, orchestration, and TUI"
requires-python = ">=3.10"
+35
View File
@@ -0,0 +1,35 @@
"""sitecustomize — the builder_bridge freeze rig (dichotomy wave gap close).
Auto-imported via PYTHONPATH=scripts/bb_freeze_seams by BOTH the truth
generator and `freeze_truth.py --verify`, so the --verify law (replay
against the pristine oracle) still holds. The seams below only pin WHERE
the oracle looks — never what it computes:
* HOME/RUNE_HOME pinned at a fresh throwaway (the memory stack's every
source abstains on an isolated HOME — warm neurons open the store
read-only, the graph store is created empty — so _retrieve_memory and
_cached_memory freeze deterministically as the degrade-safe [] path).
* RUNE_MSE_CORE=python (the selector's Rust core probe stays Python).
* RUNE_CONSTRUCTION_STORE pinned at the committed fixture store
(repo-root-relative; run generators and verify from the repo root).
The default branch (absolute, __file__-derived) is covered by the
live parity sweep, not frozen truth — no absolute paths law.
"""
import os
import sys
import tempfile
from pathlib import Path
REPO = Path(os.environ.get("BB_FREEZE_REPO", "")) or Path.cwd()
if str(REPO / "src") not in sys.path:
sys.path.insert(0, str(REPO / "src"))
_home = tempfile.mkdtemp(prefix="freeze-home-bb-")
os.environ["HOME"] = _home
os.environ.setdefault("RUNE_HOME", os.path.join(_home, ".rune"))
os.environ["RUNE_MSE_CORE"] = "python"
os.environ["RUNE_CONSTRUCTION_STORE"] = str(
Path("src") / "go" / "builder-bridge" / "fixtures" / "store_active"
)
+21
View File
@@ -0,0 +1,21 @@
"""sitecustomize — builder_bridge_cli freeze seam (clock rig).
Auto-imported by every interpreter started with this dir on PYTHONPATH
(INCLUDING the oracle CLI subprocess the truth generator spawns). Pins
the wall clock via freeze_rigs.pin_clock BEFORE the oracle imports, so
preflight's function-local `from datetime import datetime` resolves to
the frozen class (dichotomy quirk: datetime imported INSIDE functions —
module-level patching never reaches it).
Env contract:
* BBC_FROZEN_NOW — ISO-8601 instant (required to activate the pin)
* REPO_ROOT — repo root (for the freeze_rigs import)
"""
import os
import sys
if os.environ.get("BBC_FROZEN_NOW") and os.environ.get("REPO_ROOT"):
sys.path.insert(0, os.path.join(os.environ["REPO_ROOT"], "scripts"))
from freeze_rigs import pin_clock
pin_clock(os.environ["BBC_FROZEN_NOW"])
+101
View File
@@ -0,0 +1,101 @@
"""sitecustomize — the claim_audit freeze rig (dichotomy wave gap close).
Auto-imported via PYTHONPATH=scripts/ca_freeze_seams:src by BOTH the truth
generator and `freeze_truth.py --verify`, so the --verify law (replay
against the pristine oracle) still holds: the seams below only make the
oracle's already-existing behavior reachable with JSON-safe shapes.
* RUNE_MEMORY_DIR pinned to the hermetic FIXED-path scratch
(/tmp/ca_gap_freeze — wiped and reseeded at import so every process
sees byte-identical store state; rowids restart at 1).
* Embeddings forced off (lexical-only; deterministic).
* The graph DB seeded with the ledger entities the verify() cases probe
(entities table — the oracle's _graph_has SQL verbatim).
* The store seeded with warm neurons via memory_store.add_entry
(FTS-populated — raw INSERTs bypass entries_fts and recall abstains).
* Module seams bound onto rune.claim_audit:
- ca_graph_db — the FIXED-path graph DB (the oracle reads GRAPH_DB
at import; the seam makes the hermetic path reachable).
- ca_neurons — the gathered neuron rows (list_neurons shape) the
kernel consumes through ca_warm_has.
- ca_journal_path — the FIXED-path journal (IO stays Python).
"""
import os
import shutil
import sqlite3
import sys
from pathlib import Path
REPO = Path(os.environ.get("CA_FREEZE_REPO", "")) or Path.cwd()
os.environ.setdefault("RUNE_MEMORY_DIR", "/tmp/ca_gap_freeze")
SCRATCH = os.environ["RUNE_MEMORY_DIR"]
if os.path.isdir(SCRATCH):
shutil.rmtree(SCRATCH)
os.makedirs(os.path.join(SCRATCH, "store"), exist_ok=True)
os.makedirs(os.path.join(SCRATCH, "graph"), exist_ok=True)
os.makedirs(os.path.join(SCRATCH, "index"), exist_ok=True)
if str(REPO / "src") not in sys.path:
sys.path.insert(0, str(REPO / "src"))
from rune import memory_store as _store # noqa: E402
_store.DB_PATH = os.path.join(SCRATCH, "store", "memory.db")
_store.STORE_DIR = os.path.join(SCRATCH, "store")
_store._embed = lambda texts: {} # lexical-only, deterministic
_db = _store.connect(_store.DB_PATH)
try:
_store.add_entry(_db, "Kubernetes pods restart automatically on failure",
importance=0.9, source="truth")
_store.add_entry(_db, "Letta memory layers use archival recall",
importance=0.9, source="truth")
_db.commit()
# Warm neurons: kind='neuron', active — the _warm_has surface.
_db.execute(
"INSERT INTO entries (text, slug, triggers, importance, kind, status, "
"created_at) VALUES (?,?,?,?,?,?,?)",
("Kubernetes pods restart automatically on failure", "warm",
"kubernetes,pods", 0.9, "neuron", "active", "2026-10-14T00:00:00"),
)
_db.execute(
"INSERT INTO entries (text, slug, triggers, importance, kind, status, "
"created_at) VALUES (?,?,?,?,?,?,?)",
("Letta memory layers use archival recall", "warm",
"letta,memory", 0.9, "neuron", "active", "2026-10-14T00:00:00"),
)
_db.commit()
finally:
_db.close()
# Graph ledger entities — the _graph_has surface (oracle SQL verbatim).
GRAPH_DB = os.path.join(SCRATCH, "graph", "graph.sqlite")
_gdb = sqlite3.connect(GRAPH_DB)
try:
_gdb.execute(
"CREATE TABLE IF NOT EXISTS entities (id INTEGER PRIMARY KEY "
"AUTOINCREMENT, name TEXT NOT NULL UNIQUE, type TEXT NOT NULL "
"DEFAULT 'concept', summary TEXT DEFAULT '', created_at TEXT NOT NULL)"
)
_gdb.execute(
"INSERT INTO entities (name, type, summary, created_at) VALUES (?,?,?,?)",
("Kubernetes", "concept", "container orchestration", "2026-10-14T00:00:00"),
)
_gdb.execute(
"INSERT INTO entities (name, type, summary, created_at) VALUES (?,?,?,?)",
("Letta", "concept", "memory architecture", "2026-10-14T00:00:00"),
)
_gdb.commit()
finally:
_gdb.close()
import rune.claim_audit as _ca # noqa: E402
import rune.warm_neuron_store as _wns # noqa: E402
_ca.GRAPH_DB = GRAPH_DB
_ca.ca_graph_db = GRAPH_DB
_ca.ca_neurons = _wns.list_neurons()
_ca.ca_journal_path = os.path.join(SCRATCH, "index", "claim_audit.jsonl")
+111 -1
View File
@@ -3,9 +3,15 @@
oracle path, over the SAME case matrix the truth generator froze.
Run: python3 scripts/check_behavior_parity.py -> x/y lines, exit 1 on any
divergence.
FROZEN layer (gap-close): the new pure-fn surface (connect schema, core
probe, python-pin predicates, reinforce plans, list_items,
behavior_stats) replayed through the cdylib's ctypes FFI against the
frozen oracle truth — live parity for the ported fns.
"""
from __future__ import annotations
import ctypes
import json
import os
import sys
@@ -76,6 +82,109 @@ def both(name, fn):
check(name, rust, py)
# ── FROZEN layer: the gap-close fns through the cdylib FFI ────────────
FROZEN_PASS = 0
FROZEN_FAIL = 0
def frozen_check(name, got, want):
global FROZEN_PASS, FROZEN_FAIL
if got == want:
FROZEN_PASS += 1
else:
FROZEN_FAIL += 1
DIVERGENCES.append((f"FROZEN {name}", got, want))
_new_lib = ctypes.CDLL(str(bh_loader._LIB_PATH))
for _sym in ("bh_connect", "bh_core_probe", "bh_python_predicates",
"bh_reinforce_plan", "bh_list_items", "bh_behavior_stats"):
_fn = getattr(_new_lib, _sym)
_fn.argtypes = [ctypes.c_void_p]
_fn.restype = ctypes.c_void_p
def ffi(sym, payload):
data = json.dumps(payload).encode()
buf = ctypes.create_string_buffer(data)
ptr = getattr(_new_lib, sym)(ctypes.cast(buf, ctypes.c_void_p))
if not ptr:
raise RuntimeError(f"{sym} returned null")
out = ctypes.string_at(ptr).decode()
bh_loader._free(ptr)
doc = json.loads(out)
if not doc.get("ok"):
raise RuntimeError(doc.get("err", f"{sym} failed"))
return doc["value"]
os.environ["RUNE_BEHAVIOR_CORE"] = "python"
_truth = json.loads((Path(__file__).resolve().parents[1]
/ "src" / "rust" / "behavior" / "src" / "bh_truth.json").read_text())
# connect: schema + pragma through the FFI (the frozen truth carries no
# path — no absolute paths in frozen truth; the path law is asserted
# separately: memory-dir relative, behavior.db suffix)
_connect_got = ffi("bh_connect", {})
frozen_check("connect-schema",
{"journal_mode": _connect_got["journal_mode"], "schema": _connect_got["schema"]},
{"journal_mode": _truth["cases"]["connect"]["journal_mode"],
"schema": _truth["cases"]["connect"]["schema"]})
if not _connect_got["path"].endswith("/behavior.db"):
FROZEN_FAIL += 1
DIVERGENCES.append(("FROZEN connect-path", _connect_got["path"], "*/behavior.db"))
else:
FROZEN_PASS += 1
# core probe under the pin (frozen core: null)
frozen_check("core-probe-pin", ffi("bh_core_probe", {}), {"available": False})
# python-pin predicate matrix
for c in _truth["cases"]["predicates"]["corrections"]:
got = ffi("bh_python_predicates", {"kind": "correction", "row": c["row"],
"context": c["context"], "context_low": c["context_low"]})
frozen_check(f"pred-corr-{c['row']['id']}-{c['context'][:12]}", got, c["matched"])
for h in _truth["cases"]["predicates"]["habits"]:
got = ffi("bh_python_predicates", {"kind": "habit", "row": h["row"], "context": h["context"]})
frozen_check(f"pred-habit-{h['row']['id']}-{h['context'][:12]}", got, h["matched"])
# reinforce plans: full pre->final threading through BOTH paths
for key in ("reinforce_habit", "reinforce_correction"):
for case in _truth["cases"][key]:
name = case["name"]
if case["pre_row"] is None:
item_id = 99991 if name == "habit-not-found" else 99992
payload = {"item_id": item_id, "outcome": case["outcome"],
"item_type": case["item_type"], "row": None, "ts": "ts"}
frozen_check(f"reinf-{name}", ffi("bh_reinforce_plan", payload)["result"],
case["results"][0])
continue
ts = case["pre_row"]["created_at"]
cur = dict(case["pre_row"])
for i in range(case["n"]):
payload = {"item_id": case["pre_row"]["id"], "outcome": case["outcome"],
"item_type": case["item_type"], "row": cur, "ts": ts, "path": "rust"}
plan = ffi("bh_reinforce_plan", payload)
twin = ffi("bh_reinforce_plan", {**payload, "path": "python"})
frozen_check(f"reinf-{name}-step{i}-halves", plan, twin)
frozen_check(f"reinf-{name}-step{i}", plan["result"], case["results"][i])
cur.update(plan["writeback"])
frozen_check(f"reinf-{name}-final", cur, case["final_row"])
# list_items + behavior_stats over the frozen row collections
_sf = _truth["cases"]["stats_full"]
for case in _truth["cases"]["list_full"]:
got = ffi("bh_list_items", {"corrections": _sf["corrections"], "habits": _sf["habits"],
"item_type": case["item_type"], "limit": case["limit"]})
frozen_check(f"list-{case['name']}", got, case["result"])
frozen_check("stats", ffi("bh_behavior_stats", {"corrections": _sf["corrections"],
"habits": _sf["habits"],
"activations": _sf["activations"]}),
_sf["stats"])
os.environ["RUNE_BEHAVIOR_CORE"] = "auto"
# ── LIVE layer: the delegating facade vs the python pin ───────────────
# ── add shapes ────────────────────────────────────────────────────────
def add_shapes():
out = [bh.add_correction("say X", "say Y"),
@@ -174,9 +283,10 @@ def list_stats_shapes():
both("list-stats", list_stats_shapes)
print(f"FROZEN {FROZEN_PASS}/{FROZEN_PASS + FROZEN_FAIL} pure-fn replay through cdylib FFI")
print(f"{PASS}/{PASS + FAIL} live parity (rust facade vs python pin)")
for name, rust, py in DIVERGENCES:
print(f"DIVERGENCE {name}:")
print(f" rust: {json.dumps(rust, sort_keys=True)[:400]}")
print(f" py: {json.dumps(py, sort_keys=True)[:400]}")
sys.exit(1 if FAIL else 0)
sys.exit(1 if (FAIL or FROZEN_FAIL) else 0)
+215
View File
@@ -0,0 +1,215 @@
#!/usr/bin/env python3
"""check_builder_bridge_parity.py — LIVE oracle↔Go parity sweep for the
builder_bridge gap closure (dichotomy wave, worktree rune-wave-cw).
The adaptive_router precedent: preflight returns a BuilderCapsule the
freeze harness cannot JSON-serialize and stamps generated_at from an
in-function datetime import, and _default_selector/_get_selector return
live selector instances. Those surfaces are pinned HERE, by driving the
live Python oracle and the Go binary across every branch with full
to_dict + to_markdown comparison (generated_at normalized — both sides
render the same wall-clock shape, the value is the caller's).
Case families:
* route branches: LOCAL_FIX defect, STANDARD_CHANGE, RESEARCHED_CHANGE
floor (incl. the doubled floor-prefix quirk), MEASUREMENT_REQUIRED
language, inspection-verb neutral class, unicode, >200-rune titles.
* construction branches: committed fixtures (active / quiet / terminal)
AND the DEFAULT store branch (both sides read the real repo store
live — equal at the same moment regardless of its content).
* memory: degrade-safe abstention under an isolated HOME (both sides).
* selector observables: lazy singleton identity + non-None default
selector (Python-observable contract; Go's is compile-time).
Usage (from the repo root):
python3 scripts/check_builder_bridge_parity.py
"""
from __future__ import annotations
import json
import os
import subprocess
import sys
import tempfile
from pathlib import Path
REPO = Path(__file__).resolve().parent.parent
GO_DIR = REPO / "src" / "go" / "builder-bridge"
GO_BIN = Path(tempfile.mkdtemp(prefix="bb-parity-")) / "builder-bridge"
FIX = GO_DIR / "fixtures"
NOW = "2026-10-13T11:00:00+00:00"
PY_DRIVER = r"""
import json, os
import sys
sys.path.insert(0, os.environ["BB_REPO"] + "/src")
from rune import builder_bridge as bb
task = os.environ["BB_TASK"]
cap = bb.preflight(task)
d = cap.to_dict()
sel = bb._get_selector()
print(json.dumps({
"dict": d,
"md": cap.to_markdown(),
"lines": bb._active_construction_lines(),
"store": bb._construction_store(),
"selector_identity": sel is bb._get_selector(),
"default_selector": type(bb._default_selector()).__name__,
"retrieve_memory": bb._retrieve_memory(task),
"cache_key": bb._cache_key(task),
}, ensure_ascii=False))
"""
def canonical(v):
if isinstance(v, dict):
return {k: canonical(v[k]) for k in sorted(v)}
if isinstance(v, list):
return [canonical(x) for x in v]
return v
def normalize(doc):
doc = json.loads(json.dumps(doc))
d = doc.get("dict")
if isinstance(d, dict):
d["generated_at"] = "TS"
store = doc.get("store")
if isinstance(store, str):
doc["store"] = store.replace(str(REPO) + "/", "REPO/")
return doc
def run_python(task: str, construction: str | None) -> dict:
env = dict(os.environ)
home = tempfile.mkdtemp(prefix="bb-parity-py-")
env["HOME"] = home
env["RUNE_HOME"] = os.path.join(home, ".rune")
env["BB_REPO"] = str(REPO)
env["BB_TASK"] = task
if construction:
env["RUNE_CONSTRUCTION_STORE"] = construction
else:
env.pop("RUNE_CONSTRUCTION_STORE", None)
out = subprocess.run(
[sys.executable, "-c", PY_DRIVER], capture_output=True, text=True,
env=env, cwd=str(REPO), timeout=120,
)
if out.returncode != 0:
raise RuntimeError(f"python driver failed: {out.stderr[-2000:]}")
return normalize(json.loads(out.stdout))
def run_go(task: str, construction: str | None, mode: str = "--json") -> dict:
env = dict(os.environ)
home = tempfile.mkdtemp(prefix="bb-parity-go-")
env["HOME"] = home
env["RUNE_HOME"] = os.path.join(home, ".rune")
if construction:
env["RUNE_CONSTRUCTION_STORE"] = construction
else:
env.pop("RUNE_CONSTRUCTION_STORE", None)
args = [str(GO_BIN), "parity", task, "--now", NOW, mode]
out = subprocess.run(args, capture_output=True, text=True,
env=env, cwd=str(REPO), timeout=60)
if out.returncode != 0:
raise RuntimeError(f"go driver failed: {out.stderr[-2000:]}")
if mode == "--json":
doc = json.loads(out.stdout)
doc["generated_at"] = "TS"
return doc
if mode == "--store":
return out.stdout.strip().replace(str(REPO) + "/", "REPO/")
# --md: fmt.Println appends exactly one trailing newline; to_markdown
# output never ends with one, so strip it for the raw-string compare.
if out.stdout.endswith("\n"):
return out.stdout[:-1]
return out.stdout
CASES = [
("local_defect_active", "Fix the telemetry summary log level constant in stage_telemetry.py", "active"),
("research_floor", "New subsystem: evaluate and adopt an external vector database dependency", "active"),
("standard_change", "Extend the config struct with a new field for the retry budget", "quiet"),
("quiet_local_fix", "Fix typo in CLI help text", "quiet"),
("terminal_store", "Fix the crash in the retry loop when the queue is empty", "terminal"),
("default_store", "Fix the log level constant", None),
("unicode_task", "Réparez le café ☕ débordé du module de télémétrie et le radix élevé naïf", "active"),
("long_title", "Measure and fix " + "the very long running parsing pipeline stage " * 12, "active"),
("mechanism_language", "measure the throughput of the parser under load", "active"),
("inspection_verb", "explain what the retry module does with the backoff", "quiet"),
("external_ref", "see https://example.com/api docs for the field names", "active"),
]
def main() -> int:
build = subprocess.run(
["go", "build", "-o", str(GO_BIN), "."],
cwd=str(GO_DIR), capture_output=True, text=True,
)
if build.returncode != 0:
print("go build failed:", build.stderr)
return 1
fails = 0
for name, task, store in CASES:
construction = str(FIX / f"store_{store}") if store else None
py = run_python(task, construction)
go = run_go(task, construction, "--json")
# capsule dict parity (timestamp-normalized)
py_dict = canonical(py["dict"])
go_dict = canonical(go)
if py_dict != go_dict:
fails += 1
print(f"FAIL {name} dict:\n PY: {json.dumps(py_dict, sort_keys=True, ensure_ascii=False)[:600]}\n GO: {json.dumps(go_dict, sort_keys=True, ensure_ascii=False)[:600]}")
# markdown parity (rendered from the same capsule)
py_md = py["md"]
go_md = run_go(task, construction, "--md")
if py_md != go_md:
fails += 1
print(f"FAIL {name} md:\n PY: {py_md[:300]!r}\n GO: {go_md[:300]!r}")
# construction projection parity (lines mode)
py_lines = canonical(py["lines"])
go_lines = canonical(json.loads(run_go(task, construction, "--lines")))
if py_lines != go_lines:
fails += 1
print(f"FAIL {name} lines:\n PY: {py_lines}\n GO: {go_lines}")
# store resolution parity (env verbatim / repo-root default)
py_store = py["store"]
go_store = run_go("x", construction, "--store")
if py_store != go_store:
fails += 1
print(f"FAIL {name} store: PY {py_store!r} GO {go_store!r}")
print(f"ok {name}: route={py_dict.get('task_route')} floor={py_dict.get('floor')} "
f"lines={len(py['lines'])} constraints={len(py_dict.get('constraints', []))}")
# selector observables (Python-side contract; Go pins via compile-time
# singleton + the frozen abstention rows)
py = run_python("selector probe", str(FIX / "store_active"))
if not py["selector_identity"]:
fails += 1
print("FAIL selector identity: _get_selector() is not a singleton")
if py["default_selector"] != "MemorySelector":
fails += 1
print(f"FAIL default selector: {py['default_selector']!r} != 'MemorySelector'")
if py["retrieve_memory"] != []:
fails += 1
print(f"FAIL retrieve under isolated HOME: {py['retrieve_memory']!r} != []")
print("ok selector: singleton identity, MemorySelector default, abstention []")
if fails:
print(f"PARITY FAILED: {fails} divergence(s)")
return 1
print(f"PARITY OK: {len(CASES)} case families byte-equal (dict + markdown + lines + store)")
return 0
if __name__ == "__main__":
sys.exit(main())
+92
View File
@@ -0,0 +1,92 @@
#!/usr/bin/env python3
"""check_cache_parity.py — live CLI parity: the Python oracle
(python -m rune.cache) vs the Go port (built binary) over the same argv
matrix, each in its own throwaway memory dir. Byte-for-byte stdout with
ISO timestamps and age values normalized (both engines render real
clocks). Covers every ported fn through the CLI surface: put_cache,
get_cache, invalidate, invalidate_scope, invalidate_all, cache_stats,
handle_hook, main (usage gates, --json/plain rendering, ensure_ascii).
"""
import json
import os
import re
import subprocess
import sys
import tempfile
from pathlib import Path
REPO = Path(__file__).resolve().parent.parent
GO_BIN = Path(tempfile.mkdtemp(prefix="cache-parity-")) / "cache"
TS_RE = re.compile(r"\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?\+00:00")
AGE_RE = re.compile(r'"age_seconds": [0-9.e+-]+')
AGE_S_RE = re.compile(r"\(age: \d+s\)")
def normalize(s: str) -> str:
s = TS_RE.sub("<TS>", s)
s = AGE_RE.sub('"age_seconds": <AGE>', s)
return AGE_S_RE.sub("(age: <AGE>s", s)
MATRIX = [
["put", "alpha", "Alpha value line one\nAlpha line two"],
["put", "beta", "Beta retrieval value", "--scope", "retrieval", "--source-hash", "src-1", "--json"],
["put", "uni-ü", "Wörter with ümlaut", "--json"],
["get", "alpha", "--json"],
["get", "alpha"],
["get", "uni-ü", "--json"],
["get", "missing-key"],
["get"],
["put", "only-key"],
["invalidate", "alpha", "--reason", "stale", "--json"],
["invalidate-scope", "retrieval", "--json"],
["invalidate-all", "--json"],
["stats"],
["stats", "--json"],
["hook", "--event", "memory.created", "--data", '{"x": 1}'],
["hook"],
]
def py_run(argv: list[str], mem: str) -> str:
env = dict(os.environ, RUNE_MEMORY_DIR=mem, PYTHONPATH=str(REPO / "src"))
r = subprocess.run([sys.executable, "-m", "rune.cache", *argv],
capture_output=True, text=True, cwd=REPO, env=env)
if r.returncode != 0:
sys.exit(f"oracle CLI {argv} failed: {r.stderr}")
return r.stdout
def go_run(argv: list[str], mem: str) -> str:
env = dict(os.environ, RUNE_MEMORY_DIR=mem)
r = subprocess.run([str(GO_BIN), *argv], capture_output=True, text=True, cwd=REPO, env=env)
if r.returncode != 0:
sys.exit(f"go CLI {argv} failed: {r.stderr}")
return r.stdout
def main() -> int:
build = subprocess.run(["go", "build", "-o", str(GO_BIN), "."],
cwd=REPO / "src/go/cache", capture_output=True, text=True)
if build.returncode != 0:
sys.exit(f"go build failed: {build.stderr}")
py_mem = tempfile.mkdtemp(prefix="cache-parity-py-")
go_mem = tempfile.mkdtemp(prefix="cache-parity-go-")
passed = 0
for argv in MATRIX:
py_out = normalize(py_run(argv, py_mem))
go_out = normalize(go_run(argv, go_mem))
if py_out != go_out:
print(f"FAIL {' '.join(argv)}\n py: {py_out!r}\n go: {go_out!r}")
return 1
passed += 1
print(f"PASS {' '.join(json.dumps(a, ensure_ascii=False) for a in argv)}")
print(f"LIVE PARITY 100% ({passed}/{len(MATRIX)} cases)")
return 0
if __name__ == "__main__":
sys.exit(main())
@@ -0,0 +1,378 @@
#!/usr/bin/env python3
"""Live parity: capability_broker gap-closing ports vs the Python oracle
(dichotomy wave, contract BUILDER-2026-10-13T16:01:25Z-9b9389-factory-gap-cb).
Layers:
1. FROZEN — frozen_gap_truth.json (generated by
scripts/gen_capability_broker_gap_truth.py against the LIVE oracle with
RUNE_CAPABILITY_BROKER_CORE=python pinned) replayed through the ctypes
FFI cb_* entries case by case, deep-copied, threading the fixture state
exactly as the oracle's replayable-script sequence did.
2. FUZZ — seeded random manifests/registries/queries/hooks (seed 2479)
per kernel: oracle floor vs FFI, exact compare.
3. LIVE — dual-fixture: the oracle runs on fixture home A, the FFI on
fixture home B, both canonical-seeded; results identical.
Exit 0 only at 100% parity on the gap-closing functions.
Run: python3 scripts/check_capability_broker_gap_parity.py
Needs: cargo build --release in src/rust/capability_broker (the .so).
"""
import copy
import json
import os
import random
import shutil
import sys
from pathlib import Path
REPO = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(REPO / "src"))
from rune import broker_loader # noqa: E402
from rune import capability_broker as cb # noqa: E402
TRUTH_PATH = REPO / "src" / "rust" / "capability_broker" / "frozen_gap_truth.json"
HOME_A = Path("/tmp/rune_cb_parity_a")
HOME_B = Path("/tmp/rune_cb_parity_b")
# Pin the oracle's module-level card I/O onto fixture A (the module constants
# resolved at import; the FFI layer gets the same values as explicit paths).
CB_REGISTRY = HOME_A / "src" / "rune" / ".microkernel.json"
CB_CARDS = HOME_A / "memory" / "index" / "capability_cards.json"
# Pinned staleness epochs (fixture law — no wall-clock timing luck; mirrors
# the generator's os.utime pins).
FIXED_SEED_MTIME = 1_000_000_000.0
FIXED_REGISTRY_MTIME = 1_000_000_100.0
fails: list[str] = []
counts = {"frozen": 0, "fuzz": 0, "live": 0}
def fail(layer, name, detail):
fails.append(f"[{layer}] {name}: {detail}")
print(f"FAIL[{layer}] {name}: {detail}")
def j(x):
return json.dumps(x, sort_keys=True, ensure_ascii=True)
def check(layer, name, want, got):
counts[layer] += 1
if j(want) != j(got):
fail(layer, name, f"want={j(want)}\n got={j(got)}")
def oracle_tools():
try:
from rune.tool_executor import TOOLS
except ImportError:
from tool_executor import TOOLS
return list(TOOLS)
def build_fixture(home: Path) -> tuple[str, str]:
shutil.rmtree(home, ignore_errors=True)
registry = home / "src" / "rune" / ".microkernel.json"
cards = home / "memory" / "index" / "capability_cards.json"
registry.parent.mkdir(parents=True)
cards.parent.mkdir(parents=True)
registry.write_text(json.dumps(_registry_content()))
cards.write_text(json.dumps([{"name": "seed-stale", "description": "seed",
"capabilities": ["seed_cap"], "file": "seed.py",
"full_path": "plugins/seed/seed.py", "priority": 3,
"semantic_examples": [], "risk": "read-only",
"auto_invoked": False, "hooks": [],
"searchable_text": "seed stale card"}]))
os.utime(cards, (FIXED_SEED_MTIME, FIXED_SEED_MTIME))
os.utime(registry, (FIXED_REGISTRY_MTIME, FIXED_REGISTRY_MTIME))
return str(registry), str(cards)
def _registry_content():
"""The canonical fixture registry — the frozen truth carries its VALUE
(the load_registry case); read from the truth so the fixture and the
corpus can never drift apart."""
truth = json.loads(TRUTH_PATH.read_text())
for case in truth["cases"]:
if case["fn"] == "load_registry":
return case["expected"]
raise RuntimeError("load_registry case missing from the frozen truth")
def b_paths():
return build_fixture_b[0], build_fixture_b[1]
def b_registry_path():
return build_fixture_b[0]
def b_cards_path():
return build_fixture_b[1]
build_fixture_b: tuple[str, str] = ("", "")
def oracle_call(fn, a):
return {
"generate_card": lambda: cb.generate_card(a["name"], a["manifest"]),
"build_cards": lambda: cb.build_cards(),
"load_registry": lambda: cb.load_registry(),
"cards_are_stale": lambda: cb._cards_are_stale(),
"native_tool_schemas": lambda: cb._native_tool_schemas(),
"match_capabilities": lambda: cb.match_capabilities(a["query"], a["top_k"]),
"handle_hook": lambda: cb.handle_hook(a["event"], a["data"]),
}[fn]()
def ffi_call(fn, a):
return {
"generate_card": lambda: broker_loader.generate_card(a["name"], a["manifest"]),
"build_cards": lambda: broker_loader.build_cards(b_registry_path()),
"load_registry": lambda: broker_loader.load_registry(b_registry_path()),
"cards_are_stale": lambda: broker_loader.cards_are_stale(b_cards_path(), b_registry_path()),
"native_tool_schemas": lambda: broker_loader.native_tool_schemas(a["tools"]),
"match_capabilities": lambda: broker_loader.match_capabilities(
a["cards"], a["query"], a["top_k"]),
"handle_hook": lambda: broker_loader.handle_hook(a["event"], a["data"], a["cards"]),
}[fn]()
# ── layer 1: FROZEN replay through the FFI ──────────────────────────────────
def replay_frozen() -> None:
truth = json.loads(TRUTH_PATH.read_text())
cases = truth["cases"]
reg_b, cards_b = build_fixture(HOME_B)
build_fixture_b = (reg_b, cards_b)
globals()["build_fixture_b"] = build_fixture_b
tools = oracle_tools()
tools_from_truth: list | None = None
cards_state: list = []
for idx, case in enumerate(cases):
fn, args = case["fn"], copy.deepcopy(case["args"])
want = case["expected"]
label = f"#{idx} {fn}"
try:
if fn == "_cards_are_stale":
got = broker_loader.cards_are_stale(cards_b, reg_b)
elif fn == "load_cards":
t = tools if tools_from_truth is None else tools_from_truth
got = broker_loader.load_cards(cards_b, reg_b, t)
cards_state = copy.deepcopy(got)
elif fn == "build_cards":
got = broker_loader.build_cards(reg_b)
elif fn == "load_registry":
got = broker_loader.load_registry(reg_b)
elif fn == "_native_tool_schemas":
got = broker_loader.native_tool_schemas(tools)
tools_from_truth = (
[copy.deepcopy(v) for v in got.values()]
if isinstance(got, dict) else []
)
elif fn == "generate_card":
got = broker_loader.generate_card(args[0], args[1])
elif fn == "_py_score_card":
# in-process kernel contract — the same cs arithmetic the
# oracle reaches through cs_loader
from rune import cs_loader
got = cs_loader.score_card(args[0], args[1])
elif fn == "match_capabilities":
got = broker_loader.match_capabilities(cards_state, args[0], int(args[1]))
elif fn == "handle_hook":
got = broker_loader.handle_hook(
args[0], args[1] if len(args) > 1 else {}, cards_state)
else:
fail("frozen", label, "no FFI mapping")
continue
check("frozen", label, want, got)
except Exception as exc: # noqa: BLE001 — the envelope err surfaced as a raise
fail("frozen", label, f"FFI raised: {type(exc).__name__}: {exc}")
# ── layer 2: seeded fuzz, oracle floor vs FFI ───────────────────────────────
CAP_POOL = ["memory_recall", "memory_write", "claim_verification", "warm_routing",
"politics", "research", "tasks", "cache", "epistemic_verify"]
WORDS = ["memory", "store", "this", "decision", "verify", "claim", "drift",
"cache", "route", "task", "file", "lint", "query", "remember", "zzz"]
def random_manifest(rng):
m = {}
if rng.random() < 0.9:
m["description"] = " ".join(rng.choice(WORDS) for _ in range(rng.randint(0, 8)))
if rng.random() < 0.8:
m["capabilities"] = rng.sample(CAP_POOL, rng.randint(0, 3))
if rng.random() < 0.4:
m["hooks"] = {"on_message": "handle_hook"}
if rng.random() < 0.5:
m["priority"] = rng.choice([1, 4, 10, 100, 2.5, 7])
if rng.random() < 0.5:
m["_file"] = rng.choice(["main.py", "plugins/x/main.py", ""])
return m
def replay_fuzz() -> None:
rng = random.Random(2479)
build_fixture(HOME_B) # canonical registry under fixture B for build_cards
for i in range(200):
name = f"plug{i}"
manifest = random_manifest(rng)
try:
want = cb.generate_card(name, copy.deepcopy(manifest))
except Exception as exc: # noqa: BLE001
want = {"__raise__": type(exc).__name__}
try:
got = broker_loader.generate_card(name, copy.deepcopy(manifest))
except Exception as exc: # noqa: BLE001
got = {"__raise__": type(exc).__name__}
check("fuzz", f"generate_card#{i}", want, got)
for i in range(60):
plugins = {}
for p in range(rng.randint(0, 5)):
if rng.random() < 0.85:
plugins[f"plug{p}"] = {"manifest": random_manifest(rng)}
else:
plugins[f"plug{p}"] = {"active": False}
build_fixture(HOME_A) # fresh dirs on both sides each iteration
reg_b, _ = build_fixture(HOME_B)
Path(CB_REGISTRY).write_text(json.dumps({"plugins": plugins}))
reg_b2, _2 = b_paths()
Path(reg_b2).write_text(json.dumps({"plugins": plugins}))
want = cb.build_cards()
got = broker_loader.build_cards(reg_b2)
check("fuzz", f"build_cards#{i}", want, got)
# canonical restore + rebuild both sides once (deterministic card pool)
build_fixture(HOME_A)
reg_b, cards_b = build_fixture(HOME_B)
build_fixture_b = (reg_b, cards_b)
globals()["build_fixture_b"] = build_fixture_b
cb_cards = cb.load_cards()
ffi_cards = broker_loader.load_cards(cards_b, reg_b, oracle_tools())
check("fuzz", "card_pool", cb_cards, ffi_cards)
for i in range(60):
query = " ".join(rng.choice(WORDS) for _ in range(rng.randint(0, 6)))
top_k = rng.choice([1, 3, 5, 10])
want = cb.match_capabilities(query, top_k)
got = broker_loader.match_capabilities(ffi_cards, query, top_k)
check("fuzz", f"match#{i}", want, got)
for i in range(60):
event = "on_message" if rng.random() < 0.67 else "other"
data: dict = {}
if rng.random() < 0.85:
data["message"] = " ".join(rng.choice(WORDS) for _ in range(rng.randint(0, 5)))
if rng.random() < 0.3:
data["text"] = " ".join(rng.choice(WORDS) for _ in range(rng.randint(0, 5)))
if rng.random() < 0.2:
data.pop("message", None)
data["status"] = "error state" if rng.random() < 0.5 else ""
if event == "other" and rng.random() < 0.5:
data = {}
try:
want = cb.handle_hook(event, copy.deepcopy(data))
except Exception as exc: # noqa: BLE001
want = {"__raise__": type(exc).__name__}
try:
got = broker_loader.handle_hook(event, copy.deepcopy(data), ffi_cards)
except Exception as exc: # noqa: BLE001
got = {"__raise__": type(exc).__name__}
check("fuzz", f"hook#{i}", want, got)
# staleness flip, rebuilt identically on both sides (20× both arms)
for i in range(20):
reg_a, cards_a = build_fixture(HOME_A)
reg_b, cards_b = build_fixture(HOME_B)
build_fixture_b = (reg_b, cards_b)
globals()["build_fixture_b"] = build_fixture_b
want = cb._cards_are_stale()
got = broker_loader.cards_are_stale(cards_b, reg_b)
check("fuzz", f"stale_pre#{i}", want, got)
cb.load_cards() # atomic rebuild mutates fixture A
broker_loader.load_cards(cards_b, reg_b, oracle_tools()) # mutates B
want = cb._cards_are_stale()
got = broker_loader.cards_are_stale(cards_b, reg_b)
check("fuzz", f"stale_post#{i}", want, got)
# ── layer 3: LIVE dual-fixture battery ──────────────────────────────────────
def run_live() -> None:
reg_a, _ = build_fixture(HOME_A)
reg_b, cards_b = build_fixture(HOME_B)
build_fixture_b = (reg_b, cards_b)
globals()["build_fixture_b"] = build_fixture_b
tools = oracle_tools()
pairs = [
("load_registry", {}),
("build_cards", {}),
("native_tool_schemas", {"tools": tools}),
("cards_are_stale", {}),
]
for fn, a in pairs:
check("live", fn, oracle_call(fn, a), ffi_call(fn, a))
# match/hook: identical card material on both sides — drive the FFI
# rebuild first (the oracle's load_cards below mutates A the same way)
ffi_index = broker_loader.load_cards(cards_b, reg_b, tools)
check("live", "index_bytes", cb.load_cards(), ffi_index)
cards = copy.deepcopy(ffi_index)
for i, query in enumerate([
"recall and store memory facts", "verify this claim", "route this task",
"find files matching a pattern", "zzz nothing", "cache this result",
]):
check("live", f"match#{i}",
cb.match_capabilities(query, 5),
broker_loader.match_capabilities(cards, query, 5))
for i, (event, data) in enumerate([
("on_message", {"message": "verify this claim about drift"}),
("other", {"message": "hello world"}),
("on_message", {"status": "error state"}),
]):
check("live", f"hook#{i}",
cb.handle_hook(event, copy.deepcopy(data)),
broker_loader.handle_hook(event, copy.deepcopy(data), cards))
def main() -> int:
if not broker_loader.available():
print("broker_loader .so missing — cargo build --release in "
"src/rust/capability_broker")
return 2
# The oracle floor reads RUNE_CAPABILITY_BROKER_CORE — pin pure Python so
# the facade runs the ORACLE arms (the FFI layer is driven directly).
os.environ["RUNE_CAPABILITY_BROKER_CORE"] = "python"
cb.REGISTRY = str(CB_REGISTRY)
cb.CARDS_FILE = str(CB_CARDS)
for p in (HOME_A, HOME_B):
shutil.rmtree(p, ignore_errors=True)
replay_frozen()
replay_fuzz()
run_live()
total = sum(counts.values())
print(f"parity: {total - len(fails)}/{total} checks OK "
f"(frozen={counts['frozen']} fuzz={counts['fuzz']} live={counts['live']})")
if fails:
print(f"FAILURES: {len(fails)}")
return 1
print("LIVE PARITY 100% on the gap-closing functions")
return 0
if __name__ == "__main__":
raise SystemExit(main())
+259
View File
@@ -0,0 +1,259 @@
#!/usr/bin/env python3
"""Live parity: claim_audit Rust core vs Python oracle (dichotomy wave,
close-PARTIAL gap pass). Layers:
1. FROZEN — the gap truth corpus (src/rust/claim_audit/frozen_truth.json,
generated by scripts/gen_claim_audit_truth.py under the
scripts/ca_freeze_seams rig against the LIVE oracle): every row
replayed through the ctypes FFI of the NEW claim_audit cdylib, case
by case. The main() CLI rows (recorded via argv patching — the
harness cannot call a no-arg main) replay through ca_main with the
same argv shapes against the scratch journal.
2. FUZZ — seeded reframe/scan/degrade sweeps (seed 2479): oracle vs FFI
kernel, exact compare.
3. LIVE — dual-mode facade battery: the same audit()/scan_text() calls
executed through the oracle module directly (Python floor) and
through the FFI kernel; results must be identical.
Exit 0 only at 100% parity on the gap-closing functions.
"""
import copy
import ctypes
import io
import json
import os
import random
import sys
from contextlib import redirect_stdout
from pathlib import Path
REPO = Path(__file__).resolve().parents[1]
# The rig must import FIRST (it wipes + reseeds the scratch store at import).
sys.path.insert(0, str(REPO / "scripts" / "ca_freeze_seams"))
sys.path.insert(0, str(REPO / "src"))
import sitecustomize # noqa: F401,E402 (the ca_freeze_seams rig)
os.environ["PYTHONHASHSEED"] = "0"
import rune.claim_audit as oracle # noqa: E402
LIB = REPO / "src" / "rust" / "claim_audit" / "target" / "release" / "libclaim_audit.so"
if not LIB.is_file():
sys.exit("FATAL: Rust core not built — cargo build --release in src/rust/claim_audit")
GRAPH = oracle.ca_graph_db
NEURONS = copy.deepcopy(oracle.ca_neurons)
oracle.JOURNAL = oracle.ca_journal_path
TRUTH = json.loads(
(REPO / "src" / "rust" / "claim_audit" / "frozen_truth.json").read_text())
fails: list[str] = []
counts = {"frozen": 0, "fuzz": 0, "live": 0}
def fail(layer, name, detail):
fails.append(f"[{layer}] {name}: {detail}")
print(f"FAIL[{layer}] {name}: {detail}"[:400])
def j(x):
return json.dumps(x, sort_keys=True, ensure_ascii=True)
def check(layer, name, want, got):
counts[layer] += 1
if j(want) != j(got):
fail(layer, name, f"want={j(want)[:300]} got={j(got)[:300]}")
# ── FFI ──────────────────────────────────────────────────────────────────────
_lib = ctypes.CDLL(str(LIB))
def _call(sym, payload):
fn = getattr(_lib, sym)
fn.argtypes = [ctypes.c_void_p]
fn.restype = ctypes.c_void_p
data = json.dumps(payload).encode()
buf = ctypes.create_string_buffer(data)
ptr = fn(ctypes.cast(buf, ctypes.c_void_p))
if not ptr:
raise RuntimeError(f"{sym} returned null")
out = ctypes.string_at(ptr).decode()
doc = json.loads(out)
if not doc.get("ok"):
raise RuntimeError(doc.get("err", f"{sym} failed"))
return doc["value"]
def ffi_reframe(text):
return _call("ca_reframe", {"text": text})
def ffi_scan(text):
return _call("ca_scan", {"text": text})
def ffi_graph_has(term):
return _call("ca_graph_has", {"term": term, "graph_db": GRAPH})
def ffi_warm_has(term):
return _call("ca_warm_has", {"term": term, "neurons": NEURONS})
def ffi_verify(claim):
return _call("ca_verify", {"claim": claim, "graph_db": GRAPH, "neurons": NEURONS})
def ffi_degrade(claim, verdict):
return _call("ca_degrade", {"claim": claim, "verdict": verdict})
def ffi_report(rows):
return _call("ca_report", {"rows": rows})
def ffi_audit(draft):
return _call("ca_audit", {"draft": draft, "graph_db": GRAPH, "neurons": NEURONS})
def ffi_scan_text(text):
return _call("ca_scan_text", {"text": text, "graph_db": GRAPH, "neurons": NEURONS})
def ffi_symmetry_safe(text):
return _call("ca_symmetry_safe", {"text": text})
def ffi_handle_hook(event, data=None):
return _call("ca_handle_hook", {"event": event, "data": data})
def ffi_main(payload):
return _call("ca_main", payload)
# ── layer 1: FROZEN ──────────────────────────────────────────────────────────
for row in TRUTH:
fn, args = row["fn"], row["args"]
if fn == "reframe":
check("frozen", f"reframe{args}", row["expected"], ffi_reframe(*args))
elif fn == "_graph_has":
check("frozen", f"_graph_has{args}", row["expected"], ffi_graph_has(*args))
elif fn == "_warm_has":
check("frozen", f"_warm_has{args}", row["expected"], ffi_warm_has(*args))
elif fn == "verify":
v, hits = oracle.verify(*args)
check("frozen", f"verify{args}", {"verdict": v, "evidence_hits": hits},
ffi_verify(*args))
elif fn == "_symmetry_safe":
check("frozen", f"_symmetry_safe{args}", row["expected"], ffi_symmetry_safe(*args))
elif fn == "handle_hook":
check("frozen", f"handle_hook{args}", row["expected"], ffi_handle_hook(*args))
# main() CLI rows: same argv shapes the generator recorded, replayed through
# ca_main against the scratch journal (isolated IO).
oracle.JOURNAL = oracle.ca_journal_path
if os.path.exists(oracle.JOURNAL):
os.remove(oracle.JOURNAL)
def run_main(argv):
saved = sys.argv
sys.argv = argv
buf = io.StringIO()
with redirect_stdout(buf):
oracle.main()
sys.argv = saved
return buf.getvalue()
MAIN_ARGV = [
["claim_audit.py", "reframe", "we have exceeded the frontier."],
["claim_audit.py", "scan", "We definitely beat everyone."],
["claim_audit.py", "verify", "the sky is blue"],
["claim_audit.py", "audit", "We definitely beat everyone."],
["claim_audit.py", "report"],
["claim_audit.py", "hook", "--event", "on_response", "--data", json.dumps({"k": "v"})],
]
for argv in MAIN_ARGV:
want = run_main(list(argv))
payload = {"argv": list(argv), "graph_db": GRAPH, "neurons": NEURONS}
if len(argv) > 1 and argv[1] == "report":
with open(oracle.JOURNAL) as f:
payload["rows"] = [json.loads(line) for line in f if line.strip()]
got = ffi_main(payload)["output"]
# ca_main returns the printed body without the trailing newline
if want.endswith("\n") and not got.endswith("\n"):
got = got + "\n"
check("frozen", f"main{argv[1]}", want, got)
# ── layer 2: FUZZ (seed 2479) ────────────────────────────────────────────────
rng = random.Random(2479)
WORDS = ["Kubernetes", "Letta", "zebraquant", "pods", "memory", "frontier",
"recall", "cluster", "archival", "benchmark"]
REFRAME_T = ["we have exceeded {} in speed", "The {} is definitely fast",
"We beat {} soundly", "plain text about {}", ""]
for i in range(60):
w = rng.choice(WORDS)
# reframe fuzz
t = rng.choice(REFRAME_T).format(w)
check("fuzz", f"reframe#{i}", oracle.reframe(t), ffi_reframe(t))
# scan fuzz
s = f"{rng.choice(WORDS)} is {rng.choice(['definitely', 'probably', 'never', 'always'])} {rng.choice(WORDS)}."
check("fuzz", f"scan#{i}", oracle.scan(s), ffi_scan(s))
DEGRADE_CLAIMS = ["we have exceeded Letta's recall", "It is definitely 10x faster.",
"the sky is blue", "We never ship bugs", "solid work, measured twice"]
for i in range(20):
c = rng.choice(DEGRADE_CLAIMS)
v = rng.choice(["PASS", "DEGRADE"])
want_t, want_n = oracle.degrade(c, v)
got = ffi_degrade(c, v)
check("fuzz", f"degrade#{i}", {"text": want_t, "note": want_n}, got)
# verify fuzz over ledger-anchored + unanchored claims
VERIFY_CLAIMS = ["Kubernetes measured at 99%",
"Letta memory layers use archival recall, as measured",
"we have exceeded the frontier",
"zebraquant fiber optics need calibration",
"the sky is blue"]
for i in range(15):
c = rng.choice(VERIFY_CLAIMS)
want_v, want_h = oracle.verify(c)
got = ffi_verify(c)
check("fuzz", f"verify#{i}", {"verdict": want_v, "evidence_hits": want_h}, got)
# ── layer 3: LIVE (dual-mode facade) ─────────────────────────────────────────
DRAFTS = [
"We definitely beat everyone. The sky is blue.",
"Kubernetes pods restart automatically on failure, as measured.",
"plain text with no strong claims at all",
"We have exceeded Letta's recall by 10x.",
]
for i, d in enumerate(DRAFTS):
want = oracle.audit(d)
# strip the journal side-effect shape: compare the returned dicts
got = ffi_audit(d)
check("live", f"audit#{i}", want, got)
want_st = oracle.scan_text(d)
got_st = ffi_scan_text(d)
check("live", f"scan_text#{i}", want_st, got_st)
# report() reads the journal file (IO stays Python) — parity is on the
# aggregation kernel over the same rows:
with open(oracle.JOURNAL) as f:
journal_rows = [json.loads(line) for line in f if line.strip()]
check("live", "report-kernel", oracle.report(), ffi_report(journal_rows))
print(f"parity: frozen={counts['frozen']} fuzz={counts['fuzz']} live={counts['live']} "
f"fails={len(fails)}")
sys.exit(1 if fails else 0)
@@ -0,0 +1,128 @@
#!/usr/bin/env python3
"""Live parity: construction_interface Rust kernels vs the frozen oracle
truth (dichotomy wave, contract factory-gap-ci). Layers:
1. FROZEN — the frozen truth corpora (frozen_ci_truth.json 85 cases +
frozen_ci_truth_hash.json 5 shape-pinned cases, generated by
scripts/gen_construction_interface_truth.py against the LIVE Python
oracle through the scripts/ci_freeze_seams rig) replayed through
the ci_replay ctypes FFI entry of the built cdylib, case by case.
2. LIVE — a fresh re-freeze of the oracle through the same rig in a
subprocess; the regenerated corpora must be byte-identical to the
committed files (the oracle is still the parity authority while the
strangler runs).
Exit 0 only at 100% parity (85 verbatim + 5 shape-pinned + byte-identical
re-freeze).
"""
import ctypes
import json
import os
import subprocess
import sys
import tempfile
from pathlib import Path
REPO = Path(__file__).resolve().parents[1]
CRATE = REPO / "src" / "rust" / "construction_interface"
LIB = CRATE / "target" / "release" / "libconstruction_interface.so"
FROZEN = CRATE / "frozen_ci_truth.json"
FROZEN_HASH = CRATE / "frozen_ci_truth_hash.json"
HASH_ID_PREFIXES = (
"contract:", "regression:", "verification:",
"composition:", "acquisition:",
)
def normalize_hash_ids(obj):
if isinstance(obj, str):
kind, _, digits = obj.partition(":")
if (f"{kind}:" in HASH_ID_PREFIXES and digits
and len(digits) <= 8 and digits.isdigit()):
return f"{kind}:#"
return obj
if isinstance(obj, list):
return [normalize_hash_ids(v) for v in obj]
if isinstance(obj, dict):
return {k: normalize_hash_ids(v) for k, v in obj.items()}
return obj
def replay(lib, case):
payload = json.dumps(case, separators=(",", ":")).encode()
ptr = lib.ci_replay(payload, len(payload))
if not ptr:
raise RuntimeError("ci_replay returned NULL")
text = ctypes.c_char_p(ptr).value.decode()
lib.ci_free_string(ptr)
return json.loads(text)
def frozen_layer():
lib = ctypes.CDLL(str(LIB))
lib.ci_replay.argtypes = [ctypes.c_char_p, ctypes.c_size_t]
lib.ci_replay.restype = ctypes.c_void_p
lib.ci_free_string.argtypes = [ctypes.c_void_p]
lib.ci_free_string.restype = None
ok = 0
cases = json.loads(FROZEN.read_text())
for case in cases:
got = replay(lib, case)
assert got == case["expected"], (
f"FROZEN divergence: {case['fn']} "
f"{case['args'][0] if case['args'] else '?'}")
ok += 1
hash_ok = 0
for case in json.loads(FROZEN_HASH.read_text()):
got = normalize_hash_ids(replay(lib, case))
want = normalize_hash_ids(case["expected"])
assert got == want, (
f"HASH divergence: {case['fn']} "
f"{case['args'][0] if case['args'] else '?'}")
hash_ok += 1
print(f"FROZEN: PARITY OK {ok}/{len(cases)} verbatim "
f"+ {hash_ok} hash-shape cases")
return ok, hash_ok
def main() -> int:
committed_main = FROZEN.read_bytes()
committed_hash = FROZEN_HASH.read_bytes()
n_main, n_hash = frozen_layer()
with tempfile.TemporaryDirectory(prefix="ci_gap_parity_") as _scratch:
# the re-freeze must run at the CANONICAL rig home — the mini-doc
# paths are embedded in the frozen truth, so a different
# CI_FREEZE_HOME changes the bytes without changing behavior
home = "/tmp/ci_gap_freeze_home"
subprocess.run(["rm", "-rf", home], check=True)
env = dict(
os.environ,
CI_FREEZE_HOME=home,
PYTHONPATH="scripts/ci_freeze_seams:src",
CS_RUST_LIB="/mnt/workdrive/rune/src/rust/capability_scoring/"
"target/release/libcapability_scoring.so",
)
r = subprocess.run(
[sys.executable, "scripts/gen_construction_interface_truth.py"],
cwd=str(REPO), env=env, capture_output=True, text=True, timeout=600)
if r.returncode != 0:
print(r.stdout[-2000:])
print(r.stderr[-2000:])
print("LIVE: re-freeze FAILED")
return 1
same_main = FROZEN.read_bytes() == committed_main
same_hash = FROZEN_HASH.read_bytes() == committed_hash
if not (same_main and same_hash):
print(f"LIVE: re-freeze NOT byte-identical "
f"(main={same_main} hash={same_hash})")
return 1
print(f"LIVE: fresh re-freeze byte-identical "
f"({n_main}+{n_hash} cases, oracle authority held)")
print("PARITY OK construction_interface")
return 0
if __name__ == "__main__":
sys.exit(main())
+190
View File
@@ -0,0 +1,190 @@
#!/usr/bin/env python3
"""check_construction_mode_parity.py — live parity: the Rust construction_mode
core (.so via cm_loader) vs the live Python oracle, 100% on the full gap
surface (dichotomy wave #2479 gap close).
Corpus: the frozen envelope (frozen_cm_truth.json — 36 classify cases, 3
to_dict receiver cases, 5 from_dict projections, 3 error shapes) replayed
against BOTH sides live, plus the invalid-override ValueError crash-parity
case (un-freezable through the shared harness; compared here).
The oracle side runs in a SUBPROCESS with PYTHONHASHSEED=0 — the oracle's
lexicons are Python sets, so multi-hit evidence order is hash-random per
process and the deterministic contract is the seed-0 order the Rust
arrays reproduce (memory_consolidation precedent; the truth generator
re-execs itself under the same seed).
Usage: python3 scripts/check_construction_mode_parity.py
Exit 0 iff every case matches on BOTH sides (and the frozen expected).
"""
from __future__ import annotations
import json
import os
import subprocess
import sys
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(ROOT / "src"))
from rune import cm_loader # noqa: E402
ENV = ROOT / "src" / "rust" / "construction_mode" / "src" / "frozen_cm_truth.json"
ORACLE_HELPER = r"""
import json, sys, os
sys.path.insert(0, %(src)r)
os.environ["RUNE_CM_CORE"] = "python"
os.environ["RUNE_CONSTRUCTION_DECISION_CORE"] = "python"
from rune import construction_mode as cm
CASES = json.load(sys.stdin)["CASES"]
out = {"classify": [], "to_dict": [], "from_dict": [], "errors": {}}
for case in CASES["classify"]:
d = cm.classify_mode(case["objective"], **case["kwargs"])
out["classify"].append(d.to_dict())
for inst in CASES["to_dict"]:
obj = cm.ConstructionMode.__new__(cm.ConstructionMode)
for k, v in inst.items():
setattr(obj, k, v)
out["to_dict"].append(obj.to_dict())
for d in CASES["from_dict"]:
out["from_dict"].append(cm.ConstructionMode.from_dict(d).to_dict())
try:
cm.ConstructionMode.from_dict({"evidence": []})
except TypeError as e:
out["errors"]["from_dict_missing_mode"] = str(e)
try:
cm.ConstructionMode.from_dict(123)
except TypeError as e:
out["errors"]["from_dict_non_dict"] = str(e)
_broken = cm.ConstructionMode.__new__(cm.ConstructionMode)
_broken.mode = "X"
try:
_broken.to_dict()
except AttributeError as e:
out["errors"]["to_dict_missing_attribute"] = str(e)
try:
cm.classify_mode("anything", explicit_override="MAGIC_MODE")
except ValueError as e:
out["errors"]["classify_invalid_override"] = str(e)
print(json.dumps(out))
"""
FAILS = [0]
def check(label: str, got, want) -> None:
if json.dumps(got, sort_keys=True) != json.dumps(want, sort_keys=True):
FAILS[0] += 1
print(f"MISMATCH {label}")
print(f" rust: {json.dumps(got, sort_keys=True)[:220]}")
print(f" oracle: {json.dumps(want, sort_keys=True)[:220]}")
else:
print(f"ok {label}")
def run_oracle(cases: dict) -> dict:
env = {**os.environ, "PYTHONHASHSEED": "0"}
code = ORACLE_HELPER % {"src": str(ROOT / "src")}
r = subprocess.run(
[sys.executable, "-c", code],
input=json.dumps({"CASES": cases}), capture_output=True, text=True,
env=env, timeout=120,
)
if r.returncode != 0:
print("ORACLE SUBPROCESS FAILED:", r.stderr[-500:])
sys.exit(1)
return json.loads(r.stdout)
def rust_classify(objective: str, kwargs: dict) -> dict:
payload = {"objective": objective}
for k, v in kwargs.items():
if v is not None:
payload[k] = v
return cm_loader._call(payload)
def main() -> int:
env = json.loads(ENV.read_text())
classify_cases = []
for case in env["cases"]:
if case["fn"] != "cm_classify_to_dict":
continue
classify_cases.append({
"objective": case["args"][0],
"kwargs": case["kwargs"],
"frozen": case["expected"],
})
to_dict_insts = [
{k: v for k, v in case["recv"].items() if k != "cls"}
for case in env["cases"] if case["fn"] == "ConstructionMode.to_dict"
]
to_dict_frozen = [
case["expected"]["result"]
for case in env["cases"] if case["fn"] == "ConstructionMode.to_dict"
]
from_dict_inputs = [c["args"] for c in env["from_dict_cases"]]
from_dict_frozen = [c["expected"] for c in env["from_dict_cases"]]
oracle = run_oracle({
"classify": [{"objective": c["objective"], "kwargs": c["kwargs"]}
for c in classify_cases],
"to_dict": to_dict_insts,
"from_dict": from_dict_inputs,
})
for i, case in enumerate(classify_cases):
got = rust_classify(case["objective"], case["kwargs"])
check(f"classify[{i}] {case['objective'][:40]!r}", got, oracle["classify"][i])
check(f"classify[{i}] frozen {case['objective'][:40]!r}", got, case["frozen"])
for i, inst in enumerate(to_dict_insts):
got = cm_loader.to_dict(inst)
check(f"to_dict[{i}] {inst['mode']}", got, oracle["to_dict"][i])
check(f"to_dict[{i}] frozen {inst['mode']}", got, to_dict_frozen[i])
for i, d in enumerate(from_dict_inputs):
got = cm_loader.from_dict(d)
check(f"from_dict[{i}]", got, oracle["from_dict"][i])
check(f"from_dict[{i}] frozen", got, from_dict_frozen[i])
shapes = env["error_shapes"]
for key, call in [
("from_dict_missing_mode", lambda: cm_loader.from_dict({"evidence": []})),
("from_dict_non_dict", lambda: cm_loader.from_dict(123)),
("to_dict_missing_attribute", lambda: cm_loader.to_dict({"mode": "X"})),
]:
try:
call()
print(f"MISMATCH {key}: rust returned ok, oracle raises")
FAILS[0] += 1
except RuntimeError as e:
check(f"error[{key}]", str(e), shapes[key])
# invalid override: the facade path raises ValueError before the FFI
# (cm_loader mirrors the oracle's own validation message).
try:
cm_loader.classify("anything", explicit_override="MAGIC_MODE")
print("MISMATCH classify_invalid_override: no ValueError")
FAILS[0] += 1
except ValueError as e:
check("error[classify_invalid_override]", str(e),
oracle["errors"]["classify_invalid_override"])
total = (2 * (len(classify_cases) + len(to_dict_insts) + len(from_dict_inputs))
+ 3 + 1)
if FAILS[0]:
print(f"\nPARITY FAILED: {FAILS[0]} mismatches")
return 1
print(f"\nPARITY OK: 100% — {len(classify_cases)} classify + "
f"{len(to_dict_insts)} to_dict + {len(from_dict_inputs)} from_dict "
f"+ 4 error shapes, rust == oracle == frozen ({total} comparisons)")
return 0
if __name__ == "__main__":
sys.exit(main())
@@ -0,0 +1,522 @@
#!/usr/bin/env python3
"""check_construction_projection_parity.py — live parity for the
construction_projection dichotomy gap close (#2479): the Rust kernel
(.so via cproj_loader) vs the live Python oracle floor vs the frozen
truth — 100% on the full surface.
Structure (single oracle subprocess under the freeze rig, checker process
with the kernel live):
* FROZEN rows (52) — 3-way: kernel | oracle floor | frozen expected;
* FACADE fuzz rows (240 project + 40 minidoc) — the facade called in
the checker process (kernel live) AND in the subprocess (floor) with
the same fake-scaffold/fake-bridge inputs — must agree with each
other and with the loader-direct kernel calls;
* VALIDATE rows — the fuzz projections validated under both kernels;
* CRASH rows — shapes where the oracle raises: the kernel errs, the
facade falls back to the floor and reproduces the identical
exception on BOTH sides.
Usage: python3 scripts/check_construction_projection_parity.py
Exit 0 iff every comparison matches.
"""
from __future__ import annotations
import json
import os
import random
import shutil
import subprocess
import sys
import tempfile
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(ROOT / "src"))
TRUTH = ROOT / "src" / "rust" / "construction_projection" / "src" / "frozen_truth.json"
ORACLE_HELPER = r"""
import copy, json, os, sys, tempfile, shutil
for p in (%(scripts)r, %(src)r):
if p not in sys.path:
sys.path.insert(0, p)
import rune.construction_projection as cp # floor pinned by the rig
from rune import event_wait as ew
from freeze_truth import _run_case
payload = json.load(sys.stdin)
REAL_WAIT = ew.operation_wait
class _FakeScaffold:
def __init__(self, spec):
self._doc = copy.deepcopy(spec.get("load") or {})
if "project_id" in spec:
self.project_id = spec["project_id"]
def load(self):
return copy.deepcopy(self._doc)
def _bridge(bridge):
mode = (bridge or {}).get("__mode__", "none")
def _wait(operation_id):
if mode == "oserr":
raise OSError(2, "bridge data root unreadable (parity-pinned)")
if mode == "runtimeerr":
raise RuntimeError("waitstore not resolvable (parity-pinned)")
if mode == "found":
return dict((bridge or {}).get("record") or {})
return None
return _wait
out = {
"rows": [
_run_case(cp, {"fn": r["fn"], "args": r["args"],
"kwargs": r.get("kwargs", {})})
for r in payload["ROWS"]
],
"facade_project": [],
"facade_entity": [],
"facade_validate": [],
"facade_minidoc": [],
"crash": {},
}
for spec, cid, bridge, kwargs in payload["FACADE_PROJECT"]:
ew.operation_wait = _bridge(bridge)
try:
p = cp.project(_FakeScaffold(spec), cid, **kwargs)
out["facade_project"].append(p)
finally:
ew.operation_wait = REAL_WAIT
for spec, cid, _bridge, _kwargs in payload["FACADE_PROJECT"]:
out["facade_entity"].append(cp._contract_entity(copy.deepcopy(spec["load"] or {}), cid))
# validate rows: over the facade projections (real 24-field shapes)
out["facade_validate"] = [cp.validate(p) for p in out["facade_project"]]
for spec, cid in payload["FACADE_MINIDOC"]:
scratch = tempfile.mkdtemp(prefix="cpjfloor-")
try:
path = cp.write_mini_doc(_FakeScaffold(spec), cid, out_dir=scratch)
out["facade_minidoc"].append({
"file": os.path.basename(str(path)),
"content": open(path, encoding="utf-8").read(),
"projection": cp.project(_FakeScaffold(spec), cid),
})
finally:
shutil.rmtree(scratch, ignore_errors=True)
for kind, args in payload["CRASH"]:
try:
if kind in ("entity_nondict", "entity_null_entities"):
result = cp._contract_entity(args[0], args[1])
elif kind == "validate_nondict":
result = cp.validate(args[0])
elif kind in ("blocker_int", "checkpoint_int"):
result = cp.project(_FakeScaffold({"load": args[0]}), args[1])
elif kind in ("surface_int", "evidence_int"):
result = cp.write_mini_doc(_FakeScaffold({"load": args[0]}), args[1])
else:
raise AssertionError(kind)
out["crash"][kind] = "NO_CRASH:" + json.dumps(result, sort_keys=True)
except Exception as e: # noqa: BLE001 — the crash IS the check
out["crash"][kind] = f"{type(e).__name__}: {e}"
print(json.dumps(out))
"""
FAILS: list = [0]
CHECKS: list = [0]
def check(label, got, want) -> None:
CHECKS[0] += 1
gs = json.dumps(got, sort_keys=True, default=str)
ws = json.dumps(want, sort_keys=True, default=str)
if gs != ws:
FAILS[0] += 1
print(f"MISMATCH {label}\n got: {gs[:260]}\n want: {ws[:260]}")
def fuzz_corpus(n: int, seed: int = 2026) -> list:
"""(spec, contract_id, bridge, kwargs) fuzz rows — adversarial shapes."""
rng = random.Random(seed)
ALPH = "abcxyzΛ中é." # multibyte — the codepoint-truncation quirk
rows = []
def rnd_str(maxlen=40):
return "".join(rng.choice(ALPH) for _ in range(rng.randint(0, maxlen)))
for i in range(n):
ents = []
for k in range(rng.randint(0, 3)):
e = {"id": f"contract:C-{i}-{k}"}
if rng.random() < 0.8:
e["phase"] = rng.choice(["draft", "approved", "verifying", "closed",
"awaiting_approval"])
ids: dict = {}
if rng.random() < 0.7:
ids["construction_mode"] = rng.choice(["BUILD_NEW", "PATCH", ""])
if rng.random() < 0.7:
ids["depth"] = rng.choice(["standard", "deep", 0])
if rng.random() < 0.5:
ids["next_action"] = rng.choice([rnd_str(15), None])
if rng.random() < 0.4:
ids["blocker"] = rng.choice([
{"class": rng.choice(["SCOPE", "BLOCKED"]),
"evidence": rnd_str(150)},
rnd_str(20),
"",
])
if rng.random() < 0.5:
ids["objective"] = rnd_str(50)
if rng.random() < 0.3:
ids["affected_surface"] = "src/" + rnd_str(8) + ".py"
if rng.random() < 0.4:
ids["task_ref"] = "T" + str(rng.randint(0, 200))
e["identities"] = ids
ext: dict = {}
if rng.random() < 0.6:
ext["readiness_canary"] = rng.choice(["ready", None, ""])
if rng.random() < 0.6:
ext["liveness_canary"] = "live"
if rng.random() < 0.6:
ext["exit_canary"] = "exit"
if rng.random() < 0.5:
ext["contract_quality"] = {
rng.choice(["correctly_predicted", "scope_check", "zz_last"]):
rng.choice([0, 3, True, "green"]),
}
if rng.random() < 0.5:
ext["decision_trace"] = {"approval": rng.choice([
{"required": True},
{"required": False, "state": "REQUIRED"},
{"required": 0},
{},
])}
if rng.random() < 0.4:
ext["affected_paths"] = [
"src/" + rnd_str(6) + ".py"
for _ in range(rng.randint(0, 3))
]
if rng.random() < 0.3:
ext["need"] = {"objective": rnd_str(30)}
e["ext"] = ext
if rng.random() < 0.6:
e["checkpoints"] = [
{"evidence": rng.choice(["", rnd_str(140)])}
for _ in range(rng.randint(0, 3))
]
ents.append(e)
spec = {"load": {"entities": ents}}
if rng.random() < 0.8:
spec["project_id"] = f"proj-{i}"
cid = rng.choice([f"C-{i}-0", f"C-{i}-1", ""]) if ents else "C-404"
bridge = rng.choice([
None, {},
{"__mode__": "found", "record": {"status": "W", "wait_id": "w7"}},
{"__mode__": "oserr"},
{"__mode__": "runtimeerr"},
])
kwargs: dict = {}
for k in ("originating_goal_id", "stage", "builder_state",
"verification_state", "checkpoint", "failure_class",
"completion_state"):
if rng.random() < 0.6:
kwargs[k] = rnd_str(10)
if rng.random() < 0.7:
kwargs["operation_id"] = rng.choice(["op-a", ""])
if rng.random() < 0.5:
kwargs["correlation_id"] = "corr"
rows.append((spec, cid, bridge, kwargs))
return rows
def rust_entity(doc, cid):
from rune import cproj_loader
return cproj_loader.contract_entity(doc, cid)
def rust_validate(p):
from rune import cproj_loader
return cproj_loader.validate(p)
def rust_project(entity, cid, waiting_state, live_correlation, kwargs):
from rune import cproj_loader
return cproj_loader.project(
entity if entity is not None else {},
contract_id=cid,
project_id=kwargs.get("project_id", ""),
originating_goal_id=kwargs.get("originating_goal_id", ""),
operation_id=kwargs.get("operation_id", ""),
waiting_state=waiting_state,
live_correlation=live_correlation,
stage=kwargs.get("stage", ""),
builder_state=kwargs.get("builder_state", ""),
verification_state=kwargs.get("verification_state", ""),
checkpoint=kwargs.get("checkpoint", ""),
failure_class=kwargs.get("failure_class", ""),
completion_state=kwargs.get("completion_state", ""),
)
def rust_write_mini_doc(entity, cid, projection):
from rune import cproj_loader
return cproj_loader.write_mini_doc(
entity if entity is not None else {}, cid, projection)
class _KernelScaffold:
"""Fake scaffold for the CHECK process (kernel live)."""
def __init__(self, spec):
import copy
self._doc = copy.deepcopy(spec.get("load") or {})
if "project_id" in spec:
self.project_id = spec["project_id"]
def load(self):
import copy
return copy.deepcopy(self._doc)
def _check_bridge(bridge):
"""Same fake-bridge rule as the rig (duplicated HERE — the parity
contract pins both sides against the same fake, never the real store)."""
mode = (bridge or {}).get("__mode__", "none")
def _wait(operation_id):
if mode == "oserr":
raise OSError(2, "bridge data root unreadable (parity-pinned)")
if mode == "runtimeerr":
raise RuntimeError("waitstore not resolvable (parity-pinned)")
if mode == "found":
return dict((bridge or {}).get("record") or {})
return None
return _wait
def run_oracle(payload: dict) -> dict:
"""The floor side: one subprocess under the freeze rig (oracle = Python)."""
code = ORACLE_HELPER % {"scripts": str(ROOT / "scripts"), "src": str(ROOT / "src")}
env = {
**os.environ,
"PYTHONHASHSEED": "0",
"PYTHONPATH": (
f"{ROOT / 'scripts' / 'cproj_freeze_seams'}:{ROOT / 'scripts'}:{ROOT / 'src'}"
),
"RUNE_CONSTRUCTION_PROJECTION_CORE": "python",
}
r = subprocess.run([sys.executable, "-c", code], input=json.dumps(payload),
capture_output=True, text=True, env=env, timeout=900)
if r.returncode != 0:
print("ORACLE SUBPROCESS FAILED:", r.stderr[-1500:])
sys.exit(1)
return json.loads(r.stdout)
def crash_shapes() -> list:
"""(kind, factory) — the factory builds the floor-call inputs."""
LONG_INT = 5
return [
("entity_nondict", lambda: (42, "X")),
("entity_null_entities", lambda: ({"entities": None}, "X")),
("validate_nondict", lambda: (42,)),
("blocker_int", lambda: (
{"entities": [{"id": "contract:X",
"identities": {"blocker": {"evidence": LONG_INT}}}]}, "X")),
("checkpoint_int", lambda: (
{"entities": [{"id": "contract:X",
"checkpoints": [{"evidence": LONG_INT}]}]}, "X")),
("surface_int", lambda: (
{"entities": [{"id": "contract:X",
"ext": {"affected_paths": LONG_INT}}]}, "X")),
("evidence_int", lambda: (
{"entities": [{"id": "contract:X", "identities": {},
"checkpoints": [{"evidence": "ev"}]}]}, "X")),
]
def main() -> int:
from rune import cproj_loader
if not cproj_loader.available():
print("cproj_loader kernel not built — build "
"src/rust/construction_projection first")
return 1
envelope = json.loads(TRUTH.read_text())
truth_rows = envelope["cases"]
fuzz = fuzz_corpus(240)
facade_minidoc_rows = [(fz[0], fz[1]) for fz in fuzz[:40]]
payload = {
"ROWS": truth_rows,
"FACADE_PROJECT": fuzz,
"FACADE_MINIDOC": facade_minidoc_rows,
"CRASH": [(kind, factory()) for kind, factory in crash_shapes()],
}
oracle = run_oracle(payload)
total = len(truth_rows)
print(f"== frozen rows ({total}) 3-way: kernel | oracle floor | frozen ==")
for i, row in enumerate(truth_rows):
fn, expected = row["fn"], row["expected"]
check(f"frozen[{i}] frozen-vs-oracle {fn}", expected,
oracle["rows"][i]["expected"])
if fn == "cpj_freeze_contract_entity":
doc, cid = row["args"][0], row["args"][1]
check(f"frozen[{i}] contract_entity kernel-vs-frozen",
rust_entity(doc, cid), expected)
check(f"frozen[{i}] contract_entity facade-kernel",
cp_contract_entity(doc, cid), expected)
elif fn == "cpj_freeze_validate":
p = row["args"][0]
check(f"frozen[{i}] validate kernel-vs-frozen",
rust_validate(p), expected)
check(f"frozen[{i}] validate facade-kernel", cp_validate(p), expected)
elif fn == "cpj_freeze_project":
spec, cid = row["args"][0], row["args"][1]
bridge, kwargs = row["args"][2], row["kwargs"]
wrapped = expected
args_full = {**kwargs, "project_id": spec.get("project_id", "")}
entity = rust_entity(spec["load"], cid)
got_kernel = rust_project(entity, cid, wrapped["waiting_state"],
wrapped["live_correlation"], args_full)
check(f"frozen[{i}] project kernel-vs-frozen", got_kernel,
wrapped["projection"])
got_facade = facade_project(spec, cid, bridge, kwargs)
check(f"frozen[{i}] project facade-kernel-vs-frozen", got_facade,
wrapped["projection"])
elif fn == "cpj_freeze_write_mini_doc":
spec, cid = row["args"]
entity = rust_entity(spec["load"], cid)
check(f"frozen[{i}] mini-doc kernel-vs-frozen bytes",
rust_write_mini_doc(entity, cid, row["expected"]["projection"]),
row["expected"]["content"])
check(f"frozen[{i}] mini-doc kernel-vs-frozen name",
f"{cid}.md", row["expected"]["file"])
print(f"== facade both-pins fuzz ({len(fuzz)} project / "
f"{len(facade_minidoc_rows)} mini-doc / {total} validate rows) ==")
for i, (spec, cid, bridge, kwargs) in enumerate(fuzz):
want = oracle["facade_project"][i]
got_facade = facade_project(spec, cid, bridge, kwargs)
check(f"facade fuzz[{i}]", got_facade, want)
args_full = {**kwargs, "project_id": spec.get("project_id", "")}
entity = rust_entity(spec["load"], cid)
got_kernel = rust_project(entity, cid, want["waiting_state"],
want["correlation_id"], args_full)
check(f"kernel-direct fuzz[{i}]", got_kernel, want)
for i, p in enumerate(oracle["facade_project"][:40]):
check(f"validate fuzz[{i}]", cp_validate(p), oracle["facade_validate"][i])
check(f"validate kernel-direct fuzz[{i}]", rust_validate(p),
oracle["facade_validate"][i])
for i, (spec, cid) in enumerate(facade_minidoc_rows):
want = oracle["facade_minidoc"][i]
scratch = tempfile.mkdtemp(prefix="cpjkern-")
try:
path = minidoc_kernel_facade(spec, cid, scratch)
check(f"mini-doc facade-kernel[{i}] bytes", path.read_text(encoding="utf-8"),
want["content"])
check(f"mini-doc facade-kernel[{i}] name", path.name, want["file"])
entity = rust_entity(spec["load"], cid)
check(f"mini-doc kernel-direct[{i}] bytes",
rust_write_mini_doc(entity, cid, want["projection"]),
want["content"])
finally:
shutil.rmtree(scratch, ignore_errors=True)
print("== crash parity (kernel errs -> facade floor raises the oracle's exact exception) ==")
for kind, factory in crash_shapes():
args = factory()
want = oracle["crash"][kind]
try:
got = facade_crash_call(kind, args)
check(f"crash[{kind}]", f"NO_CRASH:{json.dumps(got, sort_keys=True)}", want)
except Exception as e: # noqa: BLE001 — the crash IS the check
check(f"crash[{kind}]", f"{type(e).__name__}: {e}", want)
if FAILS[0]:
print(f"\nPARITY FAILED: {FAILS[0]} mismatches of {CHECKS[0]}")
return 1
print(f"\nPARITY OK: 100% — {CHECKS[0]} comparisons, rust == oracle == frozen "
f"({total} frozen rows + {len(fuzz)} fuzz project + "
f"{len(facade_minidoc_rows)} mini-doc + {len(crash_shapes())} crash)")
return 0
# ── facade calls in the CHECK process (kernel live — no pin set) ────────────
def cp_contract_entity(doc, cid):
from rune import construction_projection as cp
return cp._contract_entity(doc, cid)
def cp_validate(p):
from rune import construction_projection as cp
out = cp.validate(p)
return out
def _patch_bridge(bridge, fn, *args, **kwargs):
from rune import event_wait as ew
real = ew.operation_wait
ew.operation_wait = _check_bridge(bridge)
try:
return fn(*args, **kwargs)
finally:
ew.operation_wait = real
def facade_project(spec, cid, bridge, kwargs):
from rune import construction_projection as cp
p = _patch_bridge(bridge, cp.project, _KernelScaffold(spec), cid,
**dict(kwargs))
return p
def minidoc_kernel_facade(spec, cid, out_dir):
from rune import construction_projection as cp
return cp.write_mini_doc(_KernelScaffold(spec), cid, out_dir=out_dir)
def facade_crash_call(kind, args):
"""The facade path with the kernel live: kernel errs → floor raises."""
from rune import construction_projection as cp
if kind in ("entity_nondict", "entity_null_entities"):
return cp._contract_entity(args[0], args[1])
if kind == "validate_nondict":
return cp.validate(args[0])
if kind in ("blocker_int", "checkpoint_int"):
return cp.project(_KernelScaffold({"load": args[0]}), args[1])
if kind in ("surface_int", "evidence_int"):
return cp.write_mini_doc(_KernelScaffold({"load": args[0]}), args[1])
raise AssertionError(kind)
if __name__ == "__main__":
sys.exit(main())
+385
View File
@@ -0,0 +1,385 @@
#!/usr/bin/env python3
"""Live parity: context_pressure Rust core vs Python oracle (dichotomy wave,
close-PARTIAL gap pass). Layers:
1. FROZEN — (a) the envelope truth corpus replayed through the ctypes
FFI; (b) kernel cases (entry BYTE lines, log parses, stats counts,
hook result+entry, CLI dispatch {output, code, entry}) through the
FFI; (c) INDEPENDENT oracle-floor regeneration of both sections
compared against the frozen file (truth-consumed-not-self-generated).
2. FUZZ — 1250+ seeded comparisons (seed 2479): oracle floor vs kernel
across estimate/measure/detect/entry-assembly/log-tail/stats-counts/
hook (crash parity included, exact str(e) contract).
3. LIVE — dual-mode facade battery: the same calls through
rune.context_pressure with RUNE_CPS_CORE=python (oracle floor) and
with the Rust core live; return docs AND the appended JSONL lines
must be identical (the clock is rig-frozen, so lines are byte-stable).
MUST run under the freeze rig: PYTHONPATH=scripts/cps_freeze_seams (pins
the oracle floor + hermetic scratch + frozen clock).
Exit 0 only at 100% parity on the gap-closing surface.
"""
from __future__ import annotations
import json
import os
import random
import sys
from pathlib import Path
REPO = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(REPO / "scripts"))
import context_pressure_truth as cpt # noqa: E402
SCRATCH = cpt.SCRATCH
FROZEN_NOW = cpt.FROZEN_NOW
# Rig guard: refuse to run unpinned (would touch the real ~/.rune).
if os.environ.get("RUNE_MEMORY_DIR") != os.path.join(SCRATCH, "memory"):
sys.exit("FATAL: run under the rig (PYTHONPATH=scripts/cps_freeze_seams)")
if os.environ.get("RUNE_CPS_CORE") != "python":
sys.exit("FATAL: rig must pin RUNE_CPS_CORE=python")
sys.path.insert(0, str(REPO / "src"))
import rune.context_pressure as cp # noqa: E402
from rune import cps_loader # noqa: E402
if not cps_loader.available():
sys.exit("FATAL: Rust core not built — cargo build --release in src/rust/context_pressure")
TRUTH = json.loads(
(REPO / "src" / "rust" / "context_pressure" / "src"
/ "frozen_cp_truth.json").read_text())
fails: list[str] = []
counts = {"frozen": 0, "regen": 0, "fuzz": 0, "live": 0}
def fail(layer, name, detail):
fails.append(f"[{layer}] {name}: {detail}")
print(f"FAIL[{layer}] {name}: {detail}"[:400])
def j(x):
return json.dumps(x, sort_keys=True, ensure_ascii=True)
def check(layer, name, want, got):
counts[layer] += 1
if j(want) != j(got):
fail(layer, name, f"want={j(want)[:300]} got={j(got)[:300]}")
def check_crash(layer, name, want, exc):
"""want is the frozen '__crash__ TYPE: message' string."""
counts[layer] += 1
got = f"{type(exc).__name__}: {exc}"
if j(want) != j(got):
fail(layer, name, f"want={want} got={got}")
def pin(mode):
if mode == "python":
os.environ["RUNE_CPS_CORE"] = "python"
os.environ["RUNE_CONTEXT_PRESSURE_CORE"] = "python"
else:
os.environ.pop("RUNE_CPS_CORE", None)
os.environ.pop("RUNE_CONTEXT_PRESSURE_CORE", None)
# ── layer 1: FROZEN (kernel through the FFI) ──────────────────────────────
for row in TRUTH.get("cases", []):
fn, args, kwargs, want = (row["fn"], row["args"], row.get("kwargs", {}),
row["expected"])
try:
if fn == "estimate_tokens":
check("frozen", f"ffi_{fn}:{args[0][:12]}", want,
cps_loader.estimate_tokens(args[0]))
elif fn == "measure_pressure":
check("frozen", f"ffi_{fn}:{args[0][:12]}:{kwargs.get('max_tokens')}",
want, cps_loader.measure_pressure(args[0], kwargs.get("max_tokens", 128000)))
elif fn == "detect_degradation":
check("frozen", f"ffi_{fn}:{args[0][0][:12]}", want,
cps_loader.detect_degradation(args[0]))
elif fn == "handle_hook":
got = cps_loader.handle_hook(args[0], args[1], FROZEN_NOW)
check("frozen", f"ffi_{fn}:{args[0]}", want, got["result"])
except Exception as e: # noqa: BLE001 — crash parity surfaces here
fail("frozen", f"ffi_{fn}", f"{type(e).__name__}: {e}")
for kind, rows in TRUTH.get("kernel_cases", {}).items():
for row in rows:
args, expect, name = row["args"], row["expect"], row["name"]
if kind == "logMeasurement":
entry = cps_loader.log_measurement(args["measurement"],
args["session_id"], args["now"])
counts["frozen"] += 1
# BYTE law: the facade writes json.dumps(entry) + "\n" (default
# ensure_ascii) — the frozen line is the oracle's exact bytes.
if json.dumps(entry) + "\n" != expect["line"]:
fail("frozen", f"{kind}/{name}/line",
f"want={expect['line'][:160]} got={json.dumps(entry)[:160]}")
elif kind == "readLog":
check("frozen", f"{kind}/{name}", expect,
cps_loader.read_log(args["content"], args["limit"]))
elif kind == "logStats":
try:
check("frozen", f"{kind}/{name}", expect,
cps_loader.log_stats(args["content"]))
except Exception as e: # noqa: BLE001
if isinstance(expect, dict) and "__crash__" in expect:
check_crash("frozen", f"{kind}/{name}", expect["__crash__"], e)
else:
fail("frozen", f"{kind}/{name}", f"unexpected crash {e}")
elif kind == "kernelHook":
try:
got = cps_loader.handle_hook(args["event"], args["data"], args["now"])
if isinstance(expect, dict) and "__crash__" in expect:
fail("frozen", f"{kind}/{name}", "kernel did not crash where oracle did")
else:
check("frozen", f"{kind}/{name}", expect, got)
except Exception as e: # noqa: BLE001
if isinstance(expect, dict) and "__crash__" in expect:
check_crash("frozen", f"{kind}/{name}", expect["__crash__"], e)
else:
fail("frozen", f"{kind}/{name}", f"unexpected crash {e}")
elif kind == "mainDispatch":
try:
got = cps_loader.main_dispatch(args["argv"], args["content"], args["now"])
want = {k: expect[k] for k in ("output", "code") if k in expect}
gotv = {k: got[k] for k in ("output", "code") if k in got}
check("frozen", f"{kind}/{name}", want, gotv)
if "entry" in expect:
check("frozen", f"{kind}/{name}/entry", expect["entry"], got.get("entry"))
except Exception as e: # noqa: BLE001
fail("frozen", f"{kind}/{name}", f"unexpected crash {e}")
# ── layer 1c: independent oracle-floor regeneration vs the frozen file ────
env_regen = cpt.regen_envelope_cases()
check("regen", "envelope_cases", TRUTH["cases"], env_regen)
kc_regen = cpt.regen_kernel_cases()
for kind, rows in TRUTH["kernel_cases"].items():
check("regen", f"kernel_cases:{kind}", rows, kc_regen[kind])
# ── layer 2: FUZZ (oracle floor vs kernel, seeded) ────────────────────────
rng = random.Random(2479)
VOCAB = ["hello", "world", "éé", "üü", "dup", "word", "👍", "a_b_c",
"MiXeD", "runner", "label", "law", "123"]
WORDS = ["dup", "word", "pair", "echo", "alpha", "beta"]
def rand_text():
n = rng.randrange(0, 12)
return " ".join(rng.choice(VOCAB) for _ in range(n))
def rand_measurement():
if rng.random() < 0.5:
return cp.measure_pressure(rand_text())
base = rng.choice(["tokens", "user_key", "note"])
doc = {base: rng.randrange(0, 50)}
if rng.random() < 0.7:
doc["pressure"] = rng.choice([0.0, 0.5, 1.0, 0.666, 2.5])
if rng.random() < 0.5:
doc["status"] = rng.choice(["ok", "warning", "critical", None])
return doc
for trial in range(200):
text = rand_text()
check("fuzz", f"estimate:{trial}", cp.estimate_tokens(text),
cps_loader.estimate_tokens(text))
for trial in range(400):
text = rand_text()
max_tokens = rng.choice([1, 2, 3, 7, 12000, 20000, 128000, 99999])
w_err = g_err = None
try:
w = cp.measure_pressure(text, max_tokens=max_tokens)
except Exception as e: # noqa: BLE001
w, w_err = None, f"{type(e).__name__}: {e}"
try:
g = cps_loader.measure_pressure(text, max_tokens)
except Exception as e: # noqa: BLE001
g, g_err = None, f"{type(e).__name__}: {e}"
counts["fuzz"] += 1
if w_err or g_err:
if w_err != g_err:
fail("fuzz", f"measure:{trial}", f"crash mismatch {w_err} vs {g_err}")
elif j(w) != j(g):
fail("fuzz", f"measure:{trial}", f"want={j(w)[:200]} got={j(g)[:200]}")
for trial in range(200):
n = rng.randrange(2, 9)
responses = []
for i in range(n):
if i == 0 and rng.random() < 0.5:
responses.append(rand_text())
else:
responses.append(" ".join(rng.choice(WORDS)
for _ in range(rng.randrange(1, 12))))
check("fuzz", f"detect:{trial}", cp.detect_degradation(responses),
cps_loader.detect_degradation(responses))
for trial in range(200):
m = rand_measurement()
sid = rng.choice(["", "session A", "s" * 40])
want = {"timestamp": FROZEN_NOW, "session_id": sid, **m}
got = cps_loader.log_measurement(m, sid, FROZEN_NOW)
counts["fuzz"] += 1
if j(want) != j(got):
fail("fuzz", f"log_measurement:{trial}", f"want={j(want)[:200]} got={j(got)[:200]}")
LOG_POOL = [
'{"tokens": 3, "pressure": 0.5, "status": "warning"}',
'{"tokens": 1, "pressure": 0.0, "status": "ok"}',
'{"status": "critical"}',
"not json at all",
"5",
"",
' {"padded": true} ',
"[]",
'"str line"',
]
for trial in range(150):
n = rng.randrange(0, 10)
content = "\n".join(rng.choice(LOG_POOL) for _ in range(n))
if content and rng.random() < 0.5:
content += "\n"
limit = rng.choice([-2, 0, 1, 2, 3, 5, 20])
cpt._seed_log(content)
w = cp.read_log(limit=limit)
g = cps_loader.read_log(content, limit)
counts["fuzz"] += 1
if j(w) != j(g):
fail("fuzz", f"read_log:{trial}:lim{limit}", f"want={j(w)[:200]} got={j(g)[:200]}")
for trial in range(100):
n = rng.randrange(0, 8)
content = "\n".join(rng.choice(LOG_POOL) for _ in range(n))
if content and rng.random() < 0.7:
content += "\n"
cpt._seed_log(content)
try:
w = cp.log_stats()
w_err = None
except Exception as e: # noqa: BLE001
w, w_err = None, f"{type(e).__name__}: {e}"
try:
g = cps_loader.log_stats(content)
g_err = None
except Exception as e: # noqa: BLE001
g, g_err = None, f"{type(e).__name__}: {e}"
counts["fuzz"] += 1
if w_err or g_err:
if w_err != g_err:
fail("fuzz", f"log_stats:{trial}", f"crash mismatch {w_err} vs {g_err}")
elif j(w) != j(g):
fail("fuzz", f"log_stats:{trial}", f"want={j(w)[:200]} got={j(g)[:200]}")
HOOK_EVENTS = ["on_message", "on_message", "on_message", "other_event", ""]
HOOK_DATAS = [
{"message": "hello"},
{"message": "x" * 95000},
{"text": "hello world"},
{"message": "", "text": "ok text"},
{"other": 1},
{"a": True, "n": None},
{"k": "a'b"},
{},
None,
[1, 2],
True,
5,
"plain str",
]
for trial in range(150):
event = rng.choice(HOOK_EVENTS)
data = rng.choice(HOOK_DATAS)
seed_data = json.loads(json.dumps(data)) if isinstance(data, (dict, list, str)) else data
try:
cpt._seed_log("")
w = cp.handle_hook(event, seed_data)
w_entry = None
for line in cpt._read_log_file().splitlines():
if line.strip():
w_entry = json.loads(line)
w_err = None
except Exception as e: # noqa: BLE001
w, w_entry, w_err = None, None, f"{type(e).__name__}: {e}"
try:
g = cps_loader.handle_hook(event, data, FROZEN_NOW)
g_err = None
except Exception as e: # noqa: BLE001
g, g_err = None, f"{type(e).__name__}: {e}"
counts["fuzz"] += 1
if w_err or g_err:
if w_err != g_err:
fail("fuzz", f"hook:{trial}:{event}", f"crash mismatch {w_err} vs {g_err}")
else:
g_entry = g.get("entry")
want = {"result": w, "entry": w_entry}
got = {"result": g.get("result"), "entry": g_entry}
if j(want) != j(got):
fail("fuzz", f"hook:{trial}:{event}", f"want={j(want)[:260]} got={j(got)[:260]}")
# ── layer 3: LIVE (dual-mode facade battery) ──────────────────────────────
BIG = "x" * 95000
CASES = [
("estimate_unicode", lambda: cp.estimate_tokens("héllo wörld 👍")),
("measure_ok", lambda: cp.measure_pressure("hello world")),
("measure_warning", lambda: cp.measure_pressure("x" * 49000, max_tokens=20000)),
("measure_critical", lambda: cp.measure_pressure(BIG, max_tokens=12000)),
("measure_empty", lambda: cp.measure_pressure("")),
("detect_trio", lambda: cp.detect_degradation(["aaa", "bbb", "ccc"])),
("detect_decline", lambda: cp.detect_degradation(["x" * 200, "y" * 180, "", "", ""])),
("detect_insufficient", lambda: cp.detect_degradation(["a", "b"])),
("read_log", lambda: cpt._seed_log('{"a": 1}\nbroken\n{"b": 2}\n')
or cp.read_log(limit=2)),
("log_stats", lambda: cpt._seed_log(
'{"status": "warning"}\n{"status": "critical"}\nbroken\n') or cp.log_stats()),
("log_stats_empty", lambda: cpt._seed_log("") or cp.log_stats()),
("log_measurement", lambda: cpt._seed_log("") or cp.log_measurement(
{"tokens": 3, "max_tokens": 128000, "pressure": 0.0, "status": "ok",
"recommendation": "none"}, "sid-1") or cpt._read_log_file()),
("log_measurement_override", lambda: cpt._seed_log("") or cp.log_measurement(
{"timestamp": "T-override", "user_key": "u"}, "") or cpt._read_log_file()),
("hook_ok", lambda: cpt._seed_log("") or cp.handle_hook("on_message", {"text": "hello"})),
("hook_critical", lambda: cpt._seed_log("") or cp.handle_hook(
"on_message", {"message": BIG})),
("hook_str_data", lambda: cpt._seed_log("") or cp.handle_hook(
"on_message", {"other": 1})),
("hook_empty", lambda: cpt._seed_log("") or cp.handle_hook("on_message", {})),
("hook_wrong_event", lambda: cpt._seed_log("") or cp.handle_hook(
"ping", {"message": BIG})),
]
results = {}
for mode in ("python", "rust"):
pin(mode)
mode_out = {}
for name, fn in CASES:
try:
mode_out[name] = fn()
except Exception as e: # noqa: BLE001 — crash parity surfaces here
mode_out[name] = {"__crash__": f"{type(e).__name__}: {e}"}
results[mode] = mode_out
pin("python")
for name, _ in CASES:
counts["live"] += 1
w, g = results["python"][name], results["rust"][name]
if j(w) != j(g):
fail("live", f"dual:{name}", f"want={j(w)[:260]} got={j(g)[:260]}")
print(f"parity: frozen={counts['frozen']} regen={counts['regen']} "
f"fuzz={counts['fuzz']} live={counts['live']} failures={len(fails)}")
sys.exit(1 if fails else 0)
+233
View File
@@ -0,0 +1,233 @@
#!/usr/bin/env python3
"""check_cron_engine_parity.py — LIVE parity for the cron_engine GO port
(#2479 dichotomy gap-close): drives the Python oracle (src/rune/
cron_engine.py) and the GO binary through IDENTICAL scenarios and diffs
their JSON outputs — beyond frozen-truth replay, this exercises the two
implementations LIVE (real subprocesses, real files) under a pinned
clock + hermetic HOME.
Python side mirrors the Go binary's `scenario` mode exactly (op set,
output shape). Paths are tokenized to <HOME> before comparison.
Usage: python3 scripts/check_cron_engine_parity.py <go-binary>
(build first: cd src/go/cron-engine && go build -o /tmp/cron-engine .)
"""
import json
import os
import subprocess
import sys
import tempfile
from pathlib import Path
REPO = Path(__file__).resolve().parent.parent
sys.path.insert(0, str(REPO / "src"))
os.environ.setdefault("RUNE_CRON_ENGINE_CORE", "python")
from rune import cron_engine as ce # noqa: E402
import rune.subsystem_health as _SH # noqa: E402
_SH.record_failure = lambda *a, **k: True # hermetic: no ledger writes
FROZEN_NOW = "2026-10-13T09:20:00"
def frozen_clock(iso):
from datetime import datetime, timezone
base = datetime.fromisoformat(iso)
class FrozenDatetime(datetime):
@classmethod
def now(cls, tz=None):
return base.replace(tzinfo=tz) if tz is not None else base
return FrozenDatetime
class StopTime:
def __init__(self, engine):
self._e = engine
def sleep(self, _s):
if self._e is not None:
self._e.running = False
def run_python(sc):
ce.datetime = frozen_clock(sc["frozen_now"])
home = tempfile.mkdtemp(prefix="ce-live-py-")
os.environ["HOME"] = home
storage = os.path.join(home, ".rune", "cron.json")
logp = os.path.join(home, ".rune", "cron.log")
e = ce.CronEngine.__new__(ce.CronEngine)
e.storage_path = storage
e.tasks = {}
e.running = False
e.thread = None
e._last_run_minute = {}
e._load()
def rd(p):
return open(p).read() if os.path.exists(p) else None
def dump():
return {
"running": e.running,
"storage_path": e.storage_path,
"log_path": logp,
"tasks": [{"name": n, "task": t.to_dict()} for n, t in e.tasks.items()],
"_last_run_minute": dict(e._last_run_minute), # snapshot (no live aliasing)
}
steps = []
for op in sc["ops"]:
k = op["op"]
if k == "add":
t = e.add_task(op["name"], op["expr"], op["command"], op.get("description", ""))
steps.append({"op": "add", "task": t.to_dict()})
elif k == "enable":
steps.append({"op": "enable", "ok": e.enable_task(op["name"])})
elif k == "disable":
steps.append({"op": "disable", "ok": e.disable_task(op["name"])})
elif k == "remove":
steps.append({"op": "remove", "ok": e.remove_task(op["name"])})
elif k == "run":
steps.append({"op": "run", "result": e.run_task(op["name"])})
elif k == "fire":
steps.append({"op": "fire", "fired": e.fire_on_task_complete()})
elif k == "loop":
real = ce.time
ce.time = StopTime(e)
try:
e._run_loop()
finally:
ce.time = real
steps.append({"op": "loop"})
elif k == "start":
real = ce.time
ce.time = StopTime(e)
try:
e.start()
e.stop()
finally:
ce.time = real
steps.append({"op": "start+stop"})
elif k == "stop":
e.stop()
steps.append({"op": "stop"})
elif k == "save":
e._save()
steps.append({"op": "save", "ok": True})
elif k == "load":
e._load()
steps.append({"op": "load", "ok": True})
elif k == "storage":
steps.append({"op": "storage", "bytes": rd(storage)})
elif k == "log":
steps.append({"op": "log", "bytes": rd(logp)})
elif k == "state":
steps.append({"op": "state", "state": dump()})
else:
raise ValueError(k)
return {"home": home, "out": {"steps": steps, "final": dump()}}
def run_go(binary, sc_path):
r = subprocess.run([binary, "scenario", str(sc_path)],
capture_output=True, text=True, timeout=120)
if r.returncode != 0:
raise RuntimeError(f"go scenario failed: {r.stderr}")
# the binary's temp home differs per run — recover it from final.storage_path
out = json.loads(r.stdout)
home = os.path.dirname(os.path.dirname(out["final"]["storage_path"]))
return {"home": home, "out": out}
def tokenize(obj, home):
if isinstance(obj, str):
return obj.replace(home, "<HOME>")
if isinstance(obj, list):
return [tokenize(x, home) for x in obj]
if isinstance(obj, dict):
return {k: tokenize(v, home) for k, v in obj.items()}
return obj
SCENARIOS = [
# 1: lifecycle + run envelopes + storage/log bytes
{"frozen_now": FROZEN_NOW, "ops": [
{"op": "add", "name": "z-first", "expr": "on_complete", "command": "echo one"},
{"op": "add", "name": "a-second", "expr": "*/5 * * * *", "command": "echo '中文 twø'", "description": "d-ü"},
{"op": "add", "name": "bad", "expr": "* * * * *", "command": "nope-cmd-xyz"},
{"op": "add", "name": "quoted", "expr": "* * * * *", "command": "echo 'unterminated"},
{"op": "state"},
{"op": "run", "name": "z-first"},
{"op": "run", "name": "bad"},
{"op": "run", "name": "quoted"},
{"op": "run", "name": "ghost"},
{"op": "disable", "name": "a-second"},
{"op": "fire"},
{"op": "storage"},
{"op": "log"},
{"op": "state"},
]},
# 2: scheduler loop — matching, non-matching, dedup, disabled
{"frozen_now": FROZEN_NOW, "ops": [
{"op": "add", "name": "match", "expr": "* * * * *", "command": "echo m"},
{"op": "add", "name": "nomatch", "expr": "5 4 * * *", "command": "echo n"},
{"op": "add", "name": "off", "expr": "* * * * *", "command": "echo o"},
{"op": "disable", "name": "off"},
{"op": "loop"},
{"op": "loop"},
{"op": "storage"},
{"op": "log"},
{"op": "state"},
]},
# 3: persistence round-trip + start/stop + remove
{"frozen_now": FROZEN_NOW, "ops": [
{"op": "add", "name": "keep", "expr": "0 9 * * 1", "command": "echo k"},
{"op": "add", "name": "drop", "expr": "0 9 * * 1", "command": "echo d"},
{"op": "remove", "name": "drop"},
{"op": "run", "name": "keep"},
{"op": "storage"},
{"op": "start"},
{"op": "state"},
{"op": "stop"},
]},
]
def main():
binary = sys.argv[1] if len(sys.argv) > 1 else "/tmp/cron-engine"
ok = 0
for i, sc in enumerate(SCENARIOS, 1):
with tempfile.NamedTemporaryFile("w", suffix=".json", delete=False) as f:
json.dump(sc, f)
sc_path = f.name
try:
py = run_python(sc)
go = run_go(binary, sc_path)
finally:
os.unlink(sc_path)
pyj = tokenize(py["out"], py["home"])
goj = tokenize(go["out"], go["home"])
if pyj == goj:
ok += 1
print(f"scenario {i}: LIVE PARITY OK ({len(sc['ops'])} ops)")
else:
print(f"scenario {i}: LIVE PARITY FAILED")
pj, gj = json.dumps(pyj, indent=1, sort_keys=True), json.dumps(goj, indent=1, sort_keys=True)
for pl, gl in zip(pj.splitlines(), gj.splitlines()):
if pl != gl:
print(f" py: {pl}")
print(f" go: {gl}")
break
return 1
print(f"LIVE PARITY: {ok}/{len(SCENARIOS)} scenarios identical (oracle vs GO)")
return 0
if __name__ == "__main__":
sys.exit(main())
+256
View File
@@ -0,0 +1,256 @@
#!/usr/bin/env python3
"""check_drift_compression_parity.py — live parity for the drift_compression
gap-close port (dichotomy wave, #2479 tranche).
Three live layers over the FROZEN truth
(src/rust/memory_scoring/src/frozen_dcomp_truth.json, 65 cases, frozen via
scripts/gen_drift_compression_truth.py against the pure _py_* oracle):
1. facade PINNED — RUNE_MEMORY_CORE=python: the public fns run the
load-bearing Python fallback against the frozen expectations.
2. facade LIVE — delegation on (the built memory_scoring .so through
ms_loader): the same public fns against the same expectations.
3. KERNEL — ms_loader.* called directly (the FFI envelope path).
Plus two end-to-end seams the frozen file cannot carry (a sqlite
connection is not JSON-freezable):
4. db-level get_compression_stats: an in-memory entries table seeded with
active/inactive rows, SQL nulls and mixed rock statuses — pinned vs
live vs the _py math, all three must agree (pins the status='active'
filter and the None coercion of SQL nulls).
5. FUZZ (seed 2479): deterministic random entries/rows/texts (unicode
included) — pinned facade vs live facade vs kernel, plus the stats
row-reduction, N rounds each.
Comparison law: structural == (dict/list equality). The one documented
representation quirk: integral FLOATS crossing the FFI render int-shaped
(savings_pct 50.0 from the oracle, 50 from the envelope) — == treats them
equal, which is exactly how the oracle's own consumers read the dict;
byte-shape parity for the stats dict is pinned by the Rust battery's
frozen replay instead.
Exit 0 iff every layer is 100%.
Run: PYTHONPATH=src python3 scripts/check_drift_compression_parity.py
"""
from __future__ import annotations
import json
import os
import random
import sqlite3
import sys
from pathlib import Path
REPO = Path(__file__).resolve().parents[1]
TRUTH_PATH = REPO / "src" / "rust" / "memory_scoring" / "src" / "frozen_dcomp_truth.json"
FUZZ_SEED = 2479
sys.path.insert(0, str(REPO / "src"))
# The delegation pin is read PER CALL (drift_core._ms_core reads the env
# every time), so one process can exercise both modes by toggling.
os.environ["RUNE_MEMORY_CORE"] = "python"
from rune import drift_compression as dc # noqa: E402
from rune import ms_loader # noqa: E402
STATUSES = ["washable", "established", "rock", "muddy", None]
FILLER = "alpha bravo charlie delta echo foxtrot golf hotel "
def long_text(n: int) -> str:
return (FILLER * (n // len(FILLER) + 1))[:n]
def pinned() -> bool:
return os.environ.get("RUNE_MEMORY_CORE") == "python"
def facade_call(fn_name: str, args: list, kwargs: dict):
"""Public-facade dispatch for one frozen case (stats → the rows kernel)."""
if fn_name == "_py_get_compression_stats":
fn = dc._py_get_compression_stats if pinned() else ms_loader.get_compression_stats
return fn(*args, **kwargs)
public = fn_name.removeprefix("_py_")
fn = getattr(dc, public)
return fn(*args, **kwargs)
def kernel_call(fn_name: str, args: list, kwargs: dict):
if fn_name == "_py_get_compression_ratio":
return ms_loader.get_compression_ratio(*args, **kwargs)
if fn_name == "_py_compress_text":
return ms_loader.compress_text(*args, **kwargs)
if fn_name == "_py_compress_entry":
return ms_loader.compress_entry(*args, **kwargs)
if fn_name == "_py_should_warn":
return ms_loader.should_warn(*args, **kwargs)
if fn_name == "_py_warn_before_compress":
return ms_loader.warn_before_compress(*args, **kwargs)
if fn_name == "_py_get_compression_stats":
return ms_loader.get_compression_stats(*args, **kwargs)
raise KeyError(fn_name)
def run_layer(label: str, cases: list, call) -> tuple[int, int]:
ok = 0
fails = []
for case in cases:
try:
got = call(case["fn"], case["args"], case.get("kwargs", {}))
except Exception as e: # noqa: BLE001 — a crash IS the divergence
fails.append((case["fn"], case["args"], f"raised {type(e).__name__}: {e}"))
continue
if got == case["expected"]:
ok += 1
else:
fails.append((case["fn"], case["args"], f"got {got!r} want {case['expected']!r}"))
print(f"{label}: {ok}/{len(cases)} match")
for fn, args, detail in fails[:5]:
print(f" DIVERGE {fn} args={json.dumps(args, default=str)[:120]}: {detail[:200]}")
return ok, len(cases)
def make_db() -> sqlite3.Connection:
db = sqlite3.connect(":memory:")
db.execute(
"CREATE TABLE entries (id INTEGER PRIMARY KEY, text TEXT, wash_count INTEGER,"
" rock_status TEXT, status TEXT)"
)
db.executemany(
"INSERT INTO entries VALUES (?,?,?,?,?)",
[
(1, long_text(120), 0, "washable", "active"),
(2, long_text(80), 5, "rock", "active"),
(3, long_text(60), 3, "established", "active"),
(4, long_text(90), 15, "washable", "active"),
(5, None, None, None, "active"), # SQL nulls (LENGTH(NULL) → None)
(6, long_text(500), 25, "washable", "active"),
(7, long_text(77), 7, "washable", "retired"), # filtered: status != active
(8, long_text(33), 1, "muddy", "active"), # unknown status
],
)
return db
def db_level_check() -> tuple[int, int]:
db = make_db()
os.environ["RUNE_MEMORY_CORE"] = "python"
pinned_stats = dc.get_compression_stats(db)
del os.environ["RUNE_MEMORY_CORE"]
live_stats = dc.get_compression_stats(db)
db.close()
rows = [
["washable", 0, 120], ["rock", 5, 80], ["established", 3, 60],
["washable", 15, 90], [None, None, None], ["washable", 25, 500],
["muddy", 1, 33],
]
math_stats = dc._py_get_compression_stats(rows)
checks = [pinned_stats == live_stats, live_stats == math_stats]
print(f"db-level get_compression_stats: pinned==live {checks[0]}, live==math {checks[1]}")
if not all(checks):
print(f" pinned: {pinned_stats}")
print(f" live: {live_stats}")
print(f" math: {math_stats}")
return sum(checks), len(checks)
def fuzz_check(rounds: int = 400) -> tuple[int, int]:
rng = random.Random(FUZZ_SEED)
ok = total = 0
def agree(label: str, values: list) -> None:
nonlocal ok, total
total += 1
if all(v == values[0] for v in values[1:]):
ok += 1
else:
print(f" FUZZ DIVERGE [{label}]: {json.dumps(values, default=str)[:400]}")
os.environ["RUNE_MEMORY_CORE"] = "python"
for i in range(rounds):
text = long_text(rng.choice([0, 5, 19, 20, 21, 100, 199, 200, 201, 600, 1337]))
if rng.random() < 0.2:
text = text + "汉字" * rng.randint(1, 4) + " " * rng.randint(0, 3)
entry = {"text": text}
if rng.random() < 0.8:
entry["wash_count"] = rng.choice([0, 1, 5, 9, 10, 19, 20, 25, 100, None])
if rng.random() < 0.8:
entry["rock_status"] = rng.choice(STATUSES)
if rng.random() < 0.5:
entry["id"] = rng.choice([i, f"slug-{i}", None])
ratio = rng.choice([0.0, 0.1, 0.2, 0.25, 0.5, 0.9, 0.999, 1.0, rng.random()])
# pinned facade (pure Python)
ce_p = dc.compress_entry(entry)
sw_p = dc.should_warn(entry)
wb_p = dc.warn_before_compress(entry)
ct_p = dc.compress_text(text, ratio)
# live facade (delegation)
del os.environ["RUNE_MEMORY_CORE"]
ce_l = dc.compress_entry(entry)
sw_l = dc.should_warn(entry)
wb_l = dc.warn_before_compress(entry)
ct_l = dc.compress_text(text, ratio)
# kernel direct
ce_k = ms_loader.compress_entry(entry)
sw_k = ms_loader.should_warn(entry)
wb_k = ms_loader.warn_before_compress(entry)
ct_k = ms_loader.compress_text(text, ratio)
os.environ["RUNE_MEMORY_CORE"] = "python"
agree("compress_entry", [ce_p, ce_l, ce_k])
agree("should_warn", [sw_p, sw_l, sw_k])
agree("warn_before_compress", [wb_p, wb_l, wb_k])
agree("compress_text", [ct_p, ct_l, ct_k])
if rng.random() < 0.35:
rows = [
[
rng.choice(STATUSES),
rng.choice([0, 3, 10, 15, 20, 40, None]),
rng.choice([0, 1, 17, 33, 100, 250, 1000, None]),
]
for _ in range(rng.randint(0, 6))
]
st_p = dc._py_get_compression_stats(rows)
st_k = ms_loader.get_compression_stats(rows)
agree("get_compression_stats", [st_p, st_k])
print(f"fuzz (seed {FUZZ_SEED}): {ok}/{total} agree across pinned/live/kernel")
return ok, total
def main() -> int:
if not ms_loader.available():
print("memory_scoring .so not built — run cargo build --release first")
return 1
cases = json.loads(TRUTH_PATH.read_text())
total_ok = total_n = 0
os.environ["RUNE_MEMORY_CORE"] = "python"
ok, n = run_layer("facade pinned (RUNE_MEMORY_CORE=python)", cases, facade_call)
total_ok, total_n = total_ok + ok, total_n + n
del os.environ["RUNE_MEMORY_CORE"]
ok, n = run_layer("facade live (Rust core through ms_loader)", cases, facade_call)
total_ok, total_n = total_ok + ok, total_n + n
ok, n = run_layer("kernel direct (FFI envelope)", cases, kernel_call)
total_ok, total_n = total_ok + ok, total_n + n
ok, n = db_level_check()
total_ok, total_n = total_ok + ok, total_n + n
ok, n = fuzz_check()
total_ok, total_n = total_ok + ok, total_n + n
print(f"parity: {total_ok}/{total_n} match")
return 0 if total_ok == total_n else 1
if __name__ == "__main__":
sys.exit(main())
+388
View File
@@ -0,0 +1,388 @@
#!/usr/bin/env python3
"""Live parity: drift_core Rust kernel vs Python oracle (dichotomy wave,
close-PARTIAL gap pass). Layers:
1. FROZEN — the gap truth corpus (src/rust/drift_core/frozen_truth.json,
generated by scripts/gen_drift_core_truth.py under the
scripts/dc_freeze_seams rig against the LIVE oracle with
RUNE_DRIFT_CORE=python pinned): every row replayed through the ctypes
FFI kernel, exact JSON compare (typing included — ints stay ints,
round(x, n) floats stay floats), case by case.
2. FUZZ — seeded random surfaces (seed 2479): eligibility tuples, fama
row sets, velocity/direction aggregates, promote decisions — the
oracle's Python floor vs the FFI kernel, exact compare.
3. LIVE — dual-mode facade battery: the same db-carrying calls
(promote_entry incl. the post-UPDATE store state, compute_fama,
compute_drift_velocity, compute_drift_direction, pre_commit_gate)
executed with RUNE_DRIFT_CORE=python (oracle floor) and with the Rust
kernel live; results and store effects must be identical.
Exit 0 only at 100% parity on the gap-closing functions.
"""
import copy
import json
import os
import random
import shutil
import sys
from pathlib import Path
REPO = Path(__file__).resolve().parents[1]
os.environ["RUNE_DRIFT_CORE"] = "python" # oracle floor to start
PARITY_HOME = "/tmp/dc_parity"
sys.path.insert(0, str(REPO / "src"))
from rune import memory_store as store # noqa: E402
from rune import drift_core as dc # noqa: E402
from rune import dcore_loader # noqa: E402
if not dcore_loader.available():
sys.exit("FATAL: Rust kernel not built — cargo build --release in src/rust/drift_core")
TRUTH = json.loads(
(REPO / "src" / "rust" / "drift_core" / "frozen_truth.json").read_text()
)
NOW = "2026-10-13T12:00:00.123456+00:00"
# Pin the oracle's module clock to NOW (the harness's frozen-clock trick):
# the oracle's check_promotion_eligibility resolves `now` internally via
# _now_iso(None), and the kernel calls below pass NOW explicitly — both
# sides must see the same instant for the value-reason strings to match.
from datetime import datetime as _dt # noqa: E402
class _FrozenDatetime(_dt):
@classmethod
def now(cls, tz=None):
base = _dt.fromisoformat(NOW)
return base.replace(tzinfo=tz) if tz is not None else base
dc.datetime = _FrozenDatetime
fails: list[str] = []
counts = {"frozen": 0, "fuzz": 0, "live": 0}
def fail(layer, name, detail):
fails.append(f"[{layer}] {name}: {detail}")
print(f"FAIL[{layer}] {name}: {detail}"[:400])
def j(x):
return json.dumps(x, sort_keys=True, ensure_ascii=True)
def check(layer, name, want, got):
counts[layer] += 1
if j(want) != j(got):
fail(layer, name, f"want={j(want)[:300]} got={j(got)[:300]}")
def pin(mode):
"""Flip the facade pin at runtime (dcore_loader.core reads env per call)."""
if mode == "python":
os.environ["RUNE_DRIFT_CORE"] = "python"
else:
os.environ.pop("RUNE_DRIFT_CORE", None)
def fresh_db(tag):
"""Hermetic per-call scratch store (both pins see identical state)."""
root = os.path.join(PARITY_HOME, tag)
if os.path.isdir(root):
shutil.rmtree(root)
os.makedirs(os.path.join(root, "store"), exist_ok=True)
path = os.path.join(root, "dc-parity.db")
db = store.connect(path)
return db, path
def seed_rows(db, rows):
for i, r in enumerate(rows):
db.execute(
"INSERT INTO entries (id, text, importance, created_at, status, "
"wash_count, rock_status, last_washed) VALUES (?,?,?,?,?,?,?,?)",
(
r.get("id", i + 1),
r.get("text", f"row {i}"),
r.get("importance", 0.5),
"2026-10-01T00:00:00.000000+00:00",
r.get("status", "active"),
r.get("wash_count", 0),
r.get("rock_status", "washable"),
r.get("last_washed"),
),
)
db.commit()
store._embed = lambda texts: {} # lexical-only, deterministic
# ── 1. FROZEN: replay the gap truth through the FFI kernel ──────────────────
for row in TRUTH["cases"]:
fn = row["fn"]
args = row["args"]
kwargs = row.get("kwargs", {})
exp = row["expected"]
if fn == "_now_iso":
if args[0] is None:
got = dcore_loader.now_iso(None)
check("frozen", "now_iso.frozen-clock-shape", True, "T" in got)
else:
check("frozen", "now_iso.passthrough", exp, dcore_loader.now_iso(args[0]))
elif fn == "dc_freeze_ms_core":
pin("python")
py_probe_none = dc._dc_core() is None
pin("live")
live_probe = dcore_loader.core() is not None
check("frozen", "ms_core.probe", [True, True, True],
[exp is True, py_probe_none, live_probe])
elif fn == "compute_value":
got = dcore_loader.compute_value(args[0], kwargs.get("current_goals"), NOW)
check("frozen", "compute_value", exp, got)
elif fn == "check_promotion_eligibility":
got = dcore_loader.check_promotion_eligibility(args[0], NOW)
check("frozen", "check_promotion_eligibility", exp, list(got))
elif fn == "pre_commit_gate_entry":
check("frozen", "gate_entry", exp, dcore_loader.pre_commit_gate_entry(args[0]))
elif fn == "dc_freeze_gate":
check("frozen", "gate.empty-body", exp, dcore_loader.pre_commit_gate())
elif fn == "dc_freeze_promote":
entry = args[0]
entry_id = args[1]
got = dcore_loader.promote_entry(entry, entry_id, NOW)
check("frozen", f"promote[{entry_id}]", exp["result"], got)
elif fn == "dc_freeze_fama":
got = dcore_loader.compute_fama(args[0], args[1], args[2])
check("frozen", "fama", exp, got)
elif fn == "dc_freeze_velocity":
changes, promotions = exp["counts"]
got = dcore_loader.compute_drift_velocity(changes, promotions, args[1])
check("frozen", f"velocity[d={args[1]}]", exp["out"], got)
elif fn == "dc_freeze_direction":
total, established, rock = exp["counts"]
got = dcore_loader.compute_drift_direction(total, established, rock)
check("frozen", "direction", exp["out"], got)
else:
sys.exit(f"FATAL: unmapped truth row {fn}")
# ── 2. FUZZ: seeded random surfaces, oracle floor vs FFI kernel ─────────────
rng = random.Random(2479)
def _iso(dt):
return dt.isoformat()
from datetime import datetime, timedelta, timezone # noqa: E402
_now = datetime.now(timezone.utc)
IN_W = _iso(_now - timedelta(seconds=60)) # inside every window (days >= 1)
OUT_W = _iso(_now - timedelta(days=3650)) # outside every window
for i in range(150):
entry = {
"id": i + 1,
"text": f"fuzz entry {i} proven deployment runner kubernetes",
"wash_count": rng.choice([0, 1, 5, 19, 20, 25, 40, 60]),
"importance": rng.choice([0.0, 0.3, 0.5, 0.8, 1.0]),
"rock_status": rng.choice(["washable", "established", "rock", "odd"]),
"last_accessed": rng.choice([
"2026-10-13T06:00:00.000000+00:00",
"2026-10-10T12:00:00.000000+00:00",
"2026-09-01T12:00:00.000000+00:00",
None,
]),
}
pin("python")
want = list(dc.check_promotion_eligibility(copy.deepcopy(entry)))
got = dcore_loader.check_promotion_eligibility(copy.deepcopy(entry), NOW)
check("fuzz", f"eligibility[{i}]", want, list(got))
for i in range(150):
n = rng.randint(0, 6)
rows = [
{
"status": rng.choice(["active", "active", "retired"]),
"rock_status": rng.choice(["washable", "established", "rock"]),
"wash_count": rng.choice([0, 1, 7, None]),
}
if rng.random() < 0.85
else None
for _ in range(n)
]
ids = list(range(1, n + 1))
db, _ = fresh_db(f"fuzz-fama-{i}")
try:
present = [{**r, "id": ids[k]} for k, r in enumerate(rows) if r is not None]
if present:
seed_rows(db, present)
pin("python")
want = dc.compute_fama(db, "fuzz query", ids)
finally:
db.close()
got = dcore_loader.compute_fama(rows, "fuzz query", ids)
check("fuzz", f"fama[{i}]", want, got)
for i in range(100):
promotions = rng.randint(0, 20)
changes = promotions + rng.randint(0, 40)
days = rng.choice([1, 2, 3, 7, 14, 30])
db, _ = fresh_db(f"fuzz-vel-{i}")
try:
# Seed so the oracle's SQL lands exactly on (changes, promotions):
# every in-window active row counts as a change; the established
# subset additionally counts as a promotion.
rows = (
[{"status": "active", "rock_status": "washable", "last_washed": IN_W}]
* (changes - promotions)
+ [{"status": "active", "rock_status": "established", "last_washed": IN_W}]
* promotions
+ [{"status": "active", "rock_status": "washable", "last_washed": OUT_W}]
* 3
)
seed_rows(db, rows)
pin("python")
want = dc.compute_drift_velocity(db, days)
finally:
db.close()
got = dcore_loader.compute_drift_velocity(changes, promotions, days)
check("fuzz", f"velocity[{i}]", want, got)
for i in range(100):
total = rng.randint(0, 20)
established = rng.randint(0, total)
rock = rng.randint(0, established)
db, _ = fresh_db(f"fuzz-dir-{i}")
try:
# established-count includes rock rows (rock_status IN clause), so
# seed established-status rows only for the non-rock share.
rows = (
[{"status": "active", "rock_status": "established"}]
* (established - rock)
+ [{"status": "active", "rock_status": "rock"}] * rock
+ [{"status": "active", "rock_status": "washable"}]
* (total - established)
+ [{"status": "retired", "rock_status": "rock"}]
)
seed_rows(db, rows)
pin("python")
want = dc.compute_drift_direction(db)
finally:
db.close()
got = dcore_loader.compute_drift_direction(total, established, rock)
check("fuzz", f"direction[{i}]", want, got)
for i in range(100):
entry = {
"id": 1,
"text": "fuzz promote candidate",
"wash_count": rng.choice([0, 5, 20, 25, 40]),
"importance": rng.choice([0.2, 0.5, 0.8, 1.0]),
"rock_status": rng.choice(["washable", "established", "rock"]),
}
entry_id = entry["id"]
db, _ = fresh_db(f"fuzz-promote-{i}")
try:
seed_rows(db, [entry])
pin("python")
want = dc.promote_entry(db, entry_id)
finally:
db.close()
got = dcore_loader.promote_entry(entry, entry_id, NOW)
check("fuzz", f"promote[{i}]", want, got)
# ── 3. LIVE: dual-mode facade (delegation wiring end to end) ────────────────
SCENARIOS = {
"promote": [
{"id": 1, "text": "proven deployment runner", "wash_count": 25,
"importance": 0.8, "rock_status": "washable"},
{"id": 2, "text": "locked anchor", "wash_count": 40,
"importance": 0.9, "rock_status": "rock"},
{"id": 3, "text": "young entry", "wash_count": 4,
"importance": 0.9, "rock_status": "washable"},
{"id": 4, "text": "proven established", "wash_count": 25,
"importance": 0.8, "rock_status": "established"},
],
"fama": [
{"id": 1, "status": "active", "rock_status": "washable", "wash_count": 5},
{"id": 2, "status": "active", "rock_status": "established", "wash_count": 0},
{"id": 3, "status": "retired", "rock_status": "rock", "wash_count": 3},
],
"velocity": [
{"status": "active", "rock_status": "washable", "last_washed": IN_W},
{"status": "active", "rock_status": "established", "last_washed": IN_W},
{"status": "active", "rock_status": "washable", "last_washed": OUT_W},
],
"direction": [
{"status": "active", "rock_status": "washable"},
{"status": "active", "rock_status": "established"},
{"status": "active", "rock_status": "rock"},
],
}
def run_facade(mode):
pin(mode)
out = {}
db, _ = fresh_db(f"live-{mode}")
try:
seed_rows(db, SCENARIOS["promote"])
out["promote"] = [dc.promote_entry(db, i) for i in (1, 2, 3, 4)]
out["promote_after"] = [
dict(r) if r else None
for r in (
db.execute(
"SELECT rock_status, promotion_eligible FROM entries WHERE id = ?",
(i,),
).fetchone()
for i in (1, 2, 3, 4)
)
]
finally:
db.close()
db, _ = fresh_db(f"live-fama-{mode}")
try:
seed_rows(db, SCENARIOS["fama"])
out["fama"] = dc.compute_fama(db, "deploy", [1, 2, 3, 99])
finally:
db.close()
for days in (7, 1, 0, 30):
db, _ = fresh_db(f"live-vel-{mode}-{days}")
try:
seed_rows(db, SCENARIOS["velocity"])
out[f"velocity-{days}"] = dc.compute_drift_velocity(db, days)
finally:
db.close()
db, _ = fresh_db(f"live-dir-{mode}")
try:
seed_rows(db, SCENARIOS["direction"])
out["direction"] = dc.compute_drift_direction(db)
out["gate"] = dc.pre_commit_gate(db, 1)
finally:
db.close()
return out
py_mode = run_facade("python")
rust_mode = run_facade("live")
for key in py_mode:
check("live", key, py_mode[key], rust_mode[key])
# The pin contract, both directions.
pin("python")
check("live", "pin.python-floor", True, dc._dc_core() is None)
pin("live")
check("live", "pin.live-kernel", True, dc._dc_core() is not None)
print(
f"parity: frozen={counts['frozen']} fuzz={counts['fuzz']} "
f"live={counts['live']} failures={len(fails)}"
)
sys.exit(1 if fails else 0)
+286
View File
@@ -0,0 +1,286 @@
#!/usr/bin/env python3
"""check_event_bus_parity.py — live oracle-vs-Go parity sweep for the
event_bus gap closure (#2479, contract factory-gap-eb).
The frozen envelope (truth_bus.json, 61 cases) pins the surface byte-
identically. THIS script drives the LIVE Python oracle (under the
scripts/eb_freeze_seams rig: frozen clock + deterministic uuid counter +
hermetic journal sandbox) and the Go binary (`op` mode, EE_FROZEN_NOW +
per-op reset + the same sandbox normalization envs) across the same
branches plus live extras, comparing the PYTHON-json byte form of every
result:
* store_path — the env-derivation matrix via SUBPROCESSES (sandbox/,
empty/, RUNE_HOME/, ~/ expansion, $HOME expansion, unset default),
normalized to EB_SANDBOX / EB_HOME / REPO_ROOT placeholders.
* event_types — the vocabulary table in definition order.
* content_hash — any-shape payloads (sort_keys, ensure_ascii).
* emit/emit_line — envelope build + durable append + journal LINE bytes,
incl. the loud ValueError branches (dict/int/NoneType/float/bool/list).
* log — filter + [-limit:] truncation matrix (0 → ALL, -N → front drop),
the typed corrupt-file raise, and the cross-writer probe (oracle
writes, Go replays the SAME file via the "replay" op).
* stats — (total, by_type) first-occurrence order.
* handle_hook — prefix, payload shaping (raw[:200], str(v)[:200] with
repr forms + truncation, falsy data), journal after each hook.
* main — captured CLI stdout + exit (emit/log/stats/hook, --json modes).
Usage: PYTHONPATH=scripts/eb_freeze_seams:src python3 scripts/check_event_bus_parity.py
[--bin src/go/event-bus/event-bus]
Exit 0 on 100% parity (incl. the negative control detecting perturbation),
1 with the first divergences, 2 if the negative control fails to detect.
"""
import argparse
import json
import os
import subprocess
import sys
import tempfile
from pathlib import Path
REPO = Path(__file__).resolve().parent.parent
sys.path.insert(0, str(REPO / "src"))
FROZEN_NOW = "2026-10-14T11:22:33.123456+00:00"
import rune.event_bus as eb # noqa: E402 (rig active via PYTHONPATH)
SANDBOX = eb.EB_SANDBOX # the rig's hermetic journal dir (shared both sides)
def run_go(binpath, env, req):
p = subprocess.run([str(binpath), "op"], input=json.dumps(req),
capture_output=True, text=True, env=env)
if p.returncode != 0:
raise RuntimeError(f"go op {req.get('op')} exited {p.returncode}: "
f"{p.stdout} {p.stderr}")
return json.loads(p.stdout)["json"]
def go_env(extra=None):
env = dict(os.environ)
env["EE_FROZEN_NOW"] = FROZEN_NOW
env["RUNE_MEMORY_DIR"] = SANDBOX
env["EB_SANDBOX_ROOT"] = SANDBOX
env["EB_REPO_ROOT"] = str(REPO)
if extra:
env.update(extra)
return env
def normalize(s, subs):
for value, placeholder in subs:
s = s.replace(value, placeholder)
return s.replace("/mnt/workdrive/rune", "REPO_ROOT")
def oracle_subproc(env, code):
p = subprocess.run([sys.executable, "-c", code], capture_output=True,
text=True, env=env, cwd=str(REPO))
return p
def main():
ap = argparse.ArgumentParser()
ap.add_argument("--bin", default=str(REPO / "src/go/event-bus/event-bus"))
args = ap.parse_args()
binpath = Path(args.bin)
if not binpath.exists():
print(f"Go binary missing: {binpath} (go build -o event-bus . in src/go/event-bus)")
return 1
fails = total = 0
def check(name, oracle_json, go_json):
nonlocal fails, total
total += 1
if oracle_json != go_json:
fails += 1
print(f"DIVERGE {name}:\n oracle: {oracle_json[:300]}\n"
f" go: {go_json[:300]}")
# ── store_path — the env-derivation matrix (subprocess pairs) ─────
# The ORACLE side runs WITHOUT the rig (PYTHONPATH=src only): these
# rows are pure path derivation (no clock/uuid mints). The GO side
# normalizes through the EB_* placeholder envs.
home1 = Path(tempfile.mkdtemp(prefix="eb-parity-home-"))
home2 = Path(tempfile.mkdtemp(prefix="eb-parity-home2-"))
variants = [
("default", {"RUNE_MEMORY_DIR": None, "RUNE_HOME": None},
{"/mnt/workdrive/rune": "REPO_ROOT"}, {}),
("sb", {"RUNE_MEMORY_DIR": SANDBOX}, {(SANDBOX): "EB_SANDBOX"},
{"EB_SANDBOX_ROOT": SANDBOX}),
("empty", {"RUNE_MEMORY_DIR": ""}, {}, {}),
("rune_home", {"RUNE_MEMORY_DIR": None, "RUNE_HOME": str(home1)},
{str(home1): "EB_HOME"}, {"EB_HOME_ROOT": str(home1)}),
("tilde", {"RUNE_MEMORY_DIR": "~/eb-x", "RUNE_HOME": None, "HOME": str(home2)},
{str(home2): "EB_HOME"}, {"EB_HOME_ROOT": str(home2)}),
("dollar", {"RUNE_MEMORY_DIR": "$HOME/eb-v", "RUNE_HOME": None, "HOME": str(home1)},
{str(home1): "EB_HOME"}, {"EB_HOME_ROOT": str(home1)}),
]
for name, env_over, subs, go_norms in variants:
base = {k: v for k, v in os.environ.items()
if k not in ("RUNE_MEMORY_DIR", "RUNE_HOME")}
base["PYTHONPATH"] = str(REPO / "src")
py_env = dict(base)
for k, v in env_over.items():
if v is None:
py_env.pop(k, None)
else:
py_env[k] = v
code = "import sys; sys.path.insert(0, %r); import rune.event_bus as eb; print(eb._store_path())" % str(REPO / "src")
p = oracle_subproc(py_env, code)
oracle_path = p.stdout.strip()
go_env_v = go_env({**go_norms})
for k, v in env_over.items():
if v is None:
go_env_v.pop(k, None)
else:
go_env_v[k] = v
got = run_go(binpath, go_env_v, {"op": "store_path"})
check(f"store_path:{name}",
json.dumps(normalize(oracle_path, list(subs.items()))),
got)
# ── event_types — vocabulary table ─────────────────────────────────
check("event_types", json.dumps(eb.eb_event_types()),
run_go(binpath, go_env(), {"op": "event_types"}))
# ── content_hash — any-shape payloads ──────────────────────────────
HASH_PAYLOADS = [
{}, {"k": "v"}, {"b": 2, "a": [1, 2.0]}, ["x", {"z": 1}],
{"é": "ümlaut", "deep": {"z": 1, "a": [{"b": 2.0, "a": [True, None]}]}},
"raw string payload", 1234, 2.5, 1e30, True, None,
{"text": "quote\" inside\\ back\nnewline\ttab"},
]
for i, payload in enumerate(HASH_PAYLOADS):
kw = {} if i == 0 else None # the {} payload rides via args
check(f"content_hash:{i}",
json.dumps(eb.eb_content_hash(payload if payload != {} or i > 0 else {}))
if i or payload else json.dumps(eb.eb_content_hash({})),
run_go(binpath, go_env(), {"op": "content_hash", "payload": payload}))
# ── emit — envelope build + durable append ─────────────────────────
EMIT_CASES = [
("user.message", "user", {"text": "hi"}),
("tool.result", "", None), # bare defaults
("rune.started", "system", {}), # {} falsy → hash ""
("x.y", "", None), # → partition "system"
("memory.created", "sys", {"nested": {"a": [1, 2, "x"]}, "flag": True, "nothing": None}),
("user.message", "café", {"text": "quote\" inside\\ back\nnewline\ttab", "é": "ümlaut"}),
("capability.failed", "sys", {"float_int": 1.0, "float_frac": 2.5, "big": 1e30}),
("task.created", "sys", [1, "two", None, True]),
("task.created", "sys", "raw string payload"),
("task.created", "sys", 0),
]
for case in EMIT_CASES:
t, src, payload = case
check(f"emit:{t}/{str(src)[:20]}",
json.dumps(eb.eb_emit(t, source=src, payload=payload)),
run_go(binpath, go_env(), {"op": "emit", "event_type": t,
"source": src, "payload": payload}))
for bad in ({}, 5, None, 2.5, True, []):
check(f"emit_valueerror:{type(bad).__name__}",
json.dumps(eb.eb_emit("x", source=bad)),
run_go(binpath, go_env(), {"op": "emit", "event_type": "x",
"source": bad, "payload": None}))
# ── emit_line — the journal LINE bytes ──────────────────────────────
for t, src, payload in (
("user.message", "user", {"text": "hi"}),
("session.ended", "microkernel", {"k": ["a", {"z": 2.0}]})):
line = eb.eb_emit_line(t, source=src, payload=payload)
check(f"emit_line:{t}",
json.dumps(line),
run_go(binpath, go_env(), {"op": "emit_line", "event_type": t,
"source": src, "payload": payload}))
# ── log — truncation + filter matrix ────────────────────────────────
LOG_CASES = [None, 2, 0, -1, -3, -1000, 100]
for limit in LOG_CASES:
check(f"log:{limit}",
json.dumps(eb.eb_log(limit=limit, event_type=None)),
run_go(binpath, go_env(), {"op": "log", "limit": limit, "event_type": None}))
for limit, et in ((3, "user.message"), (3, "nope"), (2, "tool.result"), (0, "user.message")):
check(f"log:{limit}:{et}",
json.dumps(eb.eb_log(limit=limit, event_type=et)),
run_go(binpath, go_env(), {"op": "log", "limit": limit, "event_type": et}))
# correlated corrupt-line raise (message-only contract)
p = eb._store_path()
p.parent.mkdir(parents=True, exist_ok=True)
p.write_text("not json\n")
try:
eb.log()
oracle_corrupt = json.dumps({"error": None})
except RuntimeError as e:
oracle_corrupt = json.dumps({"error": "RuntimeError", "message": str(e)})
check("log_corrupt", oracle_corrupt,
run_go(binpath, go_env(), {"op": "replay"}))
p.unlink() # the corrupt fixture must not leak into the cross-writer probe
# cross-writer probe: the ORACLE writes N events; Go replays the SAME file
eb_emit = [eb.emit("user.message", source="user", payload={"i": i}) for i in range(3)]
go_rows = run_go(binpath, go_env(), {"op": "replay"})
check("replay_cross_writer",
json.dumps({"rows": eb.log()}),
go_rows)
if len(json.loads(go_rows)["rows"]) != 3:
fails += 1
print("CROSS-WRITER probe: Go replayed != 3 rows")
# ── stats — first-occurrence by_type ────────────────────────────────
check("stats", json.dumps(eb.eb_stats()),
run_go(binpath, go_env(), {"op": "stats"}))
# ── handle_hook — prefix + payload shaping ──────────────────────────
HOOK_CASES = [
("on_startup", None), ("on_message", {"k": "v", "n": 5}),
("weird.event", None),
("on_response", '{"x": 1, "y": [2, 3]}'),
("on_schedule", "not json at all"),
("on_session_end", ""), ("on_session_end", 0), ("on_session_end", "0"),
("on_session_end", "[1, 2]"),
("on_session_end", '{"deep": {"z": 1, "a": ["ü"]}}'),
("on_memory_add", {"long": "x" * 250, "uni": "café", "d": {"k": None},
"l": [1, "two"], "b": True, "fl": 2.5, "ni": None}),
("on_startup", {"empty": {}, "list": [], "str": ""}),
("on_startup", {"floats": [1.0, 1200.0, 1e-7, 2.5]}),
]
for ev, data in HOOK_CASES:
name = f"hook:{ev}:{str(data)[:24]}"
check(name, json.dumps(eb.eb_handle_hook(ev, data)),
run_go(binpath, go_env(), {"op": "handle_hook", "event": ev, "data": data}))
# ── main — captured CLI stdout ──────────────────────────────────────
MAIN_CASES = [
(["event_bus.py", "emit", "user.message", "--source", "user",
"--payload", '{"text":"hi"}'], False),
(["event_bus.py", "hook", "--event", "on_startup", "--data", '{"k":"v"}'], False),
(["event_bus.py", "stats"], False),
(["event_bus.py", "log", "--limit", "2"], False),
(["event_bus.py", "emit", "session.started", "--json"], False),
(["event_bus.py", "stats", "--json"], True),
(["event_bus.py", "log"], True),
(["event_bus.py", "hook"], False),
(["event_bus.py", "emit"], False),
]
for i, (argv, seed) in enumerate(MAIN_CASES):
kw = {"seed": True} if seed else {}
check(f"main:{i}",
json.dumps(eb.eb_main(argv, **kw)),
run_go(binpath, go_env(), {"op": "main", "argv": argv, "seed": seed}))
# ── negative control — a perturbed comparison MUST diverge ─────────
probe = run_go(binpath, go_env(), {"op": "stats"})
mutated = probe.replace(":2", ":999", 1) if ":2" in probe else probe + "x"
if mutated == probe:
print("NEGATIVE CONTROL FAILED TO DETECT")
return 2
print(f"parity: {total - fails}/{total} match (negative control: detected)")
return 1 if fails else 0
if __name__ == "__main__":
sys.exit(main())
+265
View File
@@ -0,0 +1,265 @@
#!/usr/bin/env python3
"""check_event_envelope_parity.py — live oracle-vs-Go parity sweep for
the event_envelope gap closure (#2479, contract factory-gap-ee).
The frozen envelope (truth_envelope.json, 83 cases) pins the surface
byte-identically. THIS script drives the LIVE Python oracle (under the
scripts/ee_freeze_seams rig: frozen clock + deterministic uuid counter)
and the Go binary (`op` mode, EE_FROZEN_NOW + per-op counter reset)
across the same branches, comparing the PYTHON-json byte form of every
result (separators ", "/": ", ensure_ascii, insertion order):
* classify_authority / classify_urgency — \b<word>\b regex semantics
(multi-word "stop doing" vs bare "stop", punctuation adjacency,
unicode word chars: "stopé" never matches, channel defaults).
* create_envelope — legacy path: auto authority/urgency, explicit
overrides, unicode + nested payloads.
* EventEnvelope.create — canonical bridge: CHANNELS prior vocabulary,
channel/source/unknown fallback chain, canonical asdict nesting.
* to_dict — 9-key legacy dict with insertion-ordered payloads.
* to_canonical_dict — schema_version-first key order,
content-addressed payload_hash (ensure_ascii hashing), and the loud
RuntimeError branch for un-bridged envelopes.
* test_envelope — the in-module self-test's captured stdout.
* CHANNELS / AUTHORITY_CLASSES — the constant tables.
Usage: PYTHONPATH=scripts/ee_freeze_seams:src python3 scripts/check_event_envelope_parity.py
[--bin src/go/event-bus/event-bus]
Exit 0 on 100% parity, 1 with the first divergences.
"""
import argparse
import json
import os
import subprocess
import sys
from pathlib import Path
REPO = Path(__file__).resolve().parent.parent
sys.path.insert(0, str(REPO / "src"))
FROZEN_NOW = "2026-10-14T11:22:33.123456+00:00"
import rune.event_envelope as ee # noqa: E402 (rig active via PYTHONPATH)
CLASSIFY_AUTHORITY = [
("hello there", "conversation"),
("Fix the failing test", "work"),
("run the suite", "work"),
("build it", "conversation"),
("test everything", "conversation"),
("create a file", "work"),
("add the guard", "work"),
("remove the shim", "work"),
("update the docs", "work"),
("change the port", "work"),
("Stop everything!", "work"),
("please cancel the order", "work"),
("abort the run", "work"),
("emergency shutdown", "work"),
("halt", "work"),
("Actually, don't modify the microkernel", "conversation"),
("dont do that", "conversation"),
("stop doing that", "work"),
("use rust instead", "work"),
("rather use go", "work"),
("pause for a bit", "work"),
("wait", "work"),
("hold", "work"),
("resume the work", "work"),
("continue the build", "work"),
("go", "work"),
("how is it going", "work"),
("what is the state", "work"),
("status?", "work"),
("progress report", "work"),
("check the log", "work"),
("hello", "work"),
("hello", "conversation"),
("hello", ""),
("stop,", "work"),
("unstoppable force", "work"),
("stopit now", "work"),
("", "work"),
("", "conversation"),
(" FIX it ", "work"),
("café stop", "work"),
("stopé now", "work"),
("Let's BUILD it, then run tests", "work"),
("what about the status, and check twice", "work"),
]
CLASSIFY_URGENCY = [
("anything", "emergency"),
("urgent please", "directive"),
("asap", "directive"),
("immediately", "conversation"),
("do it now", "directive"),
("critical issue", "conversation"),
("when you can", "directive"),
("no rush", "directive"),
("eventually", "conversation"),
("sometime later", "conversation"),
("when", "directive"),
("rush", "directive"),
("hello", "conversation"),
("", "directive"),
("NOW please", "directive"),
("no rushing", "directive"), # \b boundary: "rushing" ≠ "rush"
]
CREATE_ENVELOPE = [
("user", "conversation", {"text": "hello"}),
("user", "work", {"text": "Fix the failing test"}),
("user", "work", {"text": "Stop everything!"}),
("user", "conversation", {"text": "Actually, don't modify the microkernel"}),
("user", "work", {"text": "when you can"}),
("sensor", "sensor", {}),
("user", "work", {"text": "run it"}, "status_query", "t-42", "low"),
("user", "conversation", {"text": "hi", "extra": {"nested": [1, 2.5, None, True]}}),
("user", "work", {"text": "café résumé 🎯", "z": 1, "a": 2}),
("tool", "tool", {"result": "ok", "code": 0}),
]
CREATE = [
("user", "conversation", {"text": "hello"}),
("tool", "tool", {"x": 1}),
("user", "work", {"text": "Fix it"}),
("system", "system", {}),
("bg", "background", {}),
("sensor", "sensor", {}),
("user", "", {}),
("", "", {}),
("user", "unknown-channel", {"text": "hi"}),
]
TO_DICT_STATES = [
{"event_id": "evt_abc123def456", "timestamp": FROZEN_NOW,
"source": "user", "channel": "conversation", "authority_class": "conversation",
"task_id": None, "payload": {"text": "hi"}, "provenance": {}, "urgency": "normal"},
{"event_id": "id-2", "timestamp": "2026-10-14T00:00:00+00:00",
"source": "tool", "channel": "work", "authority_class": "directive",
"task_id": "t-9", "payload": {"n": 1.5, "b": False, "nil": None, "list": [1, "two"]},
"provenance": {"origin": "café", "chain": ["a", "b"]}, "urgency": "high"},
{"event_id": "id-3", "timestamp": FROZEN_NOW,
"source": "user", "channel": "", "authority_class": "",
"task_id": None, "payload": {}, "provenance": {"k": "v"}, "urgency": "low"},
]
TO_CANONICAL = [
("user", "conversation", {"text": "hello"}),
("tool", "tool", {"x": 1, "a": 2.0}),
("user", "work", {"text": "café résumé", "z": 1, "a": [True, None]}),
("system", "system", {}),
("bg", "background", {"nested": {"deep": [{"k": "v"}, 7]}}),
]
def run_go(binpath, env, req):
p = subprocess.run([str(binpath), "op"], input=json.dumps(req),
capture_output=True, text=True, env=env)
if p.returncode != 0:
raise RuntimeError(f"go op {req.get('op')} exited {p.returncode}: "
f"{p.stdout} {p.stderr}")
return json.loads(p.stdout)["json"]
def main():
ap = argparse.ArgumentParser()
ap.add_argument("--bin", default=str(REPO / "src/go/event-bus/event-bus"))
args = ap.parse_args()
binpath = Path(args.bin)
if not binpath.exists():
print(f"Go binary missing: {binpath} (go build -o event-bus . in src/go/event-bus)")
return 1
go_env = dict(os.environ)
go_env["EE_FROZEN_NOW"] = FROZEN_NOW
go_env.pop("EE_UUID_BASE", None)
fails = total = 0
def check(name, oracle_json, go_json):
nonlocal fails, total
total += 1
if oracle_json != go_json:
fails += 1
print(f"DIVERGE {name}:\n oracle: {oracle_json[:300]}\n"
f" go: {go_json[:300]}")
# classify — public fns (no mints; live semantics)
for text, channel in CLASSIFY_AUTHORITY:
check(f"classify_authority:{text[:30]!r}",
json.dumps(ee.classify_authority(text, channel)),
run_go(binpath, go_env, {"op": "classify_authority",
"text": text, "channel": channel}))
for text, authority in CLASSIFY_URGENCY:
check(f"classify_urgency:{text[:30]!r}",
json.dumps(ee.classify_urgency(text, authority)),
run_go(binpath, go_env, {"op": "classify_urgency",
"text": text, "authority_class": authority}))
# create_envelope — rig seam (per-call mint reset) vs op (per-op reset)
for row in CREATE_ENVELOPE:
source, channel, payload = row[0], row[1], row[2]
req = {"op": "create_envelope", "source": source, "channel": channel,
"payload": payload}
if len(row) > 3:
req["authority_class"] = row[3]
if len(row) > 4:
req["task_id"] = row[4]
if len(row) > 5:
req["urgency"] = row[5]
check(f"create_envelope:{source}/{channel}/{str(payload)[:30]}",
json.dumps(ee.ee_create_envelope(*row)),
run_go(binpath, go_env, req))
# EventEnvelope.create — canonical bridge
for source, channel, payload in CREATE:
check(f"create:{source}/{channel}",
json.dumps(ee.ee_create(source, channel, payload)),
run_go(binpath, go_env, {"op": "create", "source": source,
"channel": channel, "payload": payload}))
# to_dict — explicit states (insertion-ordered payloads byte-compared)
for state in TO_DICT_STATES:
full = dict(state)
full["_canonical"] = None
check(f"to_dict:{state['event_id']}",
json.dumps(ee.ee_to_dict(full)),
run_go(binpath, go_env, {"op": "to_dict", "state": full}))
# to_canonical_dict — bridged
for source, channel, payload in TO_CANONICAL:
check(f"to_canonical_dict:{source}/{channel}/{str(payload)[:30]}",
json.dumps(ee.ee_to_canonical_dict(source, channel, payload)),
run_go(binpath, go_env, {"op": "to_canonical_dict", "source": source,
"channel": channel, "payload": payload}))
# to_canonical_dict — unbridged loud failure
state = dict(TO_DICT_STATES[0])
state["_canonical"] = None
check("to_canonical_dict:unbridged",
json.dumps(ee.ee_to_canonical_dict_unbridged(state)),
run_go(binpath, go_env, {"op": "to_canonical_dict_unbridged",
"state": state}))
# test_envelope — captured stdout
check("test_envelope",
json.dumps(ee.ee_test_envelope()),
run_go(binpath, go_env, {"op": "test_envelope"}))
# constant tables
check("channels",
json.dumps(ee.ee_channels()),
run_go(binpath, go_env, {"op": "channels"}))
check("authority_classes",
json.dumps(ee.ee_authority_classes()),
run_go(binpath, go_env, {"op": "authority_classes"}))
print(f"parity: {total - fails}/{total} match")
return 1 if fails else 0
if __name__ == "__main__":
sys.exit(main())
+206
View File
@@ -0,0 +1,206 @@
#!/usr/bin/env python3
"""Live parity: graph_memory Rust kernels vs Python oracle (dichotomy wave,
gap-close pass). Layers:
1. FROZEN — the gap truth corpus (src/rust/graph_memory/frozen_truth.json,
generated by scripts/gen_graph_memory_truth.py under the
scripts/gm_freeze_seams rig against the LIVE oracle): the kernel-owned
rows (now_iso, strength_to_conf) replayed through the ctypes FFI,
case by case, byte-exact.
2. FUZZ — 60 seeded random op-sequences (seed 2479): the full facade
(add_edge/resolve_entity/query/stats with their kernel decisions)
executed with RUNE_GRAPH_MEMORY_CORE=python (oracle floor) and with
the Rust core live, under a pinned clock; per-op results, final
stats, and a query sweep must be identical.
3. LIVE — dual-mode determinism: the same facade calls on the same
hermetic store both pins; supersession chains preserved.
Exit 0 only at 100% parity on the gap-closing functions.
"""
import importlib
import json
import os
import random
import shutil
import sys
from datetime import datetime as _dt
from pathlib import Path
REPO = Path(__file__).resolve().parents[1]
os.environ["RUNE_GRAPH_MEMORY_CORE"] = "python" # oracle floor to start
SCRATCH = "/tmp/gm_parity"
os.environ["RUNE_MEMORY_DIR"] = SCRATCH
sys.path.insert(0, str(REPO / "src"))
import rune.gm_loader as gl # noqa: E402
import rune.graph_memory as gm # noqa: E402
if not gl.available():
sys.exit("FATAL: Rust core not built — cargo build --release in src/rust/graph_memory")
FROZEN_NOW = "2026-10-13T12:00:00"
fails: list[str] = []
counts = {"frozen": 0, "fuzz": 0, "live": 0}
def fail(layer, name, detail):
fails.append(f"[{layer}] {name}: {detail}")
print(f"FAIL[{layer}] {name}: {detail}"[:400])
def j(x):
return json.dumps(x, sort_keys=True, ensure_ascii=True)
def check(layer, name, want, got):
counts[layer] += 1
if j(want) != j(got):
fail(layer, name, f"want={j(want)[:300]} got={j(got)[:300]}")
def pin(mode):
if mode == "python":
os.environ["RUNE_GRAPH_MEMORY_CORE"] = "python"
else:
os.environ.pop("RUNE_GRAPH_MEMORY_CORE", None)
def frozen_clock():
base = _dt.fromisoformat(FROZEN_NOW)
class FrozenDatetime(_dt):
@classmethod
def now(cls, tz=None):
if tz is not None:
return base.replace(tzinfo=tz)
return base
gm.datetime = FrozenDatetime
def fresh_db():
shutil.rmtree(os.path.join(SCRATCH, "graph"), ignore_errors=True)
return gm.connect()
TRUTH = json.loads(
(REPO / "src" / "rust" / "graph_memory" / "frozen_truth.json").read_text())
CASES = TRUTH["cases"] if isinstance(TRUTH, dict) else TRUTH
# ── layer 1: FROZEN (kernel-owned rows through the FFI) ────────────────────
for row in CASES:
fn = row["fn"]
if fn == "now_iso":
check("frozen", "ffi_now_iso", row["expected"],
gl.now_iso("2026-10-13T12:00:00.123456+00:00"))
elif fn == "strength_to_conf":
(sv,) = row["args"]
res = gl.strength_to_conf(sv)
got = res["conf"] if res["ok"] else None
check("frozen", f"ffi_strength_to_conf:{sv!r}", row["expected"], got)
# ── layers 2+3: FUZZ + LIVE (dual-mode facade on random op-sequences) ───────
NAMES = ["Ada Lovelace", "Babbage", "Analytical Engine", "Difference Engine",
" punched card ", "Nightflyer", "", "babbage"]
PREDS = ["builds", "knows", "Works On", "frobnicate", "uses", "LIKES", "part_of"]
TYPES = ["person", "project", "alien", "tool", ""]
EVID = ["first notes", "revised notes", " spaced ", "x" * 500, ""]
rng = random.Random(2479)
def run_seq(seq, mode):
pin(mode)
importlib.reload(gm)
frozen_clock()
db = fresh_db()
out = []
for op in seq:
kind = op[0]
if kind == "add":
_, subj, pred, obj, kw = op
out.append(gm.add_edge(db, subj, pred, obj, **kw))
elif kind == "resolve":
_, name, nt = op
out.append(gm.resolve_entity(db, name, nt))
elif kind == "query":
_, term, hops = op
out.append(gm.query(db, term, hops=hops))
elif kind == "stats":
out.append(gm.stats(db))
sweep = [gm.query(db, t, hops=h) for t in ("Ada Lovelace", "babbage",
"Engine", "zzz") for h in (0, 1, 2)]
out.append(gm.stats(db))
db.close()
return out, sweep
for trial in range(60):
seq = []
for _ in range(rng.randrange(4, 14)):
r = rng.random()
if r < 0.55:
kw = {}
if rng.random() < 0.5:
kw["confidence"] = rng.choice([None, 0.5, 0.9, 0.99, 0.3])
if rng.random() < 0.6 or "confidence" not in kw:
kw["strength"] = rng.choice([None, 2, 3, 4, 5, "4", 3.5, "x"])
if rng.random() < 0.7:
kw["evidence"] = rng.choice(EVID)
if rng.random() < 0.4:
kw["source"] = rng.choice(["truth", "curator", ""])
if rng.random() < 0.3:
kw["subj_type"] = rng.choice(TYPES)
if rng.random() < 0.3:
kw["obj_type"] = rng.choice(TYPES)
seq.append(("add", rng.choice(NAMES), rng.choice(PREDS),
rng.choice(NAMES), kw))
elif r < 0.7:
seq.append(("resolve", rng.choice(NAMES), rng.choice(TYPES)))
elif r < 0.9:
seq.append(("query", rng.choice(NAMES + ["Engine", "ada lovelace"]),
rng.choice([0, 1, 2, -1])))
else:
seq.append(("stats",))
want_out, want_sweep = run_seq(seq, "python")
got_out, got_sweep = run_seq(seq, "rust")
for i, (w, g) in enumerate(zip(want_out, got_out)):
check("fuzz", f"trial{trial}:op{i}", w, g)
for i, (w, g) in enumerate(zip(want_sweep, got_sweep)):
check("fuzz", f"trial{trial}:sweep{i}", w, g)
if fails:
break
# ── layer 3: LIVE — pinned-clock determinism + supersession chains ─────────
def chain_probe(mode):
pin(mode)
importlib.reload(gm)
frozen_clock()
db = fresh_db()
gm.add_edge(db, "Ada", "uses", "Engine", confidence=0.6, evidence="v1", source="t")
gm.add_edge(db, "Ada", "uses", "Engine", confidence=0.7, evidence="v2", source="t")
gm.add_edge(db, "Ada", "uses", "Engine", confidence=0.7, evidence="v2", source="t") # dup
gm.add_edge(db, "Ada", "uses", "Engine", confidence=0.65, evidence="v2", source="t") # weaker dup
gm.add_edge(db, "Ada", "uses", "Engine", confidence=0.65, evidence="v3", source="t") # weaker, NEW evidence -> supersede
rows = [dict(r) for r in db.execute(
"SELECT id, subj_id, pred, obj_id, confidence, evidence, status, superseded_by "
"FROM edges ORDER BY id")]
q = gm.query(db, "engine", hops=1)
s = gm.stats(db)
db.close()
return rows, q, s
want_chain = chain_probe("python")
got_chain = chain_probe("rust")
for i in range(len(want_chain[0])):
check("live", f"supersession_chain:edge{i}", want_chain[0][i], got_chain[0][i])
check("live", "supersession_chain:query", want_chain[1], got_chain[1])
check("live", "supersession_chain:stats", want_chain[2], got_chain[2])
print(f"parity: {sum(counts.values())} checks "
f"(frozen {counts['frozen']}, fuzz {counts['fuzz']}, live {counts['live']}) "
f"— {len(fails)} failures")
sys.exit(1 if fails else 0)
+78
View File
@@ -0,0 +1,78 @@
#!/usr/bin/env python3
"""Live parity: layout_contract Rust kernels vs the frozen oracle truth
(dichotomy wave-5 gap-close). Layers:
1. FROZEN — the frozen truth corpus (frozen_lc_gap_truth.json, 34 cases,
generated by scripts/gen_layout_contract_truth.py against the LIVE
Python oracle through the scripts/lc_freeze_seams rig: pinned
RUNE_*_CORE=python floors, frozen clock on both now seams,
DOC-CARRYING wrappers) replayed through the lc_replay ctypes FFI
entry of the built cdylib, case by case.
2. LIVE — a fresh re-freeze of the oracle through the same rig in a
subprocess (LC_TRUTH_OUT redirected to a temp file); the regenerated
corpus must be byte-identical to the committed file (the oracle is
still the parity authority while the strangler runs).
Exit 0 only at 100% parity (34 verbatim + byte-identical re-freeze).
"""
import json
import os
import subprocess
import sys
import tempfile
from pathlib import Path
REPO = Path(__file__).resolve().parents[1]
CRATE = REPO / "src" / "rust" / "layout_contract"
FROZEN = CRATE / "frozen_lc_gap_truth.json"
sys.path.insert(0, str(REPO / "src"))
from rune import lc_loader # noqa: E402
def frozen_layer() -> int:
lib = lc_loader._load()
env = json.loads(FROZEN.read_text())
ok = 0
for case in env["cases"]:
got = lc_loader.replay(case)
assert got == case["expected"], (
f"FROZEN divergence: {case['fn']} "
f"{case['args'][1] if len(case['args']) > 1 else '?'}")
ok += 1
print(f"FROZEN: {ok}/{len(env['cases'])} cases verbatim through lc_replay")
return ok
def live_layer() -> None:
with tempfile.TemporaryDirectory(prefix="lc-parity-") as td:
out = Path(td) / "frozen_lc_gap_truth.json"
env = dict(
os.environ,
PYTHONPATH="scripts/lc_freeze_seams:src",
LC_TRUTH_OUT=str(out),
)
r = subprocess.run(
[sys.executable, "scripts/gen_layout_contract_truth.py"],
cwd=str(REPO), env=env, capture_output=True, text=True, timeout=600)
if r.returncode != 0:
print(r.stdout[-2000:])
print(r.stderr[-2000:])
print("LIVE: re-freeze FAILED")
raise SystemExit(1)
fresh = out.read_bytes()
committed = FROZEN.read_bytes()
if fresh != committed:
print("LIVE: re-freeze is NOT byte-identical to the committed corpus")
raise SystemExit(1)
n = len(json.loads(fresh)["cases"])
print(f"LIVE: re-freeze byte-identical ({n} cases)")
if __name__ == "__main__":
if not lc_loader.available():
print(f"layout_contract core not built: {lc_loader._LIB_PATH}")
raise SystemExit(1)
frozen_layer()
live_layer()
print("PARITY 100%")
+344
View File
@@ -0,0 +1,344 @@
#!/usr/bin/env python3
"""check_microkernel_parity.py — live oracle-vs-Go parity sweep for the
microkernel gap closure (dichotomy wave #2479, worktree rune-wave-cq).
The frozen envelope (truth_microkernel_gap.json, 25 cases) pins the gap
fns byte-identically. THIS script drives the LIVE Python oracle
(src/rune/microkernel.py) and the Go binary's parity op mode across every
branch class with FRESH fixtures (not the frozen ones): extract_manifest
(prefix traps, nested literals, unicode), discover (mixed dir), registry
load/save shapes, and fire/_run_hook (ok-json / raw-stdout truncation /
rc-error / timeout / skipped / ghost-file / empty-file / two-listeners /
no-listeners).
Normalization law (shared with the rig): wall-clock durations → "<ms>",
fire results name-sorted, fixture paths → <dir>. Data keys alphabetical
(the Go map marshal is key-sorted; plugins canonicalize the payload).
Usage: python3 scripts/check_microkernel_parity.py [--bin <path>]
Exit 0 on 100% parity, 1 with the first divergence.
"""
from __future__ import annotations
import argparse
import copy
import json
import os
import re
import subprocess
import sys
import tempfile
from datetime import datetime, timezone
from pathlib import Path
REPO = Path(__file__).resolve().parent.parent
sys.path.insert(0, str(REPO / "src"))
sys.path.insert(0, str(REPO / "src" / "rune"))
import microkernel as mk # noqa: E402
FROZEN_NOW = "2026-10-13T11:05:00"
FROZEN_NOW_AWARE = FROZEN_NOW + "+00:00"
OK_JSON = (
"import json, sys\n"
"data = sys.argv[sys.argv.index('--data') + 1]\n"
"print(json.dumps({'echo': json.loads(data)}))\n"
)
RAW_LONG = "print('h\\u00e9llo-\\u2192ok ' * 90)\n"
BOOM = ("import sys\n"
"sys.stderr.write('\\u00e9rr\\u00f4r-' * 80)\n"
"sys.exit(3)\n")
SLOW = "import time\ntime.sleep(4)\n"
FAILS: list[str] = []
CHECKS = [0]
def check(name, oracle_val, go_val):
CHECKS[0] += 1
a = json.dumps(oracle_val, sort_keys=True, ensure_ascii=False)
b = json.dumps(go_val, sort_keys=True, ensure_ascii=False)
if a != b:
FAILS.append(f"{name}:\n oracle: {a[:300]}\n go: {b[:300]}")
# ── clock pin (aware — fire() mixes naive/aware now()) ────────────────────
def pin_clock():
base = datetime.fromisoformat(FROZEN_NOW).replace(tzinfo=timezone.utc)
class Frozen(datetime):
@classmethod
def now(cls, tz=None):
if tz is not None:
return base.replace(tzinfo=tz)
return base
old = mk.datetime
mk.datetime = Frozen
return old
# ── Go side ────────────────────────────────────────────────────────────────
def run_go(binpath, req, env_dir=None):
env = dict(os.environ)
if env_dir:
env["RUNE_MEMORY_DIR"] = env_dir
p = subprocess.run([str(binpath), "parity"], input=json.dumps(req),
capture_output=True, text=True, env=env, timeout=120)
if p.returncode != 0:
raise RuntimeError(f"go op {req.get('op')} exited {p.returncode}: "
f"{p.stdout} {p.stderr}")
return json.loads(p.stdout)
# ── normalization ──────────────────────────────────────────────────────────
def norm_fire(result):
out = copy.deepcopy(result)
if "total_duration_ms" in out:
out["total_duration_ms"] = "<ms>"
for r in out.get("results", []):
if "duration_ms" in r:
r["duration_ms"] = "<ms>"
out["results"] = sorted(out.get("results", []), key=lambda r: r.get("name", ""))
return out
def norm_logs(log):
return [{"event": e.get("event"), "timestamp": e.get("timestamp"),
"hooks_fired": e.get("hooks_fired"), "duration_ms": "<ms>"}
for e in log]
def oracle_fire_with(manifest, event, data, timeout):
"""Fire through the live oracle; the manifest's _file must already
point at an existing fixture script (or a ghost for not-found)."""
work = tempfile.mkdtemp(prefix="mk_par_fire_")
mk.REGISTRY_DB = os.path.join(work, "registry.json")
mk.register(dict(manifest))
result = mk.fire(event, data=data, timeout=timeout)
log = mk._load_registry().get("log", [])
return {"result": norm_fire(result), "log": norm_logs(log)}
def go_registry_blob(manifest):
return {
"plugins": {manifest["name"]: {
"manifest": {"name": manifest["name"]},
"registered_at": FROZEN_NOW_AWARE,
"active": bool(manifest.get("auto_activate", True)),
"file": manifest.get("_file", ""),
}},
"capabilities": {},
"hooks": {ev: [manifest["name"]] for ev, on in manifest.get("hooks", {}).items() if on},
"log": [],
}
def main() -> int:
ap = argparse.ArgumentParser()
ap.add_argument("--bin", default="/tmp/mk-parity-bin")
args = ap.parse_args()
binpath = Path(args.bin)
old_clock = pin_clock()
# ── now_iso: FORMAT parity (wall clock — both must emit the shape) ──
CHECKS[0] += 1
shape = re.compile(r"^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\+00:00$")
if not (shape.match(mk.now_iso()) and shape.match(run_go(binpath, {"op": "now_iso"})["result"])):
FAILS.append(f"now_iso shape: oracle {mk.now_iso()!r} go {run_go(binpath, {'op': 'now_iso'})['result']!r}")
# ── extract_manifest: content sweep ──────────────────────────────
contents = [
'PLUGIN = {\n "name": "x",\n "capabilities": ["a", "b"],\n "hooks": {"e": "handle_hook"},\n "priority": 2,\n "auto_activate": False,\n}\n',
'PLUGINX = {\n "name": "prefix-trap",\n}\n', # startswith("PLUGIN")
'PLUGIN={"name":"dense","n":0.5}\n', # no spaces
"PLUGIN = {'k': 'v', 't': (1, 2), 'l': [1, [2, 3]]}\n", # tuple literal
'PLUGIN = {\n "name": "é中",\n "s": "tab\\tnewline\\nquote\\"q",\n}\n',
'PLUGIN = {\n "name": "trail",\n "arr": [1, 2, 3,],\n}\n', # trailing comma in list
'no manifest here\n',
'PLUGIN = {\n "name": "never-closed",\n',
]
for i, content in enumerate(contents):
fd, fpath = tempfile.mkstemp(suffix=".py")
with os.fdopen(fd, "w") as f:
f.write(content)
try:
oracle = copy.deepcopy(mk._extract_manifest(fpath))
finally:
os.unlink(fpath)
go = run_go(binpath, {"op": "extract_manifest", "content": content})["result"]
check(f"extract_manifest[{i}]", oracle, go)
# ── discover: mixed fixture dir ──────────────────────────────────
work = tempfile.mkdtemp(prefix="mk_par_disc_")
fixture = Path(work) / "scripts"
fixture.mkdir()
files = {
"alpha.py": 'PLUGIN = {\n "name": "alpha",\n "capabilities": ["cap"],\n "hooks": {"evt": "run"},\n "priority": 1,\n}\n',
"beta.py": 'PLUGIN = {\n "name": "beta",\n "capabilities": ["cap"],\n "priority": 9,\n}\n',
"gamma.py": 'PLUGIN = {"version": "0"}\n', # no name → error row
"delta.py": 'def plain():\n pass\n', # no PLUGIN → skipped
"_under.py": 'PLUGIN = {"name": "under"}\n',
"microkernel.py": 'PLUGIN = {"name": "self"}\n',
}
for fname, src in files.items():
(fixture / fname).write_text(src)
real_listdir = os.listdir
old_dir, old_db = mk.SCRIPTS_DIR, mk.REGISTRY_DB
mk.SCRIPTS_DIR = str(fixture)
mk.REGISTRY_DB = os.path.join(work, "registry.json")
os.listdir = lambda p: sorted(files) if str(p) == str(fixture) else real_listdir(p)
try:
oracle_result = copy.deepcopy(mk.discover())
oracle_state = mk._load_registry()
finally:
os.listdir = real_listdir
mk.SCRIPTS_DIR, mk.REGISTRY_DB = old_dir, old_db
oracle_proj = {
"plugins": {n: {"active": p.get("active"), "registered_at": p.get("registered_at"),
"file": p.get("file", "").replace(str(fixture), "<dir>")}
for n, p in oracle_state["plugins"].items()},
"capabilities": oracle_state["capabilities"],
"hooks": oracle_state["hooks"],
}
go = run_go(binpath, {"op": "discover", "dir": str(fixture), "now": FROZEN_NOW_AWARE})
go_proj = {
"plugins": {n: {"active": p["active"], "registered_at": p["registered_at"],
"file": p["file"].replace(str(fixture), "<dir>")}
for n, p in go["plugins"].items()},
"capabilities": go["capabilities"],
"hooks": go["hooks"],
}
check("discover.result", oracle_result, go["result"])
check("discover.registry", oracle_proj, go_proj)
# ── registry load/save shapes ────────────────────────────────────
old_db = mk.REGISTRY_DB
load_dir = tempfile.mkdtemp(prefix="mk_par_load_")
full = json.dumps({
"plugins": {"q": {"manifest": {"name": "q", "priority": 3},
"registered_at": FROZEN_NOW_AWARE, "active": False,
"file": "/y/q.py"}},
"capabilities": {"c": ["q"]},
"hooks": {"e2": ["q"]},
"log": [{"event": "e2", "timestamp": FROZEN_NOW_AWARE,
"hooks_fired": 2, "duration_ms": 3.25}],
}, indent=2)
def oracle_load(content):
mk.REGISTRY_DB = os.path.join(load_dir, "registry.json")
try:
db = mk.REGISTRY_DB
if content is None:
if os.path.exists(db):
os.unlink(db)
else:
with open(db, "w") as f:
f.write(content)
reg = mk._load_registry()
return {"plugins": {n: {"active": p.get("active"),
"registered_at": p.get("registered_at"),
"file": p.get("file", "")}
for n, p in reg.get("plugins", {}).items()},
"capabilities": reg.get("capabilities", {}),
"hooks": reg.get("hooks", {}),
"log": reg.get("log", [])}
finally:
mk.REGISTRY_DB = old_db
for label, content in (("missing", None), ("corrupt", "}{ nope"), ("full", full)):
oracle = oracle_load(content)
go = run_go(binpath, {"op": "registry_load", "content": content}, env_dir=load_dir)
check(f"registry_load.{label}", oracle,
{"plugins": {n: {"active": p["active"],
"registered_at": p["registered_at"], "file": p["file"]}
for n, p in go["plugins"].items()},
"capabilities": go["capabilities"], "hooks": go["hooks"], "log": go["log"]})
# roundtrip
mk.REGISTRY_DB = os.path.join(load_dir, "registry.json")
try:
first = mk._load_registry()
mk._save_registry(first)
again = mk._load_registry()
oracle_rt = {"stable": first == again}
finally:
mk.REGISTRY_DB = old_db
go_rt = run_go(binpath, {"op": "registry_roundtrip"}, env_dir=load_dir)
check("registry_roundtrip", oracle_rt, {"stable": go_rt["stable"]})
# ── fire / _run_hook branch matrix ───────────────────────────────
evt = "evt"
fire_cases = [
("ok_json", OK_JSON, {"name": "okp", "hooks": {evt: True}}, evt, {"a": 1, "b": "x"}, 30),
("raw_text", RAW_LONG, {"name": "rawp", "hooks": {evt: True}}, evt, None, 30),
("rc_error", BOOM, {"name": "boomp", "hooks": {evt: True}}, evt, None, 30),
("timeout", SLOW, {"name": "slowp", "hooks": {evt: True}}, evt, None, 1),
("skipped", OK_JSON, {"name": "offp", "hooks": {evt: True}, "auto_activate": False}, evt, None, 30),
("ghost_file", None, {"name": "ghostp", "hooks": {evt: True}, "_file": "/nonexistent/ghost.py"}, evt, None, 30),
("empty_file", None, {"name": "nofilep", "hooks": {evt: True}}, evt, None, 30),
("no_listeners", OK_JSON, {"name": "lonely", "capabilities": ["c"]}, "nope_evt", None, 30),
]
for label, script, manifest, event, data, timeout in fire_cases:
manifest = dict(manifest)
if script is not None:
work = tempfile.mkdtemp(prefix="mk_par_fx_")
fpath = os.path.join(work, "plugin.py")
with open(fpath, "w") as f:
f.write(script)
manifest["_file"] = fpath
oracle = oracle_fire_with(manifest, event, data, timeout)
blob = go_registry_blob(manifest)
go = run_go(binpath, {"op": "fire", "registry": blob, "event": event,
"data": data, "timeout_ms": timeout * 1000,
"now": FROZEN_NOW_AWARE})
go = {"result": norm_fire(go["result"]), "log": norm_logs(go["log"])}
check(f"fire.{label}", oracle, go)
# two listeners in parallel
work2 = tempfile.mkdtemp(prefix="mk_par_two_")
tmpdb2 = os.path.join(work2, "registry.json")
old_db = mk.REGISTRY_DB
mk.REGISTRY_DB = tmpdb2
try:
for nm in ("zz", "aa"):
fpath = os.path.join(work2, nm + ".py")
with open(fpath, "w") as f:
f.write(OK_JSON)
mk.register({"name": nm, "hooks": {evt: True}, "_file": fpath})
oracle = {"result": norm_fire(mk.fire(evt, data={"z": 1}, timeout=30)),
"log": norm_logs(mk._load_registry().get("log", []))}
finally:
mk.REGISTRY_DB = old_db
blob = {
"plugins": {
"zz": {"manifest": {"name": "zz"}, "registered_at": FROZEN_NOW_AWARE,
"active": True, "file": os.path.join(work2, "zz.py")},
"aa": {"manifest": {"name": "aa"}, "registered_at": FROZEN_NOW_AWARE,
"active": True, "file": os.path.join(work2, "aa.py")},
},
"capabilities": {}, "hooks": {evt: ["zz", "aa"]}, "log": [],
}
go = run_go(binpath, {"op": "fire", "registry": blob, "event": evt,
"data": {"z": 1}, "timeout_ms": 30000, "now": FROZEN_NOW_AWARE})
go = {"result": norm_fire(go["result"]), "log": norm_logs(go["log"])}
check("fire.two_listeners", oracle, go)
mk.datetime = old_clock
print(f"{'FAIL' if FAILS else 'OK'}: {CHECKS[0] - len(FAILS)}/{CHECKS[0]} checks passed")
for f in FAILS:
print(" " + f)
return 1 if FAILS else 0
if __name__ == "__main__":
sys.exit(main())
+197
View File
@@ -0,0 +1,197 @@
#!/usr/bin/env python3
"""check_model_connect_parity.py — live oracle-vs-Go parity sweep for the
model_connect gap closure (#2479, contract factory-gap-mconn).
The frozen envelope (truth.json) pins the ported surface byte-identically.
THIS script drives the LIVE Python oracle and the Go binary (stdin op
dispatch) across every op family — clean, moe, route, ctx_budget, now
(clock pinned on both sides), hook, and the cloud-model config sweep
(per-fixture hermetic HOME shared by oracle and binary) — comparing
sort_keys JSON. Exit 0 on 100% parity, 1 with the first divergences.
Usage: python3 scripts/check_model_connect_parity.py
[--bin src/go/model-connect/model-connect]
"""
import argparse
import json
import os
import subprocess
import sys
import tempfile
from datetime import datetime, timezone
from pathlib import Path
REPO = Path(__file__).resolve().parent.parent
sys.path.insert(0, str(REPO / "src"))
import rune.model_connect as mc # noqa: E402
FROZEN_NOW = "2026-10-14T08:00:00+00:00"
CLEAN = [
"hf.co/DavidAU/Qwen3.6-27B-Fable-Fusion-711-Uncensored-Heretic-NM-DAU-NEO-MAX-MTP-GGUF:IQ2_M",
"hf.co/org/Llama-3-8B-Instruct:latest",
"hf.co/short/gemma-2-9b",
"hf.co/user/nano-model",
"hf.co/user/ab",
"qwen2.5:3b",
"mimo-v2.5-pro",
"llava:7b",
"huggingface.co/x/y/Llama-3-8B",
]
MOE = [
"mixtral:8x7b", "qwen2.5:3b", "deepseek-moe-16b", "My-Mixture-Model",
"expert-v1", "4x22b-tiny", "plain-conversational", "GPT-XL",
]
MODELS_ALL = [
"qwen2.5:3b", "qwen2.5:7b", "qwen3:14b", "qwen2.5-coder:14b",
"hf.co/DavidAU/Qwen3.6-27B-Fable-Fusion-711-Uncensored-Heretic-NM-DAU-NEO-MAX-MTP-GGUF:IQ2_M",
"mixtral:8x7b-instruct-v0.1-q4_0", "qwen2.5vl:3b", "llava:7b",
"qwen3-embedding:0.6b", "nomic-embed-text:latest", "mxbai-embed-large:latest",
]
ROUTE = [
("coding", MODELS_ALL), ("research", MODELS_ALL), ("conversation", MODELS_ALL),
("unrestricted", MODELS_ALL), ("unknown-type", MODELS_ALL),
("coding", ["mystery-model:x"]), ("coding", []),
]
CTX = ["deterministic", "qwen2.5:3b", "qwen3:14b", "qwen3.6:27b",
"mimo-v2.5-pro", "totally-unknown-model", ""]
HOOKS = [
("pre_tool_use", {"tool": "bash", "dry": False}),
("", None),
("post_response", {"ok": True}),
("unicode-évent", {}),
]
FIXTURES = {
"main": """{
// MiMoCode config — JSONC: comments and trailing commas allowed
"provider": {
"ollama": { // skipped: local models handled by list_models
"models": {
"qwen3:14b": {},
},
},
"openai": {
"models": {
"gpt-5.2": {"contextLength": 400000},
"o4-mini": "not-even-a-dict",
},
},
"kimi": {
"models": {
"kimi-for-coding": {},
},
},
},
}
""",
"only_ollama": '{\n "provider": {\n "ollama": {"models": {"qwen2.5:3b": {}}},\n },\n}\n',
"no_models_key": '{\n "provider": {\n "anthropic": {"apiKey": "sk-test"},\n },\n}\n',
"no_provider_key": '{\n "theme": "dark",\n}\n',
"broken_late": '{\n "provider": {\n "a": {"models": {"m1": {}}},\n "b": {"models": "not-a-dict"},\n },\n}\n',
"null_models": '{\n "provider": {\n "z": {"models": null},\n },\n}\n',
"url_corruption": '{\n "provider": {\n "gateway": {\n "baseUrl": "http://api.example.com/v1",\n "models": {"gw-model": {}},\n },\n },\n}\n',
}
def run_go(binpath, req, env=None):
e = dict(os.environ)
if env:
e.update(env)
p = subprocess.run([str(binpath)], input=json.dumps(req), capture_output=True,
text=True, env=e)
if p.returncode != 0:
raise RuntimeError(f"go op {req.get('op')} exited {p.returncode}: {p.stdout} {p.stderr}")
return json.loads(p.stdout)
def frozen_clock():
base = datetime.fromisoformat(FROZEN_NOW)
class FrozenDatetime(datetime):
@classmethod
def now(cls, tz=None):
return base if tz is not None else base.replace(tzinfo=None)
return FrozenDatetime
def main():
ap = argparse.ArgumentParser()
ap.add_argument("--bin", default=str(REPO / "src/go/model-connect/model-connect"))
args = ap.parse_args()
binpath = Path(args.bin)
if not binpath.exists():
subprocess.run(["go", "build", "-o", str(binpath), str(binpath.parent)],
check=True, cwd=binpath.parent)
fails = total = 0
def check(name, oracle_val, go_val):
nonlocal fails, total
total += 1
if json.dumps(oracle_val, sort_keys=True) != json.dumps(go_val, sort_keys=True):
fails += 1
print(f"DIVERGE {name}:\n oracle: {json.dumps(oracle_val)[:300]}\n go: {json.dumps(go_val)[:300]}")
for name in CLEAN:
g = run_go(binpath, {"op": "clean", "name": name})
check(f"clean:{name[:40]}", {"result": mc._clean_model_name(name)}, g)
for name in MOE:
g = run_go(binpath, {"op": "moe", "name": name})
check(f"moe:{name}", {"result": mc.is_moe_model(name)}, g)
for task, models in ROUTE:
g = run_go(binpath, {"op": "route", "task": task, "models": models})
check(f"route:{task}", mc.route_model(task, models), g)
for mid in CTX:
g = run_go(binpath, {"op": "ctx_budget", "model": mid})
check(f"ctx_budget:{mid}", {"result": mc._ctx_budget(mid)}, g)
saved_dt = mc.datetime
mc.datetime = frozen_clock()
try:
g = run_go(binpath, {"op": "now"}, env={"MCONN_CLOCK": FROZEN_NOW})
check("now", {"result": mc._now()}, g)
finally:
mc.datetime = saved_dt
for event, data in HOOKS:
g = run_go(binpath, {"op": "hook", "event": event, "data": data})
check(f"hook:{event}", {"result": mc.handle_hook(event, data)}, g)
saved_home = os.environ.get("HOME")
try:
for label, fixture in FIXTURES.items():
with tempfile.TemporaryDirectory() as td:
cfg = os.path.join(td, ".config", "mimocode")
os.makedirs(cfg)
with open(os.path.join(cfg, "mimocode.jsonc"), "w") as f:
f.write(fixture)
os.environ["HOME"] = td
oracle_val = mc._get_cloud_models()
g = run_go(binpath, {"op": "cloud_models"}, env={"HOME": td})
check(f"cloud:{label}", {"result": oracle_val}, g)
with tempfile.TemporaryDirectory() as td:
os.environ["HOME"] = td
oracle_val = mc._get_cloud_models()
g = run_go(binpath, {"op": "cloud_models"}, env={"HOME": td})
check("cloud:missing", {"result": oracle_val}, g)
finally:
if saved_home is not None:
os.environ["HOME"] = saved_home
print(f"parity: {total - fails}/{total} match")
return 1 if fails else 0
if __name__ == "__main__":
sys.exit(main())
+337
View File
@@ -0,0 +1,337 @@
#!/usr/bin/env python3
"""check_model_profiles_parity.py — live oracle-vs-Go parity sweep for the
model_profiles gap closure (#2479, contract factory-gap-mp).
The frozen envelope (frozen_mp_truth.json, 36 cases) pins the seam
surface byte-identically. THIS script drives the LIVE Python oracle
(src/rune/model_profiles.py) and the Go binary across the broader
surface the frozen corpus samples: every model family + unknown,
parameter/quantization edge shapes, the sanitization matrix, the
to_dict/from_dict lens (incl. unknown-key filtering and defaults),
build assembly across families (uncensored tier, display/size
overrides), record sequences (dedup, empty-topic, success mix),
prompt-context shapes, the scan sweep against a canned Ollama server
(fresh + existing-preservation + banker's rounding + nameless skip +
dead-port degrade), and save/load round-trips (byte-identical raw
text). Timestamps are pinned via the binary's "now" seam and the
oracle's module-global datetime patch; stores are per-case hermetic
temp dirs on both sides.
Usage: PYTHONPATH=src python3 scripts/check_model_profiles_parity.py
[--bin src/go/model-profiles/model-profiles]
Exit 0 on 100% parity, 1 with the first divergence.
"""
import argparse
import dataclasses
import json
import os
import shutil
import subprocess
import sys
import tempfile
import threading
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
from pathlib import Path
REPO = Path(__file__).resolve().parent.parent
sys.path.insert(0, str(REPO / "src"))
import rune.model_profiles as mp # noqa: E402
FROZEN_NOW = "2026-10-13T09:41:23.123456"
NAMES = [
"qwen2.5:7b", "Qwen3:14b", "llama3.1:8b", "mistral-7b", "gemma2:9b",
"phi3:mini", "deepseek-r1:32b", "DavidAU-Qwen-14b", "some-new-model",
"library/qwen3:14b", "a?b:c/d", "model-70B-GGUF", "Qwen2.5-0.5b",
"dolphin-uncensored:7b", "qwen2.5:14b-instruct-q5_K_M",
"llama-3-8b-Q4_K_M", "deepseek-r1:70b-IQ2_M", "phi-4-14b-int4",
"model-3B-FP16", "tiny-INT8", "x-GGUF-fp32",
]
QUANT_NAMES = [
"m-Q4_K_M", "m-IQ3_XS", "m-q5_k_m", "m-iq2_m", "m-GGUF", "m-gguf",
"m-FP16", "m-FP32", "m-INT8", "m-INT4", "m-none",
]
BUILD_CASES = [
("qwen3:14b", {"display_name": "Qwen3 14B", "size_gb": 9.0}),
("mistral-7b", None),
("llama3.1:8b", {"display_name": "L", "size_gb": 4.5}),
("gemma2:9b", {"display_name": "G"}),
("phi3:mini", {"size_gb": 2.1}),
("deepseek-r1:32b", {"display_name": "DS", "size_gb": 19.2}),
("DavidAU-X:7b", None),
("dolphin-uncensored:7b", None),
("mystery-model", None),
("mystery-model", {"display_name": "M", "size_gb": 1.5}),
]
RECORD_SEQS = [
[[True, ""]],
[[False, "refuses weapons"]],
[[False, "t1"], [False, "t1"]],
[[False, ""]],
[[True, ""], [False, "a"], [True, ""], [False, "b"], [False, "a"]],
[[False, "x"], [False, "y"], [False, "z"]],
]
CTX_SEEDS = [
{"name": "full:1b", "strengths": ["s1", "s2", "s3", "s4"],
"prompting_tips": ["tip one", "tip two"],
"known_refusal_topics": ["r1", "r2", "r3", "r4"], "safety_tier": 2},
{"name": "tips:1b", "prompting_tips": ["only tip"]},
{"name": "tier:1b", "safety_tier": 1},
{"name": "refusals:1b", "known_refusal_topics": ["r1"]},
]
SCAN_MODELS = [
{"name": "qwen2.5:7b", "size": 7516192768},
{"name": "banker-lo:2b", "size": 2415919104},
{"name": "banker-hi:2b", "size": 2952790016},
{"name": "llama3.1:8b", "size": 4831838208},
{"size": 999},
{"name": "sizeless:1b"},
]
class _TagsHandler(BaseHTTPRequestHandler):
payload = b"{}"
def do_GET(self):
self.send_response(200)
self.send_header("Content-Type", "application/json")
self.send_header("Content-Length", str(len(self.payload)))
self.end_headers()
self.wfile.write(self.payload)
def log_message(self, *a):
pass
def canned_server(fixture):
handler = type("H", (_TagsHandler,),
{"payload": json.dumps(fixture).encode()})
srv = ThreadingHTTPServer(("127.0.0.1", 0), handler)
threading.Thread(target=srv.serve_forever, daemon=True).start()
return srv
def run_go(binpath, req):
p = subprocess.run([str(binpath)], input=json.dumps(req),
capture_output=True, text=True)
if p.returncode != 0:
raise RuntimeError(
f"go op {req.get('op')} exited {p.returncode}: {p.stdout} {p.stderr}")
return json.loads(p.stdout)["result"]
def fresh_store():
d = tempfile.mkdtemp(prefix="mp_parity_")
return os.path.join(d, ".rune", "model_profiles")
def oracle_in_store(store):
"""Point the oracle at a hermetic store (PROFILES_DIR is module-global)."""
mp.PROFILES_DIR = store
def main():
ap = argparse.ArgumentParser()
ap.add_argument("--bin", default=str(
REPO / "src/go/model-profiles/model-profiles"))
args = ap.parse_args()
binpath = Path(args.bin)
if not binpath.exists():
binpath = Path("/tmp/mp-go")
fails = total = 0
def canon(v):
# Integral-float law (the context_broker precedent): the oracle's
# build path assigns int 0 where the dataclass declares float
# (size_gb=0 vs 0.0) — numerically identical, textually distinct.
# Canonicalize integral floats to int on BOTH sides before compare.
if isinstance(v, float) and v.is_integer():
return int(v)
if isinstance(v, dict):
return {k: canon(x) for k, x in v.items()}
if isinstance(v, list):
return [canon(x) for x in v]
return v
def check(name, oracle_val, go_val):
nonlocal fails, total
total += 1
if json.dumps(canon(oracle_val), sort_keys=True) != json.dumps(canon(go_val), sort_keys=True):
fails += 1
print(f"DIVERGE {name}:\n oracle: {json.dumps(oracle_val)[:300]}\n"
f" go: {json.dumps(go_val)[:300]}")
# pure detection surface (no store, no clock)
for n in NAMES:
check(f"family:{n}", mp.detect_family(n),
run_go(binpath, {"op": "detect_family", "name": n}))
for n in NAMES + QUANT_NAMES:
check(f"params:{n}", mp.detect_parameters(n),
run_go(binpath, {"op": "detect_parameters", "name": n}))
check(f"quant:{n}", mp.detect_quantization(n),
run_go(binpath, {"op": "detect_quantization", "name": n}))
for inter, succ in [(0, 0), (1, 1), (10, 7), (4, 0), (3, 2)]:
p = mp.ModelProfile(name="x", interactions=inter, successes=succ)
check(f"success_rate:{inter}/{succ}", p.success_rate,
run_go(binpath, {"op": "success_rate",
"interactions": inter, "successes": succ}))
# sanitization matrix (compare file NAMES — store roots differ)
for n in NAMES:
store = fresh_store()
oracle_in_store(store)
oracle_name = os.path.basename(mp.get_profile_path(n))
go_name = run_go(binpath, {"op": "get_profile_path",
"name": n, "store": store})
check(f"path:{n}", oracle_name, go_name)
# to_dict / from_dict lens
full = mp.ModelProfile(
name="qwen2.5:7b", display_name="Q ✓", family="qwen",
parameters="7B", quantization="Q4_K_M", size_gb=4.7,
strengths=["a", "b"], weaknesses=["c"], prompting_tips=["t1"],
safety_tier=2, known_refusal_topics=["r1"],
thinking_format="<think>", response_style="concise",
context_window=32768, optimal_temperature=0.7,
interactions=10, successes=7, failures=3,
last_used="2026-10-12T00:00:00+00:00",
created="2026-10-01T00:00:00+00:00")
check("to_dict:full", full.to_dict(),
run_go(binpath, {"op": "to_dict", **full.to_dict()}))
for doc in ({"name": "n", "bogus": 1, "context_window": 8192},
{"name": "n2"},
dataclasses.asdict(full)):
check(f"from_dict:{doc.get('name')}",
dataclasses.asdict(mp.ModelProfile.from_dict(doc)),
run_go(binpath, {"op": "from_dict", **doc}))
# build assembly (pin the oracle clock; binary takes "now")
import datetime as dtmod
real_dt = dtmod.datetime
class FrozenDT(real_dt):
@classmethod
def now(cls, tz=None):
base = real_dt(2026, 10, 13, 9, 41, 23, 123456)
return base.replace(tzinfo=tz) if tz is not None else base
mp.datetime = FrozenDT
try:
for name, info in BUILD_CASES:
oracle = dataclasses.asdict(
mp.build_profile_from_ollama(name, info))
go = run_go(binpath, {"op": "build_profile", "name": name,
"model_info": info, "now": FROZEN_NOW + "+00:00"})
check(f"build:{name}", oracle, go)
finally:
mp.datetime = real_dt
# record sequences + prompt context (hermetic store each, both
# sides replay the same sequence from empty, then compare docs)
mp.datetime = FrozenDT
try:
for i, seq in enumerate(RECORD_SEQS):
ostore, gstore = fresh_store(), fresh_store()
oracle_in_store(ostore)
for success, topic in seq:
mp.record_interaction(f"m{i}:1b", success, topic)
for success, topic in seq:
run_go(binpath, {"op": "record", "name": f"m{i}:1b",
"success": success, "topic": topic,
"store": gstore, "now": FROZEN_NOW + "+00:00"})
oracle_in_store(ostore)
o_doc = dataclasses.asdict(mp.load_profile(f"m{i}:1b"))
g_doc = run_go(binpath, {"op": "load_profile",
"name": f"m{i}:1b", "store": gstore})
check(f"record-x[{i}]", o_doc, g_doc)
finally:
mp.datetime = real_dt
for seed in CTX_SEEDS:
name = seed["name"]
ostore, gstore = fresh_store(), fresh_store()
oracle_in_store(ostore)
mp.save_profile(mp.ModelProfile.from_dict(seed))
go_state = dict(seed)
run_go(binpath, {"op": "save_profile", "store": gstore, **go_state})
oracle_in_store(ostore)
o_ctx = mp.get_prompt_context(name)
g_ctx = run_go(binpath, {"op": "prompt_context",
"name": name, "store": gstore})
check(f"ctx:{name}", o_ctx, g_ctx)
# save/load round-trip byte parity (raw file text)
for doc in (dataclasses.asdict(full), {"name": "plain-model"},
{"name": "d:1b", "family": "deepseek", "size_gb": 0.0,
"safety_tier": 3, "optimal_temperature": 0.6}):
ostore, gstore = fresh_store(), fresh_store()
oracle_in_store(ostore)
mp.save_profile(mp.ModelProfile.from_dict(doc))
with open(mp.get_profile_path(doc["name"])) as f:
o_raw = f.read()
g_raw = run_go(binpath, {"op": "save_profile",
"store": gstore, **doc})
check(f"save-raw:{doc['name']}", o_raw, g_raw)
# scan sweep (canned server; existing-preservation; dead degrade)
for label, fixture, seed in (
("fresh", {"models": SCAN_MODELS}, None),
("existing", {"models": SCAN_MODELS[:3]}, {"name": "qwen2.5:7b",
"family": "qwen", "interactions": 5, "successes": 4,
"known_refusal_topics": ["old"], "size_gb": 1.0}),
("empty", {"models": []}, None),
("nameless", {"models": [{"size": 1}, {}]}, None)):
srv = canned_server(fixture)
url = f"http://127.0.0.1:{srv.server_address[1]}"
try:
ostore, gstore = fresh_store(), fresh_store()
oracle_in_store(ostore)
if seed:
mp.save_profile(mp.ModelProfile.from_dict(seed))
# seed the GO store with the same file the oracle has
os.makedirs(gstore, exist_ok=True)
for f in os.listdir(ostore):
shutil.copy(os.path.join(ostore, f),
os.path.join(gstore, f))
saved_url = mp.OLLAMA_URL
mp.OLLAMA_URL = url
mp.datetime = FrozenDT
try:
o_profiles = [dataclasses.asdict(p)
for p in mp.scan_all_models()]
finally:
mp.OLLAMA_URL = saved_url
mp.datetime = real_dt
g_profiles = run_go(binpath, {"op": "scan", "store": gstore,
"ollama_url": url,
"now": FROZEN_NOW + "+00:00"})
check(f"scan:{label}", o_profiles, g_profiles)
finally:
srv.shutdown()
# dead-port degrade
ostore, gstore = fresh_store(), fresh_store()
oracle_in_store(ostore)
saved_url = mp.OLLAMA_URL
mp.OLLAMA_URL = "http://127.0.0.1:1"
try:
o_dead = mp.scan_all_models()
finally:
mp.OLLAMA_URL = saved_url
g_dead = run_go(binpath, {"op": "scan", "store": gstore,
"ollama_url": "http://127.0.0.1:1"})
check("scan:dead", o_dead, g_dead)
print(f"parity: {total - fails}/{total} match")
return 1 if fails else 0
if __name__ == "__main__":
raise SystemExit(main())
+225
View File
@@ -0,0 +1,225 @@
#!/usr/bin/env python3
"""check_model_registry_parity.py — LIVE parity for the model_registry GO
port (#2479 dichotomy gap-close): drives the Python oracle
(src/rune/model_registry.py, through the scripts/mreg_freeze_seams seam
wrappers) and the GO binary through IDENTICAL ops and diffs their JSON
outputs — beyond frozen-truth replay, this exercises the two
implementations LIVE against arbitrary inputs, including the corrected
TOOL_RESULT_RESERVE=1024 (the batch-67 port shipped 2048).
Usage (the seam rig must bind the wrappers — PYTHONPATH carries it):
cd src/go/model-registry && go build -o /tmp/model-registry .
PYTHONPATH=scripts/mreg_freeze_seams:src \
python3 scripts/check_model_registry_parity.py /tmp/model-registry
"""
import json
import os
import subprocess
import sys
from pathlib import Path
REPO = Path(__file__).resolve().parent.parent
sys.path.insert(0, str(REPO / "src"))
# RUNE_*_CORE=python pin: model_registry has NO loader seam (pure Python)
# — the env is set for uniformity with the other parity checkers; the
# oracle ignores it (documented vacuous pin).
os.environ.setdefault("RUNE_MODEL_REGISTRY_CORE", "python")
import rune.model_registry as mr # noqa: E402
if not hasattr(mr, "seam_get_profile"):
sys.exit("seam rig not bound — run with PYTHONPATH=scripts/mreg_freeze_seams:src")
T0FULL = {
"id": "deterministic", "provider": "local", "tier": "T0",
"local": True, "context_window": 0,
"supports_tools": False, "supports_structured_output": False,
"supports_reasoning_field": False,
"estimated_latency": "instant", "estimated_cost": "0", "enabled": True,
}
T1FULL = {
"id": "qwen2.5:3b", "provider": "ollama", "tier": "T1",
"local": True, "context_window": 32768,
"supports_tools": False, "supports_structured_output": False,
"supports_reasoning_field": False,
"estimated_latency": "low", "estimated_cost": "0", "enabled": True,
}
T2FULL = {
"id": "qwen3:14b", "provider": "ollama", "tier": "T2",
"local": True, "context_window": 32768,
"supports_tools": False, "supports_structured_output": False,
"supports_reasoning_field": False,
"estimated_latency": "medium", "estimated_cost": "0", "enabled": True,
}
T4FULL = {
"id": "mimo-v2.5-pro", "provider": "openai", "tier": "T4",
"local": False, "context_window": 128000,
"supports_tools": True, "supports_structured_output": True,
"supports_reasoning_field": True,
"estimated_latency": "higher", "estimated_cost": "paid", "enabled": True,
}
def tweak(base, **kw):
p = dict(base)
p.update(kw)
return p
STATE_H = [["T1", T1FULL],
["X0", tweak(T0FULL, id="x0", context_window=4096, enabled=False,
estimated_latency="low")],
["T2", T2FULL]]
STATE_FLOOR = [["tiny", tweak(T4FULL, id="tiny-cloud", tier="T9",
context_window=1100, estimated_latency="low")]]
STATE_DUP = [
["fake", tweak(T4FULL, local=True, provider="ollama", tier="T4",
context_window=32768, estimated_latency="medium")],
["real", T4FULL],
]
STATE_CROSS = [["K1", tweak(T1FULL, id="p1", tier="T9")]]
STATE_ODD = [["T4", T4FULL],
["TX", tweak(T2FULL, id="odd", tier="TX", supports_tools=True)]]
STATE_ODD_R = [["TX", tweak(T2FULL, id="odd", tier="TX", supports_tools=True)],
["T4", T4FULL]]
STATE_TIE = [["TA", tweak(T2FULL, id="first")],
["TB", tweak(T2FULL, id="second")]]
STATE_ALL_OFF = [["T1", tweak(T1FULL, enabled=False)],
["T2", tweak(T2FULL, enabled=False)]]
def run_python(ops):
steps = []
for op in ops:
k = op["op"]
state = op.get("state")
if k == "to_dict":
r = mr.seam_to_dict(state)
elif k == "get_profile":
r = mr.seam_get_profile(state, op["tier"])
elif k == "get_enabled_profiles":
r = mr.seam_get_enabled_profiles(state)
elif k == "get_profiles_by_tier":
r = mr.seam_get_profiles_by_tier(state, op["tier"])
elif k == "get_cheapest_capable":
r = mr.seam_get_cheapest_capable(
state, op["tools"], op["structured"], op["reasoning"])
elif k == "list_profiles":
r = mr.seam_list_profiles(state)
elif k == "resolve":
r = mr.seam_resolve_budget(op["model"], op["kind"], None)
elif k == "resolve_custom":
# RAW registry (no ctor fallback) — matches the binary's
# resolve_custom op (registryFromRaw semantics)
reg = mr.ModelRegistry.__new__(mr.ModelRegistry)
reg.profiles = {key: mr.ModelProfile(**p) for key, p in state}
r = mr.resolve_context_budget(op["model"], op["kind"], reg)
elif k == "test_registry":
r = mr.seam_test_registry()
else:
raise ValueError(k)
steps.append({"op": k, "result": r})
return {"steps": steps}
def run_go(binary, ops_path):
r = subprocess.run([binary, "scenario", str(ops_path)],
capture_output=True, text=True, timeout=120)
if r.returncode != 0:
raise RuntimeError(f"go scenario failed: {r.stderr}")
return json.loads(r.stdout)
SCENARIOS = [
# 1: profile surface — to_dict, listings (order-proof), key-vs-attr
{"ops": [
{"op": "to_dict", "state": T0FULL},
{"op": "to_dict", "state": T4FULL},
{"op": "list_profiles", "state": []},
{"op": "list_profiles", "state": STATE_H},
{"op": "get_profile", "tier": "T1"},
{"op": "get_profile", "tier": "TX"},
{"op": "get_profile", "state": STATE_CROSS, "tier": "K1"},
{"op": "get_profile", "state": STATE_CROSS, "tier": "T9"},
{"op": "get_enabled_profiles", "state": []},
{"op": "get_enabled_profiles", "state": STATE_H},
{"op": "get_profiles_by_tier", "tier": "T2"},
{"op": "get_profiles_by_tier", "state": STATE_CROSS, "tier": "T9"},
{"op": "get_profiles_by_tier", "state": STATE_H, "tier": "T2"},
]},
# 2: cheapest matrix + odd-tier/​stable-tie/disabled branches
{"ops": [
{"op": "get_cheapest_capable", "state": [],
"tools": False, "structured": False, "reasoning": False},
{"op": "get_cheapest_capable", "state": [],
"tools": True, "structured": False, "reasoning": False},
{"op": "get_cheapest_capable", "state": [],
"tools": False, "structured": True, "reasoning": False},
{"op": "get_cheapest_capable", "state": [],
"tools": False, "structured": False, "reasoning": True},
{"op": "get_cheapest_capable", "state": [],
"tools": True, "structured": True, "reasoning": True},
{"op": "get_cheapest_capable", "state": STATE_ODD,
"tools": True, "structured": False, "reasoning": False},
{"op": "get_cheapest_capable", "state": STATE_ODD_R,
"tools": True, "structured": False, "reasoning": False},
{"op": "get_cheapest_capable", "state": STATE_TIE,
"tools": False, "structured": False, "reasoning": False},
{"op": "get_cheapest_capable", "state": STATE_ALL_OFF,
"tools": False, "structured": False, "reasoning": False},
]},
# 3: budget sweep — default registry × kinds + the FLAG FIX rows
{"ops": [
{"op": "resolve", "model": "", "kind": "default"},
{"op": "resolve", "model": "", "kind": "embed"},
{"op": "resolve", "model": "qwen2.5:3b", "kind": "verify"},
{"op": "resolve", "model": "qwen3:14b", "kind": "summarize"},
{"op": "resolve", "model": "mimo-v2.5-pro", "kind": "default"},
{"op": "resolve", "model": "mimo-v2.5-pro", "kind": "summarize"},
{"op": "resolve", "model": "mimo-v2.5-pro", "kind": "embed"},
{"op": "resolve", "model": "deterministic", "kind": "default"},
{"op": "resolve", "model": "no-such-model", "kind": "weirdkind"},
]},
# 4: custom registries — floor, duplicate-id first-match, empty raw,
# ctor-falsy default (through the seam = ctor path)
{"ops": [
{"op": "resolve_custom", "state": STATE_FLOOR,
"model": "tiny-cloud", "kind": "default"},
{"op": "resolve_custom", "state": STATE_DUP,
"model": "mimo-v2.5-pro", "kind": "default"},
{"op": "resolve_custom", "state": [],
"model": "ghost", "kind": "verify"},
{"op": "resolve", "model": "qwen2.5:3b", "kind": "verify"},
{"op": "test_registry"},
]},
]
def main():
binary = sys.argv[1] if len(sys.argv) > 1 else "/tmp/model-registry"
ok = 0
for i, sc in enumerate(SCENARIOS, 1):
with open("/tmp/mreg_scenario.json", "w") as f:
json.dump(sc, f)
py = run_python(sc["ops"])
go = run_go(binary, "/tmp/mreg_scenario.json")
if py == go:
ok += 1
print(f"scenario {i}: LIVE PARITY OK ({len(sc['ops'])} ops)")
else:
print(f"scenario {i}: LIVE PARITY FAILED")
pj = json.dumps(py, indent=1, sort_keys=True)
gj = json.dumps(go, indent=1, sort_keys=True)
for pl, gl in zip(pj.splitlines(), gj.splitlines()):
if pl != gl:
print(f" py: {pl}")
print(f" go: {gl}")
break
return 1
print(f"LIVE PARITY: {ok}/{len(SCENARIOS)} scenarios identical (oracle vs GO)")
return 0
if __name__ == "__main__":
sys.exit(main())
+196
View File
@@ -0,0 +1,196 @@
#!/usr/bin/env python3
"""check_parallel_processor_parity.py — live oracle-vs-Go parity sweep for
the parallel_processor gap closure (#2479, contract factory-gap-pp).
The frozen envelope (truth.json) pins the ported surface byte-identically.
THIS script drives the LIVE Python oracle and the Go binary (stdin op
dispatch, `parallel-processor op`) across every op family — run_parallel,
run_parallel_with_args (full parse-branch matrix), class pools at several
worker counts, status, singleton/global lifecycle, crash parity — plus the
CLI surface (status / test / unknown / usage), comparing sort_keys JSON
(structural) or exact lines. Exit 0 on 100% parity.
Usage: PYTHONPATH=scripts/pp_freeze_seams:src python3 scripts/check_parallel_processor_parity.py
[--bin src/go/parallel-processor/parallel-processor]
"""
import argparse
import json
import os
import subprocess
import sys
from pathlib import Path
REPO = Path(__file__).resolve().parent.parent
sys.path.insert(0, str(REPO / "src"))
# the rig (on PYTHONPATH) pins threading.active_count to this and binds
# the spec seams; the Go seam is pinned to the same value per process.
FROZEN_ACTIVE = 4
import rune.parallel_processor as pp # noqa: E402
def s(kind, **kw):
d = {"kind": kind}
d.update(kw)
return d
# ── oracle side (rig seams give the spec grammar real callables) ────────────
def py_op(op, req):
if op == "run_parallel":
return pp.run_parallel([_zero(t) for t in req["tasks"]])
if op == "run_parallel_with_args":
return pp.run_parallel_with_args([_task(t) for t in req["tasks"]])
if op == "class_run_parallel":
p = pp.ParallelProcessor(req["max_workers"])
r = p.run_parallel([_zero(t) for t in req["tasks"]])
p.shutdown(wait=True)
return r
if op == "class_run_parallel_with_args":
p = pp.ParallelProcessor(req["max_workers"])
r = p.run_parallel_with_args([_task(t) for t in req["tasks"]])
p.shutdown(wait=True)
return r
if op == "get_status":
return pp.get_status()
if op == "class_get_status":
p = pp.ParallelProcessor(req["max_workers"])
r = {"result": p.get_status(), "max_workers": req["max_workers"]}
p.shutdown(wait=True)
return r
if op == "get_processor_status":
return pp._pp_get_processor_status()
if op == "shutdown_then_status":
return pp._pp_shutdown_then_status()
if op == "shutdown_then_run":
return pp._pp_shutdown_then_run()
if op == "new_bad":
return pp._pp_new_bad()
if op == "shutdown_processor_cycle":
return pp._pp_shutdown_processor_cycle()
raise ValueError(f"unknown op {op}")
def _zero(spec):
return pp._pp_spec_zero(spec)
def _task(spec):
return pp._pp_spec_task(spec)
# ── Go side (one fresh process per op) ──────────────────────────────────────
def go_op(binpath, op, req):
full = dict(req)
full["op"] = op
env = dict(os.environ)
env["PP_ACTIVE_THREADS"] = str(FROZEN_ACTIVE)
p = subprocess.run([str(binpath), "op"], input=json.dumps(full),
capture_output=True, text=True, env=env, cwd=str(REPO))
if p.returncode != 0:
raise RuntimeError(f"go op {op} exited {p.returncode}: {p.stdout} {p.stderr}")
return json.loads(p.stdout)
def jdump(v):
return json.dumps(v, sort_keys=True)
# ── the sweep ───────────────────────────────────────────────────────────────
OPS = [
("run_parallel", {"tasks": [s("call", fn="const", ret=1), s("call", fn="boom", msg="x"), 42, None, "s", True, 4.5, [1], {"a": 1}]}),
("run_parallel", {"tasks": []}),
("run_parallel", {"tasks": [s("call", fn="sleepret", ms=50, ret="a"), s("call", fn="sleepret", ms=5, ret="b"), s("call", fn="sleepret", ms=25, ret="c")]}),
("run_parallel_with_args", {"tasks": [
s("call", fn="echo", args=[1, 2], kwargs={"scale": 10}),
s("call", fn="add", args=[7, 8]),
s("call", fn="add", args=[2.25, 1]),
s("call", fn="boom", msg="wops"),
s("raw", value=3.5),
s("emptytuple"),
s("notcall", value=[3, 4]),
s("argsnotseq", fn="echo", value="xy"),
s("kwnotdict", fn="echo", value="kw"),
]}),
("class_run_parallel", {"max_workers": 2, "tasks": [s("call", fn="const", ret="p"), s("call", fn="const", ret="q"), s("call", fn="boom", msg="in-class"), s("call", fn="sleepret", ms=15, ret="r")]}),
("class_run_parallel", {"max_workers": 8, "tasks": [s("raw", value=False)] * 3 + [s("call", fn="const", ret="ok")]}),
("class_run_parallel_with_args", {"max_workers": 1, "tasks": [s("call", fn="echo"), s("notcall", value=0), s("call", fn="add", args=[20, 22])]}),
("get_status", {}),
("class_get_status", {"max_workers": 1}),
("class_get_status", {"max_workers": 9}),
("get_processor_status", {}),
("shutdown_then_status", {}),
("shutdown_then_run", {}),
("new_bad", {}),
("shutdown_processor_cycle", {}),
]
def cli_lines(argv, env_extra=None, cwd=None):
env = dict(os.environ)
if env_extra:
env.update(env_extra)
p = subprocess.run(argv, capture_output=True, text=True, env=env, cwd=cwd or str(REPO))
return p.returncode, p.stdout, p.stderr
def cli_parity(binpath):
"""CLI surface: status / test / unknown / usage — the oracle's main()."""
checks = []
go_env = {"PP_ACTIVE_THREADS": str(FROZEN_ACTIVE)}
rc_p, out_p, _ = cli_lines([sys.executable, str(REPO / "src/rune/parallel_processor.py"), "status"])
rc_g, out_g, _ = cli_lines([str(binpath), "status"], go_env)
checks.append(("cli status", rc_p == rc_g and out_p == out_g, out_p, out_g))
rc_p, out_p, _ = cli_lines([sys.executable, str(REPO / "src/rune/parallel_processor.py"), "test"])
rc_g, out_g, _ = cli_lines([str(binpath), "test"])
# wall-clock lines vary by design; the Results line and the verdict
# line are the deterministic contract
det = lambda out: (out.strip().splitlines()[-2], out.strip().splitlines()[-1]) # noqa: E731
checks.append(("cli test (results+verdict)", rc_p == rc_g and det(out_p) == det(out_g), det(out_p), det(out_g)))
rc_p, out_p, _ = cli_lines([sys.executable, str(REPO / "src/rune/parallel_processor.py"), "bogus"])
rc_g, out_g, _ = cli_lines([str(binpath), "bogus"])
checks.append(("cli unknown", rc_p == rc_g and out_p == out_g, out_p, out_g))
rc_p, out_p, _ = cli_lines([sys.executable, str(REPO / "src/rune/parallel_processor.py")])
rc_g, out_g, _ = cli_lines([str(binpath)])
checks.append(("cli usage", rc_p == rc_g and out_p == out_g, out_p, out_g))
return checks
def main() -> int:
ap = argparse.ArgumentParser()
ap.add_argument("--bin", default=str(REPO / "src/go/parallel-processor/parallel-processor"))
args = ap.parse_args()
binpath = Path(args.bin)
failures = 0
total = 0
for op, req in OPS:
total += 1
py = py_op(op, req)
go = go_op(binpath, op, req)
if jdump(py) != jdump(go):
failures += 1
print(f"DIVERGE {op} {json.dumps(req)[:80]}")
print(f" python: {jdump(py)[:300]}")
print(f" go: {jdump(go)[:300]}")
for name, ok, want, got in cli_parity(binpath):
total += 1
if not ok:
failures += 1
print(f"DIVERGE {name}\n python: {want!r}\n go: {got!r}")
print(f"parity: {total - failures}/{total} match" + (" — FAILURES" if failures else ""))
return 1 if failures else 0
if __name__ == "__main__":
raise SystemExit(main())
@@ -0,0 +1,335 @@
#!/usr/bin/env python3
"""Live parity: progressive_escalation Rust core vs Python oracle (dichotomy
wave, close-PARTIAL gap pass). Layers:
1. FROZEN — the gap truth corpus
(src/rust/progressive_escalation/frozen_truth.json, generated by
scripts/gen_progressive_escalation_truth.py under the
scripts/pe_freeze_seams rig against the LIVE oracle with
RUNE_PROGRESSION_ESCALATION_CORE=python pinned): harness rows (19
should_escalate + 10 get_next_tier + 3 handle_hook + 3 to_dict recv
rows) and the 12 loop scenarios replayed through the ctypes FFI;
PLUGIN asserted against pe_plugin.
2. FUZZ — seeded (2479): 300 should_escalate rows (random passed values
over the truthiness law, attempt/max boundaries, trigger/unknown/
None/absent reasons), 150 get_next_tier rows, 100 execute_with_escalation
scenarios (random budgets, canned per-tier executor results and
verifier verdicts) — oracle (with Python doubles) vs FFI kernel.
3. LIVE — dual-mode facade battery: execute_with_escalation over the
oracle's MockExecutor/MockVerifier contract (as _ScriptExecutor/
_Verdict doubles), should_escalate, get_next_tier, handle_hook
executed with RUNE_PROGRESSION_ESCALATION_CORE=python (oracle floor)
and with the Rust core live; results must be identical. Plus the
kernel-failure fallback (the facade degrades to the inline oracle).
Exit 0 only at 100% parity on the gap-closing functions.
"""
import copy
import dataclasses
import json
import os
import random
import sys
from pathlib import Path
REPO = Path(__file__).resolve().parents[1]
os.environ["RUNE_PROGRESSION_ESCALATION_CORE"] = "python" # oracle floor to start
sys.path.insert(0, str(REPO / "src"))
import rune.progressive_escalation as pe # noqa: E402
from rune import progressive_escalation_loader as core # noqa: E402
if not core.available():
sys.exit("FATAL: Rust core not built — cargo build --release in "
"src/rust/progressive_escalation")
TRUTH = json.loads(
(REPO / "src" / "rust" / "progressive_escalation" / "frozen_truth.json").read_text())
PLUGIN_WANT = json.loads(
(REPO / "src" / "rust" / "progressive_escalation" / "frozen_plugin.json").read_text())
fails: list[str] = []
counts = {"frozen": 0, "fuzz": 0, "live": 0}
def fail(layer, name, detail):
fails.append(f"[{layer}] {name}: {detail}")
print(f"FAIL[{layer}] {name}: {detail}"[:400])
def j(x):
return json.dumps(x, sort_keys=True, ensure_ascii=True, default=str)
def check(layer, name, want, got):
counts[layer] += 1
if j(want) != j(got):
fail(layer, name, f"want={j(want)[:300]} got={j(got)[:300]}")
def pin(mode):
"""Flip the facade pin at runtime (pe loader.core reads env per call)."""
if mode == "python":
os.environ["RUNE_PROGRESSION_ESCALATION_CORE"] = "python"
else:
os.environ.pop("RUNE_PROGRESSION_ESCALATION_CORE", None)
# ── layer 1: FROZEN (truth rows through the FFI kernels) ───────────────────
for c in TRUTH["cases"]:
fn, args = c["fn"], c["args"]
want = c["expected"]["result"] if "recv" in c else c["expected"]
if fn == "should_escalate":
check("frozen", f"pe_should_escalate:{args[1]}/{args[2]}:"
f"{args[0].get('escalation_reason')}", want,
core.should_escalate(args[0], args[1], args[2]))
elif fn == "get_next_tier":
check("frozen", f"pe_next_tier:{args[0]}/{args[1]}", want,
core.next_tier(args[0], args[1]))
elif fn == "handle_hook":
check("frozen", f"pe_handle_hook:{args[0]}", want,
core.handle_hook(args[0], args[1] if len(args) > 1 else None))
elif fn == "EscalationResult.to_dict":
check("frozen", "pe_escalation_result:recv", want,
core.escalation_result(c["recv"]))
else:
raise AssertionError(f"unknown frozen fn {fn}")
for s in TRUTH["extra"]["scenarios"]:
check("frozen", f"pe_execute:{s['name']}", s["expected"],
core.execute(s["job"], s["budget"], s["executor"], s["verifier"]))
check("frozen", "pe_plugin", PLUGIN_WANT, core.plugin())
# ── layer 2: FUZZ (oracle vs FFI kernel, seeded) ───────────────────────────
TRIGGER_SET = sorted(pe.ESCALATION_TRIGGERS)
PASS_VALUES = [True, False, 1, 0, "", "yes", None]
REASONS = TRIGGER_SET + ["mystery_reason", "", None]
rng = random.Random(2479)
for trial in range(300):
vr = {}
pick = rng.randrange(4)
if pick != 0:
vr["passed"] = PASS_VALUES[rng.randrange(len(PASS_VALUES))]
if pick != 1:
reason = REASONS[rng.randrange(len(REASONS))]
if reason is not None or rng.randrange(2):
vr["escalation_reason"] = reason
attempt = rng.randrange(0, 7)
max_attempts = rng.randrange(0, 7)
exp = pe.should_escalate(copy.deepcopy(vr), attempt, max_attempts)
got = core.should_escalate(copy.deepcopy(vr), attempt, max_attempts)
check("fuzz", f"should_escalate:{trial}", exp, got)
TIERS = ["T0", "T1", "T2", "T3", "T4"]
for trial in range(150):
current = rng.choice(TIERS + ["T9", "", "t0", "T5"])
max_tier = rng.choice(TIERS + ["", "T7"])
exp = pe.get_next_tier(current, max_tier)
got = core.next_tier(current, max_tier)
check("fuzz", f"next_tier:{trial}:{current}/{max_tier}", exp, got)
def _fz_doubles():
class _FzVerdict:
def __init__(self, doc):
self.passed = doc["passed"]
self.failures = doc["failures"]
self.escalation_reason = doc["escalation_reason"]
def to_dict(self):
return {"passed": self.passed, "failures": self.failures,
"escalation_reason": self.escalation_reason}
class _FzExecutor:
def __init__(self, per_tier):
self.per_tier = copy.deepcopy(per_tier)
def execute(self, job_arg, budget_arg):
tier = (job_arg.get("preferred_tiers") or ["T0"])[0]
return copy.deepcopy(self.per_tier.get(tier))
class _FzVerifier:
def __init__(self, per_tier):
self.per_tier = copy.deepcopy(per_tier)
def verify(self, result, verifier_type):
tier = result.get("tier_used", "T0")
return _FzVerdict(copy.deepcopy(self.per_tier.get(tier)))
return _FzExecutor, _FzVerifier
_FzExecutor, _FzVerifier = _fz_doubles()
def rand_result(tier, trial):
out = {
"tier_used": tier,
"model_used": f"model-{tier}",
"output": rng.choice(["plain", {"k": trial}, [trial, None], "", None]),
"success": rng.choice([True, False]),
}
if rng.randrange(5) == 0:
out["error"] = rng.choice(["boom", ""],)
return out
def rand_vr(tier, trial):
pick = rng.randrange(10)
if pick == 9:
return {"passed": True, "failures": [], "escalation_reason": None}
failures = rng.choice([[], [], [f"Failed at {tier}"], ["one"], []])
reason = rng.choice(["tests_fail", "schema_invalid", "mystery_reason"])
passed = False if pick != 0 else bool(rng.randrange(2))
return {"passed": passed, "failures": failures, "escalation_reason": reason}
# execute_with_escalation fuzz: the spec is built ONCE (seeded); the oracle
# runs with Python doubles, the kernel with the same spec via pe_execute.
for trial in range(100):
start = rng.choice(TIERS)
max_tier = rng.choice(TIERS)
attempts = rng.randrange(0, 6)
job = {"job_id": f"fz-{trial}"}
if rng.randrange(3):
job["verification_method"] = "unit_test"
budget = {"start_tier": start, "max_tier": max_tier,
"max_attempts": attempts}
executor_spec = {"per_tier": {
t: rand_result(t, trial) for t in TIERS}}
verifier_spec = {"per_tier": {t: rand_vr(t, trial) for t in TIERS}}
exp = dataclasses.asdict(pe.execute_with_escalation(
copy.deepcopy(job), copy.deepcopy(budget),
_FzExecutor(executor_spec["per_tier"]), _FzVerifier(verifier_spec["per_tier"])))
got = core.execute(copy.deepcopy(job), copy.deepcopy(budget),
executor_spec, verifier_spec)
check("fuzz", f"execute:{trial}:{start}/{max_tier}/{attempts}/"
f"{'vm' if 'verification_method' in job else 'novm'}", exp, got)
# ── layer 3: LIVE (dual-mode facade battery) ───────────────────────────────
SELF_TEST_JOB = {"job_id": "test-1", "task_family": "coding",
"objective": "Fix failing test",
"verification_method": "unit_test"}
SELF_TEST_BUDGET = {"start_tier": "T0", "max_tier": "T4", "max_attempts": 5}
class _Verdict:
"""The oracle's dynamic VerificationResult type."""
def __init__(self, doc):
self.passed = doc["passed"]
self.failures = doc["failures"]
self.escalation_reason = doc["escalation_reason"]
def to_dict(self):
return {"passed": self.passed, "failures": self.failures,
"escalation_reason": self.escalation_reason}
class MockExecutor:
"""The oracle's MockExecutor verbatim."""
def execute(self, job, budget):
tier = (job.get("preferred_tiers") or ["T0"])[0]
return {
"job_id": job.get("job_id"),
"tier_used": tier,
"model_used": f"model-{tier}",
"success": True,
"output": f"Result from {tier}",
}
class MockVerifier:
"""The oracle's MockVerifier contract (fail_until_tier)."""
def __init__(self, fail_until_tier="T2"):
self.fail_until_tier = fail_until_tier
def verify(self, result, verifier_type):
tier = result.get("tier_used", "T0")
passed = tier >= self.fail_until_tier
return _Verdict({
"passed": passed,
"failures": [] if passed else [f"Failed at {tier}"],
"escalation_reason": None if passed else "tests_fail",
})
CASES = [
("exec_self_test", lambda: dataclasses.asdict(
pe.execute_with_escalation(
copy.deepcopy(SELF_TEST_JOB), copy.deepcopy(SELF_TEST_BUDGET),
MockExecutor(), MockVerifier()))),
("exec_no_verification", lambda: dataclasses.asdict(
pe.execute_with_escalation(
{"job_id": "nv-1", "task_family": "coding"},
{"start_tier": "T1", "max_tier": "T4", "max_attempts": 5},
MockExecutor(), MockVerifier()))),
("should_escalate", lambda: pe.should_escalate(
{"passed": False, "failures": ["x"],
"escalation_reason": "tests_fail"}, 0, 3)),
("should_escalate_pass", lambda: pe.should_escalate(
{"passed": True}, 0, 3)),
("should_escalate_max", lambda: pe.should_escalate(
{"passed": False}, 4, 3)),
("next_tier", lambda: pe.get_next_tier("T0", "T4")),
("next_tier_at_max", lambda: pe.get_next_tier("T4", "T4")),
("hook", lambda: pe.handle_hook("progressive_escalation.ready")),
("hook_data", lambda: pe.handle_hook("tick", {"n": 1})),
]
results = {}
for mode in ("python", "live"):
pin(mode)
mode_out = {}
for name, fn in CASES:
try:
mode_out[name] = fn()
except Exception as e: # noqa: BLE001 — crash parity surfaces here
mode_out[name] = {"__crash__": f"{type(e).__name__}: {e}"}
results[mode] = mode_out
for name, _ in CASES:
check("live", f"dual:{name}", results["python"][name], results["live"][name])
# The oracle's own asserts hold under BOTH pins.
for mode_results in ("python", "live"):
s = results[mode_results]
assert s["exec_self_test"]["success"] is True, f"{mode_results}: self-test failed"
assert s["exec_self_test"]["final_tier"] >= "T2", f"{mode_results}: tier"
# kernel-failure fallback: patch the loader's core() to raise; the facade
# degrades to the inline oracle on every delegating surface.
pin("live")
real_core = pe._pe_core
try:
pe._pe_core = lambda: (_ for _ in ()).throw(RuntimeError("boom"))
check("live", "fallback:should_escalate", True,
pe.should_escalate({"passed": False, "escalation_reason": "tests_fail"}, 0, 3))
check("live", "fallback:should_escalate_pass", False,
pe.should_escalate({"passed": True}, 0, 3))
check("live", "fallback:next_tier", "T1", pe.get_next_tier("T0", "T4"))
check("live", "fallback:hook",
{"status": "ok", "event": "tick",
"handler": "progressive_escalation"},
pe.handle_hook("tick"))
fb = dataclasses.asdict(pe.execute_with_escalation(
copy.deepcopy(SELF_TEST_JOB), copy.deepcopy(SELF_TEST_BUDGET),
MockExecutor(), MockVerifier()))
check("live", "fallback:exec_self_test", results["python"]["exec_self_test"], fb)
finally:
pe._pe_core = real_core
pin("python")
print(f"parity: frozen={counts['frozen']} fuzz={counts['fuzz']} live={counts['live']} "
f"failures={len(fails)}")
sys.exit(1 if fails else 0)
+396
View File
@@ -0,0 +1,396 @@
#!/usr/bin/env python3
"""check_stage_guards_parity.py — live oracle-vs-Go parity sweep for the
stage_guards gap closure (#2479, contract factory-gap-cz).
The frozen envelope (truth.json, 40 cases + sg_seams.json, 30 rows)
pins the JSON-native surface byte-identically. THIS script drives the
LIVE Python oracle (in-process) and the Go binary (CLI subcommands:
to-dict / check / readiness / execute / liveness / verify-tests /
henxels-placement / reconcile) across the same branches plus the seams
the frozen corpus cannot reach: exception-message contracts
(StageBlocked / ExitCanaryFailed / FileNotFoundError crash parity on
bad cwd and missing binary), the action seam (None-action shape),
stderr/stdout separation, rune-safe tails under the [-500:] boundary,
and the NEW fns (StageContract.to_dict via chk — argv None vs [] vs
list, empty checks, full ten-key shape).
Usage: PYTHONPATH=src python3 scripts/check_stage_guards_parity.py
[--bin src/go/stage-guards/stage-guards]
Exit 0 on 100% parity, 1 with the first divergence count.
"""
from __future__ import annotations
import argparse
import json
import os
import shutil
import subprocess
import sys
import tempfile
from dataclasses import asdict
from pathlib import Path
REPO = Path(__file__).resolve().parent.parent
sys.path.insert(0, str(REPO / "src"))
import rune.stage_guards as sg # noqa: E402
from rune.stage_guards import ( # noqa: E402
ExitCanaryFailed, StageBlocked, StageCheck, StageContract,
TestExpectations,
)
PASS = 0
TOTAL = 0
def ok(name: str, cond: bool, detail: str = "") -> None:
global PASS, TOTAL
TOTAL += 1
if cond:
PASS += 1
else:
print(f"DIVERGE {name}: {detail}")
def run_go(binpath, *args) -> tuple[int, str, str]:
p = subprocess.run([str(binpath), *args], capture_output=True,
text=True, timeout=120)
return p.returncode, p.stdout, p.stderr
def go_json(binpath, *args) -> dict | list:
rc, out, err = run_go(binpath, *args)
if rc != 0:
raise RuntimeError(f"go {args[0]} exited {rc}: {out} {err}")
return json.loads(out)
def go_error(binpath, *args) -> str:
rc, out, err = run_go(binpath, *args)
if rc == 0:
raise RuntimeError(f"go {args[0]} unexpectedly succeeded: {out}")
for line in err.splitlines():
if line.startswith("error: "):
return line[len("error: "):]
return err.strip()
def stage_json(stage: StageContract) -> str:
return json.dumps(asdict(stage))
# ── §1 to_dict (the NEW fns: to_dict + nested chk) ──────────────────────────
def parity_to_dict(bin) -> None:
contracts = [
StageContract(
stage_id="sg-1", contract_id="contract:sg",
dependencies=["stage-a", "stage-b"],
ready_when=[StageCheck(name="probe", kind="path_exists",
path="/tmp/sg-parity/exists.bin")],
done_when=[StageCheck(name="echo", kind="command",
argv=["echo"]),
StageCheck(name="gate", kind="assert",
description="gate holds"),
StageCheck(name="bare", kind="command")],
invariants=[StageCheck(name="inv", kind="command")],
expected_effect="probes exist",
retry_class="KNOWN_PROCESS_DEFECT", idempotency_key="op-42"),
StageContract(stage_id="bare"),
StageContract(stage_id="argv-shapes", done_when=[
StageCheck(name="nil", kind="command"),
StageCheck(name="empty", kind="command", argv=[]),
StageCheck(name="list", kind="command", argv=["a", "b"]),
]),
]
for c in contracts:
py = c.to_dict()
go = go_json(bin, "to-dict", stage_json(c))
ok(f"to_dict:{c.stage_id}", py == go,
f"\npy: {json.dumps(py, sort_keys=True)}\ngo: {json.dumps(go, sort_keys=True)}")
# ── §2 _run_check sweep ─────────────────────────────────────────────────────
def parity_run_check(bin, scratch: Path) -> None:
exists = scratch / "exists.bin"
exists.write_bytes(b"12345")
empty = scratch / "empty.bin"
empty.write_bytes(b"")
checks = [
StageCheck(name="echo-ok", kind="command", argv=["/bin/echo", "ok"]),
StageCheck(name="pat-hit", kind="command",
argv=["/bin/echo", "hello 42 world"],
output_pattern="hello (\\d+)"),
StageCheck(name="pat-miss", kind="command",
argv=["/bin/echo", "hello 42 world"],
output_pattern="nope (\\d+)"),
StageCheck(name="false-with-pattern", kind="command",
argv=["/bin/false"], output_pattern="x (\\d+)"),
StageCheck(name="no-exec", kind="command",
argv=["/nonexistent/sg-parity-cmd"]),
StageCheck(name="no-argv", kind="command"),
StageCheck(name="path-hit", kind="path_exists", path=str(exists)),
StageCheck(name="path-empty", kind="path_exists", path=str(empty)),
StageCheck(name="path-miss", kind="path_exists",
path=str(scratch / "missing.bin")),
StageCheck(name="assert-nil", kind="assert", description="gate"),
StageCheck(name="assert-unnamed", kind="assert"),
StageCheck(name="bogus", kind="bogus", path="whatever"),
]
for c in checks:
py = sg._run_check(c)
go = go_json(bin, "check", json.dumps(asdict(c)))
ok(f"run_check:{c.name}", py == go,
f"\npy: {json.dumps(py, sort_keys=True)}\ngo: {json.dumps(go, sort_keys=True)}")
# ── §3 readiness + execute (incl. exception-message contracts) ─────────────
def parity_stages(bin, scratch: Path) -> None:
marker = scratch / "effect.txt"
stages = [
("ready-pass", StageContract(
stage_id="r1", ready_when=[
StageCheck(name="pre", kind="command", argv=["/bin/echo", "ok"]),
StageCheck(name="probe", kind="path_exists",
path=str(scratch / "exists.bin"))],
done_when=[
StageCheck(name="effect", kind="path_exists", path=str(marker))],
expected_effect="marker exists")),
]
for name, stage in stages:
py = sg.readiness_canary(stage)
go = go_json(bin, "readiness", stage_json(stage))
ok(f"readiness:{name}", py == go,
f"\npy: {json.dumps(py, sort_keys=True)}\ngo: {json.dumps(go, sort_keys=True)}")
# execute PASS with action=None (the CLI action seam)
marker.write_text("done")
stage = StageContract(
stage_id="x1",
ready_when=[StageCheck(name="pre", kind="command",
argv=["/bin/echo", "ok"])],
done_when=[StageCheck(name="effect", kind="path_exists",
path=str(marker))])
py = sg.execute_stage(stage, None)
go = go_json(bin, "execute", stage_json(stage))
ok("execute:pass-nil-action", py == go,
f"\npy: {json.dumps(py, sort_keys=True)}\ngo: {json.dumps(go, sort_keys=True)}")
# BLOCKED: Python raises StageBlocked; the MESSAGE is the contract
blocked = StageContract(
stage_id="xb1",
ready_when=[StageCheck(name="prereq", kind="path_exists",
path=str(scratch / "missing-prereq.bin"))])
try:
sg.execute_stage(blocked, lambda: {"never": "runs"})
py_msg = "NO-RAISE"
except StageBlocked as e:
py_msg = str(e)
go_msg = go_error(bin, "execute", stage_json(blocked))
ok("execute:blocked-message", py_msg == go_msg,
f"\npy: {py_msg!r}\ngo: {go_msg!r}")
# FAILED exit canary: action "succeeds" but the effect is absent
failed = StageContract(
stage_id="xf1",
ready_when=[StageCheck(name="pre", kind="command",
argv=["/bin/echo", "ok"])],
done_when=[StageCheck(name="effect", kind="path_exists",
path=str(scratch / "never-written.bin"))])
try:
sg.execute_stage(failed, lambda: {"claimed": "complete, trust me"})
py_msg = "NO-RAISE"
except ExitCanaryFailed as e:
py_msg = str(e)
go_msg = go_error(bin, "execute", stage_json(failed))
ok("execute:failed-message", py_msg == go_msg,
f"\npy: {py_msg!r}\ngo: {go_msg!r}")
# ── §4 liveness (quarter ties + boundaries) ─────────────────────────────────
def parity_liveness(bin) -> None:
rows = [
(100.0, 100.25, 300.0), (100.0, 400.25, 300.0),
(100.0, 100.75, 0.5), (100.25, 400.5, 300.25),
(100.5, 88.25, 300.0), (0.0, 12.5, 12.5), (10.0, 12.75, 2.5),
]
for last, now, limit in rows:
py = sg.liveness_canary(last, now=now, stall_limit_secs=limit)
go = go_json(bin, "liveness", repr(last), repr(now), repr(limit))
ok(f"liveness:{now - last}", py == go,
f"\npy: {json.dumps(py, sort_keys=True)}\ngo: {json.dumps(go, sort_keys=True)}")
# ── §5 verify_test_truth (§15G false-green classes + crash parity) ─────────
def parity_verify(bin, scratch: Path) -> None:
def runner(name: str, body: str) -> str:
p = scratch / name
p.write_text(body)
p.chmod(0o755)
return f"./{name}"
green = runner("green.sh", '#!/bin/bash\necho "# pass 5"\nexit 0\n')
silent = runner("silent.sh", "#!/bin/bash\nexit 0\n")
skipped = runner("skipped.sh",
'#!/bin/bash\necho "# pass 5"\necho "# skipped 5"\nexit 0\n')
exit2 = runner("exit2.sh", '#!/bin/bash\necho "# pass 4"\nexit 2\n')
noise = runner("noise.sh",
'#!/bin/bash\necho "noise on stderr" >&2\necho "# pass 7"\nexit 0\n')
long_line = "a" * 490 + "é" * 12
long_r = runner("long.sh", f"#!/bin/bash\necho '{long_line}'\nexit 0\n")
art = scratch / "art.js"
art.write_text("export const x = 1\n")
empty_art = scratch / "empty.js"
empty_art.write_text("")
rows = [
(["bash", "-c", "echo '# pass 5'"], {},
TestExpectations(require_tests=True)),
([green], {}, TestExpectations(require_tests=True)),
([silent], {}, TestExpectations(require_tests=True)),
([green], {}, TestExpectations(min_tests=11)),
([skipped], {}, TestExpectations(require_tests=True)),
([exit2], {}, TestExpectations(require_tests=True)),
([green], {"required_artifacts": ["no-such.js"]},
TestExpectations(require_tests=True)),
([green], {"required_artifacts": ["art.js"]},
TestExpectations(require_tests=True)),
([green], {"required_artifacts": ["empty.js"]},
TestExpectations(require_tests=True)),
([silent], {}, TestExpectations(require_tests=False)),
([noise], {}, TestExpectations(require_tests=True)),
([long_r], {}, TestExpectations(require_tests=False)),
([green], {"base_dir": str(scratch.parent)},
TestExpectations(require_tests=True, required_artifacts=[
str(scratch.relative_to(scratch.parent))])),
]
for i, (cmd, exp_kwargs, expectations) in enumerate(rows):
base = exp_kwargs.pop("base_dir", str(scratch))
py = sg.verify_test_truth(cmd, str(scratch), expectations,
base_dir=base)
expd = {"require_tests": expectations.require_tests,
"min_tests": expectations.min_tests}
if expectations.test_output_pattern:
expd["test_output_pattern"] = expectations.test_output_pattern
if expectations.forbid_all_skipped:
expd["forbid_all_skipped"] = expectations.forbid_all_skipped
if expectations.required_artifacts:
expd["required_artifacts"] = expectations.required_artifacts
go = go_json(bin, "verify-tests", json.dumps(cmd), str(scratch),
json.dumps(expd), base)
ok(f"verify:{i}:{cmd[0].split('/')[-1]}", py == go,
f"\npy: {json.dumps(py, sort_keys=True)}\ngo: {json.dumps(go, sort_keys=True)}")
# crash parity: bad cwd — Python raises FileNotFoundError naming the DIR
try:
sg.verify_test_truth([green], str(scratch / "no-such-dir"),
TestExpectations(), base_dir=".")
py_msg = "NO-RAISE"
except FileNotFoundError as e:
py_msg = str(e)
rc, out, err = run_go(bin, "verify-tests", json.dumps([green]),
str(scratch / "no-such-dir"), "{}", ".")
go_msg = err.strip()
if go_msg.startswith("error: "):
go_msg = go_msg[len("error: "):]
ok("verify:bad-cwd-crash", rc != 0 and py_msg == go_msg,
f"\npy: {py_msg!r}\ngo: rc={rc} {go_msg!r}")
# crash parity: missing binary
try:
sg.verify_test_truth(["/nonexistent/sg-parity-runner"], str(scratch),
TestExpectations(), base_dir=".")
py_msg = "NO-RAISE"
except FileNotFoundError as e:
py_msg = str(e)
rc, out, err = run_go(bin, "verify-tests",
json.dumps(["/nonexistent/sg-parity-runner"]),
str(scratch), "{}", ".")
go_msg = err.strip()
if go_msg.startswith("error: "):
go_msg = go_msg[len("error: "):]
ok("verify:missing-bin-crash", rc != 0 and py_msg == go_msg,
f"\npy: {py_msg!r}\ngo: rc={rc} {go_msg!r}")
# ── §6 henxels placement ────────────────────────────────────────────────────
def parity_henxels(bin) -> None:
rows = [
("STANDARD", True, "s-structural"),
("FULL", False, "s-full"),
("PROJECT_BUILD", False, "s-project"),
("LIGHT", False, "s-typo"),
("TINY", False, "s-tiny"),
]
for depth, structural, sid in rows:
py = sg.henxels_placement(depth=depth,
structural_boundary=structural,
stage_id=sid)
go = go_json(bin, "henxels-placement", depth,
"true" if structural else "false", sid)
ok(f"henxels:{depth}:{structural}", py == go,
f"\npy: {json.dumps(py, sort_keys=True)}\ngo: {json.dumps(go, sort_keys=True)}")
# ── §7 reconcile (public seam: read_actual closure) ─────────────────────────
def parity_reconcile(bin) -> None:
rows = [
({"a": 1, "b": "x"}, {"a": 1, "b": "x"}, [], "s1"),
({"a": 1}, {"a": 2}, [], "s1"),
({"a": 1, "b": 2}, {"a": 9, "b": 2}, ["a"], "s1"),
({"a": 1}, {}, [], "s2"),
({"flag": True}, {"flag": True}, [], "sb"), # bool equal (stable)
({"flag": True}, {"flag": "yes"}, [], "sbf"), # bool mismatch (stable)
# bool-vs-number rows are excluded by the truth-stability law: the
# Rust kernel says True != 1 while Python == reconciles — divergence
# documented in sg-summary.md, pinned only via _py_reconcile truth.
({"a": None}, {}, [], "s6"), # want-None quirk
({}, {"a": 1}, [], "s4"),
({"items": [1, 2]}, {"items": [1, 2, 3]}, [], "s9"),
({"f": 1.5}, {"f": 1.5}, [], "s10"),
]
for desired, actual, tol, sid in rows:
py = sg.reconcile(desired, lambda a=actual: a, stage_id=sid,
tolerance=set(tol))
go = go_json(bin, "reconcile", json.dumps(desired),
json.dumps(actual), sid, json.dumps(tol))
ok(f"reconcile:{sid}", py == go,
f"\npy: {json.dumps(py, sort_keys=True)}\ngo: {json.dumps(go, sort_keys=True)}")
def main() -> int:
ap = argparse.ArgumentParser()
ap.add_argument("--bin", default=str(REPO / "src/go/stage-guards/stage-guards"))
args = ap.parse_args()
binpath = Path(args.bin)
if not binpath.exists():
subprocess.run(["go", "build", "-o", str(binpath), "."],
cwd=REPO / "src/go/stage-guards", check=True)
scratch = Path(tempfile.mkdtemp(prefix="sg_parity_"))
try:
parity_to_dict(binpath)
parity_run_check(binpath, scratch)
parity_stages(binpath, scratch)
parity_liveness(binpath)
parity_verify(binpath, scratch)
parity_henxels(binpath)
parity_reconcile(binpath)
finally:
shutil.rmtree(scratch, ignore_errors=True)
print(f"parity: {PASS}/{TOTAL} match")
if PASS != TOTAL:
return 1
return 0
if __name__ == "__main__":
raise SystemExit(main())
@@ -0,0 +1,161 @@
#!/usr/bin/env python3
"""check_standardized_providers_parity.py — live oracle-vs-Go parity sweep
for the standardized_providers gap closure (#2479, contract factory-gap-sp).
The frozen corpus (truth.json) pins the ported surface byte-identically.
THIS script drives the LIVE Python oracle (in-process, under the
scripts/sp_freeze_seams rig: pinned HOME + provider_registry sibling-import
path) and the Go binary across every op family — list, get (all providers +
None branches), connect (every gate branch and every provider),
connect_all_local, and the CLI (usage/list/connect variants/connect-all/
unknown, compared as EXACT stdout BYTES) — comparing sort_keys JSON; CLI
text is compared byte-for-byte. Exit 0 on 100% parity, 1 with divergences.
Usage (repo root; the seams dir is mandatory — pins HOME + binds seams):
PYTHONPATH=scripts/sp_freeze_seams:src python3 scripts/check_standardized_providers_parity.py \
[--bin src/go/standardized-providers/standardized-providers]
"""
import argparse
import json
import os
import subprocess
import sys
from pathlib import Path
REPO = Path(os.path.abspath(__file__)).resolve().parents[1]
sys.path.insert(0, str(REPO / "src"))
sys.path.insert(0, str(REPO / "scripts"))
import rune.standardized_providers as sp # noqa: E402 (rig auto-bound)
PROVIDERS = [
"ollama", "vllm", "lmstudio", "xiaomi", "openai",
"anthropic", "openrouter", "groq", "together", "fireworks",
]
CLOUD = ["xiaomi", "openai", "anthropic", "openrouter", "groq", "together", "fireworks"]
KEYS = {
"xiaomi": "mimo-key", "openai": "sk-live-parity", "anthropic": "sk-ant",
"openrouter": "or-key", "groq": "gsk-key", "together": "tog-key",
"fireworks": "fw-key",
}
BIN_DEFAULT = REPO / "src" / "go" / "standardized-providers" / "standardized-providers"
def run_go(req, binpath, env=None):
e = dict(os.environ)
if env:
e.update(env)
p = subprocess.run([str(binpath), "--op"], input=json.dumps(req),
capture_output=True, text=True, env=e)
if p.returncode != 0:
raise RuntimeError(f"go op {req.get('op')} exited {p.returncode}: {p.stdout} {p.stderr}")
return json.loads(p.stdout)
def oracle_connect(name, key=...):
"""Call the oracle connect_provider exactly like the Go op: key=None
means no kwarg; a string key rides api_key."""
kwargs = {} if key is ... else {"api_key": key}
return sp.connect_provider(name, **kwargs)
def oracle_cli(argv_tail):
"""Drive the REAL main() with patched argv + captured stdout (the same
machinery the frozen seams use)."""
argv = ["standardized_providers.py"] + argv_tail
import contextlib
import io
saved = sys.argv
sys.argv = argv
buf = io.StringIO()
try:
with contextlib.redirect_stdout(buf):
sp.main()
finally:
sys.argv = saved
return {"stdout": buf.getvalue()}
def main() -> int:
ap = argparse.ArgumentParser()
ap.add_argument("--bin", type=Path, default=BIN_DEFAULT)
args = ap.parse_args()
checks = 0
fails = 0
def check(label, oracle_value, go_value, exact_bytes=False):
nonlocal checks, fails
checks += 1
if exact_bytes:
ok = oracle_value == go_value
else:
ok = json.dumps(oracle_value, sort_keys=True) == json.dumps(go_value, sort_keys=True)
if not ok:
fails += 1
print(f"FAIL {label}:\n oracle: {oracle_value!r}\n go: {go_value!r}")
# ── list ──
check("list", sp.list_providers(), run_go({"op": "list"}, args.bin))
# ── get (all + None branches, dataclass projection) ──
for name in PROVIDERS + ["ghost-provider", ""]:
want = sp.get_provider_asdict(name)
got = run_go({"op": "get", "name": name}, args.bin)
check(f"get:{name!r}", want, got)
# ── connect (gates + every provider) ──
for name in ["ghost-provider", "unknown-server-1"]:
check(f"connect:{name}", oracle_connect(name),
run_go({"op": "connect", "name": name}, args.bin))
for name in CLOUD:
check(f"connect:{name}:nokey", oracle_connect(name),
run_go({"op": "connect", "name": name}, args.bin))
check("connect:openai:empty-key", oracle_connect("openai", ""),
run_go({"op": "connect", "name": "openai", "key": ""}, args.bin))
for name in ["ollama", "vllm", "lmstudio"]:
check(f"connect:{name}", oracle_connect(name),
run_go({"op": "connect", "name": name}, args.bin))
for name in CLOUD:
check(f"connect:{name}:key", oracle_connect(name, KEYS[name]),
run_go({"op": "connect", "name": name, "key": KEYS[name]}, args.bin))
# ── connect_all_local ──
check("connect_all", sp.connect_all_local(),
run_go({"op": "connect_all"}, args.bin))
# ── CLI (EXACT stdout bytes, both sides run the real main()) ──
cli_cases = [
([], "usage"),
(["list"], "list"),
(["connect"], "connect-noargs"),
(["connect", "openai", "sk-cli"], "connect-key-ok"),
(["connect", "ghost-provider"], "connect-unknown"),
(["connect", "ollama"], "connect-local"),
(["connect", "xiaomi"], "connect-nokey"),
(["connect-all"], "connect-all"),
(["frobnicate"], "unknown-command"),
]
for argv_tail, label in cli_cases:
want = oracle_cli(argv_tail)
got = run_go({"op": "cli", "args": argv_tail}, args.bin)
check(f"cli:{label}", want, got, exact_bytes=True)
# the binary ALSO exposes the CLI surface via argv — byte-compare
# that path too (the bare script default mode).
p = subprocess.run([str(args.bin)] + argv_tail, capture_output=True, text=True)
got_direct = {"stdout": p.stdout}
checks += 1
if want != got_direct:
fails += 1
print(f"FAIL cli-argv:{label}:\n oracle: {want!r}\n go: {got_direct!r}")
print(f"standardized-providers live parity: {checks - fails}/{checks} "
f"({args.bin.name})")
if fails:
return 1
return 0
if __name__ == "__main__":
sys.exit(main())
+488
View File
@@ -0,0 +1,488 @@
#!/usr/bin/env python3
"""Live parity: structural_model Rust kernels vs Python oracle (dichotomy
wave, issue #2479 tranche). Layers:
1. FROZEN — the frozen truth corpus (frozen_sm_truth.json, generated by
scripts/gen_structural_model_truth.py against the LIVE oracle with
RUNE_STM_CORE=python + RUNE_STRUCTURAL_CORE=python pinned) replayed
through the ctypes FFI, case by case, deep-copied inputs; save() /
_init_project() compared BYTE-EXACT on real files.
2. FUZZ — 300 seeded random models (seed 2479): oracle floor vs FFI
on every kernel, exact compare; save() byte-exact.
3. LIVE — dual-mode facade battery: the same facade calls executed
with RUNE_STM_CORE=python (oracle floor) and with the Rust core
live; results must be identical (clock pinned).
Exit 0 only at 100% parity.
"""
import copy
import json
import os
import random
import string
import subprocess
import sys
import tempfile
from pathlib import Path
os.environ["RUNE_STM_CORE"] = "python" # oracle floor for compare
os.environ["RUNE_STRUCTURAL_CORE"] = "python" # the floor's store core
REPO = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(REPO / "src"))
from rune import structural_store as ss # noqa: E402
from rune import structural_model as sm # noqa: E402
from rune import stm_loader # noqa: E402
FIXED_NOW = "2026-10-13T01:02:03Z"
ss.now = lambda: FIXED_NOW # both sides stamp with the pinned clock
TRUTH = json.loads((REPO / "src" / "rust" / "structural_model" / "src" / "frozen_sm_truth.json").read_text())
fails: list[str] = []
counts = {"frozen": 0, "fuzz": 0, "live": 0}
def j(x):
return json.dumps(x, sort_keys=True, ensure_ascii=True)
def fail(layer, name, detail):
fails.append(f"[{layer}] {name}: {detail}")
print(f"FAIL[{layer}] {name}: {detail[:240]}")
def check(layer, name, want, got):
counts[layer] += 1
if j(want) != j(got):
fail(layer, name, f"want={j(want)[:280]} got={j(got)[:280]}")
def receiver(doc, project_id="proj", path="/tmp/sm-parity/structural.json"):
m = sm.StructuralModel.__new__(sm.StructuralModel)
m.store_dir = None
m.project_id = project_id
m.path = path
m.doc = doc
return m
def oracle_call(fn, a):
"""The oracle floor (delegation pinned off) for one frozen case."""
if fn in {
"children",
"beneath",
"owning_domain",
"dependencies",
"consumers",
"interfaces_for",
"state_owned",
"verification_surfaces",
"deployment_surfaces",
"canonical_state_owner",
"supersession",
"impact_closure",
}:
m = receiver(copy.deepcopy(a["doc"]))
if fn == "impact_closure":
return m.impact_closure(a["eid"], max_depth=a.get("max_depth", 8))
return getattr(m, fn)(a["eid"])
if fn == "add":
m = receiver(copy.deepcopy(a["doc"]))
return {
"doc": m.doc,
"eid": m.add(
a["kind"],
a["name"],
parent=a.get("parent"),
ext=a.get("ext"),
evidence_ref=a.get("evidence_ref", "structural-model"),
),
}
if fn == "relate":
m = receiver(copy.deepcopy(a["doc"]))
return {
"doc": m.doc,
"rel": m.relate(
a["from_id"],
a["rel"],
a["to_id"],
evidence_ref=a.get("evidence_ref", "structural-model"),
authority=a.get("authority", "model-author"),
status=a.get("status", "active"),
ext=a.get("ext"),
),
}
if fn == "workspace_record":
return sm.workspace_record(
contract_id=a["contract_id"],
construction_base=a["construction_base"],
runtime_generation=a.get("runtime_generation", ""),
candidate_generation=a.get("candidate_generation", ""),
promotion_target=a.get("promotion_target", "gitea/master"),
rollback_generation=a.get("rollback_generation", ""),
)
if fn == "workspace_advance":
record = copy.deepcopy(a["record"])
return sm.workspace_advance(record, a["stage"], evidence=a.get("evidence", ""))
raise AssertionError(fn)
def ffi_call(fn, a):
if fn in {
"children",
"beneath",
"owning_domain",
"dependencies",
"consumers",
"interfaces_for",
"state_owned",
"verification_surfaces",
"deployment_surfaces",
"canonical_state_owner",
"supersession",
"impact_closure",
}:
return stm_loader.query(copy.deepcopy(a["doc"]), a["eid"], fn, max_depth=a.get("max_depth"))
if fn == "add":
return stm_loader.add(
copy.deepcopy(a["doc"]),
a["kind"],
a["name"],
parent=a.get("parent"),
ext=a.get("ext"),
evidence_ref=a.get("evidence_ref", "structural-model"),
now=FIXED_NOW,
)
if fn == "relate":
return stm_loader.relate(
copy.deepcopy(a["doc"]),
a["from_id"],
a["rel"],
a["to_id"],
evidence_ref=a.get("evidence_ref", "structural-model"),
authority=a.get("authority", "model-author"),
status=a.get("status", "active"),
ext=a.get("ext"),
now=FIXED_NOW,
)
if fn == "workspace_record":
return stm_loader.workspace_record(
contract_id=a["contract_id"],
construction_base=a["construction_base"],
runtime_generation=a.get("runtime_generation", ""),
candidate_generation=a.get("candidate_generation", ""),
promotion_target=a.get("promotion_target", "gitea/master"),
rollback_generation=a.get("rollback_generation", ""),
)
if fn == "workspace_advance":
return stm_loader.workspace_advance(copy.deepcopy(a["record"]), a["stage"], evidence=a.get("evidence", ""))
raise AssertionError(fn)
def call_side(call):
"""Run a case body; errors become comparable markers."""
try:
return {"__ok__": call()}
except (ValueError, KeyError) as exc:
return {"__err__": f"{type(exc).__name__}: {exc}"}
def frozen():
for fn, cases in TRUTH["groups"].items():
if fn in {"save", "reload", "init_project"}:
continue # byte-law layer below
for c in cases:
a = copy.deepcopy(c["args"])
want = call_side(lambda: oracle_call(fn, a))
got = call_side(lambda: ffi_call(fn, a))
check("frozen", f"{fn}/{c['name']}", want, got)
def byte_law(tmp):
"""save / _init_project / reload must be byte-exact through the FFI."""
for c in TRUTH["groups"]["save"]:
name = c["name"]
m = receiver(copy.deepcopy(c["args"]["doc"]), path=tmp / f"py/{name}.json")
m.save()
want = {"content": Path(m.path).read_text(), "doc": m.doc}
out = stm_loader.save(copy.deepcopy(c["args"]["doc"]), str(tmp / f"rs/{name}.json"))
got = {"content": Path(out["path"]).read_text(), "doc": out["doc"]}
check("frozen", f"save-bytes/{name}", want, got)
c = TRUTH["groups"]["init_project"][0]
m = sm.StructuralModel(tmp / "py-init", c["args"]["project_id"])
want = {"content": Path(m.path).read_text(), "doc": m.doc}
out = stm_loader.init_project(
copy.deepcopy(c["args"]["doc"]), c["args"]["project_id"], str(tmp / "rs-init/structural.json"), FIXED_NOW
)
got = {"content": Path(out["path"]).read_text(), "doc": out["doc"]}
check("frozen", "init_project-bytes", want, got)
# reload: FFI doc equals the floor's reloaded doc, byte-exact source
m2 = sm.StructuralModel(tmp / "py-init", c["args"]["project_id"])
m2.reload()
got_doc = stm_loader.reload(str(tmp / "py-init/structural.json"))
check("frozen", "reload-roundtrip", m2.doc, got_doc)
check("frozen", "reload-missing-none", None, stm_loader.reload(str(tmp / "nope.json")))
# ── fuzz (seeded) ───────────────────────────────────────────────────────────
KINDS = list(sm.ENTITY_KINDS) + ["widget"]
RELS = list(sm.RELATION_TYPES) + ["hates"]
IDS = [
"project:p",
"domain:d",
"component:a",
"component:b",
"interface:i",
"state_store:s",
"test_suite:t",
"deployment_surface:ds",
"environment:e",
"component:old",
"é-unit",
"x" * 40,
"",
]
STATUSES = [None, None, "active", "stale", "STALE", "CURRENT", "root"]
def rand_rel(rnd):
r = {
"type": rnd.choice(RELS),
"from": rnd.choice(IDS),
"to": rnd.choice(IDS),
"evidence_refs": sorted({f"ev-{rnd.randint(0, 2)}" for _ in range(rnd.randint(0, 2))}),
"observed_at": FIXED_NOW,
}
st = rnd.choice(STATUSES)
if st:
r["status"] = st
if rnd.random() < 0.2:
r["authority"] = rnd.choice(["model-author", "importer", "user"])
if rnd.random() < 0.15:
r["ext"] = {"n": rnd.randint(0, 5)}
return r
def rand_doc(rnd):
d = {"schema_version": 1, "generated_at": FIXED_NOW, "entities": [], "relationships": [], "observations": []}
for _ in range(rnd.randint(0, 6)):
e = {
"id": rnd.choice(IDS) or f"component:f{rnd.randint(0, 8)}",
"kind": rnd.choice(sm.ENTITY_KINDS),
"maturity": rnd.choice(["DECLARED", "PRESENT", "WIRED", "VERIFIED"]),
"tags": [],
"identities": {},
"evidence_refs": sorted({f"ev-{rnd.randint(0, 2)}" for _ in range(rnd.randint(0, 2))}),
"observed_at": FIXED_NOW,
}
if rnd.random() < 0.25:
e["aliases"] = [f"component:old{rnd.randint(0, 3)}"]
if rnd.random() < 0.2:
e.pop("identities") # the KeyError crash-parity class
d["entities"].append(e)
for _ in range(rnd.randint(0, 8)):
d["relationships"].append(rand_rel(rnd))
return d
def fuzz(tmp):
rnd = random.Random(2479)
for i in range(300):
d = rand_doc(rnd)
eid = rnd.choice(IDS) or "component:a"
for fn in [
"children",
"beneath",
"owning_domain",
"dependencies",
"consumers",
"interfaces_for",
"state_owned",
"verification_surfaces",
"deployment_surfaces",
"canonical_state_owner",
"supersession",
]:
want = call_side(lambda: oracle_call(fn, {"doc": d, "eid": eid}))
got = call_side(lambda: ffi_call(fn, {"doc": d, "eid": eid}))
check("fuzz", f"{fn}/{i}", want, got)
depth = rnd.choice([1, 2, 8])
want = call_side(lambda: oracle_call("impact_closure", {"doc": d, "eid": eid, "max_depth": depth}))
got = call_side(lambda: ffi_call("impact_closure", {"doc": d, "eid": eid, "max_depth": depth}))
check("fuzz", f"impact_closure/{i}", want, got)
# mutations
kind, name = rnd.choice(KINDS), f"n{i}"
a = {
"doc": d,
"kind": kind,
"name": name,
"parent": rnd.choice([None, "domain:d"]),
"ext": rnd.choice([None, {"k": i}, {}]),
"evidence_ref": rnd.choice(["structural-model", "", f"ev-{i}"]),
}
want = call_side(lambda: oracle_call("add", a))
got = call_side(lambda: ffi_call("add", a))
check("fuzz", f"add/{i}", want, got)
ra = {
"doc": d,
"from_id": rnd.choice(IDS),
"rel": rnd.choice(RELS),
"to_id": rnd.choice(IDS),
"evidence_ref": rnd.choice(["structural-model", "ev"]),
"authority": rnd.choice(["model-author", "importer"]),
"status": rnd.choice(["active", "CURRENT"]),
"ext": rnd.choice([None, {"z": 1}, {}]),
}
want = call_side(lambda: oracle_call("relate", ra))
got = call_side(lambda: ffi_call("relate", ra))
check("fuzz", f"relate/{i}", want, got)
# lifecycle
stages = rnd.choice([[], ["base_verified"], ["base_verified", "worktree_created"]])
record = sm.workspace_record(contract_id=f"C{i}", construction_base=f"sha{i}")
for s in stages:
record = sm.workspace_advance(record, s)
stage = rnd.choice(sm.WORKSPACE_LIFECYCLE_STAGES + ("bogus",))
wa = {"record": record, "stage": stage, "evidence": rnd.choice(["", "e" * rnd.randint(1, 250)])}
want = call_side(lambda: oracle_call("workspace_advance", wa))
got = call_side(lambda: ffi_call("workspace_advance", wa))
check("fuzz", f"workspace_advance/{i}", want, got)
# save byte law on random docs
if i % 6 == 0:
m = receiver(copy.deepcopy(d), path=tmp / f"fz-py/{i}.json")
try:
m.save()
want_c = Path(m.path).read_text()
except ValueError as exc:
want_c = f"__err__ {exc}"
out = call_side(lambda: stm_loader.save(copy.deepcopy(d), str(tmp / f"fz-rs/{i}.json")))
if isinstance(out.get("__ok__"), dict):
got_c = Path(out["__ok__"]["path"]).read_text()
else:
got_c = f"__err__ {out.get('__err__', '')}"
counts["fuzz"] += 1
if want_c != got_c:
fail("fuzz", f"save-bytes/{i}", f"py={want_c[:120]!r} rs={got_c[:120]!r}")
# ── live dual-mode facade battery ───────────────────────────────────────────
FACADE_CODE = r"""
import copy, json, os, sys, tempfile, calendar, time as _time, types
sys.path.insert(0, "src")
from rune import structural_store as ss
FIXED = "2026-10-13T01:02:03Z"
ss.now = lambda: FIXED
from rune import structural_model as sm
out = {}
with tempfile.TemporaryDirectory() as td:
m = sm.StructuralModel(td + "/store", "scaffolding")
m.add("domain", "construction", parent="project:scaffolding")
m.add("subsystem", "kernel", parent="domain:construction")
m.add("component", "scaffold", parent="subsystem:kernel")
m.add("component", "beta", parent="subsystem:kernel")
m.add("interface", "api", parent="subsystem:kernel")
m.add("state_store", "st", parent="project:scaffolding",
ext={"engine": "sqlite"})
m.add("test_suite", "kt", parent="project:scaffolding")
m.add("deployment_surface", "live", parent="project:scaffolding")
try:
m.add("widget", "x")
out["bad_kind"] = "NO RAISE"
except ValueError as e:
out["bad_kind"] = str(e)
try:
m.relate("component:scaffold", "hates", "component:beta")
out["bad_rel"] = "NO RAISE"
except ValueError as e:
out["bad_rel"] = str(e)
m.relate("component:scaffold", "provides", "interface:api")
m.relate("component:beta", "consumes", "interface:api")
m.relate("component:beta", "depends_on", "component:scaffold")
m.relate("component:scaffold", "owns", "state_store:st")
m.relate("component:scaffold", "verified_by", "test_suite:kt")
m.relate("component:scaffold", "deployed_by", "deployment_surface:live")
m.relate("component:scaffold", "supersedes", "component:beta")
m.relate("component:beta", "legacy_of", "component:scaffold")
m.relate("component:scaffold", "reads", "state_store:st",
authority="importer", status="CURRENT", ext={"mode": "ro"})
m.save()
out["doc"] = m.doc
out["file_sha"] = __import__("hashlib").sha256(
open(td + "/store/structural.json", "rb").read()).hexdigest()
m2 = sm.StructuralModel(td + "/store", "scaffolding")
m2.reload()
out["reload_same"] = m2.doc == m.doc
eid = "component:scaffold"
for q in ["children", "beneath", "owning_domain", "dependencies",
"consumers", "interfaces_for", "state_owned",
"verification_surfaces", "deployment_surfaces",
"canonical_state_owner", "supersession"]:
out[q] = getattr(m, q)(eid)
out["closure"] = m.impact_closure(eid)
out["closure_root"] = m.impact_closure("project:scaffolding")
out["closure_unknown"] = m.impact_closure("nope")
rec = sm.workspace_record(contract_id="WC", construction_base="sha-base")
out["record"] = rec
# snapshot at capture: the ORACLE mutates the record in place and
# returns the same dict — a later call through the same reference
# would alias into the captured result (Python-only artifact, not a
# kernel divergence; the kernel returns fresh dicts)
out["advance"] = copy.deepcopy(
sm.workspace_advance(rec, "base_verified", evidence="seed"))
out["advance2"] = copy.deepcopy(
sm.workspace_advance(rec, "worktree_created"))
try:
sm.workspace_advance(out["advance2"], "pushed")
out["advance_err"] = "NO RAISE"
except ValueError as e:
out["advance_err"] = str(e)
print(json.dumps(out, sort_keys=True))
"""
def facade_battery():
def run(tag):
env = dict(os.environ)
env.pop("RUNE_STM_CORE", None)
env.pop("RUNE_STRUCTURAL_CORE", None)
if tag == "python":
env["RUNE_STM_CORE"] = "python"
env["RUNE_STRUCTURAL_CORE"] = "python"
r = subprocess.run(
[sys.executable, "-c", FACADE_CODE], capture_output=True, text=True, cwd=str(REPO), env=env, timeout=180
)
if r.returncode != 0:
fail("live", tag, r.stderr[-400:])
return None
return json.loads(r.stdout)
py = run("python")
rs = run("rust")
if py is None or rs is None:
return
check("live", "dual-mode-facade", py, rs)
def main():
if not stm_loader.available():
print("Rust core not built — run cargo build --release in src/rust/structural_model")
return 2
with tempfile.TemporaryDirectory() as td:
frozen()
byte_law(Path(td))
fuzz(Path(td))
facade_battery()
total = sum(counts.values())
print(
f"\nPARITY: {total} checks, {len(fails)} failures "
f"(frozen={counts['frozen']} fuzz={counts['fuzz']} live={counts['live']})"
)
return 1 if fails else 0
if __name__ == "__main__":
sys.exit(main())
+250
View File
@@ -0,0 +1,250 @@
#!/usr/bin/env python3
"""check_tiered_executor_parity.py — live oracle-vs-Go parity sweep for
the tiered_executor gap closure (dichotomy wave #2479, contract
factory-gap-cs).
Run under the scripts/te_freeze_seams rig (PYTHONPATH), which pins
time.time (both sides then ride the TE_LATENCY_MS=0 wall-clock seam) and
starts the OLLAMA echo server the frozen envelope was captured with.
THIS script drives the LIVE Python oracle and the Go binary (`op` stdin
dispatch) across every op family — job/result serializers via the real
constructors, deterministic family paths incl. rune-slicing truncation,
no-profile early returns through subset registries, model paths through
the echo server (payload bytes ride back as the response), crash-parity
error envelopes, _ctx_budget rows, the TestExecutor self-test — plus the
CLI surface (test / execute / usage / unknown), comparing sort_keys JSON
or exact lines. Exit 0 on 100% parity.
Usage: PYTHONPATH=scripts/te_freeze_seams REPO_ROOT=$PWD python3 \\
scripts/check_tiered_executor_parity.py [--bin src/go/tiered-executor/tiered-executor]
"""
import argparse
import contextlib
import io
import json
import os
import re
import subprocess
import sys
from pathlib import Path
LAT_RE = re.compile(r'"latency_ms": [0-9.eE+-]+')
def norm_latency(text):
"""Wall-clock law: the CLI execute output embeds a measured latency
(oracle: live time.time; Go: measured unless the seam pin rides env)
— replaced structurally on BOTH sides before the byte compare."""
return LAT_RE.sub('"latency_ms": <wall-clock>', text)
REPO = Path(__file__).resolve().parent.parent
sys.path.insert(0, str(REPO / "src"))
import rune.tiered_executor as te # rig-bound: _te_* seams + frozen time # noqa: E402
from rune.model_registry import ModelProfile # noqa: E402
T3_PROFILE = {
"id": "qwen3.6:27b", "provider": "ollama", "tier": "T3", "local": True,
"context_window": 32768, "supports_tools": False,
"supports_structured_output": False, "supports_reasoning_field": False,
"estimated_latency": "high", "estimated_cost": "0", "enabled": True,
}
EMPTY_REG = {"T9": {**T3_PROFILE, "id": "none", "tier": "T9"}}
BUDGET_T0 = {"start_tier": "T0", "max_tier": "T0"}
BUDGET_T2 = {"start_tier": "T2", "max_tier": "T4"}
def echo_url():
return os.environ["OLLAMA_URL"]
# ── oracle side (rig seams already give registry specs / per-case urls) ──────
def py_op(op, req):
if op == "to_dict_job":
return te._te_job_to_dict(req["job"])
if op == "to_dict_result":
return te._te_result_to_dict(req["result"])
if op == "execute":
return te._te_execute(req.get("registry"), req["job"], req["budget"])
if op == "execute_ollama":
return te._te_execute_ollama(req.get("url"), req.get("registry"),
req["job"], req["budget"])
if op == "ctx_budget":
return te._ctx_budget(req["model"])
if op == "test_executor":
# te.test_executor prints its report inline — capture it (the CLI
# parity block below verifies those printed lines byte-exactly)
sink = io.StringIO()
with contextlib.redirect_stdout(sink):
return te._te_test_executor()
raise ValueError(f"unknown op {op}")
# ── Go side (one fresh process per op) ───────────────────────────────────────
def go_op(binpath, op, req):
full = dict(req)
full["op"] = op
env = dict(os.environ)
env["TE_LATENCY_MS"] = "0"
p = subprocess.run([str(binpath), "op"], input=json.dumps(full),
capture_output=True, text=True, env=env, cwd=str(REPO))
if p.returncode != 0:
raise RuntimeError(f"go op {op} exited {p.returncode}: {p.stdout} {p.stderr}")
return json.loads(p.stdout)
def jdump(v):
return json.dumps(_norm(v), sort_keys=True, ensure_ascii=True)
def _norm(v):
"""Canonical walk: integral floats collapse to int for the COMPARISON
only (dichotomy quirk — Python renders 0.0, Go 0; parsed-equal same
number). Non-integral floats (latency 12.5) stay untouched."""
if isinstance(v, bool):
return v
if isinstance(v, float) and v.is_integer():
return int(v)
if isinstance(v, list):
return [_norm(x) for x in v]
if isinstance(v, dict):
return {k: _norm(x) for k, x in v.items()}
return v
OPS = [
("to_dict_job", {"job": {"job_id": "p1", "task_family": "greeting", "objective": "Respond to hello"}}),
("to_dict_job", {"job": {"job_id": "p2", "task_family": "coding", "objective": "日本語 café",
"inputs": {"path": "src/x.py"}, "risk": "high",
"reversibility": "irreversible", "verification_method": "pytest",
"preferred_tiers": ["T0", "T1"], "max_tier": "T3",
"required_output_schema": "diff"}}),
("to_dict_result", {"result": {"job_id": "p3", "tier_used": "T0", "model_used": "deterministic", "success": True}}),
("to_dict_result", {"result": {"job_id": "p4", "tier_used": "T1", "model_used": "qwen2.5:3b",
"success": False, "output": None, "error": "kaput",
"verification_result": {"ok": 1}, "attempts": 2,
"latency_ms": 9.75, "tokens_used": 7}}),
("execute", {"job": {"job_id": "p5", "task_family": "greeting", "objective": "salut"}, "budget": BUDGET_T0}),
("execute", {"job": {"job_id": "p6", "task_family": "lookup", "objective": "find x"}, "budget": BUDGET_T0}),
("execute", {"job": {"job_id": "p7", "task_family": "other", "objective": "plain"}, "budget": BUDGET_T0}),
# [:100] char-slice rows (dichotomy quirk: rune-safe truncation)
("execute", {"job": {"job_id": "p8", "task_family": "greeting", "objective": "x" * 140}, "budget": BUDGET_T0}),
("execute", {"job": {"job_id": "p9", "task_family": "lookup", "objective": "日本語" * 60}, "budget": BUDGET_T0}),
("execute", {"job": {"job_id": "p10", "task_family": "coding", "objective": "héllo wörld", "preferred_tiers": ["T0"]},
"budget": BUDGET_T2}),
# no-profile early returns through a subset registry (empty dict is FALSY)
("execute", {"registry": EMPTY_REG, "job": {"job_id": "p11", "task_family": "coding", "objective": "x",
"preferred_tiers": ["T4"]}, "budget": {"start_tier": "T4", "max_tier": "T4"}}),
("execute", {"registry": EMPTY_REG, "job": {"job_id": "p12", "task_family": "coding", "objective": "x"},
"budget": {"start_tier": "T3", "max_tier": "T3"}}),
# model paths through the rig's echo server (payload rides back)
("execute_ollama", {"job": {"job_id": "p13", "task_family": "coding", "objective": "fix it"},
"budget": {"start_tier": "T1", "max_tier": "T2"}}),
("execute_ollama", {"job": {"job_id": "p14", "task_family": "coding",
"objective": ('héllo wörld ' * 80) + '日本語 "q" \\ \t\n' + ("🚀" * 30)},
"budget": {"start_tier": "T1", "max_tier": "T2"}}),
("execute_ollama", {"job": {"job_id": "p15", "task_family": "coding", "objective": "preferred",
"preferred_tiers": ["T2"]},
"budget": {"start_tier": "T0", "max_tier": "T4"}}),
("execute_ollama", {"registry": {"T1": {**T3_PROFILE, "id": "custom-1b", "tier": "T1"}},
"job": {"job_id": "p16", "task_family": "coding", "objective": "custom"},
"budget": {"start_tier": "T1", "max_tier": "T2"}}),
# crash-parity rows through the model path
("execute_ollama", {"url": "definitely-not-a-url",
"job": {"job_id": "p17", "task_family": "coding", "objective": "bad"},
"budget": {"start_tier": "T1", "max_tier": "T2"}}),
("execute_ollama", {"url": "http://127.0.0.1:9",
"job": {"job_id": "p18", "task_family": "coding", "objective": "refused"},
"budget": {"start_tier": "T1", "max_tier": "T2"}}),
("ctx_budget", {"model": "qwen2.5:3b"}),
("ctx_budget", {"model": "qwen3:14b"}),
("ctx_budget", {"model": "mimo-v2.5-pro"}),
("ctx_budget", {"model": ""}),
("ctx_budget", {"model": "deterministic"}),
("ctx_budget", {"model": "no-such-model"}),
("test_executor", {}),
]
def cli_lines(argv, env_extra=None):
env = dict(os.environ)
if env_extra:
env.update(env_extra)
env["TE_LATENCY_MS"] = "0"
p = subprocess.run(argv, capture_output=True, text=True, env=env, cwd=str(REPO))
return p.returncode, p.stdout, p.stderr
def cli_parity(binpath):
"""CLI surface: test / execute T0 / execute T1 (echo) / usage /
unknown arg / execute with a missing arg — the oracle's main()."""
checks = []
oracle = [sys.executable, str(REPO / "src/rune/tiered_executor.py")]
rc_p, out_p, _ = cli_lines(oracle + ["test"], {"OLLAMA_URL": echo_url()})
rc_g, out_g, _ = cli_lines([str(binpath), "test"], {"OLLAMA_URL": echo_url()})
checks.append(("cli test", rc_p == rc_g and out_p == out_g, out_p, out_g))
def run(argv, env_extra):
rc, out, _ = cli_lines(argv, env_extra)
return rc, norm_latency(out), _
job = json.dumps({"job_id": "c1", "task_family": "greeting", "objective": "hi"})
rc_p, out_p, _ = run(oracle + ["execute", job, json.dumps(BUDGET_T0)], {"OLLAMA_URL": echo_url()})
rc_g, out_g, _ = run([str(binpath), "execute", job, json.dumps(BUDGET_T0)], {"OLLAMA_URL": echo_url()})
checks.append(("cli execute T0 (latency normalized)", rc_p == rc_g and out_p == out_g, out_p, out_g))
job_t1 = json.dumps({"job_id": "c2", "task_family": "coding", "objective": "fix it"})
rc_p, out_p, _ = run(oracle + ["execute", job_t1, json.dumps({"start_tier": "T1", "max_tier": "T2"})],
{"OLLAMA_URL": echo_url()})
rc_g, out_g, _ = run([str(binpath), "execute", job_t1, json.dumps({"start_tier": "T1", "max_tier": "T2"})],
{"OLLAMA_URL": echo_url()})
checks.append(("cli execute T1 via echo (latency normalized)", rc_p == rc_g and out_p == out_g, out_p, out_g))
rc_p, out_p, _ = cli_lines(oracle + ["execute", job])
rc_g, out_g, _ = cli_lines([str(binpath), "execute", job])
checks.append(("cli execute missing budget -> usage", rc_p == rc_g and out_p == out_g, out_p, out_g))
rc_p, out_p, _ = cli_lines(oracle + ["bogus"])
rc_g, out_g, _ = cli_lines([str(binpath), "bogus"])
checks.append(("cli unknown", rc_p == rc_g and out_p == out_g, out_p, out_g))
rc_p, out_p, _ = cli_lines(oracle)
rc_g, out_g, _ = cli_lines([str(binpath)])
checks.append(("cli usage", rc_p == rc_g and out_p == out_g, out_p, out_g))
return checks
def main() -> int:
ap = argparse.ArgumentParser()
ap.add_argument("--bin", default=str(REPO / "src/go/tiered-executor/tiered-executor"))
args = ap.parse_args()
binpath = Path(args.bin)
failures = 0
total = 0
for op, req in OPS:
total += 1
py = py_op(op, req)
go = go_op(binpath, op, req)
if jdump(py) != jdump(go):
failures += 1
print(f"DIVERGE {op} {json.dumps(req)[:100]}")
print(f" python: {jdump(py)[:400]}")
print(f" go: {jdump(go)[:400]}")
for name, ok, want, got in cli_parity(binpath):
total += 1
if not ok:
failures += 1
print(f"DIVERGE {name}\n python: {want!r}\n go: {got!r}")
print(f"parity: {total - failures}/{total} match" + (" — FAILURES" if failures else ""))
return 1 if failures else 0
if __name__ == "__main__":
raise SystemExit(main())
+320
View File
@@ -0,0 +1,320 @@
#!/usr/bin/env python3
"""Live parity: token_optimizer Rust kernel vs Python oracle (dichotomy wave,
close-PARTIAL gap pass). Layers:
1. FROZEN — the gap truth corpus (src/rust/token_optimizer/frozen_truth.json,
generated by scripts/gen_token_optimizer_truth.py under the
scripts/to_freeze_seams rig against the LIVE oracle with both core
pins python): the get_optimizer construction rows replayed through the
ctypes FFI op (envelope state vs the frozen oracle observation,
last_save_time excluded — the facade stamps the monotonic clock after
_load); the pin contracts asserted in BOTH directions.
2. FUZZ — 40 seeded optimizer instances (seed 2479), each running a
random op script (static/dynamic/optimize/status/stats/save_if_dirty/
flush/mark_dirty) with a PATCHED module clock (frozen datetime +
counter monotonic): the full observation tape (per-op result + state +
storage file) must be IDENTICAL with RUNE_TOKEN_OPTIMIZER_CORE=python
(oracle floor) and with the Rust kernel live through the facade's
_run_kernel delegation.
3. LIVE — dual-mode E2E on the gap fns: the real module-level
get_optimizer()/optimize_prompt() API, the 8 storage-file construction
variants, and the _write_snapshot conversion, both pins.
Exit 0 only at 100% parity on the gap-closing functions.
"""
import json
import os
import random
import shutil
import sys
from datetime import datetime, timezone
from pathlib import Path
REPO = Path(__file__).resolve().parents[1]
os.environ["RUNE_TOKEN_OPTIMIZER_CORE"] = "python" # oracle floor to start
PARITY_HOME = "/tmp/to_parity"
sys.path.insert(0, str(REPO / "src"))
from rune import to_loader # noqa: E402
from rune import token_optimizer as to # noqa: E402
if not to_loader.available():
sys.exit("FATAL: Rust core not built — cargo build --release in src/rust/token_optimizer")
TRUTH = json.loads(
(REPO / "src" / "rust" / "token_optimizer" / "frozen_truth.json").read_text())
fails: list[str] = []
counts = {"frozen": 0, "fuzz": 0, "live": 0}
def fail(layer, name, detail):
fails.append(f"[{layer}] {name}: {detail}")
print(f"FAIL[{layer}] {name}: {detail}"[:400])
def j(x):
return json.dumps(x, sort_keys=True, ensure_ascii=True)
def check(layer, name, want, got):
counts[layer] += 1
if j(want) != j(got):
fail(layer, name, f"want={j(want)[:300]} got={j(got)[:300]}")
def pin(mode):
if mode == "python":
os.environ["RUNE_TOKEN_OPTIMIZER_CORE"] = "python"
else:
os.environ.pop("RUNE_TOKEN_OPTIMIZER_CORE", None)
# ── layer 1: FROZEN (construction rows through the FFI) ────────────────────
for row in TRUTH:
if row["fn"] != "to_get_optimizer_state":
continue
file_state, seed = row["args"]
exp = row["expected"]
env = to_loader.run_op(
"get_optimizer", {},
{"storage_text": None if file_state == "absent" else seed})
got_state = env["value"]
want_state = {
"cache": exp["cache"],
"stats": exp["stats"],
"dirty": exp["dirty"],
"changes_since_save": exp["changes_since_save"],
}
got_cmp = {k: got_state[k] for k in want_state}
check("frozen", f"ffi_get_optimizer:{file_state}", want_state, got_cmp)
# pin contracts, both directions (probes live in the facade seam).
pin("python")
check("frozen", "pin_contract:to_core_python_floor", None, to._to_core())
pin("rust")
check("frozen", "pin_contract:to_core_reachable", True, to._to_core() is not None)
pin("python")
# ── the patched clock (both pins see identical time) ───────────────────────
FROZEN_NOW = datetime(2026, 10, 14, 6, 0, 0, tzinfo=timezone.utc)
class _FrozenDatetime(datetime):
@classmethod
def now(cls, tz=None):
return FROZEN_NOW if tz is not None else FROZEN_NOW.replace(tzinfo=None)
class _Clock:
def __init__(self):
self.t = 1000.0
def monotonic(self):
return self.t
def advance(self, dt):
self.t += dt
def reset_scratch():
if os.path.isdir(PARITY_HOME):
shutil.rmtree(PARITY_HOME)
os.makedirs(PARITY_HOME, exist_ok=True)
STORAGE = os.path.join(PARITY_HOME, "token_optimizer.json")
PERSONA = "P" * 80 # deterministic long persona (bypasses persona_definition)
TEXTS = [
"fix the login bug",
"kubernetes pods restart on failure",
" spaced out text with runs ",
"multi\nline\ncontext\nwith\nnewlines",
"",
"unicode ✓ snowman ☃ and dashes — oh my",
]
CONTEXTS = ["", "recent work on the parser; recent work on the parser;",
"noise noise noise noise noise noise noise noise noise noise",
"one two three four five six seven eight nine ten"]
def drive(script, seed_file=None):
"""Run one op script through the facade; return the observation tape."""
reset_scratch()
if seed_file is not None:
with open(STORAGE, "w") as f:
f.write(seed_file)
clock = _Clock()
to.time = clock # the facade's `import time` binding — module-local
to.datetime = _FrozenDatetime
to._optimizer = None
opt = to.TokenOptimizer(storage_path=STORAGE)
opt._load_persona_definition = lambda: PERSONA
tape = []
def state_obs():
return {
"cache": [e.to_dict() for e in opt.cache.values()],
"stats": dict(opt.stats),
"dirty": opt._dirty,
"changes": opt._changes_since_save,
}
def file_obs():
if not os.path.exists(STORAGE):
return None
with open(STORAGE) as f:
return f.read()
for kind, arg in script:
clock.advance(0.5)
if kind == "dt":
clock.advance(arg) # jump the clock (debounce boundary probes)
elif kind == "get_static_cache":
tape.append({"r": opt.get_static_cache(), "s": state_obs()})
elif kind == "get_dynamic_cache":
tape.append({"r": opt.get_dynamic_cache(arg), "s": state_obs()})
elif kind == "optimize_prompt":
tape.append({"r": opt.optimize_prompt(arg[0], arg[1]), "s": state_obs()})
elif kind == "get_status":
tape.append({"r": opt.get_status(), "s": state_obs()})
elif kind == "get_cache_stats":
tape.append({"r": opt.get_cache_stats(), "s": state_obs()})
elif kind == "save_if_dirty":
opt._save_if_dirty()
tape.append({"r": None, "s": state_obs(), "f": file_obs()})
elif kind == "flush":
opt.flush()
tape.append({"r": None, "s": state_obs(), "f": file_obs()})
elif kind == "mark_dirty":
opt._mark_dirty()
tape.append({"r": None, "s": state_obs()})
final = {"tape": tape, "file": file_obs(), "status": opt.get_status()}
to.time, to.datetime = __import__("time"), datetime
return final
# ── layer 2: FUZZ (dual-mode full state machine) ──────────────────────────
rng = random.Random(2479)
SEEDS = [None,
'{"cache": {"static": {"key": "static", "content": "seed persona",'
' "tokens": 3, "last_used": "2026-10-14T00:00:00+00:00",'
' "use_count": 9, "hit_count": 4}}, "stats": {"total_calls": 2,'
' "total_tokens_saved": 10, "cache_hits": 1, "cache_misses": 1}}']
for trial in range(40):
script = []
for _ in range(rng.randrange(4, 9)):
roll = rng.random()
if roll < 0.10:
script.append(("dt", rng.choice([0.0, 10.0, 31.0, 65.0])))
elif roll < 0.30:
script.append(("get_static_cache", None))
elif roll < 0.50:
script.append(("get_dynamic_cache", rng.choice(CONTEXTS)))
elif roll < 0.70:
script.append(("optimize_prompt", (rng.choice(TEXTS), rng.choice(CONTEXTS))))
elif roll < 0.78:
script.append(("get_status", None))
elif roll < 0.86:
script.append(("get_cache_stats", None))
elif roll < 0.92:
script.append(("save_if_dirty", None))
elif roll < 0.97:
script.append(("flush", None))
else:
script.append(("mark_dirty", None))
seed_file = rng.choice(SEEDS)
pin("python")
want = drive(script, seed_file)
pin("rust")
got = drive(script, seed_file)
check("fuzz", f"trial{trial}", want, got)
if fails:
break
pin("python")
# ── layer 3: LIVE (dual-mode E2E on the gap fns) ───────────────────────────
def dual(label, call):
pin("python")
want = call()
pin("rust")
got = call()
check("live", label, want, got)
# module-level API through the REAL global singleton (get_optimizer path).
def module_api():
reset_scratch()
to._optimizer = None
clock = _Clock()
to.time, to.datetime = clock, _FrozenDatetime
os.environ["RUNE_MEMORY_DIR"] = PARITY_HOME
try:
r1 = to.optimize_prompt("hello world", "some context here")
opt = to.get_optimizer()
r2 = {"status": opt.get_status(), "stats": opt.get_cache_stats(),
"singleton": to.get_optimizer() is opt}
return {"r1": r1, "r2": r2}
finally:
to.time, to.datetime = __import__("time"), datetime
to._optimizer = None
dual("module_api:get_optimizer_singleton", module_api)
# the 8 construction variants through the REAL get_optimizer (both pins).
CONS = [r for r in TRUTH if r["fn"] == "to_get_optimizer_state"]
for row in CONS:
file_state, seed = row["args"]
def construct(file_state=file_state, seed=seed):
reset_scratch()
if file_state != "absent":
with open(STORAGE, "w") as f:
f.write(seed)
to._optimizer = None
os.environ["RUNE_MEMORY_DIR"] = PARITY_HOME
try:
opt = to.get_optimizer()
second = to.get_optimizer()
out = {
"cache": [e.to_dict() for e in opt.cache.values()],
"stats": dict(opt.stats),
"dirty": opt._dirty,
"changes": opt._changes_since_save,
"singleton_reused": second is opt,
}
return out
finally:
to._optimizer = None
dual(f"construct:{file_state}", construct)
# _write_snapshot conversion through the REAL facade method (both pins).
SNAP = [r for r in TRUTH if r["fn"] == "to_write_snapshot_doc"][0]["args"][0]
def snap_write():
reset_scratch()
path = os.path.join(PARITY_HOME, "snap.json")
opt = to.TokenOptimizer.__new__(to.TokenOptimizer)
opt.storage_path = path
to.TokenOptimizer._write_snapshot(opt, SNAP)
with open(path) as f:
return json.load(f)
dual("_write_snapshot:doc", snap_write)
print(f"parity: {sum(counts.values())} checks "
f"(frozen {counts['frozen']}, fuzz {counts['fuzz']}, live {counts['live']}) "
f"— {len(fails)} failures")
sys.exit(1 if fails else 0)
+273
View File
@@ -0,0 +1,273 @@
#!/usr/bin/env python3
"""Live parity: voice_hybrid Rust core vs Python oracle (dichotomy wave,
close-PARTIAL gap pass). Layers:
1. FROZEN — the gap truth corpus (src/rust/voice_hybrid/frozen_truth.json,
generated by scripts/gen_voice_hybrid_truth.py under the
scripts/vh_freeze_seams rig against the LIVE oracle with
RUNE_VOICE_HYBRID_CORE=python pinned): the kernel-shaped rows replayed
through the ctypes FFI, case by case; the PLUGIN row asserted against
vh_plugin.
2. FUZZ — 300 seeded random ops (seed 2479): the oracle's relevance math
vs the FFI kernel, exact compare; 200 seeded grow ops (oracle dict
update vs the FFI kernel's returned state+result), exact compare.
3. LIVE — dual-mode facade battery: the same facade calls (blend on four
messages, always, grow good/bad/neutral, handle_hook) executed with
RUNE_VOICE_HYBRID_CORE=python (oracle floor) and with the Rust core
live; results must be identical.
Exit 0 only at 100% parity on the gap-closing functions.
"""
import copy
import json
import os
import random
import sys
from pathlib import Path
REPO = Path(__file__).resolve().parents[1]
os.environ["RUNE_VOICE_HYBRID_CORE"] = "python" # oracle floor to start
PARITY_HOME = "/tmp/vh_parity"
sys.path.insert(0, str(REPO / "src"))
import rune.memory_env as _menv # noqa: E402
_menv.memory_dir = lambda: PARITY_HOME
os.environ["RUNE_MEMORY_DIR"] = PARITY_HOME
os.environ["RUNE_STORE_DB"] = os.path.join(PARITY_HOME, "store", "memory.db")
import rune.voice_hybrid as vh # noqa: E402
import rune.vh_loader as core # noqa: E402
# STORE_DB is resolved at oracle IMPORT time — re-point it at the parity
# scratch (same law as the behavior both-pins test re-pointing DB_PATH).
vh.STORE_DB = os.path.join(PARITY_HOME, "store", "memory.db")
if not core.available():
sys.exit("FATAL: Rust core not built — cargo build --release in src/rust/voice_hybrid")
TRUTH = json.loads(
(REPO / "src" / "rust" / "voice_hybrid" / "frozen_truth.json").read_text())
PLUGIN_WANT = json.loads(
(REPO / "src" / "rust" / "voice_hybrid" / "frozen_plugin.json").read_text())
fails: list[str] = []
counts = {"frozen": 0, "fuzz": 0, "live": 0}
def fail(layer, name, detail):
fails.append(f"[{layer}] {name}: {detail}")
print(f"FAIL[{layer}] {name}: {detail}"[:400])
def _norm(x):
# The FFI boundary renders every number as float (1 -> 1.0); the oracle
# keeps ints (hits, turns). Normalize integral floats to ints before
# comparing, so parity asserts VALUES, not renderer trivia.
if isinstance(x, float) and x.is_integer() and abs(x) < 9.0e15:
return int(x)
if isinstance(x, list):
return [_norm(v) for v in x]
if isinstance(x, dict):
return {k: _norm(v) for k, v in x.items()}
return x
def j(x):
return json.dumps(_norm(x), sort_keys=True, ensure_ascii=True)
def check(layer, name, want, got):
counts[layer] += 1
if j(want) != j(got):
fail(layer, name, f"want={j(want)[:300]} got={j(got)[:300]}")
def pin(mode):
"""Flip the facade pin at runtime (vh_loader.core reads env per call)."""
if mode == "python":
os.environ["RUNE_VOICE_HYBRID_CORE"] = "python"
else:
os.environ.pop("RUNE_VOICE_HYBRID_CORE", None)
SEED_TEXTS = [
("Alfred keeps his composure with dry wry understatement at tea time", "persona"),
("Bayonetta dances with sassy cheeky glamour, darling", "identity"),
("The cosmos invites wonder and skepticism about the universe", "delivery"),
("Elementary deduction: observe the clue and deduce the pattern", "operating"),
("Lestat performs with theatrical flamboyant charisma", "persona"),
("A quiet ledger note with no dimensional terms at all", "persona"),
("Debug the broken trace and fix the root cause error", "operating"),
]
def seed_store():
"""The rig's seed (scripts/vh_freeze_seams/sitecustomize.py), verbatim
rows, at the parity scratch — both pins see byte-identical stores."""
import shutil
import sqlite3
if os.path.isdir(PARITY_HOME):
shutil.rmtree(PARITY_HOME)
os.makedirs(os.path.join(PARITY_HOME, "store"), exist_ok=True)
os.makedirs(os.path.join(PARITY_HOME, "index"), exist_ok=True)
db = sqlite3.connect(os.environ["RUNE_STORE_DB"])
try:
db.execute(
"CREATE TABLE entries (id INTEGER PRIMARY KEY AUTOINCREMENT,"
" text TEXT, topic TEXT, status TEXT)"
)
db.executemany(
"INSERT INTO entries (text, topic, status) VALUES (?, ?, 'active')",
SEED_TEXTS,
)
db.commit()
finally:
db.close()
def fetch_rows():
db = vh._connect()
try:
return [dict(r) for r in db.execute(
"SELECT text, topic FROM entries WHERE topic IN "
"('persona','identity','delivery','operating') AND status='active'"
).fetchall()]
finally:
db.close()
# ── layer 1: FROZEN (kernel rows through the FFI) ──────────────────────────
by_fn = {}
for i, row in enumerate(TRUTH):
by_fn.setdefault(row["fn"], i)
seed_store() # the fetch/profile/blend/always rows need the seeded store
vh.STORE_DB = os.path.join(PARITY_HOME, "store", "memory.db")
for row in TRUTH:
fn, args, kwargs, want = row["fn"], row["args"], row.get("kwargs", {}), row["expected"]
if fn == "_relevance":
check("frozen", f"ffi_relevance:{args[0][:24]}", want, core.relevance(*args, **kwargs))
elif fn == "vh_fetch_rows":
check("frozen", "ffi_fetch_rows", want, fetch_rows())
check("frozen", "ffi_profiles:seeded_rows", TRUTH[by_fn["source_profiles"]]["expected"],
core.profiles([{"text": r["text"], "topic": r["topic"]} for r in fetch_rows()]))
elif fn == "source_profiles":
check("frozen", "ffi_profiles:source_profiles", want,
core.profiles([{"text": t, "topic": tp} for t, tp in SEED_TEXTS]))
elif fn == "blend":
check("frozen", f"ffi_blend:{args[0][:24]}", want, core.blend(
args[0], [{"text": t, "topic": tp} for t, tp in SEED_TEXTS],
{"source_weight": {}, "turns": 0, "events": []}))
elif fn == "always":
check("frozen", "ffi_always", want, core.always(
[{"text": t, "topic": tp} for t, tp in SEED_TEXTS]))
elif fn == "grow":
# The frozen grow rows capture the RESULT (the oracle saves state
# to disk as a side effect). Replay the update through the FFI on
# the same fresh input; assert result + the returned post-state
# against a fresh oracle run (load+save redirected at the parity
# scratch, seeded with the identical input state).
import rune.memory_env as _me2
real_mem2 = _me2.memory_dir
_me2.memory_dir = lambda: PARITY_HOME
try:
with open(os.path.join(PARITY_HOME, "index", "voice_state.json"), "w") as f:
json.dump({"source_weight": {}, "turns": 0, "events": []}, f)
exp_res = vh.grow(*args)
with open(os.path.join(PARITY_HOME, "index", "voice_state.json")) as f:
exp_state = json.load(f)
finally:
_me2.memory_dir = real_mem2
got = core.grow({"source_weight": {}, "turns": 0, "events": []}, *args)
check("frozen", f"ffi_grow:{args[0]}:{args[1]}", exp_res, got["result"])
check("frozen", f"ffi_grow_state:{args[0]}:{args[1]}", exp_state, got["state"])
elif fn == "handle_hook":
check("frozen", f"ffi_handle_hook:{args[0]}", want, core.handle_hook(*args))
check("frozen", "ffi_plugin", PLUGIN_WANT, core.plugin())
# ── layer 2: FUZZ (oracle math vs FFI kernel, seeded) ──────────────────────
rng = random.Random(2479)
VOCAB = [t for dim in vh._DIMENSIONS.values() for t in dim["terms"]]
for trial in range(300):
n = rng.randrange(0, 8)
terms = rng.sample(VOCAB, n) if n else []
msg = " ".join(rng.sample(VOCAB, rng.randrange(0, 12))).lower()
check("fuzz", f"relevance:{trial}", vh._relevance(msg, terms), core.relevance(msg, terms))
for trial in range(200):
state = {"source_weight": {}, "turns": rng.randrange(0, 50), "events": []}
for _ in range(rng.randrange(1, 4)):
src = rng.choice(list(vh._DIMENSIONS) + ["unknown_dim"])
out = rng.choice(["good", "bad", "neutral", "mystery"])
note = rng.choice(["", "x" * 100, "note with ünicode → chars"])
# expected = the oracle's PURE update math (no disk): drive the
# real grow with memory_dir redirected at the parity scratch.
# grow LOADS state from disk — seed the scratch file with `state`
# first so the load returns exactly our input.
import rune.memory_env as _me
real_mem = _me.memory_dir
_me.memory_dir = lambda: PARITY_HOME
try:
with open(os.path.join(PARITY_HOME, "index", "voice_state.json"), "w") as f:
json.dump(copy.deepcopy(state), f)
exp_res = vh.grow(src, out, note)
# grow saved the successor to the scratch file — reload it as
# the expected post-state (proves save+result agree).
with open(os.path.join(PARITY_HOME, "index", "voice_state.json")) as f:
exp_saved = json.load(f)
finally:
_me.memory_dir = real_mem
got = core.grow(copy.deepcopy(state), src, out, note)
check("fuzz", f"grow:{trial}:{src}:{out}", exp_res, got["result"])
check("fuzz", f"grow_state:{trial}:{src}:{out}", exp_saved, got["state"])
state = got["state"]
# ── layer 3: LIVE (dual-mode facade battery) ───────────────────────────────
seed_store()
CASES = [
("blend_empty", lambda: vh.blend("")),
("blend_composure", lambda: vh.blend("alfred kept his composure with dry wry understatement")),
("blend_deduction", lambda: vh.blend("debug the broken trace: observe the clue and deduce the root cause")),
("blend_wonder", lambda: vh.blend("the cosmos is full of wonder, stars and doubt")),
("always", lambda: vh.always()),
("grow_good", lambda: vh.grow("composure", "good")),
("grow_bad", lambda: vh.grow("confidence", "bad")),
("grow_neutral", lambda: vh.grow("wonder", "neutral")),
("hook", lambda: vh.handle_hook("voice_ready")),
("profiles", lambda: vh.source_profiles()),
("relevance", lambda: vh._relevance("alfred at tea", vh._DIMENSIONS["composure"]["terms"])),
]
results = {}
for mode in ("python", "rust"):
pin(mode)
seed_store() # identical store per mode; grow writes reset each mode
mode_out = {}
for name, fn in CASES:
if name.startswith("grow_"):
seed_growth = {"source_weight": {}, "turns": 0, "events": []}
import json as _json
gp = os.path.join(PARITY_HOME, "index", "voice_state.json")
with open(gp, "w") as f:
_json.dump(seed_growth, f)
try:
mode_out[name] = fn()
except Exception as e: # noqa: BLE001 — crash parity surfaces here
mode_out[name] = {"__crash__": f"{type(e).__name__}: {e}"}
results[mode] = mode_out
for name, _ in CASES:
check("live", f"dual:{name}", results["python"][name], results["rust"][name])
print(f"parity: frozen={counts['frozen']} fuzz={counts['fuzz']} live={counts['live']} "
f"failures={len(fails)}")
sys.exit(1 if fails else 0)
+224
View File
@@ -0,0 +1,224 @@
#!/usr/bin/env python3
"""check_witness_parity.py — live oracle-vs-Go parity sweep for the
witness gap closure (#2479, contract factory-gap-wi).
The frozen envelope (truth.json, 58 cases) pins the JSON-native surface
byte-identically. THIS script drives the LIVE Python oracle (kernel
delegation on — the Rust cognition_core is the authority) and the Go
binary (`op` mode) across the same branches plus the seams the harness
cannot freeze: the full log round-trip with BYTE-COMPARED log files
(frozen clock → identical jsonl bytes incl. ", "/": " separators,
insertion order, ensure_ascii), read_log deque semantics against
hand-seeded blank/malformed lines, log_stats shapes incl. list-shaped
signals and skip_rate half-even rounding, the missing-file branches, and
_now under the pinned clock.
Usage: PYTHONPATH=src python3 scripts/check_witness_parity.py
[--bin src/go/witness/witness]
Exit 0 on 100% parity, 1 with the first divergence.
"""
import argparse
import json
import os
import shutil
import subprocess
import sys
from pathlib import Path
REPO = Path(__file__).resolve().parent.parent
sys.path.insert(0, str(REPO / "src"))
sys.path.insert(0, str(REPO / "scripts"))
FROZEN_NOW = "2026-10-14T09:15:00.123456+00:00"
SCRATCH_P = Path("/tmp/witness_parity_py/memory")
SCRATCH_G = Path("/tmp/witness_parity_go/memory")
os.environ["RUNE_MEMORY_DIR"] = str(SCRATCH_P)
os.environ["RUNE_FROZEN_NOW"] = FROZEN_NOW
from freeze_truth import _pin_clock # noqa: E402
import rune.witness as wt # noqa: E402
_pin_clock(wt) # module-global datetime pinned → _now() frozen both sides
IS_CORRECTION = [
"no, that's wrong, fix it",
"Actually, you misunderstood the requirement",
"that answer is wrong",
"incorrect output",
"not right either",
"please try again",
"nope",
"stop doing that",
"we already did the migration",
"that's not what I asked for", # hits via the lowercase that'?s? not (correct|right|what)
"I meant the left column", # capital-I quirk → False
"I already told you", # capital-I quirk → False
"wrongly spelled", # \b boundary → False
"looks good to me",
"",
"don't do that",
"I told you the column",
]
EXTRACT_TOPIC = [
"the deployment runner needs repair now",
"fix this now",
"",
"café résumé matters",
"the fix_it_loop crashed again",
"alpha beta gamma delta epsilon zeta eta theta",
"WHY DOES THIS matter",
"why does the memory keep drifting",
]
DETECT_SIGNALS = [
("", None, None, None),
("hello", "boom", None, None),
("hello", "é" * 250, None, None),
("hello", None, "done", None),
("hello", None, "completed", None),
("hello", None, "abandoned", None),
("hello", None, "failed", None),
("hello", None, "running", None),
("no, that's wrong, try again", None, None, None),
("i need to check that", None, None, None),
("we already did the migration", None, None, None),
("I'll send the report", None, None, None),
("anyway moving on to budgets", None, None, ["budget"]),
("the deployment runner needs repair", None, None, ["deployment", "runner"]),
("urgent! I prefer rust, but actually wait", None, None, None),
("why does the memory keep drifting", None, None, None),
]
LOG_ENTRIES = [
({"correction": True, "corrected_topic": ["budgets"]}, "user corrected the budget", "sess-1"),
({"urgency_detected": True}, "", "sess-2"),
({"correction": True}, "r2", ""),
({"learning_opportunity": True}, "noted — café", "s4"),
({"completion": "done"}, "", "s5"),
({"error": True}, "logged", "s6"),
({"error": True}, "", "s7"),
({"commitment_detected": True}, "planned", "s8"),
]
def run_go(binpath, env, req):
p = subprocess.run([str(binpath), "op"], input=json.dumps(req),
capture_output=True, text=True, env=env)
if p.returncode != 0:
raise RuntimeError(f"go op {req.get('op')} exited {p.returncode}: {p.stdout} {p.stderr}")
out = json.loads(p.stdout)
return out.get("result")
def main():
ap = argparse.ArgumentParser()
ap.add_argument("--bin", default=str(REPO / "src/go/witness/witness"))
args = ap.parse_args()
binpath = Path(args.bin)
if not binpath.exists():
print(f"Go binary missing: {binpath} (go build -o witness . in src/go/witness)")
return 1
for scratch in (SCRATCH_P, SCRATCH_G):
base = scratch.parent
if base.exists():
shutil.rmtree(base)
scratch.mkdir(parents=True)
go_env = dict(os.environ)
go_env["RUNE_MEMORY_DIR"] = str(SCRATCH_G)
go_env["WITNESS_FROZEN_NOW"] = FROZEN_NOW
fails = total = 0
def check(name, oracle_val, go_val):
nonlocal fails, total
total += 1
# log_stats may carry INT signal_types keys (list-shaped signals —
# Python dicts accept them; json.dumps coerces to "1"/"2" on dump
# but sort_keys chokes first). Normalize the way dumps coerces.
if isinstance(oracle_val, dict) and "signal_types" in oracle_val:
oracle_val = dict(oracle_val)
oracle_val["signal_types"] = {
str(k): v for k, v in oracle_val["signal_types"].items()}
if json.dumps(oracle_val, sort_keys=True) != json.dumps(go_val, sort_keys=True):
fails += 1
print(f"DIVERGE {name}:\n oracle: {json.dumps(oracle_val)[:300]}\n"
f" go: {json.dumps(go_val)[:300]}")
# _now under the pinned clock
check("now", wt._now(), run_go(binpath, go_env, {"op": "now"}))
# is_correction — live public fn (capital-letter quirk included)
for text in IS_CORRECTION:
check(f"is_correction:{text[:30]!r}", wt.is_correction(text),
run_go(binpath, go_env, {"op": "is_correction", "text": text}))
# extract_topic — live kernel delegation
for text in EXTRACT_TOPIC:
check(f"extract_topic:{text[:30]!r}", wt.extract_topic(text),
run_go(binpath, go_env, {"op": "extract_topic", "text": text}))
# detect_signals — live kernel delegation, full dicts
for msg, te, ts, rt in DETECT_SIGNALS:
check(f"detect_signals:{msg[:30]!r}",
wt.detect_signals(msg, tool_error=te, task_status=ts, recent_topics=rt),
run_go(binpath, go_env, {"op": "detect_signals", "message": msg,
"tool_error": te, "task_status": ts,
"recent_topics": rt}))
# gather seams
check("stopwords", wt._stopwords(), run_go(binpath, go_env, {"op": "stopwords"}))
check("tables", wt._tables(), run_go(binpath, go_env, {"op": "tables"}))
# log family — read/stats on missing files
check("read_log:missing", wt.read_log(20),
run_go(binpath, go_env, {"op": "read_log", "limit": 20}))
check("log_stats:missing", wt.log_stats(), run_go(binpath, go_env, {"op": "log_stats"}))
# log_entry sequence — then BYTE-COMPARE the two jsonl files
for signals, reflection, session in LOG_ENTRIES:
wt.log_entry(signals, reflection, session)
run_go(binpath, go_env, {"op": "log_entry", "signals": signals,
"reflection": reflection, "session_id": session})
py_log = Path(wt.LOG_PATH).read_bytes()
go_log = (SCRATCH_G / "index" / "witness_log.jsonl").read_bytes()
total += 1
if py_log != go_log:
fails += 1
print(f"DIVERGE log-file-bytes:\n oracle: {py_log[:200]!r}\n go: {go_log[:200]!r}")
# read_log limits (deque semantics) + log_stats (skip_rate half-even)
for limit in (0, 1, 2, 3, 20, 99):
check(f"read_log:{limit}", wt.read_log(limit),
run_go(binpath, go_env, {"op": "read_log", "limit": limit}))
check("log_stats:full", wt.log_stats(), run_go(binpath, go_env, {"op": "log_stats"}))
# hand-seeded blank + malformed lines land on BOTH files identically
seed = b'{bad json\n\n{"signals": [1, 2, 2], "reflection": "x"}\n'
with open(wt.LOG_PATH, "ab") as f:
f.write(seed)
with open(SCRATCH_G / "index" / "witness_log.jsonl", "ab") as f:
f.write(seed)
for limit in (3, 20):
check(f"read_log:seeded:{limit}", wt.read_log(limit),
run_go(binpath, go_env, {"op": "read_log", "limit": limit}))
check("log_stats:seeded", wt.log_stats(), run_go(binpath, go_env, {"op": "log_stats"}))
# missing-file branches again after wipe
os.remove(wt.LOG_PATH)
os.remove(SCRATCH_G / "index" / "witness_log.jsonl")
check("read_log:removed", wt.read_log(5),
run_go(binpath, go_env, {"op": "read_log", "limit": 5}))
check("log_stats:removed", wt.log_stats(), run_go(binpath, go_env, {"op": "log_stats"}))
print(f"parity: {total - fails}/{total} match")
return 1 if fails else 0
if __name__ == "__main__":
sys.exit(main())
+562
View File
@@ -0,0 +1,562 @@
# Freeze rig for the construction_interface dichotomy gap-closing (dichotomy
# wave #2479 gap port). Auto-imported on interpreter start
# (PYTHONPATH=scripts/ci_freeze_seams:src) by BOTH the truth generator
# (scripts/gen_construction_interface_truth.py) and the shared harness's
# --verify mode, so frozen truth is byte-reproducible in any process:
#
# * EVERY RUNE_*_CORE gate is pinned to "python" — the oracle runs its
# pure-Python floors end to end (construction_interface, scaffold,
# structural_store, construction_decision, construction_mode, capability
# ledger, programme continuation, layout contract, ...). The shared
# harness's _pin_oracle_cores cannot reach the transitive gates; this
# blanket pin is the poisoned-truth law for the whole dependency cone.
# * The wall clocks are FROZEN: rune.structural_store.now and
# rune.scaffold.now (bound import) report CI_FROZEN_NOW. The oracle
# stamps need ids, observed_at, checkpoints and closure records through
# these two seams; the frozen truth carries the constant instant.
# * uuid.uuid4 is a deterministic counter (submit_need mints contract ids
# from uuid4().hex[:6]); the counter RESETS per rig helper call so a
# case's ids depend only on how many mints happen inside it.
# * CI_FREEZE_HOME (default /tmp/ci_gap_freeze_home) roots every per-case
# hermetic store: cases/<case>/proj/.rune/scaffold — deterministic
# per-case dirs, because envelopes that carry paths (mini_doc) must
# replay byte-identically.
# * DOC-CARRYING SEAMS: the Rust kernel is a pure doc-in/doc-out membrane
# (the store stays with the facade), so every stateful seam below takes
# the FULL input doc as an argument — the frozen args replay in the Rust
# battery without any store. The input docs are built by the deterministic
# builder helpers (build_doc/submit_doc/walk_doc) that the GENERATOR
# calls; the seam injects the doc into a fresh hermetic store, runs the
# ORACLE method, and returns the envelope (plus oracle-derived doc
# outputs where the kernel's contract includes them).
# * write_mini_doc is redirected into the case dir (the oracle's default
# routes through the SOURCE TREE — a repo-dependent absolute path).
#
# KNOWN-NONDETERMINISTIC SEAM (memory_consolidation precedent): the
# obligation ids in _obligations_projection carry Python's
# process-randomized str hash. Cases whose output carries those ids live
# in the SEPARATE frozen_ci_truth_hash.json battery (captured + verified
# with PYTHONHASHSEED=0) and are SHAPE-pinned in the Rust battery and the
# parity check — never value-frozen in the hash-free battery.
import itertools
import json
import os
import shutil
import uuid as _uuid
from pathlib import Path
for _k in list(os.environ):
if _k.startswith("RUNE_") and _k.endswith("_CORE"):
os.environ[_k] = "python"
CI_FREEZE_HOME = os.environ.get("CI_FREEZE_HOME") or "/tmp/ci_gap_freeze_home"
FROZEN_NOW = "2026-10-13T09:41:23Z"
import rune.structural_store as ss # noqa: E402
import rune.scaffold as _sc # noqa: E402
ss.now = lambda: FROZEN_NOW
_sc.now = lambda: FROZEN_NOW
# programme_continuation stamps saved_at/at through time.strftime directly
# (not ss.now) — pin the time module floor for it.
import rune.capability_ledger as _cl_mod # noqa: E402
import rune.programme_continuation as _pc_mod # noqa: E402
import time as _time_mod # noqa: E402
_cl_mod._now = lambda: FROZEN_NOW
_pc_mod.time = type("_T", (), {
"strftime": staticmethod(lambda f, _t: FROZEN_NOW),
"gmtime": staticmethod(lambda *_a: None),
"time": staticmethod(lambda: 0.0),
"monotonic": staticmethod(lambda: 0.0),
})()
_MINT = itertools.count(1)
class _DetUUID:
def __init__(self, n: int):
self.hex = f"{n:06x}" + "0" * 26
def _reset_mint():
global _MINT
_MINT = itertools.count(1)
_uuid.uuid4 = lambda: _DetUUID(next(_MINT)) # type: ignore[assignment]
import rune.construction_interface as ci # noqa: E402
# write_mini_doc redirect (source-tree default → per-case dir)
import rune.construction_projection as _cp_mod # noqa: E402
_orig_mini_doc = _cp_mod.write_mini_doc
def _hermetic_mini_doc(scaffold, contract_id, out_dir=None):
case = os.environ.get("CI_ACTIVE_CASE", "mini-doc")
out = Path(CI_FREEZE_HOME) / "cases" / case / "docs"
return _orig_mini_doc(scaffold, contract_id, out_dir=out)
_cp_mod.write_mini_doc = _hermetic_mini_doc
# Originals captured BEFORE the seam bindings below shadow the module
# globals the oracle itself calls internally (envelope assembly etc.) —
# the wrappers must call the captured originals, never the shadowed name.
_ORIG = {name: getattr(ci, name) for name in (
"_envelope", "_to_stage_check", "_guard_specs_from_obligations",
"t_layout", "_obligations_projection", "_obligation_scope_files",
"main")}
FIXTURE_ENTITIES = [
{"id": "capability:exporter", "kind": "capability", "identities": {},
"maturity": "WIRED", "evidence_refs": ["f"], "relationships": [],
"observations": []},
{"id": "contract:csv_export", "kind": "contract", "identities": {},
"maturity": "SEED", "evidence_refs": ["f"], "relationships": [],
"observations": []},
]
FIXTURE_RELATIONSHIPS = [
{"type": "implements", "from": "capability:exporter",
"to": "contract:csv_export", "evidence_refs": ["f"], "observations": []},
]
def _case_dir(case: str) -> Path:
os.environ["CI_ACTIVE_CASE"] = case
d = Path(CI_FREEZE_HOME) / "cases" / case
shutil.rmtree(d, ignore_errors=True)
(d / "proj" / ".rune").mkdir(parents=True, exist_ok=True)
return d
def _iface(case: str, project_id: str = "gap-ci-proj"):
_reset_mint()
d = _case_dir(case)
store = str(d / "proj" / ".rune" / "scaffold")
iface = ci.ConstructionInterface(
builder="factory-gap-ci", project_store=store, project_id=project_id)
iface.scaffold.init(purpose="fixture")
doc = iface.scaffold.load()
for e in FIXTURE_ENTITIES:
doc["entities"].append(json.loads(json.dumps(e)))
for r in FIXTURE_RELATIONSHIPS:
doc["relationships"].append(json.loads(json.dumps(r)))
iface.scaffold.save(doc)
return iface
def _iface_with_doc(case: str, doc: dict, project_id: str = "gap-ci-proj"):
"""Fresh hermetic store with `doc` injected — the seam entry point."""
_reset_mint()
d = _case_dir(case)
store = str(d / "proj" / ".rune" / "scaffold")
iface = ci.ConstructionInterface(
builder="factory-gap-ci", project_store=store, project_id=project_id)
iface.scaffold.init(purpose="fixture")
iface.scaffold.save(json.loads(json.dumps(doc)))
return iface
def build_doc() -> dict:
"""The fixture authority document (pure dict, no store IO)."""
doc = ss.new_doc()
for e in FIXTURE_ENTITIES:
doc["entities"].append(json.loads(json.dumps(e)))
for r in FIXTURE_RELATIONSHIPS:
doc["relationships"].append(json.loads(json.dumps(r)))
return doc
def submit_doc(case: str, doc: dict, objective: str = "persistent project export",
**kw) -> dict:
"""Builder helper (NOT a frozen fn): run oracle submit_need over a
hermetic store seeded with `doc`; return the updated doc."""
payload = dict(
constraints={"contracts": ["contract:csv_export"]},
affected_surface=[],
evidence_refs=["x"],
approval_context="covered by fixture authority",
)
payload.update(kw)
iface = _iface_with_doc(case, doc)
r = iface.submit_need(objective, **payload)
assert r["success"] or not payload.get("generate", True), r
return iface.scaffold.load()
def walk_doc(case: str, doc: dict, objective: str = "persistent project export",
phases=("approved", "building", "verifying"), **kw) -> dict:
"""Builder helper: submit + walk the legal ladder in ONE process."""
iface = _iface_with_doc(case, doc)
payload = dict(
constraints={"contracts": ["contract:csv_export"]},
affected_surface=[],
evidence_refs=["x"],
approval_context="covered by fixture authority",
)
payload.update(kw)
r = iface.submit_need(objective, **payload)
assert r["success"], r
cid = r["ids"]["contract_id"]
for ph in phases:
t = iface.transition(cid, ph)
assert t["success"], t
return iface.scaffold.load()
def contract_of(doc: dict, contract_id: str):
for e in doc.get("entities", []):
if e.get("kind") == "construction_contract" and \
e.get("id") == f"contract:{contract_id}":
return e
return None
def build_ledger_caps() -> dict:
"""A valid capability-ledger doc via the ledger's own define API
(builder helper; frozen clock keeps it deterministic)."""
from rune.capability_ledger import CapabilityLedger
ledger = CapabilityLedger(Path(CI_FREEZE_HOME) / "cases" / "b-ledger")
ledger.define(capability_id="capability:exporter", name="exporter",
purpose="export fixtures", owning_project="gap-ci-proj",
component="exporter", source_locations=["src/export.py"])
return json.loads(json.dumps(ledger.doc))
def _discover_doc(contract_id: str, observed_at: str, project: str) -> dict:
"""A minimal store doc carrying ONE construction contract (builder
helper for the discover_active_contract seam)."""
doc = ss.new_doc()
ss.add_entity(doc, id=f"contract:{contract_id}",
kind="construction_contract",
identities={"project": project, "scope": [],
"affected_entities": []},
evidence_refs=["f"])
doc["entities"][-1]["observed_at"] = observed_at
return doc
def _submitted_cid(doc: dict) -> str:
for e in doc.get("entities", []):
if e.get("kind") == "construction_contract":
return e["id"].split(":", 1)[1]
raise AssertionError("no contract in doc")
# ── pure module-level seams ─────────────────────────────────────────────────
def _envelope(operation, *, success, ids=None, state=None, evidence=None,
errors=None, warnings=None, extra=None):
return _ORIG["_envelope"](operation, success=success, ids=ids, state=state,
evidence=evidence, errors=errors,
warnings=warnings, **(extra or {}))
def _to_stage_check(spec):
from rune import stage_guards as _sg
c = _sg.StageCheck(
name=str(spec.get("name", "guard")),
kind=str(spec.get("kind", "assert")),
argv=spec.get("argv"),
output_pattern=str(spec.get("output_pattern", "")),
path=str(spec.get("path", "")),
check=spec.get("check"),
description=str(spec.get("description", "")),
)
return {"name": c.name, "kind": c.kind, "argv": c.argv,
"output_pattern": c.output_pattern, "path": c.path,
"check": c.check.__name__ if callable(c.check) else None,
"description": c.description}
def _guard_specs_from_obligations(c):
return _ORIG["_guard_specs_from_obligations"](c)
def t_layout(ext):
return _ORIG["t_layout"](ext)
def _obligations_projection(c):
return _ORIG["_obligations_projection"](c)
def _obligation_scope_files(obligations):
return _ORIG["_obligation_scope_files"](obligations)
def main(case, argv):
"""The JSON CLI transport over the hermetic rune-internal store."""
_reset_mint()
d = _case_dir(case)
(d / "store" / "scaffold").mkdir(parents=True, exist_ok=True)
prev = os.getcwd()
os.chdir(d)
try:
inner = ci.ConstructionInterface(builder="factory-gap-ci")
inner.scaffold.init(purpose="fixture")
return _ORIG["main"](list(argv))
finally:
os.chdir(prev)
# ── authority access ─────────────────────────────────────────────────────────
def _authorities(scaffold_doc, spine_doc=None, mode="external_project"):
"""The oracle's authority assembly given the loaded docs (doc-carrying:
the loads stay with the caller)."""
auth = {"project_scaffold": scaffold_doc}
if mode == "rune_internal" and spine_doc is not None:
auth["rune_spine"] = spine_doc
return auth
def _record_session(doc, operation, detail, builder="factory-gap-ci",
mode="external_project", now=None):
iface = _iface("rec-session")
d = json.loads(json.dumps(doc))
iface._record_session(d, operation, detail)
return d
# ── classify / context / capabilities ───────────────────────────────────────
def classify(decision, builder="factory-gap-ci"):
"""Envelope assembly over the canonical classifier's result (the
classifier itself is construction_mode's port surface)."""
iface = _iface("classify")
d = dict(decision)
env = _ORIG["_envelope"]("classify", success=d.get("mode") != "UNKNOWN",
state={**d, "builder": builder})
return env
def construction_context(case, doc, contract_id=None,
builder="factory-gap-ci", project="gap-ci-proj"):
iface = _iface_with_doc(case, doc, project_id=project)
return iface.construction_context(contract_id)
def capabilities(mode="external_project", project="gap-ci-proj"):
iface = _iface("caps")
iface.mode = mode
iface.scaffold.project_id = project
return iface.capabilities()
# ── submit_need ──────────────────────────────────────────────────────────────
def submit_need(case, doc, objective, origin="builder", constraints=None,
affected_surface=None, evidence_refs=None,
approval_context="", task_ref="", generate=True,
contract_id=None):
iface = _iface_with_doc(case, doc)
kw = dict(origin=origin, generate=generate)
if constraints is not None:
kw["constraints"] = constraints
if affected_surface is not None:
kw["affected_surface"] = affected_surface
if evidence_refs is not None:
kw["evidence_refs"] = evidence_refs
kw["approval_context"] = approval_context
kw["task_ref"] = task_ref
if contract_id is not None:
kw["contract_id"] = contract_id
return iface.submit_need(objective, **kw)
# ── read projections + evidence + verification ──────────────────────────────
def inspect_decision(case, doc, contract_id):
iface = _iface_with_doc(case, doc)
return iface.inspect_decision(contract_id)
def get_scope(case, doc, contract_id):
iface = _iface_with_doc(case, doc)
return iface.get_scope(contract_id)
def get_obligations(case, doc, contract_id):
iface = _iface_with_doc(case, doc)
return iface.get_obligations(contract_id)
def report_observation(case, doc, contract_id, observations):
iface = _iface_with_doc(case, doc)
return iface.report_observation(contract_id, observations)
def verify(case, doc, contract_id, changed_files=None,
layout_observations=None):
iface = _iface_with_doc(case, doc)
return iface.verify(contract_id, changed_files=changed_files,
layout_observations=layout_observations)
def transition(case, doc, contract_id, phase, evidence_ref="",
guard_checks=None):
iface = _iface_with_doc(case, doc)
return iface.transition(contract_id, phase, evidence_ref=evidence_ref,
guard_checks=guard_checks)
def close(case, doc, contract_id, observed_evidence, scope_files=None):
"""`doc` must already carry the contract at verifying (walk_doc)."""
iface = _iface_with_doc(case, doc)
return iface.close(contract_id, observed_evidence=observed_evidence,
scope_files=scope_files)
def _programme_continuation(case, doc, contract_id, programmes=None):
"""programmes: list of programme DOCS (generator-built via the pc API);
the seam persists them into the case's programme area, runs the oracle,
and returns the continuation plus the persisted-after docs."""
from rune import programme_continuation as pc
iface = _iface_with_doc(case, doc)
base = Path(iface.scaffold.current).parent / pc.DEFAULT_PROGRAMME_AREA
if programmes is not None:
base.mkdir(parents=True, exist_ok=True)
for pd in programmes:
prog = pc.Programme(
programme_id=pd["programme_id"], objective=pd["objective"],
stages=[pc.ProgrammeStage(**s) for s in pd["stages"]])
prog.save(base)
out = iface._programme_continuation(contract_id)
after = None
if base.is_dir():
after = []
for f in sorted(base.glob("*.json")):
after.append(json.loads(f.read_text()))
return {"continuation": out, "programmes_after": after}
def _auto_material_change(case, doc, scope_files, capabilities=None):
"""capabilities: the ledger DOC (kernel input); the seam persists it as
the project rune_model ledger, runs the oracle, and returns the oracle
result plus the ledger doc after the oracle's material_change/save."""
from rune.capability_ledger import CapabilityLedger
iface = _iface_with_doc(case, doc)
if capabilities is not None:
ledger_dir = Path(iface.scaffold.store_dir).parent / "rune_model"
ledger_dir.mkdir(parents=True, exist_ok=True)
(ledger_dir / "capability_ledger.json").write_text(
json.dumps(capabilities))
out = iface._auto_material_change(
list(scope_files), note="contract closed (material change)")
after = None
led = Path(iface.scaffold.store_dir).parent / "rune_model" / \
"capability_ledger.json"
if led.is_file():
after = json.loads(led.read_text())
return {"result": out, "ledger_after": after}
def discover_active_contract(case, candidates, root_name="store"):
"""candidates: [{project: str|null, doc: {...}}] — the seam persists
each doc at projects/<p>/current.json (or the root current.json) inside
the case dir and runs the oracle over that store root."""
d = _case_dir(case)
for cand in candidates:
proj, doc = cand["project"], cand["doc"]
if proj is None:
(d / "current.json").write_text(json.dumps(doc))
else:
p = d / "projects" / proj
p.mkdir(parents=True, exist_ok=True)
(p / "current.json").write_text(json.dumps(doc))
return ci.ConstructionInterface.discover_active_contract(str(d))
def resume(case, doc, contract_id):
iface = _iface_with_doc(case, doc)
return iface.resume(contract_id)
def amend_scope(case, doc, contract_id, add_paths, reason, authority="user"):
iface = _iface_with_doc(case, doc)
env = iface.amend_scope(contract_id, add_paths, reason=reason,
authority=authority)
return {"envelope": env,
"contract_after": contract_of(iface.scaffold.load(), contract_id)}
def ladder_walk(case, objective="persistent project export"):
"""The FULL ladder in ONE process (the shared-store clobber law):
submit_need → approved → building → verifying → close, with the read
projections riding the walk."""
iface = _iface(case)
out = []
r = iface.submit_need(
objective,
constraints={"contracts": ["contract:csv_export"]},
affected_surface=[], evidence_refs=["x"],
approval_context="covered by fixture authority")
out.append({"step": "submit_need", "envelope": r})
if not r["success"]:
return out
cid = r["ids"]["contract_id"]
out.append({"step": "inspect_decision", "envelope": iface.inspect_decision(cid)})
out.append({"step": "get_scope", "envelope": iface.get_scope(cid)})
out.append({"step": "verify", "envelope": iface.verify(cid)})
for ph in ("approved", "building", "verifying"):
t = iface.transition(cid, ph)
out.append({"step": f"transition:{ph}", "envelope": t})
if not t["success"]:
return out
c = iface.close(cid, observed_evidence=[
{"kind": "port_evidence", "detail": "gap closed with proof"}])
out.append({"step": "close", "envelope": c})
return out
# Bind the seams onto the oracle module so the shared harness's
# getattr(module, fn) resolves every frozen fn name.
ci.ladder_walk = ladder_walk
ci.submit_need = submit_need
ci.classify = classify
ci.construction_context = construction_context
ci.capabilities = capabilities
ci.inspect_decision = inspect_decision
ci.get_scope = get_scope
ci.get_obligations = get_obligations
ci.report_observation = report_observation
ci.verify = verify
ci.transition = transition
ci.close = close
ci._programme_continuation = _programme_continuation
ci._auto_material_change = _auto_material_change
ci.discover_active_contract = discover_active_contract
ci.resume = resume
ci.amend_scope = amend_scope
ci._authorities = _authorities
ci._record_session = _record_session
ci.t_layout = t_layout
ci._obligations_projection = _obligations_projection
ci._obligation_scope_files = _obligation_scope_files
ci._guard_specs_from_obligations = _guard_specs_from_obligations
ci.ci_to_stage_check = _to_stage_check
ci._envelope = _envelope
ci.main = main
# NOTE: ci._to_stage_check is deliberately NOT rebound — the oracle's
# transition() calls the module-global _to_stage_check internally and needs
# real StageCheck objects for the readiness canary. The rig's JSON-safe
# _to_stage_check is exposed as the ci_to_stage_check seam instead (same
# logic, JSON-safe projection).
# ci._obligations_projection IS rebound to the identity wrapper above
# (pure dict in → dict out through the captured original) — internal
# oracle calls with live contract dicts pass through unharmed.
@@ -0,0 +1,63 @@
#!/usr/bin/env python3
"""Close the adaptive_router Phase B contract (dichotomy wave follow-up).
Contract BUILDER-2026-10-14T09:00:07Z-70ebf0-factory-gap-ar sits at
verifying (walked draft->approved->building->verifying in ONE process).
This closes it with the post-push SHAs:
feat 6452b8a0 close PARTIAL gaps (salvaged landing, contract
BUILDER-2026-10-13T16:25:22Z-7e3fd4-factory-gap-ar)
phase B 3789f814 language-advantage pass (this contract's deliverable)
One process (shared-store clobber hazard; segment writes are slow).
"""
import json
import os
import sys
from pathlib import Path
os.environ.setdefault(
"CS_RUST_LIB",
"/mnt/workdrive/rune/src/rust/capability_scoring/target/release/libcapability_scoring.so",
)
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "src"))
from rune.construction_interface import ConstructionInterface
CID = "BUILDER-2026-10-14T09:00:07Z-70ebf0-factory-gap-ar"
iface = ConstructionInterface(builder="factory-gap-ar")
c = iface.close(CID, observed_evidence=[
{
"kind": "port_evidence",
"detail": "adaptive_router Phase B language-advantage pass — "
"phase B 3789f814 refactor(adaptive_router): Phase B "
"language-advantage pass — dichotomy wave (pushed "
"gitea/master 6208acdc..3789f814). Behavior-neutral: "
"typed Route constants (RouteLocalFix/RouteStandard/"
"RouteResearched) at every route comparison, "
"floorRiskSet/floorUncertaintySet O(1) membership maps "
"replacing slice scans in FloorAppliesFromFlags/"
"FloorReason/FloorApplies, single-pass floor in "
"ClassifyRoute (FloorReason hits once, floor = hits "
"nonempty), FloorReason hits prealloc. Proof of no "
"behavior change: go test 7/7 green, frozen truth 25/25 "
"byte-identical (freeze_truth.py --verify), live parity "
"32/32 (check_adaptive_router_parity.py), gofmt+vet+go "
"build clean, pytest 19/19 both pins. Parent parity "
"commit feat 6452b8a0 (contract "
"BUILDER-2026-10-13T16:25:22Z-7e3fd4-factory-gap-ar).",
},
], scope_files=[
"src/rune/adaptive_router.py",
"src/go/adaptive-router/main.go",
"src/go/adaptive-router/cli.go",
"src/go/adaptive-router/truth.json",
"src/go/adaptive-router/truth_test.go",
"scripts/gen_adaptive_router_truth.py",
"scripts/check_adaptive_router_parity.py",
])
print("close:", json.dumps(c)[:300])
ok = c.get("success")
print("CONTRACT", CID, "closed" if ok else "CLOSE_FAILED")
sys.exit(0 if ok else 1)
@@ -0,0 +1,85 @@
#!/usr/bin/env python3
"""Close the #2479 dichotomy-wave contract for builder_bridge_cli in ONE
process (submit → approved → building → verifying → closed), with SHA
evidence. Run with CS_RUST_LIB pointing at a built capability_scoring .so."""
import json
import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "src"))
PARITY_SHA = sys.argv[1] if len(sys.argv) > 1 else ""
PHASEB_SHA = sys.argv[2] if len(sys.argv) > 2 else ""
if not (PARITY_SHA and PHASEB_SHA):
sys.exit("usage: close_contract_builder_bridge_cli.py <parity_sha> <phaseb_sha>")
from rune.construction_interface import ConstructionInterface
iface = ConstructionInterface(builder="factory-batch-i")
r = iface.submit_need(
"Port builder_bridge_cli to FULL Go (#2479 dichotomy tranche, GO "
"verdict): the CLI shell with exact oracle semantics — argv join-then-"
"strip (inner spaces kept), --json consumed only at argv[1] (anywhere "
"else it is task text), print()'s always-trailing newline (empty "
"capsule renders a single \\n), Python json.dumps byte-parity "
"(insertion order, ', '/': ' separators, ensure_ascii \\uXXXX, "
"surrogate pairs) — over the deterministic preflight chain (route "
"authority mirrored from src/go/adaptive-router incl. the rrf cgo "
"membrane; capsule render from src/go/builder-bridge; rune-safe "
"truncation per the str[:n] law; Python's [:200]-on-joined-reasons "
"precedence). Reactive seams excluded per event-wait precedent "
"(memory retrieval, construction projection — oracle degrade paths; "
"PL1 lessons empty by design). Frozen truth 13 cases from the live "
"oracle subprocess under pinned seams (frozen clock sitecustomize "
"rig, empty memory/construction stores, HOME isolation for the "
"hardcoded ~/.config/opencode shard sources); byte-deterministic "
"regeneration; live parity Go binary == Python oracle 13/13; Phase B "
"allocation-flat render pass (measured, allocs-asserted).",
origin="builder",
)
print("submit_need:", json.dumps(r)[:200])
if not r.get("success"):
sys.exit(1)
cid = r["ids"]["contract_id"]
print("contract_id:", cid)
for phase in ("approved", "building", "verifying"):
t = iface.transition(cid, phase)
if not t.get("success"):
print(f"transition->{phase} FAILED:", json.dumps(t)[:300])
sys.exit(1)
print("walked to verifying")
c = iface.close(cid, observed_evidence=[{
"kind": "port_evidence",
"detail": (
f"builder_bridge_cli GO dichotomy completion — parity commit {PARITY_SHA}, "
f"Phase B commit {PHASEB_SHA}; fn coverage 0/1 NOT TOUCHED -> 1/1 FULL "
"(audit CURRENT instrument); frozen-truth battery replays 13 cases "
"byte-identical (src/go/builder-bridge-cli/truth.json, generated from "
"the live oracle subprocess: scripts/gen_builder_bridge_cli_truth.py — "
"re-run regenerates byte-identical); live parity Go binary == live "
"Python oracle on all 13 argv vectors under identical pinned env "
"(frozen clock, empty stores, HOME isolation) 13/13 IDENTICAL; "
"go build + go vet + gofmt clean; Python suite tests/test_builder_bridge.py "
"13 passed (no Python surface touched). Documented divergences: "
"memory retrieval + construction projection are reactive seams that "
"stay Python (event-wait precedent) — the Go preflight returns the "
"oracle's own degrade-path output (empty lines) which is exactly what "
"the frozen corpus pins; provenance 'ambiguous' renders Go 'false' vs "
"Python 'False' (not observable in any CLI output)."
),
}], scope_files=[
"src/rune/builder_bridge_cli.py",
"src/go/builder-bridge-cli/go.mod",
"src/go/builder-bridge-cli/main.go",
"src/go/builder-bridge-cli/preflight.go",
"src/go/builder-bridge-cli/truth.json",
"src/go/builder-bridge-cli/truth_test.go",
"scripts/gen_builder_bridge_cli_truth.py",
"scripts/bbc_freeze_seams/sitecustomize.py",
"scripts/close_contract_builder_bridge_cli.py",
])
print("close:", json.dumps(c)[:300])
print("CONTRACT", cid, "closed" if c.get("success") else "CLOSE_FAILED")
@@ -17,14 +17,14 @@ from rune.construction_interface import ConstructionInterface
cid = sys.argv[1]
iface = ConstructionInterface(builder="factory-gap-cp")
t = iface.transition(cid, "verifying", evidence_ref="feat 1ad658cf — battery 14/14, clippy 0, harness 18/18, live parity 192/192 both pins, pytest 30/30+20/20 both pins")
t = iface.transition(cid, "verifying", evidence_ref="feat 1ad658cf — battery 14/14, clippy 0, harness 18/18, live parity 192/192 both pins, pytest 30/30+20/20 both pins; phase B f2ae1b0f — SignalTally struct + free _check, zero-copy _surface_text tokens, Map::with_capacity(3) need envelope (battery 14/14, parity 192/192 both pins re-run post-B)")
print("transition->verifying:", json.dumps(t)[:300])
if not t.get("success"):
print("TRANSITION FAILED — aborting"); sys.exit(1)
c = iface.close(cid, observed_evidence=[{
"kind": "port_evidence",
"detail": "construction_pattern dichotomy completion — feat 1ad658cf "
"detail": "construction_pattern dichotomy completion — feat 1ad658cf + phase B f2ae1b0f "
"'feat(construction_pattern): close PARTIAL gaps — dichotomy "
"wave'. Audit PARTIAL 7/13 -> FULL 13/13 (headline 74/192, "
"fn 1358/2278). Ported _need_dict (FFI need envelope, wired "
+105
View File
@@ -0,0 +1,105 @@
#!/usr/bin/env python3
"""Close the #2479 dichotomy-wave contract for context_pressure in ONE
process (submit → approved → building → verifying → closed), with SHA
evidence. Run with CS_RUST_LIB pointing at a built capability_scoring .so."""
import json
import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "src"))
PARITY_SHA = sys.argv[1] if len(sys.argv) > 1 else ""
if not PARITY_SHA:
sys.exit("usage: close_contract_context_pressure.py <parity_sha>")
from rune.construction_interface import ConstructionInterface
iface = ConstructionInterface(builder="factory-gap-cps")
r = iface.submit_need(
"Port context_pressure to FULL Rust (#2479 dichotomy tranche, RUST "
"verdict — was 3/9 PARTIAL): the pure compute + entry assembly with "
"exact oracle semantics — codepoint-based token estimation (Python "
"len(), max(1, int(len/3.5))), the pressure ladder (raw-pressure "
"gates vs banker-correct round(x, 3) display, ZeroDivisionError "
"parity on max_tokens=0), degradation signals (avg-first/avg-last "
"trend, \\w+ unique-ratio repetition, generic-ratio composite with "
"the int-0 max(0, x) type law), JSONL entry assembly "
"({timestamp, session_id, **measurement} spread-override law), the "
"log tail reader (deque(maxlen) semantics, file-iteration law — no "
"phantom line after a final newline, blank/unparseable skip, "
"negative-limit [] floor), stats counting (exact AttributeError on "
"parsed non-dict lines), the on-message hook (data truthiness, "
"message/text/str(data) fallback with Python repr shapes), and CLI "
"dispatch (argparse shapes incl. code-2 exits, .1% renders, "
"indent=2 dumps). File IO (LOG_PATH append/read) and the wall clock "
"stay in the Python facade (no-clock law — now is always an "
"argument); cps_loader.py is the ctypes seam (RUNE_CPS_CORE / "
"RUNE_CONTEXT_PRESSURE_CORE pins, error envelopes raise the mapped "
"exceptions so crash parity holds). Frozen truth 75 cases under the "
"cps_freeze_seams rig (explicit core pins, frozen clock, hermetic "
"RUNE_MEMORY_DIR scratch, CPS_SEED_LOG for CLI subprocess rows); "
"byte-identical regeneration x2; shared-harness --verify OK; live "
"parity frozen=78 regen=6 fuzz=1400 live=18 failures=0; Rust "
"battery 10/10; clippy -D warnings + fmt clean; pytest 34/34 both "
"pins; audit 3/9 PARTIAL -> 9/9 FULL (RUST).",
origin="builder",
)
print("submit_need:", json.dumps(r)[:200])
if not r.get("success"):
sys.exit(1)
cid = r["ids"]["contract_id"]
print("contract_id:", cid)
for phase in ("approved", "building", "verifying"):
t = iface.transition(cid, phase)
if not t.get("success"):
print(f"transition->{phase} FAILED:", json.dumps(t)[:300])
sys.exit(1)
print("walked to verifying")
c = iface.close(cid, observed_evidence=[{
"kind": "port_evidence",
"detail": (
f"context_pressure RUST dichotomy completion — parity commit {PARITY_SHA}; "
"fn coverage 3/9 PARTIAL -> 9/9 FULL (audit CURRENT instrument, "
"docs/dichotomy-rebase-honest-audit.md regenerated at that commit); "
"frozen-truth battery replays 75 cases byte-identical "
"(src/rust/context_pressure/src/frozen_cp_truth.json via include_str! "
"in branch_battery.rs, generated from the live oracle floor under "
"scripts/cps_freeze_seams: scripts/gen_context_pressure_truth.py — "
"re-run regenerates byte-identical, sha256-stable x2); shared harness "
"freeze_truth.py --verify OK (28 envelope cases byte-identical); live "
"parity scripts/check_context_pressure_parity.py frozen=78 regen=6 "
"fuzz=1400 live=18 failures=0 (crash parity with exact str(e) "
"contract); cargo test 10/10, cargo clippy -D warnings clean, cargo "
"fmt clean, cargo build --release green; Python suite "
"tests/test_context_pressure.py 34 passed BOTH pins (python pin + "
"kernel live), ruff clean. Documented divergences: _now stays Python "
"(no-clock law — timestamps are arguments); file IO (LOG_PATH "
"append/read, CLI printing) stays in the facade — the kernel owns "
"entry assembly, log parsing, stats counting, hook derivation and "
"CLI dispatch decisions; read_log negative limit mirrors the "
"oracle's OBSERVED [] (best-effort floor swallows deque's "
"ValueError); integral floats crossing FFI render int-shaped "
"envelope-side (pyjson Num law) — live parity compares "
"structurally, byte shape pinned by the battery."
),
}], scope_files=[
"src/rune/context_pressure.py",
"src/rune/cps_loader.py",
"src/rust/context_pressure/Cargo.toml",
"src/rust/context_pressure/Cargo.lock",
"src/rust/context_pressure/src/lib.rs",
"src/rust/context_pressure/src/branch_battery.rs",
"src/rust/context_pressure/src/frozen_cp_truth.json",
"scripts/gen_context_pressure_truth.py",
"scripts/context_pressure_truth.py",
"scripts/check_context_pressure_parity.py",
"scripts/cps_freeze_seams/sitecustomize.py",
"scripts/close_contract_context_pressure.py",
"tests/test_context_pressure.py",
"verification/summary-cp.md",
])
print("close:", json.dumps(c)[:300])
print("CONTRACT", cid, "closed" if c.get("success") else "CLOSE_FAILED")
+89
View File
@@ -0,0 +1,89 @@
#!/usr/bin/env python3
"""Close the #2479 dichotomy-wave cron_engine gap contract (GO port).
Full lifecycle walk in ONE process (shared-store clobber hazard; segment
transitions take ~60s each over ~610 segments — do NOT split across
processes). Carries the already-pushed SHA as evidence:
feat c113b8e6 close PARTIAL gaps — dichotomy wave (Phase B folded)
Usage: close_contract_cron_engine.py
"""
import json
import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "src"))
from rune.construction_interface import ConstructionInterface
PARITY_SHA = "c113b8e6"
EVIDENCE = f"parity {PARITY_SHA}; phase B folded into the parity commit"
iface = ConstructionInterface(builder="factory-gap-ce")
r = iface.submit_need(
"cron_engine dichotomy gap-close (GO): name-preserving port of the 14 "
"unmatched functions (get_cron_engine singleton family, run_task "
"method+module, start_engine/stop_engine, to_dict, "
"fire_on_task_complete, stop, _run_loop, _parse_cron_field/"
"_should_run mirror-carried, _execute_task, _log_execution/_log_error "
"with 5MB rotation) into src/go/cron-engine, plus Python-exact "
"ordered _save/_load (insertion order + ensure_ascii + CronTask(**) "
"TypeError semantics), a shlex.split port with the oracle's ValueError "
"messages, pyISO isoformat parity, and subprocess error-message "
"translation (FileNotFoundError/PermissionError/TimeoutExpired str(e) "
"forms; nonzero exit is a returncode, not an error). IO behind "
"injectable clock/sleep/exec/recordFailure seams. Frozen-truth battery "
"(truth_gap.json, 46 cases / 12 wrapper fns) via the shared harness + "
"wrapper shims — byte-identical --verify and fresh re-freeze. gofmt/"
"vet/build clean; gap replay 46/46 + legacy 25/25 + 5 tests green; "
"live parity 3/3 scenarios (31 ops) oracle-vs-GO identical; CLI "
"byte-identical under both Python pins. dichotomy audit cron_engine "
"27/27 FULL. Delivered on gitea/master: feat " + PARITY_SHA + ".",
origin="builder",
)
print("submit_need:", json.dumps(r)[:300])
if not r.get("success"):
print("NEED FAILED — aborting")
sys.exit(1)
c = r["ids"]["contract_id"]
print("contract_id:", c)
for phase in ("approved", "building", "verifying"):
t = iface.transition(c, phase, evidence_ref=EVIDENCE)
ok = t.get("success")
print(f"transition->{phase}:", "ok" if ok else json.dumps(t)[:300])
if not ok:
sys.exit(1)
cres = iface.close(c, observed_evidence=[{
"kind": "port_evidence",
"detail": (
f"cron_engine GO dichotomy gap-close — parity commit {PARITY_SHA} "
f"(Phase B folded); dichotomy audit fn coverage 13/27 PARTIAL -> "
f"27/27 FULL (missing list emptied); 46-case frozen gap truth "
f"(scripts/gen_cron_engine_gap_truth.py wrapper shims — byte-identical "
f"--verify AND fresh re-freeze), gap replay 46/46 + legacy 25/25 + 5 "
f"Go tests green, gofmt/vet/build clean, live parity 3/3 scenarios "
f"(31 ops oracle-vs-GO identical via scripts/check_cron_engine_"
f"parity.py), CLI byte-identical under both Python pins. Evidence: "
f"verification/ce-* (exit codes + summary committed)."
),
}], scope_files=[
"src/rune/cron_engine.py",
"src/go/cron-engine/main.go",
"src/go/cron-engine/scenario.go",
"src/go/cron-engine/truth_gap.json",
"src/go/cron-engine/truth_gap_test.go",
"scripts/gen_cron_engine_gap_truth.py",
"scripts/check_cron_engine_parity.py",
])
print("close:", json.dumps(cres)[:300])
if not cres.get("success"):
sys.exit(1)
doc = iface.scaffold.load()
e = iface.scaffold.contract(doc, c)
print("FINAL PHASE:", e.get("phase") if e else "MISSING")
if not e or e.get("phase") != "closed":
sys.exit(1)
print("CLOSED", c)
+145
View File
@@ -0,0 +1,145 @@
#!/usr/bin/env python3
"""Close the #2479 dichotomy-wave drift_compression gap contract (RUST port).
Full lifecycle walk in ONE process (shared-store clobber hazard; segment
transitions take ~60s each — do NOT split across processes). The final
step is iface.close() with contract_quality observed_evidence (the bare
`transition -> closed` is rejected by the quality gate). Safe to re-run:
pass the existing contract id to resume an interrupted walk.
Carries the already-pushed parity SHA as evidence:
feat 1fbc504b close PARTIAL gaps — dichotomy wave (3/7 -> 7/7)
refactor 772b1758 Phase B language-advantage pass
Usage: close_contract_drift_compression.py [contract_id]
"""
import json
import os
import sys
from pathlib import Path
os.environ.setdefault(
"CS_RUST_LIB",
"/mnt/workdrive/rune/src/rust/capability_scoring/target/release/libcapability_scoring.so",
)
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "src"))
from rune.construction_interface import ConstructionInterface
PARITY_SHA = "1fbc504b"
PHASEB_SHA = "772b1758"
EVIDENCE = f"parity {PARITY_SHA}, phase B {PHASEB_SHA}"
NEED = (
"drift_compression dichotomy gap-close (RUST): name-preserving port "
"of the 4 audit-missing functions into src/rust/memory_scoring "
"compression.rs — the audit alias now follows the live delegation "
"chain (drift_compression -> drift_core._ms_core -> ms_loader -> "
"libmemory_scoring.so) instead of cognition_core. NEW kernel: "
"get_compression_stats (SQL stays in the Python facade per the "
"boundary law; row-reduction math — int() truncation after the float "
"multiply, banker's rounding at the 1e2 scale, SQL-null coercion, "
"empty-store int-shaped 0 — in Rust + ms_get_compression_stats FFI + "
"loader wrapper + oracle delegation with a load-bearing "
"_py_get_compression_stats fallback). Fix-first defect proven by the "
"new frozen battery: warn_before_compress emitted the COERCED "
"rock_status where the oracle emits the raw value (present-None rides "
"the warning dict as null). Frozen truth 65 cases via the shared "
"freeze_truth harness (the six _py_* kernels — delegation-proof by "
"construction), byte-identical across repeated gen + --verify runs; "
"cargo battery 7/7 (include_str! embed); clippy -D warnings + fmt "
"clean; live parity 1935/1935 (pinned facade / live facade / kernel "
"direct / db-level sqlite seam / fuzz seed 2479); Python both pins "
"green; ruff clean. Dichotomy audit 3/7 PARTIAL -> 7/7 FULL (RUST). "
"Delivered on gitea/master: feat " + PARITY_SHA + ", phase B "
+ PHASEB_SHA + "."
)
iface = ConstructionInterface(builder="factory-gap-dcomp")
if len(sys.argv) > 1:
cid = sys.argv[1]
print("resuming contract:", cid)
else:
r = iface.submit_need(NEED, origin="builder")
print("submit_need:", json.dumps(r)[:300])
if not r.get("success"):
print("NEED FAILED — aborting")
sys.exit(1)
cid = r["ids"]["contract_id"]
print("contract_id:", cid)
def phase_of(cid):
doc = iface.scaffold.load()
e = iface.scaffold.contract(doc, cid)
return e.get("phase") if e else "MISSING"
phase = phase_of(cid)
print("current phase:", phase)
for want in ("approved", "building", "verifying"):
if phase == want or phase in ("verifying", "closed"):
break
t = iface.transition(cid, want, evidence_ref=EVIDENCE)
ok = t.get("success")
print(f"transition->{want}:", "ok" if ok else json.dumps(t)[:300])
if not ok:
sys.exit(1)
phase = want
c = iface.close(
cid,
observed_evidence=[{
"kind": "port_evidence",
"detail": "drift_compression dichotomy completion — parity "
f"{PARITY_SHA} feat(drift_compression): close PARTIAL "
"gaps — dichotomy wave; pushed gitea/master. Rust port "
"at src/rust/memory_scoring (compression.rs kernels + "
"ms_* FFI + ms_loader seam) closes the audit gaps "
"name-preserving: the pure five already lived there "
"(H3 slice 2) behind a stale audit alias (now mapped to "
"the live delegation chain); get_compression_stats is "
"new kernel work (SQL stays Python — boundary law; "
"int() truncation, banker's rounding at 1e2, SQL-null "
"coercion, empty-store int-shaped 0; crash parity: "
"short rows -> 'list index out of range'). Generator "
"scripts/gen_drift_compression_truth.py: 65-case frozen "
"truth (shared freeze_truth harness, the six _py_* "
"kernels — delegation-proof by construction) "
"regenerates byte-identical; freeze_truth --verify OK "
"twice against the live oracle. Battery 7/7 replay "
"VERBATIM (65 rows, include_str! embed + crash-parity "
"row shapes); live parity "
"scripts/check_drift_compression_parity.py 1935/1935 "
"(pinned facade / live facade / kernel direct / "
"db-level sqlite seam / fuzz seed 2479); clippy -D "
"warnings + fmt clean; Python both pins green "
"(test_ms_loader_seam 7/7 incl. 2 new stats tests; "
"shims failures pre-exist identically on base). Audit "
"3/7 → 7/7 FULL (RUST). Phase B 772b1758: zero-copy "
"char_indices prefix, exhaustive match dispatch, "
"try_fold accumulators — behavior-identical, battery + "
"parity re-green. Divergences (documented): integral "
"floats crossing the FFI render int-shaped "
"(savings_pct 50.0 oracle-side vs 50 envelope-side) — "
"compared structurally, byte shape pinned by the Rust "
"battery's frozen replay.",
}],
scope_files=[
"src/rust/memory_scoring/src/compression.rs",
"src/rust/memory_scoring/src/lib.rs",
"src/rust/memory_scoring/src/branch_battery.rs",
"src/rust/memory_scoring/src/frozen_dcomp_truth.json",
"src/rune/drift_compression.py",
"src/rune/ms_loader.py",
"scripts/gen_drift_compression_truth.py",
"scripts/check_drift_compression_parity.py",
],
)
print("close:", json.dumps(c)[:400])
final = phase_of(cid)
print("FINAL PHASE:", final)
ok = c.get("success") and final == "closed"
print("CLOSED" if ok else "CLOSE_FAILED", cid)
sys.exit(0 if ok else 1)
+114
View File
@@ -0,0 +1,114 @@
#!/usr/bin/env python3
"""Close the #2479 dichotomy-wave event_envelope gap contract (GO port).
Full lifecycle walk in ONE process (shared-store clobber hazard; segment
transitions can take ~60s each — do NOT split across processes). Carries
the rebased parity SHA as evidence:
feat 7f1f919d close PARTIAL gaps — dichotomy wave
Usage: close_contract_event_envelope.py
"""
import json
import os
import sys
from pathlib import Path
os.environ.setdefault(
"CS_RUST_LIB",
"/mnt/workdrive/rune/src/rust/capability_scoring/target/release/libcapability_scoring.so",
)
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "src"))
from rune.construction_interface import ConstructionInterface
PARITY_SHA = "7f1f919d"
EVIDENCE = f"parity {PARITY_SHA}"
iface = ConstructionInterface(builder="factory-gap-ee")
# Resume support: the first walk attempt hit the quality-gate law at the
# final step (raw `closed` transition refused) — pass the existing
# contract id to finish it; no argument walks a fresh contract end to end.
existing = sys.argv[1] if len(sys.argv) > 1 else None
if existing:
r = {"success": True, "ids": {"contract_id": existing}}
else:
r = iface.submit_need(
"event_envelope dichotomy gap-close (GO): name-preserving port of the 3 "
"audit-missing functions (to_dict, to_canonical_dict, test_envelope) "
"into src/go/event-bus as ToDict / ToCanonicalDict / TestEnvelope plus "
"the canonical-bridge classmethod CreateEnvelope (EventEnvelope.create: "
"CHANNELS prior vocabulary, prior-or-channel-or-source-or-unknown "
"fallback), and parity-driven defect fixes to the old-era port: "
"classifyAuthority/classifyUrgency now use the oracle's \\b<word>\\b "
"regex semantics with Unicode word chars (multi-word 'stop doing' vs "
"bare 'stop', punctuation adjacency, 'stopé' never matches; low "
"urgency 'when you can'/'no rush' multi-word entries), pyQuoteEvent "
"gains ensure_ascii escaping (unicode payload_hash parity, DEL/astral/"
"surrogate pairs), createEnvelope derives text from payload['text'] "
"(oracle signature), and minted ids/timestamps go through the "
"no-clock/no-random seams (EE_FROZEN_NOW + per-op uuid counter; "
"random uuid4-shaped ids in production). Frozen-truth battery "
"(truth_envelope.json, 83 cases incl. the loud RuntimeError branch "
"for un-bridged envelopes, schema_version-first canonical key order, "
"content-addressed payload_hash, captured test_envelope stdout) "
"generated under the scripts/ee_freeze_seams rig via freeze_truth.py "
"and verified byte-identical x2, embedded VERBATIM in "
"truth_envelope_test.go TestFrozenEnvelopeTruthReplay + seam units; "
"live parity sweep 91/91 PYTHON-json byte compare "
"(scripts/check_event_envelope_parity.py, negative control detects "
"divergence); gofmt/vet/go build clean; Python oracle battery green "
"both pins (25 live + 25 RUNE_EVENT_ENVELOPE_CORE=python). Dichotomy "
"audit 5/8 PARTIAL -> 8/8 FULL. Delivered on gitea/master: feat " + PARITY_SHA + ".",
origin="builder",
)
print("submit_need:", json.dumps(r)[:300])
if not r.get("success"):
print("NEED FAILED — aborting")
sys.exit(1)
c = r["ids"]["contract_id"]
print("contract_id:", c)
if not existing:
for phase in ("approved", "building", "verifying"):
t = iface.transition(c, phase, evidence_ref=EVIDENCE)
ok = t.get("success")
print(f"transition->{phase}:", "ok" if ok else json.dumps(t)[:300])
if not ok:
sys.exit(1)
# QUALITY-GATE LAW (2026-10-13): `closed` enters via close() — the
# predicted-vs-observed quality computation — never a raw transition.
closed = iface.close(c, observed_evidence=[{
"kind": "port_evidence",
"detail": (
f"parity {PARITY_SHA}: frozen-truth battery 83 cases byte-identical "
"(truth_envelope.json, freeze_truth.py --verify x2 under "
"scripts/ee_freeze_seams), live parity 91/91 "
"(scripts/check_event_envelope_parity.py), gofmt/vet/go build clean, "
"Python suite green both pins (25 live + 25 pinned), dichotomy "
"audit 5/8 -> 8/8 FULL"
),
}], scope_files=[
"src/rune/event_envelope.py",
"src/go/event-bus/envelope.go",
"src/go/event-bus/bus.go",
"src/go/event-bus/main.go",
"src/go/event-bus/truth_envelope.json",
"src/go/event-bus/truth_envelope_test.go",
"scripts/gen_event_envelope_truth.py",
"scripts/check_event_envelope_parity.py",
"scripts/ee_freeze_seams/sitecustomize.py",
])
print("close:", "ok" if closed.get("success") else json.dumps(closed)[:400])
if not closed.get("success"):
sys.exit(1)
doc = iface.scaffold.load()
e = iface.scaffold.contract(doc, c)
print("FINAL PHASE:", e.get("phase") if e else "MISSING")
if not e or e.get("phase") != "closed":
sys.exit(1)
print("CLOSED", c)
@@ -0,0 +1,84 @@
#!/usr/bin/env python3
"""Close the #2479 dichotomy-wave contract for evidence_capsule in ONE
process (submit → approved → building → verifying → closed), with SHA
evidence. Run with CS_RUST_LIB pointing at a built capability_scoring .so."""
import json
import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "src"))
PARITY_SHA = sys.argv[1] if len(sys.argv) > 1 else ""
PHASEB_SHA = sys.argv[2] if len(sys.argv) > 2 else ""
TRUTHFIX_SHA = sys.argv[3] if len(sys.argv) > 3 else ""
if not (PARITY_SHA and PHASEB_SHA):
sys.exit("usage: close_contract_evidence_capsule.py <parity_sha> <phaseb_sha> [truthfix_sha]")
from rune.construction_interface import ConstructionInterface
iface = ConstructionInterface(builder="factory-batch-i")
r = iface.submit_need(
"Complete the evidence_capsule dichotomy port to FULL Rust (#2479 "
"tranche): the fixed-size evidence-capsule kernel — pack (slot caps "
"5/3/3 with explicit truncation counts and None-or-missing -> [] "
"defaults) / size (missing keys -> 0) / unpack (raw_ref pointer + "
"complete flag; a MISSING truncated map means complete) — as "
"doc-envelope FFI (ec_* symbols, free via capability_scoring "
"cs_free_string — no free re-export); ec_loader mirroring "
"broker_loader.py; facade keeps the Python floor, RUNE_EC_CORE="
"python pin; frozen-oracle battery (every branch: empty/full/"
"over-full per slot, exact boundary fills, explicit empties, "
"missing-key size/unpack) on the SHARED freeze_truth harness "
"(kwargs envelope — --verify byte-identical); live parity 100% "
"(delegation-live vs python-pin); Phase B language-advantage pass "
"(single-pass truncation count).",
origin="builder",
)
print("submit_need:", json.dumps(r)[:200])
if not r.get("success"):
sys.exit(1)
cid = r["ids"]["contract_id"]
print("contract_id:", cid)
for phase in ("approved", "building", "verifying"):
t = iface.transition(cid, phase)
if not t.get("success"):
print(f"transition->{phase} FAILED:", json.dumps(t)[:300])
sys.exit(1)
print("walked to verifying")
c = iface.close(cid, observed_evidence=[{
"kind": "port_evidence",
"detail": (
f"evidence_capsule RUST dichotomy completion — parity commit {PARITY_SHA}, "
f"Phase B commit {PHASEB_SHA}"
+ (f", frozen-truth harness-compliance fix {TRUTHFIX_SHA}" if TRUTHFIX_SHA else "")
+ "; kernel surface pack/size/unpack 3/3 ported (module-level 3/4: `_core` "
"is the strangler loader glue — stays Python per FFI-machinery doctrine, "
"fleet precedent concept_topology FULL with `_core` unmatched); "
"frozen-truth battery replays the 16-case envelope VERBATIM "
"(src/rust/evidence_capsule/frozen_ec_truth.json, regenerated via the "
"shared harness, RUNE_EC_CORE=python pinned, deep-copied inputs); "
"freeze_truth.py --verify byte-identical against the live oracle; "
"live parity delegation-live (Rust .so) == python-pin on all 16 truth "
"inputs; pytest 26 passed both pins (tests/test_adapt_quartet.py + "
"tests/test_orchestration_records.py); cargo build + clippy -D warnings "
"clean. Documented divergence: none behavioral; the truth-file reshape "
"fixed a verification gap (per-module kwargs-in-args shape the shared "
"--verify could not replay)."
),
}], scope_files=[
"src/rune/evidence_capsule.py",
"src/rune/ec_loader.py",
"src/rust/evidence_capsule/Cargo.toml",
"src/rust/evidence_capsule/Cargo.lock",
"src/rust/evidence_capsule/src/lib.rs",
"src/rust/evidence_capsule/src/branch_battery.rs",
"src/rust/evidence_capsule/frozen_ec_truth.json",
"scripts/gen_evidence_capsule_truth.py",
"scripts/walk_contract_evidence_capsule.py",
"scripts/close_contract_evidence_capsule.py",
])
print("close:", json.dumps(c)[:300])
print("CONTRACT", cid, "closed" if c.get("success") else "CLOSE_FAILED")
+75
View File
@@ -0,0 +1,75 @@
#!/usr/bin/env python3
"""Close the #2479 dichotomy-wave gap-closing construction contract for
capability_broker with SHA evidence (opener: open_contract_gap_cb.py).
One process: building -> verifying -> closed (shared-store clobber
hazard law). CS_RUST_LIB must point at a BUILT capability_scoring .so."""
import json
import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "src"))
FEAT_SHA = sys.argv[1] if len(sys.argv) > 1 else ""
PHASEB_SHA = sys.argv[2] if len(sys.argv) > 2 else ""
if not (FEAT_SHA and PHASEB_SHA):
sys.exit("usage: close_contract_gap_cb.py <feat_sha> <phaseb_sha>")
from rune.construction_interface import ConstructionInterface
cid = "BUILDER-2026-10-13T16:01:25Z-9b9389-factory-gap-cb"
iface = ConstructionInterface(builder="factory-gap-cb")
t = iface.transition(cid, "verifying")
print("transition->verifying:", json.dumps(t)[:300])
if not t.get("success"):
sys.exit(1)
c = iface.close(cid, observed_evidence=[{
"kind": "port_evidence",
"detail": (
f"capability_broker dichotomy gap-close — feat commit {FEAT_SHA}, "
f"Phase B commit {PHASEB_SHA}, both verified as gitea/master "
"ancestors. Module audit 10/19 PARTIAL -> 19/19 FULL "
"(missing list empty). The 10 audit-missing fns ported "
"name-preserving into src/rust/capability_broker/src/gap.rs "
"(_native_tool_schemas, load_registry, _cards_are_stale, "
"load_cards, generate_card, build_cards, _cs_core, "
"_py_score_card, match_capabilities, handle_hook) with cb_* "
"doc-envelope FFI, ctypes loader bindings, facade delegation "
"under RUNE_CAPABILITY_BROKER_CORE. Frozen-truth battery "
"(gap_battery.rs) replays the 33-case shared-harness corpus "
"VERBATIM (include_str!) — 11/0 green; freeze_truth.py --verify "
"33 cases byte-identical against the live oracle (fixture-pinned "
"standalone + self-verifying regen); live parity 468/468 "
"(frozen=33 fuzz=421 live=14) = 100% on the gap fns; clippy "
"-D warnings clean; adjacent pytest 107/107 BOTH pins; full "
"suite both pins zero-delta vs the 118-failure master baseline. "
"Evidence: verification/cb-*.{log,exit} + cb-summary.md "
"(committed with the Phase B). Phase B advantages: trait CbIo "
"IO injection, Result error paths, exhaustive handle_hook "
"match, zero-copy static tables, in-process Rust-to-Rust cs "
"kernel delegation. Adjacent fix-first with proof: "
"tests/test_connection_pool.py evict-oldest flag normalized to "
"basenames (raw tempdir-path substring flake, ~17% isolated; "
"fd74311b-class instrument bug, not a port regression)."
),
}], scope_files=[
"src/rust/capability_broker/src/gap.rs",
"src/rust/capability_broker/src/gap_battery.rs",
"src/rust/capability_broker/src/lib.rs",
"src/rust/capability_broker/src/broker.rs",
"src/rust/capability_broker/frozen_gap_truth.json",
"src/rune/broker_loader.py",
"src/rune/capability_broker.py",
"scripts/gen_capability_broker_gap_truth.py",
"scripts/check_capability_broker_gap_parity.py",
"scripts/open_contract_gap_cb.py",
"scripts/close_contract_gap_cb.py",
"tests/test_capability_broker_delegation.py",
"tests/test_p1_01_capability_authority.py",
"tests/test_connection_pool.py",
"verification/cb-summary.md",
])
print("close:", json.dumps(c)[:300])
print("CONTRACT", cid, "closed" if c.get("success") else "CLOSE_FAILED")
sys.exit(0 if c.get("success") else 1)
+73
View File
@@ -0,0 +1,73 @@
#!/usr/bin/env python3
"""Close the #2479 dichotomy-wave layout_contract gap contract (Rust port).
Full lifecycle walk in ONE process (shared-store clobber hazard; segment
transitions take ~60s each — do NOT split across processes). Carries the
already-pushed parity SHA as evidence:
feat 9ed9a7a2 close PARTIAL gaps — dichotomy wave-5
Usage: close_contract_layout_contract.py
"""
import json
import os
import sys
from pathlib import Path
os.environ.setdefault(
"CS_RUST_LIB",
"/mnt/workdrive/rune/src/rust/capability_scoring/target/release/libcapability_scoring.so",
)
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "src"))
from rune.construction_interface import ConstructionInterface
PARITY_SHA = "9ed9a7a2"
EVIDENCE = f"parity {PARITY_SHA}"
iface = ConstructionInterface(builder="factory-gap-lc")
r = iface.submit_need(
"layout_contract dichotomy gap-close (Rust): name-preserving port "
"of the 4 audit-missing functions (define_region, bind_component, "
"amend_layout_contract, record_layout_observation) into "
"src/rust/layout_contract/src/kernels.rs as pure doc-in/doc-out "
"kernels (now is an argument; structural_store merge law "
"replicated), FFI lc_define_region/lc_bind_component/"
"lc_amend_layout_contract/lc_record_observation + lc_replay, facade "
"delegation with ValueError translation and identity-preserving "
"absorb, freeze rig scripts/lc_freeze_seams (blanket + EXPLICIT "
"core pins, frozen clock on both now seams, doc-carrying wrappers), "
"35-case frozen corpus frozen_lc_gap_truth.json via the shared "
"harness verified byte-identical, gap_battery 10/10 (verbatim "
"replay + FFI roundtrip + branch proofs), clippy -D warnings clean, "
"live parity 35/35 + byte-identical re-freeze "
"(scripts/check_layout_contract_parity.py), layout+consumer tests "
"64/64 BOTH pins. Ladder caught and fixed 4 real divergences "
"pre-commit: re-bind assigns a fresh amendments ledger; identities "
"merge is wholesale key assignment (add_entity .update() law); "
"framework detail rides **framework_attrs (no named param); "
"serde_json preserve_order for insertion-order stability. Dichotomy "
"audit 2/6 PARTIAL -> 6/6 FULL (RUST). Delivered on gitea/master: "
"feat " + PARITY_SHA + ".",
origin="builder",
)
print("submit_need:", json.dumps(r)[:300])
if not r.get("success"):
print("NEED FAILED — aborting")
sys.exit(1)
c = r["ids"]["contract_id"]
print("contract_id:", c)
for phase in ("approved", "building", "verifying", "closed"):
t = iface.transition(c, phase, evidence_ref=EVIDENCE)
ok = t.get("success")
print(f"transition->{phase}:", "ok" if ok else json.dumps(t)[:300])
if not ok:
sys.exit(1)
doc = iface.scaffold.load()
e = iface.scaffold.contract(doc, c)
print("FINAL PHASE:", e.get("phase") if e else "MISSING")
if not e or e.get("phase") != "closed":
sys.exit(1)
print("CLOSED", c)
+120
View File
@@ -0,0 +1,120 @@
#!/usr/bin/env python3
"""Close the #2479 dichotomy-wave microkernel gap contract (GO port).
Full lifecycle walk in ONE process (shared-store clobber hazard — do NOT
split across processes; re-walk on a fresh post-rebase store per the
segment-architecture conflict pattern). The QUALITY-GATE LAW (scaffold.py
2026-10-13) requires the designed close() entry (predicted-vs-observed
quality + material-change) rather than a raw transition to 'closed'.
Carries the already-pushed SHAs:
feat 3a1b9e54 close PARTIAL gaps — dichotomy wave
chore da9e15e9 regenerate audit — microkernel FULL
Usage: close_contract_microkernel.py
"""
import json
import os
import sys
from pathlib import Path
os.environ.setdefault(
"CS_RUST_LIB",
"/mnt/workdrive/rune/src/rust/research_budget/target/release/deps/libcapability_scoring.so",
)
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "src"))
from rune.construction_interface import ConstructionInterface
PARITY_SHA = "3a1b9e54"
AUDIT_SHA = "da9e15e9"
EVIDENCE = f"parity {PARITY_SHA}; audit {AUDIT_SHA}"
DETAIL = (
f"microkernel GO dichotomy gap-close — parity commit {PARITY_SHA}, "
f"audit commit {AUDIT_SHA}; dichotomy audit fn coverage 6/12 "
"PARTIAL -> 12/12 FULL. Ported name-preserving into "
"src/go/microkernel: NowIso (+nowFunc clock seam, Python "
"isoformat timespec=seconds +00:00 shape), ExtractManifest "
"(brace-counted PLUGIN block + ast.literal_eval-subset parser: "
"dicts/lists/tuples/strings-with-escapes/ints/floats/True/False/"
"None, comments, trailing commas, unicode, rune-safe truncation), "
"Discover (self-registration sweep, sorted listing), RunHook "
"(subprocess hook runner: skipped / file-not-found / ok-JSON / "
"raw-stdout-[:500] / rc-error stderr-[:200] / timeout, banker's-"
"rounded durations), Fire (8-way parallel dispatch + bounded "
"fire-log, CLI fire case rewired off the old fake), "
"LoadRegistry/SaveRegistry (renamed from lowercase; corrupt-file "
"full-default parity, log normalized to []). Register fixes proven "
"vs oracle: Python truthiness for hook values (string targets "
"index — real PLUGIN dicts use them) and auto_activate, _file "
"plumbed into entries. Frozen truth via the shared "
"scripts/freeze_truth.py harness (generator "
"scripts/gen_microkernel_gap_truth.py, aware-clock pin — fire() "
"mixes naive/aware datetime.now()): 25-case envelope regen-stable, "
"--verify byte-identical x2; Go battery 25/25 subtests "
"(truth_microkernel_gap_test.go), -race clean; live oracle-vs-Go "
"parity 24/24 (scripts/check_microkernel_parity.py, parity op mode "
"in parity.go); gofmt/vet/go build ./... clean; Python both-pins "
"green for the module (18 test_p1_01 failures proven pre-existing "
"on stashed base). Six representation-level divergences documented "
"(listing order, non-dict PLUGIN crash class, --data separators, "
"partial-registry crash class, integral-float rendering, typed-"
"struct persistence). Evidence read back: verification/"
"summary-microkernel.md + verification/microkernel-"
"{truth,goladder,live-parity,pytest-*,audit}.exit"
)
iface = ConstructionInterface(builder="factory-gap-mk")
r = iface.submit_need(
"microkernel dichotomy gap-close (GO): name-preserving port of the 6 "
"unmatched fns (now_iso, discover, _extract_manifest, _load_registry, "
"_save_registry, _run_hook) into src/go/microkernel, plus Fire wiring "
"the CLI fire case to real 8-way parallel subprocess dispatch with the "
"bounded fire-log, and Register fixes (Python truthiness for hook "
"values, _file plumbing). Frozen-truth battery 25/25, live parity "
"24/24, gofmt/vet/build clean, Python both-pins green (18 test_p1_01 "
"failures proven pre-existing). Audit: microkernel 6/12 PARTIAL -> "
"12/12 FULL. Delivered on gitea/master: feat " + PARITY_SHA + ", "
"audit " + AUDIT_SHA + ".",
origin="builder",
)
print("submit_need:", json.dumps(r)[:300])
if not r.get("success"):
print("NEED FAILED — aborting")
sys.exit(1)
c = r["ids"]["contract_id"]
print("contract_id:", c)
for phase in ("approved", "building", "verifying"):
t = iface.transition(c, phase, evidence_ref=EVIDENCE)
ok = t.get("success")
print(f"transition->{phase}:", "ok" if ok else json.dumps(t)[:300])
if not ok:
sys.exit(1)
closed = iface.close(
c,
observed_evidence=[{"kind": "port_evidence", "detail": DETAIL}],
scope_files=[
"src/go/microkernel/main.go",
"src/go/microkernel/microkernel.go",
"src/go/microkernel/parity.go",
"src/go/microkernel/truth_microkernel.json",
"src/go/microkernel/truth_microkernel_test.go",
"src/go/microkernel/truth_microkernel_gap.json",
"src/go/microkernel/truth_microkernel_gap_test.go",
"scripts/gen_microkernel_gap_truth.py",
"scripts/check_microkernel_parity.py",
"scripts/close_contract_microkernel.py",
"verification/summary-microkernel.md",
],
)
print("close:", json.dumps(closed)[:400])
doc = iface.scaffold.load()
e = iface.scaffold.contract(doc, c)
print("FINAL PHASE:", e.get("phase") if e else "MISSING")
if not closed.get("success") or not e or e.get("phase") != "closed":
sys.exit(1)
print("CLOSED", c)
+69
View File
@@ -0,0 +1,69 @@
#!/usr/bin/env python3
"""Close the #2479 dichotomy-wave model_connect gap contract (GO port).
Full lifecycle walk in ONE process (shared-store clobber hazard; segment
transitions take ~60s each — do NOT split across processes). Carries the
already-pushed parity SHA as evidence:
feat 1f2fe468 close PARTIAL gaps — dichotomy wave (7/11 -> 11/11)
Usage: close_contract_model_connect.py
"""
import json
import os
import sys
from pathlib import Path
os.environ.setdefault(
"CS_RUST_LIB",
"/mnt/workdrive/rune/src/rust/capability_scoring/target/release/libcapability_scoring.so",
)
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "src"))
from rune.construction_interface import ConstructionInterface
PARITY_SHA = "1f2fe468"
EVIDENCE = f"parity {PARITY_SHA}"
iface = ConstructionInterface(builder="factory-gap-mconn")
r = iface.submit_need(
"model_connect dichotomy gap-close (GO): name-preserving port of "
"the 4 audit-missing functions (_ctx_budget, _now, "
"_get_cloud_models, handle_hook) into src/go/model-connect as "
"CtxBudget / Now / GetCloudModels / HandleHook, wall clock behind "
"the injectable MCONN_CLOCK seam, hermetic HOME via "
"scripts/mconn_freeze_seams, frozen-truth battery (truth.json, "
"40-case envelope) generated against the live Python oracle and "
"verified byte-identical via freeze_truth.py, embedded VERBATIM in "
"truth_test.go TestFrozenTruthReplay (3/3); CI replay binary 40/40; "
"live parity sweep 44/44 "
"(scripts/check_model_connect_parity.py), gofmt/vet/go build clean, "
"Python oracle smoke green both pins. Oracle quirks preserved and "
"frozen: string-blind JSONC // strip (URL corruption -> []), "
"partial cloud list on mid-provider shape errors, "
"insertion-order provider/model iteration, live model_registry "
"constants (OUTPUT_RESERVE default 2048 / TOOL_RESULT_RESERVE "
"1024). Dichotomy audit 7/11 PARTIAL -> 11/11 FULL. Delivered on "
"gitea/master: feat " + PARITY_SHA + ".",
origin="builder",
)
print("submit_need:", json.dumps(r)[:300])
if not r.get("success"):
print("NEED FAILED — aborting")
sys.exit(1)
c = r["ids"]["contract_id"]
print("contract_id:", c)
for phase in ("approved", "building", "verifying", "closed"):
t = iface.transition(c, phase, evidence_ref=EVIDENCE)
ok = t.get("success")
print(f"transition->{phase}:", "ok" if ok else json.dumps(t)[:300])
if not ok:
sys.exit(1)
doc = iface.scaffold.load()
e = iface.scaffold.contract(doc, c)
print("FINAL PHASE:", e.get("phase") if e else "MISSING")
if not e or e.get("phase") != "closed":
sys.exit(1)
print("CLOSED", c)
+107
View File
@@ -0,0 +1,107 @@
#!/usr/bin/env python3
"""Close the #2479 dichotomy-wave model_registry gap contract (GO port).
Full lifecycle walk in ONE process (shared-store clobber hazard; segment
transitions take ~60s each — do NOT split across processes). Carries the
already-pushed parity SHA as evidence:
feat 67972c8e close PARTIAL gaps — dichotomy wave (2/8 -> 8/8)
Usage: close_contract_model_registry.py
"""
import json
import os
import sys
from pathlib import Path
os.environ.setdefault(
"CS_RUST_LIB",
"/mnt/workdrive/rune/src/rust/capability_scoring/target/release/libcapability_scoring.so",
)
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "src"))
from rune.construction_interface import ConstructionInterface
PARITY_SHA = "67972c8e"
EVIDENCE = f"parity {PARITY_SHA}; no Phase B (two-commit flow: parity + store close)"
iface = ConstructionInterface(builder="factory-gap-mreg")
r = iface.submit_need(
"model_registry dichotomy gap-close (GO): name-preserving port of the 6 "
"audit-missing functions (to_dict, get_profile, get_enabled_profiles, "
"get_profiles_by_tier, list_profiles, test_registry) into "
"src/go/model-registry alongside the existing "
"get_cheapest_capable/resolve_context_budget surface, and the "
"VERIFY+FIX of the known flag: batch-67 hardcoded toolReserve=2048 "
"where the live oracle holds TOOL_RESULT_RESERVE=1024, plus the "
"missing OUTPUT_RESERVE per-task-kind ladder {default 2048, verify "
"512, summarize 1024, embed 0} (local-gated, never tier-gated; the "
"legacy truth rows were blind — both local). Insertion-order laws "
"pinned in truth: dict-key get_profile vs tier-attr "
"get_profiles_by_tier, first-id-match resolve, STABLE tie sort, "
"constructor falsy->DEFAULT_PROFILES law, `(reg.profiles or {})` "
"empty branch via a __new__ seam. Frozen-truth battery "
"(truth_gap.json, 35 cases / 10 wrapper seams) via the shared "
"harness + scripts/mreg_freeze_seams — byte-identical --verify AND "
"fresh re-freeze. gofmt/vet/go build clean; go tests 4/4; binary "
"replay-gap 35/35 + legacy replay 4/4; live parity 4/4 scenarios "
"(36 ops; scripts/check_model_registry_parity.py); Python suite "
"green both pins + oracle CLI smoke (no loader seam exists — pin "
"vacuous, documented). dichotomy audit model_registry 2/8 PARTIAL -> "
"8/8 FULL. Delivered on gitea/master: feat " + PARITY_SHA + ".",
origin="builder",
)
print("submit_need:", json.dumps(r)[:300])
if not r.get("success"):
print("NEED FAILED — aborting")
sys.exit(1)
c = r["ids"]["contract_id"]
print("contract_id:", c)
for phase in ("approved", "building", "verifying"):
t = iface.transition(c, phase, evidence_ref=EVIDENCE)
ok = t.get("success")
print(f"transition->{phase}:", "ok" if ok else json.dumps(t)[:300])
if not ok:
sys.exit(1)
cres = iface.close(c, observed_evidence=[{
"kind": "port_evidence",
"detail": (
f"model_registry GO dichotomy gap-close — parity commit "
f"{PARITY_SHA} (no Phase B); dichotomy audit fn coverage 2/8 "
f"PARTIAL -> 8/8 FULL (missing list emptied; programme FULL 55% "
f"-> 56% at close, 107/192). KNOWN FLAG verified+fixed: "
f"batch-67 toolReserve=2048 vs live oracle "
f"TOOL_RESULT_RESERVE=1024 + OUTPUT_RESERVE task-kind ladder "
f"(pinned by TestReserveConstants + frozen "
f"resolve('mimo-v2.5-pro', kind) rows: 124928/125952/126976). "
f"35-case frozen gap truth (scripts/gen_model_registry_gap_"
f"truth.py + scripts/mreg_freeze_seams — byte-identical --verify "
f"AND fresh re-freeze), go tests 4/4, binary replay-gap 35/35 + "
f"legacy replay 4/4, gofmt/vet/build clean, live parity 4/4 "
f"scenarios (36 ops oracle-vs-GO identical via "
f"scripts/check_model_registry_parity.py), Python suite 5/5 "
f"both pins + oracle CLI smoke. Evidence: verification/mreg-* "
f"(exit codes + summary committed; .log gitignored)."
),
}], scope_files=[
"src/rune/model_registry.py",
"src/go/model-registry/main.go",
"src/go/model-registry/gap.go",
"src/go/model-registry/truth_gap.json",
"src/go/model-registry/truth_gap_test.go",
"scripts/gen_model_registry_gap_truth.py",
"scripts/check_model_registry_parity.py",
"scripts/mreg_freeze_seams/sitecustomize.py",
])
print("close:", json.dumps(cres)[:300])
if not cres.get("success"):
sys.exit(1)
doc = iface.scaffold.load()
e = iface.scaffold.contract(doc, c)
print("FINAL PHASE:", e.get("phase") if e else "MISSING")
if not e or e.get("phase") != "closed":
sys.exit(1)
print("CLOSED", c)
@@ -0,0 +1,132 @@
#!/usr/bin/env python3
"""Close the #2479 dichotomy-wave parallel_processor gap contract (GO port).
Full lifecycle walk in ONE process (shared-store clobber hazard; segment
transitions take ~60s each — do NOT split across processes). The final
step is iface.close() with contract_quality observed_evidence (the
bare `transition -> closed` is rejected by the quality gate). Safe to
re-run: pass the existing contract id to resume an interrupted walk.
Carries the already-pushed parity SHA as evidence:
feat 16a2aa20 close PARTIAL gaps — dichotomy wave (3/14 -> 14/14)
Usage: close_contract_parallel_processor.py [contract_id]
"""
import json
import os
import sys
from pathlib import Path
os.environ.setdefault(
"CS_RUST_LIB",
"/mnt/workdrive/rune/src/rust/capability_scoring/target/release/libcapability_scoring.so",
)
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "src"))
from rune.construction_interface import ConstructionInterface
PARITY_SHA = "16a2aa20"
EVIDENCE = f"parity {PARITY_SHA}"
NEED = (
"parallel_processor dichotomy gap-close (GO): name-preserving port of "
"the 11 audit-missing functions (run_parallel class+module, "
"run_parallel_with_args, get_status, shutdown, _shutdown_processor, "
"get_processor, test_parallel + nested task_1/2/3, main CLI mirror) "
"into src/go/parallel-processor (RunParallelWithArgs, GetStatus, "
"Shutdown, ShutdownProcessor, GetProcessor, TestParallel with "
"task_1/2/3 closures), semaphore-bounded goroutine pool preserving "
"submission order, frozen-truth battery (truth.json, 23-case "
"envelope via the shared freeze_truth.py harness + "
"scripts/pp_freeze_seams rig: kind/fn/value SPEC grammar so "
"callables ride JSON rows, threading.active_count pinned) verified "
"byte-identical twice, embedded VERBATIM in truth_test.go "
"TestFrozenTruthReplay (5/5); CI replay binary PARITY OK 23/23; live "
"parity sweep 19/19 (scripts/check_parallel_processor_parity.py: 15 "
"op families + 4 CLI checks), gofmt/vet/go build clean, Python "
"oracle smoke green both pins. Oracle quirks preserved and frozen: "
"submit-after-shutdown raises from the submit loop (crash parity "
"panic 'cannot schedule new futures after shutdown'), "
"ParallelProcessor(0) 'max_workers must be greater than 0', Python "
"type-name TypeError envelopes for non-callables, with-args parse "
"errors with type(task).__name__ and repr shapes, non-seq args "
"wrapped, non-dict kwargs reset, pool_threads = configured bound. "
"Dichotomy audit 3/14 PARTIAL -> 14/14 FULL. Delivered on "
"gitea/master: feat " + PARITY_SHA + "."
)
iface = ConstructionInterface(builder="factory-gap-pp")
if len(sys.argv) > 1:
cid = sys.argv[1]
print("resuming contract:", cid)
else:
r = iface.submit_need(NEED, origin="builder")
print("submit_need:", json.dumps(r)[:300])
if not r.get("success"):
print("NEED FAILED — aborting")
sys.exit(1)
cid = r["ids"]["contract_id"]
print("contract_id:", cid)
def phase_of(cid):
doc = iface.scaffold.load()
e = iface.scaffold.contract(doc, cid)
return e.get("phase") if e else "MISSING"
phase = phase_of(cid)
print("current phase:", phase)
for want in ("approved", "building", "verifying"):
if phase == want or phase in ("verifying", "closed"):
break
t = iface.transition(cid, want, evidence_ref=EVIDENCE)
ok = t.get("success")
print(f"transition->{want}:", "ok" if ok else json.dumps(t)[:300])
if not ok:
sys.exit(1)
phase = want
c = iface.close(
cid,
observed_evidence=[{
"kind": "port_evidence",
"detail": "parallel_processor dichotomy completion — parity "
f"{PARITY_SHA} feat(parallel_processor): close PARTIAL "
"gaps — dichotomy wave; pushed gitea/master. Go port at "
"src/go/parallel-processor closes the audit gaps "
"name-preserving (RunParallel/RunParallelWithArgs class+"
"module, GetStatus, Shutdown, ShutdownProcessor, "
"GetProcessor, TestParallel with task_1/2/3, oracle-"
"mirroring main CLI) over a semaphore-bounded goroutine "
"pool. Freeze rig scripts/pp_freeze_seams + generator "
"scripts/gen_parallel_processor_truth.py: 23-case frozen "
"truth regenerates byte-identical; freeze_truth --verify "
"OK twice against the live oracle. Battery 5/5 replay "
"VERBATIM (23/23 rows); replay binary PARITY OK 23/23; "
"live parity scripts/check_parallel_processor_parity.py "
"19/19 (15 op families + 4 CLI checks); gofmt/vet/build "
"clean; Python oracle smoke both pins. Audit 3/14 → "
"14/14 FULL. Divergences (documented): none — "
"nondeterministic surfaces (active_threads, timing "
"report lines) are pinned/verified structurally by "
"design, not divergences.",
}],
scope_files=[
"src/go/parallel-processor/parallel_processor.go",
"src/go/parallel-processor/replay.go",
"src/go/parallel-processor/main.go",
"src/go/parallel-processor/truth_test.go",
"src/go/parallel-processor/truth.json",
"scripts/pp_freeze_seams/sitecustomize.py",
"scripts/gen_parallel_processor_truth.py",
"scripts/check_parallel_processor_parity.py",
],
)
print("close:", json.dumps(c)[:400])
final = phase_of(cid)
print("FINAL PHASE:", final)
ok = c.get("success") and final == "closed"
print("CLOSED" if ok else "CLOSE_FAILED", cid)
sys.exit(0 if ok else 1)
+135
View File
@@ -0,0 +1,135 @@
#!/usr/bin/env python3
"""Close the #2479 dichotomy-wave provider_registry gap contract (GO port).
Full lifecycle walk in ONE process (shared-store clobber hazard; segment
transitions can take ~60s each — do NOT split across processes). Carries
the already-pushed SHAs as evidence:
feat 3422130d close PARTIAL gaps — dichotomy wave (parity + defect fixes)
phaseB 9954e34a Phase B language-advantage pass — dichotomy wave
QUALITY-GATE LAW (16c5f22a): final entry is close() (predicted-vs-observed
contract_quality), not a raw transition to closed.
Usage: close_contract_provider_registry.py
"""
import json
import os
import sys
from pathlib import Path
os.environ.setdefault(
"CS_RUST_LIB",
"/mnt/workdrive/rune/src/rust/capability_scoring/target/release/libcapability_scoring.so",
)
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "src"))
from rune.construction_interface import ConstructionInterface
PARITY_SHA = "3422130d"
PHASE_B_SHA = "9954e34a"
EVIDENCE = f"parity {PARITY_SHA}, phase B {PHASE_B_SHA}"
iface = ConstructionInterface(builder="factory-gap-pr")
r = iface.submit_need(
"provider_registry dichotomy gap-close (GO): name-preserving port of "
"the 17 audit-missing functions (_load_config, _save_config, connect, "
"disconnect, list_providers, get_provider, list_models, _fetch_models, "
"_fetch_ollama_models, _fetch_openai_models, _fetch_anthropic_models, "
"_clean_model_name, generate, _generate_ollama, _generate_openai, "
"_generate_anthropic, _format_tools_openai, _execute_tool_calls, "
"_execute_tool_calls_anthropic, get_registry, connect_provider, "
"list_all_models, _ctx_budget) into src/go/provider-registry "
"(registry.go, toolcalls.go, chat.go, pyjson.go), with the "
"python-parity JSON layer (PyDict insertion-order semantics, "
"json.dumps separators/ensure_ascii) and network behind the "
"injectable Do seam. Truth batteries frozen from the live oracle and "
"verified byte-identical via freeze_truth.py (truth.json, 19 cases) "
"and scripts/gen_provider_registry_truth.py --check "
"(truth_registry.json, 44 scenarios: config load/save/mask, connect/"
"disconnect, list_models orchestration incl. fetch-error degrade, "
"fetch dispatch, clean_model_name, generate branches with scripted "
"HTTP, ctx budget); embedded VERBATIM in truth_test.go + "
"truth_registry_test.go. gofmt/vet/go build clean; go test green "
"under -race; Python oracle tests 8/8 both pins (live and "
"RUNE_PROVIDER_REGISTRY_CORE=python). Defect fixes found by parity: "
"oracle _execute_tool_calls/_execute_tool_calls_anthropic crashed on "
"non-JSON-serializable tool results — now degrade to an error-marker "
"message (parity with the Go port's degradation). Phase B ("
+ PHASE_B_SHA + "): concurrent ListModels/ListAllModels — goroutine "
"fan-out per enabled provider with deterministic registry-order "
"assembly (byte-identical output, mutex-guarded test capture seam, "
"race-detector clean). Dichotomy audit 11/28 PARTIAL -> 28/28 FULL. "
"Delivered on gitea/master: feat " + PARITY_SHA + ", phase B "
+ PHASE_B_SHA + ".",
origin="builder",
)
print("submit_need:", json.dumps(r)[:300])
if not r.get("success"):
print("NEED FAILED — aborting")
sys.exit(1)
c = r["ids"]["contract_id"]
print("contract_id:", c)
for phase in ("approved", "building", "verifying"):
t = iface.transition(c, phase, evidence_ref=EVIDENCE)
ok = t.get("success")
print(f"transition->{phase}:", "ok" if ok else json.dumps(t)[:300])
if not ok:
sys.exit(1)
cl = iface.close(
c,
observed_evidence=[
{
"kind": "port_evidence",
"detail": "provider_registry dichotomy completion — feat "
+ PARITY_SHA
+ " 'feat(provider_registry): close PARTIAL gaps — "
"dichotomy wave' + phase B " + PHASE_B_SHA
+ " 'refactor(provider_registry): Phase B "
"language-advantage pass — dichotomy wave', both "
"pushed gitea/master. Audit PARTIAL 11/28 -> FULL "
"28/28 (GO; headline FULL 88/192 after rebase "
"merge, fn 1500/2278). Verification all exit 0 "
"(verification/pr-*.exit): gofmt/vet/go build "
"clean; go test green incl. -race (previously-"
"failing subtests _fetch_anthropic_models/"
"static_list + _fetch_models/dispatch_anthropic "
"PASS); freeze_truth --verify 19/19 byte-identical; "
"gen_provider_registry_truth.py --check 44/44 "
"byte-identical; pytest 8/8 both pins (live + "
"RUNE_PROVIDER_REGISTRY_CORE=python). Zero "
"regressions.",
},
],
scope_files=[
"src/rune/provider_registry.py",
"src/go/provider-registry/format.go",
"src/go/provider-registry/main.go",
"src/go/provider-registry/registry.go",
"src/go/provider-registry/toolcalls.go",
"src/go/provider-registry/chat.go",
"src/go/provider-registry/pyjson.go",
"src/go/provider-registry/truth.json",
"src/go/provider-registry/truth_registry.json",
"src/go/provider-registry/truth_test.go",
"src/go/provider-registry/truth_registry_test.go",
"src/go/provider-registry/truth_format_test.go",
"scripts/gen_provider_registry_truth.py",
"docs/dichotomy-rebase-honest-audit.md",
],
)
print("close:", json.dumps(cl)[:300])
if not cl.get("success"):
print("CLOSE FAILED")
sys.exit(1)
doc = iface.scaffold.load()
e = iface.scaffold.contract(doc, c)
print("FINAL PHASE:", e.get("phase") if e else "MISSING")
q = (e or {}).get("ext", {}).get("contract_quality")
print("CONTRACT_QUALITY:", json.dumps(q)[:200] if q else "MISSING")
if not e or e.get("phase") != "closed":
sys.exit(1)
print("CLOSED", c)
+90
View File
@@ -0,0 +1,90 @@
#!/usr/bin/env python3
"""Close the #2479 dichotomy-wave salience_gate gap contract (RUST port).
Full lifecycle walk in ONE process (shared-store clobber hazard; segment
transitions can take ~60s each — do NOT split across processes). Carries
the already-pushed parity SHAs as evidence:
feat 9539d5b6 close PARTIAL gaps — dichotomy wave
phaseB 2350e02e Phase B language-advantage pass — dichotomy wave
Usage: close_contract_salience_gate.py
"""
import json
import os
import sys
from pathlib import Path
os.environ.setdefault(
"CS_RUST_LIB",
"/mnt/workdrive/rune/src/rust/capability_scoring/target/release/libcapability_scoring.so",
)
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "src"))
from rune.construction_interface import ConstructionInterface
PARITY_SHA = "9539d5b6"
PHASEB_SHA = "2350e02e"
EVIDENCE = f"parity {PARITY_SHA}, phase B {PHASEB_SHA}"
iface = ConstructionInterface(builder="factory-gap-sg")
r = iface.submit_need(
"salience_gate dichotomy gap-close (RUST): name-preserving port of the "
"4 audit-missing functions into src/rust/salience_gate (the module's "
"existing delegation side — classification side=RUST; no Go "
"salience-gate dir exists): _sg_core (kernel mirror of the facade "
"availability probe, pin lattice), to_dict (SalienceDecision struct + "
"projection, evaluate_salience flows through it), handle_hook (event "
"echo, data accepted+ignored), test_salience (embedded oracle smoke, "
"print-byte-matched), plus oracle-level evaluate_salience_dict JSON "
"view (shared freeze harness cannot serialize the dataclass return — "
"construction_decision normalize_need_json precedent). Dichotomy audit "
"1/5 PARTIAL -> 6/6 FULL. Three parity defects fixed (frozen-truth "
"battery caught all): novel-family single-append (oracle guards ONE "
"if; duplicate append inflated witness rule), failure-family "
"doesn't-work/not-working arm omitted, word_boundary_contains Python-"
"\\b parity (alphanumeric + underscore + UTF-8 continuation bytes). "
"Frozen truth via shared harness scripts/freeze_truth.py: "
"frozen_sg_truth.verify.json 52 rows byte-identical under "
"freeze_truth.py --verify in BOTH core states (floor SG_RUST_LIB-"
"poisoned AND kernel-built); frozen_sg_truth.json 63-row envelope "
"(multi-family evaluation-order rows + _sg_core row — the shared "
"gate's RUNE_SALIENCE_GATE_CORE pin cannot reach this oracle). "
"branch_battery.rs replays both verbatim via include_str (12 tests); "
"poisoned-truth law: generator pins RUNE_SALIENCE_CORE=python AND "
"poisons SG_RUST_LIB (the module's real floor pins — the facade "
"evaluate path ignores RUNE_*_CORE). Live parity: gen "
"--replay facade live + kernel direct 119/119 (exact evaluation-order "
"kernel rows; facade rows under the oracle's declared sorted-"
"comparison contract); crate canary 6/6; oracle smoke green in 3 pin "
"states (live, probe-pinned, pure floor). Phase B (2350e02e): "
"ASCII-anchored Cow lowercase avoidance (zero-alloc common path, "
"Unicode mappings never skipped), std-only hot-path bench (ns/call "
"over the 56-envelope frozen corpus + ns/scan), #[must_use] pure "
"surface, idiomatic single-append family guards. rustfmt clean, "
"clippy -D warnings clean. Evidence: verification/salience-gate-*.log "
"(cargotest/clippy/freeze-verify/replay/canary/python-pins/goladder/"
"audit, all exit 0, Read back). Delivered on gitea/master: feat "
"9539d5b6, phase B 2350e02e.",
origin="builder",
)
print("submit_need:", json.dumps(r)[:300])
if not r.get("success"):
print("NEED FAILED — aborting")
sys.exit(1)
c = r["ids"]["contract_id"]
print("contract_id:", c)
for phase in ("approved", "building", "verifying", "closed"):
t = iface.transition(c, phase, evidence_ref=EVIDENCE)
ok = t.get("success")
print(f"transition->{phase}:", "ok" if ok else json.dumps(t)[:300])
if not ok:
sys.exit(1)
doc = iface.scaffold.load()
e = iface.scaffold.contract(doc, c)
print("FINAL PHASE:", e.get("phase") if e else "MISSING")
if not e or e.get("phase") != "closed":
sys.exit(1)
print("CLOSED", c)
+156
View File
@@ -0,0 +1,156 @@
#!/usr/bin/env python3
"""Close the #2479 dichotomy-wave stage_guards gap contract (GO port) in
ONE process (shared-store clobber hazard; segment transitions can take
~60s each — do NOT split across processes).
QUALITY-GATE LAW (scaffold.py, 2026-10-13): entering `closed` happens via
iface.close(contract_id, observed_evidence=..., scope_files=...) — the
predicted-vs-observed quality computation — never a raw transition.
Resumable: if open factory-gap-cz contracts already exist in the store
(e.g. a prior walk stopped at `verifying` because it attempted the raw
transition), the LATEST is resumed and duplicates are abandoned with a
note. Otherwise the canonical submit_need → approved → building →
verifying walk runs first.
Usage: close_contract_stage_guards.py
"""
import json
import os
import sys
from pathlib import Path
os.environ.setdefault(
"CS_RUST_LIB",
"/mnt/workdrive/rune/src/rust/capability_scoring/target/release/libcapability_scoring.so",
)
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "src"))
from rune.construction_interface import ConstructionInterface
from rune.scaffold import entity
PARITY_SHA = "5750a4b0"
EVIDENCE = f"parity {PARITY_SHA}"
NEED_TEXT = (
"stage_guards dichotomy gap-close (GO): name-preserving port of the 2 "
"audit-missing functions (StageContract.to_dict + nested chk) into "
"src/go/stage-guards as (*StageContract).ToDict / chk, plus "
"parity-driven defect fixes to the old-era port: exact oracle evidence "
"key sets (no omitempty zero-drops), Python f-string True/False "
"rationales, numeric half-even idle_secs via pyRound1 (was a %.1f "
"string), stdout-only pattern search + rune-safe [:100]/[-500:] "
"truncation, crash-parity messages (IndexError/ENOENT/NoneType, "
"StageBlocked/ExitCanaryFailed list-repr texts, FileNotFoundError on "
"bad cwd), oracle TestExpectations defaults, and Python == reconcile "
"semantics (True==1, want-null quirk, non-dict actual). Frozen-truth "
"battery: truth.json 40 cases via the shared freeze_truth.py harness "
"(recv form for first-arg dataclasses) + sg_seams.json 30 rig rows "
"(callables + TestExpectations), both byte-identical across gen x2 "
"and verify x2 and embedded VERBATIM in the Go battery; live parity "
"56/56 via scripts/check_stage_guards_parity.py (8 CLI subcommands "
"incl. exception-message and crash classes); gofmt/vet/go build "
"clean; Python oracle battery green both pins (16 passed x2); "
"kernel-vs-floor cross-check: frozen corpus fully stable (bool-vs-"
"number reconcile divergence documented, excluded by the stability "
"law). Harness _out recursion fix backward-compat-proven on witness "
"truth. Dichotomy audit 7/9 PARTIAL -> 9/9 FULL. Delivered on "
"gitea/master: feat " + PARITY_SHA + "."
)
OBSERVED_DETAIL = (
f"stage_guards GO dichotomy completion — parity commit {PARITY_SHA}; "
"fn coverage 7/9 PARTIAL -> 9/9 FULL (audit CURRENT instrument); "
"frozen truth 40 harness cases + 30 seam rows byte-identical across "
"gen x2 and rig --verify x2 (src/go/stage-guards/truth.json + "
"sg_seams.json, generated by scripts/gen_stage_guards_truth.py); "
"Go battery replays both files verbatim (truth_test.go, ok "
"rune/stage-guards); live parity 56/56 via "
"scripts/check_stage_guards_parity.py (to-dict/check/readiness/"
"execute/liveness/verify-tests/henxels-placement/reconcile incl. "
"StageBlocked/ExitCanaryFailed/FileNotFoundError crash classes); "
"gofmt + go vet + go build ./... clean; Python suite green both pins "
"(16 passed live + 16 passed RUNE_COGNITION_CORE=python, 2 cc skips "
"— no .so in worktree); kernel-vs-floor cross-check in the main "
"checkout: frozen corpus fully stable (verification/sg-kernel-"
"crosscheck.log). Documented divergences: Rust broker::reconcile "
"treats bool-vs-number as unequal while Python == reconciles (pinned "
"only through direct _py_reconcile rows; public-path corpora exclude "
"mixed types by the truth-stability law); Python re.error text vs "
"RE2 parse errors unfrozen; Go assert seam bool-typed. Evidence "
"files: verification/sg-*.{log,exit} + sg-summary.md."
)
SCOPE_FILES = [
"src/rune/stage_guards.py",
"src/go/stage-guards/go.mod",
"src/go/stage-guards/main.go",
"src/go/stage-guards/truth.json",
"src/go/stage-guards/sg_seams.json",
"src/go/stage-guards/truth_test.go",
"scripts/gen_stage_guards_truth.py",
"scripts/check_stage_guards_parity.py",
"scripts/freeze_truth.py",
"scripts/close_contract_stage_guards.py",
"docs/dichotomy-rebase-honest-audit.md",
]
iface = ConstructionInterface(builder="factory-gap-cz")
# ── resume-or-submit ────────────────────────────────────────────────────────
def _open_factory_gap_cz(d):
found = []
for ent in d.get("entities", []):
cid = ent.get("id", "")
if isinstance(cid, str) and cid.startswith("contract:BUILDER-") \
and cid.endswith("factory-gap-cz") \
and ent.get("phase") not in ("closed", "abandoned", "failed"):
found.append((cid[len("contract:"):], ent.get("phase")))
return sorted(found)
doc = iface.scaffold.load()
existing = _open_factory_gap_cz(doc)
if existing:
cid, phase = existing[-1] # latest wins
print(f"resuming contract {cid} (phase {phase}); "
f"{len(existing) - 1} duplicate(s) to abandon")
for dup_cid, _ in existing[:-1]:
r = iface.transition(dup_cid, "abandoned",
evidence_ref="duplicate submission — close walk "
"retried after a refused raw "
"closed transition (quality-gate law)")
print(f"abandoned {dup_cid}:", "ok" if r.get("success") else json.dumps(r)[:200])
if not r.get("success"):
sys.exit(1)
else:
r = iface.submit_need(NEED_TEXT, origin="builder")
print("submit_need:", json.dumps(r)[:300])
if not r.get("success"):
print("NEED FAILED — aborting")
sys.exit(1)
cid = r["ids"]["contract_id"]
print("contract_id:", cid)
for phase in ("approved", "building", "verifying"):
t = iface.transition(cid, phase, evidence_ref=EVIDENCE)
ok = t.get("success")
print(f"transition->{phase}:", "ok" if ok else json.dumps(t)[:300])
if not ok:
sys.exit(1)
# ── the designed entry to `closed`: close() computes contract_quality ──────
c = iface.close(cid, observed_evidence=[{
"kind": "port_evidence",
"detail": OBSERVED_DETAIL,
}], scope_files=SCOPE_FILES)
print("close:", json.dumps(c)[:300])
if not c.get("success"):
sys.exit(1)
doc = iface.scaffold.load()
e = iface.scaffold.contract(doc, cid)
print("FINAL PHASE:", e.get("phase") if e else "MISSING")
if not e or e.get("phase") != "closed":
sys.exit(1)
print("CLOSED", cid)
+147
View File
@@ -0,0 +1,147 @@
#!/usr/bin/env python3
"""Close the #2479 dichotomy-wave tiered_executor gap contract (GO port).
Full lifecycle walk in ONE process (shared-store clobber hazard; segment
transitions take ~60s each — do NOT split across processes). The final
step is iface.close() with contract_quality observed_evidence (the bare
`transition -> closed` is rejected by the quality gate). Safe to re-run:
pass the existing contract id to resume an interrupted walk.
Carries the already-pushed parity SHA as evidence:
feat 213f09fb close PARTIAL gaps — dichotomy wave (3/8 -> 8/8)
Usage: close_contract_tiered_executor.py [contract_id]
"""
import json
import os
import sys
from pathlib import Path
os.environ.setdefault(
"CS_RUST_LIB",
"/mnt/workdrive/rune/src/rust/capability_scoring/target/release/libcapability_scoring.so",
)
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "src"))
from rune.construction_interface import ConstructionInterface
PARITY_SHA = "213f09fb"
EVIDENCE = f"parity {PARITY_SHA}"
NEED = (
"tiered_executor dichotomy gap-close (GO): name-preserving port of the "
"5 audit-missing functions (CognitiveJob.to_dict, "
"CognitiveResult.to_dict, TieredExecutor.execute full surface, "
"_execute_model, _ctx_budget, test_executor) into "
"src/go/tiered-executor (toDict methods + renderResultCLI indent-2 "
"byte renderer, Execute with the no-profile early return / T0 "
"deterministic vs model dispatch, ExecuteModel with json.dumps "
"byte-parity OLLAMA payload + ensure_ascii + rune-safe [:2000] "
"response slice + crash-parity envelopes, CtxBudget over the vendored "
"ResolveCtxBudget per the GO SIBLING ISOLATION law, TestExecutor with "
"Python True/False print literals and assert crash parity), frozen-"
"truth battery (truth.json, 27-case envelope via the shared "
"freeze_truth.py harness + scripts/te_freeze_seams rig: time.time "
"pinned so every latency is exactly 0.0 with the TE_LATENCY_MS Go "
"seam mirror, OLLAMA echo server reflecting the request body so the "
"json.dumps payload bytes ride the rows, ModelRegistry({}) falsiness "
"-> DEFAULT_PROFILES, T9 sentinel registry for the no-profile rows) "
"verified byte-identical twice, embedded VERBATIM in truth_test.go "
"TestFrozenTruthReplay (27/27); CI replay binary PARITY OK 27/27; "
"live parity sweep 31/31 (scripts/check_tiered_executor_parity.py: "
"25 op families + 6 CLI checks incl. test/execute/usage); gofmt/vet/"
"go build clean, Python oracle smoke green both pins (no loader seam "
"— vacuous pin, parallel_processor precedent). Oracle quirks "
"preserved and frozen: str[:n] char-slicing (rune-safe truncation "
"rows for [:100] and [:2000]), str(e) message-only error envelopes, "
"integral-float rendering (CLI emits 0.0 byte-exactly; op comparison "
"integrality-normalized), dict insertion-order payload bytes. "
"Dichotomy audit 3/8 PARTIAL -> 8/8 FULL. Delivered on "
"gitea/master: feat " + PARITY_SHA + "."
)
iface = ConstructionInterface(builder="factory-gap-te")
if len(sys.argv) > 1:
cid = sys.argv[1]
print("resuming contract:", cid)
else:
r = iface.submit_need(NEED, origin="builder")
print("submit_need:", json.dumps(r)[:300])
if not r.get("success"):
print("NEED FAILED — aborting")
sys.exit(1)
cid = r["ids"]["contract_id"]
print("contract_id:", cid)
def phase_of(cid):
doc = iface.scaffold.load()
e = iface.scaffold.contract(doc, cid)
return e.get("phase") if e else "MISSING"
phase = phase_of(cid)
print("current phase:", phase)
for want in ("approved", "building", "verifying"):
if phase == want or phase in ("verifying", "closed"):
break
t = iface.transition(cid, want, evidence_ref=EVIDENCE)
ok = t.get("success")
print(f"transition->{want}:", "ok" if ok else json.dumps(t)[:300])
if not ok:
sys.exit(1)
phase = want
c = iface.close(
cid,
observed_evidence=[{
"kind": "port_evidence",
"detail": "tiered_executor dichotomy completion — parity "
f"{PARITY_SHA} feat(tiered_executor): close PARTIAL "
"gaps — dichotomy wave; pushed gitea/master. Go port at "
"src/go/tiered-executor closes the audit gaps "
"name-preserving (toDict on CognitiveJob/CognitiveResult "
"+ renderResultCLI byte renderer, Execute with no-profile "
"early return and T0-vs-model dispatch, ExecuteModel with "
"json.dumps byte-parity payload / rune-safe [:2000] slice "
"/ crash-parity envelopes, CtxBudget + vendored "
"ResolveCtxBudget, TestExecutor assert-parity). Freeze "
"rig scripts/te_freeze_seams + generator "
"scripts/gen_tiered_executor_truth.py: 27-case frozen "
"truth regenerates byte-identical; freeze_truth --verify "
"OK twice against the live oracle. Battery 11 tests "
"green (TestFrozenTruthReplay 27/27 VERBATIM); CI replay "
"binary PARITY OK 27/27; live parity "
"scripts/check_tiered_executor_parity.py 31/31 (25 op "
"families + 6 CLI checks); gofmt/vet/go build clean; "
"Python oracle smoke both pins. Audit 3/8 → 8/8 FULL. "
"Divergences (documented in verification/te-summary.md): "
"(1) transport-error text beyond the two deterministic "
"frozen classes (unknown-url-type, connection-refused) "
"is stack-specific — contract is the message-only error "
"envelope shape; (2) CLI execute latency_ms measured "
"live on both sides — normalized structurally in parity, "
"pinned 0.0 via the time/TE_LATENCY_MS seams in the "
"frozen rows; (3) integral-float rendering 0.0 vs 0 "
"equal-after-parse (op comparison), CLI emits 0.0 "
"byte-exactly.",
}],
scope_files=[
"src/go/tiered-executor/executor.go",
"src/go/tiered-executor/main.go",
"src/go/tiered-executor/context_budget.go",
"src/go/tiered-executor/pyjson.go",
"src/go/tiered-executor/truth_test.go",
"src/go/tiered-executor/truth.json",
"scripts/te_freeze_seams/sitecustomize.py",
"scripts/gen_tiered_executor_truth.py",
"scripts/check_tiered_executor_parity.py",
],
)
print("close:", json.dumps(c)[:400])
final = phase_of(cid)
print("FINAL PHASE:", final)
ok = c.get("success") and final == "closed"
print("CLOSED" if ok else "CLOSE_FAILED", cid)
sys.exit(0 if ok else 1)
+191
View File
@@ -0,0 +1,191 @@
#!/usr/bin/env python3
"""Close the #2479 dichotomy-wave voice_sync gap contract (RUST port).
Full lifecycle in ONE process (shared-store clobber hazard; segment
transitions take ~30-60s each — do NOT split across processes). Carries
the already-pushed parity SHAs as evidence:
feat 3a2c7646 port to FULL Rust — dichotomy wave
phaseB b2652913 Phase B language-advantage pass — dichotomy wave
QUALITY-GATE LAW (scaffold.py 2026-10-13): the walk stops at `verifying`
and closes through the DESIGNED iface.close() entry (predicted-vs-
observed quality + material-change) — a raw transition to 'closed' is
REFUSED.
Usage: close_contract_voice_sync.py
"""
import json
import os
import sys
from pathlib import Path
os.environ.setdefault(
"CS_RUST_LIB",
"/mnt/workdrive/rune-wave-db/src/rust/capability_scoring/target/release/libcapability_scoring.so",
)
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "src"))
from rune.construction_interface import ConstructionInterface
PARITY_SHA = "3a2c7646"
PHASEB_SHA = "b2652913"
EVIDENCE = f"parity {PARITY_SHA}, phase B {PHASEB_SHA}"
iface = ConstructionInterface(builder="factory-gap-vs")
r = iface.submit_need(
"voice_sync dichotomy gap-close (RUST): name-preserving port of the 7 "
"audit-missing functions into src/rust/voice_sync (the module's "
"classification side — sqlite3 storage-backed; a stale Go voice-sync "
"dir exists from an early partial batch and is untouched; my diff "
"brings zero Go files): get_delivery_register_from_db / "
"get_delivery_register (the chunk row-selection loop — rows fetched "
"Python-side, SQL WHERE + fresh-store OperationalError guard stay in "
"the facade), extract_voice_section (section parser), "
"generate_voice_section (assembler), update_rune_md_content / "
"update_rune_md (pure splice view, composite {result,new_content} so "
"the facade performs the write; the oracle gains the same oracle-level "
"pure view the shared freeze gate pins — salience_gate "
"evaluate_salience_dict precedent), check_sync, handle_hook, "
"sync_voice (parts-shaped decisions), _vs_core (kernel mirror of the "
"facade probe contract, pin lattice) plus plugin. Facade delegation "
"via vs_loader.py (10 vs_* doc-envelope symbols, free via "
"capability_scoring cs_free_string, VOICE_SYNC_RUST_LIB override, "
"RUNE_VOICE_SYNC_CORE=python pin — the shared harness derives EXACTLY "
"this pin name, inverting salience's wrong-name quirk). SQLite I/O, "
"rune.md writes, wall-clock _now and the argparse main() CLI stay "
"facade-side (behavior crate precedent). Dichotomy audit PARTIAL 3/10 "
"-> FULL 12/12. Parity defects pinned pre-landing: len>200 is a "
"CODEPOINT count; the +10 offset past the ## Voice header advances by "
"CHARS (char-boundary safe with multibyte tails); handle_hook's "
"auto-sync branch reports synced:true even on error details (oracle "
"verbatim); whitespace-only register parses to the four-empty-lists "
"TRUTHY dict while the empty string is None. Frozen truth via the "
"shared scripts/freeze_truth.py harness (generator "
"scripts/gen_voice_sync_truth.py, poisoned-truth law "
"RUNE_VOICE_SYNC_CORE=python): frozen_vs_truth.verify.json 37 pure "
"rows byte-identical under freeze_truth.py --verify; envelope "
"frozen_vs_truth.json 64 rows (verify rows first + rig-required "
"store/file rows whose kernel-shaped inputs ride in args with "
"fixtures for --replay; branch_battery.rs replays both VERBATIM via "
"include_str!, order-sensitive canonical-string compare — the facade "
"consumes kernel JSON directly so Python insertion order must "
"survive: serde_json preserve_order). Live parity 100%: gen --replay "
"facade-delegating + kernel-direct 125/125; crate canary 15/15; "
"second-modality differential 2479-seed fuzz beyond the corpus 486 "
"comparisons / 0 divergences; pytest 17/17 in three pin states (live "
"/ RUNE_VOICE_SYNC_CORE=python / VOICE_SYNC_RUST_LIB poisoned); full "
"suite 2763+2764 passed with every remaining failure PROVEN "
"pre-existing by stashing the voice_sync diff. Phase B (b2652913): "
"contains_ci_upper ASCII-anchored zero-alloc needle matching (full "
"to_uppercase fallback so Unicode case mappings are never skipped), "
"chars().take(201) bounded length probe, #[must_use] pure surface, "
"ci<=>upper-contains equivalence self-check over the frozen corpus + "
"std-only bench (register probe 8.6us/call over 65 rows, needle scans "
"3.3us/text, chain 10.8us/call). rustfmt clean, clippy -D warnings "
"clean, zero Go surface. Evidence read back: "
"verification/voice-sync-{freeze-verify,cargotest,clippy,replay,"
"canary,differential,python-pins,goladder,audit,phaseb-cargotest,"
"phaseb-parity,phaseb-canary,phaseb-python}.log (all exit 0). "
f"Delivered on gitea/master: feat {PARITY_SHA}, phase B {PHASEB_SHA}.",
origin="builder",
)
print("submit_need:", json.dumps(r)[:300])
if not r.get("success"):
print("NEED FAILED — aborting")
sys.exit(1)
c = r["ids"]["contract_id"]
print("contract_id:", c)
for phase in ("approved", "building", "verifying"):
t = iface.transition(c, phase, evidence_ref=EVIDENCE)
ok = t.get("success")
print(f"transition->{phase}:", "ok" if ok else json.dumps(t)[:300])
if not ok:
sys.exit(1)
doc = iface.scaffold.load()
e = iface.scaffold.contract(doc, c)
print("PHASE:", e.get("phase") if e else "MISSING")
if not e or e.get("phase") != "verifying":
print("walk did not reach verifying — aborting before close")
sys.exit(1)
# QUALITY-GATE LAW: raw transition to 'closed' is REFUSED — designed close.
closed = iface.close(
c,
observed_evidence=[
{
"kind": "port_evidence",
"detail": (
f"voice_sync RUST dichotomy gap-close — parity commit {PARITY_SHA}, "
f"Phase B commit {PHASEB_SHA}; dichotomy audit fn coverage 3/10 "
"PARTIAL -> 12/12 FULL (update_rune_md_content + _vs_core join "
"the surface per the salience_gate precedent; _py_* helpers "
"are the audit's machinery class; the module's classification "
"side is RUST sqlite3 storage-backed — no Go surface). "
"Ported name-preserving: get_delivery_register_from_db / "
"get_delivery_register (chunk row loop, rows fetched "
"Python-side), extract_voice_section, generate_voice_section, "
"update_rune_md_content / update_rune_md (pure splice view, "
"composite result/new_content — facade performs the write), "
"check_sync, handle_hook, sync_voice (parts-shaped), _vs_core "
"(probe pin lattice), plugin. Facade delegation via "
"vs_loader.py (10 vs_* doc-envelope symbols, free via "
"capability_scoring cs_free_string, VOICE_SYNC_RUST_LIB "
"override, RUNE_VOICE_SYNC_CORE=python pin — the shared "
"harness pin derives EXACTLY this name). Frozen truth via "
"the shared scripts/freeze_truth.py harness (generator "
"scripts/gen_voice_sync_truth.py, poisoned-truth law): "
"verify view 37 pure rows byte-identical under "
"freeze_truth.py --verify; envelope 64 rows whose "
"kernel-shaped inputs ride in args with replay fixtures "
"(branch_battery.rs include_str replay, order-sensitive "
"canonical-string compare via serde_json preserve_order, 16 "
"tests). Live parity 100%: gen --replay facade-delegating + "
"kernel-direct 125/125; canary 15/15; second-modality "
"differential 486 comparisons / 0 divergences (2479-seed "
"fuzz incl. multibyte splices + sandboxed I/O decisions); "
"pytest 17/17 in three pin states (live / "
"RUNE_VOICE_SYNC_CORE=python / VOICE_SYNC_RUST_LIB "
"poisoned); full suite 2763+2764 passed with all remaining "
"failures stash-proven pre-existing (none involve "
"voice_sync). Phase B (b2652913): contains_ci_upper "
"zero-alloc ASCII needle matching with full-mapping "
"fallback, take(201) bounded length probe, #[must_use] "
"pure surface, equivalence self-check + std-only bench. "
"rustfmt clean, clippy -D warnings clean, zero Go surface. "
"Evidence read back: verification/voice-sync-{freeze-verify,"
"cargotest,clippy,replay,canary,differential,python-pins,"
"goladder,audit,phaseb-cargotest,phaseb-parity,phaseb-canary,"
"phaseb-python}.log (all exit 0). Delivered on gitea/"
f"master: feat {PARITY_SHA}, phase B {PHASEB_SHA}."
),
}
],
scope_files=[
"src/rune/voice_sync.py",
"src/rune/vs_loader.py",
"src/rust/voice_sync/src/lib.rs",
"src/rust/voice_sync/src/branch_battery.rs",
"src/rust/voice_sync/src/frozen_vs_truth.json",
"src/rust/voice_sync/src/frozen_vs_truth.verify.json",
"src/rust/voice_sync/Cargo.toml",
"src/rust/voice_sync/Cargo.lock",
"src/rust/voice_sync/canary_voice_sync.py",
"scripts/gen_voice_sync_truth.py",
"tests/test_voice_sync_port.py",
"scripts/close_contract_voice_sync.py",
],
)
print("close:", json.dumps(closed)[:400])
doc = iface.scaffold.load()
e = iface.scaffold.contract(doc, c)
phase = e.get("phase") if e else None
print("FINAL PHASE:", phase)
if phase == "closed":
print("CLOSED", c)
sys.exit(0)
print("not closed — inspect store")
sys.exit(1)
+74
View File
@@ -0,0 +1,74 @@
#!/usr/bin/env python3
"""Close the #2479 dichotomy-wave witness gap contract (GO port).
Full lifecycle walk in ONE process (shared-store clobber hazard; segment
transitions can take ~60s each — do NOT split across processes). Carries
the already-pushed parity SHA as evidence:
feat cc51b181 close PARTIAL gaps — dichotomy wave
Usage: close_contract_witness.py
"""
import json
import os
import sys
from pathlib import Path
os.environ.setdefault(
"CS_RUST_LIB",
"/mnt/workdrive/rune/src/rust/capability_scoring/target/release/libcapability_scoring.so",
)
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "src"))
from rune.construction_interface import ConstructionInterface
PARITY_SHA = "cc51b181"
EVIDENCE = f"parity {PARITY_SHA}"
iface = ConstructionInterface(builder="factory-gap-wi")
r = iface.submit_need(
"witness dichotomy gap-close (GO): name-preserving port of the 4 "
"audit-missing functions (_now, log_entry, read_log, log_stats) into "
"src/go/witness as now / logEntry / readLog / logStats with the "
"injectable clock + log-path seams, plus parity-driven defect fixes "
"to the old-era port: current 20-pattern correction table + family "
"tables, kernel-parity extract_topic (ASCII \\w runs, cap 5), "
"detect_signals kernel order (error → correction → completion → "
"drift → commitment → contradiction → preference → urgency → "
"learning) with case-insensitive family matching, rune-safe [:200] "
"error_text and context[-500:], extraction-ordered new_topics, "
"num_ctx 30720 via the _ctx_budget seam, and json.dumps byte-parity "
"log lines (separators, insertion order, ensure_ascii). Frozen-truth "
"battery (truth.json, 58 cases incl. the capital-letter is_correction "
"quirk, completion triple, half-even skip_rate 37.5→38%) generated "
"against the live oracle and verified byte-identical via "
"freeze_truth.py, embedded VERBATIM in truth_test.go "
"TestFrozenTruthReplay + seam units (deque read semantics, malformed/"
"blank lines, list-shaped signal_types, log-line bytes, rune "
"truncation); live parity sweep 59/59 with byte-compared log files "
"(scripts/check_witness_parity.py); gofmt/vet/go build clean; Python "
"oracle battery green both pins (16 live + 9 under "
"RUNE_COGNITION_CORE=python). Dichotomy audit 11/15 PARTIAL -> "
"15/15 FULL. Delivered on gitea/master: feat " + PARITY_SHA + ".",
origin="builder",
)
print("submit_need:", json.dumps(r)[:300])
if not r.get("success"):
print("NEED FAILED — aborting")
sys.exit(1)
c = r["ids"]["contract_id"]
print("contract_id:", c)
for phase in ("approved", "building", "verifying", "closed"):
t = iface.transition(c, phase, evidence_ref=EVIDENCE)
ok = t.get("success")
print(f"transition->{phase}:", "ok" if ok else json.dumps(t)[:300])
if not ok:
sys.exit(1)
doc = iface.scaffold.load()
e = iface.scaffold.contract(doc, c)
print("FINAL PHASE:", e.get("phase") if e else "MISSING")
if not e or e.get("phase") != "closed":
sys.exit(1)
print("CLOSED", c)
+40
View File
@@ -0,0 +1,40 @@
"""sitecustomize — the construction_mode freeze rig (dichotomy wave gap
close).
Auto-imported via PYTHONPATH=scripts/cm_freeze_seams by BOTH the truth
generator and `freeze_truth.py --verify`, so the --verify law (replay
against the pristine oracle) still holds:
* RUNE_CM_CORE=python + RUNE_CONSTRUCTION_DECISION_CORE=python pinned
for the whole cone. The harness's _pin_oracle_cores sets
RUNE_CONSTRUCTION_MODE_CORE, which this oracle does not read; and
classify_mode's file-scope branch imports
construction_decision.classify_surface, whose own delegation gate
must be pinned too (transitive-core law, ci_freeze_seams precedent).
* Module seam bound onto rune.construction_mode:
- cm_classify_to_dict(objective, **kwargs) — drives the REAL
classify_mode and returns its own to_dict() projection (the
return value is a ConstructionMode instance, which is not
JSON-serializable; the frozen contract is the projection the
facade and the Rust core both speak).
"""
import os
import sys
from pathlib import Path
os.environ["RUNE_CM_CORE"] = "python"
os.environ["RUNE_CONSTRUCTION_DECISION_CORE"] = "python"
REPO = Path(os.environ.get("CM_FREEZE_REPO", "")) or Path.cwd()
if str(REPO / "src") not in sys.path:
sys.path.insert(0, str(REPO / "src"))
import rune.construction_mode as _cm # noqa: E402
def _cm_classify_to_dict(objective, **kwargs):
return _cm.classify_mode(objective, **kwargs).to_dict()
_cm.cm_classify_to_dict = _cm_classify_to_dict
@@ -0,0 +1,59 @@
#!/usr/bin/env python3
"""Complete the layout_contract dichotomy close: the walk reached
'verifying' (BUILDER-2026-10-14T05:21:12Z-4723a5-factory-gap-lc); the
final step must enter via close() — the quality-gate law (2026-10-13)
requires the predicted-vs-observed contract_quality computation, not a
raw transition. One process, no interleaved writers.
Usage: complete_close_contract_layout_contract.py
"""
import json
import os
import sys
from pathlib import Path
os.environ.setdefault(
"CS_RUST_LIB",
"/mnt/workdrive/rune/src/rust/capability_scoring/target/release/libcapability_scoring.so",
)
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "src"))
from rune.construction_interface import ConstructionInterface
PARITY_SHA = "9ed9a7a2"
EVIDENCE = f"parity {PARITY_SHA}"
CID = "BUILDER-2026-10-14T05:21:12Z-4723a5-factory-gap-lc"
iface = ConstructionInterface(builder="factory-gap-lc")
r = iface.close(
CID,
observed_evidence=[
{"kind": "port_evidence", "detail": "parity " + PARITY_SHA,
"entity": "module:layout_contract"},
{"kind": "port_evidence", "detail":
"frozen corpus 35 cases byte-identical (frozen_lc_gap_truth.json); "
"gap_battery 10/10; clippy -D warnings clean",
"entity": "module:layout_contract"},
{"kind": "port_evidence", "detail":
"live parity 35/35 + byte-identical re-freeze "
"(scripts/check_layout_contract_parity.py); layout+consumer tests "
"64/64 BOTH pins",
"entity": "module:layout_contract"},
{"kind": "port_evidence", "detail":
"dichotomy audit 2/6 PARTIAL -> 6/6 FULL (RUST)",
"entity": "module:layout_contract"},
],
)
print("close:", json.dumps(r)[:400])
if not r.get("success"):
print("CLOSE FAILED — aborting")
sys.exit(1)
doc = iface.scaffold.load()
e = iface.scaffold.contract(doc, CID)
print("FINAL PHASE:", e.get("phase") if e else "MISSING")
if not e or e.get("phase") != "closed":
sys.exit(1)
print("CLOSED", CID)
+351
View File
@@ -0,0 +1,351 @@
#!/usr/bin/env python3
"""context_pressure_truth — shared capture/regeneration helpers for the
context_pressure dichotomy gap-close (issue #2479 tranche).
Used by scripts/gen_context_pressure_truth.py (freeze) and
scripts/check_context_pressure_parity.py (independent regeneration for the
truth-consumed-not-self-generated gate). EVERY process that imports this
module MUST run under the scripts/cps_freeze_seams rig
(PYTHONPATH=scripts/cps_freeze_seams) so:
* RUNE_CPS_CORE/RUNE_CONTEXT_PRESSURE_CORE=python — poisoned-truth law:
the ORACLE FLOOR captures/regenerates every expectation.
* datetime is frozen to CPS_FROZEN_NOW — entry lines are byte-stable.
* RUNE_MEMORY_DIR points at the hermetic scratch; LOG_PATH (resolved at
oracle import) lives there. CPS_SEED_LOG injects log file content for
CLI subprocess rows (the rig wipes and reseeds at import).
Kernel case shapes:
logMeasurement args {measurement, session_id, now} → expect {line}
readLog args {content, limit} → expect [entries]
logStats args {content} → expect counts | __crash__
kernelHook args {event, data, now} → expect {result, entry} | __crash__
mainDispatch args {argv, content, now} → expect {output, code} [, entry doc] | {output, code}
Crash rows store "__crash__ TYPE: message" — the exact str(e) contract.
"""
from __future__ import annotations
import copy
import json
import os
import subprocess
import sys
from pathlib import Path
REPO = Path(__file__).resolve().parents[1]
FROZEN_NOW = os.environ.get("CPS_FROZEN_NOW", "2026-10-14T01:02:03.456789+00:00")
SCRATCH = os.environ.get("CPS_FREEZE_SCRATCH", "/tmp/cps_gap_freeze")
LOG_FILE = os.path.join(SCRATCH, "memory", "index", "context_pressure.jsonl")
ORACLE = REPO / "src" / "rune" / "context_pressure.py"
RIG_DIR = REPO / "scripts" / "cps_freeze_seams"
def _oracle():
import rune.context_pressure as cp
return cp
def _seed_log(content: str) -> None:
os.makedirs(os.path.dirname(LOG_FILE), exist_ok=True)
with open(LOG_FILE, "w") as f:
f.write(content)
def _read_log_file() -> str:
try:
with open(LOG_FILE, "r") as f:
return f.read()
except OSError:
return ""
# ── kernel-case capture (oracle floor) ────────────────────────────────────
def capture_log_measurement(measurement, session_id, now):
_seed_log("")
cp = _oracle()
cp.log_measurement(measurement, session_id)
return {"line": _read_log_file()}
def capture_read_log(content, limit):
_seed_log(content)
cp = _oracle()
return cp.read_log(limit=limit)
def capture_log_stats(content):
_seed_log(content)
cp = _oracle()
try:
return cp.log_stats()
except Exception as e: # noqa: BLE001 — crash parity capture
return {"__crash__": f"{type(e).__name__}: {e}"}
def capture_hook(event, data):
_seed_log("")
cp = _oracle()
try:
result = cp.handle_hook(event, data)
except Exception as e: # noqa: BLE001 — crash parity capture
return {"__crash__": f"{type(e).__name__}: {e}"}
entry = None
for line in _read_log_file().splitlines():
if line.strip():
entry = json.loads(line)
return {"result": result, "entry": entry}
def capture_cli(argv, seed_content):
"""Run the real CLI (src/rune/context_pressure.py) under the rig; return
{output, code} plus the entry line the hook arm appended (if any).
`argv` carries the synthetic program name at [0] (parse_cli law: the
kernel skips argv[0] exactly like the oracle skips sys.argv[0]); the
subprocess receives argv[1:]."""
_seed_log(seed_content)
env = dict(os.environ)
rig = str(RIG_DIR)
if rig not in env.get("PYTHONPATH", ""):
env["PYTHONPATH"] = rig + (":" + env["PYTHONPATH"] if env.get("PYTHONPATH") else "")
# CLI subprocess rows: the scratch lives in the /tmp rig layout — the
# seeded content rides CPS_SEED_LOG (the subprocess's rig re-seeds it
# after its scratch wipe).
env["CPS_SEED_LOG"] = seed_content
env["RUNE_MEMORY_DIR"] = os.path.join(SCRATCH, "memory")
proc = subprocess.run(
[sys.executable, str(ORACLE), *argv[1:]],
capture_output=True, text=True, env=env,
)
out = {"output": proc.stdout[:-1] if proc.stdout.endswith("\n") else proc.stdout,
"code": proc.returncode}
if any(a == "hook" for a in argv):
entry = None
for line in _read_log_file().splitlines():
if line.strip():
try:
entry = json.loads(line)
except json.JSONDecodeError:
continue
out["entry"] = entry
return out
# ── the corpora ───────────────────────────────────────────────────────────
def envelope_case_specs():
"""The pure-surface rows (regenerated independently by
freeze_truth.py --verify): (fn, args, kwargs)."""
big = "x" * 95000 # ok pressure at default max_tokens
return [
("estimate_tokens", ("",), {}),
("estimate_tokens", ("hello world",), {}),
("estimate_tokens", ("héllo wörld",), {}),
("estimate_tokens", ("👍👍",), {}),
("estimate_tokens", ("x" * 1000,), {}),
("measure_pressure", ("",), {}),
("measure_pressure", ("hello world",), {}),
("measure_pressure", ("x" * 100000,), {}),
("measure_pressure", ("x" * 49000,), {"max_tokens": 20000}),
("measure_pressure", ("x" * 17430,), {"max_tokens": 8000}),
("measure_pressure", ("x" * 9000,), {"max_tokens": 12000}),
("measure_pressure", ("x" * 10830,), {"max_tokens": 12000}),
("measure_pressure", (big,), {"max_tokens": 12000}),
("detect_degradation", (["a", "b"],), {}),
("detect_degradation", (["aaa", "bbb", "ccc"],), {}),
("detect_degradation", (["x" * 200, "y" * 180, "", "", ""],), {}),
("detect_degradation", (["dup word word", "word dup word", "word word dup"],), {}),
("detect_degradation", (["a b c d", "a b c d", "a b c d"],), {}),
("detect_degradation", (["z" * 99, "z" * 100, "z" * 101],), {}),
("detect_degradation", (["éé üü éé", "üü éé üü", "éé üü"],), {}),
("detect_degradation", (["short", "tiny", "x" * 300],), {}),
("handle_hook", ("on_message", {"message": big}), {}),
("handle_hook", ("on_message", {"message": "x" * 403500}), {}),
("handle_hook", ("on_message", {"text": "hello"}), {}),
("handle_hook", ("on_message", {"other": 1}), {}),
("handle_hook", ("on_message", {}), {}),
("handle_hook", ("on_message", None), {}),
("handle_hook", ("other_event", {"message": big}), {}),
]
def kernel_case_specs():
"""The kernel rows (captured from the oracle floor; replayed by the
Rust battery, the loader FFI and regenerated independently here)."""
m_ok = _oracle_measure("hello world")
m_warn = _oracle_measure("x" * 49000, 20000)
m_crit = _oracle_measure("x" * 95000, 12000)
d_int0 = _pure_detect(["aaa", "bbb", "ccc"])
return {
"logMeasurement": [
("tokens_and_zero_pressure", m_ok, ""),
("warning_pressure", m_warn, ""),
("critical_pressure", m_crit, ""),
("int_zero_fields", d_int0, ""),
("session_id", m_ok, "session 9"),
("override_and_extra",
{"timestamp": "T-override", "session_id": "SID-OVR",
"user_key": "u", "tokens": 42, "pressure": 0.5,
"status": "warning"}, ""),
("unicode_escape_probe",
{"note": "éé", "pressure": 0.0, "status": "ok"}, ""),
],
"readLog": [
("read_all", "e1\ne2\n", 20),
("tail_two_of_four", "l1\nl2\nl3\nl4\n", 2),
("blank_and_invalid", '{"a": 1}\n\nnot json\n{"b": 2}\n', 20),
("limit_zero", "e1\ne2\n", 0),
("trailing_newline_no_phantom", "a\nb\nc\n", 2),
("float_pressure", '{"tokens": 3, "pressure": 0.5}\n', 20),
("int_line", "5\n", 20),
],
"logStats": [
("mixed_counts",
'{"status": "warning"}\n{"status": "warning"}\n'
'{"status": "warning"}\n{"status": "critical"}\n'
'{"status": "critical"}\n{"status": "ok"}\n\nbroken\n'),
("empty", ""),
("non_dict_line_crash", "5\n"),
],
"kernelHook": [
("critical_message", "on_message", {"message": "x" * 403500}),
("ok_text", "on_message", {"text": "hello"}),
("str_data_fallback", "on_message", {"other": 1}),
("both_empty_fallback", "on_message", {"message": "", "text": ""}),
("empty_data", "on_message", {}),
("wrong_event", "other_event", {"message": "hello"}),
("repr_bool_none", "on_message", {"a": True, "n": None}),
("repr_quote_probe", "on_message", {"k": "a'b"}),
("message_int_crash", "on_message", {"message": 5}),
("list_data_crash", "on_message", [1, 2]),
("bool_data_crash", "on_message", True),
("int_data_crash", "on_message", 5),
("null_data", "on_message", None),
],
"mainDispatch": [
("measure_plain", ["cp", "measure", "hello world"], ""),
("measure_json", ["cp", "measure", "hello world", "--json"], ""),
("measure_max_tokens", ["cp", "measure", "x" * 49000,
"--max-tokens", "20000"], ""),
("degrade_plain", ["cp", "degrade", "a b c|a b c|a b"], ""),
("degrade_json", ["cp", "degrade", "dup word|dup word|dup word",
"--json"], ""),
("log_plain", ["cp", "log", "--limit", "2"],
'{"tokens": 3, "pressure": 0.5, "status": "warning", "timestamp": "2026-10-14T01:02:03.456789+00:00"}\n{"tokens": 1, "pressure": 0.0, "status": "ok", "timestamp": "x"}\nbroken\n'),
("log_json", ["cp", "log", "--json"],
'{"pressure": 0.5, "status": "warning"}\n'),
("stats_plain", ["cp", "stats"],
'{"status": "warning"}\n{"status": "critical"}\n{"status": "ok"}\n'),
("stats_json", ["cp", "stats", "--json"],
'{"status": "warning"}\n'),
("hook_ok", ["cp", "hook", "--event", "on_message",
"--data", '{"message": "hello"}'], ""),
("hook_critical", ["cp", "hook", "--event", "on_message",
"--data", '{"message": "' + "x" * 95000 + '"}'], ""),
("hook_default_event", ["cp", "hook"], ""),
("unknown_cmd", ["cp", "bogus"], ""),
("no_cmd", ["cp"], ""),
("unknown_flag", ["cp", "measure", "x", "--bogus"], ""),
("bad_int", ["cp", "measure", "--max-tokens", "abc"], ""),
("extra_positional", ["cp", "measure", "a", "b"], ""),
],
}
def _oracle_measure(text, max_tokens=128000):
"""The oracle floor with the core pin active (poisoned-truth law:
the LIVE module computes every measurement)."""
return _oracle().measure_pressure(text, max_tokens=max_tokens)
def _pure_detect(responses):
return _oracle().detect_degradation(responses)
def regen_kernel_cases():
"""Regenerate every kernel row from the live oracle floor."""
specs = kernel_case_specs()
rows = {"logMeasurement": [], "readLog": [], "logStats": [],
"kernelHook": [], "mainDispatch": []}
for name, m, sid in specs["logMeasurement"]:
rows["logMeasurement"].append({
"fn": "log_measurement", "name": name,
"args": {"measurement": m, "session_id": sid, "now": FROZEN_NOW},
"expect": capture_log_measurement(copy.deepcopy(m), sid, FROZEN_NOW),
})
for name, content, limit in specs["readLog"]:
rows["readLog"].append({
"fn": "read_log", "name": name,
"args": {"content": content, "limit": limit},
"expect": capture_read_log(content, limit),
})
for name, content in specs["logStats"]:
rows["logStats"].append({
"fn": "log_stats", "name": name,
"args": {"content": content},
"expect": capture_log_stats(content),
})
for name, event, data in specs["kernelHook"]:
rows["kernelHook"].append({
"fn": "handle_hook", "name": name,
"args": {"event": event, "data": data, "now": FROZEN_NOW},
"expect": capture_hook(event, copy.deepcopy(data)),
})
for name, argv, seed in specs["mainDispatch"]:
rows["mainDispatch"].append({
"fn": "main_dispatch", "name": name,
"args": {"argv": argv, "content": seed, "now": FROZEN_NOW},
"expect": capture_cli(argv, seed),
})
return rows
def regen_envelope_cases():
"""Drive the pure-surface rows against the live oracle (in-rig)."""
cp = _oracle()
rows = []
for fn, args, kwargs in envelope_case_specs():
a = copy.deepcopy(args)
k = copy.deepcopy(kwargs)
result = getattr(cp, fn)(*a, **k)
rows.append({"fn": fn, "args": list(a), "kwargs": k,
"expected": copy.deepcopy(result)})
return rows
def write_envelope(path: Path) -> int:
cases = regen_envelope_cases()
kcases = regen_kernel_cases()
doc = {
"module": "context_pressure",
"frozen_now": FROZEN_NOW,
"cases": cases,
"kernel_cases": kcases,
}
path.parent.mkdir(parents=True, exist_ok=True)
path.write_text(json.dumps(doc, indent=2, ensure_ascii=False, sort_keys=False) + "\n")
total = len(cases) + sum(len(v) for v in kcases.values())
return total
def kernel_cases_total() -> int:
specs = kernel_case_specs()
return sum(len(v) for v in specs.values())
def main() -> int:
out = REPO / "src" / "rust" / "context_pressure" / "src" / "frozen_cp_truth.json"
total = write_envelope(out)
print(f"frozen {total} cases -> {out}")
return 0
if __name__ == "__main__":
if str(REPO / "scripts") not in sys.path:
sys.path.insert(0, str(REPO / "scripts"))
raise SystemExit(main())
+134
View File
@@ -0,0 +1,134 @@
"""sitecustomize — the construction_projection freeze rig (dichotomy wave
gap close).
Auto-imported via PYTHONPATH=scripts/cproj_freeze_seams by BOTH the truth
generator and `freeze_truth.py --verify`, so the --verify law (replay
against the pristine oracle) still holds: the seams below only make the
oracle's already-existing behavior reachable with JSON-safe shapes.
* RUNE_CONSTRUCTION_PROJECTION_CORE=python pinned (the oracle floor; the
harness's _pin_oracle_cores does this too — belt and braces).
* Module seams bound onto rune.construction_projection:
- cpj_freeze_contract_entity(doc, contract_id) — the REAL floor lookup
with JSON-safe args.
- cpj_freeze_project(scaffold_spec, contract_id, bridge, kwargs) —
rebuilds a JSON-specified fake scaffold, pins
rune.event_wait.operation_wait per the bridge row, drives the REAL
floor project(), and echoes the adapter-resolved bridge scalars
(waiting_state/live_correlation) the Rust battery needs as kernel
inputs (the SPEC-grammar law: the battery rebuilds its calls from
the same rows).
- cpj_freeze_validate(projection) — the REAL floor validator.
- cpj_freeze_write_mini_doc(scaffold_spec, contract_id) — drives the
REAL floor write_mini_doc into a hermetic FIXED-path scratch dir
(/tmp/cpj_gap_freeze, wiped per call), echoes the markdown bytes
and the file NAME (never an absolute path — no machine-specific
paths in frozen truth).
The fake bridge never touches the real waitstore: `bridge = None` (no
lookup), {} (operation id points at no record → None), a record dict
(rec found), or {"__raise__": "OSError"|"RuntimeError"} (the two degrading
failure classes the oracle catches → BRIDGE_UNREACHABLE).
"""
import os
import shutil
import sys
from pathlib import Path
os.environ["RUNE_CONSTRUCTION_PROJECTION_CORE"] = "python"
REPO = Path(os.environ.get("CPJ_FREEZE_REPO", "")) or Path.cwd()
if str(REPO / "src") not in sys.path:
sys.path.insert(0, str(REPO / "src"))
SCRATCH = "/tmp/cpj_gap_freeze"
if os.path.isdir(SCRATCH):
shutil.rmtree(SCRATCH)
os.makedirs(SCRATCH, exist_ok=True)
OUT_DIR = os.path.join(SCRATCH, "docs")
import rune.construction_projection as _cp # noqa: E402
from rune import event_wait as _ew # noqa: E402
REAL_OPERATION_WAIT = _ew.operation_wait
class _FakeScaffold:
"""JSON-rebuildable scaffold stand-in: the two attributes the oracle
touches (load() result, project_id). No store, no IO."""
def __init__(self, spec: dict):
doc = spec.get("load")
self._doc = {} if doc is None else doc
if "project_id" in spec:
self.project_id = spec["project_id"]
def load(self):
import copy
return copy.deepcopy(self._doc)
def _fake_operation_wait(bridge):
mode = (bridge or {}).get("__mode__", "none")
def _wait(operation_id):
if mode == "oserr":
raise OSError(2, "bridge data root unreadable (freeze-pinned)")
if mode == "runtimeerr":
raise RuntimeError("waitstore not resolvable (freeze-pinned)")
if mode == "found":
return dict((bridge or {}).get("record") or {})
if mode in ("none", "missing"):
return None
raise ValueError(f"unknown bridge mode {mode!r}")
return _wait
def _with_bridge(bridge, fn, *args, **kwargs):
_ew.operation_wait = _fake_operation_wait(bridge)
try:
return fn(*args, **kwargs)
finally:
_ew.operation_wait = REAL_OPERATION_WAIT
def cpj_freeze_contract_entity(doc, contract_id):
return _cp._contract_entity(doc, contract_id)
def cpj_freeze_project(scaffold_spec, contract_id, bridge, **kwargs):
scaffold = _FakeScaffold(scaffold_spec)
result = _with_bridge(bridge, _cp.project, scaffold, contract_id, **kwargs)
waiting_state = result.get("waiting_state", "")
live_correlation = result.get("correlation_id", "")
return {
"projection": result,
"waiting_state": waiting_state,
"live_correlation": live_correlation,
}
def cpj_freeze_validate(projection):
return _cp.validate(projection)
def cpj_freeze_write_mini_doc(scaffold_spec, contract_id):
scaffold = _FakeScaffold(scaffold_spec)
if os.path.isdir(OUT_DIR):
shutil.rmtree(OUT_DIR)
os.makedirs(OUT_DIR, exist_ok=True)
path = _cp.write_mini_doc(scaffold, contract_id, out_dir=OUT_DIR)
return {
"file": os.path.basename(str(path)),
"content": Path(path).read_text(encoding="utf-8"),
"projection": _cp.project(scaffold, contract_id),
}
_cp.cpj_freeze_contract_entity = cpj_freeze_contract_entity
_cp.cpj_freeze_project = cpj_freeze_project
_cp.cpj_freeze_validate = cpj_freeze_validate
_cp.cpj_freeze_write_mini_doc = cpj_freeze_write_mini_doc
+51
View File
@@ -0,0 +1,51 @@
"""sitecustomize — the context_pressure freeze rig (dichotomy wave gap close).
Auto-imported via PYTHONPATH=scripts/cps_freeze_seams by BOTH the truth
generator (scripts/gen_context_pressure_truth.py), the CLI subprocess rows,
and `freeze_truth.py --verify`, so frozen truth is byte-reproducible in any
process — and the --verify law (replay against the pristine oracle) holds:
* RUNE_CPS_CORE=python + RUNE_CONTEXT_PRESSURE_CORE=python — the oracle
runs its pure-Python floor (kernel delegation pinned OFF; poisoned-
truth law).
* datetime.datetime is FROZEN to CPS_FROZEN_NOW — the oracle reads
datetime.now(timezone.utc) in _now() at every entry-assembly site; the
frozen truth carries the constant instant.
* RUNE_MEMORY_DIR points at a hermetic FIXED-path scratch wiped at
import (LOG_PATH resolves at oracle import; every process starts from
the same empty log).
"""
import os
import shutil
import sys
from pathlib import Path
REPO = Path(os.environ.get("CPS_FREEZE_REPO", Path.cwd()))
os.environ.setdefault("RUNE_CPS_CORE", "python")
os.environ.setdefault("RUNE_CONTEXT_PRESSURE_CORE", "python")
SCRATCH = os.environ.get("CPS_FREEZE_SCRATCH", "/tmp/cps_gap_freeze")
if os.path.isdir(SCRATCH):
shutil.rmtree(SCRATCH)
os.makedirs(os.path.join(SCRATCH, "memory", "index"), exist_ok=True)
os.environ["RUNE_MEMORY_DIR"] = os.path.join(SCRATCH, "memory")
# CPS_SEED_LOG: log-file content for CLI subprocess rows (the CLI reads
# LOG_PATH, which the wipe just recreated — reseed right before the import).
_SEED_LOG = os.environ.get("CPS_SEED_LOG")
if _SEED_LOG is not None:
with open(os.path.join(SCRATCH, "memory", "index",
"context_pressure.jsonl"), "w") as _f:
_f.write(_SEED_LOG)
FROZEN_NOW = os.environ.get("CPS_FROZEN_NOW", "2026-10-14T01:02:03.456789+00:00")
if str(REPO / "scripts") not in sys.path:
sys.path.insert(0, str(REPO / "scripts"))
from freeze_rigs import pin_clock # noqa: E402
pin_clock(FROZEN_NOW)
if str(REPO / "src") not in sys.path:
sys.path.insert(0, str(REPO / "src"))
+45
View File
@@ -0,0 +1,45 @@
#!/usr/bin/env python3
"""ct_rig.py — deterministic fixture modules for the contracts gap-close
frozen truth (dichotomy wave, #2479 tranche).
The contracts oracle resolves modules with a bare ``__import__``; two of
its branches need modules no stdlib provides:
* import-time crash (``except Exception -> crash`` on import): see
``ct_rig_badimport.py`` (raises RuntimeError at import).
* projection-time crash (``_project`` raising on a hostile result):
``make_bad_len`` returns an object whose ``__len__`` raises, so
``hasattr(result, "__len__")`` is True but ``len(result)`` explodes.
``make_ok`` / ``ATTR_VALUE`` cover the plain found paths without depending
on any third-party module. Everything here is pure and deterministic —
safe to import from both the freeze generator and ``--verify`` (both run
with ``scripts/`` on ``sys.path``).
"""
ATTR_VALUE = "ct-rig-stable-value"
class _BadLen:
def __len__(self):
raise RuntimeError("boom")
def make_bad_len():
"""Return an object that breaks ``_project``'s ``len()`` call."""
return _BadLen()
def make_ok():
"""Return a plain JSON-safe dict (the found-path control case)."""
return {"ok": True, "n": 3}
def make_none():
"""Return None (the expect_not_none-fail control case)."""
return None
def raise_on_call():
"""Raise on call (the call-crash control case)."""
raise ValueError("rig call failure")
+11
View File
@@ -0,0 +1,11 @@
#!/usr/bin/env python3
"""ct_rig_badimport.py — import-crash fixture for the contracts gap-close
frozen truth (dichotomy wave, #2479 tranche).
Importing this module raises a non-ImportError, exercising the oracle's
``except Exception -> crash`` import branch in ``_resolve_and_project``
(and ``_run_contract_python``'s outer catch). Deterministic by
construction. See ``ct_rig.py`` for the companion fixtures.
"""
raise RuntimeError("rig import failure")
+232
View File
@@ -0,0 +1,232 @@
"""sitecustomize — the drift_core freeze rig (dichotomy wave gap-close).
Auto-imported via PYTHONPATH=scripts/dc_freeze_seams:src by BOTH the truth
generator and `freeze_truth.py --verify`, so the --verify law (replay
against the pristine oracle) still holds: the seams below only make the
oracle's already-existing behavior reachable with JSON-safe shapes.
* RUNE_DRIFT_CORE=python pinned (the oracle floor; the harness's
_pin_oracle_cores does this too — belt and braces) and a frozen clock
(RUNE_FROZEN_NOW — the harness patches the oracle module's `datetime`,
which reaches _now_iso and the velocity cutoff).
* RUNE_MEMORY_CORE deliberately NOT pinned: the scoring oracle was
RETIRED (raises) — promote/eligibility/value rows delegate to the BUILT
memory_scoring kernel, exactly as the oracle does in production. The
rig fails loudly when the .so is missing (determinism requires it).
* Hermetic FIXED-path scratch (/tmp/dc_gap_freeze — wiped and reseeded
per seam call, so rows are self-contained and promote's UPDATE can
never leak into the next row).
* Embeddings forced off (deterministic; no drift fn reads vectors).
* Module seams bound onto rune.drift_core:
- dc_freeze_promote(entry, entry_id) — seeds the SELECT-visible row
(explicit id), runs the oracle promote_entry, echoes the result
AND the post-UPDATE rock_status/promotion_eligible.
- dc_freeze_fama(rows, query, ids) — seeds aligned rows, runs the
oracle compute_fama. Args rows are the exact fetch shape
(status, rock_status, wash_count), so the battery replays the
kernel directly from args.
- dc_freeze_velocity(rows, days) — seeds last_washed/status/rock_status
rows, runs the oracle compute_drift_velocity, echoes the COUNT
aggregates the oracle computed (the kernel's actual inputs).
- dc_freeze_direction(rows) — same for compute_drift_direction.
- dc_freeze_gate(entry_id) — pre_commit_gate (None → JSON null).
- dc_freeze_ms_core() — the _ms_core probe contract, JSON-safe
(True = kernel delegation live under the rig).
"""
import os
import shutil
import sys
from pathlib import Path
REPO = Path(os.environ.get("DC_FREEZE_REPO", "")) or Path.cwd()
os.environ["RUNE_DRIFT_CORE"] = "python"
os.environ.setdefault(
"RUNE_FROZEN_NOW", "2026-10-13T12:00:00.123456+00:00"
)
SCRATCH = "/tmp/dc_gap_freeze"
if os.path.isdir(SCRATCH):
shutil.rmtree(SCRATCH)
os.makedirs(os.path.join(SCRATCH, "store"), exist_ok=True)
if str(REPO / "src") not in sys.path:
sys.path.insert(0, str(REPO / "src"))
from rune import memory_store as _store # noqa: E402
PINNED = os.path.join(SCRATCH, "dc-freeze.db")
_store.DB_PATH = os.path.join(SCRATCH, "store", "memory.db")
_store.STORE_DIR = os.path.join(SCRATCH, "store")
_store._embed = lambda texts: {} # lexical-only, deterministic
import rune.drift_core as _dc # noqa: E402
FROZEN_NOW = os.environ["RUNE_FROZEN_NOW"]
def _fresh_db():
"""Self-contained rows: wipe + reseed the scratch db per seam call."""
if os.path.exists(PINNED):
os.remove(PINNED)
return _store.connect(PINNED)
def _seed_row(db, entry_id, text, **cols):
db.execute(
"INSERT INTO entries (id, text, importance, created_at, status, "
"wash_count, rock_status, last_washed) VALUES (?,?,?,?,?,?,?,?)",
(
entry_id,
text,
cols.get("importance", 0.5),
cols.get("created_at", "2026-10-01T00:00:00.000000+00:00"),
cols.get("status", "active"),
cols.get("wash_count", 0),
cols.get("rock_status", "washable"),
cols.get("last_washed"),
),
)
db.commit()
def dc_freeze_promote(entry, entry_id):
db = _fresh_db()
try:
if entry is not None:
_seed_row(
db,
entry_id,
entry.get("text", "seeded row"),
wash_count=entry.get("wash_count", 0),
importance=entry.get("importance", 0.5),
rock_status=entry.get("rock_status", "washable"),
)
result = _dc.promote_entry(db, entry_id)
after = db.execute(
"SELECT rock_status, promotion_eligible FROM entries WHERE id = ?",
(entry_id,),
).fetchone()
return {
"result": result,
"after": dict(after) if after else None,
}
finally:
db.close()
def dc_freeze_fama(rows, query, ids):
db = _fresh_db()
try:
for i, row in enumerate(rows):
if row is None:
continue
_seed_row(
db,
ids[i],
f"fama row {i}",
status=row.get("status", "active"),
wash_count=row.get("wash_count", 0),
rock_status=row.get("rock_status", "washable"),
)
return _dc.compute_fama(db, query, ids)
finally:
db.close()
def dc_freeze_velocity(rows, days):
from datetime import timedelta
db = _fresh_db()
try:
for i, row in enumerate(rows):
_seed_row(
db,
i + 1,
f"velocity row {i}",
status=row.get("status", "active"),
rock_status=row.get("rock_status", "washable"),
last_washed=row.get("last_washed"),
)
out = _dc.compute_drift_velocity(db, days)
# Echo the aggregates the oracle computed (kernel's inputs): the
# cutoff re-derived exactly as the oracle derives it.
from datetime import datetime, timezone
base = datetime.fromisoformat(FROZEN_NOW)
cutoff = (
base.replace(tzinfo=timezone.utc) - timedelta(days=days)
).isoformat()
changes = db.execute(
"SELECT COUNT(*) FROM entries WHERE last_washed > ? AND status = 'active'",
(cutoff,),
).fetchone()[0]
promotions = db.execute(
"SELECT COUNT(*) FROM entries WHERE rock_status != 'washable' "
"AND last_washed > ? AND status = 'active'",
(cutoff,),
).fetchone()[0]
return {"counts": [changes, promotions], "out": out}
finally:
db.close()
def dc_freeze_direction(rows):
db = _fresh_db()
try:
for i, row in enumerate(rows):
_seed_row(
db,
i + 1,
f"direction row {i}",
status=row.get("status", "active"),
rock_status=row.get("rock_status", "washable"),
)
out = _dc.compute_drift_direction(db)
total = db.execute(
"SELECT COUNT(*) FROM entries WHERE status = 'active'"
).fetchone()[0]
established = db.execute(
"SELECT COUNT(*) FROM entries WHERE rock_status IN "
"('established', 'rock') AND status = 'active'"
).fetchone()[0]
rock = db.execute(
"SELECT COUNT(*) FROM entries WHERE rock_status = 'rock' "
"AND status = 'active'"
).fetchone()[0]
return {"counts": [total, established, rock], "out": out}
finally:
db.close()
def dc_freeze_gate(entry_id):
db = _fresh_db()
try:
return _dc.pre_commit_gate(db, entry_id)
finally:
db.close()
def dc_freeze_ms_core():
return _dc._ms_core() is not None
_dc.dc_freeze_promote = dc_freeze_promote
_dc.dc_freeze_fama = dc_freeze_fama
_dc.dc_freeze_velocity = dc_freeze_velocity
_dc.dc_freeze_direction = dc_freeze_direction
_dc.dc_freeze_gate = dc_freeze_gate
_dc.dc_freeze_ms_core = dc_freeze_ms_core
# Loud failure law: the eligible-path rows delegate to the memory_scoring
# kernel (its Python oracle is retired and raises); determinism requires
# the built .so.
from rune import ms_loader # noqa: E402
if not ms_loader.available():
raise SystemExit(
"dc_freeze_seams: memory_scoring kernel not built — run "
"cargo build --release in src/rust/memory_scoring first "
"(the Python oracle was retired; eligible-path rows need it)"
)
+5 -1
View File
@@ -173,6 +173,10 @@ def module_to_keys(module_stem: str) -> list[str]:
"curator": ["curator-core"],
"token_counting": ["cognition-token", "cognition"],
"query_memory": ["cognition-query", "cognition"],
# drift_compression's kernels live in the memory_scoring crate
# (H3 slice 2 + the stats kernel): the live delegation chain is
# drift_compression → drift_core._ms_core → ms_loader → .so.
"drift_compression": ["memory_scoring"],
}
if module_stem in aliases:
keys = aliases[module_stem] + keys
@@ -180,7 +184,7 @@ def module_to_keys(module_stem: str) -> list[str]:
if module_stem in {
"tier_manager", "safety_override", "pins", "identity_anchors",
"abstraction", "growth_delta", "witness", "persona_gate",
"memory_consolidation", "drift_compression", "context_broker",
"memory_consolidation", "context_broker",
"persona_definition", "goal",
}:
keys.append("cognition_core")
+204
View File
@@ -0,0 +1,204 @@
"""eb_freeze_seams — sitecustomize rig for freezing event_bus truth.
Auto-imported on interpreter start (PYTHONPATH=scripts/eb_freeze_seams:src)
by BOTH the truth generator (scripts/gen_event_bus_truth.py) and the
shared harness's --verify mode, so frozen truth is byte-reproducible in any
process (dichotomy wave #2479 gap close, contract factory-gap-eb):
* datetime.datetime is FROZEN to EB_FROZEN_NOW — the oracle stamps the
envelope timestamp through rune.orchestration.records._now (a bound
import the module-level pin cannot reach). The class patch runs before
either module imports.
* uuid.uuid4 is a deterministic counter (ee_freeze_seams precedent) —
records.new_id mints "evt_" + uuid4().hex[:12]. The counter RESETS per
seam call so a case's ids depend only on the mints inside it.
* RUNE_MEMORY_DIR is pinned to a hermetic mkdtemp sandbox BEFORE
rune.event_bus imports — journal writes never touch the repo, and
event_bus.EVENT_LOG (an import-time constant) resolves to the sandbox.
* The seam wrappers (eb_store_path, eb_event_types, eb_content_hash,
eb_emit, eb_emit_line, eb_log, eb_log_corrupt, eb_stats,
eb_handle_hook, eb_main) are bound onto rune.event_bus so the shared
harness's getattr(module, fn) freezes the event-bus surface: each one
runs the REAL oracle fns and returns JSON-safe snapshots (journal
replays, captured journal line bytes, captured CLI stdout, and the
loud ValueError message-only contract).
* Machine paths never enter truth: absolute roots are normalized to
EB_SANDBOX / EB_HOME / REPO_ROOT placeholders (paths quirk law).
"""
import contextlib # noqa: E402
import io # noqa: E402
import itertools # noqa: E402
import os # noqa: E402
import sys # noqa: E402
import tempfile # noqa: E402
import uuid as _uuid # noqa: E402
_REPO = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
sys.path.insert(0, os.path.join(_REPO, "scripts"))
sys.path.insert(0, os.path.join(_REPO, "src"))
from freeze_rigs import pin_clock # noqa: E402
# EB_FROZEN_NOW: the pinned instant every clock site reports.
FROZEN_NOW = "2026-10-14T11:22:33.123456+00:00"
pin_clock(FROZEN_NOW)
_MINT = itertools.count(1)
class _DetUUID:
"""uuid4() stand-in whose .hex (records.new_id) and str() (legacy
default_factory) are pure functions of the counter."""
def __init__(self, n: int):
self.hex = f"{n:032x}"
self.int = int(self.hex, 16)
def __str__(self):
h = self.hex
return f"{h[:8]}-{h[8:12]}-{h[12:16]}-{h[16:20]}-{h[20:]}"
def _reset_mint():
global _MINT
_MINT = itertools.count(1)
_uuid.uuid4 = lambda: _DetUUID(next(_MINT)) # type: ignore[assignment]
# Hermetic journal sandbox BEFORE rune.event_bus imports — EVENT_LOG is an
# import-time constant (os.path.join(memory_dir(), ...)), so the env pin
# must precede the import. The sandbox path itself never enters truth.
_SANDBOX = tempfile.mkdtemp(prefix="eb-freeze-mem-")
os.environ["RUNE_MEMORY_DIR"] = _SANDBOX
import rune.event_bus as eb # noqa: E402 (after the clock + uuid + env pins)
# The three seed events (the legacy suite's a/a/b shape): ids ride the
# counter (1..3 -> flattened evt_000000000000), types/types order pinned.
SEEDS = [
("user.message", "user", {"text": "hi"}),
("tool.result", "", None),
("user.message", "user", {"n": 1}),
]
def _seed():
for t, src, payload in SEEDS:
eb.emit(t, source=src, payload=payload)
def _normalize(p) -> str:
s = str(p)
s = s.replace(_SANDBOX, "EB_SANDBOX")
home = os.environ.get("EB_FREEZE_HOME", "")
if home:
s = s.replace(home, "EB_HOME")
s = s.replace(_REPO, "REPO_ROOT")
return s
def _clear_journal():
p = eb._store_path()
if p.exists():
p.unlink()
def eb_store_path():
return _normalize(eb._store_path())
def eb_event_types():
return dict(eb.EVENT_TYPES)
def eb_content_hash(payload):
return eb._content_hash(payload)
def eb_emit(event_type, source="", payload=None):
_reset_mint()
_clear_journal()
try:
d = eb.emit(event_type, source=source, payload=payload)
except ValueError as e:
return {"error": "ValueError", "message": str(e), "journal": eb.log()}
return {"emitted": d, "journal": eb.log()}
def eb_emit_line(event_type, source="", payload=None):
_reset_mint()
_clear_journal()
eb.emit(event_type, source=source, payload=payload)
return eb._store_path().read_text()
def eb_log(limit=None, event_type=None):
_reset_mint()
_clear_journal()
_seed()
return {"rows": eb.log(limit=limit, event_type=event_type)}
def eb_log_corrupt():
_reset_mint()
_clear_journal()
p = eb._store_path()
p.parent.mkdir(parents=True, exist_ok=True)
p.write_text("not json\n")
try:
eb.log()
return {"error": None}
except RuntimeError as e:
return {"error": "RuntimeError", "message": str(e)}
def eb_stats():
_reset_mint()
_clear_journal()
_seed()
total, by_type = eb.stats()
return {"total": total, "by_type": by_type}
def eb_handle_hook(event, data=None):
_reset_mint()
_clear_journal()
try:
r = eb.handle_hook(event, data)
except ValueError as e:
return {"hook": {"error": "ValueError", "message": str(e)}}
return {"hook": r, "journal": eb.log()}
def eb_main(argv, seed=False):
_reset_mint()
_clear_journal()
if seed:
_seed()
old = sys.argv
buf = io.StringIO()
code = 0
try:
sys.argv = list(argv)
with contextlib.redirect_stdout(buf):
eb.main()
except SystemExit as e:
code = e.code if isinstance(e.code, int) else 0
finally:
sys.argv = old
return {"stdout": buf.getvalue(), "exit": code}
eb.eb_store_path = eb_store_path
eb.eb_event_types = eb_event_types
eb.eb_content_hash = eb_content_hash
eb.eb_emit = eb_emit
eb.eb_emit_line = eb_emit_line
eb.eb_log = eb_log
eb.eb_log_corrupt = eb_log_corrupt
eb.eb_stats = eb_stats
eb.eb_handle_hook = eb_handle_hook
eb.eb_main = eb_main
eb.EB_SANDBOX = _SANDBOX
+127
View File
@@ -0,0 +1,127 @@
"""ee_freeze_seams — sitecustomize rig for freezing event_envelope truth.
Auto-imported on interpreter start (PYTHONPATH=scripts/ee_freeze_seams:src)
by BOTH the truth generator (scripts/gen_event_envelope_truth.py) and the
shared harness's --verify mode, so frozen truth is byte-reproducible in any
process (dichotomy wave #2479 gap port, contract factory-gap-ee):
* datetime.datetime is FROZEN to EE_FROZEN_NOW — the oracle stamps
timestamps at TWO clock sites the shared harness's module pin cannot
both reach: the legacy default_factory
(datetime.now(timezone.utc).isoformat()) and the canonical bridge
(rune.orchestration.records._now, bound import). The class patch
below runs before either module imports.
* uuid.uuid4 is a deterministic counter (ci_freeze_seams precedent) —
records.new_id mints "evt_" + uuid4().hex[:12] and the legacy
default_factory mints str(uuid4()). The counter RESETS per seam
helper call so a case's ids depend only on how many mints happen
inside it.
* The module seams (ee_create, ee_create_envelope, ee_to_dict,
ee_to_canonical_dict, ee_to_canonical_dict_unbridged,
ee_test_envelope) are bound onto rune.event_envelope so the shared
harness's getattr(module, fn) can freeze method/classmethod surface:
wrappers run the REAL oracle fns and return JSON-safe asdicts (or
the captured RuntimeError message / stdout bytes for the
loud-failure and print paths).
"""
import contextlib # noqa: E402
import io # noqa: E402
import itertools # noqa: E402
import os # noqa: E402
import sys # noqa: E402
import uuid as _uuid # noqa: E402
from dataclasses import asdict # noqa: E402
_REPO = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
sys.path.insert(0, os.path.join(_REPO, "scripts"))
sys.path.insert(0, os.path.join(_REPO, "src"))
from freeze_rigs import pin_clock # noqa: E402
# EE_FROZEN_NOW: the pinned instant every clock site reports.
FROZEN_NOW = "2026-10-14T11:22:33.123456+00:00"
pin_clock(FROZEN_NOW)
_MINT = itertools.count(1)
class _DetUUID:
"""uuid4() stand-in whose .hex (records.new_id) and str() (legacy
default_factory) are pure functions of the counter."""
def __init__(self, n: int):
self.hex = f"{n:032x}"
self.int = int(self.hex, 16)
def __str__(self):
h = self.hex
return f"{h[:8]}-{h[8:12]}-{h[12:16]}-{h[16:20]}-{h[20:]}"
def _reset_mint():
global _MINT
_MINT = itertools.count(1)
_uuid.uuid4 = lambda: _DetUUID(next(_MINT)) # type: ignore[assignment]
import rune.event_envelope as _ee # noqa: E402 (after the clock + uuid pins)
def ee_channels():
return _ee.CHANNELS
def ee_authority_classes():
return _ee.AUTHORITY_CLASSES
def ee_create(source, channel, payload):
_reset_mint()
return asdict(_ee.EventEnvelope.create(source, channel, payload))
def ee_create_envelope(source, channel, payload, authority_class=None,
task_id=None, urgency=None):
_reset_mint()
return asdict(_ee.create_envelope(source, channel, payload,
authority_class, task_id, urgency))
def ee_to_dict(state):
# state carries EVERY legacy field explicitly — no default mints, so
# the row is deterministic without a counter reset.
return _ee.EventEnvelope(**state).to_dict()
def ee_to_canonical_dict(source, channel, payload):
_reset_mint()
return _ee.EventEnvelope.create(source, channel, payload).to_canonical_dict()
def ee_to_canonical_dict_unbridged(state):
env = _ee.EventEnvelope(**state)
try:
env.to_canonical_dict()
return {"error": None}
except RuntimeError as e:
return {"error": "RuntimeError", "message": str(e)}
def ee_test_envelope():
_reset_mint()
buf = io.StringIO()
with contextlib.redirect_stdout(buf):
_ee.test_envelope()
return buf.getvalue()
_ee.ee_channels = ee_channels
_ee.ee_authority_classes = ee_authority_classes
_ee.ee_create = ee_create
_ee.ee_create_envelope = ee_create_envelope
_ee.ee_to_dict = ee_to_dict
_ee.ee_to_canonical_dict = ee_to_canonical_dict
_ee.ee_to_canonical_dict_unbridged = ee_to_canonical_dict_unbridged
_ee.ee_test_envelope = ee_test_envelope
+80
View File
@@ -0,0 +1,80 @@
#!/bin/bash
# factory_status.sh — the factory at a glance. Run directly, or in a
# second terminal: watch -n 30 --color bash /mnt/workdrive/rune/scripts/factory_status.sh
# Everything here is READ-ONLY (git + file mtimes + claims + audit).
REPO=/mnt/workdrive/rune
cd "$REPO" || exit 1
B='\033[1m'; D='\033[2m'; G='\033[32m'; Y='\033[33m'; R='\033[31m'; C='\033[36m'; N='\033[0m'
now_epoch=$(date +%s)
echo -e "${B}═════════════════ RUNE FACTORY — LIVE STATUS ═════════════════${N} $(date '+%H:%M:%S')"
# ── headline ────────────────────────────────────────────────────────────
git fetch gitea -q 2>/dev/null
HEADLINE=$(python3 scripts/dichotomy_audit.py 2>/dev/null | head -1)
GATE=$(bash scripts/factory_spawn_gate.sh 2>/dev/null | head -1)
ACTIVE=$(echo "$GATE" | grep -oE 'active=[0-9]+' | cut -d= -f2)
UNVER=$(echo "$GATE" | grep -oE 'unverified=[0-9]+' | cut -d= -f2)
LAND=$(python3 -c "import json; c=json.load(open('docs/factory-claims.json')); print(len(c['landed']))")
INFL=$(python3 -c "import json; c=json.load(open('docs/factory-claims.json')); print(len(c['in_flight']))")
LAST_CLOSE=$(git log gitea/master --format='%cr — %s' --grep='chore(store): close' -1 2>/dev/null | head -c 100)
echo -e " ${C}$HEADLINE${N}"
echo -e " ${GATE} claims: ${G}${LAND} landed${N} / ${Y}${INFL} in-flight${N}"
echo -e " last landing: ${D}${LAST_CLOSE}${N}"
# ── lanes: one line per worktree ────────────────────────────────────────
echo -e "\n${B}── LANES ──${N}"
printf " ${B}%-16s %-24s %-10s %-9s %-8s %s${N}\n" "WORKTREE" "MODULE" "ACTIVITY" "DIRTY" "AHEAD" "HEAD"
for wt in /mnt/workdrive/rune-wave-*; do
[ -d "$wt" ] || continue
name=$(basename "$wt" | sed 's/rune-wave-//')
wname=$(basename "$wt")
mod=$(python3 -c "
import json
c = json.load(open('docs/factory-claims.json'))
for m, w in c['in_flight'].items():
if w.split()[0] in ('$wt', '$wname'): print(m); break
" 2>/dev/null)
[ -z "$mod" ] && mod="-"
# newest file mtime = work signal
newest=$(find "$wt/src" "$wt/scripts" -type f -newer "$wt/go.mod" -printf '%T@\n' 2>/dev/null | sort -rn | head -1 | cut -d. -f1)
if [ -n "$newest" ] && [ "$((now_epoch - newest))" -lt 300 ]; then
act="${G}● writing${N}"
elif [ -n "$newest" ] && [ "$((now_epoch - newest))" -lt 3600 ]; then
act="${Y}● $(( (now_epoch - newest) / 60 ))m ago${N}"
else
act="${D}○ idle${N}"
fi
dirty=$(git -C "$wt" status --porcelain 2>/dev/null | wc -l | tr -d ' ')
ahead=$(git -C "$wt" rev-list --count gitea/master..HEAD 2>/dev/null)
hsha=$(git -C "$wt" log --oneline -1 --format='%h' 2>/dev/null)
printf " %-16s %-24s %-20b %-9s %-8s %s\n" "$name" "$mod" "$act" "$dirty" "$ahead" "$hsha"
done
# ── recent master movement ─────────────────────────────────────────────
echo -e "\n${B}── MASTER (last 5) ──${N}"
git log gitea/master --oneline -5 2>/dev/null | while read -r line; do echo -e " ${D}${line}${N}"; done
# ── landings awaiting verification ──────────────────────────────────────
PENDING=$(python3 - <<'EOF' 2>/dev/null
import json, subprocess
c = json.load(open('docs/factory-claims.json'))
landed = set(c['landed'])
out = subprocess.run(['git','log','gitea/master','--format','%s','-200'],capture_output=True,text=True).stdout
import re
pend = []
for line in out.splitlines():
m = re.search(r'chore\(store\): close ([a-z_]+) dichotomy contract', line)
if m and m.group(1) not in landed:
pend.append(m.group(1))
print(', '.join(dict.fromkeys(pend)) if pend else '')
EOF
)
if [ -n "$PENDING" ]; then
echo -e "\n${Y}── CLOSES AWAITING VERIFICATION: $PENDING ──${N}"
fi
echo
+22 -4
View File
@@ -11,6 +11,7 @@ set -u
SHA="$1"
CRATE="$2"
LANG_="${3:-rust}"
FACADE_OVERRIDE="${4:-}"
REPO=/mnt/workdrive/rune
PASS=0; FAIL=0
@@ -48,7 +49,7 @@ fi
# Layer 3: truth file exists and is consumed (path made ABSOLUTE here —
# later layers run from the repo root, a relative path breaks 7e's read)
TRUTH=$(find . \( -name "frozen_*_truth.json" -o -name "frozen_truth.json" -o -name "frozen_*_truth.json" -o -name "truth.json" -o -name "truth_*.json" \) 2>/dev/null | head -1)
TRUTH=$(find . \( -name "frozen_*_truth.json" -o -name "frozen_truth.json" -o -name "*_truth.json" -o -name "truth.json" -o -name "truth_*.json" -o -name "ct_*.json" \) 2>/dev/null | head -1)
[ -n "$TRUTH" ] && TRUTH="$(pwd)/${TRUTH#./}"
if [ -n "$TRUTH" ]; then
ROWS=$(python3 -c "import json; d=json.load(open('$TRUTH')); print(len(d) if isinstance(d,list) else sum(len(v) if isinstance(v,list) else 0 for v in d.values()))" 2>/dev/null)
@@ -83,6 +84,12 @@ MOD=$(basename "$CRATE" | tr '-' '_') # crate dir -> module stem
STEM="${MOD%_loader}"; STEM="${STEM%-loader}"
LOADER="src/rune/${STEM}_loader.py"
FACADE="src/rune/${STEM}.py"
# Shared-kernel crates (cognition_core hosts many modules' kernels) have
# NO 1:1 facade — pass it explicitly as $4 (e.g. src/rune/safety_override.py).
if [ -n "$FACADE_OVERRIDE" ]; then
FACADE="$FACADE_OVERRIDE"
echo " [INFO] facade override: $FACADE (shared-kernel crate)"
fi
# 7a/7b: connection completeness. Language-dependent law:
# RUST — facade delegates through a ctypes *_loader.py (doc-envelope FFI).
# GO — Go kernels are services/binaries by verdict; the facade keeps
@@ -92,17 +99,28 @@ CRATE_DIR="$CRATE"
if [ "$LANG_" = "rust" ]; then
# 7a: loader exists — discovered from the facade's own import (loader
# naming uses abbreviated stems: subsystem_health -> sh_loader).
# REPLAY-SURFACE crates (ci_replay-style: the facade consumes the
# kernel through battery/CLI evidence, not a ctypes loader) are
# legitimate without a loader import — the kernel FFI surface + truth
# reference IS the connection proof.
LOADER_REF=$(grep -oE "[a-z0-9]+_loader" "$FACADE" 2>/dev/null | head -1)
KERNEL_FFI=$(grep -rlE 'pub extern "C" fn' "$CRATE_DIR" --include='*.rs' 2>/dev/null | head -1)
if [ -n "$LOADER_REF" ] && [ -f "src/rune/${LOADER_REF}.py" ]; then
check "PASS" "7a loader exists: src/rune/${LOADER_REF}.py (per facade import)"
elif [ -n "$KERNEL_FFI" ] && grep -qE 'include_str!.*truth|truth[_./-]' "$CRATE_DIR" --include='*.rs' -r 2>/dev/null; then
check "PASS" "7a replay-surface crate: kernel FFI + truth battery (no loader by design)"
elif [ -f "$FACADE" ] && ! grep -qE "import.*_loader|from.*_loader" "$FACADE"; then
check "FAIL" "7a facade imports no loader"
check "FAIL" "7a facade imports no loader and crate has no kernel FFI"
else
check "FAIL" "7a loader referenced as $LOADER_REF but file missing"
fi
# 7b: facade delegation wired (core-selection seam)
# 7b: facade delegation wired (core-selection seam). Replay-surface
# crates pass 7a via kernel FFI — their 7b is the same evidence: the
# crate's battery replays frozen truth through the kernel surface.
if [ -f "$FACADE" ] && grep -qE "RUNE_[A-Z_]+_CORE|_loader" "$FACADE" 2>/dev/null; then
check "PASS" "7b facade has core-selection seam"
elif [ -n "$KERNEL_FFI" ]; then
check "PASS" "7b replay-surface: battery replays truth through kernel FFI"
else
check "FAIL" "7b facade not wired to implementation"
fi
@@ -149,7 +167,7 @@ def count(o):
return sum(count(v) for v in o.values())
return 0
total = 0
for t in glob.glob('$CRATE_DIR/truth*.json') + glob.glob('$CRATE_DIR/frozen*truth*.json') + glob.glob('$CRATE_DIR/src/frozen*truth*.json') + glob.glob('$CRATE_DIR/src/truth*.json'):
for t in glob.glob('$CRATE_DIR/truth*.json') + glob.glob('$CRATE_DIR/frozen*truth*.json') + glob.glob('$CRATE_DIR/*_truth.json') + glob.glob('$CRATE_DIR/ct_*.json') + glob.glob('$CRATE_DIR/src/frozen*truth*.json') + glob.glob('$CRATE_DIR/src/truth*.json') + glob.glob('$CRATE_DIR/src/*_truth.json') + glob.glob('$CRATE_DIR/src/ct_*.json'):
try:
total += count(json.load(open(t)))
except Exception:
+7 -1
View File
@@ -126,9 +126,15 @@ def _rebuild_receiver(mod, recv: dict):
def _out(value):
"""JSON-safe outward snapshot: dataclass instances → asdict."""
"""JSON-safe outward snapshot: dataclass instances → asdict, recursing
through lists/dicts (receivers whose attrs carry lists of dataclasses —
e.g. StageContract.ready_when — serialize instead of crashing)."""
if dataclasses.is_dataclass(value) and not isinstance(value, type):
return dataclasses.asdict(value)
if isinstance(value, list):
return [_out(v) for v in value]
if isinstance(value, dict):
return {k: _out(v) for k, v in value.items()}
return copy.deepcopy(value)
+133 -19
View File
@@ -1,27 +1,40 @@
#!/usr/bin/env python3
"""Freeze behavior oracle truth for the Rust port battery
(dichotomy wave #2479 tranche, batch: behavior).
(dichotomy wave #2479 tranche, batch: behavior; gap-close pass).
behavior.py's decision surface (9 public fns):
behavior.py's decision surface (14 fns):
connect, add_correction, add_habit, match_context, reinforce,
list_items, behavior_stats, main (CLI — not frozen; argparse/IO),
PLUGIN (data — embedded verbatim in the crate).
_reinforce_rust, _reinforce_python, _correction_matches_python,
_habit_matches_python, _bh_core, list_items, behavior_stats,
main (CLI — not frozen; argparse/IO), PLUGIN (data — embedded
verbatim in the crate).
The decision math (reinforce counting/confidence/promotion/state) is
served IN-PROCESS by the Rust evidence_provenance cdylib through
ep_loader — the oracle IS the strangler shim. The frozen truth pins
RUNE_BEHAVIOR_CORE=python (no-op today; the POISONED-TRUTH LAW: a
future delegating facade must never silently record kernel output as
oracle truth).
RUNE_BEHAVIOR_CORE=python (the POISONED-TRUTH LAW: a future delegating
facade must never silently record kernel output as oracle truth).
Frozen: add_correction/add_habit return shapes, match_context branch
matrix (pattern/domain/confidence/match_type/invalid-regex), reinforce
branch matrix (habit/correction x success/failure/neutral x
promotion/archival/not-found), list_items filters+limits, stats
counts. SQLite rows replayed as dicts (row_factory=Row -> dict(c)).
matrix (pattern/domain/confidence/match_type/invalid-regex), the
python-pin predicate matrix (every row × context through
_correction_matches_python/_habit_matches_python), reinforce branch
matrix (habit/correction x success/failure/neutral x
promotion/archival/not-found, WITH pre-rows), list_items filters+
limits+FULL row outputs, stats counts + the row collections they count,
connect's schema (sqlite_master DDL, creation order), the _bh_core pin
probe. SQLite rows replayed as dicts (row_factory=Row -> dict(c)).
Output: /tmp/behavior_truth.json — replayed VERBATIM by
src/rust/behavior/src/branch_battery.rs.
Clock law: RUNE_FROZEN_NOW pins behavior.datetime (the freeze_truth
harness clock) — every created_at/last_reinforced/last_activated in the
corpus is frozen, so regeneration is byte-identical and the battery
replays timestamps VERBATIM.
Outputs:
/tmp/behavior_truth.json — replayed VERBATIM by
src/rust/behavior/src/branch_battery.rs
src/rust/behavior/bh_pure_truth.json — freeze_truth-envelope corpus
(pure-fn cases; byte-verified via freeze_truth.py --verify)
"""
from __future__ import annotations
@@ -33,14 +46,24 @@ from pathlib import Path
os.environ["RUNE_BEHAVIOR_CORE"] = "python" # freeze the ORACLE, never the kernel
FROZEN_NOW = "2026-10-13T00:00:00"
os.environ["RUNE_FROZEN_NOW"] = FROZEN_NOW
_tmp = tempfile.mkdtemp(prefix="bh-truth-")
os.environ["RUNE_HOME"] = _tmp
os.environ["RUNE_MEMORY_DIR"] = os.path.join(_tmp, "memory")
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "src"))
sys.path.insert(0, str(Path(__file__).resolve().parent))
import freeze_truth # noqa: E402 (shared harness: clock pin + envelope)
from rune import behavior as bh # noqa: E402
freeze_truth._pin_clock(bh) # behavior.datetime -> frozen clock
CRATE = Path(__file__).resolve().parents[1] / "src" / "rust" / "behavior"
def row(table, rid):
db = bh.connect()
@@ -114,19 +137,47 @@ cases["match"].append(match_case("habit-regex-hit", "run the unit tests"))
cases["match"].append(match_case("low-conf-filtered", "zzz-no-match-ever quiet"))
cases["match"].append(match_case("bad-regex-skipped", "([unclosed anything"))
# ── python-pin predicate matrix (gap-close surface) ───────────────────
# Every correction/habit row present at match time × every match
# context, through the INLINE oracle predicates — the verbatim replay
# corpus for _correction_matches_python / _habit_matches_python.
MATCH_CONTEXTS = [
"deploy to shell now", "deploy the editor", "unrelated chatter here",
"run the unit tests", "zzz-no-match-ever quiet", "([unclosed anything",
]
_db = bh.connect()
_corr_rows = [dict(r) for r in _db.execute("SELECT * FROM corrections").fetchall()]
_habit_rows = [dict(r) for r in _db.execute("SELECT * FROM habits").fetchall()]
_db.close()
cases["predicates"] = {
"corrections": [
{"context": ctx, "row": dict(c), "context_low": ctx.lower(),
"matched": bh._correction_matches_python(dict(c), ctx, ctx.lower())}
for ctx in MATCH_CONTEXTS for c in _corr_rows
],
"habits": [
{"context": ctx, "row": dict(h),
"matched": bh._habit_matches_python(dict(h), ctx)}
for ctx in MATCH_CONTEXTS for h in _habit_rows
],
}
# ── reinforce matrix ──────────────────────────────────────────────────
def reinf_case(name, item_type, outcome, seed_fn, pre=None, n=1):
rid = seed_fn()["added"]
table = "habits" if item_type == "habit" else "corrections"
if pre:
db = bh.connect()
for k, v in pre.items():
db.execute(f"UPDATE {'habits' if item_type == 'habit' else 'corrections'} SET {k}=? WHERE id=?", (v, rid))
db.execute(f"UPDATE {table} SET {k}=? WHERE id=?", (v, rid))
db.commit()
db.close()
pre_row = row(table, rid)
outs = [bh.reinforce(rid, outcome, item_type=item_type) for _ in range(n)]
return {"name": name, "item_type": item_type, "outcome": outcome,
"pre": pre or {}, "n": n, "results": outs,
"final_row": row("habits" if item_type == "habit" else "corrections", rid)}
"pre": pre or {}, "n": n, "pre_row": pre_row,
"results": outs,
"final_row": row(table, rid)}
cases["reinforce_habit"].append(reinf_case(
@@ -159,12 +210,12 @@ cases["reinforce_correction"].append(reinf_case(
lambda: bh.add_correction("x5", "y5"), n=1))
cases["reinforce_habit"].append(
{"name": "habit-not-found", "item_type": "habit", "outcome": "success",
"pre": {}, "n": 1,
"pre": {}, "n": 1, "pre_row": None,
"results": [bh.reinforce(99991, "success", item_type="habit")],
"final_row": None})
cases["reinforce_correction"].append(
{"name": "correction-not-found", "item_type": "correction",
"outcome": "success", "pre": {}, "n": 1,
"outcome": "success", "pre": {}, "n": 1, "pre_row": None,
"results": [bh.reinforce(99992, "success", item_type="correction")],
"final_row": None})
@@ -183,14 +234,77 @@ cases["list"].append({"name": "limit-1", "n_corr": len(got.get("corrections", []
# ── stats ─────────────────────────────────────────────────────────────
cases["stats"].append({"name": "counts", "expected": bh.behavior_stats()})
# ── gap-close surfaces: tie pin, full rows, list/stats replay ────────
# Tie law: two lowest-id corrections share the top confidence — SQLite
# returns rowid order for equal ORDER BY keys; the port's stable sort
# must reproduce it (pinned here, not assumed).
db = bh.connect()
db.execute("UPDATE corrections SET confidence=0.85 WHERE id=(SELECT MIN(id) FROM corrections)")
db.execute("UPDATE corrections SET confidence=0.85 WHERE id=(SELECT MIN(id) FROM corrections WHERE id > (SELECT MIN(id) FROM corrections))")
db.commit()
db.close()
_dump_db = bh.connect()
_all_corrections = [dict(r) for r in _dump_db.execute("SELECT * FROM corrections ORDER BY id").fetchall()]
_all_habits = [dict(r) for r in _dump_db.execute("SELECT * FROM habits ORDER BY id").fetchall()]
_n_activations = _dump_db.execute("SELECT COUNT(*) FROM habit_activations").fetchone()[0]
_dump_db.close()
cases["list_full"] = []
for t, lim in [("all", 20), ("correction", 20), ("habit", 20), ("all", 1), ("all", 3)]:
got = bh.list_items(item_type=t, limit=lim)
cases["list_full"].append({
"name": f"{t}-limit{lim}", "item_type": t, "limit": lim,
"result": json.loads(json.dumps(got))})
cases["stats_full"] = {
"corrections": json.loads(json.dumps(_all_corrections)),
"habits": json.loads(json.dumps(_all_habits)),
"activations": _n_activations,
"stats": bh.behavior_stats(),
}
# ── connect (schema as sqlite stores it) + the _bh_core pin probe ────
db = bh.connect()
cases["connect"] = {
"journal_mode": db.execute("PRAGMA journal_mode").fetchone()[0],
"schema": [
{"kind": r["type"], "name": r["name"], "sql": r["sql"]}
for r in db.execute(
"SELECT type, name, sql FROM sqlite_master "
"WHERE sql IS NOT NULL AND name NOT LIKE 'sqlite_%'").fetchall()],
}
db.close()
cases["core_probe"] = {"runes_behavior_core_env": os.environ["RUNE_BEHAVIOR_CORE"],
"core": bh._bh_core()}
truth = {"frozen": "behavior decision surface (reinforce math via ep strangler shim)",
"frozen_now": FROZEN_NOW,
"oracle": "src/rune/behavior.py",
"cases": cases,
"plugin": bh.PLUGIN}
out = Path("/tmp/behavior_truth.json")
out.write_text(json.dumps(truth, indent=1, default=str) + "\n")
# ── freeze_truth-envelope corpus: the PURE fn surface ────────────────
# (predicates over row dicts + reinforce not-found envelopes + the
# _bh_core pin probe — byte-verified via freeze_truth.py --verify)
pure_cases = []
for ctx in MATCH_CONTEXTS:
for c in _corr_rows:
pure_cases.append(("_correction_matches_python", (dict(c), ctx, ctx.lower()), {}))
for h in _habit_rows:
pure_cases.append(("_habit_matches_python", (dict(h), ctx), {}))
pure_cases.append(("reinforce", (99991, "success"), {"item_type": "habit"}))
pure_cases.append(("reinforce", (99992, "success"), {"item_type": "correction"}))
pure_cases.append(("_bh_core", (), {}))
pure_truth = freeze_truth.freeze("rune.behavior", pure_cases, oracle_module="rune.behavior")
freeze_truth.write_envelope(FROZEN_NOW, pure_truth, CRATE / "bh_pure_truth.json")
n = (len(cases["add_correction"]) + len(cases["add_habit"]) + len(cases["match"])
+ len(cases["reinforce_habit"]) + len(cases["reinforce_correction"])
+ len(cases["list"]) + len(cases["stats"]))
print(f"froze {n} cases -> {out}")
print(f"froze {n} cases + {len(cases['predicates']['corrections'])}+"
f"{len(cases['predicates']['habits'])} predicate rows + "
f"{len(cases['list_full'])} full lists -> {out}")
print(f"froze {len(pure_truth)} pure cases -> {CRATE / 'bh_pure_truth.json'}")
+94
View File
@@ -0,0 +1,94 @@
#!/usr/bin/env python3
"""gen_builder_bridge_cli_truth.py — freeze the builder_bridge_cli parity
oracle (dichotomy wave #2479, GO verdict).
The module is a CLI (argv → stdout), so truth is frozen by RUNNING the
live Python oracle as a subprocess per case under pinned seams — the
oracle's own degrade paths make the surface deterministic:
* RUNE_MEMORY_DIR → fresh empty dir (selector unavailable → no memory
lines; the same degrade the oracle takes in any selector failure)
* RUNE_CONSTRUCTION_STORE → fresh empty dir (no active contract → no
construction lines)
* BBC_FROZEN_NOW via scripts/bbc_freeze_seams/sitecustomize.py — the
wall clock pinned before import (generated_at in --json output)
* BUILDER_BRIDGE_REPO → this checkout (sys.path bootstrap target)
* deep-copied argv per case; every CLI branch exercised (no-args,
join/strip semantics, --json as argv[1] exactly, --json as task
text, all three routes, floor + not-grounded constraints, test-
surface verifiability, inspection verbs)
Output: src/go/builder-bridge-cli/truth.json — [{"id", "args",
"frozen_now", "stdout", "exit"}...] — replayed VERBATIM by the module's
truth_test.go and byte-compared in live parity.
Byte-determinism: fixed frozen_now, fixed argv literals, fresh-but-empty
degrade dirs — re-running regenerates a byte-identical file.
"""
import json
import os
import subprocess
import sys
import tempfile
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
FROZEN_NOW = "2026-10-14T09:00:00+00:00"
CASES = [
{"id": "no_args", "args": []},
{"id": "local_fix_typo", "args": ["fix", "the", "typo", "in", "scripts/foo.py"]},
{"id": "floor_trigger", "args": ["adopt", "a", "replacement", "architecture",
"for", "the", "memory", "subsystem"]},
{"id": "json_local_fix", "args": ["--json", "fix", "the", "typo", "in", "scripts/foo.py"]},
{"id": "json_floor", "args": ["--json", "adopt", "a", "replacement", "architecture"]},
{"id": "json_empty_task", "args": ["--json"]},
{"id": "mechanism_constraint", "args": ["measure", "the", "latency", "of",
"the", "parser", "under", "load"]},
{"id": "external_constraint", "args": ["integrate", "the", "payments", "api",
"service", "endpoint"]},
{"id": "json_as_task_text", "args": ["summarize", "--json", "fix"]},
{"id": "join_strip_inner_spaces", "args": [" ", "fix bug ", " "]},
{"id": "whitespace_only_task", "args": [" "]},
{"id": "test_surface_verifiable", "args": ["fix", "the", "crash", "in",
"parser.py", "covered", "by",
"tests/test_parser.py"]},
{"id": "inspection_verb_readonly", "args": ["review", "the", "cache", "module"]},
]
def run_oracle(args: list[str]) -> dict:
mem = tempfile.mkdtemp(prefix="bbc-truth-mem-")
constr = tempfile.mkdtemp(prefix="bbc-truth-constr-")
home = tempfile.mkdtemp(prefix="bbc-truth-home-")
env = dict(os.environ)
env.update({
"BUILDER_BRIDGE_REPO": str(ROOT),
"RUNE_MEMORY_DIR": mem,
"RUNE_CONSTRUCTION_STORE": constr,
# HOME isolation (pin_home law): the selector's shard sources read
# a HARDCODED ~/.config/opencode dir that ignores RUNE_* isolation
# (memory_selector P1-03 deviation note) — a fresh HOME makes every
# source degrade to [] hermetically.
"HOME": home,
"PYTHONPATH": str(ROOT / "scripts" / "bbc_freeze_seams"),
"REPO_ROOT": str(ROOT),
"BBC_FROZEN_NOW": FROZEN_NOW,
})
p = subprocess.run(
[sys.executable, str(ROOT / "src" / "rune" / "builder_bridge_cli.py"), *args],
capture_output=True, text=True, env=env, timeout=120,
)
return {"stdout": p.stdout, "exit": p.returncode}
if __name__ == "__main__":
truth = []
for case in CASES:
r = run_oracle(list(case["args"]))
truth.append({"id": case["id"], "args": case["args"],
"frozen_now": FROZEN_NOW,
"stdout": r["stdout"], "exit": r["exit"]})
print(f"{case['id']}: exit={r['exit']} stdout={r['stdout'][:60]!r}")
out = ROOT / "src" / "go" / "builder-bridge-cli" / "truth.json"
out.write_text(json.dumps(truth, indent=1, ensure_ascii=False) + "\n")
print(f"frozen {len(truth)} cases -> {out}")
+157
View File
@@ -0,0 +1,157 @@
#!/usr/bin/env python3
"""gen_builder_bridge_truth.py — shared-harness truth battery for the
builder_bridge gap closure (dichotomy wave, worktree rune-wave-cw).
Uses scripts/freeze_truth.py (the ONE truth law) to freeze
src/rune/builder_bridge.py behavior for the Go port at
src/go/builder-bridge:
* BuilderCapsule.to_dict / to_markdown — recv form, every branch:
defaults, the line caps (13 memory lines → 12, 7 lesson lines → 6),
the inject-nothing short-circuit, floor-only rendering, construction
projection rendering.
* _cache_key — whitespace collapse + case folding + unicode + empty.
* _validated_lessons_for — the PL1-empty contract (handoff §9).
* _retrieve_memory / _cached_memory — the degrade-safe abstention path
under the pinned-HOME rig (every selector source abstains on an
isolated HOME; fresh + cache-hit rows).
* _construction_store — the env-override branch, verbatim (the default
branch is __file__-derived and machine-absolute: live parity covers
it, frozen truth does not carry absolute paths).
* _active_construction_lines — the committed fixture store
(two open contracts pin observed_at ordering; scope caps at 8;
obligations count + first-3 kind rendering; need/next_action lines).
NOT frozen here (adaptive_router precedent: "cases whose oracle return
carries dataclass instances are exercised through their JSON-native
integration surface instead, and by the Go seam unit tests + live parity
sweep"): preflight returns a BuilderCapsule the harness cannot
JSON-serialize and stamps generated_at from an in-function datetime
import. scripts/check_builder_bridge_parity.py drives the LIVE oracle and
the Go binary across every branch with full to_dict + to_markdown
comparison under the frozen clock — that is its parity gate.
_default_selector / _get_selector return live selector instances (not
JSON-safe); their observable contract (non-None on this stack, lazy
singleton identity) is asserted by the same live parity sweep.
Rig (auto via PYTHONPATH=scripts/bb_freeze_seams — see
scripts/bb_freeze_seams/sitecustomize.py): pinned HOME/RUNE_HOME,
RUNE_MSE_CORE=python, RUNE_CONSTRUCTION_STORE=<repo>/src/go/
builder-bridge/fixtures/store_active (run from the repo root).
Verify (byte-identical law, from the repo root):
PYTHONPATH=scripts/bb_freeze_seams python3 scripts/freeze_truth.py \\
--verify src/go/builder-bridge/truth.json \\
--module rune.builder_bridge
"""
import os
import sys
from pathlib import Path
REPO = Path(__file__).resolve().parent.parent
sys.path.insert(0, str(REPO / "src"))
sys.path.insert(0, str(Path(__file__).resolve().parent))
FROZEN_NOW = "2026-10-13T11:00:00+00:00"
os.environ.setdefault("RUNE_FROZEN_NOW", FROZEN_NOW)
from freeze_truth import freeze, write_envelope # noqa: E402
def capsule_recv(**over):
state = {
"task_route": "",
"floor": False,
"unknowns": [],
"memory_lines": [],
"lesson_lines": [],
"constraints": [],
"construction_lines": [],
"generated_at": "",
"core_version": "rune-core/operator-path",
}
state.update(over)
return {"cls": "BuilderCapsule", **state}
def main():
memory13 = [f"memory line {i}" for i in range(13)]
lessons7 = [f"lesson {i}" for i in range(7)]
construction = [
"contract c-gap-fixture · phase building · status open · mode BUILD",
"project: issue161-harness",
"next action: commit the fix",
]
cases = [
# to_dict — defaults (the capsule's own field defaults)
{"fn": "BuilderCapsule.to_dict", "recv": capsule_recv(), "args": [], "kwargs": {}},
# to_dict — the caps: 13 memory lines → 12, 7 lesson lines → 6
{"fn": "BuilderCapsule.to_dict",
"recv": capsule_recv(task_route="STANDARD_CHANGE", floor=True,
unknowns=["verifiability"],
memory_lines=memory13, lesson_lines=lessons7,
constraints=["keep it bounded"],
construction_lines=construction,
generated_at="2026-10-13T11:00:00+00:00"),
"args": [], "kwargs": {}},
# to_dict — custom core_version passes through
{"fn": "BuilderCapsule.to_dict",
"recv": capsule_recv(task_route="LOCAL_FIX", core_version="rune-core/test"),
"args": [], "kwargs": {}},
# to_markdown — inject-nothing short-circuit (LOCAL_FIX, all empty)
{"fn": "BuilderCapsule.to_markdown",
"recv": capsule_recv(task_route="LOCAL_FIX"), "args": [], "kwargs": {}},
# to_markdown — STANDARD_CHANGE with nothing useful is ALSO silent
{"fn": "BuilderCapsule.to_markdown",
"recv": capsule_recv(task_route="STANDARD_CHANGE"), "args": [], "kwargs": {}},
# to_markdown — full rendering, every section
{"fn": "BuilderCapsule.to_markdown",
"recv": capsule_recv(task_route="RESEARCHED_CHANGE", floor=True,
unknowns=["external dependency"],
memory_lines=["mem one", "mem two"],
lesson_lines=["lesson one"],
constraints=["Deep-research floor: x"],
construction_lines=construction),
"args": [], "kwargs": {}},
# to_markdown — floor-only DEEP_RESEARCH renders the floor line
{"fn": "BuilderCapsule.to_markdown",
"recv": capsule_recv(task_route="DEEP_RESEARCH", floor=True),
"args": [], "kwargs": {}},
# to_markdown — unknowns-only still renders (not inject-nothing)
{"fn": "BuilderCapsule.to_markdown",
"recv": capsule_recv(task_route="LOCAL_FIX", unknowns=["verifiability"]),
"args": [], "kwargs": {}},
# to_markdown — construction projection renders for a LOCAL_FIX too
{"fn": "BuilderCapsule.to_markdown",
"recv": capsule_recv(task_route="LOCAL_FIX", construction_lines=construction),
"args": [], "kwargs": {}},
# _cache_key — collapse + fold + unicode + empty
("_cache_key", ("Fix the\tTELEMETRY\n summary",), {}),
("_cache_key", (" ünïcode tásk — with gaps ",), {}),
("_cache_key", ("",), {}),
("_cache_key", ("SIMPLE",), {}),
# _validated_lessons_for — empty until PL1 promotes a lesson
("_validated_lessons_for", ("fix the retry backoff",), {}),
# _retrieve_memory — degrade-safe abstention under the pinned rig
("_retrieve_memory", ("",), {}),
("_retrieve_memory", ("Fix typo in CLI help text",), {}),
("_retrieve_memory", ("Add the telemetry summary",), {}),
# _cached_memory — fresh miss then cache hit (both via the rig [])
("_cached_memory", ("Fix the telemetry summary log level",), {}),
("_cached_memory", ("fix THE TELEMETRY summary log level",), {}), # same cache key
("_cached_memory", ("a different task entirely",), {}),
# _construction_store — env override branch, verbatim
("_construction_store", (), {}),
# _active_construction_lines — the committed fixture store
("_active_construction_lines", (), {}),
]
truth = freeze("rune.builder_bridge", cases, oracle_module="rune.builder_bridge")
dest = REPO / "src/go/builder-bridge/truth.json"
write_envelope(FROZEN_NOW, truth, dest)
print(f"wrote {len(truth)} cases -> {dest}")
if __name__ == "__main__":
main()
+89
View File
@@ -0,0 +1,89 @@
#!/usr/bin/env python3
"""gen_cache_truth.py — cache dichotomy gap-close truth battery (shared
freeze_truth.py harness, live oracle, envelope format with pinned clock).
Every ported fn and every freezable branch: _now/_now_ts/_parse_ts
(frozen clock, garbage + None inputs), _hash, _compress, flush_stats
(normalizes the flush interval), put_cache (default/explicit compressed,
scope, source_hash, upsert resurrection), get_cache (hit, pending-
visible double-hit, true miss, invalidated miss), invalidate,
invalidate_scope, invalidate_all, cache_stats (rates, scopes), the
50-event flush threshold, and handle_hook (mapped event, zero-count
event, unmapped event).
NOT freezable here (no oracle fn can idle 30s): the 30s-interval flush
branch — pinned by the Python battery (monkeypatched time.monotonic)
and the Go battery (monotonic seam) instead.
RUNE_MEMORY_DIR is sandboxed to a throwaway BEFORE the oracle import
(DB_PATH is derived at import time).
"""
import os
import sys
import tempfile
from pathlib import Path
REPO = Path(__file__).resolve().parent.parent
_SBOX = tempfile.mkdtemp(prefix="freeze-cache-truth-")
os.environ["RUNE_MEMORY_DIR"] = _SBOX
sys.path.insert(0, str(REPO / "scripts"))
sys.path.insert(0, str(REPO / "src"))
from freeze_truth import freeze, write_envelope # noqa: E402
FROZEN_NOW = "2026-10-13T12:00:00+00:00" # microsecond 0 -> fraction-less isoformat
def main() -> int:
os.environ["RUNE_FROZEN_NOW"] = FROZEN_NOW
alpha = "Alpha full value line one\nAlpha line two"
beta = "Beta value for the retrieval scope"
gamma = "Gamma value for the warm digest scope"
uni = "Wörter value with ümlaut"
cases = [
("_now", (), {}),
("_now_ts", (), {}),
("_parse_ts", ("2026-10-13T12:00:00+00:00",), {}),
("_parse_ts", ("garbage",), {}),
("_parse_ts", (None,), {}),
("_hash", ("hello",), {}),
("_compress", ("# comment\n====\ndecorative line survives compression test\n(_source_: cite)\nab\n",), {}),
("flush_stats", (), {}),
("put_cache", ("alpha", alpha), {}),
("put_cache", ("beta", beta), {"scope": "retrieval", "source_hash": "src-1"}),
("put_cache", ("gamma", gamma), {"scope": "warm_digest"}),
("put_cache", ("uni-ü", uni), {"compressed": "MANUAL-COMPRESSED"}),
("get_cache", ("alpha",), {}),
("get_cache", ("alpha",), {}),
("get_cache", ("never-seen",), {}),
("cache_stats", (), {}),
("invalidate", ("alpha",), {"reason": "stale"}),
("get_cache", ("alpha",), {}),
("invalidate_scope", ("retrieval",), {"reason": "event test"}),
("invalidate_all", (), {"reason": "nuke"}),
("cache_stats", (), {}),
("put_cache", ("alpha", "Alpha rewritten value"), {}),
("get_cache", ("alpha",), {}),
("handle_hook", ("memory.created", {}), {}),
("handle_hook", ("persona.updated", None), {}),
("handle_hook", ("completely.unknown", None), {}),
# the 50-event flush threshold: put resets the counter, then 50
# hits — the 50th record crosses _FLUSH_THRESHOLD and flushes.
("put_cache", ("counter", "Counter value for the threshold walk"), {}),
]
cases.extend([("get_cache", ("counter",), {})] * 50)
cases.append(("cache_stats", (), {}))
truth = freeze("rune.cache", cases, oracle_module="rune.cache")
out = REPO / "src/go/cache/frozen_truth.json"
write_envelope(FROZEN_NOW, truth, out)
print(f"wrote {len(truth)} cases to {out} (sandbox {_SBOX})")
return 0
if __name__ == "__main__":
sys.exit(main())
+292
View File
@@ -0,0 +1,292 @@
#!/usr/bin/env python3
"""Freeze the capability_broker gap-closing truth corpus (dichotomy wave
#2479 gap-cb tranche).
Drives the LIVE Python oracle (src/rune/capability_broker.py) through the
shared harness (scripts/freeze_truth.py: RUNE_CAPABILITY_BROKER_CORE=python
auto-pinned from the module stem, inputs deep-copied per case,
{"fn","args","kwargs","expected"} envelope) into
src/rust/capability_broker/frozen_gap_truth.json, embedded VERBATIM by the
crate's cfg(test) battery (gap_battery.rs, include_str!).
Determinism contract — fixture-home replay (provider_budget law): the
oracle's module-level card I/O (REGISTRY / CARDS_FILE) resolves through
memory_env from RUNE_HOME / RUNE_SCRIPTS_DIR, so every case replays
against a rebuilt fixture home:
RUNE_HOME = /tmp/rune_cb_truth_home
RUNE_SCRIPTS_DIR= /tmp/rune_cb_truth_home/src/rune
src/rune/.microkernel.json ← SYNTHETIC_REGISTRY (frozen const)
memory/index/capability_cards.json ← STALE_CARDS_SEED, written
BEFORE the registry (stale arm)
The case list is a REPLAYABLE SCRIPT over that home (stateful mtimes are
legal because every replay mutates the fixture identically from the same
canonical seed): staleness flips when load_cards' atomic rebuild rewrites
the index, and every later score/match/hook case reads the rebuilt index.
WARNING: SYNTHETIC_REGISTRY / STALE_CARDS_SEED below are kept byte-equal
with the consts embedded in src/rust/capability_broker/src/gap_battery.rs —
the Rust battery rebuilds the same fixture home from the same values.
Self-verifying (byte-identical law): rebuild → freeze → rebuild → freeze
(byte-compare) → rebuild → run the shared harness gate in a fresh
subprocess — must report byte-identical:
python3 scripts/gen_capability_broker_gap_truth.py # self-verifies
Standalone re-verify later (fixture rebuilt first):
python3 scripts/gen_capability_broker_gap_truth.py --setup
RUNE_HOME=/tmp/rune_cb_truth_home \
RUNE_SCRIPTS_DIR=/tmp/rune_cb_truth_home/src/rune \
RUNE_CAPABILITY_BROKER_CORE=python \
python3 scripts/freeze_truth.py --verify \
src/rust/capability_broker/frozen_gap_truth.json \
--module rune.capability_broker
Excluded from the envelope (documented seams, not oracle-freezable — no
absolute paths, no live module handles): `_cs_core`'s Some arm (returns the
cs_loader module, not JSON — the pinned-None arm is asserted by the
both-pins pytest and the kernel mirror by the Rust battery) and the
corrupt-file / OSError arms of load_cards (seam battery + the live parity
script drive those against dual fixtures). No absolute path appears in the
frozen truth.
"""
import json
import os
import shutil
import subprocess
import sys
from pathlib import Path
os.environ["RUNE_CAPABILITY_BROKER_CORE"] = "python" # poisoned-truth law
REPO = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(REPO / "src"))
sys.path.insert(0, str(REPO / "scripts"))
HOME = Path("/tmp/rune_cb_truth_home")
OUT = REPO / "src" / "rust" / "capability_broker" / "frozen_gap_truth.json"
FROZEN_NOW = "2026-10-13T10:47:50Z"
# Fixture env MUST precede the oracle import (module constants resolve at
# import time through memory_env).
os.environ["RUNE_HOME"] = str(HOME)
os.environ["RUNE_SCRIPTS_DIR"] = str(HOME / "src" / "rune")
SYNTHETIC_REGISTRY = {
"plugins": {
"hooked": {
"manifest": {
"name": "hooked",
"description": "recall and store memory facts",
"capabilities": ["memory_recall", "memory_write"],
"hooks": {"on_message": "handle_hook"},
"priority": 10,
"_file": "plugins/hooked/main.py",
},
"registered_at": "2026-10-13T01:02:03",
"active": True,
},
"verifier": {
"manifest": {
"name": "verifier",
"description": "verify this claim and detect drift",
"capabilities": ["claim_verification"],
"priority": 20,
"_file": "main.py",
},
},
"verbose": {
"manifest": {
"name": "verbose",
"description": "search, search, and search the store again, "
"then validate, audit, and extract",
"capabilities": ["abstraction"],
"priority": 40,
},
},
"plain": {
"manifest": {
"name": "plain",
"description": "route this task",
"capabilities": ["warm_routing"],
},
},
"unicode": {
"manifest": {
"name": "unicode",
"description": "Vérifiez les mémoires récemment écrites",
"capabilities": ["research"],
"priority": 2.5,
},
},
"empty_manifest": {"manifest": {}, "active": False},
"no_manifest": {"active": False},
"default_priority": {
"manifest": {
"name": "default_priority",
"description": "compile the constitution",
"capabilities": [],
}
},
}
}
# Seeded BEFORE the registry so the staleness arms are deterministic:
STALE_CARDS_SEED = [
{
"name": "zed",
"description": "old seeded card for a retired plugin",
"capabilities": ["zed_cap"],
"file": "zed.py",
"full_path": "plugins/zed/zed.py",
"priority": 3,
"semantic_examples": [],
"risk": "read-only",
"auto_invoked": False,
"hooks": [],
"searchable_text": "zed old seeded card zed_retired_cap",
}
]
# both fixture mtimes are PINNED to fixed epochs (os.utime) — wall-clock
# timing luck in adjacent writes is never part of the truth. The rebuild
# in the case sequence rewrites the index with a real (necessarily later)
# mtime, flipping staleness deterministically.
FIXED_SEED_MTIME = 1_000_000_000.0
FIXED_REGISTRY_MTIME = 1_000_000_100.0
def build_fixture() -> None:
shutil.rmtree(HOME, ignore_errors=True)
(HOME / "src" / "rune").mkdir(parents=True)
(HOME / "memory" / "index").mkdir(parents=True)
cards_file = HOME / "memory" / "index" / "capability_cards.json"
cards_file.write_text(json.dumps(STALE_CARDS_SEED, indent=2))
registry_file = HOME / "src" / "rune" / ".microkernel.json"
registry_file.write_text(json.dumps(SYNTHETIC_REGISTRY, indent=2))
os.utime(cards_file, (FIXED_SEED_MTIME, FIXED_SEED_MTIME))
os.utime(registry_file, (FIXED_REGISTRY_MTIME, FIXED_REGISTRY_MTIME))
def main() -> int:
if len(sys.argv) > 1 and sys.argv[1] == "--setup":
build_fixture()
print(f"canonical seed fixture rebuilt at {HOME}")
return 0
from rune import capability_broker as cb
from freeze_truth import freeze, write_envelope
build_fixture()
hooked_card = cb.generate_card(
"hooked", dict(SYNTHETIC_REGISTRY["plugins"]["hooked"]["manifest"])
)
cases = [
# ── staleness + rebuild chain over the fixture home ───────────────
("_cards_are_stale", [], {}), # registry newer than the seed
("load_cards", [], {}), # atomic rebuild: plugin + native cards
("_cards_are_stale", [], {}), # cards now newer
("load_cards", [], {}), # fresh read of the rebuilt index
("build_cards", [], {}), # plugin cards only
("load_registry", [], {}),
("_native_tool_schemas", [], {}),
# ── generate_card (pure — manifest corpus) ────────────────────────
("generate_card", [
"hooked",
dict(SYNTHETIC_REGISTRY["plugins"]["hooked"]["manifest"]),
]),
("generate_card", ["bare_name", {}]),
("generate_card", [
"many_verbs",
{"description": "search, search, and search the store again, "
"then validate, audit, and extract", "capabilities": ["unknown_cap"]},
]),
("generate_card", [
"capped_examples",
{"description": "covers many known caps",
"capabilities": ["memory_recall", "memory_write", "memory_search"]},
]),
("generate_card", [
"empty_hooks",
{"description": "recall something", "capabilities": ["memory_recall"],
"hooks": {}},
]),
("generate_card", [
"flat_file",
{"description": "verify this", "capabilities": [], "_file": "main.py",
"priority": 7},
]),
("generate_card", [
"empty_file", {"description": "", "capabilities": [], "_file": ""},
]),
("generate_card", [
"float_priority",
{"description": "assess the runtime", "capabilities": [], "priority": 2.5},
]),
("generate_card", [
"unicode",
dict(SYNTHETIC_REGISTRY["plugins"]["unicode"]["manifest"]),
]),
("generate_card", ["no_caps_no_hooks", {"description": "route the task"}]),
("generate_card", ["", {"description": "route me", "capabilities": []}]),
("generate_card", [
"verb_str_caps",
{"description": "letter iteration is legal on str caps",
"capabilities": "abc"},
]),
# ── _py_score_card happy arm (cs core delegation) ─────────────────
("_py_score_card", [dict(hooked_card), "recall memory facts"]),
("_py_score_card", [dict(hooked_card), "no keywords here"]),
# ── match_capabilities over the rebuilt index ────────────────────
("match_capabilities", ["recall and store memory facts", 5]),
("match_capabilities", ["verify this claim about drift", 3]),
("match_capabilities", ["zzz nothing matches here", 5]),
("match_capabilities", ["read a file and lint it", 2]),
# ── handle_hook branches ─────────────────────────────────────────
("handle_hook", ["other", {"message": "hello world"}]),
("handle_hook", ["on_message", {}]),
("handle_hook", ["on_message", {"message": ""}]),
("handle_hook", ["on_message", {"message": " "}]),
("handle_hook", ["on_message", {"message": "hi"}]),
("handle_hook", ["on_message", {"text": "find previous decisions about Y"}]),
("handle_hook", ["on_message", {"status": "error state"}]),
("handle_hook", ["on_message", {"message": "remember this fact and store it"}]),
]
truth = freeze("rune.capability_broker", cases, oracle_module="rune.capability_broker")
# byte-identical law: a rebuilt fixture home + a fresh oracle process
# must regenerate the same truth, case for case.
build_fixture()
truth2 = freeze("rune.capability_broker", cases, oracle_module="rune.capability_broker")
if json.dumps(truth, sort_keys=True) != json.dumps(truth2, sort_keys=True):
print("MISMATCH: truth not replayable against a rebuilt fixture home")
return 1
write_envelope(FROZEN_NOW, truth, OUT)
env = dict(os.environ)
env["PYTHONPATH"] = os.pathsep.join(
[str(REPO / "src"), str(REPO / "scripts"), env.get("PYTHONPATH", "")]
).rstrip(os.pathsep)
build_fixture()
gate = subprocess.run(
[sys.executable, str(REPO / "scripts" / "freeze_truth.py"),
"--verify", str(OUT), "--module", "rune.capability_broker"],
capture_output=True, text=True, env=env,
)
print(gate.stdout, gate.stderr)
if gate.returncode != 0:
print("VERIFY GATE FAILED")
return 1
print(f"frozen {len(truth)} cases -> {OUT} (harness gate byte-identical)")
return 0
if __name__ == "__main__":
raise SystemExit(main())
+124
View File
@@ -0,0 +1,124 @@
#!/usr/bin/env python3
"""gen_claim_audit_truth.py — factory wave GAP truth for claim_audit.
Freezes the oracle behavior of the 10 audit-gap functions (dichotomy wave
#2479) through the SHARED harness (scripts/freeze_truth.py — one law).
Runs under the freeze rig (scripts/ca_freeze_seams/sitecustomize.py —
PYTHONPATH-imported by BOTH this generator and --verify): hermetic
FIXED-path scratch (/tmp/ca_gap_freeze — wiped and reseeded at import),
graph DB seeded with the ledger entities, store seeded with warm neurons
via add_entry (FTS-populated), embeddings off, and the ca_* seams bound
onto rune.claim_audit (graph path, gathered neuron rows, journal path).
Run (from the repo root):
PYTHONHASHSEED=0 PYTHONPATH=scripts/ca_freeze_seams:src \
python3 scripts/gen_claim_audit_truth.py
Verify (byte-identical, same rig):
PYTHONHASHSEED=0 PYTHONPATH=scripts/ca_freeze_seams:src \
python3 scripts/freeze_truth.py --verify \
src/rust/claim_audit/frozen_truth.json \
--module rune.claim_audit
Case map (every gap branch):
* reframe — exceeded-assertion rewrite, definitely-soften,
empty passthrough.
* _graph_has — ledger hit (Kubernetes), miss (zebraquant),
missing DB floors False.
* _warm_has — neuron hit (kubernetes), miss (zebraquant),
None store floors False (probe seam).
* verify — PASS (graph hit + quantified anchor),
DEGRADE comparative-no-support, DEGRADE plain.
* _symmetry_safe — never-fatal floor {} (research_lens absent).
* handle_hook — default envelope {status, event, handler}.
* main — CLI dispatch per command (reframe/scan/verify/
audit/report/hook), journal/report IO isolated
to the scratch journal.
"""
import json
import sys
from pathlib import Path
REPO = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(REPO / "scripts"))
from freeze_truth import freeze, write # noqa: E402
import rune.claim_audit as oracle # noqa: E402
GRAPH = oracle.ca_graph_db
NEURONS = oracle.ca_neurons
# The main() CLI cases run against the scratch journal (isolated IO).
oracle.JOURNAL = oracle.ca_journal_path
def _warm_none(_term):
return None
cases = [
# reframe: input-hygiene rewrites.
("reframe", ("we have exceeded the frontier in speed.",), {}),
("reframe", ("The result is definitely correct.",), {}),
("reframe", ("",), {}),
# _graph_has: ledger entity lookup.
("_graph_has", ("Kubernetes",), {}),
("_graph_has", ("zebraquant fiber optics",), {}),
("_graph_has", ("anything",), {}),
# _warm_has: store-backed neuron lookup (real store + None-store seam).
("_warm_has", ("kubernetes",), {}),
("_warm_has", ("zebraquant",), {}),
# verify: the verdict tree.
("verify", ("Kubernetes measured at 99% [EVIDENCE: bench run]",), {}),
("verify", ("we have exceeded Letta",), {}),
("verify", ("the sky is blue",), {}),
# _symmetry_safe: never-fatal floor.
("_symmetry_safe", ("the sky is blue",), {}),
# handle_hook: the default envelope.
("handle_hook", ("on_response",), {}),
("handle_hook", ("custom_event", {"k": "v"}), {}),
# main: CLI dispatch (each isolated to the scratch journal).
("main", ([],), {}),
]
def main() -> int:
# main() reads sys.argv — drive it per case through argv patching.
# The harness cannot call main() (it takes no args), so these rows are
# recorded here and REPLAYED by the parity script + battery through
# ca_main (same argv shapes, same scratch journal).
import io
from contextlib import redirect_stdout
truth = freeze("rune.claim_audit", [
c for c in cases if c[0] != "main"
], oracle_module="rune.claim_audit")
argv_cases = [
["claim_audit.py", "reframe", "we have exceeded the frontier."],
["claim_audit.py", "scan", "We definitely beat everyone."],
["claim_audit.py", "verify", "the sky is blue"],
["claim_audit.py", "audit", "We definitely beat everyone."],
["claim_audit.py", "report"],
["claim_audit.py", "hook", "--event", "on_response",
"--data", json.dumps({"k": "v"})],
]
saved = sys.argv
for argv in argv_cases:
sys.argv = argv
buf = io.StringIO()
with redirect_stdout(buf):
oracle.main()
truth.append({"fn": "main", "args": [argv], "kwargs": {},
"expected": buf.getvalue()})
sys.argv = saved
write(truth, REPO / "src" / "rust" / "claim_audit" / "frozen_truth.json")
print(f"froze {len(truth)} cases")
return 0
if __name__ == "__main__":
raise SystemExit(main())
+714
View File
@@ -0,0 +1,714 @@
#!/usr/bin/env python3
"""gen_construction_commands_truth.py — freeze/replay parity truth for
construction_commands (dichotomy wave, #2479 gap-close tranche).
Freeze mode (default): exercises the LIVE Python oracle
(src/rune/construction_commands.py — RUNE_CONSTRUCTION_COMMANDS_CORE
pinned python, poisoned-truth law) across every command/branch and
records (input, expected) pairs into
src/rust/construction_commands/frozen_cc_truth.json.
Replay mode (--replay): re-runs the SAME scenarios with the Rust core
delegation ACTIVE (pin lifted post-import) and asserts both kernel-level
(loader direct) and facade-level (dispatch end-to-end through a real
ConstructionInterface + segment-architecture store) parity against the
frozen file.
Truth groups:
* command / dispatch_prep / dispatch_finish — kernel decision
surfaces. `command` expected values are literal oracle returns; the
prep/finish groups' expected values are the kernel surfaces the
facade consumes, derived from the oracle's observable pieces
(command() return, ledger state, interface envelope rules) — the
facade-only dispatch_exec group pins the END-TO-END equivalence.
* dispatch_exec — facade-only (real interface + segment-store IO
stays in Python): whole dispatch runs against seeded stores.
Clock law: the oracle's recorded_at seam is time.strftime(time.gmtime())
— the generator patches the ORACLE module's `time` attribute with a
frozen gmtime, so kernels receive `now` as an argument (recorded_at is
byte-stable across processes).
Idempotency-ledger law: the module-global `_outcomes` ledger evolves
across a case SEQUENCE within one process; freeze and replay run the
identical case list with unique per-case command ids, so ledger
evolution is identical. Kernel cases are otherwise stateless
(prior_outcome is an explicit input; replay-pair cases derive prior
from the oracle's own first-delivery envelope).
Hash law: PYTHONHASHSEED=0 enforced by re-exec (resume projections
derive obligation ids from hash() — frozen truth must never embed
process-random hashes).
"""
import copy
import json
import os
import shutil
import sys
import tempfile
import time as _real_time
from pathlib import Path
REPO = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
TRUTH_PATH = os.path.join(REPO, "src", "rust", "construction_commands", "src",
"frozen_cc_truth.json")
REPLAY = "--replay" in sys.argv
# Hash law: determinism across processes (re-exec BEFORE any oracle work).
if os.environ.get("PYTHONHASHSEED") != "0":
os.environ["PYTHONHASHSEED"] = "0"
os.execv(sys.executable, [sys.executable] + sys.argv)
os.environ["RUNE_CONSTRUCTION_COMMANDS_CORE"] = "python" # poisoned-truth law
sys.path.insert(0, os.path.join(REPO, "src"))
from rune import scaffold as sc # noqa: E402
from rune import construction_commands as oracle_mod # noqa: E402
FROZEN_TS = 1791892800 # 2026-10-13T12:00:00Z
FROZEN_NOW = _real_time.strftime("%Y-%m-%dT%H:%M:%SZ", _real_time.gmtime(FROZEN_TS))
assert FROZEN_NOW == "2026-10-13T12:00:00Z"
class _FrozenTime:
"""Patches the ORACLE module's `time` namespace (recorded_at seam)."""
@staticmethod
def gmtime():
return _real_time.gmtime(FROZEN_TS)
@staticmethod
def strftime(fmt, t=None):
return _real_time.strftime(fmt, t)
oracle_mod.time = _FrozenTime
if REPLAY:
sys.path.insert(0, os.path.join(REPO, "src", "rune"))
import ccmd_loader # noqa: E402 (kernel-level replay side)
# replay law: the facade pass must exercise the LIVE Rust delegation
# path — the pin is lifted AFTER import (facade reads env at call time).
del os.environ["RUNE_CONSTRUCTION_COMMANDS_CORE"]
_DIR_SEQ = [0]
_CASE_SEQ = [0]
def fresh_dir():
"""Deterministic per-case dir — replay recreates the same paths."""
_DIR_SEQ[0] += 1
d = os.path.join(tempfile.gettempdir(), f"cc_truth_frozen_{_DIR_SEQ[0]:03d}")
shutil.rmtree(d, ignore_errors=True)
os.makedirs(d)
return d
class _Probe:
"""Stand-in for the serving scaffold: the validator only calls
.load(), and here it returns the PRE-LOADED doc (deep-copied per
call like a real load)."""
def __init__(self, doc):
self._doc = doc
def load(self):
return copy.deepcopy(self._doc)
def probe(doc):
return None if doc is None else _Probe(doc)
def seed_store(d, cid="c1", phase="draft", identities=None,
purpose="dichotomy truth"):
store = os.path.join(d, ".rune", "scaffold")
s = sc.Scaffold(store, "proj")
doc = s.init(purpose=purpose)
sc.add_entity(doc, id=f"contract:{cid}", kind="contract",
identities=identities if identities is not None else {"scope": []},
evidence_refs=["e"])
doc["entities"][-1]["phase"] = phase
s.commit(doc, what="seed")
return store
def run_exec(seed, specs):
"""Seed a store then run a dispatch call sequence against it
(oracle during freeze, delegated facade during replay)."""
d = fresh_dir()
store = seed_store(d, **seed)
rets = []
for spec in specs:
kwargs = copy.deepcopy(spec)
if kwargs.pop("internal", False):
cwd = os.getcwd()
os.chdir(d)
try:
rets.append(oracle_mod.dispatch(kwargs.pop("command_type"),
**kwargs))
finally:
os.chdir(cwd)
else:
kwargs["store_path"] = store + "|proj"
rets.append(oracle_mod.dispatch(kwargs.pop("command_type"),
**kwargs))
return rets
_GROUPS: dict = {}
def _rec(group, name, inp, expected):
_GROUPS.setdefault(group, []).append(
{"name": name, "input": inp, "expected": expected})
def cmd_case(rec_name, *, command_type, construction_id="c1",
correlation_id="corr-1", command_id=None, payload=None,
doc=None):
"""Kernel command case: input IS the ccm_command payload; expected is
the literal oracle `command()` return."""
_CASE_SEQ[0] += 1
cid = command_id if command_id is not None else f"cmd-k{_CASE_SEQ[0]:03d}"
doc = copy.deepcopy(doc)
ret = oracle_mod.command(
command_type, construction_id=construction_id,
correlation_id=correlation_id, command_id=cid,
payload=copy.deepcopy(payload or {}), scaffold=probe(doc),
)
inp = {"command_type": command_type, "construction_id": construction_id,
"correlation_id": correlation_id, "command_id": cid,
"payload": copy.deepcopy(payload or {}), "now": FROZEN_NOW,
"prior_outcome": None, "scaffold_doc": doc}
_rec("command", rec_name, inp, ret)
def cmd_pair_case(rec_name, *, command_type, construction_id="c1",
command_id="cmd-1", payload=None, doc=None):
"""Idempotency replay: the oracle delivers the SAME command_id twice;
prior_outcome is its own first envelope. expected = second return."""
doc = copy.deepcopy(doc)
payload0 = copy.deepcopy(payload or {})
first = oracle_mod.command(
command_type, construction_id=construction_id,
correlation_id="corr-1", command_id=command_id,
payload=copy.deepcopy(payload0), scaffold=probe(doc),
)
prior = copy.deepcopy(first)
second = oracle_mod.command(
command_type, construction_id=construction_id,
correlation_id="corr-1", command_id=command_id,
payload=copy.deepcopy(payload0), scaffold=probe(doc),
)
inp = {"command_type": command_type, "construction_id": construction_id,
"correlation_id": "corr-1", "command_id": command_id,
"payload": payload0, "now": FROZEN_NOW,
"prior_outcome": prior, "scaffold_doc": doc}
_rec("command", rec_name, inp, second)
def c_cmd_replay_accept(rec_name="command-replay-returns-prior-plus-flag"):
cmd_pair_case(rec_name, command_type="RESUME",
doc={"entities": [{"id": "contract:c1", "phase": "draft"}]})
def c_cmd_replay_refusal(rec_name="command-replay-of-refused-envelope"):
cmd_pair_case(rec_name, command_type="START",
doc={"entities": [{"id": "contract:c1", "phase": "approved"}]})
def c_cmd_unknown():
cmd_case("command-unknown-pause", command_type="PAUSE")
def c_cmd_lowercase_unknown():
cmd_case("command-vocabulary-exact-match", command_type="start")
def c_cmd_no_construction_id():
cmd_case("command-empty-construction-id-refused", command_type="RESUME",
construction_id="")
def c_cmd_no_scaffold():
cmd_case("command-no-serving-scaffold-refused", command_type="RESUME")
def c_cmd_unknown_construction():
cmd_case("command-unknown-construction-refused", command_type="RESUME",
doc={"entities": [{"id": "project:proj", "kind": "project"}]})
def c_cmd_doc_without_entities():
cmd_case("command-doc-without-entities-key", command_type="RESUME",
doc={})
def c_cmd_request_state():
cmd_case("command-request-state-accepts-read-only", command_type="REQUEST_STATE",
doc={"entities": [{"id": "project:proj", "kind": "project"},
{"id": "contract:c1", "phase": "draft"}]})
def c_cmd_request_state_closed():
# REQUEST_STATE ignores the phase entirely (read-only projection)
cmd_case("command-request-state-phase-agnostic", command_type="REQUEST_STATE",
doc={"entities": [{"id": "contract:c1", "phase": "closed"}]})
def c_cmd_resume_draft():
cmd_case("command-resume-draft-accepts", command_type="RESUME",
doc={"entities": [{"id": "contract:c1", "phase": "draft"}]})
def c_cmd_resume_closed():
cmd_case("command-resume-closed-refuses", command_type="RESUME",
doc={"entities": [{"id": "contract:c1", "phase": "closed"}]})
def c_cmd_resume_abandoned():
cmd_case("command-resume-abandoned-refuses", command_type="RESUME",
doc={"entities": [{"id": "contract:c1", "phase": "abandoned"}]})
def c_cmd_start_draft():
cmd_case("command-start-draft-accepts-approved", command_type="START",
doc={"entities": [{"id": "contract:c1", "phase": "draft"}]})
def c_cmd_start_approved():
cmd_case("command-start-approved-refuses", command_type="START",
doc={"entities": [{"id": "contract:c1", "phase": "approved"}]})
def c_cmd_pa_user():
cmd_case("command-provide-approval-user-provenance",
command_type="PROVIDE_APPROVAL", payload={"approved_by": "user"},
doc={"entities": [{"id": "contract:c1", "phase": "draft"}]})
def c_cmd_pa_missing_provenance():
cmd_case("command-provide-approval-provenance-required",
command_type="PROVIDE_APPROVAL", payload={},
doc={"entities": [{"id": "contract:c1", "phase": "draft"}]})
def c_cmd_pa_substrate():
cmd_case("command-provide-approval-substrate-refused",
command_type="PROVIDE_APPROVAL",
payload={"approved_by": "substrate"},
doc={"entities": [{"id": "contract:c1", "phase": "draft"}]})
def c_cmd_pa_building():
cmd_case("command-provide-approval-draft-only",
command_type="PROVIDE_APPROVAL", payload={"approved_by": "user"},
doc={"entities": [{"id": "contract:c1", "phase": "building"}]})
def c_cmd_ack_ok():
for phase in ("failed", "building", "verifying"):
cmd_case(f"command-acknowledge-{phase}-accepts-building",
command_type="ACKNOWLEDGE_BLOCKER",
doc={"entities": [{"id": "contract:c1", "phase": phase}]})
def c_cmd_ack_draft():
cmd_case("command-acknowledge-draft-refuses",
command_type="ACKNOWLEDGE_BLOCKER",
doc={"entities": [{"id": "contract:c1", "phase": "draft"}]})
def c_cmd_pc_authority():
cmd_case("command-context-user-authority-forged", command_type="PROVIDE_CONTEXT",
payload={"add_paths": ["src/x.py"], "approved_by": "user"},
doc={"entities": [{"id": "contract:c1", "phase": "draft"}]})
def c_cmd_pc_substrate_authority():
cmd_case("command-context-never-user-forged-substrate",
command_type="PROVIDE_CONTEXT",
payload={"add_paths": ["src/x.py"], "reason": "extra surface"},
doc={"entities": [{"id": "contract:c1", "phase": "draft"}]})
def c_cmd_pc_empty():
cmd_case("command-context-empty-add-paths-refused", command_type="PROVIDE_CONTEXT",
payload={"add_paths": []},
doc={"entities": [{"id": "contract:c1", "phase": "draft"}]})
def c_cmd_pc_missing():
cmd_case("command-context-missing-add-paths-refused", command_type="PROVIDE_CONTEXT",
payload={},
doc={"entities": [{"id": "contract:c1", "phase": "draft"}]})
def c_cmd_pc_truthy_string():
# `payload.get("add_paths") or []` passes ANY truthy value through —
# a truthy non-list rides into args (execute-side crash parity)
cmd_case("command-context-truthy-non-list-rides-through",
command_type="PROVIDE_CONTEXT", payload={"add_paths": "src"},
doc={"entities": [{"id": "contract:c1", "phase": "draft"}]})
def c_cmd_pc_reason_null():
# payload.get(key, default): a PRESENT null wins over the default
cmd_case("command-context-present-null-reason-wins", command_type="PROVIDE_CONTEXT",
payload={"add_paths": ["a"], "reason": None},
doc={"entities": [{"id": "contract:c1", "phase": "draft"}]})
def c_cmd_pc_reason_default():
cmd_case("command-context-default-reason", command_type="PROVIDE_CONTEXT",
payload={"add_paths": ["a"]},
doc={"entities": [{"id": "contract:c1", "phase": "draft"}]})
def prep_case(rec_name, *, command_type, construction_id="c1",
correlation_id="corr-1", command_id=None, payload=None,
prior=None, serving_error=None, expected=None, doc=None):
_CASE_SEQ[0] += 1
cid = command_id if command_id is not None else f"cmd-p{_CASE_SEQ[0]:03d}"
inp = {"command_type": command_type, "construction_id": construction_id,
"correlation_id": correlation_id, "command_id": cid,
"payload": copy.deepcopy(payload or {}), "now": FROZEN_NOW,
"prior_outcome": copy.deepcopy(prior),
"serving_error": serving_error, "scaffold_doc": copy.deepcopy(doc)}
_rec("dispatch_prep", rec_name, inp, expected)
def c_prep_serving_unavailable():
exc = ("import failed: " + "z" * 210)
env = {"accepted": False, "executed": False, "success": False,
"error": f"serving unavailable: {exc}"[:200],
"command_type": "START", "construction_id": "c1"}
prep_case("dispatch-prep-serving-unavailable-truncated", command_type="START",
serving_error=exc,
expected={"kind": "final", "record": False, "envelope": env})
def c_prep_serving_unavailable_unicode():
# s[:200] slices CHARACTERS — a multibyte exc makes byte-truncation
# (the char-vs-byte quirk) observable
exc = "失败" * 150
env = {"accepted": False, "executed": False, "success": False,
"error": f"serving unavailable: {exc}"[:200],
"command_type": "START", "construction_id": "c1"}
assert len(env["error"]) == 200 # codepoints, not bytes
prep_case("dispatch-prep-serving-unavailable-rune-truncation",
command_type="START", serving_error=exc,
expected={"kind": "final", "record": False, "envelope": env})
def c_prep_replay():
prior = {"accepted": True, "op": "resume",
"args": {"contract_id": "c1"}, "command_id": "cmd-1",
"construction_id": "c1", "correlation_id": "corr-1",
"recorded_at": "2026-10-13T11:00:00Z", "idempotent_replay": False}
env = {"accepted": True, "executed": False, "success": True,
"idempotent_replay": True, "op": "resume",
"command_type": "RESUME", "construction_id": "c1",
"correlation_id": "corr-1", "command_id": "cmd-1"}
prep_case("dispatch-prep-replay-no-second-execution", command_type="RESUME",
prior=prior,
expected={"kind": "final", "record": False, "envelope": env})
def c_prep_refusal():
doc = {"entities": [{"id": "contract:c1", "phase": "approved"}]}
reason = "START requires draft phase (current: approved)"
intent = {"accepted": False, "reason": reason, "command_id": "cmd-r01",
"construction_id": "c1", "correlation_id": "corr-1",
"recorded_at": FROZEN_NOW, "idempotent_replay": False}
env = {"accepted": False, "executed": False, "success": True,
"reason": reason, "command_type": "START",
"construction_id": "c1", "correlation_id": "corr-1",
"command_id": "cmd-r01", "idempotent_replay": False}
prep_case("dispatch-prep-refusal-is-protocol-outcome", command_type="START",
command_id="cmd-r01", doc=doc,
expected={"kind": "final", "record": True, "intent": intent,
"envelope": env})
def _intent(op, args, cid="cmd-x01", construction_id="c1"):
return {"accepted": True, "op": op, "args": args, "command_id": cid,
"construction_id": construction_id, "correlation_id": "corr-1",
"recorded_at": FROZEN_NOW, "idempotent_replay": False}
def c_prep_exec_start():
doc = {"entities": [{"id": "contract:c1", "phase": "draft"}]}
prep_case("dispatch-prep-exec-start", command_type="START", command_id="cmd-x01", doc=doc,
expected={"kind": "exec", "record": True, "op": "transition",
"args": {"contract_id": "c1", "phase": "approved"},
"evidence_ref": "command:cmd-x01",
"intent": _intent("transition", {"contract_id": "c1",
"phase": "approved"})})
def c_prep_exec_approval_provenance():
doc = {"entities": [{"id": "contract:c1", "phase": "draft"}]}
args = {"contract_id": "c1", "phase": "approved", "approved_by": "user"}
prep_case("dispatch-prep-exec-approval-provenance-suffix",
command_type="PROVIDE_APPROVAL", payload={"approved_by": "user"},
command_id="cmd-x01", doc=doc,
expected={"kind": "exec", "record": True, "op": "transition",
"args": args,
"evidence_ref": "command:cmd-x01 approved_by:user",
"intent": _intent("transition", args)})
def c_prep_exec_amend():
doc = {"entities": [{"id": "contract:c1", "phase": "draft"}]}
args = {"contract_id": "c1", "add_paths": ["a"],
"reason": "substrate context", "authority": "substrate"}
prep_case("dispatch-prep-exec-amend-scope", command_type="PROVIDE_CONTEXT",
payload={"add_paths": ["a"]}, command_id="cmd-x01", doc=doc,
expected={"kind": "exec", "record": True, "op": "amend_scope",
"args": args, "evidence_ref": "",
"intent": _intent("amend_scope", args)})
def c_prep_exec_request_state():
doc = {"entities": [{"id": "contract:c1", "phase": "draft"}]}
args = {"contract_id": "c1"}
prep_case("dispatch-prep-exec-request-state-resume", command_type="REQUEST_STATE",
command_id="cmd-x01", doc=doc,
expected={"kind": "exec", "record": True, "op": "resume",
"args": args, "evidence_ref": "",
"intent": _intent("resume", args)})
def finish_case(rec_name, env, intent=None, command_type="START",
construction_id="c1"):
intent = intent or {"accepted": True, "op": "transition",
"args": {"contract_id": construction_id},
"command_id": "cmd-1", "construction_id": construction_id,
"correlation_id": "corr-1", "recorded_at": FROZEN_NOW,
"idempotent_replay": False}
expected = {"accepted": True, "executed": True,
"success": bool(env.get("success")),
"envelope": copy.deepcopy(env),
"command_type": command_type,
"construction_id": construction_id,
"correlation_id": intent.get("correlation_id", ""),
"command_id": intent.get("command_id", ""),
"idempotent_replay": False}
inp = {"command_type": command_type, "construction_id": construction_id,
"intent": copy.deepcopy(intent), "env": copy.deepcopy(env)}
_rec("dispatch_finish", rec_name, inp, expected)
def c_finish_success():
finish_case("dispatch-finish-success-transition-envelope",
{"schema": 1, "operation": "transition", "success": True,
"ids": {"contract_id": "c1"}, "state": {"phase": "approved"},
"evidence": [], "errors": [], "warnings": []})
def c_finish_failure():
finish_case("dispatch-finish-failure-carries-envelope",
{"schema": 1, "operation": "transition", "success": False,
"ids": {"contract_id": "c1"}, "state": {},
"evidence": [], "errors": [{"error": "VERIFICATION_FAILED",
"detail": "boom"}],
"warnings": []})
def c_finish_truthiness_string():
finish_case("dispatch-finish-success-truthy-string", {"success": "yes"})
def c_finish_truthiness_zero():
finish_case("dispatch-finish-success-falsy-zero", {"success": 0})
def c_finish_truthiness_missing():
finish_case("dispatch-finish-success-missing-key-falsy", {"ids": {}})
def c_finish_truthiness_null():
finish_case("dispatch-finish-success-null-falsy", {"success": None})
def c_finish_passthrough_ids():
intent = {"accepted": True, "op": "resume", "args": {"contract_id": "zz"},
"command_id": "cmd-77", "construction_id": "zz",
"correlation_id": "corr-77", "recorded_at": FROZEN_NOW,
"idempotent_replay": False}
finish_case("dispatch-finish-command-provenance-passthrough",
{"success": True, "ids": {"contract_id": "zz"}}, intent=intent,
command_type="RESUME", construction_id="zz")
# ── facade-only group: dispatch END-TO-END through real stores ──────────────
def exec_case(rec_name, seed, specs):
rets = run_exec(seed, specs)
_rec("dispatch_exec", rec_name,
{"seed": seed, "specs": copy.deepcopy(specs)}, rets)
def c_exec_start_end_to_end():
exec_case("dispatch-exec-start-moves-draft-to-approved",
{"cid": "c1"},
[{"command_type": "START", "construction_id": "c1",
"command_id": "cmd-start-1"}])
def c_exec_second_start_refused():
exec_case("dispatch-exec-second-start-refused", {"cid": "c1"},
[{"command_type": "START", "construction_id": "c1",
"command_id": "cmd-first"},
{"command_type": "START", "construction_id": "c1",
"command_id": "cmd-second"}])
def c_exec_idempotent_replay():
spec = {"command_type": "START", "construction_id": "c1",
"command_id": "cmd-idem-1"}
exec_case("dispatch-exec-idempotent-replay-no-double-execution",
{"cid": "c1"}, [spec, dict(spec)])
def c_exec_resume_projection():
exec_case("dispatch-exec-resume-read-only-projection",
{"cid": "c1", "phase": "building",
"identities": {"scope": ["src/a.py"],
"need": "build the thing",
"origin": "builder", "resolution": "BUILD",
"toolchain": {"selected_language": "python"}}},
[{"command_type": "RESUME", "construction_id": "c1",
"command_id": "cmd-resume-1"}])
def c_exec_unknown_command():
exec_case("dispatch-exec-pause-refused-not-in-vocabulary", {"cid": "c1"},
[{"command_type": "PAUSE", "construction_id": "c1",
"command_id": "cmd-pause-1"}])
def c_exec_provide_context_amends():
exec_case("dispatch-exec-provide-context-amends-scope-sorted",
{"cid": "c1", "identities": {"scope": ["src/m.py"]}},
[{"command_type": "PROVIDE_CONTEXT", "construction_id": "c1",
"command_id": "cmd-ctx-1",
"payload": {"add_paths": ["zeta.py", "alpha.py"]}},
{"command_type": "RESUME", "construction_id": "c1",
"command_id": "cmd-ctx-2"}])
def c_exec_acknowledge_blocker():
exec_case("dispatch-exec-acknowledge-blocker-retries-building",
{"cid": "c1", "phase": "failed"},
[{"command_type": "ACKNOWLEDGE_BLOCKER", "construction_id": "c1",
"command_id": "cmd-ack-1"}])
def c_exec_rune_internal_sandbox():
# rune-internal mode (default store_path) against an EMPTY cwd — a
# hermetic fresh store is served, so unknown construction refuses
# deterministically without touching the real repo store
exec_case("dispatch-exec-rune-internal-fresh-store-refused", {},
[{"command_type": "REQUEST_STATE", "construction_id": "ghost",
"command_id": "cmd-sandbox-1", "internal": True}])
def c_exec_provenance_refusal():
exec_case("dispatch-exec-substrate-cannot-approve", {"cid": "c1"},
[{"command_type": "PROVIDE_APPROVAL", "construction_id": "c1",
"command_id": "cmd-pas-1",
"payload": {"approved_by": "substrate"}}])
CASES = [
c_cmd_replay_accept, c_cmd_replay_refusal, c_cmd_unknown,
c_cmd_lowercase_unknown, c_cmd_no_construction_id, c_cmd_no_scaffold,
c_cmd_unknown_construction, c_cmd_doc_without_entities,
c_cmd_request_state, c_cmd_request_state_closed, c_cmd_resume_draft,
c_cmd_resume_closed, c_cmd_resume_abandoned, c_cmd_start_draft,
c_cmd_start_approved, c_cmd_pa_user, c_cmd_pa_missing_provenance,
c_cmd_pa_substrate, c_cmd_pa_building, c_cmd_ack_ok, c_cmd_ack_draft,
c_cmd_pc_authority, c_cmd_pc_substrate_authority, c_cmd_pc_empty,
c_cmd_pc_missing, c_cmd_pc_truthy_string, c_cmd_pc_reason_null,
c_cmd_pc_reason_default,
c_prep_serving_unavailable, c_prep_serving_unavailable_unicode,
c_prep_replay, c_prep_refusal, c_prep_exec_start,
c_prep_exec_approval_provenance, c_prep_exec_amend,
c_prep_exec_request_state,
c_finish_success, c_finish_failure, c_finish_truthiness_string,
c_finish_truthiness_zero, c_finish_truthiness_missing,
c_finish_truthiness_null, c_finish_passthrough_ids,
c_exec_start_end_to_end, c_exec_second_start_refused,
c_exec_idempotent_replay, c_exec_resume_projection,
c_exec_unknown_command, c_exec_provide_context_amends,
c_exec_acknowledge_blocker, c_exec_rune_internal_sandbox,
c_exec_provenance_refusal,
]
def main():
if REPLAY:
# the replay side consumes the frozen file ONLY — the freeze
# case-runners must NOT re-run through the delegated facade
# here (they would evolve the module ledger before the
# comparison passes and turn fresh deliveries into replays)
with open(TRUTH_PATH) as f:
groups = json.load(f)["cases"]
else:
for c in CASES:
c()
groups = _GROUPS
total = sum(len(v) for v in groups.values())
if REPLAY:
failures = 0
checked = 0
for group, cases in groups.items():
for case in cases:
spec = CALLS.get(group)
if spec is None:
continue
checked += 1
got = spec(copy.deepcopy(case["input"]))
want = copy.deepcopy(case["expected"])
if got != want:
failures += 1
print(f"DIVERGE [{group}] {case['name']}")
print(" got: ", json.dumps(got, sort_keys=True,
default=str)[:600])
print(" want:", json.dumps(want, sort_keys=True,
default=str)[:600])
print(f"replay: {checked - failures}/{checked} ({total} recorded)")
return 1 if failures else 0
doc = {
"frozen": FROZEN_NOW,
"oracle": "src/rune/construction_commands.py",
"pin": "RUNE_CONSTRUCTION_COMMANDS_CORE=python + PYTHONHASHSEED=0",
"note": ("Frozen via scripts/gen_construction_commands_truth.py against the "
"live Python oracle; the oracle's recorded_at time seam patched to "
+ FROZEN_NOW + ". Kernel groups (command, dispatch_prep, "
"dispatch_finish) replay through ccm_loader; the dispatch_exec "
"group is facade-only (real ConstructionInterface + segment-store "
"IO stays in Python)."),
"cases": groups,
}
os.makedirs(os.path.dirname(TRUTH_PATH), exist_ok=True)
with open(TRUTH_PATH, "w") as f:
json.dump(doc, f, indent=1)
f.write("\n")
print(f"frozen {total} cases → {os.path.relpath(TRUTH_PATH, REPO)}")
return 0
CALLS = {
"command": lambda i: ccmd_loader.command(i),
"dispatch_prep": lambda i: ccmd_loader.dispatch(i),
"dispatch_finish": lambda i: ccmd_loader.dispatch_finish(i),
"dispatch_exec": lambda i: run_exec(i["seed"], i["specs"]),
}
if __name__ == "__main__":
sys.exit(main())
+12 -1
View File
@@ -52,9 +52,20 @@ import os
import sys
from pathlib import Path
# POISONED-TRUTH LAW: freeze the ORACLE (pure Python, own core pinned)
# POISONED-TRUTH LAW: freeze the ORACLE (pure Python, own core pinned).
# RUNE_CM_CORE pinned too: make_decision calls construction_mode.classify_mode
# whose delegation gate is transitive — _pin_oracle_cores cannot reach it
# (ci_freeze_seams lesson). Unpinned, the frozen construction_mode trace
# captured the Rust core's output instead of the oracle's.
os.environ["RUNE_CONSTRUCTION_DECISION_CORE"] = "python"
os.environ["RUNE_CM_CORE"] = "python"
os.environ.pop("RUNE_SCAFFOLD_CORE", None)
# The oracle's lexicons are Python sets — multi-hit evidence order is
# hash-random per process; freeze under the pinned seed (the Rust
# construction_mode arrays reproduce this order).
if os.environ.get("PYTHONHASHSEED") != "0":
os.execve(sys.executable, [sys.executable, __file__],
{**os.environ, "PYTHONHASHSEED": "0"})
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "src"))
+303
View File
@@ -0,0 +1,303 @@
#!/usr/bin/env python3
"""Freeze the dichotomy-wave gap truth for src/rune/construction_interface
through the SHARED harness (scripts/freeze_truth.py — one law).
The oracle is a stateful facade (ConstructionInterface over a Scaffold
store) with clock/uuid nondeterminism, so this generator runs under the
freeze rig (scripts/ci_freeze_seams/sitecustomize.py):
pinned RUNE_*_CORE=python floors, frozen clock, deterministic uuid mint,
hermetic per-case stores (deterministic per-case dirs — envelopes that
carry paths, like mini_doc, replay byte-identically), and DOC-CARRYING
seam bindings the shared harness can getattr: the Rust kernel is a pure
doc-in/doc-out membrane, so every stateful case carries the full input
doc in its args and replays in the battery with no store.
Run (from the repo root):
rm -rf /tmp/ci_gap_freeze_home
CI_FREEZE_HOME=/tmp/ci_gap_freeze_home \
PYTHONPATH=scripts/ci_freeze_seams:src \
python3 scripts/gen_construction_interface_truth.py
Verify (byte-identical, same rig):
CI_FREEZE_HOME=/tmp/ci_gap_freeze_home \
PYTHONPATH=scripts/ci_freeze_seams:src \
python3 scripts/freeze_truth.py --verify \
src/rust/construction_interface/frozen_ci_truth.json \
--module rune.construction_interface
Every public function and branch is exercised. The obligation-id seam
(_obligations_projection carries process-randomized str hash) lives in
the SEPARATE frozen_ci_truth_hash.json battery (captured + verified with
PYTHONHASHSEED=0) and is SHAPE-pinned downstream — never value-frozen
here.
"""
import os
import subprocess
import sys
from pathlib import Path
REPO = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(REPO / "scripts"))
from freeze_truth import freeze, write # noqa: E402
import sitecustomize as rig # noqa: E402
# ── deterministic input docs (builder helpers; NOT frozen fns) ──
DOC0 = rig.build_doc() # fixture authority, no contract
DOC_SUBMITTED = rig.submit_doc("b-submitted", rig.build_doc())
DOC_WALKED = rig.walk_doc("b-walked", rig.build_doc())
DOC_WITH_LEDGER_CAPS = rig.build_ledger_caps()
PROGRAMMES_BOUND = [{
"programme_id": "prog-gap-ci", "objective": "close the gap",
"stages": [
{"stage_id": rig._submitted_cid(DOC_SUBMITTED),
"objective": "the gap stage"},
{"stage_id": "next-stage", "objective": "the next stage"},
],
}]
GUARD_FAIL = [{"name": "always-fail", "kind": "command", "argv": ["false"]}]
GUARD_PASS = [{"name": "always-pass", "kind": "command", "argv": ["true"]}]
GUARD_ASSERT = [{"name": "truthy", "kind": "assert",
"description": "always true"}]
cases = [
# ── _envelope: success + failure shapes, extra keys ──
("_envelope", ("op",), {"success": True}),
("_envelope", ("op",), {"success": False,
"errors": [{"error": "X"}],
"warnings": [{"warning": "W"}],
"ids": {"a": "b"}, "state": {"k": 1},
"extra": {"extra_key": "extra"}}),
# ── _to_stage_check: full spec, defaults ──
("ci_to_stage_check", ({"name": "g", "kind": "command",
"argv": ["true"], "output_pattern": "ok",
"path": "/x", "description": "d"},), {}),
("ci_to_stage_check", ({},), {}),
# ── _guard_specs_from_obligations: guard rows, junk, bad JSON ──
("_guard_specs_from_obligations",
({"identities": {"verification_obligations": [
'guard:{"name": "g1", "kind": "command", "argv": ["true"]}',
"free-text obligation",
"guard:not-json{{{",
'["not", "a", "dict"]',
'guard:{"name": "g2"}',
]}},), {}),
("_guard_specs_from_obligations", ({},), {}),
# ── t_layout: present + absent ──
("t_layout", ({"decision_trace": {"layout_obligations": [
{"component": "c", "obligation": "o"}]}},), {}),
("t_layout", ({},), {}),
# ── _obligations_projection: synthetic hash-free fixtures (empty,
# pattern-only, layout-only — the contract/structural id branches
# carry process-randomized hash → hash battery) ──
("_obligations_projection", ({},), {}),
("_obligations_projection",
({"ext": {"decision_trace": {"obligations": {"pattern": [
{"id": "pat-1", "pattern": "seed_loop", "revision": 3,
"obligation": "keep the seed loop closed", "verdict": "SATISFIED",
"reason": "evidence row 1", "pattern_applicability": "always"}]}}}},),
{}),
("_obligations_projection",
({"ext": {"decision_trace": {"layout_obligations": [
{"component": "ui:header", "obligation": "stay in region top",
"verification": "adapter observation"}]}}},), {}),
# ── _obligation_scope_files: passthrough stub ──
("_obligation_scope_files", ([{"id": "x"}],), {}),
("_obligation_scope_files", ([],), {}),
# ── _authorities: external mode, rune-internal w/ + w/o spine ──
("_authorities", (rig.build_doc(),), {}),
("_authorities", (rig.build_doc(), {"schema_version": 1,
"entities": []}),
{"mode": "rune_internal"}),
("_authorities", (rig.build_doc(), None), {"mode": "rune_internal"}),
# ── _record_session: append + long-detail truncation ──
("_record_session", (rig.build_doc(), "submit_need", "short detail"), {}),
("_record_session", (rig.build_doc(), "close", "d" * 500), {}),
# ── classify: envelope assembly over classifier results ──
("classify", ({"mode": "UNKNOWN", "evidence": ["probe: which surface?"],
"probe_questions": ["q1"]},), {}),
("classify", ({"mode": "EXISTING_PROJECT_CHANGE", "evidence": ["e1"],
"probe_questions": []},), {}),
("classify", ({"mode": "LOCAL_CHANGE"},),
{"builder": "other-builder"}),
# ── construction_context: none active, explicit unknown id (the
# ACTIVE projection carries obligation ids → hash battery) ──
("construction_context", ("cc-none", rig.build_doc()), {}),
("construction_context", ("cc-unknown", DOC_SUBMITTED, "NOPE"), {}),
# ── capabilities: the full discovery envelope, both modes ──
("capabilities", (), {"mode": "external_project"}),
("capabilities", (), {"mode": "rune_internal",
"project": "issue161-harness"}),
# ── submit_need: happy, empty objective, MATERIAL_GAP, approval,
# no-generate, custom contract id, task_ref ──
("submit_need", ("sn-ok", rig.build_doc(), "persistent project export"), {}),
("submit_need", ("sn-empty", rig.build_doc(), ""), {}),
("submit_need", ("sn-gap", rig.build_doc(),
"change the exporter widget colors"),
{"affected_surface": ["capability:exporter"], "constraints": {},
"evidence_refs": ["x"]}),
("submit_need", ("sn-appr", rig.build_doc(),
"start a brand new repository for billing"),
{"constraints": {"new_repository": True}, "evidence_refs": ["x"]}),
("submit_need", ("sn-nogen", rig.build_doc(), "persistent project export"),
{"generate": False}),
("submit_need", ("sn-cid", rig.build_doc(), "persistent project export"),
{"contract_id": "MY-CID"}),
("submit_need", ("sn-task", rig.build_doc(), "persistent project export"),
{"task_ref": "task-1"}),
# ── inspect_decision: ok + unknown ──
("inspect_decision", ("in-ok", DOC_SUBMITTED,
rig._submitted_cid(DOC_SUBMITTED)), {}),
("inspect_decision", ("in-no", DOC_SUBMITTED, "NOPE"), {}),
# ── get_scope: ok + unknown ──
("get_scope", ("gs-ok", DOC_SUBMITTED,
rig._submitted_cid(DOC_SUBMITTED)), {}),
("get_scope", ("gs-no", DOC_SUBMITTED, "NOPE"), {}),
# ── get_obligations: unknown (ok carries hash ids → hash battery) ──
("get_obligations", ("go-no", DOC_SUBMITTED, "NOPE"), {}),
# ── report_observation: ok, bare-dict, missing entity, unknown ──
("report_observation", ("ro-ok", DOC_SUBMITTED,
rig._submitted_cid(DOC_SUBMITTED),
[{"entity": "contract:csv_export",
"detail": "observed while building"}]), {}),
("report_observation", ("ro-bare", DOC_SUBMITTED,
rig._submitted_cid(DOC_SUBMITTED),
{"entity": "x"}), {}),
("report_observation", ("ro-noent", DOC_SUBMITTED,
rig._submitted_cid(DOC_SUBMITTED),
[{"detail": "x"}]), {}),
("report_observation", ("ro-no", DOC_SUBMITTED, "NOPE",
[{"entity": "x"}]), {}),
# ── verify: unknown, scope unknown/green/red, layout PASS/FAIL/UNKNOWN,
# walked-contract contract-quality projection ──
("verify", ("vf-no", DOC_SUBMITTED, "NOPE"), {}),
("verify", ("vf-base", DOC_SUBMITTED,
rig._submitted_cid(DOC_SUBMITTED)), {}),
("verify", ("vf-green", DOC_SUBMITTED, rig._submitted_cid(DOC_SUBMITTED)),
{"changed_files": ["src/allowed.py"]}),
("verify", ("vf-red", DOC_SUBMITTED, rig._submitted_cid(DOC_SUBMITTED)),
{"changed_files": ["src/evil.py"]}),
("verify", ("vf-pass", DOC_SUBMITTED, rig._submitted_cid(DOC_SUBMITTED)),
{"layout_observations": {"components": []}}),
("verify", ("vf-fail", DOC_SUBMITTED, rig._submitted_cid(DOC_SUBMITTED)),
{"layout_observations": {"header": {"region": "bottom"}}}),
("verify", ("vf-unk", DOC_SUBMITTED, rig._submitted_cid(DOC_SUBMITTED)),
{"layout_observations": {"header": {"region": "top"}}}),
# ── transition: happy edge, illegal edge, unknown, guard block/pass ──
("transition", ("tr-appr", DOC_SUBMITTED,
rig._submitted_cid(DOC_SUBMITTED), "approved"), {}),
("transition", ("tr-ill", DOC_SUBMITTED,
rig._submitted_cid(DOC_SUBMITTED), "closed"), {}),
("transition", ("tr-no", DOC_SUBMITTED, "NOPE", "approved"), {}),
("transition", ("tr-block", DOC_SUBMITTED,
rig._submitted_cid(DOC_SUBMITTED), "approved"),
{"guard_checks": GUARD_FAIL}),
("transition", ("tr-pass", DOC_SUBMITTED,
rig._submitted_cid(DOC_SUBMITTED), "approved"),
{"guard_checks": GUARD_PASS}),
("transition", ("tr-assert", DOC_SUBMITTED,
rig._submitted_cid(DOC_SUBMITTED), "approved"),
{"guard_checks": GUARD_ASSERT}),
# ── close: full ladder doc, unknown, custom scope files ──
("close", ("cl-ok", DOC_WALKED, rig._submitted_cid(DOC_WALKED),
[{"kind": "port_evidence", "detail": "gap closed"}]), {}),
("close", ("cl-scope", DOC_WALKED, rig._submitted_cid(DOC_WALKED),
[{"kind": "port_evidence", "detail": "gap closed"}]),
{"scope_files": ["src/export.py"]}),
("close", ("cl-no", DOC_WALKED, "NOPE", [{"entity": "x"}]), {}),
# ── _programme_continuation: bound, unbound stage, no programme dir ──
("_programme_continuation",
("pc-hit", DOC_SUBMITTED, rig._submitted_cid(DOC_SUBMITTED)),
{"programmes": PROGRAMMES_BOUND}),
("_programme_continuation",
("pc-miss", DOC_SUBMITTED, "other-stage"),
{"programmes": PROGRAMMES_BOUND}),
("_programme_continuation",
("pc-none", DOC_SUBMITTED, rig._submitted_cid(DOC_SUBMITTED)), {}),
# ── _auto_material_change: hit, miss, no ledger ──
("_auto_material_change",
("mc-hit", DOC_SUBMITTED, ["src/export.py"]),
{"capabilities": DOC_WITH_LEDGER_CAPS}),
("_auto_material_change",
("mc-miss", DOC_SUBMITTED, ["src/zzz.py"]),
{"capabilities": DOC_WITH_LEDGER_CAPS}),
("_auto_material_change",
("mc-nol", DOC_SUBMITTED, ["src/export.py"]), {}),
# ── discover_active_contract: seeded store, empty store ──
("discover_active_contract", ("dc-seed",
[{"project": "alpha", "doc": rig._discover_doc("old", "2026-10-01T00:00:00Z", "alpha")},
{"project": None, "doc": rig._discover_doc("main-latest", "2026-10-03T00:00:00Z", "gamma")}]),
{}),
("discover_active_contract", ("dc-empty", []), {}),
# ── resume: unknown (ok carries hash ids → hash battery) ──
("resume", ("rs-no", DOC_SUBMITTED, "NOPE"), {}),
# ── amend_scope: ok, non-user, unknown ──
("amend_scope", ("am-ok", DOC_SUBMITTED,
rig._submitted_cid(DOC_SUBMITTED), ["src/a.py"]),
{"reason": "user asked"}),
("amend_scope", ("am-nouser", DOC_SUBMITTED,
rig._submitted_cid(DOC_SUBMITTED), ["src/a.py"]),
{"reason": "x", "authority": "builder"}),
("amend_scope", ("am-no", DOC_SUBMITTED, "NOPE", ["a"]),
{"reason": "x"}),
# ── main: every CLI command ──
("main", ("m-help",), {"argv": ["--help"]}),
("main", ("m-unk",), {"argv": ["frobnicate"]}),
("main", ("m-caps",), {"argv": ["capabilities"]}),
("main", ("m-cls",), {"argv": ["classify",
'{"objective": "fix typo"}']}),
("main", ("m-ctx",), {"argv": ["context"]}),
("main", ("m-sub",), {"argv": ["submit-need",
'{"objective": "x"}']}),
("main", ("m-dec",), {"argv": ["decision", "NOPE"]}),
("main", ("m-scope",), {"argv": ["scope", "NOPE"]}),
("main", ("m-obl",), {"argv": ["obligations", "NOPE"]}),
("main", ("m-obs",), {"argv": ["observe", "NOPE", "[]"]}),
("main", ("m-ver",), {"argv": ["verify", "NOPE"]}),
("main", ("m-tr",), {"argv": ["transition", "NOPE", "approved"]}),
("main", ("m-close",), {"argv": ["close", "NOPE", "[]"]}),
("main", ("m-res",), {"argv": ["resume", "NOPE"]}),
# ── the FULL ladder in ONE process (shared-store clobber law) ──
("ladder_walk", ("walk1",), {}),
("ladder_walk", ("walk2", "start a brand new repository for billing"), {}),
]
truth = freeze("rune.construction_interface", cases,
oracle_module="rune.construction_interface")
write(truth, REPO / "src" / "rust" / "construction_interface"
/ "frozen_ci_truth.json")
print(f"froze {len(truth)} cases")
# ── §2 hash battery: every envelope carrying obligation ids. Captured +
# verified with PYTHONHASHSEED=0 (set at INTERPRETER start — the seed
# cannot be changed mid-process, so the main run re-execs itself for
# this part); the Rust battery SHAPE-pins these ids (prefix before ":",
# stable description/kind/provenance/status) — never value-freezes the
# randomized suffix. ──
HASH_CASES = [
("_obligations_projection", (rig.contract_of(DOC_SUBMITTED,
rig._submitted_cid(DOC_SUBMITTED)),), {}),
("construction_context", ("hc-active", DOC_SUBMITTED), {}),
("construction_context", ("hc-explicit", DOC_SUBMITTED,
rig._submitted_cid(DOC_SUBMITTED)), {}),
("get_obligations", ("ho-ok", DOC_SUBMITTED,
rig._submitted_cid(DOC_SUBMITTED)), {}),
("resume", ("hr-ok", DOC_SUBMITTED,
rig._submitted_cid(DOC_SUBMITTED)), {}),
]
if os.environ.get("CI_GEN_HASH_ONLY") == "1":
assert os.environ.get("PYTHONHASHSEED") == "0", \
"hash battery requires PYTHONHASHSEED=0 at interpreter start"
hash_truth = freeze("rune.construction_interface", HASH_CASES,
oracle_module="rune.construction_interface")
write(hash_truth, REPO / "src" / "rust" / "construction_interface"
/ "frozen_ci_truth_hash.json")
print(f"froze {len(hash_truth)} hash cases (PYTHONHASHSEED=0)")
else:
env = dict(os.environ, PYTHONHASHSEED="0", CI_GEN_HASH_ONLY="1",
PYTHONPATH="scripts/ci_freeze_seams:src")
subprocess.run([sys.executable, str(Path(__file__).resolve())],
check=True, env=env, cwd=str(REPO))
+239
View File
@@ -0,0 +1,239 @@
#!/usr/bin/env python3
"""Freeze construction_mode oracle truth for the Rust gap-closing port
battery (dichotomy wave #2479, shared harness scripts/freeze_truth.py).
Run with the rig on PYTHONPATH so the oracle floor is pinned for the
whole cone:
PYTHONPATH=scripts/cm_freeze_seams python3 scripts/gen_construction_mode_truth.py
Exercises EVERY function and branch of src/rune/construction_mode.py:
cm_classify_to_dict (seam -> the REAL classify_mode + its own
to_dict) — all five modes, every branch of the
decision tree: explicit override (valid/UNKNOWN,
authority provenance, target_project carried,
project_authority/proposed_by_model left at their
dataclass defaults — the early-return defaults
law), NOT_CONSTRUCTION (no verb, verb with
non-constructible object, standalone-evidence
rescue), empty objective (with kwargs that must
NOT leak into the early return), standalone with
all three project_exists states, article-standalone
(guards: local/scope/file/target/exists), LOCAL_CHANGE
(scoped/file/target/exists corroboration, [:3]
evidence slices), EXISTING_PROJECT_CHANGE (scope/
target/exists, authority rune/issue161-harness/
other), UNKNOWN (verb-only, no-evidence, structural
contradiction, proven non-existence probe), and the
affected_surface escalation (UNKNOWN -> EPC 0.6
with probes retained, [:2] slice, LOCAL passthrough).
ConstructionMode.to_dict (full instance, defaults instance, override-
carrying instance — recv receiver form)
ConstructionMode.from_dict (auxiliary from_dict_cases column: full dict
+ unknown keys, minimal, partial, explicit
nulls honored verbatim, override/proposed
carried; plus error-shape column for missing
mode / non-dict / missing attribute)
Output:
src/rust/construction_mode/src/frozen_cm_truth.json (battery
envelope: generator/module/from_dict_cases/error_shapes/cases)
src/rust/construction_mode/src/frozen_cm_truth.verify.json (bare
harness array — the `freeze_truth.py --verify` law, byte-identical)
Verify (both pins required — seed for the set-iteration order, rig for
the oracle floor):
PYTHONHASHSEED=0 PYTHONPATH=scripts/cm_freeze_seams \
python3 scripts/freeze_truth.py --verify \
src/rust/construction_mode/src/frozen_cm_truth.verify.json \
--module rune.construction_mode
"""
from __future__ import annotations
import json
import os
import sys
from pathlib import Path
# HASH-RANDOMIZATION LAW (memory_consolidation precedent): the oracle's
# lexicons are Python SETS — multi-hit evidence order is hash-random per
# process. Truth is frozen under PYTHONHASHSEED=0; re-exec to pin it.
if os.environ.get("PYTHONHASHSEED") != "0":
os.execve(sys.executable, [sys.executable, __file__],
{**os.environ, "PYTHONHASHSEED": "0"})
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "src"))
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
from freeze_truth import freeze, write as _harness_write # noqa: E402
import rune.construction_mode as cm # noqa: E402
OUT = Path(__file__).resolve().parents[1] / "src" / "rust" / "construction_mode" / "src"
assert hasattr(cm, "cm_classify_to_dict"), "run with PYTHONPATH=scripts/cm_freeze_seams"
FD = "cm_classify_to_dict"
# ── classify_mode: every branch of the decision tree ───────────────────────
classify_cases = [
# PROJECT_BUILD — standalone + from scratch, exists=False
(FD, ["build a standalone scheduler service from scratch"], {"project_exists": False}),
# LOCAL_CHANGE — known extensionless file binds a scoped target
(FD, ["fix the typo in the README"], {}),
# LOCAL_CHANGE — smallness + scoping corroboration
(FD, ["small patch to the module"], {}),
# EPC — "this project" scope + article guard (scoped blocks standalone)
(FD, ["add a flag to this project's deploy script"], {"project_exists": True}),
# EPC — "the codebase" scope
(FD, ["implement the new feature in the codebase"], {"project_exists": True}),
# NOT_CONSTRUCTION — question intent, no construction verb
(FD, ["what is the confidence score"], {}),
# NOT_CONSTRUCTION — verb present, object not buildable
(FD, ["make a list of items"], {}),
# UNKNOWN — empty objective
(FD, [""], {}),
# UNKNOWN — verb, no scope, no standalone
(FD, ["build the thing"], {}),
# UNKNOWN — standalone contradicted by existing project
(FD, ["build a standalone scheduler"], {"project_exists": True}),
# UNKNOWN — standalone with no existence evidence
(FD, ["build a standalone scheduler"], {"project_exists": None}),
# UNKNOWN — scoped change against proven-nonexistent project
(FD, ["refactor the module"], {"project_exists": False}),
# PROJECT_BUILD — indefinite-article new-artifact language
(FD, ["build me a program that renames photos"], {"project_exists": False}),
# UNKNOWN — article + creation verb but "fix a bug" is local-guarded
(FD, ["fix a bug"], {"project_exists": False}),
# PROJECT_BUILD — article + artifact noun, no scope evidence
(FD, ["add a flag to the deploy script"], {"project_exists": False}),
# EPC — "the module" scope (module is a construction word)
(FD, ["explain how the module works"], {}),
# EPC — explicit target project (rune -> rune_internal authority)
(FD, ["create a CLI that sorts files"], {"target_project": "rune", "project_exists": True}),
# EPC — "the service" scope
(FD, ["write tests for the service"], {"project_exists": True}),
# UNKNOWN — verb-only, export feature
(FD, ["implement export feature"], {}),
# LOCAL_CHANGE — "that module" scoping
(FD, ["quick fix for that module"], {}),
# override — valid PROJECT_BUILD with named authority
(FD, ["build something"], {"explicit_override": "PROJECT_BUILD", "override_authority": "operator_bob"}),
# override — target_project carried; project_authority/proposed stay None
(FD, ["build a standalone export tool"],
{"explicit_override": "EXISTING_PROJECT_CHANGE", "target_project": "rune",
"override_authority": "operator"}),
# override — UNKNOWN forces clarification_required
(FD, ["anything"], {"explicit_override": "UNKNOWN"}),
# NOT_CONSTRUCTION early return drops target_project + model_proposal
(FD, ["what is a chord"], {"target_project": "rune", "model_proposal": {"mode": "LOCAL_CHANGE"}}),
# NOT_CONSTRUCTION verb-object branch also drops model_proposal
(FD, ["make a list of items"], {"model_proposal": {"mode": "PROJECT_BUILD"}}),
# empty objective early return drops target_project + model_proposal
(FD, [""], {"target_project": "webapp", "model_proposal": {"mode": "X"}}),
# NOT_CONSTRUCTION skipped: standalone evidence rescues a verb+list
(FD, ["make a list of ideas for a new app"], {}),
# affected_surface escalates UNKNOWN -> EPC 0.6, probes retained
(FD, ["build the thing"], {"affected_surface": ["module:deploy_stage"]}),
# affected_surface on LOCAL_CHANGE — [:2] evidence slice
(FD, ["small patch to the module"], {"affected_surface": ["module:a", "module:b", "module:c"]}),
# affected_surface escalates standalone-UNKNOWN too
(FD, ["build a standalone scheduler"], {"project_exists": None, "affected_surface": ["module:x"]}),
# model_proposal falsy (empty dict) collapses to None
(FD, ["implement export feature"], {"model_proposal": {}}),
# model_proposal recorded verbatim, never authority
(FD, ["implement export feature"],
{"model_proposal": {"pattern_id": "x", "provider": "p", "confidence": 0.4}}),
# authority — issue161-harness maps to rune_internal
(FD, ["refactor the module"], {"target_project": "issue161-harness", "project_exists": True}),
# authority + proven-nonexistent probe names the target
(FD, ["refactor the module"], {"target_project": "webapp", "project_exists": False}),
# target_project alone scopes (no project_exists kwarg)
(FD, ["refactor the module"], {"target_project": "webapp"}),
# LOCAL_CHANGE — dotted source file binds a scoped target
(FD, ["small fix in scheduler.py"], {}),
]
# ── ConstructionMode.to_dict — receiver form (instance rebuilt by the
# harness's shape-matched receiver reconstruction) ────────────────────────
to_dict_cases = [
{"fn": "ConstructionMode.to_dict",
"recv": {"cls": "ConstructionMode", "mode": "PROJECT_BUILD",
"evidence": ["standalone/new-lifecycle language: ['standalone']"],
"target_project": "webapp", "project_authority": "webapp",
"confidence": 0.9, "clarification_required": False,
"probe_questions": [], "bootstrap_required": True,
"override": None, "proposed_by_model": {"mode": "LOCAL_CHANGE"}},
"args": [], "kwargs": {}},
{"fn": "ConstructionMode.to_dict",
# every attr explicit at its dataclass default — the harness rebuilds
# receivers via __new__, so "minimal" means "all defaults present"
"recv": {"cls": "ConstructionMode", "mode": "UNKNOWN",
"evidence": [], "target_project": None, "project_authority": None,
"confidence": 0.0, "clarification_required": False,
"probe_questions": [], "bootstrap_required": False,
"override": None, "proposed_by_model": None},
"args": [], "kwargs": {}},
{"fn": "ConstructionMode.to_dict",
"recv": {"cls": "ConstructionMode", "mode": "LOCAL_CHANGE",
"evidence": ["explicit override by operator"], "target_project": None,
"project_authority": None, "confidence": 1.0,
"clarification_required": False, "probe_questions": [],
"bootstrap_required": False,
"override": {"authority": "operator", "from_mode": None},
"proposed_by_model": None},
"args": [], "kwargs": {}},
]
cases = classify_cases + to_dict_cases
truth = freeze("rune.construction_mode", cases, oracle_module="rune.construction_mode")
# ── auxiliary columns (cd envelope precedent): from_dict projections and
# error shapes — classmethod returns an instance (not JSON-serializable
# for the shared-harness writer), so these ride the battery envelope ────
FD_INPUTS = [
{"mode": "PROJECT_BUILD", "evidence": ["a"], "target_project": "webapp",
"project_authority": "webapp", "confidence": 0.9,
"clarification_required": False, "probe_questions": ["q?"],
"bootstrap_required": True, "override": {"authority": "op", "from_mode": None},
"proposed_by_model": {"mode": "X"}, "wibble": "future-data"},
{"mode": "UNKNOWN"},
{"mode": "EXISTING_PROJECT_CHANGE", "evidence": ["e1", "e2"], "confidence": 0.8},
{"mode": "LOCAL_CHANGE", "target_project": None, "evidence": None,
"proposed_by_model": None},
{"mode": "NOT_CONSTRUCTION", "override": {"authority": "user", "from_mode": "UNKNOWN"}},
]
from_dict_cases = [
{"args": d, "expected": cm.ConstructionMode.from_dict(d).to_dict()}
for d in FD_INPUTS
]
error_shapes = {}
try:
cm.ConstructionMode.from_dict({"evidence": []})
except TypeError as e:
error_shapes["from_dict_missing_mode"] = str(e)
try:
cm.ConstructionMode.from_dict(123)
except TypeError as e:
error_shapes["from_dict_non_dict"] = str(e)
_broken = cm.ConstructionMode.__new__(cm.ConstructionMode)
_broken.mode = "X"
try:
_broken.to_dict()
except AttributeError as e:
error_shapes["to_dict_missing_attribute"] = str(e)
doc = json.loads(json.dumps(truth)) # harness array (serializable projection)
envelope = {
"generator": "scripts/gen_construction_mode_truth.py",
"module": "src/rune/construction_mode.py",
"from_dict_cases": from_dict_cases,
"error_shapes": error_shapes,
"cases": doc,
}
(OUT / "frozen_cm_truth.json").write_text(json.dumps(envelope, indent=2, ensure_ascii=False) + "\n")
_harness_write(truth, OUT / "frozen_cm_truth.verify.json")
print(f"wrote {len(truth)} harness cases "
f"(+{len(from_dict_cases)} from_dict projections) -> {OUT}")
@@ -0,0 +1,315 @@
#!/usr/bin/env python3
"""gen_construction_projection_truth.py — factory wave GAP truth for
construction_projection.
Freezes the oracle behavior of ALL FOUR public functions (the audit named
three gaps: _contract_entity, validate, write_mini_doc; project's
pre-existing kernel path is replayed too) through the SHARED harness
(scripts/freeze_truth.py — one law).
Runs under the freeze rig (scripts/cproj_freeze_seams/sitecustomize.py —
PYTHONPATH-imported by BOTH this generator and --verify): pinned floor
(RUNE_CONSTRUCTION_PROJECTION_CORE=python), a JSON-specified fake scaffold
(load() doc + project_id), and a pinned fake bridge for
rune.event_wait.operation_wait (found / no-record / OSError /
RuntimeError / no-lookup rows). write_mini_doc rows write into a hermetic
fixed-path scratch dir and freeze the markdown BYTES + the file NAME —
never an absolute path (quirks: machine-specific paths).
The PROJECT rows carry the oracle kwargs in the harness-kwargs slot, and
the rig echoes the adapter-resolved bridge scalars (waiting_state /
live_correlation) inside the expected wrapper — the Rust battery rebuilds
its kernel calls from the same rows (the SPEC-grammar law).
Run (from the repo root):
PYTHONHASHSEED=0 PYTHONPATH=scripts/cproj_freeze_seams:src \
python3 scripts/gen_construction_projection_truth.py
Verify (byte-identical, same rig):
PYTHONHASHSEED=0 PYTHONPATH=scripts/cproj_freeze_seams:src \
python3 scripts/freeze_truth.py --verify \
src/rust/construction_projection/src/frozen_truth.verify.json \
--module rune.construction_projection
Case map (every gap branch — freezable shapes; the oracle's CRASH shapes
(null entities, non-dict projection, non-str slicing, non-str blocker
evidence) are crash-parity rows in scripts/check_construction_projection_
parity.py, un-freezable through the shared harness):
* cpj_freeze_contract_entity — match / no-match (absent key) /
no-match (different contract) / empty entities / missing entities key /
empty contract_id (matches id "contract:") / first-of-duplicates.
* cpj_freeze_validate — valid full projection (empty list) / missing one
field / missing several (FIELDS order) / schema_version 2 / 'X' /
None / True (bool-subclass equality — VALID, True == 1) / 1.0
(numeric equality — valid) / [1] / {'a': 1} / all-missing (24
missing-field errors in order).
* cpj_freeze_project — empty scaffold (defaults) / full entity
(the W6-era canary regression shape) / blocker dict (class default +
>120-char evidence truncation) / blocker string / evidence truncation +
empty skipped / approval.required truthy non-bool ('yes') / state ==
REQUIRED / phase awaiting_approval / falsy 0 / canaries (null rides /
missing defaults) / mode+depth falsy collapse / operation-wait found
(correlation passthrough + empty-correlation wait_id fallback) /
no-record / OSError / RuntimeError / no lookup (empty operation_id).
* cpj_freeze_write_mini_doc — full entity / objective fallback chain
(need → ext.need.objective → placeholder) / surface list / single string
/ decision_trace fallback / ids fallback / no surface / quality dict
(sort_keys rendering) / empty + missing quality / task_ref present /
absent / evidence rows / none recorded / empty-surface-list falsiness.
"""
import json
import sys
from pathlib import Path
REPO = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(REPO / "scripts"))
from freeze_truth import freeze, write, write_envelope # noqa: E402
NOW = "2026-10-14T12:00:00.000000"
LONG = "e" * 200 # >120 chars — the [:120] codepoint-truncation quirk
def doc_of(*entities):
return {"entities": list(entities)}
def entity(cid, **kw):
e = {"id": f"contract:{cid}"}
e.update(kw)
return e
FULL_ENTITY = {
"id": "contract:B-1",
"phase": "verifying",
"identities": {
"construction_mode": "BUILD_NEW",
"depth": "standard",
"next_action": "verify",
},
"ext": {
"readiness_canary": "ready",
"liveness_canary": "live",
"exit_canary": "exit",
"decision_trace": {"approval": {"required": True}},
},
"checkpoints": [{"evidence": "ev-1"}, {"evidence": ""}],
}
PROJECTION_KWARGS = dict(stage="st1", builder_state="building")
FULL_KWARGS = dict(
originating_goal_id="goal-9",
operation_id="",
correlation_id="corr-1",
stage="st1",
builder_state="building",
verification_state="verified",
checkpoint="cp-1",
failure_class="none",
completion_state="done",
)
# ── _contract_entity ────────────────────────────────────────────────────────
contract_entity_cases = [
("cpj_freeze_contract_entity", (doc_of(entity("B-1", phase="verifying")), "B-1"), {}),
("cpj_freeze_contract_entity", (doc_of(entity("A-1"), entity("B-2")), "B-9"), {}),
("cpj_freeze_contract_entity", (doc_of(entity("B-1", phase="first"), entity("B-1", phase="dup")), "B-1"), {}),
("cpj_freeze_contract_entity", ({"entities": []}, "B-1"), {}),
("cpj_freeze_contract_entity", ({}, "B-1"), {}),
("cpj_freeze_contract_entity", ({}, ""), {}),
("cpj_freeze_contract_entity", (doc_of(entity("", phase="empty")), ""), {}),
]
# ── validate ────────────────────────────────────────────────────────────────
VALID = {f: f"{f}-v" for f in (
"schema_version", "project_id", "originating_goal_id", "construction_id",
"contract_id", "mode", "depth", "phase", "stage", "operation_id",
"waiting_state", "correlation_id", "builder_state", "blockers",
"approval_required", "readiness_canary", "liveness_canary", "exit_canary",
"verification_state", "checkpoint", "evidence_refs", "failure_class",
"completion_state", "candidate_next_action",
)}
VALID["schema_version"] = 1
VALID["blockers"] = []
VALID["evidence_refs"] = []
VALID["approval_required"] = False
missing_one = dict(VALID)
del missing_one["depth"]
missing_several = dict(VALID)
for gone in ("stage", "liveness_canary", "checkpoint"): # FIELDS order
del missing_several[gone]
all_missing = {"schema_version": 1}
validate_cases = []
for _name, proj in (
("valid_full", dict(VALID)),
("missing_one", missing_one),
("missing_several", missing_several),
("all_missing", all_missing),
("schema_2", dict(VALID, schema_version=2)),
("schema_str", dict(VALID, schema_version="X")),
("schema_none", dict(VALID, schema_version=None)),
("schema_true", dict(VALID, schema_version=True)), # bool subclass → valid
("schema_1_0", dict(VALID, schema_version=1.0)), # numeric equality → valid
("schema_list", dict(VALID, schema_version=[1])),
("schema_dict", dict(VALID, schema_version={"a": 1})),
):
validate_cases.append(("cpj_freeze_validate", (proj,), {}))
# ── project ─────────────────────────────────────────────────────────────────
project_cases = [
# (args: scaffold_spec, contract_id, bridge_spec-or-None, kwargs: oracle kwargs)
({"load": doc_of(), "project_id": "testproj"}, "B-1", None, {}),
({"load": {}}, "B-1", None, {}), # no project_id attr → getattr "" default
({"load": doc_of(FULL_ENTITY), "project_id": "testproj"}, "B-1", None,
dict(PROJECTION_KWARGS)),
({"load": doc_of(FULL_ENTITY), "project_id": "testproj"}, "B-1", None,
dict(FULL_KWARGS)),
# blocker dict: class default + >120 evidence truncation.
({"load": doc_of(entity(
"B-2", identities={"blocker": {"evidence": LONG}}))}, "B-2", None, {}),
({"load": doc_of(entity(
"B-3", identities={"blocker": {"class": "SCOPE", "evidence": "short"}}))},
"B-3", None, {}),
# blocker string variant + the empty-string falsy skip.
({"load": doc_of(entity(
"B-4", identities={"blocker": "hard blocker string"}))}, "B-4", None, {}),
({"load": doc_of(entity(
"B-5", identities={"blocker": ""}))}, "B-5", None, {}),
# evidence truncation + empty rows skipped.
({"load": doc_of(entity(
"B-6",
checkpoints=[{"evidence": LONG}, {"evidence": ""}, {"no": "e"}]))},
"B-6", None, {}),
# approval_required legs: truthy non-bool / state REQUIRED / phase.
({"load": doc_of(entity(
"B-7", ext={"decision_trace": {"approval": {"required": "yes"}}}))},
"B-7", None, {}),
({"load": doc_of(entity(
"B-8", ext={"decision_trace": {
"approval": {"required": False, "state": "REQUIRED"}}}))},
"B-8", None, {}),
({"load": doc_of(entity("B-9", phase="awaiting_approval"))}, "B-9", None, {}),
# falsy 0 approval + missing trace entirely.
({"load": doc_of(entity(
"B-10", ext={"decision_trace": {"approval": {"required": 0}}}))},
"B-10", None, {}),
# canaries: null RIDES (dict.get returns None — the default applies only
# when MISSING) + the others present.
({"load": doc_of(entity("B-11", ext={
"readiness_canary": None, "liveness_canary": "live"}))}, "B-11", None, {}),
# mode/depth falsy collapse ("") + null next_action.
({"load": doc_of(entity(
"B-12", identities={"construction_mode": "", "depth": 0,
"next_action": None}))},
"B-12", None, {}),
# ── bridge rows ──
({"load": doc_of(), "project_id": "testproj"}, "B-13",
{"__mode__": "found", "record": {"status": "WAITING_EXTERNAL", "wait_id": "w-9"}},
dict(PROJECTION_KWARGS, operation_id="op-x")),
({"load": doc_of(), "project_id": "testproj"}, "B-14",
{"__mode__": "found", "record": {"status": "READY_TO_RESUME",
"wait_id": "w-10",
"ext": {"operation_id": "op-y"}}},
dict(PROJECTION_KWARGS, operation_id="op-y", correlation_id="corr-2")),
({"load": doc_of(), "project_id": "testproj"}, "B-15",
None, dict(PROJECTION_KWARGS, operation_id="op-z")),
({"load": doc_of(), "project_id": "testproj"}, "B-16",
{"__mode__": "oserr"}, dict(PROJECTION_KWARGS, operation_id="op-e")),
({"load": doc_of(), "project_id": "testproj"}, "B-17",
{"__mode__": "runtimeerr"}, dict(PROJECTION_KWARGS, operation_id="op-r")),
({"load": doc_of(), "project_id": "testproj"}, "B-18",
{"__mode__": "found", "record": {"status": "S", "wait_id": "w-1"}},
dict(PROJECTION_KWARGS, operation_id="")),
]
def project_row(spec, cid, bridge, kwargs):
return ("cpj_freeze_project", (spec, cid, bridge), kwargs)
# ── write_mini_doc ──────────────────────────────────────────────────────────
WIDE_ENTITY = {
"id": "contract:M-1",
"phase": "closed",
"identities": {
"objective": "build the mini-doc path",
"construction_mode": "BUILD_NEW",
"depth": "standard",
"task_ref": "T16.9",
},
"ext": {
"affected_paths": ["src/x.py", "tests/x.py"],
"contract_quality": {"correctly_predicted": 3, "genuinely_unexpected_new": 0,
"scope_check": "green", "zebra_last": True},
"readiness_canary": "ready",
},
"checkpoints": [{"evidence": "evidence-a"}, {"evidence": "evidence-b"}],
}
mini_doc_specs = [
# full entity: objective + list surface + quality + task_ref + evidence.
({"load": doc_of(WIDE_ENTITY), "project_id": "testproj"}, "M-1"),
# objective fallback chain: identities.need.
({"load": doc_of(entity("M-2", identities={"need": "the need text"})),
"project_id": "p"}, "M-2"),
# objective fallback chain: ext.need.objective.
({"load": doc_of(entity("M-3", ext={"need": {"objective": "deep objective"}})),
"project_id": "p"}, "M-3"),
# no objective at all → placeholder line.
({"load": doc_of(entity("M-4", identities={})), "project_id": "p"}, "M-4"),
# surface: single string wrapped.
({"load": doc_of(entity("M-5", ext={"affected_paths": "src/only.py"})),
"project_id": "p"}, "M-5"),
# surface: decision_trace.affected_surfaces.affected_paths fallback.
({"load": doc_of(entity("M-6", ext={"decision_trace": {
"affected_surfaces": {"affected_paths": ["src/c.py"]}}})),
"project_id": "p"}, "M-6"),
# surface: ids.affected_surface fallback.
({"load": doc_of(entity("M-7", identities={"affected_surface": "src/d.py"})),
"project_id": "p"}, "M-7"),
# no surface anywhere → "(no affected surface recorded)".
({"load": doc_of(entity("M-8", identities={}, ext={})), "project_id": "p"}, "M-8"),
# quality empty dict → 'not recorded'.
({"load": doc_of(entity("M-9", ext={"contract_quality": {}})),
"project_id": "p"}, "M-9"),
# quality missing → 'not recorded'.
({"load": doc_of(entity("M-10", ext={})), "project_id": "p"}, "M-10"),
# no task_ref → trailing period only.
({"load": doc_of(entity("M-11", identities={"objective": "o"})),
"project_id": "p"}, "M-11"),
# no checkpoints → "(none recorded)" evidence section.
({"load": doc_of(entity("M-12", identities={"objective": "o"})),
"project_id": "p"}, "M-12"),
# empty surface LIST truthiness edge ([] → falsy → placeholder).
({"load": doc_of(entity("M-13", ext={"affected_paths": []})),
"project_id": "p"}, "M-13"),
]
mini_doc_cases = [
("cpj_freeze_write_mini_doc", (spec, cid), {})
for spec, cid in mini_doc_specs
]
cases = (
contract_entity_cases
+ validate_cases
+ [project_row(*r) for r in project_cases]
+ mini_doc_cases
)
truth = freeze("rune.construction_projection", cases,
oracle_module="rune.construction_projection")
OUT = REPO / "src" / "rust" / "construction_projection" / "src"
OUT.mkdir(parents=True, exist_ok=True)
write_envelope(NOW, truth, OUT / "frozen_truth.json")
write(truth, OUT / "frozen_truth.verify.json")
print(f"wrote {len(truth)} cases -> {OUT / 'frozen_truth.json'} (+ .verify.json)")
doc = json.loads(json.dumps(truth))
print("case mix:", {k: sum(1 for c in doc if c["fn"] == k)
for k in sorted({c["fn"] for c in doc})})
+34
View File
@@ -0,0 +1,34 @@
#!/usr/bin/env python3
"""Freeze the dichotomy-wave truth corpus for src/rune/context_pressure.py.
LAW (poisoned-truth): RUNE_CPS_CORE / RUNE_CONTEXT_PRESSURE_CORE=python —
pinned by the scripts/cps_freeze_seams rig; truth is generated by the
PYTHON ORACLE ONLY (the facade floor + the real CLI for the dispatch rows).
Run:
PYTHONPATH=scripts/cps_freeze_seams python3 scripts/gen_context_pressure_truth.py
Portable law = the pure compute + entry assembly:
estimate_tokens (codepoint len, max(1, int(len/3.5)))
measure_pressure (raw-pressure gates, banker round(x, 3))
detect_degradation(trend/repetition/generic signals, max(0, x) type law)
handle_hook (data truthiness, message/text/str(data) fallback)
log_measurement ({"timestamp", "session_id", **measurement} spread)
read_log (deque(maxlen) tail, blank/invalid skip)
log_stats (counts + exact AttributeError on non-dict lines)
main (argparse shapes, .1% renders, indent=2 dumps, code-2 law)
File IO + wall clock stay in the facade (no-clock law: now is an argument).
"""
from __future__ import annotations
import sys
from pathlib import Path
REPO = Path(__file__).resolve().parents[1]
if str(REPO / "scripts") not in sys.path:
sys.path.insert(0, str(REPO / "scripts"))
import context_pressure_truth # noqa: E402
if __name__ == "__main__":
raise SystemExit(context_pressure_truth.main())
+584
View File
@@ -0,0 +1,584 @@
#!/usr/bin/env python3
"""gen_contracts_gap_truth.py — freeze/replay parity truth for the contracts
gap-close (dichotomy wave, #2479 tranche).
Freeze mode (default): exercises the LIVE Python oracle
(src/rune/contracts.py — the 7 functions the audit names as missing:
_ct_core, _resolve_and_project, _run_contract_python, capture_signatures,
save_signatures, load_signatures, main, plus run_contract/run_all_contracts
companions) and records the truth into
src/rust/contracts/src/ct_gap_truth.json.
The file has two sections:
* ``cases`` — shared-harness schema, re-verifiable with
``PYTHONPATH=src python3 scripts/freeze_truth.py --verify
src/rust/contracts/src/ct_gap_truth.json --module rune.contracts``.
Contract-taking fns cross via the harness ``recv`` form: the receiver
spec rebuilds a live ``Contract`` (cls __new__ + attrs, no IO) and the
fn is called as an unbound-style first argument. ``expect_type`` stays
None because a type object is not JSON-safe — the type-check branches
are covered by the pre-existing 58-case ``ct_truth.json`` battery,
replayed through the new ``_run_contract_python`` Rust kernel.
``check_signature_drift()`` reads the real signatures file (no args) so
it stays out of the harness set (its compare kernel is already frozen
in ct_truth.json's drift_cases).
* ``extra`` — oracle-derived rows the harness cannot round-trip
(``ContractResult`` dataclasses are not JSON-native; ``save/load`` touch
the signatures file; ``main`` drives argv/stdout/exit-code):
``result_cases`` (run_contract / _run_contract_python asdicts),
``run_all`` (42 asdicts), ``probes`` (loader-state -> gate bool),
``file_cases`` (per-case deterministic dirs, no paths in expectations),
``main_cases`` (argv/stdout/exit-code). Embedded VERBATIM in the
``gap_battery`` alongside ``cases``.
Replay mode (--replay): re-runs the SAME scenarios with the Rust core
delegation ACTIVE and asserts facade-level and kernel-level parity.
Poisoned-truth law: freeze pins RUNE_CONTRACTS_CORE=python BEFORE any
oracle import (the shared harness also pins it per module stem).
Mutation law: case inputs are deep-copied BEFORE they reach the oracle.
Deterministic-dirs law: file/main cases redirect SIGNATURES_FILE into
/tmp/ct-gap-freeze/<case>/ (fixed names — identical at freeze, --verify
and --replay); expectations never embed the paths.
"""
import copy
import dataclasses
import io
import json
import os
import sys
from contextlib import redirect_stdout
REPO = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
TRUTH_PATH = os.path.join(REPO, "src", "rust", "contracts",
"src", "ct_gap_truth.json")
FREEZE_ROOT = "/tmp/ct-gap-freeze"
REPLAY = "--replay" in sys.argv
sys.path.insert(0, os.path.join(REPO, "scripts"))
sys.path.insert(0, os.path.join(REPO, "src"))
from freeze_truth import freeze # noqa: E402
if not REPLAY:
os.environ["RUNE_CONTRACTS_CORE"] = "python" # poisoned-truth law
else:
os.environ.pop("RUNE_CONTRACTS_CORE", None) # live-parity law
sys.path.insert(0, os.path.join(REPO, "src", "rune"))
import contracts as oracle_mod # noqa: E402
def contract_dict(name, module, function, args=(), kwargs=None, **kw):
"""A JSON-safe Contract field dict (exact dataclass field set)."""
return {
"name": name,
"module": module,
"function": function,
"args": list(args),
"kwargs": dict(kwargs or {}),
"expect_type": None,
"expect_keys": kw.get("expect_keys"),
"expect_len": kw.get("expect_len"),
"expect_not_none": kw.get("expect_not_none", False),
"expect_callable": kw.get("expect_callable", False),
"skip_on_import_error": kw.get("skip_on_import_error", True),
}
def recv_case(fn, contract, args=()):
"""Harness case in recv form: {"cls": "Contract", <field>: value}
rebuilds a live Contract receiver; the fn is called fn(contract, *args).
The harness records the result AND the post-call receiver attrs —
contracts are never mutated, so attrs echo the inputs."""
recv = {"cls": "Contract"}
recv.update(copy.deepcopy(contract))
return {"fn": fn, "recv": recv, "args": list(args), "kwargs": {}}
def live_contract(d):
"""Rebuild the live Contract from a JSON-safe field dict."""
return oracle_mod.Contract(
name=d["name"], module=d["module"], function=d["function"],
args=tuple(d["args"]), kwargs=dict(d["kwargs"]),
expect_type=None, expect_keys=d["expect_keys"],
expect_len=d["expect_len"], expect_not_none=d["expect_not_none"],
expect_callable=d["expect_callable"],
skip_on_import_error=d["skip_on_import_error"],
)
# ── branch inventory ───────────────────────────────────────────────────────
# _resolve_and_project + run_contract/_run_contract_python share this
# inventory: every phase branch (found / import_error / import-crash /
# not_found / call-crash / project-crash), the expect_callable
# short-circuit (callable and non-callable), the plain-attribute path,
# and each expectation branch (not-none, keys ok/missing, len
# ok/mismatch). expect_type stays None (JSON law).
RESOLVE_CASES = [
("rp-found-dict", contract_dict("rp found", "ct_rig", "make_ok")),
("rp-found-none-notnone-fail", contract_dict(
"rp none", "ct_rig", "make_none", expect_not_none=True)),
("rp-found-str-attr", contract_dict(
"rp attr", "ct_rig", "ATTR_VALUE")),
("rp-call-crash", contract_dict("rp crash", "ct_rig", "raise_on_call")),
("rp-project-crash", contract_dict("rp proj", "ct_rig", "make_bad_len")),
("rp-import-error", contract_dict(
"rp import", "definitely_missing_module_xyz", "whatever")),
("rp-import-crash", contract_dict(
"rp badimport", "ct_rig_badimport", "whatever")),
("rp-not-found", contract_dict(
"rp notfound", "ct_rig", "no_such_fn_xyz")),
("rp-expect-callable", contract_dict(
"rp callable", "ct_rig", "make_ok", expect_callable=True)),
("rp-expect-callable-not", contract_dict(
"rp notcallable", "ct_rig", "ATTR_VALUE", expect_callable=True)),
("rp-keys-ok", contract_dict(
"rp keys", "ct_rig", "make_ok", expect_keys=["ok"])),
("rp-keys-missing", contract_dict(
"rp keys miss", "ct_rig", "make_ok", expect_keys=["nope"])),
("rp-len-ok", contract_dict(
"rp len", "ct_rig", "make_ok", expect_len=2)),
("rp-len-mismatch", contract_dict(
"rp len miss", "ct_rig", "make_ok", expect_len=9)),
]
# _project: (contract, JSON-safe result) — every projection branch
# (dict/empty-dict/list/str/None/int-unsized/bool). expect_type None →
# type_ok is always null here; the True/False branches live in the
# 58-case ct_truth.json battery.
PROJECT_CASES = [
("pj-dict", contract_dict("pj", "ct_rig", "make_ok"),
{"ok": True, "n": 3}),
("pj-empty-dict", contract_dict("pj", "ct_rig", "make_ok"), {}),
("pj-list", contract_dict("pj", "ct_rig", "make_ok"), [1, 2, 3]),
("pj-str", contract_dict("pj", "ct_rig", "make_ok"), "hello"),
("pj-none", contract_dict("pj", "ct_rig", "make_ok"), None),
("pj-int-unsized", contract_dict("pj", "ct_rig", "make_ok"), 42),
("pj-true", contract_dict("pj", "ct_rig", "make_ok"), True),
]
def freeze_harness_cases():
"""Cases for the shared harness (JSON-safe in/out, --verify clean)."""
entries = [("_ct_core", [], {})]
for _tag, c in RESOLVE_CASES:
entries.append(recv_case("_resolve_and_project", c))
for _tag, c, result in PROJECT_CASES:
entries.append(recv_case("_project", c, [result]))
entries.append(("capture_signatures", [], {}))
return freeze("rune.contracts", entries, oracle_module="rune.contracts")
def case_dir(name):
d = os.path.join(FREEZE_ROOT, name)
os.makedirs(d, exist_ok=True)
return d
def seed_drifted(d):
"""Write a saved-sigs file that drifts from the live capture on
exactly one key (the alphabetically first)."""
cur = oracle_mod.capture_signatures()
key = sorted(cur)[0]
saved = {key: "(old_sig)", sorted(cur)[1]: cur[sorted(cur)[1]]}
oracle_mod.SIGNATURES_FILE = os.path.join(d, "sigs.json")
with open(oracle_mod.SIGNATURES_FILE, "w") as f:
json.dump(saved, f, indent=2)
return key, cur[key]
def freeze_extra():
"""Oracle-derived rows the harness cannot round-trip (dataclass
returns, file IO, argv/stdout). Per-case deterministic dirs; no paths
in expectations."""
extra = {}
# result_cases: run_contract + _run_contract_python asdicts over the
# resolve inventory (pinned core: run_contract == oracle path), plus
# the skip=False import-error fail branch.
result_cases = []
for tag, c in RESOLVE_CASES:
for fn_name in ("run_contract", "_run_contract_python"):
fn = getattr(oracle_mod, fn_name)
got = fn(live_contract(copy.deepcopy(c)))
result_cases.append({
"name": f"{fn_name}:{tag}",
"contract": copy.deepcopy(c),
"fn": fn_name,
"expected": dataclasses.asdict(copy.deepcopy(got)),
})
noskip = contract_dict("rp import no-skip",
"definitely_missing_module_xyz", "whatever",
skip_on_import_error=False)
for fn_name in ("run_contract", "_run_contract_python"):
fn = getattr(oracle_mod, fn_name)
got = fn(live_contract(copy.deepcopy(noskip)))
result_cases.append({
"name": f"{fn_name}:rp-import-noskip-fail",
"contract": copy.deepcopy(noskip),
"fn": fn_name,
"expected": dataclasses.asdict(copy.deepcopy(got)),
})
extra["result_cases"] = result_cases
# delegated_cases: the facade's DELEGATED run_contract outputs (Rust
# kernel over the resolution). Recorded by calling the loader kernel
# directly (the env pin only gates loader.core(), not the FFI). For
# every resolve row the kernel verdict is frozen next to the oracle
# verdict — one known path divergence: a result whose PROJECTION
# raises (rp-project-crash) is a crash on the delegated path (eager
# projection) but a PASS on the pure-Python path (lazy checks). Both
# behaviors are oracle-shipped; the battery replays both.
from rune import contracts_loader # noqa: E402
delegated = []
delegated_inventory = [(t, c) for t, c in RESOLVE_CASES] + [
("rp-import-noskip-fail", noskip)]
for tag, c in delegated_inventory:
live = live_contract(copy.deepcopy(c))
phase, err, call, proj = oracle_mod._resolve_and_project(
copy.deepcopy(live))
out = contracts_loader.verdict({
"name": c["name"], "module": c["module"],
"function": c["function"], "expect_type": None,
"expect_keys": c["expect_keys"], "expect_len": c["expect_len"],
"expect_not_none": c["expect_not_none"],
"expect_callable": c["expect_callable"],
"skip_on_import_error": c["skip_on_import_error"],
"phase": phase, "phase_error": err, "callable": call,
"projection": proj})
delegated.append({
"name": f"run_contract:{tag}",
"contract": copy.deepcopy(c),
"resolution": [phase, err, call, proj],
"expected": out,
})
extra["delegated_cases"] = delegated
# run_all: the full 42-result order-preserving run, plus the
# resolution inputs (spec fields + _resolve_and_project outcome) that
# produced them — the battery replays run_all_contracts over these.
# Two rows are env-pinned (sibling crates' .so build state decides
# their error text); they are frozen as captured in this checkout.
run_all = [
dataclasses.asdict(copy.deepcopy(r))
for r in oracle_mod.run_all_contracts()
]
run_all_inputs = []
for c in oracle_mod.CONTRACTS:
phase, err, call, proj = oracle_mod._resolve_and_project(c)
run_all_inputs.append({
"name": c.name, "module": c.module, "function": c.function,
"expect_type": (c.expect_type.__name__
if c.expect_type is not None else None),
"expect_keys": c.expect_keys, "expect_len": c.expect_len,
"expect_not_none": c.expect_not_none,
"expect_callable": c.expect_callable,
"skip_on_import_error": c.skip_on_import_error,
"phase": phase, "phase_error": err, "callable": call,
"projection": proj,
})
assert len(run_all) == len(run_all_inputs) == len(oracle_mod.CONTRACTS)
extra["run_all"] = run_all
extra["run_all_inputs"] = run_all_inputs
# probes: loader states -> gate bool (module objects are not
# JSON-safe; the recorded bool is `result is not None` from live calls).
real_loader = oracle_mod.contracts_loader
class _NoCore:
def core(self):
return None
class _RaisingCore:
def core(self):
raise RuntimeError("rig core failure")
class _LiveCore:
def core(self):
return object()
probes = []
for tag, loader in (("probe:loader-none", None),
("probe:core-none", _NoCore()),
("probe:core-raises", _RaisingCore()),
("probe:core-live", _LiveCore())):
oracle_mod.contracts_loader = loader
try:
got = oracle_mod._ct_core()
probes.append({"name": tag, "expected": got is not None})
finally:
oracle_mod.contracts_loader = real_loader
extra["probes"] = probes
# file_cases: save/load through per-case dirs (SIGNATURES_FILE seam).
real_file = oracle_mod.SIGNATURES_FILE
file_cases = []
sig_sets = {
"sigset:two": {"m.f": "(x)", "n.g": "(a, b=None)"},
"sigset:empty": {},
"sigset:unicode": {"m.f": "(s='héllo → world')"},
}
try:
for tag, sigs in sig_sets.items():
d = case_dir(tag.replace(":", "-"))
oracle_mod.SIGNATURES_FILE = os.path.join(d, "sigs.json")
if os.path.exists(oracle_mod.SIGNATURES_FILE):
os.remove(oracle_mod.SIGNATURES_FILE)
oracle_mod.save_signatures(copy.deepcopy(sigs))
with open(oracle_mod.SIGNATURES_FILE) as f:
content = f.read()
loaded = oracle_mod.load_signatures()
file_cases.append({"name": tag, "sigs": copy.deepcopy(sigs),
"content": content,
"expected": copy.deepcopy(loaded)})
# load-missing -> {} (no file on disk).
d = case_dir("sigset-missing")
oracle_mod.SIGNATURES_FILE = os.path.join(d, "absent.json")
if os.path.exists(oracle_mod.SIGNATURES_FILE):
os.remove(oracle_mod.SIGNATURES_FILE)
file_cases.append({"name": "sigset:missing",
"sigs": {},
"content": None,
"expected": oracle_mod.load_signatures()})
# load-corrupt -> {} (suppressed exception branch).
d = case_dir("sigset-corrupt")
oracle_mod.SIGNATURES_FILE = os.path.join(d, "corrupt.json")
with open(oracle_mod.SIGNATURES_FILE, "w") as f:
f.write("{not json")
file_cases.append({"name": "sigset:corrupt",
"sigs": {},
"content": "{not json",
"expected": oracle_mod.load_signatures()})
finally:
oracle_mod.SIGNATURES_FILE = real_file
extra["file_cases"] = file_cases
# main_cases: argv dispatch (stdout captured, SystemExit caught,
# signatures file redirected per case). Call-time prints from live
# contract modules interleave into `test` output (deterministic in
# this env; Python-side IO — the battery splits at the first result
# line). The two -drift variants pre-seed a drifted saved file so the
# drift-printing branches are frozen too.
real_argv = sys.argv
main_cases = []
try:
for tag, argv in (("main:usage", ["contracts.py"]),
("main:test", ["contracts.py", "test"]),
("main:signatures", ["contracts.py", "signatures"]),
("main:drift", ["contracts.py", "drift"]),
("main:bogus", ["contracts.py", "bogus"])):
d = case_dir(tag.replace(":", "-"))
oracle_mod.SIGNATURES_FILE = os.path.join(d, "sigs.json")
if os.path.exists(oracle_mod.SIGNATURES_FILE):
os.remove(oracle_mod.SIGNATURES_FILE)
sys.argv = list(argv)
buf = io.StringIO()
code = 0
with redirect_stdout(buf):
try:
oracle_mod.main()
except SystemExit as e:
code = e.code if isinstance(e.code, int) else 1
main_cases.append({"name": tag, "argv": list(argv),
"exit_code": code,
"expected": buf.getvalue()})
for tag, argv in (("main:test-drift", ["contracts.py", "test"]),
("main:drift-drift", ["contracts.py", "drift"])):
d = case_dir(tag.replace(":", "-"))
key, cur_sig = seed_drifted(d)
sys.argv = list(argv)
buf = io.StringIO()
code = 0
with redirect_stdout(buf):
try:
oracle_mod.main()
except SystemExit as e:
code = e.code if isinstance(e.code, int) else 1
main_cases.append({
"name": tag, "argv": list(argv), "exit_code": code,
"drift_key": key, "drift_line": f"{key}: (old_sig) → {cur_sig}",
"expected": buf.getvalue()})
finally:
sys.argv = real_argv
oracle_mod.SIGNATURES_FILE = real_file
extra["main_cases"] = main_cases
return extra
def canon(x):
return json.dumps(x, sort_keys=True, default=str)
def replay():
"""Live parity: facade (delegation active) + kernel (loader direct)
against the frozen file."""
with open(TRUTH_PATH) as f:
doc = json.load(f)
failures = 0
# Warm import order (mirrors freeze: run_all ran first, so every
# contract module is in sys.modules before main_cases capture stdout).
oracle_mod.run_all_contracts()
# Facade replay A: harness-case fns through the live oracle must
# reproduce the frozen expectations (recv rebuilt by hand — the
# harness does this at --verify time). _ct_core is pin/env-dependent
# (the probes section covers its branch logic).
for c in doc["cases"]:
if c["fn"] == "_ct_core":
continue
fn = getattr(oracle_mod, c["fn"])
if "recv" in c:
got = fn(live_contract(c["recv"]), *copy.deepcopy(c["args"]))
want = c["expected"]["result"]
else:
got = fn(*copy.deepcopy(c["args"]), **copy.deepcopy(c["kwargs"]))
want = c["expected"]
if canon(got) != canon(want):
failures += 1
print(f"HARNESS DIVERGE {c['fn']} {c['recv'].get('name', c['args'])}"
f"\n got: {canon(got)[:300]}\n want: {canon(want)[:300]}")
# Facade replay B: run_contract/_run_contract_python over the resolve
# inventory must reproduce the frozen result_cases (frozen on the
# pinned python path — run_contract rows replay with the pin set so
# the facade takes the oracle path; the delegated path is replayed
# kernel-side below).
for rc in doc["extra"]["result_cases"]:
fn = getattr(oracle_mod, rc["fn"])
if rc["fn"] == "run_contract":
os.environ["RUNE_CONTRACTS_CORE"] = "python"
try:
got = dataclasses.asdict(
fn(live_contract(copy.deepcopy(rc["contract"]))))
finally:
os.environ.pop("RUNE_CONTRACTS_CORE", None)
if canon(got) != canon(rc["expected"]):
failures += 1
print(f"FACADE DIVERGE {rc['name']}"
f"\n got: {canon(got)[:300]}"
f"\n want: {canon(rc['expected'])[:300]}")
# Facade replay C: save/load through the per-case dirs (recreated
# identically) must reproduce content + loaded maps. The missing and
# corrupt rows only exercise load (mirroring freeze).
real_file = oracle_mod.SIGNATURES_FILE
real_argv = sys.argv
try:
for fc in doc["extra"]["file_cases"]:
d = case_dir(fc["name"].replace(":", "-"))
path = os.path.join(d, "sigs.json")
if fc["name"] == "sigset:missing":
path = os.path.join(d, "absent.json")
elif fc["name"] == "sigset:corrupt":
path = os.path.join(d, "corrupt.json")
oracle_mod.SIGNATURES_FILE = path
if os.path.exists(path):
os.remove(path)
if fc["name"] == "sigset:corrupt":
with open(path, "w") as f:
f.write(fc["content"])
elif fc["name"] != "sigset:missing":
oracle_mod.save_signatures(copy.deepcopy(fc["sigs"]))
with open(path) as f:
content = f.read()
if content != fc["content"]:
failures += 1
print(f"FILE DIVERGE {fc['name']} content\n"
f" got: {content[:200]}"
f"\n want: {fc['content'][:200]}")
loaded = oracle_mod.load_signatures()
if canon(loaded) != canon(fc["expected"]):
failures += 1
print(f"FILE DIVERGE {fc['name']} loaded")
# Facade replay D: argv dispatch (stdout + exit code). The -drift
# variants re-seed the drifted saved file first (mirroring freeze).
for mc in doc["extra"]["main_cases"]:
d = case_dir(mc["name"].replace(":", "-"))
oracle_mod.SIGNATURES_FILE = os.path.join(d, "sigs.json")
if os.path.exists(oracle_mod.SIGNATURES_FILE):
os.remove(oracle_mod.SIGNATURES_FILE)
if mc["name"].endswith("-drift"):
seed_drifted(d)
sys.argv = list(mc["argv"])
buf = io.StringIO()
code = 0
with redirect_stdout(buf):
try:
oracle_mod.main()
except SystemExit as e:
code = e.code if isinstance(e.code, int) else 1
if code != mc["exit_code"] or buf.getvalue() != mc["expected"]:
failures += 1
print(f"MAIN DIVERGE {mc['name']} exit {code}!= {mc['exit_code']}"
f" or stdout drift\n got: {buf.getvalue()[:200]}"
f"\n want: {mc['expected'][:200]}")
finally:
oracle_mod.SIGNATURES_FILE = real_file
sys.argv = real_argv
# Kernel replay: ct_verdict over the frozen resolutions must
# reproduce the frozen delegated verdicts (the delegated path's
# contract — including the eager-projection crash row).
from rune import contracts_loader # noqa: E402
if contracts_loader.core() is None:
print("REPLAY ABORT: kernel not built")
return 2
checked = 0
for dc in doc["extra"]["delegated_cases"]:
c = dc["contract"]
phase, err, call, proj = dc["resolution"]
out = contracts_loader.verdict({
"name": c["name"], "module": c["module"],
"function": c["function"], "expect_type": None,
"expect_keys": c["expect_keys"], "expect_len": c["expect_len"],
"expect_not_none": c["expect_not_none"],
"expect_callable": c["expect_callable"],
"skip_on_import_error": c["skip_on_import_error"],
"phase": phase, "phase_error": err, "callable": call,
"projection": proj})
checked += 1
if canon(out) != canon(dc["expected"]):
failures += 1
print(f"KERNEL DIVERGE {dc['name']}"
f"\n got: {canon(out)[:300]}"
f"\n want: {canon(dc['expected'])[:300]}")
n_results = len(doc["extra"]["result_cases"])
n_delegated = len(doc["extra"]["delegated_cases"])
print(f"replay: failures={failures} "
f"(facade {n_results}, kernel {n_delegated} checked)")
return 1 if failures else 0
def main():
if REPLAY:
return replay()
cases = freeze_harness_cases()
extra = freeze_extra()
doc = {"cases": cases, "extra": extra,
"note": "Frozen via scripts/gen_contracts_gap_truth.py against "
"the live Python oracle (RUNE_CONTRACTS_CORE=python). "
"cases: shared-harness schema (--verify clean, recv-form "
"Contract receivers). extra: oracle-derived rows "
"(dataclass/file/argv surface). Battery embeds this "
"VERBATIM."}
with open(TRUTH_PATH, "w") as f:
json.dump(doc, f, indent=1)
f.write("\n")
total = (len(cases) + len(extra["result_cases"])
+ len(extra["delegated_cases"]) + 1
+ len(extra["run_all_inputs"]) + len(extra["probes"])
+ len(extra["file_cases"]) + len(extra["main_cases"]))
print(f"frozen {total} rows -> {os.path.relpath(TRUTH_PATH, REPO)} "
f"({len(cases)} harness + {len(extra['result_cases'])} results + "
f"{len(extra['delegated_cases'])} delegated + "
f"run_all/{len(extra['run_all'])}+{len(extra['run_all_inputs'])} inputs"
f" + {len(extra['probes'])} probes + "
f"{len(extra['file_cases'])} file + {len(extra['main_cases'])} main)")
return 0
if __name__ == "__main__":
sys.exit(main())
+416
View File
@@ -0,0 +1,416 @@
#!/usr/bin/env python3
"""gen_cron_engine_gap_truth.py — cron-engine gap-closing truth battery
(#2479 dichotomy wave, GO side).
Closes the PARTIAL audit gaps: to_dict, run_task (method + module),
fire_on_task_complete, start/stop, _run_loop, _execute_task,
_log_execution/_log_error, get_cron_engine/start_engine/stop_engine
(parseCronField/shouldRun already existed; extra branch rows frozen too).
Uses the SHARED harness (scripts/freeze_truth.py) with the hook_engine
wrapper-shim law: CronEngine methods are stateful and touch the clock,
HOME (~/.rune/cron.log), subprocesses and threads — none of which the
bare harness pins. Every row is frozen against a module-level WRAPPER
(_ce_* below, in THIS module registered as
gen_cron_engine_gap_truth_shims):
* FROZEN clock: cron_engine.datetime patched with the harness's frozen
class (module-level import → the patch reaches every method).
* HERMETIC per-row HOME: fresh mkdtemp per wrapper call; every path in
the capture is tokenized to <CE_HOME> (no absolute paths in truth).
* _run_loop rows: cron_engine.time swapped for a stopper whose sleep()
flips the engine's running flag — exactly ONE loop iteration, then a
clean exit (deterministic under the frozen clock).
* record_failure (rune.subsystem_health) is neutralized during rows —
the oracle imports it lazily inside except blocks, and its ledger
writes are outside the captured surface.
* capture shape: {"result", "post": {running, storage_path, tasks
(insertion-ordered [name, to_dict] pairs), _last_run_minute},
"files" (~/.rune dir inventory), "storage", "log"}.
Verify (this file ships its own --verify — same byte-compare law as the
harness, plus the shim-module registration the stock CLI cannot do):
python3 scripts/gen_cron_engine_gap_truth.py --verify
Usage: python3 scripts/gen_cron_engine_gap_truth.py (from repo root)
"""
import json
import os
import sys
import tempfile
from pathlib import Path
REPO = Path(__file__).resolve().parent.parent
sys.path.insert(0, str(REPO / "scripts"))
sys.path.insert(0, str(REPO / "src"))
from freeze_truth import freeze, write_envelope, _frozen_clock # noqa: E402
FROZEN_NOW = "2026-10-13T09:20:00"
TOKEN = "<CE_HOME>"
os.environ["RUNE_FROZEN_NOW"] = FROZEN_NOW
os.environ["RUNE_CRON_ENGINE_CORE"] = "python" # poisoned-truth law
from rune import cron_engine as CE # noqa: E402
import rune.subsystem_health as _SH # noqa: E402
_CE = {"ready": False}
def _prepare():
"""Idempotent per-process pinning: frozen clock + neutral recorder."""
if not _CE["ready"]:
CE.datetime = _frozen_clock(FROZEN_NOW)
_SH.record_failure = lambda *a, **k: True
_CE["ready"] = True
return CE
class _StopTime:
"""time-module stand-in: first sleep() stops the engine's loop."""
def __init__(self, engine):
self._engine = engine
def sleep(self, _s):
if self._engine is not None:
self._engine.running = False
def _hermetic_home():
home = tempfile.mkdtemp(prefix="ce-freeze-")
os.environ["HOME"] = home
return home
def _log_path(home):
return os.path.join(home, ".rune", "cron.log")
def _build_engine(state, home):
e = CE.CronEngine.__new__(CE.CronEngine)
e.storage_path = state["storage_path"].replace(TOKEN, home)
e.tasks = {}
for name, t in state.get("tasks", {}).items():
e.tasks[name] = CE.CronTask(**t)
e.running = state.get("running", False)
e.thread = None
e._last_run_minute = dict(state.get("_last_run_minute", {}))
return e
def _seed_log(state, home):
d = os.path.dirname(_log_path(home))
for fname, size in state.get("seed_log", {}).items():
os.makedirs(d, exist_ok=True)
with open(os.path.join(d, fname), "wb") as f:
f.write(b"x" * size)
def _capture(e, home, result=None):
d = os.path.dirname(_log_path(home))
files = {}
if os.path.isdir(d):
files = {f: os.path.getsize(os.path.join(d, f))
for f in sorted(os.listdir(d))
if os.path.isfile(os.path.join(d, f))}
def rd(p):
return open(p).read() if os.path.exists(p) else None
return {
"result": result,
"post": {
"running": e.running,
"storage_path": e.storage_path.replace(home, TOKEN),
"tasks": [[n, t.to_dict()] for n, t in e.tasks.items()],
"_last_run_minute": e._last_run_minute,
},
"files": files,
"storage": rd(e.storage_path),
"log": rd(_log_path(home)),
}
# ── wrappers (the frozen fn names) ────────────────────────────────
def _ce_to_dict(task):
_prepare()
return CE.CronTask(**task).to_dict()
def _ce_parse(field, low, high):
_prepare()
return sorted(CE.CronEngine._parse_cron_field(field, low, high))
def _ce_should_run(state, name, y, mo, d, h, mi):
ce = _prepare()
home = _hermetic_home()
e = _build_engine(state, home)
now = ce.datetime(y, mo, d, h, mi, tzinfo=ce.timezone.utc)
return e._should_run(e.tasks[name], now)
def _ce_run_task(state, name):
_prepare()
home = _hermetic_home()
e = _build_engine(state, home)
return _capture(e, home, result=e.run_task(name))
def _ce_fire(state):
_prepare()
home = _hermetic_home()
e = _build_engine(state, home)
return _capture(e, home, result=e.fire_on_task_complete())
def _ce_stop(state):
_prepare()
home = _hermetic_home()
e = _build_engine(state, home)
e.stop()
return _capture(e, home)
def _ce_execute(state, name):
_prepare()
home = _hermetic_home()
e = _build_engine(state, home)
e._execute_task(e.tasks[name])
return _capture(e, home)
def _ce_run_loop(state):
ce = _prepare()
home = _hermetic_home()
_seed_log(state, home)
e = _build_engine(state, home)
real = ce.time
ce.time = _StopTime(e)
try:
e._run_loop()
finally:
ce.time = real
return _capture(e, home)
def _ce_log_execution(state, name, rc):
_prepare()
home = _hermetic_home()
_seed_log(state, home)
e = _build_engine(state, home)
class _R: # CompletedProcess stand-in: only returncode is read
returncode = rc
e._log_execution(e.tasks[name], _R())
return _capture(e, home)
def _ce_log_error(state, name, msg):
_prepare()
home = _hermetic_home()
_seed_log(state, home)
e = _build_engine(state, home)
e._log_error(e.tasks[name], msg)
return _capture(e, home)
def _ce_singleton(op, name="", expr="*/5 * * * *", command="echo hi"):
ce = _prepare()
home = _hermetic_home()
ce._cron_engine = None
if op == "get":
e = ce.get_cron_engine()
return _capture(e, home, result=len(e.list_tasks()))
if op == "start_stop":
# REAL sleeper: the loop thread blocks in its 60s sleep, so the
# mid-capture (running=True) is race-free and stop()'s 5s join
# timeout is exercised — mirrors the Go battery exactly.
ce.start_engine()
mid = _capture(ce._cron_engine, home)
ce.stop_engine()
end = _capture(ce._cron_engine, home)
end["extra"] = mid
return end
if op == "module_run":
e = ce.get_cron_engine()
e.add_task(name, expr, command, "")
r = ce.run_task(name)
return _capture(ce._cron_engine, home, result=r)
if op == "module_list":
e = ce.get_cron_engine()
e.add_task(name, expr, command, "d1")
e.add_task(name + "-2", "*/5 * * * *", "echo two", "d2")
return _capture(e, home, result=[t["name"] for t in ce.list_tasks()])
raise ValueError(op)
# ── case matrix ───────────────────────────────────────────────────
def _task(name, expr, command, **over):
t = {"name": name, "cron_expression": expr, "command": command,
"description": "", "enabled": True, "last_run": None,
"next_run": None, "run_count": 0}
t.update(over)
return t
def _state(tasks=None, **over):
s = {"storage_path": TOKEN + "/.rune/cron.json", "tasks": tasks or {},
"running": False, "_last_run_minute": {}}
s.update(over)
return s
T_ECHO = _task("t-echo", "*/5 * * * *", "echo hello")
def cases():
C = []
# to_dict — pure dataclass rendering (defaults, non-ascii, full state)
C.append(("_ce_to_dict", [dict(
T_ECHO, last_run="2026-01-02T03:04:05+00:00",
next_run="2026-01-02T03:04:05+00:00", run_count=7, description="d")], {}))
C.append(("_ce_to_dict",
[{"name": "m", "cron_expression": "* * * * *", "command": "echo m"}], {}))
C.append(("_ce_to_dict", [dict(T_ECHO, name="ü-task", description="中文 <>&")], {}))
# _parse_cron_field — extra branches beyond the batch-1 matrix
for field, low, high in [("*/15", 0, 59), ("5/15", 0, 59), ("10-5", 0, 59),
("1-10/2,30", 0, 59), ("*", 1, 12),
("2,4-6/2", 1, 12), ("0", 0, 23), ("9-17", 0, 23),
("*/5", 0, 23)]:
C.append(("_ce_parse", [field, low, high], {}))
# _should_run — match/mismatch/dedup/field-count/weekday-7
S = lambda t, **kw: (_state({"t-echo": t}, **kw), "t-echo")
C.append(("_ce_should_run", list(S(T_ECHO)) + [2026, 10, 13, 9, 20], {}))
C.append(("_ce_should_run",
list(S(_task("t-echo", "30 12 * * *", "echo x"))) + [2026, 10, 13, 9, 20], {}))
C.append(("_ce_should_run",
list(S(T_ECHO, _last_run_minute={"t-echo": "2026-10-13 09:20"}))
+ [2026, 10, 13, 9, 20], {}))
C.append(("_ce_should_run",
list(S(_task("t-echo", "* * * *", "echo x"))) + [2026, 10, 13, 9, 20], {}))
C.append(("_ce_should_run",
list(S(_task("t-echo", "* * * * 0", "echo x"))) + [2026, 10, 11, 0, 0], {}))
C.append(("_ce_should_run",
list(S(_task("t-echo", "* * * * 7", "echo x"))) + [2026, 10, 11, 0, 0], {}))
C.append(("_ce_should_run",
list(S(_task("t-echo", "* * * * 1", "echo x"))) + [2026, 10, 5, 0, 0], {}))
C.append(("_ce_should_run",
list(S(_task("t-echo", "* * * * 1", "echo x"))) + [2026, 10, 11, 0, 0], {}))
# run_task — every envelope branch
C.append(("_ce_run_task", [_state({"t-echo": T_ECHO}), "t-echo"], {}))
C.append(("_ce_run_task", [_state({"t-echo": T_ECHO}), "ghost"], {}))
C.append(("_ce_run_task",
[_state({"t-nope": _task("t-nope", "* * * * *", "nope-cmd-xyz")}), "t-nope"], {}))
C.append(("_ce_run_task",
[_state({"t-q": _task("t-q", "* * * * *", "echo 'unterminated")}), "t-q"], {}))
C.append(("_ce_run_task",
[_state({"t-false": _task("t-false", "* * * * *", "false")}), "t-false"], {}))
C.append(("_ce_run_task",
[_state({"t-sh": _task("t-sh", "* * * * *", "sh -c 'echo out; echo err 1>&2'")}),
"t-sh"], {}))
C.append(("_ce_run_task",
[_state({"t-esc": _task("t-esc", "* * * * *", "echo a\\ b")}), "t-esc"], {}))
# fire_on_task_complete — order, disabled, non-on_complete, failures
C.append(("_ce_fire", [_state({
"oc-first": _task("oc-first", "on_complete", "echo one"),
"t-sched": _task("t-sched", "5 4 * * *", "echo sched"),
"oc-second": _task("oc-second", "on_complete", "echo two"),
"oc-off": _task("oc-off", "on_complete", "echo off", enabled=False),
})], {}))
C.append(("_ce_fire", [_state({
"oc-bad": _task("oc-bad", "on_complete", "nope-cmd-xyz"),
})], {}))
# stop (thread=None paths)
C.append(("_ce_stop", [_state({"t-echo": T_ECHO}, running=True)], {}))
C.append(("_ce_stop", [_state(running=False)], {}))
# _execute_task — success + failure-to-log paths
C.append(("_ce_execute", [_state({"t-echo": T_ECHO}), "t-echo"], {}))
C.append(("_ce_execute",
[_state({"t-nope": _task("t-nope", "* * * * *", "nope-cmd-xyz")}), "t-nope"], {}))
# _run_loop — stopped / fires / silent / dedup-guard
C.append(("_ce_run_loop", [_state({"t-echo": T_ECHO}, running=False)], {}))
C.append(("_ce_run_loop", [_state({"t-echo": T_ECHO}, running=True)], {}))
C.append(("_ce_run_loop",
[_state({"t-sched": _task("t-sched", "5 4 * * *", "echo sched")}, running=True)], {}))
C.append(("_ce_run_loop",
[_state({"t-echo": T_ECHO}, running=True,
_last_run_minute={"t-echo": "2026-10-13 09:20"})], {}))
# _log_execution / _log_error — fresh, append, rotation (both sides
# of the 5MB threshold)
ROT = 5 * 1024 * 1024
C.append(("_ce_log_execution", [_state({"t-echo": T_ECHO}), "t-echo", 0], {}))
C.append(("_ce_log_execution",
[_state({"t-echo": T_ECHO}, seed_log={"cron.log": 12}), "t-echo", 3], {}))
C.append(("_ce_log_execution",
[_state({"t-echo": T_ECHO},
seed_log={"cron.log": ROT + 1, "cron.log.1": 100, "cron.log.2": 7}),
"t-echo", 0], {}))
C.append(("_ce_log_execution",
[_state({"t-echo": T_ECHO}, seed_log={"cron.log": ROT}), "t-echo", 0], {}))
C.append(("_ce_log_error",
[_state({"t-nope": _task("t-nope", "* * * * *", "nope-cmd-xyz")}),
"t-nope", "[Errno 2] No such file or directory: 'nope-cmd-xyz'"], {}))
# singleton family (module-level fns)
C.append(("_ce_singleton", ["get", "", "", ""], {}))
C.append(("_ce_singleton", ["start_stop", "", "", ""], {}))
C.append(("_ce_singleton", ["module_run", "m1", "*/5 * * * *", "echo via-global"], {}))
C.append(("_ce_singleton", ["module_list", "n1", "on_complete", "echo one"], {}))
return C
SHIMS = "gen_cron_engine_gap_truth_shims"
def main():
sys.modules[SHIMS] = sys.modules["__main__"]
truth = freeze(SHIMS, cases(), oracle_module=SHIMS)
target = REPO / "src" / "go" / "cron-engine" / "truth_gap.json"
write_envelope(FROZEN_NOW, truth, target)
print(f"wrote {target} ({len(truth)} cases)")
def verify(path):
raw = json.loads(path.read_text())
frozen = raw["cases"] if isinstance(raw, dict) else raw
if isinstance(raw, dict) and raw.get("frozen_now"):
os.environ["RUNE_FROZEN_NOW"] = raw["frozen_now"]
sys.modules[SHIMS] = sys.modules["__main__"]
recased = [{"fn": c["fn"], "args": c.get("args", []), "kwargs": c.get("kwargs", {})}
for c in frozen]
fresh = freeze(SHIMS, recased, oracle_module=SHIMS)
if json.dumps(fresh, sort_keys=True) != json.dumps(frozen, sort_keys=True):
print(f"MISMATCH: regenerated truth differs from {path}")
for f, g in zip(frozen, fresh):
if json.dumps(f, sort_keys=True) != json.dumps(g, sort_keys=True):
print(f" first divergence at fn={f['fn']}")
print(f" frozen: {json.dumps(f['expected'])[:300]}")
print(f" oracle: {json.dumps(g['expected'])[:300]}")
break
return 1
print(f"OK: {len(frozen)} cases byte-identical against live oracle")
return 0
if __name__ == "__main__":
if len(sys.argv) > 1 and sys.argv[1] == "--verify":
sys.exit(verify(REPO / "src" / "go" / "cron-engine" / "truth_gap.json"))
main()
+152
View File
@@ -0,0 +1,152 @@
#!/usr/bin/env python3
"""gen_drift_compression_truth.py — freeze drift_compression oracle truth
for the memory_scoring gap-close battery (dichotomy wave, #2479 tranche).
Freezes the PURE, replayable oracle surface (the six _py_* kernels:
_py_get_compression_ratio, _py_compress_text, _py_compress_entry,
_py_should_warn, _py_warn_before_compress, _py_get_compression_stats)
through the SHARED harness (scripts/freeze_truth.py) into
src/rust/memory_scoring/src/frozen_dcomp_truth.json — the freeze_truth
list format, so `freeze_truth.py --verify` re-freezes it byte-identically
against the live oracle (byte-identical law).
Poisoned-truth law: RUNE_MEMORY_CORE=python is pinned BEFORE any import —
drift_compression's delegation chain runs through drift_core._ms_core,
which reads RUNE_MEMORY_CORE (the harness's stem-derived pin cannot reach
a cross-module chain). Freezing the _py_* kernels directly makes the truth
delegation-proof by construction: no pin can poison a pure function.
Boundary law: the sqlite read in the public get_compression_stats(db)
stays in the Python facade — _py_get_compression_stats(rows) freezes the
math on the fetched triples [rock_status, wash_count, text_len], exactly
the payload the Rust kernel receives. The db-level seam (SQL, status
filtering, None coercion of SQL nulls) is covered live by
scripts/check_drift_compression_parity.py, not by frozen truth (a sqlite
connection is not JSON-freezable).
No clock, no HOME, no file seams in this module — no rig needed.
Run: python3 scripts/gen_drift_compression_truth.py
"""
from __future__ import annotations
import os
import sys
from pathlib import Path
REPO = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(REPO / "src"))
sys.path.insert(0, str(REPO / "scripts"))
os.environ["RUNE_MEMORY_CORE"] = "python" # poisoned-truth law
from freeze_truth import freeze, write as freeze_write # noqa: E402
TRUTH_PATH = REPO / "src" / "rust" / "memory_scoring" / "src" / "frozen_dcomp_truth.json"
import rune.drift_compression as dc # noqa: E402 (after the pin)
def long(n, filler="alpha bravo charlie delta echo foxtrot golf hotel "):
"""Deterministic n-char text (repeats a 40-char filler, truncated)."""
return (filler * (n // len(filler) + 1))[:n]
LONG_TEXT = long(300)
TRAILING_TEXT = long(120) + " " # cut boundary lands on trailing blanks
CASES = [
# ── _py_get_compression_ratio: the wash ladder × rock status ──────────
("_py_get_compression_ratio", (0, "washable"), {}),
("_py_get_compression_ratio", (9, "washable"), {}),
("_py_get_compression_ratio", (10, "washable"), {}), # partial threshold
("_py_get_compression_ratio", (19, "washable"), {}),
("_py_get_compression_ratio", (20, "washable"), {}), # full threshold
("_py_get_compression_ratio", (100, "washable"), {}),
("_py_get_compression_ratio", (5, "established"), {}), # status overrides wash
("_py_get_compression_ratio", (50, "established"), {}),
("_py_get_compression_ratio", (0, "rock"), {}),
("_py_get_compression_ratio", (25, "rock"), {}),
("_py_get_compression_ratio", (15, "muddy"), {}), # unknown status → washable math
("_py_get_compression_ratio", (10.5, "washable"), {}), # float wash
("_py_get_compression_ratio", (), {"wash_count": 20, "rock_status": "rock"}), # kwargs path
# ── _py_compress_text: ratio extremes + keep_chars clamp + unicode ────
("_py_compress_text", (long(100), 0.0), {}), # ratio 0 → full text
("_py_compress_text", (long(100), 1.0), {}), # ratio 1 → ""
("_py_compress_text", (long(100), 0.5), {}), # plain 50% cut + "..."
("_py_compress_text", (long(100),), {"ratio": 0.5}), # kwargs path
("_py_compress_text", (long(100), 0.3), {}),
("_py_compress_text", (long(100), 0.999), {}), # keep 0 → clamped to 20
("_py_compress_text", ("short text", 0.5), {}), # len < 20 → min(20, len) = full
("_py_compress_text", ("exactly-twenty-chars", 0.9), {}), # clamp keeps all 20
("_py_compress_text", ("", 0.5), {}), # empty text
("_py_compress_text", (TRAILING_TEXT, 0.5), {}), # rstrip before "..."
("_py_compress_text", ("métier naïve 中文文本 twenty", 0.5), {}), # codepoints, not bytes
("_py_compress_text", (long(100), -0.1), {}), # ratio < 0 → full text
("_py_compress_text", (long(100), 1.5), {}), # ratio > 1 → ""
# ── _py_compress_entry: coercion lattice on the entry dict ────────────
("_py_compress_entry", ({"text": long(100)},), {}), # defaults wash 0 washable
("_py_compress_entry", ({},), {}), # no text → ""
("_py_compress_entry", ({"text": long(100), "wash_count": 10},), {}),
("_py_compress_entry", ({"text": long(100), "wash_count": 25},), {}),
("_py_compress_entry", ({"text": long(100), "rock_status": "rock"},), {}),
("_py_compress_entry", ({"text": long(100), "rock_status": "established"},), {}),
("_py_compress_entry", ({"text": "tiny", "wash_count": None},), {}), # None wash → or 0
("_py_compress_entry", ({"text": "tiny", "rock_status": None},), {}), # None status → "washable"
("_py_compress_entry", ({"text": long(60), "wash_count": 0, "rock_status": "muddy"},), {}),
# ── _py_should_warn: every warn branch + both strict boundaries ───────
("_py_should_warn", ({"wash_count": 10, "text": "t"},), {}), # proven
("_py_should_warn", ({"wash_count": 9, "text": "t"},), {}), # below wash gate
("_py_should_warn", ({"rock_status": "established", "text": "t"},), {}),
("_py_should_warn", ({"rock_status": "rock", "text": "t"},), {}),
("_py_should_warn", ({"text": long(201)},), {}), # len > 200, ratio 0.5
("_py_should_warn", ({"text": long(200)},), {}), # len == 200 → no warn
("_py_should_warn", ({"text": long(300), "wash_count": 12},), {}), # ratio 0.25 ≤ 0.3 → no
("_py_should_warn", ({"text": long(300), "wash_count": 25},), {}), # ratio 0.1 → but wash ≥ 10 → yes
("_py_should_warn", ({},), {}), # all defaults
# ── _py_warn_before_compress: every recommendation branch + id shape ──
("_py_warn_before_compress", ({"id": 7, "text": long(100), "rock_status": "rock"},), {}),
("_py_warn_before_compress", ({"id": 8, "text": long(100), "wash_count": 25},), {}),
("_py_warn_before_compress", ({"id": 9, "text": long(100), "wash_count": 15},), {}),
("_py_warn_before_compress", ({"id": 10, "text": long(100)},), {}),
("_py_warn_before_compress", ({"text": long(100)},), {}), # no id → null
("_py_warn_before_compress", ({"id": "slug-1", "text": "tiny", "wash_count": None},), {}), # coerced wash rides verbatim
("_py_warn_before_compress", ({"id": None, "text": "", "rock_status": None},), {}),
# ── _py_get_compression_stats: the row-reduction lattice ──────────────
("_py_get_compression_stats", ([],), {}), # empty store → int 0 pct
("_py_get_compression_stats", ([["washable", 0, 100]],), {}), # integral 50.0 pct
("_py_get_compression_stats", ([["rock", 5, 50]],), {}), # ratio 0 → no savings
("_py_get_compression_stats", ([["established", 0, 50]],), {}), # 20% → 40.0 pct
("_py_get_compression_stats", ([["washable", 15, 40]],), {}), # ratio 0.25 → 25.0 pct
("_py_get_compression_stats", ([["washable", 25, 40]],), {}), # ratio 0.1 → 10.0 pct
("_py_get_compression_stats", ([["washable", 0, 33]],), {}), # int() truncation 16.5 → 16
("_py_get_compression_stats", ([["washable", 0, 1], ["washable", 0, 2]],), {}), # 33.33 pct rounding
("_py_get_compression_stats", ([["washable", 0, 2], ["washable", 0, 1]],), {}), # 66.67 pct rounding
("_py_get_compression_stats", ([["washable", 0, 2], ["rock", 0, 798]],), {}), # 0.125 → banker's 0.12
("_py_get_compression_stats", ([["washable", 0, 6], ["rock", 0, 794]],), {}), # 0.375 → banker's 0.38
("_py_get_compression_stats", ([["washable", 0, 100], ["established", 5, 60], ["rock", 9, 80]],), {}),
("_py_get_compression_stats", ([[None, None, None]],), {}), # SQL null row coerced
("_py_get_compression_stats", ([["washable", 0, 100], [None, None, None], ["rock", 1, 10]],), {}),
]
def main() -> int:
# sanity: every case fn exists on the oracle (import-time typos die here)
fns = {c[0] for c in CASES}
missing = [f for f in fns if not hasattr(dc, f)]
if missing:
print(f"ORACLE MISSING FNS: {missing}")
return 1
truth = freeze("rune.drift_compression", CASES, oracle_module="rune.drift_compression")
freeze_write(truth, TRUTH_PATH)
print(f"froze {len(truth)} cases -> {TRUTH_PATH.relative_to(REPO)}")
return 0
if __name__ == "__main__":
sys.exit(main())
+266
View File
@@ -0,0 +1,266 @@
#!/usr/bin/env python3
"""gen_drift_core_truth.py — factory wave GAP truth for drift_core.
Freezes the oracle behavior of the 8 audit-gap functions (dichotomy wave
#2479: _ms_core, _now_iso, promote_entry, compute_fama,
compute_drift_velocity, compute_drift_direction, pre_commit_gate,
pre_commit_gate_entry) plus scoring-surface regression rows (compute_value,
check_promotion_eligibility) through the SHARED harness
(scripts/freeze_truth.py — one law).
Runs under the freeze rig (scripts/dc_freeze_seams/sitecustomize.py —
PYTHONPATH-imported by BOTH this generator and --verify): pinned floor
(RUNE_DRIFT_CORE=python), frozen clock (RUNE_FROZEN_NOW reaches _now_iso
and the velocity cutoff through the harness's module-datetime patch),
hermetic per-row scratch store, embeddings off, and the db-carrying seams
(promote/fama/velocity/direction/gate) that drive the REAL oracle fns with
JSON-safe shapes. The memory_scoring kernel is intentionally LIVE (its
Python oracle is retired and raises — determinism requires the built .so;
the rig fails loudly when it is missing).
Run (from the repo root, under the sqlite-vec venv):
PYTHONHASHSEED=0 PYTHONPATH=scripts/dc_freeze_seams:src \
~/.venvs/memory/bin/python3 scripts/gen_drift_core_truth.py
Verify (byte-identical, same rig):
PYTHONHASHSEED=0 PYTHONPATH=scripts/dc_freeze_seams:src \
~/.venvs/memory/bin/python3 scripts/freeze_truth.py --verify \
src/rust/drift_core/frozen_truth.json \
--module rune.drift_core
Case map (every gap branch):
* _now_iso — None (frozen clock) + passthrough.
* _ms_core — probe contract True under the rig (kernel live).
* compute_value — no-goals + goals rows (ms-kernel regression).
* check_promotion_eligibility — eligible tuple row.
* pre_commit_gate_entry — short / refusal / well-formed critics.
* dc_freeze_gate — the empty oracle body (None → null).
* dc_freeze_promote — not-found / already-rock / ineligible-low-wash /
washable→established / established→rock /
unknown-status→established; `after` pins the UPDATE.
* dc_freeze_fama — empty ids / all-valid / mixed / missing rows /
inactive / null-wash+established.
* dc_freeze_velocity — inside+outside window / over-threshold alert /
days=0 (max(1,·) floor) / integral 2.0 rounding.
* dc_freeze_direction — stable / drifting / empty store / rock-only.
"""
import sys
from pathlib import Path
REPO = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(REPO / "scripts"))
from freeze_truth import freeze, write_envelope # noqa: E402
NOW = "2026-10-13T12:00:00.123456+00:00"
IN_WINDOW = "2026-10-12T00:00:00.000000+00:00" # 1.5 days before NOW
OUT_WINDOW = "2026-10-01T00:00:00.000000+00:00" # far outside 7 days
# After the days=-3 cutoff (NOW + 3d): negative windows only see future rows.
NEG_WINDOW = "2026-10-17T00:00:00.000000+00:00"
cases = [
# _now_iso: frozen-clock branch + passthrough branch.
("_now_iso", (None,), {}),
("_now_iso", ("2026-01-02T03:04:05.666666+00:00",), {}),
# _ms_core probe contract: kernel delegation live under the rig.
("dc_freeze_ms_core", (), {}),
# Scoring-surface regression (delegates to the live ms kernel; the
# clock is frozen so the value is deterministic).
(
"compute_value",
({"text": "k8s pods restart on failure", "wash_count": 25,
"importance": 0.8, "rock_status": "washable"},),
{},
),
(
"compute_value",
({"text": "voice stays consistent", "wash_count": 3,
"importance": 0.6, "rock_status": "washable"},),
{"current_goals": ["voice consistency"]},
),
(
"check_promotion_eligibility",
({"text": "k8s pods restart on failure", "wash_count": 25,
"importance": 0.8, "rock_status": "washable"},),
{},
),
# pre_commit_gate_entry critics: short / refusal / well-formed.
(
"pre_commit_gate_entry",
({"text": "no"},),
{},
),
(
"pre_commit_gate_entry",
({"text": "I'm sorry, but I can't help with that request"},),
{},
),
(
"pre_commit_gate_entry",
({"text": "Kubernetes pods restart on failure"},),
{},
),
# pre_commit_gate: the empty oracle body.
("dc_freeze_gate", (7,), {}),
# promote_entry ladder.
(
"dc_freeze_promote",
(None, 999),
{},
),
(
"dc_freeze_promote",
({"text": "locked identity anchor", "wash_count": 40,
"importance": 0.9, "rock_status": "rock"}, 1),
{},
),
(
"dc_freeze_promote",
({"text": "barely washed entry", "wash_count": 5,
"importance": 0.9, "rock_status": "washable"}, 2),
{},
),
(
"dc_freeze_promote",
({"text": "proven deployment runner", "wash_count": 25,
"importance": 0.8, "rock_status": "washable"}, 3),
{},
),
(
"dc_freeze_promote",
({"text": "proven established entry", "wash_count": 25,
"importance": 0.8, "rock_status": "established"}, 4),
{},
),
(
"dc_freeze_promote",
({"text": "proven unknown-status entry", "wash_count": 25,
"importance": 0.8, "rock_status": "weird"}, 5),
{},
),
# compute_fama.
("dc_freeze_fama", ([], "anything", []), {}),
(
"dc_freeze_fama",
(
[
{"status": "active", "rock_status": "washable", "wash_count": 5},
{"status": "active", "rock_status": "established", "wash_count": 0},
],
"deploy runner",
[1, 2],
),
{},
),
(
"dc_freeze_fama",
(
[
{"status": "active", "rock_status": "washable", "wash_count": 5},
None,
{"status": "retired", "rock_status": "rock", "wash_count": 9},
],
"deploy runner",
[1, 2, 3],
),
{},
),
(
"dc_freeze_fama",
(
[
{"status": "active", "rock_status": "established", "wash_count": None},
{"status": "active", "rock_status": "washable", "wash_count": 0},
],
"voice identity",
[1, 2],
),
{},
),
# compute_drift_velocity: window membership, alert, floor, rounding.
(
"dc_freeze_velocity",
(
[
{"last_washed": IN_WINDOW, "status": "active",
"rock_status": "washable"},
{"last_washed": OUT_WINDOW, "status": "active",
"rock_status": "established"},
],
7,
),
{},
),
(
"dc_freeze_velocity",
(
[
{"last_washed": IN_WINDOW, "status": "active",
"rock_status": "established"},
{"last_washed": IN_WINDOW, "status": "retired",
"rock_status": "rock"},
{"last_washed": IN_WINDOW, "status": "active",
"rock_status": "rock"},
],
1,
),
{},
),
("dc_freeze_velocity", ([], 0), {}),
(
"dc_freeze_velocity",
([{"last_washed": IN_WINDOW, "status": "active",
"rock_status": "washable"}] * 14, 7),
{},
),
(
"dc_freeze_velocity",
([{"last_washed": IN_WINDOW, "status": "active",
"rock_status": "washable"}] * 22, 2),
{},
),
(
"dc_freeze_velocity",
(
[
{"last_washed": NEG_WINDOW, "status": "active",
"rock_status": "washable"},
{"last_washed": NEG_WINDOW, "status": "active",
"rock_status": "established"},
{"last_washed": IN_WINDOW, "status": "active",
"rock_status": "rock"},
],
-3,
),
{},
),
# compute_drift_direction.
(
"dc_freeze_direction",
(
[
{"status": "active", "rock_status": "washable"},
{"status": "active", "rock_status": "established"},
{"status": "active", "rock_status": "rock"},
],
),
{},
),
(
"dc_freeze_direction",
([{"status": "active", "rock_status": "washable"}] * 5,),
{},
),
("dc_freeze_direction", ([],), {}),
(
"dc_freeze_direction",
([{"status": "retired", "rock_status": "rock"}],),
{},
),
]
truth = freeze("rune.drift_core", cases, oracle_module="rune.drift_core")
dest = REPO / "src" / "rust" / "drift_core" / "frozen_truth.json"
write_envelope(NOW, truth, dest)
print(f"wrote {len(truth)} cases -> {dest}")
+124 -19
View File
@@ -1,35 +1,140 @@
#!/usr/bin/env python3
"""gen_event_bus_truth.py — factory batch 9 truth battery (live oracle)."""
"""gen_event_bus_truth.py — shared-harness truth battery for the event_bus
gap closure (#2479, contract factory-gap-eb).
import json
Uses scripts/freeze_truth.py (the ONE truth law) under the
scripts/eb_freeze_seams sitecustomize rig (PYTHONPATH carries BOTH) to
freeze src/rune/event_bus.py behavior for the Go port at src/go/event-bus:
* _content_hash — the orchestration sha256: convention over any payload
shape (sort_keys=True is recursive, ", "/": " separators, ensure_ascii).
* eb_store_path — the canonical journal path under the hermetic RUNE_MEMORY_DIR
sandbox, normalized to EB_SANDBOX (machine paths never enter truth).
* eb_event_types — EVENT_TYPES in definition order (json.dumps keeps it).
* eb_emit — envelope build + durable append: schema_version-first to_dict,
partition_key from source-or-system, payload_hash truthiness ({}, 0 and
None hash ""), minted event_id / frozen clock, and the loud ValueError
branches (non-str source: dict/int/NoneType/float/bool/list — message
carries the Python type name, NOTHING written).
* eb_emit_line — the exact journal LINE bytes (json.dumps(to_dict,
sort_keys=True) + newline).
* eb_log — replay + event_type filter + events[-limit:] truncation
(limit 0 → ALL — the -0 slice quirk; -1 → [1:] drops the first).
* eb_log_corrupt — the typed corrupt-line raise (message-only contract).
* eb_stats — (total, by_type) with by_type in first-occurrence order.
* eb_handle_hook — hook.<event> vocabulary prefix, source microkernel,
payload shaping (str → json.loads with the raw[:200] fallback; dict →
str(v)[:200] CODEPOINT truncation with Python repr forms; falsy data
stays {}), and the journal replay after each hook.
* eb_main — captured CLI stdout + exit code under the pins (emit/log/stats/
hook, --json modes, the usage line for a bare emit).
Verify (byte-identical law):
PYTHONPATH=scripts/eb_freeze_seams:src \\
python3 scripts/freeze_truth.py --verify src/go/event-bus/truth_bus.json \\
--module rune.event_bus
"""
import os
import sys
from pathlib import Path
REPO = Path(__file__).resolve().parent.parent
sys.path.insert(0, str(REPO / "src"))
sys.path.insert(0, str(REPO / "src" / "rune"))
sys.path.insert(0, str(Path(__file__).resolve().parent))
import event_bus as eb # noqa: E402
FROZEN_NOW = "2026-10-14T11:22:33.123456+00:00"
os.environ["RUNE_FROZEN_NOW"] = FROZEN_NOW
from freeze_truth import freeze, write_envelope # noqa: E402
def main():
payloads = [
{},
{"k": "v"},
{"task_id": "t1", "status": "failed", "count": 3},
{"nested": {"a": [1, 2, "x"]}, "flag": True, "nothing": None},
{"text": "quote\" inside\\ back\nnewline\ttab"},
{"float_int": 1.0, "float_frac": 2.5},
]
cases = [
{"fn": "hash", "name": f"payload_{i}", "input": {"payload": p},
"expected": {"hash": eb._content_hash(p)}}
for i, p in enumerate(payloads)
# ── _content_hash — direct oracle rows ──────────────────────────
("_content_hash", ({},), {}),
("_content_hash", ({"k": "v"},), {}),
("_content_hash", ({"task_id": "t1", "status": "failed", "count": 3},), {}),
("_content_hash", ({"nested": {"a": [1, 2, "x"]}, "flag": True, "nothing": None},), {}),
("_content_hash", ({"text": "quote\" inside\\ back\nnewline\ttab"},), {}),
("_content_hash", ({"é": "ümlaut", "b": {"z": 1, "a": 2.0}},), {}),
("_content_hash", ([1, "two", None, True],), {}),
("_content_hash", ({"float_int": 1.0, "float_frac": 2.5, "big": 1e30},), {}),
("_content_hash", ("raw string payload",), {}),
("_content_hash", ({"z": 1, "a": 2},), {}), # sort_keys reorders
# ── eb_store_path / eb_event_types ─────────────────────────────
("eb_store_path", (), {}),
("eb_event_types", (), {}),
# ── eb_emit — envelope build + durable append ──────────────────
("eb_emit", ("user.message",), {"source": "user", "payload": {"text": "hi"}}),
("eb_emit", ("tool.result",), {}), # bare defaults
("eb_emit", ("rune.started",), {"source": "system", "payload": {}}), # {} falsy
("eb_emit", ("x.y",), {"source": "", "payload": None}), # system fallback
("eb_emit", ("memory.created",), {"source": "sys",
"payload": {"nested": {"a": [1, 2, "x"]}, "flag": True, "nothing": None}}),
("eb_emit", ("user.message",), {"source": "café",
"payload": {"text": "quote\" inside\\ back\nnewline\ttab", "é": "ümlaut"}}),
("eb_emit", ("capability.failed",), {"source": "sys",
"payload": {"float_int": 1.0, "float_frac": 2.5, "big": 1e30}}),
("eb_emit", ("task.created",), {"source": "sys", "payload": [1, "two", None, True]}),
("eb_emit", ("task.created",), {"source": "sys", "payload": "raw string payload"}),
("eb_emit", ("task.created",), {"source": "sys", "payload": 0}), # falsy int
# ── eb_emit — loud ValueError + nothing written ────────────────
("eb_emit", ("x",), {"source": {}, "payload": None}),
("eb_emit", ("x",), {"source": 5, "payload": None}),
("eb_emit", ("x",), {"source": None, "payload": None}),
("eb_emit", ("x",), {"source": 2.5, "payload": None}),
("eb_emit", ("x",), {"source": True, "payload": None}),
("eb_emit", ("x",), {"source": [], "payload": None}),
# ── eb_emit_line — the journal LINE bytes ───────────────────────
("eb_emit_line", ("user.message",), {"source": "user", "payload": {"text": "hi"}}),
("eb_emit_line", ("session.ended",), {"source": "microkernel",
"payload": {"k": ["a", {"z": 2.0}]}}),
# ── eb_log — filter + [-limit:] truncation matrix ──────────────
("eb_log", (), {"limit": None, "event_type": None}),
("eb_log", (), {"limit": 2, "event_type": None}),
("eb_log", (), {"limit": 0, "event_type": None}), # -0 → ALL
("eb_log", (), {"limit": -1, "event_type": None}), # [1:] quirk
("eb_log", (), {"limit": 100, "event_type": None}),
("eb_log", (), {"limit": 3, "event_type": "user.message"}),
("eb_log", (), {"limit": 3, "event_type": "nope"}),
("eb_log", (), {"limit": 2, "event_type": "tool.result"}),
("eb_log_corrupt", (), {}),
# ── eb_stats ────────────────────────────────────────────────────
("eb_stats", (), {}),
# ── eb_handle_hook — prefix + payload shaping ──────────────────
("eb_handle_hook", ("on_startup",), {}),
("eb_handle_hook", ("on_message",), {"data": {"k": "v", "n": 5}}),
("eb_handle_hook", ("weird.event",), {}),
("eb_handle_hook", ("on_response",), {"data": '{"x": 1, "y": [2, 3]}'}),
("eb_handle_hook", ("on_schedule",), {"data": "not json at all"}),
("eb_handle_hook", ("hook.on_startup",), {}),
("eb_handle_hook", ("on_session_end",), {"data": ""}),
("eb_handle_hook", ("on_session_end",), {"data": 0}),
("eb_handle_hook", ("on_session_end",), {"data": "0"}),
("eb_handle_hook", ("on_memory_add",),
{"data": {"long": "x" * 250, "uni": "café", "d": {"k": None},
"l": [1, "two"], "b": True, "fl": 2.5, "ni": None}}),
("eb_handle_hook", ("on_session_end",), {"data": "[1, 2]"}),
("eb_handle_hook", ("on_session_end",), {"data": '{"deep": {"z": 1, "a": ["ü"]}}'}),
# ── eb_main — captured CLI stdout ───────────────────────────────
("eb_main", (["event_bus.py", "emit", "user.message", "--source", "user",
"--payload", '{"text":"hi"}'],), {}),
("eb_main", (["event_bus.py", "hook", "--event", "on_startup",
"--data", '{"k":"v"}'],), {}),
("eb_main", (["event_bus.py", "stats"],), {}),
("eb_main", (["event_bus.py", "log", "--limit", "2"],), {}),
("eb_main", (["event_bus.py", "emit", "session.started", "--json"],), {}),
("eb_main", (["event_bus.py", "stats", "--json"],), {"seed": True}),
("eb_main", (["event_bus.py", "log"],), {"seed": True}),
("eb_main", (["event_bus.py", "hook"],), {}),
("eb_main", (["event_bus.py", "emit"],), {}),
]
out = {"oracle": "event_bus._content_hash", "generated": "2026-10-07", "cases": cases}
(REPO / "src/go/event-bus" / "truth_bus.json").write_text(json.dumps(out, indent=1) + "\n")
print(f"wrote {len(cases)} cases")
truth = freeze("rune.event_bus", cases, oracle_module="rune.event_bus")
dest = REPO / "src/go/event-bus/truth_bus.json"
write_envelope(FROZEN_NOW, truth, dest)
print(f"wrote {len(truth)} cases -> {dest}")
if __name__ == "__main__":
main()
main()
+171
View File
@@ -0,0 +1,171 @@
#!/usr/bin/env python3
"""gen_event_envelope_truth.py — shared-harness truth battery for the
event_envelope gap closure (#2479, contract factory-gap-ee).
Uses scripts/freeze_truth.py (the ONE truth law) under the
scripts/ee_freeze_seams sitecustomize rig (PYTHONPATH carries BOTH) to
freeze src/rune/event_envelope.py behavior for the Go port at
src/go/event-bus:
* classify_authority / classify_urgency — the \\b<word>\\b regex
semantics incl. the multi-word amendment list ("stop doing" is NOT
bare "stop"), punctuation adjacency ("stop," still matches), and the
channel-default fallbacks.
* create_envelope — the legacy direct-constructor path (auto authority
+ urgency from payload["text"], explicit overrides, minted
event_id/timestamp under the deterministic uuid + frozen clock).
* EventEnvelope.create — the canonical-bridge classmethod: event_type
follows the CHANNELS prior vocabulary (tool -> tool_result),
channel-not-in-CHANNELS fallback chain, and the nested canonical
record rides in asdict form (_canonical).
* to_dict — the 9-key legacy dict.
* to_canonical_dict — schema_version-1 dict with content-addressed
payload_hash (key order: schema_version first, payload_hash in
place), incl. the loud RuntimeError branch for un-bridged
envelopes (message-only contract).
* test_envelope — the in-module self-test's exact stdout bytes
(captured under the rig's deterministic ids).
* CHANNELS / AUTHORITY_CLASSES — the constant tables.
Verify (byte-identical law):
PYTHONPATH=scripts/ee_freeze_seams:src \\
python3 scripts/freeze_truth.py --verify src/go/event-bus/truth_envelope.json \\
--module rune.event_envelope
"""
import os
import sys
from pathlib import Path
REPO = Path(__file__).resolve().parent.parent
sys.path.insert(0, str(REPO / "src"))
sys.path.insert(0, str(Path(__file__).resolve().parent))
FROZEN_NOW = "2026-10-14T11:22:33.123456+00:00"
os.environ["RUNE_FROZEN_NOW"] = FROZEN_NOW
from freeze_truth import freeze, write_envelope # noqa: E402
def main():
cases = [
# ── constant tables ────────────────────────────────────────────
("ee_channels", (), {}),
("ee_authority_classes", (), {}),
# ── classify_authority — regex \b semantics ────────────────────
("classify_authority", ("hello there", "conversation"), {}),
("classify_authority", ("Fix the failing test", "work"), {}), # directive
("classify_authority", ("run the suite", "work"), {}), # directive
("classify_authority", ("build it", "conversation"), {}), # directive
("classify_authority", ("test everything", "conversation"), {}), # directive
("classify_authority", ("create a file", "work"), {}), # directive
("classify_authority", ("add the guard", "work"), {}), # directive
("classify_authority", ("remove the shim", "work"), {}), # directive
("classify_authority", ("update the docs", "work"), {}), # directive
("classify_authority", ("change the port", "work"), {}), # directive
("classify_authority", ("Stop everything!", "work"), {}), # emergency
("classify_authority", ("please cancel the order", "work"), {}), # emergency
("classify_authority", ("abort the run", "work"), {}), # emergency
("classify_authority", ("emergency shutdown", "work"), {}), # emergency
("classify_authority", ("halt", "work"), {}), # emergency
# task amendments BEFORE emergency — multi-word lists
("classify_authority", ("Actually, don't modify the microkernel", "conversation"), {}),
("classify_authority", ("dont do that", "conversation"), {}), # dont (no apostrophe)
("classify_authority", ("stop doing that", "work"), {}), # "stop doing" ≠ bare stop
("classify_authority", ("use rust instead", "work"), {}), # instead
("classify_authority", ("rather use go", "work"), {}), # rather
# pause / resume
("classify_authority", ("pause for a bit", "work"), {}), # pause
("classify_authority", ("wait", "work"), {}), # wait
("classify_authority", ("hold", "work"), {}), # hold
("classify_authority", ("resume the work", "work"), {}), # resume
("classify_authority", ("continue the build", "work"), {}), # continue
("classify_authority", ("go", "work"), {}), # go
# status queries
("classify_authority", ("how is it going", "work"), {}), # how
("classify_authority", ("what is the state", "work"), {}), # what
("classify_authority", ("status?", "work"), {}), # status
("classify_authority", ("progress report", "work"), {}), # progress
("classify_authority", ("check the log", "work"), {}), # check
# channel defaults + boundary/adjacency quirks
("classify_authority", ("hello", "work"), {}), # work default → directive
("classify_authority", ("hello", "conversation"), {}), # conversation default
("classify_authority", ("hello", ""), {}), # non-work default
("classify_authority", ("stop,", "work"), {}), # punctuation-adjacent → emergency
("classify_authority", ("unstoppable force", "work"), {}), # \b boundary → no match
("classify_authority", ("stopit now", "work"), {}), # no boundary → resume (now? no—
# ^ "stopit" fails \bstop\b; no other list hits → work default directive
("classify_authority", ("", "work"), {}), # empty text → work default
("classify_authority", ("", "conversation"), {}), # empty → conversation
("classify_authority", (" FIX it ", "work"), {}), # lower().strip() + \b spacing
("classify_authority", ("café stop", "work"), {}), # unicode text, ascii word
("classify_authority", ("stopé now", "work"), {}), # é is a word char: no \b after stop
# ── classify_urgency ──────────────────────────────────────────
("classify_urgency", ("anything", "emergency"), {}), # critical via class
("classify_urgency", ("urgent please", "directive"), {}), # high
("classify_urgency", ("asap", "directive"), {}), # high
("classify_urgency", ("immediately", "conversation"), {}), # high
("classify_urgency", ("do it now", "directive"), {}), # high
("classify_urgency", ("critical issue", "conversation"), {}), # high
("classify_urgency", ("when you can", "directive"), {}), # low (multi-word)
("classify_urgency", ("no rush", "directive"), {}), # low (multi-word)
("classify_urgency", ("eventually", "conversation"), {}), # low
("classify_urgency", ("sometime later", "conversation"), {}), # low
("classify_urgency", ("when", "directive"), {}), # bare "when" → normal (multi-word quirk)
("classify_urgency", ("rush", "directive"), {}), # bare "rush" → normal
("classify_urgency", ("hello", "conversation"), {}), # normal
("classify_urgency", ("", "directive"), {}), # normal
# ── create_envelope — legacy path (auto + explicit) ───────────
("ee_create_envelope", ("user", "conversation", {"text": "hello"}), {}),
("ee_create_envelope", ("user", "work", {"text": "Fix the failing test"}), {}),
("ee_create_envelope", ("user", "work", {"text": "Stop everything!"}), {}),
("ee_create_envelope", ("user", "conversation", {"text": "Actually, don't modify the microkernel"}), {}),
("ee_create_envelope", ("user", "work", {"text": "when you can"}), {}),
("ee_create_envelope", ("sensor", "sensor", {}), {}), # no text key → defaults
("ee_create_envelope", ("user", "work", {"text": "run it"}, "status_query", "t-42", "low"), {}),
("ee_create_envelope", ("user", "conversation", {"text": "hi", "extra": {"nested": [1, 2.5, None, True]}}), {}),
# ── EventEnvelope.create — canonical bridge ───────────────────
("ee_create", ("user", "conversation", {"text": "hello"}), {}),
("ee_create", ("tool", "tool", {"x": 1}), {}), # prior: tool_result
("ee_create", ("user", "work", {"text": "Fix it"}), {}), # prior: directive
("ee_create", ("system", "system", {}), {}), # prior: system_event
("ee_create", ("bg", "background", {}), {}), # prior: background
("ee_create", ("sensor", "sensor", {}), {}), # prior: sensor
("ee_create", ("user", "", {}), {}), # channel "" → source fallback
("ee_create", ("", "", {}), {}), # everything empty → unknown
("ee_create", ("user", "unknown-channel", {"text": "hi"}), {}), # channel not in CHANNELS
# ── to_dict — 9-key legacy dict ───────────────────────────────
("ee_to_dict", ({"event_id": "evt_abc123def456",
"timestamp": "2026-10-14T11:22:33.123456+00:00",
"source": "user", "channel": "conversation",
"authority_class": "conversation", "task_id": None,
"payload": {"text": "hi"}, "provenance": {},
"urgency": "normal", "_canonical": None},), {}),
("ee_to_dict", ({"event_id": "id-2", "timestamp": "2026-10-14T00:00:00+00:00",
"source": "tool", "channel": "work",
"authority_class": "directive", "task_id": "t-9",
"payload": {"n": 1.5, "b": False, "nil": None, "list": [1, "two"]},
"provenance": {"origin": "café", "chain": ["a", "b"]},
"urgency": "high", "_canonical": None},), {}),
# ── to_canonical_dict — bridged + loud failure ────────────────
("ee_to_canonical_dict", ("user", "conversation", {"text": "hello"}), {}),
("ee_to_canonical_dict", ("tool", "tool", {"x": 1, "a": 2.0}), {}), # integral float in hash corpus
("ee_to_canonical_dict", ("user", "work", {"text": "café résumé", "z": 1, "a": [True, None]}), {}),
("ee_to_canonical_dict", ("system", "system", {}), {}), # empty payload hash
("ee_to_canonical_dict_unbridged", ({"event_id": "legacy-1",
"timestamp": "2026-10-14T11:22:33.123456+00:00",
"source": "user", "channel": "conversation",
"authority_class": "", "task_id": None,
"payload": {}, "provenance": {},
"urgency": "normal", "_canonical": None},), {}),
# ── test_envelope — captured stdout ───────────────────────────
("ee_test_envelope", (), {}),
]
truth = freeze("rune.event_envelope", cases, oracle_module="rune.event_envelope")
dest = REPO / "src/go/event-bus/truth_envelope.json"
write_envelope(FROZEN_NOW, truth, dest)
print(f"wrote {len(truth)} cases -> {dest}")
if __name__ == "__main__":
main()
+70 -55
View File
@@ -1,74 +1,89 @@
#!/usr/bin/env python3
"""gen_evidence_capsule_truth.py — freeze the evidence_capsule parity
oracle (dichotomy wave #2479 tranche).
oracle (dichotomy wave #2479 tranche) via the SHARED harness
(scripts/freeze_truth.py) so `freeze_truth.py --verify` replays it.
Generator law: RUNE_EC_CORE=python pinned, inputs deep-copied, every
public function and branch exercised (pack empty/full/over-full for each
slot, defaults for contradictions/limits/raw_ref, exact-boundary fills,
truncated-count arithmetic; size incl. missing keys; unpack complete and
truncated, missing raw_ref/truncated). Output:
src/rust/evidence_capsule/frozen_ec_truth.json — replayed VERBATIM by
the crate's cfg(test) battery.
Generator law: RUNE_EC_CORE=python pinned (the module's own core var —
the harness's generic pinner cannot reach it), inputs deep-copied by
the harness, every public function and branch exercised (pack
empty/full/over-full for each slot, defaults for contradictions/limits/
raw_ref, exact-boundary fills, truncated-count arithmetic; size incl.
missing keys; unpack complete and truncated, missing raw_ref/truncated).
Output: src/rust/evidence_capsule/frozen_ec_truth.json — envelope
{"frozen_now", "cases"} with the kwargs convention; replayed VERBATIM
by the crate's cfg(test) battery.
Byte-determinism: frozen_now is a fixed constant (no wall clock), cases
come from literals — re-running regenerates a byte-identical file.
Verify: RUNE_EC_CORE=python python3 scripts/freeze_truth.py --verify
src/rust/evidence_capsule/frozen_ec_truth.json --module rune.evidence_capsule
"""
import copy
import json
import os
import sys
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(ROOT / "src"))
sys.path.insert(0, str(ROOT / "src" / "rune"))
sys.path.insert(0, str(ROOT / "scripts"))
os.environ["RUNE_EC_CORE"] = "python"
os.environ["RUNE_EC_CORE"] = "python" # the oracle's own core pin
import evidence_capsule as ec # noqa: E402
from freeze_truth import freeze, write_envelope # noqa: E402
cases: list = []
FROZEN_NOW = "2026-10-13T12:44:00+00:00" # original freeze moment, fixed
def freeze(fn, args):
args = copy.deepcopy(args)
f = getattr(ec, fn)
expected = f(**copy.deepcopy(args))
cases.append({"fn": fn, "args": args, "expected": expected})
def items(tag, n):
def items(tag: str, n: int):
return [f"{tag}{i}" for i in range(n)]
# --- pack: every slot shape ---
freeze("pack", {"claims": []}) # all defaults
freeze("pack", {"claims": items("c", 3)}) # under-fill
freeze("pack", {"claims": items("c", 5)}) # exact claims boundary
freeze("pack", {"claims": items("c", 9),
"contradictions": ["c1", "c2", "c3", "c4"],
"limits": ["l1"], "raw_ref": "run/123"})
freeze("pack", {"claims": items("c", 7),
"contradictions": items("x", 3), # exact contra boundary
"limits": items("l", 5), "raw_ref": "r"}) # limits over-fill
freeze("pack", {"claims": items("c", 2), "contradictions": [],
"limits": [], "raw_ref": ""}) # explicit empties
freeze("pack", {"claims": items("cl", 6), "contradictions": items("k", 4),
"limits": items("m", 4), "raw_ref": "run/9"}) # all over-fill
CASES = [
# --- pack: every slot shape ---
("pack", (), {"claims": []}), # all defaults
("pack", (), {"claims": items("c", 3)}), # under-fill
("pack", (), {"claims": items("c", 5)}), # exact claims boundary
("pack", (), {"claims": items("c", 9),
"contradictions": ["c1", "c2", "c3", "c4"],
"limits": ["l1"], "raw_ref": "run/123"}),
("pack", (), {"claims": items("c", 7),
"contradictions": items("x", 3), # exact contra boundary
"limits": items("l", 5), "raw_ref": "r"}), # limits over-fill
("pack", (), {"claims": items("c", 2), "contradictions": [],
"limits": [], "raw_ref": ""}), # explicit empties
("pack", (), {"claims": items("cl", 6), "contradictions": items("k", 4),
"limits": items("m", 4), "raw_ref": "run/9"}), # all over-fill
# --- size: every branch incl. missing keys ---
("size", (), {"capsule": {"claims": ["a", "b"], "contradictions": ["c"],
"limits": ["d"], "raw_ref": "",
"truncated": {"claims": 0, "contradictions": 0,
"limits": 0}}}),
("size", (), {"capsule": {"claims": [], "contradictions": [], "limits": [],
"raw_ref": "", "truncated": {"claims": 0,
"contradictions": 0,
"limits": 0}}}),
("size", (), {"capsule": {}}),
("size", (), {"capsule": {"claims": ["a"]}}),
("size", (), {"capsule": {"claims": ["c0", "c1", "c2", "c3", "c4"],
"contradictions": ["x0", "x1", "x2"],
"limits": ["l0", "l1", "l2"], "raw_ref": "",
"truncated": {"claims": 4, "contradictions": 6,
"limits": 6}}}),
# --- unpack: complete, truncated, missing keys ---
("unpack", (), {"capsule": {"claims": ["a"], "contradictions": [], "limits": [],
"raw_ref": "", "truncated": {"claims": 0,
"contradictions": 0,
"limits": 0}}}),
("unpack", (), {"capsule": {"claims": ["x0", "x1", "x2", "x3", "x4"],
"contradictions": [], "limits": [], "raw_ref": "",
"truncated": {"claims": 4, "contradictions": 0,
"limits": 0}}}),
("unpack", (), {"capsule": {}}),
("unpack", (), {"capsule": {"claims": ["a"], "raw_ref": "r/1"}}),
]
# --- size: every branch incl. missing keys ---
freeze("size", {"capsule": ec.pack(["a", "b"], ["c"], ["d"])})
freeze("size", {"capsule": ec.pack([])})
freeze("size", {"capsule": {}})
freeze("size", {"capsule": {"claims": ["a"]}})
freeze("size", {"capsule": ec.pack(items("c", 9), items("x", 9), items("l", 9))})
# --- unpack: complete, truncated, missing keys ---
freeze("unpack", {"capsule": ec.pack(["a"])})
freeze("unpack", {"capsule": ec.pack(items("x", 9))})
freeze("unpack", {"capsule": {}})
freeze("unpack", {"capsule": {"claims": ["a"], "raw_ref": "r/1"}})
doc = {"module": "evidence_capsule", "core_env": "RUNE_EC_CORE=python",
"cases": cases}
out = ROOT / "src" / "rust" / "evidence_capsule" / "frozen_ec_truth.json"
out.parent.mkdir(parents=True, exist_ok=True)
out.write_text(json.dumps(doc, indent=1) + "\n")
print(f"frozen {len(cases)} cases -> {out}")
if __name__ == "__main__":
truth = freeze("evidence_capsule", CASES, oracle_module="rune.evidence_capsule")
out = ROOT / "src" / "rust" / "evidence_capsule" / "frozen_ec_truth.json"
write_envelope(FROZEN_NOW, truth, out)
print(f"frozen {len(truth)} cases -> {out}")
+121
View File
@@ -0,0 +1,121 @@
#!/usr/bin/env python3
"""gen_graph_memory_truth.py — factory wave GAP truth for graph_memory.
Freezes the oracle behavior of the 6 audit-gap functions (dichotomy wave
#2479: now_iso, connect, resolve_entity, add_edge, query, stats) through
the SHARED harness (scripts/freeze_truth.py — one law).
Runs under the freeze rig (scripts/gm_freeze_seams/sitecustomize.py —
PYTHONPATH-imported by BOTH this generator and --verify): RUNE_MEMORY_DIR
pinned to a wiped-per-process hermetic scratch, the clock pinned via
RUNE_FROZEN_NOW (the harness patches the oracle's module-global datetime),
and the gm_* seams that drive the REAL db-carrying fns on the hermetic
connection with JSON-safe shapes.
Run (from the repo root):
PYTHONHASHSEED=0 RUNE_FROZEN_NOW=2026-10-13T12:00:00 \
PYTHONPATH=scripts/gm_freeze_seams:src \
python3 scripts/gen_graph_memory_truth.py
Verify (byte-identical, same rig — the envelope carries frozen_now):
PYTHONHASHSEED=0 PYTHONPATH=scripts/gm_freeze_seams:src \
python3 scripts/freeze_truth.py --verify \
src/rust/graph_memory/frozen_truth.json \
--module rune.graph_memory
Case map (every gap branch):
* now_iso — seconds-precision shape (frozen clock; fractional dropped).
* gm_connect — DDL shape (entities/aliases/edges tables exist).
* strength_to_conf — direct kernel: below-floor (2, 2.9, 0, -1), floor
(3->0.76), mid (4->0.88, 3.5 float artifact), ceiling (5->0.99,
6/100 capped), unparseable (None, "x", "", object) -> None.
* gm_resolve — create (person type kept), alias-hit (case-insensitive),
unknown-type fallback (concept), empty/blank -> None.
* gm_add_edge — unknown pred refused (False), gated strength (False),
None-confidence+None-strength refused (False), happy path (True),
duplicate re-add (True, no new row), stronger re-add (True,
supersedes), self-loop refused (False), empty-subj refused (False),
pred normalization ("Works On" -> works_on), evidence cap (400).
* gm_query — exact hit (facts projected, timestamps "TS"), alias hit,
substring fallback, miss -> [], empty -> [].
* gm_stats — counts + top-8 predicates after the seeded writes.
"""
import sys
from pathlib import Path
REPO = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(REPO / "scripts"))
from freeze_truth import freeze, write_envelope # noqa: E402
import rune.graph_memory as oracle # noqa: E402
FROZEN_NOW = "2026-10-13T12:00:00"
cases = [
# now_iso: seconds-precision shape under the frozen clock.
("now_iso", (), {}),
# gm_connect: the DDL shape on the pinned dir.
("gm_connect", (), {}),
# strength_to_conf: the gating kernel, every branch.
("strength_to_conf", (2,), {}),
("strength_to_conf", (2.9,), {}),
("strength_to_conf", (0,), {}),
("strength_to_conf", (-1,), {}),
("strength_to_conf", (3,), {}),
("strength_to_conf", (4,), {}),
("strength_to_conf", (5,), {}),
("strength_to_conf", (3.5,), {}),
("strength_to_conf", (6,), {}),
("strength_to_conf", (100,), {}),
("strength_to_conf", (None,), {}),
("strength_to_conf", ("x",), {}),
("strength_to_conf", ("",), {}),
("strength_to_conf", ("4",), {}),
# gm_resolve: create / alias-hit / fallback / empty.
("gm_resolve", ("Ada Lovelace", "person"), {}),
("gm_resolve", ("ada lovelace",), {}),
("gm_resolve", ("Analytical Engine", "machine"), {}),
("gm_resolve", ("",), {}),
("gm_resolve", (" ",), {}),
("gm_resolve", (None,), {}),
# gm_add_edge: every branch of the gating + supersession machine.
("gm_add_edge", ("Ada Lovelace", "frobnicate", "Analytical Engine",
{"confidence": 0.9}), {}),
("gm_add_edge", ("Ada Lovelace", "builds", "Analytical Engine",
{"strength": 2}), {}),
("gm_add_edge", ("Ada Lovelace", "builds", "Analytical Engine", {}), {}),
("gm_add_edge", ("Ada Lovelace", "builds", "Analytical Engine",
{"confidence": 0.9, "evidence": "first notes",
"source": "truth"}), {}),
("gm_add_edge", ("Ada Lovelace", "builds", "Analytical Engine",
{"confidence": 0.9, "evidence": "first notes",
"source": "truth"}), {}),
("gm_add_edge", ("Ada Lovelace", "builds", "Analytical Engine",
{"confidence": 0.95, "evidence": "revised notes",
"source": "truth"}), {}),
("gm_add_edge", ("Ada Lovelace", "likes", "Ada Lovelace",
{"confidence": 0.9}), {}),
("gm_add_edge", ("", "likes", "Analytical Engine",
{"confidence": 0.9}), {}),
("gm_add_edge", ("Ada Lovelace", "Works On", "Difference Engine",
{"confidence": 0.8, "evidence": "e",
"source": "truth"}), {}),
("gm_add_edge", ("Ada Lovelace", "knows", "Charles Babbage",
{"confidence": 0.8, "evidence": "y" * 500,
"source": "truth"}), {}),
# gm_query: exact / alias / substring / miss / empty.
("gm_query", ("Ada Lovelace", 1), {}),
("gm_query", ("ada lovelace", 1), {}),
("gm_query", ("Babbage", 1), {}),
("gm_query", ("Nobody Here", 1), {}),
("gm_query", ("", 1), {}),
# gm_stats: counts after the seeded writes.
("gm_stats", (), {}),
]
truth = freeze("rune.graph_memory", cases, oracle_module="rune.graph_memory")
write_envelope(FROZEN_NOW, truth,
REPO / "src" / "rust" / "graph_memory" / "frozen_truth.json")
print(f"froze {len(truth)} rows -> src/rust/graph_memory/frozen_truth.json")
+278
View File
@@ -0,0 +1,278 @@
#!/usr/bin/env python3
"""gen_layout_contract_truth.py — freeze the layout_contract gap truth
(define_region / bind_component / amend_layout_contract /
record_layout_observation) through the SHARED harness
(scripts/freeze_truth.py — one law).
The oracle fns mutate a doc argument and stamp observed_at through
structural_store.now, so this generator runs under the freeze rig
(scripts/lc_freeze_seams/sitecustomize.py): pinned RUNE_*_CORE=python
floors, frozen clock on both now seams, and DOC-CARRYING wrappers that
record {"result", "doc": {entities, observations}} — the Rust kernel is a
pure doc-in/doc-out membrane (the store stays with the facade), so every
case carries the full input doc in its args and replays in the battery
with no store. Errors freeze as {"error": "Type: message"}
(construction_decision convention). The input docs are LITERAL dicts that
match add_entity output exactly — built by hand here, deterministic by
construction (no store IO; this module has no file-IO surface).
Run (from the repo root):
PYTHONPATH=scripts/lc_freeze_seams:src \
python3 scripts/gen_layout_contract_truth.py
Verify (byte-identical, same rig):
PYTHONPATH=scripts/lc_freeze_seams:src \
python3 scripts/freeze_truth.py --verify \
src/rust/layout_contract/frozen_lc_gap_truth.json \
--module rune.layout_contract
Every ported function and branch is exercised:
define_region new (defaults / all kwargs), merge-update
(identities refresh, evidence union, maturity
high-water, tags union), empty evidence_refs
bind_component ui:-prefixing (both forms), unknown region,
lock/provenance law (2 rejections), re-bind merge
(amendments preserved, DRIFTING→ACTIVE, evidence
union), order/parent_of, framework_attrs
amend_layout_contract no contract, flexible amend (region/order),
ui:-prefixed, USER-LOCKED rejections (non-user
auth ×2, missing reason), authorized amend,
unlock (authorized + rejected), unknown region,
prior amendments append + reason[:200] truncation
record_layout_observation empty adapter, empty observed, prefix mix,
append to existing observations, empty obs dict
"""
import os
import sys
from pathlib import Path
REPO = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(REPO / "scripts"))
from freeze_truth import freeze, write_envelope # noqa: E402
import sitecustomize as rig # noqa: E402 (rig-bound: pinned cores + clock)
NOW = rig.FROZEN_NOW
OUT = Path(os.environ.get("LC_TRUTH_OUT")
or REPO / "src" / "rust" / "layout_contract" / "frozen_lc_gap_truth.json")
def new_doc():
return {"schema_version": 1, "generated_at": NOW,
"entities": [], "relationships": [], "observations": []}
# ── literal fixtures (match add_entity output exactly) ──────────────────────
def region(rid, **ids):
ident = {"parent": "", "orientation": "", "sizing": "",
"visibility": "", "provenance": "scaffold", "tech": {}}
ident.update(ids)
return {"id": f"region:{rid}", "kind": "layout_region",
"maturity": "DECLARED", "tags": [], "identities": ident,
"evidence_refs": ["region-defined:scaffold"],
"observed_at": NOW}
DOC_REGIONS = new_doc()
DOC_REGIONS["entities"] = [
region("header", orientation="horizontal", sizing="auto",
visibility="visible"),
region("sidebar", parent="header", order=1, orientation="vertical",
sizing="fill", visibility="visible", provenance="user",
tech={"tui": "pane"}),
{"id": "region:main", "kind": "layout_region", "maturity": "DECLARED",
"tags": [], "identities": {"parent": "", "orientation": "",
"sizing": "", "visibility": "",
"provenance": "scaffold", "tech": {}},
"evidence_refs": ["spec-layout"], "observed_at": NOW},
]
def contract(component, region_id, *, lock=False, provenance="scaffold",
order=None, anchor="", framework_attrs=None, status="ACTIVE",
evidence="layout-bind:scaffold", amendments=None,
last_violation=None):
ident = {"component": component, "region": region_id, "lock": lock,
"provenance": provenance, "anchor": anchor, "sizing": "",
"visibility": "", "implementation": "",
"framework_attrs": dict(framework_attrs or {})}
if order is not None:
ident["order"] = order
ext = {"amendments": amendments or []}
if last_violation is not None:
ext["last_violation"] = last_violation
return {"id": f"layout:{component}", "kind": "layout_contract",
"maturity": "DECLARED", "tags": [], "identities": ident,
"evidence_refs": [evidence], "observed_at": NOW,
"ext": ext, "status": status}
def with_contracts(**kw):
doc = new_doc()
doc["entities"] = list(DOC_REGIONS["entities"]) + [
contract("ui:version-info", "sidebar", lock=True, provenance="user",
order=1, anchor="top", evidence="issue-105", **kw),
contract("ui:status-bar", "main",
framework_attrs={"qt": "QStatusBar"})]
return doc
DOC_WITH_CONTRACTS = with_contracts()
DOC_DRIFTING = with_contracts(
status="DRIFTING",
last_violation={"at": NOW, "observed": {"region": "main"},
"reason": "region 'main' != required 'sidebar'"},
)
DOC_AMENDED = new_doc()
DOC_AMENDED["entities"] = list(DOC_REGIONS["entities"]) + [
contract("ui:version-info", "sidebar", lock=True, provenance="user",
order=1, anchor="top", evidence="issue-105",
amendments=[{"at": NOW, "authorized_by": "user",
"reason": "first move",
"evidence": "am-0",
"changes": {"anchor": "top"}}]),
contract("ui:status-bar", "main",
framework_attrs={"qt": "QStatusBar"}),
]
DOC_MATURE = new_doc()
_mature_sidebar = region("sidebar", parent="header")
_mature_sidebar["maturity"] = "WIRED"
_mature_sidebar["tags"] = ["layout"]
DOC_MATURE["entities"] = [
region("header"),
_mature_sidebar,
{"id": "region:main", "kind": "layout_region", "maturity": "DECLARED",
"tags": [], "identities": {"parent": "", "orientation": "",
"sizing": "", "visibility": "",
"provenance": "scaffold", "tech": {}},
"evidence_refs": ["spec-layout"], "observed_at": NOW},
]
DOC_WITH_OBS = new_doc()
DOC_WITH_OBS["observations"] = [
{"kind": "layout_observed", "component": "ui:footer",
"adapter": "prev", "observed": {"region": "main"},
"observed_at": NOW},
]
cases = [
# ── define_region: new entity, defaults ─────────────────────────────────
("define_region", (new_doc(), "header"), {}),
# all kwargs (tech dict, explicit provenance/evidence)
("define_region", (new_doc(), "sidebar"),
{"parent": "header", "order": 1, "orientation": "vertical",
"sizing": "fill", "visibility": "visible", "tech": {"tui": "pane"},
"provenance": "user", "evidence_refs": ["spec-11"]}),
# explicit empty evidence_refs mints the region-defined default too
# (Python `x or [default]` falsiness law)
("define_region", (new_doc(), "r-empty"),
{"evidence_refs": []}),
# unsorted evidence_refs freeze sorted
("define_region", (new_doc(), "multi"),
{"evidence_refs": ["b", "a", "c"]}),
# ── define_region: merge-update paths ───────────────────────────────────
# no-op re-define (identities overwritten with defaults, observed_at
# refreshed)
("define_region", (DOC_REGIONS, "sidebar"), {}),
# union merge: identities refresh + evidence union, order re-set
("define_region", (DOC_REGIONS, "sidebar"),
{"order": 2, "orientation": "horizontal", "evidence_refs": ["spec-12"]}),
# mature sidebar: maturity high-water (DECLARED does NOT downgrade
# WIRED), tags union (none added via this API)
("define_region", (DOC_MATURE, "sidebar"),
{"evidence_refs": ["fresh"]}),
# ── bind_component: new contracts ───────────────────────────────────────
# USER-LOCKED bind (lock + user provenance)
("bind_component", (DOC_REGIONS, "version-info", "sidebar"),
{"lock": True, "provenance": "user", "order": 1, "anchor": "top",
"evidence_ref": "issue-105"}),
# flexible bind, all defaults
("bind_component", (DOC_REGIONS, "status-bar", "main"), {}),
# ui:-prefixed component + open-world framework attrs (they ride the
# **framework_attrs catch-all — passed as bare kwargs, like real callers)
# + implementation
("bind_component", (DOC_REGIONS, "ui:footer", "main"),
{"sizing": "1-line", "visibility": "always",
"implementation": "src/ui/footer.py",
"css": "flex", "qt": "QStatusBar"}),
# parent_of + order on a bare name
("bind_component", (DOC_REGIONS, "panel", "sidebar"),
{"parent_of": "ui:version-info", "order": 2}),
# ── bind_component: rejections (the lock/provenance law) ────────────────
("bind_component", (DOC_REGIONS, "x", "nope"), {}),
("bind_component", (DOC_REGIONS, "x", "sidebar"), {"lock": True}),
("bind_component", (DOC_REGIONS, "x", "sidebar"),
{"lock": True, "provenance": "builder"}),
# ── bind_component: re-bind merges ──────────────────────────────────────
# identities refresh (anchor), ACTIVE kept; the amendments ledger is
# RESET by re-binding (fresh binding — the oracle assigns [], not
# appends)
("bind_component", (DOC_WITH_CONTRACTS, "version-info", "sidebar"),
{"lock": True, "provenance": "user", "order": 1, "anchor": "top-left",
"evidence_ref": "rebind-1"}),
# re-bind over a NON-EMPTY amendments ledger: cleared (the
# discriminating case — empty-ledger re-binds can't tell)
("bind_component", (DOC_AMENDED, "version-info", "sidebar"),
{"lock": True, "provenance": "user", "order": 1, "anchor": "top"}),
# DRIFTING contract re-bound returns to ACTIVE
("bind_component", (DOC_DRIFTING, "version-info", "sidebar"),
{"lock": True, "provenance": "user", "order": 1, "anchor": "top"}),
# ui:-prefixed re-bind: region change + evidence union
("bind_component", (DOC_WITH_CONTRACTS, "ui:status-bar", "sidebar"),
{"evidence_ref": "move-1"}),
# ── amend_layout_contract: rejections ───────────────────────────────────
("amend_layout_contract", (new_doc(), "version-info"), {}),
("amend_layout_contract", (DOC_WITH_CONTRACTS, "version-info"),
{"new_region": "main"}),
("amend_layout_contract", (DOC_WITH_CONTRACTS, "version-info"),
{"authorized_by": "model"}),
("amend_layout_contract", (DOC_WITH_CONTRACTS, "version-info"),
{"authorized_by": "user"}),
("amend_layout_contract", (DOC_WITH_CONTRACTS, "version-info"),
{"unlock": True, "authorized_by": "user"}),
("amend_layout_contract", (DOC_WITH_CONTRACTS, "status-bar"),
{"unlock": True}),
("amend_layout_contract", (DOC_WITH_CONTRACTS, "status-bar"),
{"new_region": "nope"}),
# ── amend_layout_contract: mutations ────────────────────────────────────
# flexible builder amend (region + order + evidence)
("amend_layout_contract", (DOC_WITH_CONTRACTS, "status-bar"),
{"new_region": "sidebar", "new_order": 0, "authorized_by": "builder",
"reason": "reorganize", "evidence_ref": "am-1"}),
# ui:-prefixed component, order-only amend
("amend_layout_contract", (DOC_WITH_CONTRACTS, "ui:status-bar"),
{"new_order": 3}),
# authorized USER-LOCKED amend
("amend_layout_contract", (DOC_WITH_CONTRACTS, "version-info"),
{"new_region": "main", "authorized_by": "user",
"reason": "user wants it in main"}),
# authorized unlock
("amend_layout_contract", (DOC_WITH_CONTRACTS, "version-info"),
{"unlock": True, "authorized_by": "user", "reason": "free it"}),
# append to a prior amendments ledger + reason[:200] truncation
("amend_layout_contract", (DOC_AMENDED, "version-info"),
{"new_order": 5, "authorized_by": "user", "reason": "R" * 300,
"evidence_ref": "am-2"}),
# ── record_layout_observation ───────────────────────────────────────────
("record_layout_observation", (new_doc(), "", {}), {}),
("record_layout_observation", (new_doc(), "qt-adapter", {}), {}),
# prefix mix (bare, ui:-prefixed, new) + multi-field obs
("record_layout_observation",
(new_doc(), "tui",
{"version-info": {"region": "sidebar", "order": 1},
"ui:status-bar": {"region": "main"},
"footer": {"region": "main", "parent": "header"}}), {}),
# append to existing observations
("record_layout_observation",
(DOC_WITH_OBS, "tui", {"version-info": {"region": "main"}}), {}),
# empty obs dict passthrough
("record_layout_observation", (new_doc(), "web-dom", {"x": {}}), {}),
]
truth = freeze("rune.layout_contract", cases,
oracle_module="rune.layout_contract")
write_envelope(NOW, truth, OUT)
print(f"froze {len(truth)} cases -> {OUT}")
+416
View File
@@ -0,0 +1,416 @@
#!/usr/bin/env python3
"""gen_microkernel_gap_truth.py — microkernel gap-closing truth battery
(dichotomy wave #2479, worktree rune-wave-cq).
Closes the PARTIAL audit gaps: now_iso, discover, _extract_manifest,
_load_registry, _save_registry, _run_hook (fire's hook runner).
Uses the SHARED harness (scripts/freeze_truth.py): RUNE core pinned to
python, deep-copied inputs, envelope with its own frozen_now:
PYTHONPATH=src python3 scripts/freeze_truth.py \
--verify src/go/microkernel/truth_microkernel_gap.json \
--module rune.microkernel
STATEFULNESS / DETERMINISM LAWS:
* _extract_manifest takes an fpath — the shim carries the file CONTENT
in args, writes a temp file, calls the real oracle fn, returns the
parsed manifest (paths never enter the result).
* discover iterates os.listdir (filesystem order) and stamps absolute
_file paths — the shim installs a fixture dir, pins os.listdir to the
EXACT frozen filename order (sorted — matches the Go port's
os.ReadDir), calls the real discover(), and normalizes every path to
<dir>/<fname> stubs. Machine-independent, replay-stable.
* _run_hook is a closure inside fire() — it is exercised through the
real fire() with ONE listener per branch class (fixture scripts are
in-file constants: deterministic stdout/stderr). wall-clock durations
(duration_ms / total_duration_ms) are normalized to "<ms>" — the
no-wall-clock law.
* _load_registry/_save_registry: missing file, corrupt file, full-shape
file (verbatim load), and a save->load roundtrip of the default shape.
Usage: python3 scripts/gen_microkernel_gap_truth.py (from repo root)
python3 scripts/gen_microkernel_gap_truth.py --verify
"""
import copy
import json
import os
import sys
import tempfile
from datetime import datetime as _dt, timezone as _tz
from pathlib import Path
REPO = Path(__file__).resolve().parent.parent
sys.path.insert(0, str(REPO / "scripts"))
sys.path.insert(0, str(REPO / "src"))
sys.path.insert(0, str(REPO / "src" / "rune"))
from freeze_truth import freeze, write_envelope # noqa: E402
FROZEN_NOW = "2026-10-13T11:05:00"
os.environ["RUNE_FROZEN_NOW"] = FROZEN_NOW
os.environ["RUNE_MICROKERNEL_CORE"] = "python" # poisoned-truth law
import microkernel as mk # noqa: E402
SHIM = "gen_microkernel_gap_truth_shims"
def _pin_mk_clock():
"""microkernel's fire() mixes datetime.now() (naive) and
datetime.now(timezone.utc) (aware) — the harness clock is naive-only,
so shims that reach register()/fire() pin an AWARE frozen clock.
Durations collapse to 0.0 (normalized to <ms> by the rig regardless)."""
base = _dt.fromisoformat(FROZEN_NOW).replace(tzinfo=_tz.utc)
class _Frozen(_dt):
@classmethod
def now(cls, tz=None):
if tz is not None:
return base.replace(tzinfo=tz)
return base
old = mk.datetime
mk.datetime = _Frozen
return old
# ── fixture hook scripts (deterministic output; stdlib only) ──────────────
OK_JSON = (
"import json, sys\n"
"data = sys.argv[sys.argv.index('--data') + 1]\n"
"print(json.dumps({'echo': json.loads(data)}))\n"
)
RAW_LONG = (
"print('h\\u00e9llo-\\u2192ok ' * 120)\n" # 1200 codepoints, non-JSON
)
BOOM = (
"import sys\n"
"sys.stderr.write('\\u00e9rr\\u00f4r-' * 100)\n" # 600 codepoints
"sys.exit(3)\n"
)
SLOW = "import time\ntime.sleep(5)\n"
def _norm_fire(result):
"""Normalize wall-clock fields + as_completed order (the rig law)."""
out = copy.deepcopy(result)
if "total_duration_ms" in out:
out["total_duration_ms"] = "<ms>"
for r in out.get("results", []):
if "duration_ms" in r:
r["duration_ms"] = "<ms>"
if isinstance(r.get("error"), str):
r["error"] = r["error"]
out["results"] = sorted(out.get("results", []), key=lambda r: r.get("name", ""))
return out
def _norm_log(log):
out = []
for e in log:
e = dict(e)
e["duration_ms"] = "<ms>"
out.append(e)
return out
def _registry_projection(reg, dir_token):
plugins = {}
for name, p in reg["plugins"].items():
plugins[name] = {
"active": p.get("active"),
"registered_at": p.get("registered_at"),
"file": p.get("file", "").replace(dir_token, "<dir>"),
}
return {
"plugins": plugins,
"capabilities": reg.get("capabilities", {}),
"hooks": reg.get("hooks", {}),
}
# ── wrapper shims: module-level names the harness can call ────────────────
def _mk_extract(content):
fd, fpath = tempfile.mkstemp(suffix=".py", prefix="mk_gap_")
try:
with os.fdopen(fd, "w") as f:
f.write(content)
return {"result": copy.deepcopy(mk._extract_manifest(fpath))}
finally:
os.unlink(fpath)
def _mk_discover(filenames, contents, now):
"""Fixture-driven discover: filenames (EXACT listing order — pass them
sorted, matching the Go port's os.ReadDir), contents {fname: source}."""
work = tempfile.mkdtemp(prefix="mk_disc_")
fixture = Path(work) / "scripts"
fixture.mkdir()
for fname, src in contents.items():
(fixture / fname).write_text(src)
tmpdb = os.path.join(work, "registry.json")
old_dir, old_db = mk.SCRIPTS_DIR, mk.REGISTRY_DB
real_listdir = os.listdir
old_clock = _pin_mk_clock()
mk.SCRIPTS_DIR = str(fixture)
mk.REGISTRY_DB = tmpdb
os.listdir = lambda p: list(filenames) if str(p) == str(fixture) else real_listdir(p)
try:
result = copy.deepcopy(mk.discover())
state = _registry_projection(mk._load_registry(), str(fixture))
finally:
os.listdir = real_listdir
mk.SCRIPTS_DIR, mk.REGISTRY_DB = old_dir, old_db
mk.datetime = old_clock
return {"result": result, "registry": state}
def _mk_load(content):
"""_load_registry over a fixture registry file (None = missing file).
Projection: the port stores TYPED manifests, so the frozen contract is
the round-tripped shape (active/registered_at/file + indexes + log),
not the verbatim manifest dict."""
work = tempfile.mkdtemp(prefix="mk_load_")
db = os.path.join(work, "registry.json")
old_db = mk.REGISTRY_DB
mk.REGISTRY_DB = db
try:
if content is not None:
with open(db, "w") as f:
f.write(content)
elif os.path.exists(db):
os.unlink(db)
loaded = mk._load_registry()
return {"result": _registry_projection(loaded, "<none>"), "log": loaded.get("log", [])}
finally:
mk.REGISTRY_DB = old_db
def _mk_save_load_default():
"""_save_registry -> _load_registry roundtrip of the default shape."""
work = tempfile.mkdtemp(prefix="mk_rt_")
db = os.path.join(work, "registry.json")
old_db = mk.REGISTRY_DB
mk.REGISTRY_DB = db
try:
loaded = mk._load_registry()
mk._save_registry(loaded)
again = mk._load_registry()
return {"first": copy.deepcopy(loaded), "again": copy.deepcopy(again),
"stable": loaded == again}
finally:
mk.REGISTRY_DB = old_db
def _mk_fire(script, manifest, event, data, timeout):
"""fire() with ONE registered listener whose _file is the fixture
script (or a ghost/empty path for the not-found class). Exercises the
oracle's _run_hook closure branch selected by the fixture."""
work = tempfile.mkdtemp(prefix="mk_fire_")
if script is not None:
fpath = os.path.join(work, "plugin.py")
with open(fpath, "w") as f:
f.write(script)
manifest = dict(manifest)
manifest["_file"] = fpath
else:
manifest = dict(manifest) # _file stays whatever the caller set
tmpdb = os.path.join(work, "registry.json")
old_db = mk.REGISTRY_DB
old_clock = _pin_mk_clock()
mk.REGISTRY_DB = tmpdb
try:
mk.register(manifest)
result = mk.fire(event, data=data, timeout=timeout)
state = mk._load_registry()
return {"result": _norm_fire(result), "log": _norm_log(state.get("log", []))}
finally:
mk.REGISTRY_DB = old_db
mk.datetime = old_clock
def _mk_fire_two(scripts, manifests, event, data, timeout):
"""fire() with TWO listeners (parallelism + log entry)."""
work = tempfile.mkdtemp(prefix="mk_fire2_")
tmpdb = os.path.join(work, "registry.json")
old_db = mk.REGISTRY_DB
old_clock = _pin_mk_clock()
mk.REGISTRY_DB = tmpdb
try:
for script, manifest in zip(scripts, manifests):
manifest = dict(manifest)
if script is not None:
fpath = os.path.join(work, manifest["name"] + ".py")
with open(fpath, "w") as f:
f.write(script)
manifest["_file"] = fpath
mk.register(manifest)
result = mk.fire(event, data=data, timeout=timeout)
state = mk._load_registry()
return {"result": _norm_fire(result), "log": _norm_log(state.get("log", []))}
finally:
mk.REGISTRY_DB = old_db
mk.datetime = old_clock
CACHEY = (
'PLUGIN = {\n'
' "name": "cache",\n'
' "version": "0.1.0",\n'
' "description": "Cache system — event-driven invalidation.",\n'
' "capabilities": ["cache", "invalidation"],\n'
' "hooks": {\n'
' "on_session_end": "handle_hook",\n'
' "on_memory_add": "handle_hook",\n'
' },\n'
' "dependencies": [],\n'
' "priority": 1,\n'
' "auto_activate": True,\n'
'}\n'
)
def main():
sys.modules[SHIM] = sys.modules["__main__"]
cases = []
# ── now_iso (pinned clock: RUNE_FROZEN_NOW → datetime frozen) ──
cases.append(("now_iso", [], {}))
# ── _extract_manifest branches ────────────────────────────────
cases.append((f"{SHIM}._mk_extract", [CACHEY], {}))
cases.append((f"{SHIM}._mk_extract", ["X = 1\n"], {}))
cases.append((f"{SHIM}._mk_extract", ["PLUGIN = {}\n"], {}))
cases.append((f"{SHIM}._mk_extract", ["PLUGIN = {}\nX = 1\n"], {}))
cases.append((f"{SHIM}._mk_extract", ['PLUGIN = {\n "name": "x",\n'], {}))
cases.append((f"{SHIM}._mk_extract",
["PLUGIN = {'name': 'café', 'n': 1.5, 'neg': -3, 'big': 1e3}\n"], {}))
cases.append((f"{SHIM}._mk_extract",
['PLUGIN = {\n # comment inside\n "name": "x",\n}\n'], {}))
cases.append((f"{SHIM}._mk_extract",
['PLUGIN = {\n "name": "x",\n "hooks": {"a": True, "b": False},\n "nested": {"deep": [1, 2, {"k": "v"}]},\n}\n'], {}))
# ── discover (fixture dir, pinned listing order = sorted) ─────
mixed_files = ["_private.py", "a_cache.py", "b_noname.py", "c_plain.py",
"d_falsy.py", "microkernel.py", "notes.txt"]
mixed_contents = {
"a_cache.py": CACHEY,
"b_noname.py": 'PLUGIN = {\n "version": "0.1.0",\n}\n',
"c_plain.py": "def run():\n pass\n",
"d_falsy.py": ('PLUGIN = {\n "name": "d",\n "capabilities": ["d"],\n'
' "hooks": {"on_x": False, "on_y": "", "on_z": 0},\n}\n'),
"_private.py": CACHEY,
"microkernel.py": CACHEY,
"notes.txt": "not a plugin",
}
cases.append((f"{SHIM}._mk_discover", [mixed_files, mixed_contents, FROZEN_NOW], {}))
cases.append((f"{SHIM}._mk_discover", [[], {}, FROZEN_NOW], {}))
shared_files = ["s1.py", "s2.py"]
shared_contents = {
"s1.py": 'PLUGIN = {\n "name": "s1",\n "capabilities": ["shared"],\n "priority": 5,\n}\n',
"s2.py": 'PLUGIN = {\n "name": "s2",\n "capabilities": ["shared"],\n "priority": 10,\n}\n',
}
cases.append((f"{SHIM}._mk_discover", [shared_files, shared_contents, FROZEN_NOW], {}))
# ── _load_registry / _save_registry ───────────────────────────
full_registry = json.dumps({
"plugins": {"p": {"manifest": {"name": "p", "priority": 1},
"registered_at": "2026-10-13T11:05:00+00:00",
"active": True, "file": "/x/p.py"}},
"capabilities": {"cap": ["p"]},
"hooks": {"evt": ["p"]},
"log": [{"event": "evt", "timestamp": "2026-10-13T11:05:00+00:00",
"hooks_fired": 1, "duration_ms": 12.5}],
}, indent=2)
cases.append((f"{SHIM}._mk_load", [None], {}))
cases.append((f"{SHIM}._mk_load", ["{oops"], {}))
cases.append((f"{SHIM}._mk_load", [full_registry], {}))
cases.append((f"{SHIM}._mk_save_load_default", [], {}))
# ── _run_hook (through fire, one branch class per case) ───────
evt = "on_session_end"
cases.append((f"{SHIM}._mk_fire",
[OK_JSON, {"name": "okp", "hooks": {evt: True}},
evt, {"k": "v", "n": 2}, 30], {}))
cases.append((f"{SHIM}._mk_fire",
[RAW_LONG, {"name": "rawp", "hooks": {evt: True}}, evt, None, 30], {}))
cases.append((f"{SHIM}._mk_fire",
[BOOM, {"name": "boomp", "hooks": {evt: True}}, evt, None, 30], {}))
cases.append((f"{SHIM}._mk_fire",
[SLOW, {"name": "slowp", "hooks": {evt: True}}, evt, None, 1], {}))
cases.append((f"{SHIM}._mk_fire",
[OK_JSON, {"name": "offp", "hooks": {evt: True}, "auto_activate": False},
evt, None, 30], {}))
cases.append((f"{SHIM}._mk_fire",
[None, {"name": "ghostp", "hooks": {evt: True}, "_file": "/nonexistent/ghost.py"},
evt, None, 30], {}))
cases.append((f"{SHIM}._mk_fire",
[None, {"name": "nofilep", "hooks": {evt: True}}, evt, None, 30], {}))
# fire with NO listeners: early return, no log entry
cases.append((f"{SHIM}._mk_fire",
[OK_JSON, {"name": "lonely", "capabilities": ["x"]}, "no_such_event", None, 30], {}))
# two listeners in parallel: sorted results + one log entry
cases.append((f"{SHIM}._mk_fire_two",
[[OK_JSON, OK_JSON],
[{"name": "zz", "hooks": {evt: True}},
{"name": "aa", "hooks": {evt: True}}],
evt, {"k": 1}, 30], {}))
# harness resolves dotted names against ONE module — freeze per case
# against the fn's OWN module (same law as gen_hook_engine_gap_truth).
truth = []
for fn, args, kwargs in cases:
if fn.startswith(f"{SHIM}."):
mod, short = SHIM, fn.split(".")[-1]
else:
mod, short = "microkernel", fn
rows = freeze(mod, [(short, args, kwargs)], oracle_module=mod)
rows[0]["fn"] = fn
rows[0]["oracle"] = mod
truth.append(rows[0])
target = REPO / "src" / "go" / "microkernel" / "truth_microkernel_gap.json"
write_envelope(FROZEN_NOW, truth, target)
print(f"wrote {target} ({len(truth)} cases)")
def verify(path):
"""Per-case-module verify (same byte-compare law as the harness)."""
raw = json.loads(path.read_text())
frozen = raw["cases"] if isinstance(raw, dict) else raw
if isinstance(raw, dict) and raw.get("frozen_now"):
os.environ["RUNE_FROZEN_NOW"] = raw["frozen_now"]
sys.modules.setdefault(SHIM, sys.modules["__main__"])
fresh = []
for c in frozen:
mod = c.get("oracle", "microkernel")
short = c["fn"].split(".")[-1]
rows = freeze(mod, [(short, c.get("args", []), c.get("kwargs", {}))],
oracle_module=mod)
rows[0]["fn"] = c["fn"]
rows[0]["oracle"] = mod
fresh.append(rows[0])
if json.dumps(fresh, sort_keys=True) != json.dumps(frozen, sort_keys=True):
print(f"MISMATCH: regenerated truth differs from {path}")
for f, g in zip(frozen, fresh):
if json.dumps(f, sort_keys=True) != json.dumps(g, sort_keys=True):
print(f" first divergence at fn={f['fn']}")
print(f" frozen: {json.dumps(f['expected'])[:300]}")
print(f" oracle: {json.dumps(g['expected'])[:300]}")
break
return 1
print(f"OK: {len(frozen)} cases byte-identical against live oracles")
return 0
if __name__ == "__main__":
if len(sys.argv) > 1 and sys.argv[1] == "--verify":
sys.exit(verify(REPO / "src" / "go" / "microkernel" / "truth_microkernel_gap.json"))
main()
+177
View File
@@ -0,0 +1,177 @@
#!/usr/bin/env python3
"""gen_model_connect_truth.py — freeze the model_connect gap-close truth
envelope via the shared freeze_truth.py harness (#2479 wave 4).
Covers the full ported surface, exercising every branch:
* _clean_model_name — HF repo paths (family+size / family+version+size /
short-part / no-match truncation) and clean names (passthrough)
* is_moe_model — every MOE pattern family + negatives
* route_model — exact matches per tier, unknown task type, fallback,
empty list (null model/tier)
* _ctx_budget — every DEFAULT_PROFILES id (incl. deterministic's 0-window
→ 8192 floor), the cloud (non-local) tool reserve, unknown + empty ids
* _now — the pinned-clock isoformat
* handle_hook — constant envelope over varied events/data
* _get_cloud_models (seeded/missing seams) — JSONC comments + trailing
commas, ollama skip, multi-provider ordering, provider without models,
config without provider, the PARTIAL-return mid-loop shape error, the
naive comment-strip corrupting URLs, and the missing-file branch
Usage (from the repo root; the seams dir is mandatory — it pins HOME and
binds the cloud seams):
PYTHONPATH=scripts/mconn_freeze_seams:src python3 scripts/gen_model_connect_truth.py
"""
import os
import sys
from pathlib import Path
REPO = Path(os.path.abspath(__file__)).resolve().parents[1]
sys.path.insert(0, str(REPO / "src"))
sys.path.insert(0, str(REPO / "scripts"))
FROZEN_NOW = "2026-10-14T08:00:00+00:00" # microsecond=0: isoformat == the pin
os.environ["RUNE_FROZEN_NOW"] = FROZEN_NOW
import freeze_truth # noqa: E402
MODELS_ALL = [
"qwen2.5:3b",
"qwen2.5:7b",
"qwen3:14b",
"qwen2.5-coder:14b",
"hf.co/DavidAU/Qwen3.6-27B-Fable-Fusion-711-Uncensored-Heretic-NM-DAU-NEO-MAX-MTP-GGUF:IQ2_M",
"mixtral:8x7b-instruct-v0.1-q4_0",
"qwen2.5vl:3b",
"llava:7b",
"qwen3-embedding:0.6b",
"nomic-embed-text:latest",
"mxbai-embed-large:latest",
]
FIXTURE_MAIN = """{
// MiMoCode config — JSONC: comments and trailing commas allowed
"provider": {
"ollama": { // skipped: local models handled by list_models
"models": {
"qwen3:14b": {},
},
},
"openai": {
"models": {
"gpt-5.2": {"contextLength": 400000},
"o4-mini": "not-even-a-dict", // model_config is unused by the oracle
},
},
"kimi": {
"models": {
"kimi-for-coding": {},
},
},
},
}
"""
FIXTURE_ONLY_OLLAMA = """{
"provider": {
"ollama": {
"models": {"qwen2.5:3b": {}},
},
},
}
"""
FIXTURE_NO_MODELS_KEY = """{
"provider": {
"anthropic": {
"apiKey": "sk-test",
},
},
}
"""
FIXTURE_NO_PROVIDER_KEY = """{
// no providers configured
"theme": "dark",
}
"""
FIXTURE_BROKEN_LATE = """{
"provider": {
"a": {"models": {"m1": {}}},
"b": {"models": "not-a-dict"},
},
}
"""
FIXTURE_URL_CORRUPTION = """{
"provider": {
"gateway": {
"baseUrl": "http://api.example.com/v1",
"models": {"gw-model": {}},
},
},
}
"""
cases = []
# _clean_model_name
for name in [
"hf.co/DavidAU/Qwen3.6-27B-Fable-Fusion-711-Uncensored-Heretic-NM-DAU-NEO-MAX-MTP-GGUF:IQ2_M",
"hf.co/org/Llama-3-8B-Instruct:latest",
"hf.co/short/gemma-2-9b",
"hf.co/user/nano-model",
"hf.co/user/ab",
"qwen2.5:3b",
"mimo-v2.5-pro",
"llava:7b",
]:
cases.append(("_clean_model_name", (name,), {}))
# is_moe_model
for name, want in [
("mixtral:8x7b", True),
("qwen2.5:3b", False),
("deepseek-moe-16b", True),
("My-Mixture-Model", True),
("expert-v1", True),
("4x22b-tiny", True),
("plain-conversational", False),
("GPT-XL", False),
]:
cases.append(("is_moe_model", (name,), {}))
# route_model (available_models always explicit — the None default would
# fall through to the networked list_models, which is reactive-side only)
for task, models in [
("coding", MODELS_ALL),
("research", MODELS_ALL),
("conversation", MODELS_ALL),
("unknown-type", MODELS_ALL),
("coding", ["mystery-model:x"]),
("coding", []),
]:
cases.append(("route_model", (task,), {"available_models": models}))
# _ctx_budget
for mid in ["deterministic", "qwen2.5:3b", "qwen3:14b", "qwen3.6:27b",
"mimo-v2.5-pro", "totally-unknown-model", ""]:
cases.append(("_ctx_budget", (mid,), {}))
# _now (pinned clock)
cases.append(("_now", (), {}))
# handle_hook
cases.append(("handle_hook", ("pre_tool_use", {"tool": "bash", "dry": False}), {}))
cases.append(("handle_hook", ("", None), {}))
cases.append(("handle_hook", ("post_response", {"ok": True}), {}))
# _get_cloud_models via the pinned-HOME seams
for fixture in [FIXTURE_MAIN, FIXTURE_ONLY_OLLAMA, FIXTURE_NO_MODELS_KEY,
FIXTURE_NO_PROVIDER_KEY, FIXTURE_BROKEN_LATE,
FIXTURE_URL_CORRUPTION]:
cases.append(("_get_cloud_models_seeded", (fixture,), {}))
cases.append(("_get_cloud_models_missing", (), {}))
truth = freeze_truth.freeze("model_connect", cases, oracle_module="rune.model_connect")
out = REPO / "src" / "go" / "model-connect" / "truth.json"
freeze_truth.write_envelope(FROZEN_NOW, truth, out)
print(f"wrote {len(truth)} cases -> {out}")
# sanity: the pinned clock must render exactly as the envelope pin
now_row = [c for c in truth if c["fn"] == "_now"][0]
assert now_row["expected"] == FROZEN_NOW, now_row
print("_now pinned-clock row:", now_row["expected"])
+162
View File
@@ -0,0 +1,162 @@
#!/usr/bin/env python3
"""gen_model_profiles_truth.py — freeze model_profiles oracle truth via
the SHARED harness (scripts/freeze_truth.py, freeze()) through the
scripts/mp_freeze_seams rig (auto-imported sitecustomize: HOME pinned
to MP_FREEZE_HOME before the oracle import, per-case hermetic store
wipe+seed, canned Ollama server, JSON-safe wrapper seams).
Laws honoured:
* hermetic: PROFILES_DIR is expanduser-derived AT IMPORT — the rig
pins HOME to the fixed /tmp/mp_gap_freeze_home root (the CI_FREEZE_HOME
precedent: frozen absolute paths stay byte-identical across processes).
* no wall-clock: created/last_used come from the harness's frozen
clock (write_envelope carries RUNE_FROZEN_NOW inside the file).
* no network: scan_all_models runs against a canned in-process server
(or a refused port for the degrade branch); OLLAMA_URL is repointed
per case at call time.
* self-contained rows: every stateful seam wipes + re-seeds the store
from its args, so --verify replays byte-identically in any order.
* byte-parity corpus: save_profile rows carry the RAW file text — the
Go port's Python-shaped JSON writer must reproduce it exactly
(asdict field order, indent=2 separators, float rendering, ASCII
escaping). Seeds keep integral floats in float form (0.0) — the
integral-float law; int-valued size_gb/optimal_temperature seeds
render differently (Python keeps the int) and stay out of the corpus.
Regenerate + re-verify (byte-identical law — two runs, then verify):
PYTHONPATH=scripts/mp_freeze_seams:src python3 scripts/gen_model_profiles_truth.py
PYTHONPATH=scripts/mp_freeze_seams:src python3 scripts/freeze_truth.py \
--verify src/go/model-profiles/frozen_mp_truth.json \
--module rune.model_profiles
"""
import json
import os
import sys
from pathlib import Path
REPO = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(REPO / "scripts"))
sys.path.insert(0, str(REPO / "src"))
from freeze_truth import freeze, write_envelope # noqa: E402 (shared harness)
FROZEN_NOW = "2026-10-13T09:41:23.123456"
OUT = REPO / "src" / "go" / "model-profiles" / "frozen_mp_truth.json"
FULL_STATE = {
"name": "qwen2.5:7b",
"display_name": "Qwen2.5 7B ✓",
"family": "qwen",
"parameters": "7B",
"quantization": "Q4_K_M",
"size_gb": 4.7,
"strengths": ["reasoning", "coding", "instruction-following", "multilingual"],
"weaknesses": ["verbose thinking"],
"prompting_tips": [
"Be direct", "Use structure", "Specify the language", "Ask for concise",
],
"safety_tier": 2,
"known_refusal_topics": ["weapons", "malware"],
"thinking_format": "<think>",
"response_style": "concise",
"context_window": 32768,
"optimal_temperature": 0.7,
"interactions": 10,
"successes": 7,
"failures": 3,
"last_used": "2026-10-12T00:00:00+00:00",
"created": "2026-10-01T00:00:00+00:00",
}
QWEN_FILE = "qwen2.5_7b.json"
SCAN_FRESH = {"models": [
{"name": "qwen2.5:7b", "size": 7516192768},
{"name": "banker-tie-lo:2b", "size": 2415919104}, # 2.25 GB → 2.2 (ties-to-even)
{"name": "banker-tie-hi:2b", "size": 2952790016}, # 2.75 GB → 2.8 (ties-to-even)
{"size": 123}, # no name → skipped
{"name": "noninteger:5b", "size": 5000000000}, # 4.656… → 4.7
]}
SCAN_EXISTING = {"models": [
{"name": "qwen2.5:7b", "size": 7516192768},
{"name": "llama3.1:8b-q4_K_M", "size": 4831838208}, # 4.5 GB
]}
CASES = [
# ── get_profile_path: filesystem sanitization ────────────────────
("seam_get_profile_path", ("qwen2.5:7b",), {}),
("seam_get_profile_path", ("library/qwen3:14b",), {}),
("seam_get_profile_path", ("a?b:c/d",), {}),
("seam_get_profile_path", ("plain-model",), {}),
# ── load_profile: disk → dataclass, suppressed-exception floor ───
("seam_load_profile", ("qwen2.5:7b", {QWEN_FILE: FULL_STATE}), {}),
("seam_load_profile", ("qwen2.5:7b", None), {}), # no file → None
("seam_load_profile", ("qwen2.5:7b", {"other_7b.json": FULL_STATE}), {}), # wrong file → None
("seam_load_profile", ("qwen2.5:7b", {QWEN_FILE: "{not json"}), {}), # corrupt → None
("seam_load_profile", ("qwen2.5:7b", {QWEN_FILE: { # unknown keys filtered
"name": "qwen2.5:7b", "bogus": 1, "family": "qwen"}}), {}),
("seam_load_profile", ("qwen2.5:7b", {QWEN_FILE: { # missing optionals → defaults
"name": "qwen2.5:7b", "interactions": 5}}), {}),
("seam_load_profile", ("qwen2.5:7b", {QWEN_FILE: {"family": "qwen"}}), {}), # missing name → TypeError suppressed
# ── save_profile: BYTE-PARITY corpus (raw file text) ─────────────
("seam_save_profile", (FULL_STATE,), {}),
("seam_save_profile", ({"name": "plain-model"},), {}), # all defaults
("seam_save_profile", ({
"name": "deepseek-r1:32b", "family": "deepseek", "parameters": "32B",
"size_gb": 0.0, "strengths": [], "safety_tier": 3,
"optimal_temperature": 0.6,
},), {}),
# ── build_profile_from_ollama: knowledge merge + clock + tier ────
("seam_build_profile_from_ollama", ("qwen3:14b", {"display_name": "Qwen3 14B", "size_gb": 9.0}), {}),
("seam_build_profile_from_ollama", ("mistral-7b", None), {}),
("seam_build_profile_from_ollama", ("dolphin-uncensored:7b", None), {}),
("seam_build_profile_from_ollama", ("DAVIDAU-test:14b", None), {}),
("seam_build_profile_from_ollama", ("some-new-model", {"display_name": "X"}), {}),
("seam_build_profile_from_ollama", ("deepseek-r1:32b", {"display_name": "DS", "size_gb": 19.2}), {}),
# ── scan_all_models: Ollama sweep (canned server / dead port) ────
("seam_scan_all_models", (SCAN_FRESH,), {}),
("seam_scan_all_models", (SCAN_EXISTING, {QWEN_FILE: FULL_STATE}), {}), # existing → learned data kept
("seam_scan_all_models", ({"models": [{"name": "phi3:mini"}]}, None), {}), # no size → 0.0
("seam_scan_all_models", ("dead", None), {}),
# ── get_or_create_profile: load-or-build-and-save ────────────────
("seam_get_or_create_profile", ("qwen2.5:7b", {QWEN_FILE: FULL_STATE}), {}),
("seam_get_or_create_profile", ("brand-new-model", None), {}),
# ── record_interaction: learning accumulator (state = the contract)
("seam_record_interaction", ("qwen3:14b", [[True, ""]], None), {}),
("seam_record_interaction", ("fresh-fail:1b", [[False, "refuses weapons"]], None), {}),
("seam_record_interaction", ("dup-topic:1b", [[False, "t1"], [False, "t1"]], None), {}),
("seam_record_interaction", ("no-topic:1b", [[False, ""]], None), {}),
("seam_record_interaction", ("qwen2.5:7b", [[False, "politics"]], {QWEN_FILE: FULL_STATE}), {}),
# ── get_prompt_context: operator string assembly ─────────────────
("seam_get_prompt_context", ("qwen2.5:7b", {QWEN_FILE: FULL_STATE}), {}),
("seam_get_prompt_context", ("tips-only:1b", {"tips-only_1b.json": {
"name": "tips-only:1b", "prompting_tips": ["tip one"]}}), {}),
("seam_get_prompt_context", ("unknown-model-x", None), {}), # fresh unknown → ""
# ── to_dict / from_dict (dataclass surface) ──────────────────────
("seam_to_dict", (FULL_STATE,), {}),
("seam_from_dict", ({"name": "n", "bogus_key": 1, "context_window": 8192},), {}),
]
def main() -> int:
# The harness clock pin is env-driven (RUNE_FROZEN_NOW) — set it for
# the generation run too, not just --verify (write_envelope then
# carries the same instant for byte-identical re-freezes).
os.environ["RUNE_FROZEN_NOW"] = FROZEN_NOW
truth = freeze("model_profiles", CASES, oracle_module="rune.model_profiles")
write_envelope(FROZEN_NOW, truth, OUT)
print(f"froze {len(truth)} cases -> {OUT}")
return 0
if __name__ == "__main__":
raise SystemExit(main())
+185
View File
@@ -0,0 +1,185 @@
#!/usr/bin/env python3
"""gen_model_registry_gap_truth.py — model_registry gap-closing truth
battery (dichotomy wave #2479 gap port).
Closes the PARTIAL audit gaps: to_dict, get_profile, get_enabled_profiles,
get_profiles_by_tier, list_profiles, test_registry (get_cheapest_capable
and resolve_context_budget existed; resolve's constants were WRONG in the
2026-10-09 Go port — toolReserve 2048 vs the oracle's TOOL_RESULT_RESERVE
1024 — and task_kind was missing entirely; the frozen rows pin the live
constants).
Uses the SHARED harness (scripts/freeze_truth.py) through the
scripts/mreg_freeze_seams rig (auto-imported sitecustomize that binds
JSON-safe seam_* wrappers onto the oracle module — registry methods
return ModelProfile dataclass instances, which the harness cannot
serialize). The oracle is PURE Python: no loader seam (RUNE pin vacuous),
no clock, no HOME — envelope frozen_now is conventional only.
Registry states ride as ORDERED [tier_key, profile_dict] PAIRS (dict
insertion order is load-bearing at three points: get_profile is a KEY
lookup while get_profiles_by_tier matches the tier ATTRIBUTE;
resolve_context_budget breaks on the FIRST id match; list_profiles
returns values in insertion order). Receiver-style truth is NOT possible
for this module — resolve_context_budget is module-level, so the shared
harness's fn(inst, ...) call would bind the instance to model_id; the
raw-receiver branch is pinned through a __new__ seam instead.
Regenerate + re-verify (byte-identical law — two runs, then verify):
PYTHONPATH=scripts/mreg_freeze_seams:src python3 scripts/gen_model_registry_gap_truth.py
PYTHONPATH=scripts/mreg_freeze_seams:src python3 scripts/freeze_truth.py \
--verify src/go/model-registry/truth_gap.json \
--module rune.model_registry
Usage: python3 scripts/gen_model_registry_gap_truth.py (from repo root)
"""
import sys
from pathlib import Path
REPO = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(REPO / "scripts"))
sys.path.insert(0, str(REPO / "src"))
from freeze_truth import freeze, write_envelope # noqa: E402 (shared harness)
FROZEN_NOW = "2026-10-14T09:00:00" # vacuous pin (clock-free oracle)
OUT = REPO / "src" / "go" / "model-registry" / "truth_gap.json"
# ── profile shapes (to_dict field order, all 11 fields explicit) ──────
T0FULL = {
"id": "deterministic", "provider": "local", "tier": "T0",
"local": True, "context_window": 0,
"supports_tools": False, "supports_structured_output": False,
"supports_reasoning_field": False,
"estimated_latency": "instant", "estimated_cost": "0", "enabled": True,
}
T1FULL = {
"id": "qwen2.5:3b", "provider": "ollama", "tier": "T1",
"local": True, "context_window": 32768,
"supports_tools": False, "supports_structured_output": False,
"supports_reasoning_field": False,
"estimated_latency": "low", "estimated_cost": "0", "enabled": True,
}
T2FULL = {
"id": "qwen3:14b", "provider": "ollama", "tier": "T2",
"local": True, "context_window": 32768,
"supports_tools": False, "supports_structured_output": False,
"supports_reasoning_field": False,
"estimated_latency": "medium", "estimated_cost": "0", "enabled": True,
}
T4FULL = {
"id": "mimo-v2.5-pro", "provider": "openai", "tier": "T4",
"local": False, "context_window": 128000,
"supports_tools": True, "supports_structured_output": True,
"supports_reasoning_field": True,
"estimated_latency": "higher", "estimated_cost": "paid",
"enabled": True,
}
def tweak(base, **kw):
p = dict(base)
p.update(kw)
return p
# ── custom registry states ([tier_key, profile_dict] pairs, ordered) ──
STATE_FLOOR = [["tiny", tweak(T4FULL, id="tiny-cloud", tier="T9",
context_window=1100,
estimated_latency="low")]]
STATE_DUP = [
["fake", tweak(T4FULL, local=True, provider="ollama", tier="T4",
context_window=32768, estimated_latency="medium")],
["real", T4FULL],
]
STATE_H = [["T1", T1FULL],
["X0", tweak(T0FULL, id="x0", context_window=4096, enabled=False,
estimated_latency="low")],
["T2", T2FULL]]
STATE_CROSS = [["K1", tweak(T1FULL, id="p1", tier="T9")]]
STATE_ODD = [["T4", T4FULL],
["TX", tweak(T2FULL, id="odd", tier="TX", supports_tools=True)]]
STATE_ODD_R = [["TX", tweak(T2FULL, id="odd", tier="TX", supports_tools=True)],
["T4", T4FULL]]
STATE_TIE = [["TA", tweak(T2FULL, id="first")], ["TB", tweak(T2FULL, id="second")]]
STATE_ALL_OFF = [["T1", tweak(T1FULL, enabled=False)],
["T2", tweak(T2FULL, enabled=False)]]
def main():
cases = []
# ── resolve_context_budget, registry=None (uses the default registry)
cases.append(("resolve_context_budget", ("",)))
cases.append(("resolve_context_budget", ("", "embed")))
cases.append(("resolve_context_budget", ("qwen2.5:3b", "verify")))
cases.append(("resolve_context_budget", ("qwen3:14b", "summarize")))
# THE KNOWN FLAG (model_connect agent, 2026-10-14): the old Go port
# hardcoded toolReserve=2048; the oracle holds 1024 (and the local
# flag, not the tier, gates it). These rows pin the live constants.
cases.append(("resolve_context_budget", ("mimo-v2.5-pro",)))
cases.append(("resolve_context_budget", ("mimo-v2.5-pro", "summarize")))
cases.append(("resolve_context_budget", ("mimo-v2.5-pro", "embed")))
# T0 window 0 → `context_window or 8192`
cases.append(("resolve_context_budget", ("deterministic",)))
# unknown task_kind → default reserve
cases.append(("resolve_context_budget", ("no-such-model", "weirdkind")))
# ── RAW registry (via __new__, no ctor fallback): empty profiles
# reaches the `(reg.profiles or {})` branch — the ctor cannot
# (its falsy dict falls back to DEFAULT_PROFILES)
cases.append(("seam_resolve_budget_raw", ([], "ghost", "verify")))
cases.append(("seam_resolve_budget_raw", (STATE_FLOOR, "tiny-cloud",
"default")))
# ── to_dict (both flag-poles of the profile table)
cases.append(("seam_to_dict", (T4FULL,)))
cases.append(("seam_to_dict", (T0FULL,)))
# ── get_profile: hit, miss, key≠attr (KEY lookup, not tier attr);
# falsy [] pairs → constructor falls back to DEFAULT_PROFILES
cases.append(("seam_get_profile", ([], "T1")))
cases.append(("seam_get_profile", ([], "TX")))
cases.append(("seam_get_profile", (STATE_CROSS, "T9")))
cases.append(("seam_get_profile", (STATE_CROSS, "K1")))
# ── get_enabled_profiles: default order; disabled skipped in place
cases.append(("seam_get_enabled_profiles", ([],)))
cases.append(("seam_get_enabled_profiles", (STATE_H,)))
# ── get_profiles_by_tier: attr match (not key), enabled-only
cases.append(("seam_get_profiles_by_tier", ([], "T2")))
cases.append(("seam_get_profiles_by_tier", (STATE_CROSS, "T9")))
cases.append(("seam_get_profiles_by_tier", (STATE_H, "T2")))
# ── get_cheapest_capable: flag gates, odd-tier sort fallback (5),
# STABLE tie, all-disabled → None
cases.append(("seam_get_cheapest_capable", ([], False, False, False)))
cases.append(("seam_get_cheapest_capable", ([], True, False, False)))
cases.append(("seam_get_cheapest_capable", ([], True, True, True)))
cases.append(("seam_get_cheapest_capable", (STATE_ODD, True, False, False)))
cases.append(("seam_get_cheapest_capable", (STATE_ODD_R, True, False, False)))
cases.append(("seam_get_cheapest_capable", (STATE_TIE, False, False, False)))
cases.append(("seam_get_cheapest_capable", (STATE_ALL_OFF, False, False, False)))
# ── list_profiles: insertion order of VALUES (not the key set)
cases.append(("seam_list_profiles", ([],)))
cases.append(("seam_list_profiles", (STATE_H,)))
# ── resolve through the seam (pairs path): falsy → DEFAULT ctor
# quirk; floor; duplicate-id first-match
cases.append(("seam_resolve_budget", ("qwen2.5:3b", "verify", [])))
cases.append(("seam_resolve_budget", ("tiny-cloud", "default", STATE_FLOOR)))
cases.append(("seam_resolve_budget", ("mimo-v2.5-pro", "default", STATE_DUP)))
# ── test_registry: stdout bytes + None result (asserts live here)
cases.append(("seam_test_registry", ()))
truth = freeze("rune.model_registry", cases, "rune.model_registry")
write_envelope(FROZEN_NOW, truth, OUT)
print(f"wrote {OUT} ({len(truth)} frozen cases)")
if __name__ == "__main__":
main()
+418
View File
@@ -0,0 +1,418 @@
#!/usr/bin/env python3
"""gen_mp_battery.py — ONE-SHOT generator: emit
src/go/model-profiles/frozen_battery_test.go with the frozen truth
(frozen_mp_truth.json) embedded VERBATIM (never hand-transcribed) plus
the dispatch harness. Re-run after any truth regeneration."""
import json
from pathlib import Path
REPO = Path(__file__).resolve().parents[1]
TRUTH = REPO / "src" / "go" / "model-profiles" / "frozen_mp_truth.json"
OUT = REPO / "src" / "go" / "model-profiles" / "frozen_battery_test.go"
HARNESS = r'''package main
// frozen_battery_test.go — gap-closing wave (#2479 dichotomy tranche):
// replays the shared-harness frozen oracle truth (generated by
// scripts/gen_model_profiles_truth.py via scripts/freeze_truth.py
// through the scripts/mp_freeze_seams rig, RUNE_FROZEN_NOW pinned)
// VERBATIM, in order, against the store seam repointed at a fresh temp
// dir. The case sequence is self-seeding: replaying it from an empty
// store regenerates every byte of expected state — exactly what
// PYTHONPATH=scripts/mp_freeze_seams:src python3 scripts/freeze_truth.py \
// --verify src/go/model-profiles/frozen_mp_truth.json \
// --module rune.model_profiles
// checks against the live oracle. (GENERATED by scripts/gen_mp_battery.py
// — do not hand-edit the truth const.)
//
// DIVERGENCE (documented, not a bug — the local_tool_runtime precedent):
// load_profile({"name": <non-string>}) is ACCEPTED by the Python oracle
// (dataclass __init__ performs no type checks) but REJECTED by the Go
// port (typed signature). No frozen row carries that shape.
import (
"encoding/json"
"fmt"
"net/http"
"net/http/httptest"
"os"
"path/filepath"
"reflect"
"strings"
"testing"
"time"
)
const frozenMpTruthJSON = `__TRUTH__`
func decodeMPArg(t *testing.T, raw json.RawMessage, dst any) {
t.Helper()
var v any
if err := json.Unmarshal(raw, &v); err != nil {
t.Fatalf("arg decode: %v", err)
}
if v == nil {
return // null → leave the zero value (None default)
}
if err := json.Unmarshal(raw, dst); err != nil {
t.Fatalf("arg re-decode: %v", err)
}
}
func profileToMap(p ModelProfile) map[string]any {
raw, err := json.Marshal(p)
if err != nil {
panic(err)
}
var m map[string]any
if err := json.Unmarshal(raw, &m); err != nil {
panic(err)
}
return m
}
func seedStore(t *testing.T, seed map[string]json.RawMessage) {
t.Helper()
if err := os.MkdirAll(profilesDir, 0o755); err != nil {
t.Fatal(err)
}
for name, raw := range seed {
var v any
if err := json.Unmarshal(raw, &v); err != nil {
t.Fatalf("seed decode: %v", err)
}
var data []byte
if s, ok := v.(string); ok {
data = []byte(s) // raw-text seed (corrupt-JSON floor)
} else {
data, _ = json.Marshal(v)
}
if err := os.WriteFile(filepath.Join(profilesDir, name), data, 0o644); err != nil {
t.Fatal(err)
}
}
}
func storeFiles() map[string]any {
out := map[string]any{}
entries, err := os.ReadDir(profilesDir)
if err != nil {
return out
}
for _, e := range entries {
if e.IsDir() || !strings.HasSuffix(e.Name(), ".json") {
continue
}
raw, err := os.ReadFile(filepath.Join(profilesDir, e.Name()))
if err != nil {
continue
}
var v any
if err := json.Unmarshal(raw, &v); err != nil {
continue
}
out[e.Name()] = v
}
return out
}
// dispatchFrozen — one frozen case against the ported surface. Stateful
// ops mirror the rig seams: wipe the store, seed from the args, run,
// return the JSON-native projection.
func dispatchFrozen(t *testing.T, fn string, args []json.RawMessage) any {
t.Helper()
arg := func(i int, dst any) { decodeMPArg(t, args[i], dst) }
argOpt := func(i int, dst any) {
if i < len(args) {
decodeMPArg(t, args[i], dst)
}
}
switch fn {
case "seam_get_profile_path":
var name string
arg(0, &name)
got := getProfilePath(name)
rel, err := filepath.Rel(profilesDir, got)
if err != nil {
t.Fatal(err)
}
// The frozen expectation carries the rig's absolute path; the
// contract is the sanitized FILE NAME (store root is the seam).
return filepath.Join("$STORE", rel)
case "seam_load_profile":
var name string
arg(0, &name)
var seed map[string]json.RawMessage
argOpt(1, &seed)
os.RemoveAll(profilesDir)
if seed != nil {
seedStore(t, seed)
}
if p, ok := loadProfile(name); ok {
return profileToMap(*p)
}
return nil
case "seam_save_profile":
var state map[string]json.RawMessage
arg(0, &state)
p := profileFromState(t, state)
os.RemoveAll(profilesDir)
saveProfile(p)
raw, err := os.ReadFile(getProfilePath(p.Name))
if err != nil {
t.Fatalf("save wrote nothing: %v", err)
}
return map[string]any{"raw": string(raw), "parsed": storeFiles()}
case "seam_build_profile_from_ollama":
var name string
arg(0, &name)
var info map[string]any
arg(1, &info)
return profileToMap(buildProfileFromOllama(name, info))
case "seam_scan_all_models":
var fixture any
arg(0, &fixture)
var seed map[string]json.RawMessage
argOpt(1, &seed)
os.RemoveAll(profilesDir)
if seed != nil {
seedStore(t, seed)
}
saved := ollamaURL
var srv *httptest.Server
if s, ok := fixture.(string); ok && s == "dead" {
ollamaURL = "http://127.0.0.1:1"
} else {
payload, _ := json.Marshal(fixture)
srv = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
_, _ = w.Write(payload)
}))
ollamaURL = srv.URL
}
profiles := scanAllModels()
ollamaURL = saved
if srv != nil {
srv.Close()
}
out := make([]any, len(profiles))
for i, p := range profiles {
out[i] = profileToMap(p)
}
return map[string]any{"profiles": out, "files": storeFiles()}
case "seam_get_or_create_profile":
var name string
arg(0, &name)
var seed map[string]json.RawMessage
argOpt(1, &seed)
os.RemoveAll(profilesDir)
if seed != nil {
seedStore(t, seed)
}
p := getOrCreateProfile(name)
return map[string]any{"profile": profileToMap(p), "files": storeFiles()}
case "seam_record_interaction":
var name string
arg(0, &name)
var outcomes [][]any
arg(1, &outcomes)
var seed map[string]json.RawMessage
argOpt(2, &seed)
os.RemoveAll(profilesDir)
if seed != nil {
seedStore(t, seed)
}
for _, oc := range outcomes {
success, _ := oc[0].(bool)
topic, _ := oc[1].(string)
recordInteraction(name, success, topic)
}
return storeFiles()
case "seam_get_prompt_context":
var name string
arg(0, &name)
var seed map[string]json.RawMessage
argOpt(1, &seed)
os.RemoveAll(profilesDir)
if seed != nil {
seedStore(t, seed)
}
return getPromptContext(name)
case "seam_to_dict":
var state map[string]json.RawMessage
arg(0, &state)
return profileToMap(profileFromState(t, state))
case "seam_from_dict":
var data map[string]json.RawMessage
arg(0, &data)
return profileToMap(profileFromState(t, data))
default:
t.Fatalf("frozen case names unknown fn %q", fn)
return nil
}
}
// profileFromState rebuilds a ModelProfile from a from_dict-shaped doc
// (unknown keys filtered, absent keys defaulted — the oracle lens).
func profileFromState(t *testing.T, state map[string]json.RawMessage) ModelProfile {
t.Helper()
p := defaultModelProfile("")
get := func(key string) (json.RawMessage, bool) {
raw, ok := state[key]
return raw, ok
}
if raw, ok := get("name"); ok {
if err := json.Unmarshal(raw, &p.Name); err != nil {
t.Fatalf("state name: %v", err)
}
}
strField := func(key string, dst *string) {
if raw, ok := get(key); ok {
if err := json.Unmarshal(raw, dst); err != nil {
t.Fatalf("state %s: %v", key, err)
}
}
}
strField("display_name", &p.DisplayName)
strField("family", &p.Family)
strField("parameters", &p.Parameters)
strField("quantization", &p.Quantization)
strField("thinking_format", &p.ThinkingFormat)
strField("response_style", &p.ResponseStyle)
strField("last_used", &p.LastUsed)
strField("created", &p.Created)
numField := func(key string, dst *float64) {
if raw, ok := get(key); ok {
var n json.Number
if err := json.Unmarshal(raw, &n); err != nil {
t.Fatalf("state %s: %v", key, err)
}
f, err := n.Float64()
if err != nil {
t.Fatalf("state %s: %v", key, err)
}
*dst = f
}
}
intField := func(key string, dst *int) {
if raw, ok := get(key); ok {
var n json.Number
if err := json.Unmarshal(raw, &n); err != nil {
t.Fatalf("state %s: %v", key, err)
}
i, err := n.Int64()
if err != nil {
t.Fatalf("state %s: %v", key, err)
}
*dst = int(i)
}
}
var f float64
numField("size_gb", &f)
p.SizeGB = f
numField("optimal_temperature", &p.OptimalTemperature)
intField("safety_tier", &p.SafetyTier)
intField("context_window", &p.ContextWindow)
intField("interactions", &p.Interactions)
intField("successes", &p.Successes)
intField("failures", &p.Failures)
listField := func(key string, dst *[]string) {
if raw, ok := get(key); ok {
var l []string
if err := json.Unmarshal(raw, &l); err != nil {
t.Fatalf("state %s: %v", key, err)
}
if l == nil {
l = []string{}
}
*dst = l
}
}
listField("strengths", &p.Strengths)
listField("weaknesses", &p.Weaknesses)
listField("prompting_tips", &p.PromptingTips)
listField("known_refusal_topics", &p.KnownRefusalTopics)
return p
}
// normalizeExpected rewrites the rig-rooted absolute paths the frozen
// expectations carry into the $STORE placeholder (the store root is the
// seam — only the sanitized file name is contractual).
func normalizeExpected(v any) any {
switch x := v.(type) {
case string:
if strings.Contains(x, ".rune/model_profiles/") {
parts := strings.Split(x, ".rune/model_profiles/")
return filepath.Join("$STORE", parts[len(parts)-1])
}
return x
case map[string]any:
for k, e := range x {
x[k] = normalizeExpected(e)
}
return x
case []any:
for i, e := range x {
x[i] = normalizeExpected(e)
}
return x
default:
return v
}
}
func TestFrozenBattery(t *testing.T) {
setProfilesDir(filepath.Join(t.TempDir(), ".rune", "model_profiles"))
savedNow := nowUTC
nowUTC = func() time.Time {
return time.Date(2026, 10, 13, 9, 41, 23, 123456000, time.UTC)
}
defer func() { nowUTC = savedNow }()
var envelope struct {
FrozenNow string `json:"frozen_now"`
Cases []struct {
Fn string `json:"fn"`
Args []json.RawMessage `json:"args"`
Kwargs map[string]any `json:"kwargs"`
Expected any `json:"expected"`
} `json:"cases"`
}
if err := json.Unmarshal([]byte(frozenMpTruthJSON), &envelope); err != nil {
t.Fatalf("frozen truth malformed: %v", err)
}
for i, c := range envelope.Cases {
if len(c.Kwargs) != 0 {
t.Fatalf("case %d %s: unexpected kwargs %v", i, c.Fn, c.Kwargs)
}
got := dispatchFrozen(t, c.Fn, c.Args)
raw, err := json.Marshal(got)
if err != nil {
t.Fatalf("case %d %s: marshal got: %v", i, c.Fn, err)
}
var gotAny any
if err := json.Unmarshal(raw, &gotAny); err != nil {
t.Fatalf("case %d %s: reparse: %v", i, c.Fn, err)
}
wantAny := normalizeExpected(c.Expected)
if !reflect.DeepEqual(gotAny, wantAny) {
gj, _ := json.Marshal(gotAny)
ej, _ := json.Marshal(wantAny)
t.Errorf("case %d %s:\n got %s\n want %s", i, c.Fn, gj, ej)
}
}
fmt.Printf("replayed %d frozen cases\n", len(envelope.Cases))
}
'''
def main() -> int:
truth = TRUTH.read_text()
assert truth.endswith("\n"), "truth file must end with newline"
body = HARNESS.replace("__TRUTH__", truth.rstrip("\n"))
OUT.write_text(body)
print(f"wrote {OUT} ({len(body)} bytes)")
return 0
if __name__ == "__main__":
raise SystemExit(main())
Loaded 100 of 901 files, more files were not shown because too many files have changed in this diff. Show more