Record Class Checkpoint

java.lang.Object
java.lang.Record
com.tnsai.reliability.Checkpoint
Record Components:
runId - correlation id for the whole run; opaque
stepIndex - zero-based position in the run's step list
capturedAt - wall-clock instant the checkpoint was saved
state - serialized agent / step state — opaque bytes
metadata - free-form labels (step name, agent id, …) visible to operators in store dumps
previousCheckpointId - parent checkpoint, when forming a chain for retention truncation; empty for the first checkpoint of a run

public record Checkpoint(String runId, int stepIndex, Instant capturedAt, byte[] state, Map<String,Object> metadata, Optional<String> previousCheckpointId) extends Record
Durable snapshot of a ResumableRun at a step boundary (issue #82 closeout / TNS-299).

Each step boundary in a long-running agent execution captures one of these. The orchestrator persists them via a CheckpointStore so a process crash, runtime upgrade, or operator-initiated pause can be recovered from the latest entry without redoing finished steps.

Serialization shape

state is opaque to this primitive — the orchestrator and the step impls own its format. JSON is the recommended default for debuggability; binary is opt-in for hot paths. Keeping the byte payload format off the Checkpoint record itself lets stores round-trip checkpoints without parsing them.

Identity

(runId, stepIndex) is the natural identifier — every step in a run produces at most one checkpoint. checkpointId() returns the conventional concatenation that adapters use when keying their underlying storage.
Since:
0.10.0 (TNS-299)
  • Constructor Details

    • Checkpoint

      public Checkpoint(String runId, int stepIndex, Instant capturedAt, byte[] state, Map<String,Object> metadata, Optional<String> previousCheckpointId)
      Creates an instance of a Checkpoint record class.
      Parameters:
      runId - the value for the runId record component
      stepIndex - the value for the stepIndex record component
      capturedAt - the value for the capturedAt record component
      state - the value for the state record component
      metadata - the value for the metadata record component
      previousCheckpointId - the value for the previousCheckpointId record component
  • Method Details

    • checkpointId

      public String checkpointId()
      Stable identifier formed from runId and stepIndex. Stores typically use this as their primary key. Format is intentionally simple — <runId>:<stepIndex> — so it survives filesystem / SQL / Redis backends without escaping concerns. Run ids must therefore not contain ':'; compact constructor does NOT enforce this so consumers can use a different separator convention if they own the id space.
    • stateCopy

      public byte[] stateCopy()
      Returns:
      defensive copy of state; mutations to the returned array do not affect the checkpoint.
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with '=='.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • runId

      public String runId()
      Returns the value of the runId record component.
      Returns:
      the value of the runId record component
    • stepIndex

      public int stepIndex()
      Returns the value of the stepIndex record component.
      Returns:
      the value of the stepIndex record component
    • capturedAt

      public Instant capturedAt()
      Returns the value of the capturedAt record component.
      Returns:
      the value of the capturedAt record component
    • state

      public byte[] state()
      Returns the value of the state record component.
      Returns:
      the value of the state record component
    • metadata

      public Map<String,Object> metadata()
      Returns the value of the metadata record component.
      Returns:
      the value of the metadata record component
    • previousCheckpointId

      public Optional<String> previousCheckpointId()
      Returns the value of the previousCheckpointId record component.
      Returns:
      the value of the previousCheckpointId record component