Class: SolidLoop::LoopsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/solid_loop/loops_controller.rb

Instance Method Summary collapse

Instance Method Details

#force_stopObject



48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'app/controllers/solid_loop/loops_controller.rb', line 48

def force_stop
  # Cleanup 6 — force-stop synchronously fails+hides the loop's processing
  # shell(s) inside the same transition txn, so no terminal loop retains an
  # orphaned hidden `processing` shell. The block runs under the loop lock.
  @loop.transition_status(
    from: SolidLoop::Loop::STOPPABLE_STATUSES,
    to: :failed,
    error_message: "Stopped by admin UI",
    execution_token: nil,
    lease_expires_at: nil
  ) { fail_and_hide_processing_shells!(@loop) }
  redirect_to loop_path(@loop), alert: "Loop force stopped."
end

#freezeObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/controllers/solid_loop/loops_controller.rb', line 27

def freeze
  @loop.with_lock do
    attributes = { frozen_at: Time.current }
    if SolidLoop::Loop::ACTIVE_STATUSES.include?(@loop.status)
      # Cleanup 4 + 6 — freezing an active loop pauses it: clear the LLM lease
      # (non-`running` target must NULL lease_expires_at so the DB CHECK holds
      # and the reaper stops re-selecting it) and synchronously fail+hide any
      # orphaned `processing` assistant shell so no paused loop keeps one.
      attributes.merge!(status: :paused, execution_token: nil, lease_expires_at: nil)
      fail_and_hide_processing_shells!(@loop)
    end
    @loop.update!(attributes)
  end
  redirect_to loop_path(@loop), notice: "Loop frozen."
end

#indexObject



5
6
7
8
9
10
11
# File 'app/controllers/solid_loop/loops_controller.rb', line 5

def index
  query = SolidLoop::Admin::LoopsQuery.new(params)
  return redirect_to(loop_path(query.exact_match)) if query.exact_match

  @pagination = paginate(query.call)
  @loops = @pagination[:records]
end

#observeObject



22
23
24
25
# File 'app/controllers/solid_loop/loops_controller.rb', line 22

def observe
  @loop.update!(observe_enabled: !@loop.observe_enabled)
  redirect_to loop_path(@loop), notice: "Observe mode toggled."
end

#showObject



13
14
15
16
17
18
19
20
# File 'app/controllers/solid_loop/loops_controller.rb', line 13

def show
  messages_scope = SolidLoop::Admin::MessagesQuery
    .new(params, scope: @loop.messages.includes(:tool_calls).order(Arel.sql("COALESCE(conversation_order, id)")))
    .call

  @messages_pagination = paginate(messages_scope, per_page: 100)
  @messages = @messages_pagination[:records]
end

#unfreezeObject



43
44
45
46
# File 'app/controllers/solid_loop/loops_controller.rb', line 43

def unfreeze
  @loop.update!(frozen_at: nil)
  redirect_to loop_path(@loop), notice: "Loop unfrozen."
end