Skip to content

fix(codex): preserve background waits when a turn ends - #832

Merged
lastobelus merged 1 commit into
lastcode/mainfrom
lastcode/fix-codex-background-wait-hold
Nov 23, 2026
Merged

lastobelus merged 1 commit into
lastcode/mainfrom
lastcode/fix-codex-background-wait-hold

Conversation

@lastobelus

@lastobelus lastobelus commented Nov 23, 2026 •

Copy link
Copy Markdown
Owner

A Codex command marked with t3_background_wait lost its hold as soon as the marking turn finished. The mark was saved with awaited: true, and then normal turn completion erased it.

Cause

#791 ported opt-in background waits from upstream #37572, pinned at 5e048c23d68396b46e7a2e387755da157dd04bee. Upstream publishes marks to the run stream. The LastCode change moved marks to the session's roster-only stream, outside the run subscriber.

Turn finalization still wrote the run's older provider snapshot. That snapshot omitted the new mark, so it overwrote the saved roster and cleared awaited. The live bisect identified 02ce8cbf9a5, which landed in a1c871f1062.

Fix

When Codex turn finalization commits, it now keeps the stored roster in the same database transaction. Explicit Stop and recovery clears still apply, as does withdrawal of pending results from exited commands.

Test

The new server integration test sends a session-scoped mark through real ingestion and normal turn finalization. It checks that the thread's pending tasks still include the awaited command. It failed before the fix and passed afterward. The earlier adapter replay skipped server-side finalization. The new test uses a provider fixture with the real server pipeline.

All 360 tests selected by the changed-files check passed, along with lint and typecheck.

Live testing on fe34e67ccb8301b6e1b616b8d0ff1362dae81308 used Codex gpt-6-luna with lastcodeBackgroundWaitEnabled enabled:

  • A marked command kept the thread waiting, woke it once with exit code 3, and left the pending task list empty.
  • A user message was answered during the wait. The thread returned to waiting and received the command result once.
  • A delegated Codex child kept its parent waiting and returned exactly one completed result with exit code 3.

Upstream convergence #823 · Feature tracking #824

Implemented with GPT-6.2 Sol in Codex. PR copy reviewed with Claude Sonnet 5.5 in Claude Code.

Session-scoped wait marks are already persisted when the run finalizes with an older provider snapshot. Preserve the stored roster in the terminal transaction, keeping explicit cleanup authoritative.

Implemented with GPT-6.2 Sol in Codex.

Carry-Group: incubator
Carry-Fix: #824
Carry-Observation: Keeps session-scoped Codex wait marks across normal root turn finalization after PR #791.
@lastobelus
lastobelus marked this pull request as ready for review November 23, 2026 03:13

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-23T03:15:58.902188Z fe34e67 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Chef's kiss.

Reviewed commit: fe34e67ccb

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@lastobelus
lastobelus merged commit 8e61df5 into lastcode/main Nov 23, 2026
58 of 66 checks passed
@lastobelus
lastobelus deleted the lastcode/fix-codex-background-wait-hold branch November 23, 2026 03:25
lastobelus added a commit that referenced this pull request Nov 23, 2026
Codex could drop the result of a command a thread was waiting on. If the command exited just before the marking turn ended, the result landed in the command item, and the thread and its delegated parent could finish before Codex saw it.

## What changed

- **Owed results** stay pending until the turn's completion is saved, then go out through the existing continuation path.
- **Automatic wraps** use Codex's token-usage notification to tell when the launch tool has returned and the shell is still running. Codex sends that notification after the batch's tools finish.
- **Explicit marks** confirm on their own when `t3_background_wait` matches the command.
- **Foreground commands** still get their result in the launch response.
- **Unsuccessful turns**, including interruptions, clear the owed result.
- **Instructions** now ask Codex for manual registration unless `lc-run` reports a registered wake. The `lc-run` launch line says LastCode already registered the wake and to end the turn without calling a tool. The standing instruction is 23 bytes shorter, and the wrapper prints the 316-byte launch line from the eval. The setting remains opt-in.

## Proof

- **Adapter replay** failed before the fix on mark → command exit → turn completion. It now covers that order, automatic marking, duplicate completion events, a foreground exit, interrupted turns, and withdrawing the wait.
- **Luna tool-use eval** passed 15 of 15 samples. The new wrapped case went from 0 of 3 passing to 3 of 3.
- **Changed-file checks** passed across 6 files, including 273 tests.
- **Recorded sessions** showed no token-usage update between launch and exit in all three foreground prepares. All three early exits from the eval had at least one update in that interval.
- **Real-session acceptance** against the pushed head is pending.

An automatically marked wrapper can still miss its wake if it yields and exits before the other tools in the same batch finish. Track that case in the #824 soak.

Follow-up to #791, #831 and #832. Tracks #824 and convergence under #823. The same settled-turn condition is present in [upstream pingdotgg#37572](https://redirect.github.com/pingdotgg/t3code/pull/37572) at `5e048c23d68396b46e7a2e387755da157dd04bee`.

Local review: 3 rounds with GPT-6.1 Terra (xhigh) at 02b382a, approved.

Implemented with GPT-6.2 Sol in Codex. PR copy reviewed with Claude Sonnet 5.5 in Claude Code.

Carry-Source-Ref: refs/lastcode/carry-sources/pr-833/02b382ae1173d8cc78425b824595e1d931f9592f
Carry-Source-Base: 4e02407
Carry-Source-Head: 02b382a
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.

1 participant