@openclaw/acpx 2026.9.1-beta.1 → 2026.9.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,14 +1,45 @@
1
1
  import { d as withAcpxLeaseEnvironment, i as createAcpxProcessLeaseId, o as hashAcpxProcessCommand, t as ACPX_PROBE_LEASE_SESSION_KEY, u as readAcpxProcessLeaseIdentity, v as splitCommandParts } from "./process-lease-Cwvj7WGe.js";
2
2
  import { AcpRuntimeError } from "./runtime-api.js";
3
- import { d as OPENCLAW_CODEX_CONFIG_ARG, l as CODEX_ACP_PACKAGE, n as cleanupOpenClawOwnedAcpxProcessTree, r as isOpenClawLeaseAwareAcpxProcessCommand, t as cleanupOpenClawOwnedAcpxPendingLease } from "./process-reaper-DduWm_7N.js";
3
+ import { t as resolveAcpxSessionResource } from "./session-resource-UWe7qD3m.js";
4
+ import { a as CODEX_ACP_PACKAGE, i as isOpenClawLeaseAwareAcpxProcessCommand, n as cleanupOpenClawOwnedAcpxPendingLease, o as OPENCLAW_CODEX_CONFIG_ARG, r as cleanupOpenClawOwnedAcpxProcessTree } from "./service-COMUTA5A.js";
4
5
  import { parseStrictPositiveInteger } from "openclaw/plugin-sdk/number-runtime";
5
6
  import { normalizeStringEntries } from "openclaw/plugin-sdk/string-coerce-runtime";
6
7
  import path, { resolve } from "node:path";
7
8
  import fs from "node:fs/promises";
8
9
  import { sliceUtf16Safe } from "openclaw/plugin-sdk/text-utility-runtime";
9
10
  import { AsyncLocalStorage } from "node:async_hooks";
10
- import { ACPX_BACKEND_ID, AcpxRuntime as AcpxRuntime$1, createAcpRuntime, createAgentRegistry, createFileSessionStore, decodeAcpxRuntimeHandleState, encodeAcpxRuntimeHandleState, isRequestedModelUnsupportedError } from "acpx/runtime";
11
+ import { ACPX_BACKEND_ID, AcpxRuntime as AcpxRuntime$1, createAcpRuntime, createAgentRegistry, createFileSessionStore, decodeAcpxRuntimeHandleState, decodeAcpxRuntimeHandleState as decodeAcpxRuntimeHandleState$1, encodeAcpxRuntimeHandleState, isRequestedModelUnsupportedError } from "acpx/runtime";
11
12
  import { redactSensitiveText } from "openclaw/plugin-sdk/security-runtime";
13
+ //#region extensions/acpx/src/session-owner.ts
14
+ function requireAcpxOwnerMigration(sessionKey) {
15
+ throw new AcpRuntimeError("ACP_SESSION_INIT_FAILED", `ACP session "${sessionKey}" has an unqualified or unverifiable backend locator. Stop the Gateway and run "openclaw doctor --fix" to migrate ownership without losing history, then restart.`, { detailCode: "SESSION_OWNER_MIGRATION_REQUIRED" });
16
+ }
17
+ function assertAcpxSessionOwnerLocator(target, legacyBareSessionKeys) {
18
+ const resource = resolveAcpxSessionResource(target);
19
+ const qualified = resource === target.sessionKey.trim().toLowerCase();
20
+ const persisted = target.persistedHandle;
21
+ if (!qualified && (legacyBareSessionKeys?.has(target.sessionKey.trim().toLowerCase()) || legacyBareSessionKeys?.has(resource) && !persisted)) requireAcpxOwnerMigration(target.sessionKey);
22
+ if (persisted) {
23
+ const decoded = decodeAcpxRuntimeHandleState$1(persisted.runtimeSessionName);
24
+ if (!qualified && !decoded || decoded && (decoded.name !== resource || persisted.acpxRecordId && decoded.acpxRecordId !== persisted.acpxRecordId)) requireAcpxOwnerMigration(target.sessionKey);
25
+ }
26
+ return resource;
27
+ }
28
+ /** Preserve physical oneshot record IDs and the upstream-encoded runtime handle. */
29
+ function toAcpxResourceInput(input) {
30
+ const sessionKey = assertAcpxSessionOwnerLocator({
31
+ ...input.handle,
32
+ persistedHandle: input.handle
33
+ });
34
+ return {
35
+ ...input,
36
+ handle: {
37
+ ...input.handle,
38
+ sessionKey
39
+ }
40
+ };
41
+ }
42
+ //#endregion
12
43
  //#region extensions/acpx/src/runtime.ts
13
44
  /**
14
45
  * OpenClaw ACPX runtime adapter. It wraps the upstream acpx runtime with
@@ -50,7 +81,8 @@ function isGenericInternalAcpError(error) {
50
81
  async function readCodexWrapperStderrTail(params) {
51
82
  if (!params.wrapperRoot || !params.leaseId) return "";
52
83
  try {
53
- return compactDiagnosticText(redactSensitiveText(sliceUtf16Safe(await fs.readFile(path.join(params.wrapperRoot, codexWrapperStderrLogFileName(params.leaseId)), "utf8"), -6e3)));
84
+ const text = await fs.readFile(path.join(params.wrapperRoot, codexWrapperStderrLogFileName(params.leaseId)), "utf8");
85
+ return compactDiagnosticText(redactSensitiveText(sliceUtf16Safe(text, -6e3)));
54
86
  } catch {
55
87
  return "";
56
88
  }
@@ -178,7 +210,7 @@ const OPENCLAW_BRIDGE_EXECUTABLE = "openclaw";
178
210
  const OPENCLAW_BRIDGE_SUBCOMMAND = "acp";
179
211
  const CODEX_ACP_AGENT_ID = "codex";
180
212
  const CODEX_ACP_OPENCLAW_PREFIX = "openai/";
181
- const CLAUDE_ACP_OPENCLAW_PREFIX = "anthropic/";
213
+ const CLAUDE_ACP_OPENCLAW_PREFIX = /^(?:anthropic|amazon-bedrock)\//i;
182
214
  const CODEX_ACP_THINKING_ALIASES = /* @__PURE__ */ new Map([
183
215
  ["off", void 0],
184
216
  ["minimal", "low"],
@@ -341,8 +373,9 @@ function withCodexSessionModel(input, override) {
341
373
  function normalizeClaudeAcpModelOverride(rawModel) {
342
374
  const raw = rawModel?.trim();
343
375
  if (!raw) return;
344
- if (!raw.toLowerCase().startsWith(CLAUDE_ACP_OPENCLAW_PREFIX)) return raw;
345
- return raw.slice(10).trim() || void 0;
376
+ const prefix = raw.match(CLAUDE_ACP_OPENCLAW_PREFIX);
377
+ if (!prefix) return raw;
378
+ return raw.slice(prefix[0].length).trim() || void 0;
346
379
  }
347
380
  function withAcpxSessionOptions(input) {
348
381
  const existingOptions = input.sessionOptions;
@@ -426,7 +459,12 @@ function withManagedToolsMcpSessionEnv(params) {
426
459
  }];
427
460
  return {
428
461
  ...server,
429
- env
462
+ env,
463
+ args: params.agentId ? [
464
+ ...server.args,
465
+ "--openclaw-agent-id",
466
+ params.agentId
467
+ ] : server.args
430
468
  };
431
469
  });
432
470
  return changed ? nextServers : params.mcpServers;
@@ -434,6 +472,7 @@ function withManagedToolsMcpSessionEnv(params) {
434
472
  /** OpenClaw-managed ACP runtime implementation backed by the upstream acpx runtime. */
435
473
  var AcpxRuntime = class {
436
474
  constructor(options, testOptions) {
475
+ this.ownerAwareSessions = 1;
437
476
  this.codexAcpModelOverrideScope = new AsyncLocalStorage();
438
477
  this.managedToolsSessionDelegates = /* @__PURE__ */ new Map();
439
478
  this.launchLeaseScope = new AsyncLocalStorage();
@@ -441,6 +480,7 @@ var AcpxRuntime = class {
441
480
  this.processLeaseTransitionTails = /* @__PURE__ */ new Map();
442
481
  this.processLeaseOperationCounts = /* @__PURE__ */ new Map();
443
482
  this.uncertainProcessLeaseIds = /* @__PURE__ */ new Set();
483
+ this.legacyBareSessionKeys = new Set(options.openclawLegacyBareSessionKeys);
444
484
  const { openclawProcessCleanup, ...delegateTestOptions } = testOptions ?? {};
445
485
  this.processCleanupDeps = openclawProcessCleanup;
446
486
  this.wrapperRoot = options.openclawWrapperRoot;
@@ -484,12 +524,11 @@ var AcpxRuntime = class {
484
524
  }
485
525
  resolveDelegateForSession(params) {
486
526
  if (shouldUseBridgeSafeDelegateForCommand(params.command)) return this.bridgeSafeDelegate;
487
- return this.resolveManagedToolsDelegateForSession(params.sessionKey);
527
+ return this.resolveManagedToolsDelegateForSession(params);
488
528
  }
489
- resolveManagedToolsDelegateForSession(sessionKey) {
529
+ resolveManagedToolsDelegateForSession(target) {
490
530
  if (!this.managedToolsMcpBridgeEnabled) return this.delegate;
491
- const normalizedSessionKey = sessionKey.trim();
492
- if (!normalizedSessionKey) return this.delegate;
531
+ const normalizedSessionKey = resolveAcpxSessionResource(target);
493
532
  const cached = this.managedToolsSessionDelegates.get(normalizedSessionKey);
494
533
  if (cached) return cached;
495
534
  const delegate = new AcpxRuntime$1({
@@ -498,7 +537,8 @@ var AcpxRuntime = class {
498
537
  pluginToolsEnabled: this.pluginToolsMcpBridgeEnabled,
499
538
  openclawToolsEnabled: this.openclawToolsMcpBridgeEnabled,
500
539
  mcpServers: this.delegateOptions.mcpServers,
501
- sessionKey: normalizedSessionKey
540
+ sessionKey: target.sessionKey,
541
+ agentId: target.agentId
502
542
  })
503
543
  }, this.delegateTestOptions);
504
544
  this.managedToolsSessionDelegates.set(normalizedSessionKey, delegate);
@@ -511,7 +551,11 @@ var AcpxRuntime = class {
511
551
  this.managedToolsSessionDelegates.delete(normalizedSessionKey);
512
552
  }
513
553
  async loadOperationSnapshotForHandle(handle) {
514
- const record = await this.sessionStore.load(handle.acpxRecordId ?? handle.sessionKey);
554
+ assertAcpxSessionOwnerLocator({
555
+ ...handle,
556
+ persistedHandle: handle
557
+ }, this.legacyBareSessionKeys);
558
+ const record = await this.sessionStore.load(handle.acpxRecordId ?? resolveAcpxSessionResource(handle));
515
559
  return {
516
560
  record,
517
561
  command: readAgentCommandFromRecord(record) ?? resolveAgentCommand({
@@ -523,7 +567,8 @@ var AcpxRuntime = class {
523
567
  resolveDelegateForOperationSnapshot(handle, snapshot) {
524
568
  return this.resolveDelegateForSession({
525
569
  command: snapshot.command,
526
- sessionKey: handle.sessionKey
570
+ sessionKey: handle.sessionKey,
571
+ agentId: handle.agentId
527
572
  });
528
573
  }
529
574
  commandWithLaunchLease(command) {
@@ -622,7 +667,7 @@ var AcpxRuntime = class {
622
667
  await processLeaseStore.save({
623
668
  leaseId: identity.leaseId,
624
669
  gatewayInstanceId: identity.gatewayInstanceId,
625
- sessionKey: handle.sessionKey,
670
+ sessionKey: resolveAcpxSessionResource(handle),
626
671
  wrapperRoot,
627
672
  wrapperPath: extractGeneratedWrapperPath(command),
628
673
  rootPid: recordPid ?? 0,
@@ -632,7 +677,7 @@ var AcpxRuntime = class {
632
677
  });
633
678
  return;
634
679
  }
635
- if (existing.gatewayInstanceId !== identity.gatewayInstanceId || existing.sessionKey !== handle.sessionKey || existing.wrapperRoot !== wrapperRoot) throw new AcpRuntimeError("ACP_TURN_FAILED", `ACPX process lease ${identity.leaseId} belongs to another session`);
680
+ if (existing.gatewayInstanceId !== identity.gatewayInstanceId || existing.sessionKey !== resolveAcpxSessionResource(handle) || existing.wrapperRoot !== wrapperRoot) throw new AcpRuntimeError("ACP_TURN_FAILED", `ACPX process lease ${identity.leaseId} belongs to another session`);
636
681
  });
637
682
  return identity;
638
683
  }
@@ -672,7 +717,7 @@ var AcpxRuntime = class {
672
717
  });
673
718
  }
674
719
  async finalizeProcessLeaseForOperation(handle, identity) {
675
- await this.finalizeProcessLeaseForSession(handle.acpxRecordId ?? handle.sessionKey, identity);
720
+ await this.finalizeProcessLeaseForSession(handle.acpxRecordId ?? resolveAcpxSessionResource(handle), identity);
676
721
  }
677
722
  async finalizeProcessLeaseForSession(sessionId, identity) {
678
723
  if (!identity || !this.processLeaseStore) return;
@@ -687,7 +732,8 @@ var AcpxRuntime = class {
687
732
  }
688
733
  this.uncertainProcessLeaseIds.delete(identity.leaseId);
689
734
  try {
690
- const recordIdentity = readAcpxProcessLeaseIdentity(readAgentCommandFromRecord(await this.sessionStore.load(sessionId)));
735
+ const record = await this.sessionStore.load(sessionId);
736
+ const recordIdentity = readAcpxProcessLeaseIdentity(readAgentCommandFromRecord(record));
691
737
  if (recordIdentity?.leaseId !== identity.leaseId || recordIdentity.gatewayInstanceId !== identity.gatewayInstanceId) await processLeaseStore.markState(identity.leaseId, "lost");
692
738
  } catch {}
693
739
  });
@@ -763,7 +809,7 @@ var AcpxRuntime = class {
763
809
  }
764
810
  }
765
811
  async readCodexTurnFailureStderr(params) {
766
- const record = await this.sessionStore.load(params.handle.acpxRecordId ?? params.handle.sessionKey);
812
+ const record = await this.sessionStore.load(params.handle.acpxRecordId ?? resolveAcpxSessionResource(params.handle));
767
813
  return readCodexWrapperStderrTail({
768
814
  wrapperRoot: this.wrapperRoot,
769
815
  leaseId: readOpenClawLeaseIdFromRecord(record)
@@ -772,7 +818,7 @@ var AcpxRuntime = class {
772
818
  async cleanupProcessTreeForRecord(handle, record) {
773
819
  const leaseId = readOpenClawLeaseIdFromRecord(record);
774
820
  const rootPid = readAgentPidFromRecord(record);
775
- const sessionKeys = [handle.sessionKey, readSessionRecordName(record)];
821
+ const sessionKeys = [resolveAcpxSessionResource(handle), readSessionRecordName(record)];
776
822
  const selectedLease = selectCurrentSessionLease({
777
823
  leases: this.gatewayInstanceId && this.processLeaseStore ? await this.processLeaseStore.listOpen(this.gatewayInstanceId) : [],
778
824
  sessionKeys,
@@ -828,18 +874,28 @@ var AcpxRuntime = class {
828
874
  });
829
875
  }
830
876
  async ensureSession(input) {
831
- return await this.runSerializedSessionEnsure(input.sessionKey, () => this.ensureSessionUnlocked(input));
877
+ const resource = assertAcpxSessionOwnerLocator(input, this.legacyBareSessionKeys);
878
+ return await this.runSerializedSessionEnsure(resource, () => this.ensureSessionUnlocked(input));
832
879
  }
833
- async ensureSessionUnlocked(input) {
834
- assertSupportedRuntimeSessionMode(input.mode);
880
+ async ensureSessionUnlocked(logicalInput) {
881
+ assertSupportedRuntimeSessionMode(logicalInput.mode);
835
882
  const command = resolveAgentCommand({
836
- agentName: input.agent,
883
+ agentName: logicalInput.agent,
837
884
  agentRegistry: this.agentRegistry
838
885
  });
839
886
  const delegate = this.resolveDelegateForSession({
840
887
  command,
841
- sessionKey: input.sessionKey
888
+ sessionKey: logicalInput.sessionKey,
889
+ agentId: logicalInput.agentId
842
890
  });
891
+ const logicalTarget = {
892
+ sessionKey: logicalInput.sessionKey,
893
+ agentId: logicalInput.agentId
894
+ };
895
+ const input = {
896
+ ...logicalInput,
897
+ sessionKey: resolveAcpxSessionResource(logicalInput)
898
+ };
843
899
  const isCodexAcp = normalizeAgentName(input.agent) === CODEX_ACP_AGENT_ID && isCodexAcpCommand(command);
844
900
  const claudeModelOverride = isClaudeAcpCommand(command) ? normalizeClaudeAcpModelOverride(input.model) : void 0;
845
901
  const codexClassification = isCodexAcp ? classifyCodexAcpModelRequest(input.model, input.thinking) : void 0;
@@ -863,38 +919,42 @@ var AcpxRuntime = class {
863
919
  command: stableLaunchCommand,
864
920
  resumeSessionId: input.resumeSessionId
865
921
  });
866
- const handle = !codexModelOverride ? await this.runWithLaunchLease({
867
- sessionKey: ensureInput.sessionKey,
868
- command: stableLaunchCommand,
869
- reusableCommand,
870
- run: () => this.withCodexWrapperDiagnostics({
922
+ return {
923
+ ...!codexModelOverride ? await this.runWithLaunchLease({
924
+ sessionKey: ensureInput.sessionKey,
871
925
  command: stableLaunchCommand,
872
- fallbackCode: "ACP_SESSION_INIT_FAILED",
873
- run: () => ensureDelegateSessionWithModelFallback(delegate, ensureInput)
874
- })
875
- }) : await this.runWithLaunchLease({
876
- sessionKey: input.sessionKey,
877
- command: stableLaunchCommand,
878
- reusableCommand,
879
- run: () => this.codexAcpModelOverrideScope.run(codexModelOverride, () => this.withCodexWrapperDiagnostics({
926
+ reusableCommand,
927
+ run: () => this.withCodexWrapperDiagnostics({
928
+ command: stableLaunchCommand,
929
+ fallbackCode: "ACP_SESSION_INIT_FAILED",
930
+ run: () => ensureDelegateSessionWithModelFallback(delegate, ensureInput)
931
+ })
932
+ }) : await this.runWithLaunchLease({
933
+ sessionKey: input.sessionKey,
880
934
  command: stableLaunchCommand,
881
- fallbackCode: "ACP_SESSION_INIT_FAILED",
882
- run: () => delegate.ensureSession(withAcpxSessionOptions(ensureInput))
883
- }))
884
- });
885
- return appliedModel ? {
886
- ...handle,
887
- appliedModel
888
- } : handle;
935
+ reusableCommand,
936
+ run: () => this.codexAcpModelOverrideScope.run(codexModelOverride, () => this.withCodexWrapperDiagnostics({
937
+ command: stableLaunchCommand,
938
+ fallbackCode: "ACP_SESSION_INIT_FAILED",
939
+ run: () => delegate.ensureSession(withAcpxSessionOptions(ensureInput))
940
+ }))
941
+ }),
942
+ ...logicalTarget,
943
+ ...appliedModel ? { appliedModel } : {}
944
+ };
889
945
  }
890
946
  async *runTurn(input) {
891
- const record = await this.sessionStore.load(input.handle.acpxRecordId ?? input.handle.sessionKey);
947
+ assertAcpxSessionOwnerLocator({
948
+ ...input.handle,
949
+ persistedHandle: input.handle
950
+ }, this.legacyBareSessionKeys);
951
+ const record = await this.sessionStore.load(input.handle.acpxRecordId ?? resolveAcpxSessionResource(input.handle));
892
952
  const turnLease = await this.prepareProcessLeaseForOperation(input.handle, record);
893
953
  let command;
894
954
  try {
895
955
  command = (await this.loadOperationSnapshotForHandle(input.handle)).command;
896
956
  const delegate = this.resolveDelegateForOperationSnapshot(input.handle, await this.loadOperationSnapshotForHandle(input.handle));
897
- for await (const event of delegate.runTurn(withOpenClawManagedTurnTimeout(input))) {
957
+ for await (const event of delegate.runTurn(withOpenClawManagedTurnTimeout(toAcpxResourceInput(input)))) {
898
958
  if (event.type !== "error" || !isCodexAcpCommand(command) || !isGenericInternalAcpErrorMessage(event.message)) {
899
959
  yield event;
900
960
  continue;
@@ -929,7 +989,7 @@ var AcpxRuntime = class {
929
989
  try {
930
990
  return {
931
991
  command,
932
- turn: delegate.startTurn(withOpenClawManagedTurnTimeout(input))
992
+ turn: delegate.startTurn(withOpenClawManagedTurnTimeout(toAcpxResourceInput(input)))
933
993
  };
934
994
  } catch (error) {
935
995
  if (!isCodexAcpCommand(command) || !isGenericInternalAcpError(error)) throw error;
@@ -999,23 +1059,24 @@ var AcpxRuntime = class {
999
1059
  };
1000
1060
  }
1001
1061
  getCapabilities(input) {
1002
- return this.delegate.getCapabilities(input);
1062
+ return this.delegate.getCapabilities(input?.handle ? toAcpxResourceInput({ handle: input.handle }) : input);
1003
1063
  }
1004
1064
  async getStatus(input) {
1005
1065
  const snapshot = await this.loadOperationSnapshotForHandle(input.handle);
1006
- return this.resolveDelegateForOperationSnapshot(input.handle, snapshot).getStatus(input);
1066
+ return this.resolveDelegateForOperationSnapshot(input.handle, snapshot).getStatus(toAcpxResourceInput(input));
1007
1067
  }
1008
1068
  async setMode(input) {
1009
1069
  const snapshot = await this.loadOperationSnapshotForHandle(input.handle);
1010
- await this.runWithProcessLeaseForHandle(input.handle, snapshot.record, () => this.resolveDelegateForOperationSnapshot(input.handle, snapshot).setMode(input));
1070
+ await this.runWithProcessLeaseForHandle(input.handle, snapshot.record, () => this.resolveDelegateForOperationSnapshot(input.handle, snapshot).setMode(toAcpxResourceInput(input)));
1011
1071
  }
1012
1072
  async setConfigOption(input) {
1013
1073
  const snapshot = await this.loadOperationSnapshotForHandle(input.handle);
1014
- await this.runWithProcessLeaseForHandle(input.handle, snapshot.record, () => this.setConfigOptionUnlocked(input, snapshot));
1074
+ return await this.runWithProcessLeaseForHandle(input.handle, snapshot.record, () => this.setConfigOptionUnlocked(input, snapshot));
1015
1075
  }
1016
- async setConfigOptionUnlocked(input, snapshot) {
1076
+ async setConfigOptionUnlocked(logicalInput, snapshot) {
1017
1077
  const { command } = snapshot;
1018
- const delegate = this.resolveDelegateForOperationSnapshot(input.handle, snapshot);
1078
+ const delegate = this.resolveDelegateForOperationSnapshot(logicalInput.handle, snapshot);
1079
+ const input = toAcpxResourceInput(logicalInput);
1019
1080
  const key = input.key.trim().toLowerCase();
1020
1081
  const isCodexAcp = isCodexAcpCommand(command);
1021
1082
  if (WIRE_TIMEOUT_CONFIG_KEYS.has(key) && (isCodexAcp || isClaudeAcpCommand(command))) return;
@@ -1024,45 +1085,43 @@ var AcpxRuntime = class {
1024
1085
  const classification = classifyCodexAcpModelRequest(input.value);
1025
1086
  if (classification.kind === "unsupported") failUnsupportedCodexAcpModel(input.value);
1026
1087
  const { override } = classification;
1027
- if (override.model) await delegate.setConfigOption({
1088
+ const modelResult = override.model ? await delegate.setConfigOption({
1028
1089
  ...input,
1029
1090
  key: "model",
1030
1091
  value: override.model
1031
- });
1032
- if (override.reasoningEffort) await delegate.setConfigOption({
1092
+ }) : void 0;
1093
+ if (override.reasoningEffort) return await delegate.setConfigOption({
1033
1094
  ...input,
1034
1095
  key: "reasoning_effort",
1035
1096
  value: override.reasoningEffort
1036
1097
  });
1037
- return;
1098
+ return modelResult;
1038
1099
  }
1039
1100
  if (key === "thinking" || key === "thought_level" || key === "reasoning_effort") {
1040
1101
  const classification = classifyCodexAcpModelRequest(void 0, input.value);
1041
1102
  const reasoningEffort = classification.kind === "override" ? classification.override.reasoningEffort : void 0;
1042
- if (!reasoningEffort) return;
1043
- await delegate.setConfigOption({
1103
+ if (!reasoningEffort) throw new AcpRuntimeError("ACP_BACKEND_UNSUPPORTED_CONTROL", "Clearing Codex reasoning effort on an existing session is unsupported. Choose a supported explicit effort; the current effort is unchanged.");
1104
+ return await delegate.setConfigOption({
1044
1105
  ...input,
1045
1106
  key: "reasoning_effort",
1046
1107
  value: reasoningEffort
1047
1108
  });
1048
- return;
1049
1109
  }
1050
1110
  }
1051
- if (isClaudeAcpCommand(command) && key === "model") {
1052
- await delegate.setConfigOption({
1053
- ...input,
1054
- value: normalizeClaudeAcpModelOverride(input.value) ?? input.value
1055
- });
1056
- return;
1057
- }
1058
- await delegate.setConfigOption(input);
1111
+ if (isClaudeAcpCommand(command) && key === "model") return await delegate.setConfigOption({
1112
+ ...input,
1113
+ value: normalizeClaudeAcpModelOverride(input.value) ?? input.value
1114
+ });
1115
+ return await delegate.setConfigOption(input);
1059
1116
  }
1060
1117
  async cancel(input) {
1061
1118
  const snapshot = await this.loadOperationSnapshotForHandle(input.handle);
1062
- await this.resolveDelegateForOperationSnapshot(input.handle, snapshot).cancel(input);
1119
+ await this.resolveDelegateForOperationSnapshot(input.handle, snapshot).cancel(toAcpxResourceInput(input));
1063
1120
  }
1064
1121
  async prepareFreshSession(input) {
1065
- this.sessionStore.markFresh(input.sessionKey);
1122
+ const resource = assertAcpxSessionOwnerLocator(input, this.legacyBareSessionKeys);
1123
+ this.sessionStore.markFresh(resource);
1124
+ this.legacyBareSessionKeys.delete(resource);
1066
1125
  }
1067
1126
  async close(input) {
1068
1127
  const snapshot = await this.loadOperationSnapshotForHandle(input.handle);
@@ -1073,7 +1132,7 @@ var AcpxRuntime = class {
1073
1132
  let closeSucceeded;
1074
1133
  try {
1075
1134
  await delegate.close({
1076
- handle: input.handle,
1135
+ handle: toAcpxResourceInput(input).handle,
1077
1136
  reason: input.reason,
1078
1137
  discardPersistentState: input.discardPersistentState
1079
1138
  });
@@ -1082,8 +1141,11 @@ var AcpxRuntime = class {
1082
1141
  await this.cleanupProcessTreeForRecord(input.handle, snapshot.record);
1083
1142
  cleanupSucceeded = true;
1084
1143
  }
1085
- if (closeSucceeded) this.releaseManagedToolsDelegateForSession(input.handle.sessionKey);
1086
- if (closeSucceeded && input.discardPersistentState) this.sessionStore.markFresh(input.handle.sessionKey);
1144
+ if (closeSucceeded) this.releaseManagedToolsDelegateForSession(resolveAcpxSessionResource(input.handle));
1145
+ if (closeSucceeded && input.discardPersistentState) await this.prepareFreshSession({
1146
+ ...input.handle,
1147
+ persistedHandle: input.handle
1148
+ });
1087
1149
  } finally {
1088
1150
  if (cleanupSucceeded) await this.finalizeProcessLeaseForOperation(input.handle, closeLease);
1089
1151
  else await this.releaseProcessLeaseAfterUncertainFailure(closeLease);