Documentation
¶
Overview ¶
Package prioritize keeps the score cache warm: when unscored backlog items sit in a repo's working set, ONE batch-scorer task (executor type "prioritize") is minted per repo; when that task completes, its verdicts are cached (priority_scores) and applied to the matching PENDING tasks as task.reprioritized facts. The agent only contributes scores; everything downstream (batching, dedup, precedence, protection) is mechanical.
Triggers are journal-driven (cursor "prioritize-sweeper", head-bootstrapped like every sweeper): a harvest enqueue means new unscored work; a scorer completion means verdicts to apply — and, right after applying, a re-check for items that entered the working set while the batch was in flight. The first sweep (BootMint) also mints for pre-cursor pending items, so enabling the sweeper on a pool with a standing backlog scores it without waiting for a fresh enqueue.
Loop safety is structural: batch tasks are type "prioritize", never "agent", so they never trigger mints themselves; a batch's dedup key is the hash of its exact key set, so an unchanged working set never re-mints (a dead batch is retried only when the set changes — the DLQ is the human surface until then); and every mint pass runs under the pool's budget guard like every other enqueue.
Index ¶
Constants ¶
const ( // ConsumerKey is the sweeper's identity in the watermarks table: the // persisted cursor shared by every sweeper instance over the same // database, rewindable with `tq watermarks set prioritize-sweeper SEQ` // (replay is idempotent: cache upserts and same-value priority updates // write nothing new). ConsumerKey = "prioritize-sweeper" // SourceScorer stamps cached verdicts (queue.PriorityScore.Source): // the batch scorer's identity. The model itself lives in each repo's // crush config and is deliberately not claimed here. SourceScorer = "ai:batch-scorer" // PrioritySourceAI is the task.reprioritized source label for applied // verdicts (ADR-0015 §3 ladder: ai). PrioritySourceAI = "ai" )
Variables ¶
This section is empty.
Functions ¶
func DedupKey ¶
DedupKey is the dedup identity of one repo's batch over one exact key set: "prioritize:<repo>:<hash>". A set that changes (new item, item reworded and re-keyed) mints a fresh batch; an unchanged set never mints twice — even after the first batch died, whose recovery then rides the next set change (the DLQ is the human surface until then).
Types ¶
type SweepStats ¶
type SweepStats struct {
// Facts is the number of new facts consumed.
Facts int
// BatchesEnqueued counts fresh scorer tasks this sweep created.
BatchesEnqueued int
// BatchesKnown counts mints whose batch task already existed (dedup
// hit — the batch ran, or is in flight, elsewhere).
BatchesKnown int
// VerdictsCached counts verdicts written to the score cache.
VerdictsCached int
// TasksReprioritized counts PENDING tasks whose priority changed by an
// applied verdict.
TasksReprioritized int
// Skipped counts facts that could not yield work (vanished records,
// foreign payload shapes, unparsable results).
Skipped int
}
SweepStats summarizes one sweep pass.
type Sweeper ¶
type Sweeper struct {
// contains filtered or unexported fields
}
Sweeper turns the journal's enqueue and scorer-completion facts into batch-scorer mints and score applications. It is safe for concurrent use (a mutex serializes sweeps).
func NewSweeper ¶
NewSweeper returns a sweeper over store. The cursor resumes from the persisted checkpoint; a first run bootstraps at the journal head (same semantics as the review and dlqfix sweepers).
func (*Sweeper) Sweep ¶
func (s *Sweeper) Sweep(ctx context.Context) (SweepStats, error)
Sweep consumes new facts since the last pass: harvest enqueues trigger a mint check for their repo, scorer completions apply their verdicts. Idempotent by dedup keys, cache upserts and same-value transition guards — a replayed page (crash between consumption and checkpoint) re-hits dedup instead of duplicating work. The cursor checkpoints after each page; a failed checkpoint stops the sweep.
type SweeperConfig ¶
type SweeperConfig struct {
// Model, when set, overrides the scorer model in every batch payload.
// Empty (the recommended default) leaves model+effort to each repo's
// crush config.
Model string
// Yolo marks the scorer autonomous (same contract as agent payloads).
Yolo bool
// AllowDirty lets the scorer start on a dirty tree. Default false: the
// scorer reads the repo for context and should see committed state.
AllowDirty bool
// BootMint makes the FIRST sweep also mint for the pre-cursor working
// set (items already pending when the sweeper was enabled), instead of
// waiting for the next enqueue to trigger.
BootMint bool
// Log receives one summary line per mint/apply. nil logs nothing.
Log *slog.Logger
// PageSize bounds one fact-stream page; 0 selects the default.
PageSize int
}
SweeperConfig controls one Sweeper.