Skip to content

fix(cli): tolerate missing current working directory - #10233

Open
OolonColoophid wants to merge 1 commit into
NousResearch:mainfrom
OolonColoophid:fix/missing-cwd-startup
Open

fix(cli): tolerate missing current working directory#10233
OolonColoophid wants to merge 1 commit into
NousResearch:mainfrom
OolonColoophid:fix/missing-cwd-startup

Conversation

@OolonColoophid

@OolonColoophid OolonColoophid commented Apr 15, 2026

Copy link
Copy Markdown

Summary

  • handle FileNotFoundError when load_cli_config() resolves terminal.cwd from os.getcwd()
  • clear stale TERMINAL_CWD when the working directory is gone or auto-cwd is unset
  • add a regression test covering startup from a deleted current directory

Why

If Hermes is launched from a shell whose current working directory has been deleted or moved, os.getcwd() raises FileNotFoundError during CLI startup. This change makes Hermes fall back safely instead of crashing.

Test Plan

  • pytest tests/cli/test_cli_init.py::TestLoadCliConfig::test_missing_current_working_directory_falls_back_safely -q
  • pytest tests/cli/test_cli_init.py tests/hermes_cli/test_config_env_expansion.py tests/tools/test_modal_sandbox_fixes.py -q
  • manually verified hermes --help succeeds from a deleted cwd

Disclosure

This PR was prepared by Rook, an AI coding assistant, and reviewed by Ian before opening.

@OolonColoophid
OolonColoophid force-pushed the fix/missing-cwd-startup branch from 415dbbb to 77bf9d3 Compare April 15, 2026 10:57
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/cli CLI entry point, hermes_cli/, setup wizard labels Apr 26, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Likely duplicate of #4982 — same fix guarding os.getcwd() against FileNotFoundError from deleted CWD.

@teknium1 teknium1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the focused deleted-CWD startup fix. The underlying CLI failure still exists on current main, but this patch needs a narrow port to the newer CWD-resolution path.

Problems

  • The unguarded startup call is now cli.py:602, and CLI_CONFIG = load_cli_config() still executes it at import time (cli.py:728). The PR hunk targets the older branch and GitHub reports the PR as conflicting.
  • Current main protects gateway lazy imports with _HERMES_GATEWAY (gateway/run.py:1292-1294) and skips rewriting its resolved CWD (cli.py:646-653). Porting the added unconditional TERMINAL_CWD removal would erase that gateway value when getcwd() fails.

Suggested changes

  • Apply the guard around the current local-backend branch at cli.py:601-603 and retain the existing gateway preservation contract.
  • Add a direct-loader regression test for the deleted-CWD path plus a gateway-marker preservation case.

Automated hermes-sweeper review.

Comment thread cli.py
logger.warning("Current working directory no longer exists; leaving terminal.cwd unset")
terminal_config.pop("cwd", None)
defaults["terminal"].pop("cwd", None)
os.environ.pop("TERMINAL_CWD", None)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

When porting this to current main, do not clear TERMINAL_CWD for a gateway lazy import. gateway/run.py:1292-1294 sets _HERMES_GATEWAY to preserve its resolved CWD, and current cli.py:646-653 honors that contract.

@teknium1 teknium1 added sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform labels Jul 12, 2026
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 P2 Medium — degraded but workaround exists sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants