feat(deltawire): representation optimizer (Stage 2) + pre-materialization safety gate - #128
Merged
Merged
Conversation
…ization safety gate Add a deterministic representation-selection layer that decides whether DeltaWire applies, which semantic representation fits, and which transport is cheapest — then hands a safe spec to the unchanged supervisor. - internal/optimizer: feature vector, candidate enumeration, Pareto frontier, and a metric-driven selector emitting recommend/optional/not_recommended/ abstain with reason codes, selection_blocking, and failure_class. Python is modeled as a policy-excluded comparison class (unsafe_program), never selected and never given fabricated metrics. - directspec: transport-agnostic LoadJSON/LoadTyped sharing one canonicalize+SHA tail so YAML, canonical JSON, compact JSON, and typed args normalize identically. - directspec.Preflight: enforced pre-materialization cardinality/output/plan/ overflow safety gate, wired into the supervise compile path before expansion (closes GAPS #4). Supervisor stays strategy-neutral. - cli: new 'deltawire optimize' subcommand (json/markdown). Tests: 14 canonical cases, 105 deterministic mutation failures, transport & semantic equivalence, repeated-byte determinism; zero model/provider calls.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds DeltaWire's missing Stage 2 layer (per
eval/docs/11-direct-optimal-spec-research-plan.md, GAPS.md #4 and #10): a deterministic representation-selection system. Given a direct spec it computes a feature vector, enumerates candidate semantic representations × transports, computes a Pareto frontier, and emits a deterministic recommendation with reason codes — then hands a safe spec to the unchanged supervisor.DeltaWire stops being merely a format: it can now say "this is a high-fit finite relationship, use direct YAML" — or "this is trivial / irregular / structurally unsafe, do not use DeltaWire."
Architecture
Three concerns are kept strictly separated:
internal/optimizer):recommended/optional/not_recommendedare non-blocking;abstainis blocking (selection_blocking: true).directspec.Preflight, enforced in the compile path): pre-materialization cardinality/output/plan/overflow bounds; hard failure →abstain+failure_class: resource_bound_exceeded.internal/supervisor, untouched): only ever receives an already-selected admissible candidate. Recommendation is never encoded as FSM events.What changed
internal/optimizer/(new)features,candidates,pareto,select,transport— feature vector, candidate metrics, non-dominated frontier (no weighted score), metric-driven selectorinternal/directspec/guard.go(new)Cardinality, single-recordEstimateOutputBytes, and the enforcedPreflightsafety gateinternal/directspec/parser.goLoadJSON+LoadTypedshare onefinalize(validate → canonicalize → SHA) tail so all transports normalize identicallyinternal/cli/supervise.goPreflightwired in beforeCompile— rejects oversized/unbounded specs before any row expansion (closes GAPS #4)internal/cli/optimize.go(new)deltawire optimize <spec> [--format markdown]Design decisions (confirmed)
unsafe_programwithimplemented:false,policy_admissible:false,arbitrary_code:true, reason codesnot_implemented/unsafe_program_disallowed/outside_generation_boundary. Never generated, executed, or selected. Byte metrics are null, never fabricated. No-executable-code invariant intact.Applicability — outcomes emerge from metrics (case names never hard-coded)
recommendedoptionaloptionalornot_recommended(by amplification)not_recommendedabstainabstain+resource_bound_exceededVerification — all gates pass
go test ./...,-race,-count=20,go vet— passbash scripts/validate.sh→ EXIT 0 (clean state),git diff --checkcleanExample (
deltawire optimize, range-piecewise, 300 records):{"decision":"recommended","selection_blocking":false, "selected_form":"direct_relation","selected_transport":"compact_json", "reason_codes":["regular_finite_relation","high_amplification","piecewise_conditional"]}Note (pre-existing, not from this PR)
A second consecutive
scripts/validate.shrun tripseval/scripts/v8/validate.py:build_and_manifest.shstages a freshly-built (gitignored) linux binary, but the script checks it against a pin (e5198d15…) frozen to older code — which even a cleanmainbuild (3a4f2f17…) no longer matches. A clean single run (as CI does) passes. The frozen evidence pin was intentionally left untouched.