Skip to content

The agent that grows with you

fix: keep _redact_process_result's one-arg signature; hook task_id is the process owner's

teknium1152bef7531bb
diff --git a/tests/tools/test_process_registry.py b/tests/tools/test_process_registry.py
index dfac3336ade..69de2ef1155 100644
--- a/tests/tools/test_process_registry.py
+++ b/tests/tools/test_process_registry.py
@@ -2075,8 +2075,10 @@ class TestHandleProcessTransformHook:
out = json.loads(pr._handle_process({"action": action, "session_id": sess.id}, task_id="task-bg"))
assert out[key].startswith("REWRITTEN:raw line"), (action, out)
assert [s for s in seen if s[0] == "transform_terminal_output"]
- # The hook sees the command, the recorded exit code (None while running) and the caller's task_id.
- assert ("transform_terminal_output", "python app.py", 3, "task-bg") in seen
+ # The hook sees the command, the recorded exit code (None while running) and the process
+ # OWNER's task_id (the session's, not the caller's — a sibling polling a handed-off process
+ # is still observing that owner's output).
+ assert ("transform_terminal_output", "python app.py", 3, "t1") in seen
def test_hook_replacement_is_still_redacted(self, monkeypatch):
secret = "sk-proj-abc123def456ghi789jkl012mno345"
diff --git a/tools/process_registry.py b/tools/process_registry.py
index ae924176c79..2b417d618c9 100644
--- a/tools/process_registry.py
+++ b/tools/process_registry.py
@@ -2499,7 +2499,7 @@ def transform_process_output(output: str, *, command: str, returncode: Optional[
return _apply_output_transform_hook(command, output, returncode, task_id or "", "")
-def _redact_process_result(result: dict, *, task_id: str = "") -> dict:
+def _redact_process_result(result: dict) -> dict:
"""Transform, then redact secrets from background-process output before it reaches the
model, session.db and CLI, mirroring the foreground ``terminal`` pipeline (hook first,
redaction after) so the two surfaces can't diverge. Respects ``security.redact_secrets``;
@@ -2512,7 +2512,10 @@ def _redact_process_result(result: dict, *, task_id: str = "") -> dict:
from agent.redact import redact_sensitive_text, redact_terminal_output
command = result.get("command") or ""
- task_id = task_id or str(result.get("task_id") or "")
+ # The hook's task_id is the process OWNER's (poll/log/wait results carry only session_id).
+ task_id = str(result.get("task_id") or "")
+ if not task_id and (session := process_registry.get(str(result.get("session_id") or ""))) is not None:
+ task_id = str(getattr(session, "task_id", "") or "")
for key in ("output", "output_preview"):
if isinstance(value := result.get(key), str) and value:
value = transform_process_output(value, command=command, returncode=result.get("exit_code"), task_id=task_id)
@@ -2605,7 +2608,7 @@ def _handle_process(args, **kw):
return tool_error(f"session_id is required for {action}")
handler, redact = _SESSION_ACTIONS[action]
result = handler(session_id, args)
- return json.dumps(_redact_process_result(result, task_id=kw.get("task_id") or "") if redact else result, ensure_ascii=False)
+ return json.dumps(_redact_process_result(result) if redact else result, ensure_ascii=False)
return tool_error(f"Unknown process action: {action}. Use: list, poll, log, wait, kill, write, submit, close, handoff")