Skip to main content

Module prefilter

Module prefilter 

Source
Expand description

The free gate before the Stop model call (internal evaluation “stop-prefilter”, not published).

The consequence model (predict.rs) costs one model call (~6 s, ~$0.03-0.07) per turn end, and most turn ends touch no lesson at all. So word matching first scores this turn alone: the best BM25 match of its prompt, touches and final message against the lessons, divided by the largest idf a word can have in this store (scores grow with the number of lessons; this keeps one threshold valid for a store of 10 or of 100). Below the threshold the hook asks nothing and costs 0 tokens; at or above it, predict decides as before. Calibrated on the graded preempt cases and the engineer’s real turn ends (eval/preempt/stop_prefilter.py).

Structs§

Tally
What the gate did in a store’s session state (borg status): turn ends skipped at 0 tokens, turn ends that asked the model, and the model’s cost as logged by #borg-predict-cost (USD for Claude, tokens for codex:<model>). Live checks (live.rs) log #borg-predict-cost too, and a live cost line each: they are counted apart (live_checks, live_cost), not as turn ends.

Constants§

MARKERS
State-file markers that close a turn (hook.rs appends one at every Stop that reaches the conscience). Never a selection line (#borg-select, #borg-pf, #borg-placebo, #borg-routed): those come mid-turn too and close nothing. Protocol.
THRESHOLD
Learned (evaluation-decided): pre-registered in the internal evaluation “stop-prefilter” (not published): 0.9 × the lowest score of any labelled checkpoint with a relevant lesson in its shortlist (9.28), rounded down.

Functions§

changes
Whether a tool call changes state: an edit tool (Edit, Write, MultiEdit, NotebookEdit), or a Bash command any part of which is not read-only (READ_ONLY, read-only git), redirects output into a file, or edits in place (sed -i, find -delete/-exec). Other tools (Read, Grep, Glob, …) read.
edits_gate
BORG_STOP_GATE=edits (internal evaluation “whole-store”, not published): instead of the lexical score, the model is asked whenever this turn changed something (an edit tool, or a shell command that is not read-only), and a read-only or talk-only turn skips. Default (unset or anything else): the lexical gate above.
features
The gate’s score and what an eval needs beside it (eval/preempt/stop_prefilter.py).
score
The gate’s score of the state file + final message: this turn’s best lesson match over the store’s largest idf. 0 for an empty store or a turn that matches nothing.
skip
Some(score) when the Stop hook should skip the model call for this state file + final message.
tally
threshold
The threshold in force: BORG_PREFILTER = “off” (None: always ask the model), a number, or unset (THRESHOLD). An unparsable value keeps the default.
turn
What the state file gained since the last Stop: this turn’s prompt and touches (plus the drone’s final message, appended by the caller). A live check’s ask (#borg-asked followed by #borg-live, main.rs ask_live) comes during the turn and does not end it.