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

推荐订阅源

V
V2EX
aimingoo的专栏
aimingoo的专栏
S
SegmentFault 最新的问题
博客园_首页
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
IT之家
IT之家
博客园 - 【当耐特】
月光博客
月光博客
C
Check Point Blog
T
The Blog of Author Tim Ferriss
罗磊的独立博客
博客园 - Franky
MongoDB | Blog
MongoDB | Blog
H
Help Net Security
Microsoft Security Blog
Microsoft Security Blog
B
Blog
阮一峰的网络日志
阮一峰的网络日志
腾讯CDC
美团技术团队
N
Netflix TechBlog - Medium
Stack Overflow Blog
Stack Overflow Blog
Y
Y Combinator Blog
L
LangChain 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(config): sanitize pending delivery hydration · opencl...
vincentkoc · 2026-05-16 · via Recent Commits to openclaw:main

@@ -1,6 +1,9 @@

11

import fs from "node:fs";

22

import { createSubsystemLogger } from "../../logging/subsystem.js";

3-

import { normalizeSessionDeliveryFields } from "../../utils/delivery-context.shared.js";

3+

import {

4+

normalizeDeliveryContext,

5+

normalizeSessionDeliveryFields,

6+

} from "../../utils/delivery-context.shared.js";

47

import { getFileStatSnapshot } from "../cache-utils.js";

58

import {

69

cloneSessionStoreRecord,

@@ -37,6 +40,104 @@ function isSessionEntryRecord(value: unknown): value is SessionEntry {

3740

return !!value && typeof value === "object" && !Array.isArray(value);

3841

}

394243+

function isRecord(value: unknown): value is Record<string, unknown> {

44+

return !!value && typeof value === "object" && !Array.isArray(value);

45+

}

46+47+

function normalizeOptionalFiniteNumber(value: unknown): number | undefined {

48+

return typeof value === "number" && Number.isFinite(value) && value >= 0 ? value : undefined;

49+

}

50+51+

function normalizeOptionalAttemptCount(value: unknown): number | undefined {

52+

return typeof value === "number" && Number.isInteger(value) && value >= 0 ? value : undefined;

53+

}

54+55+

function normalizeOptionalStringOrNull(value: unknown): string | null | undefined {

56+

if (value === null || typeof value === "string") {

57+

return value;

58+

}

59+

return undefined;

60+

}

61+62+

function normalizeOptionalDeliveryContext(

63+

value: unknown,

64+

): SessionEntry["pendingFinalDeliveryContext"] {

65+

if (!isRecord(value)) {

66+

return undefined;

67+

}

68+

const normalized = normalizeDeliveryContext({

69+

channel: typeof value.channel === "string" ? value.channel : undefined,

70+

to: typeof value.to === "string" ? value.to : undefined,

71+

accountId: typeof value.accountId === "string" ? value.accountId : undefined,

72+

threadId:

73+

typeof value.threadId === "string" || typeof value.threadId === "number"

74+

? value.threadId

75+

: undefined,

76+

});

77+

return normalized?.channel && normalized.to ? normalized : undefined;

78+

}

79+80+

function sameDeliveryContext(

81+

left: SessionEntry["pendingFinalDeliveryContext"],

82+

right: SessionEntry["pendingFinalDeliveryContext"],

83+

): boolean {

84+

return (

85+

(left?.channel ?? undefined) === (right?.channel ?? undefined) &&

86+

(left?.to ?? undefined) === (right?.to ?? undefined) &&

87+

(left?.accountId ?? undefined) === (right?.accountId ?? undefined) &&

88+

(left?.threadId ?? undefined) === (right?.threadId ?? undefined)

89+

);

90+

}

91+92+

function normalizePendingFinalDeliveryFields(entry: SessionEntry): SessionEntry {

93+

let next = entry;

94+95+

const assign = <K extends keyof SessionEntry>(key: K, value: SessionEntry[K] | undefined) => {

96+

if (entry[key] === value) {

97+

return;

98+

}

99+

if (next === entry) {

100+

next = { ...entry };

101+

}

102+

if (value === undefined) {

103+

delete next[key];

104+

} else {

105+

next[key] = value;

106+

}

107+

};

108+109+

assign("pendingFinalDelivery", entry.pendingFinalDelivery === true ? true : undefined);

110+

assign("pendingFinalDeliveryText", normalizeOptionalStringOrNull(entry.pendingFinalDeliveryText));

111+

assign(

112+

"pendingFinalDeliveryCreatedAt",

113+

normalizeOptionalFiniteNumber(entry.pendingFinalDeliveryCreatedAt),

114+

);

115+

assign(

116+

"pendingFinalDeliveryLastAttemptAt",

117+

normalizeOptionalFiniteNumber(entry.pendingFinalDeliveryLastAttemptAt),

118+

);

119+

assign(

120+

"pendingFinalDeliveryAttemptCount",

121+

normalizeOptionalAttemptCount(entry.pendingFinalDeliveryAttemptCount),

122+

);

123+

assign(

124+

"pendingFinalDeliveryLastError",

125+

normalizeOptionalStringOrNull(entry.pendingFinalDeliveryLastError),

126+

);

127+

const pendingFinalDeliveryContext = normalizeOptionalDeliveryContext(

128+

entry.pendingFinalDeliveryContext,

129+

);

130+

if (!sameDeliveryContext(entry.pendingFinalDeliveryContext, pendingFinalDeliveryContext)) {

131+

assign("pendingFinalDeliveryContext", pendingFinalDeliveryContext);

132+

}

133+

assign(

134+

"pendingFinalDeliveryIntentId",

135+

normalizeOptionalStringOrNull(entry.pendingFinalDeliveryIntentId),

136+

);

137+138+

return next;

139+

}

140+40141

function normalizeSessionEntryDelivery(entry: SessionEntry): SessionEntry {

41142

const normalized = normalizeSessionDeliveryFields({

42143

channel: entry.channel,

@@ -94,7 +195,9 @@ export function normalizeSessionStore(store: Record<string, SessionEntry>): bool

94195

continue;

95196

}

96197

const normalized = stripPersistedSkillsCache(

97-

normalizeSessionEntryDelivery(normalizeSessionRuntimeModelFields(entry)),

198+

normalizePendingFinalDeliveryFields(

199+

normalizeSessionEntryDelivery(normalizeSessionRuntimeModelFields(entry)),

200+

),

98201

);

99202

if (normalized !== entry) {

100203

store[key] = normalized;