Class: SolidLoop::ToolCall

Inherits:
ApplicationRecord show all
Defined in:
app/models/solid_loop/tool_call.rb

Instance Method Summary collapse

Instance Method Details

#idempotency_keyObject

Stable per-invocation idempotency key. executed_at prevents SolidLoop from re-invoking a checkpointed tool, but a crash between a remote side effect and the checkpoint commit can still double-invoke: handlers of irreversible tools should dedupe on this key (delivered via CallContext#idempotency_key in-process and MCP _meta on the wire).



13
14
15
# File 'app/models/solid_loop/tool_call.rb', line 13

def idempotency_key
  "solid_loop:tool_call:#{id}"
end

#lease_held_by?(token, now: Time.current) ⇒ Boolean

The per-tool_call lease (docs/decisions/durable_attempt_lease.md). A live lease means THIS worker's lease_token is stamped and the lease has not expired. The canonical completion write re-checks this under the row lock (alongside the loop's execution_token) so a stale worker whose lease was revoked by pause/reclaim writes nothing canonical.

now is passed explicitly so a single fenced transaction evaluates expiry against one consistent clock.

Returns:

  • (Boolean)


25
26
27
28
29
30
# File 'app/models/solid_loop/tool_call.rb', line 25

def lease_held_by?(token, now: Time.current)
  token.present? &&
    lease_token == token &&
    leased_until.present? &&
    leased_until > now
end

#response_messageObject



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

def response_message
  message.loop.messages
    .where(role: :tool, tool_call_id: tool_call_id)
    .where("id > ?", message_id)
    .order(:id)
    .first
end