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

推荐订阅源

J
Java Code Geeks
Google DeepMind News
Google DeepMind News
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
小众软件
小众软件
Blog — PlanetScale
Blog — PlanetScale
腾讯CDC
A
About on SuperTechFans
Vercel News
Vercel News
I
InfoQ
阮一峰的网络日志
阮一峰的网络日志
月光博客
月光博客
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
人人都是产品经理
人人都是产品经理
S
SegmentFault 最新的问题
V
Visual Studio Blog
T
Tailwind CSS Blog
大猫的无限游戏
大猫的无限游戏
M
MIT News - Artificial intelligence
博客园 - 【当耐特】
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Microsoft Azure Blog
Microsoft Azure Blog
Apple Machine Learning Research
Apple Machine Learning Research
GbyAI
GbyAI
美团技术团队

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
refactor(cron): keep legacy notify migration in doctor · ...
steipete · 2026-05-31 · via Recent Commits to openclaw:main
11

import path from "node:path";

2-

import type { DatabaseSync } from "node:sqlite";

32

import {

43

normalizeLowercaseStringOrEmpty,

54

normalizeOptionalString,

65

normalizeStringifiedOptionalString,

76

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

87

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

9-

import type { Insertable, Selectable } from "kysely";

108

import { parseByteSize } from "../cli/parse-bytes.js";

119

import type { CronConfig } from "../config/types.cron.js";

12-

import { executeSqliteQuerySync, getNodeSqliteKysely } from "../infra/kysely-sync.js";

13-

import type { DB as OpenClawStateKyselyDatabase } from "../state/openclaw-state-db.generated.js";

1410

import {

1511

openOpenClawStateDatabase,

1612

runOpenClawStateWriteTransaction,

1713

} from "../state/openclaw-state-db.js";

1814

import type { CronRunLogEntry } from "./run-log-types.js";

19-

import { parseCronRunLogEntryObject } from "./run-log/entry-codec.js";

15+

import {

16+

countCronRunLogRows,

17+

insertCronRunLogEntry,

18+

parseStoredRunLogEntry,

19+

pruneCronRunLogRows,

20+

readCronRunLogRows,

21+

readCronRunLogRowsPage,

22+

} from "./run-log/sqlite-store.js";

2023

import type { CronDeliveryStatus, CronRunStatus } from "./types.js";

21242225

export type { CronRunLogEntry } from "./run-log-types.js";

@@ -55,11 +58,6 @@ type AppendCronRunLogOptions = {

5558

keepLines?: number | false;

5659

};

576058-

type CronRunLogsTable = OpenClawStateKyselyDatabase["cron_run_logs"];

59-

type CronRunLogDatabase = Pick<OpenClawStateKyselyDatabase, "cron_run_logs">;

60-

type CronRunLogRow = Selectable<CronRunLogsTable>;

61-

type CronRunLogInsert = Insertable<CronRunLogsTable>;

62-6361

const INVALID_CRON_RUN_LOG_JOB_ID_MESSAGE = "invalid cron run log job id";

64626563

function assertSafeCronRunLogJobId(jobId: string): string {

@@ -132,207 +130,6 @@ function cronStoreKey(storePath: string): string {

132130

return path.resolve(storePath);

133131

}

134132135-

function getCronRunLogKysely(db: DatabaseSync) {

136-

return getNodeSqliteKysely<CronRunLogDatabase>(db);

137-

}

138-139-

function normalizeNumber(value: number | bigint | null): number | undefined {

140-

if (typeof value === "bigint") {

141-

return Number(value);

142-

}

143-

return typeof value === "number" ? value : undefined;

144-

}

145-146-

function booleanToInteger(value: boolean | undefined): number | null {

147-

return typeof value === "boolean" ? (value ? 1 : 0) : null;

148-

}

149-150-

function integerToBoolean(value: number | bigint | null): boolean | undefined {

151-

const normalized = normalizeNumber(value);

152-

return normalized == null ? undefined : normalized !== 0;

153-

}

154-155-

function bindCronRunLogRow(params: {

156-

storeKey: string;

157-

seq: number;

158-

entry: CronRunLogEntry;

159-

}): CronRunLogInsert {

160-

const entry = params.entry;

161-

return {

162-

store_key: params.storeKey,

163-

job_id: entry.jobId,

164-

seq: params.seq,

165-

ts: entry.ts,

166-

status: entry.status ?? null,

167-

error: entry.error ?? null,

168-

summary: entry.summary ?? null,

169-

diagnostics_summary: entry.diagnostics?.summary ?? null,

170-

delivery_status: entry.deliveryStatus ?? null,

171-

delivery_error: entry.deliveryError ?? null,

172-

delivered: booleanToInteger(entry.delivered),

173-

session_id: entry.sessionId ?? null,

174-

session_key: entry.sessionKey ?? null,

175-

run_id: entry.runId ?? null,

176-

run_at_ms: entry.runAtMs ?? null,

177-

duration_ms: entry.durationMs ?? null,

178-

next_run_at_ms: entry.nextRunAtMs ?? null,

179-

model: entry.model ?? null,

180-

provider: entry.provider ?? null,

181-

total_tokens: entry.usage?.total_tokens ?? null,

182-

entry_json: JSON.stringify(entry),

183-

created_at: Date.now(),

184-

};

185-

}

186-187-

function parseStoredRunLogEntry(row: CronRunLogRow): CronRunLogEntry | null {

188-

let rawEntry: unknown;

189-

try {

190-

rawEntry = JSON.parse(row.entry_json);

191-

} catch {

192-

return null;

193-

}

194-

const parsed = parseCronRunLogEntryObject(rawEntry, { jobId: row.job_id });

195-

if (!parsed) {

196-

return null;

197-

}

198-

return {

199-

...parsed,

200-

ts: normalizeNumber(row.ts) ?? parsed.ts,

201-

jobId: row.job_id,

202-

status: (row.status as CronRunStatus | null) ?? parsed.status,

203-

error: row.error ?? parsed.error,

204-

summary: row.summary ?? parsed.summary,

205-

delivered: integerToBoolean(row.delivered) ?? parsed.delivered,

206-

deliveryStatus: (row.delivery_status as CronDeliveryStatus | null) ?? parsed.deliveryStatus,

207-

deliveryError: row.delivery_error ?? parsed.deliveryError,

208-

sessionId: row.session_id ?? parsed.sessionId,

209-

sessionKey: row.session_key ?? parsed.sessionKey,

210-

runId: row.run_id ?? parsed.runId,

211-

runAtMs: normalizeNumber(row.run_at_ms) ?? parsed.runAtMs,

212-

durationMs: normalizeNumber(row.duration_ms) ?? parsed.durationMs,

213-

nextRunAtMs: normalizeNumber(row.next_run_at_ms) ?? parsed.nextRunAtMs,

214-

model: row.model ?? parsed.model,

215-

provider: row.provider ?? parsed.provider,

216-

};

217-

}

218-219-

function readCronRunLogRows(db: DatabaseSync, storeKey: string, jobId?: string): CronRunLogRow[] {

220-

let query = getCronRunLogKysely(db)

221-

.selectFrom("cron_run_logs")

222-

.selectAll()

223-

.where("store_key", "=", storeKey);

224-

if (jobId) {

225-

query = query.where("job_id", "=", jobId);

226-

}

227-

return executeSqliteQuerySync(db, query.orderBy("ts", "asc").orderBy("seq", "asc")).rows;

228-

}

229-230-

function buildRunLogWhereClause(params: {

231-

storeKey: string;

232-

jobId?: string;

233-

statuses: CronRunStatus[] | null;

234-

deliveryStatuses: CronDeliveryStatus[] | null;

235-

runId?: string;

236-

}): { whereSql: string; values: Array<string | number> } {

237-

const clauses = ["store_key = ?"];

238-

const values: Array<string | number> = [params.storeKey];

239-

if (params.jobId) {

240-

clauses.push("job_id = ?");

241-

values.push(params.jobId);

242-

}

243-

if (params.statuses?.length) {

244-

clauses.push(`status IN (${params.statuses.map(() => "?").join(", ")})`);

245-

values.push(...params.statuses);

246-

}

247-

if (params.deliveryStatuses?.length) {

248-

clauses.push(

249-

`COALESCE(delivery_status, 'not-requested') IN (${params.deliveryStatuses

250-

.map(() => "?")

251-

.join(", ")})`,

252-

);

253-

values.push(...params.deliveryStatuses);

254-

}

255-

const runId = normalizeOptionalString(params.runId);

256-

if (runId) {

257-

clauses.push("run_id = ?");

258-

values.push(runId);

259-

}

260-

return { whereSql: clauses.join(" AND "), values };

261-

}

262-263-

function countCronRunLogRows(

264-

db: DatabaseSync,

265-

whereSql: string,

266-

values: Array<string | number>,

267-

): number {

268-

const row = db

269-

.prepare(`SELECT COUNT(*) AS count FROM cron_run_logs WHERE ${whereSql}`)

270-

.get(...values) as { count?: number | bigint } | undefined;

271-

return normalizeNumber(row?.count ?? null) ?? 0;

272-

}

273-274-

function readCronRunLogRowsPage(params: {

275-

db: DatabaseSync;

276-

storeKey: string;

277-

jobId?: string;

278-

statuses: CronRunStatus[] | null;

279-

deliveryStatuses: CronDeliveryStatus[] | null;

280-

runId?: string;

281-

sortDir: CronRunLogSortDir;

282-

offset?: number;

283-

limit?: number;

284-

}): CronRunLogRow[] {

285-

const { whereSql, values } = buildRunLogWhereClause(params);

286-

const order = params.sortDir === "asc" ? "ASC" : "DESC";

287-

const limitSql =

288-

params.limit === undefined || params.offset === undefined ? "" : " LIMIT ? OFFSET ?";

289-

const limitValues =

290-

params.limit === undefined || params.offset === undefined ? [] : [params.limit, params.offset];

291-

return params.db

292-

.prepare(

293-

`SELECT * FROM cron_run_logs WHERE ${whereSql} ORDER BY ts ${order}, seq ${order}${limitSql}`,

294-

)

295-

.all(...values, ...limitValues) as CronRunLogRow[];

296-

}

297-298-

function nextCronRunLogSeq(db: DatabaseSync, storeKey: string, jobId: string): number {

299-

const row = db

300-

.prepare(

301-

"SELECT COALESCE(MAX(seq), 0) AS seq FROM cron_run_logs WHERE store_key = ? AND job_id = ?",

302-

)

303-

.get(storeKey, jobId) as { seq?: number | bigint } | undefined;

304-

return (normalizeNumber(row?.seq ?? null) ?? 0) + 1;

305-

}

306-307-

function insertCronRunLogEntry(db: DatabaseSync, storeKey: string, entry: CronRunLogEntry): void {

308-

const seq = nextCronRunLogSeq(db, storeKey, entry.jobId);

309-

executeSqliteQuerySync(

310-

db,

311-

getCronRunLogKysely(db)

312-

.insertInto("cron_run_logs")

313-

.values(bindCronRunLogRow({ storeKey, seq, entry })),

314-

);

315-

}

316-317-

function pruneCronRunLogRows(

318-

db: DatabaseSync,

319-

storeKey: string,

320-

jobId: string,

321-

keepLines: number,

322-

): void {

323-

const keep = Math.max(1, Math.floor(keepLines));

324-

db.prepare(

325-

`DELETE FROM cron_run_logs

326-

WHERE store_key = ? AND job_id = ?

327-

AND seq NOT IN (

328-

SELECT seq FROM cron_run_logs

329-

WHERE store_key = ? AND job_id = ?

330-

ORDER BY seq DESC

331-

LIMIT ?

332-

)`,

333-

).run(storeKey, jobId, storeKey, jobId, keep);

334-

}

335-336133

export async function appendCronRunLog(params: {

337134

storePath: string;

338135

entry: CronRunLogEntry;

@@ -503,14 +300,14 @@ export async function readCronRunLogEntriesPage(

503300

const offset = Math.max(0, Math.floor(opts.offset ?? 0));

504301505302

if (!query) {

506-

const { whereSql, values } = buildRunLogWhereClause({

303+

const total = countCronRunLogRows({

304+

db,

507305

storeKey,

508306

jobId,

509307

statuses,

510308

deliveryStatuses,

511309

runId: opts.runId,

512310

});

513-

const total = countCronRunLogRows(db, whereSql, values);

514311

const boundedOffset = Math.min(total, offset);

515312

const entries = readCronRunLogRowsPage({

516313

db,