nautechsystems/nautilus_trader · error

latest anchor

Error message

latest anchor

What it means

Test panic from `.expect("latest anchor")` on the backend's `latest_snapshot_anchor()` query, which returns `Result<Option<SnapshotAnchor>, EventStoreError>`. The panic fires either on a backend error or because the assertion compares against `Some(anchor)` and the query returned `None` — i.e. the anchor recorded moments earlier is not visible to the backend query.

Source

Thrown at crates/event_store/src/writer/mod.rs:1883

        let writer = EventStoreWriter::spawn(
            Box::new(wrapper),
            get_atomic_clock_static(),
            noop_halt(),
            WriterConfig::default(),
        )
        .expect("spawn");

        writer.submit(entry_draft(10)).expect("submit first");
        writer.submit(entry_draft(11)).expect("submit second");
        let anchor = writer
            .record_snapshot_anchor("cache://position-snapshots/P-1/0", "blake3:abc")
            .expect("record anchor");

        let backend = shared.lock();
        assert_eq!(anchor.high_watermark, 2);
        assert_eq!(
            backend.latest_snapshot_anchor().expect("latest anchor"),
            Some(anchor),
        );
    }
}

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Query the same `SharedMemory` backend instance the writer was spawned with (verify wrapper/shared wiring).
  2. Confirm `record_snapshot_anchor` returned `Ok` and its ack came from the writer thread before asserting.
  3. Handle the `Err` case explicitly to see the backend error instead of panicking on `expect`.
  4. If `None`, check whether the backend's `record_snapshot_anchor` path stores anchors in the queried collection.

Example fix

// before
assert_eq!(backend.latest_snapshot_anchor().expect("latest anchor"), Some(anchor));
// after
let latest = backend.latest_snapshot_anchor()
    .unwrap_or_else(|e| panic!("latest anchor query failed: {e:?}"));
assert!(latest.is_some(), "anchor must be recorded before latest_snapshot_anchor query");
assert_eq!(latest, Some(anchor));
Defensive patterns

Strategy: validation

Validate before calling

let latest = backend.latest_snapshot_anchor()?;
assert!(latest.is_some(), "anchor must exist after record_snapshot_anchor Ok");

Type guard

fn anchor_recorded(r: &Result<Option<SnapshotAnchor>, EventStoreError>) -> bool {
    matches!(r, Ok(Some(_)))
}

Try / catch

match backend.latest_snapshot_anchor() {
    Ok(Some(anchor)) => verify(anchor),
    Ok(None) => log::warn!("no anchor recorded yet"),
    Err(e) => log::error!("anchor query failed: {e}"),
}

Prevention

When it happens

Trigger: `latest_snapshot_anchor` returning `Err(EventStoreError)` (storage/read failure); returning `None` because the anchor was never durably recorded, was recorded on a different backend instance, or the shared wrapper was locked/mutated inconsistently.

Common situations: Querying a different backend object than the one the writer owns; madsim/shared-memory visibility issues; reading before the writer thread actually committed the anchor despite the ack.

Understand the failure class

Background: Record Not Found Errors: "not found", RecordNotFound, and "was not found" — what they mean and how to fix them — this error's family across 28 libraries.

Related errors


AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08). Data as JSON: /api/errors/0b2585df74db74bc. Report an issue: GitHub.