mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-05-22 05:22:09 +00:00
fix(tool-result-storage): persist via stdin to bypass 128 KB exec-arg cap (#22913)
Linux's MAX_ARG_STRLEN caps any single argv element at 128 KB (32 * PAGE_SIZE). The previous heredoc-in-the-command-string approach in _write_to_sandbox put the entire tool result inside the 'bash -c' arg, so any result over ~128 KB raised OSError [Errno 7] 'Argument list too long' before the heredoc ever ran. The caller logged a warning, but quiet_mode (CLI default) sets tools.* to ERROR — so the warning never reached agent.log either, and the agent saw a 1.5 KB preview tagged 'Full output could not be saved to sandbox'. Hits delegate_task with 3+ subagent outputs routinely now. Switch to passing content via env.execute(stdin_data=...). cmd is now just 'mkdir -p X && cat > Y' (under 1 KB), and the heavyweight payload travels through stdin where there is no argv-element limit. E2E reproduced the user's exact 144,778-char delegate_task envelope: old code OSError'd, new code round-trips cleanly to disk with all three task summaries intact.
This commit is contained in:
parent
ded194eb6a
commit
08ec602770
2 changed files with 29 additions and 20 deletions
|
|
@ -76,15 +76,21 @@ def _heredoc_marker(content: str) -> str:
|
|||
|
||||
|
||||
def _write_to_sandbox(content: str, remote_path: str, env) -> bool:
|
||||
"""Write content into the sandbox via env.execute(). Returns True on success."""
|
||||
marker = _heredoc_marker(content)
|
||||
"""Write content into the sandbox via env.execute(). Returns True on success.
|
||||
|
||||
Pushes ``content`` through stdin rather than embedding it in the command
|
||||
string. Linux's ``MAX_ARG_STRLEN`` caps any single argv element at 128 KB
|
||||
(32 * PAGE_SIZE), so the previous heredoc-in-the-command-string approach
|
||||
silently failed with ``OSError: [Errno 7] Argument list too long`` for any
|
||||
tool result over ~128 KB — exactly the case persistence exists to handle.
|
||||
Routing through stdin removes that ceiling on local + ssh (``_stdin_mode
|
||||
== "pipe"``); remote backends with ``_stdin_mode == "heredoc"`` keep their
|
||||
existing API-body sized limit, which is orders of magnitude larger than
|
||||
the exec-arg ceiling.
|
||||
"""
|
||||
storage_dir = os.path.dirname(remote_path)
|
||||
cmd = (
|
||||
f"mkdir -p {shlex.quote(storage_dir)} && cat > {shlex.quote(remote_path)} << '{marker}'\n"
|
||||
f"{content}\n"
|
||||
f"{marker}"
|
||||
)
|
||||
result = env.execute(cmd, timeout=30)
|
||||
cmd = f"mkdir -p {shlex.quote(storage_dir)} && cat > {shlex.quote(remote_path)}"
|
||||
result = env.execute(cmd, timeout=30, stdin_data=content)
|
||||
return result.get("returncode", 1) == 0
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue