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
+70
-34
@@ -4,6 +4,7 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -13,9 +14,9 @@ type Formula interface {
|
||||
describe() string
|
||||
}
|
||||
|
||||
// PredicateLabel lets a ThunkFormula expose the identity of the closure it
|
||||
// wraps. ThunkFormula satisfies it through its Name field; an empty name
|
||||
// serializes without a name.
|
||||
// PredicateLabel lets a ThunkFormula expose the caller's label for the closure
|
||||
// it wraps. ThunkFormula satisfies it through the name passed to ThunkNamed;
|
||||
// an unnamed thunk serializes without a name.
|
||||
type PredicateLabel interface {
|
||||
PredicateName() string
|
||||
}
|
||||
@@ -50,17 +51,26 @@ type PureFormula struct {
|
||||
Value bool
|
||||
}
|
||||
|
||||
// ThunkFormula wraps an opaque predicate closure. Func returns the predicate's
|
||||
// boolean result and a non-nil error when the predicate threw; a thrown
|
||||
// predicate is a witnessed violation distinct from a plain false. Name carries
|
||||
// the predicate's identity so two distinct predicates produce distinct
|
||||
// describe() keys and are never merged during obligation collapse.
|
||||
// ThunkFormula wraps an opaque predicate closure. The closure returns the
|
||||
// predicate's boolean result and a non-nil error when the predicate threw; a
|
||||
// thrown predicate is a witnessed violation distinct from a plain false.
|
||||
//
|
||||
// Every thunk carries an identity assigned at construction, and the identity
|
||||
// is part of its describe() key. Two thunks are therefore equal keys only when
|
||||
// they are copies of the same constructed value, which is what lets obligation
|
||||
// collapse merge residuals without ever merging distinct predicates. The
|
||||
// fields are unexported so a thunk cannot be built without one.
|
||||
type ThunkFormula struct {
|
||||
Func func() (bool, error)
|
||||
Name string
|
||||
predicate func() (bool, error)
|
||||
name string
|
||||
identity uint64
|
||||
}
|
||||
|
||||
func (t ThunkFormula) PredicateName() string { return t.Name }
|
||||
func (t ThunkFormula) PredicateName() string { return t.name }
|
||||
|
||||
// thunkIdentities hands out the per-thunk identity. It only has to separate
|
||||
// thunks within one process, so a counter is enough.
|
||||
var thunkIdentities atomic.Uint64
|
||||
|
||||
// NowFormula marks its inner formula for evaluation at the current step only.
|
||||
// Primarily used so that now(...).implies(...) parses unambiguously.
|
||||
@@ -113,10 +123,16 @@ func Always(inner Formula) Formula { return AlwaysFormula{Inner: inner} }
|
||||
|
||||
func Pure(value bool) Formula { return PureFormula{Value: value} }
|
||||
|
||||
func Thunk(function func() (bool, error)) Formula { return ThunkFormula{Func: function} }
|
||||
func Thunk(function func() (bool, error)) Formula {
|
||||
return ThunkFormula{predicate: function, identity: thunkIdentities.Add(1)}
|
||||
}
|
||||
|
||||
func ThunkNamed(name string, function func() (bool, error)) Formula {
|
||||
return ThunkFormula{Func: function, Name: name}
|
||||
return ThunkFormula{
|
||||
predicate: function,
|
||||
name: name,
|
||||
identity: thunkIdentities.Add(1),
|
||||
}
|
||||
}
|
||||
|
||||
func Now(inner Formula) Formula { return NowFormula{Inner: inner} }
|
||||
@@ -172,10 +188,7 @@ func (a AlwaysFormula) describe() string {
|
||||
}
|
||||
func (p PureFormula) describe() string { return fmt.Sprintf("Pure(%t)", p.Value) }
|
||||
func (t ThunkFormula) describe() string {
|
||||
if t.Name != "" {
|
||||
return "Thunk(" + t.Name + ")"
|
||||
}
|
||||
return "Thunk(...)"
|
||||
return fmt.Sprintf("Thunk(%s#%d)", t.name, t.identity)
|
||||
}
|
||||
func (n NowFormula) describe() string { return "Now(" + n.Inner.describe() + ")" }
|
||||
func (n NextFormula) describe() string { return "Next(" + n.Inner.describe() + ")" }
|
||||
@@ -206,10 +219,43 @@ func (n NotFormula) describe() string { return "Not(" + n.Inner.describe() + ")"
|
||||
func Describe(formula Formula) string { return formula.describe() }
|
||||
|
||||
// withinNode mirrors the optional `within` clause attached to bounded
|
||||
// Eventually nodes in the JSON AST.
|
||||
// Always/Eventually nodes in the JSON AST.
|
||||
type withinNode struct {
|
||||
Amount int64 `json:"amount"`
|
||||
Unit string `json:"unit"`
|
||||
// Deadline is the absolute instant the window closes, in unix
|
||||
// milliseconds, present once the evaluator resolved a relative duration
|
||||
// against an observation. Two obligations spawned at different steps from
|
||||
// the same duration differ only here, so without it they serialize
|
||||
// identically and the trace erases the distinction the evaluator makes.
|
||||
Deadline int64 `json:"deadline,omitempty"`
|
||||
}
|
||||
|
||||
// withinFor renders the bound clause of a bounded Always or Eventually. The
|
||||
// authored window (steps or duration) stays in amount/unit so readers keep
|
||||
// seeing what the spec asked for; the resolved deadline rides alongside.
|
||||
func withinFor(
|
||||
hasStepBound bool,
|
||||
stepBound int,
|
||||
duration time.Duration,
|
||||
hasDeadline bool,
|
||||
deadline time.Time,
|
||||
) *withinNode {
|
||||
var node *withinNode
|
||||
switch {
|
||||
case hasStepBound:
|
||||
node = &withinNode{Amount: int64(stepBound), Unit: "steps"}
|
||||
case duration > 0:
|
||||
node = &withinNode{Amount: duration.Milliseconds(), Unit: "milliseconds"}
|
||||
case hasDeadline:
|
||||
return &withinNode{Amount: deadline.UnixMilli(), Unit: "deadline"}
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
if hasDeadline {
|
||||
node.Deadline = deadline.UnixMilli()
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
func (a AlwaysFormula) MarshalJSON() ([]byte, error) {
|
||||
@@ -218,14 +264,9 @@ func (a AlwaysFormula) MarshalJSON() ([]byte, error) {
|
||||
Arg Formula `json:"arg"`
|
||||
Within *withinNode `json:"within,omitempty"`
|
||||
}{Op: "always", Arg: a.Inner}
|
||||
switch {
|
||||
case a.HasStepBound:
|
||||
payload.Within = &withinNode{Amount: int64(a.StepBound), Unit: "steps"}
|
||||
case a.Duration > 0:
|
||||
payload.Within = &withinNode{Amount: a.Duration.Milliseconds(), Unit: "milliseconds"}
|
||||
case a.HasDeadline:
|
||||
payload.Within = &withinNode{Amount: a.Deadline.UnixMilli(), Unit: "deadline"}
|
||||
}
|
||||
payload.Within = withinFor(
|
||||
a.HasStepBound, a.StepBound, a.Duration, a.HasDeadline, a.Deadline,
|
||||
)
|
||||
return json.Marshal(payload)
|
||||
}
|
||||
|
||||
@@ -256,14 +297,9 @@ func (e EventuallyFormula) MarshalJSON() ([]byte, error) {
|
||||
Arg Formula `json:"arg"`
|
||||
Within *withinNode `json:"within,omitempty"`
|
||||
}{Op: "eventually", Arg: e.Inner}
|
||||
switch {
|
||||
case e.HasStepBound:
|
||||
payload.Within = &withinNode{Amount: int64(e.StepBound), Unit: "steps"}
|
||||
case e.Duration > 0:
|
||||
payload.Within = &withinNode{Amount: e.Duration.Milliseconds(), Unit: "milliseconds"}
|
||||
case e.HasDeadline:
|
||||
payload.Within = &withinNode{Amount: e.Deadline.UnixMilli(), Unit: "deadline"}
|
||||
}
|
||||
payload.Within = withinFor(
|
||||
e.HasStepBound, e.StepBound, e.Duration, e.HasDeadline, e.Deadline,
|
||||
)
|
||||
return json.Marshal(payload)
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user