Class: SolidLoop::Pipeline::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/solid_loop/pipeline/context.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(loop_id:, execution_token: nil) ⇒ Context

Returns a new instance of Context.



38
39
40
41
42
43
# File 'lib/solid_loop/pipeline/context.rb', line 38

def initialize(loop_id:, execution_token: nil)
  @loop = SolidLoop::Loop.find(loop_id)
  @execution_token = execution_token
  @metadata = {}
  @payload = {}
end

Instance Attribute Details

#agentObject

Inputs



5
6
7
# File 'lib/solid_loop/pipeline/context.rb', line 5

def agent
  @agent
end

#aggregatorObject

Returns the value of attribute aggregator.



15
16
17
# File 'lib/solid_loop/pipeline/context.rb', line 15

def aggregator
  @aggregator
end

#assistant_messageObject

Returns the value of attribute assistant_message.



13
14
15
# File 'lib/solid_loop/pipeline/context.rb', line 13

def assistant_message
  @assistant_message
end

#content_started_atObject

Returns the value of attribute content_started_at.



14
15
16
# File 'lib/solid_loop/pipeline/context.rb', line 14

def content_started_at
  @content_started_at
end

#debug_outputObject

Returns the value of attribute debug_output.



16
17
18
# File 'lib/solid_loop/pipeline/context.rb', line 16

def debug_output
  @debug_output
end

#detected_reasoning_fieldObject

Returns the value of attribute detected_reasoning_field.



29
30
31
# File 'lib/solid_loop/pipeline/context.rb', line 29

def detected_reasoning_field
  @detected_reasoning_field
end

#durationObject

Results



20
21
22
# File 'lib/solid_loop/pipeline/context.rb', line 20

def duration
  @duration
end

#error_bodyObject

Captured (non-2xx) failing-response envelope so the wire-log Event can persist status/headers/body even when the streaming adapter has already drained response.body via on_data.



26
27
28
# File 'lib/solid_loop/pipeline/context.rb', line 26

def error_body
  @error_body
end

#error_headersObject

Captured (non-2xx) failing-response envelope so the wire-log Event can persist status/headers/body even when the streaming adapter has already drained response.body via on_data.



26
27
28
# File 'lib/solid_loop/pipeline/context.rb', line 26

def error_headers
  @error_headers
end

#error_statusObject

Captured (non-2xx) failing-response envelope so the wire-log Event can persist status/headers/body even when the streaming adapter has already drained response.body via on_data.



26
27
28
# File 'lib/solid_loop/pipeline/context.rb', line 26

def error_status
  @error_status
end

#eventObject

Returns the value of attribute event.



12
13
14
# File 'lib/solid_loop/pipeline/context.rb', line 12

def event
  @event
end

#exceptionObject

Returns the value of attribute exception.



28
29
30
# File 'lib/solid_loop/pipeline/context.rb', line 28

def exception
  @exception
end

#execution_tokenObject

Returns the value of attribute execution_token.



31
32
33
# File 'lib/solid_loop/pipeline/context.rb', line 31

def execution_token
  @execution_token
end

#first_token_atObject

Returns the value of attribute first_token_at.



14
15
16
# File 'lib/solid_loop/pipeline/context.rb', line 14

def first_token_at
  @first_token_at
end

#heartbeatObject

The background lease renewer for THIS turn. ResponseParsing (and any other canonical-write site) calls heartbeat&.check! before committing, so a worker whose lease was lost mid-stream raises SolidLoop::LostLease instead of writing a turn it no longer owns.



36
37
38
# File 'lib/solid_loop/pipeline/context.rb', line 36

def heartbeat
  @heartbeat
end

#last_ui_update_atObject

Returns the value of attribute last_ui_update_at.



14
15
16
# File 'lib/solid_loop/pipeline/context.rb', line 14

def last_ui_update_at
  @last_ui_update_at
end

#log_bufferObject

Returns the value of attribute log_buffer.



16
17
18
# File 'lib/solid_loop/pipeline/context.rb', line 16

def log_buffer
  @log_buffer
end

#loopObject

Inputs



5
6
7
# File 'lib/solid_loop/pipeline/context.rb', line 5

def loop
  @loop
end

#messagesObject

ActiveRecord relation



6
7
8
# File 'lib/solid_loop/pipeline/context.rb', line 6

def messages
  @messages
end

#messages_text_for_token_estimationObject

Working state



11
12
13
# File 'lib/solid_loop/pipeline/context.rb', line 11

def messages_text_for_token_estimation
  @messages_text_for_token_estimation
end

#metadataObject

Hash for middlewares to share custom state



30
31
32
# File 'lib/solid_loop/pipeline/context.rb', line 30

def 
  @metadata
end

#model_configObject

Inputs



5
6
7
# File 'lib/solid_loop/pipeline/context.rb', line 5

def model_config
  @model_config
end

#normalized_dataObject

Data normalized by the dialect



27
28
29
# File 'lib/solid_loop/pipeline/context.rb', line 27

def normalized_data
  @normalized_data
end

#payloadObject

The hash that will be sent to the LLM (messages, tools, model, etc)



7
8
9
# File 'lib/solid_loop/pipeline/context.rb', line 7

def payload
  @payload
end

#request_started_atObject

Returns the value of attribute request_started_at.



14
15
16
# File 'lib/solid_loop/pipeline/context.rb', line 14

def request_started_at
  @request_started_at
end

#request_urlObject

Returns the value of attribute request_url.



21
22
23
# File 'lib/solid_loop/pipeline/context.rb', line 21

def request_url
  @request_url
end

#responseObject

Faraday response object



22
23
24
# File 'lib/solid_loop/pipeline/context.rb', line 22

def response
  @response
end

#timingsObject

Returns the value of attribute timings.



17
18
19
# File 'lib/solid_loop/pipeline/context.rb', line 17

def timings
  @timings
end

#triggering_messageObject

Returns the value of attribute triggering_message.



8
9
10
# File 'lib/solid_loop/pipeline/context.rb', line 8

def triggering_message
  @triggering_message
end

Instance Method Details

#loop_active?Boolean

Returns:

  • (Boolean)


45
46
47
48
# File 'lib/solid_loop/pipeline/context.rb', line 45

def loop_active?
  # Fail closed: a context without a generation token never owns the loop.
  @loop.running? && @execution_token.present? && @loop.execution_token == @execution_token
end

#loop_active_fresh?Boolean

Returns:

  • (Boolean)


50
51
52
53
# File 'lib/solid_loop/pipeline/context.rb', line 50

def loop_active_fresh?
  @loop.reload
  loop_active?
end

#mark_request_started!Object

Used by inner layers to record timing precisely



56
57
58
# File 'lib/solid_loop/pipeline/context.rb', line 56

def mark_request_started!
  @request_started_at = Time.current
end