Class: Collavre::Task

Inherits:
ApplicationRecord show all
Defined in:
app/models/collavre/task.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.duplicate_running_for_comment?(agent_id, comment_id) ⇒ Boolean

Check if agent already has an in-flight task triggered by the same comment. Treats “delegated” as in-flight: a Claude Channel task that is waiting on an external MCP reply is still active work — re-dispatching the same comment would produce duplicate replies.

Returns:

  • (Boolean)


32
33
34
35
36
37
38
# File 'app/models/collavre/task.rb', line 32

def self.duplicate_running_for_comment?(agent_id, comment_id)
  where(agent_id: agent_id, status: %w[running delegated], trigger_event_name: "comment_created")
    .find_each do |task|
    return true if task.trigger_event_payload&.dig("comment", "id").to_s == comment_id.to_s
  end
  false
end

Instance Method Details

#fire_completion_callbacks_after_external_claimObject

Replay the after_update_commit callbacks when the status transition was made via an UPDATE that bypassed callbacks (e.g. update_all in an atomic claim flow). The private callback predicates rely on saved_change_to_attribute? which is false outside a save lifecycle, so the callbacks themselves would no-op when called directly. This method is the supported escape hatch for AgentsController#finalize_claimed_task to drive the same side effects (trigger-loop continuation + stop-button broadcast) once the related reply_comment has been persisted.



48
49
50
51
# File 'app/models/collavre/task.rb', line 48

def fire_completion_callbacks_after_external_claim
  check_trigger_loop_completion if trigger_loop_completion_eligible?
  broadcast_stop_button_removal if terminal_status?
end