//! Async job pipeline for memory-tree work.
//!
//! Replaces the previous synchronous `append_leaf → cascade_seal → LLM
//! summarise` chain on the ingest hot path with a SQLite-backed job queue
//! and a worker pool. The shape is:
//!
//! ```text
//! ingest::persist
//!   └── writes chunk row (lifecycle = pending_extraction)
//!       enqueues `extract_chunk`
//!
//! worker pool (3 tasks) ──► claims jobs by kind:
//!   extract_chunk   → LLM extraction → admission decision → enqueue append_buffer
//!   append_buffer   → push to L0 → enqueue seal if gate met → enqueue topic_route
//!   seal            → seal one level → enqueue parent seal if cascading
//!   topic_route     → match topics → enqueue per-topic append_buffer
//!   digest_daily    → call tree_global::digest::end_of_day_digest
//!   flush_stale     → enqueue seals for time-stale buffers
//!
//! scheduler (1 task) ──► daily wall-clock tick:
//!   enqueues digest_daily(yesterday) + flush_stale(today)
//! ```
//!
//! All persistence lives in the same `chunks.db` as `mem_tree_chunks` so a
//! producer can insert its side-effect and its follow-up job in one tx.
//! See [`store::enqueue_tx`] for the in-tx producer entry point.
//!
//! This queue used to live under `openhuman::memory::jobs`; it now has a
//! dedicated top-level home (`openhuman::memory_queue`) because it is an
//! execution/runtime concern rather than a leaf of the memory policy API.
//! `openhuman::memory` re-exports it as `memory::jobs` during the migration.

pub(crate) mod handlers;
mod ops;
mod redact;
pub mod scheduler;
pub mod store;
pub mod testing;
pub mod types;
pub(crate) mod worker;

pub use ops::{backfill_in_progress, ensure_reembed_backfill, set_backfill_in_progress};
pub use store::{
    claim_next, count_by_status, count_total, enqueue, enqueue_tx, get_job, mark_deferred,
    mark_done, mark_failed, recover_stale_locks, DEFAULT_LOCK_DURATION_MS,
};
pub use testing::drain_until_idle;
pub use types::{
    AppendBufferPayload, AppendTarget, ExtractChunkPayload, FlushStalePayload, Job, JobKind,
    JobOutcome, JobStatus, NewJob, NodeRef, SealPayload,
};
pub use worker::{start, wake_workers};
