Repository navigation
Conversation
A tool result over the cap was cut only on the way to the session log. The model kept the full result for the rest of the turn, so the next turn's replay diverged at the cut and the provider re-prefilled the whole turn. Bound the result when it enters the conversation. The preview is what the session files and replays; the full body goes to a managed file under the workspace, named by a trusted hint. The limit is opencode's line/byte budget (2000 lines or 50 KiB, whichever is reached first), with a tail preview for exec. The cut stays inside the untrusted fence and keeps the END marker and any trusted note. The save-side cap remains as a fallback for a result no ingestion path bounded.
gloryfromca
left a comment
There was a problem hiding this comment.
Blocking: the managed-output writer can escape the workspace through a pre-existing symlink and change the target directory's permissions.
I reviewed the full diff and the surrounding result-ingestion, trust-fence, session replay, retrieval, and transcript paths. I also checked the commit history and compatibility of the legacy character cap, looked for weakened tests, and covered the applicable AGENTS.md, CONTEXT-MAP.md/runtime architecture constraints.
Verification: uv run pytest tests/test_tool_output_store.py tests/test_context_source_refs.py tests/test_agent_loop_turn_record.py tests/test_security_trust.py tests/test_agent_loop_backend_dispatch.py tests/test_rpc_session.py -x (370 passed). The first attempt did not execute tests because the fresh environment lacked raven_everos; after uv sync --all-packages, the unchanged command passed.
One blocking finding is inline.
A pre-existing tool-output symlink made mkdir, chmod, os.open and prune_tool_outputs act on its target outside the workspace. Refuse a symlinked managed directory before mkdir, and re-check after mkdir that it still resolves under the workspace before chmodding or writing. A refused path keeps the existing fallback: the model gets the bounded preview with no path, and prune is not reached. Add tests for an outside target and an inside target; both fail at the previous head and pass after the fix.
|
@0xKT could you take a look for approval when you have a minute? The B1 |
gloryfromca
left a comment
There was a problem hiding this comment.
No blockers; this can merge as far as I am concerned.
The symlink escape reported on the prior revision is fixed and the thread is settled. I reviewed the new commit and rechecked the full diff, result-ingestion and managed-file callers, trust-fence and replay behavior, relevant history and backward compatibility, test changes for weakening, and the applicable AGENTS.md and CONTEXT-MAP.md/runtime architecture constraints. I found no new plain error worth raising.
Verification: uv run pytest tests/test_tool_output_store.py tests/test_context_source_refs.py tests/test_agent_loop_turn_record.py tests/test_security_trust.py tests/test_agent_loop_backend_dispatch.py tests/test_rpc_session.py -x (372 passed).
Summary
A tool result over the cap used to be cut only on the way to the
session log. The model kept the full result for the rest of the turn,
so the next turn's replay diverged at the cut and the provider
re-prefilled the whole turn.
The result is now bounded when it enters the conversation. The
bounded preview is what the session files and replays; the full body
is written to a managed file under the workspace and named in a
trusted hint. The preview stays inside the untrusted fence, keeps the
END marker and any trusted note, and uses opencode's budget: 2000
lines or 50 KiB of UTF-8 bytes, whichever is reached first. exec
keeps the tail of its output; every other tool keeps the head.
The managed file is created owner-only, pruned after seven days, and
the hint names only the reader tools the turn actually has. A write
failure still returns the bounded preview without a path, so a
side-file failure never fails the turn. The save-side character cap
remains as a fallback for a result no ingestion path bounded, and
the legacy toolResultMaxChars setting is still honoured as an extra
cap.
A pre-existing
tool-outputsymlink is refused: the writer checksthe managed directory before and after
mkdir, and refuses it unlessit resolves inside the workspace. A refused path falls back to the
bounded preview with no path.
Follows the cache-hit work in #1276 and #1294.
Type
Verification
The user-facing docs did not change; the config docstrings describe
the new budgets and the managed file.
The new regression tests cover: the send/replay byte equality across
two turns, the managed file body, line/byte/character budgets, the
exec tail, idempotence, a tool result carrying its own marker, a
write failure, the seven-day prune, reader-tool selection in the
hint, atomic 0600 file creation with chmod disabled, and a symlinked
managed directory. The symlink tests cover an outside target (no
file, no mode change, no prune of an old file) and an inside target
(the refusal is unconditional); both fail at the previous head and
pass after the fix.
Risk
Under-budget tool results are unchanged. Over-budget results
intentionally show the model a bounded preview plus a path hint
instead of the full body; the full body is in a 7-day managed file
and the model can read it with the file tools the turn has. That is
the trade that keeps this turn's sent bytes equal to the next turn's
replay. The full body now uses disk outside the session JSONL; the
preview remains the durable replay record. Files are created with
O_EXCL and mode 0600, the directory is 0700, and the body is
scrubbed before fencing. A symlinked managed directory cannot
redirect the write, the chmod or the prune outside the workspace. A
concurrent directory swap between the check and the open is not
closed by this change; that needs the dirfd/openat hardening.
Legacy toolResultMaxChars is still honoured as an extra cap, so old
configs load and keep their bound. Rollback is a revert; there is no
data or config migration, and managed files are temporary.
Related Issues
Follows the cache-hit work in #1276 and #1294. No issue is closed by
this PR.