mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 06:00:43 +00:00
refactor(codex): avoid sync context history reads (#75917)
This commit is contained in:
committed by
GitHub
parent
1b76a3fc30
commit
ab25a26c24
@@ -212,6 +212,7 @@ describe("runCodexAppServerAttempt context-engine lifecycle", () => {
|
||||
SessionManager.open(sessionFile).appendMessage(
|
||||
assistantMessage("existing context", Date.now()) as never,
|
||||
);
|
||||
const openSpy = vi.spyOn(SessionManager, "open");
|
||||
const contextEngine = createContextEngine();
|
||||
const harness = createStartedThreadHarness();
|
||||
const params = createParams(sessionFile, workspaceDir);
|
||||
@@ -265,6 +266,7 @@ describe("runCodexAppServerAttempt context-engine lifecycle", () => {
|
||||
|
||||
await harness.completeTurn();
|
||||
await run;
|
||||
expect(openSpy).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("calls afterTurn with the mirrored transcript and runs turn maintenance", async () => {
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { createHash } from "node:crypto";
|
||||
import fs from "node:fs/promises";
|
||||
import { SessionManager } from "@mariozechner/pi-coding-agent";
|
||||
import {
|
||||
assembleHarnessContextEngine,
|
||||
bootstrapHarnessContextEngine,
|
||||
@@ -401,9 +400,7 @@ export async function runCodexAppServerAttempt(
|
||||
},
|
||||
});
|
||||
const hadSessionFile = await fileExists(params.sessionFile);
|
||||
const sessionManager = activeContextEngine ? SessionManager.open(params.sessionFile) : undefined;
|
||||
let historyMessages =
|
||||
(await readMirroredSessionHistoryMessages(params.sessionFile, sessionManager)) ?? [];
|
||||
let historyMessages = (await readMirroredSessionHistoryMessages(params.sessionFile)) ?? [];
|
||||
const hookContext = {
|
||||
runId: params.runId,
|
||||
agentId: sessionAgentId,
|
||||
@@ -421,7 +418,6 @@ export async function runCodexAppServerAttempt(
|
||||
sessionId: params.sessionId,
|
||||
sessionKey: sandboxSessionKey,
|
||||
sessionFile: params.sessionFile,
|
||||
sessionManager,
|
||||
runtimeContext: buildHarnessContextEngineRuntimeContext({
|
||||
attempt: runtimeParams,
|
||||
workspaceDir: effectiveWorkspace,
|
||||
@@ -1121,7 +1117,6 @@ export async function runCodexAppServerAttempt(
|
||||
promptCache: result.promptCache,
|
||||
}),
|
||||
runMaintenance: runHarnessContextEngineMaintenance,
|
||||
sessionManager,
|
||||
warn: (message) => embeddedAgentLog.warn(message),
|
||||
});
|
||||
}
|
||||
@@ -1557,9 +1552,8 @@ function readString(record: JsonObject, key: string): string | undefined {
|
||||
|
||||
async function readMirroredSessionHistoryMessages(
|
||||
sessionFile: string,
|
||||
sessionManager?: Pick<SessionManager, "buildSessionContext">,
|
||||
): Promise<AgentMessage[] | undefined> {
|
||||
const messages = await readCodexMirroredSessionHistoryMessages(sessionFile, sessionManager);
|
||||
const messages = await readCodexMirroredSessionHistoryMessages(sessionFile);
|
||||
if (!messages) {
|
||||
embeddedAgentLog.warn("failed to read mirrored session history for codex harness hooks", {
|
||||
sessionFile,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import fs from "node:fs/promises";
|
||||
import type { SessionEntry, SessionManager } from "@mariozechner/pi-coding-agent";
|
||||
import type { SessionEntry } from "@mariozechner/pi-coding-agent";
|
||||
import {
|
||||
buildSessionContext,
|
||||
migrateSessionEntries,
|
||||
@@ -18,12 +18,8 @@ function isMissingFileError(error: unknown): boolean {
|
||||
|
||||
export async function readCodexMirroredSessionHistoryMessages(
|
||||
sessionFile: string,
|
||||
sessionManager?: Pick<SessionManager, "buildSessionContext">,
|
||||
): Promise<AgentMessage[] | undefined> {
|
||||
try {
|
||||
if (sessionManager) {
|
||||
return sessionManager.buildSessionContext().messages;
|
||||
}
|
||||
const raw = await fs.readFile(sessionFile, "utf-8");
|
||||
const entries = parseSessionEntries(raw);
|
||||
const firstEntry = entries[0] as { type?: unknown; id?: unknown } | undefined;
|
||||
|
||||
@@ -23,7 +23,7 @@ export async function bootstrapHarnessContextEngine(params: {
|
||||
sessionId: string;
|
||||
sessionKey?: string;
|
||||
sessionFile: string;
|
||||
sessionManager: unknown;
|
||||
sessionManager?: unknown;
|
||||
runtimeContext?: ContextEngineRuntimeContext;
|
||||
runMaintenance?: typeof runHarnessContextEngineMaintenance;
|
||||
warn: (message: string) => void;
|
||||
@@ -101,7 +101,7 @@ export async function finalizeHarnessContextEngineTurn(params: {
|
||||
tokenBudget?: number;
|
||||
runtimeContext?: ContextEngineRuntimeContext;
|
||||
runMaintenance?: typeof runHarnessContextEngineMaintenance;
|
||||
sessionManager: unknown;
|
||||
sessionManager?: unknown;
|
||||
warn: (message: string) => void;
|
||||
}) {
|
||||
if (!params.contextEngine) {
|
||||
|
||||
Reference in New Issue
Block a user