返回 DeepSeek-Reasonix
provider_diagnostics.go
根目录 / internal / control / provider_diagnostics.go
1 package control
2
3 import (
4 "sync"
5
6 "reasonix/internal/provider"
7 )
8
9 type providerDiagnostic struct {
10 provider.RequestObservation
11 TurnID string `json:"turnId,omitempty"`
12 }
13
14 type providerDiagnosticBuffer struct {
15 mu sync.Mutex
16 requests []providerDiagnostic
17 dropped uint64
18 turns []providerDiagnosticTurn
19 }
20
21 func (c *Controller) recordProviderRequest(turnID string, observation provider.RequestObservation) {
22 b := &c.providerDiagnostics
23 b.mu.Lock()
24 defer b.mu.Unlock()
25 for i := range b.requests {
26 if b.requests[i].ID == observation.ID {
27 b.requests[i] = providerDiagnostic{observation, turnID}
28 return
29 }
30 }
31 // Updates for an evicted request cannot displace newer requests or inflate
32 // the dropped count. One entry per HTTP attempt, including all heartbeat reads.
33 if observation.Phase != "request_started" {
34 return
35 }
36 if len(b.requests) == 128 {
37 for i := range b.turns {
38 if b.turns[i].id == b.requests[0].TurnID {
39 b.turns[i].dropped++
40 break
41 }
42 }
43 copy(b.requests, b.requests[1:])
44 b.requests = b.requests[:127]
45 b.dropped++
46 }
47 b.requests = append(b.requests, providerDiagnostic{observation, turnID})
48 }
49
50 func (c *Controller) providerDiagnosticSnapshot() any {
51 b := &c.providerDiagnostics
52 b.mu.Lock()
53 defer b.mu.Unlock()
54 return struct {
55 Requests []providerDiagnostic `json:"requests"`
56 Dropped uint64 `json:"dropped"`
57 Scope string `json:"scope"`
58 }{append([]providerDiagnostic{}, b.requests...), b.dropped, "current controller lifetime; transport bytes include heartbeats, not proof of model progress; durable per-turn snapshots are in diagnostic/provider commit events"}
59 }
60
60 lines GO