mirror of
https://github.com/priyanshujain/sanderling.git
synced 2026-10-02 19:17:10 +00:00
experiment instrumentation: step budgets, arm labels, campaign runner (#72)
* feat(cli): add --max-steps for step-bounded runs runner.Options.MaxSteps already worked but was unreachable from the command line. A step budget is what makes two generators comparable: one making a model call per step and one drawing from a PRNG are not comparable per second. Claude-Session: https://claude.ai/code/session_01A5KmftdEJ49A9z5mF5ESrX * feat(trace): record arm membership and host in meta.json meta.json recorded the seed but not which picker ran, how it was configured, what budget it was given, or which machine produced it. A directory of runs cannot be attributed to an experiment cell without those, which makes any factorial computed from such a directory unanalysable after the fact. Claude-Session: https://claude.ai/code/session_01A5KmftdEJ49A9z5mF5ESrX * feat(cli): add --arm and populate run meta from it Model and instructions are recorded only when the LLM picker is the one that will actually run, so a spec declaring generator = llm() that is run under the seeded picker does not label its trace with a model it never called. Claude-Session: https://claude.ai/code/session_01A5KmftdEJ49A9z5mF5ESrX * feat(campaign): sweep seeds for one experiment cell campaign.json lists the seeds a sweep intended to run and is written before the first run, so a host that dropped runs shows up as missing seeds rather than as a smaller sample. Seed 0 is rejected: sanderling test reads it as "derive a seed from the clock", which is why conformance/gates.sh controls nothing today. Each run contributes one runs.jsonl line carrying steps to first violation by origin step, the step that armed the failed obligation, so the survival analysis never reopens a trace. Claude-Session: https://claude.ai/code/session_01A5KmftdEJ49A9z5mF5ESrX * fix(runner): no silent generator fallback, and llm on web --generator llm against a spec declaring no generator = llm(...) logged a warning and ran the seeded picker. For a comparison campaign that is silent arm corruption: the run completes, the directory looks correct, and the wrong policy drove it. It is now fatal. pickSources also returned the V8 source for both action and extractor on web before it looked at the generator, so the llm policy was unreachable there. The two axes are now independent: the driver picks the extractor source, the flag picks the action source, and llmSource composes with either because the runner populates the candidate list and screenshot on every platform. Claude-Session: https://claude.ai/code/session_01A5KmftdEJ49A9z5mF5ESrX * fix(chrome): make the hierarchy dump agree with the web runtime Three facts differed between the dump the goja host reads and the DOM the V8 host reads, so the two enumerated different candidates on one page. scrollable was never emitted, and worker.go reads exactly that attribute while targets.ts requires it for scrolls, so the goja host could not offer a single web scroll. clickable tested el.onclick, which React assigns to its root container for event delegation, making the whole viewport a tap target here and in no other enumeration. Both now resolve through the selector sets in pkg/spec/src/web-runtime.ts. The dump also rooted at body while collectTargets walks querySelectorAll("*"), so the goja host never saw html, where page-level scrolling lives. It now roots at documentElement and skips the head subtree, which is all zero-bounds and would otherwise carry script and title text into the trace. Claude-Session: https://claude.ai/code/session_01A5KmftdEJ49A9z5mF5ESrX * fix(conformance): give the gate reproducible seeds SEED defaulted to 0 and sanderling test reads --seed 0 as "derive a seed from the clock", so the tunable controlled nothing and a gate failure could not be re-run. SEEDS now takes one explicit non-zero seed per run, recorded in the results table so a failing row names its stream. The five runs stay on five different streams: a gate that scored one path five times would catch less than one that scores five. Claude-Session: https://claude.ai/code/session_01A5KmftdEJ49A9z5mF5ESrX * fix(chrome): emit editable as a plain boolean editable was emitted as `isEditable || null`, and an absent field sends internal/hierarchy into the native fallback, which reads any class name containing "EditText" as an Android text widget. On web that is just a CSS class, so a page styling a div with it was editable to the goja host and not to the web runtime, and the model policy could be offered typing into a div. Claude-Session: https://claude.ai/code/session_01A5KmftdEJ49A9z5mF5ESrX * fix(spec): leave the head subtree out of the web target walk collectTargets walked querySelectorAll("*") while the hierarchy dump skips head, so the two hosts enumerated different element sets on every page with a <head>. No candidate changes: builtinCandidates pushes only for targets acceptsTarget admits, and head elements have no positive bounds, so the list the draw ranges over is untouched. What changes is that targetIndex now means the same thing on both hosts. Claude-Session: https://claude.ai/code/session_01A5KmftdEJ49A9z5mF5ESrX * test(chrome): compare the facts both hosts derive from one DOM The existing parity harness hand-authors the facts on both sides, so it proves that given identical facts both hosts select identical candidates, and says nothing about the two code paths that derive those facts from a real page. Four divergences lived in that blind spot and it passed throughout. This drives one real page and compares clickable, enabled, editable, scrollable and positiveBounds element by element, plus the element sets themselves, which is what catches a host that omits html or includes head. Reverting any of the four fixes makes it fail naming the element and the fact. Claude-Session: https://claude.ai/code/session_01A5KmftdEJ49A9z5mF5ESrX * chore(make): run the browser packages one at a time Both launch Chrome and launching two at once has failed with "Launch: context canceled". Claude-Session: https://claude.ai/code/session_01A5KmftdEJ49A9z5mF5ESrX * style: remove every em-dash and en-dash Eighteen occurrences across fourteen files. Each sentence was repunctuated to suit what the dash was doing rather than swapped for a hyphen, which produces comma splices. The minus sign in folio-web's ledger is a minus sign and stays. Claude-Session: https://claude.ai/code/session_01A5KmftdEJ49A9z5mF5ESrX * fix(chrome): honor the caller context in Launch Launch and clearState ran against d.tabCtx, so a target that accepts the connection and never answers wedged the process past its own --duration and through SIGTERM, needing SIGKILL. Unattended that is a campaign worker lost for the rest of the sweep with no diagnostic. The browser is still allocated against d.tabCtx first, because chromedp starts Chrome under whichever context calls Run first and allocating under a caller deadline would kill the browser when Launch returns. Everything after allocation goes through runCtx. Claude-Session: https://claude.ai/code/session_01A5KmftdEJ49A9z5mF5ESrX * fix(sidecarassets): publish the extracted jar through a rename Extract wrote a 96 MB jar with a plain WriteFile into a temp path every sanderling process on the host shares. On a cold host several concurrent workers all miss the checksum and all write the same path, and O_TRUNC lets one spawn a JVM against another's half-written archive. A fresh experiment host is exactly a cold host. Claude-Session: https://claude.ai/code/session_01A5KmftdEJ49A9z5mF5ESrX * feat(campaign): kill a run that outlives --run-timeout A wedged run holds its worker for the rest of the sweep, and on an unattended host nothing else will send it a signal. Defaults to three times --duration and must exceed it. A killed run is recorded as timed_out rather than as a generic failure, so the analysis can tell a lost cell from a real crash. Claude-Session: https://claude.ai/code/session_01A5KmftdEJ49A9z5mF5ESrX * style(test): gofmt browser_test.go Claude-Session: https://claude.ai/code/session_01A5KmftdEJ49A9z5mF5ESrX
This commit is contained in:
44 files changed
+3021
-87
No files matched your search
@@ -34,7 +34,7 @@ const (
|
||||
// screenshot, picks ONE number, and echoes that action so a mismatch can be
|
||||
// caught. The app-specific description (spec instructions) is appended.
|
||||
const llmSystemPrompt = "You are exercising a UI to find bugs. Each turn you get a screenshot and a numbered list of concrete actions, each with a weight hinting how much the test author wants it exercised (higher = more). " +
|
||||
"Pick the ONE action most likely to make progress or expose a defect. Bugs often hide in repeated or rapid actions, so once a screen works, deliberately stress it — for example submitting the same form twice in a row to check it is not applied more than once — rather than only advancing. " +
|
||||
"Pick the ONE action most likely to make progress or expose a defect. Bugs often hide in repeated or rapid actions, so once a screen works, deliberately stress it (for example submitting the same form twice in a row to check it is not applied more than once) rather than only advancing. " +
|
||||
"Respond with your reasoning, the chosen number, and chosen_action copied verbatim from that line. For a typing action, also provide the text to enter."
|
||||
|
||||
// llmSource selects each step's action with an OpenAI-compatible vision model
|
||||
|
||||
@@ -16,6 +16,8 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/priyanshujain/sanderling/internal/driver"
|
||||
mockdriver "github.com/priyanshujain/sanderling/internal/driver/mock"
|
||||
"github.com/priyanshujain/sanderling/internal/hierarchy"
|
||||
"github.com/priyanshujain/sanderling/internal/llmclient"
|
||||
"github.com/priyanshujain/sanderling/internal/verifier"
|
||||
@@ -276,6 +278,100 @@ func TestPickSourcesSeededByDefault(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// seededFixtureSpec declares no generator = llm(...), so --generator llm has
|
||||
// nothing to build a picker from.
|
||||
const seededFixtureSpec = `
|
||||
import { always, taps, typing, weighted } from "@sanderling/spec";
|
||||
globalThis.properties = { ok: always(() => true) };
|
||||
globalThis.actions = weighted([1, taps], [1, typing]);
|
||||
`
|
||||
|
||||
func newSeededVerifier(t *testing.T) *verifier.Verifier {
|
||||
t.Helper()
|
||||
verifierInstance, err := verifier.New()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := verifierInstance.Load(bundleSpec(t, seededFixtureSpec)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, ok := verifierInstance.LLMConfig(); ok {
|
||||
t.Fatal("seeded fixture spec must not register an llm action backend")
|
||||
}
|
||||
return verifierInstance
|
||||
}
|
||||
|
||||
// TestPickSourcesRejectsLLMWithoutSpecConfig pins the abort. Falling back to the
|
||||
// seeded picker here completes the run, writes a well-formed output directory,
|
||||
// and records it under the requested arm, so a campaign cell silently reports
|
||||
// the wrong policy's numbers.
|
||||
func TestPickSourcesRejectsLLMWithoutSpecConfig(t *testing.T) {
|
||||
for name, activeDriver := range map[string]driver.DeviceDriver{
|
||||
"native": nil,
|
||||
"web": &webMockDriver{Driver: mockdriver.New()},
|
||||
} {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
action, extractor, err := pickSources(Options{
|
||||
Driver: activeDriver,
|
||||
Verifier: newSeededVerifier(t),
|
||||
Generator: "llm",
|
||||
Logger: slog.New(slog.NewTextHandler(io.Discard, nil)),
|
||||
})
|
||||
if err == nil {
|
||||
t.Fatalf("pickSources = (%T, %T), want an error", action, extractor)
|
||||
}
|
||||
if action != nil || extractor != nil {
|
||||
t.Errorf("sources = (%v, %v), want both nil alongside the error", action, extractor)
|
||||
}
|
||||
if !strings.Contains(err.Error(), "generator = llm(...)") {
|
||||
t.Errorf("error = %q, want it to name the missing spec declaration", err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// TestPickSourcesOnWebComposesLLMWithWebExtractors covers the second half of the
|
||||
// same claim: the picker is chosen by --generator and the extractor source by
|
||||
// the driver, so the llm policy runs on web instead of being silently replaced
|
||||
// by the V8 picker.
|
||||
func TestPickSourcesOnWebComposesLLMWithWebExtractors(t *testing.T) {
|
||||
fake := newFakeOpenRouter(t)
|
||||
_, verifierInstance := newLLMSource(t, fake)
|
||||
action, extractor, err := pickSources(Options{
|
||||
Driver: &webMockDriver{Driver: mockdriver.New()},
|
||||
Verifier: verifierInstance,
|
||||
Generator: "llm",
|
||||
Logger: slog.New(slog.NewTextHandler(io.Discard, nil)),
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("pickSources: %v", err)
|
||||
}
|
||||
if _, ok := action.(*llmSource); !ok {
|
||||
t.Errorf("action source = %T, want *llmSource on web with --generator llm", action)
|
||||
}
|
||||
if _, ok := extractor.(webSource); !ok {
|
||||
t.Errorf("extractor source = %T, want webSource so overrides still come from V8", extractor)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPickSourcesOnWebSeededKeepsBothOnV8(t *testing.T) {
|
||||
action, extractor, err := pickSources(Options{
|
||||
Driver: &webMockDriver{Driver: mockdriver.New()},
|
||||
Verifier: newSeededVerifier(t),
|
||||
Generator: "seeded",
|
||||
Logger: slog.New(slog.NewTextHandler(io.Discard, nil)),
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("pickSources: %v", err)
|
||||
}
|
||||
if _, ok := action.(webSource); !ok {
|
||||
t.Errorf("action source = %T, want webSource for the seeded web path", action)
|
||||
}
|
||||
if _, ok := extractor.(webSource); !ok {
|
||||
t.Errorf("extractor source = %T, want webSource for the seeded web path", extractor)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLLMSourceDrivesExecutedActions(t *testing.T) {
|
||||
fake := newFakeOpenRouter(t)
|
||||
source, verifierInstance := newLLMSource(t, fake)
|
||||
|
||||
+36
-26
@@ -3,6 +3,7 @@ package runner
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
|
||||
@@ -64,39 +65,48 @@ func (s webSource) ExtractorOverrides(ctx context.Context) (map[int]json.RawMess
|
||||
|
||||
// pickSources selects the runtime's action and extractor sources ONCE at setup
|
||||
// from the driver's capabilities, the --generator flag, and the spec, so the
|
||||
// step loop never type-asserts. With --generator llm and a spec-declared
|
||||
// generator = llm({...}) it constructs the chat-completions client and returns
|
||||
// an llmSource for selection while extractor overrides still come from the goja
|
||||
// path. Otherwise the seeded goja picker drives.
|
||||
// step loop never type-asserts.
|
||||
//
|
||||
// The two axes are independent. The DRIVER decides where extractor overrides
|
||||
// come from: the web path reads the values its extractors computed in V8, every
|
||||
// other path has none. The --generator flag decides who picks the action, and
|
||||
// the llm picker composes with either extractor source because it reads the
|
||||
// goja-side candidate list and screenshot, both of which the runner populates on
|
||||
// every platform.
|
||||
//
|
||||
// A missing generator = llm(...) is fatal rather than a fallback to the seeded
|
||||
// picker. Falling back silently corrupts a comparison campaign: the run
|
||||
// completes and the output directory looks correct while the wrong policy drove
|
||||
// it.
|
||||
func pickSources(options Options) (ActionSource, ExtractorSource, error) {
|
||||
seeded := ActionSource(gojaSource{verifier: options.Verifier})
|
||||
extractor := ExtractorSource(gojaSource{verifier: options.Verifier})
|
||||
if web, ok := options.Driver.(driver.WebDriver); ok {
|
||||
source := webSource{web: web}
|
||||
return source, source, nil
|
||||
seeded, extractor = source, source
|
||||
}
|
||||
if options.Generator != "llm" {
|
||||
return seeded, extractor, nil
|
||||
}
|
||||
config, ok := options.Verifier.LLMConfig()
|
||||
if !ok {
|
||||
return nil, nil, errors.New("--generator llm: the spec declares no generator = llm(...); add one to the spec or drop --generator llm")
|
||||
}
|
||||
client, err := llmclient.New()
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("llm action generator: %w", err)
|
||||
}
|
||||
logger := options.Logger
|
||||
if logger == nil {
|
||||
logger = slog.Default()
|
||||
}
|
||||
if options.Generator == "llm" {
|
||||
config, ok := options.Verifier.LLMConfig()
|
||||
if !ok {
|
||||
logger.Warn("--generator llm requested but spec declares no generator = llm(); using the seeded picker")
|
||||
} else {
|
||||
client, err := llmclient.New()
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("llm action generator: %w", err)
|
||||
}
|
||||
action := &llmSource{
|
||||
verifier: options.Verifier,
|
||||
client: client,
|
||||
model: config.Model,
|
||||
instructions: config.Instructions,
|
||||
logger: logger,
|
||||
history: newActionHistory(llmHistorySize),
|
||||
}
|
||||
return action, gojaSource{verifier: options.Verifier}, nil
|
||||
}
|
||||
action := &llmSource{
|
||||
verifier: options.Verifier,
|
||||
client: client,
|
||||
model: config.Model,
|
||||
instructions: config.Instructions,
|
||||
logger: logger,
|
||||
history: newActionHistory(llmHistorySize),
|
||||
}
|
||||
source := gojaSource{verifier: options.Verifier}
|
||||
return source, source, nil
|
||||
return action, extractor, nil
|
||||
}
|
||||
Reference in new issue
Block a user