

























@@ -36,6 +36,7 @@ import {
3636reconcileOrphanedRestoredRuns,
3737reconcileOrphanedRun,
3838resolveAnnounceRetryDelayMs,
39+resolveArchiveAfterMs,
3940resolveSubagentRunOrphanReason,
4041resolveSubagentSessionStatus,
4142safeRemoveAttachmentsDir,
@@ -196,8 +197,6 @@ const LIFECYCLE_ERROR_RETRY_GRACE_MS = 15_000;
196197 * `timed out` completion right before the eventual success.
197198 */
198199const LIFECYCLE_TIMEOUT_RETRY_GRACE_MS = 15_000;
199-/** Absolute TTL for session-mode runs after cleanup completes (no archiveAtMs). */
200-const SESSION_RUN_TTL_MS = 5 * 60_000; // 5 minutes
201200/** Absolute TTL for orphaned pendingLifecycleError / pendingLifecycleTimeout entries. */
202201const PENDING_LIFECYCLE_TERMINAL_TTL_MS = 5 * 60_000; // 5 minutes
203202/** Grace period before treating a "running" subagent without a live run context as stale. */
@@ -751,6 +750,7 @@ async function sweepSubagentRuns() {
751750try {
752751const now = Date.now();
753752const storeCache = new Map<string, Record<string, SessionEntry>>();
753+const sessionRetentionMs = resolveArchiveAfterMs(subagentRegistryDeps.getRuntimeConfig());
754754let mutated = false;
755755for (const [runId, entry] of subagentRuns.entries()) {
756756if (typeof entry.endedAt !== "number") {
@@ -813,12 +813,18 @@ async function sweepSubagentRuns() {
813813}
814814}
815815816-// Session-mode runs have no archiveAtMs — apply absolute TTL after cleanup completes.
816+// Session-mode runs have no archiveAtMs because the child session is retained
817+// independently — but the registry row itself still needs to be reaped after
818+// cleanup, otherwise `subagents list` and other registry-backed surfaces grow
819+// without bound. Honor the same `agents.defaults.subagents.archiveAfterMinutes`
820+// window run-mode uses for `archiveAtMs`, so operators get one consistent
821+// retention knob (default 60 minutes; 0 disables session-mode reaping).
817822// Use cleanupCompletedAt (not endedAt) to avoid interrupting deferred cleanup flows.
818823if (!entry.archiveAtMs) {
819824if (
825+typeof sessionRetentionMs === "number" &&
820826typeof entry.cleanupCompletedAt === "number" &&
821-now - entry.cleanupCompletedAt > SESSION_RUN_TTL_MS
827+now - entry.cleanupCompletedAt > sessionRetentionMs
822828) {
823829clearPendingLifecycleError(runId);
824830void notifyContextEngineSubagentEnded({
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。