Skip to content

[#180]: fix(discover): recognise token_budget_abort and inference_stream_cancelled as turn-terminating events#184

Merged
delexw merged 4 commits into
mainfrom
fix-issue-180
Jul 14, 2026
Merged

[#180]: fix(discover): recognise token_budget_abort and inference_stream_cancelled as turn-terminating events#184
delexw merged 4 commits into
mainfrom
fix-issue-180

Conversation

@delexw

@delexw delexw commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

Problem

Codex v0.142.0 introduced token_budget_abort (fired when the rollout token budget is exhausted) and inference_stream_cancelled (fired when inference is cancelled mid-turn). Codex v0.143.0 (PRs #29918 and #30144) now reliably flushes both events to disk during shutdown — previously they could be lost.

The scan_session_file function in discover.rs classifies a session as completed by recognising turn-terminating events (task_complete, turn_aborted). However, token_budget_abort and inference_stream_cancelled fell through to the catch-all _ => {} arm and were silently ignored. As a result, sessions that terminated via budget exhaustion or cancelled inference were incorrectly shown as is_ongoing = true in the session list until the 60-second mtime fallback elapsed.

Fix

Added a combined match arm in the event_msg branch of scan_session_file:

"token_budget_abort" | "inference_stream_cancelled" => {
    is_ongoing = false;
    end_time = v
        .get("timestamp")
        .and_then(|v| v.as_str())
        .map(|s| s.to_string());
}

This mirrors the existing turn_aborted handler and correctly marks the session as not ongoing, capturing end_time from the event timestamp.

Tests

Two regression tests added to src-tauri/src/parser/discover.rs:

  • v0143_token_budget_abort_marks_session_not_ongoing — verifies a session file containing token_budget_abort (no task_complete) is discovered with is_ongoing = false and correct end_time.
  • v0143_inference_stream_cancelled_marks_session_not_ongoing — same for inference_stream_cancelled.

All 323 Rust lib tests pass. Clippy -D warnings clean.

Fixes #180

delexw added 3 commits July 12, 2026 11:05
…elled as turn-terminating events

Codex v0.142.0 introduced token_budget_abort; Codex v0.143.0 (PRs
#29918, #30144) now reliably preserves both token_budget_abort and
inference_stream_cancelled on disk during shutdown.

The discover.rs scanner's event_msg match handled task_complete and
turn_aborted as turn-terminating signals, but left these two events to
fall through to the catch-all arm.  Sessions ending via budget exhaustion
or cancelled inference were therefore shown as is_ongoing=true in the
session list until the 60-second mtime fallback elapsed.

Add a combined match arm for both events that sets is_ongoing=false and
captures end_time from the event timestamp, consistent with the existing
turn_aborted handler.

Adds two regression tests in the discover module.

Fixes #180
…vents

Codex v0.143.0 (PRs #29918 and #30144) now preserves trailing realtime
transcript text and terminal rollout events during shutdown, and writes
session_end reliably via an atexit handler even after crashes.

Add a clarifying comment in turn.rs explaining that unknown event types
at the tail of a v0.143.0 session carry no turn-building semantics and
are safely handled by the existing catch-all. Add two regression tests
in session.rs:

- v0143_trailing_transcript_and_reliable_session_end_parse_correctly:
  a normal session with a trailing unknown event (realtime_transcript_text)
  between task_complete and session_end parses correctly with
  is_ongoing=false and final_answer populated.

- v0143_session_end_without_task_complete_marks_turn_aborted: a crash
  scenario where session_end is written by the atexit handler but
  task_complete was never emitted; the existing abrupt-cutoff workaround
  fires and sets TurnStatus::Aborted, is_ongoing=false.

Fixes #180
Codex v0.143.0 (PRs #29918, #30144) preserves trailing transcript text
and terminal rollout events during shutdown instead of dropping them.
Some of these events end in `_end` but carry no call_id and aren't
real tool calls. finalize_unknown_end() used unwrap_or_else to
fabricate a pending call for any unmatched _end event, so these
non-tool-call events were turned into phantom ToolCalls in the turn's
tool list.

Guard against this by returning early when call_id is empty and no
pending call matches, so terminal rollout events are discarded instead
of corrupting the turn.

Fixes #180
@delexw
delexw merged commit ac1565f into main Jul 14, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Compat] Codex v0.143.0: trailing transcript text and rollout events now preserved during shutdown

2 participants