refactor: drop legacy session store keys

This commit is contained in:
Peter Steinberger
2026-01-17 06:48:34 +00:00
parent 353d778988
commit 37a2eee837
22 changed files with 65 additions and 93 deletions

View File

@@ -1,6 +1,7 @@
import { loadConfig } from "../config/config.js";
import { loadSessionStore, resolveStorePath } from "../config/sessions.js";
import { getAgentRunContext, registerAgentRunContext } from "../infra/agent-events.js";
import { parseAgentSessionKey } from "../routing/session-key.js";
export function resolveSessionKeyForRun(runId: string) {
const cached = getAgentRunContext(runId)?.sessionKey;
@@ -9,9 +10,12 @@ export function resolveSessionKeyForRun(runId: string) {
const storePath = resolveStorePath(cfg.session?.store);
const store = loadSessionStore(storePath);
const found = Object.entries(store).find(([, entry]) => entry?.sessionId === runId);
const sessionKey = found?.[0];
if (sessionKey) {
const storeKey = found?.[0];
if (storeKey) {
const parsed = parseAgentSessionKey(storeKey);
const sessionKey = parsed?.rest ?? storeKey;
registerAgentRunContext(runId, { sessionKey });
return sessionKey;
}
return sessionKey;
return undefined;
}

View File

@@ -30,7 +30,7 @@ describe("gateway server agent", () => {
testState.sessionStorePath,
JSON.stringify(
{
main: {
"agent:main:main": {
sessionId: "sess-main-stale",
updatedAt: Date.now(),
lastChannel: "whatsapp",
@@ -115,7 +115,7 @@ describe("gateway server agent", () => {
testState.sessionStorePath,
JSON.stringify(
{
main: {
"agent:main:main": {
sessionId: "sess-main-account",
updatedAt: Date.now(),
lastChannel: "whatsapp",
@@ -160,7 +160,7 @@ describe("gateway server agent", () => {
testState.sessionStorePath,
JSON.stringify(
{
main: {
"agent:main:main": {
sessionId: "sess-main-explicit",
updatedAt: Date.now(),
lastChannel: "whatsapp",
@@ -205,7 +205,7 @@ describe("gateway server agent", () => {
testState.sessionStorePath,
JSON.stringify(
{
main: {
"agent:main:main": {
sessionId: "sess-main-explicit-account",
updatedAt: Date.now(),
lastChannel: "whatsapp",
@@ -251,7 +251,7 @@ describe("gateway server agent", () => {
testState.sessionStorePath,
JSON.stringify(
{
main: {
"agent:main:main": {
sessionId: "sess-main-implicit",
updatedAt: Date.now(),
lastChannel: "whatsapp",
@@ -294,7 +294,7 @@ describe("gateway server agent", () => {
testState.sessionStorePath,
JSON.stringify(
{
main: {
"agent:main:main": {
sessionId: "sess-main-images",
updatedAt: Date.now(),
},
@@ -347,7 +347,7 @@ describe("gateway server agent", () => {
testState.sessionStorePath,
JSON.stringify(
{
main: {
"agent:main:main": {
sessionId: "sess-main-missing-provider",
updatedAt: Date.now(),
},
@@ -388,7 +388,7 @@ describe("gateway server agent", () => {
testState.sessionStorePath,
JSON.stringify(
{
main: {
"agent:main:main": {
sessionId: "sess-main-whatsapp",
updatedAt: Date.now(),
lastChannel: "whatsapp",
@@ -433,7 +433,7 @@ describe("gateway server agent", () => {
testState.sessionStorePath,
JSON.stringify(
{
main: {
"agent:main:main": {
sessionId: "sess-main",
updatedAt: Date.now(),
lastChannel: "telegram",
@@ -477,7 +477,7 @@ describe("gateway server agent", () => {
testState.sessionStorePath,
JSON.stringify(
{
main: {
"agent:main:main": {
sessionId: "sess-discord",
updatedAt: Date.now(),
lastChannel: "discord",
@@ -521,7 +521,7 @@ describe("gateway server agent", () => {
testState.sessionStorePath,
JSON.stringify(
{
main: {
"agent:main:main": {
sessionId: "sess-slack",
updatedAt: Date.now(),
lastChannel: "slack",
@@ -565,7 +565,7 @@ describe("gateway server agent", () => {
testState.sessionStorePath,
JSON.stringify(
{
main: {
"agent:main:main": {
sessionId: "sess-signal",
updatedAt: Date.now(),
lastChannel: "signal",

View File

@@ -84,7 +84,7 @@ describe("gateway server agent", () => {
testState.sessionStorePath,
JSON.stringify(
{
main: {
"agent:main:main": {
sessionId: "sess-teams",
updatedAt: Date.now(),
lastChannel: "msteams",
@@ -137,7 +137,7 @@ describe("gateway server agent", () => {
testState.sessionStorePath,
JSON.stringify(
{
main: {
"agent:main:main": {
sessionId: "sess-alias",
updatedAt: Date.now(),
lastChannel: "imessage",
@@ -210,7 +210,7 @@ describe("gateway server agent", () => {
testState.sessionStorePath,
JSON.stringify(
{
main: {
"agent:main:main": {
sessionId: "sess-main-webchat",
updatedAt: Date.now(),
lastChannel: "webchat",
@@ -254,7 +254,7 @@ describe("gateway server agent", () => {
testState.sessionStorePath,
JSON.stringify(
{
main: {
"agent:main:main": {
sessionId: "sess-main-webchat-internal",
updatedAt: Date.now(),
lastChannel: "webchat",
@@ -412,7 +412,7 @@ describe("gateway server agent", () => {
testState.sessionStorePath,
JSON.stringify(
{
main: {
"agent:main:main": {
sessionId: "sess-main",
updatedAt: Date.now(),
},

View File

@@ -240,7 +240,7 @@ describe("gateway server chat", () => {
testState.sessionStorePath,
JSON.stringify(
{
main: {
"agent:main:main": {
sessionId: "sess-main",
updatedAt: Date.now(),
},
@@ -353,7 +353,7 @@ describe("gateway server chat", () => {
testState.sessionStorePath,
JSON.stringify(
{
main: {
"agent:main:main": {
sessionId: "sess-main",
sessionFile: forkedPath,
updatedAt: Date.now(),
@@ -401,7 +401,7 @@ describe("gateway server chat", () => {
testState.sessionStorePath,
JSON.stringify(
{
main: {
"agent:main:main": {
sessionId: "sess-main",
updatedAt: Date.now(),
},
@@ -451,7 +451,7 @@ describe("gateway server chat", () => {
testState.sessionStorePath,
JSON.stringify(
{
main: {
"agent:main:main": {
sessionId: "sess-main",
updatedAt: Date.now(),
},

View File

@@ -221,7 +221,7 @@ describe("gateway server node/bridge", () => {
testState.sessionStorePath,
JSON.stringify(
{
main: {
"agent:main:main": {
sessionId: "sess-main",
updatedAt: Date.now(),
},
@@ -278,7 +278,7 @@ describe("gateway server node/bridge", () => {
testState.sessionStorePath,
JSON.stringify(
{
main: {
"agent:main:main": {
sessionId: "sess-main",
updatedAt: Date.now(),
},
@@ -335,7 +335,7 @@ describe("gateway server node/bridge", () => {
testState.sessionStorePath,
JSON.stringify(
{
main: {
"agent:main:main": {
sessionId: "sess-main",
updatedAt: Date.now(),
},
@@ -412,7 +412,7 @@ describe("gateway server node/bridge", () => {
testState.sessionStorePath,
JSON.stringify(
{
main: {
"agent:main:main": {
sessionId: "sess-main",
updatedAt: Date.now(),
},

View File

@@ -46,7 +46,7 @@ describe("gateway server node/bridge", () => {
testState.sessionStorePath,
JSON.stringify(
{
main: {
"agent:main:main": {
sessionId: "sess-main",
updatedAt: Date.now(),
lastChannel: "whatsapp",
@@ -83,7 +83,7 @@ describe("gateway server node/bridge", () => {
string,
{ sessionId?: string } | undefined
>;
expect(stored.main?.sessionId).toBe("sess-main");
expect(stored["agent:main:main"]?.sessionId).toBe("sess-main");
expect(stored["node-ios-node"]).toBeUndefined();
await server.close();
@@ -96,7 +96,7 @@ describe("gateway server node/bridge", () => {
testState.sessionStorePath,
JSON.stringify(
{
main: {
"agent:main:main": {
sessionId: "sess-main",
updatedAt: Date.now(),
},
@@ -187,7 +187,7 @@ describe("gateway server node/bridge", () => {
testState.sessionStorePath,
JSON.stringify(
{
main: {
"agent:main:main": {
sessionId: "sess-main",
updatedAt: Date.now(),
},

View File

@@ -359,8 +359,8 @@ describe("gateway server sessions", () => {
storePath,
JSON.stringify(
{
main: { sessionId: "sess-main", updatedAt: Date.now() },
"discord:group:dev": {
"agent:main:main": { sessionId: "sess-main", updatedAt: Date.now() },
"agent:main:discord:group:dev": {
sessionId: "sess-active",
updatedAt: Date.now(),
},

View File

@@ -50,10 +50,7 @@ export function loadSessionEntry(sessionKey: string) {
const agentId = resolveSessionStoreAgentId(cfg, canonicalKey);
const storePath = resolveStorePath(sessionCfg?.store, { agentId });
const store = loadSessionStore(storePath);
const parsed = parseAgentSessionKey(canonicalKey);
const legacyKey = parsed?.rest ?? parseAgentSessionKey(sessionKey)?.rest ?? undefined;
const entry =
store[canonicalKey] ?? store[sessionKey] ?? (legacyKey ? store[legacyKey] : undefined);
const entry = store[canonicalKey];
return { cfg, storePath, store, entry, canonicalKey };
}
@@ -248,10 +245,8 @@ export function resolveGatewaySessionStoreTarget(params: { cfg: ClawdbotConfig;
return { agentId, storePath, canonicalKey, storeKeys };
}
const parsed = parseAgentSessionKey(canonicalKey);
const storeKeys = new Set<string>();
storeKeys.add(canonicalKey);
if (parsed?.rest) storeKeys.add(parsed.rest);
if (key && key !== canonicalKey) storeKeys.add(key);
return {
agentId,

View File

@@ -1,3 +1,4 @@
import type { NormalizedChatType } from "../channels/chat-type.js";
import type { SessionEntry } from "../config/sessions.js";
import type { DeliveryContext } from "../utils/delivery-context.js";
@@ -16,7 +17,7 @@ export type GatewaySessionRow = {
subject?: string;
room?: string;
space?: string;
chatType?: "direct" | "group" | "channel";
chatType?: NormalizedChatType;
updatedAt: number | null;
sessionId?: string;
systemSent?: boolean;