Skip to content

refactor(cli): load history reads on demand - #8212

Merged
loopx-agent merged 2 commits into
mainfrom
codex/small-kernel-history-loading-20261106
Nov 7, 2026
Merged

loopx-agent merged 2 commits into
mainfrom
codex/small-kernel-history-loading-20261106

Conversation

@cocolord

@cocolord cocolord commented Nov 6, 2026

Copy link
Copy Markdown
Collaborator

Goal And Delivered Outcome

Ordinary history help and Agent reads currently import the complete CLI and more than 1,150 LoopX modules. This proposal reuses the existing history registrar/handler through cli_runtime selected loading. The same registered Agent read falls from 1,603 to 417 ms median in the source checkout and from 1,648 to 414 ms in the installed monolithic wheel.

  • Outcome basis: accepted small-kernel / monorepo distribution RFC, R0 reader loading.
  • Gap and result: remove unrelated cold Python loading from ordinary history reads while preserving chronology, scope, evidence windows, diagnostics and required native ownership.
  • Intended base: main, baseline 22b0f6c25a0450a66bd93f05954808dc0a5800ed.

中文:普通 history 帮助与 Agent 读取按需复用既有 owner;源码/已安装 wheel 的注册读取中位耗时分别降低约 74%/75%。维护、parser 拒绝及预加载完整 CLI 保留原路径,双语 RFC 记录实测收益与限制。

Author Declaration

  • Written by: model_agent — TRAE, GPT-6 family (OpenAI).
  • Specification and revision: docs/architecture/rfcs/monorepo-distribution-split-v0.md and its Chinese mirror at baseline 22b0f6c25.
Criterion (spec clause) Disposition Symbol / path Test or command
R0: characterize and reduce command-specific loading before public moves implemented within this reader slice loopx/cli_runtime.py::_build_selected_parser, _dispatch_selected, _run_command History/parser tests; actual source and installed-wheel console matrix; matched timings
Preserve history/evidence semantics and existing public compatibility implemented within this reader slice Existing cli_commands.history registrar/handler remain unchanged; maintenance and preloaded facade fallback UTC ordering, Agent filtering, limits, evidence windows, diagnostics, symbol identity/signature, handler/renderer probes
Keep core effects under their existing native owner implemented Existing TS/native runtime, unchanged Disposable native namespaces; cold missing-Node refusal and serving-runtime reuse
I3: at least one minor release for public moves out_of_scope No public module moves Public symbol identity/signature checks
Full R0/V10, M1, split installation, R1/context/host qualification and open decisions deferred Existing RFC acceptance owners This proposal does not close those acceptance boundaries
  • Self-check: inspected the final diff, compatibility paths and both RFC checkpoints; ran the checks below. No history algorithm or decision owner was added.

Scope And Continuation

  • Completed scope: one reversible history-loader change, independent semantic tests, a durable entrypoint smoke and bilingual RFC evidence.
  • Rollback: revert this commit; no state migration.
  • Remaining work: full small-kernel acceptance stays open. The proposed help p95 target of 200 ms is still unmet; D6 is not adopted. Existing catalog-facade and distribution work retain their own acceptance.
  • Delivery boundary: completed author proposal for review. Pending CI, known architecture holds and maintainer merge authority remain separate.

Validation

  • Tested revision: eb6f3eb177ced2200344554e41fa32d86f5cbf67. Final console/timing runs used identical source bytes before the evidence-only checkpoint commit.
  • Run state: finished.
  • Input classes: synthetic, public_fixture.
Check kind Result Public-safe evidence / limitation
static passed Ruff on changed Python files; whitespace/compile checks; staged and committed bilingual RFC checks
unit passed Final history and general parser selection: 26 passed. Includes UTC order, Agent scope, limits, parser diagnostics, native evidence windows, cold Node absence and preloaded full-CLI handler compatibility
regression_parity passed 27 actual-console cases in each of baseline/candidate source and installed-wheel environments, plus four facade handler/renderer probes. stdout/stderr/exit and public symbol identity/signature match. The preloaded-handler probe failed before the compatibility refinement
real_entrypoint passed Actual loopx console entry in source and newly installed monolithic wheel; reader, negative, fallback and facade paths
real_backend passed Existing native Node 26 runtime in disposable process/data namespaces with authenticated shutdown; no active application state used
integration passed Existing CLI command modularization smoke, including history refusal/loading oracle; durable history/artifact/evidence oracles retained
integration failed Source-session loader inventory test fails identically on untouched baseline: missing issue-fix/correction-settlement classifications
integration failed Turn-preview import-boundary test fails identically on untouched baseline: eager loopx.extensions.process_runtime
manual passed Matched source/wheel timings and effect observations summarized below
static passed Standard risk-based premerge on the exact five committed paths: six direct checks, six catalog canaries, eight docs/project/content smokes and public-boundary scan; no failures/skips/advisory failures. This is scoped validation, separate from the two architecture holds above
integration not_run Full remote CI has not completed; local scoped validation is not full-suite qualification

The wider first local selection had 258 passes and three failures. Two newly added negative tests incorrectly allowed native service reuse; they were corrected to isolate all temporary-runtime variables and both reruns passed. The remaining source-denial failure reproduced on the untouched baseline. A separate import/budget selection had 33 passes and the Turn-preview failure, also reproduced on that baseline. These failures are retained and are not waived.

中文:最终真实 console 与兼容性矩阵通过。两项主线已有架构失败均在未修改基线上复现,保留为资格限制;完整 CI 尚待完成,帮助 p95 也未达到提出的目标。

On Apple M4 Pro / 48 GiB, macOS 27 arm64, Python 3.13.5 and Node 26.0.0, each workload has 30 interleaved baseline/candidate pairs with matched dependencies, source, fixtures and precompiled bytecode. Python processes are fresh; native-service reuse is warm. Final sampling took 229 seconds, and all three rounds total 698 seconds under the frozen 20-minute sampling bound. Setup, validation and tracing costs are separate.

Workload Median / p95 elapsed ms, base → candidate Median CPU ms Median CLI peak RSS MiB
Source help 1552 / 1862 → 204 / 349 670 → 100 91.4 → 31.3
Source Agent read 1603 / 1833 → 417 / 482 665 → 150 91.9 → 34.4
Wheel help 1621 / 2053 → 220 / 375 695 → 100 91.8 → 31.0
Wheel Agent read 1648 / 1825 → 414 / 462 725 → 150 92.2 → 34.6

Help loads 155 rather than 1,157 LoopX modules, registered reads 208 rather than 1,158, and evidence reads 210 rather than 1,159. Help has zero observed writes/process starts/connections. Cold registered reads preserve six write-opens, two process starts, one connection and 252/355 client IPC bytes sent/received; evidence reads preserve one write-open, two connections and 1377/804 IPC bytes. Output bytes match. Descendant CPU/RSS/I/O, full model cost and human attention cost remain unknown; module count alone is not an outcome claim.

  • Coverage and gaps: the production reader, native evidence, parser/maintenance fallback, source/wheel imports and explicit facade bindings were exercised. The two inherited architecture failures and unmet proposed latency target remain visible. Change-quality qualification is disabled by the current policy; no strict receipt is claimed.
  • Changed surfaces: Python CLI loading, entrypoint regression tests, durable modularization smoke, bilingual RFC checkpoint. No frontend interaction or configuration change.

Frontend / Visual Evidence

  • UI impact: none. Existing CLI output and operations retain parity; this is a loader refactor and RFC checkpoint. First-viewport evidence is not applicable.
  • Source data: synthetic, public_fixture.

Type of Change

  • Refactoring
  • Documentation update
  • Test update

LoopX Area

  • Control plane
  • Public docs
  • Host or runtime integration

Technical Direction

  • Existing small-kernel RFC R0 reader loading; no acceptance or decision closure is inferred from this proposal.

Shared-authority RFC fixture impact

N/A: no authority-store, routing or compatibility-projection change. Existing native ownership is retained.

Boundary Checklist

  • Public diff and body exclude private state, raw traces, credentials, internal links and local machine paths.
  • Scope follows the accepted reader task; no duplicate benchmark work.
  • Both RFC mirrors change, with staged/head bilingual checks.
  • UI impact is none.
  • The commit includes a DCO sign-off.

Signed-off-by: lusendong.6789 <lusendong.6789@bytedance.com>
Co-authored-by: TRAE CLI <traecli@bytedance.com>
loopx-agent
loopx-agent previously approved these changes Nov 6, 2026

@loopx-agent loopx-agent 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; model=gpt-6.1-sol; provider=OpenAI; runtime_reported; reasoning_effort=max.

当前 exact head 的代码结论:8212@eb6f3eb177ced2200344554e41fa32d86f5cbf67。

未发现阻塞本代码切片的 finding。

动机 / Motivation

受影响的是反复查询工作历史的 CLI 使用者;即使只看帮助,原入口也先加载完整命令树。

旧入口查询 history 帮助会加载 1,157 个 LoopX 模块;新入口复用原 history 命令,只加载 155 个,帮助输出与旧入口一致。

已验证普通查询、帮助、维护子命令与错误处理保持原输出和退出码,同时帮助启动的受控样本明显变快。

本 PR 不完成整个 R0 包拆分,也不证明跨平台安装、冷启动 p95、模型效果或长程完整成本收益。

完整 R0 性能资格、其他命令闭包与分发拆包仍由原路线图负责,本切片只交付 history 的按需加载。

召回的经验建议在这里用于核对第一个有用的用户结果和失败后的可用入口;没有继承历史case结论,也不把未来产品阶段变成当前切片的新门禁。材料送达不代表已验证记忆改善效果。

改动思路 / Approach

loader只负责选择加载;原handler继续拥有过滤、维护与错误规则,19行生产增量与收益相称。

只交付history按需加载,不完成整个R0拆包。

普通history/help进入selected parser,复用注册器与原handler;维护子命令、preloaded full CLI和解析拒绝继续走完整入口。原index、过滤、顺序、错误和写入owner都不移动。这个分支变化可用一张路径表表达,不需要额外图形服务。

分支 当前观察
ordinary history/help selected loading,原handler输出逐字不变。
maintenance/parser/preloaded CLI 完整CLI兼容与原拒绝路径保留。

具体改动 / Changes

完整差异 5 文件,+315/-0;行为实验共同基线 22b0f6c25a0450a66bd93f05954808dc0a5800ed,当前head eb6f3eb177ced2200344554e41fa32d86f5cbf67。19行生产代码改加载,181行入口测试与24行smoke保护原业务;51/40行双语ledger只记录该增量,不是独立验收依据。

接受的规范是 docs/architecture/rfcs/monorepo-distribution-split-v0.md,固定在修改前 revision 22b0f6c25a0450a66bd93f05954808dc0a5800ed;当前新增的规范/ledger内容不能自证实现已满足合同。

criterion_id 当前核验
I2 implemented:register_history_command/handle_history_command reuse and 207 tests
I3 implemented:13 real-console paired cases, exact stdout/stderr/exit
I7 implemented:155 vs1157 module observation and deliberate route removal
V1 implemented:fresh subprocess module inventory
V3 implemented:13 paired console cases and preloaded-handler tests
V10 deferred:本次五对帮助启动样本只验证该入口,不能认证完整 R0、p95 或跨平台。

关键代码讲解

  • _build_selected_parser:使用已有register_history_command建立单命令parser。
  • _dispatch_selected:保留Kunlun outer guard并调用已有history handler。
  • _run_command:preloaded cli和维护子命令回full;普通history进入selected;解析拒绝回canonical错误。

本次独立运行207项相关测试全部通过,另13组成对真实console覆盖帮助、JSON/Markdown、Agent与UTC排序、零/负limit、未知Goal/Agent、复合拒绝precedence、parser错误、维护入口、空与倒序index;stdout、stderr、exit逐字相同,没有normalize。输入index和registry保持不变,原生backend进程已停止。

额外5组成对交错fresh-process history --help 样本:基线中位数约661ms,新head约139ms;这是单机warm-filesystem的小样本,不是p95或完整成本资格。基线加载1,157个LoopX模块,新head155个且不加载 loopx.cli;在独立进程仅移除history selected membership后,完整CLI/1,157模块重新出现,oracle能检出加载退化。

对主干的风险 / Risks

最强反例是优化只让help变快却改变查询过滤、拒绝优先级或维护owner。上述真实console同时固定25条foreign记录与limit,检查不同UTC偏移排序,负limit和复合错误;207项原生测试还覆盖Node缺失、原handler patchpoint与evidence窗口。没有新增授权开关或将domain判断塞入genericCore。

本次仓库原生检查 结果
原始17根 mypy、完整control-plane TypeScript 6.0.3 PASS;Python3.14.8/Node24.21.0,隔离review worktree环境。
标准premerge机械项 PASS:6 direct +15 selected,含DCO、双语RFC、diff与语义检查;整体premerge仍exit1。
全树Ruff FAIL:B/H完整109个规范化path/code/location/message一致,31个失败source及配置blob不变;独立changed-invariant验证另列。没有把原失败改写成pass。
严格exact-scope质量回执 FAIL已写入;verify为invalid_receipt,保留required Ruff失败。没有CQR pass或门禁豁免。
远端CI UNVERIFIED/not_consulted;当前wait_for_ci=false,未查询、轮询或等待。

语义与 CI 对齐

history加载选择保持local-only词汇;公开参数、诊断、原外层guard与维护生命周期都复用现有owner。当前独立证据已覆盖本改动;policy26允许将已独立归因且未触及的required red检查与review verdict分开。严格CQR仍因required Ruff失败阻断资格,不能据此合并。

我的整体评价 / Verdict

long_horizon preserved:历史只读、scope/排序与原维护authority保持,重复查询减少无关加载;user_experience improved:仍用同一命令,一轮输入即可得到原结果,拒绝后的修正路径不变。最高价值的有界简化是共用现有registrar/handler,本PR已经采取;不需再建路由状态或复制业务实现。加载集合是本地命令分类,未扩展通用状态词汇。

检查的是 console CLI 与生成的宿主指令,没有修改页面、布局或 App 导航。 无受影响的图形界面;实际模型遵循与平台安装未验证。

本head review为APPROVE;没有阻塞本代码切片的finding。严格质量门仍FAIL,完整R0、wheel/平台、模型与完整成本资格没有完成;本结论不授予merge。

English verdict: APPROVE. Exact head eb6f3eb: history demand loading preserves all thirteen real-console comparisons and passes 207 relevant tests; quality/merge qualification remains held.

@mergify

mergify Bot commented Nov 7, 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, @cocolord.

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 Nov 7, 2026
Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com>

@loopx-agent loopx-agent 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.

APPROVE — exact head 7f9e235cd80d73bf4f4f76ac18467bfa3c4b04b9.

Re-reviewed after integrating current main 2659e5f7.

  • history remains a selected reader while registry, version, and heartbeat-prequota retain their independent routes.
  • All parallel English/Chinese RFC checkpoints and evidence remain intact.
  • Exact-head verification: the CLI entrypoint suite passes 264; the modularization smoke, changed-file Ruff, diff hygiene, and bilingual RFC verifier pass; the merge commit carries DCO.

Approval is limited to merge readiness at this exact head.

@loopx-agent
loopx-agent merged commit 0744b34 into main Nov 7, 2026
4 of 7 checks passed
@loopx-agent
loopx-agent deleted the codex/small-kernel-history-loading-20261106 branch November 7, 2026 09:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-rebase Mergify: the pull request has merge conflicts with its base branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants