Skip to content

perf(cli): dispatch global reads through their lightweight owner - #6993

Open
hhyykk wants to merge 1 commit into
loopx-project:mainfrom
hhyykk:codex/architecture-payoff-round4-20261021
Open

hhyykk wants to merge 1 commit into
loopx-project:mainfrom
hhyykk:codex/architecture-payoff-round4-20261021

Conversation

@hhyykk

@hhyykk hhyykk commented Oct 21, 2026

Copy link
Copy Markdown
Collaborator

Goal And Delivered Outcome

Five existing read commands (goal-portfolio, global-summary, global-gates, global-todos, global-risks) currently load the complete compatibility CLI before parsing or dispatching. Their argparse registration also imports the read implementation. A caller asking for help pays for unrelated command handlers and status dependencies.

Reuse the selected-command parser/shared dispatcher. Move the unchanged registration into summary_all_registration.py, retain the old registration import as an alias, and remove the full CLI's old dispatch branch. The normal entrypoint loads only registration for help and the existing read handler for accepted commands. Full-parser callers reuse that same dispatch.

Basis: TypeScript control-plane migration RFC Stage 3 caller adoption, docs/architecture/rfcs/typescript-control-plane-migration-v0.md at a590609a357f7cde17289b5ceba9f85a9fcb46cc. Target: main. No kernel/lifecycle/default-provider completion claimed.

Author Declaration

  • Written by: model_agent, OpenAI GPT-6 Codex, for the requesting operator.

Implemented against

Criterion Disposition Symbol / evidence
Actual caller adoption, with old dispatch retired implemented cli_runtime.py selected path; old cli.py global-read branch deleted
Small shared interface over existing owners implemented parser-only registration + existing handler; normal and compatibility CLI adapters
Preserve commands, flags, diagnostics, formatting and authority implemented help/parser parity, real File/SQLite readbacks and failure checks; existing registry/runtime resolution and native-controller guard
Demonstrate incremental complete-entrypoint payoff implemented both performance arms include pending #6992; table below does not recount its original gain
Complete migration, R1–R3 or provider promotion out_of_scope no semantic store/backend routing or execution-policy change

Self-check: clean-code-guard, test-guard and docs-guard; four original function ASTs are identical after the move; CLI/real-provider/installed paths and historical import regression tested. No real model, live provider send, merge or deployment was run.

Scope And Continuation

  • One registration implementation; the old import aliases the same function for the existing legacy export facade. It exits with those legacy facade consumers. No second registration or handler implementation is kept.
  • Product economics: +150 / −136 lines, net +14. Registration bodies are moves, not semantic deletion payoff. The old 11-line full-CLI dispatch is retired. Bridge operations/dependencies/public flags/data caches added: 0. Existing typed semantic owners and native method sequences remain unchanged.
  • GLOBAL_READ_COMMANDS remains a local dispatch group of existing parser command names. It does not add a command, persisted value, domain enum or shared protocol; the diff-scoped advisory finding was reviewed as local vocabulary.
  • Reviewed all 48 open PR file sets and refreshed the latest feat(planning): keep Goal context current with independent Agent adoption #6987 head immediately before publication. No reviewed PR owns the new registration module or changes this read handler. perf(cli): reuse selected dispatch for manager Inbox commands #6989 shares CLI/parser-test files but changes Inbox commands; its patch cleanly applies on the combined candidate, and that combination passes 66 CLI tests. perf(portfolio): share executable revision across one evidence read #6990 changes the portfolio's outer scope; no portfolio timing is credited here. perf(quota): reuse one executable revision per public read #6992 changes public quota scope; it is deliberately present in both performance arms. Shared RFC edits are distinct paragraphs. This product PR is based on main, not stacked on those PRs.
  • Complete within these five existing CLI commands. Remaining global-plan/history/kernel opportunities are not bundled or described as shipped work.

Validation

  • Tested revision: c984ac2fbaae3d234aad76493c0c8af69df19f93.
  • Run state: finished. Input classes: synthetic, public_fixture.
Check kind Result Public-safe evidence / limitation
integration passed 176 related tests across CLI entrypoint, global Todo/risk/summary and Goal portfolio; focused registration/diagnostic/read checks rerun after final cleanup
regression_parity passed all five command help/unknown-option/invalid-limit paths compare with the full parser; accepted empty reads forbid loopx.cli import and preserve coverage/error behavior
regression_parity passed same final no-full-CLI regression fails on baseline and passes on candidate, with independent actual module-root assertions
static passed four moved/retained function ASTs match baseline exactly; scoped Ruff; control-plane typecheck; staged/head bilingual checks; diff whitespace
integration passed pending #6992 + this change + #6989 apply without conflict; 66 CLI tests pass in that combined tree
real_backend passed 10 real File/SQLite read cases (all five commands, eight existing canonical Goals) and five malformed-registry refusals; registry/state bytes unchanged
regression_parity passed real read outputs match after only observation-clock/derived-digest normalization; persisted source times, inventory/file revisions, coverage, warnings, task identities and other fields retained; portfolio snapshot hashes independently verified
real_entrypoint passed matched complete entrypoint measurements below; every child proves its actual Python root and read children prove native root, module loading and native methods
integration passed normal wheel/sdist builds and separately installed environments; actual console from empty-project cwd, no source PYTHONPATH; repeat all 15 File/SQLite/failure cases

Incremental performance, after #6992

This is deliberately not main versus a candidate that takes credit for the already-proposed quota scope fix:

  • Baseline: public perf(quota): reuse one executable revision per public read #6992 head cdc0c89e13c13a7f53427b60ad881c18583d6049.
  • Candidate experiment: that same head plus this PR commit, applied cleanly in a disposable worktree. All four changed CLI module bytes match the product PR exactly. The shared quota scope is therefore present in both arms; the product remains independently applicable to main.
  • Linux, Python 3.11, Node 24.21.0 / SQLite 3.53.4; 15 fresh Python processes/arm/case, sequential arms, complete package bytecode prepared in both, one untimed warmup/case and warm native runtime for reads. Bytecode coverage is checked against each package's full source set; the candidate's one additional module is expected.
  • Timings include process startup, imports, parser, real source/status/quota reads and output. The help case measures the actual entrypoint/argparse exit. Native read methods/order stay equal; valid reads stop loading loopx.cli, and help does not load the read handler.
Case Baseline p95 ms Candidate p95 ms Change
Help 1011.4 55.2 -94.5%
SQLite, 8 Goals 1836.4 1213.5 -33.9%

The global read's code scans fall 10 → 1 by composing the existing whole-command scope. This is additional caller scope sharing after #6992's per-decision scope, not its earlier 346 → 10 saving. No source fact or result is cached. Help text is byte-identical. Read outputs match except observation times; source fields, alerts, coverage and the local-registry global-directory warning remain visible. No complete global-inventory or all-healthy claim is made.

These are local synthetic workload measurements with prepared bytecode/native caches, not cold installation, model/task quality, token savings or the entire LoopX application. No wall-clock assertion is added to the test suite; the deterministic regression checks retired imports and actual behavior.

Reproduce the incremental comparison

Use the public synthetic setup_goals.py fixture setup from #6992. It creates real disposable File/SQLite stores and public Todos without executing work. Use empty fixture/evidence directories, the same Python interpreter and qualified Node, and install Python/Node dependencies in both checkouts.

Create two disposable worktrees from public #6992 head cdc0c89e13c13a7f53427b60ad881c18583d6049; cherry-pick this PR commit into only the candidate worktree. This intentionally includes the same earlier optimization on both sides. Save the following script outside both checkouts, idle unrelated work, and run sequentially:

python3 qualify.py BASE_CHECKOUT FIXTURE_DIRECTORY/sqlite-8 BASE_OUTPUT --expect-full yes --samples 15
python3 qualify.py CANDIDATE_CHECKOUT FIXTURE_DIRECTORY/sqlite-8 HEAD_OUTPUT --expect-full no --samples 15

The script precompiles each package, verifies bytecode completeness and actual import origins, records every sample/output/native method, rejects an unexpected full CLI import, and stops only its owned runtime. Usage pings are disabled. Harness SHA256: ebd2cf3d5813fd0135a34e70fee079e33d4e6cc0b9be7f36fd67e0d11ce86d31.

import argparse,hashlib,importlib.util,json,os,statistics,subprocess,sys
from pathlib import Path
from time import perf_counter
p=argparse.ArgumentParser();p.add_argument('repo');p.add_argument('fixture');p.add_argument('out');p.add_argument('--samples',type=int,default=15);p.add_argument('--expect-full',choices=('yes','no'),required=True);a=p.parse_args();repo=Path(a.repo).resolve();fixture=Path(a.fixture).resolve();out=Path(a.out).resolve();out.mkdir(parents=True,exist_ok=True);tmp=out/'tmp';tmp.mkdir(exist_ok=True)
env={**os.environ,'TMPDIR':str(tmp),'TEMP':str(tmp),'TMP':str(tmp),'LOOPX_USAGE_PING':'0','PYTHONPATH':str(repo),'PYTHONDONTWRITEBYTECODE':'1'};compile_env=dict(env);compile_env.pop('PYTHONDONTWRITEBYTECODE',None);subprocess.run([sys.executable,'-m','compileall','-q',str(repo/'loopx')],cwd=repo,env=compile_env,check=True);missing=[str(f) for f in (repo/'loopx').rglob('*.py') if not Path(importlib.util.cache_from_source(str(f))).exists()];assert not missing,missing
script='''import json,pathlib,sys,loopx
expected=pathlib.Path(sys.argv[1]);kind=sys.argv[2];sys.argv=sys.argv[:1]+sys.argv[3:]
assert pathlib.Path(loopx.__file__).resolve()==expected/'loopx/__init__.py'
scans=[];methods=[]
if kind!='help':
 from loopx.control_plane import effect_runtime as er
 assert er._control_plane_root().resolve()==expected/'loopx/control_plane'
 original=er._runtime_fingerprint;request=er._request_with_info
 def scan():
  value=original();scans.append(value);return value
 def rpc(*args,**kwargs):methods.append(kwargs['method']);return request(*args,**kwargs)
 er._runtime_fingerprint=scan;er._request_with_info=rpc
from loopx.entrypoint import main
try:code=main()
except SystemExit as exc:code=exc.code
sys.stderr.write('PROOF='+json.dumps({'module':str(pathlib.Path(loopx.__file__).resolve()),'full_cli':'loopx.cli' in sys.modules,'handler_loaded':'loopx.cli_commands.summary_all' in sys.modules,'code_scans':len(scans),'methods':methods})+'\\n')
raise SystemExit(code)
'''
base=['--registry',str(fixture/'registry.json'),'--format','json'];modes={'help':['global-summary','--help'],'read':[ *base,'global-summary','--agent-id','worker','--limit','128','--scan-path',str(fixture/'public')]};rows=[]
def invoke(kind,argv):
 t=perf_counter();pr=subprocess.run([sys.executable,'-c',script,str(repo),kind,*argv],cwd=repo,env=env,capture_output=True,text=True,timeout=90);ms=(perf_counter()-t)*1000;assert pr.returncode==0,(kind,pr.stdout,pr.stderr);proof=json.loads(next(x.removeprefix('PROOF=') for x in pr.stderr.splitlines() if x.startswith('PROOF=')));assert proof['module']==str(repo/'loopx/__init__.py');assert proof['full_cli']==(a.expect_full=='yes'),proof
 if kind=='read':assert json.loads(pr.stdout)['summary']['runnable_todo_count']==8
 elif a.expect_full=='no':assert proof['handler_loaded'] is False
 return ms,pr.stdout,proof
try:
 for kind,argv in modes.items():
  invoke(kind,argv);samples=[];outputs=[];proofs=[]
  for _ in range(a.samples):
   elapsed,stdout,proof=invoke(kind,argv);samples.append(elapsed);outputs.append(stdout);proofs.append(proof)
  row={'mode':kind,'samples_ms':samples,'p50_ms':statistics.median(samples),'p95_ms':sorted(samples)[int((len(samples)-1)*.95+.5)],'outputs':outputs,'proofs':proofs};rows.append(row);print(json.dumps({k:row[k] for k in ('mode','p50_ms','p95_ms')}),flush=True)
 (out/'receipt.json').write_text(json.dumps({'revision':subprocess.check_output(['git','-C',str(repo),'rev-parse','HEAD'],text=True).strip(),'package_bytecode_complete':True,'python':sys.version,'harness_sha256':hashlib.sha256(Path(__file__).read_bytes()).hexdigest(),'cli_source_hashes':{name:hashlib.sha256((repo/name).read_bytes()).hexdigest() for name in ('loopx/cli.py','loopx/cli_runtime.py','loopx/cli_commands/summary_all.py','loopx/cli_commands/summary_all_registration.py') if (repo/name).exists()},'rows':rows},indent=2)+'\n')
finally:
 sys.path[:0]=[str(repo),str(repo/'tests')];from managed_effect_runtime_fixture import capture_disposable_effect_runtimes,stop_disposable_effect_runtimes;stop_disposable_effect_runtimes(out,capture_disposable_effect_runtimes(out))

Coverage/gaps: full repository suite, PostgreSQL, Windows, browser/model roundtrips and live provider delivery were not run. No TS domain code changed. Hosted CI and maintainer review remain separate from these local author checks.

Frontend / Visual Evidence

UI impact: none. Existing help text, flags and read output shapes remain unchanged; no new screen or capability.

Change Area

  • Control plane / CLI caller adoption.

Technical Direction

Existing TypeScript control-plane migration, Stage 3. Reuse existing registration/transport/semantic owners and retire the obsolete caller branch; do not add per-field bridges.

Shared-authority RFC fixture impact

  • Schema: existing synthetic canonical Goals, registered worker, public open Todos, real read-observation files, File/SQLite views.
  • No authority/provider/projection schema or scheduling rule changes. Parser/dispatch relocation retains current scope, malformed-source refusals and source coverage. Request scope pins code identity, not authority data.
  • File/SQLite real and installed consumer arms passed. Legacy/file/PostgreSQL promotion rehearsal not run: this does not promote/select a provider or alter compatibility projection semantics. R1–R3/D1–D3 remain outside this caller-adoption slice.

Boundary Checklist

  • Public-safe diff/body; no private state, raw traces/verifier output, credentials, internal URLs or machine paths.
  • Current open PRs reviewed; previous optimizations not recounted as new gain.
  • Scoped to the requested independently measurable improvement.
  • Paired RFC changes; staged/head bilingual checks pass.
  • UI impact none.
  • DCO sign-off included.

Signed-off-by: aihop <4408344+hhyykk@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.

Reviewer: model_agent; gpt-6.1-sol; OpenAI; runtime_reported; reasoning_effort=max.

动机

需要在命令行反复读取多个 Goal 状态的用户和 Agent。

帮助和五个全局读取命令过去先加载完整兼容 CLI;现在帮助只加载参数注册,读取走既有处理器和统一分发。

原有五个命令的参数、帮助、错误、范围和状态读回保持一致,帮助与实际读取的加载开销下降。

本改动不更改配额、权限、Todo 状态或 provider 路由,也不交付完整原生 CLI 或安装态 App。

完整原生 CLI、托管及安装态 App、长期任务收益和完整成本仍由迁移主线继续验收。

改动思路

参数注册与执行处理分开,并复用原 dispatcher,删除完整 CLI 的重复分支。 只迁移既有五个全局读取命令的参数注册和 CLI 调用路径。

正常入口先按既有命令名选择轻量 parser,再经原 guard、registry/runtime 解析与统一 dispatcher 调用原 handler。完整 parser 的兼容入口也复用相同 dispatcher,旧分支移除。注册函数搬到只定义参数的模块,旧 import 只是同一个函数的 alias;帮助不必加载 handler。解析拒绝仍回到原完整 parser 以保留诊断。

这是调用路径及代码版本生命周期的有界改进。状态和准入规则仍由既有 typed owner 决定,观察来源缺失仍明确显示;没有额外 provider、协议操作、领域状态、权限判断或同步状态副本。

具体改动

评审完整 head c984ac2fbaae3d234aad76493c0c8af69df19f93,实际 PR merge-base 为 a590609a357f7cde17289b5ceba9f85a9fcb46cc。先固定接受的 docs/architecture/rfcs/typescript-control-plane-migration-v0.md,规范修订 a590609a357f7cde17289b5ceba9f85a9fcb46cc,再读完整提案。

规范逐项映射:§2.4 复用既有 owner,未双跑语义;§2.8 以同输入基线/当前入口核验成本;§5 分开报告生产 LOC、代码搬移和兼容边界;§6 比较完整输出、真实 File/SQLite、失败恢复和反例敏感性;§7 从正常 wheel/sdist 的实际 console 执行。以上在本切片 implemented;Stage 3 的完整 native CLI/App 收敛 deferred,剩余边界如动机所述。这里不以零语义删除、目录移动或更少 RPC 宣称完成整个迁移阶段。

关键代码讲解

生产代码 +150/-136,净 +14;四个原函数 AST 完全一致,旧完整 CLI 的 11 行导入/分发退役。搬移不计作领域语义删除;旧注册 alias 对应实际 legacy export facade 调用者,随这些消费者退役而退出。新 GLOBAL_READ_COMMANDS 是已有五个命令的本地分发集合,没有新增共享协议词汇。

176 项相关 Python 测试通过;标准 premerge 的 6 项直接检查通过,19 项选中检查中 18 项通过,原输出差分红灯的独立归因见下节。

每个 PR 独立比较 40 组真实 File/SQLite CLI 结果,覆盖五个命令、四个 manager-view、单 Goal 范围、未知范围、坏参数、损坏来源和暂停/恢复。另补 cap 与新来源的反例。每个 PR 的正常 wheel、sdist 各 25 个 console 案例通过:独立环境、空 cwd、无源码 PYTHONPATH,包内生产字节和 native 根已核。注册、state 和历史源文件保持不变。

比较保留完整字段、错误全文、权限、覆盖率、新鲜度标签、持久化时间及文件/库存 revision,只规范化明确的观察时钟和观察耗时。portfolio 的来源 digest 由捕获的原始 status 重算,原始快照和 manager context 的派生身份也独立核验,再比较规范化后的含义;没有直接删掉 opaque ID 掩盖差异。

增量实验在两臂都保留 #6992 的公共 quota scope,再加入本 PR;私有组合的四份 CLI 生产文件与当前 PR 逐字一致。相同 SQLite 八 Goal 输入、相同 Python/Node、完整字节码和已热原生运行时,每臂 15 次正常入口新进程:摘要 p50 1067.82→747.14 ms、p95 1120.95→781.75 ms;帮助 p95 380.28→36.26 ms。全部输出保持一致,不重复计算 #6992 的收益。

对主干的风险

最关键的风险是代码 scope 跨请求泄漏,或入口搬移改变拒绝顺序、隐藏来源不完整和旧状态。实际负例保留:未知 Goal 的原合同是 code 0、空结果与 missing_goal_ids/不完整覆盖,不是凭空改为拒绝码;坏 registry 和无对应 mode 的 exact Todo 保持原错误;暂停后可见任务从 8 变 7,恢复后回到 8。未配置全局目录的 gates/todos 仍报来源不可用,不能称全局来源全健康。cap 下其余行明确 omitted,新注册的坏来源不会闯入已限定的 Goal 读取;显式读坏来源保持 unknown。

语义与 CI 对齐

原 main-relative premerge 仍红,未改门槛。固定较新 main 5bf58c1ca3d21919b15c662bc705c3e069bfb496,用同一完整检查分别对不可变基线与当前 head 运行,全部 15 条失败身份和细节一致:规划结构/动作摘要,以及三条 status Markdown 增长 38、允许 32 的预算。相关 status/quota/输出检查 owner 字节不变,触发与本 PR 的五个 global 命令分发分离;实际 PR 基线到 head 的完整 96 项输出差分通过。按现行评审失败归因规则,这是既有不相关红灯,保留单独集成/合并资格 hold。不能把“可 APPROVE”改写成“原 premerge 全绿”。

原生调用的方法序列保持一致;没有发起真实工作、外部 provider 投递或修改活跃 Goal。旧缺陷/私有变体会失败,当前 head 通过;包构建使用当前源码重建忽略的 Chat 资源后正常完成,最初错误构建调用和旧资源拒绝均保留。没有弱化断言、删掉失败或修改 budget。未查询、轮询或等待远程 CI。

冷原生启动、daemon RSS、PostgreSQL、Windows、安装态 App/Lark/模型以及长程净收益和完整成本仍未验证;本次不改变它们的原验收或授予推广资格。

我的整体评价

未发现本次精确 head 的阻断问题,结论 APPROVE。交付判断为 justified_increment:真实调用者获得可测的读取成本改善,边界可独立验证和回滚;不把这一结果等同整体 Stage 3、Goal 完成或模型收益。long_horizon 判为 preserved:当前状态、暂停、范围、失败恢复与后续读取语义保留;user_experience 判为 improved:同一读任务减少本地等待,无新增准备、权限或确认轮次。

参数注册与执行处理分开,并复用原 dispatcher,删除完整 CLI 的重复分支。 只迁移既有五个全局读取命令的参数注册和 CLI 调用路径。 兼容保留有真实调用方;采用现有 typed vocabulary/owner,没有新增领域状态分类或以 prose 猜测规则。保留已说明的未测边界和单独集成红灯。APPROVE 不授予合并、安装或发布权限。

English verdict: APPROVE — c984ac2fbaae3d234aad76493c0c8af69df19f93. Global reads reuse the existing selected parser/dispatcher and unchanged handler. 176 focused tests,40 full real-provider CLI pairs,50 installed console cases and isolated incremental CLI measurements pass. The original premerge remains red on15 independently matched pre-existing failures; preserve the separate integration hold.

This branch has not been deployed

No deployments
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