Skip to content

[codex] Preserve agent continuity across cache and compression paths - #47639

Draft
changw98ic wants to merge 1 commit into
NousResearch:mainfrom
changw98ic:codex/preserve-agent-continuity
Draft

[codex] Preserve agent continuity across cache and compression paths#47639
changw98ic wants to merge 1 commit into
NousResearch:mainfrom
changw98ic:codex/preserve-agent-continuity

Conversation

@changw98ic

Copy link
Copy Markdown

Summary

This PR tightens several continuity boundaries in the agent runtime:

  • Preserve Codex backend cache routing by sending request-level session_id and x-client-request-id headers for stable prompt-cache keys.
  • Flush the current conversation tail before compression rotates the session, so session persistence and memory extraction do not drop the active turn.
  • Recover complete tool-call markup emitted as Anthropic text into normalized tool calls.
  • Coerce hermes config set values based on the known default type, avoiding boolean coercion for string enums such as approvals.mode=off.
  • Wait briefly for in-flight MCP discovery before agent construction and log MCP discovery failures with actionable warning context.
  • Handle non-text macOS keychain stdout defensively when reading Claude Code credentials.

Validation

  • git diff --check
  • .venv/bin/python -m pytest tests/hermes_cli/test_set_config_value.py tests/hermes_cli/test_mcp_startup.py tests/tui_gateway/test_wait_for_mcp_discovery.py -q
    45 passed
  • .venv/bin/python -m pytest tests/agent/transports/test_codex_transport.py tests/agent/transports/test_transport.py -q
    80 passed, 1 warning
  • .venv/bin/python -m pytest tests/run_agent/test_compression_boundary_hook.py tests/run_agent/test_compression_persistence.py -q
    13 passed, 1 warning
  • Live Codex cache probe with request-level session headers: second request reported cached_tokens=5376.

Full-suite note

I also ran scripts/run_tests.sh after creating a local .venv. The run completed with 30975 passed, 57 failed, and 4 per-file timeouts. I did not treat that as a green full-suite because the failures were traced to local environment and runner constraints:

  • local DNS maps github.com, example.com, and cdn.discordapp.com to 198.18.0.x, triggering SSRF protections in browser/web/Discord/Matrix tests;
  • wecom optional extra was missing initially; installing it made tests/gateway/test_wecom_callback.py pass;
  • macOS lacks Linux systemctl / user D-Bus for systemd tests;
  • /tmp resolves to /private/tmp on macOS;
  • the per-file runner timeout is 140s while slow files pass individually, e.g. tests/run_agent/test_run_agent.py passed standalone in 322s.

Several agent paths were losing continuity at boundaries: config writes coerced string enums as booleans, Codex backend requests dropped request-level cache identifiers, compression could rotate sessions before flushing the current tail, Anthropic text-emitted tool calls were left as plain text, and early agent construction could miss MCP discovery results.

This keeps the fixes narrow to existing provider, config, compression, and startup paths, with regression coverage for each behavior instead of adding new core surface.

Constraint: Per-conversation prompt caching and session persistence are load-bearing Hermes invariants.

Rejected: Add new tool or provider surfaces | these were boundary fixes in existing code paths.

Confidence: medium

Scope-risk: moderate

Directive: Do not remove Codex backend request-level session_id / x-client-request-id headers without re-running a live cache-hit probe.

Tested: git diff --check

Tested: .venv/bin/python -m pytest tests/hermes_cli/test_set_config_value.py tests/hermes_cli/test_mcp_startup.py tests/tui_gateway/test_wait_for_mcp_discovery.py -q (45 passed)

Tested: .venv/bin/python -m pytest tests/agent/transports/test_codex_transport.py tests/agent/transports/test_transport.py -q (80 passed, 1 warning)

Tested: .venv/bin/python -m pytest tests/run_agent/test_compression_boundary_hook.py tests/run_agent/test_compression_persistence.py -q (13 passed, 1 warning)

Tested: live Codex cache probe with request-level session headers: second request reported cached_tokens=5376.

Not-tested: Green full-suite in this macOS/DNS environment; scripts/run_tests.sh completed earlier with 30975 passed, 57 failed, and 4 file timeouts, traced to local DNS/SSRF behavior, optional extras, macOS systemd gaps, path normalization, and runner timeout limits.
@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 comp/cli CLI entry point, hermes_cli/, setup wizard comp/tui Terminal UI (ui-tui/ + tui_gateway/) provider/openai OpenAI / Codex Responses API provider/anthropic Anthropic native Messages API labels Jun 17, 2026
@teknium1

Copy link
Copy Markdown
Contributor

Thanks for collecting several continuity cases. One configuration bug is still present on current main: hermes_cli/config.py:8157-8165 globally converts off to False, even though approvals.mode is a string enum in DEFAULT_CONFIG (hermes_cli/config.py:2533-2536). The type-aware coercion and regression test are worth preserving as a focused salvage.

Problems

  • The new Anthropic parser converts plain text markup into executable tool calls. Current main deliberately strips standalone tool-call markup instead (agent/agent_runtime_helpers.py:641-664; tests/run_agent/test_run_agent.py:453-496). Please do not add a new model-output reconstruction path without a focused reproduction and end-to-end safety case.
  • The fixed six-second MCP wait conflicts with the current configurable, cache-safe late-refresh design (hermes_cli/config.py:1359-1372; hermes_cli/mcp_startup.py:87-100).
  • Codex cache headers and compression-tail persistence are already implemented on main (agent/transports/codex.py:332-354, commit 4d39a603d; agent/conversation_compression.py:765-775, commit 81ff916e5).

Suggested changes

  • Split and salvage only the config coercion fix with its regression test.
  • Drop the text-to-tool-call and fixed-wait portions unless independently reworked against current main.

Automated hermes-sweeper review.

@teknium1 teknium1 added sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state sweeper:risk-security-boundary Sweeper risk: may affect sandboxing, auth, credentials, or sensitive data sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:risk-caching Sweeper risk: may break/degrade prompt caching or cache-key stability (invariant) sweeper:blast-broad Sweeper blast radius: broad — a core path most sessions hit area/compression Context compression and continuation sessions labels Jul 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/compression Context compression and continuation sessions comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint comp/cli CLI entry point, hermes_cli/, setup wizard comp/tui Terminal UI (ui-tui/ + tui_gateway/) P2 Medium — degraded but workaround exists provider/anthropic Anthropic native Messages API provider/openai OpenAI / Codex Responses API sweeper:blast-broad Sweeper blast radius: broad — a core path most sessions hit sweeper:risk-caching Sweeper risk: may break/degrade prompt caching or cache-key stability (invariant) sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:risk-security-boundary Sweeper risk: may affect sandboxing, auth, credentials, or sensitive data sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants