Skip to content

fix(tui): detach foreground shell before steering - #4979

Open
nightt5879 wants to merge 1 commit into
Hmbown:mainfrom
nightt5879:nightt5879/issue-4930-detach-before-steer
Open

fix(tui): detach foreground shell before steering#4979
nightt5879 wants to merge 1 commit into
Hmbown:mainfrom
nightt5879:nightt5879/issue-4930-detach-before-steer

Conversation

@nightt5879

Copy link
Copy Markdown
Contributor

Summary

  • request that a blocking foreground Bash wait move to /jobs before enqueueing a same-turn steer
  • keep the current busy-Enter queue behavior intact while covering every path that actually steers, including explicit steer and queued-message promotion
  • distinguish true foreground waits from detached jobs that intentionally remain Running

Fixes #4930

Why this still applies on current main

Since the report, bare Enter during a busy turn was changed to queue a follow-up. The ordering bug still exists when that follow-up is explicitly promoted into the active turn (or the user uses the explicit steer chord): the shared steer boundary sent the message without first releasing a foreground shell wait. Centralizing the detach request in steer_user_message preserves the newer queue contract and fixes every real steer entry point.

The App and Engine share the same ShellManager. Setting its foreground-background request before enqueueing the steer lets the Bash wait loop return; the turn loop can then consume the steer. If shell tracking cannot accept the request, the existing lossless fallback restores the draft/queue instead of sending out of order.

Verification

  • cargo fmt --all -- --check
  • cargo check -p codewhale-tui --bin codewhale-tui --locked
  • focused UI steer tests: 2 passed
  • foreground/background classification tests: 2 passed
  • queued-message promotion test: 1 passed
  • real foreground shell detach test: 1 passed
  • TUI Clippy with -D warnings: passed after allowing four Rust 1.95 lint classes already present in untouched upstream code
  • full TUI binary suite before the final classification-only boundary test: 9,216 passed, 4 ignored, 4 failed; the three parallel shared-state/timing failures all passed immediately in isolation, while the documented Windows Job Object baseline failure reproduced in isolation and its failing test/implementation are unchanged
  • git diff --check

Self-review

Reviewed the hook, pause-state rollback, queue fallback, Ctrl+B, detached-job, and engine-consumption paths. Message-submit denial happens before detach, normal busy Enter still queues, shell-manager errors fail closed, existing Ctrl+B status text is preserved, and detached jobs with a shell_task_id no longer masquerade as foreground waits.

Request that a blocking foreground Bash wait move to /jobs before enqueueing same-turn steer input, so the turn loop can consume the user's follow-up. Preserve the existing lossless queue fallback if shell tracking cannot accept the request.

Distinguish a true foreground wait from detached Running jobs by their shell task identity, and cover both the ordering and classification boundaries with regression tests.

Fixes Hmbown#4930

Signed-off-by: Nightt <87569709+nightt5879@users.noreply.github.com>
@nightt5879
nightt5879 requested a review from Hmbown as a code owner July 30, 2026 02:51
@nightt5879

Copy link
Copy Markdown
Contributor Author

@codex review

Please review current head 171e97054. Focus on the ordering and failure-atomicity of requesting foreground Bash backgrounding before same-turn steer dispatch, the shared ShellManager boundary, hook/paused-state/queue fallback behavior, and whether shell_task_id.is_none() correctly distinguishes a foreground wait from an already detached Running job. Please flag any race that could leave a steer blocked or detach the wrong shell.

@chatgpt-codex-connector

Copy link
Copy Markdown

To use Codex here, create a Codex account and connect to github.

@Hmbown Hmbown added this to the v0.9.3 milestone Jul 30, 2026
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.

Enter during foreground shell should detach it before steering

2 participants