The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(gateway): polish background process notifications
Tim Smykovbfbf31d5768d
diff --git a/gateway/run_notifications.py b/gateway/run_notifications.pyindex 1b66585b8b8..440db0d8eb2 100644--- a/gateway/run_notifications.py+++ b/gateway/run_notifications.py@@ -1644,7 +1644,8 @@ class GatewayNotificationsMixin:def _redacted_output_tail(session, limit: int) -> str:"""Last ``limit`` chars of process output through the secret redactors (unconditional floor)."""from gateway.run import _redact_gateway_user_facing_secrets- new_output = session.output_buffer[-limit:] if session.output_buffer else ""+ from tools.ansi_strip import strip_ansi+ new_output = strip_ansi(session.output_buffer[-limit:]) if session.output_buffer else ""if new_output:from agent.redact import redact_terminal_outputnew_output = redact_terminal_output(new_output, getattr(session, "command", "") or "")@@ -1703,19 +1704,26 @@ class GatewayNotificationsMixin:}def _format_process_final_message(self, session_id: str, session, notify_mode: str) -> str:+ """Human-facing completion message. Every mode shares the one-line status header; the+ raw-output modes (all/result/error) append the bounded output tail under it instead of the+ old bracketed ``[Background process proc_… finished~ …]`` debug wrapper (#54266)."""from gateway.run import _format_concise_process_notification, _redact_gateway_user_facing_secretsnew_output = self._redacted_output_tail(session, 1000)- if notify_mode != "concise":- return (- f"[Background process {session_id} finished with exit code {session.exit_code}~ "- f"Here's the final output:\n{new_output}]"- )_started = getattr(session, "started_at", None)_dur = max(0.0, time.time() - _started) if isinstance(_started, (int, float)) else None- return _format_concise_process_notification(- session_id, _redact_gateway_user_facing_secrets(getattr(session, "command", "") or ""),- session.exit_code, new_output, duration_seconds=_dur,- )+ command = _redact_gateway_user_facing_secrets(getattr(session, "command", "") or "")+ if notify_mode == "concise":+ return _format_concise_process_notification(session_id, command, session.exit_code, new_output,+ duration_seconds=_dur)+ header = _format_concise_process_notification(session_id, command, session.exit_code, "", duration_seconds=_dur)+ return f"{header}\n\nFinal output:\n```\n{new_output.strip()}\n```" if new_output.strip() else header++ def _format_process_running_message(self, session) -> str:+ from gateway.run import _redact_gateway_user_facing_secrets, _shorten_command_for_display+ new_output = self._redacted_output_tail(session, 500)+ short_cmd = _shorten_command_for_display(_redact_gateway_user_facing_secrets(getattr(session, "command", "") or ""))+ header = "⏳ Background task still running" + (f" — `{short_cmd}`" if short_cmd else "")+ return f"{header}\n\nRecent output:\n```\n{new_output.strip()}\n```" if new_output.strip() else headerasync def _run_process_watcher(self, watcher: dict) -> None:"""Poll a background process and push updates until it exits. Mode@@ -1782,9 +1790,7 @@ class GatewayNotificationsMixin:elif has_new_output and notify_mode == "all" and not agent_notify:# New output — deliver a status update (only in "all" mode; agent_notify watchers# only care about completion).- new_output = self._redacted_output_tail(session, 500)await self._send_watcher_message(- platform_name, chat_id, thread_id,- f"[Background process {session_id} is still running~ New output:\n{new_output}]", watcher,+ platform_name, chat_id, thread_id, self._format_process_running_message(session), watcher,)logger.debug("Process watcher ended%s: %s", " (silent)" if silent else "", session_id)diff --git a/website/docs/user-guide/messaging/index.md b/website/docs/user-guide/messaging/index.mdindex 96446f46e04..ea9a505e80a 100644--- a/website/docs/user-guide/messaging/index.md+++ b/website/docs/user-guide/messaging/index.md@@ -519,9 +519,9 @@ display:| Mode | What you receive ||------|-----------------|| `concise` | One-line status message on completion; failures append a short output tail (default) |-| `all` | Running-output updates **and** the final raw-output message |-| `result` | Only the final raw-output completion message (regardless of exit code) |-| `error` | Only the final raw-output message when the exit code is non-zero |+| `all` | Running-output updates **and** the final status message with the output tail |+| `result` | Only the final status message with the output tail (regardless of exit code) |+| `error` | Only the final status message with the output tail when the exit code is non-zero || `off` | No process watcher messages at all |You can also set this via environment variable: