Skip to content

Codex message edit fails with 502: stored checkpoint references another thread’s session #3281

Closed

Description

@markasoftware-tc

Summary

Editing a message in an existing Codex conversation fails with HTTP 502. Investigation found that bb’s stored turn checkpoints reference a different Codex session—the session belonging to a Side Chat fork—even though those turns exist in the original session.

The original failure is supported by logs and persisted history, but the UI trigger has not been reproduced on fresh threads. An isolated test demonstrates a potentially related identity-bookkeeping defect in current main; its connection to this incident remains unverified.

Versions and environment

  • bb 0.41.0, installed through Nix.
  • Ubuntu 24.04.4 LTS.
  • Codex CLI 0.153.2; affected conversation used gpt-6-astra.
  • Local bb server/host daemon, default data directory ~/.bb.
  • Affected conversation and Side Chat fork shared an unmanaged checkout.
  • Source inspected at main commit 426ed789da370de6198bb954a935b09f4cf48bc8.
  • Current main was inspected and tested at the identity-registry level; the full application was not run from that commit.

Steps to reproduce

Reported UI sequence, not yet independently reproducible:

  1. In an existing Codex conversation, send a message.
  2. Within a few seconds, click Stop.
  3. Attempt to edit the previous message.
  4. The edit fails with HTTP 502.

The affected conversation was itself a fork and had a Side Chat fork. Whether that history is necessary is unknown.

Fresh-thread attempts did not reproduce the failure:

  • Fork → rename source → edit latest message.
  • Nested fork → additional messages → edit.
  • Idle fork → continue source → interrupt final response → edit.
  • Send → Stop → explicitly edit the message preceding the aborted turn, with delays of 0, 0.25, 1, 2, and 3 seconds before Stop.

These attempts used the bb CLI/backend, not automated UI clicks. All edits succeeded. They used the existing bb data directory, not a clean profile.

Expected vs actual

Expected: editing succeeds using the selected conversation’s provider history.

Actual: the UI reports HTTP 502. The host daemon logged two failures in `thread.rewind.prepare`:

    JsonRpcResponseError: turn not found: 01a08289-1c02-7561-b462-324532447b30

The JSON-RPC error code was `-32000`. Both failures appear in `~/.bb/logs/host-daemon.27.log`, lines 42–43.

Evidence

Affected bb thread: thr_qt7ksugfxh
Side Chat fork: thr_5dh7735g66
Project: proj_pizg8ky8sa
Environment: env_vw3diaeh83

The original conversation’s actual Codex session is:

01a0827d-0363-7000-a638-cd83e8531d49

The Side Chat fork’s Codex session is:

01a08281-b4d4-7b11-9e74-d4ae752b5fc5

Read-only inspection of bb’s SQLite events and Codex rollout JSONL files found:

  • Event 525, at 19:31:49 UTC on September 8, correctly records the original session.
  • Event 526, a thread-name update at 19:34:01 UTC, records the fork’s session instead. This is the first observed mismatch, not proof that renaming caused it.
  • Subsequent turn-completion events 711, 804, 883, and 897 all record the fork’s session.
  • Each of those four checkpoints exists in the original session’s rollout and is absent from the fork’s rollout.

For example, event 883 contains:

{
  "providerThreadId": "01a08281-b4d4-7b11-9e74-d4ae752b5fc5",
  "status": "completed",
  "providerCheckpointId": "01a08289-1c02-7561-b462-324532447b30"
}

That checkpoint actually belongs to session 01a0827d-0363-7000-a638-cd83e8531d49.

Current main’s edit handler takes the preceding completion’s stored session ID and checkpoint and uses them to prepare the rewind. Consequently, the observed mismatched pair explains the provider’s “turn not found” response:

const precedingTurn = db
.select({ turnId: events.turnId })
.from(events)
.where(
and(
eq(events.threadId, thread.id),
eq(events.type, "turn/started"),
lt(events.sequence, requestRow.sequence),
isNull(events.parentToolCallId),
),
)
.orderBy(desc(events.sequence))
.limit(1)
.get();
const precedingTurnId = precedingTurn?.turnId ?? null;
const precedingCompletion =
precedingTurnId === null
? null
: getTurnCompletion(db, thread.id, precedingTurnId);
if (
precedingTurnId !== null &&
(precedingCompletion === null ||
precedingCompletion.providerThreadId === null)
) {
conflict("This earlier turn has no provider history");
}
const precedingProviderCheckpoint =
precedingTurnId === null
? null
: resolveTurnProviderCheckpointId({
providerCheckpointId: precedingCompletion?.providerCheckpointId,
providerId: thread.providerId,
turnId: precedingTurnId,
});
if (precedingTurnId !== null && precedingProviderCheckpoint === null) {
conflict("This earlier provider turn has no editable history checkpoint");
}
return {
leadingAgentOnlyInput: getLeadingAgentOnlyInput(request.input),
currentTurnId: accepted.turnId,
oldMaxSequence: getHighWaterMarks(db, [thread.id])[thread.id] ?? 0,
precedingProviderCheckpoint,
requestSequence: requestRow.sequence,
sourceProviderThreadId:
precedingTurnId === null
? null
: (precedingCompletion?.providerThreadId ?? null),
};
}
function resolveEditableTurn(
db: DbQueryConnection,
thread: Thread,
requestSequence?: number,
): EditableTurn {
if (thread.archivedAt !== null || thread.deletedAt !== null) {

Potential contributing defect, not a confirmed incident root cause:

  • recordProviderThreadIdentity() records the mapping but does not remove the thread from pendingIdentityThreadIds.
  • A later identity event whose thread ID is not registered can consume that stale pending entry and overwrite its mapping.
  • Event stamping then replaces the event’s provider session ID with the registry’s mapping while retaining its checkpoint.

Sources:

recordProviderThreadIdentity(args: RecordProviderThreadIdentityArgs): void {

function emitTranslatedEvents(args: EmitTranslatedEventsArgs): void {

An isolated test importing the registry directly from this commit confirmed that registering and resolving two threads leaves both pending; consuming the fallback selects the already-resolved original thread. Recording the fork’s identity there and stamping an original-thread completion produces the same kind of session/checkpoint mismatch.

This test explicitly exercises the fallback. It does not establish which real notification, if any, triggered it in this incident.

What you ruled out

  • The requested checkpoint is not missing from all Codex history; it exists in the original session.
  • Ordinary forking and rapid Stop/edit operations did not reproduce the problem on fresh threads.
  • Current main retains the relevant identity fallback and trusts the stored session/checkpoint pair; upgrading alone has not been verified as a repair.
  • No matching issue was found by searching open and closed issues for “turn not found,” “edit” plus “502,” and “pendingIdentityThreadIds.”
  • UI-specific timing, the exact notification sequence, and behavior with a clean data directory remain untested.

AGENT GENERATED

Suggested priority and effort (optional)

Blocks editing in at least one existing conversation. Original Codex history remains intact; no repair or workaround has been verified. Scope and effort are unknown.

Checks

  • I reproduced this on the latest release or on main, or I say above that I could not.
  • I searched open and closed issues for the same problem.
  • If an agent wrote this, the body ends with > AGENT GENERATED and links the thread or report.

Activity

  1. added theissue type on Sep 8, 2026
  2. added
    threads
    provider-codex
    partial-repro
    on Sep 8, 2026
  3. bb-slop-cop commented on Sep 9, 2026

    @bb-slop-cop
    Contributor

    🚨 SLOP COP 🚨 · new-issue-autopilot

    Preserved Bug · Medium priority · Medium effort and threads, provider-codex.

    Updated reproduction report: PARTIALLY REPRODUCED, medium incident-level confidence. Applied partial-repro.

    Two clean checkouts of current main reproduce stale pending identities overwriting a resolved session while event stamping retains its original checkpoint. The real notification sequence and Stop/edit failure remain unverified. The focused reproduction fails as expected in both checkouts; all three existing identity tests pass.

    No PR: the user-visible failure is not sufficiently reproduced to claim a verified repair.

  4. markasoftware-tc commented on Sep 10, 2026

    @markasoftware-tc
    Author

    triggered again today while forking

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

    partial-reproprovider-codexthreads

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions