Skip to content

perf(termux): speed up non-tui cli startup#29438

Closed
adybag14-cyber wants to merge 1 commit into
NousResearch:mainfrom
adybag14-cyber:perf/termux-cold-start
Closed

perf(termux): speed up non-tui cli startup#29438
adybag14-cyber wants to merge 1 commit into
NousResearch:mainfrom
adybag14-cyber:perf/termux-cold-start

Conversation

@adybag14-cyber

@adybag14-cyber adybag14-cyber commented May 20, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Optimizes non-TUI Hermes CLI cold starts on Termux/Android for older single-core mobile devices, while keeping the desktop startup path unchanged.

The previous Termux TUI cold-start work is now upstream. This follow-up targets classic CLI/script invocations:

  • hermes
  • hermes chat ...
  • hermes -z ...
  • hermes --version
  • hermes version

On Termux, obvious non-TUI chat/oneshot/version invocations now use the lightweight top-level/chat parser and skip building the full subcommand tree. --help still falls back to the full parser so complete help output is preserved.

For debugging or exact legacy behavior, set HERMES_TERMUX_DISABLE_FAST_CLI=1.

This also removes two expensive chat-start side effects from the default Termux path:

  • background update prefetch is opt-in on Termux via HERMES_TERMUX_PREFETCH_UPDATES=1
  • bundled skill sync is cached by checkout revision, so unchanged launches avoid rehashing every bundled skill; HERMES_TERMUX_FORCE_SKILLS_SYNC=1 forces the old full sync path

The bundled-skill cache remains update-safe: after a git/update revision changes, the next launch runs a real sync and refreshes the stamp.

Local Termux timing with this branch loaded through the installed Hermes venv:

  • python -m hermes_cli.main --version: median 0.357s before -> 0.222s after
  • python -m hermes_cli.main version: median 0.362s before -> 0.219s after
  • python -m hermes_cli.main chat --bogus: median 0.300s before -> 0.215s after
  • tools.skills_sync.sync_skills(quiet=True): median 0.075s before -> cached Termux skip 0.0001s after
  • python -m hermes_cli.main --help: remains on the full parser, median about 0.32s

Related Issue

N/A

Type of Change

  • ðŸ�› Bug fix (non-breaking change that fixes an issue)
  • ✨ New feature (non-breaking change that adds functionality)
  • 🔒 Security fix
  • ðŸ“� Documentation update
  • ✅ Tests (adding or improving test coverage)
  • â™»ï¸� Refactor (no behavior change)
  • 🎯 New skill (bundled or hub)

Changes Made

  • hermes_cli/main.py
    • Adds a Termux-only fast CLI launch path for obvious non-TUI chat, oneshot, and version invocations.
    • Preserves full-parser behavior for help and non-Termux platforms.
    • Adds HERMES_TERMUX_DISABLE_FAST_CLI=1 as an escape hatch for the new parser shortcut.
    • Extracts agent plugin/MCP/hook startup prep into _prepare_agent_startup() so the full parser and fast parser share the same agent lifecycle setup.
    • Splits version output from update checking so the Termux fast path can avoid synchronous update work.
    • Skips background update prefetch by default on Termux; opt back in with HERMES_TERMUX_PREFETCH_UPDATES=1.
    • Adds a Termux bundled-skill sync stamp keyed by checkout revision; force a real sync with HERMES_TERMUX_FORCE_SKILLS_SYNC=1.
  • tests/hermes_cli/test_tui_resume_flow.py
    • Covers the new Termux non-TUI fast parser for chat, oneshot, version, and help fallback.
    • Covers bundled-skill sync stamp invalidation, cached skip, and forced sync.

How to Test

  1. Syntax check:
    /data/data/com.termux/files/home/.hermes/hermes-agent/.venv/bin/python -m py_compile hermes_cli/main.py tests/hermes_cli/test_tui_resume_flow.py
  2. New focused tests:
    /data/data/com.termux/files/home/.hermes/hermes-agent/.venv/bin/python -m pytest -o addopts='' tests/hermes_cli/test_tui_resume_flow.py::test_termux_fast_cli_launch_chat_uses_light_parser tests/hermes_cli/test_tui_resume_flow.py::test_termux_fast_cli_launch_oneshot_uses_light_parser tests/hermes_cli/test_tui_resume_flow.py::test_termux_fast_cli_launch_version_skips_update_check tests/hermes_cli/test_tui_resume_flow.py::test_termux_fast_cli_launch_skips_help tests/hermes_cli/test_tui_resume_flow.py::test_termux_fast_cli_launch_can_be_disabled tests/hermes_cli/test_tui_resume_flow.py::test_termux_bundled_skills_stamp_controls_sync tests/hermes_cli/test_tui_resume_flow.py::test_termux_skips_bundled_skill_sync_when_stamp_fresh tests/hermes_cli/test_tui_resume_flow.py::test_termux_forced_bundled_skill_sync_runs -q
  3. Startup regression tests:
    /data/data/com.termux/files/home/.hermes/hermes-agent/.venv/bin/python -m pytest -o addopts='' tests/hermes_cli/test_startup_plugin_gating.py -q
    /data/data/com.termux/files/home/.hermes/hermes-agent/.venv/bin/python -m pytest -o addopts='' tests/hermes_cli/test_tui_resume_flow.py -q
    /data/data/com.termux/files/home/.hermes/hermes-agent/.venv/bin/python -m pytest -o addopts='' tests/hermes_cli/test_subparser_routing_fallback.py tests/hermes_cli/test_ignore_user_config_flags.py -q
  4. Diff hygiene:
    git diff --check

Checklist

Code

  • I've read the Contributing Guide
  • My commit messages follow Conventional Commits (fix(scope):, feat(scope):, etc.)
  • I searched for existing PRs to make sure this isn't a duplicate
  • My PR contains only changes related to this fix/feature (no unrelated commits)
  • I've run pytest tests/ -q and all tests pass
  • I've added tests for my changes (required for bug fixes, strongly encouraged for features)
  • I've tested on my platform: Termux on Android, Python 3.11.10

Documentation & Housekeeping

  • I've updated relevant documentation (README, docs/, docstrings) — or N/A
  • I've updated cli-config.yaml.example if I added/changed config keys — or N/A
  • I've updated CONTRIBUTING.md or AGENTS.md if I changed architecture or workflows — or N/A
  • I've considered cross-platform impact (Windows, macOS) per the compatibility guide
  • I've updated tool descriptions/schemas if I changed tool behavior — or N/A

For New Skills

N/A

Screenshots / Logs

Focused test output:

8 passed in 0.87s
37 passed in 1.29s
34 passed in 1.60s
11 passed in 1.07s

Timing output:

top --version: median=0.222s
version cmd: median=0.219s
chat invalid parser: median=0.215s
termux skill sync cached median=0.0001s

@alt-glitch alt-glitch added type/perf Performance improvement or optimization P3 Low — cosmetic, nice to have comp/cli CLI entry point, hermes_cli/, setup wizard labels May 20, 2026
@teknium1

Copy link
Copy Markdown
Contributor

Salvaged onto current main via #30121 (rebase-merge → 2a474bc — your authorship preserved in git log). Cherry-picked your commit and added a follow-up that resolves packed-refs and worktree common-dir loose refs, so the skill-sync stamp invalidates correctly on repos after git gc and on linked worktrees too. Thanks for the Termux cold-start work — fast non-TUI parser, opt-in update prefetch, and stamp-based skill sync all carry your name in the history. First merge for you — appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/cli CLI entry point, hermes_cli/, setup wizard P3 Low — cosmetic, nice to have type/perf Performance improvement or optimization

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants