Preserve independent background sessions through owner shutdown and idle cleanup
This commit is contained in:
@@ -55,8 +55,9 @@ type bridge struct {
|
||||
detached time.Time
|
||||
}
|
||||
|
||||
// Options describes one private, database-scoped bridge. MaxDetached bounds its
|
||||
// lifetime without a Pipelines client, even with an unresolved approval.
|
||||
// Options describes one private, database-scoped bridge. Positive timeout
|
||||
// values opt into detached expiry; zero keeps the original upstream connection
|
||||
// and its live sessions/callbacks until explicitly stopped.
|
||||
type Options struct {
|
||||
Dir, Upstream string
|
||||
Idle, MaxDetached time.Duration
|
||||
@@ -221,7 +222,7 @@ func (h *bridge) expire(idle, maxDetached time.Duration) {
|
||||
return
|
||||
case <-ticker.C:
|
||||
h.mu.Lock()
|
||||
expired := h.active == nil && (time.Since(h.detached) >= maxDetached || (len(h.pending) == 0 && time.Since(h.detached) >= idle))
|
||||
expired := h.active == nil && ((maxDetached > 0 && time.Since(h.detached) >= maxDetached) || (idle > 0 && len(h.pending) == 0 && time.Since(h.detached) >= idle))
|
||||
h.mu.Unlock()
|
||||
if expired {
|
||||
h.cancel()
|
||||
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Main is the detached bridge's command entry point.
|
||||
@@ -15,8 +14,8 @@ func Main(args []string) int {
|
||||
flags := flag.NewFlagSet("pipelines-codex-host", flag.ContinueOnError)
|
||||
dir := flags.String("dir", "", "private per-server host directory")
|
||||
upstream := flags.String("upstream", "", "existing Codex App Server Unix socket")
|
||||
idle := flags.Duration("idle", 20*time.Minute, "exit after this long detached without pending interactions")
|
||||
maxDetached := flags.Duration("max-detached", 24*time.Hour, "maximum detached lifetime, including pending interactions")
|
||||
idle := flags.Duration("idle", 0, "optional detached idle expiry (0 keeps the upstream session connection)")
|
||||
maxDetached := flags.Duration("max-detached", 0, "optional detached lifetime limit (0 keeps live sessions)")
|
||||
if err := flags.Parse(args); err != nil {
|
||||
return 2
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user