Repository navigation
Description
Context
fusion-executor (L4 generic-tool layer) is the monorepo's controlled execution sandbox + macOS OS-level control hub. It replaces what fusion-code currently does inline — subprocess spawning, command validation, timeout, stdio capture, file IO, git rollback — with a hardened Rust+PyO3 core (security guard, PTY/stdio sandbox, diagnostics slicer, auto-rollback, native file tools, GUI control).
Audit audit/fusion-ar-audit.md P2-7 designates fusion-executor as the home for the code-sandbox capability currently embedded per-vertical (e.g. fusion-science PythonExecutor/JupyterKernel/RExecutor). ARCH-3 of the fusion-executor architecture audit (audit/fusion-executor-audit-result-0827.md) found zero real consumers — the executor exists but nothing in the monorepo delegates to it yet.
Proposal
Strip fusion-code's own subprocess/file-IO into an ExecutorDriver interface that delegates to fusion_executor.FusionSandboxExecutor. All command validation, timeout, stdio capture, and diagnostics parsing move to the executor; fusion-code keeps the agent loop, model prompting, and self-healing control.
Stable Python API (already shipped)
from fusion_executor import FusionSandboxExecutor, ExecutionResult, RollbackPolicy
ex = FusionSandboxExecutor()
result: ExecutionResult = ex.run(
"pytest tests/",
cwd=repo,
task_id="task-42",
timeout_sec=60.0,
auto_rollback=RollbackPolicy(max_consecutive_failures=3, file_damage_check=True),
)ExecutionResult on exit_code != 0 carries a pre-sliced diagnostics (error_type, file_path, line_number, code_snippet, raw_trace) — feed it straight into the next model prompt; do not re-parse raw stdout.
Other relevant methods: run_streaming() (live stdio chunks), file_edit()/multi_edit()/write_file()/apply_patch()/replace_function() (Claude-SDK FileEdit parity, atomic + flock), glob()/grep_with_opts() (ripgrep parity), shell_start()/shell_output()/kill_shell() (background tasks), snapshot_create()/rollback() (caller-driven), serve() UDS JSON-RPC server with subscribe() server-push (telemetry/stdio/screenshot), gui_action() (macOS Accessibility control).
Contract points fusion-code must own
- Diagnostics parsing — read
result.diagnosticsto build the next model turn. - Circuit breaker — the executor is per-task stateless by design and does not count consecutive failures. The caller owns that count.
RollbackPolicy.max_consecutive_failuresis the threshold field the caller reads (the executor accepts it on the wire but never reads it — reserved by design). Hitting the threshold stops the self-healing loop (fail visibly) instead of looping forever.
Integration skeleton
A runnable one-way reference skeleton lives in fusion-executor (does not import fusion-code):
fusion-executor/examples/08_integrate_fusion_code.py— self-healing loop: parse diagnostics, own the consecutive-failure count as a circuit breaker, optionalauto_rollback.
Why file an issue, not a PR
This is a cross-project refactor touching fusion-code's architecture (agent loop vs execution delegation). Filing the issue for fusion-code maintainers to scope; a PR would follow once the ExecutorDriver boundary is agreed. Per the monorepo rule, upstream changes go issue -> PR -> code.
References
- fusion-executor PRD:
architecture/fusion-executor-prd.md(data schema §4, diagnostics algorithm §4.2, fusion-code refactor plan) - fusion-executor audit (ARCH-3):
audit/fusion-executor-audit-result-0827.md - monorepo audit:
audit/fusion-ar-audit.mdP2-7
Activity
refactor(screens): extract message-display derive into messageDisplay…
feat(executor): delegate file-write disk step to executor (#176)
dahai80 commentedon Aug 30, 2026
Landed in
5296004(direct-push main).What
Extends the existing executor subprocess delegation (previously bash-only) to cover file-IO disk writes.
FileWriteTool/FileEditTool/MultiEditToolnow delegate the final byte-write step to thefusion-executorsubprocess via the existing UDS NDJSON-RPC seam (executor.write_file), instead of writing in-process.Boundary (key design decision)
File tools interleave heavy client-side coordination around the disk write — staleness check, quote normalization (
findActualString+preserveQuoteStyle), client-side patch generation (getPatchForEdit), LSPdidChange/didSave, VSCode diff notify,readFileState.set, git-diff. The executor's ownfile_edit/multi_edit/apply_patchdo their own independent string matching (no quote-norm, no staleness, no LSP) — delegating "the edit" would diverge semantics and lose staleness/LSP/readFileState.Correct boundary: delegate ONLY the final
writeTextContentstep, AFTER fusion-code completes all client-side coordination. A new helpercallWriteViaExecutor(...)is invoked in place ofwriteTextContent; it fail-opens to in-processwriteTextContenton any divergence. The executor'sfile_edit/multi_edit/apply_patch/replace_functionare deliberately not used — onlywrite_file(raw byte write).Fail-open mitigations (never block a user's edit)
callWriteViaExecutorreturnsnull(→ in-process write) when:atomic_writewould replace the link; in-process preserves it)ok:falseEditResultCRLF is normalized client-side before sending (executor writes raw bytes). Everything after the write (LSP, VSCode, readFileState, git-diff) runs unchanged on both paths — it operates on the path, not the write mechanism.
Default-off, byte-identical-off
FUSION_CODE_EXECUTOR_ENABLEDunset →callWriteViaExecutorreturnsnullat the env gate →writeTextContentruns in-process, identical to today. Runtime env gate (like the bash seam), not afeature()build flag — unconditionalrequire()keeps executor code in the bundle, gated at runtime.Wire
executor.write_fileparams{path, content, cwd?}→EditResult {ok, path?, error?, matches?}(source of truth:fe-tools/src/lib.rs:54).Files
src/services/executor/types.ts—EditResultwire type.src/services/executor/ExecutorClient.ts—writeFilemethod (reuses existingsendRequest).src/services/executor/ExecutorInstance.ts—writeFilewrapper (health-gated, no retry).src/services/executor/executorDriver.ts—isFileWriteRouteable+callWriteViaExecutor+ExecutorClientLikeextension.src/tools/FileWriteTool/FileWriteTool.ts/FileEditTool/FileEditTool.ts/MultiEditTool/MultiEditTool.ts— per-call swap site atwriteTextContent.src/__tests__/executor/writeDelegation.test.ts— 12 unit tests via the_setExecutorClientForTestinginjection seam.Gates
typecheck 0 / 973 tests pass (+12 new) / biome clean on changed files (pre-existing format deviations on FileEdit/FileWrite unchanged) / build:dev 3829 modules (matches HEAD, executor runtime-gated off).