class RubyLLM::Browser::OperationStore

Durable bookkeeping for browser operations.

The host supplies an implementation. {InMemoryOperationStore} is a fixture for tests and single-process demos only; production multi-worker or restart-safe use requires a durable store (for example the ActiveRecord store in ‘ruby_llm/browser/rails`).

Every method is expected to be atomic. Callers assume:

Public Instance Methods

attach_or_reserve(_operation) click to toggle source

Returns the existing operation for the same actor/run/idempotency key, or reserves operation. Duplicate jobs must attach, never start a second session.

# File lib/ruby_llm/browser/operation_store.rb, line 27
def attach_or_reserve(_operation)
  raise NotImplementedError, "OperationStore#attach_or_reserve must be implemented"
end
claim_start(_operation, now:) click to toggle source

Atomically changes reserved to starting, checking the caller’s fence. A second delivery must never start even when it read the row before the first claim.

# File lib/ruby_llm/browser/operation_store.rb, line 59
def claim_start(_operation, now:)
  raise NotImplementedError, "OperationStore#claim_start must be implemented"
end
confirm_closed(_operation, session_id:, now:) click to toggle source

Records provider-confirmed closure of this exact session, including cancellation.

# File lib/ruby_llm/browser/operation_store.rb, line 69
def confirm_closed(_operation, session_id:, now:)
  raise NotImplementedError, "OperationStore#confirm_closed must be implemented"
end
fetch(_id) click to toggle source

@return [Operation, nil]

# File lib/ruby_llm/browser/operation_store.rb, line 32
def fetch(_id)
  raise NotImplementedError, "OperationStore#fetch must be implemented"
end
fetch!(_id) click to toggle source

Returns the operation or raises {InvalidInput} when absent.

# File lib/ruby_llm/browser/operation_store.rb, line 37
def fetch!(_id)
  raise NotImplementedError, "OperationStore#fetch! must be implemented"
end
lease(_id, actor_id:, run_id:, now:) click to toggle source

Claims the operation for one worker, bumping its fence token.

@return [Operation] the newly leased operation @raise [NotAuthorized] a different actor/run tries to claim it

# File lib/ruby_llm/browser/operation_store.rb, line 45
def lease(_id, actor_id:, run_id:, now:)
  raise NotImplementedError, "OperationStore#lease must be implemented"
end
mark_cleanup_pending(_id, actor_id:, run_id:, error_code: nil, now:) click to toggle source

Marks an operation unable to confirm its own cleanup.

@return [Operation]

# File lib/ruby_llm/browser/operation_store.rb, line 76
def mark_cleanup_pending(_id, actor_id:, run_id:, error_code: nil, now:)
  raise NotImplementedError, "OperationStore#mark_cleanup_pending must be implemented"
end
open_for(_actor_id) click to toggle source

@return [Array<Operation>] operations currently holding a slot for the actor

# File lib/ruby_llm/browser/operation_store.rb, line 81
def open_for(_actor_id)
  raise NotImplementedError, "OperationStore#open_for must be implemented"
end
open_operations() click to toggle source

@return [Array<Operation>] every open operation across all actors. Used by the

cleanup reaper, which is a host-operated, system-wide sweep.
# File lib/ruby_llm/browser/operation_store.rb, line 87
def open_operations
  raise NotImplementedError, "OperationStore#open_operations must be implemented"
end
record_session(_operation, session_id:, now:) click to toggle source

Persists a returned session even if cancellation fenced its starting worker.

# File lib/ruby_llm/browser/operation_store.rb, line 64
def record_session(_operation, session_id:, now:)
  raise NotImplementedError, "OperationStore#record_session must be implemented"
end
reserve(_operation) click to toggle source

Atomically stores a new operation and enforces the actor’s concurrency budget. @raise [InvalidInput] the id already exists @raise [BudgetExhausted] the concurrency slot is taken

# File lib/ruby_llm/browser/operation_store.rb, line 21
def reserve(_operation)
  raise NotImplementedError, "OperationStore#reserve must be implemented"
end
update(_operation) click to toggle source

Persists operation only if its fence is current.

@return [Operation] the stored operation @raise [InvalidInput] the writer is fenced (stale)

# File lib/ruby_llm/browser/operation_store.rb, line 53
def update(_operation)
  raise NotImplementedError, "OperationStore#update must be implemented"
end