



















@@ -54,6 +54,7 @@ function startCompaction(sessionFile: string, options: { currentTokenCount?: num
5454sessionKey: "agent:main:session-1",
5555 sessionFile,
5656workspaceDir: tempDir,
57+trigger: "manual",
5758 ...options,
5859});
5960}
@@ -64,6 +65,7 @@ function startSandboxedCompaction(sessionFile: string) {
6465sessionKey: "agent:main:session-1",
6566 sessionFile,
6667workspaceDir: tempDir,
68+trigger: "manual",
6769config: { agents: { defaults: { sandbox: { mode: "all" } } } },
6870});
6971}
@@ -74,6 +76,7 @@ function startNodeExecCompaction(sessionFile: string) {
7476sessionKey: "agent:main:session-1",
7577 sessionFile,
7678workspaceDir: tempDir,
79+trigger: "manual",
7780config: { tools: { exec: { host: "node", node: "worker-1" } } },
7881});
7982}
@@ -123,6 +126,63 @@ describe("maybeCompactCodexAppServerSession", () => {
123126expect(details.pending).toBe(true);
124127});
125128129+it("skips native app-server compaction for automatic budget triggers", async () => {
130+const fake = createFakeCodexClient();
131+setCodexAppServerClientFactoryForTest(async () => fake.client);
132+const sessionFile = await writeTestBinding();
133+134+const result = requireCompactResult(
135+await maybeCompactCodexAppServerSession({
136+sessionId: "session-1",
137+sessionKey: "agent:main:session-1",
138+ sessionFile,
139+workspaceDir: tempDir,
140+trigger: "budget",
141+currentTokenCount: 456,
142+}),
143+);
144+145+expect(fake.request).not.toHaveBeenCalled();
146+expect(result.ok).toBe(true);
147+expect(result.compacted).toBe(false);
148+expect(result.reason).toBe("codex app-server owns automatic compaction");
149+expect(result.result?.tokensBefore).toBe(456);
150+expect(compactDetails(result)).toMatchObject({
151+backend: "codex-app-server",
152+skipped: true,
153+reason: "non_manual_trigger",
154+trigger: "budget",
155+});
156+});
157+158+it("skips native app-server compaction when trigger is omitted", async () => {
159+const fake = createFakeCodexClient();
160+setCodexAppServerClientFactoryForTest(async () => fake.client);
161+const sessionFile = await writeTestBinding();
162+163+const result = requireCompactResult(
164+await maybeCompactCodexAppServerSession({
165+sessionId: "session-1",
166+sessionKey: "agent:main:session-1",
167+ sessionFile,
168+workspaceDir: tempDir,
169+currentTokenCount: 789,
170+}),
171+);
172+173+expect(fake.request).not.toHaveBeenCalled();
174+expect(result.ok).toBe(true);
175+expect(result.compacted).toBe(false);
176+expect(result.reason).toBe("codex app-server owns automatic compaction");
177+expect(result.result?.tokensBefore).toBe(789);
178+expect(compactDetails(result)).toMatchObject({
179+backend: "codex-app-server",
180+skipped: true,
181+reason: "non_manual_trigger",
182+trigger: "unknown",
183+});
184+});
185+126186it("blocks native app-server compaction when the current OpenClaw session is sandboxed", async () => {
127187const fake = createFakeCodexClient();
128188setCodexAppServerClientFactoryForTest(async () => fake.client);
@@ -278,6 +338,7 @@ describe("maybeCompactCodexAppServerSession", () => {
278338sessionKey: "agent:main:session-1",
279339 sessionFile,
280340workspaceDir: tempDir,
341+trigger: "manual",
281342config: {
282343agents: {
283344defaults: {
@@ -313,6 +374,7 @@ describe("maybeCompactCodexAppServerSession", () => {
313374sessionKey: "agent:sara:session-1",
314375 sessionFile,
315376workspaceDir: tempDir,
377+trigger: "manual",
316378config: {
317379agents: {
318380list: [
@@ -354,6 +416,7 @@ describe("maybeCompactCodexAppServerSession", () => {
354416sessionKey: "agent:nik:session-1",
355417 sessionFile,
356418workspaceDir: tempDir,
419+trigger: "manual",
357420config: {
358421agents: {
359422defaults: {
@@ -402,6 +465,7 @@ describe("maybeCompactCodexAppServerSession", () => {
402465sessionKey: "agent:lossless:session-1",
403466 sessionFile,
404467workspaceDir: tempDir,
468+trigger: "manual",
405469 contextEngine,
406470config: {
407471plugins: {
@@ -455,6 +519,7 @@ describe("maybeCompactCodexAppServerSession", () => {
455519sessionKey: "agent:lossless-child:session-1",
456520 sessionFile,
457521workspaceDir: tempDir,
522+trigger: "manual",
458523 contextEngine,
459524config: {
460525plugins: {
@@ -511,6 +576,7 @@ describe("maybeCompactCodexAppServerSession", () => {
511576sessionKey: "agent:main:session-1",
512577 sessionFile,
513578workspaceDir: tempDir,
579+trigger: "manual",
514580authProfileId: "openai-codex:runtime",
515581});
516582此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。