Dashboard › opencode › Distillation
13187bf4-f0d7-4209-8154-d6def4ba7ef5["lore_tm_v1_VgXKq1gRYGlcsi50_ZzLf5_mhBDSPnOsfiXpNUpbZjg","lore_tm_v1_ikQjpUNi8f8n5MIQWdH6kxge1KyQ31PYLHo8BALYbGA","lore_tm_v1_cJ-KcsQ9trA-zPPHXuJ0ElKAE_6QIheVINsqlmMUaj8","lore_tm_v1_2Oo2vrSEz6W2mfOO7JqQ3dVoUVpqTidSUYkmEAUBkPI","lore_tm_v1_URRtl0SMPrBInD-vgcEfZKwHgUpjw4BqZ_cippCwFHI"]
Date: Sep 16, 2026
packages/core/src/session/context-epoch.ts exports SessionContextEpoch and defines Prepared with baseline: string and baselineSeq: number.SessionContextEpoch.initialize(...) accepts db, context, sessionID, and a durable SessionExecutionClaim.Claim; it delegates to initializeOnce(...) under span SessionContextEpoch.initialize and may return Prepared | undefined or fail with SystemContext.InitializationBlocked.SessionContextEpoch.prepare(...) accepts db, events, context, sessionID, and claim; it delegates to prepareOnce(...) under span SessionContextEpoch.prepare and may fail with SystemContext.InitializationBlocked | ContextSnapshotDecodeError.prepareOnce(...) concurrently loads the current SystemContext, stored context epoch via find(db, sessionID), and SessionHistory.latestCompaction(db, sessionID) with { concurrency: "unbounded" }.prepareOnce(...) calls SystemContext.initialize(value), persists the generation through insert(...), and returns its baseline and baselineSeq.Schema.decodeUnknownEffect(SystemContext.Snapshot); decoding failures become ContextSnapshotDecodeError({ sessionID, details: String(error) }).compaction.seq > stored.baseline_seq; then replacementSeq = compaction.seq and SystemContext.replace(value, snapshot) is used. Otherwise SystemContext.reconcile(value, snapshot) is used.Unchanged or ReplacementBlocked, prepareOnce(...) retains and returns stored.baseline with stored.baseline_seq.ReplacementReady, prepareOnce(...) uses replacementSeq or falls back to EventV2.latestSequence(db, sessionID), persists the replacement with replace(...), and returns the replacement generationβs baseline and sequence.SessionEvent.ContextUpdated with a new SessionMessage.ID, current DateTime, and result.text; its commit callback invokes advance(db, sessionID, result.snapshot, claim).pipe(Effect.orDie), after which the stored baseline and baseline sequence remain the returned epoch anchor.initializeOnce(...) does nothing when SessionContextEpoch.exists(...) is true; otherwise it initializes the context, inserts the generated epoch, and returns its baseline and sequence.SessionContextEpoch.reset(...) deletes the SessionContextEpochTable row for the specified sessionID.context-epoch.ts routes epoch insertion, replacement, and snapshot advancement through SessionExecutionClaim.transaction(...), fencing each mutation with the supplied durable execution claim.baselineSeq from EventV2.latestSequence(db, sessionID) and writes session_id, baseline, snapshot, and baseline_seq; replacement updates the same generation fields, while advancement updates only snapshot.replace(...) and advance(...) terminate with Effect.die("Context Epoch not found") if their update returns no row.packages/core/src/session/message-updater.ts contains the stale-projection rule that a newer turn supersedes stale incomplete rows and an older assistant projection must never be resumed; it exports SessionMessageUpdater.packages/core/src/session/message-updater.ts projects session.next.compaction.ended into a compaction message carrying metadata, reason, summary: event.data.text, recent: event.data.recent, and time.created: event.data.timestamp; session.next.revert.staged, session.next.revert.cleared, and session.next.revert.committed currently map to Effect.void.packages/core/src/session/sql.ts defines SessionMessageTable as session_message with primary-key id, cascade-linked session_id, type, unique per-session seq, timestamps, and JSON data; indexes are session_message_session_seq_idx (unique), session_message_session_type_seq_idx, session_message_session_time_created_id_idx, and session_message_time_created_idx.SessionInputTable is session_input with primary-key id, cascade-linked session_id, JSON prompt, delivery, admitted_seq, nullable promoted_seq, wake_pending defaulting to false, wake_attempts defaulting to 0, and time_created defaulting to Date.now().SessionInputTable enforces unique (session_id, admitted_seq) and unique (session_id, promoted_seq) through session_input_session_admitted_seq_idx and session_input_session_promoted_seq_idx; pending-delivery ordering uses session_input_session_pending_delivery_seq_idx over session_id, promoted_seq, delivery, and admitted_seq, while wake scanning uses session_input_wake_pending_promoted_attempts_time_created_id_idx.SessionRecoveryTable is session_recovery with fields session_id, execution_id, nullable cascade-linked assistant_message_id, required cascade-linked continuation_message_id, phase "ready" | "unknown" | "continue", wake_pending defaulting to true, wake_attempts defaulting to 0, nullable recovery_error, and required time_created.SessionRecoveryTable uses execution_id as primary key session_recovery_pk, uniquely indexes continuation_message_id as session_recovery_continuation_message_idx, and scans wake work through session_recovery_wake_pending_error_attempts_created_execution_idx over wake_pending, recovery_error, wake_attempts, time_created, and execution_id.SessionExecutionTable is session_execution with id, cascade-linked session_id, owner_id, nullable assistant_message_id, phase "ready" | "safe" | "unknown" | "continue", time_created, expires_at, and nullable recovery_error.SessionExecutionTable uses primary key session_execution_pk on id, unique index session_execution_session_idx on session_id, index session_execution_owner_idx on owner_id, and check session_execution_phase_check restricting phase to 'ready', 'safe', 'unknown', or 'continue'.SESSION_EXECUTION_LEASE_MS = 30_000.SessionContextEpochTable is session_context_epoch, keyed by cascade-linked session_id, with required baseline, JSON snapshot: SystemContext.Snapshot, and required baseline_seq.