Skip to content

fix(codex): resume long sessions and restore compaction - #5

Merged
LuneZ99 merged 3 commits into
agent/codex-long-sessions-cleanfrom
fix/codex-resume-and-compaction
Aug 13, 2026
Merged

LuneZ99 merged 3 commits into
agent/codex-long-sessions-cleanfrom
fix/codex-resume-and-compaction

Conversation

@LuneZ99

@LuneZ99 LuneZ99 commented Aug 13, 2026

Copy link
Copy Markdown

问题

生产账户的持久 Codex thread 已累计 3313 条消息,恢复时超过固定 15 秒,Hermes 因 thread/resume timed out after 15s 回退。与此同时,无 live Codex session 的 app-server 会话在压缩时直接 no-op,使 transcript 持续膨胀。

修复

对应上游问题: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 passed
  • 全量测试运行到 62% 时已有 111 个基线失败后停止;失败集中在缺少 aiohttp / anthropic / acp 等可选依赖及现有 EOL 测试,与本 PR 路径无关。相关 app-server/session/context-compressor 套件均通过。

没有新增重试、配置项或兼容层。

xenuloyalofficer and others added 2 commits August 13, 2026 06:56
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
@LuneZ99
LuneZ99 requested a review from corgi-bot August 13, 2026 07:04
@LuneZ99
LuneZ99 requested review from corgi-bot and removed request for corgi-bot August 13, 2026 07:19
@LuneZ99

LuneZ99 commented Aug 13, 2026

Copy link
Copy Markdown
Author

自审结论:APPROVED。已检查完整调用链、边界与测试覆盖:持久 thread 恢复仅移除不合理的 15 秒固定期限,新建 thread 仍保留握手超时;无 live Codex session 时复用现有 Hermes 压缩路径,避免 transcript 无界增长;未引入重试框架、配置项或额外抽象。全部 CI 通过,0 个 unresolved thread,未发现 important 级问题。

@LuneZ99
LuneZ99 merged commit 639b402 into agent/codex-long-sessions-clean Aug 13, 2026
71 of 73 checks passed
@LuneZ99
LuneZ99 deleted the fix/codex-resume-and-compaction branch August 13, 2026 07:24
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.

2 participants