| 1 | package control |
| 2 | |
| 3 | import "reasonix/internal/sessioninbox" |
| 4 | |
| 5 | // hasPendingUserWork reads only already-owned state and an already open inbox. |
| 6 | // It never creates an inbox or holds a Controller lock while taking an |
| 7 | // Agent/Store lock. A busy or unreadable durable inbox conservatively yields to |
| 8 | // potential user work, which must win over automatic Goal continuation. |
| 9 | func (c *Controller) hasPendingUserWork() bool { |
| 10 | if c == nil { |
| 11 | return false |
| 12 | } |
| 13 | c.mu.Lock() |
| 14 | canceling := c.cancelRequestedLocked() |
| 15 | parked := len(c.turns.pending) > 0 |
| 16 | executor := c.executor |
| 17 | c.mu.Unlock() |
| 18 | if canceling || parked { |
| 19 | return true |
| 20 | } |
| 21 | if executor != nil && executor.HasUnappliedSteer() { |
| 22 | return true |
| 23 | } |
| 24 | c.inbox.mu.Lock() |
| 25 | store := c.inbox.store |
| 26 | c.inbox.mu.Unlock() |
| 27 | if store == nil { |
| 28 | return false |
| 29 | } |
| 30 | snapshot, err := store.TryFreshSnapshot() |
| 31 | if err != nil || snapshot.Readonly { |
| 32 | return true |
| 33 | } |
| 34 | for _, item := range snapshot.Items { |
| 35 | switch item.State { |
| 36 | case sessioninbox.StateQueued, sessioninbox.StateBlocked, |
| 37 | sessioninbox.StateUncertain, sessioninbox.StateSteerAccepted: |
| 38 | return true |
| 39 | } |
| 40 | } |
| 41 | return false |
| 42 | } |
| 43 |