Skip to content

test(terminus): wait for the foreground process before sending Ctrl-C - #5943

Open
ananthsub wants to merge 3 commits into
mainfrom
ananthsub/terminus-interrupt-race
Open

ananthsub wants to merge 3 commits into
mainfrom
ananthsub/terminus-interrupt-race

Conversation

@ananthsub

@ananthsub ananthsub commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

What changed and why

This PR collects the timing fixes for the Terminus sandboxed agent's terminal tests. Two tmux-backed Ctrl-C tests sent keys after a fixed delay and assumed sleep was already running. Both failed when it was not.

Exited-shell recovery test, interrupt case. The test types set -e; sleep 120 and sends Ctrl-C a fixed 0.3 s later, then expects the pane to die. If Ctrl-C arrives before sleep starts, bash receives it at the prompt and keeps running, so the pane never dies. The test then fails with pane_dead still 0. In my own check on an unloaded host, the unmodified test failed all five isolated runs. The test now:

  • polls until sleep is the pane's foreground command before it pastes the queued input and sends Ctrl-C
  • polls for the dead pane with a 30 s deadline instead of a fixed 10 s loop
  • waits for the RECOVERED output after recovery with the polling helper, instead of a fixed loop that ended without saying what it last saw
  • polls pane.log for the same line, because pipe-pane writes the log through a separate process and the log can lag the screen
  • queues about 95 KB of pending input instead of about 1.3 MB

The 95 KB payload is still far more than the 4 KB kernel input queue, so tmux still holds pending input when the shell dies. The failure case (sleep 2; false) skips the new wait for sleep, because a slow runner could see that sleep finish before the poll.

Full-PTY Ctrl-C test. The test typed sleep 120, waited a fixed 0.3 s, and then checked that sleep was still running after a raw Ctrl-C. On a loaded runner the pane could be read before sleep had started, which failed with assert 'bash' == 'sleep'. A reviewer saw this in several of 20 loaded rounds. The test now polls until sleep is running before it sends the raw Ctrl-C. It still waits 0.2 s and reads once to check that sleep survived, because a slow runner can only make sleep look more stuck. The later checks for TERMINAL_RECOVERED and for the raw-mode bytes poll the pane instead of reading it once.

The full-PTY fix moves here from #5901, which no longer touches this file, so all Terminus test fixes land together. Both tests share one eventually helper. It polls until a condition holds and raises an error that includes the last value it saw.

Issue: none. This is a small test-only follow-up to the timing audit in #5901.

Validation

All runs used a venv built from the server lock file (uv sync --frozen --all-extras in responses_api_agents/terminus_2_sandboxed_agent) on a 24-core host:

  • Before the full-PTY fix moved here, the interrupt case was run 20 times in a row on an idle host and 20 times in a row with 24 busy loops spinning. Every run passed.
  • With the full-PTY fix in place, pytest -n 16 tests/test_terminal.py passed every test in 13 rounds. Ten rounds ran with 24 busy loops spinning. Other work kept the host's load average above 100 throughout.
  • After the pane.log poll was added, 4 more rounds under the same load passed every test.
  • In a separate review, 12 loaded rounds of the whole file under -n 16 with 24 busy loops passed every test. Removing the drain makes both Ctrl-C tests fail.
  • pre-commit run --files on the changed file passed.

A separate bug in the product's input drain can still lose Ctrl-C or give up too early under heavy parallelism. That bug is being fixed in #5951, which is stacked on this PR. The smaller payload keeps this test within the drain's fixed 5-second budget under load, but this test can still fail on the drain's false-quiet bug under heavy parallelism until that fix lands.

Rollout evidence

N/A: test-only change with no agent or verifier behavior change.

@github-actions

github-actions Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

@svcnvidia-nemo-ci svcnvidia-nemo-ci left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

SHIP

LGTM — no concerns found. I checked the updated recovery test against the terminal’s interrupt and recovery paths. Both exit triggers retain the assertions for discarded pending input, preserved files, and reset shell state.

Static review only; I did not run tests.

Note: formal approval is not available for this request, so this review is posted as a comment only.

Review generated by codex. This was a full review. Request a full review with /review reset=true.

ananthsub added a commit that referenced this pull request Nov 10, 2026
Several core, model, agent and terminal_bench_4 tests gave real work a
deadline of tens of milliseconds, or bounded how long it took, and
failed whenever a busy CI runner was slower.

Give deadlines that must not fire room for a slow runner, hold the
first model attempt on an event so only it times out, replace the
elapsed bound on concurrent stale-copy deletion with a gate that every
deletion must reach, and apply the 25 ms verifier budget only to the
terminal_bench_4 cases meant to run out of it.

The exec-transport and supervision changes moved to #5933 and the
terminus changes to #5943.

Signed-off-by: Ananth Subramaniam <[email protected]>
The interrupt case of the exited-shell recovery test sent Ctrl-C a fixed
0.3 s after typing `set -e; sleep 120`. When the Ctrl-C arrived before
sleep started, bash took it at the prompt, survived, and the pane never
died, so the test failed most runs even on an idle host.

Poll until sleep is the pane's foreground command before pasting the
queued input and sending Ctrl-C, and poll for the dead pane with a 30 s
deadline instead of a fixed 10 s loop. The polling helper matches the
one #5901 adds for the full-PTY test in the same file.

Signed-off-by: Ananth Subramaniam <[email protected]>
Make the polling helper raise with the last value it saw instead of
returning False, matching the copy in #5901, and use it
for the RECOVERED output wait in place of a silent fixed loop.

Queue 1024 commands (about 95 KB) instead of 32768 (about 1.3 MB).
That is still far beyond the 4 KB kernel input queue, so the test still
needs the drain. The smaller payload keeps the input drain's fixed
5 s budget from running out on a busy runner.

Signed-off-by: Ananth Subramaniam <[email protected]>
…e pane log

Bring the full-PTY Ctrl-C test fix over from #5901 so all
terminus test fixes land together. The test now polls until sleep is the
foreground command before sending the raw Ctrl-C, and polls the pane for
TERMINAL_RECOVERED and the raw-mode bytes instead of reading it once.
Under load it failed with `'bash' == 'sleep'` when the pane was read
before sleep had started.

The exited-shell recovery test also polls pane.log for the RECOVERED
line. pipe-pane writes the log through a separate process, so the log
can lag the screen that the earlier wait already checked.

Signed-off-by: Ananth Subramaniam <[email protected]>
@ananthsub
ananthsub force-pushed the ananthsub/terminus-interrupt-race branch from 446a8c1 to 5ce5723 Compare November 10, 2026 17:03
@ananthsub ananthsub changed the title test(terminus): wait for sleep before interrupting the exited shell test(terminus): wait for the foreground process before sending Ctrl-C Nov 10, 2026
ananthsub added a commit that referenced this pull request Nov 10, 2026
Several core, model, agent and terminal_bench_4 tests gave real work a
deadline of tens of milliseconds, or bounded how long it took, and
failed whenever a busy CI runner was slower.

Give deadlines that must not fire room for a slow runner, replace the
elapsed bound on concurrent stale-copy deletion with a gate that every
deletion must reach, and apply the 25 ms verifier budget only to the
terminal_bench_4 cases meant to run out of it.

The exec-transport and supervision changes moved to #5933 and the
terminus changes to #5943.

Signed-off-by: Ananth Subramaniam <[email protected]>
ananthsub added a commit that referenced this pull request Nov 11, 2026
Several core, model, agent and terminal_bench_4 tests gave real work a
deadline of tens of milliseconds, or bounded how long it took, and
failed whenever a busy CI runner was slower.

Give deadlines that must not fire room for a slow runner, replace the
elapsed bound on concurrent stale-copy deletion with a gate that every
deletion must reach, and apply the 25 ms verifier budget only to the
terminal_bench_4 cases meant to run out of it.

The exec-transport and supervision changes moved to #5933 and the
terminus changes to #5943.

Signed-off-by: Ananth Subramaniam <[email protected]>
@svcnvidia-nemo-ci svcnvidia-nemo-ci added ci CI, automation, test queue, or workflow infrastructure work area:agent Agent harnesses and Responses API agent behavior needs-review PR is ready for code review and waiting on a reviewer labels Nov 16, 2026

This branch was previously deployed

1 inactive deployment
public — 5ce57238 Deployed Nov 10, 2026 by copy-pr-bot[bot] via release / finalize / notify #11483
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:agent Agent harnesses and Responses API agent behavior ci CI, automation, test queue, or workflow infrastructure work needs-review PR is ready for code review and waiting on a reviewer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants