Skip to content

[Thread API] read_thread omits completed response after context compaction #40977

Open

Description

@unthingable

What version of the Codex App are you using?

Codex task-management API surface in Codex Desktop.

  • Bundled runtime recorded by the affected session: codex-cli 0.150.0-alpha.8
  • Current local CLI: codex-cli 0.149.1
  • Platform: macOS Darwin 24.6.0 arm64
  • Affected task source: vscode
  • Model: not surfaced in the session metadata

What issue are you seeing?

After a target task performs context compaction, a cross-thread read can silently omit the target task's latest completed assistant response.

The task completes normally and the raw rollout JSONL contains the final assistant message. However, the thread-management API reports the latest turn as completed while returning an empty item list and no latest assistant message. This makes read-only cross-thread review and handoff retrieval fail even though the response is persisted locally.

The compaction correlation is evidence from one reproduction, not a confirmed causal mechanism.

Reproduction

  1. Use a sufficiently long-running Codex task that performs context compaction.
  2. From another task, send a read-only review request to that task.
  3. Wait for the target task to finish.
  4. Call wait_threads and then read_thread for the exact target thread ID.
  5. Observe that the target turn is completed, but its retrievable items are empty.
  6. Inspect the local rollout JSONL and observe that the assistant response is present.

Affected task:

01a03fe0-2471-7ec2-a29f-6117f1f3f022

Observed local rollout evidence:

  • compacted record at ordinal 2015, timestamp 2026-08-26T21:26:58.831Z
  • assistant response_item at ordinal 2093
  • task_complete at ordinal 2095, with a non-empty last_agent_message
  • read_thread / wait_threads result: latest turn completed, but items: [], latestAssistantMessageId: null, and latestAssistantMessage: null

The raw response remains in:

~/.codex/sessions/2026/08/26/rollout-2026-08-26T23-00-49-01a03fe0-2471-7ec2-a29f-6117f1f3f022.jsonl

Older assistant messages from the same task were retrievable, so this is not simply lack of access to the task.

Expected behavior

A completed target turn should expose its assistant response through read_thread, regardless of whether context compaction occurred. If transcript hydration fails, the API should return an explicit error or incomplete-state marker rather than a successful completed turn with an empty transcript.

Actual behavior

The status path correctly observes completion, but the transcript path silently drops the latest response. Repeated waiting does not restore it. Reading the raw rollout JSONL recovers the response, but that is an internal, unsupported fallback and is not available for remote tasks.

Related issues

This report is narrower: the target task completes, local storage contains the assistant message, but the cross-thread read_thread result omits it after compaction.

Privacy

The raw transcript is not attached because it contains private project conversation and local paths. The rollout path, task ID, turn status, ordinals, and metadata above are sanitized evidence.

Activity

  1. added
    bug
    app
    app-server
    session
    context
    on Aug 26, 2026
  2. github-actions commented on Aug 26, 2026

    @github-actions
    Contributor
  3. coolnames commented on Aug 29, 2026

    @coolnames

    I reproduced the same completed-turn/empty-items contradiction on Codex Desktop for macOS 26.825.32147, bundled codex-cli 0.150.0-alpha.12.2, with a deterministic restart boundary.
    A task created before a complete Desktop restart continues to accept and execute turns afterward. Its rollout JSONL contains commentary, tool calls, results, and a final response, but wait_threads reports null assistant/tool content and read_thread returns the correct completed turn with items: [].
    Pre-restart history remains readable. A second post-restart turn in the same persisted task reproduces the failure. A new task created after the restart exposes full content normally through both APIs.
    This isolates the condition to turns appended to a resumed pre-restart task, rather than a general monitoring outage. Shipped implementation inspection suggests the resumed paginated-history hydration path may reuse a stale conversation-level itemsBackwardsCursor for newly appended turns.
    I have a complete controlled reproduction report and private rollout evidence. Feedback ID: 01a040f9-b215-70d3-866e-c7b9b2370289. Related: #40512 and #40014.

  4. infinityfy commented on Aug 30, 2026

    @infinityfy

    I can reproduce the same failure on Codex Desktop for Windows, but without
    requiring context compaction.

    Additional evidence:

    • Still affected with bundled CLI 0.151.0-alpha.7.2.
    • The first adjacent affected release observed locally was 0.148.0-alpha.15;
      sessions originally created with 0.148.0-alpha.9 remain reliable on the
      same current host.
    • Fresh-session reproduction: 4/4 turns visible before a full Desktop restart;
      the first post-restart turn completed but returned items=[] and
      latestAssistantMessage=null.
    • The affected thread has history_mode=paginated.
    • thread_history_projection_state.next_rollout_byte_offset exactly equals the
      rollout file size: 349430 bytes.
    • thread_turns contains the completed turn and a valid final_agent_item_id.
    • thread_items contains both functionCallOutput and agentMessage rows.
    • read_thread still returns items=[] with includeOutputs=false and true.
    • All three local SQLite databases pass PRAGMA integrity_check.
    • Desktop logs show thread/items/list returning without an explicit error.

    This narrows the affected sample to a reader/mapper/filter/cache failure after
    history projection is already complete, rather than missing model output or a
    lagging projection waterline.

    I have a sanitized evidence report with exact turn IDs, ordinals, hashes, and
    version comparisons. Raw transcripts and databases are not public because they
    may contain private context.

  5. dengdingchang commented on Sep 8, 2026

    @dengdingchang

    Additional reproduction on a macOS Desktop coordinator reading an SSH-connected Linux task.

    Environment observed on 2026-09-08:

    • Desktop app version 26.901.51231, build 8109.
    • Remote codex-cli 0.153.4.

    Native history exists while Desktop task tools return empty items

    For the same remote task and exact same completed turn:

    • Native app-server thread/turns/list with itemsView: "full": 14 items, including 3 agent messages.
    • Native thread/read with includeTurns: true: the same 14 items and 3 agent messages.
    • Desktop read_thread, explicitly targeting that SSH host: 0 items.

    This also reproduced for a later in-progress turn: native full history returned 26 items including 4 agent messages, while Desktop returned 0 items for the same turn. A separate native thread/items/list request with a null cursor returned complete items too. No resume, restart, or interruption of the target task was needed.

    Pagination hypothesis, not a confirmed root cause

    A read-only experiment with server-issued opaque cursors reproduced a potential failure mechanism:

    1. Obtain a backwardsCursor from an older turn's item page.
    2. Read the latest turn using descending item pagination.
    3. With cursor: null, the latest turn returned 51 items and no next page.
    4. With the older backwards cursor, it returned 0 items, no next page, and no error.

    The installed Desktop's paginated history path appears to reuse a conversation-level item boundary when hydrating individual turns. We have NOT captured the actual Desktop cursor used in the failing request, so this remains a candidate explanation. Please check whether full-history task-tool reads inadvertently inherit an older UI pagination boundary. A regression covering an old boundary plus a new turn may help. An explicit incomplete-history result would also be preferable to silent empty items.

    Separate remote callback capability question

    In the affected remote task context, task read/wait tools are available but send_message_to_thread is not exposed. The coordinator can send into the remote task. Is there a supported remote-to-coordinator result callback path, or is the missing outbound tool an intentional current limitation? This is separate from the empty-history defect; we are not claiming they share a root cause.

    A bounded workaround was tested: the Mac initiates SSH, registers native fs/watch on the remote rollout, and reads full history after fs/changed. A local observer can then relay a sanitized report to its coordinator. This is Mac-initiated observation, NOT remote task-initiated delivery, and it does not repair native cross-thread callbacks or persist after the observer exits.

    No signed app, tool filters, SSH permissions, or business task configuration were modified. Private transcripts, task identifiers, host addresses, credentials, and project paths are intentionally omitted.

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

    appapp-serverbugcontextsession

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions