From 038da08073239a2bd22eab90b1d5340b04ff1fc6 Mon Sep 17 00:00:00 2001 From: Syu <62822461+SYU8384@users.noreply.github.com> Date: Thu, 11 Jun 2026 20:09:39 +0900 Subject: [PATCH] fix(discord): clean migrated thread binding state (#89552) * fix(discord): clean migrated thread binding state * fix(discord): omit undefined thread binding fields --------- Co-authored-by: Hex --- ...odel-picker-preferences-migrations.test.ts | 2 +- .../model-picker-preferences-migrations.ts | 5 +++- .../src/monitor/thread-bindings.state.ts | 27 ++++++++++++++----- 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/extensions/discord/src/monitor/model-picker-preferences-migrations.test.ts b/extensions/discord/src/monitor/model-picker-preferences-migrations.test.ts index ae64dd9e0aa0..abff98398ea0 100644 --- a/extensions/discord/src/monitor/model-picker-preferences-migrations.test.ts +++ b/extensions/discord/src/monitor/model-picker-preferences-migrations.test.ts @@ -193,7 +193,7 @@ describe("Discord model picker preference migration", () => { expect(plan.pluginId).toBe("discord"); expect(plan.namespace).toBe("thread-bindings"); const entries = await plan.readEntries(); - expect(entries).toEqual([ + expect(entries).toStrictEqual([ { key: "default:legacy-thread", value: { diff --git a/extensions/discord/src/monitor/model-picker-preferences-migrations.ts b/extensions/discord/src/monitor/model-picker-preferences-migrations.ts index 0301d4741470..dfdeb27e8883 100644 --- a/extensions/discord/src/monitor/model-picker-preferences-migrations.ts +++ b/extensions/discord/src/monitor/model-picker-preferences-migrations.ts @@ -195,7 +195,10 @@ export const detectDiscordLegacyStateMigrations: BundledChannelLegacyStateMigrat )) { const normalized = normalizePersistedBinding(rawKey, rawEntry); if (normalized) { - out.push({ key: toBindingRecordKey(normalized), value: normalized }); + out.push({ + key: toBindingRecordKey(normalized), + value: normalized, + }); } } return out; diff --git a/extensions/discord/src/monitor/thread-bindings.state.ts b/extensions/discord/src/monitor/thread-bindings.state.ts index 2ab405a9b29d..18f42ac65f9c 100644 --- a/extensions/discord/src/monitor/thread-bindings.state.ts +++ b/extensions/discord/src/monitor/thread-bindings.state.ts @@ -215,23 +215,36 @@ export function normalizePersistedBinding( } } - return { + const record: ThreadBindingRecord = { accountId, channelId, threadId, targetKind, targetSessionKey, agentId, - label, - webhookId, - webhookToken, boundBy, boundAt, lastActivityAt, - idleTimeoutMs: migratedIdleTimeoutMs, - maxAgeMs: migratedMaxAgeMs, - metadata, }; + if (label !== undefined) { + record.label = label; + } + if (webhookId !== undefined) { + record.webhookId = webhookId; + } + if (webhookToken !== undefined) { + record.webhookToken = webhookToken; + } + if (migratedIdleTimeoutMs !== undefined) { + record.idleTimeoutMs = migratedIdleTimeoutMs; + } + if (migratedMaxAgeMs !== undefined) { + record.maxAgeMs = migratedMaxAgeMs; + } + if (metadata !== undefined) { + record.metadata = metadata; + } + return record; } export function normalizeThreadBindingDurationMs(raw: unknown, defaultsTo: number): number {