kcode-k1-audio-classification 0.4.0

Durable K1 audio classification facade
Documentation
# K1 audio classification

Durable facade for the exact KTO subsystem `audio-classification`. It exposes audio intake and fragment operations while delegating projection, replay, recovery, provider execution, health, and shutdown to the coordinator. It does not expose providers, deployment, networking, or service integration.

## Public API

```rust
pub use kcode_k1_audio_classification_projection::{
    ExecutedAnalysis, FragmentId, FragmentStageV1, FragmentStatus, LlmJobState,
    LlmJobStatus, OverallState, SpeakerLabelV1, StageState, StageStatus,
};

pub struct AudioClassification;

impl AudioClassification {
    pub fn open(
        root: &Path,
        ordering: Arc<K1TxnOrdering>,
        peering: Arc<K1Peering>,
        objects: Arc<K1Objects>,
        analyzer: Analyzer,
    ) -> Result<Self, String>;
    pub fn submit(&self, ogg_bytes: &[u8]) -> Result<FragmentId, String>;
    pub fn status(&self, fragment_id: FragmentId) -> Result<Option<FragmentStatus>, String>;
    pub fn retry(&self, fragment_id: FragmentId) -> Result<(), String>;
    pub fn discard(&self, fragment_id: FragmentId) -> Result<(), String>;
    pub fn submit_labels(
        &self,
        fragment_id: FragmentId,
        labels: Vec<SpeakerLabelV1>,
    ) -> Result<(), String>;
}
```

The re-exported declarations and implemented traits are defined by the projection contract. `FragmentId` is the immutable audio Object transaction ID. Status includes overall state, all six exact stage statuses, retained per-attempt LLM jobs, interim transaction ID and analysis, confirmed labels and deterministic final transcript, and the oldest 5,000 canonical errors plus truncation state.

`submit` strictly validates one complete positive-duration non-chained Ogg Opus fragment of at most 150 seconds, stores its exact bytes as an `audio/ogg` Object, and queues it. A Queue failure after Object persistence can leave a harmless orphan Object. `retry` accepts only Failed work, reserves concurrent retry admission, and durably submits exactly one existing Queue event; its callback performs the Failed-to-Queued transition and starts the new generation. `discard` rejects unknown fragments, is idempotent in Discarded state, admits at most one simultaneous discard transaction, and permanently suppresses late results. `submit_labels` accepts only Completed work, admits at most one simultaneous label transaction, and requires exactly one nonblank single-line person ID for every interim speaker in interim order.

## Persistence and lifecycle

Opening delegates registration, replay, projection recovery, interrupted-attempt failure, and queued-work startup to the coordinator. Replay never starts provider work. Recoverable projection invalidity rebuilds from genesis. Projection, callback-effect, driver, reorganization, and ambiguously committed submission failures fault the facade and require reopen; ambiguous submissions are never retried.

Up to eight fragment attempts execute in independent lanes with FIFO overflow. A blocked attempt does not delay unrelated facade operations or available lanes. Drop delegates bounded shutdown and does not wait for provider return. Generation activity suppresses delivery after abort, replacement, shutdown, or drop.

Facade locks protect only short operation reservations and span no external call. Projection serialization is limited to the coordinator's bounded SQLite owner operation. KTO, Peering, Objects, filesystem, provider, and SQLite latency has no finite bound. Encoding and projection work are linear in addressed bounded values, submission is linear in audio bytes plus dependency persistence, and startup replay is linear in matching canonical history.