From 87aa31956840c5909aba7fd2af798d478e2aa610 Mon Sep 17 00:00:00 2001 From: Gio Della-Libera Date: Mon, 18 May 2026 16:48:23 -0700 Subject: [PATCH] fix(export): preserve explicit trajectory session keys (#83308) --- src/commands/export-trajectory.test.ts | 26 +++++++++++++++++++++++ src/commands/export-trajectory.ts | 29 +++++++++++++++++++------- 2 files changed, 48 insertions(+), 7 deletions(-) diff --git a/src/commands/export-trajectory.test.ts b/src/commands/export-trajectory.test.ts index 84a2201d7b1..4a96da4ff7d 100644 --- a/src/commands/export-trajectory.test.ts +++ b/src/commands/export-trajectory.test.ts @@ -57,6 +57,32 @@ describe("exportTrajectoryCommand", () => { expect(runtime.exit).toHaveBeenCalledWith(1); }); + it("preserves direct options when an encoded request omits them", async () => { + const runtime = createRuntime(); + const requestJsonBase64 = Buffer.from( + JSON.stringify({ output: "/tmp/export.json" }), + "utf8", + ).toString("base64url"); + + await exportTrajectoryCommand( + { + requestJsonBase64, + sessionKey: "agent:main:telegram:direct:123", + store: "/tmp/direct-store.json", + }, + runtime, + ); + + expect(mocks.resolveDefaultSessionStorePath).not.toHaveBeenCalled(); + expect(mocks.loadSessionStore).toHaveBeenCalledWith("/tmp/direct-store.json", { + skipCache: true, + }); + expect(runtime.error).toHaveBeenCalledWith( + "Session not found: agent:main:telegram:direct:123. Run openclaw sessions to see available sessions.", + ); + expect(runtime.exit).toHaveBeenCalledWith(1); + }); + it("points missing session users at the sessions command", async () => { const runtime = createRuntime(); diff --git a/src/commands/export-trajectory.ts b/src/commands/export-trajectory.ts index 1ada4ac73c5..63fd22e4809 100644 --- a/src/commands/export-trajectory.ts +++ b/src/commands/export-trajectory.ts @@ -56,13 +56,28 @@ function decodeExportTrajectoryRequest(encoded: string): Partial = {}; + const sessionKey = readOptionalString(request.sessionKey); + if (sessionKey !== undefined) { + opts.sessionKey = sessionKey; + } + const output = readOptionalString(request.output); + if (output !== undefined) { + opts.output = output; + } + const store = readOptionalString(request.store); + if (store !== undefined) { + opts.store = store; + } + const agent = readOptionalString(request.agent); + if (agent !== undefined) { + opts.agent = agent; + } + const workspace = readOptionalString(request.workspace); + if (workspace !== undefined) { + opts.workspace = workspace; + } + return opts; } function resolveExportTrajectoryOptions(