The open-source app everyone uses to manage agents at work
TypeScript acpxagent-orchestrationagent-skillsagentic-aiai-agentsai-engineeringai-governanceai-toolsautonomous-agentsclaudeclaude-codeclaude-skillscodexhermesllmmcpmulti-agentopenclawproject-managementworkflow-automation
fix openclaw gateway session key routing
Shoaib Ansari8e2148e99d9a
diff --git a/packages/adapters/openclaw-gateway/src/server/execute.test.ts b/packages/adapters/openclaw-gateway/src/server/execute.test.tsnew file mode 100644index 0000000000..0b18108c7a--- /dev/null+++ b/packages/adapters/openclaw-gateway/src/server/execute.test.ts@@ -0,0 +1,52 @@+import { describe, expect, it } from "vitest";+import { resolveSessionKey } from "./execute.js";++describe("resolveSessionKey", () => {+ it("prefixes run-scoped session keys with the configured agent", () => {+ expect(+ resolveSessionKey({+ strategy: "run",+ configuredSessionKey: null,+ agentId: "meridian",+ runId: "run-123",+ issueId: null,+ }),+ ).toBe("agent:meridian:paperclip:run:run-123");+ });++ it("prefixes issue-scoped session keys with the configured agent", () => {+ expect(+ resolveSessionKey({+ strategy: "issue",+ configuredSessionKey: null,+ agentId: "meridian",+ runId: "run-123",+ issueId: "issue-456",+ }),+ ).toBe("agent:meridian:paperclip:issue:issue-456");+ });++ it("prefixes fixed session keys with the configured agent", () => {+ expect(+ resolveSessionKey({+ strategy: "fixed",+ configuredSessionKey: "paperclip",+ agentId: "meridian",+ runId: "run-123",+ issueId: null,+ }),+ ).toBe("agent:meridian:paperclip");+ });++ it("does not double-prefix an already-routed session key", () => {+ expect(+ resolveSessionKey({+ strategy: "fixed",+ configuredSessionKey: "agent:meridian:paperclip",+ agentId: "meridian",+ runId: "run-123",+ issueId: null,+ }),+ ).toBe("agent:meridian:paperclip");+ });+});diff --git a/packages/adapters/openclaw-gateway/src/server/execute.ts b/packages/adapters/openclaw-gateway/src/server/execute.tsindex f1c85c11c2..c3092205d3 100644--- a/packages/adapters/openclaw-gateway/src/server/execute.ts+++ b/packages/adapters/openclaw-gateway/src/server/execute.ts@@ -126,16 +126,26 @@ function normalizeSessionKeyStrategy(value: unknown): SessionKeyStrategy {return "issue";}-function resolveSessionKey(input: {+function prefixSessionKeyForAgent(sessionKey: string, agentId: string | null): string {+ if (!agentId || sessionKey.startsWith("agent:")) return sessionKey;+ return `agent:${agentId}:${sessionKey}`;+}++export function resolveSessionKey(input: {strategy: SessionKeyStrategy;configuredSessionKey: string | null;+ agentId: string | null;runId: string;issueId: string | null;}): string {const fallback = input.configuredSessionKey ?? "paperclip";- if (input.strategy === "run") return `paperclip:run:${input.runId}`;- if (input.strategy === "issue" && input.issueId) return `paperclip:issue:${input.issueId}`;- return fallback;+ if (input.strategy === "run") {+ return prefixSessionKeyForAgent(`paperclip:run:${input.runId}`, input.agentId);+ }+ if (input.strategy === "issue" && input.issueId) {+ return prefixSessionKeyForAgent(`paperclip:issue:${input.issueId}`, input.agentId);+ }+ return prefixSessionKeyForAgent(fallback, input.agentId);}function isLoopbackHost(hostname: string): boolean {@@ -1060,6 +1070,7 @@ export async function execute(ctx: AdapterExecutionContext): Promise<AdapterExecconst sessionKey = resolveSessionKey({strategy: sessionKeyStrategy,configuredSessionKey,+ agentId: nonEmpty(ctx.config.agentId),runId: ctx.runId,issueId: wakePayload.issueId,});