Skip to content

Show CLI help before importing delivery backends - #1523

Merged
mergify[bot] merged 2 commits into
mainfrom
lean178/1489-help-startup
Nov 26, 2026
Merged

mergify[bot] merged 2 commits into
mainfrom
lean178/1489-help-startup

Conversation

@eowca

@eowca eowca commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Show CLI help before importing delivery backends

Context and goal

  • Goal: Load just the argument parser for help and load package metadata only for explicit version requests.
  • Problem: The CLI imports review, GitHub, sandbox and queue code before parsing arguments.
  • Context: The audit measured 143.11 ms for CLI help and 63.69 ms for a byte-identical parser-only prototype.

Closes #1489

Acceptance

  • Console script and CLI module help and version preserve existing output and exits.
  • Help launches no tools and imports no delivery backends. Version metadata loads only when requested.
  • Interleaved help benchmark demonstrates the savings. Reuse existing tests with no net test lines.

Validation evidence

31 interleaved fresh processes measured module help at 84.81 ms before and 33.75 ms after. Console help was 81.60 ms before and 35.13 ms after. Top-level and subcommand help, version, and the missing-command error matched byte-for-byte. Focused CLI tests, lint and dependency checks passed. Test lines are net zero.

Base

Base: a68ef3b

Validation

Recorded for 0816ccf8fc80

  • uv run --group dev ruff check src tests: exit 0
  • uv run --group dev tach check: exit 0
  • uv run --python 3.14 python scripts/check_architecture_docs.py: exit 0
  • scripts/size_budget.sh: exit 0
  • uv run --group dev pytest -q: exit 0

Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

Review

  • primary, claude, fecc36d, request_changes
  • delta, claude, 0816ccf, approve

Co-Authored-By: Codex <noreply@openai.com>

@loopzero-feder-positronics loopzero-feder-positronics Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

loopzero primary review by claude on fecc36dba803e7ccf3b0f95bf852a975e851ac23, 46.2s: request_changes (0 critical, 1 important, 3 suggestion)

Settings per native call (launch configuration and CLI claims, not backend attestation):

  • Call 1: requested model claude-opus-5-5 (effort medium); CLI-reported model claude-opus-5-5 (effort unknown); configured model claude-opus-5-5 (effort medium)

Native Claude output is retained in the restricted local review receipt.

Comment thread docs/ARCHITECTURE.md Resolved
Comment thread src/loopzero/cli.py

# Module execution parses help and version before loading delivery code.
if __name__ == "__main__":
_module_args = parse_args(build_parser(), None)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

suggestion: python -m loopzero.cli parses argv twice; _module_args is never used

Under -m, line 9 parses argv into _module_args, and nothing reads it. The if __name__ == "__main__": sys.exit(main()) block at line 1773 then calls main(), which runs build_parser() and parse_args() again, including the stdout reconfigure and the validation. Output stays the same, but this is a dead variable plus duplicated parsing, and the two entry paths can drift apart. Smallest fix: make the bottom block sys.exit(_run(_module_args)), which removes the second parse and gives the early parse a reader.

Comment thread src/loopzero/cli.py Outdated
try:
with _proc.unwind_on_sigterm():
return args.func(args)
handler = getattr(args, "func", None) or globals()[f"cmd_{args.command}"]

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

suggestion: args.func fallback is kept only for one test

The parser no longer sets func, so getattr(args, "func", None) or ... only serves test_progress_output_precedes_the_stderr_verdict_in_one_file. That test injects a parser with func=wait. Production code now dispatches two ways. A simpler option is to dispatch only through globals()[f"cmd_{args.command}"] and have the test monkeypatch cli.cmd_merge (or cli._run) instead.

Comment thread tests/test_cli.py
out = capsys.readouterr().out
assert stop.value.code == 0 and re.fullmatch(r"loopzero \S+ .+\n", out), out
@pytest.mark.parametrize("flag, pattern", [("--version", r"loopzero \S+ .+\n\Z"), ("--help", r"usage: loopzero ")])
def test_cli_info_leaves_delivery_backends_unloaded(flag, pattern):

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

suggestion: Nothing tests the console-script entry point (loopzero._cli_entry:main)

Acceptance requires the console script's help and version output to stay the same and help to load no backends. The rewritten test only runs -m loopzero.cli. _cli_entry.main is the actual [project.scripts] target, and no test imports or calls it, so a regression there (for example, importing loopzero.cli at module level) would go unnoticed. You can cover it without adding test lines by having one parametrized case run -c 'import sys; from loopzero._cli_entry import main; sys.exit(main())' instead of -m loopzero.cli.

Architecture-Review: unchanged; the documented CLI layout stands and the automated parser watch follows its new file

Co-Authored-By: Codex <noreply@openai.com>

@loopzero-feder-positronics loopzero-feder-positronics Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

loopzero delta review by claude on 0816ccf8fc809d76661cd5dd59acbb7a2b1e1641, 20.8s: approve (0 critical, 0 important, 0 suggestion)

Settings per native call (launch configuration and CLI claims, not backend attestation):

  • Call 1: requested model claude-opus-5-5 (effort medium); CLI-reported model claude-opus-5-5 (effort unknown); configured model claude-opus-5-5 (effort medium)

Native Claude output is retained in the restricted local review receipt.

@eowca
eowca marked this pull request as ready for review November 26, 2026 06:51
@eowca

eowca commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

@Mergifyio queue

@mergify

mergify Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

✅ Merged into main as 9fe962b at 06:57 UTC

4 min in the queue, 3 min of it CI.

So far

  • ✅ Entered the queue Thu 26 Nov, 06:52 · rule main · triggered by @eowca with the @mergifyio queue command
  • ✅ Passed · draft #1567
  • ✅ Merged 06:57 · 9fe962b · squash
3 merge conditions met
  • github-review-approved · required by GitHub repository ruleset rule main: PR only, Mergify queue, existing checks required
  • any of · required by GitHub repository ruleset rule main: PR only, Mergify queue, existing checks required:
    • check-success = checks
    • check-neutral = checks
    • check-skipped = checks
  • any of · required by GitHub repository ruleset rule main: PR only, Mergify queue, existing checks required:
    • check-success = Loop-zero Eligibility
    • check-neutral = Loop-zero Eligibility
    • check-skipped = Loop-zero Eligibility

Times in UTC · dashboard · how the merge queue works

@eowca

eowca commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

No description provided.

@mergify
mergify Bot merged commit 9fe962b into main Nov 26, 2026
17 checks passed
@mergify mergify Bot removed the queued label Nov 26, 2026
@eowca
eowca deleted the lean178/1489-help-startup branch November 26, 2026 06:57
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.

Show CLI help before importing delivery backends

1 participant