mirror of
https://github.com/priyanshujain/sanderling.git
synced 2026-10-02 11:07:10 +00:00
fix ltl semantics and unify action enumeration (#71)
* fix(ltl): give every thunk a construction identity Two distinct unnamed predicates both described as "Thunk(...)", so obligation collapse merged their residuals and could drop a live violation. Identity is assigned at construction and the fields are unexported, so a thunk cannot be built without one. Claude-Session: https://claude.ai/code/session_01Fj4wJUikdABuMQEETwW55J * fix(ltl): reduce a thrown-predicate residual instead of panicking The verifier substitutes an ErrorFormula for the residual of a property whose predicate threw, and that residual is fed back in on the next step. reduce had no case for it, so the run crashed. It re-reports the same failure now. Claude-Session: https://claude.ai/code/session_01Fj4wJUikdABuMQEETwW55J * fix(ltl): make a bounded always the dual of a bounded eventually G<=n(f) and not F<=n(not f) disagreed on traces where the inner was still pending when the window closed, so nnf's negation normal form was not semantics preserving. Both sides now range over the observations at which their inner can definitely resolve: the eventually keeps a pending inner as a disjunct, and the always discharges vacuously at window close. Claude-Session: https://claude.ai/code/session_01Fj4wJUikdABuMQEETwW55J * fix(ltl): arm a one-shot root once per run A root that carries its own horizon is one obligation for the whole run, not one per observation. Re-instantiating a top-level eventually monitored G F<=n(p) instead of F<=n(p) and left one live obligation per step behind; a bounded always restarted its window every step and never closed. Claude-Session: https://claude.ai/code/session_01Fj4wJUikdABuMQEETwW55J * fix(verifier): stop wrapping a top-level eventually in always `eventually(p).within(300, "seconds")` as a property meant "within 300 seconds of every step", which spawned an obligation per step with its own resolved deadline. A 553-step run carried 553 of them and serialized a 75 KB residual. Claude-Session: https://claude.ai/code/session_01Fj4wJUikdABuMQEETwW55J * fix(ltl): serialize the resolved deadline of a bounded window Two obligations spawned at different steps from one duration-bounded formula differ only in the deadline the evaluator resolved for them, so they serialized identically and the trace erased a distinction the evaluator makes. The authored window stays in amount/unit; the resolved deadline rides alongside. Claude-Session: https://claude.ai/code/session_01Fj4wJUikdABuMQEETwW55J * fix(verifier): split a witness's origin step from its detection step A deferred obligation spans two steps: the one that armed it and the one whose reduction failed. They were conflated under one index, so the extractor snapshot (which is the detecting step's state) was reported against the origin step. Claude-Session: https://claude.ai/code/session_01Fj4wJUikdABuMQEETwW55J * fix(runner): record a witness's detection step in the trace Claude-Session: https://claude.ai/code/session_01Fj4wJUikdABuMQEETwW55J * feat(replay-ui): show the step a violation was detected at The witness evidence is the detecting step's state, so say which step that is and let a reader jump to it. Claude-Session: https://claude.ai/code/session_01Fj4wJUikdABuMQEETwW55J * fix(verifier): record the extractor state the predicates actually read On the web path extractor bodies are evaluated in V8 and injected here, but only the goja value was replaced. The trace diff and the violation witness therefore described a state no property ever saw. Claude-Session: https://claude.ai/code/session_01Fj4wJUikdABuMQEETwW55J * refactor(spec): one candidate producer over one target-eligibility rule Both hosts routed verbs themselves and both policies enumerated their own actions, and all four drifted. Web sent `swipes` to scrollable containers only, so swipe-to-dismiss on a list row was reachable on native and unreachable on web; the model policy folded gestures its own way and could not reach what the seeded picker drew. A host now reports facts about every element and never decides which verb may act on it: targets.ts acceptsTarget owns that for both. pick.ts builtinCandidates is the single enumeration, and the model policy reads it through __sanderlingEnumerateBuiltin__ instead of reimplementing it in Go. Gesture verbs change with it: scrolls stay vertical over scrollable containers, swipes go free-form in all four directions from any element with real bounds. Claude-Session: https://claude.ai/code/session_01Fj4wJUikdABuMQEETwW55J * fix(runner): name a builtin scroll by its drag origin A builtin gesture carries endpoints and no selector, so every scroll rendered as "Scroll down " in the prompt's recent-action memory and two scrollable regions were indistinguishable. Claude-Session: https://claude.ai/code/session_01Fj4wJUikdABuMQEETwW55J * fix(chrome): clear storage over cdp instead of scripting an opaque origin Launch runs while the tab is still on about:blank, whose opaque origin denies storage access, so localStorage.clear() threw SecurityError and every web run died at launch. Storage.clearDataForOrigin needs no navigation. The exception helper lands here because "Uncaught" is what hid this for so long. Claude-Session: https://claude.ai/code/session_01Fj4wJUikdABuMQEETwW55J * fix(chrome): enable the swiftshader webgl fallback Headless Chrome runs with --disable-gpu, and without this flag it refuses the software WebGL backend: getContext returns null, so a canvas-rendered app paints nothing and every screenshot is identical black. Claude-Session: https://claude.ai/code/session_01Fj4wJUikdABuMQEETwW55J * fix(web): resolve testTag through data-testid or id Compose Multiplatform emits its testTag into the element id, which the native table already accepts via the resource-id alias. The two web selector tables were the only place that rejected it. Claude-Session: https://claude.ai/code/session_01Fj4wJUikdABuMQEETwW55J * test(spec): type-check the spec api as part of make test The fake runtime in api.test.ts did not return a chainable handle from extract, so the file had not type-checked since named() was added. Wiring the check into make test stops it drifting again. Claude-Session: https://claude.ai/code/session_01Fj4wJUikdABuMQEETwW55J * docs(manual): one-shot eventually and the gesture verbs Claude-Session: https://claude.ai/code/session_01Fj4wJUikdABuMQEETwW55J
This commit is contained in:
48 files changed
+2604
-712
No files matched your search
+85
-24
@@ -37,6 +37,10 @@ type Evaluator struct {
|
||||
violated bool
|
||||
steps int
|
||||
violation *Violation
|
||||
// oneShot marks a root that is armed once at the first observation rather
|
||||
// than re-asserted at every one; armed records that it has been.
|
||||
oneShot bool
|
||||
armed bool
|
||||
}
|
||||
|
||||
// obligation pairs a residual formula with the step that spawned it, so a
|
||||
@@ -62,7 +66,8 @@ type Violation struct {
|
||||
}
|
||||
|
||||
func NewEvaluator(formula Formula) *Evaluator {
|
||||
return &Evaluator{root: nnf(formula)}
|
||||
normalized := nnf(formula)
|
||||
return &Evaluator{root: normalized, oneShot: isOneShotRoot(normalized)}
|
||||
}
|
||||
|
||||
// Observe evaluates the formula against the current state and returns the
|
||||
@@ -89,8 +94,11 @@ func (e *Evaluator) ObserveAtStep(now time.Time, step int) Verdict {
|
||||
}
|
||||
e.steps = step
|
||||
|
||||
fresh := obligation{formula: rootObligation(e.root), origin: step}
|
||||
obligations := append(e.pending, fresh)
|
||||
obligations := make([]obligation, 0, len(e.pending)+1)
|
||||
obligations = append(obligations, e.pending...)
|
||||
if formula, ok := e.instantiateRoot(); ok {
|
||||
obligations = append(obligations, obligation{formula: formula, origin: step})
|
||||
}
|
||||
e.pending = e.pending[:0]
|
||||
|
||||
for _, entry := range obligations {
|
||||
@@ -121,8 +129,11 @@ func (e *Evaluator) ObserveAtStep(now time.Time, step int) Verdict {
|
||||
|
||||
// collapse removes structurally-identical obligations, keeping the first
|
||||
// occurrence in order so the surviving entry carries the earliest origin step.
|
||||
// Distinct predicates never merge because ThunkFormula's name participates in
|
||||
// its describe() key, so deduping cannot hide a violation.
|
||||
// Equal describe() keys mean the same operators over the same predicates with
|
||||
// the same remaining bounds, so the merged obligations reduce identically on
|
||||
// every future and dropping one cannot hide a violation. Distinct predicates
|
||||
// never merge because every thunk's construction-time identity is part of its
|
||||
// key, whether or not the caller named it.
|
||||
func collapse(obligations []obligation) []obligation {
|
||||
if len(obligations) < 2 {
|
||||
return obligations
|
||||
@@ -264,10 +275,48 @@ func (e *Evaluator) Residual() Formula {
|
||||
return combined
|
||||
}
|
||||
|
||||
// rootObligation returns the formula to instantiate at each step. An outer
|
||||
// Always is stripped so its inner is re-evaluated every step; any other root
|
||||
// formula is itself re-instantiated each step (matching the v0.1 semantics
|
||||
// where a bare Thunk is re-observed on every call).
|
||||
// instantiateRoot returns the obligation to register for this observation, and
|
||||
// whether there is one at all. A one-shot root is armed only at the first
|
||||
// observation; a recurring root is re-asserted at every one.
|
||||
func (e *Evaluator) instantiateRoot() (Formula, bool) {
|
||||
if !e.oneShot {
|
||||
return rootObligation(e.root), true
|
||||
}
|
||||
if e.armed {
|
||||
return nil, false
|
||||
}
|
||||
e.armed = true
|
||||
return e.root, true
|
||||
}
|
||||
|
||||
// isOneShotRoot reports whether a root formula is a single obligation for the
|
||||
// whole run rather than one instance per observation.
|
||||
//
|
||||
// A root that carries its own horizon is one-shot: an eventually is a
|
||||
// reachability goal ("this happens at some point"), and a bounded always is a
|
||||
// single window. Re-instantiating either at every step would monitor a
|
||||
// different property -- G F<=n(p) instead of F<=n(p), and G(p) instead of
|
||||
// G<=n(p), the latter because a re-instantiated window restarts and never
|
||||
// closes -- and would leave one live obligation per step behind.
|
||||
//
|
||||
// Every other root keeps the implicit-always reading: an unbounded always
|
||||
// re-instantiates its inner (which is what gives each instance its own origin
|
||||
// step), and a bare predicate or connective is re-asserted each observation.
|
||||
func isOneShotRoot(root Formula) bool {
|
||||
switch concrete := root.(type) {
|
||||
case EventuallyFormula:
|
||||
return true
|
||||
case AlwaysFormula:
|
||||
return concrete.HasStepBound || concrete.HasDeadline || concrete.Duration > 0
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// rootObligation returns the formula a recurring root instantiates at each
|
||||
// step. An outer Always is stripped so its inner is re-evaluated every step;
|
||||
// any other root formula is itself re-instantiated each step (matching the
|
||||
// v0.1 semantics where a bare Thunk is re-observed on every call).
|
||||
func rootObligation(root Formula) Formula {
|
||||
if always, ok := root.(AlwaysFormula); ok {
|
||||
return always.Inner
|
||||
@@ -333,8 +382,14 @@ func reduce(formula Formula, now time.Time) reduceResult {
|
||||
}
|
||||
return violatedWith(concrete, "pure false")
|
||||
|
||||
case ErrorFormula:
|
||||
// A thrown predicate substituted into a residual at the trace
|
||||
// boundary. Reducing it re-reports the same failure rather than
|
||||
// crashing the run.
|
||||
return violatedByError(concrete, concrete.Message)
|
||||
|
||||
case ThunkFormula:
|
||||
result, err := concrete.Func()
|
||||
result, err := concrete.predicate()
|
||||
if err != nil {
|
||||
return violatedByError(concrete, err.Error())
|
||||
}
|
||||
@@ -363,6 +418,9 @@ func reduce(formula Formula, now time.Time) reduceResult {
|
||||
if innerResult.status == statusHolds {
|
||||
return holds()
|
||||
}
|
||||
// The window is measured in observations at which the inner could have
|
||||
// discharged, so an inner that is merely pending has not discharged and
|
||||
// the window closing on it is a violation.
|
||||
if concrete.HasStepBound && concrete.StepBound <= 1 {
|
||||
return violatedFrom(innerResult, concrete, "eventually bound exhausted")
|
||||
}
|
||||
@@ -373,6 +431,14 @@ func reduce(formula Formula, now time.Time) reduceResult {
|
||||
if concrete.HasStepBound {
|
||||
next.StepBound = concrete.StepBound - 1
|
||||
}
|
||||
// F(inner) unrolls to inner or X F(inner). A pending inner is a
|
||||
// deferred way of satisfying the promise, so it is kept as a disjunct
|
||||
// rather than dropped; dropping it is what made an inner that only
|
||||
// resolves on a later step unsatisfiable, and it is the mirror of the
|
||||
// conjunct Always keeps below.
|
||||
if innerResult.status == statusPending {
|
||||
return pending(OrFormula{Left: innerResult.formula, Right: next})
|
||||
}
|
||||
return pending(next)
|
||||
|
||||
case ImpliesFormula:
|
||||
@@ -444,25 +510,20 @@ func reduce(formula Formula, now time.Time) reduceResult {
|
||||
if innerResult.status == statusViolated {
|
||||
return violatedFrom(innerResult, concrete, "always inner violated")
|
||||
}
|
||||
// A bounded Always is the dual of a bounded Eventually: once the window
|
||||
// closes without a breach it is vacuously satisfied. A pending inner at
|
||||
// the closing step is a deferred obligation (a strong next, or an inner
|
||||
// liveness that has not discharged); it must be carried so a later step
|
||||
// or Finalize resolves it, never dropped to holds.
|
||||
// A bounded Always must reduce exactly as its dual does, so that
|
||||
// G<=n(f) and not F<=n(not f) agree on every trace. The dual of "the
|
||||
// window closed on an inner that never definitely held, so violate" is
|
||||
// "the window closed on an inner that was never definitely breached, so
|
||||
// hold". A pending inner has not been breached inside the window, so it
|
||||
// discharges vacuously here exactly as its negation violates on the
|
||||
// Eventually side.
|
||||
if concrete.HasStepBound && concrete.StepBound <= 1 {
|
||||
if innerResult.status == statusHolds {
|
||||
return holds()
|
||||
}
|
||||
return pending(innerResult.formula)
|
||||
return holds()
|
||||
}
|
||||
if concrete.HasDeadline && !now.Before(concrete.Deadline) {
|
||||
if innerResult.status == statusHolds {
|
||||
return holds()
|
||||
}
|
||||
return pending(innerResult.formula)
|
||||
return holds()
|
||||
}
|
||||
next := concrete
|
||||
next.Inner = concrete.Inner
|
||||
if concrete.HasStepBound {
|
||||
next.StepBound = concrete.StepBound - 1
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user