Skip to content

Pre-turn thread usage snapshots are dropped as "orphan thread-state snapshot with no stored turn/started" #1727

Closed

Description

@ymichael

On codex resume and on a fork's first turn, the server warns Dropped orphan thread-state snapshot with no stored turn/started for thread/tokenUsage/updated and thread/contextWindowUsage/updated events that arrive before the turn's turn/started is stored, and drops them.

Evidence (final gate run 2, /tmp/final-gate-2.md, pre-existing observation 4, reproduced on origin/main):

  • Seen on the codex archive→unarchive→resume flow and on the first turn of a forked codex thread. Usage did land for both threads afterwards, so the impact is a transiently missing usage number, not persistent loss.

Question to answer: are pre-turn usage snapshots meant to be dropped, or should they be buffered/attached once the turn row exists? Where to look: apps/server/src/internal/events.ts (~line 949, the drop-with-warning site) and the turn/started persistence ordering for resume/fork first turns.

Surfaced during #1640 final validation; pre-existing (verified on origin/main).

AGENT GENERATED: by Claude Fable 5

Activity

  1. self-assigned this
    on Aug 17, 2026
  2. added theissue type on Aug 18, 2026
  3. added
    providers
    provider-codex
    on Aug 18, 2026
  4. SawyerHood commented on Aug 18, 2026

    @SawyerHood
    Collaborator

    Reproduction & root-cause report: https://get-bb.github.io/reports/issues/1727.html

    • Verdict: REPRODUCED · root-cause confidence: high
    • Root cause (short): codex app-server replays the previous turn's token usage on thread/resume and thread/fork; the codex bridge stamps that old Codex turn id with the NEW session's per-session prefix (bt--), so the server sees a turn it never stored turn/started for and (by design) drops the snapshot with a warn log — on resume the payload is an exact duplicate of what is already stored (log noise only), on fork the parent's inherited context usage is discarded until the fork's first turn.
    • Proposed fix: Keep the server-side orphan drop (it is the correct safety net; buffering would re-create the fork batch-wedging bug). Fix in the codex bridge (plugins/provider-codex/src/bridge/bridge.ts, toCanonicalEvents ~L620): track Codex turn ids this session has emitted turn/started for; for thread/tokenUsage/updated or thread/contextWindowUsage/updated naming any other turn (only resume/fork replays do that), emit the context-window usage thread-scoped ({kind:"thread"} is allowed by the domain scope policy and is what the ACP bridge already does) and drop the token usage (turn-only by policy; duplicate…
    • Caveats: Not a visual bug, so no screenshots. The worktree was created at a108fa7 (origin/main tip) rather than 16ceb3a; I checked out 16ceb3a before the live runs and rebuilt (relevant files are equivalent between the two). The bridge-level repro test needs a small opt-in extension of the test fixture fake-codex-app-server.mjs (diff included) to mirror the real app-server's usage replay on resume; t…

    The report has copy-paste repro steps, screenshots where the bug is visual, code permalinks at 16ceb3a54, and repro artifacts. It was independently re-run by a second agent (see its Verification section).

    AGENT GENERATED: by Claude Opus 5

  5. added
    confirmed-repro
    on Aug 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

confirmed-reproprovider-codexproviders

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions