queue

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package queue manages the learn inbox: job files written by the SessionEnd hook, a lockfile so only one worker mines at a time, and per-transcript byte cursors. Deletion is parse-gated (ecosystem lesson): a job is removed only after a successfully processed mine — crashes and retries never lose observations. Three failures move the job to inbox/failed/ (circuit break).

Index

Constants

This section is empty.

Variables

View Source
var ErrLocked = errors.New("queue: another learn worker is running")

ErrLocked reports another live worker holds the lock — the caller should simply exit; the queue drains on the next run.

Functions

func Done

func Done(j Job) error

Done removes a successfully processed job (parse-gated: call only after the mine result was parsed and persisted).

func Enqueue added in v0.3.0

func Enqueue(inboxDir string, job Job) error

Enqueue atomically writes one stable transcript pointer. The filename is derived from source+session+path, so re-running a history scan (or a hook re-delivering the same session) overwrites in place instead of creating a duplicate job. Codex can reach this boundary through either a direct hook transcript path or the rollout scanner, so the stable key is an active cross-mechanism safety property.

func Fail

func Fail(j Job) (parked bool, err error)

Fail records one failed attempt. The job file survives under a .fN suffix until maxAttempts, then moves to inbox/failed/ for manual inspection. Returns true when the job was parked (no more retries).

func ScannerBlockedTranscripts added in v0.3.0

func ScannerBlockedTranscripts(inboxDir string) map[string]struct{}

ScannerBlockedTranscripts returns transcript paths that a rollout scanner must not enqueue again. It includes active jobs, retry-renamed .json.fN jobs, and jobs parked after exhausting their retry ladder. Without the parked set, a periodic scan would silently resurrect a circuit-broken job every ten minutes. This read-only helper never repairs malformed entries.

func ShouldMine

func ShouldMine(cur Cursor, size int64, sessionEnd bool, now time.Time) bool

ShouldMine decides whether a transcript has enough new content to be worth parsing. size is the transcript's current byte size.

Types

type Cursor

type Cursor struct {
	Offset  int64     `json:"offset"`
	MinedAt time.Time `json:"mined_at"`
}

Cursor is one transcript's mining progress: everything before Offset has been mined once (plan §learning A — each region mined exactly once).

type Cursors

type Cursors struct {
	// contains filtered or unexported fields
}

Cursors is the persistent transcript_path → Cursor map.

func LoadCursors

func LoadCursors(stateDir string) *Cursors

LoadCursors reads state/learn_cursors.json; a missing or corrupt file yields an empty map (worst case: some regions are mined twice — the dedup stage absorbs that).

func (*Cursors) Get

func (c *Cursors) Get(transcriptPath string) Cursor

Get returns the cursor for a transcript (zero value = never mined).

func (*Cursors) Save

func (c *Cursors) Save() error

Save writes the map atomically (temp + rename) and prunes entries whose transcript no longer exists, so the file cannot grow without bound.

func (*Cursors) Set

func (c *Cursors) Set(transcriptPath string, cur Cursor)

Set records progress for a transcript.

type Job

type Job struct {
	SessionID      string          `json:"session_id"`
	TranscriptPath string          `json:"transcript_path"`
	CWD            string          `json:"cwd"`
	Source         harness.Harness `json:"source,omitempty"`
	Trigger        string          `json:"trigger,omitempty"`
	EnqueuedAt     string          `json:"enqueued_at"`
	// contains filtered or unexported fields
}

Job is one queued transcript, as enqueued by the SessionEnd hook.

func List

func List(inboxDir string) ([]Job, error)

List reads every pending job (including previously failed retries), newest first. A malformed job file is parked, never fatal.

func (Job) Attempts

func (j Job) Attempts() int

func (Job) EffectiveSource added in v0.3.0

func (j Job) EffectiveSource() harness.Harness

func (Job) IsFinal added in v0.3.0

func (j Job) IsFinal() bool

Missing trigger is a job from the old SessionEnd-only queue format.

func (Job) Path

func (j Job) Path() string

Path returns the job file location; Attempts the prior failure count.

type Lock

type Lock struct {
	// contains filtered or unexported fields
}

Lock is a held lockfile.

func TryLock

func TryLock(stateDir string) (*Lock, error)

TryLock acquires state/learn.lock exclusively. A stale lockfile (older than staleLock) is broken once and re-acquired.

func (*Lock) Unlock

func (l *Lock) Unlock()

Unlock releases the lockfile.

Jump to

Keyboard shortcuts

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