Skip fallback needs complete, empty evidence; capture lists over-budget changes

The server skip fallback for stages with a skipped edge now applies only
when every earlier visit recorded a complete file-change capture with no
changed files and no image artifact. Any change (no repo-specific UI path
or extension list), any partial/unavailable/missing capture, a human
decision or a checkpoint-retry prefix runs the model. auto_skip=false opts
a stage out. The fallback verdict names the server fallback.

Capture compares over-budget text by hash and, in Git, lists paths it
could not compare when their git status changes, marked no_patch, so a
large workspace no longer records files: [] for a real edit. Run detail
gains a warnings list for partial/unavailable captures, also printed by
inspect on stderr.
This commit is contained in:
2026-11-04 12:56:40 +00:00
parent fa6c0864db
commit f16d61cdfa
14 changed files with 660 additions and 188 deletions
+56 -50
View File
@@ -3,36 +3,35 @@ package server
import (
"fmt"
"path"
"path/filepath"
"strings"
"git.a-wan.net/alan/pipelines/internal/protocol"
)
// UI-surface classification is the single source of truth for the deterministic
// pre-check that lets a stage declaring a `skipped` route short-circuit when the
// run changed no rendered surface. The path/extension lists live only here; the
// skip guard, its reason and the resumed-run seed all read them.
// The server skip fallback lets a stage that declares a `skipped` route
// short-circuit, without a model call, only when the run's evidence proves there
// is nothing to review: every visit so far recorded a complete file-change
// capture, none of them recorded any change, and no visit captured a rendered
// (image) artifact. Anything else runs the stage's model, which may still choose
// `skipped` itself.
//
// The rule deliberately classifies no path as "not UI". A path/extension list
// encodes one repository's layout (Go TUIs, Flutter .dart, Kotlin, SwiftUI,
// templates, strings files and config can all be rendered surface), and absent
// or partial evidence must never be read as "no edits". A wrong run costs one
// model call; a wrong skip ships an unreviewed UI change.
// maxRetainedChangedPaths bounds how many recorded changed paths a runState
// retains for the skip reason. The full count is kept separately, so the reason
// stays informative without unbounded memory.
// retains as a sample. The full count is kept separately.
const maxRetainedChangedPaths = 32
// uiSurfaceDirs are the workspace prefixes whose changes are a user-facing
// surface. Matching is on a path boundary, so "androidx/" is not "android/".
var uiSurfaceDirs = []string{"android", "internal/tui"}
// serverSkipReasonPrefix starts every server fallback skip reason, so the
// verdict says plainly that no model ran, and so a resumed run recognises its
// own earlier fallback steps (which have no capture of their own).
const serverSkipReasonPrefix = "Server fallback skip (no model run):"
// presentationExtensions are the rendered presentation file types a change can
// touch without living under a surface directory.
var presentationExtensions = map[string]bool{
".html": true,
".css": true,
".js": true,
".ts": true,
".jsx": true,
".tsx": true,
}
// autoSkipConfig is the stage config that opts a stage out of the fallback.
const autoSkipConfig = "auto_skip"
// renderedArtifactExtensions are the image types a captured artifact may carry
// when its content type was not recorded or sniffed as an image.
@@ -44,22 +43,6 @@ var renderedArtifactExtensions = map[string]bool{
".webp": true,
}
// uiSurfacePath reports whether a run-relative, forward-slash workspace path
// changed a user-facing surface: a file under android/ or internal/tui/, or a
// file with a presentation extension. It is O(len(path)) with no I/O.
func uiSurfacePath(p string) bool {
clean := strings.TrimPrefix(path.Clean(filepath.ToSlash(p)), "/")
if clean == "" || clean == "." {
return false
}
for _, dir := range uiSurfaceDirs {
if clean == dir || strings.HasPrefix(clean, dir+"/") {
return true
}
}
return presentationExtensions[strings.ToLower(path.Ext(clean))]
}
// uiSurfaceArtifact reports whether a captured artifact is a rendered surface:
// an image content type, or an image file extension when no type was recorded.
func uiSurfaceArtifact(a protocol.StageArtifact) bool {
@@ -69,19 +52,20 @@ func uiSurfaceArtifact(a protocol.StageArtifact) bool {
return renderedArtifactExtensions[strings.ToLower(path.Ext(a.Name))]
}
// recordChanges folds one completed step's observed changes into the run's
// UI-surface decision. It retains a bounded sample of paths; the count is
// unbounded so the reason can state the true total. It is O(changes) with no I/O.
// recordChanges folds one executed visit's observed changes into the run's
// skip evidence. A nil, partial or unavailable capture marks the run's
// evidence incomplete for the rest of the run. It retains a bounded sample of
// paths; the count is unbounded. It is O(changes) with no I/O.
func (s *runState) recordChanges(changes *protocol.StageFileChanges, artifacts []protocol.StageArtifact) {
if changes == nil || changes.Status != "complete" {
s.captureIncomplete++
}
if changes != nil {
for _, file := range changes.Files {
s.changedCount++
if len(s.changedPaths) < maxRetainedChangedPaths {
s.changedPaths = append(s.changedPaths, file.Path)
}
if !s.uiSurface && uiSurfacePath(file.Path) {
s.uiSurface = true
}
// The full captured set is a separate, unbounded dedupe of the actual
// evidence, unlike the bounded changedPaths sample above.
if file.Path == "" || s.capturedSeen[file.Path] {
@@ -101,16 +85,38 @@ func (s *runState) recordChanges(changes *protocol.StageFileChanges, artifacts [
}
}
// skipReasonLine states, as one bounded line, why the guard skipped a stage: no
// recorded change touched a UI surface. It names the retained checked paths.
func skipReasonLine(state *runState) string {
if state.changedCount == 0 {
return "no UI surface changed (no recorded file changes)"
// recordPersistedStep seeds the skip evidence from a stored step when a run is
// resumed or retried. A server fallback skip executed nothing and carries no
// capture, so it neither adds evidence nor makes it incomplete; every other
// stored visit (including a human decision, during which the workspace was not
// observed) is folded in like a live visit.
func (s *runState) recordPersistedStep(step protocol.RunStep) {
if serverSkipStep(step) {
return
}
line := fmt.Sprintf("no UI surface changed in %d recorded file change(s): %s", state.changedCount, strings.Join(state.changedPaths, ", "))
if extra := state.changedCount - len(state.changedPaths); extra > 0 {
line = fmt.Sprintf("%s (+%d more)", line, extra)
s.recordChanges(step.FileChanges, step.Artifacts)
}
// serverSkipStep reports whether a stored step is a server fallback skip.
func serverSkipStep(step protocol.RunStep) bool {
return step.Outcome == "skipped" && step.FileChanges == nil && step.Verdict != nil &&
step.Verdict.ReasonSource == protocol.VerdictReasonFallback &&
strings.HasPrefix(step.Verdict.Reason, serverSkipReasonPrefix)
}
// autoSkipEligible reports whether the server may skip a stage declaring a
// `skipped` route: the stage has not opted out, every visit so far recorded a
// complete capture, no change was recorded and no rendered artifact captured.
func autoSkipEligible(configs map[string]string, state *runState) bool {
if configs[autoSkipConfig] == "false" {
return false
}
return state.captureIncomplete == 0 && state.changedCount == 0 && !state.uiSurface
}
// skipReasonLine states, as one bounded line, why the server skipped a stage.
func skipReasonLine() string {
line := fmt.Sprintf("%s every earlier visit's file-change capture was complete and recorded no file changes or screenshots.", serverSkipReasonPrefix)
runes := []rune(line)
if len(runes) > protocol.VerdictReasonCap {
return string(runes[:protocol.VerdictReasonCap])