You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
**Gotcha**: `BlockRestrictedWrites()` silently drops writes to reserved keys. This prevents plugins from accidentally overwriting internal state.
247
247
248
+
**Hard rule — never store stream-sized data in `BifrostContext`.** Context holds small handles only: IDs, durations, booleans, interface pointers. Any per-request state that scales with stream content (chunk buffers, accumulated payloads, replay queues, large per-request slices/maps) must live in a top-level manager keyed by `RequestID`, not in `ctx`. Reference implementations:
249
+
250
+
-`framework/streaming.Accumulator` — owns a `sync.Map` of per-stream `StreamAccumulator` entries keyed by `RequestID`. Only `BifrostContextKeyAccumulatorID` (the ID string) is stored on the context; the chunk buffers live in the manager. The pause/resume gate (`gate.go`) extends the same per-stream entry with a state machine — again, **no buffer in ctx**.
251
+
- The `Tracer` interface (in ctx as a small pointer) is the access path for plugins/providers to reach managers without putting bulky data on the context itself.
252
+
253
+
When in doubt: if your new ctx key would hold a slice/map that grows with request content, route the storage through a manager and keep only the ID in ctx.
Copy file name to clipboardExpand all lines: core/schemas/bifrost.go
+1Lines changed: 1 addition & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -194,6 +194,7 @@ const (
194
194
BifrostContextKeyNumberOfRetriesBifrostContextKey="bifrost-number-of-retries"// int (to store the number of retries (set by bifrost - DO NOT SET THIS MANUALLY))
195
195
BifrostContextKeyFallbackIndexBifrostContextKey="bifrost-fallback-index"// int (to store the fallback index (set by bifrost - DO NOT SET THIS MANUALLY)) 0 for primary, 1 for first fallback, etc.
196
196
BifrostContextKeyStreamEndIndicatorBifrostContextKey="bifrost-stream-end-indicator"// bool (set by bifrost - DO NOT SET THIS MANUALLY))
197
+
BifrostContextKeyStreamGatedBifrostContextKey="bifrost-stream-gated"// bool (set by ctx.PauseStream/ResumeStream/EndStream when a plugin first engages the pause/resume gate; provider helpers use this as a fast-path check to skip Tracer.GateSend on streams that never engage the gate)
197
198
BifrostContextKeyStreamIdleTimeoutBifrostContextKey="bifrost-stream-idle-timeout"// time.Duration (per-chunk idle timeout for streaming)
198
199
BifrostContextKeySkipKeySelectionBifrostContextKey="bifrost-skip-key-selection"// bool (will pass an empty key to the provider)
0 commit comments