mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-07 10:41:25 +00:00
fix(discord): preserve channel session keys via channel_id fallbacks (#17622)
* fix(discord): preserve channel session keys via channel_id fallbacks * docs(changelog): add discord session continuity note * Tests: cover discord channel_id fallback --------- Co-authored-by: Shadow <hi@shadowing.dev>
This commit is contained in:
@@ -56,10 +56,20 @@ function resolveSessionKey({ sessionKey, sessionId }: SessionRef) {
|
||||
return sessionKey ?? sessionId ?? "unknown";
|
||||
}
|
||||
|
||||
function findStateBySessionId(sessionId: string): SessionState | undefined {
|
||||
for (const state of diagnosticSessionStates.values()) {
|
||||
if (state.sessionId === sessionId) {
|
||||
return state;
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
export function getDiagnosticSessionState(ref: SessionRef): SessionState {
|
||||
pruneDiagnosticSessionStates();
|
||||
const key = resolveSessionKey(ref);
|
||||
const existing = diagnosticSessionStates.get(key);
|
||||
const existing =
|
||||
diagnosticSessionStates.get(key) ?? (ref.sessionId && findStateBySessionId(ref.sessionId));
|
||||
if (existing) {
|
||||
if (ref.sessionId) {
|
||||
existing.sessionId = ref.sessionId;
|
||||
|
||||
@@ -34,6 +34,18 @@ describe("diagnostic session state pruning", () => {
|
||||
|
||||
expect(getDiagnosticSessionStateCountForTest()).toBe(2000);
|
||||
});
|
||||
|
||||
it("reuses keyed session state when later looked up by sessionId", () => {
|
||||
const keyed = getDiagnosticSessionState({
|
||||
sessionId: "s1",
|
||||
sessionKey: "agent:main:discord:channel:c1",
|
||||
});
|
||||
const bySessionId = getDiagnosticSessionState({ sessionId: "s1" });
|
||||
|
||||
expect(bySessionId).toBe(keyed);
|
||||
expect(bySessionId.sessionKey).toBe("agent:main:discord:channel:c1");
|
||||
expect(getDiagnosticSessionStateCountForTest()).toBe(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe("logger import side effects", () => {
|
||||
|
||||
Reference in New Issue
Block a user