Telegram: persist detached plugin bindings

This commit is contained in:
huntharo 2026-03-15 11:31:35 -04:00 committed by Vincent Koc
parent 7ef75b8779
commit 24850b5cc4
2 changed files with 43 additions and 1 deletions

View File

@ -211,4 +211,40 @@ describe("telegram thread bindings", () => {
);
expect(fs.existsSync(statePath)).toBe(false);
});
it("persists unbinds before restart so removed bindings do not come back", async () => {
stateDirOverride = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-telegram-bindings-"));
process.env.OPENCLAW_STATE_DIR = stateDirOverride;
createTelegramThreadBindingManager({
accountId: "default",
persist: true,
enableSweeper: false,
});
const bound = await getSessionBindingService().bind({
targetSessionKey: "plugin-binding:openclaw-codex-app-server:abc123",
targetKind: "session",
conversation: {
channel: "telegram",
accountId: "default",
conversationId: "8460800771",
},
});
await getSessionBindingService().unbind({
bindingId: bound.bindingId,
reason: "test-detach",
});
__testing.resetTelegramThreadBindingsForTests();
const reloaded = createTelegramThreadBindingManager({
accountId: "default",
persist: true,
enableSweeper: false,
});
expect(reloaded.getByConversationId("8460800771")).toBeUndefined();
});
});

View File

@ -544,7 +544,7 @@ export function createTelegramThreadBindingManager(
resolveBindingKey({ accountId, conversationId }),
record,
);
void persistBindingsToDisk({ accountId, persist: manager.shouldPersistMutations() });
await persistBindingsToDisk({ accountId, persist: manager.shouldPersistMutations() });
logVerbose(
`telegram: bound conversation ${conversationId} -> ${targetSessionKey} (${summarizeLifecycleForLog(
record,
@ -604,6 +604,9 @@ export function createTelegramThreadBindingManager(
reason: input.reason,
sendFarewell: false,
});
if (removed.length > 0) {
await persistBindingsToDisk({ accountId, persist: manager.shouldPersistMutations() });
}
return removed.map((entry) =>
toSessionBindingRecord(entry, {
idleTimeoutMs,
@ -623,6 +626,9 @@ export function createTelegramThreadBindingManager(
reason: input.reason,
sendFarewell: false,
});
if (removed) {
await persistBindingsToDisk({ accountId, persist: manager.shouldPersistMutations() });
}
return removed
? [
toSessionBindingRecord(removed, {