Skip to content

perf(cli): reuse selected dispatch for manager Inbox commands - #6989

Open
hhyykk wants to merge 1 commit into
loopx-project:mainfrom
hhyykk:codex/inbox-cli-caller-adoption-20261021
Open

hhyykk wants to merge 1 commit into
loopx-project:mainfrom
hhyykk:codex/inbox-cli-caller-adoption-20261021

Conversation

@hhyykk

@hhyykk hhyykk commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

Goal And Delivered Outcome

Normal manager-inbox commands load the full compatibility CLI, although the selected-command dispatcher already provides the same parser and native runtime request scope. This adopts that existing path and deletes the duplicate compatibility dispatch branch. Inbox command inputs, outputs, guards and durable effects stay the same; unrelated CLI imports disappear.

  • Basis: TypeScript control-plane migration RFC, Stage 3 caller adoption, at 68e99ad93ef1954a0bf90ad7158ffb85cf365f2d.
  • Before → after: the same result publication/replay test fails on the old entrypoint with unexpected module import: loopx.cli and passes with identical response/receipt bytes on the new entrypoint.
  • Base: main; complete within this CLI scope.

Author Declaration

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

Implemented against

Specification: docs/architecture/rfcs/typescript-control-plane-migration-v0.md, revision 68e99ad93ef1954a0bf90ad7158ffb85cf365f2d.

Criterion Disposition Path / evidence
Stage 3: actual caller consumes the existing migrated control path implemented loopx/cli_runtime.py, normal installed CLI
Retire replaced orchestration in the same change implemented old Inbox branch removed from loopx/cli.py; compatibility CLI uses the shared dispatcher
Preserve authority, live source reads and receipts implemented unchanged existing handler/native owners; refusal, publication, replay, conflict and controlled revision checks
Complete R1–R3 / asynchronous delivery migration out_of_scope no completion claim; existing #6855 remains separate

Self-check: production, test and docs guard review; related tests, real disposable File/SQLite records, installed artifacts and fresh main integration. No real model or external delivery qualification claimed.

Scope And Continuation

  • Reuse existing registration, handler, registry/runtime-root resolution and native-controller guard.
  • The existing common dispatcher resolves executable revision once per command. This reuses that scope; source records remain live reads under their existing locks. There is no cross-command data cache.
  • Production economics: 14 added / 14 removed, net 0 lines; no new bridge, dependency, native operation, schema or store. Python provider IO and existing TypeScript semantic owners remain unchanged. RPC counts remain one per File/SQLite result publication, two for the controlled source-session path.
  • Reviewed the 48-PR discovery inventory and refreshed against all 47 currently open PRs, including changed planning/turn heads. No other reviewed PR touches cli_runtime.py or changes Inbox dispatch hunks. refactor(todos): compose full readback in one TypeScript transaction #6874/perf(control-plane): reuse acceptance reads within one Todo snapshot #6984 concern Todo reads; refactor(collaboration): converge return delivery and restart recovery in TypeScript #6855 concerns return delivery/recovery. Shared RFC/README edits and unrelated cli.py hunks are acknowledged; there is no duplicate implementation.
  • An additional native result-store prototype was tested then excluded: caller adoption produced most of the measured benefit with a smaller compatibility surface. No prototype scaffolding is in this diff.

Validation

  • Tested revision: d941ee98c599e6edf5a006d14e6cbe8e07010b86 on 68e99ad93ef1954a0bf90ad7158ffb85cf365f2d.
  • Run state: finished. Input classes: synthetic, public_fixture.
Check kind Result Evidence / limitation
integration passed 325 Python tests covering CLI, manager-context roundtrip, Goal identity, peer store, request amendment/recovery, Inbox recovery and executable request scope; run before rebase, unchanged relevant production/test files
integration passed 63 CLI entrypoint + task-planning tests rerun on final rebased HEAD
unit passed 37 related TS Inbox read/receipt/result-publication/request-control contracts; no TS product diff
static passed control-plane typecheck, scoped Ruff and paired RFC check
regression_parity passed 22 semantic rows across File, SQLite and controlled exact source sessions, plus reverse SQLite run; persisted records equal; rejected operations produce no writes; recording remains delivered:false
regression_parity passed same final regression test loaded against baseline fails on full CLI import and passes on candidate, with independently verified module roots
real_entrypoint passed 240 source-verified fresh Python CLI processes on pinned baseline/candidate series; another 60 fresh processes and seven semantic rows on final main/HEAD
real_backend passed disposable real File and SQLite records; no production state or external provider sends
integration passed normal wheel + sdist builds at final HEAD; independent installed environments, empty-project cwd, no source PYTHONPATH; legacy/exact request, acknowledge, report, separate-process replay, conflict refusal and readback

Complete-command performance

Linux; Python 3.11; Node 24.21.0 / SQLite 3.53.4; disposable synthetic Goal. Each sample starts a fresh Python CLI process, uses a warm managed native runtime and records a new result update. Includes parsing, imports, registry lookup, source reads, RPC and durable result recording. The harness asserts loaded Python and TS roots; each child emits a source-origin proof. No timestamp normalization beyond a fixed semantic-fixture clock and disposable-root substitution.

Fresh final comparison: main 68e99ad93ef1954a0bf90ad7158ffb85cf365f2d versus this HEAD, 15 samples per arm per history; all seven SQLite semantic/persisted-state observations match.

SQLite history p50 ms, base → head p95 ms, base → head p95 change
Small 1034.7 → 371.7 1072.4 → 522.8 -51.3%
Expanded (+32 appended updates) 1035.7 → 351.0 1147.4 → 395.0 -65.6%

Supporting pinned-base repeated/reversed SQLite series (30 samples/arm/history) measured p95 1,096.8 → 386.7 ms and 1,135.5 → 363.6 ms. File/controlled profiles (15/arm) also improved. That earlier baseline was 98709770d80e9c332f3c07d2b545226a6dd17521; the five measured runtime files have unchanged hashes after rebase. Earlier cwd-contaminated and CPU-contended study runs were excluded, not pooled into these figures.

These results qualify this CLI overhead change only. They do not measure task success, model quality, token savings, cold native-runtime startup or the entire LoopX application. Full repository tests, Windows, PostgreSQL, browser flows and real model/provider delivery were not run for this scoped change; hosted CI is separate.

Portable qualification harness and reproduction

Save the script below as qualify.py outside both checkouts. Install repository Python dependencies and run npm ci in both checkouts. Use a qualified Node runtime (the run above used 24.21.0 / SQLite 3.53.4), the same Python interpreter, and idle the machine. Outputs must be separate empty directories. Run sequentially:

python3 qualify.py BASE_CHECKOUT BASE_EVIDENCE --providers file,sqlite,controlled --samples 15
python3 qualify.py HEAD_CHECKOUT HEAD_EVIDENCE --providers file,sqlite,controlled --samples 15

Compare receipt.json rows for exact equality; performance contains every sample and method count, and subprocess_import_receipts proves actual module origins. Synthetic fixtures only; the script disables usage pings and stops its managed native runtime.

Harness SHA256: 703773c33713122c8bbcbfccd7e2201e49573f18f102998d464f55beb8833742.

import argparse,contextlib,hashlib,io,json,os,statistics,subprocess,sys,tempfile,time
from pathlib import Path
p=argparse.ArgumentParser();p.add_argument('repo');p.add_argument('out');p.add_argument('--samples',type=int,default=15);p.add_argument('--providers',default='file,sqlite,controlled');p.add_argument('--history',type=int,default=32);args=p.parse_args()
repo=Path(args.repo).resolve();out=Path(args.out).resolve();out.mkdir(parents=True,exist_ok=True)
os.environ.update(LOOPX_USAGE_PING='0',PYTHONDONTWRITEBYTECODE='1',TMPDIR=str(out/'tmp'),TEMP=str(out/'tmp'),TMP=str(out/'tmp'))
Path(os.environ['TMPDIR']).mkdir(exist_ok=True);tempfile.tempdir=os.environ['TMPDIR']
sys.path[:0]=[str(repo),str(repo/'tests'),str(repo/'tests/control_plane')]
import loopx
from loopx.entrypoint import main
from loopx.control_plane import effect_runtime
from loopx.control_plane.collaboration import inbox,peers,request_control_source
from test_collaboration_goal_instance import _create_source_registry,_brief
from canonical_authority_fixture import promoted_create_fixture
for owner in [inbox,peers,request_control_source]:owner._now=lambda:'2026-10-21T00:00:00+00:00'
assert Path(loopx.__file__).resolve()==repo/'loopx/__init__.py'
assert effect_runtime._control_plane_root().resolve()==repo/'loopx/control_plane'
import_receipts=[]
calls=[];transport=[];original=effect_runtime._request_with_info

def capture(*a,**kw):
 calls.append(kw['method']);began=time.perf_counter();reply=original(*a,**kw)
 transport.append({'method':kw['method'],'params_utf8_bytes':len(json.dumps(kw['params'],ensure_ascii=False,separators=(',',':')).encode()),'ms':(time.perf_counter()-began)*1000});return reply
effect_runtime._request_with_info=capture

def command(root,registry,goal,agent,rid,action,*extra):
 return ['--registry',str(registry),'--runtime-root',str(root),'--format','json','manager-inbox',action,'--goal-id',goal,'--agent-id',agent,'--request-id',rid,*extra]

def invoke(argv):
 stream=io.StringIO();calls.clear();transport.clear();began=time.perf_counter()
 with contextlib.redirect_stdout(stream):code=main(argv)
 return {'exit_code':code,'value':json.loads(stream.getvalue()),'methods':list(calls),'transport':list(transport),'ms':(time.perf_counter()-began)*1000}

def normal(value):
 if isinstance(value,dict):return {k:normal(v) for k,v in value.items()}
 if isinstance(value,list):return [normal(v) for v in value]
 if isinstance(value,str):return value.replace(str(out),'<fixture>')
 return value

def observations(root):
 base=root/'.local/manager-context'
 return {str(f.relative_to(base)):normal(json.loads(f.read_text())) for f in sorted(base.rglob('*.json')) if any(x in f.parts for x in ('entries','decisions','replies'))}

def percentile(values,q):return sorted(values)[min(len(values)-1,int((len(values)-1)*q+.5))]

all_rows=[];perf=[];clock_contract='fixed Inbox/peer/source-control clock for semantic rows; real clock in subprocess performance runs'
try:
 for provider in args.providers.split(','):
  folder=out/provider;folder.mkdir(exist_ok=True)
  if provider=='controlled':
   registry=_create_source_registry(folder);root=folder;goal='delivery';sender='builder';agent='reviewer';ref={'goal_id':goal,'goal_instance_id':'ginst_'+'a'*32}
   from loopx.control_plane.projects.registry_codec import source_session_registry_transaction
   with source_session_registry_transaction(registry,operation='fixture_runtime') as tx:
    configured=tx.payload_copy();configured['common_runtime_root']=str(root);tx.commit(configured)
  else:
   registry,root,_=promoted_create_fixture(folder,provider=provider,registered_agents=['builder','reviewer']);goal='goal-a';sender='builder';agent='reviewer';ref=None
  receipt=peers.request(root,registry,goal,sender,agent,'qualified-review',_brief('Review exact fixture'),caller_goal_ref=ref)
  rid=receipt['request_id'];revision=[]
  if provider=='controlled':
   kw=dict(registry_path=registry,runtime_root=root,goal_ref=ref,receiver_agent_id=agent,request_id=rid,actor_agent_id=sender)
   view=request_control_source.execute_request_control(**kw,operation='inspect')['view']
   revised=request_control_source.execute_request_control(**kw,operation='revise',parameters={'operation_id':'correction','expected_revision':view['revision'],'expected_digest':view['revision_digest'],'brief':_brief('Review corrected evidence'),'reason':'Use current source'},execute=True)
   revision=['--request-revision','2','--request-digest',revised['view']['revision_digest']]
  ack=command(root,registry,goal,agent,rid,'acknowledge','--decision','adopt','--reason','Reviewed exact evidence',*revision)
  report=command(root,registry,goal,agent,rid,'report','--phase','conclusion','--reply-text','The independent fixture review passed.',*(['--request-revision','2'] if provider=='controlled' else []))
  rows=[('unassessed-report',report,1),('ack',ack,0),('ack-replay',ack,0),('conflicting-decision',command(root,registry,goal,agent,rid,'acknowledge','--decision','reject','--reason','Different assessment',*revision),1)]
  if provider=='controlled':rows.append(('stale-revision',command(root,registry,goal,agent,rid,'acknowledge','--decision','adopt','--reason','Reviewed exact evidence','--request-revision','1'),1))
  rows += [('report',report,0),('report-replay',report,0),('conflicting-result',command(root,registry,goal,agent,rid,'report','--phase','conclusion','--reply-text','A conflicting result.',*(['--request-revision','2'] if provider=='controlled' else [])),1)]
  for name,argv,expected in rows:
   before=observations(root);result=invoke(argv);after=observations(root)
   assert result['exit_code']==expected and result['value']['ok']==(expected==0),(provider,name,result)
   if expected:assert before==after,(provider,name,'rejected operation wrote state')
   if name.startswith('report'):assert result['value'].get('delivered') is False,(provider,name,'recording is not delivery')
   all_rows.append({'provider':provider,'case':name,'exit_code':result['exit_code'],'observation':normal(result['value']),'methods':result['methods'],'persisted':after})
  env={**os.environ,'PYTHONPATH':os.pathsep.join([str(repo),str(repo/'tests'),str(repo/'tests/control_plane')])}
  for history in ([0,args.history] if args.samples else []):
   for n in range(history):
    seeded=invoke([*report,'--update-id',f'history-{n}']);assert seeded['exit_code']==0,seeded
   warm=[];full=[]
   for n in range(args.samples):
    sample=invoke([*report,'--update-id',f'warm-{history}-{n}']);assert sample['exit_code']==0,sample;warm.append(sample)
   for n in range(args.samples):
    began=time.perf_counter();pr=subprocess.run([sys.executable,'-c','import pathlib,sys,loopx; actual=pathlib.Path(loopx.__file__).resolve(); assert actual==pathlib.Path('+repr(str(repo/'loopx/__init__.py'))+'); sys.stderr.write("QUALIFIED_SOURCE="+str(actual)+"\\n"); from loopx.entrypoint import main; raise SystemExit(main())',*report,'--update-id',f'cli-{history}-{n}'],cwd=repo,env=env,capture_output=True,text=True,timeout=60)
    assert pr.returncode==0,(pr.stdout,pr.stderr);assert json.loads(pr.stdout).get('delivered') is False
    actual=next(line.removeprefix('QUALIFIED_SOURCE=') for line in pr.stderr.splitlines() if line.startswith('QUALIFIED_SOURCE='));assert Path(actual)==repo/'loopx/__init__.py';import_receipts.append({'provider':provider,'history_seed':history,'sample':n,'module':actual,'verified':True})
    full.append((time.perf_counter()-began)*1000)
   rpc=[v['ms'] for sample in warm for v in sample['transport']]
   perf.append({'provider':provider,'history_seed':history,'warm_p50_ms':statistics.median(v['ms'] for v in warm),'warm_p95_ms':percentile([v['ms'] for v in warm],.95),'full_cli_p50_ms':statistics.median(full),'full_cli_p95_ms':percentile(full,.95),'warm_samples':[v['ms'] for v in warm],'full_cli_samples':full,'methods':warm[-1]['methods'],'params_utf8_bytes':sum(v['params_utf8_bytes'] for v in warm[-1]['transport']),'rpc_p50_ms':statistics.median(rpc),'rpc_p95_ms':percentile(rpc,.95)})
   print(json.dumps({'provider':provider,'history_seed':history,'full_cli_p95_ms':perf[-1]['full_cli_p95_ms'],'methods':perf[-1]['methods']}),flush=True)
 document={'revision':subprocess.check_output(['git','-C',str(repo),'rev-parse','HEAD'],text=True).strip(),'harness_sha256':hashlib.sha256(Path(__file__).read_bytes()).hexdigest(),'clock_contract':clock_contract,'python_module':str(Path(loopx.__file__).resolve()),'native_module_root':str(effect_runtime._control_plane_root().resolve()),'subprocess_import_receipts':import_receipts,'rows':all_rows,'performance':perf,'candidate_files_sha256':{str(f.relative_to(repo)):hashlib.sha256(f.read_bytes()).hexdigest() for f in [repo/'loopx/control_plane/collaboration/inbox.py',repo/'loopx/control_plane/collaboration/inbox_read.ts',repo/'loopx/control_plane/effect_runtime_handlers.ts',repo/'loopx/cli.py',repo/'loopx/cli_runtime.py']}}
 (out/'receipt.json').write_text(json.dumps(document,indent=2)+'\n');print(json.dumps({'rows':len(all_rows),'status':'complete'}),flush=True)
finally:effect_runtime.restart_effect_runtime()

Frontend / Visual Evidence

UI impact: none. No dashboard, browser behavior or presentation surface changes; the paired RFC text documents caller ownership only.

Change Area

  • Control plane (CLI caller adoption)

Technical Direction

Existing TypeScript control-plane migration, Stage 3 caller adoption. Semantic ownership is unchanged.

Shared-authority RFC fixture impact

  • Fixture schema: disposable Goal, registered sender/receiver, collaboration brief, request/decision/result records; File, default SQLite and exact controlled source-session arms.
  • Reviewed no-impact rationale: no authority/schema/provider routing/compatibility projection changes; request validity, revision, refusal, replay and conflict observations remain equal. Existing locks and receiver identity handling remain in the original handler.
  • Provider conformance: File, SQLite, controlled source-session; installed legacy/exact profiles.
  • Read-only legacy/file/PostgreSQL three-arm promotion rehearsal: not run. This PR does not promote a provider or change authority/runtime backend routing; full PostgreSQL/R1–R3 qualification remains outside this CLI dispatch scope.

Boundary Checklist

  • Public-safe diff and description; no private data, raw traces, credentials, internal URLs or machine paths.
  • Existing work reviewed; no duplicate maintainer benchmark project.
  • Scoped to the requested caller improvement.
  • Both RFC languages changed; python3 scripts/check_rfc_bilingual.py --base origin/main --head HEAD passes.
  • UI impact none.
  • DCO sign-off included.

Signed-off-by: aihop <4408344+hhyykk@users.noreply.github.com>

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.

1 participant