bitfab 0.75.3 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0e8124c4242b339613c4f4b714a68305748f2c32e2d894fd884250bc8c1e4036
4
- data.tar.gz: 9ed475b72f8f55b58334af9fe4feae30b07940aa9847c763fbccba227e21e41c
3
+ metadata.gz: e1cd0e2dfeb949aaf6704e07fb9ddf887cbda9ed15575a8991da34dcb5a6e46a
4
+ data.tar.gz: 2f559b3fff94599854d089482b43c61000ca15eadb8818e18f9764aa5c73e44d
5
5
  SHA512:
6
- metadata.gz: 7b1356376e48cbaf2a8889fdf7c26945ed21050035603ae480e00d6da313acff4292c981d7f9be751b3dcfd37aa954d5ab6619d492a4f0547f8af5f99faddfdb
7
- data.tar.gz: 15239246da620b92a67d87aa731974b22efe17fa97f2f25103491454a6ddd64327225a3b12f92f6df9ebc1770aceb82a7eb090a938ec31b95d32b0ba63ebd37e
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, and a span that recorded an error 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`.
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
 
@@ -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?
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Bitfab
4
- VERSION = "0.75.3"
4
+ VERSION = "0.75.4"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bitfab
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.75.3
4
+ version: 0.75.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Harvest Team