kcode-k1-chat-thread-durable-turn 0.1.8

Synchronous durable turn owner for one K1 chat thread
Documentation
1
2
3
4
5
6
7
8
9
10
11
# K1 chat thread durable turn 0.1.8

`DurableTurn` synchronously owns canonical conversation history and its durable persistence for the K1 Main Actor. `boxes` exposes canonical boxes; `events` returns cloned durable event records in record order.

`prepare_preflight` is a fresh-session-only atomic persistence operation. It appends ordered System Message and Tool Call boxes through Codex State and persists those boxes with one `chat_preflight` v1 event in one existing session transaction. The event records each call sequence and blocking mode; `preflight_calls` exposes the recovered or newly prepared calls with their stable IDs, call BoxIDs, names, arguments and modes. No inference starts here.

`ModelUsage` is the `model_usage` durable-event payload. Its public fields are `provider`, `model`, `context_id`, `provider_turn_id`, `usage`, `cumulative_usage`, and `context_limit_tokens`; `TokenBreakdown` supplies its six public normalized token counters. Both values use snake-case JSON fields. `record_model_usage(connected_box_id, usage)` persists one independent event after the current canonical box frontier. A nonzero connection must name a canonical Agent Response; zero is unassociated.

`complete` persists its terminal Agent Response, trailing canonical arrivals, and one `llm_done` event. `complete_recoverable_failure` persists a caller-selected safe terminal Agent Response and the same completion event without exposing a raw provider diagnostic. `reset_provider_context` prepares the full canonical conversation for the next provider process after a recoverable failure. `halt_critical` persists a non-restartable stalled state. `record_diagnostic` persists only one bounded typed `chat_diagnostic` code; it never stores raw diagnostic text.

Recovery preserves all durable events while retaining existing `llm_done` scheduling behavior. Tool Result v1 and v2 acceptance remains idempotent, Tool Messages remain nontriggering, and mailbox-flush preparation and commit retain their existing behavior. This crate does not classify diagnostic text, retry provider operations, or own asynchronous provider/model-usage transport.