@openclaw/codex 2026.9.6 → 2026.9.8
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.
- package/README.md +2 -0
- package/assets/icon.png +0 -0
- package/dist/.setup/{account-usage-runtime-Eem_WGqY.mjs → account-usage-runtime-G348lY1q.mjs} +5 -5
- package/dist/.setup/{apply-DDOi8uNx.mjs → apply-Cqb-YoCS.mjs} +22 -36
- package/dist/.setup/{attempt-client-cleanup-CEv1cKwF.mjs → attempt-client-cleanup-B-S7ngS_.mjs} +128 -37
- package/dist/.setup/attempt-workspace-context-BJ5Z_olH.mjs +164 -0
- package/dist/.setup/{auth-binding-DhLWa_7K.mjs → auth-binding-BLWz7stm.mjs} +14 -1
- package/dist/.setup/{auth-cache-key-B2mpaI9D.mjs → auth-cache-key-Dnps4W4_.mjs} +36 -34
- package/dist/.setup/{auth-profile-WqZtZfXN.mjs → auth-profile-B0okYl2D.mjs} +1 -2
- package/dist/.setup/auth-start-options-BPIPeEX8.mjs +44 -0
- package/dist/.setup/{binding-connection-ThoatDcb.mjs → binding-connection-DTtN1KrX.mjs} +2 -2
- package/dist/.setup/{binding-connection.runtime-yoHrABt-.mjs → binding-connection.runtime-6TpgD1M6.mjs} +4 -4
- package/dist/.setup/{bounded-turn-B2HScEgT.mjs → bounded-turn-BNunZPtz.mjs} +15 -18
- package/dist/.setup/bounded-turn-isolation-B8K_ylqk.mjs +14 -0
- package/dist/.setup/{build-state-C7EnDVgr.mjs → build-state-DIQ5O_-S.mjs} +1 -1
- package/dist/.setup/{capabilities-CDXOOFdZ.mjs → capabilities-B3WEZl4e.mjs} +2 -10
- package/dist/.setup/{client-catalog-response-BMgt_4q4.mjs → client-catalog-response-DRvx_wCC.mjs} +1 -1
- package/dist/.setup/{client-Cs08OXVQ.mjs → client-qyUBJlGZ.mjs} +138 -399
- package/dist/.setup/{command-dispatch-B4JuOsOk.mjs → command-dispatch-Btrs1D6f.mjs} +5 -8
- package/dist/.setup/{command-formatters-Bmqvr9tO.mjs → command-formatters-R3ckE3Co.mjs} +29 -61
- package/dist/.setup/{command-handlers-DW7Lx9oH.mjs → command-handlers-DvlCHJch.mjs} +222 -343
- package/dist/.setup/{command-rpc-DixIj3HW.mjs → command-rpc-skzRq4wD.mjs} +15 -18
- package/dist/.setup/compact-8ttks5U5.mjs +776 -0
- package/dist/.setup/{config-BoTP_mrL.mjs → config-DKhXquav.mjs} +26 -28
- package/dist/.setup/{config-options-BvaRs51b.mjs → config-options-CzyWLTJt.mjs} +24 -37
- package/dist/.setup/{config-parsing-CcB9iPoq.mjs → config-parsing-b088LyhT.mjs} +57 -60
- package/dist/.setup/{config-runtime-C8Rw1m1m.mjs → config-runtime-C0NbLms1.mjs} +2 -2
- package/dist/.setup/{config-security-BEReZ6go.mjs → config-security-CE-FcGw9.mjs} +32 -111
- package/dist/.setup/{config-utils-DujwEnhg.mjs → config-utils-D0CXecki.mjs} +3 -13
- package/dist/.setup/context-engine-projection-PezSESth.mjs +387 -0
- package/dist/.setup/{conversation-binding-DP-gMrBP.mjs → conversation-binding-74LaGGH-.mjs} +67 -90
- package/dist/.setup/{conversation-binding-data-CrcyZk6O.mjs → conversation-binding-data-C746z5Pn.mjs} +8 -12
- package/dist/.setup/{conversation-control-uK9Jomlc.mjs → conversation-control-OrN6zuaY.mjs} +8 -8
- package/dist/.setup/{cyber-failover-DYwbmf1o.mjs → cyber-failover-XV0nNRZu.mjs} +1 -1
- package/dist/.setup/{cyber-failover-notice-e9G3J9-e.mjs → cyber-failover-notice-RNpGpTyP.mjs} +1 -1
- package/dist/.setup/{dynamic-tools-BDXl-8Cw.mjs → dynamic-tools-Db2sY5cZ.mjs} +2305 -2606
- package/dist/.setup/{effective-mcp-catalog-CvnvnGIe.mjs → effective-mcp-catalog-Bi6-SQ7i.mjs} +8 -17
- package/dist/.setup/{ephemeral-turn-poidXgek.mjs → ephemeral-turn-DiCS1ijR.mjs} +3 -3
- package/dist/.setup/event-projector-assistant-message-MV_1dj-3.mjs +69 -0
- package/dist/.setup/{event-projector-usage-CnBS8Wa3.mjs → event-projector-usage-03R0I2dM.mjs} +3 -25
- package/dist/.setup/event-projector-values-DJSz8BTk.mjs +106 -0
- package/dist/.setup/incognito-session-DWYapfwf.mjs +2 -0
- package/dist/.setup/{inference-context-D96l9-ew.mjs → inference-context-D-9gWlTR.mjs} +16 -18
- package/dist/.setup/inference-dispatch-CMZtjQyz.mjs +359 -0
- package/dist/.setup/inference-metadata-CgIf7sOx.mjs +81 -0
- package/dist/.setup/{inference-proxy-b-aJMSxm.mjs → inference-proxy-DhcXOgUE.mjs} +174 -214
- package/dist/.setup/{isolated-completion-BIZFhTNG.mjs → isolated-completion-D80IXfQF.mjs} +9 -12
- package/dist/.setup/{managed-binary-BnshlFag.mjs → managed-binary-kiWRhNRE.mjs} +8 -12
- package/dist/.setup/{model-catalog-CfXJf9Ay.mjs → model-catalog-DiC0Tkha.mjs} +11 -10
- package/dist/.setup/model-runtime-BdqzOMkU.mjs +11 -0
- package/dist/.setup/{models-KnqBv0hE.mjs → models-DfLmPV0k.mjs} +9 -18
- package/dist/.setup/{native-auth-rWbGbMn3.mjs → native-auth-CuG53tu4.mjs} +4 -4
- package/dist/.setup/{native-execution-policy-umd0tgh4.mjs → native-execution-policy-BxZJy5mP.mjs} +5 -30
- package/dist/.setup/{native-subagent-monitor-D3filLY2.mjs → native-subagent-monitor-BwkQXf9e.mjs} +4395 -3609
- package/dist/.setup/native-subagent-pending-assignments-DwkCzLvD.mjs +203 -0
- package/dist/.setup/native-task-assignments-DMQ0g3hu.mjs +194 -0
- package/dist/.setup/{node-cli-sessions-r3avj02l.mjs → node-cli-sessions-HC4W6FLI.mjs} +19 -49
- package/dist/.setup/{node-exec-server.runtime-BDwWXVpK.mjs → node-exec-server.runtime-BgBfWQqo.mjs} +3 -6
- package/dist/.setup/{plan-CN3VwfNU.mjs → plan-DPdMk1Oy.mjs} +49 -92
- package/dist/.setup/{plugin-activation-DT3MNtqj.mjs → plugin-activation-cNHRfaxU.mjs} +8 -36
- package/dist/.setup/{plugin-app-cache-key-B2CsSdnV.mjs → plugin-app-cache-key-BL9B5H0L.mjs} +6 -23
- package/dist/.setup/{plugin-inventory-BoRei8Z4.mjs → plugin-inventory-Cky2XJUw.mjs} +21 -21
- package/dist/.setup/{plugin-marketplace-discovery-CDOi8IFs.mjs → plugin-marketplace-discovery-D_dV9FXa.mjs} +18 -24
- package/dist/.setup/{plugin-metadata-cache-Ctmo83k_.mjs → plugin-metadata-cache-BRwtRct9.mjs} +116 -176
- package/dist/.setup/{provider-BOsxQHOM.mjs → provider-D6F_7p1I.mjs} +11 -14
- package/dist/.setup/{provider-capabilities-BfE88FZ5.mjs → provider-capabilities-DG5qbsUZ.mjs} +13 -18
- package/dist/.setup/{rate-limits-CMU3DUD0.mjs → rate-limits-B7-X2TgG.mjs} +9 -31
- package/dist/.setup/{request-D2L0zMrq.mjs → request-BZOfsSXW.mjs} +7 -6
- package/dist/.setup/responses-oauth-twnuTaAa.mjs +93 -0
- package/dist/.setup/rpc-error-BlD2vuzn.mjs +31 -0
- package/dist/.setup/{run-attempt-BHu11r7h.mjs → run-attempt-dYJhjZrp.mjs} +1035 -1023
- package/dist/.setup/{run-attempt-lifecycle-B7JbY4-F.mjs → run-attempt-lifecycle-C-6O3Exn.mjs} +10 -24
- package/dist/.setup/{runtime-artifact-CLZ8udh-.mjs → runtime-artifact-DDQ-HGXf.mjs} +16 -4
- package/dist/.setup/runtime-artifact-connection-D68qQn1m.mjs +78 -0
- package/dist/.setup/sandbox-guard-DjCz2eOw.mjs +126 -0
- package/dist/.setup/scope-DOC1Xjc8.mjs +6 -0
- package/dist/.setup/session-binding-DGCYAfvD.mjs +443 -0
- package/dist/.setup/{session-binding-record-BGoz8wOK.mjs → session-binding-record-Oe9L-CNY.mjs} +52 -130
- package/dist/.setup/{session-binding-sidecars-BlB5EvIS.mjs → session-binding-sidecars-jo6H8dFr.mjs} +196 -17
- package/dist/.setup/{session-catalog-Pno1xGcl.mjs → session-catalog-BFafIiF6.mjs} +185 -350
- package/dist/.setup/{session-catalog-adoption-BI6UTDZT.mjs → session-catalog-adoption-BU_pHWG7.mjs} +7 -6
- package/dist/.setup/{session-catalog-archive-lHBqzhaO.mjs → session-catalog-archive-spHfihri.mjs} +6 -6
- package/dist/.setup/session-catalog-events-BMCFMZw-.mjs +139 -0
- package/dist/.setup/session-catalog-home-id-vlih0B_g.mjs +22 -0
- package/dist/.setup/{session-catalog-index-B9_VQIUz.mjs → session-catalog-index-DwJjnF5k.mjs} +126 -122
- package/dist/.setup/{session-catalog-index-order-hcdz07yN.mjs → session-catalog-index-order-BcQpHks3.mjs} +1 -1
- package/dist/.setup/{session-catalog-index-state-Dgh8ORJm.mjs → session-catalog-index-state-TeO7EyO-.mjs} +3 -2
- package/dist/.setup/session-catalog-limits-DDxOsQeC.mjs +14 -0
- package/dist/.setup/session-catalog-list-request-CvtxrYSe.mjs +170 -0
- package/dist/.setup/session-catalog-native-projection-CuaFZuQE.mjs +178 -0
- package/dist/.setup/{session-catalog-node-adoption-ITddWx_X.mjs → session-catalog-node-adoption-DgXvSGu0.mjs} +10 -27
- package/dist/.setup/{session-catalog-node-continue-6g6qi4A9.mjs → session-catalog-node-continue-DjKXHBbi.mjs} +8 -10
- package/dist/.setup/session-catalog-node-lookup-CtAXI5W5.mjs +56 -0
- package/dist/.setup/{session-catalog-native-projection-DowriLid.mjs → session-catalog-parsing-CPGaPYr-.mjs} +11 -194
- package/dist/.setup/{session-catalog-projection-zK_PUsiE.mjs → session-catalog-projection-CGfzfP93.mjs} +6 -4
- package/dist/.setup/session-catalog-provenance-DoAvktcj.mjs +95 -0
- package/dist/.setup/{session-cli-irrD-uo7.mjs → session-cli-DlmBHYIe.mjs} +9 -22
- package/dist/.setup/{session-history-BrqhSCf9.mjs → session-history-D83lJWHG.mjs} +4 -6
- package/dist/.setup/{session-history-import-D-3wAgOP.mjs → session-history-import-WhX-X33a.mjs} +7 -10
- package/dist/.setup/session-history-read-Ov3StuL4.mjs +133 -0
- package/dist/.setup/{session-history.worker-CaCh0xF_.mjs → session-history.worker-MnPKncqP.mjs} +9 -5
- package/dist/.setup/session-initialization-6aveB9qb.mjs +22 -0
- package/dist/.setup/{session-permission-policy-BI1QK_98.mjs → session-permission-policy-Ci_fVX6y.mjs} +4 -8
- package/dist/.setup/{session-retirement-BH-S6qkJ.mjs → session-retirement-LlYWBKTJ.mjs} +17 -17
- package/dist/.setup/{settled-turn-context-fmwouT5I.mjs → settled-turn-context-D4yj4rxf.mjs} +1 -1
- package/dist/.setup/{settled-turn-finalizer-DiAi6Kx6.mjs → settled-turn-finalizer-DW9W3gza.mjs} +14 -10
- package/dist/.setup/{shared-client-DA4VR4Eb.mjs → shared-client-CJCTeFpQ.mjs} +783 -412
- package/dist/.setup/shared-client-lifecycle-7xgtlo15.mjs +153 -0
- package/dist/.setup/{side-question-BJ1wSDcB.mjs → side-question-BLeGj7TQ.mjs} +79 -143
- package/dist/.setup/{source-CUzJq5WN.mjs → source-CJis_1EF.mjs} +80 -137
- package/dist/.setup/{thread-lifecycle-B3mfz1TG.mjs → thread-lifecycle-_bAbjedG.mjs} +294 -737
- package/dist/.setup/{thread-ownership-DcTtAcXj.mjs → thread-ownership-B6pPt21M.mjs} +45 -10
- package/dist/.setup/{incognito-session-uhrBF6wJ.mjs → thread-ownership-queue-Dp24d7-F.mjs} +1 -2
- package/dist/.setup/{thread-policy-DGuQsuFC.mjs → thread-policy-gNPzzpVp.mjs} +46 -7
- package/dist/.setup/{thread-requests-BLvGkP2R.mjs → thread-requests-OWGOiDaV.mjs} +199 -302
- package/dist/.setup/{thread-resume-DIBXwOpE.mjs → thread-resume-GOry0AYh.mjs} +6 -6
- package/dist/.setup/{timeout-C910MdAB.mjs → timeout-CXOfNoaX.mjs} +1 -35
- package/dist/.setup/{transcript-history-projection-ZZpkFkJ_.mjs → transcript-history-projection-DRSifI-1.mjs} +17 -89
- package/dist/.setup/{transcript-mirror-attestation-CzM-94NC.mjs → transcript-mirror-attestation-YSegaktH.mjs} +3 -4
- package/dist/.setup/{transcript-mirror-BtHDBp1G.mjs → transcript-mirror-kxmCYsuF.mjs} +7 -9
- package/dist/.setup/{transport-stdio-h2VHOskC.mjs → transport-stdio-Bdegpn2V.mjs} +5 -22
- package/dist/.setup/transport-websocket-BTBE-LD9.mjs +211 -0
- package/dist/.setup/{upstream-prompt-provenance-LphB8slG.mjs → upstream-prompt-provenance-fXkKbPVC.mjs} +3 -9
- package/dist/.setup/{upstream-session-fork-BUr4OUbC.mjs → upstream-session-fork-gkdRj2yH.mjs} +23 -23
- package/dist/.setup/{usage-BML0r-ua.mjs → usage-CApUvLOV.mjs} +4 -4
- package/dist/.setup/{usage-limit-error-DUMbefVY.mjs → usage-limit-error-wSMQkbpV.mjs} +4 -19
- package/dist/.setup/{web-search-provider.runtime-CDKlN-Rv.mjs → web-search-provider.runtime-UKgeiBUG.mjs} +8 -19
- package/dist/api.js +9 -11
- package/dist/catalog-page.worker.js +1 -1
- package/dist/cli-metadata.js +1 -1
- package/dist/doctor-contract-api.js +50 -8
- package/dist/harness.js +344 -1
- package/dist/index.js +193 -245
- package/dist/media-understanding-provider.js +9 -22
- package/dist/migration-provider-api.js +1 -1
- package/dist/provider-discovery.js +1 -1
- package/dist/session-history-worker-runtime.js +3 -3
- package/dist/session-history.worker.js +1 -1
- package/openclaw.plugin.json +14 -2
- package/package.json +7 -6
- package/dist/.setup/attempt-workspace-context-DUVEn_CS.mjs +0 -331
- package/dist/.setup/compact-Du5UvtxA.mjs +0 -680
- package/dist/.setup/event-projector-assistant-message-BsruvNrH.mjs +0 -103
- package/dist/.setup/event-projector-items-C6L_5ZiT.mjs +0 -234
- package/dist/.setup/harness-a_MsE4-_.mjs +0 -355
- package/dist/.setup/history-rejection-B4nOXNXF.mjs +0 -13
- package/dist/.setup/image-payload-sanitizer-tupAr-2o.mjs +0 -79
- package/dist/.setup/local-runtime-attribution-B_2mnqhb.mjs +0 -19
- package/dist/.setup/native-subagent-history-0nYYgo0k.mjs +0 -148
- package/dist/.setup/native-subagent-task-ids-wb8CKZGN.mjs +0 -441
- package/dist/.setup/plugin-approval-roundtrip-C0MZzCuP.mjs +0 -122
- package/dist/.setup/rolldown-runtime-8H4AJuhK.mjs +0 -14
- package/dist/.setup/sandbox-guard-C2sRMOEY.mjs +0 -166
- package/dist/.setup/session-binding-Cm0apEbd.mjs +0 -692
- package/dist/.setup/session-catalog-events-Bj6j94E_.mjs +0 -347
- package/dist/.setup/session-history-read-B3ZfSUbF.mjs +0 -50
- package/dist/.setup/session-initialization-rcgbZiid.mjs +0 -75
- package/dist/.setup/thread-history-page-DoVpnHim.mjs +0 -83
|
@@ -1,692 +0,0 @@
|
|
|
1
|
-
import { t as __exportAll } from "./rolldown-runtime-8H4AJuhK.mjs";
|
|
2
|
-
import { _ as adoptCodexNativeSubagentSubmissions, a as ownsStoredSessionGeneration, c as readCodexBindingTimestamp, d as readCurrentCodexNativeSubagentSubmissions, f as readPluginAppPolicyContext, g as validateBindingForWrite, h as stripUndefinedBinding, i as matchesCodexNativeSubagentSubmissionBinding, l as readCurrentCodexAppServerBinding, m as sessionBindingIdentity, n as assertCodexBindingMayBeReplaced, o as preserveCodexNativeSubagentSubmissions, p as readStoredCodexAppServerBinding, r as bindingStoreKey, s as readCodexAppServerThreadBinding, t as CodexSupervisionBindingReplacementError, u as readCurrentCodexAppServerBindings, v as mutateCodexNativeSubagentSubmissions } from "./session-binding-record-BGoz8wOK.mjs";
|
|
3
|
-
import { n as CODEX_APP_SERVER_BINDING_NAMESPACE, t as CODEX_APP_SERVER_BINDING_MAX_ENTRIES } from "./session-binding-meta-B7aEMU7g.mjs";
|
|
4
|
-
import { n as normalizeCodexAppServerBindingModelProvider } from "./auth-profile-WqZtZfXN.mjs";
|
|
5
|
-
import { asOptionalRecord } from "openclaw/plugin-sdk/string-coerce-runtime";
|
|
6
|
-
import { createHash, randomUUID } from "node:crypto";
|
|
7
|
-
import { isDeepStrictEqual } from "node:util";
|
|
8
|
-
import { AsyncLocalStorage } from "node:async_hooks";
|
|
9
|
-
import { AgentHarnessSessionSupersededError, embeddedAgentLog } from "openclaw/plugin-sdk/agent-harness-runtime";
|
|
10
|
-
import { getSessionEntry, resolveStorePath } from "openclaw/plugin-sdk/session-store-runtime";
|
|
11
|
-
//#region extensions/codex/src/app-server/session-binding.ts
|
|
12
|
-
/** SQLite-backed Codex app-server thread bindings. */
|
|
13
|
-
var session_binding_exports = /* @__PURE__ */ __exportAll({
|
|
14
|
-
CODEX_APP_SERVER_BINDING_GUARDED_REQUEST_TIMEOUT_MS: () => CODEX_APP_SERVER_BINDING_GUARDED_REQUEST_TIMEOUT_MS,
|
|
15
|
-
CODEX_APP_SERVER_BINDING_MAX_ENTRIES: () => CODEX_APP_SERVER_BINDING_MAX_ENTRIES,
|
|
16
|
-
CODEX_APP_SERVER_BINDING_NAMESPACE: () => CODEX_APP_SERVER_BINDING_NAMESPACE,
|
|
17
|
-
CodexSupervisionBindingReplacementError: () => CodexSupervisionBindingReplacementError,
|
|
18
|
-
assertCodexBindingMayBeReplaced: () => assertCodexBindingMayBeReplaced,
|
|
19
|
-
bindingStoreKey: () => bindingStoreKey,
|
|
20
|
-
createCodexAppServerBindingStore: () => createCodexAppServerBindingStore,
|
|
21
|
-
createCodexSessionGenerationSupersededError: () => createCodexSessionGenerationSupersededError,
|
|
22
|
-
createStoredCodexAppServerBinding: () => createStoredCodexAppServerBinding,
|
|
23
|
-
hashCodexAppServerBindingFingerprint: () => hashCodexAppServerBindingFingerprint,
|
|
24
|
-
normalizeStoredCodexAppServerBindingFingerprints: () => normalizeStoredCodexAppServerBindingFingerprints,
|
|
25
|
-
readCodexAppServerThreadBinding: () => readCodexAppServerThreadBinding,
|
|
26
|
-
readStoredCodexAppServerBinding: () => readStoredCodexAppServerBinding,
|
|
27
|
-
reclaimCurrentCodexSessionGeneration: () => reclaimCurrentCodexSessionGeneration,
|
|
28
|
-
resolveCodexRunSessionBindingAuthority: () => resolveCodexRunSessionBindingAuthority,
|
|
29
|
-
resolveCodexSessionBinding: () => resolveCodexSessionBinding,
|
|
30
|
-
sessionBindingIdentity: () => sessionBindingIdentity,
|
|
31
|
-
validateBindingForWrite: () => validateBindingForWrite
|
|
32
|
-
});
|
|
33
|
-
const BINDING_LEASE_RETRY_INTERVAL_MS = 1e3;
|
|
34
|
-
const BOUNDED_BINDING_FINGERPRINT_PATTERN = /^sha256:[a-f0-9]{64}$/i;
|
|
35
|
-
const CODEX_APP_SERVER_BINDING_GUARDED_REQUEST_TIMEOUT_MS = 6e4;
|
|
36
|
-
const BINDING_LEASE_STALE_MS = 65e3;
|
|
37
|
-
const BINDING_LEASE_WAIT_MS = 7e4;
|
|
38
|
-
const BINDING_LEASE_RENEW_INTERVAL_MS = Math.floor(BINDING_LEASE_STALE_MS / 3);
|
|
39
|
-
const PHYSICAL_SESSION_RETIRE_TTL_MS = BINDING_LEASE_WAIT_MS;
|
|
40
|
-
/** Decides whether a run may share the durable stable-key binding owner. */
|
|
41
|
-
function resolveCodexRunSessionBindingAuthority(params) {
|
|
42
|
-
return captureCodexSessionGenerationAuthority(params)[0];
|
|
43
|
-
}
|
|
44
|
-
/** Host lineage is recorded in the same transaction as its successor generation. */
|
|
45
|
-
function readCodexBindingSessionEntry(params) {
|
|
46
|
-
const { identity } = params;
|
|
47
|
-
return identity.sessionKey?.trim() ? getSessionEntry({
|
|
48
|
-
agentId: identity.agentId,
|
|
49
|
-
sessionKey: identity.sessionKey.trim(),
|
|
50
|
-
storePath: params.storePath?.trim() || resolveStorePath(params.config?.session?.store, { agentId: identity.agentId }),
|
|
51
|
-
hydrateSkillPromptRefs: false,
|
|
52
|
-
readConsistency: "latest"
|
|
53
|
-
}) : void 0;
|
|
54
|
-
}
|
|
55
|
-
/** Synchronous model selection recognizes the predecessor; admission rewrites its fence. */
|
|
56
|
-
function readCodexSessionOwnershipBinding(params) {
|
|
57
|
-
const binding = params.bindingStore.read(params.identity);
|
|
58
|
-
if (binding || params.identity.kind !== "session") return binding;
|
|
59
|
-
const entry = readCodexBindingSessionEntry({
|
|
60
|
-
...params,
|
|
61
|
-
identity: params.identity
|
|
62
|
-
});
|
|
63
|
-
return entry?.sessionId === params.identity.sessionId && entry.previousSessionId ? params.bindingStore.read({
|
|
64
|
-
...params.identity,
|
|
65
|
-
sessionId: entry.previousSessionId
|
|
66
|
-
}) : void 0;
|
|
67
|
-
}
|
|
68
|
-
function captureCodexSessionGenerationAuthority(params, assertCallerCurrent = () => {}) {
|
|
69
|
-
const readEntry = () => {
|
|
70
|
-
try {
|
|
71
|
-
return readCodexBindingSessionEntry(params);
|
|
72
|
-
} catch {
|
|
73
|
-
return null;
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
const entry = readEntry();
|
|
77
|
-
const current = entry?.sessionId === params.identity.sessionId;
|
|
78
|
-
const authority = entry === void 0 ? "ephemeral" : current ? "current" : "superseded";
|
|
79
|
-
const previousSessionId = current ? entry.previousSessionId : void 0;
|
|
80
|
-
const assertHostCurrent = () => {
|
|
81
|
-
if (authority === "ephemeral") return;
|
|
82
|
-
const latest = readEntry();
|
|
83
|
-
if (authority !== "current" || !latest || latest.sessionId !== params.identity.sessionId || latest.previousSessionId !== previousSessionId) throw createCodexSessionGenerationSupersededError(params.identity.sessionId);
|
|
84
|
-
};
|
|
85
|
-
const assertCurrent = () => {
|
|
86
|
-
assertCallerCurrent();
|
|
87
|
-
assertHostCurrent();
|
|
88
|
-
};
|
|
89
|
-
return [
|
|
90
|
-
authority,
|
|
91
|
-
previousSessionId,
|
|
92
|
-
assertHostCurrent,
|
|
93
|
-
assertCurrent
|
|
94
|
-
];
|
|
95
|
-
}
|
|
96
|
-
/** Builds the terminal coordination error used when a newer OpenClaw session owns the binding. */
|
|
97
|
-
function createCodexSessionGenerationSupersededError(sessionId) {
|
|
98
|
-
return new AgentHarnessSessionSupersededError(`Codex session generation is no longer current: ${sessionId}`);
|
|
99
|
-
}
|
|
100
|
-
function hashCodexAppServerBindingFingerprint(canonical) {
|
|
101
|
-
return `sha256:${createHash("sha256").update(canonical).digest("hex")}`;
|
|
102
|
-
}
|
|
103
|
-
function normalizeLegacyBindingFingerprint(value) {
|
|
104
|
-
if (typeof value !== "string" || value === "" || value === "[]" || BOUNDED_BINDING_FINGERPRINT_PATTERN.test(value)) return value;
|
|
105
|
-
return hashCodexAppServerBindingFingerprint(value);
|
|
106
|
-
}
|
|
107
|
-
function normalizeLegacyBindingFingerprints(record) {
|
|
108
|
-
let normalized = record;
|
|
109
|
-
for (const key of ["dynamicToolsFingerprint", "userMcpServersFingerprint"]) {
|
|
110
|
-
const value = record[key];
|
|
111
|
-
const next = normalizeLegacyBindingFingerprint(value);
|
|
112
|
-
if (next === value) continue;
|
|
113
|
-
if (normalized === record) normalized = { ...record };
|
|
114
|
-
Object.assign(normalized, { [key]: next });
|
|
115
|
-
}
|
|
116
|
-
return normalized;
|
|
117
|
-
}
|
|
118
|
-
function normalizeStoredCodexAppServerBindingFingerprints(value) {
|
|
119
|
-
const stored = readStoredCodexAppServerBinding(value);
|
|
120
|
-
if (!stored || stored.state !== "active") return stored;
|
|
121
|
-
const binding = normalizeLegacyBindingFingerprints(stored.binding);
|
|
122
|
-
return binding === stored.binding ? stored : readStoredCodexAppServerBinding({
|
|
123
|
-
...stored,
|
|
124
|
-
binding
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
/** Encodes a migrated sidecar binding as one canonical plugin-state row. */
|
|
128
|
-
function createStoredCodexAppServerBinding(value, options = {}) {
|
|
129
|
-
const rawRecord = asOptionalRecord(value);
|
|
130
|
-
if (!rawRecord) return;
|
|
131
|
-
const record = normalizeLegacyBindingFingerprints(rawRecord);
|
|
132
|
-
if (record.schemaVersion !== 1 && record.schemaVersion !== 2) return;
|
|
133
|
-
const pluginAppPolicyContext = readPluginAppPolicyContext(record.pluginAppPolicyContext, record.schemaVersion);
|
|
134
|
-
const historyCoveredThrough = readCodexBindingTimestamp(record.historyCoveredThrough) ?? readCodexBindingTimestamp(record.updatedAt) ?? readCodexBindingTimestamp(record.createdAt) ?? readCodexBindingTimestamp(options.now) ?? (/* @__PURE__ */ new Date()).toISOString();
|
|
135
|
-
const authProfileId = typeof record.authProfileId === "string" ? record.authProfileId : void 0;
|
|
136
|
-
const binding = readCodexAppServerThreadBinding({
|
|
137
|
-
...record,
|
|
138
|
-
modelProvider: normalizeCodexAppServerBindingModelProvider({
|
|
139
|
-
...options.lookup,
|
|
140
|
-
authProfileId,
|
|
141
|
-
modelProvider: typeof record.modelProvider === "string" ? record.modelProvider : void 0
|
|
142
|
-
}),
|
|
143
|
-
cwd: typeof record.cwd === "string" ? record.cwd : "",
|
|
144
|
-
pluginAppPolicyContext,
|
|
145
|
-
historyCoveredThrough
|
|
146
|
-
});
|
|
147
|
-
return binding ? {
|
|
148
|
-
version: 1,
|
|
149
|
-
state: "active",
|
|
150
|
-
binding: stripUndefinedBinding(binding)
|
|
151
|
-
} : void 0;
|
|
152
|
-
}
|
|
153
|
-
function bindingLeaseLostError(key, cause) {
|
|
154
|
-
return new Error(`Lost Codex binding lease: ${key}`, cause === void 0 ? void 0 : { cause });
|
|
155
|
-
}
|
|
156
|
-
async function reclaimPreparedCodexSessionGeneration(params, authority, assertCurrent = authority[3]) {
|
|
157
|
-
const plan = await params.bindingStore.prepareSessionGenerationReclaim(params.identity);
|
|
158
|
-
assertCurrent();
|
|
159
|
-
if (plan.kind === "resolved") return plan.result;
|
|
160
|
-
const [state, previousSessionId, assertHostCurrent] = authority;
|
|
161
|
-
if (state !== "current") return false;
|
|
162
|
-
params.onHostGenerationVerified?.(assertHostCurrent);
|
|
163
|
-
if (previousSessionId === plan.expectedPreviousSessionId) {
|
|
164
|
-
const adopted = await params.bindingStore.adoptSessionGeneration(params.identity, previousSessionId, assertCurrent);
|
|
165
|
-
if (adopted !== "absent") return adopted !== "conflict";
|
|
166
|
-
}
|
|
167
|
-
if (params.reclaimStale === false) return false;
|
|
168
|
-
return params.bindingStore.mutate(params.identity, {
|
|
169
|
-
kind: "reclaim-generation",
|
|
170
|
-
expectedPreviousSessionId: plan.expectedPreviousSessionId
|
|
171
|
-
}, assertCurrent);
|
|
172
|
-
}
|
|
173
|
-
/** Lets the authoritative OpenClaw session generation claim a stale stable binding row. */
|
|
174
|
-
async function reclaimCurrentCodexSessionGeneration(params) {
|
|
175
|
-
params.assertCurrent?.();
|
|
176
|
-
if (!params.identity.sessionKey?.trim()) return true;
|
|
177
|
-
const authority = captureCodexSessionGenerationAuthority(params, params.assertCurrent);
|
|
178
|
-
if (authority[0] === "superseded") return false;
|
|
179
|
-
return reclaimPreparedCodexSessionGeneration(params, authority);
|
|
180
|
-
}
|
|
181
|
-
/** Resolve continuity before selecting native queues, catalogs, or connections. */
|
|
182
|
-
async function resolveCodexSessionBinding(params) {
|
|
183
|
-
let assertCurrent = params.assertCurrent ?? (() => {});
|
|
184
|
-
const assertAdmissionCurrent = () => {
|
|
185
|
-
assertCurrent();
|
|
186
|
-
params.signal?.throwIfAborted();
|
|
187
|
-
};
|
|
188
|
-
assertAdmissionCurrent();
|
|
189
|
-
params.assertBinding?.(readCodexSessionOwnershipBinding(params));
|
|
190
|
-
const identity = params.identity;
|
|
191
|
-
const authority = identity.kind === "session" && identity.sessionKey?.trim() ? captureCodexSessionGenerationAuthority({
|
|
192
|
-
...params,
|
|
193
|
-
identity
|
|
194
|
-
}, assertCurrent) : void 0;
|
|
195
|
-
assertCurrent = authority?.[3] ?? assertCurrent;
|
|
196
|
-
assertAdmissionCurrent();
|
|
197
|
-
let binding = params.bindingStore.read(identity);
|
|
198
|
-
if (!binding && authority && identity.kind === "session") {
|
|
199
|
-
if (!await reclaimPreparedCodexSessionGeneration({
|
|
200
|
-
...params,
|
|
201
|
-
identity,
|
|
202
|
-
reclaimStale: params.reclaimStale === true
|
|
203
|
-
}, authority, assertAdmissionCurrent) && params.reclaimStale) throw createCodexSessionGenerationSupersededError(identity.sessionId);
|
|
204
|
-
binding = params.bindingStore.read(identity);
|
|
205
|
-
}
|
|
206
|
-
assertAdmissionCurrent();
|
|
207
|
-
params.assertBinding?.(binding);
|
|
208
|
-
return {
|
|
209
|
-
binding,
|
|
210
|
-
assertCurrent
|
|
211
|
-
};
|
|
212
|
-
}
|
|
213
|
-
/** Creates the single binding facade owned by the Codex plugin runtime. */
|
|
214
|
-
function createCodexAppServerBindingStore(state) {
|
|
215
|
-
const update = state.update?.bind(state);
|
|
216
|
-
if (!update) throw new Error("Codex app-server bindings require atomic plugin-state updates");
|
|
217
|
-
const leaseContext = new AsyncLocalStorage();
|
|
218
|
-
const archiveContext = new AsyncLocalStorage();
|
|
219
|
-
let activeBindingMutations = 0;
|
|
220
|
-
let pendingArchives = 0;
|
|
221
|
-
let archiveTail = Promise.resolve();
|
|
222
|
-
let bindingMutationsDrained = [];
|
|
223
|
-
const waitForBindingMutations = async () => {
|
|
224
|
-
if (activeBindingMutations === 0) return;
|
|
225
|
-
await new Promise((resolve) => {
|
|
226
|
-
bindingMutationsDrained.push(resolve);
|
|
227
|
-
});
|
|
228
|
-
};
|
|
229
|
-
const runBindingMutation = async (run) => {
|
|
230
|
-
if (archiveContext.getStore() === true) return await run();
|
|
231
|
-
if (pendingArchives > 0) throw new Error("Codex binding mutation blocked while a native archive is in progress; retry");
|
|
232
|
-
activeBindingMutations += 1;
|
|
233
|
-
try {
|
|
234
|
-
return await run();
|
|
235
|
-
} finally {
|
|
236
|
-
activeBindingMutations -= 1;
|
|
237
|
-
if (activeBindingMutations === 0) {
|
|
238
|
-
const drained = bindingMutationsDrained;
|
|
239
|
-
bindingMutationsDrained = [];
|
|
240
|
-
for (const resolve of drained) resolve();
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
};
|
|
244
|
-
const renewLease = (key, owner) => {
|
|
245
|
-
if (owner.failure || owner.phase !== "held") return;
|
|
246
|
-
try {
|
|
247
|
-
let renewed = false;
|
|
248
|
-
owner.assertCurrent?.();
|
|
249
|
-
const stored = update(key, (raw) => {
|
|
250
|
-
const current = readStoredCodexAppServerBinding(raw);
|
|
251
|
-
if (raw !== void 0 && !current) throw new Error(`Invalid Codex app-server binding row: ${key}`);
|
|
252
|
-
const lease = current?.lease;
|
|
253
|
-
const now = Date.now();
|
|
254
|
-
if (!lease || lease.token !== owner.token || lease.expiresAt <= now) return;
|
|
255
|
-
renewed = true;
|
|
256
|
-
return {
|
|
257
|
-
...current,
|
|
258
|
-
lease: {
|
|
259
|
-
token: owner.token,
|
|
260
|
-
expiresAt: now + BINDING_LEASE_STALE_MS
|
|
261
|
-
}
|
|
262
|
-
};
|
|
263
|
-
});
|
|
264
|
-
if (!renewed || !stored) owner.failure = bindingLeaseLostError(key);
|
|
265
|
-
} catch (error) {
|
|
266
|
-
owner.failure = bindingLeaseLostError(key, error);
|
|
267
|
-
}
|
|
268
|
-
};
|
|
269
|
-
const transactKey = async (key, apply, ttlMs, assertCurrent) => {
|
|
270
|
-
const deadline = Date.now() + BINDING_LEASE_WAIT_MS;
|
|
271
|
-
while (true) {
|
|
272
|
-
let busy = false;
|
|
273
|
-
let leaseLost = false;
|
|
274
|
-
let result;
|
|
275
|
-
const ownedLease = leaseContext.getStore()?.get(key);
|
|
276
|
-
if (ownedLease && ownedLease.phase !== "held") throw bindingLeaseLostError(key);
|
|
277
|
-
if (ownedLease?.failure) throw ownedLease.failure;
|
|
278
|
-
const ownedToken = ownedLease?.token;
|
|
279
|
-
assertCurrent?.();
|
|
280
|
-
ownedLease?.assertCurrent?.();
|
|
281
|
-
update(key, (raw) => {
|
|
282
|
-
const current = readStoredCodexAppServerBinding(raw);
|
|
283
|
-
if (raw !== void 0 && !current) throw new Error(`Invalid Codex app-server binding row: ${key}`);
|
|
284
|
-
const activeLease = current?.lease;
|
|
285
|
-
const now = Date.now();
|
|
286
|
-
if (ownedToken && (!activeLease || activeLease.token !== ownedToken || activeLease.expiresAt <= now)) {
|
|
287
|
-
leaseLost = true;
|
|
288
|
-
return;
|
|
289
|
-
}
|
|
290
|
-
if (activeLease && activeLease.token !== ownedToken && activeLease.expiresAt > now) {
|
|
291
|
-
busy = true;
|
|
292
|
-
return;
|
|
293
|
-
}
|
|
294
|
-
const applied = apply(current, ownedToken);
|
|
295
|
-
result = applied.result;
|
|
296
|
-
return applied.next;
|
|
297
|
-
}, ttlMs == null ? void 0 : { ttlMs });
|
|
298
|
-
if (leaseLost) {
|
|
299
|
-
const failure = bindingLeaseLostError(key);
|
|
300
|
-
if (ownedLease) ownedLease.failure = failure;
|
|
301
|
-
throw failure;
|
|
302
|
-
}
|
|
303
|
-
if (!busy) return result;
|
|
304
|
-
if (Date.now() >= deadline) throw new Error(`Timed out waiting for Codex binding lease: ${key}`);
|
|
305
|
-
await sleep(BINDING_LEASE_RETRY_INTERVAL_MS);
|
|
306
|
-
}
|
|
307
|
-
};
|
|
308
|
-
const withBindingLease = async (identity, run, options = {}) => {
|
|
309
|
-
options.assertCurrent?.();
|
|
310
|
-
const key = bindingStoreKey(identity);
|
|
311
|
-
const owned = leaseContext.getStore();
|
|
312
|
-
const existingOwner = owned?.get(key);
|
|
313
|
-
if (existingOwner) {
|
|
314
|
-
if (existingOwner.phase !== "held") throw bindingLeaseLostError(key);
|
|
315
|
-
const failureBeforeRun = existingOwner.failure;
|
|
316
|
-
if (failureBeforeRun) throw failureBeforeRun;
|
|
317
|
-
const result = await run();
|
|
318
|
-
options.assertCurrent?.();
|
|
319
|
-
const failureAfterRun = existingOwner.failure;
|
|
320
|
-
if (failureAfterRun) throw failureAfterRun;
|
|
321
|
-
return result;
|
|
322
|
-
}
|
|
323
|
-
const token = randomUUID();
|
|
324
|
-
const acquired = await transactKey(key, (current) => {
|
|
325
|
-
if (current?.state === "cleared" && current.retired === true && ownsStoredSessionGeneration(identity, current) && !options.allowRetired) return { result: false };
|
|
326
|
-
const lease = {
|
|
327
|
-
token,
|
|
328
|
-
expiresAt: Date.now() + BINDING_LEASE_STALE_MS
|
|
329
|
-
};
|
|
330
|
-
if (current?.state === "active") return {
|
|
331
|
-
result: true,
|
|
332
|
-
next: {
|
|
333
|
-
...current,
|
|
334
|
-
...preservedSessionGeneration(identity, current),
|
|
335
|
-
lease
|
|
336
|
-
}
|
|
337
|
-
};
|
|
338
|
-
if (current?.state === "cleared" && current.retired === true) return {
|
|
339
|
-
result: true,
|
|
340
|
-
next: {
|
|
341
|
-
...current,
|
|
342
|
-
lease
|
|
343
|
-
}
|
|
344
|
-
};
|
|
345
|
-
return {
|
|
346
|
-
result: true,
|
|
347
|
-
next: {
|
|
348
|
-
version: 1,
|
|
349
|
-
state: "cleared",
|
|
350
|
-
...preservedSessionGeneration(identity, current),
|
|
351
|
-
lease
|
|
352
|
-
}
|
|
353
|
-
};
|
|
354
|
-
}, void 0, options.assertCurrent);
|
|
355
|
-
options.assertCurrent?.();
|
|
356
|
-
if (!acquired) throw new Error(`Codex binding generation was retired: ${key}`);
|
|
357
|
-
const owner = {
|
|
358
|
-
token,
|
|
359
|
-
phase: "held",
|
|
360
|
-
assertCurrent: options.assertCurrent
|
|
361
|
-
};
|
|
362
|
-
const nested = new Map(owned);
|
|
363
|
-
nested.set(key, owner);
|
|
364
|
-
const heartbeat = setInterval(() => renewLease(key, owner), BINDING_LEASE_RENEW_INTERVAL_MS);
|
|
365
|
-
heartbeat.unref();
|
|
366
|
-
try {
|
|
367
|
-
const result = await leaseContext.run(nested, run);
|
|
368
|
-
options.assertCurrent?.();
|
|
369
|
-
if (owner.failure) throw owner.failure;
|
|
370
|
-
return result;
|
|
371
|
-
} finally {
|
|
372
|
-
clearInterval(heartbeat);
|
|
373
|
-
owner.phase = "closed";
|
|
374
|
-
options.assertCurrent?.();
|
|
375
|
-
try {
|
|
376
|
-
const current = readStoredCodexAppServerBinding(state.lookup(key));
|
|
377
|
-
if (current?.lease?.token === token) {
|
|
378
|
-
const ttlMs = current.state === "active" || current.retired === true && !key.startsWith("session:") ? void 0 : current.retired === true ? PHYSICAL_SESSION_RETIRE_TTL_MS : 1;
|
|
379
|
-
options.assertCurrent?.();
|
|
380
|
-
update(key, (raw) => {
|
|
381
|
-
const stored = readStoredCodexAppServerBinding(raw);
|
|
382
|
-
if (stored?.lease?.token !== token) return;
|
|
383
|
-
const { lease: _lease, ...released } = stored;
|
|
384
|
-
return released;
|
|
385
|
-
}, ttlMs === void 0 ? void 0 : { ttlMs });
|
|
386
|
-
}
|
|
387
|
-
} catch (error) {
|
|
388
|
-
options.assertCurrent?.();
|
|
389
|
-
embeddedAgentLog.warn("failed to release codex app-server binding lease", {
|
|
390
|
-
key,
|
|
391
|
-
error
|
|
392
|
-
});
|
|
393
|
-
}
|
|
394
|
-
}
|
|
395
|
-
};
|
|
396
|
-
const transitionSessionGeneration = async (identity, mode) => {
|
|
397
|
-
return await runBindingMutation(async () => {
|
|
398
|
-
const key = bindingStoreKey(identity);
|
|
399
|
-
const ttlMs = mode === "reset" ? leaseContext.getStore()?.has(key) ? void 0 : 1 : identity.sessionKey?.trim() ? void 0 : PHYSICAL_SESSION_RETIRE_TTL_MS;
|
|
400
|
-
return await transactKey(key, (current, leaseToken) => {
|
|
401
|
-
if (!current) return { result: "absent" };
|
|
402
|
-
if (!ownsStoredSessionGeneration(identity, current)) return { result: "conflict" };
|
|
403
|
-
if (current.state === "cleared" && current.retired === true) return { result: mode === "retire" ? "applied" : "conflict" };
|
|
404
|
-
return {
|
|
405
|
-
result: "applied",
|
|
406
|
-
next: {
|
|
407
|
-
version: 1,
|
|
408
|
-
state: "cleared",
|
|
409
|
-
...mode === "retire" ? { retired: true } : {},
|
|
410
|
-
...storedSessionGeneration(identity, current),
|
|
411
|
-
...current.lease && current.lease.token === leaseToken ? { lease: current.lease } : {}
|
|
412
|
-
}
|
|
413
|
-
};
|
|
414
|
-
}, ttlMs);
|
|
415
|
-
});
|
|
416
|
-
};
|
|
417
|
-
return {
|
|
418
|
-
read: (identity) => readCurrentCodexAppServerBinding(state, identity),
|
|
419
|
-
...state.lookupMany ? { readMany: (identities) => readCurrentCodexAppServerBindings(state, identities) } : {},
|
|
420
|
-
readNativeSubagentSubmissions: (identity, owner) => readCurrentCodexNativeSubagentSubmissions(state, identity, owner),
|
|
421
|
-
async hasOtherThreadOwner(threadId, currentIdentity) {
|
|
422
|
-
const currentKey = currentIdentity ? bindingStoreKey(currentIdentity) : void 0;
|
|
423
|
-
return state.entries().some(({ key, value }) => {
|
|
424
|
-
const stored = readStoredCodexAppServerBinding(value);
|
|
425
|
-
if (!stored) throw new Error(`Invalid Codex app-server binding row: ${key}`);
|
|
426
|
-
const isCurrentOwner = currentIdentity !== void 0 && key === currentKey && (currentIdentity.kind === "conversation" || stored.sessionId === currentIdentity.sessionId.trim());
|
|
427
|
-
if (stored.state !== "active" || stored.binding.threadId !== threadId || isCurrentOwner) return false;
|
|
428
|
-
return true;
|
|
429
|
-
});
|
|
430
|
-
},
|
|
431
|
-
async prepareSessionGenerationReclaim(identity) {
|
|
432
|
-
const key = bindingStoreKey(identity);
|
|
433
|
-
const raw = state.lookup(key);
|
|
434
|
-
const current = readStoredCodexAppServerBinding(raw);
|
|
435
|
-
if (raw !== void 0 && !current) throw new Error(`Invalid Codex app-server binding row: ${key}`);
|
|
436
|
-
if (!current) return {
|
|
437
|
-
kind: "resolved",
|
|
438
|
-
result: true
|
|
439
|
-
};
|
|
440
|
-
const currentSessionId = current.sessionId;
|
|
441
|
-
if (!currentSessionId) return {
|
|
442
|
-
kind: "resolved",
|
|
443
|
-
result: current.state !== "cleared" || current.retired !== true
|
|
444
|
-
};
|
|
445
|
-
if (currentSessionId === identity.sessionId) return current.state === "cleared" && current.retired === true ? {
|
|
446
|
-
kind: "verify",
|
|
447
|
-
expectedPreviousSessionId: currentSessionId
|
|
448
|
-
} : {
|
|
449
|
-
kind: "resolved",
|
|
450
|
-
result: true
|
|
451
|
-
};
|
|
452
|
-
return {
|
|
453
|
-
kind: "verify",
|
|
454
|
-
expectedPreviousSessionId: currentSessionId
|
|
455
|
-
};
|
|
456
|
-
},
|
|
457
|
-
async mutate(identity, mutation, assertCurrent) {
|
|
458
|
-
return await runBindingMutation(async () => {
|
|
459
|
-
const key = bindingStoreKey(identity);
|
|
460
|
-
const retainLegacyClear = mutation.kind === "clear" && key.startsWith("conversation:legacy-");
|
|
461
|
-
return await transactKey(key, (current, leaseToken) => {
|
|
462
|
-
if (mutation.kind === "record-native-subagent-submission" || mutation.kind === "consume-native-subagent-submission") {
|
|
463
|
-
if (!assertCurrent) throw new Error("Codex native subagent submission mutation requires current authority.");
|
|
464
|
-
assertCurrent();
|
|
465
|
-
if (current?.state !== "active" || !ownsStoredSessionGeneration(identity, current) || identity.kind === "session" && mutation.owner.sessionId !== identity.sessionId || !matchesCodexNativeSubagentSubmissionBinding(current.binding, mutation.owner)) return { result: false };
|
|
466
|
-
const changed = mutateCodexNativeSubagentSubmissions({
|
|
467
|
-
current: current.nativeSubagentSubmissions,
|
|
468
|
-
owner: mutation.owner,
|
|
469
|
-
receipt: mutation.receipt,
|
|
470
|
-
consume: mutation.kind === "consume-native-subagent-submission"
|
|
471
|
-
});
|
|
472
|
-
if (!changed.applied) return { result: false };
|
|
473
|
-
const { nativeSubagentSubmissions: _previous, ...bindingOwner } = current;
|
|
474
|
-
return {
|
|
475
|
-
result: true,
|
|
476
|
-
next: {
|
|
477
|
-
...bindingOwner,
|
|
478
|
-
...changed.next ? { nativeSubagentSubmissions: changed.next } : {}
|
|
479
|
-
}
|
|
480
|
-
};
|
|
481
|
-
}
|
|
482
|
-
const ownsGeneration = ownsStoredSessionGeneration(identity, current);
|
|
483
|
-
const ownedLease = current?.lease && current.lease.token === leaseToken ? { lease: current.lease } : {};
|
|
484
|
-
if (mutation.kind === "reclaim-generation") {
|
|
485
|
-
if (identity.kind !== "session" || !identity.sessionKey?.trim()) return { result: false };
|
|
486
|
-
if (!current) return { result: true };
|
|
487
|
-
if (ownsGeneration) {
|
|
488
|
-
if (current.state === "cleared" && current.retired === true && current.sessionId === mutation.expectedPreviousSessionId) return {
|
|
489
|
-
result: true,
|
|
490
|
-
next: {
|
|
491
|
-
version: 1,
|
|
492
|
-
state: "cleared",
|
|
493
|
-
sessionId: identity.sessionId,
|
|
494
|
-
...ownedLease
|
|
495
|
-
}
|
|
496
|
-
};
|
|
497
|
-
return { result: current.state !== "cleared" || current.retired !== true };
|
|
498
|
-
}
|
|
499
|
-
if (current.sessionId !== mutation.expectedPreviousSessionId) return { result: false };
|
|
500
|
-
if (current.state === "active" && current.binding.connectionScope === "supervision") return { result: false };
|
|
501
|
-
return {
|
|
502
|
-
result: true,
|
|
503
|
-
next: {
|
|
504
|
-
version: 1,
|
|
505
|
-
state: "cleared",
|
|
506
|
-
sessionId: identity.sessionId,
|
|
507
|
-
...ownedLease
|
|
508
|
-
}
|
|
509
|
-
};
|
|
510
|
-
}
|
|
511
|
-
const storedActive = current?.state === "active" ? current : void 0;
|
|
512
|
-
const active = ownsGeneration ? storedActive : void 0;
|
|
513
|
-
const retiredGeneration = current?.state === "cleared" && current.retired === true && ownsGeneration;
|
|
514
|
-
const preservesSupervisionOwner = mutation.kind === "set" && active?.binding.connectionScope === "supervision" && isSameSupervisionOwner(active.binding, mutation.binding);
|
|
515
|
-
const replacesExpectedOrdinaryOwner = mutation.kind === "replace-thread" && active?.binding.threadId === mutation.expectedThreadId && active.binding.connectionScope !== "supervision" && mutation.binding.connectionScope !== "supervision" && mutation.binding.threadId !== mutation.expectedThreadId;
|
|
516
|
-
if (mutation.kind === "set" && (mutation.if?.kind === "absent" && storedActive || current !== void 0 && !ownsGeneration || retiredGeneration || active?.binding.connectionScope === "supervision" && !preservesSupervisionOwner) || mutation.kind === "patch" && active?.binding.threadId !== mutation.threadId || mutation.kind === "replace-thread" && !replacesExpectedOrdinaryOwner || (mutation.kind === "patch-pending-supervision-branch" || mutation.kind === "commit-pending-supervision-branch") && !matchesPendingSupervisionBranch(active?.binding, mutation.expected) || mutation.kind === "clear" && (!ownsGeneration || mutation.threadId !== void 0 && active?.binding.threadId !== mutation.threadId || active?.binding.connectionScope === "supervision")) return { result: false };
|
|
517
|
-
if (mutation.kind === "clear" && retiredGeneration) return { result: true };
|
|
518
|
-
if (mutation.kind === "clear") return {
|
|
519
|
-
result: true,
|
|
520
|
-
next: {
|
|
521
|
-
version: 1,
|
|
522
|
-
state: "cleared",
|
|
523
|
-
...storedSessionGeneration(identity, current),
|
|
524
|
-
...ownedLease
|
|
525
|
-
}
|
|
526
|
-
};
|
|
527
|
-
let binding;
|
|
528
|
-
if (mutation.kind === "set" || mutation.kind === "replace-thread") binding = validateBindingForWrite(mutation.binding);
|
|
529
|
-
else if (mutation.kind === "patch-pending-supervision-branch") binding = validateBindingForWrite({
|
|
530
|
-
...active.binding,
|
|
531
|
-
pendingSupervisionBranch: mutation.pending
|
|
532
|
-
});
|
|
533
|
-
else if (mutation.kind === "commit-pending-supervision-branch") binding = validateBindingForWrite({
|
|
534
|
-
...active.binding,
|
|
535
|
-
...mutation.patch,
|
|
536
|
-
threadId: mutation.threadId,
|
|
537
|
-
pendingSupervisionBranch: void 0
|
|
538
|
-
});
|
|
539
|
-
else binding = validateBindingForWrite({
|
|
540
|
-
...active.binding,
|
|
541
|
-
...mutation.patch,
|
|
542
|
-
threadId: mutation.threadId
|
|
543
|
-
});
|
|
544
|
-
const nativeSubagentSubmissions = active ? preserveCodexNativeSubagentSubmissions(active.binding, binding, active.nativeSubagentSubmissions) : void 0;
|
|
545
|
-
return {
|
|
546
|
-
result: true,
|
|
547
|
-
next: {
|
|
548
|
-
version: 1,
|
|
549
|
-
state: "active",
|
|
550
|
-
binding,
|
|
551
|
-
...nativeSubagentSubmissions !== void 0 ? { nativeSubagentSubmissions } : {},
|
|
552
|
-
...storedSessionGeneration(identity, current),
|
|
553
|
-
...ownedLease
|
|
554
|
-
}
|
|
555
|
-
};
|
|
556
|
-
}, mutation.kind === "clear" && !retainLegacyClear && !leaseContext.getStore()?.has(key) ? 1 : void 0, assertCurrent);
|
|
557
|
-
});
|
|
558
|
-
},
|
|
559
|
-
async adoptSessionGeneration(identity, expectedPreviousSessionId, assertCurrent) {
|
|
560
|
-
return await runBindingMutation(async () => {
|
|
561
|
-
const key = bindingStoreKey(identity);
|
|
562
|
-
const expectedSessionId = expectedPreviousSessionId.trim();
|
|
563
|
-
const targetSessionId = identity.sessionId.trim();
|
|
564
|
-
if (!expectedSessionId) throw new Error("Codex session generation adoption requires the previous session id");
|
|
565
|
-
return await transactKey(key, (current) => {
|
|
566
|
-
if (current?.state !== "active") return { result: "absent" };
|
|
567
|
-
if (current.sessionId === targetSessionId) return { result: "current" };
|
|
568
|
-
if (current.sessionId !== expectedSessionId) return { result: "conflict" };
|
|
569
|
-
const { nativeSubagentSubmissions, ...bindingOwner } = current;
|
|
570
|
-
const adoptedSubmissions = adoptCodexNativeSubagentSubmissions(nativeSubagentSubmissions);
|
|
571
|
-
return {
|
|
572
|
-
result: "adopted",
|
|
573
|
-
next: {
|
|
574
|
-
...bindingOwner,
|
|
575
|
-
sessionId: targetSessionId,
|
|
576
|
-
...adoptedSubmissions !== void 0 ? { nativeSubagentSubmissions: adoptedSubmissions } : {}
|
|
577
|
-
}
|
|
578
|
-
};
|
|
579
|
-
}, void 0, assertCurrent);
|
|
580
|
-
});
|
|
581
|
-
},
|
|
582
|
-
resetSessionGeneration: (identity) => transitionSessionGeneration(identity, "reset"),
|
|
583
|
-
retireSessionGeneration: (identity) => transitionSessionGeneration(identity, "retire"),
|
|
584
|
-
async withThreadArchiveFence(run) {
|
|
585
|
-
pendingArchives += 1;
|
|
586
|
-
const operation = archiveTail.then(async () => {
|
|
587
|
-
await waitForBindingMutations();
|
|
588
|
-
return await archiveContext.run(true, run);
|
|
589
|
-
});
|
|
590
|
-
archiveTail = operation.then(() => void 0, () => void 0);
|
|
591
|
-
try {
|
|
592
|
-
return await operation;
|
|
593
|
-
} finally {
|
|
594
|
-
pendingArchives -= 1;
|
|
595
|
-
}
|
|
596
|
-
},
|
|
597
|
-
async withSessionDeletion(identity, assertCurrent, run) {
|
|
598
|
-
const key = bindingStoreKey(identity);
|
|
599
|
-
const deleteIf = state.deleteIf?.bind(state);
|
|
600
|
-
if (!deleteIf) throw new Error("Codex session deletion requires conditional plugin-state deletion");
|
|
601
|
-
return await runBindingMutation(async () => {
|
|
602
|
-
assertCurrent();
|
|
603
|
-
if (state.lookup(key) === void 0) {
|
|
604
|
-
let active = true;
|
|
605
|
-
try {
|
|
606
|
-
return await run(void 0, {
|
|
607
|
-
commit() {
|
|
608
|
-
assertCurrent();
|
|
609
|
-
if (!active || state.lookup(key) !== void 0) throw new Error("Codex binding changed before session deletion");
|
|
610
|
-
},
|
|
611
|
-
rollback() {}
|
|
612
|
-
});
|
|
613
|
-
} finally {
|
|
614
|
-
active = false;
|
|
615
|
-
}
|
|
616
|
-
}
|
|
617
|
-
return await withBindingLease(identity, async () => {
|
|
618
|
-
const owner = leaseContext.getStore().get(key);
|
|
619
|
-
const expected = state.lookup(key);
|
|
620
|
-
const stored = readStoredCodexAppServerBinding(expected);
|
|
621
|
-
if (!stored || !ownsStoredSessionGeneration(identity, stored)) throw new Error("Codex binding generation changed before session deletion");
|
|
622
|
-
const { lease: _lease, ...expectedValue } = stored;
|
|
623
|
-
let deleted;
|
|
624
|
-
let active = true;
|
|
625
|
-
const assertActive = () => {
|
|
626
|
-
assertCurrent();
|
|
627
|
-
if (!active || owner.phase === "closed" || owner.failure) throw owner.failure ?? bindingLeaseLostError(key);
|
|
628
|
-
};
|
|
629
|
-
try {
|
|
630
|
-
return await run(stored.state === "active" ? stored.binding : void 0, {
|
|
631
|
-
commit() {
|
|
632
|
-
assertActive();
|
|
633
|
-
if (deleted) return;
|
|
634
|
-
const current = state.lookup(key);
|
|
635
|
-
const { lease, ...value } = readStoredCodexAppServerBinding(current) ?? {};
|
|
636
|
-
if (!current || lease?.token !== owner.token || lease.expiresAt <= Date.now() || !isDeepStrictEqual(value, expectedValue) || !deleteIf(key, (raw) => isDeepStrictEqual(raw, current))) throw new Error("Codex binding changed before session deletion");
|
|
637
|
-
deleted = current;
|
|
638
|
-
owner.phase = "deleted";
|
|
639
|
-
},
|
|
640
|
-
rollback() {
|
|
641
|
-
assertActive();
|
|
642
|
-
if (!deleted) return;
|
|
643
|
-
const restored = {
|
|
644
|
-
...deleted,
|
|
645
|
-
lease: {
|
|
646
|
-
token: owner.token,
|
|
647
|
-
expiresAt: Date.now() + BINDING_LEASE_STALE_MS
|
|
648
|
-
}
|
|
649
|
-
};
|
|
650
|
-
if (!state.registerIfAbsent(key, restored)) throw new Error("Codex binding changed before session deletion rollback");
|
|
651
|
-
deleted = void 0;
|
|
652
|
-
owner.phase = "held";
|
|
653
|
-
}
|
|
654
|
-
});
|
|
655
|
-
} finally {
|
|
656
|
-
active = false;
|
|
657
|
-
}
|
|
658
|
-
}, {
|
|
659
|
-
allowRetired: true,
|
|
660
|
-
assertCurrent
|
|
661
|
-
});
|
|
662
|
-
});
|
|
663
|
-
},
|
|
664
|
-
withLease: withBindingLease
|
|
665
|
-
};
|
|
666
|
-
}
|
|
667
|
-
function matchesPendingSupervisionBranch(binding, expected) {
|
|
668
|
-
const pending = binding?.pendingSupervisionBranch;
|
|
669
|
-
if (!pending || binding?.threadId !== expected.sourceThreadId) return false;
|
|
670
|
-
if (pending.sourceThreadId !== expected.sourceThreadId || pending.connectionFingerprint !== expected.connectionFingerprint || pending.lastTurnId !== expected.lastTurnId) return false;
|
|
671
|
-
const currentCleanup = pending.cleanupThreadIds ?? [];
|
|
672
|
-
const expectedCleanup = expected.cleanupThreadIds ?? [];
|
|
673
|
-
return currentCleanup.length === expectedCleanup.length && currentCleanup.every((threadId, index) => threadId === expectedCleanup[index]);
|
|
674
|
-
}
|
|
675
|
-
function isSameSupervisionOwner(current, replacement) {
|
|
676
|
-
return replacement.connectionScope === "supervision" && replacement.threadId === current.threadId && replacement.supervisionSourceThreadId === current.supervisionSourceThreadId;
|
|
677
|
-
}
|
|
678
|
-
function storedSessionGeneration(identity, current) {
|
|
679
|
-
if (identity.kind === "session") return { sessionId: identity.sessionId };
|
|
680
|
-
return current?.sessionId ? { sessionId: current.sessionId } : {};
|
|
681
|
-
}
|
|
682
|
-
function preservedSessionGeneration(identity, current) {
|
|
683
|
-
if (current?.sessionId) return { sessionId: current.sessionId };
|
|
684
|
-
return storedSessionGeneration(identity, current);
|
|
685
|
-
}
|
|
686
|
-
function sleep(ms) {
|
|
687
|
-
return new Promise((resolve) => {
|
|
688
|
-
setTimeout(resolve, ms);
|
|
689
|
-
});
|
|
690
|
-
}
|
|
691
|
-
//#endregion
|
|
692
|
-
export { resolveCodexRunSessionBindingAuthority as a, reclaimCurrentCodexSessionGeneration as i, createCodexSessionGenerationSupersededError as n, resolveCodexSessionBinding as o, hashCodexAppServerBindingFingerprint as r, session_binding_exports as s, CODEX_APP_SERVER_BINDING_GUARDED_REQUEST_TIMEOUT_MS as t };
|