Skip to content

tui: add ephemeral /btw side-question threads#14506

Draft
charley-oai wants to merge 7 commits intomainfrom
ccunningham/btw-ephemeral-subagent
Draft

tui: add ephemeral /btw side-question threads#14506
charley-oai wants to merge 7 commits intomainfrom
ccunningham/btw-ephemeral-subagent

Conversation

@charley-oai
Copy link
Collaborator

@charley-oai charley-oai commented Mar 12, 2026

Summary

  • add a /btw slash command that forks the current thread into an isolated side-question child
  • keep BTW threads out of normal agent navigation and discard them when returning to the parent or switching away
  • add BTW footer copy plus TUI tests and snapshot coverage

Testing

  • cargo test -p codex-tui
  • just fix -p codex-tui
  • just fmt

@charley-oai charley-oai changed the title tui: make /btw threads ephemeral tui: add ephemeral /btw side-question threads Mar 13, 2026
charley-oai added a commit that referenced this pull request Mar 13, 2026
Bazel was failing the BTW app tests before they reached any BTW logic because the test helper tried to probe a real terminal on stdout. Add a test-only TUI constructor with synthetic terminal state and route the BTW app tests through it so they no longer depend on an interactive terminal.

Co-authored-by: Codex <noreply@openai.com>
@charley-oai
Copy link
Collaborator Author

@codex review this

Copy link
Contributor

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1909889d0a

ℹ️ 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".

@charley-oai
Copy link
Collaborator Author

@codex review this

Copy link
Contributor

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6170eda3ce

ℹ️ 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".

@charley-oai
Copy link
Collaborator Author

@codex review this

@chatgpt-codex-connector
Copy link
Contributor

Codex Review: Didn't find any major issues. Delightful!

ℹ️ 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".

charley-oai added a commit that referenced this pull request Mar 15, 2026
Bazel was failing the BTW app tests before they reached any BTW logic because the test helper tried to probe a real terminal on stdout. Add a test-only TUI constructor with synthetic terminal state and route the BTW app tests through it so they no longer depend on an interactive terminal.

Co-authored-by: Codex <noreply@openai.com>
@charley-oai charley-oai force-pushed the ccunningham/btw-ephemeral-subagent branch from dff7305 to 869c5d2 Compare March 15, 2026 07:27
@charley-oai
Copy link
Collaborator Author

@codex review this

Copy link
Contributor

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

codex/codex-rs/tui/src/app.rs

Lines 2456 to 2462 in 324aa33

if let Err(err) = app.handle_active_thread_event(tui, event).await {
break Err(err);
}
} else {
app.clear_active_thread().await;
}
AppRunControl::Continue

P1 Badge Propagate shutdown-complete exit from active thread handler

handle_active_thread_event now returns AppRunControl and emits Exit(UserRequested) after the tracked ShutdownComplete, but the main select-loop ignores that return value and always continues. This prevents ExitMode::ShutdownFirst from actually exiting on shutdown completion in the real app loop.

ℹ️ 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".

@charley-oai
Copy link
Collaborator Author

@codex review this

Copy link
Contributor

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 48b240cd92

ℹ️ 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".

charley-oai added a commit that referenced this pull request Mar 16, 2026
Bazel was failing the BTW app tests before they reached any BTW logic because the test helper tried to probe a real terminal on stdout. Add a test-only TUI constructor with synthetic terminal state and route the BTW app tests through it so they no longer depend on an interactive terminal.

Co-authored-by: Codex <noreply@openai.com>
@charley-oai charley-oai force-pushed the ccunningham/btw-ephemeral-subagent branch from ffac786 to a466f20 Compare March 16, 2026 05:39
@charley-oai
Copy link
Collaborator Author

@codex review this

Copy link
Contributor

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a466f20732

ℹ️ 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".

@charley-oai
Copy link
Collaborator Author

@codex review this

@chatgpt-codex-connector
Copy link
Contributor

Codex Review: Didn't find any major issues. Delightful!

ℹ️ 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".

charley-oai added a commit that referenced this pull request Mar 16, 2026
Bazel was failing the BTW app tests before they reached any BTW logic because the test helper tried to probe a real terminal on stdout. Add a test-only TUI constructor with synthetic terminal state and route the BTW app tests through it so they no longer depend on an interactive terminal.

Co-authored-by: Codex <noreply@openai.com>
@charley-oai charley-oai force-pushed the ccunningham/btw-ephemeral-subagent branch from 89aa63f to 68f5479 Compare March 16, 2026 06:45
@charley-oai
Copy link
Collaborator Author

@codex review this

@chatgpt-codex-connector
Copy link
Contributor

Codex Review: Didn't find any major issues. Swish!

ℹ️ 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".

@charley-oai charley-oai marked this pull request as ready for review March 16, 2026 15:59
@charley-oai charley-oai marked this pull request as draft March 16, 2026 16:02
@charley-oai
Copy link
Collaborator Author

@codex review this

Copy link
Contributor

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 31df052227

ℹ️ 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".

@charley-oai
Copy link
Collaborator Author

@codex review this

Copy link
Contributor

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b4e56ca00a

ℹ️ 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".

charley-oai added a commit that referenced this pull request Mar 17, 2026
Bazel was failing the BTW app tests before they reached any BTW logic because the test helper tried to probe a real terminal on stdout. Add a test-only TUI constructor with synthetic terminal state and route the BTW app tests through it so they no longer depend on an interactive terminal.

Co-authored-by: Codex <noreply@openai.com>
@charley-oai charley-oai force-pushed the ccunningham/btw-ephemeral-subagent branch from b4e56ca to 5570788 Compare March 17, 2026 03:44
charley-oai added a commit that referenced this pull request Mar 17, 2026
Bazel was failing the BTW app tests before they reached any BTW logic because the test helper tried to probe a real terminal on stdout. Add a test-only TUI constructor with synthetic terminal state and route the BTW app tests through it so they no longer depend on an interactive terminal.

Co-authored-by: Codex <noreply@openai.com>
@charley-oai charley-oai force-pushed the ccunningham/btw-ephemeral-subagent branch 2 times, most recently from 2be24f1 to 8ec8f95 Compare March 17, 2026 10:31
charley-oai and others added 3 commits March 23, 2026 19:29
Implement /btw as an ephemeral forked side-thread flow in the TUI and the
mirrored tui_app_server frontend. The branch adds BTW thread lifecycle and
navigation handling, uses interrupted-snapshot forks when needed, keeps BTW
threads hidden from normal agent navigation, routes BTW prompts to the model,
and mirrors the footer/fork-banner UI plus replay-only fallback behavior in the
app-server variant.

Co-authored-by: Codex <noreply@openai.com>
Co-authored-by: Codex <noreply@openai.com>
Resolve the remaining API and test drift after restacking the /btw implementation onto current main.

- align tui /btw with ForkSnapshot-based forking
- adapt tui_app_server BTW attachment to the current session/turn cache model
- make BTW fork banners deterministic even for unnamed parent threads
- clean up the stale thread_manager test import from the cherry-pick

Co-authored-by: Codex <noreply@openai.com>
@charley-oai charley-oai force-pushed the ccunningham/btw-ephemeral-subagent branch from a519259 to 5731998 Compare March 24, 2026 02:59
@charley-oai
Copy link
Collaborator Author

@codex review

Copy link
Contributor

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

self.select_agent_thread(tui, app_server, primary_thread_id)
.await?;

P2 Badge Use BTW-aware switch path during shutdown failover

When a BTW child closes unexpectedly, failover switches with select_agent_thread(...) instead of select_agent_thread_and_discard_btw_chain(...). That bypasses BTW cleanup, leaving entries in btw_threads/thread_event_channels after switching away. Hidden ephemeral threads can retain stale per-thread state (e.g., pending approvals) until a full reset.

ℹ️ 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".

charley-oai and others added 2 commits March 23, 2026 20:46
Co-authored-by: Codex <noreply@openai.com>
Co-authored-by: Codex <noreply@openai.com>
@charley-oai
Copy link
Collaborator Author

@codex review

Copy link
Contributor

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8a67c3f5c6

ℹ️ 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".

- add a live-thread fork path for pathless ephemeral threads
- use it for direct TUI /btw and /fork
- allow app-server thread/fork from ephemeral source threads

Co-authored-by: Codex <noreply@openai.com>
@charley-oai
Copy link
Collaborator Author

@codex review

Copy link
Contributor

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

async fn shutdown_current_thread(&mut self, app_server: &mut AppServerSession) {
if let Some(thread_id) = self.chat_widget.thread_id() {
// Clear any in-flight rollback guard when switching threads.
self.backtrack.pending_rollback = None;
if let Err(err) = app_server.thread_unsubscribe(thread_id).await {
tracing::warn!("failed to unsubscribe thread {thread_id}: {err}");
}
self.abort_thread_event_listener(thread_id);

P2 Badge Unsubscribe full BTW chain when replacing app-server session

This shutdown path only unsubscribes the active thread. After nested /btw, /fork and /resume call this and then clear local thread maps, so hidden BTW ancestors are no longer tracked but remain subscribed/running on the app server. That violates the discard-on-switch behavior and can leak background thread activity.

ℹ️ 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".

Comment on lines +684 to +685
if matches!(source_status, AgentStatus::Running) {
append_interrupted_boundary(history, /*turn_id*/ None)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Recompute turn state before adding interrupted fork boundary

fork_thread_from_thread gates ForkSnapshot::Interrupted on a stale source_status read before live_fork_history(). If the source thread completes between those awaits, status can still be Running and this appends an Interrupted boundary to already-complete history, producing an incorrect aborted turn in the fork.

Useful? React with 👍 / 👎.

Co-authored-by: Codex <noreply@openai.com>
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