rig

package
v0.206.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 29, 2026 License: Apache-2.0 Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package rig is the seat rigger's first slice (P3a of the envharness port, ADR 0036): a DETERMINISTIC classifier over the delegation-log corpus that puts every failed or deferred row on exactly one failure axis, and a triage report with weights over the rows eligible for each axis, the evidence (job ids) and the pre-authored remedy where the harness's closed rule vocabulary has one — and an honest "not a rule matter" bucket where it has none. It proposes nothing on its own, applies nothing, never calls the cloud; P3b (a proposer with a validation gate, the difficulty-zone and red-team objectives) waits for a trace corpus in the hundreds.

Why a classifier first (design council 2026-09-07): of 649 bad rows in the corpus that day, ~70 % were wall timeouts and seat/infrastructure errors the rule vocabulary cannot touch, only 16 rows carried a trace, and a proposer built on an unvalidated diagnosis inherits every ambiguity. The published precedence order below is the contract; a fixture with one row per boundary case pins it.

Index

Constants

View Source
const (
	LongObservationChars = 8000
	LoopSameToolRun      = 3
	ToolMisuseMin        = 2
	TwoStepMaxSteps      = 2
)

Thresholds are the classifier's constants, printed in the report so a reader knows what the labels mean.

View Source
const SubInvalid = "invalid"

SubInvalid is the schema-miss sub-axis for an answer that did not validate against the output schema at all (the re-pack failed: wrong types, wrong shape) — distinct from a valid answer with empty fields.

View Source
const SubTwoStepGrounded = "two-step-grounded"

SubTwoStepGrounded is the sub-axis (of schema-miss and anchor-miss) the P2 corpus read found: the contract carried context docs and the run stopped within two steps — the seat answered before it had read the document.

Variables

View Source
var ErrNoRows = errors.New("rig: no rows for the seat in the window")

ErrNoRows is returned when the window holds no rows for the seat; the error names the seats that WERE seen so a typo is caught by name.

Precedence is the evaluation order, published so the report can print it.

View Source
var Remedies = map[Axis]Remedy{
	AxisSeatInfra:       {Applies: "none", Rationale: "the seat or the box answered wrong (HTTP errors, engine crashes, contention): fix the serving stack; no rule shapes this"},
	AxisCallDeadline:    {Applies: "none", Rationale: "the whole call ran out of time before this subtask finished (agent_call_deadline_sec, ADR 0065): not evidence about the seat, and no rule shapes it — split the call into smaller ones or raise the deadline"},
	AxisCapacity:        {Applies: "delegator config", Key: "agent_call_deadline_sec / agent_placement_wait_sec", Value: "a full fleet is a place in line: shorten the fan-out, add a lane, or lengthen the wait that bounds it (agent_call_deadline_sec for the MCP doors, agent_placement_wait_sec for the doors without a call deadline); NOT timeout_sec, which never bounds this wait", Rationale: "every node that could run the subtask was busy for as long as the wait ran (ADR 0073)"},
	AxisTimeout:         {Applies: "contract", Key: "timeout_sec", Value: "raise toward the cap only when the row's steps show progress; otherwise the run was stuck, not slow", Rationale: "the wall ran out — a contract-side budget, not a rule"},
	AxisFinalToolCall:   {Applies: "none", Rationale: "the last step offered no tools and asked for the answer, and the seat wrote a tool call instead, again after the loop re-asked once with it quoted: the seat's template keeps continuing the tool-call turns above it, not a task too large for one contract (cutting the contract up cannot help: the run had read what it needed and most of its wall was unspent). The delegator gives the contract to another seat once; a seat that does this routinely wants a different agent seat for this lane"},
	AxisBudget:          {Applies: "contract", Key: "max_steps", Value: "the cap is 12; a run at the cap with no loop axis is a task too large for one contract — split it", Rationale: "the step budget ran out"},
	AxisAbstention:      {Applies: "contract", Key: "goal", Value: "name the context file and tell the seat to read it first; anchor acceptance on page-only tokens", Rationale: "the seat declined — usually a goal that reads as unanswerable"},
	AxisSchemaMiss:      {Applies: "node config", Key: "agent_seed_context_reads", Value: "true on the node (one read_file per context doc replayed before turn 1) when the sub-axis is two-step-grounded; otherwise anchor acceptance on the document", Rationale: "a schema-valid answer with empty or short fields — on grounded contracts stopping at two steps the seat answered before reading the document (the 2026-09-07 corpus finding, measured by the setup_ab A/B)"},
	AxisAnchorMiss:      {Applies: "contract", Key: "goal / acceptance", Value: "name the context file in the goal and tell the seat to read it first; anchor on tokens that exist only in the document (a regex alternation beats one contains:)", Rationale: "a valid answer that missed the content anchor — the seat answered generically or off-document; on grounded contracts stopping at two steps the seed key applies as for schema-miss"},
	AxisLoop:            {Applies: "node config", Key: "agent_env_rules.max_calls_per_tool", Value: "p95 of that tool's count on the seat's PASSING rows (a cap below what passing runs need converts loops into blocked reads)", Rationale: "the same tool ran again and again"},
	AxisLongObservation: {Applies: "node config", Key: "agent_env_rules.max_observation_tokens", Value: "p50 obs_chars of the seat's passing rows / 4", Rationale: "one tool result crowded the window"},
	AxisToolMisuse:      {Applies: "node config", Key: "agent_env_rules.rewrite_error", Value: "the most repeated failed-step note (trace.note, 0.113.26+) as the match, a one-line instruction as the text", Rationale: "calls that failed or never ran, repeatedly"},
	AxisUnclassified:    {Applies: "none", Rationale: "no predicate matched — read the row"},
}

Remedies maps every axis to its lever. This is a lookup table, not inference: the rigger's added value is the weight and the evidence list, never a proposal the author did not already hand-map.

Subs lists the sub-axes each axis can carry, for the report.

Functions

func Markdown

func Markdown(rep Report) string

Markdown renders the report for a human: the seat, the window, the counts, one line per axis with weight, remedy and examples.

func ParseSince

func ParseSince(s string, now time.Time) (time.Time, error)

ParseSince turns a window spec into its start instant: "<N>d", "<N>h", an RFC3339 instant, or "" (= 7d). Shared by the CLI verb and the MCP door so the two agree on what a window means.

Types

type Axis

type Axis string

Axis is one primary failure axis. The order of this list IS the precedence order: Classify evaluates the predicates top to bottom and stops at the first hit, so two runs on the same corpus never disagree.

const (
	AxisSeatInfra        Axis = "seat-infra"        // defer_class infrastructure: the seat/engine, not the loop
	AxisCallDeadline     Axis = "call-deadline"     // the whole call ran out of time before this subtask finished (ADR 0065): not evidence about the seat
	AxisCapacity         Axis = "capacity"          // defer_class capacity: every node that could run it was busy for as long as the wait ran (ADR 0073): a full fleet, neither a seat nor a wall
	AxisTimeout          Axis = "timeout"           // the contract's wall ran out
	AxisFinalToolCall    Axis = "final-tool-call"   // the forced final step was answered with a tool call, even after one re-ask: the seat's template habit, not a task too large (core.ForcedFinalToolCallReason)
	AxisBudget           Axis = "budget"            // the step budget ran out
	AxisReasoningStarved Axis = "reasoning-starved" // stop_reason reasoning_starved / empty: the completion budget went to the think block, or the seat closed with nothing (0.115.8)
	AxisAbstention       Axis = "abstention"        // defer_class abstention: the seat declined
	AxisSchemaMiss       Axis = "schema-miss"       // the answer failed acceptance on shape: empty / short fields, or did not validate at all (sub invalid)
	AxisAnchorMiss       Axis = "anchor-miss"       // a schema-valid answer missed a content anchor (contains:/regex:/not_contains:) — off-document or generic
	AxisLoop             Axis = "loop"              // trace: the same tool >= 3 times running, or a rule fired
	AxisLongObservation  Axis = "long-observation"  // trace: one observation over the long threshold
	AxisToolMisuse       Axis = "tool-misuse"       // trace: >= 2 calls that failed or never ran
	AxisUnclassified     Axis = "unclassified"
)

type AxisReport

type AxisReport struct {
	Axis      Axis     `json:"axis"`
	Sub       string   `json:"sub,omitempty"`
	Hits      int      `json:"hits"`
	Eligible  int      `json:"eligible"` // rows this axis could have classified (trace axes: rows with a trace)
	Weight    float64  `json:"weight"`   // hits / eligible
	Examples  []string `json:"examples"` // up to 5 job ids, oldest first
	Evidence  []string `json:"evidence"` // the deciding facts of the examples
	Remedy    Remedy   `json:"remedy"`
	TopReason string   `json:"top_reason,omitempty"` // seat-infra / timeout: the most repeated reason text (digits folded)
}

AxisReport is one axis's line in the report.

type Refusal

type Refusal struct {
	Status        int `json:"status"`
	RetryAfterSec int `json:"retry_after_sec,omitempty"`
}

Refusal is the delegator's marker on the row of a refused attempt.

type Remedy

type Remedy struct {
	Key       string `json:"key,omitempty"`   // config key / rule, "" when there is no lever
	Value     string `json:"value,omitempty"` // how the value is derived, in words
	Applies   string `json:"applies"`         // node config | contract | none
	Rationale string `json:"rationale"`
}

Remedy is the pre-authored lever for an axis: what the harness's closed vocabulary can do about it (Key), or the honest statement that it cannot.

type Report

type Report struct {
	Seat  string `json:"seat"`
	Node  string `json:"node,omitempty"`
	Since string `json:"since"`
	Until string `json:"until"`
	Rows  int    `json:"rows"`
	Bad   int    `json:"bad"`
	// Refusals counts the rows that were a node's capacity refusal inside a wait (Row.Refusal): attempts the
	// delegator outwaited and re-placed. They are not subtasks, so they are in neither Rows nor Bad.
	Refusals     int            `json:"refusals,omitempty"`
	WithTrace    int            `json:"with_trace"`
	BadWithTrace int            `json:"bad_with_trace"`
	Precedence   []Axis         `json:"precedence"`
	Thresholds   map[string]int `json:"thresholds"`
	Axes         []AxisReport   `json:"axes"`
	SeatsSeen    []string       `json:"seats_seen,omitempty"`
}

Report is the rigger's output for one seat and window.

func Build

func Build(rows []Row, seat, node string, since, until time.Time) (Report, error)

Build classifies the rows for one seat (alias match on the row's seat, optional node) and assembles the report. Deterministic for a fixed input: rows are processed in order, examples are the first five hits.

type Row

type Row struct {
	TS                 int64                 `json:"ts"`
	JobID              string                `json:"job_id"`
	Node               string                `json:"node"`
	Seat               string                `json:"seat"`
	Deferred           bool                  `json:"deferred"`
	DeferClass         string                `json:"defer_class"`
	AcceptancePass     bool                  `json:"acceptance_pass"`
	WallMs             int64                 `json:"wall_ms"`
	Error              string                `json:"error"`
	Contract           core.AgentContract    `json:"contract"`
	Result             *core.AgentWireResult `json:"result"`
	AcceptanceFailures []string              `json:"acceptance_failures"`
	Arm                string                `json:"arm"`
	// Refusal is set by a delegator on the row of an attempt a node answered with a capacity refusal (a 503 or
	// 429 at dispatch): the attempt is outwaited and the subtask re-placed, so the row records a place in line,
	// not an outcome, and the subtask's outcome is another row. Absent on rows written before the marker.
	Refusal *Refusal `json:"refusal,omitempty"`
}

Row is the slice of a delegation-log row the classifier reads.

func ReadShards

func ReadShards(dir string, since, until time.Time) ([]Row, int, error)

ReadShards reads every delegation-log shard whose day falls in [since, until] from dir (the harness's delegation-log directory) and returns the rows in file order. Unparseable lines are skipped and counted.

func (Row) Bad

func (r Row) Bad() bool

Bad reports whether the row is a failure the rigger classifies. A refused attempt is not one: the subtask it belonged to was re-placed, and the row of where it ended is judged on its own.

func (Row) Refused

func (r Row) Refused() bool

Refused reports whether the row is a node's capacity refusal inside a wait (see Row.Refusal).

type Verdict

type Verdict struct {
	JobID    string `json:"job_id"`
	Axis     Axis   `json:"axis"`
	Sub      string `json:"sub,omitempty"`
	Evidence string `json:"evidence"` // the fact that decided, in the row's own words
}

Verdict is one row's classification.

func Classify

func Classify(r Row) Verdict

Classify puts one bad row on exactly one axis, in Precedence order. A row that is not bad classifies as "" (the caller filters). The predicates:

  1. seat-infra: defer_class == "infrastructure" (or "config"/"contract" — the box or the contract, never the loop); ALSO no defer_class at all and the delegator's own error is a placement failure (a node's 503 shed, a refused dispatch, a dial failure) — no node produced a result. 1b. call-deadline: the reason opens with core.CallDeadlineReasonPrefix — the whole-call deadline (ADR 0065) cut the subtask, so it says nothing about the seat's speed. Ahead of timeout because the wall-timeout pattern matches the bare word "deadline"; behind seat-infra, which reads the row's CLASS: a cut is always class budget (the run's own verdict rides in the reason, never in the class), so a cut reaches this axis whatever the run reported, and only a row that carries an infrastructure, config or contract class of its own stays the seat's. 1c. capacity: defer_class == "capacity" (the capacity wait ended, the shed, a lease's place in line), or no defer_class and the delegator's error is a node's 503/429 "queue full" answer to a dispatch (a row written before delegators marked refusals). Ahead of timeout because every capacity wait bounded by the call words itself with the bare word "deadline", which the wall-timeout pattern matches: 24 of 24 capacity defers of one day were filed as timeouts with the remedy "raise timeout_sec", a key that never bounds that wait (ADR 0073). A row a delegator marked as a refused attempt (Row.Refusal) is no failure at all: the subtask was re-placed.
  2. timeout: the reason/error says wall timeout / deadline, or defer_class == "budget" with stop_reason "error" and no step-budget text. 2b. reasoning-starved: stop_reason "reasoning_starved" or "empty", or the reason opens with "empty final answer" (0.115.8) — the run produced no visible final on two attempts; the calls[] records carry the arithmetic. 2c. final-tool-call: the reason carries core.ForcedFinalToolCallReason (the forced final step was answered with a tool call, again after one re-ask), ahead of budget, which shares its stop_reason and its prefix.
  3. budget: "step budget exhausted" in the reason, or stop_reason "budget".
  4. abstention: defer_class == "abstention" — except when the reason says the OUTPUT FAILED SCHEMA, which is schema-miss / invalid (the seat answered; the answer did not validate).
  5. schema-miss: any acceptance failure that is min_items:/nonempty: — sub two-step-grounded when the contract has context docs and steps <= 2. 5b. anchor-miss: any acceptance failure that is contains:/not_contains:/ regex: (a valid answer that missed a content anchor); same sub-axis. A qualified check (contains:@grounded:...) keeps its verb prefix, so its failure is counted here, an UNKNOWN verdict (empty or absent evidence) too: the axis says which kind of check failed, and the evidence column carries "unknown at <level> authority" to tell an empty answer from a wrong one.
  6. loop (trace only): rules_fired > 0, or the same tool on >= 3 consecutive steps.
  7. long-observation (trace only): any step's obs_chars > 8,000.
  8. tool-misuse (trace only): >= 2 steps with status failed/none/unknown.
  9. unclassified.

func Verdicts

func Verdicts(rows []Row, seat, node string) []Verdict

Verdicts classifies every bad row of the seat (and node) in order — the per-row companion of Build's per-axis report, for an agreement check against independent labels or for reading one job's verdict.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL