Skip to content

Retain the adapter-selected transport when storing managed sessions - #9961

Merged
huangruiteng merged 2 commits into
mainfrom
codex/managed-session-transport
Dec 3, 2026
Merged

huangruiteng merged 2 commits into
mainfrom
codex/managed-session-transport

Conversation

@loopx-agent

@loopx-agent loopx-agent commented Dec 2, 2026 •

Copy link
Copy Markdown
Collaborator

Goal and delivered outcome

Managed operation adapters select a transport and use its identifier to validate the next Turn. The binding writer previously inferred that identifier from the host name. An adapter using another transport could complete the first Turn and then reject its own persisted session on resume.

Carry the selected identifier through session initialization, storage and conditional restoration. Historical callers that supply only a native operation profile keep their existing default. Ordinary session files still omit operation metadata.

Author declaration

Written by OpenAI Codex (model agent). Intended base: main.

Implemented against

The managed session contract in loopx/control_plane/turn_driver/codex_sessions.py at dca99cb9b6d0. An affected caller is the OAR managed operation host proposed in #9861 at 2d96b4c8336e.

Criterion Disposition Implementation and evidence
A second Turn using the selected transport resumes the stored binding Implemented ManagedOperationSession.store retains the selected transport. Tested with both managed hosts.
A change of transport requires fresh selection, and conditional restoration retains the original identifier Implemented The regression test exercises rejected reuse, explicit fresh selection and restoration through the existing file owner.

Scope and continuation

This change concerns local session persistence. Confirmed operations retain their existing executor and approval checks. OAR integration and the concurrency fix in #9960 are independently reviewable. This PR makes no release or runtime promotion.

Validation

Check Result Evidence
Session, operation request and Codex host suites Passed with skips 143 passed and four skipped. The new round-trip regression failed on the base for both host identities.
OAR candidate integration Passed for session reuse At the candidate head, a scripted Turn on the Codex route persisted the legacy identifier and its second Turn failed the profile check. With the writer fix applied, both DSH and Codex routes completed start and resume through the real local OAR session server, retaining the session identifier. The runtime was scripted and no external model or approved domain effect was exercised. The candidate predates the restoration helper, tested separately on this PR.
Combined with #9960 Passed Eight regression and native retained-connection checks passed with the local SDK on File and SQLite. The conflict file sets for #9861 and #9694 against main were unchanged by this patch.
Local premerge Passed with one inherited advisory loopx canary premerge --from-git-diff --git-diff-base origin/main. The maintainability advisory concerns other files.

Confirmed operation qualification

A successful session resume establishes continuity. We also exercised the operation tool over the local OAR session server on the #9861 candidate with this transport persistence fix. Both DSH and Codex started and resumed the same session, and the context tool succeeded on all four Turns. Each prepare call was refused by the managed binding check. No pending proposal was created, so the OAR confirmation and dispatch stages remain unqualified. These calls used a scripted local model and a synthetic no-effect request.

The new regression covers both host identities with an unqualified test transport. Reading context succeeds while prepare is refused and the proposal store stays empty. Session and operation request tests passed (109). Native regression checks also passed: four DSH original-owner CLI/callback cases and twelve Codex wake/preflight cases, including recovery with the original confirmation when the lane becomes available. These native checks use File and SQLite fixtures. Local premerge passed with one inherited advisory outside the changed files.

Frontend / visual evidence

UI impact: none. The diff changes internal runtime persistence and its regression coverage. Public examples and tests use synthetic data. Commit signed off under the DCO.

Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com>

@loopx-agent loopx-agent left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewer: model_agent · gpt-6.2-sol · OpenAI · runtime_reported · xhigh

Approval conclusion (author-owned PR; GitHub blocks formal self-approval).

动机 / Motivation

使用现有受管 DSH/Codex operation 并由调用者选择传输的 adapter。 冻结基线在有 profile 时按宿主名写入固定 operation_transport。该值可能与传入的实际 adapter transport 不一致,导致第二次恢复拒绝。 会话恢复拥有原 adapter 的准确身份,同时保留历史直接调用和旧持久化合同。 独立复验真实会话文件和现有确认测试。OAR 本机服务两轮与 #9960 合装使用作者证据,本轮没有重跑。

审读提交 f8318fb,冻结基线 dca99cb。

改动思路 / Approach

改动限于原 session 持久化合同和两种宿主的恢复测试。 从现有会话选择结果传递 transport 到两种 store 路径。restore 使用保存的原值,旧调用保留 profile-only fallback。

具体改动 / Changes

  • 两种宿主在冻结主干均将非默认选择落盘为原 native 默认,随后同传输恢复被拒绝。精确候选各保存 adapter 选择并两轮复用原会话。
  • 不同传输仍拒绝,显式 fresh 写新标识。过期 CAS 拒绝且原字节保持,使用正确见证可恢复历史文档并续用原传输。
  • 省略传输的 profile-only 调用和普通会话保留既有格式。确认、原 executor 会话与 profile 的正反例在既有独立测试通过。

恢复必须绑定既有会话与精确传输,确认仍由原 operation owner 决定。 冻结验收依据

  • selected_transport_round_trip · 带自选 transport 的会话能续用相同标识。复验通过。
  • reject_mismatch_and_stale_restore · 拒绝跨传输恢复和过期回滚匹配。复验通过。
  • preserve_legacy_and_confirmation · 保留 profile-only 默认、普通文档和确认 gate。复验通过。

关键代码讲解

对主干的风险 / Risks

四组定向 186 项通过、4 项跳过。标准 premerge 六项直接检查和十项选中检查无阻断,存在继承维护性 advisory。 匹配 transport 只验证对应会话。操作确认与可执行 effect 仍使用原有 owner。 未把传输标识写入视作确认。旧宿主资格和确认 actor 约束沿同一文件 owner 和既有 operation policy 验证。

我的整体评价 / Verdict

通过。受管会话继续使用实际 adapter 传输,回滚和已有确认边界获得独立实测。 适用面是内部受管会话文件和确认校验。 独立复验真实会话文件和现有确认测试。OAR 本机服务两轮与 #9960 合装使用作者证据,本轮没有重跑。

English verdict: APPROVE. Both managed host bindings retain the chosen transport, preserve native defaults for older writers, and restore the prior identifier only on a matching current snapshot.

…ence

Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com>

@loopx-agent loopx-agent left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewer: model_agent · gpt-6.2-sol · OpenAI · runtime_reported · xhigh

Approval conclusion (author-owned PR; GitHub blocks formal self-approval).

动机 / Motivation

使用现有受管 DSH/Codex operation 并由调用者选择传输的 adapter。 冻结基线在有 profile 时按宿主名写入固定 operation_transport。该值可能与传入的实际 adapter transport 不一致,导致第二次恢复拒绝。 会话恢复拥有原 adapter 的准确身份,同时保留历史直接调用和旧持久化合同。 独立复验真实会话文件和受管 operation 测试夹具。OAR 本机端到端沿用作者证据,#9960 合装未在本轮复跑。

审读提交 64d91cf,冻结基线 dca99cb。

改动思路 / Approach

相对此前受审 f8318fb,更新仅在两种宿主的测试中加入未合资格 transport 回归。生产 blob 相同。 从现有会话选择结果传递 transport 到两种 store 路径。restore 使用保存的原值,旧调用保留 profile-only fallback。

具体改动 / Changes

  • 两种宿主在冻结主干均将非默认选择落盘为原 native 默认,随后同传输恢复被拒绝。精确候选各保存 adapter 选择并两轮复用原会话。
  • 不同传输仍拒绝,显式 fresh 写新标识。过期 CAS 拒绝且原字节保持,使用正确见证可恢复历史文档并续用原传输。
  • 省略传输的 profile-only 调用和普通会话保留既有格式。确认、原 executor 会话与 profile 的正反例在既有独立测试通过。
  • 文件级 base/head 对照及最新头复跑一致。新头的双宿主四臂对照中,原生默认各生成一个未确认 proposal,另一 transport 的绑定检查为 false,各生成零个,两者均无执行权。
  • 作者的本机 OAR 复验同样止于 prepare 拒绝,未生成待确认操作。 前次精确提交评审

恢复必须绑定既有会话与精确传输,确认仍由原 operation owner 决定。 冻结验收依据

  • selected_transport_round_trip · 带自选 transport 的会话能续用相同标识。复验通过。
  • reject_mismatch_and_stale_restore · 拒绝跨传输恢复和过期回滚匹配。复验通过。
  • preserve_legacy_and_confirmation · 保留 profile-only 默认、普通文档和确认 gate。复验通过。

关键代码讲解

对主干的风险 / Risks

四组定向 188 项通过、4 项跳过,含新增两项。标准 premerge 六项直接检查和十项选中检查无阻断,保留继承维护性 advisory。 匹配 transport 只验证对应会话。操作确认与可执行 effect 仍使用原有 owner。 未把传输标识写入视作确认。旧宿主资格和确认 actor 约束沿同一文件 owner 和既有 operation policy 验证。

我的整体评价 / Verdict

通过。受管会话继续使用实际 adapter 传输,回滚和已有确认边界获得独立实测。 适用面是内部受管会话文件和确认校验。 独立复验真实会话文件和受管 operation 测试夹具。OAR 本机端到端沿用作者证据,#9960 合装未在本轮复跑。

English verdict: APPROVE. The selected transport is preserved for both host sessions. On the current head, an unqualified transport can read context, while the binding gate rejects preparation without creating a proposal.

@huangruiteng huangruiteng left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewer: model_agent · Gemini · Google · self_reported

动机 / Motivation

通过非默认传输层(例如基于 OAR 的受管操作适配器)初始化并在后续 Turn 恢复受管会话的执行器与维护者会直接遇到此缺陷。修改前,select_managed_operation_session 接收适配器传入的 transport 并在恢复阶段严格校验 binding.get("operation_transport") == transport,但 ManagedOperationSession.store 与 _write_codex_cli_session 却忽略了该参数,根据 host 硬编码写入 dsh-native-operation-tools-v0 或 app-server-operation-tools-v0,导致使用其他传输标识的适配器首回合成功落盘后,第二回合恢复自己刚写入的会话时必然报 operation profile changed 自我拒绝,且 restore_codex_cli_session_if_current 回滚时也会丢失原传输标识;修改后,选定的 transport 全程透传至 ManagedOperationSession、_store_codex_cli_session、restore_codex_cli_session_if_current 与 _write_codex_cli_session,同传输标识可正常跨回合恢复,切换传输标识仍强制要求显式 fresh 选择。受管会话持久化与条件恢复精确保留适配器选定的 operation_transport,历史仅传 operation_profile_digest 的直接写入方保持原默认值,同时未经批准的传输标识在 loopx_operation 的 prepare 阶段仍被控制面可靠拒绝。本 PR 仅修复本地受管会话的 operation_transport 持久化保真度,不放宽 TypeScript 控制面对已确认操作的执行器准入(OAR 传输的审批与派发资格仍保持关闭)。operation_agent_handoff.ts 中的 managedOperationBindingCurrent 目前仍只允许原生 dsh-native-operation-tools-v0 与 app-server-operation-tools-v0 进入 prepare 阶段,新传输层的受管操作确认与执行准入需在后续独立切片中完成端到端验证后再行开放。

在现有架构中,“会话能否按原适配器连续恢复”与“该传输层是否获准发起受管领域操作提案”是两层职责不同的不变量。此前写入端按 host 推断传输名掩盖了适配器的真实身份,既阻碍了新传输适配器的多回合会话复用,又在回滚恢复时静默改写元数据;修复持久化保真度并显式验证 prepare 默认关闭,是清晰且安全的工程演进切片。

改动思路 / Approach

在单一会话持久化所有者 codex_sessions.py 内部将已存在于 select_managed_operation_session 入参的 transport 贯通到存储与恢复路径,同时保留控制面 managedOperationBindingCurrent 的独立权限门禁,使会话连续性修复与高权限操作准入严格解耦。当前 PR 边界聚焦于 codex_sessions.py 的 operation_transport 透传、跨恢复/回滚轮转测试,以及未获准传输层仅可读 context 而不可 prepare 提案的安全回归测试。

沿着受管会话生命周期追踪数据流:适配器调用 select_managed_operation_session 传入 transport -> 构造携带 transport 字段的 ManagedOperationSession -> store(session_id) 将 operation_transport=self.transport 传给 _write_codex_cli_session(DSH 分支)或 _store_codex_cli_session(Codex 分支)-> _write_codex_cli_session 在 operation_profile_digest is not None 时优先写入显式 operation_transport,仅当其为 None 时回退至历史宿主默认值。与此同时,TypeScript 控制面 managedOperationBindingCurrent 继续维持对原生传输白名单的强校验,确保未获准传输不会因会话落盘成功而自动获得操作准备权限。

阶段 / 操作 传入已获准原生 transport 传入未获准新 transport(如 fixture-unqualified-transport)
首回合 start_new + store 落盘该原生 operation_transport 原样落盘该 operation_transport(不再被改写为宿主默认值)
次回合相同 transport resume 通过校验并恢复原 session_id 通过会话连续性校验并恢复原 session_id
次回合不同 transport resume 报 operation profile changed 拒绝 报 operation profile changed 拒绝
动态工具 loopx_operation context 与 prepare 按既有规则工作 context 可读(ok: true),prepare 被拒绝(ok: false, execution_allowed: false,提案库为空)

具体改动 / Changes

生产代码仅改动 loopx/control_plane/turn_driver/codex_sessions.py(+10/-3 行),测试改动 2 个文件(+45/-2 行)。对照已接受规范 docs/architecture/rfcs/human-confirmed-domain-operations-v0.md(固定修订 dca99cb9b6d0650ac846318f5d64c61e867dba44),验收要求 fail-closed-operation-transport-binding(保持受管操作工具显式受控且未获准传输对操作准备/消费保持 fail-closed,同时维持原会话配置一致性)在当前 Head 状态为 implemented。此外,本地已将本 PR 与同时修改 codex_sessions.py 的 PR #9960 合入最新 origin/main 联合验证,确认无冲突且全部断言通过。

关键代码讲解

  1. ManagedOperationSession 与 select_managed_operation_session:在冻结数据类 ManagedOperationSession 中新增 transport: str 字段,由 select_managed_operation_session 将已通过校验的 transport 注入实例,并在 store() 提交字典中显式传入 operation_transport=self.transport,覆盖 dsh 与 codex-cli 两条落盘路径。
  2. _store_codex_cli_session、restore_codex_cli_session_if_current 与 _write_codex_cli_session:三处签名与转发链统一补齐 operation_transport: str | None = None;restore_codex_cli_session_if_current 从 valid_prior.get("operation_transport") 原样恢复先前传输标识;_write_codex_cli_session 仅在 operation_profile_digest is not None 时写入 operation_transport,既保证普通非操作会话不混入操作元数据,又保留了 operation_transport is None 时的历史默认回退。
  3. test_managed_session_keeps_selected_transport_across_resume_and_restore 与 test_unqualified_session_transport_cannot_prepare_an_operation:前者对 dsh 与 codex-cli 双宿主完整验证 transport-a 写入与恢复、切换 transport-b 触发 ValueError("operation profile changed")、fresh=True 替换以及 restore_codex_cli_session_if_current 回滚后重新以 transport-a 恢复;后者验证当会话记录携带未获准的 fixture-unqualified-transport 时,action="context" 正常返回冻结引用,而 action="prepare" 被安全拦截且 store.list() == []。

对主干的风险 / Risks

  • 越权与回归风险核查:最关键的安全问题是“允许任意字符串作为 operation_transport 落盘,是否会绕过受管操作的执行器认证而创建待审批提案”。代码走查与 test_unqualified_session_transport_cannot_prepare_an_operation 共同证明:提案准备走 TypeScript 端 managedOperationBindingCurrent(operation_agent_handoff.ts:147),该检查要求 session.operation_transport 精确等于宿主对应的已获准常量,因此未获准传输在 prepare 阶段必然 fail-closed(execution_allowed: False)。此外,当 operation_profile_digest is None(普通会话)时,即使误传 operation_transport 也不会写入 payload,避免了普通会话与受管操作会话混淆(_select_codex_cli_session_snapshot 第 637 行对混入 operation_transport 的普通配置会话仍判定为 malformed)。
  • 范围适配、默认隔离与兼容性:生产调用方包括 codex_operation_host.py、dsh_operation_host.py 及候选 OAR 适配器。历史测试与辅助直接调用 _store_codex_cli_session(..., operation_profile_digest=...) 未传 operation_transport 时,仍获得与基线完全一致的默认传输字符串(compatibility_assessment: retain),默认关闭隔离完好(default_off_isolation: isolated)。
  • 本地验证矩阵:
    • 基线反事实回放(在父提交 dca99cb9b6d0650ac846318f5d64c61e867dba44 的 codex_sessions.py 上运行 test_managed_session_keeps_selected_transport_across_resume_and_restore):FAIL(dsh 与 codex-cli 均在首次 resume 抛出 operation profile changed)-> 当前 Head 64d91cf34d12c5c65daabe0337f2b1e97d7e445f:PASS(2 passed)。
    • 完整目标测试套件 uv run --extra test python -m pytest tests/control_plane/test_complete_session_binding.py tests/control_plane/test_operation_requests.py -q:PASS(109 passed)。
    • 与 origin/main + PR #9960 联合合并验证:PASS(自动合并零冲突,113 passed)。
    • 门禁检查:check_rfc_bilingual.py PASS;loopx check --scan-path PASS(errors=0, warnings=0);loopx canary premerge --from-git-diff --git-diff-base origin/main PASS(selected=10, failures=0,含 1 项与变更文件无关的历史可维护性提示 advisory_inherited_failure)。

我的整体评价 / Verdict

本 PR 修复了受管操作会话持久化层“校验用适配器 transport、落盘却按 host 硬编码覆盖”的自相矛盾缺陷,保障了多回合会话连续性与条件回滚保真度(long_horizon: improved),消除了跨回合无故报 profile 变化的错误中断(user_experience: improved;纯后端会话存储改动,无界面或视觉变更,visual_review: not_applicable)。生产代码仅净增 7 行(code_volume: necessary,compatibility_assessment: retain),同时通过真实 handler 负向测试证明未获准传输无法通过 prepare 铸造操作提案(authority_semantics: aligned,change_proportionality: proportionate)。不涉及语义词汇表变更(semantic_alignment: not_applicable)。当前远端精确 Head 64d91cf34d12c5c65daabe0337f2b1e97d7e445f 证据充分,予以批准。

English verdict: APPROVE at 64d91cf — threads the adapter-selected operation_transport through managed session storage and conditional restoration while keeping operation preparation fail-closed for unqualified transports; parent counterfactual, 109 session/request tests, PR #9960 + PR #9961 combined merge (113 passed), and premerge gate passed.

@huangruiteng
huangruiteng merged commit c45f602 into main Dec 3, 2026
30 of 35 checks passed
@huangruiteng
huangruiteng deleted the codex/managed-session-transport branch December 3, 2026 14:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants