Skip to content

feat(executor): integrate fusion-executor Layer B (Phase 1, default-off) - #135

Merged
dahai80 merged 1 commit into
mainfrom
feat/executor-integration-phase1
Aug 25, 2026
Merged

dahai80 merged 1 commit into
mainfrom
feat/executor-integration-phase1

Conversation

@dahai80

@dahai80 dahai80 commented Aug 25, 2026

Copy link
Copy Markdown
Owner

Summary

Route foreground bash commands to fusion-executor (Layer B "hands" — Rust+PyO3, self-built built-in tools + sandbox) via UDS NDJSON-RPC. = Layer A "brain" (SDK removed, self-built). This PR wires Layer A → Layer B.

Audit: audit/fusion-code-vs-executor-0825.md. PRD: architecture/fusion-executor-prd.md (3 phases; this is Phase 1 only, surgical, default-off, byte-identical when disabled).

What lands

5 new files in src/services/executor/ (mirrors the LSP stack: client → instance → manager → driver):

File Role
types.ts TS types mirroring executor Rust models (snake_case serde verbatim)
ExecutorClient.ts UDS NDJSON-RPC client (NOT LSP Content-Length). Spawns fusion-executor --serve --sock, spawn-gate, line buffer, multi-frame execute_stream
ExecutorInstance.ts State machine + crash-recovery cap, lazy-require client
manager.ts Module-scope singleton + generation counter + race-safe init (mirrors lsp/manager.ts), registerCleanup
executorDriver.ts BashTool delegation seam: callBashViaExecutor async generator (chunk→progress, result mapping), isExecutorRouteable gate, fail-open null

Plus:

  • BashTool.tsx — call() top lazy-require gate behind isEnvTruthy; routeable → executor, else runShellCommand; terminal null → in-process fallback
  • main.tsx — initializeExecutorManager() after LSP init (same trust gate)
  • .github/workflows/ci.yml — add src/services/executor/ to new-files lint list
  • CLAUDE.md + docs/model-providers.md — Executor seam section

Wire & protocol

  • NDJSON (executor fe-ipc writes serde_json::to_string(resp) + "\n" per frame), not vscode-jsonrpc Content-Length
  • execute_stream: multiple result frames share one request id — chunk ... done
  • Exit codes: 0=ok, -124=timeout, -1=blocked/internal

Gate + fail-open

  • Gate: isEnvTruthy(process.env.FUSION_CODE_EXECUTOR_ENABLED) (1/true/yes/on). Default off → BashTool uses runShellCommand, zero diff (byte-identical). Lazy-require keeps the executor module graph out of the disabled runtime path.
  • Fail-open: executor binary missing / init failed / crash → getExecutorClient() undefined → callBashViaExecutor returns null → BashTool falls back to in-process runShellCommand, logs warning. User is never blocked.
  • Background commands stay on fusion-code spawnShellTask (executor issue feat: add CreateArtifact/UpdateArtifact tools + artifact injection #1 — no background API).

Tests (23 new)

  • manager.test.ts — env gate (truthy/falsy/unset), disabled byte-identical (init no-op), enabled-but-binary-missing fail-open, singleton + generation counter
  • executorDriver.test.ts — isExecutorRouteable (5 cases), result mapping (normal/timeout/blocked), streaming chunk→progress (fullOutput accumulation), fail-open null, no-chunks 0 frames. Injection seam (_setExecutorClientForTesting) avoids mock.module cross-file pollution.

Gates

  • bun run typecheck — 0 errors
  • bun test src/__tests__/ — 431 pass (23 new)
  • executor files lint clean (added to CI lint list)
  • bun run build:dev — passes; runtime gate confirmed in minified bundle (env unset → runShellCommand)

Upstream

12 issues (#1–#12) filed on dahai80/fusion-executor for Layer B capability gaps (per issue→PR→code flow). Phase 3 (git snapshot + atomic rollback) blocked on executor issues #1/#2.

Follow-up

  • Phase 2: diagnostics slicing (executor.diagnostics already exposed; enable_rollback_snapshot=true lays groundwork)
  • Phase 3: git snapshot + atomic rollback (persistent UDS server already used via --serve)

Co-Authored-By: Claude Fable 5 [email protected]

Route foreground bash commands to fusion-executor (Layer B hands, Rust+PyO3,
self-built built-in tools + sandbox) via UDS NDJSON-RPC. fusion-code src/services/llm/
= Layer A brain (SDK removed, self-built). This wires Layer A to Layer B.

Phase 1 (PRD architecture/fusion-executor-prd.md):
- src/services/executor/types.ts — TS types mirroring executor Rust models
  (snake_case serde verbatim): ExecutionRequest/ExecutionResult/Diagnostics/
  ExecutorStreamChunk. Exit-code constants (0/-124/-1).
- ExecutorClient.ts — UDS NDJSON-RPC client (NOT LSP Content-Length framing).
  Spawns the executor serve+sock persistent UDS server, spawn-gate prevents
  ENOENT, net.Socket + line buffer. Methods health/execute/executeStream
  (multi-frame share one id: chunk then done)/stop. Crash handling isStopping+onCrash.
- ExecutorInstance.ts — state machine stopped to starting to running to stopping
  to error, MAX_CRASH_RECOVERY=3, lazy-require client.
- manager.ts — module-scope singleton + generation counter + race-safe initPromise
  (mirrors lsp/manager.ts). Gate isEnvTruthy(FUSION_CODE_EXECUTOR_ENABLED),
  unset means init no-op (byte-identical). registerCleanup on init.
- executorDriver.ts — BashTool delegation seam. callBashViaExecutor async
  generator: builds ExecutionRequest, executeStream chunk to progress protocol
  (callback to queue bridge, bursts coalesce, fullOutput preserved), terminal
  ExecutionResult to ExecResult (code=exit_code, interrupted=timed_out).
  isExecutorRouteable excludes run_in_background (issue #1) + _simulatedSedEdit.
  No client returns null (fail-open). Test injection seam.
- BashTool.tsx — call() top lazy-require gate (isEnvTruthy guard keeps executor
  module graph out of disabled runtime path). Routeable calls callBashViaExecutor,
  else runShellCommand. Terminal null calls logExecutorFallback + in-process fallback.
- main.tsx — initializeExecutorManager() after LSP init (same trust gate).

Wire = NDJSON (executor fe-ipc writes serde_json::to_string(resp)+newline per frame),
not vscode-jsonrpc Content-Length. Exit codes: 0=ok, -124=timeout, -1=blocked.

Gate + fail-open: FUSION_CODE_EXECUTOR_ENABLED unset means BashTool uses runShellCommand,
zero diff. Executor binary missing/init failed/crash means getExecutorClient() undefined,
callBashViaExecutor returns null, in-process fallback, log warning. Background commands
stay on fusion-code spawnShellTask (executor issue #1 no background API).

Tests: 23 new (manager gate/disabled/fail-open/singleton; executorDriver routing/
mapping/streaming/fail-open). Injection seam avoids mock.module cross-file pollution.

Gates: typecheck 0 errors, 431 tests pass, executor files lint clean (added to CI
lint list), build:dev passes. Runtime gate confirmed in bundle (env unset to runShellCommand).

Phase 2 (diagnostics slicing) + Phase 3 (git snapshot + atomic rollback) follow-up;
Phase 3 blocked on executor issues #1/#2 upstream.

Co-Authored-By: Claude Fable 5 <[email protected]>
@dahai80
dahai80 merged commit 3ea86de into main Aug 25, 2026
1 check passed
@dahai80
dahai80 deleted the feat/executor-integration-phase1 branch August 25, 2026 08:50
dahai80 added a commit that referenced this pull request Aug 26, 2026
Update Executor seam section: Phase 1 now PR #135, add Phase 2/3 landed
section (PR #139) covering diagnostics passthrough + slice-replace, cwd
passing + opt-in auto_rollback_policy, bashDiagnostics helper, and the
default-off byte-identical contract.

Co-Authored-By: Claude Fable 5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant