Skip to content

fix(agent): fallback to latin-1 when loading repo .env in hermes_base_env - #6505

Closed
Dusk1e wants to merge 2 commits into
NousResearch:mainfrom
Dusk1e:fix/env-loading-unicode-fallback
Closed

fix(agent): fallback to latin-1 when loading repo .env in hermes_base_env#6505
Dusk1e wants to merge 2 commits into
NousResearch:mainfrom
Dusk1e:fix/env-loading-unicode-fallback

Conversation

@Dusk1e

@Dusk1e Dusk1e commented Apr 9, 2026

Copy link
Copy Markdown
Contributor

Windows users often run into a UnicodeDecodeError right at the start because their .env files might be saved in regional encodings (like cp1252) rather than pure UTF-8. Since this happens during the initial import of hermes_base_env, it effectively bricks the environment before it even starts.

I've updated the loading logic to be more resilient. It now tries UTF-8 first, and if that fails, it falls back to Latin-1 instead of crashing. This ensures the agent can still boot even if there are non-ASCII characters in the config.

Key changes:

  • Wrapped the file read in a helper that handles the encoding fallback.
  • Added a regression test that specifically mocks a decode failure to verify the fallback path.

Test run: python -m pytest tests/environments/test_hermes_base_env_env_loading.py passed with 48 checks.

@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint area/config Config system, migrations, profiles labels Apr 30, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Related to #8415 (unified .env loading), #7098 (same fix, marked as dup of this). This is the original PR for UTF-8/latin-1 .env fallback.

1 similar comment
@alt-glitch

Copy link
Copy Markdown
Collaborator

Related to #8415 (unified .env loading), #7098 (same fix, marked as dup of this). This is the original PR for UTF-8/latin-1 .env fallback.

@teknium1

Copy link
Copy Markdown
Contributor

Thanks for the Windows encoding resilience work. This is an automated hermes-sweeper review; the requested behavior is already implemented on current main through the unified dotenv loader.

  • hermes_cli/env_loader.py:154-158 loads UTF-8 first and retries with encoding="latin-1" on UnicodeDecodeError.
  • hermes_cli/env_loader.py:263-265 applies that helper to project .env files, and active startup paths such as run_agent.py:127 use this shared loader.
  • The implementation was introduced in f24c00a5bf8845fd07e059cce3ded7056af9fec2 (fix(config): reload .env over stale shell overrides), before this PR was opened.
  • The member discussion linking fix(cli): load Hermes dotenv in mini_swe and sample_and_compress #8415 and duplicate fix(env): add encoding fallback for .env loading in base environment #7098 aligns with this unified-loader implementation. The PR's environments/hermes_base_env.py target no longer exists on current main.

Closing as implemented on main.

@teknium1 teknium1 closed this Jul 12, 2026
@teknium1 teknium1 added the sweeper:implemented-on-main Sweeper: behavior already present on current main label Jul 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/config Config system, migrations, profiles comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint P2 Medium — degraded but workaround exists sweeper:implemented-on-main Sweeper: behavior already present on current main type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants