Skip to content

Automatic context compaction destroys context #36712

Open

Description

@AliMirlou

What version of Codex CLI is running?

0.146.0

What subscription do you have?

ChatGPT Plus

Which model were you using?

gpt-5.6-sol (max)

What platform is your computer?

Linux 6.18.33.2-microsoft-standard-WSL2 x86_64 x86_64

What terminal emulator and version are you using (if applicable)?

Windows Terminal (WSL)

Codex doctor report

{
  "schemaVersion": 1,
  "generatedAt": "1785748851s since unix epoch",
  "overallStatus": "ok",
  "codexVersion": "0.146.0",
  "checks": {
    "app_server.status": {
      "id": "app_server.status",
      "category": "app-server",
      "status": "ok",
      "summary": "background server is not running",
      "details": {
        "control socket": "/home/ali/.codex/app-server-control/app-server-control.sock",
        "daemon state dir": "/home/ali/.codex/app-server-daemon",
        "mode": "ephemeral",
        "pid file": "/home/ali/.codex/app-server-daemon/app-server.pid (missing)",
        "settings": "/home/ali/.codex/app-server-daemon/settings.json (missing)",
        "status": "not running",
        "update-loop pid file": "/home/ali/.codex/app-server-daemon/app-server-updater.pid (missing)"
      },
      "remediation": null,
      "durationMs": 0
    },
    "auth.credentials": {
      "id": "auth.credentials",
      "category": "auth",
      "status": "ok",
      "summary": "auth is configured",
      "details": {
        "auth file": "/home/ali/.codex/auth.json",
        "auth storage mode": "File",
        "stored API key": "false",
        "stored ChatGPT tokens": "true",
        "stored agent identity": "false",
        "stored auth mode": "chatgpt"
      },
      "remediation": null,
      "durationMs": 0
    },
    "config.load": {
      "id": "config.load",
      "category": "config",
      "status": "ok",
      "summary": "config loaded",
      "details": {
        "CODEX_HOME": "/home/ali/.codex",
        "config.toml": "/home/ali/.codex/config.toml",
        "config.toml parse": "ok",
        "cwd": "/home/ali/codes/thunder-app",
        "enabled feature flags": "<redacted>",
        "feature flag overrides": "<redacted>",
        "feature flags enabled": "39",
        "log dir": "/home/ali/.codex/log",
        "mcp servers": "0",
        "model": "gpt-5.6-sol",
        "model provider": "openai",
        "sqlite home": "/home/ali/.codex"
      },
      "remediation": null,
      "durationMs": 0
    },
    "git.environment": {
      "id": "git.environment",
      "category": "git",
      "status": "ok",
      "summary": "git version 2.43.0",
      "details": {
        ".git entry": "directory",
        "PATH git #1": "/usr/bin/git",
        "PATH git #2": "/bin/git",
        "PATH git entries": "2",
        "git branch": "feat/refactor-camera-search",
        "git build options": "git version 2.43.0; cpu: x86_64; no commit associated with this build; sizeof-long: 8; sizeof-size_t: 8; shell-path: /bin/sh",
        "git exec path": "/usr/lib/git-core",
        "git version": "git version 2.43.0",
        "repo detected": "true",
        "repo root": "/home/ali/codes/thunder-app",
        "selected git": "/usr/bin/git"
      },
      "remediation": null,
      "durationMs": 61
    },
    "installation": {
      "id": "installation",
      "category": "install",
      "status": "ok",
      "summary": "installation looks consistent",
      "details": {
        "PATH codex #1": "/home/ali/.nvm/versions/node/v26.5.0/bin/codex",
        "current executable": "/home/ali/.nvm/versions/node/v26.5.0/lib/node_modules/@openai/codex/node_modules/@openai/codex-linux-x64/vendor/x86_64-unknown-linux-musl/bin/codex",
        "install context": "npm (package /home/ali/.nvm/versions/node/v26.5.0/lib/node_modules/@openai/codex/node_modules/@openai/codex-linux-x64/vendor/x86_64-unknown-linux-musl, bin /home/ali/.nvm/versions/node/v26.5.0/lib/node_modules/@openai/codex/node_modules/@openai/codex-linux-x64/vendor/x86_64-unknown-linux-musl/bin, resources /home/ali/.nvm/versions/node/v26.5.0/lib/node_modules/@openai/codex/node_modules/@openai/codex-linux-x64/vendor/x86_64-unknown-linux-musl/codex-resources, path /home/ali/.nvm/versions/node/v26.5.0/lib/node_modules/@openai/codex/node_modules/@openai/codex-linux-x64/vendor/x86_64-unknown-linux-musl/codex-path)",
        "managed by bun": "false",
        "managed by npm": "true",
        "managed by pnpm": "false",
        "managed package root": "/home/ali/.nvm/versions/node/v26.5.0/lib/node_modules/@openai/codex",
        "npm update target": "/home/ali/.nvm/versions/node/v26.5.0/lib/node_modules/@openai/codex"
      },
      "remediation": null,
      "durationMs": 175
    },
    "mcp.config": {
      "id": "mcp.config",
      "category": "mcp",
      "status": "ok",
      "summary": "no MCP servers configured",
      "details": {},
      "remediation": null,
      "durationMs": 0
    },
    "network.env": {
      "id": "network.env",
      "category": "network",
      "status": "ok",
      "summary": "network-related environment looks readable",
      "details": {
        "proxy env vars": "none"
      },
      "remediation": null,
      "durationMs": 0
    },
    "network.provider_reachability": {
      "id": "network.provider_reachability",
      "category": "reachability",
      "status": "ok",
      "summary": "active provider endpoints are reachable over HTTP",
      "details": {
        "ChatGPT base URL": "https://chatgpt.com/backend-api/ reachable (HTTP 403)",
        "reachability mode": "ChatGPT auth"
      },
      "remediation": null,
      "durationMs": 676
    },
    "network.websocket_reachability": {
      "id": "network.websocket_reachability",
      "category": "websocket",
      "status": "ok",
      "summary": "Responses WebSocket handshake succeeded",
      "details": {
        "DNS": "2 IPv4, 2 IPv6, first IPv4",
        "auth mode": "chatgpt",
        "connect timeout": "15000 ms",
        "endpoint": "wss://chatgpt.com/backend-api/<redacted>",
        "handshake result": "HTTP 101 Switching Protocols",
        "model provider": "openai",
        "models etag present": "true",
        "provider name": "OpenAI",
        "proxy env vars": "none",
        "reasoning header": "false",
        "server model present": "false",
        "supports websockets": "true",
        "wire API": "responses"
      },
      "remediation": null,
      "durationMs": 1583
    },
    "runtime.provenance": {
      "id": "runtime.provenance",
      "category": "runtime",
      "status": "ok",
      "summary": "running npm on linux-x86_64",
      "details": {
        "commit": "unknown",
        "current executable": "/home/ali/.nvm/versions/node/v26.5.0/lib/node_modules/@openai/codex/node_modules/@openai/codex-linux-x64/vendor/x86_64-unknown-linux-musl/bin/codex",
        "install method": "npm (package /home/ali/.nvm/versions/node/v26.5.0/lib/node_modules/@openai/codex/node_modules/@openai/codex-linux-x64/vendor/x86_64-unknown-linux-musl, bin /home/ali/.nvm/versions/node/v26.5.0/lib/node_modules/@openai/codex/node_modules/@openai/codex-linux-x64/vendor/x86_64-unknown-linux-musl/bin, resources /home/ali/.nvm/versions/node/v26.5.0/lib/node_modules/@openai/codex/node_modules/@openai/codex-linux-x64/vendor/x86_64-unknown-linux-musl/codex-resources, path /home/ali/.nvm/versions/node/v26.5.0/lib/node_modules/@openai/codex/node_modules/@openai/codex-linux-x64/vendor/x86_64-unknown-linux-musl/codex-path)",
        "platform": "linux-x86_64",
        "version": "0.146.0"
      },
      "remediation": null,
      "durationMs": 0
    },
    "runtime.search": {
      "id": "runtime.search",
      "category": "search",
      "status": "ok",
      "summary": "search is OK (bundled)",
      "details": {
        "search command": "/home/ali/.nvm/versions/node/v26.5.0/lib/node_modules/@openai/codex/node_modules/@openai/codex-linux-x64/vendor/x86_64-unknown-linux-musl/codex-path/rg",
        "search command readiness": "file exists",
        "search provider": "bundled"
      },
      "remediation": null,
      "durationMs": 0
    },
    "sandbox.helpers": {
      "id": "sandbox.helpers",
      "category": "sandbox",
      "status": "ok",
      "summary": "sandbox configuration is readable",
      "details": {
        "approval policy": "OnRequest",
        "codex-linux-sandbox helper": "/home/ali/.codex/tmp/arg0/codex-arg0hPBB1x/codex-linux-sandbox",
        "execve wrapper helper": "/home/ali/.codex/tmp/arg0/codex-arg0hPBB1x/codex-execve-wrapper",
        "filesystem sandbox": "restricted",
        "network sandbox": "restricted"
      },
      "remediation": null,
      "durationMs": 0
    },
    "state.paths": {
      "id": "state.paths",
      "category": "state",
      "status": "ok",
      "summary": "state paths and databases are inspectable",
      "details": {
        "CODEX_HOME": "/home/ali/.codex (dir)",
        "active rollout files": "53 files, 35636947 total bytes, 672395 average bytes",
        "archived rollout files": "0 files, 0 total bytes, 0 average bytes",
        "goals DB": "/home/ali/.codex/goals_1.sqlite (file)",
        "goals DB integrity": "ok",
        "log DB": "/home/ali/.codex/logs_2.sqlite (file)",
        "log DB integrity": "ok",
        "log dir": "/home/ali/.codex/log (dir)",
        "memories DB": "/home/ali/.codex/memories_1.sqlite (file)",
        "memories DB integrity": "ok",
        "sqlite home": "/home/ali/.codex (dir)",
        "state DB": "/home/ali/.codex/state_5.sqlite (file)",
        "state DB integrity": "ok",
        "thread history DB": "/home/ali/.codex/thread_history_1.sqlite (missing)",
        "thread history DB integrity": "skipped (missing)"
      },
      "remediation": null,
      "durationMs": 1904
    },
    "state.rollout_db_parity": {
      "id": "state.rollout_db_parity",
      "category": "threads",
      "status": "ok",
      "summary": "rollout files and state DB thread inventory agree",
      "details": {
        "default model provider": "openai",
        "rollout DB active files": "489",
        "rollout DB active rows": "489",
        "rollout DB archive mismatches": "0",
        "rollout DB archived files": "0",
        "rollout DB archived rows": "0",
        "rollout DB duplicate DB paths": "0",
        "rollout DB duplicate rollout thread ids": "0",
        "rollout DB malformed file names": "0",
        "rollout DB missing active rows": "0",
        "rollout DB missing archived rows": "0",
        "rollout DB model providers": "openai=298, openai-custom=191",
        "rollout DB rows": "489",
        "rollout DB scan cap reached": "false",
        "rollout DB scan errors": "0",
        "rollout DB sources": "cli=391, subagent:thread_spawn=97, subagent:review=1",
        "rollout DB stale rows": "0"
      },
      "remediation": null,
      "durationMs": 547
    },
    "system.environment": {
      "id": "system.environment",
      "category": "system",
      "status": "ok",
      "summary": "OS language C",
      "details": {
        "EDITOR": "not set",
        "LANG": "C.UTF-8",
        "LESS": "set",
        "PAGER": "set",
        "VISUAL": "not set",
        "os": "Ubuntu 24.4.0 (noble) [64-bit]",
        "os language": "C",
        "os type": "Ubuntu",
        "os version": "24.4.0"
      },
      "remediation": null,
      "durationMs": 9
    },
    "terminal.env": {
      "id": "terminal.env",
      "category": "terminal",
      "status": "ok",
      "summary": "terminal metadata was detected",
      "details": {
        "DISPLAY": "present",
        "WAYLAND_DISPLAY": "present",
        "WSL_DISTRO_NAME": "present",
        "WSL_INTEROP": "present",
        "WT_SESSION": "present",
        "color output": "enabled",
        "effective locale": "C.UTF-8",
        "stderr is terminal": "true",
        "stdin is terminal": "true",
        "stdout is terminal": "true",
        "terminal": "Windows Terminal",
        "terminal size": "167x50"
      },
      "remediation": null,
      "durationMs": 0
    },
    "terminal.title": {
      "id": "terminal.title",
      "category": "title",
      "status": "ok",
      "summary": "terminal title default",
      "details": {
        "terminal title activity": "true",
        "terminal title items": "activity, project-name",
        "terminal title project source": "git repo root",
        "terminal title project value": "thunder-app",
        "terminal title source": "default"
      },
      "remediation": null,
      "durationMs": 0
    },
    "updates.status": {
      "id": "updates.status",
      "category": "updates",
      "status": "ok",
      "summary": "update configuration is locally consistent",
      "details": {
        "cached latest version": "0.146.0",
        "check for update on startup": "true",
        "dismissed version": "0.121.0",
        "last checked at": "2026-08-02T08:13:13.593316565Z",
        "latest version": "0.146.0",
        "latest version status": "current version is not older",
        "npm update target": "/home/ali/.nvm/versions/node/v26.5.0/lib/node_modules/@openai/codex",
        "update action": "npm install -g @openai/codex",
        "version cache": "/home/ali/.codex/version.json"
      },
      "remediation": null,
      "durationMs": 1666
    }
  }
}

What issue are you seeing?

Sometimes in a long-running task, when the automatic context compaction triggers, after compaction, the agent loses track of the conversation completely and breaks with a message telling me that they don't know what to do:

• Context compacted
──────────────────────────────────────────────
• Understood. I’ll follow these repository guidelines. What would you like me to work on?

I tried asking them to find and read the uncompacted conversation history and continue where they left off but didn't work.
So I had to open a new conversation, give them the same task prompt, and tell them that the current worktree changes are the implementation attempt of another agent, check the changes and finish the task.

It happens occasionally but for a specific task today, it happened three times so far and each time, it burnt a lot of tokens and time, just to reach the point where it broke the previous time, and decided to rewrite a lot of things that it thought were not a good implementation design, when they were more than good enough for my needs.

What steps can reproduce the bug?

  • Give a large task prompt, usually using the Plan Mode and then execute the plan in a fresh context.
  • Wait for an auto compaction trigger.

What is the expected behavior?

The expected behavior is that the task implementation should continue after auto compaction.

Additional information

No response

Activity

  1. added
    bug
    on Aug 3, 2026
  2. added
    CLI
    context
    on Aug 3, 2026
  3. github-actions commented on Aug 3, 2026

    @github-actions
    Contributor
  4. vnbochkarev-netizen commented on Aug 30, 2026

    @vnbochkarev-netizen

    We hit this too. The fix pattern that works for us: take a snapshot of the full context before compaction and run a poison/integrity scan on the compacted result — if something important vanished, you notice immediately instead of mid-task.

    We packaged it as an open-source, zero-dependency skill (memory-shield): snapshot before → scan after → quarantine suspicious lines instead of silent loss. Works as a CLI, so it can wrap any agent's compaction step.

    Hope this helps others hitting the same wall.

  5. hyperbetteri commented on Sep 1, 2026

    @hyperbetteri

    Public-safe prompt pattern: Compaction / Handoff Checkpoint

    Author: Almási Andor Aladár

    For long-running tasks, a compact handoff packet can reduce context-loss damage:

    Before compaction or thread handoff, preserve only:

    • active objective;
    • latest explicit user instruction;
    • completed work;
    • pending work;
    • blockers;
    • verified facts with source/file pointers where available;
    • assumptions that are still active;
    • modified artifacts/files;
    • next safe action.

    After compaction:

    1. Compare the checkpoint against the latest user message before continuing.
    2. The latest explicit user instruction overrides stale checkpoint content.
    3. Do not reconstruct exact data, code, identifiers, or decisions from memory when a source artifact exists.
    4. If the checkpoint/summary is missing, empty, or structurally incomplete, do not silently infer a replacement task. Preserve prior state if possible or surface a recovery condition.

    This is a userland mitigation pattern. The stronger product invariant is that failed compaction must never silently replace meaningful working context with an empty/default state.

    Copyright © 2026 Almási Andor Aladár. Public-safe excerpt; no disclosure or license of the underlying private architecture.

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

    CLIbugcontext

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions