fix: align OpenAI cache affinity and use uuidv7 session ids
This commit is contained in:
@@ -15,6 +15,7 @@ import {
|
||||
} from "fs";
|
||||
import { readdir, readFile, stat } from "fs/promises";
|
||||
import { join, resolve } from "path";
|
||||
import { v7 as uuidv7 } from "uuid";
|
||||
import { getAgentDir as getDefaultAgentDir, getSessionsDir } from "../config.js";
|
||||
import {
|
||||
type BashExecutionMessage,
|
||||
@@ -197,6 +198,10 @@ export type ReadonlySessionManager = Pick<
|
||||
| "getSessionName"
|
||||
>;
|
||||
|
||||
function createSessionId(): string {
|
||||
return uuidv7();
|
||||
}
|
||||
|
||||
/** Generate a unique short ID (8 hex chars, collision-checked) */
|
||||
function generateId(byId: { has(id: string): boolean }): string {
|
||||
for (let i = 0; i < 100; i++) {
|
||||
@@ -707,7 +712,7 @@ export class SessionManager {
|
||||
}
|
||||
|
||||
const header = this.fileEntries.find((e) => e.type === "session") as SessionHeader | undefined;
|
||||
this.sessionId = header?.id ?? randomUUID();
|
||||
this.sessionId = header?.id ?? createSessionId();
|
||||
|
||||
if (migrateToCurrentVersion(this.fileEntries)) {
|
||||
this._rewriteFile();
|
||||
@@ -723,7 +728,7 @@ export class SessionManager {
|
||||
}
|
||||
|
||||
newSession(options?: NewSessionOptions): string | undefined {
|
||||
this.sessionId = options?.id ?? randomUUID();
|
||||
this.sessionId = options?.id ?? createSessionId();
|
||||
const timestamp = new Date().toISOString();
|
||||
const header: SessionHeader = {
|
||||
type: "session",
|
||||
@@ -1172,7 +1177,7 @@ export class SessionManager {
|
||||
// Filter out LabelEntry from path - we'll recreate them from the resolved map
|
||||
const pathWithoutLabels = path.filter((e) => e.type !== "label");
|
||||
|
||||
const newSessionId = randomUUID();
|
||||
const newSessionId = createSessionId();
|
||||
const timestamp = new Date().toISOString();
|
||||
const fileTimestamp = timestamp.replace(/[:.]/g, "-");
|
||||
const newSessionFile = join(this.getSessionDir(), `${fileTimestamp}_${newSessionId}.jsonl`);
|
||||
@@ -1325,7 +1330,7 @@ export class SessionManager {
|
||||
}
|
||||
|
||||
// Create new session file with new ID but forked content
|
||||
const newSessionId = randomUUID();
|
||||
const newSessionId = createSessionId();
|
||||
const timestamp = new Date().toISOString();
|
||||
const fileTimestamp = timestamp.replace(/[:.]/g, "-");
|
||||
const newSessionFile = join(dir, `${fileTimestamp}_${newSessionId}.jsonl`);
|
||||
|
||||
Reference in New Issue
Block a user