2026-07-17 08:37:52 +00:00
|
|
|
package pipeline
|
|
|
|
|
|
2026-11-22 02:24:45 +00:00
|
|
|
import "sync"
|
2026-07-17 08:37:52 +00:00
|
|
|
|
|
|
|
|
type lockedDebugRecorder struct {
|
|
|
|
|
inner DebugRecorder
|
|
|
|
|
mu sync.Mutex
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func synchronizedDebugRecorder(inner DebugRecorder) DebugRecorder {
|
|
|
|
|
if _, ok := inner.(*lockedDebugRecorder); ok {
|
|
|
|
|
return inner
|
|
|
|
|
}
|
|
|
|
|
return &lockedDebugRecorder{inner: inner}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SynchronizedDebugRecorder serializes access when a recorder is shared by
|
|
|
|
|
// pipeline operations and construction-injected LLM clients.
|
|
|
|
|
func SynchronizedDebugRecorder(inner DebugRecorder) DebugRecorder {
|
|
|
|
|
return synchronizedDebugRecorder(inner)
|
|
|
|
|
}
|
|
|
|
|
func (r *lockedDebugRecorder) Enabled() bool {
|
|
|
|
|
r.mu.Lock()
|
|
|
|
|
defer r.mu.Unlock()
|
|
|
|
|
return r.inner.Enabled()
|
|
|
|
|
}
|
|
|
|
|
func (r *lockedDebugRecorder) WriteJSON(name string, payload any) error {
|
|
|
|
|
r.mu.Lock()
|
|
|
|
|
defer r.mu.Unlock()
|
|
|
|
|
return r.inner.WriteJSON(name, payload)
|
|
|
|
|
}
|
|
|
|
|
func (r *lockedDebugRecorder) WriteBytes(name string, data []byte) error {
|
|
|
|
|
r.mu.Lock()
|
|
|
|
|
defer r.mu.Unlock()
|
|
|
|
|
return r.inner.WriteBytes(name, data)
|
|
|
|
|
}
|