Sessions, Compaction & Trajectory Tracing
CONTENTS
Mizar logs every prompt, model message, and tool call/result as an append-only event stream (SessionEvent), powering tolerant JSONL persistence, crash recovery, /tree branching, hot-cache-aware compaction, and trajectory profiling.
FIG 03 JSONL Session Forking, Compaction & Trajectory Export
Tolerant JSONL Persistence & Content-Addressed Blobs
cwd-Bucketed Lazy Persistence (mizar-session-jsonl): Persists by default under~/.mizar/sessions(override viaMIZAR_SESSIONS_DIRorsettings.jsonsessionsDir; disable vianone/off/memoryor--no-persist). Sessions bucket by canonicalizedcwdinto<sessions_dir>/<encoded-cwd>/<YYYYMMDDTHHMMSSZ>_<session_id>.jsonl(empty/missingcwdmaps to_global; symlinks resolving to the same canonical path share one bucket). Lazy creation: empty sessions never create empty.jsonlfiles until the first non-empty append orfork, and empty TUI exits omit invalid--resumehints.- Tolerant Append-Only Format & Zero Version-Number Rejection: Uses
"session","entry", and"header-patch"records. The reader scans byte-wise lines, strips BOM/blank lines, safely skips truncated crash tails, unknownrecordkinds, or unknowneventvariants (still trackingmax_persisted_seqso newseqnumbers stay strictly greater, and inserting a leading\nbefore appending if needed), and never rejects byformatVersion(both0and higher integers like999open cleanly). - Content-Addressed Image Blobs (
blobs/<sha256>): Inline base64 images are hashed with pure-Rust RFC 6234 SHA-256 and atomically written to siblingblobs/<sha256>("blob:sha256:<hex>"in JSONL). Missing blobs during resume only drop the missing attachment with a warning log without crashing. - Single-Writer & Non-Silent Error Surfacing: Runs a startup directory write probe; a dedicated
mizar-jsonl-writerthread handlesmpscappends +flush/flush_asyncbarriers and exposeslast_error(). Init, runtime write, or exit flush failures surface visibly in TUI (NoticeLevel::Error, flash banner, explicit exit error) and causemizar execto fail withreason="storage"and exit code1. - Resume & Orphan Healing: Use
-c/--continueto resume the latest workspace session or-r/--resume [id]for a specific session. Unpairedtool_callentries from past crashes are automatically healed during replay and/treeforking.
/tree Forking & Auto Titles
/treeBranching:fork(id, up_to_seq)copies prefix events into a new child session linked viaparent_idandfork_seq. BothSessionStore::forkand JSONLexec_forkreject duplicate session IDs and refuse overwriting existing.jsonlfiles, keeping mainline and sibling branches intact.- Async Session Titles (
mizar-session-title): Summarizes turns inMMDD|TYPE|Topicformat (FIX,FEA,DOC, etc.) on Turn 1 and every20turns. Manual/rename <title>setsTitleSource::Manualand locks against auto-overwrites;/renamewith no args triggers immediate LLM regeneration.
Context Compaction (B-5) & Hot-Cache-Aware Pruning
Long sessions stay accurate without thrashing provider Prompt Cache via a two-stage pipeline:
- Hot-Cache-Aware Tail Pruning (
mizar-compaction/src/pruning.rs):compaction.supersedeReads(defaulttrue): Prunes olderreadoutputs superseded by a full re-read of the same path (including superseded image attachments and their context budget).compaction.dropUseless(defaulttrue): Prunes zero-hit or superseded noise (SKILL.mdreads are always protected).- Hot-Cache & 8k Warm-Suffix Protection: Sessions on cache-enabled OpenAI Responses, reasoning-capable Anthropic Messages, or containing Responses replay / signed
thinkingblocks keep their warm prefix untouched before threshold; unprotected sessions still preserve the newest8,000tokens (flushing only after90min idle). Prunes appendSessionEvent::ToolResultPrunemarkers without mutating historical entries.
- Checkpoint Compaction (
mizar-compactionB-5):- Window Precedence:
--context-window>MIZAR_CONTEXT_WINDOW> model catalogcontextWindow>compaction.defaultContextWindow>128,000(optionally capped bycompaction.maxContextTokens). - Threshold & Recovery: Triggers at
effective_window * triggerRatio(default0.80, retainingkeepRecentTokens = 20000raw tokens) — hot-cache sessions first attempt full pruning before calling the summarizer, or run anytime via/compact [focus]. Summarization forcesReasoningEffort::Offand rejects truncated/empty wrappers. On L3 overflow recovery,mizar-agent-looprefreshes bothsystem_prompt.build_for_sessionandtools.list_declared;FileGuardTrackerontools/pre-executeblocks blind whole-filewriteoverwrites until re-read oredit.
- Window Precedence:
/trace Profiler & --trace-out Export
- Interactive 3-Lane Profiler (
Ctrl+T//trace):- WaveBand overview bar (click any pulse to jump).
- Timeline with 3 parallel lanes: L0 Input/Alerts (
USER,CTX,RepeatToolGuard), L1 LLM Turns (TTFT+Decode), and L2 Tool Execution (including nestedcodemodespans and individual tool latencies), switchable acrossDuration,Seq, andActualaxes. - Hotspots & Inspector for tool latency breakdowns, token usage, and full arguments/results.
- Headless Structured Export (
--trace-out <path>/MIZAR_TRACE_OUT): On completion, timeout, or error,mizar execatomically writes a structuredTrajectoryExportJSON file (CLI flag takes precedence over env var; in parallel batchestool_result.duration_msandresult.tool_msrecord per-tool individual execution times). Interactively,/export [path]writes JSONL trajectory logs.