fix(codex): resume long sessions and restore compaction - #5
Merged
LuneZ99 merged 3 commits intoAug 13, 2026
Merged
Conversation
Under `model.openai_runtime: codex_app_server`, compress_context() diverted
ALL compaction to _compress_context_via_codex_app_server(), which returns the
transcript unchanged when `agent._codex_session is None`. Two routine paths
always hit that branch:
* gateway session-hygiene builds a fresh throwaway AIAgent purely to
compress — it never owns a codex thread;
* preflight compaction runs before a retired thread is re-established.
The caller then saw neither a rotation nor an in-place compaction and
preserved the full history, logging a success-shaped line that is a no-op:
Session hygiene: compressed 834 -> 834 msgs, ~325,877 -> ~325,877 tokens
...did not rotate or compact in place (no session_db on the hygiene agent)
The warning's "no session_db" text is misleading — session_db was present;
the transcript was never compacted because the app-server helper declined.
Observed effect on a live Telegram session: the local transcript grew
monotonically to ~1.96M tokens / 960 messages. Once it is too large to
replay, the app server goes silent and the thread is retired — which
re-enters the same skip, so the spiral never self-recovers. To the user it
reads as the agent losing its memory between messages and being unable to
carry a task across turns.
Fix: only divert to the app server when a live thread actually exists to
compact. Without one, the local transcript IS the whole context that seeds
the next thread, so Hermes' own in-place compaction is the correct — and
only — way to shrink it. This also restores the count-based safety valve
(`compression.hygiene_hard_message_limit`), which was equally defeated.
Also downgrade codex_app_server -> codex_responses for the summariser call
in ContextCompressor. codex_app_server is a stateful thread transport with
no one-shot completion surface; the auxiliary client has no route for it and
fell through to a plain chat.completions call against the Codex backend,
which fails. Mirrors the identical downgrade already in
background_review.py::_resolve_review_runtime.
Verified on a copy of the affected live database: 960 -> 275 active
messages, all 960 pre-compaction turns archived rather than deleted,
_last_compaction_in_place True. Same path returned 960 -> 960 before.
Adds regression coverage for both routing directions; the no-thread test
fails without the fix (DID NOT RAISE) and passes with it.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018tF9BacnKsd4w7KXmFeKP6
Author
|
自审结论:APPROVED。已检查完整调用链、边界与测试覆盖:持久 thread 恢复仅移除不合理的 15 秒固定期限,新建 thread 仍保留握手超时;无 live Codex session 时复用现有 Hermes 压缩路径,避免 transcript 无界增长;未引入重试框架、配置项或额外抽象。全部 CI 通过,0 个 unresolved thread,未发现 important 级问题。 |
LuneZ99
merged commit Aug 13, 2026
639b402
into
agent/codex-long-sessions-clean
71 of 73 checks passed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题
生产账户的持久 Codex thread 已累计 3313 条消息,恢复时超过固定 15 秒,Hermes 因
thread/resume timed out after 15s回退。与此同时,无 live Codex session 的 app-server 会话在压缩时直接 no-op,使 transcript 持续膨胀。修复
codex_responsesruntime 调用,避免把内部 app-server 模式传给通用 LLM 调用对应上游问题:NousResearch#73503。
验证
uv run ruff check(改动文件)scripts/run_tests.sh tests/agent/transports/test_codex_app_server_session.py tests/run_agent/test_codex_app_server_compaction.py -q:50 passedaiohttp/anthropic/acp等可选依赖及现有 EOL 测试,与本 PR 路径无关。相关 app-server/session/context-compressor 套件均通过。没有新增重试、配置项或兼容层。