Skip to content

The agent that grows with you

chore: merge origin/main (resolve website/docs/user-guide/features/codex-app-server-runtime.md)

teknium1bf6977fe1683
diff --cc agent/codex_runtime.py
index 0c03bd6ef23,2b1736359a1..6771b62d27b
--- a/agent/codex_runtime.py
+++ b/agent/codex_runtime.py
@@@ -382,27 -451,14 +451,29 @@@ def _consume_user_interrupt(agent, acti
return interrupted, message
+def _codex_developer_instructions(agent) -> str:
+ """The prompt composition the standard loop sends as its system message (turn_context order)."""
+ developer_instructions = getattr(agent, "_cached_system_prompt", None) or ""
+ if getattr(agent, "ephemeral_system_prompt", None):
+ developer_instructions = (developer_instructions + "\n\n" + agent.ephemeral_system_prompt).strip()
+ return developer_instructions
+
+
def _ensure_codex_session(agent) -> None:
- """Lazily spawn one CodexAppServerSession per AIAgent (reused across turns, closed by the _cleanup hook)."""
+ """Lazily spawn one CodexAppServerSession per AIAgent (reused across turns, closed by the _cleanup hook).
+ A live session whose thread was started with a different prompt composition (TUI/Desktop ``/personality``
+ or a prompt mirror mutate the agent in place) is retired first so the new thread carries the current one."""
+ developer_instructions = _codex_developer_instructions(agent)
if getattr(agent, "_codex_session", None) is not None:
- return
+ # Only a session whose recorded composition differs is stale; one attached without a record is kept.
+ recorded = getattr(agent, "_codex_session_prompt", None)
+ if recorded is None or recorded == developer_instructions:
+ return
+ _close_codex_session(agent)
from agent.runtime_cwd import resolve_agent_cwd
from agent.transports.codex_app_server_session import CodexAppServerSession, _ServerRequestRouting
+ from hermes_cli.codex_runtime_switch import get_configured_codex_binary
+ from hermes_cli.config import load_config
# Approval callback: Hermes' standard prompt flow when a CLI thread installed one.
approval_callback = None
with suppress(Exception):
@@@ -421,16 -477,11 +492,17 @@@
# _emit_interim_assistant_message). Without this, Discord/Telegram users see no live tool-progress or
# interim commentary while codex_app_server is running — only the final answer (#33200). Supersedes the
# narrower item/started-only bridge from #38835.
+ # Hermes owns the prompt: the same composition the standard loop sends as its system message
+ # (cached per-session prompt + ephemeral additions such as channel overrides) rides along ONCE per
+ # thread as developerInstructions. A retired/recreated session re-sends the current composition;
+ # conversation history is still not projected into the codex thread (#74712, #26035).
+ agent._codex_session_prompt = developer_instructions
agent._codex_session = CodexAppServerSession(
cwd=getattr(agent, "session_cwd", None) or str(resolve_agent_cwd()), approval_callback=approval_callback,
+ codex_bin=get_configured_codex_binary(load_config()),
request_routing=_ServerRequestRouting(auto_approve_exec=auto_approve_requests, auto_approve_apply_patch=auto_approve_requests),
on_event=make_codex_app_server_event_bridge(agent),
+ developer_instructions=developer_instructions or None,
)
diff --cc website/docs/user-guide/features/codex-app-server-runtime.md
index bd794338cca,e7923cc8d6f..24f99c440bf
--- a/website/docs/user-guide/features/codex-app-server-runtime.md
+++ b/website/docs/user-guide/features/codex-app-server-runtime.md
@@@ -410,7 -436,7 +438,8 @@@ Known limitations
- **Hermes auth and codex auth are separate sessions.** You need both `codex login` AND `hermes auth add openai-codex` for the cleanest UX (the runtime uses codex's session for the LLM call). This is a deliberate design choice in Hermes' `_import_codex_cli_tokens` — Hermes won't share OAuth state with codex CLI to avoid clobbering each other on token refresh.
- **`delegate_task`, `memory`, `session_search`, `todo` are unavailable on this runtime.** They need the running AIAgent context which a stateless MCP callback can't provide. Use `/codex-runtime auto` when you need these.
- **No inline patch preview in approval prompts when codex doesn't track the changeset.** Codex's `fileChange` approval params don't always carry the changeset. Hermes caches the data from the corresponding `item/started` notification when possible, but if approval arrives before the item has streamed, the prompt falls back to whatever `reason` codex provides.
+ - **`fallback_providers` fail over only on quota and rate-limit failures.** When a codex app-server turn fails with a billing / usage-limit / rate-limit error, Hermes switches to the configured [fallback provider](./fallback-providers.md) and retries the same turn on it; auth failures (`codex login` expired), turn timeouts and unknown-model errors do not fail over on this runtime and surface as the turn's error instead.
+- **Conversation history is not projected into the codex thread.** The codex thread receives Hermes' system prompt when it starts plus each new user message; prior Hermes history (e.g. from a resumed session) is not replayed into it. When the composed prompt changes mid-session (for example `/personality` in the TUI or Desktop), the next turn retires the running thread and starts a new one carrying the updated prompt; that new thread does not inherit the retired thread's history.
- **Sub-second cancellation isn't guaranteed.** Mid-stream interrupts (Ctrl+C while codex is responding) are sent via `turn/interrupt`, but if codex has already flushed the final message, you get the response anyway.
If you find a bug, [open an issue](https://github.com/NousResearch/hermes-agent/issues) with the output of `hermes logs --since 5m`. Mention `codex-runtime` in the title so it's easy to triage.