Class: Xeno::TurnRunner

Inherits:
Object
  • Object
show all
Includes:
Compaction
Defined in:
lib/xeno/turn_runner.rb

Overview

Drives one turn to completion or to a park, checkpointing every move in the database. Uses RubyLLM's decomposed loop — generate, self-executed tools, add_message injection — and never run_tools (no approval gate, no per-call checkpoint) or complete (a turn must bound its model calls).

Invariants:

  • A tool execution and its transcript injection commit in one transaction; recorded calls are never re-run.
  • Every write is fenced on the claim token; a zombie affects zero rows.
  • Trailing blank assistant rows (mid-generate crash artifacts) are removed before anything else.

Constant Summary

Constants included from Compaction

Compaction::COMPACTION_PROMPT, Compaction::SUMMARY_PREFIX

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(turn, definition: Xeno.definition) ⇒ TurnRunner

Returns a new instance of TurnRunner.



20
21
22
23
24
# File 'lib/xeno/turn_runner.rb', line 20

def initialize(turn, definition: Xeno.definition)
  @turn = turn
  @session = turn.session
  @definition = definition
end

Instance Attribute Details

#definitionObject (readonly)

Returns the value of attribute definition.



18
19
20
# File 'lib/xeno/turn_runner.rb', line 18

def definition
  @definition
end

#sessionObject (readonly)

Returns the value of attribute session.



18
19
20
# File 'lib/xeno/turn_runner.rb', line 18

def session
  @session
end

#tokenObject (readonly)

Returns the value of attribute token.



18
19
20
# File 'lib/xeno/turn_runner.rb', line 18

def token
  @token
end

#turnObject (readonly)

Returns the value of attribute turn.



18
19
20
# File 'lib/xeno/turn_runner.rb', line 18

def turn
  @turn
end

Instance Method Details

#runObject



26
27
28
29
30
31
32
33
34
35
# File 'lib/xeno/turn_runner.rb', line 26

def run
  @token = turn.claim!
  return :not_claimed unless token

  ActiveSupport::Notifications.instrument("xeno.turn", turn_id: turn.id, session_id: session.id) do
    run_claimed
  end
rescue Xeno::Fenced
  :fenced
end