Something went wrong. Try again.
A Kubernetes operator that runs Claude Code sessions on long-horizon work
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576package operator
import ( "slices" "sync")
// The causes of a pass, in simmer_passes_total, beside the name of each// watch (cluster.WatchNames) and cluster.FollowedSecret.const ( // causeStart is the first pass. causeStart = "start" // causeClock is a time a pass found, when something changes with no // event. causeClock = "clock" // causeRetry is the clock after a pass that failed. causeRetry = "retry" // causeEvent is a Signal's event that gave the pass work. causeEvent = "event" // causeSubscription is a Signal's subscription that connected or // ended. causeSubscription = "subscription" // causeDataPlane is a request from a turn, a probe, or a schedule. causeDataPlane = "dataplane" // causeFreed is a pass that ended a Session or a turn, which can free // a Duty that waited. causeFreed = "freed")
// Bell wakes the pass and remembers why. A burst of rings makes one// wake, which counts each distinct cause once.type Bell struct { rung chan struct{}
mu sync.Mutex causes map[string]bool}
func NewBell() *Bell { return &Bell{rung: make(chan struct{}, 1), causes: map[string]bool{}} }
// Ring wakes the pass, or adds its cause to a wake that is already due.// It sends under the lock, and take drains under the lock, so a wake is// pending exactly while causes wait to be taken. A send after the unlock// could land after a take had already counted its cause, and wake a// pass with no cause, which simmer_passes_total would not count.func (b *Bell) Ring(cause string) { b.mu.Lock() defer b.mu.Unlock() b.causes[cause] = true select { case b.rung <- struct{}{}: default: }}
// Rung delivers one value for each wake.func (b *Bell) Rung() <-chan struct{} { return b.rung }
// take answers the causes rung since the last take, and forgets them// with the wake that a ring after the loop's wake left pending.func (b *Bell) take() []string { b.mu.Lock() defer b.mu.Unlock() select { case <-b.rung: default: } causes := make([]string, 0, len(b.causes)) for cause := range b.causes { causes = append(causes, cause) } clear(b.causes) slices.Sort(causes) return causes}