Skip to content

feat(oar): multiplex session host, direct Node Workbench bridge, and parent quota channel - #10241

Merged
huangruiteng merged 164 commits into
mainfrom
codex/oar-pr2-eliminate-py-js-pingpong
Dec 6, 2026
Merged

huangruiteng merged 164 commits into
mainfrom
codex/oar-pr2-eliminate-py-js-pingpong

Conversation

@songoow

@songoow songoow commented Dec 6, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

The OAR foundation from #9854 is on main at 93be88db8. This PR targets main and provides the direct Node host used by #10242. It eliminates the cross-language Node ↔ Python ping-pong hops in the OAR integration while preserving 100% single-owner control-plane authority and backward compatibility:

  1. Multiplexed session_host_server.ts by request_id

    • Removes per-socket inFlight + socket.pause() head-of-line blocking in loopx/control_plane/oar/session_host_server.ts, dispatching concurrent frames keyed by request_id (bounded by MAX_INFLIGHT_PER_SOCKET = 64 backpressure, MAX_STREAM_BACKPRESSURE_BYTES, deferred keep_alive: false drain, and bounded 5s shutdown drain).
    • Upgrades Workbench session ownership from 1 session per socket (WeakMap<Socket, AbortController>) to multi-session per keep-alive socket (WeakMap<Socket, { pendingOpens, sessions }>) so a single Workbench Daemon socket multiplexes all active OAR threads and disposes only its owned sessions on disconnect.
    • Keeps 100% wire compatibility with Python OarSessionClient.
  2. Direct Node-to-Node Workbench Daemon → session_host_server.ts & unified OarSessionBackend

    • Adds apps/workbench/packages/daemon/src/adapters/oar-host-client.ts (OarHostClient), a multiplexed pure-Node TCP/NDJSON client with byte-for-byte SHA-256 source fingerprint parity (computeOarHostFingerprint), private runtime directory/locator ownership & symlink checks, and atomic startup locking matching loopx/hosts/oar_client.py.
    • Unifies CoreOarHostBackend and LocalOarBackend behind OarSessionBackend in oar-core.ts / oar.ts; all managed Workbench OAR threads now share one persistent multiplexed TCP connection directly to session_host_server.ts (with onLateResult cleanup on timed-out opens and automatic onClosed eviction on host disconnect).
    • Deletes the per-session Python subprocess bridge (loopx/hosts/workbench_oar.py) and removes the Python spawnSync probe from loopx/control_plane/runtime/workbench_service.ts, eliminating the Node → Python → Node 3-hop path.
  3. Eliminate per-cycle execFile("loopx", ["quota", "should-run"]) cold Python forks in goal_worker.ts

    • Audited loopx/cli_commands/quota.py, quota_should_run.py, live_decision.py, quota.py, and status.py (~6,000+ LOC of authoritative Python orchestration including turn-start hooks, Lark inbox, replan obligations, rollout logging, and host-poll receipts). Rather than introducing a split-brain approximate TS re-implementation, loopx/cli_commands/opencode2_goal_worker.py now hosts a per-run authenticated, goal_id-scoped loopback NDJSON quota bridge (_GoalQuotaLoopbackBridge) that calls handle_quota_command in-process over a persistent connection.
    • loopx/control_plane/oar/goal_worker.ts consumes and immediately scrubs LOOPX_OAR_QUOTA_BRIDGE_* credentials from process.env (with defense-in-depth stripping in runtime_loader.ts, oar_client.py, oar-host-client.ts, and adapters/types.ts) and reuses one persistent keep-alive loopback socket across cycles (with AbortSignal cancellation, transparent reconnect on idle EOF, explicit LOOPX_BIN override compatibility, and standalone CLI fallback).

Verification

  • npm run typecheck:control-plane — pass
  • node --experimental-sqlite --experimental-strip-types ... --test tests/control_plane_ts/oar_*.test.ts tests/control_plane_ts/workbench.test.ts — all pass (including new oar_session_host_multiplex.test.ts + new loopback quota bridge tests in oar_goal_worker.test.ts)
  • npm --prefix apps/workbench run build -w @loopx/loochat + Workbench daemon OAR & lifecycle suite (oar-core.test.ts, oar.test.ts, oar-thread-status.test.ts, workbench-lifecycle.test.ts) — 39/39 pass (including byte-for-byte Node↔Python SHA-256 fingerprint parity and shared multiplexed socket verification)
  • pytest -q tests/control_plane/test_oar_*.py tests/control_plane/test_workbench_cli.py — 247/247 pass (including real non-mocked evaluate_goal_quota_in_process and end-to-end Node↔Python quota bridge test with poison loopx shim on PATH)
  • mypy, ruff (incl. external-request-lint.toml & external-transport-lint.toml), node scripts/ci/lint-external-transports.mjs, python3 -m loopx.cli check, git diff --check — all pass

songwells and others added 30 commits December 1, 2026 20:53
…verse/oar@0.142.0

Signed-off-by: song <xinxinsong66@gmail.com>
…ne MCP, and Python Keep-Alive client

Signed-off-by: song <xinxinsong66@gmail.com>
…docs and checks

Signed-off-by: song <xinxinsong66@gmail.com>
…and doctor readiness

Signed-off-by: song <xinxinsong66@gmail.com>
…ost.version

Signed-off-by: song <xinxinsong66@gmail.com>
…dex exec

Signed-off-by: song <xinxinsong66@gmail.com>
…ting

Signed-off-by: song <xinxinsong66@gmail.com>
…olated shell

Signed-off-by: song <xinxinsong66@gmail.com>
…l_worker

Signed-off-by: song <xinxinsong66@gmail.com>
Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com>
Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com>
* fix(turn): retain the selected operation transport across OAR resume

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

* Close managed OAR sessions when initialization loses its binding (#9984)

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

---------

Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com>
* Resume ordinary DSH turns with the native OAR session identity

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

* Confirm the selected DSH binding before OAR dispatch

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

---------

Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com>
* fix(turn): retain the selected operation transport across OAR resume

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

* Defer DSH operation runtime qualification to OAR session open

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

* Apply the operation host token bound in planning and CLI inspection

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

* Refuse bounded OAR DSH operations before model input

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

* Keep confirmed operations resumable when their executor is unavailable

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

---------

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

* fix(turn): retain the selected operation transport across OAR resume

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

* Defer DSH operation runtime qualification to OAR session open

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

* Apply the operation host token bound in planning and CLI inspection

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

* Preserve explicit DSH operation modules and opt into OAR tools by name

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

* Refuse bounded OAR DSH operations before model input

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

* Keep confirmed operations resumable when their executor is unavailable

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

* Reject conflicting DSH operation and runner selections in delegation planning

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

* Let ordinary DSH Turns validate the selected OAR runtime (#9993)

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

* fix(dsh): enforce and verify per-request max_tokens on ordinary OAR turns

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

---------

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

Signed-off-by: song <xinxinsong66@gmail.com>

# Conflicts:
#	package-lock.json
#	tests/test_pi_goal_mode.py
…e floor and OAR host

Signed-off-by: song <xinxinsong66@gmail.com>
…ion-phase2

Signed-off-by: song <xinxinsong66@gmail.com>

# Conflicts:
#	loopx/cli_commands/turn.py
#	loopx/cli_commands/turn_dsh_host.py
#	loopx/cli_commands/turn_registration.py
#	loopx/cli_commands/turn_selection.py
#	loopx/control_plane/oar/session_host_server.ts
#	loopx/control_plane/oar/session_hub.ts
#	loopx/control_plane/turn_driver/codex_cli.py
#	loopx/control_plane/turn_driver/codex_sessions.py
#	loopx/control_plane/turn_driver/host_binding.py
#	loopx/control_plane/work_items/operation_agent_handoff.ts
#	loopx/hosts/dsh/turn_host_adapter.py
#	loopx/hosts/oar_client.py
#	tests/control_plane/test_dsh_operation_entry.py
#	tests/control_plane/test_oar_session_client.py
#	tests/control_plane/test_operation_transport_readback.py
#	tests/control_plane_ts/oar_session_hub.test.ts
#	tests/test_codex_operation_host.py
#	tests/test_loopx_turn_driver.py
#	tests/test_loopx_turn_replan_successor.py
…ion host, and runtime loader

Signed-off-by: song <xinxinsong66@gmail.com>
…n-phase3

Signed-off-by: song <xinxinsong66@gmail.com>

# Conflicts:
#	loopx/control_plane/turn_driver/codex_cli.py
#	loopx/control_plane/turn_driver/oar_operation_host.py
…rker

Signed-off-by: song <xinxinsong66@gmail.com>
Signed-off-by: song <xinxinsong66@gmail.com>
…ion-phase2

Signed-off-by: song <xinxinsong66@gmail.com>
…n-phase3

Signed-off-by: song <xinxinsong66@gmail.com>
… 0.142.0, and add Windows Job containment

Signed-off-by: song <xinxinsong66@gmail.com>
… and Dashboard OAR observe/brands/forms

Signed-off-by: song <xinxinsong66@gmail.com>
Signed-off-by: Codex <codex@openai.com>
Signed-off-by: Codex <codex@openai.com>
Signed-off-by: Codex <codex@openai.com>
Signed-off-by: song <liusongstep@gmail.com>
Base automatically changed from codex/oar-deep-fusion-phase0-1 to main December 6, 2026 07:17
@mergify

mergify Bot commented Dec 6, 2026

Copy link
Copy Markdown

This pull request has merge conflicts with main and cannot be merged
until they are resolved. Please rebase or merge the base branch, @songoow.

Choose the remote for the base repository, not an out-of-date fork.
For a fork clone, first inspect git remote -v; upstream must point
to https://github.com/loopx-project/loopx.git. If it is absent, add it
with git remote add upstream https://github.com/loopx-project/loopx.git.
Then run:

git fetch upstream
git rebase upstream/main
# Resolve each conflict, git add the resolved files, then git rebase --continue.
git push --force-with-lease origin HEAD

For a same-repository clone whose origin points to
https://github.com/loopx-project/loopx.git, use origin instead of
upstream for fetch/rebase. If you prefer merging the base, use
git merge <base-remote>/main and push normally.

Keep the DCO Signed-off-by trailer on every commit when you rebase.
https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork

@mergify mergify Bot added the needs-rebase Mergify: the pull request has merge conflicts with its base branch label Dec 6, 2026
Signed-off-by: Codex <codex@openai.com>
Signed-off-by: song <liusongstep@gmail.com>
@mergify mergify Bot removed the needs-rebase Mergify: the pull request has merge conflicts with its base branch label Dec 6, 2026
Signed-off-by: Codex <codex@openai.com>
Signed-off-by: song <liusongstep@gmail.com>
@mergify

mergify Bot commented Dec 6, 2026

Copy link
Copy Markdown

This pull request has merge conflicts with main and cannot be merged
until they are resolved. Please rebase or merge the base branch, @songoow.

Choose the remote for the base repository, not an out-of-date fork.
For a fork clone, first inspect git remote -v; upstream must point
to https://github.com/loopx-project/loopx.git. If it is absent, add it
with git remote add upstream https://github.com/loopx-project/loopx.git.
Then run:

git fetch upstream
git rebase upstream/main
# Resolve each conflict, git add the resolved files, then git rebase --continue.
git push --force-with-lease origin HEAD

For a same-repository clone whose origin points to
https://github.com/loopx-project/loopx.git, use origin instead of
upstream for fetch/rebase. If you prefer merging the base, use
git merge <base-remote>/main and push normally.

Keep the DCO Signed-off-by trailer on every commit when you rebase.
https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork

@mergify mergify Bot added the needs-rebase Mergify: the pull request has merge conflicts with its base branch label Dec 6, 2026

@songoow songoow 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 Astra Pro · OpenAI · self_reported

Request changes conclusion (author-owned PR; GitHub blocks formal self-review)

动机 / Motivation

使用 loopx workbench start 的操作者需要 Workbench 与 Core CLI 共用宿主和会话句柄。每会话的 Python 桥接改为共享 Node 连接;基线 #10243 同时将 Workbench 的环境变量归一化。迁移后生命周期应报告 core,流式会话、取消和断线清理都由同一个宿主处理。本次覆盖托管模式、独立模式和 Goal 配额通路。

改动思路 / Approach

启动器向 daemon 传递可执行宿主入口和环境快照。OarHostClient 将带请求 ID 的命令复用到一个 Node Session Host,Goal Worker 继续向父进程申请配额。两条通路分别决定会话归属和是否允许下一轮。

具体改动 / Changes

21 个文件涉及直接连接、请求排队与取消、跨进程启动锁、会话归属和 Goal 配额。已关闭的锁竞争、取消饥饿反馈分别由真实 Python/Node 并发启动和复用套接字用例覆盖。此前旧构建的协议探测也保留在本次提交。

P2 · 托管 Workbench 与主干的环境归一化相遇时会选错会话所有者。 在 e357962 主干的 daemon-main 初始化过程中,将此 PR 启动器发出的 ROOT、HOST_ENTRY、ENV 三个旧前缀字段交给 adoptLegacyEnv。同一个配置对象在规范化前返回 core,规范化后只保留 LOOPX_WORKBENCH_OAR_CORE_*,当前读取器返回 standalone。 Core 启动端、所有者读取端、主干启动时的规范化、主干的键名迁移

对主干的风险 / Risks

git merge-tree 对 e357962 报告 8 个冲突文件。冲突包括启动协议、两端环境过滤及对应测试。直接保留 PR 一侧会让托管用户获得独立会话,生命周期状态和后续控制与其预期不同。GitHub 在该头的三项已完成检查为绿;它们未测试这两个版本的组合。

按提交树运行真实宿主测试 9/9,覆盖并发 Python/Node 启动、共享会话、取消和断线清理。隔离整合候选的启动路径 6/6、真实宿主 9/9。

我的整体评价 / Verdict

请先整合 #10243 并验证两端解析同一组字段。在只用于复核的候选中,双前缀读取、规范前缀写入和保留两条过滤规则使真实共享宿主测试通过。候选没有改动 PR,系统服务注册及 macOS 自启动未在本次复核中执行。 同步启动器、预检、宿主适配器和环境过滤器的规范键名。读取兼容旧前缀,保留配额通道过滤;过时的 Python 桥接配置继续在启动前被拒绝。让真实启动环境经过 daemon-main 使用的 adoptLegacyEnv,再断言已托管工作台返回 core;另测空配置、旧前缀、残缺配置和不兼容旧构建。

English verdict: REQUEST_CHANGES — 7d19f96. The submitted host reader falls back to standalone after current main normalizes the launch environment. The integration requires conflict resolution.

Signed-off-by: song <xinxinsong66@gmail.com>
@songoow

songoow commented Dec 6, 2026

Copy link
Copy Markdown
Collaborator Author

Synced with latest main (e357962f2, including #10243 LOOPX_WORKBENCH_* alignment) and completed preflight hardening for the managed-OAR startup compatibility review (7d19f96df..a1ac64604):

  • Merged origin/main (41da985b4):
    • Aligned coreOarHostConfig and coreOarLaunchEnvironment to LOOPX_WORKBENCH_OAR_CORE_* while retaining LOOCHAT_OAR_CORE_* read fallback and fail-closed rejection of both legacy Python-bridge prefixes.
    • Aligned LOOPX_WORKBENCH_* / LOOCHAT_* / LOOPX_OAR_QUOTA_BRIDGE_* secret stripping across oar-host-client.ts, types.ts, runtime_loader.ts, and oar_client.py.
  • Managed-OAR preflight hardening & tests (a1ac64604, building on 9b746f08b):
    • loopx/control_plane/runtime/workbench.ts: builtEntry() validates the candidate build's workbench-lifecycle.js configuredOarSessionOwner() using the real oarHostEnv before state creation, lock acquisition, or child spawn; prepareLaunch() strips stale LOOPX_WORKBENCH_OAR_CORE_PYTHON/ENTRY and LOOCHAT_OAR_CORE_* entries from .env.
    • tests/control_plane_ts/workbench.test.ts & apps/workbench/packages/daemon/test/workbench-lifecycle.test.ts: verified both matching Node-host startup (including real compiled apps/workbench preflight) and pre-spawn rejection with actionable npm ci && npm run build in <app> guidance for both #9854 (LOOCHAT_*) and #10243 (LOOPX_WORKBENCH_*) Python-bridge builds across prepareLaunch, workbench(), and workbench_service.ts.

Verification (a1ac64604, Node v24.23.0 / Python 3.12.3):

  • npm run typecheck:control-plane, @loopx/workbench-daemon build + typecheck: PASS
  • Control-plane TS (oar_*.test.ts, workbench.test.ts, workbench_autostart.test.ts): 82/82 PASS
  • Workbench daemon (oar-core, oar, oar-thread-status, workbench-lifecycle): 40/40 PASS (including Node↔Python SHA-256 fingerprint parity)
  • Python (tests/control_plane/test_oar_*.py, tests/control_plane/test_workbench_cli.py, tests/test_workbench_cli.py::test_upgraded_workbench_service_creates_one_session_on_the_shared_core, tests/test_opencode2_goal_worker_cli.py): 253/253 + 11/11 PASS
  • ruff (external-request-lint.toml, external-transport-lint.toml, CI E4,E7,E9,F), lint-external-transports.mjs, mypy --follow-imports=silent, python -m loopx.cli check (ok: true, errors: 0): PASS

@mergify mergify Bot removed the needs-rebase Mergify: the pull request has merge conflicts with its base branch label Dec 6, 2026

@songoow songoow 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 Astra Pro · OpenAI · self_reported

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

动机 / Motivation

操作者从 LoopX 启动托管 Workbench,同时从 Core CLI 查看或控制同一原生会话。旧版本为每个 Workbench 会话启动 Python 桥,新版本直接向共享 Node 宿主复用请求。配套托管配置在守护进程归一化后仍认定为 core;独立启动保持 standalone,旧构建在创建服务前收到重建提示。本次审查工作台的会话归属、跨语言启动、流式取消和 Goal 配额,未验证签名后的 macOS 自动登录服务。

改动思路 / Approach

Core 启动器以实际传给宿主的环境快照检查安装的守护进程。Workbench 适配器读取规范前缀并兼容旧前缀,用一个 Node 客户端复用连接和请求编号。宿主登记每条连接拥有的会话,Goal 的配额仍由现有父进程决定。

会话传输、启动契约和 Goal 配额通道。同一托管工作台复用一条 Node 连接访问 Core 宿主,Goal 的轮次配额交给原有父进程处理。

具体改动 / Changes

Workbench 使用说明 在主干 dd4f32c 的 apps/workbench/README.md 里区分了托管执行和独立节点。对照文档逐项验证 managed-owner 与 standalone。本次将真实 adoptLegacyEnv 接在配置读取之前,在当前提交实测新旧前缀都得到 core,空环境得到 standalone;只提供 Python 桥接或者字段残缺时,在启动前被拒绝。上次审查记录的规范化回归已解决。

多路宿主还验证了 Python/Node 并发启动只产生一个宿主,多会话 prompt、状态和迟到取消能按编号关联,连接断开仅清理自己的句柄。Goal worker 的配额、恢复和失败路径也已复测。控制面 62/63 通过,唯一失败为当前 main 同样可复现的 lifecycle.sock 绑定 EPERM。Workbench daemon 31/31、Python 会话客户端与 Goal 配额 102/102 通过。

对主干的风险 / Risks

基线和提交头上的单项排空测试都在建立本地 Unix socket 时遇到 EPERM,未进入生产排空逻辑。当前 Linux 的真实 TCP 宿主会话按预期运行,系统服务安装仍需平台 CI 覆盖。与最新 main 的合并可干净完成;它比本 PR 的分叉点多一个发布打包脚本提交,未改变被核查的宿主入口。

我的整体评价 / Verdict

建议通过此次提交。启动协议现在能在升级时明确拒绝不配套的守护进程,独立用户维持本地执行。公开协议、已有的共享宿主和配额归属均通过针对性测试;没有发现需要继续阻塞此 PR 的问题。

English verdict: APPROVE — a1ac646. Real daemon normalization preserves Core ownership, incompatible builds fail before spawn, and shared-host integration passes.

songoow pushed a commit that referenced this pull request Dec 6, 2026
Signed-off-by: song <xinxinsong66@gmail.com>
@huangruiteng
huangruiteng merged commit b6ed93e into main Dec 6, 2026
27 checks passed
@huangruiteng
huangruiteng deleted the codex/oar-pr2-eliminate-py-js-pingpong branch December 6, 2026 10:38
loopx-agent added a commit that referenced this pull request Dec 6, 2026
…ar_node monkeypatch (#10241) (#10273)

Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com>
songoow pushed a commit that referenced this pull request Dec 6, 2026
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.

4 participants