## Summary `tests/test_agents_code_flow_exec.py` carried a pin on trunk's `DirectExecutor` dropping a timed-out command's output. That was one of the reasons the code flow replaced the executor, and the pin's own docstring said what should happen to it: "pinned so a trunk fix can retire it". The trunk fix landed, the pin asserted the opposite of the truth, and `main` went red. **`main` is no longer red.** While this sat in review, a separate change replaced the pin with `test_trunks_executor_preserves_output_on_timeout`. That resolved the breakage and is the version kept here; this branch was rebased onto it rather than carrying a competing test. What remains is what that replacement did not cover: - **Why the fork exists on that axis.** The replacement asserts the new fact in one line and says nothing about what still separates the two executors. Trunk signals a kill through the stderr line and `exit_code` and nothing more, while `CodeExecResult` also flags `timed_out` and renders `TIMED_OUT_NOTE`, which tells the model its output is a fragment rather than a whole run. That difference is now asserted and explained where the pin used to sit. - **Three prose claims that are still false on `main`.** Both module docstrings advertise "the fork's three fixes" and describe trunk waiting on `communicate()` and losing the buffered output, in the present tense; the exec factory's docstring lists partial output as a difference. Each is corrected to say what is true now and what is left. The fork's drain now duplicates trunk's. That is noted in the docstring as the fork owners' call, because nothing depends on which of the two performs it and this change should not spend itself on that. No code is removed and no behaviour changes. ## Type - [x] Fix - [ ] Feature - [ ] Docs - [ ] CI / tooling - [ ] Refactor - [ ] Other ## Verification - `pytest tests/test_agents_code_flow_exec.py tests/test_agents_code_tools_plugin.py tests/test_sandbox_unit.py tests/test_agents_oncall_flow_hooks.py` -- 183 passed - `ruff check` and `ruff format --check` over the changed files -- clean - `lint-imports` -- 9 contracts kept, 0 broken - `python scripts/check_source_language.py origin/main...HEAD` -- exit 0 - `python scripts/check_commit_messages.py origin/main..HEAD` -- exit 0 Mutation, to show the added assertions are load-bearing rather than decorative: ``` trunk discards partial stdout again -> 1 failed (the inherited assertions) fork stops rendering TIMED_OUT_NOTE -> 2 failed (the added pair) ``` One mutation deliberately reported because it did **not** bite. An earlier revision asserted only that trunk's rendering lacks `TIMED_OUT_NOTE`. Making trunk emit a partial-output note in its own wording left the file green, because the constant is matched verbatim -- and that form of assertion is equally satisfied by a fork that stopped marking anything at all. Both sides are now measured in one run, so the absence reads as a difference rather than as a feature nobody has; removing the fork's append is what the second mutation above does. - [x] Relevant tests pass locally - [x] Relevant lint / type checks pass locally - [ ] User-facing docs or screenshots are updated when needed Left unchecked: no user-facing document describes either executor's timeout behaviour. The three corrected texts are module and factory docstrings. The model-facing half was checked separately and needed nothing -- the `timeout` parameter description says a command that hits its limit "is killed and the output it produced so far comes back marked partial", which is still true of this tool. ## Disclosed Four failures in `tests/test_ppt_engine_build_tool.py` appear in a wider selection and are **not** from this change. They reproduce at the `main` tip in a worktree holding none of it, and the cause is local layout rather than code: `raven_ppt` resolves to the primary checkout's `plugins-dist/ppt-engine`, which sits at an older revision than a fresh worktree's tests. Not investigated further here. How the red reached `main` is worth stating, since the cause was process rather than code. The executor fix was pushed and then rebased onto a `main` that had gained the pin in the meantime; the rebase surfaced the collision, and the merge landed on the pre-rebase head before the rebase was pushed. Rebasing before the push, as the contribution rules require, would have surfaced it while that merge request was still open. ## Risk No behaviour change: assertions added to an existing test, three docstrings corrected, no production statement altered and no code removed. The duplicated drain in the fork's executor is left exactly as it is. Rollback is a revert of the two commits. `main` stays green either way, since the breakage itself was resolved separately; what a revert costs is the stated difference between the two executors and the accuracy of the three docstrings. ## Related Issues N/A
140 lines
4.9 KiB
Python
140 lines
4.9 KiB
Python
"""Factories for the tool face code-flow contributes (raven-plugin.toml names them).
|
|
|
|
Every factory reads the flow slice's ``tools`` section and declines (returns
|
|
None) when that section leaves the face off or the slice does not parse, so a
|
|
product that wants the host's own tools simply says so and gets them.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
from typing import TYPE_CHECKING
|
|
|
|
from loguru import logger
|
|
from pydantic import ValidationError
|
|
|
|
from code_flow.config import FlowConfig, ToolsConfig
|
|
from code_flow.tools.exec import SPILL_SUBDIR, CodeExecTool, CodeExecutor
|
|
from code_flow.tools.filesystem import EditFileTool, ListDirTool, ReadFileTool, WriteFileTool
|
|
from code_flow.tools.read_state import owner_for
|
|
from code_flow.tools.search import GlobTool
|
|
from code_flow.tools.todo import STORES, TodoTool
|
|
|
|
if TYPE_CHECKING:
|
|
from raven.plugins.context import PluginContext
|
|
|
|
|
|
def _face(ctx: "PluginContext", seat: str) -> ToolsConfig | None:
|
|
"""The tool face's own section of the flow slice, or None to decline."""
|
|
try:
|
|
flow = FlowConfig.from_slice(dict(ctx.config or {}))
|
|
except ValidationError as exc:
|
|
logger.warning("code-flow: config slice is malformed; declining {}: {}", seat, exc)
|
|
return None
|
|
if not flow.tools.enabled:
|
|
return None
|
|
return flow.tools
|
|
|
|
|
|
def _fence(ctx: "PluginContext", cfg: ToolsConfig) -> tuple[Path, ...]:
|
|
"""The roots these tools may reach, mirroring what the host grants its own.
|
|
|
|
The host computes ``allowed_dirs = (workspace,) if restrict_to_workspace``
|
|
(raven/agent/loop/wiring.py) and an empty tuple means the fence is OFF --
|
|
which is what these replacements used to pass, whatever the product asked
|
|
for. The section carries the answer because a plugin factory cannot read
|
|
the host field; the launcher renders it in.
|
|
"""
|
|
return (Path(ctx.services.workspace),) if cfg.restrict_to_workspace else ()
|
|
|
|
|
|
def make_read_file(ctx: "PluginContext") -> ReadFileTool | None:
|
|
cfg = _face(ctx, "read_file")
|
|
if not cfg:
|
|
return None
|
|
return ReadFileTool(workspace=ctx.services.workspace, allowed_dirs=_fence(ctx, cfg), read_owner=owner_for(ctx))
|
|
|
|
|
|
def make_write_file(ctx: "PluginContext") -> WriteFileTool | None:
|
|
cfg = _face(ctx, "write_file")
|
|
if not cfg:
|
|
return None
|
|
return WriteFileTool(
|
|
workspace=ctx.services.workspace,
|
|
allowed_dirs=_fence(ctx, cfg),
|
|
syntax_note=cfg.python_syntax_note,
|
|
read_owner=owner_for(ctx),
|
|
)
|
|
|
|
|
|
def make_edit_file(ctx: "PluginContext") -> EditFileTool | None:
|
|
cfg = _face(ctx, "edit_file")
|
|
if not cfg:
|
|
return None
|
|
return EditFileTool(
|
|
workspace=ctx.services.workspace,
|
|
allowed_dirs=_fence(ctx, cfg),
|
|
syntax_note=cfg.python_syntax_note,
|
|
read_owner=owner_for(ctx),
|
|
require_read=cfg.require_read_before_edit,
|
|
)
|
|
|
|
|
|
def make_list_dir(ctx: "PluginContext") -> ListDirTool | None:
|
|
cfg = _face(ctx, "list_dir")
|
|
if not cfg:
|
|
return None
|
|
return ListDirTool(workspace=ctx.services.workspace, allowed_dirs=_fence(ctx, cfg))
|
|
|
|
|
|
def make_glob(ctx: "PluginContext") -> GlobTool | None:
|
|
cfg = _face(ctx, "glob")
|
|
if not cfg:
|
|
return None
|
|
return GlobTool(workspace=ctx.services.workspace, allowed_dirs=_fence(ctx, cfg))
|
|
|
|
|
|
def make_exec(ctx: "PluginContext") -> CodeExecTool | None:
|
|
"""The shell, with the clamped ceiling, the partial-output marker and the
|
|
30,000-character budget with spill. Served only where the host's own exec
|
|
would run on the host too (``tools.sandbox.backend == "none"``): the
|
|
replacement runs on the host, and a configured sandbox must not be
|
|
bypassed by a same-name tool -- so under any other backend this declines
|
|
and the host's exec keeps the shell."""
|
|
cfg = _face(ctx, "exec")
|
|
if not cfg:
|
|
return None
|
|
if cfg.exec.sandbox_backend != "none":
|
|
logger.info(
|
|
"code-flow: tools.sandbox.backend is {!r}; the host's exec keeps the shell", cfg.exec.sandbox_backend
|
|
)
|
|
return None
|
|
home = Path(ctx.services.workspace)
|
|
executor = CodeExecutor(max_timeout=cfg.exec.max_timeout, spill_dir=home / SPILL_SUBDIR)
|
|
return CodeExecTool(
|
|
timeout=cfg.exec.timeout,
|
|
working_dir=str(home),
|
|
restrict_to_workspace=cfg.restrict_to_workspace,
|
|
path_append=cfg.exec.path_append,
|
|
executor=executor,
|
|
extra_allowed_dirs=(home,),
|
|
max_timeout=cfg.exec.max_timeout,
|
|
)
|
|
|
|
|
|
def make_todo(ctx: "PluginContext") -> TodoTool | None:
|
|
"""The checklist, on the store the flow hook binds per session: one store
|
|
per Agent home, so the hook factory and this one meet on the same object."""
|
|
return TodoTool(STORES.for_home(ctx.services.workspace)) if _face(ctx, "todo") else None
|
|
|
|
|
|
__all__ = [
|
|
"make_edit_file",
|
|
"make_exec",
|
|
"make_glob",
|
|
"make_list_dir",
|
|
"make_read_file",
|
|
"make_todo",
|
|
"make_write_file",
|
|
]
|