Documentation
¶
Overview ¶
Package worker provides an asynchronous worker pool and utils for persisting conversation turns using the provided storage.Driver.
The pool decouples storage operations from the proxy's HTTP hot path so that the client-proxy-upstream interaction is fully transparent.
Embedding writes deliberately do NOT happen here: the derive worker family is the single writer of embeddings (pkg/spanembed), keyed by deterministic span identity, so the ingest hot path stays pure capture.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// Driver is the storage backend: the raw-turn layer plus the
// sessions surface (Postgres). Drivers without those capabilities
// (the in-memory test driver) make capture a no-op.
Driver storage.Driver
// NumWorkers is the number of background workers in the pool.
NumWorkers uint
// QueueSize is the capacity of the buffered job channel (defaults to 256).
QueueSize uint
// Project is the git repository or project name to tag on stored nodes.
Project string
// Logger is the provided logger
Logger *slog.Logger
}
Config is the configuration options for the worker pool.
type Job ¶
type Job struct {
Provider string
AgentName string
// ThreadID is the harness sub-thread that fired this call ("" for
// the main thread), captured at the wire and stamped onto the
// turn's nodes as non-hashed metadata.
ThreadID string
Req *llm.ChatRequest
Resp *llm.ChatResponse
// RawRequest is the verbatim provider request body the proxy
// received, persisted unparsed into the immutable raw-turn layer so
// the deriver re-parses it (and fields unknown to this build
// survive). Empty for callers that don't capture into raw_turns
// (e.g. the in-memory test driver); the raw write is skipped then.
RawRequest json.RawMessage
// Session is the optional session-tracking envelope attached to
// the turn. When non-nil and the driver supports session-aware
// ingest (Postgres), the worker UPSERTs the turn's `sessions` row
// and folds its derived_status so the deriver can resolve the
// session and attach its spans. When nil OR when the driver does
// not implement that capability (e.g. inmemory), no sessions row is
// written — this keeps unit tests working without a Postgres
// backend. The local proxy always attaches an envelope so its
// captured turns surface in the deck.
Session *sessions.IngestEnvelope
}
Job is a unit of work for the worker pool to execute against.
type Pool ¶
type Pool struct {
// contains filtered or unexported fields
}
Pool processes storage jobs asynchronously via a worker pool.
func (*Pool) Close ¶
func (p *Pool) Close()
Close signals workers to stop and waits for in-flight jobs to drain. Call this during graceful shutdown after the proxy HTTP server has stopped.
func (*Pool) Enqueue ¶
Enqueue submits a job for processing by the worker pool. Returns true if enqueued, false if the queue is full, resulting in the job being dropped