Record Class SessionEnd

java.lang.Object
java.lang.Record
com.tnsai.hooks.events.SessionEnd
Record Components:
eventId - ULID-shaped correlation id (matches the corresponding SessionStart)
timestamp - when the session closed
context - surrounding hook context
sessionId - framework session id
reason - why the session closed
lifetime - total session duration (Instant.now() - sessionStart)
messageCount - total messages exchanged
cause - throwable when reason is SessionCloseReason.ERROR; empty otherwise
All Implemented Interfaces:
HookEvent, SessionHookEvent

public record SessionEnd(String eventId, Instant timestamp, HookContext context, String sessionId, SessionCloseReason reason, Duration lifetime, long messageCount, Optional<Throwable> cause) extends Record implements SessionHookEvent
Fires when a client session closes for any reason (issue #63). Counterpart to SessionStart — flush telemetry, persist state, write a final audit entry.

Block on SessionEnd is meaningless (the session is already gone); hooks here are observation-only by convention. The dispatcher still honors Block but the server has nothing to refuse.

cause is populated only when reason is SessionCloseReason.ERROR; other reasons carry an empty Optional. Validated at construction.

Since:
0.5.0 (issue #63)
  • Constructor Details

    • SessionEnd

      public SessionEnd(String eventId, Instant timestamp, HookContext context, String sessionId, SessionCloseReason reason, Duration lifetime, long messageCount, Optional<Throwable> cause)
      Creates an instance of a SessionEnd record class.
      Parameters:
      eventId - the value for the eventId record component
      timestamp - the value for the timestamp record component
      context - the value for the context record component
      sessionId - the value for the sessionId record component
      reason - the value for the reason record component
      lifetime - the value for the lifetime record component
      messageCount - the value for the messageCount record component
      cause - the value for the cause record component
  • Method Details

    • eventType

      public String eventType()
      Description copied from interface: HookEvent
      Short stable string identifier of the event kind, e.g. "PreToolUse". Default implementation derives it from the concrete record's simple class name; concrete records may override if a different naming is desirable.
      Specified by:
      eventType in interface HookEvent
    • 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.
    • eventId

      public String eventId()
      Returns the value of the eventId record component.
      Specified by:
      eventId in interface HookEvent
      Returns:
      the value of the eventId record component
    • timestamp

      public Instant timestamp()
      Returns the value of the timestamp record component.
      Specified by:
      timestamp in interface HookEvent
      Returns:
      the value of the timestamp record component
    • context

      public HookContext context()
      Returns the value of the context record component.
      Specified by:
      context in interface HookEvent
      Returns:
      the value of the context record component
    • sessionId

      public String sessionId()
      Returns the value of the sessionId record component.
      Returns:
      the value of the sessionId record component
    • reason

      public SessionCloseReason reason()
      Returns the value of the reason record component.
      Returns:
      the value of the reason record component
    • lifetime

      public Duration lifetime()
      Returns the value of the lifetime record component.
      Returns:
      the value of the lifetime record component
    • messageCount

      public long messageCount()
      Returns the value of the messageCount record component.
      Returns:
      the value of the messageCount record component
    • cause

      public Optional<Throwable> cause()
      Returns the value of the cause record component.
      Returns:
      the value of the cause record component