Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
MUL-8022: feat(daemon): persist idle and tool watchdog settings (#9258)
Jean Wood3c94e1cc1cf1
diff --git a/server/cmd/multica/cmd_config.go b/server/cmd/multica/cmd_config.goindex 6c52f1a67e..9a30b3316f 100644--- a/server/cmd/multica/cmd_config.go+++ b/server/cmd/multica/cmd_config.go@@ -40,6 +40,8 @@ var configSetSupportedKeys = []string{"ws_claim_poll_interval","heartbeat_interval","agent_timeout",+ "agent_idle_watchdog",+ "agent_tool_watchdog","codex_semantic_inactivity_timeout","codex_handshake_timeout","disable_auto_update",@@ -53,19 +55,19 @@ var configSetCmd = &cobra.Command{Long: "Supported keys: " +"server_url, app_url, workspace_id, " +"device_name, runtime_name, workspaces_root, max_concurrent_tasks, poll_interval, ws_claim_poll_interval, " +- "heartbeat_interval, agent_timeout, " ++ "heartbeat_interval, agent_timeout, agent_idle_watchdog, agent_tool_watchdog, " +"codex_semantic_inactivity_timeout, codex_handshake_timeout, " +"disable_auto_update, auto_update_check_interval, disable_auto_reload.\n\n" +"The daemon keys (device_name, runtime_name, workspaces_root, max_concurrent_tasks, " +- "poll_interval, ws_claim_poll_interval, heartbeat_interval, agent_timeout, " ++ "poll_interval, ws_claim_poll_interval, heartbeat_interval, agent_timeout, agent_idle_watchdog, agent_tool_watchdog, " +"codex_semantic_inactivity_timeout, codex_handshake_timeout, " +"disable_auto_update, auto_update_check_interval, disable_auto_reload) mirror their " +"--flag / env counterparts and are read by `daemon start` when " +"neither the flag nor the env var is set. " +"Precedence: --flag > MULTICA_… env > config.json > built-in default. " +- "Duration keys take a positive Go duration (e.g. '10s', '500ms', '1m30s'); " +- "'0s' and negative values are rejected — except agent_timeout, where " +- "'0s' is meaningful and explicitly disables the wall-clock cap. " ++ "Duration keys take a Go duration (e.g. '10s', '500ms', '1m30s'); " ++ "most keys require a positive value, while agent_timeout, agent_idle_watchdog, " ++ "and agent_tool_watchdog also accept '0s' to disable their limit. " +"disable_auto_update and disable_auto_reload take 'true' or 'false' " +"(single-direction: setting one to 'true' turns that behavior off, " +"'false' clears the override so env/default decides). Pass an empty " +@@ -106,6 +108,8 @@ func runConfigShow(cmd *cobra.Command, _ []string) error {fmt.Fprintf(os.Stdout, "%-34s %s\n", "ws_claim_poll_interval:", valueOrDefault(cfg.WSClaimPollInterval, "(not set)"))fmt.Fprintf(os.Stdout, "%-34s %s\n", "heartbeat_interval:", valueOrDefault(cfg.HeartbeatInterval, "(not set)"))fmt.Fprintf(os.Stdout, "%-34s %s\n", "agent_timeout:", agentTimeoutDisplay(cfg.AgentTimeout))+ fmt.Fprintf(os.Stdout, "%-34s %s\n", "agent_idle_watchdog:", valueOrDefault(cfg.AgentIdleWatchdog, "(not set)"))+ fmt.Fprintf(os.Stdout, "%-34s %s\n", "agent_tool_watchdog:", valueOrDefault(cfg.AgentToolWatchdog, "(not set)"))fmt.Fprintf(os.Stdout, "%-34s %s\n", "codex_semantic_inactivity_timeout:", valueOrDefault(cfg.CodexSemanticInactivityTimeout, "(not set)"))fmt.Fprintf(os.Stdout, "%-34s %s\n", "codex_handshake_timeout:", valueOrDefault(cfg.CodexHandshakeTimeout, "(not set)"))fmt.Fprintf(os.Stdout, "%-34s %t\n", "disable_auto_update:", cfg.DisableAutoUpdate)@@ -234,6 +238,14 @@ func applyConfigSet(cfg *cli.CLIConfig, key, value string) error {}s := valuecfg.AgentTimeout = &s+ case "agent_idle_watchdog":+ if err := assignNonNegativeDuration(&cfg.AgentIdleWatchdog, key, value); err != nil {+ return err+ }+ case "agent_tool_watchdog":+ if err := assignNonNegativeDuration(&cfg.AgentToolWatchdog, key, value); err != nil {+ return err+ }case "codex_semantic_inactivity_timeout":if err := assignPositiveDuration(&cfg.CodexSemanticInactivityTimeout, key, value); err != nil {return err@@ -296,6 +308,23 @@ func assignPositiveDuration(dst *string, key, value string) error {return nil}+func assignNonNegativeDuration(dst *string, key, value string) error {+ if value == "" {+ *dst = ""+ return nil+ }+ normalized := strings.TrimSpace(value)+ d, err := time.ParseDuration(normalized)+ if err != nil {+ return fmt.Errorf("%s must be a Go duration (e.g. 15m, 0s): %w", key, err)+ }+ if d < 0 {+ return fmt.Errorf("%s must be >= 0 (got %s); use `config set %s \"\"` to clear it", key, d, key)+ }+ *dst = normalized+ return nil+}+// agentTimeoutDisplay renders the tri-state agent_timeout value for// `config show`. nil = not persisted (fall through to env/default);// non-nil "0s" = explicitly disabled; any other non-nil = the persisteddiff --git a/server/cmd/multica/cmd_config_test.go b/server/cmd/multica/cmd_config_test.goindex da37f56f35..dbd3f2e6e9 100644--- a/server/cmd/multica/cmd_config_test.go+++ b/server/cmd/multica/cmd_config_test.go@@ -293,6 +293,30 @@ func TestApplyConfigSetPositiveDurationRoundTripsToDaemonResolver(t *testing.T)}}+func TestApplyConfigSetWatchdogDurationsAllowZero(t *testing.T) {+ cases := []string{"agent_idle_watchdog", "agent_tool_watchdog"}+ for _, key := range cases {+ t.Run(key, func(t *testing.T) {+ cfg := cli.CLIConfig{}+ if err := applyConfigSet(&cfg, key, "15m"); err != nil {+ t.Fatalf("set positive duration: %v", err)+ }+ if err := applyConfigSet(&cfg, key, "0s"); err != nil {+ t.Fatalf("set zero duration: %v", err)+ }+ if err := applyConfigSet(&cfg, key, ""); err != nil {+ t.Fatalf("clear duration: %v", err)+ }+ if got := cfg.AgentIdleWatchdog + cfg.AgentToolWatchdog; got != "" {+ t.Fatalf("cleared config = %q, want empty", got)+ }+ if err := applyConfigSet(&cfg, key, "-1s"); err == nil {+ t.Fatal("expected negative duration to be rejected")+ }+ })+ }+}+// TestApplyConfigSetAgentTimeoutTriState pins the agent_timeout// pointer-based semantics: "" clears, "0s" persists as an explicit// "disabled" sentinel, positive durations persist as-is. Negativediff --git a/server/cmd/multica/cmd_daemon.go b/server/cmd/multica/cmd_daemon.goindex 56aa14f291..d1f4ac89e7 100644--- a/server/cmd/multica/cmd_daemon.go+++ b/server/cmd/multica/cmd_daemon.go@@ -106,6 +106,8 @@ func init() {f.Duration("ws-claim-poll-interval", 0, "Healthy WebSocket claim safety-poll upper bound (env: MULTICA_DAEMON_WS_CLAIM_POLL_INTERVAL)")f.Duration("heartbeat-interval", 0, "Heartbeat interval (env: MULTICA_DAEMON_HEARTBEAT_INTERVAL)")f.Duration("agent-timeout", 0, "Absolute per-run wall-clock cap; 0 = no cap, rely on the watchdogs (env: MULTICA_AGENT_TIMEOUT)")+ f.Duration("agent-idle-watchdog", 0, "No-message watchdog window; 0 = disabled (env: MULTICA_AGENT_IDLE_WATCHDOG)")+ f.Duration("agent-tool-watchdog", 0, "Silent in-flight tool watchdog window; 0 = disabled (env: MULTICA_AGENT_TOOL_WATCHDOG)")f.Duration("codex-semantic-inactivity-timeout", 0, "Codex semantic inactivity timeout (env: MULTICA_CODEX_SEMANTIC_INACTIVITY_TIMEOUT)")f.Duration("codex-handshake-timeout", 0, "Codex app-server startup RPC timeout (env: MULTICA_CODEX_HANDSHAKE_TIMEOUT)")f.Int("max-concurrent-tasks", 0, "Maximum concurrent runs (env: MULTICA_DAEMON_MAX_CONCURRENT_TASKS)")@@ -130,6 +132,8 @@ func init() {rf.Duration("ws-claim-poll-interval", 0, "Healthy WebSocket claim safety-poll upper bound (env: MULTICA_DAEMON_WS_CLAIM_POLL_INTERVAL)")rf.Duration("heartbeat-interval", 0, "Heartbeat interval (env: MULTICA_DAEMON_HEARTBEAT_INTERVAL)")rf.Duration("agent-timeout", 0, "Absolute per-run wall-clock cap; 0 = no cap, rely on the watchdogs (env: MULTICA_AGENT_TIMEOUT)")+ rf.Duration("agent-idle-watchdog", 0, "No-message watchdog window; 0 = disabled (env: MULTICA_AGENT_IDLE_WATCHDOG)")+ rf.Duration("agent-tool-watchdog", 0, "Silent in-flight tool watchdog window; 0 = disabled (env: MULTICA_AGENT_TOOL_WATCHDOG)")rf.Duration("codex-semantic-inactivity-timeout", 0, "Codex semantic inactivity timeout (env: MULTICA_CODEX_SEMANTIC_INACTIVITY_TIMEOUT)")rf.Duration("codex-handshake-timeout", 0, "Codex app-server startup RPC timeout (env: MULTICA_CODEX_HANDSHAKE_TIMEOUT)")rf.Int("max-concurrent-tasks", 0, "Maximum concurrent runs (env: MULTICA_DAEMON_MAX_CONCURRENT_TASKS)")@@ -903,6 +907,14 @@ func buildDaemonStartArgs(cmd *cobra.Command) []string {d, _ := cmd.Flags().GetDuration("agent-timeout")args = append(args, "--agent-timeout", d.String())}+ if cmd.Flags().Changed("agent-idle-watchdog") {+ d, _ := cmd.Flags().GetDuration("agent-idle-watchdog")+ args = append(args, "--agent-idle-watchdog", d.String())+ }+ if cmd.Flags().Changed("agent-tool-watchdog") {+ d, _ := cmd.Flags().GetDuration("agent-tool-watchdog")+ args = append(args, "--agent-tool-watchdog", d.String())+ }if d, _ := cmd.Flags().GetDuration("codex-semantic-inactivity-timeout"); d > 0 {args = append(args, "--codex-semantic-inactivity-timeout", d.String())}@@ -1049,6 +1061,20 @@ func runDaemonForeground(cmd *cobra.Command) error {if agentTimeoutOverride != nil {overrides.AgentTimeout = agentTimeoutOverride}+ idleWatchdogOverride, err := resolveDaemonWatchdogOverride(cmd, "agent-idle-watchdog", "MULTICA_AGENT_IDLE_WATCHDOG", fileCfg.AgentIdleWatchdog)+ if err != nil {+ return err+ }+ if idleWatchdogOverride != nil {+ overrides.AgentIdleWatchdog = idleWatchdogOverride+ }+ toolWatchdogOverride, err := resolveDaemonWatchdogOverride(cmd, "agent-tool-watchdog", "MULTICA_AGENT_TOOL_WATCHDOG", fileCfg.AgentToolWatchdog)+ if err != nil {+ return err+ }+ if toolWatchdogOverride != nil {+ overrides.AgentToolWatchdog = toolWatchdogOverride+ }semanticFlag, _ := cmd.Flags().GetDuration("codex-semantic-inactivity-timeout")semanticOverride, err := resolveDaemonDurationOverride(semanticFlag, "MULTICA_CODEX_SEMANTIC_INACTIVITY_TIMEOUT", fileCfg.CodexSemanticInactivityTimeout)if err != nil {@@ -1836,6 +1862,32 @@ func resolveDaemonAgentTimeoutOverride(cmd *cobra.Command, envName string, cfgVareturn &parsed, nil}+// resolveDaemonWatchdogOverride preserves an explicit zero, which disables+// the selected watchdog.+func resolveDaemonWatchdogOverride(cmd *cobra.Command, flagName, envName, cfgValue string) (*time.Duration, error) {+ if cmd.Flags().Changed(flagName) {+ d, _ := cmd.Flags().GetDuration(flagName)+ if d < 0 {+ return nil, fmt.Errorf("--%s must be >= 0", flagName)+ }+ return &d, nil+ }+ if !envUnset(envName) {+ return nil, nil+ }+ if cfgValue == "" {+ return nil, nil+ }+ parsed, err := time.ParseDuration(strings.TrimSpace(cfgValue))+ if err != nil {+ return nil, fmt.Errorf("config value %q for %s is not a valid duration: %w", cfgValue, envName, err)+ }+ if parsed < 0 {+ return nil, fmt.Errorf("config value %q for %s must be >= 0", cfgValue, envName)+ }+ return &parsed, nil+}+// resolveDaemonDisableSignal resolves a single-direction disable signal —// auto-update (--no-auto-update) and auto-reload (--no-auto-reload) share the// shape. Precedence, using auto-update as the example:diff --git a/server/cmd/multica/cmd_daemon_precedence_test.go b/server/cmd/multica/cmd_daemon_precedence_test.goindex 60fe2a6302..4730696c3c 100644--- a/server/cmd/multica/cmd_daemon_precedence_test.go+++ b/server/cmd/multica/cmd_daemon_precedence_test.go@@ -256,6 +256,63 @@ func TestResolveDaemonAgentTimeoutOverridePrecedence(t *testing.T) {}}+func TestResolveDaemonWatchdogOverridePrecedence(t *testing.T) {+ const envName = "TEST_MULTICA_WATCHDOG"+ newCmd := func(changed bool, value time.Duration) *cobra.Command {+ cmd := &cobra.Command{Use: "test"}+ cmd.Flags().Duration("watchdog", 0, "")+ if changed {+ _ = cmd.Flags().Set("watchdog", value.String())+ }+ return cmd+ }+ cases := []struct {+ name string+ flagChgd bool+ flag time.Duration+ env string+ cfg string+ want *time.Duration+ errSub string+ }{+ {name: "explicit zero flag", flagChgd: true, want: durationPtr(0)},+ {name: "cfg positive", cfg: "15m", want: durationPtr(15 * time.Minute)},+ {name: "env suppresses cfg", env: "20m", cfg: "15m"},+ {name: "cfg zero", cfg: "0s", want: durationPtr(0)},+ {name: "cfg invalid", cfg: "bad", errSub: "not a valid duration"},+ }+ for _, tc := range cases {+ t.Run(tc.name, func(t *testing.T) {+ if tc.env == "" {+ t.Setenv(envName, "")+ } else {+ t.Setenv(envName, tc.env)+ }+ got, err := resolveDaemonWatchdogOverride(newCmd(tc.flagChgd, tc.flag), "watchdog", envName, tc.cfg)+ if tc.errSub != "" {+ if err == nil || !strings.Contains(err.Error(), tc.errSub) {+ t.Fatalf("error = %v, want %q", err, tc.errSub)+ }+ return+ }+ if err != nil {+ t.Fatalf("unexpected error: %v", err)+ }+ if tc.want == nil {+ if got != nil {+ t.Fatalf("got %v, want nil", got)+ }+ return+ }+ if got == nil || *got != *tc.want {+ t.Fatalf("got %v, want %v", got, *tc.want)+ }+ })+ }+}++func durationPtr(value time.Duration) *time.Duration { return &value }+// TestResolveDaemonDisableSignalPrecedence pins the single-direction disable// signal shared by --no-auto-update and --no-auto-reload: flag OR falsy env OR// persisted cfg=true all disable; a truthy env leaves the override off sodiff --git a/server/internal/cli/config.go b/server/internal/cli/config.goindex edcd2b4e5d..af59f70e44 100644--- a/server/internal/cli/config.go+++ b/server/internal/cli/config.go@@ -104,6 +104,13 @@ type CLIConfig struct {// DefaultAgentTimeout.AgentTimeout *string `json:"agent_timeout,omitempty"`+ // AgentIdleWatchdog is the no-message safety window. Empty means unset;+ // 0s disables the watchdog.+ AgentIdleWatchdog string `json:"agent_idle_watchdog,omitempty"`+ // AgentToolWatchdog is the maximum silent in-flight tool window. Empty+ // means unset; 0s disables the tool-specific bound.+ AgentToolWatchdog string `json:"agent_tool_watchdog,omitempty"`+// CodexSemanticInactivityTimeout is the Codex-specific inactivity// watchdog window (Go duration string). Persist-once semantics match// PollInterval: empty = not set, positive = use this value.diff --git a/server/internal/daemon/config.go b/server/internal/daemon/config.goindex 696c588249..adece8c188 100644--- a/server/internal/daemon/config.go+++ b/server/internal/daemon/config.go@@ -178,6 +178,8 @@ type Overrides struct {// AgentTimeout is a pointer so an explicit `--agent-timeout 0` (no cap) is// distinguishable from "flag not passed". nil = use env/default.AgentTimeout *time.Duration+ AgentIdleWatchdog *time.Duration+ AgentToolWatchdog *time.DurationCodexSemanticInactivityTimeout time.DurationCodexHandshakeTimeout time.DurationMaxConcurrentTasks int@@ -337,6 +339,9 @@ func LoadConfig(overrides Overrides) (Config, error) {if err != nil {return Config{}, err}+ if overrides.AgentIdleWatchdog != nil {+ agentIdleWatchdog = *overrides.AgentIdleWatchdog+ }// MULTICA_OPENCODE_IDLE_WATCHDOG narrows the no-message window for// OpenCode's streamed model responses. Zero removes the provider-specific// override and falls back to MULTICA_AGENT_IDLE_WATCHDOG; positive values@@ -375,6 +380,9 @@ func LoadConfig(overrides Overrides) (Config, error) {if err != nil {return Config{}, err}+ if overrides.AgentToolWatchdog != nil {+ agentToolWatchdog = *overrides.AgentToolWatchdog+ }// Codex runs a semantic-inactivity timer of its own inside the app-server// protocol, and unlike the daemon's watchdog it is NOT tool-aware: a