Skip to content

fix(claude-code): keep Bash commands in the foreground in headless runs - #5549

Merged
lafrancef merged 1 commit into
NVIDIA-NeMo:mainfrom
gwarmstrong:georgea/claude-code-foreground-commands
Nov 4, 2026
Merged

lafrancef merged 1 commit into
NVIDIA-NeMo:mainfrom
gwarmstrong:georgea/claude-code-foreground-commands

Conversation

@gwarmstrong

@gwarmstrong gwarmstrong commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

claude_code_agent sets CLAUDE_CODE_DISABLE_BACKGROUND_TASKS=1 in the CLI's environment for host and sandbox runs. The README's limitations list now says so.

Why. A headless Claude Code run ends when the CLI exits, and the CLI first waits for every background task. When the model sets Bash's run_in_background on a long command, the CLI keeps waiting on it after the final answer, and the run holds its sandbox and model slot until the agent timeout.

In an internal HLE run with Claude Code 2.1.108, a rollout answered and ended its turn, then stayed open until its job was cancelled. 9 of its 47 Bash commands had been sent to the background (long brute-force loops, whose output the model then polled with sleep 2; cat <output file>).

In 2.1.108 the variable removes run_in_background from the Bash and agent tools, the prompt text that suggests it, and the Ctrl+B shortcut. Commands then run in the foreground, bounded by the Bash tool's own timeout. A model can still start a shell-level cmd &; the CLI does not track that, so it does not hold the run open.

Part of #5552. Found while validating Claude Code on HLE Diamond.

Validation

  • gym env test +entrypoint=responses_api_agents/claude_code_agent +should_validate_data=true: 171 passed.
  • The host and sandbox environment assertions fail when the variable is removed.
  • pre-commit run --all-files: clean.
  • Checked against the 2.1.108 release binary (SHA-256 verified against the release manifest): the variable gates the run_in_background parameter, its prompt text and the Ctrl+B shortcut.

Rollouts

Internal HLE Diamond text run with this change (Nemotron 3.5 Super on vLLM, 5 tasks, Claude Code 2.1.108 in OpenSandbox): 5/5 rollouts completed and healthy, and none ran on after its final answer (131 to 923 s per rollout). The Bash tool schema had no run_in_background, and 0 of 103 calls returned a background-task result. Before this change, one of the 5 rollouts in the same setup stayed open after its final answer until its job was cancelled.

Compatibility and benchmark impact

Behavior change for every Claude Code run through this adapter: the model can no longer background Bash commands through the CLI. A task that relied on run_in_background, for example to start a server and keep working, must use a shell-level background process instead. Before this change, such a run also held the rollout open until timeout after its answer.

Checklist

  • I have read the contributing guidelines.
  • The change is focused; unrelated "drive-by" edits are tracked as separate issues/PRs.
  • Tests added or updated and pass locally, or N/A for docs-only / non-code changes.
  • Documentation added or updated, or N/A with justification. The adapter README's limitations list describes the setting.
  • Pre-commit checks pass locally (pre-commit run --all-files).
  • New source files include the required Apache-2.0 SPDX header. N/A: no new source files.
  • All commits have DCO sign-off (git commit -s).

A headless Claude Code run ends when the CLI exits, and the CLI first
waits for every background task. When the model sets Bash's
run_in_background on a long command, the CLI keeps waiting on it after
the final answer, so the run holds its sandbox and model slot until the
agent timeout. On an HLE run with Claude Code 2.1.108, a rollout that
answered and ended its turn stayed open until its job was cancelled,
because 9 of its 47 Bash commands had been sent to the background.

Set CLAUDE_CODE_DISABLE_BACKGROUND_TASKS=1 for host and sandbox runs.
The CLI then drops run_in_background from the Bash tool, and each command
runs in the foreground under the Bash tool's own timeout.

Signed-off-by: gwarmstrong <[email protected]>
@copy-pr-bot

copy-pr-bot Bot commented Nov 3, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@gwarmstrong

Copy link
Copy Markdown
Contributor Author

/ok to test 6b91462

@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 reviewed all four changed files and traced the setting through the host and sandbox launch paths, including sandbox staging and the shared runner. Both paths pass the flag as "1", and the updated tests assert that value at their execution boundaries. The README documents the new default, and the PR supplies compatibility notes and representative smoke-rollout evidence.

This was a read-only source review. I didn't execute tests or independently verify the external CLI's interpretation of the flag.

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.

@lafrancef
lafrancef added this pull request to the merge queue Nov 4, 2026
@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/41796700026

Merged via the queue into NVIDIA-NeMo:main with commit 2748488 Nov 4, 2026
62 of 65 checks passed

This branch was previously deployed

1 inactive deployment
public — 6b914622 Deployed Nov 4, 2026 by copy-pr-bot[bot] via release / finalize / notify #9893
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.

3 participants