mirror of
https://github.com/openclaw/openclaw.git
synced 2026-07-13 05:16:07 +00:00
refactor: compact copilot sessions through sdk state
Route Copilot compaction through SDK-backed state, remove marker sidecars, preserve auth/session binding behavior in SQLite-backed plugin state, and route Copilot CLI budget compaction through native harness compaction.
This commit is contained in:
committed by
GitHub
parent
4550cfa6a7
commit
db4990d260
@@ -280,6 +280,8 @@ describe("runCliTurnCompactionLifecycle", () => {
|
||||
totalTokens: 950,
|
||||
totalTokensFresh: true,
|
||||
agentHarnessId: "codex",
|
||||
authProfileOverride: "github-copilot:work",
|
||||
authProfileOverrideSource: "auto",
|
||||
};
|
||||
const sessionStore: Record<string, SessionEntry> = { [sessionKey]: sessionEntry };
|
||||
await fs.writeFile(storePath, JSON.stringify(sessionStore, null, 2), "utf-8");
|
||||
@@ -368,9 +370,13 @@ describe("runCliTurnCompactionLifecycle", () => {
|
||||
currentTokenCount: 950,
|
||||
contextEngine,
|
||||
agentHarnessId: "codex",
|
||||
authProfileId: "github-copilot:work",
|
||||
trigger: "budget",
|
||||
force: true,
|
||||
});
|
||||
expect(compactAgentHarnessSessionCalls[0]?.[0].contextEngineRuntimeContext).toMatchObject({
|
||||
authProfileId: "github-copilot:work",
|
||||
});
|
||||
expect(compactCalls).toHaveLength(0);
|
||||
expect(recordCliCompactionInStore).toHaveBeenCalledTimes(1);
|
||||
expect(recordCliCompactionInStore).toHaveBeenCalledWith(
|
||||
@@ -383,11 +389,11 @@ describe("runCliTurnCompactionLifecycle", () => {
|
||||
expect(updatedEntry?.compactionCount).toBe(1);
|
||||
});
|
||||
|
||||
it("treats below-target Codex native CLI compaction as a no-op", async () => {
|
||||
const sessionKey = "agent:main:codex-under-target";
|
||||
const sessionId = "session-codex-under-target";
|
||||
const sessionFile = path.join(tmpDir, "session-codex-under-target.jsonl");
|
||||
const storePath = path.join(tmpDir, "sessions-codex-under-target.json");
|
||||
it("treats below-target Copilot native CLI compaction as a no-op", async () => {
|
||||
const sessionKey = "agent:main:copilot-under-target";
|
||||
const sessionId = "session-copilot-under-target";
|
||||
const sessionFile = path.join(tmpDir, "session-copilot-under-target.jsonl");
|
||||
const storePath = path.join(tmpDir, "sessions-copilot-under-target.json");
|
||||
await writeSessionFile({ sessionFile, sessionId });
|
||||
|
||||
const sessionEntry: SessionEntry = {
|
||||
@@ -397,7 +403,7 @@ describe("runCliTurnCompactionLifecycle", () => {
|
||||
contextTokens: 1_000,
|
||||
totalTokens: 950,
|
||||
totalTokensFresh: true,
|
||||
agentHarnessId: "codex",
|
||||
agentHarnessId: "copilot",
|
||||
};
|
||||
const sessionStore: Record<string, SessionEntry> = { [sessionKey]: sessionEntry };
|
||||
await fs.writeFile(storePath, JSON.stringify(sessionStore, null, 2), "utf-8");
|
||||
@@ -441,7 +447,7 @@ describe("runCliTurnCompactionLifecycle", () => {
|
||||
sessionAgentId: "main",
|
||||
workspaceDir: tmpDir,
|
||||
agentDir: tmpDir,
|
||||
provider: "codex",
|
||||
provider: "github-copilot",
|
||||
model: "gpt-5.5",
|
||||
});
|
||||
|
||||
@@ -934,6 +940,8 @@ describe("runCliTurnCompactionLifecycle", () => {
|
||||
totalTokens: 950,
|
||||
totalTokensFresh: true,
|
||||
agentHarnessId: "codex",
|
||||
authProfileOverride: "github-copilot:work",
|
||||
authProfileOverrideSource: "auto",
|
||||
};
|
||||
const sessionStore: Record<string, SessionEntry> = { [sessionKey]: sessionEntry };
|
||||
await fs.writeFile(storePath, JSON.stringify(sessionStore, null, 2), "utf-8");
|
||||
@@ -992,6 +1000,9 @@ describe("runCliTurnCompactionLifecycle", () => {
|
||||
|
||||
expect(compactAgentHarnessSession).toHaveBeenCalledTimes(1);
|
||||
expect(compactCalls).toHaveLength(1);
|
||||
expect(compactCalls[0]?.runtimeContext).toMatchObject({
|
||||
authProfileId: "github-copilot:work",
|
||||
});
|
||||
expect(maintenance).toHaveBeenCalledTimes(1);
|
||||
expect(recordCliCompactionInStore).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
|
||||
@@ -87,6 +87,7 @@ type CliCompactionRuntimeContextParams = {
|
||||
sessionKey: string;
|
||||
messageChannel?: string;
|
||||
agentAccountId?: string;
|
||||
authProfileId?: string;
|
||||
workspaceDir: string;
|
||||
cwd?: string;
|
||||
agentDir: string;
|
||||
@@ -174,8 +175,8 @@ function isNativeHarnessCompactionSession(
|
||||
const providerId = provider.trim().toLowerCase();
|
||||
return (
|
||||
harnessId === providerId ||
|
||||
(harnessId === "codex" &&
|
||||
(providerId === "codex" || providerId === "openai" || providerId === "openai"))
|
||||
(harnessId === "copilot" && providerId === "github-copilot") ||
|
||||
(harnessId === "codex" && (providerId === "codex" || providerId === "openai"))
|
||||
);
|
||||
}
|
||||
|
||||
@@ -211,7 +212,7 @@ function buildCliCompactionRuntimeContext(params: CliCompactionRuntimeContextPar
|
||||
messageChannel: params.messageChannel,
|
||||
messageProvider: params.messageChannel,
|
||||
agentAccountId: params.agentAccountId,
|
||||
authProfileId: undefined,
|
||||
authProfileId: params.authProfileId,
|
||||
workspaceDir: params.workspaceDir,
|
||||
cwd: params.cwd,
|
||||
agentDir: params.agentDir,
|
||||
@@ -246,6 +247,7 @@ async function compactCliTranscript(params: {
|
||||
skillsSnapshot?: SkillSnapshot;
|
||||
messageChannel?: string;
|
||||
agentAccountId?: string;
|
||||
authProfileId?: string;
|
||||
senderIsOwner?: boolean;
|
||||
thinkLevel?: Parameters<typeof buildEmbeddedCompactionRuntimeContext>[0]["thinkLevel"];
|
||||
extraSystemPrompt?: string;
|
||||
@@ -255,6 +257,7 @@ async function compactCliTranscript(params: {
|
||||
sessionKey: params.sessionKey,
|
||||
messageChannel: params.messageChannel,
|
||||
agentAccountId: params.agentAccountId,
|
||||
authProfileId: params.authProfileId,
|
||||
workspaceDir: params.workspaceDir,
|
||||
cwd: params.cwd,
|
||||
agentDir: params.agentDir,
|
||||
@@ -360,6 +363,7 @@ async function compactNativeHarnessCliTranscript(params: {
|
||||
try {
|
||||
const sessionAgentId = readAgentIdFromSessionKey(params.sessionKey);
|
||||
const nativeHarnessId = params.sessionEntry.agentHarnessId?.trim();
|
||||
const authProfileId = params.sessionEntry.authProfileOverride?.trim() || undefined;
|
||||
await cliCompactionDeps.ensureSelectedAgentHarnessPlugin({
|
||||
provider: params.provider,
|
||||
modelId: params.model,
|
||||
@@ -382,6 +386,7 @@ async function compactNativeHarnessCliTranscript(params: {
|
||||
skillsSnapshot: params.skillsSnapshot,
|
||||
provider: params.provider,
|
||||
model: params.model,
|
||||
authProfileId,
|
||||
contextTokenBudget: params.contextTokenBudget,
|
||||
currentTokenCount: params.currentTokenCount,
|
||||
trigger: "budget",
|
||||
@@ -399,6 +404,7 @@ async function compactNativeHarnessCliTranscript(params: {
|
||||
sessionKey: params.sessionKey,
|
||||
messageChannel: params.messageChannel,
|
||||
agentAccountId: params.agentAccountId,
|
||||
authProfileId,
|
||||
workspaceDir: params.workspaceDir,
|
||||
cwd: params.cwd,
|
||||
agentDir: params.agentDir,
|
||||
@@ -526,6 +532,7 @@ export async function runCliTurnCompactionLifecycle(params: {
|
||||
let nativeFallbackNeedsBindingClear = false;
|
||||
let resolvedContextEngine: ContextEngine | undefined;
|
||||
let autoCompactionGuardApplied = false;
|
||||
const authProfileId = params.sessionEntry?.authProfileOverride?.trim() || undefined;
|
||||
const applyAutoCompactionGuard = async (contextEngine: ContextEngine): Promise<void> => {
|
||||
if (autoCompactionGuardApplied) {
|
||||
return;
|
||||
@@ -606,6 +613,7 @@ export async function runCliTurnCompactionLifecycle(params: {
|
||||
skillsSnapshot: params.skillsSnapshot,
|
||||
messageChannel: params.messageChannel,
|
||||
agentAccountId: params.agentAccountId,
|
||||
authProfileId,
|
||||
senderIsOwner: params.senderIsOwner,
|
||||
thinkLevel: params.thinkLevel,
|
||||
extraSystemPrompt: params.extraSystemPrompt,
|
||||
|
||||
Reference in New Issue
Block a user