Background task notifications should include exit code and output tail

Resolved 💬 1 comment Opened May 29, 2026 by ulfhammarqvist-st Closed Jul 2, 2026

Problem

When a background Bash command (run_in_background: true) completes, the <task-notification> delivered to the model contains only:

  • task ID
  • output file path
  • status: "completed"
  • a one-line summary like Background command "..." completed (exit code 0)

The exit code is buried in the summary string, not structured. And crucially, the actual output (stdout/stderr) is not included — the model has to make a separate Read call on the output file to see what happened.

In practice, the model often skips this step and treats "completed" as "succeeded." A command that fails with exit code 1 and a clear error message goes unnoticed because the notification looks identical to a success.

Proposal

Include two additional fields in the <task-notification>:

  1. exit_code (integer) — structured, not embedded in prose
  2. output_tail (string) — last N lines (e.g. 20) of the output file

Example:

<task-notification>
  <task-id>abc123</task-id>
  <status>completed</status>
  <exit-code>1</exit-code>
  <output-tail>
. postinstall: cp: no such file or directory: ./node_modules/foo/data
. postinstall: Failed
 ELIFECYCLE  Command failed with exit code 1.
  </output-tail>
</task-notification>

This way a non-zero exit code is impossible to miss, and the error context is right there without a round-trip.

Why this matters

Background tasks are used for builds, test runs, and long-running processes where the model proceeds with other work while waiting. When the result arrives, the model needs to make a correct judgment call immediately. Forcing a manual file read to discover failures is error-prone and adds latency. The information is already available — it just isn't surfaced.

View original on GitHub ↗

This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗