Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
MUL-6558 feat(server): make task queue expiry configurable via MULTICA_TASK_QUEUED_TTL (#7418)
Martin Montes5a80f802d32d
diff --git a/.env.example b/.env.exampleindex 2520e75769..a2b86f5e05 100644--- a/.env.example+++ b/.env.example@@ -84,6 +84,12 @@ MULTICA_SHUTDOWN_HOLD_DURATION=# Accepts a positive Go duration. The default is 3h; values below 150s are# clamped to the runtime heartbeat freshness window.MULTICA_RUNTIME_RECONNECT_GRACE=3h+# How long a task may sit in 'queued' without being claimed before failing+# with 'queued_expired'. Accepts a positive Go duration; empty, unset, or+# invalid values keep the default of 2h. Raise this when a runtime has low+# task concurrency and tasks can legitimately wait behind long-running work+# — with a concurrency-1 runtime a backlog can exceed the default 2h.+MULTICA_TASK_QUEUED_TTL=2h# Comma-separated CIDR list of reverse proxies whose X-Forwarded-For /# X-Real-IP headers the per-IP webhook rate limiter is allowed to trust.# Empty (the default) means "trust no headers" — the limiter usesdiff --git a/apps/docs/content/docs/daemon-runtimes.ja.mdx b/apps/docs/content/docs/daemon-runtimes.ja.mdxindex 494722c718..841eccbda4 100644--- a/apps/docs/content/docs/daemon-runtimes.ja.mdx+++ b/apps/docs/content/docs/daemon-runtimes.ja.mdx@@ -60,7 +60,7 @@ multica daemon startランタイムがオフラインのとき:-- キュー済みのタスクは、最長 2 時間、ランタイムの復帰を待ちます。+- キュー済みのタスクは、デフォルトで最長 2 時間、ランタイムの復帰を待ちます(`MULTICA_TASK_QUEUED_TTL` で変更可能、[環境変数](/environment-variables))。- 実行中だったタスクは失敗します。条件を満たすイシューまたはチャットのタスクは自動リトライできます。- デーモンが再起動すると、ランタイムを再登録し、前回正常に終了しなかったタスクを回収します。- 7 日を超えてオフラインで、(アーカイブ済みを含め)どのエージェントにも紐づいていないランタイムは、自動的にクリーンアップされます。diff --git a/apps/docs/content/docs/daemon-runtimes.ko.mdx b/apps/docs/content/docs/daemon-runtimes.ko.mdxindex e591b7b0d7..058743ce0b 100644--- a/apps/docs/content/docs/daemon-runtimes.ko.mdx+++ b/apps/docs/content/docs/daemon-runtimes.ko.mdx@@ -60,7 +60,7 @@ multica daemon start런타임이 오프라인일 때는 다음과 같이 처리됩니다.-- 이미 큐에 들어간 태스크는 런타임이 복구될 때까지 최대 2시간 기다립니다.+- 이미 큐에 들어간 태스크는 런타임이 복구될 때까지 기본값으로 최대 2시간 기다립니다(`MULTICA_TASK_QUEUED_TTL`로 조정 가능, [환경 변수](/environment-variables)).- 실행 중인 태스크는 실패합니다. 조건을 만족하는 이슈 또는 대화 태스크는 자동으로 재시도될 수 있습니다.- 데몬이 다시 시작되면 런타임을 재등록하고 이전에 정상적으로 끝나지 않은 태스크를 회수합니다.- 7일 넘게 오프라인이고 연결된 에이전트가 하나도 없는 런타임은 보관된 에이전트까지 확인한 뒤 자동으로 정리됩니다.diff --git a/apps/docs/content/docs/daemon-runtimes.mdx b/apps/docs/content/docs/daemon-runtimes.mdxindex c31864ed6c..b5550dcc9c 100644--- a/apps/docs/content/docs/daemon-runtimes.mdx+++ b/apps/docs/content/docs/daemon-runtimes.mdx@@ -60,7 +60,7 @@ The daemon sends a heartbeat every 15 seconds. The server combines heartbeats anWhen a runtime is offline:-- Tasks already queued wait for the runtime to recover, for up to 2 hours.+- Tasks already queued wait for the runtime to recover, for up to 2 hours by default (adjustable via `MULTICA_TASK_QUEUED_TTL`, see [Environment variables](/environment-variables)).- Tasks that were running fail; eligible issue or chat tasks can retry automatically.- When the daemon starts again, it re-registers its runtimes and reclaims tasks that did not end cleanly last time.- A runtime offline for more than 7 days with no agents bound to it (including archived ones) is cleaned up automatically.diff --git a/apps/docs/content/docs/daemon-runtimes.zh.mdx b/apps/docs/content/docs/daemon-runtimes.zh.mdxindex bf990904a3..12c2827c06 100644--- a/apps/docs/content/docs/daemon-runtimes.zh.mdx+++ b/apps/docs/content/docs/daemon-runtimes.zh.mdx@@ -60,7 +60,7 @@ multica daemon start运行时离线时:-- 已经排队的 task 会等待运行时恢复,最多保留 2 小时。+- 已经排队的 task 会等待运行时恢复,默认最多保留 2 小时(可用 `MULTICA_TASK_QUEUED_TTL` 调整,见[环境变量](/environment-variables))。- 正在执行的 task 会失败;符合条件的 issue 或对话 task 可以自动重试。- 守护进程重新启动后,会重新注册运行时,并回收上一次没有正常结束的 task。- 离线超过 7 天且没有任何智能体(包括已归档的)绑定的运行时,会被自动清理。diff --git a/apps/docs/content/docs/environment-variables.ja.mdx b/apps/docs/content/docs/environment-variables.ja.mdxindex e35090f783..4026656506 100644--- a/apps/docs/content/docs/environment-variables.ja.mdx+++ b/apps/docs/content/docs/environment-variables.ja.mdx@@ -42,6 +42,7 @@ MULTICA_PUBLIC_URL=https://api.multica.example.com| `LOG_LEVEL` | アプリのデフォルト | ログレベル || `MULTICA_SHUTDOWN_HOLD_DURATION` | `0` | 終了シグナル受信後、グレースフルシャットダウンを開始するまでの待機時間 || `MULTICA_RUNTIME_RECONNECT_GRACE` | `3h` | オフラインのランタイムが処理中の作業を失敗させずに再接続できる猶予時間。`150s` 未満は `150s` に補正されます |+| `MULTICA_TASK_QUEUED_TTL` | `2h` | タスクがキュー内でクレームされずに置かれることのできる最長時間。超過すると `queued_expired` で失敗します。低並行度のランタイムが長時間実行中の作業の後ろに正当に待機しうる場合は大きくしてください |Kubernetes で shutdown hold を設定する場合、`terminationGracePeriodSeconds` は hold と実際のシャットダウンにかかる時間の合計より大きくしてください。diff --git a/apps/docs/content/docs/environment-variables.ko.mdx b/apps/docs/content/docs/environment-variables.ko.mdxindex 04dd4f19ec..349165156d 100644--- a/apps/docs/content/docs/environment-variables.ko.mdx+++ b/apps/docs/content/docs/environment-variables.ko.mdx@@ -42,6 +42,7 @@ MULTICA_PUBLIC_URL=https://api.multica.example.com| `LOG_LEVEL` | 앱 기본값 | 로그 수준 || `MULTICA_SHUTDOWN_HOLD_DURATION` | `0` | 종료 신호를 받은 뒤 graceful shutdown을 시작하기 전 대기 시간 || `MULTICA_RUNTIME_RECONNECT_GRACE` | `3h` | 오프라인 런타임이 진행 중인 작업을 실패시키지 않고 재연결할 수 있는 유예 시간. `150s` 미만은 `150s`로 조정됨 |+| `MULTICA_TASK_QUEUED_TTL` | `2h` | 태스크가 대기열에 점유되지 않고 머물 수 있는 최대 시간. 초과 시 `queued_expired`로 실패. 저 동시성 런타임이 긴 작업 뒤에 합리적으로 대기할 수 있으므로 이 경우 값을 키워야 함 |Kubernetes에서 shutdown hold를 설정하면 `terminationGracePeriodSeconds`가 hold와 실제 종료에 필요한 시간의 합보다 커야 합니다.diff --git a/apps/docs/content/docs/environment-variables.mdx b/apps/docs/content/docs/environment-variables.mdxindex 1ca1b0c01c..e1cfe89250 100644--- a/apps/docs/content/docs/environment-variables.mdx+++ b/apps/docs/content/docs/environment-variables.mdx@@ -42,6 +42,7 @@ You also need to pick an email service, otherwise verification codes and invitat| `LOG_LEVEL` | application default | Log level || `MULTICA_SHUTDOWN_HOLD_DURATION` | `0` | How long to wait after a termination signal before graceful shutdown begins || `MULTICA_RUNTIME_RECONNECT_GRACE` | `3h` | How long an offline runtime may reconnect before its in-flight tasks fail; values below `150s` are clamped |+| `MULTICA_TASK_QUEUED_TTL` | `2h` | How long a task may sit in the queue unclaimed before failing with `queued_expired`; raise it when low-concurrency runtimes can legitimately wait behind long-running work |When setting a shutdown hold on Kubernetes, `terminationGracePeriodSeconds` must exceed the hold plus the time the actual shutdown needs.diff --git a/apps/docs/content/docs/environment-variables.zh.mdx b/apps/docs/content/docs/environment-variables.zh.mdxindex aca7f910db..c37c31e855 100644--- a/apps/docs/content/docs/environment-variables.zh.mdx+++ b/apps/docs/content/docs/environment-variables.zh.mdx@@ -42,6 +42,7 @@ MULTICA_PUBLIC_URL=https://api.multica.example.com| `LOG_LEVEL` | 应用默认 | 日志级别 || `MULTICA_SHUTDOWN_HOLD_DURATION` | `0` | 收到终止信号后,开始优雅退出前等待多久 || `MULTICA_RUNTIME_RECONNECT_GRACE` | `3h` | 运行时离线后可重新连接且不终止在途 task 的宽限时间;低于 `150s` 时按 `150s` 处理 |+| `MULTICA_TASK_QUEUED_TTL` | `2h` | task 在队列中无人认领的最长时长,超过后以 `queued_expired` 失败;低并发运行时可能合理地排在长任务之后,此时应调大 |在 Kubernetes 中设置 shutdown hold 时,`terminationGracePeriodSeconds` 要大于 hold 与实际退出所需时间之和。diff --git a/apps/docs/content/docs/tasks.ja.mdx b/apps/docs/content/docs/tasks.ja.mdxindex 691676357a..445267f022 100644--- a/apps/docs/content/docs/tasks.ja.mdx+++ b/apps/docs/content/docs/tasks.ja.mdx@@ -45,7 +45,7 @@ import { Callout } from "fumadocs-ui/components/callout";| `failed` | 実行がエラーになったか中断された || `cancelled` | 実行が手動で停止された |-ランタイムがオンラインなら、新しいタスクは通常すぐに始まります。キューに入ったあとでランタイムがオフラインになった場合、タスクは復帰までキューで待機します。2 時間を超えて取得されないタスクは失敗として終了します。+ランタイムがオンラインなら、新しいタスクは通常すぐに始まります。キューに入ったあとでランタイムがオフラインになった場合、タスクは復帰までキューで待機します。2 時間(デフォルト)を超えて取得されないタスクは失敗として終了します。上限は `MULTICA_TASK_QUEUED_TTL` で変更できます([環境変数](/environment-variables))。<Callout type="info">トリガーの前の時点で対象ランタイムのオフラインが分かっている場合、一部の即時操作は、誰も取得できないタスクを作成する代わりに、いまは実行できない旨をその場で表示します。@@ -94,7 +94,7 @@ import { Callout } from "fumadocs-ui/components/callout";| 原因 | 意味 | 対処 || --- | --- | --- || `runtime_offline` | 実行中にランタイムがオフラインになった | ランタイムを復旧してからリトライ。[デーモンとランタイム](/daemon-runtimes)を参照 |-| `queued_expired` | ランタイムに取得されないまま 2 時間を超えてキューで待機した | ランタイムがオンラインであることを確認してからリトライ |+| `queued_expired` | ランタイムに取得されないまま未取得上限(デフォルト 2 時間、`MULTICA_TASK_QUEUED_TTL` で変更可能)を超えてキューで待機した | ランタイムがオンラインであることを確認してからリトライ || `runtime_recovery` | デーモンが再起動後、中断された実行を回収した | そのままリトライ || `cancelled` | 手動で停止されたか、アーカイブ・削除に伴ってキャンセルされた | 対処不要 || `timeout` | デーモンに設定された実行時間の上限を超えた | イシューの範囲を狭めるか、デーモンの `agent_timeout` を調整する |@@ -149,7 +149,7 @@ multica issue rerun <issue-id>| 状態 | 意味 | タイムアウトと結果 || --- | --- | --- || `deferred` | 後で発火するようスケジュール済み | 予定時刻になると `queued` に入り、以降は下のルールに従う |-| `queued` | ランタイムによる取得待ち | **2 時間**取得されないと失敗として終了し、自動リトライされない |+| `queued` | ランタイムによる取得待ち | **2 時間(デフォルト)**取得されないと失敗として終了し(`MULTICA_TASK_QUEUED_TTL` で上限を変更可)、自動リトライされない || `dispatched` | ランタイムが取得し、ツールを起動中 | **5 分**を超えてこの状態に留まると失敗として扱われる || `waiting_local_directory` | ローカルディレクトリロックの解放待ち | 独自のタイムアウトはなし。ディレクトリが解放されると起動フローに戻る || `running` | AI コーディングツールが実行中 | 固定の時間上限はなし。生存はランタイムのハートビート(15 秒ごと)で判定し、ハートビートを失ったランタイムは遅くとも約 3 分でオフラインと判定され、その上のタスクも失敗する |diff --git a/apps/docs/content/docs/tasks.ko.mdx b/apps/docs/content/docs/tasks.ko.mdxindex 08d243070c..6280101aff 100644--- a/apps/docs/content/docs/tasks.ko.mdx+++ b/apps/docs/content/docs/tasks.ko.mdx@@ -45,7 +45,7 @@ import { Callout } from "fumadocs-ui/components/callout";| `failed` | 실행 중 오류가 발생했거나 중단되었습니다. || `cancelled` | 실행을 수동으로 중지했습니다. |-런타임이 온라인이면 새 태스크가 보통 빠르게 시작됩니다. 태스크가 큐에 들어간 뒤 런타임이 오프라인이 되면 복구될 때까지 큐에서 기다립니다. 2시간 넘게 수령되지 않으면 태스크가 실패로 끝납니다.+런타임이 온라인이면 새 태스크가 보통 빠르게 시작됩니다. 태스크가 큐에 들어간 뒤 런타임이 오프라인이 되면 복구될 때까지 큐에서 기다립니다. 기본값인 2시간이 넘게 수령되지 않으면 태스크가 실패로 끝납니다. 상한은 `MULTICA_TASK_QUEUED_TTL`로 조정할 수 있습니다([환경 변수](/environment-variables)).<Callout type="info">트리거하기 전에 대상 런타임이 오프라인임을 시스템이 이미 아는 경우 일부 즉시 실행 작업은 수령할 수 없는 태스크를 만들지 않고 현재 실행할 수 없다고 바로 알립니다.@@ -94,7 +94,7 @@ heartbeat가 정상인 런타임은 장시간 태스크도 실행할 수 있으| 원인 | 의미 | 처리 방법 || --- | --- | --- || `runtime_offline` | 실행 중 런타임이 오프라인이 됨 | 런타임을 복구한 뒤 재시도합니다. [데몬과 런타임](/daemon-runtimes) 참고 |-| `queued_expired` | 2시간 넘게 큐에서 기다렸지만 런타임이 가져가지 않음 | 런타임이 온라인인지 확인한 뒤 재시도 |+| `queued_expired` | 수령 상한(기본 2시간, `MULTICA_TASK_QUEUED_TTL`로 조정 가능)을 넘겨서 런타임이 가져가지 않음 | 런타임이 온라인인지 확인한 뒤 재시도 || `runtime_recovery` | 데몬 재시작 후 중단된 실행을 회수함 | 바로 재시도 || `cancelled` | 수동으로 중지되었거나 보관 또는 삭제와 함께 취소됨 | 별도 처리 불필요 || `timeout` | 데몬에 설정된 실행 시간 상한을 초과함 | 이슈 범위를 줄이거나 데몬의 `agent_timeout` 조정 |@@ -149,7 +149,7 @@ multica issue rerun <issue-id>| 상태 | 의미 | timeout과 결과 || --- | --- | --- || `deferred` | 나중에 트리거되도록 예약됨 | 예정 시간이 되면 `queued`로 들어가고 이후 아래 규칙에 따라 시간을 계산합니다. |-| `queued` | 런타임이 가져가기를 기다림 | **2시간** 넘게 수령되지 않으면 실패로 끝나며 자동 재시도하지 않습니다. |+| `queued` | 런타임이 가져가기를 기다림 | **2시간(기본값)** 넘게 수령되지 않으면 실패로 끝나며(`MULTICA_TASK_QUEUED_TTL`로 상한 조정 가능) 자동 재시도하지 않습니다. || `dispatched` | 런타임이 가져갔고 도구를 시작 중 | **5분** 넘게 머물면 실패로 처리합니다. || `waiting_local_directory` | 로컬 디렉터리 잠금 해제를 기다림 | 별도 timeout이 없으며 디렉터리가 해제되면 시작 과정으로 돌아갑니다. || `running` | AI 코딩 도구 실행 중 | 고정 시간 상한이 없습니다. 런타임 heartbeat로 생존을 판단하며 15초마다 heartbeat를 보냅니다. heartbeat를 잃은 런타임은 늦어도 약 3분 뒤 오프라인으로 판단되고 그 위의 태스크도 실패합니다. |diff --git a/apps/docs/content/docs/tasks.mdx b/apps/docs/content/docs/tasks.mdxindex faa38020a6..ff2dbb815f 100644--- a/apps/docs/content/docs/tasks.mdx+++ b/apps/docs/content/docs/tasks.mdx@@ -45,7 +45,7 @@ A task typically moves through these states:| `failed` | The run errored or was interrupted || `cancelled` | The run was stopped manually |-When the runtime is online, a new task usually starts quickly; if the runtime goes offline after the task enters the queue, the task stays queued until it recovers. A task left unclaimed for more than 2 hours ends as failed.+When the runtime is online, a new task usually starts quickly; if the runtime goes offline after the task enters the queue, the task stays queued until it recovers. A task left unclaimed for more than 2 hours by default ends as failed; the limit is adjustable via `MULTICA_TASK_QUEUED_TTL` ([Environment variables](/environment-variables)).<Callout type="info">If the system already knows the target runtime is offline before triggering, some immediate actions report that the run cannot start right now instead of creating a task nothing can claim.@@ -94,7 +94,7 @@ The failure reasons shown in the execution log and usage stats fall into two gro| Reason | Meaning | What to do || --- | --- | --- || `runtime_offline` | The runtime went offline during the run | Restore the runtime and retry; see [Daemon and runtimes](/daemon-runtimes) |-| `queued_expired` | Queued for over 2 hours with no runtime claiming it | Confirm the runtime is online, then retry |+| `queued_expired` | Queued past the unclaimed limit (2 hours by default, adjustable via `MULTICA_TASK_QUEUED_TTL`) with no runtime claiming it | Confirm the runtime is online, then retry || `runtime_recovery` | The daemon reclaimed an interrupted run after restarting | Retry directly || `cancelled` | Stopped manually, or cancelled along with an archive or delete | Nothing to do || `timeout` | Exceeded the daemon's configured execution time limit | Narrow the issue scope, or adjust the daemon's `agent_timeout` |@@ -149,7 +149,7 @@ The numbers below reflect the server's default configuration, for quick cross-ch| State | Meaning | Timeout and consequence || --- | --- | --- || `deferred` | Scheduled to fire later | Enters `queued` at the scheduled time, then the rules below apply |-| `queued` | Waiting for a runtime to claim it | Fails after **2 hours** unclaimed; not retried automatically |+| `queued` | Waiting for a runtime to claim it | Fails after **2 hours by default** unclaimed (limit settable via `MULTICA_TASK_QUEUED_TTL`); not retried automatically || `dispatched` | Claimed; the tool is starting | Treated as failed after more than **5 minutes** in this state || `waiting_local_directory` | Waiting for the local directory lock to release | No timeout of its own; returns to the startup flow once the directory is released || `running` | The AI coding tool is executing | No fixed duration cap; liveness follows the runtime heartbeat — one every 15 seconds; a runtime that loses its heartbeat is marked offline within about 3 minutes at the latest, and its tasks fail with it |diff --git a/apps/docs/content/docs/tasks.zh.mdx b/apps/docs/content/docs/tasks.zh.mdxindex 514af12700..c9c44f13ed 100644--- a/apps/docs/content/docs/tasks.zh.mdx+++ b/apps/docs/content/docs/tasks.zh.mdx@@ -45,7 +45,7 @@ Issue 保存一项工作的目标、讨论、负责人和最终状态;执行| `failed` | 执行出错或中断 || `cancelled` | 执行被手动停止 |-运行时在线时,新 task 通常会很快开始;如果 task 入队后运行时离线,它会留在队列中等待恢复。排队超过 2 小时仍未被领取时,task 会以失败结束。+运行时在线时,新 task 通常会很快开始;如果 task 入队后运行时离线,它会留在队列中等待恢复。排队超过 2 小时(默认值)仍未被领取时,task 会以失败结束;该上限可通过 `MULTICA_TASK_QUEUED_TTL` 调整(见[环境变量](/environment-variables))。<Callout type="info">如果系统在触发前已经知道目标运行时离线,部分即时操作会直接提示当前无法运行,而不是继续创建一条无法领取的 task。@@ -94,7 +94,7 @@ issue 产生的所有 task 都列在 issue 右侧栏的 **执行日志**里,| 原因 | 含义 | 处理 || --- | --- | --- || `runtime_offline` | 执行期间运行时离线 | 恢复运行时后重试,见[守护进程与运行时](/daemon-runtimes) |-| `queued_expired` | 排队超过 2 小时无运行时领取 | 确认运行时在线后重试 |+| `queued_expired` | 排队超过领取上限(默认 2 小时,可用 `MULTICA_TASK_QUEUED_TTL` 调整)无运行时领取 | 确认运行时在线后重试 || `runtime_recovery` | 守护进程重启后回收了中断的执行 | 直接重试 || `cancelled` | 被手动停止,或随归档、删除一并取消 | 无需处理 || `timeout` | 超过守护进程配置的执行时长上限 | 缩小 issue 范围,或调整守护进程的 `agent_timeout` |@@ -149,7 +149,7 @@ Issue 是否完成,以实际工作进展和它的状态为准。| 状态 | 含义 | 超时与后果 || --- | --- | --- || `deferred` | 已安排稍后触发 | 到达预定时间后进入 `queued`,再按下面的规则计时 |-| `queued` | 等待运行时领取 | 超过 **2 小时**未被领取即以失败结束,不会自动重试 |+| `queued` | 等待运行时领取 | 超过 **2 小时(默认值)**未被领取即以失败结束(可用 `MULTICA_TASK_QUEUED_TTL` 调整),不会自动重试 || `dispatched` | 运行时已领取,正在启动工具 | 停留超过 **5 分钟**按失败处理 || `waiting_local_directory` | 等待本地目录锁释放 | 没有独立超时;目录释放后回到启动流程 || `running` | AI 编程工具正在执行 | 不设固定时长上限;以运行时心跳判定存活,心跳每 15 秒一次,失去心跳的运行时最迟约 3 分钟被判为离线,其上的 task 随之失败 |diff --git a/apps/docs/content/docs/troubleshooting.ja.mdx b/apps/docs/content/docs/troubleshooting.ja.mdxindex bd42e50d5c..6fa84a08a9 100644--- a/apps/docs/content/docs/troubleshooting.ja.mdx+++ b/apps/docs/content/docs/troubleshooting.ja.mdx@@ -67,7 +67,7 @@ multica config show3. エージェントに利用可能な同時実行枠が残っているか。4. デーモンに全体の実行キャパシティが残っているか。-エージェントはデフォルトで最大 6 件、1 つのデーモンはデフォルトで最大 20 件のタスクを同時に実行します。上限に達すると、新しいタスクは実行中のものが終わるまでキューに残ります。ランタイムがオフラインの間もタスクはキューに残り続け、2 時間を超えて引き受けられなかった場合にのみ失敗します。+エージェントはデフォルトで最大 6 件、1 つのデーモンはデフォルトで最大 20 件のタスクを同時に実行します。上限に達すると、新しいタスクは実行中のものが終わるまでキューに残ります。ランタイムがオフラインの間もタスクはキューに残り続け、2 時間(デフォルト)を超えて引き受けられなかった場合にのみ失敗します(上限は `MULTICA_TASK_QUEUED_TTL` で変更可能、[環境変数](/environment-variables))。```bashmultica daemon status --output jsondiff --git a/apps/docs/content/docs/troubleshooting.ko.mdx b/apps/docs/content/docs/troubleshooting.ko.mdxindex 9d044e726d..e7c050d74d 100644--- a/apps/docs/content/docs/troubleshooting.ko.mdx+++ b/apps/docs/content/docs/troubleshooting.ko.mdx@@ -67,7 +67,7 @@ multica config show3. 에이전트에 사용 가능한 동시 실행 용량이 남아 있는지4. 데몬에 전체 실행 용량이 남아 있는지-에이전트 한 명은 기본적으로 실행 태스크를 최대 6개까지 동시에 실행하고 데몬 하나는 최대 20개까지 실행합니다. 상한에 도달하면 새 실행 태스크는 큐에 남아 기존 실행이 끝난 뒤 시작됩니다. 런타임이 오프라인이어도 실행 태스크는 계속 대기하며 2시간 넘게 수령되지 않을 때만 실패합니다.+에이전트 한 명은 기본적으로 실행 태스크를 최대 6개까지 동시에 실행하고 데몬 하나는 최대 20개까지 실행합니다. 상한에 도달하면 새 실행 태스크는 큐에 남아 기존 실행이 끝난 뒤 시작됩니다. 런타임이 오프라인이어도 실행 태스크는 계속 대기하며 기본값인 2시간 넘게 수령되지 않을 때만 실패합니다(상한은 `MULTICA_TASK_QUEUED_TTL`로 조정 가능, [환경 변수](/environment-variables)).```bashmultica daemon status --output jsondiff --git a/apps/docs/content/docs/troubleshooting.mdx b/apps/docs/content/docs/troubleshooting.mdxindex e173ee05fb..24cfb2e0c1 100644--- a/apps/docs/content/docs/troubleshooting.mdx+++ b/apps/docs/content/docs/troubleshooting.mdx@@ -67,7 +67,7 @@ Open the issue's **execution log** and check the task's current status and what3. Does the agent still have concurrency headroom?4. Does the daemon still have global execution capacity?-An agent runs at most 6 tasks concurrently by default; a single daemon runs at most 20. At the limit, new tasks stay in the queue until a running one finishes. Tasks also keep queueing while the runtime is offline; they only fail after going unclaimed for more than 2 hours.+An agent runs at most 6 tasks concurrently by default; a single daemon runs at most 20. At the limit, new tasks stay in the queue until a running one finishes. Tasks also keep queueing while the runtime is offline; they only fail after going unclaimed for more than 2 hours by default (raise the limit with `MULTICA_TASK_QUEUED_TTL`, see [Environment variables](/environment-variables)).```bashmultica daemon status --output jsondiff --git a/apps/docs/content/docs/troubleshooting.zh.mdx b/apps/docs/content/docs/troubleshooting.zh.mdxindex f1270435ce..d3b28ca1db 100644--- a/apps/docs/content/docs/troubleshooting.zh.mdx+++ b/apps/docs/content/docs/troubleshooting.zh.mdx@@ -67,7 +67,7 @@ multica config show3. 智能体是否还有可用并发额度;4. 守护进程是否还有全局执行容量。-智能体默认最多同时执行 6 条执行任务;单个守护进程默认最多同时执行 20 条。达到上限时,新执行任务会留在队列中,等已有执行结束后再开始。运行时离线时,执行任务也会继续排队;超过 2 小时仍未领取才会失败。+智能体默认最多同时执行 6 条执行任务;单个守护进程默认最多同时执行 20 条。达到上限时,新执行任务会留在队列中,等已有执行结束后再开始。运行时离线时,执行任务也会继续排队;超过 2 小时(默认值)仍未领取才会失败(上限可用 `MULTICA_TASK_QUEUED_TTL` 调整,见[环境变量](/environment-variables))。```bashmultica daemon status --output jsondiff --git a/deploy/helm/multica/templates/configmap.yaml b/deploy/helm/multica/templates/configmap.yamlindex 0c554cf10f..46447728d2 100644--- a/deploy/helm/multica/templates/configmap.yaml+++ b/deploy/helm/multica/templates/configmap.yaml@@ -32,6 +32,7 @@ data:CLOUDFRONT_DOMAIN: {{ .Values.backend.config.cloudfrontDomain | quote }}CLOUDFRONT_KEY_PAIR_ID: {{ .Values.backend.config.cloudfrontKeyPairId | quote }}LOCAL_UPLOAD_BASE_URL: {{ .Values.backend.config.localUploadBaseUrl | quote }}+ MULTICA_TASK_QUEUED_TTL: {{ .Values.backend.config.taskQueuedTTL | quote }}{{- if not .Values.postgres.external.enabled }}# --- PostgreSQL (consumed by the backend to build DATABASE_URL) ---diff --git a/deploy/helm/multica/values.yaml b/deploy/helm/multica/values.yamlindex b81002c261..27aad60b26 100644--- a/deploy/helm/multica/values.yaml+++ b/deploy/helm/multica/values.yaml@@ -155,6 +155,11 @@ backend:cloudfrontDomain: ""cloudfrontKeyPairId: ""localUploadBaseUrl: http://api.multica.dev.lan+ # How long a task may sit in the queue unclaimed before failing with+ # `queued_expired`; raise it when a runtime's low task concurrency lets+ # tasks legitimately wait behind long-running work.+ # Accepts a positive duration and empty/unset falls back to the server default of 2h.+ taskQueuedTTL: 2hresources:requests:cpu: 100mdiff --git a/docker-compose.selfhost.yml b/docker-compose.selfhost.ymlindex 90c977351e..952821b811 100644--- a/docker-compose.selfhost.yml+++ b/docker-compose.selfhost.yml@@ -100,6 +100,7 @@ services:MULTICA_DATABASE_CONNECT_TIMEOUT: ${MULTICA_DATABASE_CONNECT_TIMEOUT:-5s}MULTICA_SHUTDOWN_HOLD_DURATION: ${MULTICA_SHUTDOWN_HOLD_DURATION:-}MULTICA_RUNTIME_RECONNECT_GRACE: ${MULTICA_RUNTIME_RECONNECT_GRACE:-}+ MULTICA_TASK_QUEUED_TTL: ${MULTICA_TASK_QUEUED_TTL:-}ALLOW_SIGNUP: ${ALLOW_SIGNUP:-true}ALLOWED_EMAILS: ${ALLOWED_EMAILS:-}ALLOWED_EMAIL_DOMAINS: ${ALLOWED_EMAIL_DOMAINS:-}diff --git a/scripts/helm-config.test.sh b/scripts/helm-config.test.shindex fb5fc3c6d1..1be96b89ce 100644--- a/scripts/helm-config.test.sh+++ b/scripts/helm-config.test.sh@@ -35,10 +35,18 @@ default_config="$(require_rendered_value "$default_config" 'MULTICA_VCS_INTEGRATION_ENABLED: "true"'require_rendered_value "$default_config" 'MULTICA_ENTITLEMENT_POLICY_ENABLED: "false"'require_rendered_value "$default_config" 'MULTICA_ENTITLEMENT_POLICY_URL: ""'+require_rendered_value "$default_config" 'MULTICA_TASK_QUEUED_TTL: "2h"'require_rendered_value "$default_config" 'MULTICA_DATABASE_STARTUP_TIMEOUT: "3m"'require_rendered_value "$default_config" 'MULTICA_DATABASE_CONNECT_TIMEOUT: "5s"'reject_rendered_value "$default_config" 'MULTICA_ENTITLEMENT_SERVICE_TOKEN'+queued_ttl_config="$(+ helm template multica "$CHART_DIR" \+ --show-only templates/configmap.yaml \+ --set-string backend.config.taskQueuedTTL=12h+)"+require_rendered_value "$queued_ttl_config" 'MULTICA_TASK_QUEUED_TTL: "12h"'+default_backend="$(helm template multica "$CHART_DIR" \--show-only templates/backend.yamldiff --git a/server/cmd/server/main.go b/server/cmd/server/main.goindex 1512741bc9..e23e6c213c 100644--- a/server/cmd/server/main.go+++ b/server/cmd/server/main.go@@ -598,7 +598,12 @@ func main() {)runtimeReconnectGrace = minimumRuntimeReconnectGrace}- go runRuntimeSweeper(sweepCtx, pool, queries, liveness, taskSvc, bus, runtimeReconnectGrace)+ // MULTICA_TASK_QUEUED_TTL lets self-hosted deployments that legitimately+ // hold queued work behind long-running tasks — e.g. a runtime with low+ // task concurrency — raise the built-in 2h queued expiry without losing+ // work to queued_expired failures.+ go runRuntimeSweeper(sweepCtx, pool, queries, liveness, taskSvc, bus, runtimeReconnectGrace,+ envDuration("MULTICA_TASK_QUEUED_TTL", defaultTaskQueuedTTL))go heartbeatScheduler.Run(sweepCtx)go runAutopilotFailureMonitor(autopilotCtx, queries, bus, envFailureMonitorConfig())if autopilotSvc.QuotaEnabled() {diff --git a/server/cmd/server/runtime_sweeper.go b/server/cmd/server/runtime_sweeper.goindex f42aa160b0..823d55e0ae 100644--- a/server/cmd/server/runtime_sweeper.go+++ b/server/cmd/server/runtime_sweeper.go@@ -79,17 +79,22 @@ const (// liveness + DB stale + FailTasksForOfflineRuntimes), which typically// reclaims orphaned tasks within ~180s.runningTimeoutSeconds = 9000.0- // queuedTTLSeconds expires tasks that have been sitting in 'queued'+ // defaultTaskQueuedTTL expires tasks that have been sitting in 'queued'// for longer than this without ever being claimed. This is the cleanup// arm of the MUL-1899 backlog fix: even with the dispatch-time// admission gate that blocks new enqueues against offline runtimes,// tasks already on the queue when a runtime drops off (or that lost// the race against a runtime that went offline mid-tick) need a- // time-bounded exit. 2 hours is conservatively above any reasonable- // "queued behind a long-running task" window for an online runtime, so we- // don't expire legitimately-pending work, while still draining the historical- // 87k autopilot backlog within ~24h once enabled.- queuedTTLSeconds = 2 * 3600.0+ // time-bounded exit. The 2h default was chosen under the historical+ // assumption that it sits conservatively above any reasonable "queued+ // behind a long-running task" window for an online runtime, so the sweep+ // drains the historical 87k autopilot backlog within ~24h without+ // expiring legitimately-pending work. That assumption breaks down for+ // self-hosted deployments whose runtimes have low task concurrency: a+ // single slow task can hold the rest of the queue for longer than 2+ // hours; raise it via MULTICA_TASK_QUEUED_TTL in that case to avoid+ // queued_expired failures.+ defaultTaskQueuedTTL = 2 * time.Hour// queuedExpireBatchSize caps how many queued rows a single sweeper tick// transitions to failed. Keeps the sweep transaction short even when// the historical backlog is large (~89k at MUL-1899 baseline). At 30s@@ -124,7 +129,7 @@ type runtimeGCTxStarter interface {// hot heartbeat path; the DB is allowed to lag up to runtimeHeartbeatDBFlushInterval).// When liveness is unavailable or errors, we fall back to trusting the DB// stale window — that is the original behavior.-func runRuntimeSweeper(ctx context.Context, txStarter runtimeGCTxStarter, queries *db.Queries, liveness handler.LivenessStore, taskSvc *service.TaskService, bus *events.Bus, reconnectGrace time.Duration) {+func runRuntimeSweeper(ctx context.Context, txStarter runtimeGCTxStarter, queries *db.Queries, liveness handler.LivenessStore, taskSvc *service.TaskService, bus *events.Bus, reconnectGrace time.Duration, queuedTTL time.Duration) {ticker := time.NewTicker(sweepInterval)defer ticker.Stop()@@ -137,7 +142,7 @@ func runRuntimeSweeper(ctx context.Context, txStarter runtimeGCTxStarter, queriesweepOfflineRuntimeTasks(ctx, queries, taskSvc, reconnectGrace)sweepExpiredRuntimeReconnectRetries(ctx, queries, taskSvc, reconnectGrace)sweepStaleTasks(ctx, queries, taskSvc, bus, reconnectGrace)- sweepExpiredQueuedTasks(ctx, queries, taskSvc)+ sweepExpiredQueuedTasks(ctx, queries, taskSvc, queuedTTL)sweepPendingDelegatedFailureRecoveries(ctx, taskSvc)sweepDeferredChatFinalizations(ctx, queries, taskSvc)gcRuntimes(ctx, txStarter, queries, taskSvc.Metrics, bus)@@ -524,9 +529,9 @@ func sweepStaleTasks(ctx context.Context, queries *db.Queries, taskSvc *service.// historical backlog and catches the race where a runtime goes offline AFTER// a task is already queued. Capped to queuedExpireBatchSize per tick so a// big backlog can't monopolise the DB.-func sweepExpiredQueuedTasks(ctx context.Context, queries *db.Queries, taskSvc *service.TaskService) {+func sweepExpiredQueuedTasks(ctx context.Context, queries *db.Queries, taskSvc *service.TaskService, queuedTTL time.Duration) {failedTasks, err := queries.ExpireStaleQueuedTasks(ctx, db.ExpireStaleQueuedTasksParams{- TtlSecs: queuedTTLSeconds,+ TtlSecs: queuedTTL.Seconds(),MaxPerTick: queuedExpireBatchSize,})if err != nil {diff --git a/server/cmd/server/sweeper_task_timeouts_test.go b/server/cmd/server/sweeper_task_timeouts_test.gonew file mode 100644index 0000000000..7fbfb40658--- /dev/null+++ b/server/cmd/server/sweeper_task_timeouts_test.go@@ -0,0 +1,43 @@+package main++import (+ "testing"+ "time"+)++// TestQueuedTTLFromEnv pins the env parsing for the queued TTL (the same+// helper and default main passes into runRuntimeSweeper): unset,+// unparseable, or non-positive values fall back to the documented default+// so existing deployments behave identically. A zero TTL must stay invalid:+// it would expire every queued task immediately.+func TestQueuedTTLFromEnv(t *testing.T) {+ tests := []struct {+ name string+ value string+ want time.Duration+ }{+ {name: "unset keeps the built-in default", value: "", want: 2 * time.Hour},+ {name: "positive duration overrides the default", value: "12h", want: 12 * time.Hour},+ {name: "unparseable value falls back to the default", value: "not-a-duration", want: 2 * time.Hour},+ {name: "non-positive value falls back to the default", value: "0s", want: 2 * time.Hour},+ }++ for _, tc := range tests {+ t.Run(tc.name, func(t *testing.T) {+ t.Setenv("MULTICA_TASK_QUEUED_TTL", tc.value)++ got := envDuration("MULTICA_TASK_QUEUED_TTL", defaultTaskQueuedTTL)+ if got != tc.want {+ t.Errorf("MULTICA_TASK_QUEUED_TTL=%q -> %s, want %s", tc.value, got, tc.want)+ }+ })+ }+}++// TestDefaultTaskQueuedTTL pins the built-in default so the documented 2h+// window and the code cannot drift apart.+func TestDefaultTaskQueuedTTL(t *testing.T) {+ if defaultTaskQueuedTTL != 2*time.Hour {+ t.Errorf("defaultTaskQueuedTTL = %s, want 2h", defaultTaskQueuedTTL)+ }+}