Skip to content

Commit b0e9fd6

Browse files
fix(workboard): heal oversized persisted notifications (#120999)
Preserve the existing UTF-16-safe notification cap at the canonical metadata normalization boundary so a legacy oversized row cannot abort dispatch or starve sibling cards. Move the existing capText helper into its normalization owner without production growth. Co-authored-by: licheer-zte <[email protected]> Co-authored-by: Peter Steinberger <[email protected]>
1 parent ecf0631 commit b0e9fd6

6 files changed

Lines changed: 57 additions & 13 deletions

File tree

‎extensions/workboard/src/store-card-helpers.ts‎

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import {
1616
} from "@openclaw/workboard-contract";
1717
import { safeEqualSecret } from "openclaw/plugin-sdk/security-runtime";
1818
import { normalizeOptionalString } from "openclaw/plugin-sdk/string-coerce-runtime";
19-
import { truncateUtf16Safe } from "openclaw/plugin-sdk/text-utility-runtime";
2019
import {
2120
BLOCKED_TOO_LONG_MS,
2221
MAX_CARD_ATTEMPTS,
@@ -26,6 +25,7 @@ import {
2625
} from "./store-constants.js";
2726
import type { WorkboardMutationScope } from "./store-inputs.js";
2827
import {
28+
capText,
2929
metadataIsEmpty,
3030
normalizeEvents,
3131
normalizeTimestamp,
@@ -522,13 +522,6 @@ export function computeCardDiagnostics(card: WorkboardCard, now: number): Workbo
522522
return diagnostics;
523523
}
524524

525-
export function capText(value: string | undefined, max: number): string | undefined {
526-
if (!value) {
527-
return undefined;
528-
}
529-
return value.length <= max ? value : `${truncateUtf16Safe(value, Math.max(0, max - 1))}…`;
530-
}
531-
532525
export function cardBoardId(card: WorkboardCard): string {
533526
return card.metadata?.automation?.boardId ?? "default";
534527
}

‎extensions/workboard/src/store-enrichment.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import type {
88
import type { PersistedWorkboardAttachment } from "./persistence-types.js";
99
import {
1010
assertCanMutateClaimedCard,
11-
capText,
1211
cardRunId,
1312
cardSessionKey,
1413
closeRunningAttempts,
@@ -30,6 +29,7 @@ import type {
3029
WorkboardWorkerLogInput,
3130
} from "./store-inputs.js";
3231
import {
32+
capText,
3333
clearDiagnostics,
3434
normalizeArtifact,
3535
normalizeAttachmentInput,

‎extensions/workboard/src/store-normalizers.ts‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ import {
4444
} from "@openclaw/workboard-contract";
4545
import { resolveNonNegativeIntegerOption } from "openclaw/plugin-sdk/number-runtime";
4646
import { isRecord, normalizeOptionalString } from "openclaw/plugin-sdk/string-coerce-runtime";
47+
import { truncateUtf16Safe } from "openclaw/plugin-sdk/text-utility-runtime";
4748
import {
4849
MAX_ATTACHMENT_BYTES,
4950
MAX_CARD_ARTIFACTS,
@@ -278,6 +279,13 @@ export function normalizeBoundedString(
278279
return normalized;
279280
}
280281

282+
export function capText(value: string | undefined, max: number): string | undefined {
283+
if (!value) {
284+
return undefined;
285+
}
286+
return value.length <= max ? value : `${truncateUtf16Safe(value, Math.max(0, max - 1))}…`;
287+
}
288+
281289
export function normalizeStatus(value: unknown, fallback: WorkboardStatus): WorkboardStatus {
282290
if (typeof value !== "string" || !value.trim()) {
283291
return fallback;
@@ -941,7 +949,7 @@ function normalizeNotification(value: unknown): WorkboardNotification | null {
941949
const kind = normalizeEnumValue(record.kind, WORKBOARD_NOTIFICATION_KINDS, undefined);
942950
const createdAt = normalizeTimestamp(record.createdAt, Date.now());
943951
const sequence = normalizeTimestamp(record.sequence, 0) || undefined;
944-
const message = normalizeBoundedString(record.message, undefined, 240, "notification message");
952+
const message = capText(normalizeOptionalString(record.message), 240);
945953
if (!kind || !message) {
946954
return null;
947955
}

‎extensions/workboard/src/store-workflow.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import { safeEqualSecret } from "openclaw/plugin-sdk/security-runtime";
1313
import { normalizeOptionalString } from "openclaw/plugin-sdk/string-coerce-runtime";
1414
import {
1515
assertCanMutateClaimedCard,
16-
capText,
1716
cardBoardId,
1817
cardChildIds,
1918
cardParentIds,
@@ -48,6 +47,7 @@ import type {
4847
} from "./store-inputs.js";
4948
import {
5049
appendCompletionProof,
50+
capText,
5151
clearDiagnostics,
5252
deriveChildIdempotencyKey,
5353
normalizeArtifact,

‎extensions/workboard/src/store.test.ts‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2748,6 +2748,50 @@ describe("WorkboardStore", () => {
27482748
expect(blocked.metadata?.notifications?.[0]?.message.length).toBeLessThanOrEqual(240);
27492749
});
27502750

2751+
it("heals oversized persisted notifications and keeps dispatching sibling cards", async () => {
2752+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-workboard-notification-"));
2753+
const dbPath = path.join(dir, "workboard.sqlite");
2754+
const stores = createWorkboardSqliteStores({ dbPath });
2755+
try {
2756+
const store = new WorkboardStore(stores.cards);
2757+
const poisoned = await store.create({ title: "Oversized notification", status: "ready" });
2758+
const sibling = await store.create({ title: "Unaffected sibling", status: "ready" });
2759+
const oversized = `${"x".repeat(238)}🦞${" tail".repeat(60)}`;
2760+
const rawDb = new DatabaseSync(dbPath);
2761+
try {
2762+
rawDb
2763+
.prepare(
2764+
"INSERT INTO workboard_card_notifications (id, card_id, ordinal, kind, message, created_at) VALUES (?, ?, ?, ?, ?, ?)",
2765+
)
2766+
.run("oversized", poisoned.id, 0, "failed", oversized, Date.now());
2767+
} finally {
2768+
rawDb.close();
2769+
}
2770+
2771+
expect((await store.get(poisoned.id))?.metadata?.notifications?.[0]?.message).toBe(oversized);
2772+
await expect(store.dispatch()).resolves.toBeDefined();
2773+
2774+
const repaired = await store.get(poisoned.id);
2775+
expect(repaired?.metadata?.notifications?.[0]?.message).toBe(`${"x".repeat(238)}…`);
2776+
expect(repaired?.metadata?.automation?.dispatchCount).toBe(1);
2777+
expect((await store.get(sibling.id))?.metadata?.automation?.dispatchCount).toBe(1);
2778+
2779+
const verifyDb = new DatabaseSync(dbPath, { readOnly: true });
2780+
try {
2781+
expect(
2782+
verifyDb
2783+
.prepare("SELECT message FROM workboard_card_notifications WHERE id = ?")
2784+
.get("oversized"),
2785+
).toEqual({ message: `${"x".repeat(238)}…` });
2786+
} finally {
2787+
verifyDb.close();
2788+
}
2789+
} finally {
2790+
stores.close();
2791+
fs.rmSync(dir, { recursive: true, force: true });
2792+
}
2793+
});
2794+
27512795
it("dispatches ready cards and blocks expired or timed-out work", async () => {
27522796
vi.useFakeTimers();
27532797
try {

‎extensions/workboard/src/store.ts‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import { createWorkboardSqliteStores } from "./sqlite-store.js";
2121
import {
2222
buildWorkerContext,
2323
assertCanMutateClaimedCard,
24-
capText,
2524
cardBoardId,
2625
cardRunId,
2726
cardSessionKey,
@@ -49,7 +48,7 @@ import type {
4948
WorkboardDispatchResult,
5049
WorkboardMutationScope,
5150
} from "./store-inputs.js";
52-
import { normalizeBoardId, normalizeTimestamp } from "./store-normalizers.js";
51+
import { capText, normalizeBoardId, normalizeTimestamp } from "./store-normalizers.js";
5352
import { WorkboardNotificationStore } from "./store-notifications.js";
5453

5554
export type { WorkboardDispatchResult } from "./store-inputs.js";

0 commit comments

Comments
 (0)