Skip to content

Commit 5c8f87f

Browse files
steipetechelsealongayeshafayyaz-pixel
committed
fix(acp): reject unsupported live effort before persisting
Apply configured live controls through the existing checked manager path. Keep accepted settings and conversation state when a control is rejected, and distinguish Codex startup omission from unsupported live effort clearing. Co-authored-by: chelsealong <[email protected]> Co-authored-by: ayeshafayyaz-pixel <[email protected]>
1 parent ab915c0 commit 5c8f87f

6 files changed

Lines changed: 147 additions & 31 deletions

File tree

‎docs/tools/acp-agents.md‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,10 +379,16 @@ policy. Thinking uses the agent's `thinkingDefault`, then per-model
379379
harness keeps its own defaults.
380380

381381
Changing a configured model or thinking value updates the existing session
382-
before its next turn without replacing the conversation. Removing a default
382+
before its next turn without replacing the conversation. Each option is saved
383+
only after the harness accepts it; a rejected option returns an error and keeps
384+
that option's previous selection. Model and thinking changes are independent,
385+
not an atomic batch. Removing a default
383386
uses any remaining configured policy; if none remains, OpenClaw retains the
384387
session's last selection. Omission is not a backend reset. To change thinking
385388
explicitly, use `/acp set thinking <level>` with a level supported by the harness.
389+
For Codex ACP, `off` only omits a fresh session's startup override. Switching an
390+
existing session to `off` is unsupported and returns an error without clearing
391+
its current reasoning effort or conversation.
386392

387393
### Example
388394

‎extensions/acpx/src/runtime.test.ts‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1744,7 +1744,14 @@ describe("AcpxRuntime fresh reset wrapper", () => {
17441744
key: "thinking",
17451745
value: "superhigh",
17461746
},
1747-
])("$name", async ({ key, value, expected }) => {
1747+
...["thinking", "thought_level", "reasoning_effort"].map((key) => ({
1748+
name: `rejects unsupported live Codex ACP ${key}=off`,
1749+
key,
1750+
value: "off",
1751+
expected: undefined,
1752+
errorCode: "ACP_BACKEND_UNSUPPORTED_CONTROL",
1753+
})),
1754+
])("$name", async ({ key, value, expected, errorCode }) => {
17481755
const baseStore: TestSessionStore = {
17491756
load: vi.fn(async () => ({
17501757
acpxRecordId: "agent:codex:acp:test",
@@ -1767,7 +1774,9 @@ describe("AcpxRuntime fresh reset wrapper", () => {
17671774
value,
17681775
});
17691776
if (!expected) {
1770-
await expect(update).rejects.toMatchObject({ code: "ACP_INVALID_RUNTIME_OPTION" });
1777+
await expect(update).rejects.toMatchObject({
1778+
code: errorCode ?? "ACP_INVALID_RUNTIME_OPTION",
1779+
});
17711780
expect(setConfigOption).not.toHaveBeenCalled();
17721781
return;
17731782
}

‎extensions/acpx/src/runtime.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1809,7 +1809,11 @@ export class AcpxRuntime implements CompleteAcpRuntime {
18091809
const reasoningEffort =
18101810
classification.kind === "override" ? classification.override.reasoningEffort : undefined;
18111811
if (!reasoningEffort) {
1812-
return;
1812+
// `off` omits the startup override; Codex has no live control to unset effort.
1813+
throw new AcpRuntimeError(
1814+
"ACP_BACKEND_UNSUPPORTED_CONTROL",
1815+
"Clearing Codex reasoning effort on an existing session is unsupported. Choose a supported explicit effort; the current effort is unchanged.",
1816+
);
18131817
}
18141818
await delegate.setConfigOption({
18151819
...input,

‎src/acp/control-plane/manager.runtime-config.test.ts‎

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/** Tests ACP runtime mode/config option persistence and backend control calls. */
22
import { describe, expect, it, vi } from "vitest";
3+
import { buildConfiguredAcpSessionKey } from "../persistent-bindings.types.js";
34
import {
45
type AcpRuntime,
56
AcpRuntimeError,
@@ -21,6 +22,87 @@ import {
2122
describe("AcpSessionManager runtime config", () => {
2223
installAcpSessionManagerTestLifecycle();
2324

25+
it("keeps startup omission but rejects live binding changes before overwriting accepted thinking", async () => {
26+
const managerModule = await import("./manager.js");
27+
const { ensureConfiguredAcpBindingSession } =
28+
await import("../persistent-bindings.lifecycle.js");
29+
const runtimeState = createRuntime();
30+
runtimeState.setConfigOption.mockImplementation(async ({ value }) => {
31+
if (value === "off") {
32+
throw new AcpRuntimeError("ACP_BACKEND_UNSUPPORTED_CONTROL", "Live off is unsupported");
33+
}
34+
});
35+
hoisted.requireAcpRuntimeBackendMock.mockReturnValue({
36+
id: "acpx",
37+
runtime: runtimeState.runtime,
38+
});
39+
const spec = {
40+
channel: "discord" as const,
41+
accountId: "default",
42+
conversationId: "configured-thinking",
43+
agentId: "codex",
44+
mode: "persistent" as const,
45+
thinking: "off",
46+
};
47+
const sessionKey = buildConfiguredAcpSessionKey(spec);
48+
let currentMeta: SessionAcpMeta | undefined;
49+
hoisted.readAcpSessionEntryMock.mockImplementation(() =>
50+
currentMeta ? { sessionKey, storeSessionKey: sessionKey, acp: currentMeta } : null,
51+
);
52+
hoisted.upsertAcpSessionMetaMock.mockImplementation(
53+
({
54+
mutate,
55+
}: {
56+
mutate: (
57+
current: SessionAcpMeta | undefined,
58+
entry: { acp?: SessionAcpMeta },
59+
) => SessionAcpMeta | null | undefined;
60+
}) => {
61+
currentMeta = mutate(currentMeta, { acp: currentMeta }) ?? currentMeta;
62+
return { sessionId: "configured-session", updatedAt: Date.now(), acp: currentMeta };
63+
},
64+
);
65+
const manager = new AcpSessionManager();
66+
const getManager = vi.spyOn(managerModule, "getAcpSessionManager").mockReturnValue(manager);
67+
const ensure = (thinking?: string) =>
68+
ensureConfiguredAcpBindingSession({ cfg: baseCfg, spec: { ...spec, thinking } });
69+
const runTurn = (requestId: string) =>
70+
manager.runTurn({
71+
provenance: "system",
72+
cfg: baseCfg,
73+
sessionKey,
74+
text: requestId,
75+
mode: "prompt",
76+
requestId,
77+
});
78+
try {
79+
expect(await ensure("off")).toEqual({ ok: true, sessionKey });
80+
await runTurn("first");
81+
await runTurn("second");
82+
expect(currentMeta?.runtimeOptions?.thinking).toBe("off");
83+
84+
expect(await ensure("high")).toEqual({ ok: true, sessionKey });
85+
await runTurn("third");
86+
const acceptedMeta = currentMeta;
87+
for (let attempt = 0; attempt < 2; attempt++) {
88+
expect(await ensure("off")).toEqual({
89+
ok: false,
90+
sessionKey,
91+
error: "Live off is unsupported",
92+
});
93+
expect(currentMeta).toEqual(acceptedMeta);
94+
}
95+
expect(await ensure()).toEqual({ ok: true, sessionKey });
96+
await runTurn("fourth");
97+
expect(currentMeta?.runtimeOptions?.thinking).toBe("high");
98+
expect(runtimeState.ensureSession).toHaveBeenCalledOnce();
99+
expect(runtimeState.close).not.toHaveBeenCalled();
100+
expect(runtimeState.runTurn).toHaveBeenCalledTimes(4);
101+
} finally {
102+
getManager.mockRestore();
103+
}
104+
});
105+
24106
it("persists runtime mode changes through setSessionRuntimeMode", async () => {
25107
const runtimeState = createRuntime();
26108
hoisted.requireAcpRuntimeBackendMock.mockReturnValue({

‎src/acp/persistent-bindings.lifecycle.test.ts‎

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ const managerMocks = vi.hoisted(() => ({
1010
resolveSession: vi.fn(),
1111
closeSession: vi.fn(),
1212
initializeSession: vi.fn(),
13-
updateSessionRuntimeOptions: vi.fn(),
13+
setSessionConfigOption: vi.fn(),
1414
}));
1515

1616
vi.mock("./control-plane/manager.js", () => ({
1717
getAcpSessionManager: () => ({
1818
resolveSession: managerMocks.resolveSession,
1919
closeSession: managerMocks.closeSession,
2020
initializeSession: managerMocks.initializeSession,
21-
updateSessionRuntimeOptions: managerMocks.updateSessionRuntimeOptions,
21+
setSessionConfigOption: managerMocks.setSessionConfigOption,
2222
}),
2323
}));
2424

@@ -39,7 +39,7 @@ beforeEach(async () => {
3939
metaCleared: false,
4040
});
4141
managerMocks.initializeSession.mockReset().mockResolvedValue(undefined);
42-
managerMocks.updateSessionRuntimeOptions.mockReset().mockResolvedValue(undefined);
42+
managerMocks.setSessionConfigOption.mockReset().mockResolvedValue(undefined);
4343
({ ensureConfiguredAcpBindingSession } = await import("./persistent-bindings.lifecycle.js"));
4444
});
4545

@@ -119,7 +119,7 @@ describe("ensureConfiguredAcpBindingSession", () => {
119119
expect(ensured).toEqual({ ok: true, sessionKey });
120120
expect(managerMocks.closeSession).not.toHaveBeenCalled();
121121
expect(managerMocks.initializeSession).not.toHaveBeenCalled();
122-
expect(managerMocks.updateSessionRuntimeOptions).not.toHaveBeenCalled();
122+
expect(managerMocks.setSessionConfigOption).not.toHaveBeenCalled();
123123
});
124124

125125
it.each([
@@ -141,11 +141,11 @@ describe("ensureConfiguredAcpBindingSession", () => {
141141
});
142142

143143
expect(ensured).toEqual({ ok: true, sessionKey });
144-
expect(managerMocks.updateSessionRuntimeOptions).toHaveBeenCalledWith({
145-
cfg: baseCfg,
146-
sessionKey,
147-
patch: runtimeOptions,
148-
});
144+
expect(managerMocks.setSessionConfigOption.mock.calls).toEqual(
145+
Object.entries(runtimeOptions).map(([key, value]) => [
146+
{ cfg: baseCfg, sessionKey, key, value },
147+
]),
148+
);
149149
expect(managerMocks.closeSession).not.toHaveBeenCalled();
150150
expect(managerMocks.initializeSession).not.toHaveBeenCalled();
151151
});
@@ -158,7 +158,28 @@ describe("ensureConfiguredAcpBindingSession", () => {
158158
ok: true,
159159
sessionKey,
160160
});
161-
expect(managerMocks.updateSessionRuntimeOptions).not.toHaveBeenCalled();
161+
expect(managerMocks.setSessionConfigOption).not.toHaveBeenCalled();
162+
expect(managerMocks.closeSession).not.toHaveBeenCalled();
163+
expect(managerMocks.initializeSession).not.toHaveBeenCalled();
164+
});
165+
166+
it("reports rejected live thinking without replacing or overwriting the existing session", async () => {
167+
const spec = createPersistentSpec({ thinking: "off" });
168+
const sessionKey = mockReadySession({
169+
spec,
170+
cwd: "/workspace/openclaw",
171+
thinking: "high",
172+
});
173+
managerMocks.setSessionConfigOption.mockRejectedValue(new Error("Live off is unsupported"));
174+
175+
for (let attempt = 0; attempt < 2; attempt++) {
176+
expect(await ensureConfiguredAcpBindingSession({ cfg: baseCfg, spec })).toEqual({
177+
ok: false,
178+
sessionKey,
179+
error: "Live off is unsupported",
180+
});
181+
}
182+
expect(managerMocks.setSessionConfigOption).toHaveBeenCalledTimes(2);
162183
expect(managerMocks.closeSession).not.toHaveBeenCalled();
163184
expect(managerMocks.initializeSession).not.toHaveBeenCalled();
164185
});
@@ -259,10 +280,11 @@ describe("ensureConfiguredAcpBindingSession", () => {
259280
});
260281

261282
expect(ensured).toEqual({ ok: true, sessionKey });
262-
expect(managerMocks.updateSessionRuntimeOptions).toHaveBeenCalledWith({
283+
expect(managerMocks.setSessionConfigOption).toHaveBeenCalledWith({
263284
cfg: baseCfg,
264285
sessionKey,
265-
patch: { thinking: "off" },
286+
key: "thinking",
287+
value: "off",
266288
});
267289
expect(managerMocks.closeSession).not.toHaveBeenCalled();
268290
expect(managerMocks.initializeSession).not.toHaveBeenCalled();
@@ -283,7 +305,7 @@ describe("ensureConfiguredAcpBindingSession", () => {
283305
});
284306

285307
expect(ensured).toEqual({ ok: true, sessionKey });
286-
expect(managerMocks.updateSessionRuntimeOptions).not.toHaveBeenCalled();
308+
expect(managerMocks.setSessionConfigOption).not.toHaveBeenCalled();
287309
expect(managerMocks.closeSession).not.toHaveBeenCalled();
288310
expect(managerMocks.initializeSession).not.toHaveBeenCalled();
289311
});

‎src/acp/persistent-bindings.lifecycle.ts‎

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -77,20 +77,13 @@ export async function ensureConfiguredAcpBindingSession(params: {
7777
meta: resolution.meta,
7878
})
7979
) {
80-
// Omitted options retain the current selection: ACP has no generic unset control,
81-
// and recreating a bound conversation to restore defaults would discard its history.
82-
if (
83-
(["model", "thinking"] as const).some(
84-
(key) =>
85-
runtimeOptions[key] !== undefined &&
86-
normalizeText(resolution.meta.runtimeOptions?.[key]) !== runtimeOptions[key],
87-
)
88-
) {
89-
await acpManager.updateSessionRuntimeOptions({
90-
cfg: params.cfg,
91-
sessionKey,
92-
patch: runtimeOptions,
93-
});
80+
// Apply before persisting: rejected controls must not overwrite accepted options.
81+
// Model precedes effort; omission retains the selection because ACP has no unset.
82+
for (const key of ["model", "thinking"] as const) {
83+
const value = runtimeOptions[key];
84+
if (value !== undefined && normalizeText(resolution.meta.runtimeOptions?.[key]) !== value) {
85+
await acpManager.setSessionConfigOption({ cfg: params.cfg, sessionKey, key, value });
86+
}
9487
}
9588
return {
9689
ok: true,

0 commit comments

Comments
 (0)