Skip to content

fix(cli): fully filter session_meta from restored conversations#4790

Open
Disaster-Terminator wants to merge 1 commit intoNousResearch:mainfrom
Disaster-Terminator:fix/cli-session-meta-resume
Open

fix(cli): fully filter session_meta from restored conversations#4790
Disaster-Terminator wants to merge 1 commit intoNousResearch:mainfrom
Disaster-Terminator:fix/cli-session-meta-resume

Conversation

@Disaster-Terminator
Copy link
Copy Markdown

What does this PR do?

This PR fixes the CLI restored-session path so transcript-only metadata such as session_meta does not leak back into provider-facing conversation history.

The issue is that resumed CLI conversations could restore raw session rows and reuse them as normal chat history. When those rows included non-transcript entries like session_meta, strict chat-completions providers could reject the outgoing request because of unsupported roles.

This change fixes that in two places:

  1. CLI restored history is now normalized before being reused, so resumed conversations only keep transcript-safe roles.
  2. The shared API-boundary sanitizer also drops unsupported roles before sending provider requests.

This keeps the fix narrow and defensive:

  • restored CLI conversations behave consistently
  • internal metadata rows do not re-enter conversation_history
  • unsupported roles do not cross the provider boundary even if they appear upstream

Related Issue

Fixes #4715

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

  • Added shared restored-conversation normalization in cli.py
  • Routed all CLI restored-session entry points through the same normalization path:
    • _init_agent()
    • _preload_resumed_session()
    • _handle_resume_command()
  • Ensured restored conversation history drops non-transcript roles such as session_meta
  • Kept API-boundary filtering in run_agent.py so unsupported roles are removed before provider calls
  • Added regression tests covering:
    • _sanitize_api_messages() dropping unsupported roles
    • _preload_resumed_session() filtering restored history
    • _init_agent() resumed-session loading behavior
    • _handle_resume_command() filtering /resume history

How to Test

  1. Create or use a saved CLI session whose restored rows include session_meta
  2. Resume the session through CLI startup resume or the /resume command
  3. Confirm that restored conversation_history contains only transcript-safe roles
  4. Confirm that provider-facing requests no longer include unsupported roles such as session_meta
  5. Run:
    pytest -q tests/test_agent_guardrails.py tests/test_resume_display.py tests/test_cli_resume_command.py

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: Ubuntu 24.04.4 LTS (WSL2), Python 3.11.15

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

Screenshots / Logs

Targeted regression tests passed:

pytest -q tests/test_agent_guardrails.py tests/test_resume_display.py tests/test_cli_resume_command.py
60 passed in 8.05s

I also ran `pytest tests/ -q` for broader signal, but did not use it as a merge gate because the repository test suite surfaced unrelated distributed failures outside this change set before a clean final summary could be captured.

@Disaster-Terminator Disaster-Terminator marked this pull request as ready for review April 3, 2026 16:11
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.

[Bug]: CLI resume/session restore can leak transcript-only session_meta into chat-completions payload

1 participant