Class: OllamaAgent::Runtime::IntentReservation

Inherits:
Object
  • Object
show all
Defined in:
lib/ollama_agent/runtime/intent_reservation.rb

Overview

Tracks intent hashes against sorted JSON scope lists for pre-flight conflict detection.

Instance Method Summary collapse

Constructor Details

#initialize(db) ⇒ IntentReservation

Returns a new instance of IntentReservation.



9
10
11
# File 'lib/ollama_agent/runtime/intent_reservation.rb', line 9

def initialize(db)
  @db = db
end

Instance Method Details

#conflicts_for(scopes:) ⇒ Array<String>

Returns intent_hash values whose scopes intersect scopes.

Returns:

  • (Array<String>)

    intent_hash values whose scopes intersect scopes



50
51
52
53
54
55
56
57
58
# File 'lib/ollama_agent/runtime/intent_reservation.rb', line 50

def conflicts_for(scopes:)
  wanted = normalize_scopes(scopes)
  found = []
  @db.execute("SELECT intent_hash, scopes FROM intent_reservations") do |row|
    other = JSON.parse(row["scopes"])
    found << row["intent_hash"] if scopes_overlap?(wanted, other)
  end
  found
end

#release(intent_hash:, manifest_id:) ⇒ :ok, ...

Returns:

  • (:ok, :missing, :wrong_owner)


35
36
37
38
39
40
41
# File 'lib/ollama_agent/runtime/intent_reservation.rb', line 35

def release(intent_hash:, manifest_id:)
  outcome = :ok
  @db.transaction(:immediate) do
    outcome = release_joining(intent_hash: intent_hash, manifest_id: manifest_id)
  end
  outcome
end

#release_joining(intent_hash:, manifest_id:) ⇒ :ok, ...

Like #release but assumes the caller already holds transaction(:immediate) on @db.

Returns:

  • (:ok, :missing, :wrong_owner)


45
46
47
# File 'lib/ollama_agent/runtime/intent_reservation.rb', line 45

def release_joining(intent_hash:, manifest_id:)
  release_transaction(intent_hash, manifest_id)
end

#reserve(intent_hash:, manifest_id:, scopes:, current_epoch:) ⇒ :reserved, ...

Returns:

  • (:reserved, :duplicate, :conflict)


14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/ollama_agent/runtime/intent_reservation.rb', line 14

def reserve(intent_hash:, manifest_id:, scopes:, current_epoch:)
  outcome = :reserved
  @db.transaction(:immediate) do
    outcome = reserve_joining(
      intent_hash: intent_hash,
      manifest_id: manifest_id,
      scopes: scopes,
      current_epoch: current_epoch
    )
  end
  outcome
end

#reserve_joining(intent_hash:, manifest_id:, scopes:, current_epoch:) ⇒ :reserved, ...

Like #reserve but assumes the caller already holds transaction(:immediate) on @db.

Returns:

  • (:reserved, :duplicate, :conflict)


29
30
31
32
# File 'lib/ollama_agent/runtime/intent_reservation.rb', line 29

def reserve_joining(intent_hash:, manifest_id:, scopes:, current_epoch:)
  normalized = normalize_scopes(scopes)
  reserve_transaction(intent_hash, manifest_id, normalized, current_epoch)
end