Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

MUL-6019: fix(codex): add MULTICA_CODEX_FIRST_TURN_TIMEOUT to raise the first-turn ceiling (#6753)

Danila Katalshov3025c3802729
diff --git a/apps/docs/content/docs/environment-variables.ja.mdx b/apps/docs/content/docs/environment-variables.ja.mdx
index 66b3c33acc..b76acb9c89 100644
--- a/apps/docs/content/docs/environment-variables.ja.mdx
+++ b/apps/docs/content/docs/environment-variables.ja.mdx
@@ -202,6 +202,7 @@ API key と base URL の両方が空の場合、サーバーサイド LLM 生成
| `MULTICA_AGENT_TOOL_WATCHDOG` | `2h` | 単一のツール呼び出しが静穏なままでいられる上限 |
| `MULTICA_OPENCODE_IDLE_WATCHDOG` | `10m` | OpenCode 専用の静穏しきい値 |
| `MULTICA_CODEX_SEMANTIC_INACTIVITY_TIMEOUT` | `10m` | Codex のセマンティック静穏しきい値 |
+| `MULTICA_CODEX_FIRST_TURN_TIMEOUT` | `0` | Codex 初回ターンの無進捗上限を明示的に上書き;`0` はデフォルトを維持。実効の初回ターン待機は依然として `MULTICA_CODEX_SEMANTIC_INACTIVITY_TIMEOUT` と全体の実行タイムアウトに制限される——`MULTICA_CODEX_SEMANTIC_INACTIVITY_TIMEOUT` をこの値より厳密に大きく(余裕を持たせて)設定すること。さもないと待機はその値で打ち切られ、モデルカタログの起動リトライがスキップされる。同値では不十分:セマンティックタイマーが先に起動するため、同値の場合でもリトライが失われることがある |
| `MULTICA_CODEX_HANDSHAKE_TIMEOUT` | `30s` | Codex app-server 起動ハンドシェイクの上限 |
| `MULTICA_DAEMON_AUTO_UPDATE` | Cloud は `true`、セルフホストは `false` | CLI の更新を自動でチェックして適用するか |
| `MULTICA_DAEMON_AUTO_UPDATE_INTERVAL` | `6h` | 更新チェックの間隔 |
diff --git a/apps/docs/content/docs/environment-variables.ko.mdx b/apps/docs/content/docs/environment-variables.ko.mdx
index 631dc4d9f6..b96e59685c 100644
--- a/apps/docs/content/docs/environment-variables.ko.mdx
+++ b/apps/docs/content/docs/environment-variables.ko.mdx
@@ -202,6 +202,7 @@ API key와 base URL이 모두 비어 있으면 서버 측 LLM 생성이 꺼지
| `MULTICA_AGENT_TOOL_WATCHDOG` | `2h` | 단일 도구 호출이 계속 무응답인 시간 상한 |
| `MULTICA_OPENCODE_IDLE_WATCHDOG` | `10m` | OpenCode 전용 무응답 기준값 |
| `MULTICA_CODEX_SEMANTIC_INACTIVITY_TIMEOUT` | `10m` | Codex 의미 활동 없음 기준값 |
+| `MULTICA_CODEX_FIRST_TURN_TIMEOUT` | `0` | Codex 첫 턴 무진행 상한의 명시적 재정의; `0` 은 기본값 유지. 실제 첫 턴 대기는 여전히 `MULTICA_CODEX_SEMANTIC_INACTIVITY_TIMEOUT` 및 전체 실행 타임아웃으로 제한됨 — `MULTICA_CODEX_SEMANTIC_INACTIVITY_TIMEOUT` 을 이 값보다 엄격히 크게(여유를 두고) 설정해야 하며, 그렇지 않으면 대기가 그 값으로 잘리고 모델 카탈로그 시작 재시도가 건너뛰어짐. 값이 같으면 충분하지 않음: 의미 타이머가 먼저 시작되므로 값이 같을 때도 재시도가 손실될 수 있음 |
| `MULTICA_CODEX_HANDSHAKE_TIMEOUT` | `30s` | Codex app-server 시작 handshake 상한 |
| `MULTICA_DAEMON_AUTO_UPDATE` | Cloud `true`, 자체 호스팅 `false` | CLI 자동 확인 및 업데이트 여부 |
| `MULTICA_DAEMON_AUTO_UPDATE_INTERVAL` | `6h` | 업데이트 확인 간격 |
diff --git a/apps/docs/content/docs/environment-variables.mdx b/apps/docs/content/docs/environment-variables.mdx
index 5037b45bbc..33bb23da58 100644
--- a/apps/docs/content/docs/environment-variables.mdx
+++ b/apps/docs/content/docs/environment-variables.mdx
@@ -202,6 +202,7 @@ The variables below are read on the computer that runs your agents, not in the A
| `MULTICA_AGENT_TOOL_WATCHDOG` | `2h` | Silence ceiling for a single tool call |
| `MULTICA_OPENCODE_IDLE_WATCHDOG` | `10m` | OpenCode-specific silence threshold |
| `MULTICA_CODEX_SEMANTIC_INACTIVITY_TIMEOUT` | `10m` | Codex semantic-silence threshold |
+| `MULTICA_CODEX_FIRST_TURN_TIMEOUT` | `0` | Explicit override for the Codex first-turn no-progress ceiling; `0` keeps the default. The effective first-turn wait stays bounded by `MULTICA_CODEX_SEMANTIC_INACTIVITY_TIMEOUT` and the overall execution timeout — set `MULTICA_CODEX_SEMANTIC_INACTIVITY_TIMEOUT` strictly above this value (with some margin), or the wait is truncated to it and the model-catalog startup retry is skipped. Equal values are not enough: the semantic timer is armed first, so at equal durations the retry can still be lost |
| `MULTICA_CODEX_HANDSHAKE_TIMEOUT` | `30s` | Codex app-server startup handshake ceiling |
| `MULTICA_DAEMON_AUTO_UPDATE` | Cloud `true`; self-hosted `false` | Whether to check for and apply CLI updates automatically |
| `MULTICA_DAEMON_AUTO_UPDATE_INTERVAL` | `6h` | Update check interval |
diff --git a/apps/docs/content/docs/environment-variables.zh.mdx b/apps/docs/content/docs/environment-variables.zh.mdx
index b5597b7a27..311c1e9e9a 100644
--- a/apps/docs/content/docs/environment-variables.zh.mdx
+++ b/apps/docs/content/docs/environment-variables.zh.mdx
@@ -202,6 +202,7 @@ API key 与 base URL 都为空时,服务端 LLM 生成关闭,调用方会使
| `MULTICA_AGENT_TOOL_WATCHDOG` | `2h` | 单个工具调用持续静默的上限 |
| `MULTICA_OPENCODE_IDLE_WATCHDOG` | `10m` | OpenCode 专用静默阈值 |
| `MULTICA_CODEX_SEMANTIC_INACTIVITY_TIMEOUT` | `10m` | Codex 语义静默阈值 |
+| `MULTICA_CODEX_FIRST_TURN_TIMEOUT` | `0` | 显式覆盖 Codex 首轮无进展上限;`0` 保持默认值。实际首轮等待仍受 `MULTICA_CODEX_SEMANTIC_INACTIVITY_TIMEOUT` 和总执行超时限制——需将 `MULTICA_CODEX_SEMANTIC_INACTIVITY_TIMEOUT` 设为严格大于此值(并留出余量),否则等待会被截断至该值,且会跳过模型目录启动重试。设为相等还不够:语义计时器先启动,两者相等时仍可能丢失该重试 |
| `MULTICA_CODEX_HANDSHAKE_TIMEOUT` | `30s` | Codex app-server 启动握手上限 |
| `MULTICA_DAEMON_AUTO_UPDATE` | Cloud `true`;自托管 `false` | 是否自动检查并更新 CLI |
| `MULTICA_DAEMON_AUTO_UPDATE_INTERVAL` | `6h` | 检查更新的间隔 |
diff --git a/server/internal/daemon/config.go b/server/internal/daemon/config.go
index f4c85368ce..80b4805822 100644
--- a/server/internal/daemon/config.go
+++ b/server/internal/daemon/config.go
@@ -117,15 +117,21 @@ type Config struct {
HeartbeatInterval time.Duration
AgentTimeout time.Duration
CodexSemanticInactivityTimeout time.Duration
- CodexHandshakeTimeout time.Duration
- OpenCodeIdleWatchdog time.Duration // OpenCode-specific no-message window; 0 falls back to AgentIdleWatchdog and values above it cannot extend the global bound
- AgentIdleWatchdog time.Duration // force-stop a run when the backend goes silent this long with an empty queue (0 = disabled)
- AgentToolWatchdog time.Duration // force-stop a run when a single tool call stays in flight (silent) this long (0 = disabled); backstop for hung tools now that there is no wall-clock cap
- ClaudeArgs []string
- CodexArgs []string
- CodebuddyArgs []string
- QwenArgs []string
- QwenpawArgs []string
+ // CodexFirstTurnNoProgressTimeout is an explicit override for the Codex
+ // first-turn no-progress ceiling (MULTICA_CODEX_FIRST_TURN_TIMEOUT). 0 means
+ // unset: the backend keeps its default ceiling, which CodexSemanticInactivityTimeout
+ // can only shrink. A positive value raises (or lowers) that ceiling outright,
+ // for app-servers that are legitimately slow to their first event (GH #3262).
+ CodexFirstTurnNoProgressTimeout time.Duration
+ CodexHandshakeTimeout time.Duration
+ OpenCodeIdleWatchdog time.Duration // OpenCode-specific no-message window; 0 falls back to AgentIdleWatchdog and values above it cannot extend the global bound
+ AgentIdleWatchdog time.Duration // force-stop a run when the backend goes silent this long with an empty queue (0 = disabled)
+ AgentToolWatchdog time.Duration // force-stop a run when a single tool call stays in flight (silent) this long (0 = disabled); backstop for hung tools now that there is no wall-clock cap
+ ClaudeArgs []string
+ CodexArgs []string
+ CodebuddyArgs []string
+ QwenArgs []string
+ QwenpawArgs []string
// ProfileCommandOverrides maps a custom runtime profile_id -> the absolute
// executable path to use for that profile on THIS machine (MUL-3284).
@@ -294,6 +300,36 @@ func LoadConfig(overrides Overrides) (Config, error) {
codexSemanticInactivityTimeout = overrides.CodexSemanticInactivityTimeout
}
+ // 0 = unset: the codex backend keeps its default first-turn ceiling. A
+ // positive value is an explicit operator override (GH #3262 / #5959).
+ codexFirstTurnNoProgressTimeout, err := durationFromEnv("MULTICA_CODEX_FIRST_TURN_TIMEOUT", 0)
+ if err != nil {
+ return Config{}, err
+ }
+ // The first-turn override only raises the first-turn watchdog, not the
+ // concurrent semantic-inactivity timer that the same first status:running
+ // arms — and the semantic timer is armed FIRST (codex.go resets it before
+ // creating the first-turn timer). When the override is >= the semantic
+ // timeout the effective first-item wait is truncated to the semantic
+ // timeout: at equal durations the semantic deadline is reached first, and
+ // even when both fire together Go's select does not deterministically
+ // favour the first-turn branch. The failure is then classified as semantic
+ // inactivity rather than first-turn no-progress, which disables the
+ // transient model-catalog startup retry (GH #3291). Warn unless the semantic
+ // timeout is set strictly above the first-turn timeout.
+ if codexFirstTurnNoProgressTimeout > 0 {
+ effectiveSemanticTimeout := codexSemanticInactivityTimeout
+ if effectiveSemanticTimeout <= 0 {
+ effectiveSemanticTimeout = DefaultCodexSemanticInactivityTimeout
+ }
+ if codexFirstTurnNoProgressTimeout >= effectiveSemanticTimeout {
+ slog.Warn("MULTICA_CODEX_FIRST_TURN_TIMEOUT is greater than or equal to the semantic-inactivity timeout; the effective first-turn wait is truncated to the semantic timeout and the model-catalog startup retry is disabled. Because the semantic timer is armed first and equal durations do not deterministically favour the first-turn deadline, set MULTICA_CODEX_SEMANTIC_INACTIVITY_TIMEOUT strictly above MULTICA_CODEX_FIRST_TURN_TIMEOUT (with some margin) to preserve it.",
+ "first_turn_timeout", codexFirstTurnNoProgressTimeout.String(),
+ "semantic_inactivity_timeout", effectiveSemanticTimeout.String(),
+ )
+ }
+ }
+
codexHandshakeTimeout, err := durationFromEnv("MULTICA_CODEX_HANDSHAKE_TIMEOUT", DefaultCodexHandshakeTimeout)
if err != nil {
return Config{}, err
@@ -473,45 +509,46 @@ func LoadConfig(overrides Overrides) (Config, error) {
}
return Config{
- ServerBaseURL: serverBaseURL,
- DaemonID: daemonID,
- LegacyDaemonIDs: legacyDaemonIDs,
- DeviceName: deviceName,
- RuntimeName: runtimeName,
- Profile: profile,
- Agents: agents,
- WorkspacesRoot: workspacesRoot,
- KeepEnvAfterTask: keepEnv,
- GCEnabled: gcEnabled,
- GCInterval: gcInterval,
- GCTTL: gcTTL,
- GCOrphanTTL: gcOrphanTTL,
- GCArtifactTTL: gcArtifactTTL,
- GCArtifactPatterns: gcArtifactPatterns,
- GCRepoTTL: gcRepoTTL,
- GCRepoMaintenanceEnabled: gcRepoMaintenanceEnabled,
- GCCodexSessionTTL: gcCodexSessionTTL,
- GCHermesMemoryTTL: gcHermesMemoryTTL,
- GCHermesSessionTTL: gcHermesSessionTTL,
- AutoUpdateEnabled: autoUpdateEnabled,
- AutoUpdateCheckInterval: autoUpdateInterval,
- AutoReloadEnabled: autoReloadEnabled,
- HealthPort: healthPort,
- MaxConcurrentTasks: maxConcurrentTasks,
- PollInterval: pollInterval,
- HeartbeatInterval: heartbeatInterval,
- AgentTimeout: agentTimeout,
- CodexSemanticInactivityTimeout: codexSemanticInactivityTimeout,
- CodexHandshakeTimeout: codexHandshakeTimeout,
- OpenCodeIdleWatchdog: openCodeIdleWatchdog,
- AgentIdleWatchdog: agentIdleWatchdog,
- AgentToolWatchdog: agentToolWatchdog,
- ClaudeArgs: claudeArgs,
- CodexArgs: codexArgs,
- CodebuddyArgs: codebuddyArgs,
- QwenArgs: qwenArgs,
- QwenpawArgs: qwenpawArgs,
- ProfileCommandOverrides: profileCommandOverrides,
+ ServerBaseURL: serverBaseURL,
+ DaemonID: daemonID,
+ LegacyDaemonIDs: legacyDaemonIDs,
+ DeviceName: deviceName,
+ RuntimeName: runtimeName,
+ Profile: profile,
+ Agents: agents,
+ WorkspacesRoot: workspacesRoot,
+ KeepEnvAfterTask: keepEnv,
+ GCEnabled: gcEnabled,
+ GCInterval: gcInterval,
+ GCTTL: gcTTL,
+ GCOrphanTTL: gcOrphanTTL,
+ GCArtifactTTL: gcArtifactTTL,
+ GCArtifactPatterns: gcArtifactPatterns,
+ GCRepoTTL: gcRepoTTL,
+ GCRepoMaintenanceEnabled: gcRepoMaintenanceEnabled,
+ GCCodexSessionTTL: gcCodexSessionTTL,
+ GCHermesMemoryTTL: gcHermesMemoryTTL,
+ GCHermesSessionTTL: gcHermesSessionTTL,
+ AutoUpdateEnabled: autoUpdateEnabled,
+ AutoUpdateCheckInterval: autoUpdateInterval,
+ AutoReloadEnabled: autoReloadEnabled,
+ HealthPort: healthPort,
+ MaxConcurrentTasks: maxConcurrentTasks,
+ PollInterval: pollInterval,
+ HeartbeatInterval: heartbeatInterval,
+ AgentTimeout: agentTimeout,
+ CodexSemanticInactivityTimeout: codexSemanticInactivityTimeout,
+ CodexFirstTurnNoProgressTimeout: codexFirstTurnNoProgressTimeout,
+ CodexHandshakeTimeout: codexHandshakeTimeout,
+ OpenCodeIdleWatchdog: openCodeIdleWatchdog,
+ AgentIdleWatchdog: agentIdleWatchdog,
+ AgentToolWatchdog: agentToolWatchdog,
+ ClaudeArgs: claudeArgs,
+ CodexArgs: codexArgs,
+ CodebuddyArgs: codebuddyArgs,
+ QwenArgs: qwenArgs,
+ QwenpawArgs: qwenpawArgs,
+ ProfileCommandOverrides: profileCommandOverrides,
}, nil
}
diff --git a/server/internal/daemon/config_test.go b/server/internal/daemon/config_test.go
index 6d24034761..cb4f102c4f 100644
--- a/server/internal/daemon/config_test.go
+++ b/server/internal/daemon/config_test.go
@@ -1,7 +1,9 @@
package daemon
import (
+ "bytes"
"context"
+ "log/slog"
"os"
"os/exec"
"path/filepath"
@@ -563,6 +565,99 @@ func TestLoadConfig_CodexHandshakeTimeout(t *testing.T) {
}
}
+// TestLoadConfig_CodexFirstTurnNoProgressTimeout pins the env-only
+// MULTICA_CODEX_FIRST_TURN_TIMEOUT resolution (GH #3262 / #5959): unset and an
+// explicit "0" both mean "keep the backend default" (0 = unset), while a positive
+// value is honored verbatim. There is deliberately no Overrides/CLI parity — this
+// knob is environment-only.
+func TestLoadConfig_CodexFirstTurnNoProgressTimeout(t *testing.T) {
+ stageFakeAgent(t)
+ t.Setenv("MULTICA_CODEX_FIRST_TURN_TIMEOUT", "")
+
+ cfg, err := LoadConfig(Overrides{
+ ServerURL: "http://localhost:8080",
+ WorkspacesRoot: t.TempDir(),
+ })
+ if err != nil {
+ t.Fatalf("LoadConfig with unset: %v", err)
+ }
+ if cfg.CodexFirstTurnNoProgressTimeout != 0 {
+ t.Fatalf("CodexFirstTurnNoProgressTimeout = %s, want 0 when unset", cfg.CodexFirstTurnNoProgressTimeout)
+ }
+
+ t.Setenv("MULTICA_CODEX_FIRST_TURN_TIMEOUT", "30m")
+ cfg, err = LoadConfig(Overrides{
+ ServerURL: "http://localhost:8080",
+ WorkspacesRoot: t.TempDir(),
+ })
+ if err != nil {
+ t.Fatalf("LoadConfig with env: %v", err)
+ }
+ if cfg.CodexFirstTurnNoProgressTimeout != 30*time.Minute {
+ t.Fatalf("CodexFirstTurnNoProgressTimeout = %s, want 30m from env", cfg.CodexFirstTurnNoProgressTimeout)
+ }
+
+ t.Setenv("MULTICA_CODEX_FIRST_TURN_TIMEOUT", "0")
+ cfg, err = LoadConfig(Overrides{
+ ServerURL: "http://localhost:8080",
+ WorkspacesRoot: t.TempDir(),
+ })
+ if err != nil {
+ t.Fatalf("LoadConfig with zero env: %v", err)
+ }
+ if cfg.CodexFirstTurnNoProgressTimeout != 0 {
+ t.Fatalf("CodexFirstTurnNoProgressTimeout = %s, want 0 for explicit zero", cfg.CodexFirstTurnNoProgressTimeout)
+ }
+}
+
+// TestLoadConfig_CodexFirstTurnTimeoutEqualToSemanticWarns pins the equality
+// edge (multica-eve review on #6753): because the semantic-inactivity timer is
+// armed before the first-turn timer, equal durations still let the semantic
+// deadline win and drop the #3291 startup retry. LoadConfig must warn when the
+// first-turn timeout is >= the semantic timeout, and stay quiet only when the
+// semantic timeout is strictly greater.
+func TestLoadConfig_CodexFirstTurnTimeoutEqualToSemanticWarns(t *testing.T) {
+ stageFakeAgent(t)
+
+ const warnNeedle = "MULTICA_CODEX_FIRST_TURN_TIMEOUT is greater than or equal to the semantic-inactivity timeout"
+
+ loadWithLoggedWarnings := func(t *testing.T, semantic, firstTurn string) string {
+ t.Helper()
+ var buf bytes.Buffer
+ prev := slog.Default()
+ slog.SetDefault(slog.New(slog.NewTextHandler(&buf, &slog.HandlerOptions{Level: slog.LevelWarn})))
+ t.Cleanup(func() { slog.SetDefault(prev) })
+
+ t.Setenv("MULTICA_CODEX_SEMANTIC_INACTIVITY_TIMEOUT", semantic)
+ t.Setenv("MULTICA_CODEX_FIRST_TURN_TIMEOUT", firstTurn)
+ if _, err := LoadConfig(Overrides{
+ ServerURL: "http://localhost:8080",
+ WorkspacesRoot: t.TempDir(),
+ }); err != nil {
+ t.Fatalf("LoadConfig: %v", err)
+ }
+ return buf.String()
+ }
+
+ // Equal durations: the semantic timer is armed first, so the retry can still
+ // be lost. The warning MUST fire — this is the edge the earlier `>`-only
+ // check missed.
+ if logs := loadWithLoggedWarnings(t, "15m", "15m"); !strings.Contains(logs, warnNeedle) {
+ t.Fatalf("equal durations must warn; logs = %q", logs)
+ }
+
+ // First-turn strictly above semantic: also warns (the original truncation case).
+ if logs := loadWithLoggedWarnings(t, "10m", "30m"); !strings.Contains(logs, warnNeedle) {
+ t.Fatalf("first-turn above semantic must warn; logs = %q", logs)
+ }
+
+ // Semantic strictly above first-turn: the recommended safe configuration —
+ // no warning.
+ if logs := loadWithLoggedWarnings(t, "30m", "10m"); strings.Contains(logs, warnNeedle) {
+ t.Fatalf("semantic strictly above first-turn must not warn; logs = %q", logs)
+ }
+}
+
func TestLoadConfig_OpenCodeIdleWatchdog(t *testing.T) {
stageFakeAgent(t)
t.Setenv("MULTICA_OPENCODE_IDLE_WATCHDOG", "")
diff --git a/server/internal/daemon/daemon.go b/server/internal/daemon/daemon.go
index df1666da54..dcce66357a 100644
--- a/server/internal/daemon/daemon.go
+++ b/server/internal/daemon/daemon.go
@@ -6733,14 +6733,15 @@ func (d *Daemon) runTask(ctx context.Context, task Task, provider string, slot i
idleWatchdogTimeout = d.cfg.OpenCodeIdleWatchdog
}
execOpts := agent.ExecOptions{
- Cwd: env.WorkDir,
- Model: model,
- ThreadName: deriveTaskThreadName(task),
- Timeout: d.cfg.AgentTimeout,
- SemanticInactivityTimeout: d.cfg.CodexSemanticInactivityTimeout,
- IdleWatchdogTimeout: idleWatchdogTimeout,
- HandshakeTimeout: d.cfg.CodexHandshakeTimeout,
- ResumeSessionID: task.PriorSessionID,
+ Cwd: env.WorkDir,
+ Model: model,
+ ThreadName: deriveTaskThreadName(task),
+ Timeout: d.cfg.AgentTimeout,
+ SemanticInactivityTimeout: d.cfg.CodexSemanticInactivityTimeout,
+ FirstTurnNoProgressTimeout: d.cfg.CodexFirstTurnNoProgressTimeout,
+ IdleWatchdogTimeout: idleWatchdogTimeout,
+ HandshakeTimeout: d.cfg.CodexHandshakeTimeout,
+ ResumeSessionID: task.PriorSessionID,
// Post-gate intent: PriorSessionID here already reflects the pre-flight
// resume gates (a dropped resume is surfaced via the prompt instead). If it
// survived to here, the backend must disclose the loss when the live
diff --git a/server/pkg/agent/agent.go b/server/pkg/agent/agent.go
index d5bcb2a3c9..15ec669d42 100644
--- a/server/pkg/agent/agent.go
+++ b/server/pkg/agent/agent.go
@@ -38,6 +38,16 @@ type ExecOptions struct {
MaxTurns int
Timeout time.Duration
SemanticInactivityTimeout time.Duration
+ // FirstTurnNoProgressTimeout optionally overrides the Codex first-turn
+ // no-progress ceiling — the window a turn may stay completely silent after
+ // the app-server reports turn/started before the watchdog fails it. Zero
+ // keeps the provider default and the existing behaviour where
+ // SemanticInactivityTimeout can only shrink that ceiling; a positive value
+ // sets it explicitly, upward included. This answers a different question than
+ // SemanticInactivityTimeout ("did the process ever start producing?" vs "has
+ // a running turn gone quiet?"), so the two move independently. Currently
+ // honoured by the codex backend (GH #3262).
+ FirstTurnNoProgressTimeout time.Duration
// IdleWatchdogTimeout optionally narrows the daemon's generic no-message
// watchdog for this execution. Zero keeps the daemon-wide window, and a
// value above that window cannot extend the global safety bound. The
diff --git a/server/pkg/agent/codex.go b/server/pkg/agent/codex.go
index 3f97065050..d640467ce5 100644
--- a/server/pkg/agent/codex.go
+++ b/server/pkg/agent/codex.go
@@ -1481,7 +1481,7 @@ func (b *codexBackend) executeOnce(ctx context.Context, prompt string, opts Exec
semanticTimer := time.NewTimer(semanticInactivityTimeout)
defer semanticTimer.Stop()
- firstTurnNoProgressTimeout := codexFirstTurnNoProgressTimeout(semanticInactivityTimeout)
+ firstTurnNoProgressTimeout := codexFirstTurnNoProgressTimeout(semanticInactivityTimeout, opts.FirstTurnNoProgressTimeout)
var firstTurnNoProgressTimer *time.Timer
var firstTurnNoProgressTimerC <-chan time.Time
firstTurnStarted := false
@@ -1930,7 +1930,30 @@ func stopTimer(timer *time.Timer) {
}
}
-func codexFirstTurnNoProgressTimeout(semanticInactivityTimeout time.Duration) time.Duration {
+// codexFirstTurnNoProgressTimeout resolves the first-turn watchdog ceiling:
+// how long the first turn may stay silent after turn/started before that one
+// watchdog fails it. This is only the first-turn timer's own duration — NOT
+// the effective first-item wait. The semantic-inactivity timer is armed
+// concurrently (the same first status:running resets it and starts this one),
+// so the real wait is min(this, semanticInactivityTimeout, execution timeout).
+// Raising the override above the semantic timeout therefore does not extend the
+// wait unless the semantic timeout is raised too; LoadConfig warns when it does
+// not. See the run loop's competing-timer select for the interaction.
+//
+// An explicit configured override (MULTICA_CODEX_FIRST_TURN_TIMEOUT) is honored
+// as-is, upward included: an operator whose app-server is legitimately slow to
+// its first event (a heavy MCP boot, a cold model catalog) can lift this ceiling
+// past the default that the semantic-inactivity timeout alone can never raise
+// (GH #3262 / #5959).
+//
+// With no override the behaviour is byte-identical to before: the default
+// ceiling, which the configured semantic-inactivity timeout can only ever
+// shrink, never raise. The `* 4 / 5` cannot overflow here because that branch
+// only runs when 0 < semanticInactivityTimeout <= defaultCodexFirstTurnNoProgressTimeout.
+func codexFirstTurnNoProgressTimeout(semanticInactivityTimeout, configured time.Duration) time.Duration {
+ if configured > 0 {
+ return configured
+ }
if semanticInactivityTimeout <= 0 || semanticInactivityTimeout > defaultCodexFirstTurnNoProgressTimeout {
return defaultCodexFirstTurnNoProgressTimeout
}
diff --git a/server/pkg/agent/codex_test.go b/server/pkg/agent/codex_test.go
index 9044385b68..840d55702b 100644
--- a/server/pkg/agent/codex_test.go
+++ b/server/pkg/agent/codex_test.go
@@ -759,8 +759,45 @@ func TestCodexFirstTurnNoProgressTimeoutClamp(t *testing.T) {
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
- if got := codexFirstTurnNoProgressTimeout(tc.semantic); got != tc.want {
- t.Fatalf("codexFirstTurnNoProgressTimeout(%s) = %s, want %s", tc.semantic, got, tc.want)
+ if got := codexFirstTurnNoProgressTimeout(tc.semantic, 0); got != tc.want {
+ t.Fatalf("codexFirstTurnNoProgressTimeout(%s, 0) = %s, want %s", tc.semantic, got, tc.want)
+ }
+ })
+ }
+}
+
+// TestCodexFirstTurnNoProgressTimeoutExplicitOverride covers the
+// MULTICA_CODEX_FIRST_TURN_TIMEOUT path added for GH #3262 / #5959: a positive
+// configured value is honored as-is for the first-turn watchdog ceiling,
+// including upward past the default that the semantic inactivity timeout alone
+// can never raise. This resolver only sets that one timer's duration; the
+// effective first-item wait is still min(ceiling, semantic, execution) because
+// the semantic timer runs concurrently — see
+// TestCodexExecuteFirstTurnOverrideAboveSemanticIsTruncated for that runtime
+// interaction. A non-positive override changes nothing — the function falls back
+// to the pinned default/scaling behaviour asserted by
+// TestCodexFirstTurnNoProgressTimeoutClamp.
+func TestCodexFirstTurnNoProgressTimeoutExplicitOverride(t *testing.T) {
+ t.Parallel()
+
+ cases := []struct {
+ name string
+ semantic time.Duration
+ configured time.Duration
+ want time.Duration
+ }{
+ {name: "override above the ceiling is honored in full", semantic: 0, configured: 5 * time.Minute, want: 5 * time.Minute},
+ {name: "override wins over the default 10m semantic", semantic: 10 * time.Minute, configured: 2 * time.Minute, want: 2 * time.Minute},
+ {name: "override wins over a value that would otherwise scale down", semantic: 30 * time.Second, configured: 90 * time.Second, want: 90 * time.Second},
+ {name: "override raises the resolver ceiling above the default", semantic: 0, configured: 30 * time.Minute, want: 30 * time.Minute},
+ {name: "zero override keeps the default ceiling", semantic: 0, configured: 0, want: 60 * time.Second},
+ {name: "negative override is ignored and falls back to the ceiling", semantic: 10 * time.Minute, configured: -1 * time.Second, want: 60 * time.Second},
+ }
+
+ for _, tc := range cases {
+ t.Run(tc.name, func(t *testing.T) {
+ if got := codexFirstTurnNoProgressTimeout(tc.semantic, tc.configured); got != tc.want {
+ t.Fatalf("codexFirstTurnNoProgressTimeout(%s, %s) = %s, want %s", tc.semantic, tc.configured, got, tc.want)
}
})
}
@@ -2984,6 +3021,63 @@ func TestCodexExecuteFirstTurnNoProgressSurfacesDiagnostics(t *testing.T) {
}
}
+// TestCodexExecuteFirstTurnOverrideAboveSemanticIsTruncated pins the competing-
+// timer contract for MULTICA_CODEX_FIRST_TURN_TIMEOUT (GH #3262 / #5959): the
+// first status:running arms the semantic-inactivity timer and the first-turn
+// timer together, so a first-turn override ABOVE the semantic timeout cannot
+// extend the first-item wait — the semantic timer fires first. That also
+// reclassifies the failure as semantic inactivity, so the model-catalog startup
+// retry (GH #3291) does NOT run even though the catalog-refresh-failure signal is
+// present in stderr. The resolver tests cannot observe this; this drives the real
+// run loop. It is the inverse of TestCodexExecuteFirstTurnNoProgressSurfacesDiagnostics,
+// where the first-turn timer is the smaller of the two and wins.
+func TestCodexExecuteFirstTurnOverrideAboveSemanticIsTruncated(t *testing.T) {
+ // Not t.Parallel(): this test mutates codexGracefulShutdownTimeoutNanos.
+ if runtime.GOOS == "windows" {
+ t.Skip("shell-script fixture is POSIX-only")
+ }
+ codexGracefulShutdownTimeoutNanos.Store(int64(100 * time.Millisecond))
+ t.Cleanup(func() { codexGracefulShutdownTimeoutNanos.Store(0) })
+
+ fakePath := writeFakeCodexAppServer(t, ""+
+ `STATE="$(dirname "$0")/attempts"`+"\n"+
+ `ATTEMPT=$(cat "$STATE" 2>/dev/null || echo 0)`+"\n"+
+ `ATTEMPT=$((ATTEMPT+1))`+"\n"+
+ `echo "$ATTEMPT" > "$STATE"`+"\n"+
+ `read line`+"\n"+
+ `echo '{"jsonrpc":"2.0","id":1,"result":{}}'`+"\n"+
+ `read line`+"\n"+
+ `read line`+"\n"+
+ `echo '{"jsonrpc":"2.0","id":2,"result":{"thread":{"id":"thr-trunc"}}}'`+"\n"+
+ `read line`+"\n"+
+ `echo '{"jsonrpc":"2.0","id":3,"result":{}}'`+"\n"+
+ `echo '{"jsonrpc":"2.0","method":"turn/started","params":{"threadId":"thr-trunc","turn":{"id":"turn-trunc"}}}'`+"\n"+
+ `echo 'ERROR codex_models_manager::manager: failed to refresh available models: timeout waiting for child process to exit' >&2`+"\n"+
+ `sleep 2`+"\n")
+
+ // First-turn override (5s) sits far above the semantic timeout (100ms).
+ result := executeFakeCodex(t, fakePath, ExecOptions{
+ Timeout: 5 * time.Second,
+ SemanticInactivityTimeout: 100 * time.Millisecond,
+ FirstTurnNoProgressTimeout: 5 * time.Second,
+ })
+ if result.Status != "timeout" {
+ t.Fatalf("expected timeout, got status=%q error=%q", result.Status, result.Error)
+ }
+ // The semantic timer won the race: the failure must be classified as semantic
+ // inactivity, not first-turn no-progress. The override did not extend the wait.
+ if !strings.Contains(result.Error, CodexSemanticInactivityMarker) {
+ t.Fatalf("expected semantic-inactivity classification, got %q", result.Error)
+ }
+ if strings.Contains(result.Error, CodexFirstTurnNoProgressMarker) {
+ t.Fatalf("first-turn override above the semantic timeout must not win the race: %q", result.Error)
+ }
+ // The catalog-refresh-failure signal is present, but because the failure is
+ // classified as semantic (not first-turn) the #3291 startup retry is skipped:
+ // exactly one attempt runs.
+ assertCodexAttemptCount(t, fakePath, "1")
+}
+
func TestCodexExecuteFirstItemWaitLifecycle(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("shell-script fixture is POSIX-only")