返回 DeepSeek-Reasonix
inbox_drain.go
根目录 / internal / acp / inbox_drain.go
1 package acp
2
3 import (
4 "context"
5 "errors"
6
7 "reasonix/internal/sessioninbox"
8 )
9
10 type acpInboxController interface {
11 InboxSnapshot() sessioninbox.InboxSnapshot
12 RunInboxTurn(context.Context, string) error
13 }
14
15 func drainACPInbox(ctx context.Context, ctrl acpController, runErr error) error {
16 if runErr != nil {
17 return runErr
18 }
19 inbox, ok := ctrl.(acpInboxController)
20 if !ok {
21 return nil
22 }
23 for {
24 snap := inbox.InboxSnapshot()
25 if snap.Paused {
26 return nil
27 }
28 nextID := ""
29 for _, item := range snap.Items {
30 if item.State == sessioninbox.StateQueued {
31 nextID = item.ID
32 break
33 }
34 }
35 if nextID == "" {
36 return nil
37 }
38 err := inbox.RunInboxTurn(ctx, nextID)
39 if errors.Is(err, sessioninbox.ErrNotFound) || errors.Is(err, sessioninbox.ErrInvalidState) {
40 // A concurrent queue edit won the claim; refresh the FIFO snapshot.
41 continue
42 }
43 if err != nil {
44 return err
45 }
46 }
47 }
48
48 lines GO