Documentation
¶
Overview ¶
Package loop implements the loop detector: ≥ K tool.pre events with the same tool and normalized-similar input within T minutes ⇒ one alert per episode. This is the "a session in a loop drains your budget" feature (traceability #1).
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Describe ¶
func Describe(tool string, input map[string]json.RawMessage) string
Describe renders a short human-readable form of a tool call for banners.
func ReadOnly ¶ added in v0.70.0
ReadOnly reports whether the detector ignores a tool, so a replay of stored calls (the Week card's longest loop) skips exactly what the live alert skips.
func ReadOnlyTools ¶ added in v0.70.0
func ReadOnlyTools() []string
ReadOnlyTools lists them, sorted.
func Signature ¶
func Signature(tool string, payload json.RawMessage) (sig, sample string)
Signature normalizes a tool call into a similarity key: tool name + the tool_input with volatile parts (numbers, hashes, temp paths, whitespace) collapsed. Two calls that differ only in a retry counter, a line number, or a timestamp share a signature — which is exactly what a real loop looks like.
Types ¶
type Alert ¶
type Alert struct {
Kind string `json:"kind"` // "loop"
SessionID string `json:"session_id"`
Tool string `json:"tool"`
Count int `json:"count"`
WindowMin int `json:"window_min"`
Sample string `json:"sample"` // human-readable sample of the repeated input
FirstTs time.Time `json:"first_ts"`
LastTs time.Time `json:"last_ts"`
Ts time.Time `json:"ts"`
// TaxUSD is what the repeated calls paid to re-read the conversation --
// sum of each call's context at cache-read rates, and nothing else.
//
// This is deliberately not "what the loop cost". That number was tried
// twice and was wrong both times: the session total read as the loop's
// price, and the spend inside the loop's window is mostly the useful work
// happening alongside it. The tax is neither. It is one term, attributable
// to these calls exactly, and it must stay labelled as the tax rather than
// as the loop's cost (rule 6).
//
// Zero means not computed -- an alert whose calls carried no usage.
TaxUSD float64 `json:"tax_usd,omitempty"`
// IsolatedUSD is what those same calls would have paid for context inside
// a subagent. Informational: Caprock never acts on it, because the model
// took the delegation nudge once in eight tries (spec section 6.4).
IsolatedUSD float64 `json:"isolated_usd,omitempty"`
// TaxPricedCalls is how many of the repeated calls the tax above covers,
// out of Count. A call that arrived on the hook plane carries no message
// id and so cannot be attached to the turn that paid for it -- 13% of all
// calls on the owner's archive. When this is below Count the figure is an
// understatement, and the UI says so rather than presenting it as whole.
TaxPricedCalls int `json:"tax_priced_calls,omitempty"`
}
Alert is what the detector emits (WS "alert" frame).
type Detector ¶
type Detector struct {
K int
Window time.Duration
// Cooldown suppresses repeat alerts for the same (session, signature) until
// the loop stops for this long — one alert per episode, not per event.
Cooldown time.Duration
// contains filtered or unexported fields
}
Detector keeps a sliding window of recent tool.pre signatures per session.