fix: stop emitting post-background exec updates (#61627) (thanks @openperf)

* fix(exec ): stop emitting tool updates after session is backgrounded

When an exec session is backgrounded (background: true), the owning
agent run resolves its tool-call promise and may finish.  The stdout
handler's emitUpdate() closure, however, kept invoking opts.onUpdate(),
delivering tool_execution_update events to a listener whose active run
had already ended.  This surfaced as an unhandled rejection and crashed
the gateway process.

Guard emitUpdate() with a session.backgrounded || session.exited check
so that post-background output is still captured via appendOutput() but
no longer forwarded to the (now-stale) agent-loop callback.

Fixes #61592

* style: trim exec backgrounding comments

* fix: stop emitting post-background exec updates (#61627) (thanks @openperf)

* fix: place exec changelog entry at end of fixes (#61627) (thanks @openperf)

---------

Co-authored-by: Ayaan Zaidi <hi@obviy.us>
This commit is contained in:
Chunyue Wang
2026-04-06 12:17:30 +08:00
committed by GitHub
parent e6d6b10470
commit b682202016
3 changed files with 35 additions and 0 deletions

View File

@@ -588,6 +588,9 @@ export async function runExecProcess(opts: {
if (!opts.onUpdate) {
return;
}
if (session.backgrounded || session.exited) {
return;
}
const tailText = session.tail || session.aggregated;
const warningText = opts.warnings.length ? `${opts.warnings.join("\n")}\n\n` : "";
opts.onUpdate({