Skip to main content

Module memory_workers

Module memory_workers 

Source
Expand description

SQLite-backed job queue + Phase 1 / Phase 2 workers for the autonomous memory pipeline (memory_summary.rs).

This module is split out so the memory artifact surface (prompts, paths, redaction) stays in memory_summary.rs while the runtime machinery (SQLite schema, lease/heartbeat, LLM-backed extraction + consolidation) lives here.

Status: skeletons only. The runtime spawn hook (services::start_memory_pipeline) will instantiate and drive these in the follow-up PR. Each worker is a pure function over the SQLite connection so it’s unit-testable in isolation.

Re-exports§

pub use super::memory_summary::STAGE_ONE_SYSTEM_PROMPT as STAGE1_SYSTEM_PROMPT;
pub use super::memory_summary::CONSOLIDATION_SYSTEM_PROMPT as CONSOLIDATION_SYSTEM_PROMPT_EXPORT;

Structs§

Stage1Row
One row from memory_stage1_outputs.
ThreadInfo
A single session (thread) that is eligible for Phase 1 processing.

Statics§

PIPELINE_DB_PATH
A lazily-evaluated path for the pipeline’s working DB.

Functions§

claim_stage1_job
Atomically claim one Stage 1 job. Returns the (thread_id, cwd) pair plus the ownership token if a job was claimed.
collect_threads
Collect eligible threads from sessions_dir for the given cwd. now is the current Unix timestamp in seconds.
finish_phase2
Release the Phase 2 lease (success).
heartbeat_phase2
Refresh the heart-beat on a held Phase 2 lease.
init_schema
Initialize the SQLite schema (idempotent). Safe to call on every open. Adds three tables:
list_stage1_outputs
Load all Stage 1 outputs for cwd, newest first, capped at limit.
open_db
Owned MemoryDb connection helper. Used by services to spawn the worker without exposing the raw Connection.
pipeline_db_path
Resolve where the pipeline DB should live. Mirrors MemoryBackend placement: <home>/memory/pipeline.db.
render_stage1_user
Build the user-turn text for Stage 1 by templating STAGE_ONE_USER_TEMPLATE with the session metadata + persistable items JSON.
render_stage2_user
Build the user-turn text for Stage 2 from accumulated Stage 1 rows.
run_stage1_iteration
Run one Stage 1 iteration: claim a job, call the LLM, persist the output. Returns Ok(true) if a job was processed; Ok(false) when there is nothing to do.
run_stage2_iteration
try_claim_phase2
Try to claim the global Phase 2 job for cwd. Returns Some((token, lease)) when claimed; None when another oxi process already owns it.
upsert_thread
Insert / update the row for a single thread observation.
write_stage1_output
Insert the Stage 1 output for a thread and mark it extracted.