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.
This commit is contained in:
1 parent
f07d8f3843
commit
71a7c05336
3 files changed
+5924
-18
No files matched your search
@@ -68,12 +68,35 @@ func detectFlags(bodyLower string) ([]string, []string) {
|
||||
|
||||
// ── Domain (parity with adaptive_router.py) ────────────────────────────────
|
||||
|
||||
var ROUTES = map[string]bool{"LOCAL_FIX": true, "STANDARD_CHANGE": true, "RESEARCHED_CHANGE": true}
|
||||
// Route — the three route values as a distinct type: route comparisons
|
||||
// compile against named constants instead of bare string literals (a
|
||||
// typo'd route is a compile error at every use site).
|
||||
type Route string
|
||||
|
||||
const (
|
||||
RouteLocalFix Route = "LOCAL_FIX"
|
||||
RouteStandard Route = "STANDARD_CHANGE"
|
||||
RouteResearched Route = "RESEARCHED_CHANGE"
|
||||
verifiabilityNone = "NONE"
|
||||
)
|
||||
|
||||
var ROUTES = map[Route]bool{RouteLocalFix: true, RouteStandard: true, RouteResearched: true}
|
||||
|
||||
var FLOOR_RISK_FLAGS = []string{"new_authority", "architecture_change", "data_loss_risk", "external_service", "memory_architecture"}
|
||||
var FLOOR_UNCERTAINTY_FLAGS = []string{"competing_designs", "expensive_reversal"}
|
||||
var FLOOR_EXPLICIT_MARKERS = []string{"new subsystem", "new epic", "major external", "adopt", "replacement", "architecture research"}
|
||||
|
||||
// floorRiskSet / floorUncertaintySet — O(1) membership for the floor
|
||||
// vocabulary (Phase B: the slice scans were O(n) per flag per call).
|
||||
var floorRiskSet = map[string]bool{
|
||||
"new_authority": true, "architecture_change": true, "data_loss_risk": true,
|
||||
"external_service": true, "memory_architecture": true,
|
||||
}
|
||||
|
||||
var floorUncertaintySet = map[string]bool{
|
||||
"competing_designs": true, "expensive_reversal": true,
|
||||
}
|
||||
|
||||
var ErrFloorViolation = errors.New("FloorViolation: a downgrade was attempted on a route protected by the research floor")
|
||||
|
||||
type SufficiencyInputs struct {
|
||||
@@ -148,12 +171,12 @@ func pyBool(b bool) string {
|
||||
|
||||
func FloorAppliesFromFlags(risk, uncertainty []string, bodyLower string) bool {
|
||||
for _, f := range risk {
|
||||
if contains(FLOOR_RISK_FLAGS, f) {
|
||||
if floorRiskSet[f] {
|
||||
return true
|
||||
}
|
||||
}
|
||||
for _, f := range uncertainty {
|
||||
if contains(FLOOR_UNCERTAINTY_FLAGS, f) {
|
||||
if floorUncertaintySet[f] {
|
||||
return true
|
||||
}
|
||||
}
|
||||
@@ -166,14 +189,14 @@ func FloorAppliesFromFlags(risk, uncertainty []string, bodyLower string) bool {
|
||||
}
|
||||
|
||||
func FloorReason(risk, uncertainty []string, bodyLower string) string {
|
||||
var hits []string
|
||||
hits := make([]string, 0, 3)
|
||||
for _, f := range risk {
|
||||
if contains(FLOOR_RISK_FLAGS, f) {
|
||||
if floorRiskSet[f] {
|
||||
hits = append(hits, f)
|
||||
}
|
||||
}
|
||||
for _, f := range uncertainty {
|
||||
if contains(FLOOR_UNCERTAINTY_FLAGS, f) {
|
||||
if floorUncertaintySet[f] {
|
||||
hits = append(hits, f)
|
||||
}
|
||||
}
|
||||
@@ -190,11 +213,11 @@ func FloorReason(risk, uncertainty []string, bodyLower string) string {
|
||||
|
||||
// FloorApplies — public floor predicate (canary 5).
|
||||
func FloorApplies(route string, flags []string) bool {
|
||||
if route != "RESEARCHED_CHANGE" {
|
||||
if route != string(RouteResearched) {
|
||||
return false
|
||||
}
|
||||
for _, f := range flags {
|
||||
if contains(FLOOR_RISK_FLAGS, f) || contains(FLOOR_UNCERTAINTY_FLAGS, f) {
|
||||
if floorRiskSet[f] || floorUncertaintySet[f] {
|
||||
return true
|
||||
}
|
||||
}
|
||||
@@ -257,7 +280,11 @@ func ClassifyRoute(in ClassifyInput) RouteDecision {
|
||||
if _, legacy := prov["legacy_inputs"]; legacy {
|
||||
unknowns = nil // legacy path: boolean conditions own the decision
|
||||
}
|
||||
floor := FloorAppliesFromFlags(risk, uncertainty, bodyLower)
|
||||
// Single-pass floor (Phase B): compute the reason hits once; the floor
|
||||
// bool is exactly "hits nonempty" — the same union the oracle's
|
||||
// _floor_applies_from_flags short-circuits over, in one walk.
|
||||
floorReason := FloorReason(risk, uncertainty, bodyLower)
|
||||
floor := floorReason != "unclassified"
|
||||
|
||||
if len(unknowns) > 0 {
|
||||
reasons = append(reasons, "material unknowns present: "+strings.Join(unknowns, ", "))
|
||||
@@ -273,15 +300,15 @@ func ClassifyRoute(in ClassifyInput) RouteDecision {
|
||||
}
|
||||
}
|
||||
localOK := in.HasLocalRepro && in.OwningAuthorityKnown &&
|
||||
(in.TestableLocally || (in.NarrowAndReversible && suff.Verifiability == "NONE"))
|
||||
(in.TestableLocally || (in.NarrowAndReversible && suff.Verifiability == verifiabilityNone))
|
||||
if localOK && isDefectRoute && len(risk) == 0 && len(uncertainty) == 0 && len(unknowns) == 0 && !floor {
|
||||
reasons = append(reasons, "all LOCAL_FIX conditions met; no unknowns; no floor")
|
||||
return makeDecision("LOCAL_FIX", reasons, risk, uncertainty, suff, unknowns, "HIGH", in.Body, in.PipelineSHA, false)
|
||||
return makeDecision(string(RouteLocalFix), reasons, risk, uncertainty, suff, unknowns, "HIGH", in.Body, in.PipelineSHA, false)
|
||||
}
|
||||
|
||||
if floor {
|
||||
reasons = append(reasons, "deep-research floor: "+FloorReason(risk, uncertainty, bodyLower))
|
||||
return makeDecision("RESEARCHED_CHANGE", reasons, risk, uncertainty, suff, unknowns, "HIGH", in.Body, in.PipelineSHA, true)
|
||||
reasons = append(reasons, "deep-research floor: "+floorReason)
|
||||
return makeDecision(string(RouteResearched), reasons, risk, uncertainty, suff, unknowns, "HIGH", in.Body, in.PipelineSHA, true)
|
||||
}
|
||||
|
||||
if len(risk) > 0 || len(uncertainty) > 0 || len(unknowns) > 0 {
|
||||
@@ -290,11 +317,11 @@ func ClassifyRoute(in ClassifyInput) RouteDecision {
|
||||
reasons = append(reasons, "risk/uncertainty flags: "+strings.Join(both, ", "))
|
||||
}
|
||||
reasons = append(reasons, "RESEARCHED_CHANGE: external evidence and adversarial validation justified")
|
||||
return makeDecision("RESEARCHED_CHANGE", reasons, risk, uncertainty, suff, unknowns, "HIGH", in.Body, in.PipelineSHA, floor)
|
||||
return makeDecision(string(RouteResearched), reasons, risk, uncertainty, suff, unknowns, "HIGH", in.Body, in.PipelineSHA, floor)
|
||||
}
|
||||
|
||||
reasons = append(reasons, "clear change, existing authority, no consequential selection")
|
||||
return makeDecision("STANDARD_CHANGE", reasons, risk, uncertainty, suff, unknowns, "MEDIUM", in.Body, in.PipelineSHA, false)
|
||||
return makeDecision(string(RouteStandard), reasons, risk, uncertainty, suff, unknowns, "MEDIUM", in.Body, in.PipelineSHA, false)
|
||||
}
|
||||
|
||||
func makeDecision(route string, reasons []string, risk, uncertainty []string, suff *SufficiencyInputs, unknowns []string, confidence, task, sha string, floor bool) RouteDecision {
|
||||
@@ -329,7 +356,7 @@ func makeDecision(route string, reasons []string, risk, uncertainty []string, su
|
||||
// ── Escalation / downgrade ─────────────────────────────────────────────────
|
||||
|
||||
func escalateRoute(d RouteDecision, newRoute, trigger, evidence string, logPath string) (RouteDecision, error) {
|
||||
if !ROUTES[newRoute] {
|
||||
if !ROUTES[Route(newRoute)] {
|
||||
return RouteDecision{}, fmt.Errorf("invalid route: %s", newRoute)
|
||||
}
|
||||
up := RouteDecision{
|
||||
@@ -349,10 +376,10 @@ func escalateRoute(d RouteDecision, newRoute, trigger, evidence string, logPath
|
||||
}
|
||||
|
||||
func downgradeRoute(d RouteDecision, newRoute, trigger, evidence string, logPath string) (RouteDecision, error) {
|
||||
if !ROUTES[newRoute] {
|
||||
if !ROUTES[Route(newRoute)] {
|
||||
return RouteDecision{}, fmt.Errorf("invalid route: %s", newRoute)
|
||||
}
|
||||
if d.Floor && newRoute != "RESEARCHED_CHANGE" {
|
||||
if d.Floor && Route(newRoute) != RouteResearched {
|
||||
return RouteDecision{}, ErrFloorViolation
|
||||
}
|
||||
down := RouteDecision{
|
||||
|
||||
+5875
File diff suppressed because it is too large.
Load diff
@@ -6581,3 +6581,7 @@
|
||||
{"builder": "factory-gap-vs", "detail": "BUILDER-2026-10-14T05:29:33Z-a69ece-factory-gap-vs \u2192 building", "kind": "builder_session", "mode": "rune_internal", "observed_at": "2026-10-14T05:30:09Z", "operation": "transition"}
|
||||
{"builder": "factory-gap-vs", "detail": "BUILDER-2026-10-14T05:29:33Z-a69ece-factory-gap-vs \u2192 verifying", "kind": "builder_session", "mode": "rune_internal", "observed_at": "2026-10-14T05:30:24Z", "operation": "transition"}
|
||||
{"builder": "factory-gap-vs", "detail": "BUILDER-2026-10-14T05:29:33Z-a69ece-factory-gap-vs closed", "kind": "builder_session", "mode": "rune_internal", "observed_at": "2026-10-14T05:30:42Z", "operation": "close"}
|
||||
{"builder": "factory-gap-ar", "detail": "need-2026-10-14T09:00:06Z-factory-gap-ar \u2192 REUSE", "kind": "builder_session", "mode": "rune_internal", "observed_at": "2026-10-14T09:00:07Z", "operation": "submit_need"}
|
||||
{"builder": "factory-gap-ar", "detail": "BUILDER-2026-10-14T09:00:07Z-70ebf0-factory-gap-ar \u2192 approved", "kind": "builder_session", "mode": "rune_internal", "observed_at": "2026-10-14T09:00:30Z", "operation": "transition"}
|
||||
{"builder": "factory-gap-ar", "detail": "BUILDER-2026-10-14T09:00:07Z-70ebf0-factory-gap-ar \u2192 building", "kind": "builder_session", "mode": "rune_internal", "observed_at": "2026-10-14T09:00:53Z", "operation": "transition"}
|
||||
{"builder": "factory-gap-ar", "detail": "BUILDER-2026-10-14T09:00:07Z-70ebf0-factory-gap-ar \u2192 verifying", "kind": "builder_session", "mode": "rune_internal", "observed_at": "2026-10-14T09:01:16Z", "operation": "transition"}
|
||||
Reference in new issue
Block a user