Skip to content

fix(coding-agent): asked before suspending on Ctrl+Z while work is running - #21139

Open
itskaism wants to merge 6 commits into
can1357:mainfrom
itskaism:fix/ctrl-z-busy-guard
Open

itskaism wants to merge 6 commits into
can1357:mainfrom
itskaism:fix/ctrl-z-busy-guard

Conversation

@itskaism

@itskaism itskaism commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

What

Ctrl+Z now asks before suspending when work is running. With a turn streaming, a running subagent or a background job, the first press shows a status line that names them, for example Still running: a turn, 2 subagents, 1 background job · press <key> again to suspend anyway, and does not stop the process. A second press within 3 seconds suspends as before. With nothing running, the first press suspends at once, as on main. Windows is unchanged (suspend is still unsupported there).

  • handleCtrlZ (modes/controllers/input-controller.ts) counts the work with the sources the HUD already uses: session.isStreaming for the turn, getRunningSubagentBadgeAgentIds(AgentRegistry.global()) for subagents (the running-subagents badge), and getBackgroundJobs over the running jobs of session.getAsyncJobSnapshot() for background jobs (the task job of a running subagent counts as that subagent).
  • getBackgroundJobs (modes/view-model/overlays/running-subagent-badge.ts) is the one rule for background jobs; the HUD jobs pill, the status line, Ctrl+Z and /pause call it. A task job counts as its subagent only while that subagent is in the running set, so a task job queued before its subagent starts is a background job, as the status line and /pause already counted it. The jobs pill counted only jobs without an agentId, so it now shows such a job too.
  • The confirm window is SUSPEND_CONFIRM_WINDOW_MS (3 s). It is longer than the 500 ms of the Ctrl+C and Esc double presses because the first press shows a line to read before deciding. A press after the window asks again. No setting is added.

Why

Reproduction

The interactive TUI on a pty whose session leader is an interactive bash with job control, omp as its job (Linux x64 under WSL2, main f6b51e293a from source, a scripted local model). Ctrl+Z (0x1a) moves omp from Sl+ to Tl, and bash prints [1]+ Stopped. omp shows no warning and asks nothing. Its worker child, in its own session, stays in Ssl and keeps running beside the stopped parent until fg.

One terminal held four stopped omp processes.

Cause, at main b28a3d938d

  • packages/coding-agent/src/modes/controllers/input-controller.ts:559 sends app.suspend straight to handleCtrlZ (:1864), whose only check is the Windows one. It calls ctx.suspend(...) and process.kill(0, "SIGSTOP") (:1918) on the first press. The whole foreground process group stops: the turn and the in-process subagents freeze, while children in their own sessions (MCP stdio servers, the commands the embedded shell runs) keep running with nobody reading them.

Testing

packages/coding-agent/test/input-controller-suspend.test.ts. Its setup now gives the fake context a session (streaming flag and job snapshot) and stubs AgentRegistry.global().list(); the three existing cases run with nothing running. New cases:

  • holds the first press while work runs, naming it, and suspends on a second press: a streaming turn, 2 running subagents, one background job and one job that runs a subagent. The first press does not call suspend or process.kill and shows Still running: a turn, 2 subagents, 1 background job · press … again to suspend anyway. The second press sends SIGSTOP to the process group, and SIGCONT takes the terminal back.
  • asks again when the second press comes after the confirm window: with Date.now stubbed, a second press 3 s after the first shows the line again and does not suspend.
  • holds the first press for a task job queued before its subagent runs: a task job whose subagent is not running yet holds the first press as one background job.

packages/coding-agent/test/running-subagent-background-jobs.test.ts (new): getBackgroundJobs keeps bash and eval jobs, drops the task job of a running subagent, and keeps a task job queued before its subagent runs and a task job without an agent.

packages/coding-agent/test/interactive-mode-hud-job-widgets.test.ts: new counts a task job queued before its agent runs as a background job (the jobs pill reads 1 job running); the existing counts and lists background jobs only, never a job that runs an agent now registers that agent as running.

The existing SIGSTOPs the foreground process group ... case covers the idle path: the first press suspends.

Results on Linux x64 (WSL2), bun 1.4.4:

  • Red, main b28a3d938d's packages/coding-agent/src with the first commit's tests: 3 pass, 2 fail. Both guard cases fail at expect(t.ctx.suspend).not.toHaveBeenCalled() (1 call, and 2 calls for the window case): main suspends on every press.
  • Red, the source before the getBackgroundJobs commit with this branch's tests: holds the first press for a task job queued before its subagent runs fails (1 call to suspend), counts a task job queued before its agent runs as a background job fails (no jobs segment), and the helper test does not load (Export named 'getBackgroundJobs' not found).
  • Green, this branch: input-controller-suspend 6 pass, running-subagent-background-jobs 4 pass, interactive-mode-hud-job-widgets 6 pass, status-line-background-jobs 2 pass, 0 fail in each. test/input-controller-escape.test.ts, test/input-controller-hard-abort-terminal.test.ts, test/collab/guest-subagent-badge.test.ts and test/modes/interactive-mode-live-settings.test.ts: 43 pass, 0 fail.
  • oxlint and oxfmt --check on the changed files: clean. bun run check:types in packages/coding-agent: no type errors in 5,878 files.
  • End to end on a pty, on this branch's last commit: omp as the job of an interactive bash, the scripted model running sleep 600 through the bash tool. The first Ctrl+Z left omp running (state S) and the driver found the Still running ... again to suspend anyway text on the screen; a second press within 3 s stopped it (state T). With main's packages/coding-agent/src in the same tree, the first press stopped it.
  • The runs above include no /pause test. Its job count now calls getBackgroundJobs with the rule it had before.
  • Not run: the whole bun check, so the first box below stays open.

Not covered

  • A collab guest counts the subagents of its own process, not the host's (the host's agents do not stop when the guest does).
  • Compaction and other work outside a turn, a subagent or an async job do not hold the key back.
  • When a second omp starts while a stopped one holds the newest session, --continue skips that session and resumes an older one, and --resume <id> saves to a new file. Neither says that the holder is stopped or names its pid. That is a separate change.

  • bun check passes
  • Tested locally
  • CHANGELOG updated with the required attribution (if user-facing; internal issue fixes use issue links, external contributions add the PR link and contributor credit after creation)

…nning

Ctrl+Z sends SIGSTOP to the whole foreground process group, so a running
turn and the in-process subagents freeze until `fg`, while commands in
their own sessions keep running with nobody reading them.

With a turn, a running subagent or a background job, the first press now
shows what is running and a second press within 3 seconds suspends. With
nothing running, Ctrl+Z suspends at once as before.
@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

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

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-30T14:34:39.973556Z
We couldn’t complete this review. Comment @codex review to try again.
dffed1e PR opened
ℹ️ 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 usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@roboomp roboomp added fix review:p2 triaged tui Terminal UI rendering and display ux User experience improvements labels Nov 30, 2026

@roboomp roboomp left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Rank P2. The diff is tight and correct: #runningWork gates handleCtrlZ, the idle path is unchanged, and the tests cover the hold, the confirm and the window expiry. But it changes what Ctrl+Z does by default (POSIX convention: suspend at once) with no setting to turn it off, so it needs a maintainer to sign off.

  • should-fix: the CHANGELOG entry has no PR/author attribution, though the checklist says it does.
  • should-fix: the background-job count copies #syncHudPills, and status-line.ts counts jobs a different way. Extract one shared helper.
    Maintainer question: should a busy session hold back Ctrl+Z by default, or should this sit behind a setting? A stopped job resumes intact on fg, so the harm is stalled detached children and forgotten stopped processes, not lost work.
    Thanks @itskaism for the careful repro and the red/green evidence.

Comment thread packages/coding-agent/CHANGELOG.md Outdated

### Fixed

- Ctrl+Z no longer suspends omp at once while a turn, subagents or background jobs are running. The first press names what is running, and a second press within 3 seconds suspends.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

should-fix — the entry has no attribution, but the PR checklist marks it done. AGENTS.md § Changelog says external contributions end with ([#21139](https://github.com/can1357/oh-my-pi/pull/21139) by [@itskaism](https://github.com/itskaism)). Also cut it to one user-facing line, e.g. Ctrl+Z now asks for a second press before suspending while a turn, subagents or background jobs are running.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done in 7b49595: the entry is now your one line, with the PR and author attribution. 9418389 adds a second line, with the same attribution, for the jobs pill change described in the other thread.

if (agents > 0) work.push(`${agents} ${agents === 1 ? "subagent" : "subagents"}`);
// A job that runs a subagent counts as that subagent, as in the HUD pills.
let jobs = 0;
for (const job of this.ctx.session.getAsyncJobSnapshot()?.running ?? []) if (job.agentId === undefined) jobs++;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

should-fix — this is the third copy of "count running async jobs that aren't a subagent's", and the copies disagree:

  • interactive-mode.ts:919-921 (#syncHudPills) counts job.agentId === undefined, the same rule as here.
  • status-line.ts:208-210 (#jobs) also counts type === "task" jobs whose agentId is not in the running-subagent set.

So the Ctrl+Z line can report a different job count from the status-line segment the user can see. AGENTS.md § Central Utilities: extract one helper (next to getRunningSubagentBadgeAgentIds in running-subagent-badge.ts, or on the session) and call it from all three places, or at least from the pill and here. The same goes for the subagent count: InteractiveMode already keeps #runningSubagentCount (interactive-mode.ts:3709-3716). Exposing it on InteractiveModeContext would stop this from walking the registry a second time.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done in 9418389. getBackgroundJobs(running, runningSubagentIds) sits next to getRunningSubagentBadgeAgentIds in running-subagent-badge.ts. The HUD jobs pill, the status line, Ctrl+Z and /pause call it; pauseWorkStatus in builtin-control.ts held a fourth copy, with the status line's rule.

The helper keeps the status line's rule. A task job counts as its subagent only while that subagent is in the running set, so a task job queued before its subagent starts counts as a background job. Under the pill's agentId === undefined rule that job showed in neither pill, and Ctrl+Z suspended at once while it ran. The pill now counts it for that window, so the changelog has a line for it. status-line-background-jobs.test.ts already asserted the status line's rule and is unchanged. New tests: the helper's cases, counts a task job queued before its agent runs as a background job for the pill, and holds the first press for a task job queued before its subagent runs for Ctrl+Z; both fail with the source before 9418389. The pill test for an agent's own job now registers that agent as running.

Ctrl+Z still reads AgentRegistry.global() for subagents instead of InteractiveMode's count. On a collab guest that count comes from the guest's mirror of the host's agents, which keep running when the guest's process stops; the walk runs once per key press. InteractiveMode now keeps the running ids (#runningSubagentIds) instead of their count, because the pill passes them to the helper.

…equest

Cut the entry to one line and added the PR and author attribution the changelog rules ask of external contributions.
…ll, status line, Ctrl+Z and /pause

The HUD jobs pill and the Ctrl+Z guard counted every job without an agentId. The status line and /pause also counted a task job whose subagent the running-subagents badge does not count, such as a job queued before its subagent starts. That job showed in neither HUD pill, and Ctrl+Z suspended at once with it running.

getBackgroundJobs, next to getRunningSubagentBadgeAgentIds, keeps the status line's rule, and all four places call it. Ctrl+Z still reads this process's registry rather than a collab guest's mirror of the host, since SIGSTOP stops only this process.
@itskaism

Copy link
Copy Markdown
Contributor Author

On the default: the guard changes Ctrl+Z only while a turn, a subagent or a background job is running. Then the first press shows what is running and leaves omp running; a second press within 3 s suspends as before. With nothing running, the first press suspends at once, as on main, and Windows is unchanged. A stopped omp does resume intact on fg, but until then the commands in their own sessions (MCP servers, the shell's commands) keep running with nobody reading them, and stopped sessions are easy to forget (one terminal held four stopped omp processes). I left out a setting to keep the change small.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix review:p2 triaged tui Terminal UI rendering and display ux User experience improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants