Repository navigation
Description
What happened
A branch or revision copy can silently discard a valid history-compaction checkpoint when RuntimeEvent timestamps differ from durable append order.
Since #4348, a checkpoint prefix mismatch no longer fails the copy with persistence_failed. The copy succeeds, but it drops the valid checkpoint. The target ledger can also lose the source session's cross-run interleaving because copy import groups events by run.
Expected behavior: Integrity checks and copied ledgers use durable RuntimeEvent order. A valid checkpoint remains valid after the copy.
How to reproduce
- Append compactable RuntimeEvents from two runs in interleaved order.
- Give the events timestamps that produce a different order.
- Record a history-compaction checkpoint over the durable prefix.
- Create a branch or revision.
- Observe that the copy drops the checkpoint or writes a different target prefix.
Durable order: A1 -> B1 -> A2 -> B2
Timestamp order: B1 -> B2 -> A1 -> A2
Grouped copy: A1 -> A2 -> B1 -> B2
Root cause
RuntimeReadModel used timestamps as its primary session ordering key. The copy path also imported one batch per run, which regrouped interleaved events in the target ledger.
Fix
- Require
readSessionRuntimeEventEntries()onRuntimeEventStore. - Order immutable read-model events by session ordinal.
- Keep mutable partial snapshots beside their surrounding immutable run events.
- Put legacy backfilled events without ordinals after durable events, with deterministic timestamp ordering.
- Import copied inline events in source session order, including interleaved batches from the same run.
- Keep strict checkpoint validation.
readSessionRuntimeEvents() remains timestamp-based because it includes mutable presentation snapshots and serves repair and trace projection. It is not the immutable copy-order API.
Acceptance criteria
- A valid checkpoint remains present after branch and revision copies.
- The target immutable ledger preserves the copied source order across runs.
- Changed event content still fails checkpoint validation.
- Terminal partial snapshots remain visible in the read model.
- Production and test stores use the same required ordinal-reader contract.
- The copied message, turn, run, and inline-run sets remain unchanged.
AI use
OpenAI Codex helped diagnose, implement, test, and review this change. I reviewed and approved the issue text.
Activity
Colafornia commentedon Aug 28, 2026
take
fix(runtime-host): preserve durable event order
[-]fix(runtime-host): preserve durable RuntimeEvent order in branch and revision copies[/-][+]fix(runtime): preserve durable RuntimeEvent order in conversation copies[/+]fix(runtime): preserve durable RuntimeEvent order (#4445)
fix(runtime): preserve durable RuntimeEvent order (apache#4445)