Skip to content

fix(cli): use Rich [dim] tag instead of ANSI escape in session resume messages - #39482

Merged
kshitijk4poor merged 1 commit into
NousResearch:mainfrom
liuhao1024:fix/rich-markup-error-on-session-resume
Jun 5, 2026
Merged

fix(cli): use Rich [dim] tag instead of ANSI escape in session resume messages#39482
kshitijk4poor merged 1 commit into
NousResearch:mainfrom
liuhao1024:fix/rich-markup-error-on-session-resume

Conversation

@liuhao1024

Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes a rich.errors.MarkupError crash when resuming a session whose recorded working directory is missing or inaccessible. The CLI uses Rich's markup system for styled console output, but 4 locations in _restore_session_cwd and _preload_resumed_session injected an ANSI escape code (_DIM = \x1b[2;3m) inside Rich's [...] tag syntax. Rich interprets the escape bytes as an invalid tag, then fails on the matching [/] close tag.

Related Issue

Fixes #39469

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)

Changes Made

  • cli.py: Replaced [{_DIM}]...[/] with [dim]...[/dim] in 4 locations where _DIM (ANSI escape) was used inside Rich Console.print() markup. This uses Rich's native dim style tag, consistent with existing usage elsewhere in the file (e.g., lines 4322, 4350, 5314).
  • tests/cli/test_cli_resume_command.py: Added 3 regression tests covering the missing-directory, chdir-failure, and success paths of _restore_session_cwd.

How to Test

  1. Start a session: hermes chat
  2. Exit the session
  3. Move or delete the directory the session was started from
  4. Resume the session: hermes chat -r <session_id>
  5. Verify the CLI shows a dim warning instead of crashing with MarkupError
  6. Run pytest tests/cli/test_cli_resume_command.py -xvs — all 15 tests pass

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: macOS

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 — or N/A
  • I've updated tool descriptions/schemas if I changed tool behavior — or N/A

Code Intelligence

  • Analyzed: cli.py:_restore_session_cwd() (lines 5350-5401), cli.py:_preload_resumed_session() (line 5100)
  • Callers: _preload_resumed_session called from run(), _restore_session_cwd called from _preload_resumed_session and _do_resume
  • Blast radius: LOW — 4 string-literal replacements in a single method; no control flow changes, no API changes
  • Related patterns: [dim] Rich tag already used at lines 4322, 4350, 5314 in the same file; _DIM ANSI escape remains safe in _cprint() calls (prompt_toolkit renderer, not Rich)

…on_cwd

Replace [{_DIM}] with [dim] in all _restore_session_cwd and
_preload_resumed_session messages that go through _console_print (Rich
Console.print).  _DIM is an ANSI escape (\x1b[2;3m) that Rich cannot
parse as a markup tag, causing MarkupError on session resume when the
stored cwd is missing or inaccessible.

Also uses [/dim] closing tag for explicit tag matching.

Fixes NousResearch#39469
@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 Jun 5, 2026

@tonydwb tonydwb 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.

Code Review Summary

Verdict: Approved

Regression fix for a rich.errors.MarkupError that occurred when _restore_session_cwd displayed dimmed warning/info messages using the ANSI escape variable _DIM inside Rich markup strings.

✅ Looks Good

  • Root cause is correctly diagnosed: [{_DIM}] is a Rich variable interpolation, but _DIM resolves to a raw ANSI escape (\x1b[2;3m), not a valid Rich tag name — causing a markup parse error.
  • Fix replaces [{_DIM}]...[/] with Rich's native [dim]...[/dim] tag, which is the correct approach.
  • Three regression tests added covering all affected paths: missing dir, chdir failure, and success case — all assert console.print was called without raising MarkupError.

No concerns

  • Minimal, targeted change with no side effects.
  • New tests use unittest.mock.MagicMock and unittest.mock.patch correctly.

Reviewed by Hermes Agent

@kshitijk4poor
kshitijk4poor merged commit 66a6b9c into NousResearch:main Jun 5, 2026
23 checks passed
alt-glitch pushed a commit that referenced this pull request Jun 14, 2026
…ssion-resume

fix(cli): use Rich [dim] tag instead of ANSI escape in session resume messages
T02200059 pushed a commit to T02200059/hermes-agent that referenced this pull request Jun 18, 2026
…-error-on-session-resume

fix(cli): use Rich [dim] tag instead of ANSI escape in session resume messages
waefrebeorn pushed a commit to waefrebeorn/slermes that referenced this pull request Jul 2, 2026
…-error-on-session-resume

fix(cli): use Rich [dim] tag instead of ANSI escape in session resume messages
santhreal pushed a commit to santhreal/hermes-agent that referenced this pull request Jul 13, 2026
…-error-on-session-resume

fix(cli): use Rich [dim] tag instead of ANSI escape in session resume messages
Gravezzz pushed a commit to Gravezzz/hermes-agent that referenced this pull request Jul 21, 2026
…-error-on-session-resume

fix(cli): use Rich [dim] tag instead of ANSI escape in session resume messages
leewenjie pushed a commit to leewenjie/hermes-agent that referenced this pull request Aug 7, 2026
…-error-on-session-resume

fix(cli): use Rich [dim] tag instead of ANSI escape in session resume messages
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 type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Rich MarkupError on session resume — ANSI _DIM mixed with Rich [/] close tag

4 participants