Skip to content

ownsCompaction tool-result context guard bypass still present in v2026.5.3 (Codex sessions have no mid-turn compaction protection) #77561

Closed

Description

@KelTech-Services

Follow-up to #71325 (closed/locked April 25).

The ownsCompaction bypass is still present in v2026.5.3 (06d46f7). At selection-BgogoK8g.js:7163, the tool-result context guard is only installed when ownsCompaction !== true:

if (!activeContextEngine || activeContextEngine.info.ownsCompaction !== true)
    removeToolResultContextGuard = installToolResultContextGuard({...})

Since the Codex runtime sets ownsCompaction = true, Codex sessions get zero mid-turn compaction protection during tool loops. Additionally, shouldDisablePiAutoCompaction in pi-settings-Cj8yO4dX.js:95 disables Pi internal auto-compaction for these sessions.

Environment:

  • OpenClaw 2026.5.3 (06d46f7)
  • Model: openai-codex/gpt-5.5 (primary), gpt-5.4 (fallback)
  • Compaction: mode=safeguard, maxHistoryShare=0.5, keepRecentTokens=30000
  • macOS Apple Silicon

Reproduction:
Run a heavy tool-loop (20+ sequential exec/API calls). Context overflows mid-loop. Compaction fires reactively but cannot keep up — tool results accumulate faster than compaction trims.

Error log (repeating pattern, twice in 4 hours):

[context-overflow-diag] sessionKey=agent:main:main provider=openai-codex/gpt-5.5
  source=assistantError messages=252 compactionAttempts=3 observedTokens=unknown
  error=Context overflow: estimated context size exceeds safe threshold during tool loop.
Auto-compaction failed (...). Restarting session agent:main:main -> <new-id> and retrying.

Impact:

  • observedTokens=unknown — token estimation broken for Codex sessions
  • After 3 failed compaction attempts, session is restarted to a new file
  • Agent loses all active working context — returns with no memory of in-progress work
  • No graceful recovery; user has to re-explain what the agent was doing
  • Happened twice in 4 hours during normal heavy tool work

Expected behavior:
The tool-result context guard should be installed for ALL sessions regardless of ownsCompaction, or a forceCompactTranscriptBytes hard floor (as proposed in #71325) should fire when transcript size exceeds a threshold, bypassing the ownsCompaction flag.

Activity

  1. clawsweeper commented on May 4, 2026

    @clawsweeper
    Contributor

    Thanks for the context here. I did a careful shell check against current main, and this is already implemented.

    Current main and shipped releases have the central guard-bypass fix: ownsCompaction engines now compose the context-engine loop hook with the generic tool-result context guard, and the preflight path uses LLM-boundary/unwindowed pressure so tool-heavy Codex sessions compact before provider overflow.

    I found the merged PR that appears to have closed this: #85541: Fix context pressure preflight for tool-heavy sessions.

    So I’m closing this as already implemented rather than keeping a duplicate issue open.

    Review details

    Best possible solution:

    Keep the shipped #85541 implementation for this specific guard bypass; broader context-budget and compaction-observability work can continue in their separate open issues.

    Do we have a high-confidence way to reproduce the issue?

    Yes for the historical bug: the report's old v2026.5.3 guard condition matches the predecessor discussion, and #85541 includes saved-session proof plus regression tests for the same tool-heavy/ownsCompaction pressure path. Current main no longer reproduces the bypass because the guard is installed in both ownsCompaction and non-ownsCompaction branches.

    Is this the best way to solve the issue?

    Yes. The current solution is the maintainable fix because it preserves context-engine compaction ownership while adding a host-side tool-result guard and provider-boundary pressure check before Codex submits oversized prompts.

    Security review:

    Security review: This is an issue cleanup review with no proposed patch to inspect for security or supply-chain risk.

    AGENTS.md: found and applied where relevant.

    What I checked:

    Likely related people:

    • fuller-stack-dev: Authored the first commit in the merged fix PR that added tool-payload pressure estimation and ownsCompaction guard composition for this issue class. (role: fix author; confidence: high; commits: 2962db32fea7, c08400ea7d5d; files: src/agents/embedded-agent-runner/run/preemptive-compaction.ts, src/agents/embedded-agent-runner/run/attempt.ts, src/agents/embedded-agent-runner/tool-result-context-guard.test.ts)
    • joshavant: Added the provider-boundary Codex rendered preflight follow-up in the merged PR and supplied maintainer-facing proof tying the old path to live context_length_exceeded behavior. (role: follow-up fix author and area reviewer; confidence: high; commits: f1196461d388, c08400ea7d5d; files: extensions/codex/src/app-server/run-attempt.ts, src/agents/embedded-agent-runner/run/preemptive-compaction.ts, src/plugin-sdk/agent-harness-runtime.ts)
    • steipete: Authored the earlier safeguard repair commit for the linked predecessor issue and is therefore relevant for context-engine compaction routing history, though the later fix superseded that narrower repair. (role: prior compaction-safeguard contributor; confidence: medium; commits: 41f9768cd8de; files: src/agents/embedded-agent-runner/run/attempt.ts, src/agents/embedded-agent-runner/run/preemptive-compaction.ts)

    Codex review notes: model internal, reasoning high; reviewed against 6134c00657a2; fix evidence: merged PR #85541, release v2026.5.22-beta.1, commit c08400ea7d5d.

  2. openclaw-barnacle commented on May 31, 2026

    @openclaw-barnacle

    This issue has been automatically marked as stale due to inactivity.
    Please add updates or it will be closed.

  3. added
    P2Normal backlog priority with limited blast radius.
    impact:session-stateSession, memory, transcript, context, or agent state can drift or corrupt.
    on Jun 14, 2026
  4. locked as resolved and limited conversation to collaborators on Jun 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Normal backlog priority with limited blast radius.impact:session-stateSession, memory, transcript, context, or agent state can drift or corrupt.staleMarked as stale due to inactivity

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions