Class: Silas::Compaction

Inherits:
ApplicationRecord show all
Defined in:
app/models/silas/compaction.rb

Overview

One compaction row replaces session turns 0..up_to_turn_index with a persisted summary. Written exactly once (the unique index on session_id + up_to_turn_index is the compare-and-swap claim), read deterministically forever after — which is what lets MessageBuilder stay byte-identical across crash replays: the summary is a row, never a runtime computation.

Constant Summary collapse

STATUSES =
%w[pending completed].freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.latest_for(turn) ⇒ Object

The compaction MessageBuilder applies when building turn: the newest completed summary strictly before it. (A compaction can never cover its own turn — it is created during turn N covering 0..N-1 — so < is always satisfiable; it also keeps an eval or replay of an older turn from seeing a summary written after it.)



26
27
28
29
30
# File 'app/models/silas/compaction.rb', line 26

def self.latest_for(turn)
  completed.where(session_id: turn.session_id)
           .where(up_to_turn_index: ...turn.index)
           .order(:up_to_turn_index).last
end

Instance Method Details

#completed?Boolean

Returns:

  • (Boolean)


19
# File 'app/models/silas/compaction.rb', line 19

def completed? = status == "completed"