惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Y
Y Combinator Blog
The GitHub Blog
The GitHub Blog
Vercel News
Vercel News
D
DataBreaches.Net
MongoDB | Blog
MongoDB | Blog
H
Help Net Security
小众软件
小众软件
美团技术团队
T
The Blog of Author Tim Ferriss
爱范儿
爱范儿
D
Docker
Martin Fowler
Martin Fowler
大猫的无限游戏
大猫的无限游戏
博客园 - 聂微东
Blog — PlanetScale
Blog — PlanetScale
H
Hackread – Cybersecurity News, Data Breaches, AI and More
罗磊的独立博客
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
V
V2EX
S
SegmentFault 最新的问题
云风的 BLOG
云风的 BLOG
B
Blog
雷峰网
雷峰网
The Cloudflare Blog

Recent Commits to openclaw:main

test: merge chat side-result checks · openclaw/openclaw@ddd2c2a test: merge cron history checks · openclaw/openclaw@f7eb746 test: merge responsive navigation shell checks · openclaw/openclaw@c2e4b47 docs(changelog): add codex oauth fixes · openclaw/openclaw@628e6cd test: merge navigation routing cases · openclaw/openclaw@5d8cecb Tests: mock channel registry bundled fallback · openclaw/openclaw@2b08233 Secrets: avoid broad web search discovery for single plugin config · openclaw/openclaw@a464f59 test: merge config view browser checks · openclaw/openclaw@20cf511 fix(status): align oauth health with runtime · openclaw/openclaw@eed7116 feat: add macOS screen snapshots for monitor preview (#67954) thanks … · openclaw/openclaw@f377db1 fix: report shared auth scopes in hello-ok (#67810) thanks @BunsDev · openclaw/openclaw@0b6c39b Auto-reply: avoid eager bundled route fallback · openclaw/openclaw@3ea1bf4 Tests: narrow session binding contract setup · openclaw/openclaw@54e4e16 fix(macOS): enable undo/redo in webchat composer text input (#34962) · openclaw/openclaw@00951dc Tests: speed up channel setup promotion · openclaw/openclaw@82b529a Docs: refresh agent instructions · openclaw/openclaw@5775fe2 fix(auth): serialize OAuth refresh across agents to fix #26322 (#67876) · openclaw/openclaw@8e79080 test: allow ollama public surface boundary test · openclaw/openclaw@7d4f1a6 Docs: add test performance guardrails · openclaw/openclaw@89706d3 Tests: restore context-engine usage proof · openclaw/openclaw@e4c4f95 Tests: slim context engine runtime coverage · openclaw/openclaw@74c198f ci: retry failed custom checkouts · openclaw/openclaw@0ee5baf test: trim duplicate provider auth onboarding cases · openclaw/openclaw@1ffc02e matrix: fix sessions_spawn --thread subagent session spawning (#67643) · openclaw/openclaw@1ce2596 test: reduce auth choice fixture churn · openclaw/openclaw@857b9cd test: mock health status config boundaries · openclaw/openclaw@9d5ab4a test: mock onboard config io boundary · openclaw/openclaw@299694d test: mock legacy state plugin boundaries · openclaw/openclaw@2713089 test: mock channel install boundaries · openclaw/openclaw@b945248 test: mock doctor preview channel boundaries · openclaw/openclaw@b1a3ad4
fix(cron): clean up isolated sessions after runs · opencl...
TurboTheTurt · 2026-06-22 · via Recent Commits to openclaw:main
11

/** Dispatches isolated cron output to direct delivery, mirrors, and follow-up queues. */

22

import { isAudioFileName } from "@openclaw/media-core/mime";

33

import { normalizeOptionalString } from "@openclaw/normalization-core/string-coerce";

4-

import { retireSessionMcpRuntime } from "../../agents/agent-bundle-mcp-tools.js";

54

import type { ReplyPayload } from "../../auto-reply/reply-payload.js";

65

import {

76

isSilentReplyText,

@@ -39,7 +38,6 @@ import { normalizeTargetForProvider } from "../../infra/outbound/target-normaliz

3938

import { hasReplyPayloadContent } from "../../interactive/payload.js";

4039

import { stringifyRouteThreadId } from "../../plugin-sdk/channel-route.js";

4140

import {

42-

isCronSessionKey,

4341

parseThreadSessionSuffix,

4442

resolveAgentIdFromSessionKey,

4543

} from "../../routing/session-key.js";

@@ -51,6 +49,7 @@ import type { CronJob, CronRunTelemetry } from "../types.js";

5149

import type { DeliveryTargetResolution } from "./delivery-target.js";

5250

import { pickLastNonEmptyTextFromPayloads, pickSummaryFromOutput } from "./helpers.js";

5351

import type { RunCronAgentTurnResult } from "./run.types.js";

52+

import { cleanupCronRunSessionAfterRun } from "./session-cleanup.js";

5453

import { expectsSubagentFollowup, isLikelyInterimCronMessage } from "./subagent-followup-hints.js";

55545655

function normalizeDeliveryTarget(channel: string, to: string): string {

@@ -136,6 +135,7 @@ export type DispatchCronDeliveryState = {

136135

result?: RunCronAgentTurnResult;

137136

delivered: boolean;

138137

deliveryAttempted: boolean;

138+

cronRunSessionCleanupAttempted: boolean;

139139

summary?: string;

140140

outputText?: string;

141141

synthesizedText?: string;

@@ -172,9 +172,6 @@ type CompletedDirectCronDelivery = {

172172

results: OutboundDeliveryResult[];

173173

};

174174175-

const gatewayCallRuntimeLoader = createLazyImportLoader(

176-

() => import("../../gateway/call.runtime.js"),

177-

);

178175

const deliveryOutboundRuntimeLoader = createLazyImportLoader(

179176

() => import("./delivery-outbound.runtime.js"),

180177

);

@@ -197,10 +194,6 @@ const ttsRuntimeLoader = createLazyImportLoader(() => import("../../tts/tts.runt

197194198195

const COMPLETED_DIRECT_CRON_DELIVERIES = new Map<string, CompletedDirectCronDelivery>();

199196200-

async function loadGatewayCallRuntime(): Promise<typeof import("../../gateway/call.runtime.js")> {

201-

return await gatewayCallRuntimeLoader.load();

202-

}

203-204197

async function loadDeliveryOutboundRuntime(): Promise<

205198

typeof import("./delivery-outbound.runtime.js")

206199

> {

@@ -256,29 +249,12 @@ export async function cleanupDirectCronSession(params: {

256249

sessionId: string;

257250

retireReason: string;

258251

}): Promise<void> {

259-

if (!params.job.deleteAfterRun) {

260-

return;

261-

}

262-

if (!isCronSessionKey(params.agentSessionKey)) {

263-

return;

264-

}

265-

try {

266-

const { callGateway } = await loadGatewayCallRuntime();

267-

await callGateway({

268-

method: "sessions.delete",

269-

params: {

270-

key: params.agentSessionKey,

271-

deleteTranscript: true,

272-

emitLifecycleHooks: false,

273-

},

274-

timeoutMs: 10_000,

275-

});

276-

} catch {

277-

await retireSessionMcpRuntime({

278-

sessionId: params.sessionId,

279-

reason: params.retireReason,

280-

});

281-

}

252+

await cleanupCronRunSessionAfterRun({

253+

job: params.job,

254+

agentSessionKey: params.agentSessionKey,

255+

sessionId: params.sessionId,

256+

reason: params.retireReason,

257+

});

282258

}

283259284260

function logCronDeliveryErrorDeferred(message: string): void {

@@ -940,7 +916,17 @@ export async function dispatchCronDelivery(

940916941917

let delivered = verifiedMessageToolDelivery;

942918

let deliveryAttempted = verifiedMessageToolDelivery;

943-

let directCronSessionDeleted = false;

919+

let directCronSessionCleanupAttempted = false;

920+

const buildDeliveryState = (result?: RunCronAgentTurnResult): DispatchCronDeliveryState => ({

921+

...(result ? { result } : {}),

922+

delivered,

923+

deliveryAttempted,

924+

cronRunSessionCleanupAttempted: directCronSessionCleanupAttempted,

925+

summary,

926+

outputText,

927+

synthesizedText,

928+

deliveryPayloads,

929+

});

944930

const formatDeliveryTargetError = (error: string) =>

945931

params.sourceDeliveryOutcome.unverifiedMessageToolDelivery

946932

? `${error}; the agent used the message tool, but OpenClaw could not verify that message matched the cron delivery target`

@@ -956,16 +942,18 @@ export async function dispatchCronDelivery(

956942

...params.telemetry,

957943

});

958944

const cleanupDirectCronSessionIfNeeded = async (): Promise<void> => {

959-

if (directCronSessionDeleted) {

945+

if (directCronSessionCleanupAttempted) {

960946

return;

961947

}

962-

directCronSessionDeleted = true;

963-

await cleanupDirectCronSession({

948+

const cleanupAttempted = await cleanupCronRunSessionAfterRun({

964949

job: params.job,

965950

agentSessionKey: params.agentSessionKey,

966951

sessionId: params.sessionId,

967-

retireReason: "cron-delete-after-run-fallback",

952+

reason: "cron-delete-after-run-fallback",

968953

});

954+

if (cleanupAttempted) {

955+

directCronSessionCleanupAttempted = true;

956+

}

969957

};

970958

const finishSilentReplyDelivery = async (): Promise<RunCronAgentTurnResult> => {

971959

deliveryAttempted = true;

@@ -1417,32 +1405,18 @@ export async function dispatchCronDelivery(

14171405

// non-deleteAfterRun / non-cron sessions (see cleanupDirectCronSession).

14181406

await cleanupDirectCronSessionIfNeeded();

14191407

if (!params.deliveryBestEffort) {

1420-

return {

1421-

result: failDeliveryTarget(params.resolvedDelivery.error.message),

1422-

delivered,

1423-

deliveryAttempted,

1424-

summary,

1425-

outputText,

1426-

synthesizedText,

1427-

deliveryPayloads,

1428-

};

1408+

return buildDeliveryState(failDeliveryTarget(params.resolvedDelivery.error.message));

14291409

}

14301410

await logCronDeliveryWarn(`[cron:${params.job.id}] ${params.resolvedDelivery.error.message}`);

1431-

return {

1432-

result: params.withRunSession({

1411+

return buildDeliveryState(

1412+

params.withRunSession({

14331413

status: "ok",

14341414

summary,

14351415

outputText,

14361416

deliveryAttempted,

14371417

...params.telemetry,

14381418

}),

1439-

delivered,

1440-

deliveryAttempted,

1441-

summary,

1442-

outputText,

1443-

synthesizedText,

1444-

deliveryPayloads,

1445-

};

1419+

);

14461420

}

1447142114481422

// Finalize descendant/subagent output first for text-only cron runs, then

@@ -1453,38 +1427,15 @@ export async function dispatchCronDelivery(

14531427

if (useDirectDelivery) {

14541428

const directResult = await deliverViaDirectAndCleanup(params.resolvedDelivery);

14551429

if (directResult) {

1456-

return {

1457-

result: directResult,

1458-

delivered,

1459-

deliveryAttempted,

1460-

summary,

1461-

outputText,

1462-

synthesizedText,

1463-

deliveryPayloads,

1464-

};

1430+

return buildDeliveryState(directResult);

14651431

}

14661432

} else {

14671433

const finalizedTextResult = await finalizeTextDelivery(params.resolvedDelivery);

14681434

if (finalizedTextResult) {

1469-

return {

1470-

result: finalizedTextResult,

1471-

delivered,

1472-

deliveryAttempted,

1473-

summary,

1474-

outputText,

1475-

synthesizedText,

1476-

deliveryPayloads,

1477-

};

1435+

return buildDeliveryState(finalizedTextResult);

14781436

}

14791437

}

14801438

}

148114391482-

return {

1483-

delivered,

1484-

deliveryAttempted,

1485-

summary,

1486-

outputText,

1487-

synthesizedText,

1488-

deliveryPayloads,

1489-

};

1440+

return buildDeliveryState();

14901441

}