Skip to content

Cratis Chronicle StartAtTail — skip initial reactor history

StartAtTail makes a new Cratis Chronicle reactor skip the events already in its event sequence when it first registers. Use it when deploying a notification sender or job starter should not act on old events. A reactor with a saved position keeps that position, so a restart does not skip events it has yet to handle.

Without the attribute, a new reactor starts from the beginning to catch up. Put [StartAtTail] on the C# reactor class to choose the current end of the sequence, called the tail, instead:

using Cratis.Chronicle.Events;
using Cratis.Chronicle.Reactors;
[EventType]
public record WelcomeEmailRequested(string Email);
[StartAtTail]
public class SendWelcomeEmails : IReactor
{
public Task Requested(WelcomeEmailRequested @event)
{
// Runs for events appended after this reactor was first registered.
// It does not run for the history that was already in the event log.
return Task.CompletedTask;
}
}

View C# snippet source on GitHub

The example observes events appended after its first registration, rather than sending welcome emails for the history already present.

On the reactor’s first registration, Chronicle saves a position just after the current tail before observation begins. If the sequence is empty, it starts with the first event appended to it. Later registrations and restarts retain the saved position, including when events arrived while the reactor was down. Leave the attribute in place; it does not move an existing reactor forward.

The position is per namespace: each namespace has its own observer. A reactor that appears in a new namespace starts at that namespace’s tail.

The tail belongs to whichever event sequence the reactor observes, including a named sequence or an inbox. For an inbox, events still waiting in the upstream source are not skipped by this setting. Once forwarded, they are new events in the sequence the reactor observes.

An explicit replay still reads history from the beginning. StartAtTail chooses only the initial position; it does not turn off replay.

OnceOnly skips a handler during replay, not during the initial catch-up. Catching up a newly registered reactor is ordinary observation, so OnceOnly alone still runs the handler against existing history.

Marker When it applies What it does
OnceOnly Replay Skips the marked handler for replayed events
StartAtTail First registration of a new observer Starts after the events already in its sequence

Use StartAtTail to skip initial history. Combine it with OnceOnly when the handler should also be skipped during an explicit Replay.

Neither guarantees exactly-once delivery. Recovering a failed partition delivers an event again as ordinary observation. Protect external side effects against repeated calls; the delivery identity provides a stable key for recognizing the same delivery.

Chronicle recognizes a C# reactor by its id, which defaults to the type’s full name. Renaming the class or moving its namespace changes that default id and makes it a new reactor. With StartAtTail, it starts at the tail again, skipping any history present at that moment, including events the old reactor had not handled.

Before refactoring, preserve the existing id explicitly if the reactor must keep its position. Use Reactor identity and renaming to plan that change.

Both the Chronicle server and the client must support StartAtTail. A server that predates it ignores the request, and the reactor catches up from the beginning. Upgrade the server first, then the clients, before relying on the attribute to suppress side effects against existing history.