bitfab 0.75.2 → 0.75.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/bitfab/assertions.rb +19 -42
- data/lib/bitfab/simulation_plan.rb +14 -1
- data/lib/bitfab/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e1cd0e2dfeb949aaf6704e07fb9ddf887cbda9ed15575a8991da34dcb5a6e46a
|
|
4
|
+
data.tar.gz: 2f559b3fff94599854d089482b43c61000ca15eadb8818e18f9764aa5c73e44d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f35dca4df1df1ded23c1d318da7e25a28580517823c1b6d44585f86e0f7b92c2c3c94e36e3490d996f3e2c0681bc059acff386bbdd3bc8f4a9463af7a605022d
|
|
7
|
+
data.tar.gz: c48363e7c90738ab3da81cc7a467ae5ec15ee44cdbaf069e3c1e9d7d1b7853637a899007e2aeb3b8ca7da36c7aa221414818ff8311bf8a8e1539a2b28921e4c9
|
data/README.md
CHANGED
|
@@ -235,7 +235,7 @@ class OrderPipeline
|
|
|
235
235
|
end
|
|
236
236
|
```
|
|
237
237
|
|
|
238
|
-
Capture uses `TracePoint` only during the root call. It skips Ruby/runtime code, dependency gems, Bitfab SDK internals, blocks, lambdas, and forwarding wrappers. When the root belongs to an installed application gem, that gem is the first-party boundary; neighboring dependency gems remain excluded. It follows recursion, modules, inheritance, `define_method`, and same-thread child Fibers; aliases are recorded and excluded by the name that was invoked. Child Fibers created during capture inherit node policies, trace identity, parenting, and depth limits while retaining separate call stacks. Pre-existing Fibers, `Fiber.new(storage: nil)`, and child threads do not inherit subtree context. When an inner capture ends, child Fibers retain any still-active outer capture; inherited context expires once all enclosing captures end. While a root remains active, hitting a span limit stops new capture but allows already-open spans in every Fiber to finish. `max_depth:` (default `30`), `max_captured_subtree_spans:` (default `500`), `exclude:`, and `include_wrappers:` control the subtree. There is no cap on the total number of spans one trace root sends. `max_spans:` was removed, and passing it raises `ArgumentError`. `max_captured_subtree_spans:` caps discovered calls sent with their inputs and outputs. It does not count `bitfab_node` calls, nested trace roots, or spans the loaded sim plan turned capture off for, so those keep recording past it. Spans sent without inputs and outputs only because the sim plan could not be read still count toward it. Past it, further discovered calls with capture on record nothing. Once the plan has loaded, the SDK does not send a span whose capture it turned off, and that span's children move up to the nearest visible parent. The trace's root span, a framework integration span,
|
|
238
|
+
Capture uses `TracePoint` only during the root call. It skips Ruby/runtime code, dependency gems, Bitfab SDK internals, blocks, lambdas, and forwarding wrappers. When the root belongs to an installed application gem, that gem is the first-party boundary; neighboring dependency gems remain excluded. It follows recursion, modules, inheritance, `define_method`, and same-thread child Fibers; aliases are recorded and excluded by the name that was invoked. Child Fibers created during capture inherit node policies, trace identity, parenting, and depth limits while retaining separate call stacks. Pre-existing Fibers, `Fiber.new(storage: nil)`, and child threads do not inherit subtree context. When an inner capture ends, child Fibers retain any still-active outer capture; inherited context expires once all enclosing captures end. While a root remains active, hitting a span limit stops new capture but allows already-open spans in every Fiber to finish. `max_depth:` (default `30`), `max_captured_subtree_spans:` (default `500`), `exclude:`, and `include_wrappers:` control the subtree. There is no cap on the total number of spans one trace root sends. `max_spans:` was removed, and passing it raises `ArgumentError`. `max_captured_subtree_spans:` caps discovered calls sent with their inputs and outputs. It does not count `bitfab_node` calls, nested trace roots, or spans the loaded sim plan turned capture off for, so those keep recording past it. Spans sent without inputs and outputs only because the sim plan could not be read still count toward it. Past it, further discovered calls with capture on record nothing. Once the plan has loaded, the SDK does not send a span whose capture it turned off, and that span's children move up to the nearest visible parent. The trace's root span, a framework integration span, a span that recorded an error, and a span that recorded LLM usage (token counts or a cost in its contexts) are still sent, and the SDK never builds their inputs or outputs. A `bitfab_node` call and a nested trace root ignore the plan and always keep their inputs and outputs. The client starts reading the sim plan when it is built. A `bitfab_trace` root that starts while that first read is still running waits for it, for at most five seconds. Once the first read has finished, whether it succeeded or failed, no later root waits. Nested roots and the calls beneath a root never wait, and nothing waits when the plan is disabled. If that first read fails, spans other than each trace's root span, `bitfab_node` calls, and nested trace roots are sent without inputs and outputs until a read succeeds, and they still count toward `max_captured_subtree_spans:`. Automatically captured calls are not replay mock targets. Declare a call with `bitfab_node` when replay must substitute it. The configured node records once in each enclosing trace. Mixing explicit spans with subtree tracing raises `Bitfab::MixedTracingError`.
|
|
239
239
|
|
|
240
240
|
When capture ends, already-open automatic calls in suspended Fibers are emitted once with a nil output and `Subtree capture ended before the call returned` as the error, unless a real error was already observed. Their inputs and parenting are retained. The SDK does not resume Fibers, and later resumption cannot add spans to the ended capture. If hot reload moves the root to an unresolved source, the last valid first-party boundary and its exclusions remain in use.
|
|
241
241
|
|
data/lib/bitfab/assertions.rb
CHANGED
|
@@ -4,11 +4,9 @@ require "uri"
|
|
|
4
4
|
|
|
5
5
|
module Bitfab
|
|
6
6
|
class Traces
|
|
7
|
-
CODE_DRAFT_SAVE_TIMEOUT_SECONDS = 300
|
|
8
|
-
CODED_KINDS = ["code", "hybrid", :code, :hybrid].freeze
|
|
9
7
|
CATEGORY_ID_KEYS = ["category_id", :category_id].freeze
|
|
10
8
|
DEPRECATED_CATEGORY_ID_KEYS = ["category_assertion_id", :category_assertion_id].freeze
|
|
11
|
-
private_constant :
|
|
9
|
+
private_constant :CATEGORY_ID_KEYS, :DEPRECATED_CATEGORY_ID_KEYS
|
|
12
10
|
|
|
13
11
|
def initialize(http_client)
|
|
14
12
|
@http_client = http_client
|
|
@@ -31,31 +29,23 @@ module Bitfab
|
|
|
31
29
|
# pass nil to clear it. The deprecated "category_assertion_id" is still
|
|
32
30
|
# accepted and sent as "category_id"; "category_id" wins when both are set.
|
|
33
31
|
#
|
|
34
|
-
# "
|
|
35
|
-
#
|
|
36
|
-
#
|
|
37
|
-
#
|
|
38
|
-
#
|
|
39
|
-
#
|
|
40
|
-
#
|
|
41
|
-
#
|
|
42
|
-
#
|
|
43
|
-
#
|
|
44
|
-
#
|
|
45
|
-
#
|
|
46
|
-
#
|
|
47
|
-
#
|
|
48
|
-
#
|
|
49
|
-
#
|
|
50
|
-
#
|
|
51
|
-
# the guided rewrite (unless skipped), code of that kind is written and run
|
|
52
|
-
# on the trace, and the save waits for both, so that entry's "rewrite" is
|
|
53
|
-
# already final. Its returned "codeDraft" hash says what happened:
|
|
54
|
-
# "requestedKind", "status" ("written", or "not_written" when no working
|
|
55
|
-
# code could be written and the assertion was saved as "judge" without
|
|
56
|
-
# code), and "reason" (why not, or nil). Every other entry's "codeDraft"
|
|
57
|
-
# is nil. At most 10 assertions per save may ask for code this way, and a
|
|
58
|
-
# save that asks for any waits up to five minutes.
|
|
32
|
+
# "code" is optional code that decides the assertion on a replay without
|
|
33
|
+
# the LLM judge: {"source" => ..., "spanNames" => [...]}. Send a "code"
|
|
34
|
+
# hash to set it, "code" => nil to remove it, or omit "code" to keep the
|
|
35
|
+
# current code. "source" is the body of an async TypeScript (or plain
|
|
36
|
+
# JavaScript) function called with spans (each {name, index, hasData}, in
|
|
37
|
+
# start order, without its data), input, and output. It reads span data
|
|
38
|
+
# with await named("span name") or await span.data(), with one second of
|
|
39
|
+
# compute and the data of at most 50 spans loaded within ten seconds. It
|
|
40
|
+
# returns "pass" or "fail", which decides the verdict with no judge call,
|
|
41
|
+
# or "defer" to hand the replay to the LLM judge, or {result, reason}. A
|
|
42
|
+
# defer may carry what the code found for the judge to read alongside the
|
|
43
|
+
# run: {result: "defer", reason, data}. A thrown error counts as "defer"
|
|
44
|
+
# with no data. "spanNames" lists every span a correct run is expected to
|
|
45
|
+
# produce. The code is run on the trace before saving and refused when it
|
|
46
|
+
# throws, times out, or returns anything other than a result. Returned
|
|
47
|
+
# assertions carry "code" (nil when the assertion has none) and
|
|
48
|
+
# "codeBrokenReason", which says why the code could not run on a replay.
|
|
59
49
|
#
|
|
60
50
|
# By default, after the save, Bitfab checks each assertion's text against its
|
|
61
51
|
# trace. When the text bundles two claims, adds a condition, points at a
|
|
@@ -90,8 +80,7 @@ module Bitfab
|
|
|
90
80
|
"updates" => updates.map { |update| with_new_category_key(update) },
|
|
91
81
|
"source" => source,
|
|
92
82
|
"guidedRewrite" => !skip_guided_rewrite
|
|
93
|
-
}
|
|
94
|
-
timeout: save_timeout(updates)
|
|
83
|
+
}
|
|
95
84
|
)["assertions"]
|
|
96
85
|
saved.is_a?(Array) ? saved.map { |assertion| with_both_category_keys(assertion) } : saved
|
|
97
86
|
end
|
|
@@ -102,18 +91,6 @@ module Bitfab
|
|
|
102
91
|
|
|
103
92
|
private
|
|
104
93
|
|
|
105
|
-
def save_timeout(updates)
|
|
106
|
-
asks = updates.any? do |update|
|
|
107
|
-
(update["assertions"] || update[:assertions] || []).any? { |assertion| asks_bitfab_to_write_code?(assertion) }
|
|
108
|
-
end
|
|
109
|
-
asks ? CODE_DRAFT_SAVE_TIMEOUT_SECONDS : nil
|
|
110
|
-
end
|
|
111
|
-
|
|
112
|
-
def asks_bitfab_to_write_code?(assertion)
|
|
113
|
-
kind = assertion["kind"] || assertion[:kind]
|
|
114
|
-
CODED_KINDS.include?(kind) && !assertion.key?("code") && !assertion.key?(:code)
|
|
115
|
-
end
|
|
116
|
-
|
|
117
94
|
def assertions_path(trace_id, suffix = "")
|
|
118
95
|
"/api/sdk/traces/#{URI.encode_www_form_component(trace_id).gsub("+", "%20")}/assertions#{suffix}"
|
|
119
96
|
end
|
|
@@ -4,6 +4,7 @@ module Bitfab
|
|
|
4
4
|
class SimulationPlan
|
|
5
5
|
CONTENT_KEYS = %w[input input_meta output output_meta input_serialized output_serialized replay_recording prompt].freeze
|
|
6
6
|
FRAMEWORKS = %w[openai-agents langgraph claude-agent-sdk vercel-ai].freeze
|
|
7
|
+
USAGE_FIELDS = %w[inputTokens outputTokens cachedInputTokens cacheReadTokens costUsd].freeze
|
|
7
8
|
READ_TIMEOUT = 5.0
|
|
8
9
|
REFRESH_SECONDS = 60.0
|
|
9
10
|
RETRY_SECONDS = 10.0
|
|
@@ -167,7 +168,7 @@ module Bitfab
|
|
|
167
168
|
names = @mutex.synchronize { @content_off&.fetch(key, nil) }
|
|
168
169
|
data = payload.dig("rawSpan", "span_data")
|
|
169
170
|
return payload unless data.is_a?(Hash) && names&.include?(data["name"])
|
|
170
|
-
return nil unless root?(payload) || data["error"]
|
|
171
|
+
return nil unless root?(payload) || data["error"] || usage?(data)
|
|
171
172
|
|
|
172
173
|
without_content(payload, data)
|
|
173
174
|
end
|
|
@@ -209,6 +210,18 @@ module Bitfab
|
|
|
209
210
|
payload.dig("rawSpan", "parent_id").nil?
|
|
210
211
|
end
|
|
211
212
|
|
|
213
|
+
def usage?(data)
|
|
214
|
+
contexts = data["contexts"] || data[:contexts]
|
|
215
|
+
return false unless contexts.is_a?(Array)
|
|
216
|
+
|
|
217
|
+
contexts.any? do |entry|
|
|
218
|
+
entry.is_a?(Hash) && USAGE_FIELDS.any? do |field|
|
|
219
|
+
value = entry.key?(field) ? entry[field] : entry[field.to_sym]
|
|
220
|
+
value.is_a?(Numeric)
|
|
221
|
+
end
|
|
222
|
+
end
|
|
223
|
+
end
|
|
224
|
+
|
|
212
225
|
def hold(entry)
|
|
213
226
|
@held << entry
|
|
214
227
|
start_reader([@refresh_after - now, 0].max) if @thread.nil? && !@stopped && !switched_off?
|
data/lib/bitfab/version.rb
CHANGED