Merge pull request #4799 from Perlence/fix/fork-session-id

fix(coding-agent): keep fork session id aligned
This commit is contained in:
Mario Zechner
2026-05-20 15:26:12 +02:00
committed by GitHub
2 changed files with 5 additions and 4 deletions

View File

@@ -292,12 +292,11 @@ export class AgentSessionRuntime {
return { cancelled: false, selectedText }; return { cancelled: false, selectedText };
} }
const sourceManager = SessionManager.open(currentSessionFile, sessionDir); const sessionManager = SessionManager.open(currentSessionFile, sessionDir);
const forkedSessionPath = sourceManager.createBranchedSession(targetLeafId); const forkedSessionPath = sessionManager.createBranchedSession(targetLeafId);
if (!forkedSessionPath) { if (!forkedSessionPath) {
throw new Error("Failed to create forked session"); throw new Error("Failed to create forked session");
} }
const sessionManager = SessionManager.open(forkedSessionPath, sessionDir);
await this.teardownCurrent("fork", sessionManager.getSessionFile()); await this.teardownCurrent("fork", sessionManager.getSessionFile());
this.apply( this.apply(
await this.createRuntime({ await this.createRuntime({

View File

@@ -1,6 +1,6 @@
import { existsSync, mkdirSync, realpathSync, rmSync } from "node:fs"; import { existsSync, mkdirSync, realpathSync, rmSync } from "node:fs";
import { tmpdir } from "node:os"; import { tmpdir } from "node:os";
import { join } from "node:path"; import { join, parse } from "node:path";
import { fauxAssistantMessage, registerFauxProvider } from "@earendil-works/pi-ai"; import { fauxAssistantMessage, registerFauxProvider } from "@earendil-works/pi-ai";
import { afterEach, describe, expect, it } from "vitest"; import { afterEach, describe, expect, it } from "vitest";
import { import {
@@ -274,6 +274,8 @@ describe("AgentSessionRuntime characterization", () => {
{ type: "session_shutdown", reason: "fork", targetSessionFile: runtime.session.sessionFile }, { type: "session_shutdown", reason: "fork", targetSessionFile: runtime.session.sessionFile },
{ type: "session_start", reason: "fork", previousSessionFile }, { type: "session_start", reason: "fork", previousSessionFile },
]); ]);
const sessionFileName = parse(runtime.session.sessionFile!).name;
expect(sessionFileName.endsWith(`_${runtime.session.sessionId}`)).toBe(true);
events.length = 0; events.length = 0;
cancelNextFork = true; cancelNextFork = true;