#15378: feat(exec): support `background: false` to force synchronous execution
agents
size: XS
Cluster:
Cron Job Stability Fixes
## Summary
- Gives `background: false` an explicit meaning: **force synchronous execution**, suppressing the yield timer entirely
- Previously `false` was a no-op (treated the same as omitting the parameter) — no backwards-compatibility impact
- Adds a test verifying synchronous completion even with an aggressive `backgroundMs: 10`
### Semantics after this change
| Value | Behavior |
|---|---|
| `background: true` | Immediate background (unchanged) |
| `background: undefined` | Timer-based auto-background via `yieldMs`/`backgroundMs` (unchanged) |
| `background: false` | **Synchronous — no yield timer, blocks until completion (new)** |
## Motivation
I'm building [agentpass](https://github.com/TorbenWetter/agentpass), a security gateway that mediates AI agent requests to Home Assistant through human approval on Telegram. The `agentpass request` CLI command blocks for up to 15 minutes while waiting for the guardian to approve or deny.
With the current exec tool, the default 10-second yield timer backgrounds these commands prematurely, causing the agent to announce intermediate status messages instead of waiting silently for the result. Neither `yieldMs` (clamped to 120s) nor globally raising `backgroundMs` solve this cleanly — you'd need per-command control.
`background: false` is the natural inverse of `background: true` and gives skills exactly that control.
## Implementation
When `background: false` is passed, `yieldWindow` is set to `null` — the same value used when `allowBackground` is globally disabled. This means no `setTimeout` race is created, and the code falls through to the synchronous `run.promise.then(...)` path.
## Test plan
- [x] New test: `"forces synchronous execution with background=false"` — creates an exec tool with `backgroundMs: 10`, runs a command with `background: false`, asserts `status === "completed"` (not `"running"`)
- [x] All 22 existing tests in `bash-tools.test.ts` and `bash-tools.exec.background-abort.test.ts` still pass
- [x] `pnpm build && pnpm check` passes (oxfmt, tsgo, oxlint — 0 warnings, 0 errors)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This PR updates the `exec` agent tool to give `background: false` explicit semantics: it disables the yield/background timer entirely and forces the tool call to wait for command completion. The change is implemented by treating `background === false` as a request for synchronous execution (`yieldWindow = null`), which skips the `setTimeout` yield race and falls through to the existing `run.promise.then(...)` completion path.
A new unit test is added to `bash-tools.test.ts` to ensure a command completes synchronously even when `backgroundMs` is configured aggressively low (10ms). Existing `background: true` and timer-based yield behavior (`yieldMs`/`backgroundMs`) are unchanged.
<h3>Confidence Score: 5/5</h3>
- This PR is safe to merge with minimal risk.
- The change is narrowly scoped (only affects yield-timer selection) and is covered by a targeted new unit test. The synchronous path already exists; this PR just makes it reachable via an explicit parameter. No additional callsites or side effects were introduced in the reviewed code.
- No files require special attention
<sub>Last reviewed commit: 461484b</sub>
<!-- greptile_other_comments_section -->
<sub>(2/5) Greptile learns from your feedback when you react with thumbs up/down!</sub>
<!-- /greptile_comment -->
Most Similar PRs
#23309: fix: remove 30-minute timeout for background exec sessions
by vksvikas · 2026-02-22
77.1%
#19632: fix: suppressToolErrors now suppresses exec tool failure notifications
by Gitjay11 · 2026-02-18
71.3%
#14127: fix(exec): return command output when gateway approval is Always Allow
by Siziff · 2026-02-11
71.1%
#8464: feat: make exec approval timeout configurable
by fabioaraujopt · 2026-02-04
70.7%
#18992: fix: suppress spurious tool error warnings for read-only exec commands
by Phineas1500 · 2026-02-17
70.4%
#20382: fix: move suppressToolErrors check before mutating tool check
by klawdius-noodle · 2026-02-18
69.6%
#18934: fix(agents): suppress exec tool output from channel delivery
by BinHPdev · 2026-02-17
69.4%
#17552: fix(agents): suppress tool error warnings when assistant already re...
by AytuncYildizli · 2026-02-15
69.1%
#19595: fix: elevatedDefault should default to off when tools.elevated.enab...
by guirguispierre · 2026-02-18
69.0%
#22087: Preserve assistant reply when exec fails under suppressToolErrors
by graysurf · 2026-02-20
68.9%