Class: Silas::DeltaBuffer

Inherits:
Object
  • Object
show all
Defined in:
lib/silas/delta_buffer.rb

Overview

Coalesces model text deltas into ~10Hz "delta.silas" notifications carrying the ACCUMULATED text so far — subscribers replace rather than append, which is idempotent under a crash-restream (same step id, fresh stream overwrites itself) and ordering-safe under Turbo. Deltas are decoration over the authoritative row render: never persisted, never fed back to the model, and a replayed step (already completed) emits none.

Payload: { session_id:, turn_id:, step_id:, step_index:, text: } — every subscriber MUST filter by these ids (notifications are process-global; a busy worker interleaves deltas from concurrent turns).

Constant Summary collapse

INTERVAL =

seconds between publishes; #finish flushes the tail

0.1

Instance Method Summary collapse

Constructor Details

#initialize(turn:, step:) ⇒ DeltaBuffer

Returns a new instance of DeltaBuffer.



15
16
17
18
19
20
21
# File 'lib/silas/delta_buffer.rb', line 15

def initialize(turn:, step:)
  @turn = turn
  @step = step
  @text = +""
  @published = 0
  @last_publish = 0.0
end

Instance Method Details

#append(text) ⇒ Object



23
24
25
26
27
28
# File 'lib/silas/delta_buffer.rb', line 23

def append(text)
  return if text.empty?

  @text << text
  publish if clock - @last_publish >= INTERVAL
end

#finishObject

The final flush. StepRunner calls this BEFORE the step row commits, so the authoritative after_commit render can never race a straggling batch.



32
# File 'lib/silas/delta_buffer.rb', line 32

def finish = publish