Skip to content

fix(codex): auto-unarchive archived sessions before retry - #1088

Open
patleeman wants to merge 2 commits into
get-bb:mainfrom
patleeman:agent/auto-unarchive-codex-sessions
Open

fix(codex): auto-unarchive archived sessions before retry#1088
patleeman wants to merge 2 commits into
get-bb:mainfrom
patleeman:agent/auto-unarchive-codex-sessions

Conversation

@patleeman

@patleeman patleeman commented Aug 6, 2026

Copy link
Copy Markdown

Why this is needed

bb reaps idle thread-scoped Codex processes after 30 minutes and later resumes them by provider thread ID. The persisted Codex session can also be archived independently, for example when its thread is archived in Codex Desktop. If bb later sends thread/resume, turn/start, or turn/steer for that provider thread, Codex rejects the request, and bb surfaces the failure, leaving the user to unarchive the session manually before trying again.

What changed

The runtime now recognizes Codex's archived-session error, sends thread/unarchive for the recorded provider thread, and retries the original request once. Recovery is limited to Codex and to that specific error, so other providers and other failures keep their existing behavior.

The recovery uses the existing command path for resume, turn start, and steer, including resume during thread reconfiguration. Turn-start bookkeeping still rolls back correctly if either the initial request or the retry fails.

Persisted Codex threads now start with ephemeral: false. This lets Codex materialize the rollout on disk so bb can resume it after reaping the provider process. The obsolete persistExtendedHistory field is no longer sent on start or resume.

Validation

The regression test reuses the existing fake provider and makes it return the archived-session error until bb sends thread/unarchive. This covers the recovery path without adding a separate test process or harness.

  • pnpm exec turbo run test --filter=@bb/agent-runtime — 811 tests passed
  • pnpm exec turbo run test --filter=@bb/host-daemon — 479 tests passed
  • pnpm exec turbo run typecheck --filter=@bb/agent-runtime --filter=@bb/host-daemon — passed
  • Prettier check and git diff --check — passed

Live verification

I also ran the source dev app from this branch with the real Codex CLI. I created a disposable thread, confirmed the initial Codex response, and archived only its underlying provider session with codex archive. I then restarted the dev host daemon to recreate the provider process and sent a normal follow-up through pnpm bb:dev thread tell --mode auto.

The follow-up completed successfully and returned BB_LIVE_RESTARTED_RECOVERY_OK. The Codex rollout record moved from its archived-session store back into the active session store, confirming that bb unarchived the provider session before retrying.

This remains a draft for maintainer review.

@patleeman
patleeman marked this pull request as ready for review August 6, 2026 21:49
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