Skip to content

Commit afed61a

Browse files
committed
fix: keep ACP thinking aligned after model switches
Carry published ACPX accepted control snapshots through the plugin boundary and reconcile selected thinking in the session owner. Preserve selectable pending thinking on automatic replay, persist accepted changes before later failures, and show effective thinking in command replies. Keep shipped optional-control replay and third-party void backends unchanged.
1 parent 86a0b22 commit afed61a

22 files changed

Lines changed: 502 additions & 79 deletions

‎docs/plugins/sdk-runtime.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,8 @@ snapshots; OpenClaw owns all persistence and lifecycle coordination.
263263

264264
Before advertising an ACP-backed action, use `resolveAcpSessionAvailability(...)` from `openclaw/plugin-sdk/acp-runtime`. It applies the canonical enablement, dispatch, allowed-agent, registered-backend, and backend-health checks; recheck it immediately before creating the session.
265265

266+
ACP backends can return `AcpRuntimeConfigOptionResult` from `setConfigOption(...)`: a complete `configOptions` array of `{ id, category?, currentValue, options? }`, where `currentValue` is a string or boolean. Select `options` contain `{ value }` entries or groups of `{ options: [{ value }] }`. OpenClaw reconciles an already-selected thinking override from the accepted `thought_level` category or a recognized thinking key. Automatic model replay preserves a pending thinking value only when it is still current or selectable; explicit controls always use the accepted value. An empty array removes that override; omitted or null `category` is allowed, and backend defaults are not pinned. Existing third-party backends returning `void` retain requested-value persistence. Return the snapshot after backend persistence succeeds; reject failed writes.
267+
266268
Creation holds the session lifecycle mutation fence through `afterCreate`, so new work waits for plugin-owned initialization to finish and pre-existing admitted work makes creation fail. The callback receives a clone of the created state. If it returns a patch, that patch may contain only `pluginExtensions`, and its value is the complete final `pluginExtensions` field. A callback or final-persistence failure rolls back the unchanged new row and transcript; guarded rollback preserves a row changed or claimed concurrently. `recoverMatchingInitialEntry: true` is only for retrying interrupted initialization when the persisted trusted fields match exactly, and recovery requires `afterCreate` to return a final patch.
267269

268270
Use `runWithWorkAdmission(...)` when a plugin starts work on a persisted session. The callback rejects archived or concurrently replaced sessions, keeps archive/reset/delete mutations coordinated through completion, and receives an `AbortSignal` that must be forwarded to the agent run. A harness may explicitly name trusted execution delegates through its experimental `delegatedExecutionPluginIds` registration field. Delegates can admit and run only an exact existing model-locked session; all session mutations remain restricted to the harness owner. See [Agent harness plugins](/plugins/sdk-agent-harness#delegated-execution).

‎docs/tools/acp-agents.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -839,6 +839,12 @@ does not accept a target token.
839839
| `/acp set <key> <value>` | generic | `key=cwd` uses the cwd override path. |
840840
| `/acp reset-options` | clears all runtime overrides | - |
841841

842+
When a backend returns its accepted controls, OpenClaw keeps an already-selected
843+
thinking level in sync with that response. A model switch may lower the level or
844+
remove thinking support; subsequent turns and reconnects use the accepted
845+
selection instead of replaying the old level. Backend defaults do not become new
846+
session overrides, and the model reference keeps its OpenClaw provider prefix.
847+
842848
## acpx harness, plugin setup, and permissions
843849

844850
For acpx harness configuration (Claude Code / Codex / Gemini CLI aliases),

‎extensions/acpx/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"dependencies": {
1111
"@agentclientprotocol/claude-agent-acp": "0.70.0",
1212
"@agentclientprotocol/codex-acp": "1.6.0",
13-
"acpx": "0.13.1",
13+
"acpx": "0.13.2",
1414
"smol-toml": "1.8.0",
1515
"zod": "4.4.3"
1616
},

‎extensions/acpx/runtime-api.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export {
1313
export type {
1414
AcpRuntime,
1515
AcpRuntimeCapabilities,
16+
AcpRuntimeConfigOptionResult,
1617
AcpRuntimeDoctorReport,
1718
AcpRuntimeEnsureInput,
1819
AcpRuntimeEvent,

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ describe("createLazyAcpRuntimeProxy", () => {
4545
promptStarted.promise,
4646
);
4747
const proxy = createLazyAcpRuntimeProxy(async () => runtime);
48+
const accepted = { configOptions: [{ id: "effort", currentValue: "medium" }] };
49+
runtime.setConfigOption = vi.fn(async () => accepted);
50+
await expect(proxy.setConfigOption({ handle, key: "effort", value: "high" })).resolves.toBe(
51+
accepted,
52+
);
4853

4954
await expect(proxy.doctor()).resolves.toEqual({
5055
ok: false,

‎extensions/acpx/src/runtime-proxy.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ export function createLazyAcpRuntimeProxy(
7979
await (await resolveRuntime()).setMode(input);
8080
},
8181
async setConfigOption(input) {
82-
await (await resolveRuntime()).setConfigOption(input);
82+
return await (await resolveRuntime()).setConfigOption(input);
8383
},
8484
async doctor() {
8585
return await (await resolveRuntime()).doctor();

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

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1634,19 +1634,21 @@ describe("AcpxRuntime fresh reset wrapper", () => {
16341634
save: vi.fn(async () => {}),
16351635
};
16361636
const { runtime, delegate } = makeRuntime(baseStore);
1637-
const setConfigOption = vi.spyOn(delegate, "setConfigOption").mockResolvedValue(undefined);
1637+
const accepted = { configOptions: [{ id: "reasoning_effort", currentValue: "medium" }] };
1638+
const setConfigOption = vi.spyOn(delegate, "setConfigOption").mockResolvedValue(accepted);
16381639
const handle: Parameters<NonNullable<AcpRuntime["setConfigOption"]>>[0]["handle"] = {
16391640
sessionKey: "agent:codex:acp:test",
16401641
backend: "acpx",
16411642
runtimeSessionName: "agent:codex:acp:test",
16421643
acpxRecordId: "agent:codex:acp:test",
16431644
};
16441645

1645-
await runtime.setConfigOption({
1646+
const result = await runtime.setConfigOption({
16461647
handle,
16471648
key: "model",
16481649
value,
16491650
});
1651+
expect(result).toBe(accepted);
16501652

16511653
expect(setConfigOption).toHaveBeenCalledOnce();
16521654
expect(setConfigOption).toHaveBeenCalledWith({
@@ -1694,19 +1696,26 @@ describe("AcpxRuntime fresh reset wrapper", () => {
16941696
save: vi.fn(async () => {}),
16951697
};
16961698
const { runtime, delegate } = makeRuntime(baseStore);
1697-
const setConfigOption = vi.spyOn(delegate, "setConfigOption").mockResolvedValue(undefined);
1699+
const accepted = { configOptions: [{ id: "reasoning_effort", currentValue: "high" }] };
1700+
const setConfigOption = vi
1701+
.spyOn(delegate, "setConfigOption")
1702+
.mockResolvedValueOnce({
1703+
configOptions: [{ id: "reasoning_effort", currentValue: "medium" }],
1704+
})
1705+
.mockResolvedValueOnce(accepted);
16981706
const handle: Parameters<NonNullable<AcpRuntime["setConfigOption"]>>[0]["handle"] = {
16991707
sessionKey: "agent:codex:acp:test",
17001708
backend: "acpx",
17011709
runtimeSessionName: "agent:codex:acp:test",
17021710
acpxRecordId: "agent:codex:acp:test",
17031711
};
17041712

1705-
await runtime.setConfigOption({
1713+
const result = await runtime.setConfigOption({
17061714
handle,
17071715
key: "model",
17081716
value: "openai/gpt-5.4/high",
17091717
});
1718+
expect(result).toBe(accepted);
17101719

17111720
expect(setConfigOption).toHaveBeenNthCalledWith(1, {
17121721
handle,
@@ -1786,7 +1795,10 @@ describe("AcpxRuntime fresh reset wrapper", () => {
17861795
save: vi.fn(async () => {}),
17871796
};
17881797
const { runtime, delegate } = makeRuntime(baseStore);
1789-
const setConfigOption = vi.spyOn(delegate, "setConfigOption").mockResolvedValue(undefined);
1798+
const accepted = {
1799+
configOptions: [{ id: "reasoning_effort", currentValue: expected ?? "medium" }],
1800+
};
1801+
const setConfigOption = vi.spyOn(delegate, "setConfigOption").mockResolvedValue(accepted);
17901802
const handle: Parameters<NonNullable<AcpRuntime["setConfigOption"]>>[0]["handle"] = {
17911803
sessionKey: "agent:codex:acp:test",
17921804
backend: "acpx",
@@ -1807,7 +1819,7 @@ describe("AcpxRuntime fresh reset wrapper", () => {
18071819
return;
18081820
}
18091821

1810-
await update;
1822+
await expect(update).resolves.toBe(accepted);
18111823
expect(setConfigOption).toHaveBeenCalledWith({
18121824
handle,
18131825
key: "reasoning_effort",
@@ -1924,19 +1936,21 @@ describe("AcpxRuntime fresh reset wrapper", () => {
19241936
save: vi.fn(async () => {}),
19251937
};
19261938
const { runtime, delegate } = makeRuntime(baseStore);
1927-
const setConfigOption = vi.spyOn(delegate, "setConfigOption").mockResolvedValue(undefined);
1939+
const accepted = { configOptions: [{ id: "effort", currentValue: "low" }] };
1940+
const setConfigOption = vi.spyOn(delegate, "setConfigOption").mockResolvedValue(accepted);
19281941
const handle: Parameters<NonNullable<AcpRuntime["setConfigOption"]>>[0]["handle"] = {
19291942
sessionKey: "agent:claude:acp:test",
19301943
backend: "acpx",
19311944
runtimeSessionName: "agent:claude:acp:test",
19321945
acpxRecordId: "agent:claude:acp:test",
19331946
};
19341947

1935-
await runtime.setConfigOption({
1948+
const result = await runtime.setConfigOption({
19361949
handle,
19371950
key: "model",
19381951
value: "anthropic/claude-sonnet-4-6",
19391952
});
1953+
expect(result).toBe(accepted);
19401954
await runtime.setConfigOption({
19411955
handle,
19421956
key: "model",

‎extensions/acpx/src/runtime.ts‎

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1771,17 +1771,17 @@ export class AcpxRuntime implements CompleteAcpRuntime {
17711771

17721772
async setConfigOption(
17731773
input: Parameters<NonNullable<AcpRuntime["setConfigOption"]>>[0],
1774-
): Promise<void> {
1774+
): ReturnType<NonNullable<AcpRuntime["setConfigOption"]>> {
17751775
const snapshot = await this.loadOperationSnapshotForHandle(input.handle);
1776-
await this.runWithProcessLeaseForHandle(input.handle, snapshot.record, () =>
1776+
return await this.runWithProcessLeaseForHandle(input.handle, snapshot.record, () =>
17771777
this.setConfigOptionUnlocked(input, snapshot),
17781778
);
17791779
}
17801780

17811781
private async setConfigOptionUnlocked(
17821782
input: Parameters<NonNullable<AcpRuntime["setConfigOption"]>>[0],
17831783
snapshot: AcpxHandleOperationSnapshot,
1784-
): Promise<void> {
1784+
): ReturnType<NonNullable<AcpRuntime["setConfigOption"]>> {
17851785
const { command } = snapshot;
17861786
const delegate = this.resolveDelegateForOperationSnapshot(input.handle, snapshot);
17871787
const key = input.key.trim().toLowerCase();
@@ -1796,17 +1796,17 @@ export class AcpxRuntime implements CompleteAcpRuntime {
17961796
failUnsupportedCodexAcpModel(input.value);
17971797
}
17981798
const { override } = classification;
1799-
if (override.model) {
1800-
await delegate.setConfigOption({ ...input, key: "model", value: override.model });
1801-
}
1799+
const modelResult = override.model
1800+
? await delegate.setConfigOption({ ...input, key: "model", value: override.model })
1801+
: undefined;
18021802
if (override.reasoningEffort) {
1803-
await delegate.setConfigOption({
1803+
return await delegate.setConfigOption({
18041804
...input,
18051805
key: "reasoning_effort",
18061806
value: override.reasoningEffort,
18071807
});
18081808
}
1809-
return;
1809+
return modelResult;
18101810
}
18111811
if (key === "thinking" || key === "thought_level" || key === "reasoning_effort") {
18121812
const classification = classifyCodexAcpModelRequest(undefined, input.value);
@@ -1819,22 +1819,20 @@ export class AcpxRuntime implements CompleteAcpRuntime {
18191819
"Clearing Codex reasoning effort on an existing session is unsupported. Choose a supported explicit effort; the current effort is unchanged.",
18201820
);
18211821
}
1822-
await delegate.setConfigOption({
1822+
return await delegate.setConfigOption({
18231823
...input,
18241824
key: "reasoning_effort",
18251825
value: reasoningEffort,
18261826
});
1827-
return;
18281827
}
18291828
}
18301829
if (isClaudeAcpCommand(command) && key === "model") {
1831-
await delegate.setConfigOption({
1830+
return await delegate.setConfigOption({
18321831
...input,
18331832
value: normalizeClaudeAcpModelOverride(input.value) ?? input.value,
18341833
});
1835-
return;
18361834
}
1837-
await delegate.setConfigOption(input);
1835+
return await delegate.setConfigOption(input);
18381836
}
18391837

18401838
async cancel(input: Parameters<AcpRuntime["cancel"]>[0]): Promise<void> {

‎packages/acp-core/src/runtime/types.ts‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,17 @@ export type AcpRuntimeCapabilities = {
119119
configOptionKeys?: string[];
120120
};
121121

122+
/** Complete accepted control snapshot after a successful config-option write. */
123+
export type AcpRuntimeConfigOptionResult = {
124+
configOptions: Array<{
125+
id: string;
126+
category?: string | null;
127+
currentValue: string | boolean;
128+
/** Selectable values, flat or grouped as in ACP session config options. */
129+
options?: Array<{ value: string }> | Array<{ options: Array<{ value: string }> }>;
130+
}>;
131+
};
132+
122133
export type AcpRuntimeStatus = {
123134
summary?: string;
124135
/** Backend-local record identifier, if exposed by adapter/runtime. */
@@ -241,7 +252,12 @@ export interface AcpRuntime {
241252

242253
setMode?(input: { handle: AcpRuntimeHandle; mode: string }): Promise<void>;
243254

244-
setConfigOption?(input: { handle: AcpRuntimeHandle; key: string; value: string }): Promise<void>;
255+
/** Older third-party backends may omit the accepted snapshot. Empty options are authoritative. */
256+
setConfigOption?(input: {
257+
handle: AcpRuntimeHandle;
258+
key: string;
259+
value: string;
260+
}): Promise<AcpRuntimeConfigOptionResult | void>;
245261

246262
doctor?(): Promise<AcpRuntimeDoctorReport>;
247263

‎pnpm-lock.yaml‎

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)