Skip to content

feat(executor): Phase 2 diagnostics slicing + Phase 3 git snapshot/rollback - #139

Merged
dahai80 merged 1 commit into
mainfrom
feat/executor-phase2-diagnostics-phase3-rollback
Aug 26, 2026
Merged

dahai80 merged 1 commit into
mainfrom
feat/executor-phase2-diagnostics-phase3-rollback

Conversation

@dahai80

@dahai80 dahai80 commented Aug 26, 2026

Copy link
Copy Markdown
Owner

Summary

fusion-code-side wiring for fusion-executor Phase 2 + Phase 3 (executor v0.2.0, upstream blockers cleared). Surgical, default-off, fail-open.

Phase 2 (diagnostics): preserve the server-side traceback slice the executor auto-populates on ExecutionResult.diagnostics (slicer prefers stderr, tail 30 lines, regex TS/Python/Node/Bun/Rust/Go/Swift). Phase 1 dropped it in mapResult; this threads it through ExecResult into BashTool's failure path. On failure, replace the full bash output with the compact slice to cut tokens fed to the model (PRD Phase 2 goal).

Phase 3 (snapshot + rollback): pass cwd in buildRequest so the executor can build a git snapshot (non-repo returns null safely; snapshot_id kept for debug). auto_rollback is opt-in via a separate env gate FUSION_CODE_EXECUTOR_AUTO_ROLLBACK (default off) — auto-rollback reverts the working tree on exit!=0 + file damage, which would undo the model's legit edits in an edit-test-fail coding loop. When rolled back, prefix a <note> so the model knows its edits were reverted. enable_rollback_snapshot stays on unconditionally; max_consecutive_failures is a dead field (Rust never reads it — caller owns the failure-count loop).

Changes

  • src/utils/ShellCommand.ts — ExecResult +3 optional fields (diagnostics, autoRolledBack, snapshotId). Inline Diagnostics structural type (no executor/types import — keeps utils < services dependency direction, no circular dep).
  • src/services/executor/executorDriver.ts — mapResult preserves diagnostics/snapshot/rollback; buildRequest passes cwd + opt-in auto_rollback_policy; two logForDebugging lines for diagnostics + rollback state.
  • src/tools/BashTool/BashTool.tsx — failure path uses formatDiagnosticsForModel to slice-replace full output + prefix rollback <note>.
  • src/tools/BashTool/bashDiagnostics.ts (new) — pure helper, extracted for unit testing.
  • src/__tests__/tools/BashTool/bashDiagnostics.test.ts (new) — 8 tests.
  • src/__tests__/services/executor/executorDriver.test.ts — 8 new tests (mapResult passthrough + buildRequest cwd/policy).

Why default-off / byte-identical

FUSION_CODE_EXECUTOR_ENABLED unset → isExecutorRouteable false → executorDriver never runs; in-process path leaves diagnostics/autoRolledBack/snapshotId undefined → formatDiagnosticsForModel returns the full output unchanged. No behavior change unless executor + rollback envs are explicitly set.

E2E verified (real executor binary, v0.2.0)

  • Phase 2: failing python → diagnostics auto-filled (error_type=ValueError, file_path, line_number, code_snippet, raw_trace); model receives slice not full traceback.
  • Phase 3 off (default): git-repo failure → auto_rollback_policy undefined, no rollback, snapshot_id populated (debug).
  • Phase 3 on (FUSION_CODE_EXECUTOR_AUTO_ROLLBACK=1): git-repo destructive failure → auto_rolled_back=true, working tree reverted, model sees <note>Working tree auto-reverted...</note>.
  • Non-repo cwd → snapshot_id=null, auto-rollback no-op (safe).

Gates

  • bun run typecheck — 0 errors
  • bun test src/__tests__/ — 460 pass
  • bunx biome check (executor files) — clean
  • bun run build:dev — pass

Closes #139.

…llback

Phase 2 (diagnostics): preserve the server-side traceback slice the
executor auto-populates on ExecutionResult.diagnostics, and on the
failure path replace the full bash output with that compact slice to cut
tokens fed to the model. Phase 1 dropped diagnostics in mapResult; this
threads it through ExecResult into BashTool's ShellError.stderr.

Phase 3 (snapshot + rollback): pass cwd in buildRequest so the executor
can build a git snapshot (non-repo returns null safely, snapshot_id kept
for debug). auto_rollback is opt-in via a SEPARATE env gate
FUSION_CODE_EXECUTOR_AUTO_ROLLBACK (default off) — auto-rollback reverts
the working tree on exit!=0 + file damage, which would undo the model's
legit edits in an edit-test-fail coding loop. When rolled back, prefix a
<note> so the model knows its edits were reverted. enable_rollback_snapshot
stays on unconditionally; max_consecutive_failures is a dead field (Rust
never reads it — caller owns the failure-count loop).

default-off byte-identical: FUSION_CODE_EXECUTOR_ENABLED unset ->
isExecutorRouteable false -> executorDriver never runs; in-process path
leaves diagnostics/autoRolledBack/snapshotId undefined ->
formatDiagnosticsForModel returns the full output unchanged.

New pure helper src/tools/BashTool/bashDiagnostics.ts (extracted for
unit testing, no BashTool module-graph dependency) + 8 tests. 8 new
executorDriver tests covering mapResult passthrough (diagnostics/
snapshot_id/auto_rolled_back) and buildRequest (cwd, auto_rollback
policy on/off, enable_rollback_snapshot regression).

Gates: typecheck 0 errors, lint clean, 460 tests pass, build:dev pass.

Co-Authored-By: Claude Fable 5 <[email protected]>
@dahai80
dahai80 merged commit 60798a0 into main Aug 26, 2026
1 check passed
@dahai80
dahai80 deleted the feat/executor-phase2-diagnostics-phase3-rollback branch August 26, 2026 03:56
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]>
dahai80 added a commit that referenced this pull request Aug 26, 2026
… PR #139 (#141)

PRD line 160 intent ("snapshot before executor call, rollback on failure")
is already satisfied by PR #139's in-band per-command auto-rollback
(buildRequest sends auto_rollback_policy; executor snapshots at call-start,
rolls back on exit!=0 + file-damage diff>0). The file-damage guard is safer
than PRD's blind retry-3x (only reverts when files are damaged, not on
legit edit-test-fail). The client-orchestrated whole-turn variant
(explicit snapshot_create/rollback RPC + turn lifecycle wiring) is
architecturally inferior: loses the model's good edits, needs a new
failure counter in query.ts, and the REPL query loop discards the terminal
return value (no capture path). Recording this as an explicit decision,
not backlog.

Co-authored-by: Claude Fable 5 <[email protected]>
dahai80 added a commit that referenced this pull request Aug 27, 2026
Caller-owned turn-level git snapshot at submitMessage entry + /rollback
manual command. Complementary to in-band auto-rollback (PR #139):
in-band = single-call self-contained + opt-in; turn-boundary = caller
owns the snapshot, model/user decides to /rollback — safer for the
edit-test-fail coding loop.

- types.ts: SnapshotResult/RollbackResult wire types
- ExecutorClient.ts: snapshotCreate/rollback client methods (UDS RPC)
- ExecutorInstance.ts: methods with ensureStarted health gate
- executorDriver.ts: ExecutorClientLike test seam extended
- turnSnapshot.ts (new): turn-boundary manager — takeTurnSnapshot
  (fail-soft, non-repo no-op), recordTurnFailure (counter, threshold 3),
  lastHint (staged hint drain), rollbackToTurn, ring of 5
- QueryEngine.ts: takeTurnSnapshot at submitMessage entry; case 'user'
  is_error scan + hint injection to mutableMessages
- commands/rollback/ (new): /rollback [turnId] local-jsx command
- tests: 21 unit tests (fake client: take/rollback, failure counter,
  non-repo no-op, ring bounds, default-off byte-identical)

Gate: default off, FUSION_CODE_EXECUTOR_TURN_SNAPSHOT=1 (strict truthy).
Byte-identical when env unset — takeTurnSnapshot no-op returns null,
no client calls, no ring entry, no hint. Double-gate with
FUSION_CODE_EXECUTOR_ENABLED (executor must be on too).

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